Project

General

Profile

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

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

    
22
function news_search($func_vars) {
23
	extract($func_vars, EXTR_PREFIX_ALL, 'func');
24

    
25
	// how many lines of excerpt we want to have at most
26
	$max_excerpt_num = $func_default_max_excerpt;
27
	// do we want excerpt from comments?
28
	$excerpt_from_comments = true; // TODO: make this configurable
29
	$divider = ".";
30
	$result = false;
31

    
32
	// fetch all active news-posts (from active groups) in this section.
33
	$t = time();
34
	$table_posts = TABLE_PREFIX."mod_news_posts";
35
	$table_groups = TABLE_PREFIX."mod_news_groups";
36
	$query = $func_database->query("
37
		SELECT p.post_id, p.title, p.content_short, p.content_long, p.link, p.posted_when, p.posted_by
38
		FROM $table_posts AS p LEFT OUTER JOIN $table_groups AS g ON p.group_id = g.group_id
39
		WHERE p.section_id='$func_section_id' AND p.active = '1' AND ( g.active IS NULL OR g.active = '1' )
40
		AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)
41
		ORDER BY p.post_id DESC
42
	");
43
	// now call print_excerpt() for every single post
44
	if($query->numRows() > 0) {
45
		while($res = $query->fetchRow()) {
46
			$text = $res['title'].$divider.$res['content_short'].$divider.$res['content_long'].$divider;
47
			// fetch comments and add to $text
48
			if($excerpt_from_comments) {
49
				$table = TABLE_PREFIX."mod_news_comments";
50
				$commentquery = $func_database->query("
51
					SELECT title, comment
52
					FROM $table
53
					WHERE post_id='{$res['post_id']}'
54
					ORDER BY commented_when ASC
55
				");
56
				if($commentquery->numRows() > 0) {
57
					while($c_res = $commentquery->fetchRow()) {
58
						$text .= $c_res['title'].$divider.$c_res['comment'].$divider;
59
					}
60
				}
61
			}
62
			$mod_vars = array(
63
				'page_link' => $res['link'], // use direct link to news-item
64
				'page_link_target' => "",
65
				'page_title' => $func_page_title,
66
				'page_description' => $res['title'], // use news-title as description
67
				'page_modified_when' => $res['posted_when'],
68
				'page_modified_by' => $res['posted_by'],
69
				'text' => $text,
70
				'max_excerpt_num' => $max_excerpt_num
71
			);
72
			if(print_excerpt2($mod_vars, $func_vars)) {
73
				$result = true;
74
			}
75
		}
76
	}
77
	
78
	// now fetch group-titles - ignore those without (active) postings
79
	$table_groups = TABLE_PREFIX."mod_news_groups";
80
	$table_posts = TABLE_PREFIX."mod_news_posts";
81
	$query = $func_database->query("
82
		SELECT DISTINCT g.title, g.group_id
83
		FROM $table_groups AS g INNER JOIN $table_posts AS p ON g.group_id = p.group_id
84
		WHERE g.section_id='$func_section_id' AND g.active = '1' AND p.active = '1'
85
	");
86
	// now call print_excerpt() for every single group, too
87
	if($query->numRows() > 0) {
88
		while($res = $query->fetchRow()) {
89
			$mod_vars = array(
90
				'page_link' => $func_page_link,
91
				'page_link_target' => "&g=".$res['group_id'],
92
				'page_title' => $func_page_title,
93
				'page_description' => $func_page_description,
94
				'page_modified_when' => $func_page_modified_when,
95
				'page_modified_by' => $func_page_modified_by,
96
				'text' => $res['title'].$divider,
97
				'max_excerpt_num' => $max_excerpt_num
98
			);
99
			if(print_excerpt2($mod_vars, $func_vars)) {
100
				$result = true;
101
			}
102
		}
103
	}
104
	return $result;
105
}
106

    
107
?>
(27-27/31)