1 |
1420
|
Luisehahne
|
<?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$
|
14 |
|
|
* @filesource $HeadURL$
|
15 |
|
|
* @lastmodified $Date$
|
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 |
1442
|
Luisehahne
|
static $search_sql1 = FALSE;
|
25 |
|
|
static $search_sql2 = FALSE;
|
26 |
|
|
static $search_sql3 = FALSE;
|
27 |
|
|
if(function_exists('search_make_sql_part')) {
|
28 |
|
|
if($search_sql1===FALSE)
|
29 |
|
|
$search_sql1 = search_make_sql_part($func_search_url_array, $func_search_match, array('`title`','`content_short`','`content_long`'));
|
30 |
|
|
if($search_sql2===FALSE)
|
31 |
|
|
$search_sql2 = search_make_sql_part($func_search_url_array, $func_search_match, array('`title`','`comment`'));
|
32 |
|
|
if($search_sql3===FALSE)
|
33 |
|
|
$search_sql3 = search_make_sql_part($func_search_url_array, $func_search_match, array('g.`title`'));
|
34 |
|
|
} else {
|
35 |
|
|
$search_sql1 = $search_sql2 = $search_sql3 = '1=1';
|
36 |
|
|
}
|
37 |
1420
|
Luisehahne
|
// how many lines of excerpt we want to have at most
|
38 |
|
|
$max_excerpt_num = $func_default_max_excerpt;
|
39 |
|
|
// do we want excerpt from comments?
|
40 |
|
|
$excerpt_from_comments = true; // TODO: make this configurable
|
41 |
|
|
$divider = ".";
|
42 |
|
|
$result = false;
|
43 |
|
|
|
44 |
1442
|
Luisehahne
|
if($func_time_limit>0) {
|
45 |
|
|
$stop_time = time() + $func_time_limit;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
1420
|
Luisehahne
|
// fetch all active news-posts (from active groups) in this section.
|
49 |
|
|
$t = time();
|
50 |
|
|
$table_posts = TABLE_PREFIX."mod_news_posts";
|
51 |
|
|
$table_groups = TABLE_PREFIX."mod_news_groups";
|
52 |
|
|
$query = $func_database->query("
|
53 |
|
|
SELECT p.post_id, p.title, p.content_short, p.content_long, p.link, p.posted_when, p.posted_by
|
54 |
|
|
FROM $table_posts AS p LEFT OUTER JOIN $table_groups AS g ON p.group_id = g.group_id
|
55 |
|
|
WHERE p.section_id='$func_section_id' AND p.active = '1' AND ( g.active IS NULL OR g.active = '1' )
|
56 |
|
|
AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)
|
57 |
|
|
ORDER BY p.post_id DESC
|
58 |
|
|
");
|
59 |
|
|
// now call print_excerpt() for every single post
|
60 |
|
|
if($query->numRows() > 0) {
|
61 |
|
|
while($res = $query->fetchRow()) {
|
62 |
1442
|
Luisehahne
|
$text = '';
|
63 |
|
|
// break out if stop-time is reached
|
64 |
|
|
if(isset($stop_time) && time()>$stop_time) return($result);
|
65 |
|
|
// fetch content
|
66 |
|
|
$postquery = $func_database->query("
|
67 |
|
|
SELECT title, content_short, content_long
|
68 |
|
|
FROM $table_posts
|
69 |
|
|
WHERE post_id='{$res['post_id']}' AND $search_sql1
|
70 |
|
|
");
|
71 |
|
|
if($postquery->numRows() > 0) {
|
72 |
|
|
if($p_res = $postquery->fetchRow()) {
|
73 |
|
|
$text = $p_res['title'].$divider.$p_res['content_short'].$divider.$p_res['content_long'].$divider;
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
1420
|
Luisehahne
|
// fetch comments and add to $text
|
77 |
|
|
if($excerpt_from_comments) {
|
78 |
|
|
$table = TABLE_PREFIX."mod_news_comments";
|
79 |
|
|
$commentquery = $func_database->query("
|
80 |
|
|
SELECT title, comment
|
81 |
|
|
FROM $table
|
82 |
1442
|
Luisehahne
|
WHERE post_id='{$res['post_id']}' AND $search_sql2
|
83 |
1420
|
Luisehahne
|
ORDER BY commented_when ASC
|
84 |
|
|
");
|
85 |
|
|
if($commentquery->numRows() > 0) {
|
86 |
|
|
while($c_res = $commentquery->fetchRow()) {
|
87 |
1442
|
Luisehahne
|
// break out if stop-time is reached
|
88 |
|
|
if(isset($stop_time) && time()>$stop_time) return($result);
|
89 |
1420
|
Luisehahne
|
$text .= $c_res['title'].$divider.$c_res['comment'].$divider;
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
1442
|
Luisehahne
|
if($text) {
|
94 |
|
|
$mod_vars = array(
|
95 |
|
|
'page_link' => $res['link'], // use direct link to news-item
|
96 |
|
|
'page_link_target' => "",
|
97 |
|
|
'page_title' => $func_page_title,
|
98 |
|
|
'page_description' => $res['title'], // use news-title as description
|
99 |
|
|
'page_modified_when' => $res['posted_when'],
|
100 |
|
|
'page_modified_by' => $res['posted_by'],
|
101 |
|
|
'text' => $text,
|
102 |
|
|
'max_excerpt_num' => $max_excerpt_num
|
103 |
|
|
);
|
104 |
|
|
if(print_excerpt2($mod_vars, $func_vars)) {
|
105 |
|
|
$result = true;
|
106 |
|
|
}
|
107 |
1420
|
Luisehahne
|
}
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
// now fetch group-titles - ignore those without (active) postings
|
112 |
|
|
$table_groups = TABLE_PREFIX."mod_news_groups";
|
113 |
|
|
$table_posts = TABLE_PREFIX."mod_news_posts";
|
114 |
|
|
$query = $func_database->query("
|
115 |
|
|
SELECT DISTINCT g.title, g.group_id
|
116 |
|
|
FROM $table_groups AS g INNER JOIN $table_posts AS p ON g.group_id = p.group_id
|
117 |
1442
|
Luisehahne
|
WHERE g.section_id='$func_section_id' AND g.active = '1' AND p.active = '1' AND $search_sql3
|
118 |
1420
|
Luisehahne
|
");
|
119 |
|
|
// now call print_excerpt() for every single group, too
|
120 |
|
|
if($query->numRows() > 0) {
|
121 |
|
|
while($res = $query->fetchRow()) {
|
122 |
1442
|
Luisehahne
|
// break out if stop-time is reached
|
123 |
|
|
if(isset($stop_time) && time()>$stop_time) return($result);
|
124 |
1420
|
Luisehahne
|
$mod_vars = array(
|
125 |
|
|
'page_link' => $func_page_link,
|
126 |
|
|
'page_link_target' => "&g=".$res['group_id'],
|
127 |
|
|
'page_title' => $func_page_title,
|
128 |
|
|
'page_description' => $func_page_description,
|
129 |
|
|
'page_modified_when' => $func_page_modified_when,
|
130 |
|
|
'page_modified_by' => $func_page_modified_by,
|
131 |
|
|
'text' => $res['title'].$divider,
|
132 |
|
|
'max_excerpt_num' => $max_excerpt_num
|
133 |
|
|
);
|
134 |
|
|
if(print_excerpt2($mod_vars, $func_vars)) {
|
135 |
|
|
$result = true;
|
136 |
|
|
}
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
return $result;
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
?>
|