Project

General

Profile

1
<?php
2

    
3
// $Id: view.php 901 2009-01-04 12:09:27Z Ruebenwurzel $
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 module language file exists for the language set by the user (e.g. DE, EN)
37
if(!file_exists(WB_PATH .'/modules/news/languages/'.LANGUAGE .'.php')) {
38
	// no module language file exists for the language set by the user, include default module language file EN.php
39
	require_once(WB_PATH .'/modules/news/languages/EN.php');
40
} else {
41
	// a module language file exists for the language defined by the user, load it
42
	require_once(WB_PATH .'/modules/news/languages/'.LANGUAGE .'.php');
43
}
44

    
45
//overwrite php.ini on Apache servers for valid SESSION ID Separator
46
if(function_exists('ini_set')) {
47
	ini_set('arg_separator.output', '&amp;');
48
}
49

    
50
// Check if there is a start point defined
51
if(isset($_GET['p']) AND is_numeric($_GET['p']) AND $_GET['p'] >= 0) {
52
	$position = $_GET['p'];
53
} else {
54
	$position = 0;
55
}
56

    
57
// Get user's username, display name, email, and id - needed for insertion into post info
58
$users = array();
59
$query_users = $database->query("SELECT user_id,username,display_name,email FROM ".TABLE_PREFIX."users");
60
if($query_users->numRows() > 0) {
61
	while($user = $query_users->fetchRow()) {
62
		// Insert user info into users array
63
		$user_id = $user['user_id'];
64
		$users[$user_id]['username'] = $user['username'];
65
		$users[$user_id]['display_name'] = $user['display_name'];
66
		$users[$user_id]['email'] = $user['email'];
67
	}
68
}
69

    
70
// Get groups (title, if they are active, and their image [if one has been uploaded])
71
if (isset($groups)) {
72
   unset($groups);
73
}
74
$groups[0]['title'] = '';
75
$groups[0]['active'] = true;
76
$groups[0]['image'] = '';
77
$query_users = $database->query("SELECT group_id,title,active FROM ".TABLE_PREFIX."mod_news_groups WHERE section_id = '$section_id' ORDER BY position ASC");
78
if($query_users->numRows() > 0) {
79
	while($group = $query_users->fetchRow()) {
80
		// Insert user info into users array
81
		$group_id = $group['group_id'];
82
		$groups[$group_id]['title'] = ($group['title']);
83
		$groups[$group_id]['active'] = $group['active'];
84
		if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg')) {
85
			$groups[$group_id]['image'] = WB_URL.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg';
86
		} else {
87
			$groups[$group_id]['image'] = '';
88
		}
89
	}
90
}
91

    
92
// Check if we should show the main page or a post itself
93
if(!defined('POST_ID') OR !is_numeric(POST_ID)) {
94
	
95
	// Check if we should only list posts from a certain group
96
	if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
97
		$query_extra = " AND group_id = '".$_GET['g']."'";
98
	} else {
99
		$query_extra = '';
100
	}
101
	
102
	// Get settings
103
	$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'");
104
	if($query_settings->numRows() > 0) {
105
		$fetch_settings = $query_settings->fetchRow();
106
		$setting_header = ($fetch_settings['header']);
107
		$setting_post_loop = ($fetch_settings['post_loop']);
108
		$setting_footer = ($fetch_settings['footer']);
109
		$setting_posts_per_page = $fetch_settings['posts_per_page'];
110
	} else {
111
		$setting_header = '';
112
		$setting_post_loop = '';
113
		$setting_footer = '';
114
		$setting_posts_per_page = '';
115
	}
116
	
117
	$t = time();
118
	// Get total number of posts
119
	$query_total_num = $database->query("SELECT post_id FROM ".TABLE_PREFIX."mod_news_posts
120
		WHERE section_id = '$section_id' AND active = '1' AND title != '' $query_extra 
121
		AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)");
122
	$total_num = $query_total_num->numRows();
