| 1 | <?php
 | 
  
    | 2 | /**
 | 
  
    | 3 |  *
 | 
  
    | 4 |  * @category        frontend
 | 
  
    | 5 |  * @package         framework
 | 
  
    | 6 |  * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
 | 
  
    | 7 |  * @copyright       2009-2012, WebsiteBaker Org. e.V.
 | 
  
    | 8 |  * @link            http://www.websitebaker2.org/
 | 
  
    | 9 |  * @license         http://www.gnu.org/licenses/gpl.html
 | 
  
    | 10 |  * @platform        WebsiteBaker 2.8.3
 | 
  
    | 11 |  * @requirements    PHP 5.3.6 and higher
 | 
  
    | 12 |  * @version         $Id: class.frontend.php 2 2017-07-02 15:14:29Z Manuela $
 | 
  
    | 13 |  * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/framework/class.frontend.php $
 | 
  
    | 14 |  * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
 | 
  
    | 15 |  *
 | 
  
    | 16 | */
 | 
  
    | 17 | /* -------------------------------------------------------- */
 | 
  
    | 18 | // Must include code to stop this file being accessed directly
 | 
  
    | 19 | if(!defined('WB_PATH')) {
 | 
  
    | 20 |     require_once(dirname(__FILE__).'/globalExceptionHandler.php');
 | 
  
    | 21 |     throw new IllegalFileException();
 | 
  
    | 22 | }
 | 
  
    | 23 | /* -------------------------------------------------------- */
 | 
  
    | 24 | require_once(WB_PATH.'/framework/class.wb.php');
 | 
  
    | 25 | //require_once(WB_PATH.'/framework/SecureForm.php');
 | 
  
    | 26 | 
 | 
  
    | 27 | class frontend extends wb {
 | 
  
    | 28 |     // defaults
 | 
  
    | 29 |     public $default_link,$default_page_id;
 | 
  
    | 30 |     // when multiple blocks are used, show home page blocks on
 | 
  
    | 31 |     // pages where no content is defined (search, login, ...)
 | 
  
    | 32 |     public $default_block_content=true;
 | 
  
    | 33 | 
 | 
  
    | 34 |     // page details
 | 
  
    | 35 |     // page database row
 | 
  
    | 36 |     public $page;
 | 
  
    | 37 |     public $page_id,$page_code,$page_title,$menu_title,$parent,$root_parent,$level,$position,$visibility;
 | 
  
    | 38 |     public $page_description,$page_keywords,$page_link, $page_icon, $menu_icon_0, $menu_icon_1, $tooltip;
 | 
  
    | 39 |     public $page_trail=array();
 | 
  
    | 40 | 
 | 
  
    | 41 |     public $page_access_denied;
 | 
  
    | 42 |     public $page_no_active_sections;
 | 
  
    | 43 | 
 | 
  
    | 44 |     // website settings
 | 
  
    | 45 |     public $website_title,$website_description,$website_keywords,$website_header,$website_footer;
 | 
  
    | 46 | 
 | 
  
    | 47 |     // ugly database stuff
 | 
  
    | 48 |     public $extra_where_sql, $sql_where_language;
 | 
  
    | 49 | /*
 | 
  
    | 50 |     public function __construct() {
 | 
  
    | 51 |         parent::__construct(1);
 | 
  
    | 52 | */
 | 
  
    | 53 |     public function __construct($value=true) {
 | 
  
    | 54 |         parent::__construct(1);
 | 
  
    | 55 |         $this->FrontendLanguage = isset($value) ? $value : true;
 | 
  
    | 56 |     }
 | 
  
    | 57 | 
 | 
  
    | 58 |     public function ChangeFrontendLanguage( $value=true ) {
 | 
  
    | 59 |         $this->FrontendLanguage=$value;
 | 
  
    | 60 |     }
 | 
  
    | 61 | 
 | 
  
    | 62 |     public function page_select() {
 | 
  
    | 63 |         global $page_id, $no_intro, $database;
 | 
  
    | 64 | 
 | 
  
    | 65 | /*
 | 
  
    | 66 |  * Store installed languages in SESSION
 | 
  
    | 67 |  */
 | 
  
    | 68 |         if( $this->get_session('session_started') ) {
 | 
  
    | 69 |             $_SESSION['USED_LANGUAGES'] = $this->getLanguagesInUsed();
 | 
  
    | 70 |         }
 | 
  
    | 71 | 
 | 
  
    | 72 |         $maintance = ( defined('SYSTEM_LOCKED') && (SYSTEM_LOCKED==true) ? true : false );
 | 
  
    | 73 | 
 | 
  
    | 74 |         if( ($maintance==true) || $this->get_session('USER_ID')!= 1 )
 | 
  
    | 75 |         {
 | 
  
    | 76 |            //  check for show maintenance screen and terminate if needed
 | 
  
    | 77 |             $this->ShowMaintainScreen('locked');
 | 
  
    | 78 |         }
 | 
  
    | 79 |         // We have no page id and are supposed to show the intro page
 | 
  
    | 80 |         if((INTRO_PAGE && ($maintance != true) && !isset($no_intro)) && (!isset($page_id) || !is_numeric($page_id)))
 | 
  
    | 81 |         {
 | 
  
    | 82 |             // Since we have no page id check if we should go to intro page or default page
 | 
  
    | 83 |             // Get intro page content
 | 
  
    | 84 |             $sIntroFilename = PAGES_DIRECTORY.'/intro'.PAGE_EXTENSION;
 | 
  
    | 85 |             if(file_exists(WB_PATH.$sIntroFilename)) {
 | 
  
    | 86 |                 // send intro.php as header to allow parsing of php statements
 | 
  
    | 87 |                 header("Location: ".WB_URL.$sIntroFilename."");
 | 
  
    | 88 |                 exit();
 | 
  
    | 89 |             }
 | 
  
    | 90 |         }
 | 
  
    | 91 |         // Check if we should add page language sql code
 | 
  
    | 92 |         if(PAGE_LANGUAGES) {
 | 
  
    | 93 |             $this->sql_where_language = ' AND `language`=\''.LANGUAGE.'\'';
 | 
  
    | 94 |         }
 | 
  
    | 95 |         // Get default page
 | 
  
    | 96 |         // Check for a page id
 | 
  
    | 97 |         $table_p = TABLE_PREFIX.'pages';
 | 
  
    | 98 |         $table_s = TABLE_PREFIX.'sections';
 | 
  
    | 99 |         $now = time();
 | 
  
    | 100 |         $sql  = 'SELECT `p`.`page_id`, `link` ';
 | 
  
    | 101 |         $sql .= 'FROM `'.$table_p.'` AS `p` INNER JOIN `'.$table_s.'` USING(`page_id`) ';
 | 
  
    | 102 |         $sql .= 'WHERE `parent`=0 AND `visibility`=\'public\' ';
 | 
  
    | 103 |         $sql .=     'AND (('.$now.'>=`publ_start` OR `publ_start`=0) ';
 | 
  
    | 104 |         $sql .=     'AND ('.$now.'<=`publ_end` OR `publ_end`=0)) ';
 | 
  
    | 105 |         if(trim($this->sql_where_language) != '') {
 | 
  
    | 106 |             $sql .= trim($this->sql_where_language).' ';
 | 
  
    | 107 |         }
 | 
  
    | 108 |         $sql .= 'ORDER BY `p`.`position` ASC';
 | 
  
    | 109 |         if($get_default = $database->query($sql)) {
 | 
  
    | 110 | 
 | 
  
    | 111 |             $default_num_rows = $get_default->numRows();
 | 
  
    | 112 |             if(!isset($page_id) OR !is_numeric($page_id)){
 | 
  
    | 113 |                 // Go to or show default page
 | 
  
    | 114 |                 if($default_num_rows > 0) {
 | 
  
    | 115 |                     $fetch_default = $get_default->fetchArray(MYSQLI_ASSOC);
 | 
  
    | 116 |                     $this->default_link = $fetch_default['link'];
 | 
  
    | 117 |                     $this->default_page_id = $fetch_default['page_id'];
 | 
  
    | 118 |                     // Check if we should redirect or include page inline
 | 
  
    | 119 |                     if(HOMEPAGE_REDIRECTION) {
 | 
  
    | 120 |                         // Redirect to page
 | 
  
    | 121 |     //                    header("Location: ".$this->page_link($this->default_link));
 | 
  
    | 122 |     //                    exit();
 | 
  
    | 123 |                         $this->send_header($this->page_link($this->default_link));
 | 
  
    | 124 |                     } else {
 | 
  
    | 125 |                         // Include page inline
 | 
  
    | 126 |                         $this->page_id = $this->default_page_id;
 | 
  
    | 127 |                     }
 | 
  
    | 128 |                 } else {
 | 
  
    | 129 |                        // No pages have been added, so print under construction page
 | 
  
    | 130 |     //                if(trim($this->sql_where_language) == '') {
 | 
  
    | 131 |     //                    $this->ShowMaintainScreen('new');
 | 
  
    | 132 |     //                    exit();
 | 
  
    | 133 |     //                }
 | 
  
    | 134 |                     $this->ShowMaintainScreen('new');
 | 
  
    | 135 |     //                $this->print_under_construction();
 | 
  
    | 136 |                     exit();
 | 
  
    | 137 |                 }
 | 
  
    | 138 |             } else {
 | 
  
    | 139 |                 $this->page_id=$page_id;
 | 
  
    | 140 |             }
 | 
  
    | 141 |             // Get default page link
 | 
  
    | 142 |             if(!isset($fetch_default)) {
 | 
  
    | 143 |                   $fetch_default = $get_default->fetchArray(MYSQLI_ASSOC);
 | 
  
    | 144 |                  $this->default_link = $fetch_default['link'];
 | 
  
    | 145 |                 $this->default_page_id = $fetch_default['page_id'];
 | 
  
    | 146 |             }
 | 
  
    | 147 |             return true;
 | 
  
    | 148 | 
 | 
  
    | 149 |         } else {
 | 
  
    | 150 |             $this->ShowMaintainScreen('new');
 | 
  
    | 151 |             exit();
 | 
  
    | 152 |         }
 | 
  
    | 153 | 
 | 
  
    | 154 |     }
 | 
  
    | 155 | 
 | 
  
    | 156 | 
 | 
  
    | 157 | 
 | 
  
    | 158 | 
 | 
  
    | 159 | /*
 | 
  
    | 160 |         $sql = 'SELECT `p`.`page_id`, `link` '
 | 
  
    | 161 |              . 'FROM `'.TABLE_PREFIX.'pages` `p` '
 | 
  
    | 162 |              .       'INNER JOIN `'.TABLE_PREFIX.'sections` '
 | 
  
    | 163 |              .       'USING(`page_id`) '
 | 
  
    | 164 |              . 'WHERE `parent`=0 '
 | 
  
    | 165 |              .   'AND `visibility`=\'public\' '
 | 
  
    | 166 |              .   'AND ('
 | 
  
    | 167 |              .            '('.$now.'>=`publ_start` OR `publ_start`=0) AND '
 | 
  
    | 168 |              .            '('.$now.'<=`publ_end` OR `publ_end`=0) '
 | 
  
    | 169 |              .        ')'
 | 
  
    | 170 |              .        (trim($this->sql_where_language) ? $this->sql_where_language : '')
 | 
  
    | 171 |              . ' ORDER BY `p`.`position` ASC';
 | 
  
    | 172 |         if (!($oPages = $database->query($sql))) {
 | 
  
    | 173 |         // error on read database
 | 
  
    | 174 |             throw new Exception(
 | 
  
    | 175 |                 'Error reading table \'pages\' in '.__CLASS__.'::'.
 | 
  
    | 176 |                 __METHOD__.'. Unable to find any page!'
 | 
  
    | 177 |             );
 | 
  
    | 178 |             exit;
 | 
  
    | 179 |         }
 | 
  
    | 180 |         if (
 | 
  
    | 181 |             !($aDefaultPage = $oPages->fetchRow(MYSQLI_ASSOC)) &&
 | 
  
    | 182 |             (!isset($page_id) || !intval($page_id))
 | 
  
    | 183 |         ) {        // No active page found, so show the "under construction page"
 | 
  
    | 184 |             $this->print_under_construction();
 | 
  
    | 185 |             exit;
 | 
  
    | 186 |         }
 | 
  
    | 187 |         // time to set default values
 | 
  
    | 188 |         $this->default_link    = $aDefaultPage['link'];
 | 
  
    | 189 |         $this->default_page_id = $aDefaultPage['page_id'];
 | 
  
    | 190 | //        if (!isset($page_id) || !intval($page_id)) {
 | 
  
    | 191 | //        if (!isset($page_id) || !is_numeric($page_id)) {
 | 
  
    | 192 |           if (!(isset($page_id) && is_numeric($page_id) && is_int($page_id))) {
 | 
  
    | 193 |         // use default page if validation fails
 | 
  
    | 194 |             if(HOMEPAGE_REDIRECTION) {
 | 
  
    | 195 |             // for mandatory redirect request the starting page via accessfile now
 | 
  
    | 196 |                 header("Location: ".$this->page_link($this->default_link));
 | 
  
    | 197 |                 exit;
 | 
  
    | 198 |             }
 | 
  
    | 199 |             // page_id ok, so set the needed variables to use that page
 | 
  
    | 200 |             $page_id = $this->page_id = $this->default_page_id;
 | 
  
    | 201 |         } else {
 | 
  
    | 202 |         // simply use the given page_id because anything is ok
 | 
  
    | 203 |             $this->page_id = $page_id;
 | 
  
    | 204 |         }
 | 
  
    | 205 |         return true;
 | 
  
    | 206 |     }
 | 
  
    | 207 | */
 | 
  
    | 208 | 
 | 
  
    | 209 |     public function get_page_details() {
 | 
  
    | 210 |         global $database;
 | 
  
    | 211 |         if($this->page_id != 0)
 | 
  
    | 212 |         {
 | 
  
    | 213 |             // Query page details
 | 
  
    | 214 |             $sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$this->page_id;
 | 
  
    | 215 |             $get_page = $database->query($sql);
 | 
  
    | 216 |             // Make sure page was found in database
 | 
  
    | 217 |             if($get_page->numRows() == 0) {
 | 
  
    | 218 |                 // Print page not found message
 | 
  
    | 219 |                 exit('Page '.$this->page_id.' not found');
 | 
  
    | 220 |             }
 | 
  
    | 221 |             // Fetch page details
 | 
  
    | 222 |             $this->page = $get_page->fetchRow( MYSQLI_ASSOC );
 | 
  
    | 223 |             // Check if the page language is also the selected language. If not, send headers again.
 | 
  
    | 224 |             if ($this->page['language']!=LANGUAGE) {
 | 
  
    | 225 |                 if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { // check if there is an query-string
 | 
  
    | 226 |                     header("HTTP/1.1 301 Moved Permanently"); // ADDED
 | 
  
    | 227 |                     header('Location: '.$this->page_link($this->page['link']).'?'.$_SERVER['QUERY_STRING'].'&lang='.$this->page['language']);
 | 
  
    | 228 |                 } else {
 | 
  
    | 229 |                     header("HTTP/1.1 301 Moved Permanently"); // ADDED
 | 
  
    | 230 |                     header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']);
 | 
  
    | 231 |                 }
 | 
  
    | 232 |                 exit();
 | 
  
    | 233 |             }
 | 
  
    | 234 |             // Begin code to set details as either variables of constants
 | 
  
    | 235 |             // Page ID
 | 
  
    | 236 |             if(!defined('PAGE_ID')) {define('PAGE_ID', $this->page['page_id']);}
 | 
  
    | 237 |             // Page Code
 | 
  
    | 238 |             if(!defined('PAGE_CODE')) {define('PAGE_CODE', $this->page['page_code']);}
 | 
  
    | 239 |             $this->page_code = PAGE_CODE;
 | 
  
    | 240 |             // Page Title
 | 
  
    | 241 |             if(!defined('PAGE_TITLE')) {define('PAGE_TITLE', $this->page['page_title']);}
 | 
  
    | 242 |             $this->page_title=PAGE_TITLE;
 | 
  
    | 243 |             // Menu Title
 | 
  
    | 244 |             $menu_title = $this->page['menu_title'];
 | 
  
    | 245 |             if($menu_title != '') {
 | 
  
    | 246 |                 if(!defined('MENU_TITLE')) {define('MENU_TITLE', $menu_title);}
 | 
  
    | 247 |             } else {
 | 
  
    | 248 |                 if(!defined('MENU_TITLE')) {define('MENU_TITLE', PAGE_TITLE);}
 | 
  
    | 249 |             }
 | 
  
    | 250 |             $this->menu_title = MENU_TITLE;
 | 
  
    | 251 |             $this->page_icon = $this->page['page_icon'];
 | 
  
    | 252 |             $this->menu_icon_0 = $this->page['menu_icon_0'];
 | 
  
    | 253 |             $this->menu_icon_1 = $this->page['menu_icon_1'];
 | 
  
    | 254 |             $this->tooltip = $this->page['tooltip'];
 | 
  
    | 255 |             // Page parent
 | 
  
    | 256 |             if(!defined('PARENT')) {define('PARENT', $this->page['parent']);}
 | 
  
    | 257 |             $this->parent=$this->page['parent'];
 | 
  
    | 258 |             // Page root parent
 | 
  
    | 259 |             if(!defined('ROOT_PARENT')) {define('ROOT_PARENT', $this->page['root_parent']);}
 | 
  
    | 260 |             $this->root_parent=$this->page['root_parent'];
 | 
  
    | 261 |             // Page level
 | 
  
    | 262 |             if(!defined('LEVEL')) {define('LEVEL', $this->page['level']);}
 | 
  
    | 263 |             $this->level=$this->page['level'];
 | 
  
    | 264 |             // Page position
 | 
  
    | 265 |             $this->level=$this->page['position'];
 | 
  
    | 266 |             // Page visibility
 | 
  
    | 267 |             if(!defined('VISIBILITY')) {define('VISIBILITY', $this->page['visibility']);}
 | 
  
    | 268 |             $this->visibility=$this->page['visibility'];
 | 
  
    | 269 |             // Page trail
 | 
  
    | 270 |             foreach(explode(',', $this->page['page_trail']) AS $pid) {
 | 
  
    | 271 |                 $this->page_trail[$pid]=$pid;
 | 
  
    | 272 |             }
 | 
  
    | 273 |             // Page description
 | 
  
    | 274 |             $this->page_description=$this->page['description'];
 | 
  
    | 275 |             if($this->page_description != '') {
 | 
  
    | 276 |                 define('PAGE_DESCRIPTION', $this->page_description);
 | 
  
    | 277 |             } else {
 | 
  
    | 278 |                 define('PAGE_DESCRIPTION', WEBSITE_DESCRIPTION);
 | 
  
    | 279 |             }
 | 
  
    | 280 |             // Page keywords
 | 
  
    | 281 |             $this->page_keywords=$this->page['keywords'];
 | 
  
    | 282 |             // Page link
 | 
  
    | 283 |             $this->link = $this->page_link($this->page['link']);
 | 
  
    | 284 |             $_SESSION['PAGE_ID'] = $this->page_id;
 | 
  
    | 285 |             $_SESSION['HTTP_REFERER'] = $this->link;
 | 
  
    | 286 | 
 | 
  
    | 287 |         // End code to set details as either variables of constants
 | 
  
    | 288 |         }
 | 
  
    | 289 | 
 | 
  
    | 290 |         // Figure out what template to use
 | 
  
    | 291 |         if(!defined('TEMPLATE')) {
 | 
  
    | 292 |             if(isset($this->page['template']) AND $this->page['template'] != '') {
 | 
  
    | 293 |                 if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {
 | 
  
    | 294 |                     define('TEMPLATE', $this->page['template']);
 | 
  
    | 295 |                 } else {
 | 
  
    | 296 |                     define('TEMPLATE', DEFAULT_TEMPLATE);
 | 
  
    | 297 |                 }
 | 
  
    | 298 |             } else {
 | 
  
    | 299 |                 define('TEMPLATE', DEFAULT_TEMPLATE);
 | 
  
    | 300 |             }
 | 
  
    | 301 |         }
 | 
  
    | 302 |         // Set the template dir
 | 
  
    | 303 |         define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
 | 
  
    | 304 | 
 | 
  
    | 305 |         // Check if user is allowed to view this page
 | 
  
    | 306 |         if($this->page && $this->page_is_visible($this->page) == false) {
 | 
  
    | 307 |             if(VISIBILITY == 'deleted' || VISIBILITY == 'none') {
 | 
  
    | 308 |                 // User isnt allowed on this page so tell them
 | 
  
    | 309 |                 $this->page_access_denied=true;
 | 
  
    | 310 |             } elseif(VISIBILITY == 'private' || VISIBILITY == 'registered') {
 | 
  
    | 311 |                 // Check if the user is authenticated
 | 
  
    | 312 |                 if($this->is_authenticated() == false) {
 | 
  
    | 313 |                     // User needs to login first
 | 
  
    | 314 |                     header("Location: ".WB_URL."/account/login.php?redirect=".$this->link);
 | 
  
    | 315 |                     exit(0);
 | 
  
    | 316 |                 } else {
 | 
  
    | 317 |                     // User isnt allowed on this page so tell them
 | 
  
    | 318 |                     $this->page_access_denied=true;
 | 
  
    | 319 |                 }
 | 
  
    | 320 | 
 | 
  
    | 321 |             }
 | 
  
    | 322 |         }
 | 
  
    | 323 |         // check if there is at least one active section
 | 
  
    | 324 |         if($this->page && $this->page_is_active($this->page) == false) {
 | 
  
    | 325 |             $this->page_no_active_sections=true;
 | 
  
    | 326 |         }
 | 
  
    | 327 |     }
 | 
  
    | 328 | 
 | 
  
    | 329 |     public function get_website_settings()
 | 
  
    | 330 |     {
 | 
  
    | 331 |         global $database;
 | 
  
    | 332 | 
 | 
  
    | 333 |         // set visibility SQL code
 | 
  
    | 334 |         // never show no-vis, hidden or deleted pages
 | 
  
    | 335 |         $this->extra_where_sql = '`visibility`!=\'none\' AND `visibility`!=\'hidden\' AND `visibility`!=\'deleted\'';
 | 
  
    | 336 |         // Set extra private sql code
 | 
  
    | 337 |         if($this->is_authenticated()==false) {
 | 
  
    | 338 |             // if user is not authenticated, don't show private pages either
 | 
  
    | 339 |             $this->extra_where_sql .= ' AND `visibility`!=\'private\'';
 | 
  
    | 340 |             // and 'registered' without frontend login doesn't make much sense!
 | 
  
    | 341 |             if (FRONTEND_LOGIN==false) {
 | 
  
    | 342 |                 $this->extra_where_sql .= ' AND `visibility`!=\'registered\'';
 | 
  
    | 343 |             }
 | 
  
    | 344 |         }
 | 
  
    | 345 |         $this->extra_where_sql .= $this->sql_where_language;
 | 
  
    | 346 | 
 | 
  
    | 347 |         // Work-out if any possible in-line search boxes should be shown
 | 
  
    | 348 |         if(SEARCH == 'public') {
 | 
  
    | 349 |             define('SHOW_SEARCH', true);
 | 
  
    | 350 |         } elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
 | 
  
    | 351 |             define('SHOW_SEARCH', true);
 | 
  
    | 352 |         } elseif(SEARCH == 'private' AND $this->is_authenticated() == true) {
 | 
  
    | 353 |             define('SHOW_SEARCH', true);
 | 
  
    | 354 |         } elseif(SEARCH == 'registered' AND $this->is_authenticated() == true) {
 | 
  
    | 355 |             define('SHOW_SEARCH', true);
 | 
  
    | 356 |         } else {
 | 
  
    | 357 |             define('SHOW_SEARCH', false);
 | 
  
    | 358 |         }
 | 
  
    | 359 |         // Work-out if menu should be shown
 | 
  
    | 360 |         if(!defined('SHOW_MENU')) {
 | 
  
    | 361 |             define('SHOW_MENU', true);
 | 
  
    | 362 |         }
 | 
  
    | 363 |         // Work-out if login menu constants should be set
 | 
  
    | 364 |         if(FRONTEND_LOGIN) {
 | 
  
    | 365 |             // Set login menu constants
 | 
  
    | 366 |             define('LOGIN_URL', WB_URL.'/account/login.php');
 | 
  
    | 367 |             define('LOGOUT_URL', WB_URL.'/account/logout.php');
 | 
  
    | 368 |             define('FORGOT_URL', WB_URL.'/account/forgot.php');
 | 
  
    | 369 |             define('PREFERENCES_URL', WB_URL.'/account/preferences.php');
 | 
  
    | 370 |             define('SIGNUP_URL', WB_URL.'/account/signup.php');
 | 
  
    | 371 |         }
 | 
  
    | 372 |     }
 | 
  
    | 373 | 
 | 
  
    | 374 | /*
 | 
  
    | 375 |  * replace all "[wblink{page_id}]" with real links
 | 
  
    | 376 |  * @param string &$content : reference to global $content
 | 
  
    | 377 |  * @return void
 | 
  
    | 378 |  * @history 100216 17:00:00 optimise errorhandling, speed, SQL-strict
 | 
  
    | 379 |  */
 | 
  
    | 380 |     public function preprocess(&$content)
 | 
  
    | 381 |     {
 | 
  
    | 382 |     //   do nothing
 | 
  
    | 383 |     }
 | 
  
    | 384 | /**
 | 
  
    | 385 |  *
 | 
  
    | 386 |         global $database;
 | 
  
    | 387 |         $replace_list = array();
 | 
  
    | 388 |         $pattern = '/\[wblink([0-9]+)\]/isU';
 | 
  
    | 389 |         if(preg_match_all($pattern,$content,$ids))
 | 
  
    | 390 |         {
 | 
  
    | 391 |             foreach($ids[1] as $key => $page_id)
 | 
  
    | 392 |             {
 | 
  
    | 393 |                 $replace_list[$page_id] = $ids[0][$key];
 | 
  
    | 394 |             }
 | 
  
    | 395 |             foreach($replace_list as $page_id => $tag)
 | 
  
    | 396 |             {
 | 
  
    | 397 |                 $sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.(int)$page_id;
 | 
  
    | 398 |                 $link = $database->get_one($sql);
 | 
  
    | 399 |                 if(!is_null($link))
 | 
  
    | 400 |                 {
 | 
  
    | 401 |                     $link = $this->page_link($link);
 | 
  
    | 402 |                     $content = str_replace($tag, $link, $content);
 | 
  
    | 403 |                 }
 | 
  
    | 404 |             }
 | 
  
    | 405 |         }
 | 
  
    | 406 |     }
 | 
  
    | 407 |  */
 | 
  
    | 408 | 
 | 
  
    | 409 | /*
 | 
  
    | 410 |     function preprocess(&$content) {
 | 
  
    | 411 |         global $database;
 | 
  
    | 412 |         // Replace [wblink--PAGE_ID--] with real link
 | 
  
    | 413 |         $pattern = '/\[wblink(.+?)\]/s';
 | 
  
    | 414 |         preg_match_all($pattern,$content,$ids);
 | 
  
    | 415 |         foreach($ids[1] AS $page_id) {
 | 
  
    | 416 |             $pattern = '/\[wblink'.$page_id.'\]/s';
 | 
  
    | 417 |             // Get page link
 | 
  
    | 418 |             $get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
 | 
  
    | 419 |             $fetch_link = $get_link->fetchRow();
 | 
  
    | 420 |             $link = $this->page_link($fetch_link['link']);
 | 
  
    | 421 |             $content = preg_replace($pattern,$link,$content);
 | 
  
    | 422 |         }
 | 
  
    | 423 |     }
 | 
  
    | 424 | */
 | 
  
    | 425 | 
 | 
  
    | 426 |     public function menu() {
 | 
  
    | 427 |         global $wb;
 | 
  
    | 428 |        if (!isset($wb->menu_number)) {
 | 
  
    | 429 |            $wb->menu_number = 1;
 | 
  
    | 430 |        }
 | 
  
    | 431 |        if (!isset($wb->menu_start_level)) {
 | 
  
    | 432 |            $wb->menu_start_level = 0;
 | 
  
    | 433 |        }
 | 
  
    | 434 |        if (!isset($wb->menu_recurse)) {
 | 
  
    | 435 |            $wb->menu_recurse = -1;
 | 
  
    | 436 |        }
 | 
  
    | 437 |        if (!isset($wb->menu_collapse)) {
 | 
  
    | 438 |            $wb->menu_collapse = true;
 | 
  
    | 439 |        }
 | 
  
    | 440 |        if (!isset($wb->menu_item_template)) {
 | 
  
    | 441 |            $wb->menu_item_template = '<li><span[class]>[a] [menu_title] [/a]</span>';
 | 
  
    | 442 |        }
 | 
  
    | 443 |        if (!isset($wb->menu_item_footer)) {
 | 
  
    | 444 |            $wb->menu_item_footer = '</li>';
 | 
  
    | 445 |        }
 | 
  
    | 446 |        if (!isset($wb->menu_header)) {
 | 
  
    | 447 |            $wb->menu_header = '<ul>';
 | 
  
    | 448 |        }
 | 
  
    | 449 |        if (!isset($wb->menu_footer)) {
 | 
  
    | 450 |            $wb->menu_footer = '</ul>';
 | 
  
    | 451 |        }
 | 
  
    | 452 |        if (!isset($wb->menu_default_class)) {
 | 
  
    | 453 |            $wb->menu_default_class = ' class="menu_default"';
 | 
  
    | 454 |        }
 | 
  
    | 455 |        if (!isset($wb->menu_current_class)) {
 | 
  
    | 456 |            $wb->menu_current_class = ' class="menu_current"';
 | 
  
    | 457 |        }
 | 
  
    | 458 |        if (!isset($wb->menu_parent)) {
 | 
  
    | 459 |            $wb->menu_parent = 0;
 | 
  
    | 460 |        }
 | 
  
    | 461 |        $wb->show_menu();
 | 
  
    | 462 |     }
 | 
  
    | 463 | 
 | 
  
    | 464 |     public function show_menu() {
 | 
  
    | 465 |         global $database;
 | 
  
    | 466 |         if ($this->menu_start_level>0) {
 | 
  
    | 467 |             $key_array=array_keys($this->page_trail);
 | 
  
    | 468 |             if (isset($key_array[$this->menu_start_level-1])) {
 | 
  
    | 469 |                 $real_start=$key_array[$this->menu_start_level-1];
 | 
  
    | 470 |                 $this->menu_parent=$real_start;
 | 
  
    | 471 |                 $this->menu_start_level=0;
 | 
  
    | 472 |             } else {
 | 
  
    | 473 |                 return;
 | 
  
    | 474 |             }
 | 
  
    | 475 |         }
 | 
  
    | 476 |         if ($this->menu_recurse==0)
 | 
  
    | 477 |            return;
 | 
  
    | 478 |         // Check if we should add menu number check to query
 | 
  
    | 479 |         if($this->menu_parent == 0) {
 | 
  
    | 480 |             $menu_number = '`menu`='.intval($this->menu_number);
 | 
  
    | 481 |         } else {
 | 
  
    | 482 |             $menu_number = '1';
 | 
  
    | 483 |         }
 | 
  
    | 484 |         // Query pages
 | 
  
    | 485 |         $sql  = 'SELECT `page_id`,`menu_title`,`page_title`,`link`,`target`,`level`,';
 | 
  
    | 486 |         $sql .=        '`visibility`,viewing_groups,viewing_users ';
 | 
  
    | 487 |         $sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
 | 
  
    | 488 |         $sql .= 'WHERE `parent`='.(int)$this->menu_parent.' AND '.$menu_number.' AND '.$this->extra_where_sql.' ';
 | 
  
    | 489 |         $sql .= 'ORDER BY `position` ASC';
 | 
  
    | 490 |         $query_menu = $database->query($sql);
 | 
  
    | 491 |         // Check if there are any pages to show
 | 
  
    | 492 |         if($query_menu->numRows() > 0) {
 | 
  
    | 493 |             // Print menu header
 | 
  
    | 494 |             echo "\n".$this->menu_header;
 | 
  
    | 495 |             // Loop through pages
 | 
  
    | 496 |             while($page = $query_menu->fetchRow()) {
 | 
  
    | 497 |                 // check whether to show this menu-link
 | 
  
    | 498 |                 if($this->page_is_active($page)==false && $page['link']!=$this->default_link && !INTRO_PAGE) {
 | 
  
    | 499 |                     continue; // no active sections
 | 
  
    | 500 |                 }
 | 
  
    | 501 |                 if($this->page_is_visible($page)==false) {
 | 
  
    | 502 |                     if($page['visibility'] != 'registered') // special case: page_to_visible() check wheter to show the page contents, but the menu should be visible allways
 | 
  
    | 503 |                         continue;
 | 
  
    | 504 |                 }
 | 
  
    | 505 |                 // Create vars
 | 
  
    | 506 |                 $vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');
 | 
  
    | 507 |                 // Work-out class
 | 
  
    | 508 |                 if($page['page_id'] == PAGE_ID) {
 | 
  
    | 509 |                     $class = $this->menu_current_class;
 | 
  
    | 510 |                 } else {
 | 
  
    | 511 |                     $class = $this->menu_default_class;
 | 
  
    | 512 |                 }
 | 
  
    | 513 |                 // Check if link is same as first page link, and if so change to WB URL
 | 
  
    | 514 |                 if($page['link'] == $this->default_link AND !INTRO_PAGE) {
 | 
  
    | 515 |                     $link = WB_URL;
 | 
  
    | 516 |                 } else {
 | 
  
    | 517 |                     $link = $this->page_link($page['link']);
 | 
  
    | 518 |                 }
 | 
  
    | 519 |                 // Create values
 | 
  
    | 520 |                 $values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', $page['menu_title'], $page['page_title']);
 | 
  
    | 521 |                 // Replace vars with value and print
 | 
  
    | 522 |                 echo "\n".str_replace($vars, $values, $this->menu_item_template);
 | 
  
    | 523 |                 // Generate sub-menu
 | 
  
    | 524 |                 if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) {
 | 
  
    | 525 |                     $this->menu_recurse--;
 | 
  
    | 526 |                     $this->menu_parent=$page['page_id'];
 | 
  
    | 527 |                     $this->show_menu();
 | 
  
    | 528 |                 }
 | 
  
    | 529 |                 echo "\n".$this->menu_item_footer;
 | 
  
    | 530 |             }
 | 
  
    | 531 |             // Print menu footer
 | 
  
    | 532 |             echo "\n".$this->menu_footer;
 | 
  
    | 533 |         }
 | 
  
    | 534 |     }
 | 
  
    | 535 | 
 | 
  
    | 536 | 
 | 
  
    | 537 |     // Function to show the "Under Construction" page
 | 
  
    | 538 |     public function print_under_construction() {
 | 
  
    | 539 |         $this->ShowMaintainScreen('new');
 | 
  
    | 540 |         exit();
 | 
  
    | 541 | /*
 | 
  
    | 542 |         global $MESSAGE;
 | 
  
    | 543 |         require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
 | 
  
    | 544 |         echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 | 
  
    | 545 |         <head><title>'.$MESSAGE['GENERIC_WEBSITE_UNDER_CONSTRUCTION'].'</title>
 | 
  
    | 546 |         <style type="text/css"><!-- body{ font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px; background-image: url("'.THEME_URL.'/images/background.png");background-repeat: repeat-x; background-color: #A8BCCB; text-align: center; }
 | 
  
    | 547 |         h1 { margin: 0; padding: 0; font-size: 18px; color: #000; text-transform: uppercase;
 | 
  
    | 548 | }--></style></head><body>
 | 
  
    | 549 |         <br /><h1>'.$MESSAGE['GENERIC_WEBSITE_UNDER_CONSTRUCTION'].'</h1><br />
 | 
  
    | 550 |         '.$MESSAGE['GENERIC_PLEASE_CHECK_BACK_SOON'].'</body></html>';
 | 
  
    | 551 | */
 | 
  
    | 552 |     }
 | 
  
    | 553 | 
 | 
  
    | 554 |     // Function to show the "Under Construction" page
 | 
  
    | 555 |     public function print_missing_frontend_login() {
 | 
  
    | 556 |         global $MESSAGE, $MENU, $TEXT;
 | 
  
    | 557 |         require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
 | 
  
    | 558 |         echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 | 
  
    | 559 |         <head><title>'.$MENU['LOGIN'].' '.$TEXT['DISABLED'].'</title>
 | 
  
    | 560 |         <style type="text/css"><!-- body{ font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px; background-image: url("'.THEME_URL.'/images/background.png");background-repeat: repeat-x; background-color: #A8BCCB; text-align: center; }
 | 
  
    | 561 |         h1 { margin: 0; padding: 0; font-size: 18px; color: #000; text-transform: uppercase;
 | 
  
    | 562 | }--></style></head><body>
 | 
  
    | 563 |         <br /><h1>'.($MENU['LOGIN'].' '.$TEXT['DISABLED']).'</h1><br />
 | 
  
    | 564 |         '.$MESSAGE['GENERIC_PLEASE_CHECK_BACK_SOON'].'</body></html>';
 | 
  
    | 565 |     }
 | 
  
    | 566 | 
 | 
  
    | 567 | }
 |