1
|
<?php
|
2
|
|
3
|
// $Id: view.php 656 2008-02-01 22:53:02Z thorn $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2008, 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
|
// Must include code to stop this file being access directly
|
27
|
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
|
28
|
|
29
|
// check if frontend.css file needs to be included into the <body></body> of view.php
|
30
|
if((!function_exists('register_frontend_modfiles') || !defined('MOD_FRONTEND_CSS_REGISTERED')) && file_exists(WB_PATH .'/modules/news/frontend.css')) {
|
31
|
echo '<style type="text/css">';
|
32
|
include(WB_PATH .'/modules/news/frontend.css');
|
33
|
echo "\n</style>\n";
|
34
|
}
|
35
|
|
36
|
// Check if there is a start point defined
|
37
|
if(isset($_GET['p']) AND is_numeric($_GET['p']) AND $_GET['p'] >= 0) {
|
38
|
$position = $_GET['p'];
|
39
|
} else {
|
40
|
$position = 0;
|
41
|
}
|
42
|
|
43
|
// Get user's username, display name, email, and id - needed for insertion into post info
|
44
|
$users = array();
|
45
|
$query_users = $database->query("SELECT user_id,username,display_name,email FROM ".TABLE_PREFIX."users");
|
46
|
if($query_users->numRows() > 0) {
|
47
|
while($user = $query_users->fetchRow()) {
|
48
|
// Insert user info into users array
|
49
|
$user_id = $user['user_id'];
|
50
|
$users[$user_id]['username'] = $user['username'];
|
51
|
$users[$user_id]['display_name'] = $user['display_name'];
|
52
|
$users[$user_id]['email'] = $user['email'];
|
53
|
}
|
54
|
}
|
55
|
|
56
|
// Get groups (title, if they are active, and their image [if one has been uploaded])
|
57
|
$groups[0]['title'] = '';
|
58
|
$groups[0]['active'] = true;
|
59
|
$groups[0]['image'] = '';
|
60
|
$query_users = $database->query("SELECT group_id,title,active FROM ".TABLE_PREFIX."mod_news_groups WHERE section_id = '$section_id' ORDER BY position ASC");
|
61
|
if($query_users->numRows() > 0) {
|
62
|
while($group = $query_users->fetchRow()) {
|
63
|
// Insert user info into users array
|
64
|
$group_id = $group['group_id'];
|
65
|
$groups[$group_id]['title'] = ($group['title']);
|
66
|
$groups[$group_id]['active'] = $group['active'];
|
67
|
if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg')) {
|
68
|
$groups[$group_id]['image'] = WB_URL.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg';
|
69
|
} else {
|
70
|
$groups[$group_id]['image'] = '';
|
71
|
}
|
72
|
}
|
73
|
}
|
74
|
|
75
|
// Check if we should show the main page or a post itself
|
76
|
if(!defined('POST_ID') OR !is_numeric(POST_ID)) {
|
77
|
|
78
|
// Check if we should only list posts from a certain group
|
79
|
if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
|
80
|
$query_extra = " AND group_id = '".$_GET['g']."'";
|
81
|
} else {
|
82
|
$query_extra = '';
|
83
|
}
|
84
|
|
85
|
// Get settings
|
86
|
$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'");
|
87
|
if($query_settings->numRows() > 0) {
|
88
|
$fetch_settings = $query_settings->fetchRow();
|
89
|
$setting_header = ($fetch_settings['header']);
|
90
|
$setting_post_loop = ($fetch_settings['post_loop']);
|
91
|
$setting_footer = ($fetch_settings['footer']);
|
92
|
$setting_posts_per_page = $fetch_settings['posts_per_page'];
|
93
|
} else {
|
94
|
$setting_header = '';
|
95
|
$setting_post_loop = '';
|
96
|
$setting_footer = '';
|
97
|
$setting_posts_per_page = '';
|
98
|
}
|
99
|
|
100
|
// Get total number of posts
|
101
|
$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");
|
102
|
$total_num = $query_total_num->numRows();
|
103
|
|
104
|
// Work-out if we need to add limit code to sql
|
105
|
if($setting_posts_per_page != 0) {
|
106
|
$limit_sql = " LIMIT $position,$setting_posts_per_page";
|
107
|
} else {
|
108
|
$limit_sql = "";
|
109
|
}
|
110
|
|
111
|
// Query posts (for this page)
|
112
|
$t = time();
|
113
|
$query_posts = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts
|
114
|
WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra
|
115
|
AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)
|
116
|
ORDER BY position DESC".$limit_sql);
|
117
|
$num_posts = $query_posts->numRows();
|
118
|
|
119
|
// Create previous and next links
|
120
|
if($setting_posts_per_page != 0) {
|
121
|
if($position > 0) {
|
122
|
if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
|
123
|
$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'&g='.$_GET['g'].'"><< ';
|
124
|
} else {
|
125
|
$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'"><< ';
|
126
|
}
|
127
|
$pl_append = '</a>';
|
128
|
$previous_link = $pl_prepend.$TEXT['PREVIOUS'].$pl_append;
|
129
|
$previous_page_link = $pl_prepend.$TEXT['PREVIOUS_PAGE'].$pl_append;
|
130
|
} else {
|
131
|
$previous_link = '';
|
132
|
$previous_page_link = '';
|
133
|
}
|
134
|
if($position+$setting_posts_per_page >= $total_num) {
|
135
|
$next_link = '';
|
136
|
$next_page_link = '';
|
137
|
} else {
|
138
|
if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
|
139
|
$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'&g='.$_GET['g'].'"> ';
|
140
|
} else {
|
141
|
$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'"> ';
|
142
|
}
|
143
|
$nl_append = ' >></a>';
|
144
|
$next_link = $nl_prepend.$TEXT['NEXT'].$nl_append;
|
145
|
$next_page_link = $nl_prepend.$TEXT['NEXT_PAGE'].$nl_append;
|
146
|
}
|
147
|
if($position+$setting_posts_per_page > $total_num) {
|
148
|
$num_of = $position+$num_posts;
|
149
|
} else {
|
150
|
$num_of = $position+$setting_posts_per_page;
|
151
|
}
|
152
|
$out_of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OUT_OF']).' '.$total_num;
|
153
|
$of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OF']).' '.$total_num;
|
154
|
$display_previous_next_links = '';
|
155
|
} else {
|
156
|
$display_previous_next_links = 'none';
|
157
|
}
|
158
|
|
159
|
// Print header
|
160
|
if($display_previous_next_links == 'none') {
|
161
|
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);
|
162
|
} else {
|
163
|
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);
|
164
|
}
|
165
|
|
166
|
if($num_posts > 0) {
|
167
|
if($query_extra != '') {
|
168
|
?>
|
169
|
<div class="selected_group_title">
|
170
|
<?php echo '<a href="'.htmlspecialchars(strip_tags($_SERVER['PHP_SELF'])).'">'.PAGE_TITLE.'</a> >> '.$groups[$_GET['g']]['title']; ?>
|
171
|
</div>
|
172
|
<?php
|
173
|
}
|
174
|
while($post = $query_posts->fetchRow()) {
|
175
|
if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active
|
176
|
$uid = $post['posted_by']; // User who last modified the post
|
177
|
// Workout date and time of last modified post
|
178
|
$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE);
|
179
|
$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE);
|
180
|
$publ_date = date(DATE_FORMAT,$post['published_when']);
|
181
|
// Work-out the post link
|
182
|
$post_link = page_link($post['link']);
|
183
|
if(isset($_GET['p']) AND $position > 0) {
|
184
|
$post_link .= '?p='.$position;
|
185
|
}
|
186
|
if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
|
187
|
if(isset($_GET['p']) AND $position > 0) { $post_link .= '&'; } else { $post_link .= '?'; }
|
188
|
$post_link .= 'g='.$_GET['g'];
|
189
|
}
|
190
|
// Get group id, title, and image
|
191
|
$group_id = $post['group_id'];
|
192
|
$group_title = $groups[$group_id]['title'];
|
193
|
$group_image = $groups[$group_id]['image'];
|
194
|
if($group_image == '') { $display_image = 'none'; } else { $display_image = ''; }
|
195
|
if($group_id == 0) { $display_group = 'none'; } else { $display_group = ''; }
|
196
|
// Replace [wblink--PAGE_ID--] with real link
|
197
|
$short = ($post['content_short']);
|
198
|
$wb->preprocess($short);
|
199
|
// Replace vars with values
|
200
|
$post_long_len = strlen($post['content_long']);
|
201
|
$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[LINK]', '[MODI_DATE]', '[MODI_TIME]', '[PUBLISHED_DATE]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]', '[TEXT_READ_MORE]');
|
202
|
if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
|
203
|
if($post_long_len < 9) {
|
204
|
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $short, $post_link, $post_date, $post_time, $publ_date, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email'], '');
|
205
|
} else {
|
206
|
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $short, $post_link, $post_date, $post_time, $publ_date, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email'], $TEXT['READ_MORE']);
|
207
|
}
|
208
|
} else {
|
209
|
if($post_long_len < 9) {
|
210
|
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $short, $post_link, $post_date, $post_time, $publ_date, '', '', '', '', '');
|
211
|
} else {
|
212
|
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $short, $post_link, $post_date, $post_time, $publ_date, '', '', '', '', $TEXT['READ_MORE']);
|
213
|
}
|
214
|
}
|
215
|
echo str_replace($vars, $values, $setting_post_loop);
|
216
|
}
|
217
|
}
|
218
|
}
|
219
|
|
220
|
// Print footer
|
221
|
if($display_previous_next_links == 'none') {
|
222
|
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);
|
223
|
} else {
|
224
|
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);
|
225
|
}
|
226
|
|
227
|
} elseif(defined('POST_ID') AND is_numeric(POST_ID)) {
|
228
|
|
229
|
// Get settings
|
230
|
$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'");
|
231
|
if($query_settings->numRows() > 0) {
|
232
|
$fetch_settings = $query_settings->fetchRow();
|
233
|
$setting_post_header = ($fetch_settings['post_header']);
|
234
|
$setting_post_footer = ($fetch_settings['post_footer']);
|
235
|
$setting_comments_header = ($fetch_settings['comments_header']);
|
236
|
$setting_comments_loop = ($fetch_settings['comments_loop']);
|
237
|
$setting_comments_footer = ($fetch_settings['comments_footer']);
|
238
|
} else {
|
239
|
$setting_post_header = '';
|
240
|
$setting_post_footer = '';
|
241
|
$setting_comments_header = '';
|
242
|
$setting_comments_loop = '';
|
243
|
$setting_comments_footer = '';
|
244
|
}
|
245
|
|
246
|
// Get page info
|
247
|
$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '".PAGE_ID."'");
|
248
|
if($query_page->numRows() > 0) {
|
249
|
$page = $query_page->fetchRow();
|
250
|
$page_link = page_link($page['link']);
|
251
|
if(isset($_GET['p']) AND $position > 0) {
|
252
|
$page_link .= '?p='.$_GET['p'];
|
253
|
}
|
254
|
if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
|
255
|
if(isset($_GET['p']) AND $position > 0) { $page_link .= '&'; } else { $page_link .= '?'; }
|
256
|
$page_link .= 'g='.$_GET['g'];
|
257
|
}
|
258
|
} else {
|
259
|
exit('Page not found');
|
260
|
}
|
261
|
|
262
|
// Get post info
|
263
|
$t = time();
|
264
|
$query_post = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts
|
265
|
WHERE post_id = '".POST_ID."' AND active = '1'
|
266
|
AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)
|
267
|
");
|
268
|
if($query_post->numRows() > 0) {
|
269
|
$post = $query_post->fetchRow();
|
270
|
if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active
|
271
|
$uid = $post['posted_by']; // User who last modified the post
|
272
|
// Workout date and time of last modified post
|
273
|
$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE);
|
274
|
$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE);
|
275
|
$publ_date = date(DATE_FORMAT,$post['published_when']);
|
276
|
// Get group id, title, and image
|
277
|
$group_id = $post['group_id'];
|
278
|
$group_title = $groups[$group_id]['title'];
|
279
|
$group_image = $groups[$group_id]['image'];
|
280
|
if($group_image == '') { $display_image = 'none'; } else { $display_image = ''; }
|
281
|
if($group_id == 0) { $display_group = 'none'; } else { $display_group = ''; }
|
282
|
$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[BACK]', '[MODI_DATE]', '[MODI_TIME]', '[PUBL_DATE]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]');
|
283
|
$post_short=$post['content_short'];
|
284
|
$wb->preprocess($post_short);
|
285
|
if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
|
286
|
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $post_short, $page_link, $post_date, $post_time, $publ_date, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email']);
|
287
|
} else {
|
288
|
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $post_short, $page_link, $post_date, $post_time, $publ_date, '', '', '', '');
|
289
|
}
|
290
|
$post_long = ($post['content_long']);
|
291
|
}
|
292
|
} else {
|
293
|
$wb->print_error($MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'], "javascript: history.go(-1);", false);
|
294
|
exit(0);
|
295
|
}
|
296
|
|
297
|
// Print post header
|
298
|
echo str_replace($vars, $values, $setting_post_header);
|
299
|
|
300
|
// Replace [wblink--PAGE_ID--] with real link
|
301
|
$wb->preprocess($post_long);
|
302
|
// Print long
|
303
|
echo $post_long;
|
304
|
|
305
|
// Print post footer
|
306
|
echo str_replace($vars, $values, $setting_post_footer);
|
307
|
|
308
|
// Show comments section if we have to
|
309
|
if(($post['commenting'] == 'private' AND isset($wb) AND $wb->is_authenticated() == true) OR $post['commenting'] == 'public') {
|
310
|
|
311
|
// Print comments header
|
312
|
echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID.'&sid='.$section_id, $setting_comments_header);
|
313
|
|
314
|
// Query for comments
|
315
|
$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");
|
316
|
if($query_comments->numRows() > 0) {
|
317
|
while($comment = $query_comments->fetchRow()) {
|
318
|
// Display Comments without slashes, but with new-line characters
|
319
|
$comment['comment'] = nl2br(($comment['comment']));
|
320
|
$comment['title'] = ($comment['title']);
|
321
|
// Print comments loop
|
322
|
$commented_date = gmdate(DATE_FORMAT, $comment['commented_when']+TIMEZONE);
|
323
|
$commented_time = gmdate(TIME_FORMAT, $comment['commented_when']+TIMEZONE);
|
324
|
$uid = $comment['commented_by'];
|
325
|
$vars = array('[TITLE]','[COMMENT]','[DATE]','[TIME]','[USER_ID]','[USERNAME]','[DISPLAY_NAME]', '[EMAIL]');
|
326
|
if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
|
327
|
$values = array(($comment['title']), ($comment['comment']), $commented_date, $commented_time, $uid, ($users[$uid]['username']), ($users[$uid]['display_name']), ($users[$uid]['email']));
|
328
|
} else {
|
329
|
$values = array(($comment['title']), ($comment['comment']), $commented_date, $commented_time, '0', strtolower($TEXT['UNKNOWN']), $TEXT['UNKNOWN'], '');
|
330
|
}
|
331
|
echo str_replace($vars, $values, $setting_comments_loop);
|
332
|
}
|
333
|
} else {
|
334
|
// Say no comments found
|
335
|
if(isset($TEXT['NONE_FOUND'])) {
|
336
|
echo $TEXT['NONE_FOUND'].'<br />';
|
337
|
} else {
|
338
|
echo 'None Found<br />';
|
339
|
}
|
340
|
}
|
341
|
|
342
|
// Print comments footer
|
343
|
echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID.'&sid='.$section_id, $setting_comments_footer);
|
344
|
}
|
345
|
if(ENABLED_ASP) {
|
346
|
$_SESSION['comes_from_view'] = POST_ID;
|
347
|
$_SESSION['comes_from_view_time'] = time();
|
348
|
}
|
349
|
}
|
350
|
|
351
|
?>
|