123

    
124
	// Work-out if we need to add limit code to sql
125
	if($setting_posts_per_page != 0) {
126
		$limit_sql = " LIMIT $position,$setting_posts_per_page";
127
	} else {
128
		$limit_sql = "";
129
	}
130
	
131
	// Query posts (for this page)
132
	$query_posts = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts
133
		WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra
134
		AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)
135
		ORDER BY position DESC".$limit_sql);
136
	$num_posts = $query_posts->numRows();
137
	
138
	// Create previous and next links
139
	if($setting_posts_per_page != 0) {
140
		if($position > 0) {
141
			if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
142
				$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'&amp;g='.$_GET['g'].'">&lt;&lt; ';
143
			} else {
144
				$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'">&lt;&lt; ';
145
			}
146
			$pl_append = '</a>';
147
			$previous_link = $pl_prepend.$TEXT['PREVIOUS'].$pl_append;
148
			$previous_page_link = $pl_prepend.$TEXT['PREVIOUS_PAGE'].$pl_append;
149
		} else {
150
			$previous_link = '';
151
			$previous_page_link = '';
152
		}
153
		if($position+$setting_posts_per_page >= $total_num) {
154
			$next_link = '';
155
			$next_page_link = '';
156
		} else {
157
			if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
158
				$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'&amp;g='.$_GET['g'].'"> ';
159
			} else {
160
				$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'"> ';
161
			}
162
			$nl_append = ' &gt;&gt;</a>';
163
			$next_link = $nl_prepend.$TEXT['NEXT'].$nl_append;
164
			$next_page_link = $nl_prepend.$TEXT['NEXT_PAGE'].$nl_append;
165
		}
166
		if($position+$setting_posts_per_page > $total_num) {
167
			$num_of = $position+$num_posts;
168
		} else {
169
			$num_of = $position+$setting_posts_per_page;
170
		}
171
		$out_of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OUT_OF']).' '.$total_num;
172
		$of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OF']).' '.$total_num;
173
		$display_previous_next_links = '';
174
	} else {
175
		$display_previous_next_links = 'none';
176
	}
177
		
178
	// Print header
179
	if($display_previous_next_links == 'none') {
180
		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);
181
	} else {
182
		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);
183
	}
184
	
185
	if($num_posts > 0) {
186
		if($query_extra != '') {
187
			?>
188
			<div class="selected_group_title">
189
				<?php echo '<a href="'.htmlspecialchars(strip_tags($_SERVER['PHP_SELF'])).'">'.PAGE_TITLE.'</a> &gt;&gt; '.$groups[$_GET['g']]['title']; ?>
190
			</div>
191
			<?php
192
		}
193
		while($post = $query_posts->fetchRow()) {
194
			if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active
195
				$uid = $post['posted_by']; // User who last modified the post
196
				// Workout date and time of last modified post
197
				$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE);
198
				$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE);
199
				$publ_date = date(DATE_FORMAT,$post['published_when']);
200
				$publ_time = date(TIME_FORMAT,$post['published_when']);
201
				// Work-out the post link
202
				$post_link = page_link($post['link']);
203
				if(isset($_GET['p']) AND $position > 0) {
204
					$post_link .= '?p='.$position;
205
				}
206
				if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
207
					if(isset($_GET['p']) AND $position > 0) { $post_link .= '&amp;'; } else { $post_link .= '?'; }
208
					$post_link .= 'g='.$_GET['g'];
209
				}
210
				// Get group id, title, and image
211
				$group_id = $post['group_id'];
212
				$group_title = $groups[$group_id]['title'];
213
				$group_image = $groups[$group_id]['image'];
214
				if($group_image == '') { $display_image = 'none'; } else { $display_image = ''; }
215
				if($group_id == 0) { $display_group = 'none'; } else { $display_group = ''; }
216
				// Replace [wblink--PAGE_ID--] with real link
217
				$short = ($post['content_short']);
