Revision 1457
Added by Dietmar over 13 years ago
view.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
/** |
3 | 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.
|
|
4 |
* @category WebsiteBaker
|
|
5 |
* @package modules
|
|
6 |
* @subpackage news
|
|
7 |
* @author Ryan Djurovich, Rob Smith, Werner v.d.Decken
|
|
8 |
* @copyright 2004-2011, Ryan Djurovich
|
|
9 | 9 |
* @link http://www.websitebaker2.org/ |
10 | 10 |
* @license http://www.gnu.org/licenses/gpl.html |
11 |
* @platform WebsiteBaker 2.8.x |
|
12 |
* @requirements PHP 5.2.2 and higher |
|
13 | 11 |
* @version $Id$ |
14 | 12 |
* @filesource $HeadURL$ |
15 |
* @lastmodified $Date$ |
|
16 | 13 |
* |
17 | 14 |
*/ |
18 | 15 |
|
19 | 16 |
// Must include code to stop this file being access directly |
20 | 17 |
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); } |
18 |
global $post_id, $post_section,$TEXT,$MESSAGE; |
|
21 | 19 |
|
22 | 20 |
// load module language file |
23 | 21 |
$lang = (dirname(__FILE__)) . '/languages/' . LANGUAGE . '.php'; |
... | ... | |
30 | 28 |
} |
31 | 29 |
|
32 | 30 |
// Check if there is a start point defined |
33 |
if(isset($_GET['p']) AND is_numeric($_GET['p']) AND $_GET['p'] >= 0) |
|
34 |
{ |
|
35 |
$position = $_GET['p']; |
|
36 |
} else { |
|
37 |
$position = 0; |
|
38 |
} |
|
39 |
|
|
31 |
$position = ( isset($_GET['p']) ? intval($_GET['p']) : 0); |
|
40 | 32 |
// Get user's username, display name, email, and id - needed for insertion into post info |
41 | 33 |
$users = array(); |
42 |
$query_users = $database->query("SELECT user_id,username,display_name,email FROM ".TABLE_PREFIX."users"); |
|
43 |
if($query_users->numRows() > 0) |
|
44 |
{ |
|
45 |
while( false != ($user = $query_users->fetchRow()) ) |
|
46 |
{ |
|
47 |
// Insert user info into users array |
|
48 |
$user_id = $user['user_id']; |
|
49 |
$users[$user_id]['username'] = $user['username']; |
|
50 |
$users[$user_id]['display_name'] = $user['display_name']; |
|
51 |
$users[$user_id]['email'] = $user['email']; |
|
34 |
$sql = 'SELECT `user_id`,`username`,`display_name`,`email` FROM `'.TABLE_PREFIX.'users`'; |
|
35 |
if( ($resUsers = $database->query($sql)) ) { |
|
36 |
while( $recUser = $resUsers->fetchRow() ) { |
|
37 |
$users[$recUser['user_id']] = $recUser; |
|
52 | 38 |
} |
53 | 39 |
} |
54 | 40 |
// Get groups (title, if they are active, and their image [if one has been uploaded]) |
... | ... | |
64 | 50 |
$query_users = $database->query("SELECT group_id,title,active FROM ".TABLE_PREFIX."mod_news_groups WHERE section_id = '$section_id' ORDER BY position ASC"); |
65 | 51 |
if($query_users->numRows() > 0) |
66 | 52 |
{ |
53 |
|
|
67 | 54 |
while( false != ($group = $query_users->fetchRow()) ) |
68 | 55 |
{ |
69 | 56 |
// Insert user info into users array |
... | ... | |
79 | 66 |
} |
80 | 67 |
} |
81 | 68 |
|
82 |
|
|
83 |
|
|
84 | 69 |
// Check if we should show the main page or a post itself |
85 |
if(!defined('POST_ID') OR !is_numeric(POST_ID)) |
|
70 |
// if(!defined('POST_ID') OR !is_numeric(POST_ID)) |
|
71 |
if(!isset($post_id) || !is_numeric($post_id)) |
|
86 | 72 |
{ |
87 | 73 |
|
88 | 74 |
// Check if we should only list posts from a certain group |
89 | 75 |
if(isset($_GET['g']) AND is_numeric($_GET['g'])) |
90 | 76 |
{ |
91 |
$query_extra = " AND group_id = '".$_GET['g']."'";
|
|
77 |
$query_extra = 'AND `group_id`='.(int)$_GET['g'].' ';
|
|
92 | 78 |
} else { |
93 | 79 |
$query_extra = ''; |
94 | 80 |
} |
... | ... | |
96 | 82 |
// Check if we should only list posts from a certain group |
97 | 83 |
if(isset($_GET['g']) AND is_numeric($_GET['g'])) |
98 | 84 |
{ |
99 |
$query_extra = " AND group_id = '".$_GET['g']."'";
|
|
85 |
$query_extra = 'AND `group_id`='.(int)$_GET['g'].' ';
|
|
100 | 86 |
} else { |
101 | 87 |
$query_extra = ''; |
102 | 88 |
} |
103 | 89 |
|
104 | 90 |
// Get settings |
105 |
$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'"); |
|
106 |
if($query_settings->numRows() > 0) |
|
107 |
{ |
|
108 |
$fetch_settings = $query_settings->fetchRow(); |
|
109 |
$setting_header = ($fetch_settings['header']); |
|
110 |
$setting_post_loop = ($fetch_settings['post_loop']); |
|
111 |
$setting_footer = ($fetch_settings['footer']); |
|
112 |
$setting_posts_per_page = $fetch_settings['posts_per_page']; |
|
113 |
} else { |
|
114 |
$setting_header = ''; |
|
115 |
$setting_post_loop = ''; |
|
116 |
$setting_footer = ''; |
|
117 |
$setting_posts_per_page = ''; |
|
91 |
$setting_header = $setting_post_loop = $setting_footer = $setting_posts_per_page = ''; |
|
92 |
$sql = 'SELECT `header`, `post_loop`, `footer`, `posts_per_page` '; |
|
93 |
$sql .= 'FROM `'.TABLE_PREFIX.'mod_news_settings` '; |
|
94 |
$sql .= 'WHERE `section_id`='.(int)$section_id; |
|
95 |
if( ($resSettings = $database->query($sql)) ){ |
|
96 |
if( ($recSettings = $resSettings->fetchRow()) ) { |
|
97 |
foreach($recSettings as $key=>$val){ |
|
98 |
${'setting_'.$key} = $val; |
|
99 |
} |
|
100 |
} |
|
118 | 101 |
} |
119 |
|
|
120 | 102 |
$t = time(); |
121 | 103 |
// Get total number of posts |
122 |
$query_total_num = $database->query("SELECT post_id, section_id FROM ".TABLE_PREFIX."mod_news_posts |
|
123 |
WHERE section_id = '$section_id' AND active = '1' AND title != '' $query_extra |
|
124 |
AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)"); |
|
125 |
$total_num = $query_total_num->numRows(); |
|
126 |
|
|
104 |
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'mod_news_posts` '; |
|
105 |
$sql .= 'WHERE `section_id`='.(int)$section_id.' AND `active`=1 '; |
|
106 |
$sql .= 'AND `title`!=\'\' '.$query_extra; |
|
107 |
$sql .= 'AND (`published_when`=0 OR `published_when`<='.$t.') '; |
|
108 |
$sql .= 'AND (`published_until`=0 OR `published_until`>='.$t.') '; |
|
109 |
$total_num = intval($database->get_one($sql)); |
|
127 | 110 |
// Work-out if we need to add limit code to sql |
128 | 111 |
if($setting_posts_per_page != 0) |
129 | 112 |
{ |
... | ... | |
222 | 205 |
if ($post['published_when'] === '0') $post['published_when'] = time(); |
223 | 206 |
if ($post['published_when'] > $post['posted_when']) |
224 | 207 |
{ |
225 |
$post_date = gmdate(DATE_FORMAT, $post['published_when']+TIMEZONE);
|
|
226 |
$post_time = gmdate(TIME_FORMAT, $post['published_when']+TIMEZONE);
|
|
208 |
$post_date = date(DATE_FORMAT, $post['published_when']+TIMEZONE); |
|
209 |
$post_time = date(TIME_FORMAT, $post['published_when']+TIMEZONE); |
|
227 | 210 |
} else { |
228 |
$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE);
|
|
229 |
$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE);
|
|
211 |
$post_date = date(DATE_FORMAT, $post['posted_when']+TIMEZONE); |
|
212 |
$post_time = date(TIME_FORMAT, $post['posted_when']+TIMEZONE); |
|
230 | 213 |
} |
231 | 214 |
|
232 | 215 |
$publ_date = date(DATE_FORMAT,$post['published_when']); |
... | ... | |
236 | 219 |
$post_link = page_link($post['link']); |
237 | 220 |
|
238 | 221 |
$post_link_path = str_replace(WB_URL, WB_PATH,$post_link); |
239 |
if(file_exists($post_link_path)) |
|
240 |
{ |
|
241 |
$create_date = date(DATE_FORMAT, filemtime ( $post_link_path )); |
|
242 |
$create_time = date(TIME_FORMAT, filemtime ( $post_link_path )); |
|
243 |
} else { |
|
244 |
$create_date = $publ_date; |
|
245 |
$create_time = $publ_time; |
|
246 |
} |
|
222 |
$create_date = date(DATE_FORMAT, $post['created_when']); |
|
223 |
$create_time = date(TIME_FORMAT, $post['created_when']); |
|
247 | 224 |
|
248 | 225 |
if(isset($_GET['p']) AND $position > 0) |
249 | 226 |
{ |
... | ... | |
268 | 245 |
|
269 | 246 |
// Replace [wblink--PAGE_ID--] with real link |
270 | 247 |
$short = ($post['content_short']); |
271 |
$wb->preprocess($short); |
|
272 |
|
|
273 | 248 |
// Replace vars with values |
274 | 249 |
$post_long_len = strlen($post['content_long']); |
275 | 250 |
$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[LINK]', '[MODI_DATE]', '[MODI_TIME]', '[CREATED_DATE]', '[CREATED_TIME]', '[PUBLISHED_DATE]', '[PUBLISHED_TIME]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]', '[TEXT_READ_MORE]','[SHOW_READ_MORE]'); |
... | ... | |
304 | 279 |
} |
305 | 280 |
|
306 | 281 |
} |
307 |
elseif(defined('POST_ID') AND is_numeric(POST_ID)) |
|
282 |
//elseif(defined('POST_ID') AND is_numeric(POST_ID)) |
|
283 |
elseif(isset($post_id) && is_numeric($post_id)) |
|
308 | 284 |
{ |
309 | 285 |
|
310 | 286 |
// print '<h2>'.POST_ID.'/'.PAGE_ID.'/'.POST_SECTION.'</h2>'; |
311 |
if(defined('POST_SECTION') AND POST_SECTION == $section_id) |
|
287 |
// if(defined('POST_SECTION') AND POST_SECTION == $section_id) |
|
288 |
if(isset($post_section) && ($post_section == $section_id)) |
|
312 | 289 |
{ |
313 | 290 |
// Get settings |
314 |
$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'"); |
|
315 |
if($query_settings->numRows() > 0) |
|
316 |
{ |
|
317 |
$fetch_settings = $query_settings->fetchRow(); |
|
318 |
$setting_post_header = ($fetch_settings['post_header']); |
|
319 |
$setting_post_footer = ($fetch_settings['post_footer']); |
|
320 |
$setting_comments_header = ($fetch_settings['comments_header']); |
|
321 |
$setting_comments_loop = ($fetch_settings['comments_loop']); |
|
322 |
$setting_comments_footer = ($fetch_settings['comments_footer']); |
|
323 |
} else { |
|
324 |
$setting_post_header = ''; |
|
325 |
$setting_post_footer = ''; |
|
326 |
$setting_comments_header = ''; |
|
327 |
$setting_comments_loop = ''; |
|
328 |
$setting_comments_footer = ''; |
|
329 |
} |
|
291 |
$setting_post_header = $setting_post_footer = $setting_comments_header |
|
292 |
= $setting_comments_loop = $setting_comments_footer = ''; |
|
293 |
$sql = 'SELECT `post_header`, `post_footer`, `comments_header`, `comments_loop`, `comments_footer` '; |
|
294 |
$sql .= 'FROM `'.TABLE_PREFIX.'mod_news_settings` '; |
|
295 |
$sql .= 'WHERE `section_id`='.(int)$section_id; |
|
296 |
if( ($resSettings = $database->query($sql)) ){ |
|
297 |
if( ($recSettings = $resSettings->fetchRow()) ) { |
|
298 |
foreach($recSettings as $key=>$val){ |
|
299 |
${'setting_'.$key} = $val; |
|
300 |
} |
|
301 |
} |
|
302 |
} |
|
330 | 303 |
// Get page info |
331 | 304 |
$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '".PAGE_ID."'"); |
332 | 305 |
if($query_page->numRows() > 0) |
... | ... | |
349 | 322 |
// Get post info |
350 | 323 |
$t = time(); |
351 | 324 |
$query_post = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts |
352 |
WHERE post_id = '".POST_ID."' AND active = '1'
|
|
325 |
WHERE post_id = '".$post_id."' AND active = '1'
|
|
353 | 326 |
AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)"); |
354 | 327 |
|
355 | 328 |
if($query_post->numRows() > 0) |
... | ... | |
362 | 335 |
if ($post['published_when'] === '0') $post['published_when'] = time(); |
363 | 336 |
if ($post['published_when'] > $post['posted_when']) |
364 | 337 |
{ |
365 |
$post_date = gmdate(DATE_FORMAT, $post['published_when']+TIMEZONE);
|
|
366 |
$post_time = gmdate(TIME_FORMAT, $post['published_when']+TIMEZONE);
|
|
338 |
$post_date = date(DATE_FORMAT, $post['published_when']+TIMEZONE); |
|
339 |
$post_time = date(TIME_FORMAT, $post['published_when']+TIMEZONE); |
|
367 | 340 |
} |
368 | 341 |
else |
369 | 342 |
{ |
370 |
$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE);
|
|
371 |
$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE);
|
|
343 |
$post_date = date(DATE_FORMAT, $post['posted_when']+TIMEZONE); |
|
344 |
$post_time = date(TIME_FORMAT, $post['posted_when']+TIMEZONE); |
|
372 | 345 |
} |
373 | 346 |
|
374 | 347 |
$publ_date = date(DATE_FORMAT,$post['published_when']); |
375 | 348 |
$publ_time = date(TIME_FORMAT,$post['published_when']); |
376 | 349 |
|
377 |
// Work-out the post link
|
|
378 |
$post_link = page_link($post['link']);
|
|
350 |
// Work-out the post link |
|
351 |
$post_link = page_link($post['link']); |
|
379 | 352 |
|
380 |
$post_link_path = str_replace(WB_URL, WB_PATH,$post_link); |
|
381 |
if(file_exists($post_link_path)) |
|
382 |
{ |
|
383 |
$create_date = date(DATE_FORMAT, filemtime ( $post_link_path )); |
|
384 |
$create_time = date(TIME_FORMAT, filemtime ( $post_link_path )); |
|
385 |
} else { |
|
386 |
$create_date = $publ_date; |
|
387 |
$create_time = $publ_time; |
|
388 |
} |
|
353 |
$post_link_path = str_replace(WB_URL, WB_PATH,$post_link); |
|
354 |
$create_date = date(DATE_FORMAT, $post['created_when']); |
|
355 |
$create_time = date(TIME_FORMAT, $post['created_when']); |
|
389 | 356 |
// Get group id, title, and image |
390 | 357 |
$group_id = $post['group_id']; |
391 | 358 |
$group_title = $groups[$group_id]['title']; |
... | ... | |
397 | 364 |
|
398 | 365 |
$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[BACK]', '[TEXT_BACK]', '[TEXT_LAST_CHANGED]', '[MODI_DATE]', '[TEXT_AT]', '[MODI_TIME]', '[CREATED_DATE]', '[CREATED_TIME]', '[PUBLISHED_DATE]', '[PUBLISHED_TIME]', '[TEXT_POSTED_BY]', '[TEXT_ON]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]'); |
399 | 366 |
$post_short=$post['content_short']; |
400 |
$wb->preprocess($post_short); |
|
401 | 367 |
if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') |
402 | 368 |
{ |
403 | 369 |
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $post_short, $page_link, $MOD_NEWS['TEXT_BACK'], $MOD_NEWS['TEXT_LAST_CHANGED'],$post_date, $MOD_NEWS['TEXT_AT'], $post_time, $create_date, $create_time, $publ_date, $publ_time, $MOD_NEWS['TEXT_POSTED_BY'], $MOD_NEWS['TEXT_ON'], $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email']); |
404 | 370 |
} else { |
405 | 371 |
$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $post_short, $page_link, $MOD_NEWS['TEXT_BACK'], $MOD_NEWS['TEXT_LAST_CHANGED'], $post_date, $MOD_NEWS['TEXT_AT'], $post_time, $create_date, $create_time, $publ_date, $publ_time, $MOD_NEWS['TEXT_POSTED_BY'], $MOD_NEWS['TEXT_ON'], '', '', '', ''); |
406 | 372 |
} |
407 |
|
|
408 |
$post_long = ($post['content_long']);
|
|
373 |
// $post_long = ($post['content_long']); |
|
374 |
$post_long = ($post['content_long'] != '') ? $post['content_long'] : $post['content_short'];
|
|
409 | 375 |
} |
410 | 376 |
} else { |
411 | 377 |
$wb->print_error($MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'], 'view.php', false); |
... | ... | |
414 | 380 |
|
415 | 381 |
// Print post header |
416 | 382 |
print str_replace($vars, $values, $setting_post_header); |
417 |
|
|
418 |
// Replace [wblink--PAGE_ID--] with real link |
|
419 |
$wb->preprocess($post_long); |
|
420 | 383 |
// Print long |
421 | 384 |
print $post_long; |
422 | 385 |
|
... | ... | |
429 | 392 |
// Print comments header |
430 | 393 |
$vars = array('[ADD_COMMENT_URL]','[TEXT_COMMENTS]'); |
431 | 394 |
// $pid = $admin->getIDKEY(POST_ID); |
432 |
$values = array(WB_URL.'/modules/news/comment.php?post_id='.POST_ID.'&section_id='.$section_id, $MOD_NEWS['TEXT_COMMENTS']);
|
|
395 |
$values = array(WB_URL.'/modules/news/comment.php?post_id='.$post_id.'&section_id='.$section_id, $MOD_NEWS['TEXT_COMMENTS']);
|
|
433 | 396 |
print str_replace($vars, $values, $setting_comments_header); |
434 | 397 |
|
435 | 398 |
// Query for comments |
436 |
$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");
|
|
399 |
$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");
|
|
437 | 400 |
if($query_comments->numRows() > 0) |
438 | 401 |
{ |
439 | 402 |
while( false != ($comment = $query_comments->fetchRow()) ) |
... | ... | |
442 | 405 |
$comment['comment'] = nl2br($wb->strip_slashes($comment['comment'])); |
443 | 406 |
$comment['title'] = $wb->strip_slashes($comment['title']); |
444 | 407 |
// Print comments loop |
445 |
$commented_date = gmdate(DATE_FORMAT, $comment['commented_when']+TIMEZONE);
|
|
446 |
$commented_time = gmdate(TIME_FORMAT, $comment['commented_when']+TIMEZONE);
|
|
408 |
$commented_date = date(DATE_FORMAT, $comment['commented_when']+TIMEZONE); |
|
409 |
$commented_time = date(TIME_FORMAT, $comment['commented_when']+TIMEZONE); |
|
447 | 410 |
$uid = $comment['commented_by']; |
448 | 411 |
$vars = array('[TITLE]','[COMMENT]','[TEXT_ON]','[DATE]','[TEXT_AT]','[TIME]','[TEXT_BY]','[USER_ID]','[USERNAME]','[DISPLAY_NAME]', '[EMAIL]'); |
449 | 412 |
if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') |
... | ... | |
467 | 430 |
|
468 | 431 |
// Print comments footer |
469 | 432 |
$vars = array('[ADD_COMMENT_URL]','[TEXT_ADD_COMMENT]'); |
470 |
$values = array(WB_URL.'/modules/news/comment.php?post_id='.POST_ID.'&section_id='.$section_id, $MOD_NEWS['TEXT_ADD_COMMENT']);
|
|
433 |
$values = array(WB_URL.'/modules/news/comment.php?post_id='.$post_id.'&section_id='.$section_id, $MOD_NEWS['TEXT_ADD_COMMENT']);
|
|
471 | 434 |
print str_replace($vars, $values, $setting_comments_footer); |
472 | 435 |
|
473 | 436 |
} |
... | ... | |
476 | 439 |
|
477 | 440 |
if(ENABLED_ASP) |
478 | 441 |
{ |
479 |
$_SESSION['comes_from_view'] = POST_ID;
|
|
442 |
$_SESSION['comes_from_view'] = $post_id;
|
|
480 | 443 |
$_SESSION['comes_from_view_time'] = time(); |
481 | 444 |
} |
482 | 445 |
|
483 | 446 |
} |
484 |
?> |
|
485 | 447 |
Also available in: Unified diff
Preparing 2.8.2 stable, last tests