Revision 5
Added by stefan about 19 years ago
view.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
// $Id: view.php,v 1.7 2005/06/21 09:11:27 rdjurovich Exp $ |
|
1 |
<?php |
|
4 | 2 |
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2005, Ryan Djurovich |
|
9 |
|
|
10 |
Website Baker is free software; you can redistribute it and/or modify |
|
11 |
it under the terms of the GNU General Public License as published by |
|
12 |
the Free Software Foundation; either version 2 of the License, or |
|
13 |
(at your option) any later version. |
|
14 |
|
|
15 |
Website Baker is distributed in the hope that it will be useful, |
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
GNU General Public License for more details. |
|
19 |
|
|
20 |
You should have received a copy of the GNU General Public License |
|
21 |
along with Website Baker; if not, write to the Free Software |
|
22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
|
|
24 |
*/ |
|
3 |
// $Id: view.php,v 1.7 2005/06/21 09:11:27 rdjurovich Exp $ |
|
25 | 4 |
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2005, Ryan Djurovich |
|
9 |
|
|
10 |
Website Baker is free software; you can redistribute it and/or modify |
|
11 |
it under the terms of the GNU General Public License as published by |
|
12 |
the Free Software Foundation; either version 2 of the License, or |
|
13 |
(at your option) any later version. |
|
14 |
|
|
15 |
Website Baker is distributed in the hope that it will be useful, |
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
GNU General Public License for more details. |
|
19 |
|
|
20 |
You should have received a copy of the GNU General Public License |
|
21 |
along with Website Baker; if not, write to the Free Software |
|
22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
|
|
24 |
*/ |
|
25 |
|
|
26 | 26 |
// Must include code to stop this file being access directly |
27 | 27 |
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); } |
28 |
|
|
29 |
// Check if there is a start point defined |
|
30 |
if(isset($_GET['p']) AND is_numeric($_GET['p']) AND $_GET['p'] >= 0) { |
|
31 |
$position = $_GET['p']; |
|
32 |
} else { |
|
33 |
$position = 0; |
|
34 |
} |
|
35 |
|
|
36 |
// Get user's username, display name, email, and id - needed for insertion into post info |
|
37 |
$users = array(); |
|
38 |
$query_users = $database->query("SELECT user_id,username,display_name,email FROM ".TABLE_PREFIX."users"); |
|
39 |
if($query_users->numRows() > 0) { |
|
40 |
while($user = $query_users->fetchRow()) { |
|
41 |
// Insert user info into users array |
|
42 |
$user_id = $user['user_id']; |
|
43 |
$users[$user_id]['username'] = $user['username']; |
|
44 |
$users[$user_id]['display_name'] = $user['display_name']; |
|
45 |
$users[$user_id]['email'] = $user['email']; |
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
// Get groups (title, if they are active, and their image [if one has been uploaded]) |
|
50 |
$groups[0]['title'] = ''; |
|
51 |
$groups[0]['active'] = true; |
|
52 |
$groups[0]['image'] = ''; |
|
53 |
$query_users = $database->query("SELECT group_id,title,active FROM ".TABLE_PREFIX."mod_news_groups WHERE section_id = '$section_id' ORDER BY position ASC"); |
|
54 |
if($query_users->numRows() > 0) { |
|
55 |
while($group = $query_users->fetchRow()) { |
|
56 |
// Insert user info into users array |
|
57 |
$group_id = $group['group_id']; |
|
58 |
$groups[$group_id]['title'] = stripslashes($group['title']); |
|
59 |
$groups[$group_id]['active'] = $group['active']; |
|
60 |
if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg')) { |
|
61 |
$groups[$group_id]['image'] = WB_URL.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg'; |
|
62 |
} else { |
|
63 |
$groups[$group_id]['image'] = ''; |
|
64 |
} |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
// Check if we should show the main page or a post itself |
|
69 |
if(!defined('POST_ID') OR !is_numeric(POST_ID)) { |
|
70 |
|
|
71 |
// Check if we should only list posts from a certain group |
|
72 |
if(isset($_GET['g']) AND is_numeric($_GET['g'])) { |
|
73 |
$query_extra = " AND group_id = '".$_GET['g']."'"; |
|
74 |
?> |
|
75 |
<style type="text/css">.selected_group_title { font-size: 14px; text-align: center; }</style> |
|
76 |
<?php |
|
77 |
} else { |
|
78 |
$query_extra = ''; |
|
79 |
} |
|
80 |
|
|
28 |
|
|
29 |
// Check if there is a start point defined
|
|
30 |
if(isset($_GET['p']) AND is_numeric($_GET['p']) AND $_GET['p'] >= 0) {
|
|
31 |
$position = $_GET['p'];
|
|
32 |
} else {
|
|
33 |
$position = 0;
|
|
34 |
}
|
|
35 |
|
|
36 |
// Get user's username, display name, email, and id - needed for insertion into post info
|
|
37 |
$users = array();
|
|
38 |
$query_users = $database->query("SELECT user_id,username,display_name,email FROM ".TABLE_PREFIX."users");
|
|
39 |
if($query_users->numRows() > 0) {
|
|
40 |
while($user = $query_users->fetchRow()) {
|
|
41 |
// Insert user info into users array
|
|
42 |
$user_id = $user['user_id'];
|
|
43 |
$users[$user_id]['username'] = $user['username'];
|
|
44 |
$users[$user_id]['display_name'] = $user['display_name'];
|
|
45 |
$users[$user_id]['email'] = $user['email'];
|
|
46 |
}
|
|
47 |
}
|
|
48 |
|
|
49 |
// Get groups (title, if they are active, and their image [if one has been uploaded])
|
|
50 |
$groups[0]['title'] = '';
|
|
51 |
$groups[0]['active'] = true;
|
|
52 |
$groups[0]['image'] = '';
|
|
53 |
$query_users = $database->query("SELECT group_id,title,active FROM ".TABLE_PREFIX."mod_news_groups WHERE section_id = '$section_id' ORDER BY position ASC");
|
|
54 |
if($query_users->numRows() > 0) {
|
|
55 |
while($group = $query_users->fetchRow()) {
|
|
56 |
// Insert user info into users array
|
|
57 |
$group_id = $group['group_id'];
|
|
58 |
$groups[$group_id]['title'] = stripslashes($group['title']);
|
|
59 |
$groups[$group_id]['active'] = $group['active'];
|
|
60 |
if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg')) {
|
|
61 |
$groups[$group_id]['image'] = WB_URL.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg';
|
|
62 |
} else {
|
|
63 |
$groups[$group_id]['image'] = '';
|
|
64 |
}
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
// Check if we should show the main page or a post itself
|
|
69 |
if(!defined('POST_ID') OR !is_numeric(POST_ID)) {
|
|
70 |
|
|
71 |
// Check if we should only list posts from a certain group
|
|
72 |
if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
|
|
73 |
$query_extra = " AND group_id = '".$_GET['g']."'";
|
|
74 |
?>
|
|
75 |
<style type="text/css">.selected_group_title { font-size: 14px; text-align: center; }</style>
|
|
76 |
<?php
|
|
77 |
} else {
|
|
78 |
$query_extra = '';
|
|
79 |
}
|
|
80 |
|
|
81 | 81 |
// Get settings |
82 |
$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'"); |
|
83 |
if($query_settings->numRows() > 0) { |
|
84 |
$fetch_settings = $query_settings->fetchRow(); |
|
85 |
$setting_header = stripslashes($fetch_settings['header']); |
|
86 |
$setting_post_loop = stripslashes($fetch_settings['post_loop']); |
|
87 |
$setting_footer = stripslashes($fetch_settings['footer']); |
|
88 |
$setting_posts_per_page = $fetch_settings['posts_per_page']; |
|
89 |
} else { |
|
90 |
$setting_header = ''; |
|
91 |
$setting_post_loop = ''; |
|
92 |
$setting_footer = ''; |
|
93 |
$setting_posts_per_page = ''; |
|
94 |
} |
|
95 |
|
|
96 |
// Get total number of posts |
|
97 |
$query_total_num = $database->query("SELECT post_id FROM ".TABLE_PREFIX."mod_news_posts WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra"); |
|
98 |
$total_num = $query_total_num->numRows(); |
|
99 |
|
|
100 |
// Work-out if we need to add limit code to sql |
|
101 |
if($setting_posts_per_page != 0) { |
|
102 |
$limit_sql = " LIMIT $position,$setting_posts_per_page"; |
|
103 |
} else { |
|
104 |
$limit_sql = ""; |
|
105 |
} |
|
106 |
|
|
107 |
// Query posts (for this page) |
|
108 |
$query_posts = $database->query("SELECT group_id,post_id,title,link,short,posted_by,posted_when FROM ".TABLE_PREFIX."mod_news_posts WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra ORDER BY position DESC".$limit_sql); |
|
109 |
$num_posts = $query_posts->numRows(); |
|
110 |
|
|
111 |
// Create previous and next links |
|
112 |
if($setting_posts_per_page != 0) { |
|
113 |
if($position > 0) { |
|
114 |
if(isset($_GET['g']) AND is_numeric($_GET['g'])) { |
|
115 |
$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'&g='.$_GET['g'].'"><< '; |
|
116 |
} else { |
|
117 |
$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'"><< '; |
|
118 |
} |
|
119 |
$pl_append = '</a>'; |
|
120 |
$previous_link = $pl_prepend.$TEXT['PREVIOUS'].$pl_append; |
|
121 |
$previous_page_link = $pl_prepend.$TEXT['PREVIOUS_PAGE'].$pl_append; |
|
122 |
} else { |
|
123 |
$previous_link = ''; |
|
124 |
$previous_page_link = ''; |
|
125 |
} |
|
126 |
if($position+$setting_posts_per_page >= $total_num) { |
|
127 |
$next_link = ''; |
|
128 |
$next_page_link = ''; |
|
129 |
} else { |
|
130 |
if(isset($_GET['g']) AND is_numeric($_GET['g'])) { |
|
131 |
$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'&g='.$_GET['g'].'"> '; |
|
132 |
} else { |
|
133 |
$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'"> '; |
|
134 |
} |
|
135 |
$nl_append = ' >></a>'; |
|
136 |
$next_link = $nl_prepend.$TEXT['NEXT'].$nl_append; |
|
137 |
$next_page_link = $nl_prepend.$TEXT['NEXT_PAGE'].$nl_append; |
|
138 |
} |
|
139 |
if($position+$setting_posts_per_page > $total_num) { |
|
140 |
$num_of = $position+$num_posts; |
|
141 |
} else { |
|
142 |
$num_of = $position+$setting_posts_per_page; |
|
143 |
} |
|
144 |
$out_of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OUT_OF']).' '.$total_num; |
|
145 |
$of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OF']).' '.$total_num; |
|
146 |
$display_previous_next_links = ''; |
|
147 |
} else { |
|
148 |
$display_previous_next_links = 'none'; |
|
149 |
} |
|
150 |
|
|
151 |
// Print header |
|
152 |
if($display_previous_next_links == 'none') { |
|
153 |
echo str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array('','','','','','', $display_previous_next_links), $setting_header); |
|
154 |
} else { |
|
155 |
echo str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array($next_page_link, $next_link, $previous_page_link, $previous_link, $out_of, $of, $display_previous_next_links), $setting_header); |
|
156 |
} |
|
157 |
|
|
158 |
if($num_posts > 0) { |
|
159 |
if($query_extra != '') { |
|
160 |
?> |
|
161 |
<div class="selected_group_title"> |
|
162 |
<?php echo '<a href="'.$_SERVER['PHP_SELF'].'">'.PAGE_TITLE.'</a> >> '.$groups[$_GET['g']]['title']; ?> |
|
163 |
</div> |
|
164 |
<?php |
|
165 |
} |
|
166 |
while($post = $query_posts->fetchRow()) { |
|
167 |
if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active |
|
168 |
$uid = $post['posted_by']; // User who last modified the post |
|
169 |
// Workout date and time of last modified post |
|
170 |
$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE); |
|
171 |
$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE); |
|
172 |
// Work-out the post link |
|
173 |
$post_link = page_link($post['link']); |
|
174 |
if(isset($_GET['p']) AND $position > 0) { |
|
175 |
$post_link .= '?p='.$position; |
|
176 |
} |
|
177 |
if(isset($_GET['g']) AND is_numeric($_GET['g'])) { |
|
178 |
if(isset($_GET['p']) AND $position > 0) { $post_link .= '&'; } else { $post_link .= '?'; } |
|
179 |
$post_link .= 'g='.$_GET['g']; |
|
180 |
} |
|
181 |
// Get group id, title, and image |
|
182 |
$group_id = $post['group_id']; |
|
183 |
$group_title = $groups[$group_id]['title']; |
|
184 |
$group_image = $groups[$group_id]['image']; |
|
185 |
if($group_image == '') { $display_image = 'none'; } else { $display_image = ''; } |
|
186 |
if($group_id == 0) { $display_group = 'none'; } else { $display_group = ''; } |
|
187 |
// Replace [wblink--PAGE_ID--] with real link |
|
188 |
$short = stripslashes($post['short']); |
|
189 |
$pattern = '/\[wblink(.+?)\]/s'; |
|
190 |
preg_match_all($pattern,$short,$ids); |
|
191 |
foreach($ids[1] AS $page_id) { |
|
192 |
$pattern = '/\[wblink'.$page_id.'\]/s'; |
|
193 |
// Get page link |
|
194 |
$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1"); |
|
195 |
$fetch_link = $get_link->fetchRow(); |
|
196 |
$link = page_link($fetch_link['link']); |
|
197 |
$short = preg_replace($pattern,$link,$short); |
|
198 |
} |
|
199 |
// Replace vars with values |
|
200 |
$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[LINK]', '[DATE]', '[TIME]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]', '[TEXT_READ_MORE]'); |
|
201 |
if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') { |
|
202 |
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), $short, $post_link, $post_date, $post_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email'], $TEXT['READ_MORE']); |
|
203 |
} else { |
|
204 |
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), $short, $post_link, $post_date, $post_time, '', '', '', '', $TEXT['READ_MORE']); |
|
205 |
} |
|
206 |
echo str_replace($vars, $values, $setting_post_loop); |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
// Print footer |
|
212 |
if($display_previous_next_links == 'none') { |
|
213 |
echo str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array('','','','','','', $display_previous_next_links), $setting_footer); |
|
214 |
} else { |
|
215 |
echo str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array($next_page_link, $next_link, $previous_page_link, $previous_link, $out_of, $of, $display_previous_next_links), $setting_footer); |
|
216 |
} |
|
217 |
|
|
218 |
} elseif(defined('POST_ID') AND is_numeric(POST_ID)) { |
|
219 |
|
|
220 |
// Get settings |
|
221 |
$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'"); |
|
222 |
if($query_settings->numRows() > 0) { |
|
223 |
$fetch_settings = $query_settings->fetchRow(); |
|
224 |
$setting_post_header = stripslashes($fetch_settings['post_header']); |
|
225 |
$setting_post_footer = stripslashes($fetch_settings['post_footer']); |
|
226 |
$setting_comments_header = stripslashes($fetch_settings['comments_header']); |
|
227 |
$setting_comments_loop = stripslashes($fetch_settings['comments_loop']); |
|
228 |
$setting_comments_footer = stripslashes($fetch_settings['comments_footer']); |
|
229 |
} else { |
|
230 |
$setting_post_header = ''; |
|
231 |
$setting_post_footer = ''; |
|
232 |
$setting_comments_header = ''; |
|
233 |
$setting_comments_loop = ''; |
|
234 |
$setting_comments_footer = ''; |
|
235 |
} |
|
236 |
|
|
237 |
// Get page info |
|
238 |
$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '".PAGE_ID."'"); |
|
239 |
if($query_page->numRows() > 0) { |
|
240 |
$page = $query_page->fetchRow(); |
|
241 |
$page_link = page_link($page['link']); |
|
242 |
if(isset($_GET['p']) AND $position > 0) { |
|
243 |
$page_link .= '?p='.$_GET['p']; |
|
244 |
} |
|
245 |
if(isset($_GET['g']) AND is_numeric($_GET['g'])) { |
|
246 |
if(isset($_GET['p']) AND $position > 0) { $page_link .= '&'; } else { $page_link .= '?'; } |
|
247 |
$page_link .= 'g='.$_GET['g']; |
|
248 |
} |
|
249 |
} else { |
|
250 |
exit('Page not found'); |
|
251 |
} |
|
252 |
|
|
253 |
// Get post info |
|
254 |
$query_post = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '".POST_ID."' AND active = '1'"); |
|
255 |
if($query_post->numRows() > 0) { |
|
256 |
$post = $query_post->fetchRow(); |
|
257 |
if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active |
|
258 |
$uid = $post['posted_by']; // User who last modified the post |
|
259 |
// Workout date and time of last modified post |
|
260 |
$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE); |
|
261 |
$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE); |
|
262 |
// Get group id, title, and image |
|
263 |
$group_id = $post['group_id']; |
|
264 |
$group_title = $groups[$group_id]['title']; |
|
265 |
$group_image = $groups[$group_id]['image']; |
|
266 |
if($group_image == '') { $display_image = 'none'; } else { $display_image = ''; } |
|
267 |
if($group_id == 0) { $display_group = 'none'; } else { $display_group = ''; } |
|
268 |
$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[BACK]', '[DATE]', '[TIME]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]'); |
|
269 |
if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') { |
|
270 |
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), stripslashes($post['short']), $page_link, $post_date, $post_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email']); |
|
271 |
} else { |
|
272 |
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), stripslashes($post['short']), $page_link, $post_date, $post_time, '', '', '', ''); |
|
273 |
} |
|
274 |
$post_long = stripslashes($post['long']); |
|
275 |
} |
|
276 |
} else { |
|
277 |
header('Location: '.WB_URL.'/pages/'); |
|
278 |
} |
|
279 |
|
|
280 |
// Print post header |
|
281 |
echo str_replace($vars, $values, $setting_post_header); |
|
282 |
|
|
283 |
// Replace [wblink--PAGE_ID--] with real link |
|
284 |
$pattern = '/\[wblink(.+?)\]/s'; |
|
285 |
preg_match_all($pattern,$post_long,$ids); |
|
286 |
foreach($ids[1] AS $page_id) { |
|
287 |
$pattern = '/\[wblink'.$page_id.'\]/s'; |
|
288 |
// Get page link |
|
289 |
$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1"); |
|
290 |
$fetch_link = $get_link->fetchRow(); |
|
291 |
$link = page_link($fetch_link['link']); |
|
292 |
$post_long = preg_replace($pattern,$link,$post_long); |
|
293 |
} |
|
294 |
|
|
295 |
// Print long |
|
296 |
echo $post_long; |
|
297 |
|
|
298 |
// Print post footer |
|
299 |
echo str_replace($vars, $values, $setting_post_footer); |
|
300 |
|
|
301 |
// Show comments section if we have to |
|
302 |
if($post['commenting'] == 'private' AND isset($admin) AND $admin->is_authenticated() == true OR $post['commenting'] == 'public') { |
|
303 |
|
|
304 |
// Print comments header |
|
305 |
echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID, $setting_comments_header); |
|
306 |
|
|
307 |
// Query for comments |
|
308 |
$query_comments = $database->query("SELECT title,comment,commented_when,commented_by FROM ".TABLE_PREFIX."mod_news_comments WHERE post_id = '".POST_ID."' ORDER BY commented_when ASC"); |
|
309 |
if($query_comments->numRows() > 0) { |
|
310 |
while($comment = $query_comments->fetchRow()) { |
|
311 |
// Display Comments without slashes, but with new-line characters |
|
312 |
$comment['comment'] = nl2br(stripslashes($comment['comment'])); |
|
313 |
$comment['title'] = stripslashes($comment['title']); |
|
314 |
// Print comments loop |
|
315 |
$commented_date = gmdate(DATE_FORMAT, $comment['commented_when']+TIMEZONE); |
|
316 |
$commented_time = gmdate(TIME_FORMAT, $comment['commented_when']+TIMEZONE); |
|
317 |
$uid = $comment['commented_by']; |
|
318 |
$vars = array('[TITLE]','[COMMENT]','[DATE]','[TIME]','[USER_ID]','[USERNAME]','[DISPLAY_NAME]', '[EMAIL]'); |
|
319 |
if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') { |
|
320 |
$values = array(stripslashes($comment['title']), stripslashes($comment['comment']), $commented_date, $commented_time, $uid, stripslashes($users[$uid]['username']), stripslashes($users[$uid]['display_name']), stripslashes($users[$uid]['email'])); |
|
321 |
} else { |
|
322 |
$values = array(stripslashes($comment['title']), stripslashes($comment['comment']), $commented_date, $commented_time, '0', strtolower($TEXT['UNKNOWN']), $TEXT['UNKNOWN'], ''); |
|
323 |
} |
|
324 |
echo str_replace($vars, $values, $setting_comments_loop); |
|
325 |
} |
|
326 |
} else { |
|
327 |
// Say no comments found |
|
328 |
if(isset($TEXT['NONE_FOUND'])) { |
|
329 |
echo $TEXT['NONE_FOUND'].'<br />'; |
|
330 |
} else { |
|
331 |
echo 'None Found<br />'; |
|
332 |
} |
|
333 |
} |
|
334 |
|
|
335 |
// Print comments footer |
|
336 |
echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID, $setting_comments_footer); |
|
337 |
|
|
338 |
} |
|
339 |
|
|
340 |
} |
|
82 |
$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'"); |
|
83 |
if($query_settings->numRows() > 0) { |
|
84 |
$fetch_settings = $query_settings->fetchRow(); |
|
85 |
$setting_header = stripslashes($fetch_settings['header']); |
|
86 |
$setting_post_loop = stripslashes($fetch_settings['post_loop']); |
|
87 |
$setting_footer = stripslashes($fetch_settings['footer']); |
|
88 |
$setting_posts_per_page = $fetch_settings['posts_per_page']; |
|
89 |
} else { |
|
90 |
$setting_header = ''; |
|
91 |
$setting_post_loop = ''; |
|
92 |
$setting_footer = ''; |
|
93 |
$setting_posts_per_page = ''; |
|
94 |
} |
|
95 |
|
|
96 |
// Get total number of posts |
|
97 |
$query_total_num = $database->query("SELECT post_id FROM ".TABLE_PREFIX."mod_news_posts WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra"); |
|
98 |
$total_num = $query_total_num->numRows(); |
|
341 | 99 |
|
342 |
?> |
|
100 |
// Work-out if we need to add limit code to sql |
|
101 |
if($setting_posts_per_page != 0) { |
|
102 |
$limit_sql = " LIMIT $position,$setting_posts_per_page"; |
|
103 |
} else { |
|
104 |
$limit_sql = ""; |
|
105 |
} |
|
106 |
|
|
107 |
// Query posts (for this page) |
|
108 |
$query_posts = $database->query("SELECT group_id,post_id,title,link,short,posted_by,posted_when FROM ".TABLE_PREFIX."mod_news_posts WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra ORDER BY position DESC".$limit_sql); |
|
109 |
$num_posts = $query_posts->numRows(); |
|
110 |
|
|
111 |
// Create previous and next links |
|
112 |
if($setting_posts_per_page != 0) { |
|
113 |
if($position > 0) { |
|
114 |
if(isset($_GET['g']) AND is_numeric($_GET['g'])) { |
|
115 |
$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'&g='.$_GET['g'].'"><< '; |
|
116 |
} else { |
|
117 |
$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'"><< '; |
|
118 |
} |
|
119 |
$pl_append = '</a>'; |
|
120 |
$previous_link = $pl_prepend.$TEXT['PREVIOUS'].$pl_append; |
|
121 |
$previous_page_link = $pl_prepend.$TEXT['PREVIOUS_PAGE'].$pl_append; |
|
122 |
} else { |
|
123 |
$previous_link = ''; |
|
124 |
$previous_page_link = ''; |
|
125 |
} |
|
126 |
if($position+$setting_posts_per_page >= $total_num) { |
|
127 |
$next_link = ''; |
|
128 |
$next_page_link = ''; |
|
129 |
} else { |
|
130 |
if(isset($_GET['g']) AND is_numeric($_GET['g'])) { |
|
131 |
$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'&g='.$_GET['g'].'"> '; |
|
132 |
} else { |
|
133 |
$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'"> '; |
|
134 |
} |
|
135 |
$nl_append = ' >></a>'; |
|
136 |
$next_link = $nl_prepend.$TEXT['NEXT'].$nl_append; |
|
137 |
$next_page_link = $nl_prepend.$TEXT['NEXT_PAGE'].$nl_append; |
|
138 |
} |
|
139 |
if($position+$setting_posts_per_page > $total_num) { |
|
140 |
$num_of = $position+$num_posts; |
|
141 |
} else { |
|
142 |
$num_of = $position+$setting_posts_per_page; |
|
143 |
} |
|
144 |
$out_of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OUT_OF']).' '.$total_num; |
|
145 |
$of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OF']).' '.$total_num; |
|
146 |
$display_previous_next_links = ''; |
|
147 |
} else { |
|
148 |
$display_previous_next_links = 'none'; |
|
149 |
} |
|
150 |
|
|
151 |
// Print header |
|
152 |
if($display_previous_next_links == 'none') { |
|
153 |
echo str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array('','','','','','', $display_previous_next_links), $setting_header); |
|
154 |
} else { |
|
155 |
echo str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array($next_page_link, $next_link, $previous_page_link, $previous_link, $out_of, $of, $display_previous_next_links), $setting_header); |
|
156 |
} |
|
157 |
|
|
158 |
if($num_posts > 0) { |
|
159 |
if($query_extra != '') { |
|
160 |
?> |
|
161 |
<div class="selected_group_title"> |
|
162 |
<?php echo '<a href="'.$_SERVER['PHP_SELF'].'">'.PAGE_TITLE.'</a> >> '.$groups[$_GET['g']]['title']; ?> |
|
163 |
</div> |
|
164 |
<?php |
|
165 |
} |
|
166 |
while($post = $query_posts->fetchRow()) { |
|
167 |
if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active |
|
168 |
$uid = $post['posted_by']; // User who last modified the post |
|
169 |
// Workout date and time of last modified post |
|
170 |
$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE); |
|
171 |
$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE); |
|
172 |
// Work-out the post link |
|
173 |
$post_link = page_link($post['link']); |
|
174 |
if(isset($_GET['p']) AND $position > 0) { |
|
175 |
$post_link .= '?p='.$position; |
|
176 |
} |
|
177 |
if(isset($_GET['g']) AND is_numeric($_GET['g'])) { |
|
178 |
if(isset($_GET['p']) AND $position > 0) { $post_link .= '&'; } else { $post_link .= '?'; } |
|
179 |
$post_link .= 'g='.$_GET['g']; |
|
180 |
} |
|
181 |
// Get group id, title, and image |
|
182 |
$group_id = $post['group_id']; |
|
183 |
$group_title = $groups[$group_id]['title']; |
|
184 |
$group_image = $groups[$group_id]['image']; |
|
185 |
if($group_image == '') { $display_image = 'none'; } else { $display_image = ''; } |
|
186 |
if($group_id == 0) { $display_group = 'none'; } else { $display_group = ''; } |
|
187 |
// Replace [wblink--PAGE_ID--] with real link |
|
188 |
$short = stripslashes($post['short']); |
|
189 |
$this->preprocess($short); |
|
190 |
// Replace vars with values |
|
191 |
$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[LINK]', '[DATE]', '[TIME]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]', '[TEXT_READ_MORE]'); |
|
192 |
if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') { |
|
193 |
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), $short, $post_link, $post_date, $post_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email'], $TEXT['READ_MORE']); |
|
194 |
} else { |
|
195 |
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), $short, $post_link, $post_date, $post_time, '', '', '', '', $TEXT['READ_MORE']); |
|
196 |
} |
|
197 |
echo str_replace($vars, $values, $setting_post_loop); |
|
198 |
} |
|
199 |
} |
|
200 |
} |
|
201 |
|
|
202 |
// Print footer |
|
203 |
if($display_previous_next_links == 'none') { |
|
204 |
echo str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array('','','','','','', $display_previous_next_links), $setting_footer); |
|
205 |
} else { |
|
206 |
echo str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array($next_page_link, $next_link, $previous_page_link, $previous_link, $out_of, $of, $display_previous_next_links), $setting_footer); |
|
207 |
} |
|
208 |
|
|
209 |
} elseif(defined('POST_ID') AND is_numeric(POST_ID)) { |
|
210 |
|
|
211 |
// Get settings |
|
212 |
$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'"); |
|
213 |
if($query_settings->numRows() > 0) { |
|
214 |
$fetch_settings = $query_settings->fetchRow(); |
|
215 |
$setting_post_header = stripslashes($fetch_settings['post_header']); |
|
216 |
$setting_post_footer = stripslashes($fetch_settings['post_footer']); |
|
217 |
$setting_comments_header = stripslashes($fetch_settings['comments_header']); |
|
218 |
$setting_comments_loop = stripslashes($fetch_settings['comments_loop']); |
|
219 |
$setting_comments_footer = stripslashes($fetch_settings['comments_footer']); |
|
220 |
} else { |
|
221 |
$setting_post_header = ''; |
|
222 |
$setting_post_footer = ''; |
|
223 |
$setting_comments_header = ''; |
|
224 |
$setting_comments_loop = ''; |
|
225 |
$setting_comments_footer = ''; |
|
226 |
} |
|
227 |
|
|
228 |
// Get page info |
|
229 |
$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '".PAGE_ID."'"); |
|
230 |
if($query_page->numRows() > 0) { |
|
231 |
$page = $query_page->fetchRow(); |
|
232 |
$page_link = page_link($page['link']); |
|
233 |
if(isset($_GET['p']) AND $position > 0) { |
|
234 |
$page_link .= '?p='.$_GET['p']; |
|
235 |
} |
|
236 |
if(isset($_GET['g']) AND is_numeric($_GET['g'])) { |
|
237 |
if(isset($_GET['p']) AND $position > 0) { $page_link .= '&'; } else { $page_link .= '?'; } |
|
238 |
$page_link .= 'g='.$_GET['g']; |
|
239 |
} |
|
240 |
} else { |
|
241 |
exit('Page not found'); |
|
242 |
} |
|
243 |
|
|
244 |
// Get post info |
|
245 |
$query_post = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '".POST_ID."' AND active = '1'"); |
|
246 |
if($query_post->numRows() > 0) { |
|
247 |
$post = $query_post->fetchRow(); |
|
248 |
if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active |
|
249 |
$uid = $post['posted_by']; // User who last modified the post |
|
250 |
// Workout date and time of last modified post |
|
251 |
$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE); |
|
252 |
$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE); |
|
253 |
// Get group id, title, and image |
|
254 |
$group_id = $post['group_id']; |
|
255 |
$group_title = $groups[$group_id]['title']; |
|
256 |
$group_image = $groups[$group_id]['image']; |
|
257 |
if($group_image == '') { $display_image = 'none'; } else { $display_image = ''; } |
|
258 |
if($group_id == 0) { $display_group = 'none'; } else { $display_group = ''; } |
|
259 |
$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[BACK]', '[DATE]', '[TIME]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]'); |
|
260 |
if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') { |
|
261 |
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), stripslashes($post['short']), $page_link, $post_date, $post_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email']); |
|
262 |
} else { |
|
263 |
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), stripslashes($post['short']), $page_link, $post_date, $post_time, '', '', '', ''); |
|
264 |
} |
|
265 |
$post_long = stripslashes($post['long']); |
|
266 |
} |
|
267 |
} else { |
|
268 |
header('Location: '.WB_URL.'/pages/'); |
|
269 |
} |
|
270 |
|
|
271 |
// Print post header |
|
272 |
echo str_replace($vars, $values, $setting_post_header); |
|
273 |
|
|
274 |
// Replace [wblink--PAGE_ID--] with real link |
|
275 |
$this->preprocess($postlong); |
|
276 |
// Print long |
|
277 |
echo $post_long; |
|
278 |
|
|
279 |
// Print post footer |
|
280 |
echo str_replace($vars, $values, $setting_post_footer); |
|
281 |
|
|
282 |
// Show comments section if we have to |
|
283 |
if($post['commenting'] == 'private' AND isset($admin) AND $admin->is_authenticated() == true OR $post['commenting'] == 'public') { |
|
284 |
|
|
285 |
// Print comments header |
|
286 |
echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID, $setting_comments_header); |
|
287 |
|
|
288 |
// Query for comments |
|
289 |
$query_comments = $database->query("SELECT title,comment,commented_when,commented_by FROM ".TABLE_PREFIX."mod_news_comments WHERE post_id = '".POST_ID."' ORDER BY commented_when ASC"); |
|
290 |
if($query_comments->numRows() > 0) { |
|
291 |
while($comment = $query_comments->fetchRow()) { |
|
292 |
// Display Comments without slashes, but with new-line characters |
|
293 |
$comment['comment'] = nl2br(stripslashes($comment['comment'])); |
|
294 |
$comment['title'] = stripslashes($comment['title']); |
|
295 |
// Print comments loop |
|
296 |
$commented_date = gmdate(DATE_FORMAT, $comment['commented_when']+TIMEZONE); |
|
297 |
$commented_time = gmdate(TIME_FORMAT, $comment['commented_when']+TIMEZONE); |
|
298 |
$uid = $comment['commented_by']; |
|
299 |
$vars = array('[TITLE]','[COMMENT]','[DATE]','[TIME]','[USER_ID]','[USERNAME]','[DISPLAY_NAME]', '[EMAIL]'); |
|
300 |
if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') { |
|
301 |
$values = array(stripslashes($comment['title']), stripslashes($comment['comment']), $commented_date, $commented_time, $uid, stripslashes($users[$uid]['username']), stripslashes($users[$uid]['display_name']), stripslashes($users[$uid]['email'])); |
|
302 |
} else { |
|
303 |
$values = array(stripslashes($comment['title']), stripslashes($comment['comment']), $commented_date, $commented_time, '0', strtolower($TEXT['UNKNOWN']), $TEXT['UNKNOWN'], ''); |
|
304 |
} |
|
305 |
echo str_replace($vars, $values, $setting_comments_loop); |
|
306 |
} |
|
307 |
} else { |
|
308 |
// Say no comments found |
|
309 |
if(isset($TEXT['NONE_FOUND'])) { |
|
310 |
echo $TEXT['NONE_FOUND'].'<br />'; |
|
311 |
} else { |
|
312 |
echo 'None Found<br />'; |
|
313 |
} |
|
314 |
} |
|
315 |
|
|
316 |
// Print comments footer |
|
317 |
echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID, $setting_comments_footer); |
|
318 |
|
|
319 |
} |
|
320 |
|
|
321 |
} |
|
322 |
|
|
323 |
?> |
Also available in: Unified diff
Restructured frontend code and fixed various bugs