218
				$wb->preprocess($short);
219
				// Replace vars with values
220
				$post_long_len = strlen($post['content_long']);
221
				$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[LINK]', '[MODI_DATE]', '[MODI_TIME]', '[PUBLISHED_DATE]', '[PUBLISHED_TIME]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]', '[TEXT_READ_MORE]');
222
				if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
223
					if($post_long_len < 9) {
224
						$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, $publ_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email'], '');
225
					} else {
226
						$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, $publ_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email'], $MOD_NEWS['TEXT_READ_MORE']);
227
					}
228
				} else {
229
					if($post_long_len < 9) {
230
						$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, $publ_time, '', '', '', '', '');
231
					} else {
232
						$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, $publ_time, '', '', '', '', $MOD_NEWS['TEXT_READ_MORE']);
233
					}
234
				}
235
				echo str_replace($vars, $values, $setting_post_loop);
236
			}
237
		}
238
	}
239
	
240
	// Print footer
241
	if($display_previous_next_links == 'none') {
242
		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);
243
	} else {
244
		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);
245
	}
246
	
247
} elseif(defined('POST_ID') AND is_numeric(POST_ID)) {
248
	
249
	// Get settings
250
	$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'");
251
	if($query_settings->numRows() > 0) {
252
		$fetch_settings = $query_settings->fetchRow();
253
		$setting_post_header = ($fetch_settings['post_header']);
254
		$setting_post_footer = ($fetch_settings['post_footer']);
255
		$setting_comments_header = ($fetch_settings['comments_header']);
256
		$setting_comments_loop = ($fetch_settings['comments_loop']);
257
		$setting_comments_footer = ($fetch_settings['comments_footer']);
258
	} else {
259
		$setting_post_header = '';
260
		$setting_post_footer = '';
261
		$setting_comments_header = '';
262
		$setting_comments_loop = '';
263
		$setting_comments_footer = '';
264
	}
265
	
266
	// Get page info
267
	$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '".PAGE_ID."'");
268
	if($query_page->numRows() > 0) {
269
		$page = $query_page->fetchRow();
270
		$page_link = page_link($page['link']);
271
		if(isset($_GET['p']) AND $position > 0) {
272
			$page_link .= '?p='.$_GET['p'];
273
		}
274
		if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
275
			if(isset($_GET['p']) AND $position > 0) { $page_link .= '&amp;'; } else { $page_link .= '?'; }
276
			$page_link .= 'g='.$_GET['g'];
277
		}
278
	} else {
279
		exit('Page not found');
280
	}
281
	
282
	// Get post info
283
	$t = time();
284
	$query_post = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts
285
		WHERE post_id = '".POST_ID."' AND active = '1'
286
		AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)
287
	");
288
	if($query_post->numRows() > 0) {
289
		$post = $query_post->fetchRow();
290
		if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active
291
			$uid = $post['posted_by']; // User who last modified the post
292
			// Workout date and time of last modified post
293
			$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE);
294
			$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE);
295
			$publ_date = date(DATE_FORMAT,$post['published_when']);
296
			$publ_time = date(TIME_FORMAT,$post['published_when']);
297
			// Get group id, title, and image
298
			$group_id = $post['group_id'];
299
			$group_title = $groups[$group_id]['title'];
300
			$group_image = $groups[$group_id]['image'];
301
			if($group_image == '') { $display_image = 'none'; } else { $display_image = ''; }
302
			if($group_id == 0) { $display_group = 'none'; } else { $display_group = ''; }
303
			$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]', '[PUBLISHED_DATE]', '[PUBLISHED_TIME]', '[TEXT_POSTED_BY]', '[TEXT_ON]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]');
304
			$post_short=$post['content_short'];
305
			$wb->preprocess($post_short);
306
			if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
307
				$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, $publ_date, $publ_time, $MOD_NEWS['TEXT_POSTED_BY'], $MOD_NEWS['TEXT_ON'], $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email']);
