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