| 1 | 5 | stefan | <?php
 | 
      
        | 2 |  |  | 
 | 
      
        | 3 | 11 | ryan | // $Id$
 | 
      
        | 4 |  |  | 
 | 
      
        | 5 | 5 | stefan | /*
 | 
      
        | 6 |  |  | 
 | 
      
        | 7 |  |  |  Website Baker Project <http://www.websitebaker.org/>
 | 
      
        | 8 |  |  |  Copyright (C) 2004-2005, 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 |  |  | /*
 | 
      
        | 27 |  |  | 
 | 
      
        | 28 |  |  | Frontend class
 | 
      
        | 29 |  |  | 
 | 
      
        | 30 |  |  | */
 | 
      
        | 31 |  |  | 
 | 
      
        | 32 | 18 | stefan | if(!defined('WB_PATH')) {
 | 
      
        | 33 |  |  | 	header('Location: ../index.php');
 | 
      
        | 34 |  |  | }
 | 
      
        | 35 | 5 | stefan | 
 | 
      
        | 36 |  |  | 
 | 
      
        | 37 |  |  | require_once(WB_PATH.'/framework/class.wb.php');
 | 
      
        | 38 |  |  | 
 | 
      
        | 39 |  |  | class frontend extends wb {
 | 
      
        | 40 |  |  | 	// defaults
 | 
      
        | 41 | 51 | stefan | 	var $default_link,$default_page_id;
 | 
      
        | 42 |  |  | 	// when multiple blocks are used, show home page blocks on
 | 
      
        | 43 |  |  | 	// pages where no content is defined (search, login, ...)
 | 
      
        | 44 | 55 | stefan | 	var $no_default_block_content=false;
 | 
      
        | 45 | 5 | stefan | 
 | 
      
        | 46 |  |  | 	// page details
 | 
      
        | 47 |  |  | 	// page database row
 | 
      
        | 48 |  |  | 	var $page;
 | 
      
        | 49 |  |  | 	var $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$visibility;
 | 
      
        | 50 |  |  | 	var $page_description,$page_keywords,$page_link_original,$page_link;
 | 
      
        | 51 |  |  | 	var $page_trail=array();
 | 
      
        | 52 |  |  | 
 | 
      
        | 53 |  |  | 	var $page_access_denied;
 | 
      
        | 54 |  |  | 
 | 
      
        | 55 |  |  | 	// website settings
 | 
      
        | 56 |  |  | 	var $website_title,$website_description,$website_keywords,$website_header,$website_footer;
 | 
      
        | 57 |  |  | 
 | 
      
        | 58 |  |  | 	// ugly database stuff
 | 
      
        | 59 | 27 | stefan | 	var $extra_where_sql;
 | 
      
        | 60 | 5 | stefan | 
 | 
      
        | 61 |  |  | 	function frontend() {
 | 
      
        | 62 |  |  | 		$this->wb();
 | 
      
        | 63 |  |  | 	}
 | 
      
        | 64 |  |  | 
 | 
      
        | 65 |  |  | 	function page_select() {
 | 
      
        | 66 |  |  | 		global $page_id,$no_intro;
 | 
      
        | 67 | 55 | stefan | 		$database=& $this->database;
 | 
      
        | 68 | 5 | stefan | 		// We have no page id and are supposed to show the intro page
 | 
      
        | 69 |  |  | 		if((INTRO_PAGE AND !isset($no_intro)) AND (!isset($page_id) OR !is_numeric($page_id))) {
 | 
      
        | 70 |  |  | 			// Since we have no page id check if we should go to intro page or default page
 | 
      
        | 71 |  |  | 			// Get intro page content
 | 
      
        | 72 |  |  | 			$filename = WB_PATH.PAGES_DIRECTORY.'/intro.php';
 | 
      
        | 73 |  |  | 			if(file_exists($filename)) {
 | 
      
        | 74 |  |  | 				$handle = fopen($filename, "r");
 | 
      
        | 75 |  |  | 				$content = fread($handle, filesize($filename));
 | 
      
        | 76 |  |  | 				fclose($handle);
 | 
      
        | 77 |  |  | 				$this->preprocess($content);
 | 
      
        | 78 | 42 | stefan | 				echo $this->strip_slashes_dummy($content);
 | 
      
        | 79 | 5 | stefan | 				return false;
 | 
      
        | 80 |  |  | 			}
 | 
      
        | 81 |  |  | 		}
 | 
      
        | 82 |  |  | 		// Check if we should add page language sql code
 | 
      
        | 83 |  |  | 		if(PAGE_LANGUAGES) {
 | 
      
        | 84 |  |  | 			$this->sql_where_language = " AND language = '".LANGUAGE."'";
 | 
      
        | 85 |  |  | 		}
 | 
      
        | 86 |  |  | 		// Get default page
 | 
      
        | 87 |  |  | 		// Check for a page id
 | 
      
        | 88 |  |  | 		$query_default = "SELECT page_id,link FROM ".TABLE_PREFIX."pages WHERE parent = '0' AND visibility = 'public'$this->sql_where_language ORDER BY position ASC LIMIT 1";
 | 
      
        | 89 |  |  | 		$get_default = $database->query($query_default);
 | 
      
        | 90 |  |  | 		$default_num_rows = $get_default->numRows();
 | 
      
        | 91 |  |  | 		if(!isset($page_id) OR !is_numeric($page_id)){
 | 
      
        | 92 |  |  | 			// Go to or show default page
 | 
      
        | 93 |  |  | 			if($default_num_rows > 0) {
 | 
      
        | 94 |  |  | 				$fetch_default = $get_default->fetchRow();
 | 
      
        | 95 |  |  | 				$this->default_link = $fetch_default['link'];
 | 
      
        | 96 | 51 | stefan | 				$this->default_page_id = $fetch_default['page_id'];
 | 
      
        | 97 | 5 | stefan | 				// Check if we should redirect or include page inline
 | 
      
        | 98 |  |  | 				if(HOMEPAGE_REDIRECTION) {
 | 
      
        | 99 |  |  | 					// Redirect to page
 | 
      
        | 100 |  |  | 					header("Location: ".page_link($this->default_link));
 | 
      
        | 101 |  |  | 					exit();
 | 
      
        | 102 |  |  | 				} else {
 | 
      
        | 103 |  |  | 					// Include page inline
 | 
      
        | 104 | 51 | stefan | 					$this->page_id = $this->default_page_id;
 | 
      
        | 105 | 5 | stefan | 				}
 | 
      
        | 106 |  |  | 			} else {
 | 
      
        | 107 |  |  | 		   		// No pages have been added, so print under construction page
 | 
      
        | 108 |  |  | 				$this->print_under_construction();
 | 
      
        | 109 |  |  | 				exit();
 | 
      
        | 110 |  |  | 			}
 | 
      
        | 111 |  |  | 		} else {
 | 
      
        | 112 |  |  | 			$this->page_id=$page_id;
 | 
      
        | 113 |  |  | 		}
 | 
      
        | 114 |  |  | 		// Get default page link
 | 
      
        | 115 |  |  | 		if(!isset($fetch_default)) {
 | 
      
        | 116 |  |  | 		  	$fetch_default = $get_default->fetchRow();
 | 
      
        | 117 | 51 | stefan | 	 		$this->default_link = $fetch_default['link'];
 | 
      
        | 118 |  |  | 			$this->default_page_id = $fetch_default['page_id'];
 | 
      
        | 119 | 5 | stefan | 		}
 | 
      
        | 120 |  |  | 		return true;
 | 
      
        | 121 |  |  | 	}
 | 
      
        | 122 |  |  | 
 | 
      
        | 123 |  |  | 	function get_page_details() {
 | 
      
        | 124 | 55 | stefan | 		$database = & $this->database;
 | 
      
        | 125 | 5 | stefan | 	    if($this->page_id != 0) {
 | 
      
        | 126 |  |  | 			// Query page details
 | 
      
        | 127 |  |  | 			$query_page = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '{$this->page_id}'";
 | 
      
        | 128 |  |  | 			$get_page = $database->query($query_page);
 | 
      
        | 129 |  |  | 			// Make sure page was found in database
 | 
      
        | 130 |  |  | 			if($get_page->numRows() == 0) {
 | 
      
        | 131 |  |  | 				// Print page not found message
 | 
      
        | 132 |  |  | 				exit("Page not found");
 | 
      
        | 133 |  |  | 			}
 | 
      
        | 134 |  |  | 			// Fetch page details
 | 
      
        | 135 |  |  | 			$this->page = $get_page->fetchRow();
 | 
      
        | 136 |  |  | 			// Check if the page language is also the selected language. If not, send headers again.
 | 
      
        | 137 |  |  | 			if ($this->page['language']!=LANGUAGE) {
 | 
      
        | 138 |  |  | 				require_once(WB_PATH.'/framework/functions.php');
 | 
      
        | 139 |  |  | 				header('Location: '.page_link($this->page['link']).'?lang='.$this->page['language']);
 | 
      
        | 140 |  |  | 				exit();
 | 
      
        | 141 |  |  | 			}
 | 
      
        | 142 |  |  | 			// Begin code to set details as either variables of constants
 | 
      
        | 143 |  |  | 			// Page ID
 | 
      
        | 144 |  |  | 			define('PAGE_ID', $this->page['page_id']);
 | 
      
        | 145 |  |  | 			$this->page_id=$this->page['page_id'];
 | 
      
        | 146 |  |  | 			// Page Title
 | 
      
        | 147 | 42 | stefan | 			define('PAGE_TITLE', $this->strip_slashes_dummy($this->page['page_title']));
 | 
      
        | 148 | 5 | stefan | 			$this->page_title=PAGE_TITLE;
 | 
      
        | 149 |  |  | 			// Menu Title
 | 
      
        | 150 | 42 | stefan | 			$menu_title = $this->strip_slashes_dummy($this->page['menu_title']);
 | 
      
        | 151 | 5 | stefan | 			if($menu_title != '') {
 | 
      
        | 152 |  |  | 				define('MENU_TITLE', $menu_title);
 | 
      
        | 153 |  |  | 			} else {
 | 
      
        | 154 |  |  | 				define('MENU_TITLE', PAGE_TITLE);
 | 
      
        | 155 |  |  | 			}
 | 
      
        | 156 |  |  | 			$this->menu_title=MENU_TITLE;
 | 
      
        | 157 |  |  | 			// Page parent
 | 
      
        | 158 |  |  | 			define('PARENT', $this->page['parent']);
 | 
      
        | 159 |  |  | 			$this->parent=$this->page['parent'];
 | 
      
        | 160 |  |  | 			// Page root parent
 | 
      
        | 161 |  |  | 			define('ROOT_PARENT', $this->page['root_parent']);
 | 
      
        | 162 |  |  | 			$this->root_parent=$this->page['root_parent'];
 | 
      
        | 163 |  |  | 			// Page level
 | 
      
        | 164 |  |  | 			define('LEVEL', $this->page['level']);
 | 
      
        | 165 |  |  | 			$this->level=$this->page['level'];
 | 
      
        | 166 |  |  | 			// Page visibility
 | 
      
        | 167 |  |  | 			define('VISIBILITY', $this->page['visibility']);
 | 
      
        | 168 |  |  | 			$this->visibility=$this->page['visibility'];
 | 
      
        | 169 |  |  | 			// Page trail
 | 
      
        | 170 |  |  | 			foreach(explode(',', $this->page['page_trail']) AS $pid) {
 | 
      
        | 171 |  |  | 				$this->page_trail[$pid]=$pid;
 | 
      
        | 172 |  |  | 			}
 | 
      
        | 173 |  |  | 			// Page description
 | 
      
        | 174 |  |  | 			$this->page_description=$this->page['description'];
 | 
      
        | 175 |  |  | 			// Page keywords
 | 
      
        | 176 |  |  | 			$this->page_keywords=$this->page['keywords'];
 | 
      
        | 177 |  |  | 			// Page link
 | 
      
        | 178 |  |  | 			$this->link=$this->page_link($this->page['link']);
 | 
      
        | 179 |  |  | 
 | 
      
        | 180 |  |  | 		// End code to set details as either variables of constants
 | 
      
        | 181 |  |  | 		}
 | 
      
        | 182 |  |  | 
 | 
      
        | 183 |  |  | 		// Work-out if any possible in-line search boxes should be shown
 | 
      
        | 184 |  |  | 		if(SEARCH == 'public') {
 | 
      
        | 185 |  |  | 			define('SHOW_SEARCH', true);
 | 
      
        | 186 |  |  | 		} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
 | 
      
        | 187 |  |  | 			define('SHOW_SEARCH', true);
 | 
      
        | 188 |  |  | 		} elseif(SEARCH == 'private' AND $wb->is_authenticated() == true) {
 | 
      
        | 189 |  |  | 			define('SHOW_SEARCH', true);
 | 
      
        | 190 |  |  | 		} else {
 | 
      
        | 191 |  |  | 			define('SHOW_SEARCH', false);
 | 
      
        | 192 |  |  | 		}
 | 
      
        | 193 |  |  | 		// Work-out if menu should be shown
 | 
      
        | 194 |  |  | 		if(!defined('SHOW_MENU')) {
 | 
      
        | 195 |  |  | 			define('SHOW_MENU', true);
 | 
      
        | 196 |  |  | 		}
 | 
      
        | 197 |  |  | 		// Work-out if login menu constants should be set
 | 
      
        | 198 |  |  | 		if(FRONTEND_LOGIN) {
 | 
      
        | 199 |  |  | 			// Set login menu constants
 | 
      
        | 200 |  |  | 			define('LOGIN_URL', WB_URL.'/account/login'.PAGE_EXTENSION);
 | 
      
        | 201 |  |  | 			define('LOGOUT_URL', WB_URL.'/account/logout'.PAGE_EXTENSION);
 | 
      
        | 202 |  |  | 			define('FORGOT_URL', WB_URL.'/account/forgot'.PAGE_EXTENSION);
 | 
      
        | 203 |  |  | 			define('PREFERENCES_URL', WB_URL.'/account/preferences'.PAGE_EXTENSION);
 | 
      
        | 204 |  |  | 			define('SIGNUP_URL', WB_URL.'/account/signup'.PAGE_EXTENSION);
 | 
      
        | 205 |  |  | 		}
 | 
      
        | 206 |  |  | 
 | 
      
        | 207 |  |  | 		// Figure out what template to use
 | 
      
        | 208 |  |  | 		if(!defined('TEMPLATE')) {
 | 
      
        | 209 |  |  | 			if(isset($this->page['template']) AND $this->page['template'] != '') {
 | 
      
        | 210 |  |  | 				if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {
 | 
      
        | 211 |  |  | 					define('TEMPLATE', $this->page['template']);
 | 
      
        | 212 |  |  | 				} else {
 | 
      
        | 213 |  |  | 					define('TEMPLATE', DEFAULT_TEMPLATE);
 | 
      
        | 214 |  |  | 				}
 | 
      
        | 215 |  |  | 			} else {
 | 
      
        | 216 |  |  | 				define('TEMPLATE', DEFAULT_TEMPLATE);
 | 
      
        | 217 |  |  | 			}
 | 
      
        | 218 |  |  | 		}
 | 
      
        | 219 |  |  | 		// Set the template dir
 | 
      
        | 220 |  |  | 		define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
 | 
      
        | 221 |  |  | 
 | 
      
        | 222 |  |  | 		// Check if user is allow to view this page
 | 
      
        | 223 | 27 | stefan | 		if(VISIBILITY == 'private' OR VISIBILITY == 'registered') {
 | 
      
        | 224 | 5 | stefan | 			// Check if the user is authenticated
 | 
      
        | 225 |  |  | 			if($this->is_authenticated() == false) {
 | 
      
        | 226 |  |  | 				// User needs to login first
 | 
      
        | 227 | 43 | stefan | 				header("Location: ".WB_URL."/account/login".PAGE_EXTENSION.'?redirect='.$this->link);
 | 
      
        | 228 | 5 | stefan | 			}
 | 
      
        | 229 |  |  | 			// Check if we should show this page
 | 
      
        | 230 |  |  | 			if($this->show_page($this->page) == false) {
 | 
      
        | 231 |  |  | 				$this->page_access_denied=true;
 | 
      
        | 232 |  |  | 			}
 | 
      
        | 233 | 27 | stefan | 		} elseif(VISIBILITY == 'deleted' OR VISIBILITY == 'none') {
 | 
      
        | 234 | 5 | stefan | 			// User isnt allowed on this page so tell them
 | 
      
        | 235 |  |  | 			$this->page_access_denied=true;
 | 
      
        | 236 |  |  | 		}
 | 
      
        | 237 | 27 | stefan | 		// never show no-vis, hidden or deleted pages
 | 
      
        | 238 |  |  | 		$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'";
 | 
      
        | 239 |  |  | 		// Set extra private sql code
 | 
      
        | 240 |  |  | 		if($this->is_authenticated()==false) {
 | 
      
        | 241 |  |  | 			// if user is not authenticated, don't show private pages either
 | 
      
        | 242 |  |  | 			$this->extra_where_sql .= " AND visibility != 'private'";
 | 
      
        | 243 |  |  | 			// and 'registered' without frontend login doesn't make much sense!
 | 
      
        | 244 |  |  | 			if (FRONTEND_LOGIN==false) {
 | 
      
        | 245 |  |  | 				$this->extra_where_sql .= " AND visibility != 'registered'";
 | 
      
        | 246 | 5 | stefan | 			}
 | 
      
        | 247 |  |  | 		}
 | 
      
        | 248 |  |  | 		$this->extra_where_sql .= $this->sql_where_language;
 | 
      
        | 249 |  |  | 	}
 | 
      
        | 250 |  |  | 
 | 
      
        | 251 |  |  | 	function get_website_settings() {
 | 
      
        | 252 | 55 | stefan | 		$database = & $this->database;
 | 
      
        | 253 | 5 | stefan | 		// Get website settings (title, keywords, description, header, and footer)
 | 
      
        | 254 |  |  | 		$query_settings = "SELECT name,value FROM ".TABLE_PREFIX."settings";
 | 
      
        | 255 |  |  | 		$get_settings = $database->query($query_settings);
 | 
      
        | 256 |  |  | 		while($setting = $get_settings->fetchRow()) {
 | 
      
        | 257 |  |  | 			switch($setting['name']) {
 | 
      
        | 258 |  |  | 				case 'title':
 | 
      
        | 259 | 42 | stefan | 					define('WEBSITE_TITLE', $this->strip_slashes_dummy($setting['value']));
 | 
      
        | 260 | 5 | stefan | 					$this->website_title=WEBSITE_TITLE;
 | 
      
        | 261 |  |  | 				break;
 | 
      
        | 262 |  |  | 				case 'description':
 | 
      
        | 263 |  |  | 					if($page_description != '') {
 | 
      
        | 264 |  |  | 						define('WEBSITE_DESCRIPTION', $page_description);
 | 
      
        | 265 |  |  | 					} else {
 | 
      
        | 266 | 42 | stefan | 						define('WEBSITE_DESCRIPTION', $this->strip_slashes_dummy($setting['value']));
 | 
      
        | 267 | 5 | stefan | 					}
 | 
      
        | 268 |  |  | 					$this->website_description=WEBSITE_DESCRIPTION;
 | 
      
        | 269 |  |  | 				break;
 | 
      
        | 270 |  |  | 				case 'keywords':
 | 
      
        | 271 |  |  | 					if($page_keywords != '') {
 | 
      
        | 272 | 42 | stefan | 						define('WEBSITE_KEYWORDS', $this->strip_slashes_dummy($setting['value']).' '.$page_keywords);
 | 
      
        | 273 | 5 | stefan | 					} else {
 | 
      
        | 274 | 42 | stefan | 						define('WEBSITE_KEYWORDS', $this->strip_slashes_dummy($setting['value']));
 | 
      
        | 275 | 5 | stefan | 					}
 | 
      
        | 276 |  |  | 					$this->website_keywords=WEBSITE_KEYWORDS;
 | 
      
        | 277 |  |  | 				break;
 | 
      
        | 278 |  |  | 				case 'header':
 | 
      
        | 279 | 42 | stefan | 					define('WEBSITE_HEADER', $this->strip_slashes_dummy($setting['value']));
 | 
      
        | 280 | 5 | stefan | 					$this->website_header=WEBSITE_HEADER;
 | 
      
        | 281 |  |  | 				break;
 | 
      
        | 282 |  |  | 				case 'footer':
 | 
      
        | 283 | 42 | stefan | 					define('WEBSITE_FOOTER', $this->strip_slashes_dummy($setting['value']));
 | 
      
        | 284 | 5 | stefan | 					$this->website_footer=WEBSITE_FOOTER;
 | 
      
        | 285 |  |  | 				break;
 | 
      
        | 286 |  |  | 			}
 | 
      
        | 287 |  |  | 		}
 | 
      
        | 288 |  |  | 	}
 | 
      
        | 289 |  |  | 
 | 
      
        | 290 |  |  | 	function page_link($link){
 | 
      
        | 291 |  |  | 		// Check for :// in the link (used in URL's)
 | 
      
        | 292 |  |  | 		if(strstr($link, '://') == '') {
 | 
      
        | 293 |  |  | 			return WB_URL.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
 | 
      
        | 294 |  |  | 		} else {
 | 
      
        | 295 |  |  | 			return $link;
 | 
      
        | 296 |  |  | 		}
 | 
      
        | 297 |  |  | 	}
 | 
      
        | 298 |  |  | 
 | 
      
        | 299 |  |  | 	function preprocess(&$content) {
 | 
      
        | 300 | 55 | stefan | 		$database = & $this->database;
 | 
      
        | 301 | 5 | stefan | 		// Replace [wblink--PAGE_ID--] with real link
 | 
      
        | 302 |  |  | 		$pattern = '/\[wblink(.+?)\]/s';
 | 
      
        | 303 |  |  | 		preg_match_all($pattern,$content,$ids);
 | 
      
        | 304 |  |  | 		foreach($ids[1] AS $page_id) {
 | 
      
        | 305 |  |  | 			$pattern = '/\[wblink'.$page_id.'\]/s';
 | 
      
        | 306 |  |  | 			// Get page link
 | 
      
        | 307 |  |  | 			$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
 | 
      
        | 308 |  |  | 			$fetch_link = $get_link->fetchRow();
 | 
      
        | 309 |  |  | 			$link = page_link($fetch_link['link']);
 | 
      
        | 310 |  |  | 			$content = preg_replace($pattern,$link,$content);
 | 
      
        | 311 |  |  | 		}
 | 
      
        | 312 |  |  | 	}
 | 
      
        | 313 |  |  | 
 | 
      
        | 314 | 20 | stefan | 	function menu() {
 | 
      
        | 315 |  |  | 	   if (!isset($this->menu_number)) {
 | 
      
        | 316 |  |  | 	   	$this->menu_number = 1;
 | 
      
        | 317 |  |  | 	   }
 | 
      
        | 318 |  |  | 	   if (!isset($this->menu_start_level)) {
 | 
      
        | 319 |  |  | 	   	$this->menu_start_level = 0;
 | 
      
        | 320 |  |  | 	   }
 | 
      
        | 321 |  |  | 	   if (!isset($this->menu_recurse)) {
 | 
      
        | 322 |  |  | 	   	$this->menu_recurse = -1;
 | 
      
        | 323 |  |  | 	   }
 | 
      
        | 324 |  |  | 	   if (!isset($this->menu_collapse)) {
 | 
      
        | 325 |  |  | 	   	$this->menu_collapse = true;
 | 
      
        | 326 |  |  | 	   }
 | 
      
        | 327 |  |  | 	   if (!isset($this->menu_item_template)) {
 | 
      
        | 328 |  |  | 	   	$this->menu_item_template = '<li><span[class]>[a][menu_title][/a]</span>';
 | 
      
        | 329 |  |  | 	   }
 | 
      
        | 330 |  |  | 	   if (!isset($this->menu_item_footer)) {
 | 
      
        | 331 |  |  | 	   	$this->menu_item_footer = '</li>';
 | 
      
        | 332 |  |  | 	   }
 | 
      
        | 333 |  |  | 	   if (!isset($this->menu_header)) {
 | 
      
        | 334 |  |  | 	   	$this->menu_header = '<ul>';
 | 
      
        | 335 |  |  | 	   }
 | 
      
        | 336 |  |  | 	   if (!isset($this->menu_footer)) {
 | 
      
        | 337 |  |  | 	   	$this->menu_footer = '<ul>';
 | 
      
        | 338 |  |  | 	   }
 | 
      
        | 339 |  |  | 	   if (!isset($this->menu_default_class)) {
 | 
      
        | 340 |  |  | 	   	$this->menu_default_class = ' class="menu_default"';
 | 
      
        | 341 |  |  | 	   }
 | 
      
        | 342 |  |  | 	   if (!isset($this->menu_current_class)) {
 | 
      
        | 343 |  |  | 	   	$this->menu_current_class = ' class="menu_current"';
 | 
      
        | 344 |  |  | 	   }
 | 
      
        | 345 |  |  |        if (!isset($this->menu_parent)) {
 | 
      
        | 346 |  |  |      	$this->menu_parent = 0;
 | 
      
        | 347 |  |  | 	   }
 | 
      
        | 348 |  |  | 	   $this->show_menu();
 | 
      
        | 349 | 5 | stefan | 	   if ($start_level>0) {
 | 
      
        | 350 |  |  | 	       $key_array=array_keys($this->page_trail);
 | 
      
        | 351 |  |  | 	       $real_start=$key_array[$start_level-1];
 | 
      
        | 352 |  |  | 	       if (isset($real_start))
 | 
      
        | 353 |  |  | 	       {
 | 
      
        | 354 | 20 | stefan | 	       		$this->menu_parent=$real_start;
 | 
      
        | 355 |  |  | 	          $this->show_menu();
 | 
      
        | 356 |  |  | 	       }
 | 
      
        | 357 | 5 | stefan | 	       return;
 | 
      
        | 358 |  |  | 	   }
 | 
      
        | 359 | 20 | stefan | 
 | 
      
        | 360 |  |  | 	}
 | 
      
        | 361 |  |  | 
 | 
      
        | 362 |  |  | 	function show_menu() {
 | 
      
        | 363 | 55 | stefan | 	   $database = & $this->database;
 | 
      
        | 364 | 20 | stefan | 	   if ($this->menu_recurse==0)
 | 
      
        | 365 |  |  | 	       return;
 | 
      
        | 366 | 5 | stefan | 	   // Check if we should add menu number check to query
 | 
      
        | 367 | 20 | stefan | 	   if($menu_parent == 0) {
 | 
      
        | 368 |  |  | 	       $menu_number = "menu = '$this->menu_number'";
 | 
      
        | 369 | 5 | stefan | 	   } else {
 | 
      
        | 370 |  |  | 	      $menu_number = '1';
 | 
      
        | 371 |  |  | 	   }
 | 
      
        | 372 |  |  | 	   // Query pages
 | 
      
        | 373 | 27 | stefan | 	   $query_menu = $database->query("SELECT page_id,menu_title,page_title,link,target,level,visibility FROM ".
 | 
      
        | 374 | 20 | stefan | 	TABLE_PREFIX."pages WHERE parent = '$this->menu_parent' AND $menu_number AND $this->extra_where_sql ORDER BY position ASC");
 | 
      
        | 375 | 5 | stefan | 	   // Check if there are any pages to show
 | 
      
        | 376 |  |  | 	   if($query_menu->numRows() > 0) {
 | 
      
        | 377 | 20 | stefan | 	   	  // Print menu header
 | 
      
        | 378 |  |  | 	   	  echo "\n".$this->menu_header;
 | 
      
        | 379 | 5 | stefan | 	      // Loop through pages
 | 
      
        | 380 |  |  | 	      while($page = $query_menu->fetchRow()) {
 | 
      
        | 381 | 20 | stefan | 	      	 // Check if this page should be shown
 | 
      
        | 382 | 5 | stefan | 	         // Create vars
 | 
      
        | 383 |  |  | 	         $vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');
 | 
      
        | 384 |  |  | 	         // Work-out class
 | 
      
        | 385 |  |  | 	         if($page['page_id'] == PAGE_ID) {
 | 
      
        | 386 | 20 | stefan | 	            $class = $this->menu_current_class;
 | 
      
        | 387 | 5 | stefan | 	         } else {
 | 
      
        | 388 | 20 | stefan | 	            $class = $this->menu_default_class;
 | 
      
        | 389 | 5 | stefan | 	         }
 | 
      
        | 390 |  |  | 	         // Check if link is same as first page link, and if so change to WB URL
 | 
      
        | 391 | 20 | stefan | 	         if($page['link'] == $this->default_link AND !INTRO_PAGE) {
 | 
      
        | 392 | 5 | stefan | 	            $link = WB_URL;
 | 
      
        | 393 |  |  | 	         } else {
 | 
      
        | 394 | 20 | stefan | 	            $link = $this->page_link($page['link']);
 | 
      
        | 395 | 5 | stefan | 	         }
 | 
      
        | 396 |  |  | 	         // Create values
 | 
      
        | 397 | 42 | stefan | 	         $values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $this->strip_slashes_dummy($page['menu_title']), $this->strip_slashes_dummy($page['page_title']));
 | 
      
        | 398 | 5 | stefan | 	         // Replace vars with value and print
 | 
      
        | 399 | 20 | stefan | 	         echo "\n".str_replace($vars, $values, $this->menu_item_template);
 | 
      
        | 400 | 5 | stefan | 	         // Generate sub-menu
 | 
      
        | 401 | 20 | stefan | 	         if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) {
 | 
      
        | 402 |  |  | 	            $this->menu_recurse--;
 | 
      
        | 403 |  |  | 	            $this->menu_parent=$page['page_id'];
 | 
      
        | 404 |  |  | 	            $this->show_menu();
 | 
      
        | 405 | 5 | stefan | 	         }
 | 
      
        | 406 | 20 | stefan | 	         echo "\n".$this->menu_item_footer;
 | 
      
        | 407 | 5 | stefan | 	      }
 | 
      
        | 408 |  |  | 	      // Print menu footer
 | 
      
        | 409 | 20 | stefan | 	      echo "\n".$this->menu_footer;
 | 
      
        | 410 | 5 | stefan | 	   }
 | 
      
        | 411 |  |  | 	}
 | 
      
        | 412 |  |  | 
 | 
      
        | 413 | 58 | stefan | 	function content($block = 1) {
 | 
      
        | 414 | 5 | stefan | 		// Get outside objects
 | 
      
        | 415 | 55 | stefan | 		global $TEXT,$MENU,$HEADING,$MESSAGE;
 | 
      
        | 416 | 5 | stefan | 		global $globals;
 | 
      
        | 417 | 55 | stefan | 		$database = & $this->database;
 | 
      
        | 418 |  |  | 		$admin = & $this;
 | 
      
        | 419 | 5 | stefan | 		if ($this->page_access_denied==true) {
 | 
      
        | 420 |  |  |             echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
 | 
      
        | 421 |  |  | 			exit();
 | 
      
        | 422 |  |  | 		}
 | 
      
        | 423 |  |  | 		if(isset($globals) AND is_array($globals)) { foreach($globals AS $global_name) { global $$global_name; } }
 | 
      
        | 424 |  |  | 		// Make sure block is numeric
 | 
      
        | 425 | 51 | stefan | 		if(!is_numeric($block)) { $block = 1; }
 | 
      
        | 426 | 5 | stefan | 		// Include page content
 | 
      
        | 427 | 51 | stefan | 		if(!defined('PAGE_CONTENT') OR $block!=1) {
 | 
      
        | 428 | 55 | stefan | 			if ($this->page_id==0) {
 | 
      
        | 429 |  |  | 				if ($this->default_block_content=='none') {
 | 
      
        | 430 | 51 | stefan | 					return;
 | 
      
        | 431 |  |  | 				}
 | 
      
        | 432 | 55 | stefan | 				if (is_numeric($this->default_block_content)) {
 | 
      
        | 433 |  |  | 					$page_id=$this->default_block_content;
 | 
      
        | 434 |  |  | 				} else {
 | 
      
        | 435 |  |  | 					$page_id=$this->default_page-id;
 | 
      
        | 436 |  |  | 				}
 | 
      
        | 437 | 51 | stefan | 			} else {
 | 
      
        | 438 |  |  | 				$page_id=$this->page_id;
 | 
      
        | 439 |  |  | 			}
 | 
      
        | 440 | 5 | stefan | 			// First get all sections for this page
 | 
      
        | 441 | 51 | stefan | 			$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '".$page_id."' AND block = '$block' ORDER BY position");
 | 
      
        | 442 | 5 | stefan | 			if($query_sections->numRows() > 0) {
 | 
      
        | 443 |  |  | 				// Loop through them and include there modules file
 | 
      
        | 444 |  |  | 				while($section = $query_sections->fetchRow()) {
 | 
      
        | 445 |  |  | 					$section_id = $section['section_id'];
 | 
      
        | 446 |  |  | 					$module = $section['module'];
 | 
      
        | 447 |  |  | 					require(WB_PATH.'/modules/'.$module.'/view.php');
 | 
      
        | 448 |  |  | 				}
 | 
      
        | 449 |  |  | 			}
 | 
      
        | 450 |  |  | 		} else {
 | 
      
        | 451 | 55 | stefan | 			require(PAGE_CONTENT);
 | 
      
        | 452 | 5 | stefan | 		}
 | 
      
        | 453 |  |  | 	}
 | 
      
        | 454 |  |  | 
 | 
      
        | 455 | 58 | stefan | 	function breadcrumbs($sep=' > ',$tier=1,$links=true) {
 | 
      
        | 456 |  |  | 		$page_id=&$this->page_id;
 | 
      
        | 457 |  |  | 		if ($page_id!=0)
 | 
      
        | 458 |  |  | 		{
 | 
      
        | 459 |  |  | 	 		global $database;
 | 
      
        | 460 |  |  | 			$bca=&$this->page_trail;
 | 
      
        | 461 |  |  | 			if (sizeof($bca)==0)
 | 
      
        | 462 |  |  | 			        create_breadcrumbs($page_id);
 | 
      
        | 463 |  |  | 			$counter=0;
 | 
      
        | 464 |  |  | 			foreach ($bca as $temp)
 | 
      
        | 465 |  |  | 			{
 | 
      
        | 466 |  |  | 		        if ($counter>=(tier-1));
 | 
      
        | 467 |  |  | 		        {
 | 
      
        | 468 |  |  | 					if ($counter>=$tier) echo $sep;
 | 
      
        | 469 |  |  | 					$query_menu=$database->query("SELECT menu_title,link FROM ".TABLE_PREFIX."pages WHERE page_id=$temp");
 | 
      
        | 470 |  |  | 					$page=$query_menu->fetchRow();
 | 
      
        | 471 |  |  | 					if ($links==true AND $temp!=$page_id)
 | 
      
        | 472 |  |  | 						echo '<a href="'.page_link($page['link']).'">'.$page['menu_title'].'</a>';
 | 
      
        | 473 |  |  | 					else
 | 
      
        | 474 |  |  | 					        echo stripslashes($page['menu_title']);
 | 
      
        | 475 |  |  | 		        }
 | 
      
        | 476 |  |  |                 $counter++;
 | 
      
        | 477 |  |  | 			}
 | 
      
        | 478 |  |  | 		}
 | 
      
        | 479 |  |  | 	}
 | 
      
        | 480 |  |  | 
 | 
      
        | 481 | 5 | stefan | 	// Function for page title
 | 
      
        | 482 |  |  | 	function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
 | 
      
        | 483 |  |  | 		$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
 | 
      
        | 484 |  |  | 		$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
 | 
      
        | 485 |  |  | 		echo str_replace($vars, $values, $template);
 | 
      
        | 486 |  |  | 	}
 | 
      
        | 487 |  |  | 
 | 
      
        | 488 |  |  | 	// Function for page description
 | 
      
        | 489 |  |  | 	function page_description() {
 | 
      
        | 490 |  |  | 		echo WEBSITE_DESCRIPTION;
 | 
      
        | 491 |  |  | 	}
 | 
      
        | 492 |  |  | 	// Function for page keywords
 | 
      
        | 493 |  |  | 	function page_keywords() {
 | 
      
        | 494 |  |  | 		echo WEBSITE_KEYWORDS;
 | 
      
        | 495 |  |  | 	}
 | 
      
        | 496 |  |  | 	// Function for page header
 | 
      
        | 497 |  |  | 	function page_header($date_format = 'Y') {
 | 
      
        | 498 |  |  | 		echo WEBSITE_HEADER;
 | 
      
        | 499 |  |  | 	}
 | 
      
        | 500 |  |  | 
 | 
      
        | 501 |  |  | 	// Function for page footer
 | 
      
        | 502 |  |  | 	function page_footer($date_format = 'Y') {
 | 
      
        | 503 |  |  | 		global $starttime;
 | 
      
        | 504 |  |  |    		$vars = array('[YEAR]', '[PROCESSTIME]');
 | 
      
        | 505 |  |  |    		$processtime=(microtime()>$starttime)?microtime()-$starttime:microtime()-$starttime+1;
 | 
      
        | 506 |  |  | 		$values = array(date($date_format),$processtime);
 | 
      
        | 507 |  |  | 		echo str_replace($vars, $values, WEBSITE_FOOTER);
 | 
      
        | 508 |  |  | 	}
 | 
      
        | 509 |  |  | 
 | 
      
        | 510 |  |  | 	// Function to show the "Under Construction" page
 | 
      
        | 511 |  |  | 	function print_under_construction() {
 | 
      
        | 512 |  |  | 		global $MESSAGE;
 | 
      
        | 513 |  |  | 		require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
 | 
      
        | 514 |  |  | 		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 | 
      
        | 515 |  |  | 		<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONTRUCTION'].'</title>
 | 
      
        | 516 |  |  | 		<style type="text/css"><!-- body { font-family: Verdana, Arial, Helvetica, sans-serif;
 | 
      
        | 517 |  |  | 		font-size: 12px; color: #000000;	background-color: #FFFFFF;	margin: 20px; text-align: center; }
 | 
      
        | 518 |  |  | 		h1 { margin: 0; padding: 0; }--></style></head><body>
 | 
      
        | 519 |  |  | 		<h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONTRUCTION'];'.</h1><br />
 | 
      
        | 520 |  |  | 		'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>';
 | 
      
        | 521 |  |  | 	}
 | 
      
        | 522 |  |  | }
 | 
      
        | 523 |  |  | 
 | 
      
        | 524 |  |  | ?>
 |