308
			} else {
309
				$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, $publ_date, $publ_time, $MOD_NEWS['TEXT_POSTED_BY'], $MOD_NEWS['TEXT_ON'], '', '', '', '');
310
			}
311
			$post_long = ($post['content_long']);
312
		}
313
	} else {
314
		$wb->print_error($MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'], "javascript: history.go(-1);", false);
315
		exit(0);
316
	}
317
	
318
	// Print post header
319
	echo str_replace($vars, $values, $setting_post_header);
320
	
321
	// Replace [wblink--PAGE_ID--] with real link
322
  	$wb->preprocess($post_long);
323
	// Print long
324
	echo $post_long;
325
	
326
	// Print post footer
327
	echo str_replace($vars, $values, $setting_post_footer);
328
	
329
	// Show comments section if we have to
330
	if(($post['commenting'] == 'private' AND isset($wb) AND $wb->is_authenticated() == true) OR $post['commenting'] == 'public') {
331
		
332
		// Print comments header
333
		$vars = array('[ADD_COMMENT_URL]','[TEXT_COMMENTS]');
334
		$values = array(WB_URL.'/modules/news/comment.php?id='.POST_ID.'&amp;sid='.$section_id, $MOD_NEWS['TEXT_COMMENTS']);
335
		echo str_replace($vars, $values, $setting_comments_header);
336
		
337
		// Query for comments
338
		$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");
339
		if($query_comments->numRows() > 0) {
340
			while($comment = $query_comments->fetchRow()) {
341
				// Display Comments without slashes, but with new-line characters
342
				$comment['comment'] = nl2br(($comment['comment']));
343
				$comment['title'] = ($comment['title']);
344
				// Print comments loop
345
				$commented_date = gmdate(DATE_FORMAT, $comment['commented_when']+TIMEZONE);
346
				$commented_time = gmdate(TIME_FORMAT, $comment['commented_when']+TIMEZONE);
347
				$uid = $comment['commented_by'];
348
				$vars = array('[TITLE]','[COMMENT]','[TEXT_ON]','[DATE]','[TEXT_AT]','[TIME]','[TEXT_BY]','[USER_ID]','[USERNAME]','[DISPLAY_NAME]', '[EMAIL]');
349
				if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
350
					$values = array(($comment['title']), ($comment['comment']), $MOD_NEWS['TEXT_ON'], $commented_date, $MOD_NEWS['TEXT_AT'], $commented_time, $MOD_NEWS['TEXT_BY'], $uid, ($users[$uid]['username']), ($users[$uid]['display_name']), ($users[$uid]['email']));
351
				} else {
352
					$values = array(($comment['title']), ($comment['comment']), $MOD_NEWS['TEXT_ON'], $commented_date, $MOD_NEWS['TEXT_AT'], $commented_time, $MOD_NEWS['TEXT_BY'], '0', strtolower($TEXT['UNKNOWN']), $TEXT['UNKNOWN'], '');
353
				}
354
				echo str_replace($vars, $values, $setting_comments_loop);
355
			}
356
		} else {
357
			// Say no comments found
358
			if(isset($TEXT['NONE_FOUND'])) {
359
				echo $TEXT['NONE_FOUND'].'<br />';
360
			} else {
361
				echo 'None Found<br />';
362
			}
363
		}
364
		
365
		// Print comments footer
366
		$vars = array('[ADD_COMMENT_URL]','[TEXT_ADD_COMMENT]');
367
		$values = array(WB_URL.'/modules/news/comment.php?id='.POST_ID.'&amp;sid='.$section_id, $MOD_NEWS['TEXT_ADD_COMMENT']);
368
		echo str_replace($vars, $values, $setting_comments_footer);
369
	}
370
	if(ENABLED_ASP) {
371
		$_SESSION['comes_from_view'] = POST_ID;
372
		$_SESSION['comes_from_view_time'] = time();
373
	}
374
}
375

    
376
?>
(30-30/30)