| 1 | <?php
 | 
  
    | 2 | /**
 | 
  
    | 3 |  *
 | 
  
    | 4 |  * @category        modules
 | 
  
    | 5 |  * @package         news
 | 
  
    | 6 |  * @author          WebsiteBaker Project
 | 
  
    | 7 |  * @copyright       2009-2011, Website Baker Org. e.V.
 | 
  
    | 8 |  * @link			http://www.websitebaker2.org/
 | 
  
    | 9 |  * @license         http://www.gnu.org/licenses/gpl.html
 | 
  
    | 10 |  * @platform        WebsiteBaker 2.8.x
 | 
  
    | 11 |  * @requirements    PHP 5.2.2 and higher
 | 
  
    | 12 |  * @version         $Id: view.php 1538 2011-12-10 15:06:15Z Luisehahne $
 | 
  
    | 13 |  * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/view.php $
 | 
  
    | 14 |  * @lastmodified    $Date: 2011-12-10 16:06:15 +0100 (Sat, 10 Dec 2011) $
 | 
  
    | 15 |  *
 | 
  
    | 16 |  */
 | 
  
    | 17 | 
 | 
  
    | 18 | // Must include code to stop this file being access directly
 | 
  
    | 19 | /* -------------------------------------------------------- */
 | 
  
    | 20 | if(defined('WB_PATH') == false)
 | 
  
    | 21 | {
 | 
  
    | 22 | 	// Stop this file being access directly
 | 
  
    | 23 | 		die('<head><title>Access denied</title></head><body><h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2></body></html>');
 | 
  
    | 24 | }
 | 
  
    | 25 | /* -------------------------------------------------------- */
 | 
  
    | 26 | global $post_id, $post_section,$TEXT,$MESSAGE;
 | 
  
    | 27 | 
 | 
  
    | 28 | // load module language file
 | 
  
    | 29 | $lang = (dirname(__FILE__)) . '/languages/' . LANGUAGE . '.php';
 | 
  
    | 30 | require_once(!file_exists($lang) ? (dirname(__FILE__)) . '/languages/EN.php' : $lang );
 | 
  
    | 31 | 
 | 
  
    | 32 | //overwrite php.ini on Apache servers for valid SESSION ID Separator
 | 
  
    | 33 | if(function_exists('ini_set'))
 | 
  
    | 34 | {
 | 
  
    | 35 | 	ini_set('arg_separator.output', '&');
 | 
  
    | 36 | }
 | 
  
    | 37 | 
 | 
  
    | 38 | // Check if there is a start point defined
 | 
  
    | 39 | $position = ( isset($_GET['p']) ? intval($_GET['p']) : 0);
 | 
  
    | 40 | // Get user's username, display name, email, and id - needed for insertion into post info
 | 
  
    | 41 | $users = array();
 | 
  
    | 42 | $sql = 'SELECT `user_id`,`username`,`display_name`,`email` FROM `'.TABLE_PREFIX.'users`';
 | 
  
    | 43 | if( ($resUsers = $database->query($sql)) ) {
 | 
  
    | 44 | 	while( $recUser = $resUsers->fetchRow() ) {
 | 
  
    | 45 | 		$users[$recUser['user_id']] = $recUser;
 | 
  
    | 46 | 	}
 | 
  
    | 47 | }
 | 
  
    | 48 | // Get groups (title, if they are active, and their image [if one has been uploaded])
 | 
  
    | 49 | if (isset($groups))
 | 
  
    | 50 | {
 | 
  
    | 51 |    unset($groups);
 | 
  
    | 52 | }
 | 
  
    | 53 | 
 | 
  
    | 54 | $groups[0]['title'] = '';
 | 
  
    | 55 | $groups[0]['active'] = true;
 | 
  
    | 56 | $groups[0]['image'] = '';
 | 
  
    | 57 | 
 | 
  
    | 58 | $query_users = $database->query("SELECT group_id,title,active FROM ".TABLE_PREFIX."mod_news_groups WHERE section_id = '$section_id' ORDER BY position ASC");
 | 
  
    | 59 | if($query_users->numRows() > 0)
 | 
  
    | 60 | {
 | 
  
    | 61 | 
 | 
  
    | 62 | 	while( false != ($group = $query_users->fetchRow()) )
 | 
  
    | 63 |     {
 | 
  
    | 64 | 		// Insert user info into users array
 | 
  
    | 65 | 		$group_id = $group['group_id'];
 | 
  
    | 66 | 		$groups[$group_id]['title'] = ($group['title']);
 | 
  
    | 67 | 		$groups[$group_id]['active'] = $group['active'];
 | 
  
    | 68 | 		if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg'))
 | 
  
    | 69 |         {
 | 
  
    | 70 | 			$groups[$group_id]['image'] = WB_URL.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg';
 | 
  
    | 71 | 		} else {
 | 
  
    | 72 | 			$groups[$group_id]['image'] = '';
 | 
  
    | 73 | 		}
 | 
  
    | 74 | 	}
 | 
  
    | 75 | }
 | 
  
    | 76 | 
 | 
  
    | 77 | // Check if we should show the main page or a post itself
 | 
  
    | 78 | // if(!defined('POST_ID') OR !is_numeric(POST_ID))
 | 
  
    | 79 | if(!isset($post_id) || !is_numeric($post_id))
 | 
  
    | 80 | {
 | 
  
    | 81 | 
 | 
  
    | 82 | 	// Check if we should only list posts from a certain group
 | 
  
    | 83 | 	if(isset($_GET['g']) AND is_numeric($_GET['g']))
 | 
  
    | 84 |     {
 | 
  
    | 85 | 		$query_extra = 'AND `group_id`='.(int)$_GET['g'].' ';
 | 
  
    | 86 | 	} else {
 | 
  
    | 87 | 		$query_extra = '';
 | 
  
    | 88 | 	}
 | 
  
    | 89 | 
 | 
  
    | 90 | 	// Check if we should only list posts from a certain group
 | 
  
    | 91 | 	if(isset($_GET['g']) AND is_numeric($_GET['g']))
 | 
  
    | 92 |     {
 | 
  
    | 93 | 		$query_extra = 'AND `group_id`='.(int)$_GET['g'].' ';
 | 
  
    | 94 | 	} else {
 | 
  
    | 95 | 		$query_extra = '';
 | 
  
    | 96 | 	}
 | 
  
    | 97 | 
 | 
  
    | 98 | 	// Get settings
 | 
  
    | 99 | 	$setting_header = $setting_post_loop = $setting_footer = $setting_posts_per_page = '';
 | 
  
    | 100 | 	$sql  = 'SELECT `header`, `post_loop`, `footer`, `posts_per_page` ';
 | 
  
    | 101 | 	$sql .= 'FROM `'.TABLE_PREFIX.'mod_news_settings` ';
 | 
  
    | 102 | 	$sql .= 'WHERE `section_id`='.(int)$section_id;
 | 
  
    | 103 | 	if( ($resSettings = $database->query($sql)) ){
 | 
  
    | 104 | 		if( ($recSettings = $resSettings->fetchRow()) ) {
 | 
  
    | 105 | 			foreach($recSettings as $key=>$val){
 | 
  
    | 106 | 				${'setting_'.$key} = $val;
 | 
  
    | 107 | 			}
 | 
  
    | 108 | 		}
 | 
  
    | 109 | 	}
 | 
  
    | 110 | 	$t = time();
 | 
  
    | 111 | 	// Get total number of posts
 | 
  
    | 112 | 	$sql  = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'mod_news_posts` ';
 | 
  
    | 113 | 	$sql .= 'WHERE `section_id`='.(int)$section_id.' AND `active`=1 ';
 | 
  
    | 114 | 	$sql .=        'AND `title`!=\'\' '.$query_extra;
 | 
  
    | 115 | 	$sql .=        'AND (`published_when`=0 OR `published_when`<='.$t.') ';
 | 
  
    | 116 | 	$sql .=        'AND (`published_until`=0 OR `published_until`>='.$t.') ';
 | 
  
    | 117 | 	$total_num = intval($database->get_one($sql));
 | 
  
    | 118 | 	// Work-out if we need to add limit code to sql
 | 
  
    | 119 | 	if($setting_posts_per_page != 0)
 | 
  
    | 120 |     {
 | 
  
    | 121 | 		$limit_sql = " LIMIT $position, $setting_posts_per_page";
 | 
  
    | 122 | 	} else {
 | 
  
    | 123 | 		$limit_sql = "";
 | 
  
    | 124 | 	}
 | 
  
    | 125 | 
 | 
  
    | 126 | 	// Query posts (for this page)
 | 
  
    | 127 | 	$query_posts = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts
 | 
  
    | 128 | 		WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra
 | 
  
    | 129 | 		AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)
 | 
  
    | 130 | 		ORDER BY position DESC".$limit_sql);
 | 
  
    | 131 | 	$num_posts = $query_posts->numRows();
 | 
  
    | 132 | 
 | 
  
    | 133 | 	// Create previous and next links
 | 
  
    | 134 | 	if($setting_posts_per_page != 0)
 | 
  
    | 135 |     {
 | 
  
    | 136 | 		if($position > 0)
 | 
  
    | 137 |         {
 | 
  
    | 138 | 			if(isset($_GET['g']) AND is_numeric($_GET['g']))
 | 
  
    | 139 |             {
 | 
  
    | 140 | 				$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'&g='.$_GET['g'].'"><< ';
 | 
  
    | 141 | 			} else {
 | 
  
    | 142 | 				$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'"><< ';
 | 
  
    | 143 | 			}
 | 
  
    | 144 | 			$pl_append = '</a>';
 | 
  
    | 145 | 			$previous_link = $pl_prepend.$TEXT['PREVIOUS'].$pl_append;
 | 
  
    | 146 | 			$previous_page_link = $pl_prepend.$TEXT['PREVIOUS_PAGE'].$pl_append;
 | 
  
    | 147 | 		} else {
 | 
  
    | 148 | 			$previous_link = '';
 | 
  
    | 149 | 			$previous_page_link = '';
 | 
  
    | 150 | 		}
 | 
  
    | 151 | 		if($position + $setting_posts_per_page >= $total_num)
 | 
  
    | 152 |         {
 | 
  
    | 153 | 			$next_link = '';
 | 
  
    | 154 | 			$next_page_link = '';
 | 
  
    | 155 | 		} else {
 | 
  
    | 156 | 			if(isset($_GET['g']) AND is_numeric($_GET['g']))
 | 
  
    | 157 |             {
 | 
  
    | 158 | 				$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'&g='.$_GET['g'].'"> ';
 | 
  
    | 159 | 			} else {
 | 
  
    | 160 | 				$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'"> ';
 | 
  
    | 161 | 			}
 | 
  
    | 162 | 			$nl_append = ' >></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 |         {
 | 
  
    | 168 | 			$num_of = $position+$num_posts;
 | 
  
    | 169 | 		} else {
 | 
  
    | 170 | 			$num_of = $position+$setting_posts_per_page;
 | 
  
    | 171 | 		}
 | 
  
    | 172 | 
 | 
  
    | 173 | 		$out_of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OUT_OF']).' '.$total_num;
 | 
  
    | 174 | 		$of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OF']).' '.$total_num;
 | 
  
    | 175 | 		$display_previous_next_links = '';
 | 
  
    | 176 | 	} else {
 | 
  
    | 177 | 		$display_previous_next_links = 'none';
 | 
  
    | 178 | 	}
 | 
  
    | 179 | 
 | 
  
    | 180 | 	if ($num_posts === 0)
 | 
  
    | 181 |     {
 | 
  
    | 182 | 		$setting_header = '';
 | 
  
    | 183 | 		$setting_post_loop = '';
 | 
  
    | 184 | 		$setting_footer = '';
 | 
  
    | 185 | 		$setting_posts_per_page = '';
 | 
  
    | 186 | 	}
 | 
  
    | 187 | 
 | 
  
    | 188 | 	// Print header
 | 
  
    | 189 | 	if($display_previous_next_links == 'none')
 | 
  
    | 190 |     {
 | 
  
    | 191 | 		print  str_replace( array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'),
 | 
  
    | 192 |                             array('','','','','','', $display_previous_next_links), $setting_header);
 | 
  
    | 193 | 	} else {
 | 
  
    | 194 | 		print str_replace(  array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'),
 | 
  
    | 195 |                             array($next_page_link, $next_link, $previous_page_link, $previous_link, $out_of, $of, $display_previous_next_links), $setting_header);
 | 
  
    | 196 | 	}
 | 
  
    | 197 | 	if($num_posts > 0)
 | 
  
    | 198 |     {
 | 
  
    | 199 | 		if($query_extra != '')
 | 
  
    | 200 |         {
 | 
  
    | 201 | 			?>
 | 
  
    | 202 | 			<div class="selected-group-title">
 | 
  
    | 203 | 				<?php print '<a href="'.htmlspecialchars(strip_tags($_SERVER['SCRIPT_NAME'])).'">'.PAGE_TITLE.'</a> >> '.$groups[$_GET['g']]['title']; ?>
 | 
  
    | 204 | 			</div>
 | 
  
    | 205 | 			<?php
 | 
  
    | 206 | 		}
 | 
  
    | 207 | 		while( false != ($post = $query_posts->fetchRow()) )
 | 
  
    | 208 |         {
 | 
  
    | 209 | 			if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false)
 | 
  
    | 210 |             { // Make sure parent group is active
 | 
  
    | 211 | 				$uid = $post['posted_by']; // User who last modified the post
 | 
  
    | 212 | 				// Workout date and time of last modified post
 | 
  
    | 213 | 				if ($post['published_when'] === '0') $post['published_when'] = time();
 | 
  
    | 214 | 				if ($post['published_when'] > $post['posted_when'])
 | 
  
    | 215 |                 {
 | 
  
    | 216 | 					$post_date = date(DATE_FORMAT, $post['published_when']+TIMEZONE);
 | 
  
    | 217 | 					$post_time = date(TIME_FORMAT, $post['published_when']+TIMEZONE);
 | 
  
    | 218 | 				} else {
 | 
  
    | 219 | 					$post_date = date(DATE_FORMAT, $post['posted_when']+TIMEZONE);
 | 
  
    | 220 | 					$post_time = date(TIME_FORMAT, $post['posted_when']+TIMEZONE);
 | 
  
    | 221 | 				}
 | 
  
    | 222 | 
 | 
  
    | 223 | 				$publ_date = date(DATE_FORMAT,$post['published_when']);
 | 
  
    | 224 | 				$publ_time = date(TIME_FORMAT,$post['published_when']);
 | 
  
    | 225 | 
 | 
  
    | 226 | 				// Work-out the post link
 | 
  
    | 227 | 				$post_link = page_link($post['link']);
 | 
  
    | 228 | 
 | 
  
    | 229 |                 $post_link_path = str_replace(WB_URL, WB_PATH,$post_link);
 | 
  
    | 230 |     			$create_date = date(DATE_FORMAT, $post['created_when']);
 | 
  
    | 231 |     			$create_time = date(TIME_FORMAT, $post['created_when']);
 | 
  
    | 232 | 
 | 
  
    | 233 | 				if(isset($_GET['p']) AND $position > 0)
 | 
  
    | 234 |                 {
 | 
  
    | 235 | 					$post_link .= '?p='.$position;
 | 
  
    | 236 | 				}
 | 
  
    | 237 | 				if(isset($_GET['g']) AND is_numeric($_GET['g']))
 | 
  
    | 238 |                 {
 | 
  
    | 239 | 					if(isset($_GET['p']) AND $position > 0) { $post_link .= '&'; } else { $post_link .= '?'; }
 | 
  
    | 240 |                     {
 | 
  
    | 241 | 					$post_link .= 'g='.$_GET['g'];
 | 
  
    | 242 |                     }
 | 
  
    | 243 | 				}
 | 
  
    | 244 | 
 | 
  
    | 245 | 				// Get group id, title, and image
 | 
  
    | 246 | 				$group_id = $post['group_id'];
 | 
  
    | 247 | 				$group_title = $groups[$group_id]['title'];
 | 
  
    | 248 | 				$group_image = $groups[$group_id]['image'];
 | 
  
    | 249 | 				$display_image = ($group_image == '') ? "none" : "inherit";
 | 
  
    | 250 | 				$display_group = ($group_id == 0) ? 'none' : 'inherit';
 | 
  
    | 251 | 
 | 
  
    | 252 | 				if ($group_image != "") $group_image= "<img src='".$group_image."' alt='".$group_title."' />";
 | 
  
    | 253 | 
 | 
  
    | 254 | 				// Replace [wblink--PAGE_ID--] with real link
 | 
  
    | 255 | 				$short = ($post['content_short']);
 | 
  
    | 256 | 				// Replace vars with values
 | 
  
    | 257 | 				$post_long_len = strlen($post['content_long']);
 | 
  
    | 258 | 				$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]');
 | 
  
    | 259 | 				if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '')
 | 
  
    | 260 |                 {
 | 
  
    | 261 | 					if($post_long_len < 9)
 | 
  
    | 262 |                     {
 | 
  
    | 263 | 						$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $short, '#" onclick="javascript:void(0);return false;" style="cursor:no-drop;', $post_date, $post_time, $create_date, $create_time, $publ_date, $publ_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email'], '', 'hidden');
 | 
  
    | 264 | 					} else {
 | 
  
    | 265 | 					   	$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $short, $post_link, $post_date, $post_time, $create_date, $create_time, $publ_date, $publ_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email'], $MOD_NEWS['TEXT_READ_MORE'], 'visible');
 | 
  
    | 266 | 					}
 | 
  
    | 267 | 				} else {
 | 
  
    | 268 | 					if($post_long_len < 9)
 | 
  
    | 269 |                     {
 | 
  
    | 270 | 						$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $short, '#" onclick="javascript:void(0);return false;" style="cursor:no-drop;', $post_date, $post_time, $create_date, $create_time, $publ_date, $publ_time, '', '', '', '', '','hidden');
 | 
  
    | 271 | 					} else {
 | 
  
    | 272 | 						$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, $post['title'], $short, $post_link, $post_date, $post_time, $create_date, $create_time, $publ_date, $publ_time, '', '', '', '', $MOD_NEWS['TEXT_READ_MORE'],'visible');
 | 
  
    | 273 | 					}
 | 
  
    | 274 | 				}
 | 
  
    | 275 | 				print str_replace($vars, $values, $setting_post_loop);
 | 
  
    | 276 | 			}
 | 
  
    | 277 | 		}
 | 
  
    | 278 | 	}
 | 
  
    | 279 |     // Print footer
 | 
  
    | 280 |     if($display_previous_next_links == 'none')
 | 
  
    | 281 |     {
 | 
  
    | 282 |     	print  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);
 | 
  
    | 283 |     }
 | 
  
    | 284 |     else
 | 
  
    | 285 |     {
 | 
  
    | 286 |     	print 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);
 | 
  
    | 287 |     }
 | 
  
    | 288 | 
 | 
  
    | 289 | }
 | 
  
    | 290 | //elseif(defined('POST_ID') AND is_numeric(POST_ID))
 | 
  
    | 291 | elseif(isset($post_id) && is_numeric($post_id))
 | 
  
    | 292 | {
 | 
  
    | 293 | 
 | 
  
    | 294 |   // print '<h2>'.POST_ID.'/'.PAGE_ID.'/'.POST_SECTION.'</h2>';
 | 
  
    | 295 | //  if(defined('POST_SECTION') AND POST_SECTION == $section_id)
 | 
  
    | 296 |   if(isset($post_section) && ($post_section == $section_id))
 | 
  
    | 297 |   {
 | 
  
    | 298 | 	// Get settings
 | 
  
    | 299 | 	$setting_post_header = $setting_post_footer = $setting_comments_header
 | 
  
    | 300 | 	                     = $setting_comments_loop = $setting_comments_footer = '';
 | 
  
    | 301 | 	$sql  = 'SELECT `post_header`, `post_footer`, `comments_header`, `comments_loop`, `comments_footer` ';
 | 
  
    | 302 | 	$sql .= 'FROM `'.TABLE_PREFIX.'mod_news_settings` ';
 | 
  
    | 303 | 	$sql .= 'WHERE `section_id`='.(int)$section_id;
 | 
  
    | 304 | 	if( ($resSettings = $database->query($sql)) ){
 | 
  
    | 305 | 		if( ($recSettings = $resSettings->fetchRow()) ) {
 | 
  
    | 306 | 			foreach($recSettings as $key=>$val){
 | 
  
    | 307 | 				${'setting_'.$key} = $val;
 | 
  
    | 308 | 			}
 | 
  
    | 309 | 		}
 | 
  
    | 310 | 	}
 | 
  
    | 311 | 	// Get page info
 | 
  
    | 312 | 	$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '".PAGE_ID."'");
 | 
  
    | 313 | 	if($query_page->numRows() > 0)
 | 
  
    | 314 |     {
 | 
  
    | 315 | 		$page = $query_page->fetchRow();
 | 
  
    | 316 | 		$page_link = page_link($page['link']);
 | 
  
    | 317 | 		if(isset($_GET['p']) AND $position > 0)
 | 
  
    | 318 |         {
 | 
  
    | 319 | 			$page_link .= '?p='.$_GET['p'];
 | 
  
    | 320 | 		}
 | 
  
    | 321 | 		if(isset($_GET['g']) AND is_numeric($_GET['g']))
 | 
  
    | 322 |         {
 | 
  
    | 323 | 			if(isset($_GET['p']) AND $position > 0) { $page_link .= '&'; } else { $page_link .= '?'; }
 | 
  
    | 324 | 			$page_link .= 'g='.$_GET['g'];
 | 
  
    | 325 | 		}
 | 
  
    | 326 | 	} else {
 | 
  
    | 327 | 		exit($MESSAGE['PAGES']['NOT_FOUND']);
 | 
  
    | 328 | 	}
 | 
  
    | 329 | 
 | 
  
    | 330 | 	// Get post info
 | 
  
    | 331 | 	$t = time();
 | 
  
    | 332 | 	$query_post = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts
 | 
  
    | 333 | 		WHERE post_id = '".$post_id."' AND active = '1'
 | 
  
    | 334 | 		AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)");
 | 
  
    | 335 | 
 | 
  
    | 336 | 	if($query_post->numRows() > 0)
 | 
  
    | 337 |     {
 | 
  
    | 338 | 		$post = $query_post->fetchRow();
 | 
  
    | 339 | 		if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false)
 | 
  
    | 340 |         { // Make sure parent group is active
 | 
  
    | 341 | 			$uid = $post['posted_by']; // User who last modified the post
 | 
  
    | 342 | 			// Workout date and time of last modified post
 | 
  
    | 343 | 			if ($post['published_when'] === '0') $post['published_when'] = time();
 | 
  
    | 344 | 			if ($post['published_when'] > $post['posted_when'])
 | 
  
    | 345 |             {
 | 
  
    | 346 | 				$post_date = date(DATE_FORMAT, $post['published_when']+TIMEZONE);
 | 
  
    | 347 | 				$post_time = date(TIME_FORMAT, $post['published_when']+TIMEZONE);
 | 
  
    | 348 | 			}
 | 
  
    | 349 |             else
 | 
  
    | 350 |             {
 | 
  
    | 351 | 				$post_date = date(DATE_FORMAT, $post['posted_when']+TIMEZONE);
 | 
  
    | 352 | 				$post_time = date(TIME_FORMAT, $post['posted_when']+TIMEZONE);
 | 
  
    | 353 | 			}
 | 
  
    | 354 | 
 | 
  
    | 355 | 			$publ_date = date(DATE_FORMAT,$post['published_when']);
 | 
  
    | 356 | 			$publ_time = date(TIME_FORMAT,$post['published_when']);
 | 
  
    | 357 | 
 | 
  
    | 358 | 			// Work-out the post link
 | 
  
    | 359 | 			$post_link = page_link($post['link']);
 | 
  
    | 360 | 
 | 
  
    | 361 | 			$post_link_path = str_replace(WB_URL, WB_PATH,$post_link);
 | 
  
    | 362 | 			$create_date = date(DATE_FORMAT, $post['created_when']);
 | 
  
    | 363 | 			$create_time = date(TIME_FORMAT, $post['created_when']);
 | 
  
    | 364 | 			// Get group id, title, and image
 | 
  
    | 365 | 			$group_id = $post['group_id'];
 | 
  
    | 366 | 			$group_title = $groups[$group_id]['title'];
 | 
  
    | 367 | 			$group_image = $groups[$group_id]['image'];
 | 
  
    | 368 | 			$display_image = ($group_image == '') ? "none" : "inherit";
 | 
  
    | 369 | 			$display_group = ($group_id == 0) ? 'none' : 'inherit';
 | 
  
    | 370 | 
 | 
  
    | 371 | 			if ($group_image != "") $group_image= "<img src='".$group_image."' alt='".$group_title."' />";
 | 
  
    | 372 | 
 | 
  
    | 373 | 			$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]');
 | 
  
    | 374 | 			$post_short=$post['content_short'];
 | 
  
    | 375 | 			if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '')
 | 
  
    | 376 |             {
 | 
  
    | 377 | 				$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']);
 | 
  
    | 378 | 			} else {
 | 
  
    | 379 | 				$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'], '', '', '', '');
 | 
  
    | 380 | 			}
 | 
  
    | 381 | 			// $post_long = ($post['content_long']);
 | 
  
    | 382 | 			$post_long = ($post['content_long'] != '') ? $post['content_long'] : $post['content_short'];
 | 
  
    | 383 | 		}
 | 
  
    | 384 | 	} else {
 | 
  
    | 385 | 	    	$wb->print_error($MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'], 'view.php', false);
 | 
  
    | 386 | 	}
 | 
  
    | 387 | 
 | 
  
    | 388 | 	// Print post header
 | 
  
    | 389 | 	print str_replace($vars, $values, $setting_post_header);
 | 
  
    | 390 | 	// Print long
 | 
  
    | 391 | 	print $post_long;
 | 
  
    | 392 | 
 | 
  
    | 393 | 	// Print post footer
 | 
  
    | 394 | 	print str_replace($vars, $values, $setting_post_footer);
 | 
  
    | 395 | 
 | 
  
    | 396 | 	// Show comments section if we have to
 | 
  
    | 397 | 	if(($post['commenting'] == 'private' AND isset($wb) AND $wb->is_authenticated() == true) OR $post['commenting'] == 'public')
 | 
  
    | 398 |     {
 | 
  
    | 399 | 		// Print comments header
 | 
  
    | 400 | 		$vars = array('[ADD_COMMENT_URL]','[TEXT_COMMENTS]');
 | 
  
    | 401 | 		// $pid = $admin->getIDKEY(POST_ID);
 | 
  
    | 402 | 		$values = array(WB_URL.'/modules/news/comment.php?post_id='.$post_id.'&section_id='.$section_id, $MOD_NEWS['TEXT_COMMENTS']);
 | 
  
    | 403 | 		print str_replace($vars, $values, $setting_comments_header);
 | 
  
    | 404 | 
 | 
  
    | 405 | 		// Query for comments
 | 
  
    | 406 | 		$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");
 | 
  
    | 407 | 		if($query_comments->numRows() > 0)
 | 
  
    | 408 |         {
 | 
  
    | 409 | 			while( false != ($comment = $query_comments->fetchRow()) )
 | 
  
    | 410 |             {
 | 
  
    | 411 | 				// Display Comments without slashes, but with new-line characters
 | 
  
    | 412 | 				$comment['comment'] = nl2br($wb->strip_slashes($comment['comment']));
 | 
  
    | 413 | 				$comment['title'] = $wb->strip_slashes($comment['title']);
 | 
  
    | 414 | 				// Print comments loop
 | 
  
    | 415 | 				$commented_date = date(DATE_FORMAT, $comment['commented_when']+TIMEZONE);
 | 
  
    | 416 | 				$commented_time = date(TIME_FORMAT, $comment['commented_when']+TIMEZONE);
 | 
  
    | 417 | 				$uid = $comment['commented_by'];
 | 
  
    | 418 | 				$vars = array('[TITLE]','[COMMENT]','[TEXT_ON]','[DATE]','[TEXT_AT]','[TIME]','[TEXT_BY]','[USER_ID]','[USERNAME]','[DISPLAY_NAME]', '[EMAIL]');
 | 
  
    | 419 | 				if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '')
 | 
  
    | 420 |                 {
 | 
  
    | 421 | 					$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']));
 | 
  
    | 422 | 				} else {
 | 
  
    | 423 | 					$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'], '');
 | 
  
    | 424 | 				}
 | 
  
    | 425 | 				print str_replace($vars, $values, $setting_comments_loop);
 | 
  
    | 426 | 			}
 | 
  
    | 427 | 		} else {
 | 
  
    | 428 | 			// Say no comments found
 | 
  
    | 429 | 			$content = '';
 | 
  
    | 430 | 			$vars = array('[TITLE]','[COMMENT]','[TEXT_ON]','[DATE]','[TEXT_AT]','[TIME]','[TEXT_BY]','[USER_ID]','[USERNAME]','[DISPLAY_NAME]', '[EMAIL]');
 | 
  
    | 431 | 			$values = array( '', $MOD_NEWS['NO_COMMENT_FOUND'], '', '', '', '', '', '', '', '');
 | 
  
    | 432 | 			print str_replace($vars, $values, $setting_comments_loop);
 | 
  
    | 433 | 		}
 | 
  
    | 434 | 
 | 
  
    | 435 | 		// Print comments footer
 | 
  
    | 436 | 		$vars = array('[ADD_COMMENT_URL]','[TEXT_ADD_COMMENT]');
 | 
  
    | 437 | 		$values = array(WB_URL.'/modules/news/comment.php?post_id='.$post_id.'&section_id='.$section_id, $MOD_NEWS['TEXT_ADD_COMMENT']);
 | 
  
    | 438 | 		print str_replace($vars, $values, $setting_comments_footer);
 | 
  
    | 439 | 
 | 
  
    | 440 | 	}
 | 
  
    | 441 | 
 | 
  
    | 442 |     }
 | 
  
    | 443 | 
 | 
  
    | 444 | 	if(ENABLED_ASP)
 | 
  
    | 445 |     {
 | 
  
    | 446 | 		$_SESSION['comes_from_view'] = $post_id;
 | 
  
    | 447 | 		$_SESSION['comes_from_view_time'] = time();
 | 
  
    | 448 | 	}
 | 
  
    | 449 | 
 | 
  
    | 450 | }
 |