Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         news
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2011, Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: search.php 1538 2011-12-10 15:06:15Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/search.php $
14
 * @lastmodified    $Date: 2011-12-10 16:06:15 +0100 (Sat, 10 Dec 2011) $
15
 *
16
 */
17

    
18
// Must include code to stop this file being access directly
19
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
20

    
21
function news_search($func_vars) {
22
	extract($func_vars, EXTR_PREFIX_ALL, 'func');
23
	static $search_sql1 = FALSE;
24
	static $search_sql2 = FALSE;
25
	static $search_sql3 = FALSE;
26
	if(function_exists('search_make_sql_part')) {
27
		if($search_sql1===FALSE)
28
			$search_sql1 = search_make_sql_part($func_search_url_array, $func_search_match, array('`title`','`content_short`','`content_long`'));
29
		if($search_sql2===FALSE)
30
			$search_sql2 = search_make_sql_part($func_search_url_array, $func_search_match, array('`title`','`comment`'));
31
		if($search_sql3===FALSE)
32
			$search_sql3 = search_make_sql_part($func_search_url_array, $func_search_match, array('g.`title`'));
33
	} else {
34
		$search_sql1 = $search_sql2 = $search_sql3 = '1=1';
35
	}
36
	// how many lines of excerpt we want to have at most
37
	$max_excerpt_num = $func_default_max_excerpt;
38
	// do we want excerpt from comments?
39
	$excerpt_from_comments = true; // TODO: make this configurable
40
	$divider = ".";
41
	$result = false;
42

    
43
  if($func_time_limit>0) {
44
    $stop_time = time() + $func_time_limit;
45
  }
46

    
47
	// fetch all active news-posts (from active groups) in this section.
48
	$t = time();
49
	$table_posts = TABLE_PREFIX."mod_news_posts";
50
	$table_groups = TABLE_PREFIX."mod_news_groups";
51
	$query = $func_database->query("
52
		SELECT p.post_id, p.title, p.content_short, p.content_long, p.link, p.posted_when, p.posted_by
53
		FROM $table_posts AS p LEFT OUTER JOIN $table_groups AS g ON p.group_id = g.group_id
54
		WHERE p.section_id='$func_section_id' AND p.active = '1' AND ( g.active IS NULL OR g.active = '1' )
55
		AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)
56
		ORDER BY p.post_id DESC
57
	");
58
	// now call print_excerpt() for every single post
59
	if($query->numRows() > 0) {
60
		while($res = $query->fetchRow()) {
61
			$text = '';
62
			// break out if stop-time is reached
63
			if(isset($stop_time) && time()>$stop_time) return($result);
64
			// fetch content
65
			$postquery = $func_database->query("
66
				SELECT title, content_short, content_long
67
				FROM $table_posts
68
				WHERE post_id='{$res['post_id']}' AND $search_sql1
69
			");
70
			if($postquery->numRows() > 0) {
71
				if($p_res = $postquery->fetchRow()) {
72
					$text = $p_res['title'].$divider.$p_res['content_short'].$divider.$p_res['content_long'].$divider;
73
				}
74
			}
75
			// fetch comments and add to $text
76
			if($excerpt_from_comments) {
77
				$table = TABLE_PREFIX."mod_news_comments";
78
				$commentquery = $func_database->query("
79
					SELECT title, comment
80
					FROM $table
81
					WHERE post_id='{$res['post_id']}' AND $search_sql2
82
					ORDER BY commented_when ASC
83
				");
84
				if($commentquery->numRows() > 0) {
85
					while($c_res = $commentquery->fetchRow()) {
86
						// break out if stop-time is reached
87
						if(isset($stop_time) && time()>$stop_time) return($result);
88
						$text .= $c_res['title'].$divider.$c_res['comment'].$divider;
89
					}
90
				}
91
			}
92
			if($text) {
93
				$mod_vars = array(
94
					'page_link' => $res['link'], // use direct link to news-item
95
					'page_link_target' => "",
96
					'page_title' => $func_page_title,
97
					'page_description' => $res['title'], // use news-title as description
98
					'page_modified_when' => $res['posted_when'],
99
					'page_modified_by' => $res['posted_by'],
100
					'text' => $text,
101
					'max_excerpt_num' => $max_excerpt_num
102
				);
103
				if(print_excerpt2($mod_vars, $func_vars)) {
104
					$result = true;
105
				}
106
			}
107
		}
108
	}
109
	
110
	// now fetch group-titles - ignore those without (active) postings
111
	$table_groups = TABLE_PREFIX."mod_news_groups";
112
	$table_posts = TABLE_PREFIX."mod_news_posts";
113
	$query = $func_database->query("
114
		SELECT DISTINCT g.title, g.group_id
115
		FROM $table_groups AS g INNER JOIN $table_posts AS p ON g.group_id = p.group_id
116
		WHERE g.section_id='$func_section_id' AND g.active = '1' AND p.active = '1' AND $search_sql3
117
	");
118
	// now call print_excerpt() for every single group, too
119
	if($query->numRows() > 0) {
120
		while($res = $query->fetchRow()) {
121
			// break out if stop-time is reached
122
			if(isset($stop_time) && time()>$stop_time) return($result);
123
			$mod_vars = array(
124
				'page_link' => $func_page_link,
125
				'page_link_target' => "&g=".$res['group_id'],
126
				'page_title' => $func_page_title,
127
				'page_description' => $func_page_description,
128
				'page_modified_when' => $func_page_modified_when,
129
				'page_modified_by' => $func_page_modified_by,
130
				'text' => $res['title'].$divider,
131
				'max_excerpt_num' => $max_excerpt_num
132
			);
133
			if(print_excerpt2($mod_vars, $func_vars)) {
134
				$result = true;
135
			}
136
		}
137
	}
138
	return $result;
139
}
(27-27/31)