Project

General

Profile

1
<?php
2

    
3
// $Id: view.php 399 2006-12-24 07:50:44Z Ruebenwurzel $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2007, 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 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'] = ($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
	// 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 = ($fetch_settings['header']);
86
		$setting_post_loop = ($fetch_settings['post_loop']);
87
		$setting_footer = ($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 * 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 = ($post['content_short']);
189
				$wb->preprocess($short);
190
				// Replace vars with values
191
				$post_long_len = strlen($post['content_long']);
192
				$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]');
193
				if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
194
					if($post_long_len < 9) {
195
						$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $short, $post_link, $post_date, $post_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email'], '');
196
					} else {
197
						$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $short, $post_link, $post_date, $post_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email'], $TEXT['READ_MORE']);
198
					}
199
				} else {
200
					if($post_long_len < 9) {
201
						$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $short, $post_link, $post_date, $post_time, '', '', '', '', '');
202
					} else {
203
						$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $short, $post_link, $post_date, $post_time, '', '', '', '', $TEXT['READ_MORE']);
204
					}
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 = ($fetch_settings['post_header']);
225
		$setting_post_footer = ($fetch_settings['post_footer']);
226
		$setting_comments_header = ($fetch_settings['comments_header']);
227
		$setting_comments_loop = ($fetch_settings['comments_loop']);
228
		$setting_comments_footer = ($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
			$post_short=$post['content_short'];
270
			$wb->preprocess($post_short);
271
			if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
272
				$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $post_short, $page_link, $post_date, $post_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email']);
273
			} else {
274
				$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $post_short, $page_link, $post_date, $post_time, '', '', '', '');
275
			}
276
			$post_long = ($post['content_long']);
277
		}
278
	} else {
279
		header('Location: '.WB_URL.'/pages/');
280
		exit(0);
281
	}
282
	
283
	// Print post header
284
	echo str_replace($vars, $values, $setting_post_header);
285
	
286
	// Replace [wblink--PAGE_ID--] with real link
287
  	$wb->preprocess($post_long);
288
	// Print long
289
	echo $post_long;
290
	
291
	// Print post footer
292
	echo str_replace($vars, $values, $setting_post_footer);
293
	
294
	// Show comments section if we have to
295
	if($post['commenting'] == 'private' AND isset($admin) AND $admin->is_authenticated() == true OR $post['commenting'] == 'public') {
296
		
297
		// Print comments header
298
		echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID, $setting_comments_header);
299
		
300
		// Query for comments
301
		$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");
302
		if($query_comments->numRows() > 0) {
303
			while($comment = $query_comments->fetchRow()) {
304
				// Display Comments without slashes, but with new-line characters
305
				$comment['comment'] = nl2br(($comment['comment']));
306
				$comment['title'] = ($comment['title']);
307
				// Print comments loop
308
				$commented_date = gmdate(DATE_FORMAT, $comment['commented_when']+TIMEZONE);
309
				$commented_time = gmdate(TIME_FORMAT, $comment['commented_when']+TIMEZONE);
310
				$uid = $comment['commented_by'];
311
				$vars = array('[TITLE]','[COMMENT]','[DATE]','[TIME]','[USER_ID]','[USERNAME]','[DISPLAY_NAME]', '[EMAIL]');
312
				if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
313
					$values = array(($comment['title']), ($comment['comment']), $commented_date, $commented_time, $uid, ($users[$uid]['username']), ($users[$uid]['display_name']), ($users[$uid]['email']));
314
				} else {
315
					$values = array(($comment['title']), ($comment['comment']), $commented_date, $commented_time, '0', strtolower($TEXT['UNKNOWN']), $TEXT['UNKNOWN'], '');
316
				}
317
				echo str_replace($vars, $values, $setting_comments_loop);
318
			}
319
		} else {
320
			// Say no comments found
321
			if(isset($TEXT['NONE_FOUND'])) {
322
				echo $TEXT['NONE_FOUND'].'<br />';
323
			} else {
324
				echo 'None Found<br />';
325
			}
326
		}
327
		
328
		// Print comments footer
329
		echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID, $setting_comments_footer);
330
		
331
	}
332
		
333
}
334

    
335
?>
(27-27/27)