| 1 | <?php
 | 
  
    | 2 | /**$extra_sql
 | 
  
    | 3 |  *
 | 
  
    | 4 |  * @category        framework
 | 
  
    | 5 |  * @package         frontend.functions
 | 
  
    | 6 |  * @author          Ryan Djurovich, 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.x
 | 
  
    | 11 |  * @requirements    PHP 5.2.2 and higher
 | 
  
    | 12 |  * @version         $Id: frontend.functions.php 1701 2012-08-27 14:58:44Z Luisehahne $
 | 
  
    | 13 |  * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/frontend.functions.php $
 | 
  
    | 14 |  * @lastmodified    $Date: 2012-08-27 16:58:44 +0200 (Mon, 27 Aug 2012) $
 | 
  
    | 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 | // compatibility mode for versions before 2.8.1
 | 
  
    | 25 | 	if(isset($wb)) {$admin = $wb; }
 | 
  
    | 26 | 	if(isset($wb->default_link)) { $default_link = $wb->default_link; }
 | 
  
    | 27 | 	if(isset($wb->page_trail)) {$page_trail = $wb->page_trail; }
 | 
  
    | 28 | 	if(isset($wb->page_description)) {$page_description = $wb->page_description;}
 | 
  
    | 29 | 	if(isset($wb->page_keywords)) {$page_keywords = $wb->page_keywords;}
 | 
  
    | 30 | 	if(isset($wb->link)) {$page_link = $wb->link;}
 | 
  
    | 31 | 
 | 
  
    | 32 | 	$include_head_link_css = '';
 | 
  
    | 33 | 	$include_body_links    = '';
 | 
  
    | 34 | 	$include_head_links    = '';
 | 
  
    | 35 | 
 | 
  
    | 36 | // workout to included frontend.css, fronten.js and frontend_body.js in snippets
 | 
  
    | 37 | 	$sql  = 'SELECT `directory` FROM `'.TABLE_PREFIX.'addons` ';
 | 
  
    | 38 | 	$sql .= 'WHERE `type`=\'module\' AND `function`=\'snippet\'';
 | 
  
    | 39 | 	if(($resSnippets = $database->query($sql))) {
 | 
  
    | 40 | 		while($recSnippet = $resSnippets->fetchRow()) {
 | 
  
    | 41 | 			$module_dir = $recSnippet['directory'];
 | 
  
    | 42 | 			if (file_exists(WB_PATH.'/modules/'.$module_dir.'/include.php')) {
 | 
  
    | 43 | 				include(WB_PATH.'/modules/'.$module_dir.'/include.php');
 | 
  
    | 44 | 			// check if frontend.css file needs to be included into the <head></head> of index.php
 | 
  
    | 45 | 				if( file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend.css')) {
 | 
  
    | 46 | 					$include_head_link_css .= '<link href="'.WB_URL.'/modules/'.$module_dir.'/frontend.css"';
 | 
  
    | 47 | 					$include_head_link_css .= ' rel="stylesheet" type="text/css" media="screen" />'."\n";
 | 
  
    | 48 | 					$include_head_file = 'frontend.css';
 | 
  
    | 49 | 				}
 | 
  
    | 50 | 			// check if frontend.js file needs to be included into the <body></body> of index.php
 | 
  
    | 51 | 				if(file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend.js')) {
 | 
  
    | 52 | 					$include_head_links .= '<script src="'.WB_URL.'/modules/'.$module_dir.'/frontend.js" type="text/javascript"></script>'."\n";
 | 
  
    | 53 | 					$include_head_file = 'frontend.js';
 | 
  
    | 54 | 				}
 | 
  
    | 55 | 			// check if frontend_body.js file needs to be included into the <body></body> of index.php
 | 
  
    | 56 | 				if(file_exists(WB_PATH .'/modules/'.$module_dir.'/frontend_body.js')) {
 | 
  
    | 57 | 					$include_body_links .= '<script src="'.WB_URL.'/modules/'.$module_dir.'/frontend_body.js" type="text/javascript"></script>'."\n";
 | 
  
    | 58 | 					$include_body_file = 'frontend_body.js';
 | 
  
    | 59 | 				}
 | 
  
    | 60 | 			}
 | 
  
    | 61 | 		}
 | 
  
    | 62 | 	}
 | 
  
    | 63 | 
 | 
  
    | 64 | // Frontend functions
 | 
  
    | 65 | if(!function_exists('page_link')) {
 | 
  
    | 66 | 	/**
 | 
  
    | 67 | 	 * generate full qualified URL from relative link based on pages_dir
 | 
  
    | 68 | 	 * @param string $link
 | 
  
    | 69 | 	 * @return string
 | 
  
    | 70 | 	 */
 | 
  
    | 71 | 	function page_link($link) {
 | 
  
    | 72 | 		return $GLOBALS['wb']->page_link($link);
 | 
  
    | 73 | 	}
 | 
  
    | 74 | }
 | 
  
    | 75 | 
 | 
  
    | 76 | if (!function_exists('get_page_link')) {
 | 
  
    | 77 |     /**
 | 
  
    | 78 | 	 * get relative link from database based on pages_dir
 | 
  
    | 79 | 	 * @global <type> $database
 | 
  
    | 80 | 	 * @param <type> $id
 | 
  
    | 81 | 	 * @return <type>
 | 
  
    | 82 | 	 */
 | 
  
    | 83 | 	function get_page_link( $id )
 | 
  
    | 84 |     {
 | 
  
    | 85 |         global $database;
 | 
  
    | 86 |         $sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$id;
 | 
  
    | 87 |         $link = $database->get_one( $sql );
 | 
  
    | 88 |         return $link;
 | 
  
    | 89 |     }
 | 
  
    | 90 | }
 | 
  
    | 91 | 
 | 
  
    | 92 | //function to highlight search results
 | 
  
    | 93 | if(!function_exists('search_highlight')) {
 | 
  
    | 94 | 	/**
 | 
  
    | 95 | 	 *
 | 
  
    | 96 | 	 * @staticvar boolean $string_ul_umlaut
 | 
  
    | 97 | 	 * @staticvar boolean $string_ul_regex
 | 
  
    | 98 | 	 * @param string $foo
 | 
  
    | 99 | 	 * @param array $arr_string
 | 
  
    | 100 | 	 * @return string
 | 
  
    | 101 | 	 */
 | 
  
    | 102 | 	function search_highlight($foo='', $arr_string=array()) {
 | 
  
    | 103 | 		require_once(WB_PATH.'/framework/functions.php');
 | 
  
    | 104 | 		static $string_ul_umlaut = FALSE;
 | 
  
    | 105 | 		static $string_ul_regex = FALSE;
 | 
  
    | 106 | 		if($string_ul_umlaut === FALSE || $string_ul_regex === FALSE) {
 | 
  
    | 107 | 			require(WB_PATH.'/search/search_convert.php');
 | 
  
    | 108 | 		}
 | 
  
    | 109 | 		$foo = entities_to_umlauts($foo, 'UTF-8');
 | 
  
    | 110 | 		array_walk($arr_string, create_function('&$v,$k','$v = preg_quote($v, \'~\');'));
 | 
  
    | 111 | 		$search_string = implode("|", $arr_string);
 | 
  
    | 112 | 		$string = str_replace($string_ul_umlaut, $string_ul_regex, $search_string);
 | 
  
    | 113 | 		// the highlighting
 | 
  
    | 114 | 		// match $string, but not inside <style>...</style>, <script>...</script>, <!--...--> or HTML-Tags
 | 
  
    | 115 | 		// Also droplet tags are now excluded from highlighting.
 | 
  
    | 116 | 		// split $string into pieces - "cut away" styles, scripts, comments, HTML-tags and eMail-addresses
 | 
  
    | 117 | 		// we have to cut <pre> and <code> as well.
 | 
  
    | 118 | 		// for HTML-Tags use <(?:[^<]|<.*>)*> which will match strings like <input ... value="<b>value</b>" >
 | 
  
    | 119 | 		$matches = preg_split("~(\[\[.*\]\]|<style.*</style>|<script.*</script>|<pre.*</pre>|<code.*</code>|<!--.*-->|<(?:[^<]|<.*>)*>|\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}\b)~iUs",$foo,-1,(PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY));
 | 
  
    | 120 | 		if(is_array($matches) && $matches != array()) {
 | 
  
    | 121 | 			$foo = "";
 | 
  
    | 122 | 			foreach($matches as $match) {
 | 
  
    | 123 | 				if($match{0}!="<" && !preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,8}$/i', $match) && !preg_match('~\[\[.*\]\]~', $match)) {
 | 
  
    | 124 | 					$match = str_replace(array('<', '>', '&', '"', ''', ' '), array('<', '>', '&', '"', '\'', "\xC2\xA0"), $match);
 | 
  
    | 125 | 					$match = preg_replace('~('.$string.')~ui', '_span class=_highlight__$1_/span_',$match);
 | 
  
    | 126 | 					$match = str_replace(array('&', '<', '>', '"', '\'', "\xC2\xA0"), array('&', '<', '>', '"', ''', ' '), $match);
 | 
  
    | 127 | 					$match = str_replace(array('_span class=_highlight__', '_/span_'), array('<span class="highlight">', '</span>'), $match);
 | 
  
    | 128 | 				}
 | 
  
    | 129 | 				$foo .= $match;
 | 
  
    | 130 | 			}
 | 
  
    | 131 | 		}
 | 
  
    | 132 | 
 | 
  
    | 133 | 		if(DEFAULT_CHARSET != 'utf-8') {
 | 
  
    | 134 | 			$foo = umlauts_to_entities($foo, 'UTF-8');
 | 
  
    | 135 | 		}
 | 
  
    | 136 | 		return $foo;
 | 
  
    | 137 | 	}
 | 
  
    | 138 | }
 | 
  
    | 139 | 
 | 
  
    | 140 | if (!function_exists('page_menu')) {
 | 
  
    | 141 | 	/**
 | 
  
    | 142 | 	 * Old menu generator
 | 
  
    | 143 | 	 * @deprecated from WB 2.9.x and up
 | 
  
    | 144 | 	 * @global <type> $wb
 | 
  
    | 145 | 	 * @param <type> $parent
 | 
  
    | 146 | 	 * @param <type> $menu_number
 | 
  
    | 147 | 	 * @param <type> $item_template
 | 
  
    | 148 | 	 * @param <type> $menu_header
 | 
  
    | 149 | 	 * @param <type> $menu_footer
 | 
  
    | 150 | 	 * @param <type> $default_class
 | 
  
    | 151 | 	 * @param <type> $current_class
 | 
  
    | 152 | 	 * @param <type> $recurse
 | 
  
    | 153 | 	 */
 | 
  
    | 154 | 	function page_menu($parent = 0, $menu_number = 1, $item_template = '<li[class]>[a] [menu_title] [/a]</li>', $menu_header = '<ul>', $menu_footer = '</ul>', $default_class = ' class="menu_default"', $current_class = ' class="menu_current"', $recurse = LEVEL) {
 | 
  
    | 155 | 		global $wb;
 | 
  
    | 156 | 		$wb->menu_number=$menu_number;
 | 
  
    | 157 | 		$wb->menu_item_template=$item_template;
 | 
  
    | 158 | 		$wb->menu_item_footer='';
 | 
  
    | 159 | 		$wb->menu_parent = $parent;
 | 
  
    | 160 | 		$wb->menu_header = $menu_header;
 | 
  
    | 161 | 		$wb->menu_footer = $menu_footer;
 | 
  
    | 162 | 		$wb->menu_default_class = $default_class;
 | 
  
    | 163 | 		$wb->menu_current_class = $current_class;
 | 
  
    | 164 | 		$wb->menu_recurse = $recurse+2;
 | 
  
    | 165 | 		$wb->menu();
 | 
  
    | 166 | 		unset($wb->menu_parent);
 | 
  
    | 167 | 		unset($wb->menu_number);
 | 
  
    | 168 | 		unset($wb->menu_item_template);
 | 
  
    | 169 | 		unset($wb->menu_item_footer);
 | 
  
    | 170 | 		unset($wb->menu_header);
 | 
  
    | 171 | 		unset($wb->menu_footer);
 | 
  
    | 172 | 		unset($wb->menu_default_class);
 | 
  
    | 173 | 		unset($wb->menu_current_class);
 | 
  
    | 174 | 		unset($wb->menu_start_level);
 | 
  
    | 175 | 		unset($wb->menu_collapse);
 | 
  
    | 176 | 		unset($wb->menu_recurse);
 | 
  
    | 177 | 	}
 | 
  
    | 178 | }
 | 
  
    | 179 | 
 | 
  
    | 180 | if (!function_exists('show_menu')) {
 | 
  
    | 181 | 	/**
 | 
  
    | 182 | 	 * Old menu generator
 | 
  
    | 183 | 	 * @deprecated from WB 2.9.x and up
 | 
  
    | 184 | 	 * @global  $wb
 | 
  
    | 185 | 	 * @param <type> $menu_number
 | 
  
    | 186 | 	 * @param <type> $start_level
 | 
  
    | 187 | 	 * @param <type> $recurse
 | 
  
    | 188 | 	 * @param <type> $collapse
 | 
  
    | 189 | 	 * @param <type> $item_template
 | 
  
    | 190 | 	 * @param <type> $item_footer
 | 
  
    | 191 | 	 * @param <type> $menu_header
 | 
  
    | 192 | 	 * @param <type> $menu_footer
 | 
  
    | 193 | 	 * @param <type> $default_class
 | 
  
    | 194 | 	 * @param <type> $current_class
 | 
  
    | 195 | 	 * @param <type> $parent
 | 
  
    | 196 | 	 */
 | 
  
    | 197 | 	function show_menu($menu_number = NULL, $start_level=NULL, $recurse = NULL, $collapse = NULL, $item_template = NULL, $item_footer = NULL, $menu_header = NULL, $menu_footer = NULL, $default_class = NULL, $current_class = NULL, $parent = NULL) {
 | 
  
    | 198 | 		global $wb;
 | 
  
    | 199 | 		if (isset($menu_number))
 | 
  
    | 200 | 			$wb->menu_number=$menu_number;
 | 
  
    | 201 | 		if (isset($start_level))
 | 
  
    | 202 | 			$wb->menu_start_level=$start_level;
 | 
  
    | 203 | 		if (isset($recurse))
 | 
  
    | 204 | 			$wb->menu_recurse=$recurse;
 | 
  
    | 205 | 		if (isset($collapse))
 | 
  
    | 206 | 			$wb->menu_collapse=$collapse;
 | 
  
    | 207 | 		if (isset($item_template))
 | 
  
    | 208 | 			$wb->menu_item_template=$item_template;
 | 
  
    | 209 | 		if (isset($item_footer))
 | 
  
    | 210 | 			$wb->menu_item_footer=$item_footer;
 | 
  
    | 211 | 		if (isset($menu_header))
 | 
  
    | 212 | 			$wb->menu_header=$menu_header;
 | 
  
    | 213 | 		if (isset($menu_footer))
 | 
  
    | 214 | 			$wb->menu_footer=$menu_footer;
 | 
  
    | 215 | 		if (isset($default_class))
 | 
  
    | 216 | 			$wb->menu_default_class=$default_class;
 | 
  
    | 217 | 		if (isset($current_class))
 | 
  
    | 218 | 			$wb->menu_current_class=$current_class;
 | 
  
    | 219 | 		if (isset($parent))
 | 
  
    | 220 | 			$wb->menu_parent=$parent;
 | 
  
    | 221 | 		$wb->menu();
 | 
  
    | 222 | 		unset($wb->menu_recurse);
 | 
  
    | 223 | 		unset($wb->menu_parent);
 | 
  
    | 224 | 		unset($wb->menu_start_level);
 | 
  
    | 225 | 	}
 | 
  
    | 226 | }
 | 
  
    | 227 | 
 | 
  
    | 228 | if (!function_exists('page_content')) {
 | 
  
    | 229 | 	/**
 | 
  
    | 230 | 	 *
 | 
  
    | 231 | 	 * @global array $TEXT
 | 
  
    | 232 | 	 * @global array $MENU
 | 
  
    | 233 | 	 * @global array $HEADING
 | 
  
    | 234 | 	 * @global array $MESSAGE
 | 
  
    | 235 | 	 * @global array $globals several global vars
 | 
  
    | 236 | 	 * @global datadase $database
 | 
  
    | 237 | 	 * @global wb $wb
 | 
  
    | 238 | 	 * @global string $global_name
 | 
  
    | 239 | 	 * @param int $block
 | 
  
    | 240 | 	 * @param boolean true to print $content, false return $content
 | 
  
    | 241 | 	 * @return void
 | 
  
    | 242 | 	 */
 | 
  
    | 243 | 	function page_content($block = 1, $echo=true) {
 | 
  
    | 244 | 		// Get outside objects
 | 
  
    | 245 | 		global $TEXT,$MENU,$HEADING,$MESSAGE;
 | 
  
    | 246 | 		global $globals;
 | 
  
    | 247 | 		global $database;
 | 
  
    | 248 | 		global $wb;
 | 
  
    | 249 | 		$admin = $wb;
 | 
  
    | 250 | 		if ($wb->page_access_denied==true) {
 | 
  
    | 251 | 	        echo $MESSAGE['FRONTEND_SORRY_NO_VIEWING_PERMISSIONS'];
 | 
  
    | 252 | 			return;
 | 
  
    | 253 | 		}
 | 
  
    | 254 | 		if ($wb->page_no_active_sections==true) {
 | 
  
    | 255 | 	        echo $MESSAGE['FRONTEND_SORRY_NO_ACTIVE_SECTIONS'];
 | 
  
    | 256 | 			return;
 | 
  
    | 257 | 		}
 | 
  
    | 258 | 		if(isset($globals) AND is_array($globals)) {
 | 
  
    | 259 |             foreach($globals AS $global_name) {
 | 
  
    | 260 |                 global $$global_name;
 | 
  
    | 261 | 			}
 | 
  
    | 262 |         }
 | 
  
    | 263 | 		// Make sure block is numeric
 | 
  
    | 264 | 		if( ($block = intval($block)) == 0 ) { $block = 1; }
 | 
  
    | 265 | 		// Include page content
 | 
  
    | 266 | 		if(!defined('PAGE_CONTENT') OR $block!=1)
 | 
  
    | 267 |         {
 | 
  
    | 268 | 			$page_id = intval($wb->page_id);
 | 
  
    | 269 | /* move to class.frontend
 | 
  
    | 270 |             // set session variable to save page_id only if PAGE_CONTENT is empty
 | 
  
    | 271 |             $_SESSION['PAGE_ID'] = !isset($_SESSION['PAGE_ID']) ? $page_id : $_SESSION['PAGE_ID'];
 | 
  
    | 272 |             // set to new value if page_id changed and not 0
 | 
  
    | 273 |             if(($page_id != 0) && ($_SESSION['PAGE_ID'] <> $page_id))
 | 
  
    | 274 |             {
 | 
  
    | 275 | 	            $_SESSION['PAGE_ID'] = $page_id;
 | 
  
    | 276 |             }
 | 
  
    | 277 | */
 | 
  
    | 278 | 		// First get all sections for this page
 | 
  
    | 279 | 			$sql  = 'SELECT `section_id`, `module`, `publ_start`, `publ_end` ';
 | 
  
    | 280 | 			$sql .= 'FROM `'.TABLE_PREFIX.'sections` ';
 | 
  
    | 281 | 			$sql .= 'WHERE `page_id`='.$page_id.' AND `block`='.$block.' ';
 | 
  
    | 282 | 			$sql .= 'ORDER BY `position`';
 | 
  
    | 283 | 			if( !($query_sections = $database->query($sql)) ) { return; }
 | 
  
    | 284 | 		// If none were found, check if default content is supposed to be shown
 | 
  
    | 285 | 			if($query_sections->numRows() == 0) {
 | 
  
    | 286 | 				if($wb->default_block_content == 'none') { return; }
 | 
  
    | 287 | 				if (is_numeric($wb->default_block_content)) {
 | 
  
    | 288 | 					$page_id = $wb->default_block_content;
 | 
  
    | 289 | 				} else {
 | 
  
    | 290 | 					$page_id = $wb->default_page_id;
 | 
  
    | 291 | 				}
 | 
  
    | 292 | 				$sql  = 'SELECT `section_id`, `module`, `publ_start`, `publ_end` ';
 | 
  
    | 293 | 				$sql .= 'FROM `'.TABLE_PREFIX.'sections` ';
 | 
  
    | 294 | 				$sql .= 'WHERE `page_id`='.$page_id.' AND `block`='.$block.' ';
 | 
  
    | 295 | 				$sql .= 'ORDER BY `position`';
 | 
  
    | 296 | 				if( !($query_sections = $database->query($sql)) ) { return; }
 | 
  
    | 297 | 				// Still no cotent found? Give it up, there's just nothing to show!
 | 
  
    | 298 | 				if($query_sections->numRows() == 0) { return; }
 | 
  
    | 299 | 			}
 | 
  
    | 300 | 			// Loop through them and include their module file
 | 
  
    | 301 | 			while($section = $query_sections->fetchRow()) {
 | 
  
    | 302 | 				// skip this section if it is out of publication-date
 | 
  
    | 303 | 				$now = time();
 | 
  
    | 304 | 				if( !(($now<=$section['publ_end'] || $section['publ_end']==0) && ($now>=$section['publ_start'] || $section['publ_start']==0)) ) {
 | 
  
    | 305 | 					continue;
 | 
  
    | 306 | 				}
 | 
  
    | 307 | 				$section_id = $section['section_id'];
 | 
  
    | 308 | 				$module = $section['module'];
 | 
  
    | 309 | 				// make a anchor for every section.
 | 
  
    | 310 | 				if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') {
 | 
  
    | 311 | 					echo '<a class="section_anchor" id="'.SEC_ANCHOR.$section_id.'" name="'.SEC_ANCHOR.$section_id.'"></a>';
 | 
  
    | 312 | 				}
 | 
  
    | 313 |                 // check if module exists - feature: write in errorlog
 | 
  
    | 314 | 				if(file_exists(WB_PATH.'/modules/'.$module.'/view.php')) {
 | 
  
    | 315 | 				// fetch content -- this is where to place possible output-filters (before highlighting)
 | 
  
    | 316 | 					ob_start(); // fetch original content
 | 
  
    | 317 | 					require(WB_PATH.'/modules/'.$module.'/view.php');
 | 
  
    | 318 | 					$content = ob_get_clean();
 | 
  
    | 319 | 				} else {
 | 
  
    | 320 | 					continue;
 | 
  
    | 321 | 				}
 | 
  
    | 322 | 				// highlights searchresults
 | 
  
    | 323 | 				if(isset($_GET['searchresult']) && is_numeric($_GET['searchresult']) && !isset($_GET['nohighlight']) && isset($_GET['sstring']) && !empty($_GET['sstring'])) {
 | 
  
    | 324 | 					$arr_string = explode(" ", $_GET['sstring']);
 | 
  
    | 325 | 					if($_GET['searchresult']==2) { // exact match
 | 
  
    | 326 | 						$arr_string[0] = str_replace("_", " ", $arr_string[0]);
 | 
  
    | 327 | 					}
 | 
  
    | 328 | 					echo search_highlight($content, $arr_string);
 | 
  
    | 329 | 				} elseif($echo==true) {
 | 
  
    | 330 | 					echo $content;
 | 
  
    | 331 | 				} else {
 | 
  
    | 332 | 				    return $content;
 | 
  
    | 333 | 				}
 | 
  
    | 334 | 			}
 | 
  
    | 335 | 		} else {
 | 
  
    | 336 | 			require(PAGE_CONTENT);
 | 
  
    | 337 | 		}
 | 
  
    | 338 | 	}
 | 
  
    | 339 | }
 | 
  
    | 340 | 
 | 
  
    | 341 | if (!function_exists('show_content')) {
 | 
  
    | 342 | 	function show_content($block=1) {
 | 
  
    | 343 | 		page_content($block);
 | 
  
    | 344 | 	}
 | 
  
    | 345 | }
 | 
  
    | 346 | 
 | 
  
    | 347 | if (!function_exists('show_breadcrumbs'))
 | 
  
    | 348 | {
 | 
  
    | 349 | 	function show_breadcrumbs($sep = ' » ',$level = 0, $links = true, $depth = -1, $title = '')
 | 
  
    | 350 |     {
 | 
  
    | 351 | 		global $wb,$database,$MENU;
 | 
  
    | 352 | 		$page_id = $wb->page_id;
 | 
  
    | 353 |         $title = (trim($title) == '') ? $MENU['BREADCRUMB'] : $title;
 | 
  
    | 354 | 		if ($page_id != 0)
 | 
  
    | 355 | 		{
 | 
  
    | 356 | 			$counter = 0;
 | 
  
    | 357 |             // get links as array
 | 
  
    | 358 |             $bread_crumbs = $wb->page_trail;
 | 
  
    | 359 |             $count = sizeof($bread_crumbs);
 | 
  
    | 360 |             // level can't be greater than sum of links
 | 
  
    | 361 |             $level = ($count <= $level ) ? $count-1 : $level;
 | 
  
    | 362 |             // set level from which to show, delete indexes in array
 | 
  
    | 363 | 			$crumbs = array_slice($bread_crumbs, $level );
 | 
  
    | 364 |             $depth = ($depth <= 0) ? sizeof($crumbs) : $depth;
 | 
  
    | 365 |             // if empty array, set orginal links
 | 
  
    | 366 |             $crumbs = (!empty($crumbs)) ?  $crumbs : $wb->page_trail;
 | 
  
    | 367 |             $total_crumbs = ( ($depth <= 0) || ($depth > sizeof($crumbs)) ) ? sizeof($crumbs) : $depth;
 | 
  
    | 368 |             print '<div class="breadcrumb"><span class="title">'.$title.'</span>';
 | 
  
    | 369 |           //  print_r($crumbs);
 | 
  
    | 370 | 			foreach ($crumbs as $temp)
 | 
  
    | 371 |             {
 | 
  
    | 372 |                 if($counter == $depth) { break; }
 | 
  
    | 373 |                 // set links and separator
 | 
  
    | 374 | 					$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$temp;
 | 
  
    | 375 | 					$query_menu = $database->query($sql);
 | 
  
    | 376 | 					$page = $query_menu->fetchRow();
 | 
  
    | 377 |                     $show_crumb = (($links == true) && ($temp != $page_id))
 | 
  
    | 378 |                             ? '<a href="'.page_link($page['link']).'" class="link">'.$page['menu_title'].'</a>'
 | 
  
    | 379 |                             : '<span class="crumb">'.$page['menu_title'].'</span>';
 | 
  
    | 380 |                     // Permission
 | 
  
    | 381 |                     switch ($page['visibility'])
 | 
  
    | 382 |                     {
 | 
  
    | 383 |                         case 'none' :
 | 
  
    | 384 |                         case 'hidden' :
 | 
  
    | 385 |                         // if show, you know there is an error in a hidden page
 | 
  
    | 386 |                             print $show_crumb.' ';
 | 
  
    | 387 | 	                        break;
 | 
  
    | 388 |                         default :
 | 
  
    | 389 |                             print $show_crumb;
 | 
  
    | 390 | 		                    break;
 | 
  
    | 391 |                     }
 | 
  
    | 392 | 
 | 
  
    | 393 |                     if ( ( $counter <> $total_crumbs-1 ) )
 | 
  
    | 394 |                     {
 | 
  
    | 395 |                         print '<span class="separator">'.$sep.'</span>';
 | 
  
    | 396 |                     }
 | 
  
    | 397 | 	            $counter++;
 | 
  
    | 398 |             }
 | 
  
    | 399 |             print "</div>\n";
 | 
  
    | 400 | 		}
 | 
  
    | 401 | 	}
 | 
  
    | 402 | }
 | 
  
    | 403 | 
 | 
  
    | 404 | // Function for page title
 | 
  
    | 405 | if (!function_exists('page_title')) {
 | 
  
    | 406 | 	function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
 | 
  
    | 407 | 		$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
 | 
  
    | 408 | 		$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
 | 
  
    | 409 | 		echo str_replace($vars, $values, $template);
 | 
  
    | 410 | 	}
 | 
  
    | 411 | }
 | 
  
    | 412 | 
 | 
  
    | 413 | // Function for page description
 | 
  
    | 414 | if (!function_exists('page_description')) {
 | 
  
    | 415 | 	function page_description() {
 | 
  
    | 416 | 		global $wb;
 | 
  
    | 417 | 		if ($wb->page_description!='') {
 | 
  
    | 418 | 			echo $wb->page_description;
 | 
  
    | 419 | 		} else {
 | 
  
    | 420 | 			echo WEBSITE_DESCRIPTION;
 | 
  
    | 421 | 		}
 | 
  
    | 422 | 	}
 | 
  
    | 423 | }
 | 
  
    | 424 | 
 | 
  
    | 425 | // Function for page keywords
 | 
  
    | 426 | if (!function_exists('page_keywords')) {
 | 
  
    | 427 | 	function page_keywords() {
 | 
  
    | 428 | 		global $wb;
 | 
  
    | 429 | 		if ($wb->page_keywords!='') {
 | 
  
    | 430 | 			echo $wb->page_keywords;
 | 
  
    | 431 | 		} else {
 | 
  
    | 432 | 			echo WEBSITE_KEYWORDS;
 | 
  
    | 433 | 		}
 | 
  
    | 434 | 	}
 | 
  
    | 435 | }
 | 
  
    | 436 | 
 | 
  
    | 437 | // Function for page header
 | 
  
    | 438 | if (!function_exists('page_header')) {
 | 
  
    | 439 | 	function page_header($date_format = 'Y') {
 | 
  
    | 440 | 		echo WEBSITE_HEADER;
 | 
  
    | 441 | 	}
 | 
  
    | 442 | }
 | 
  
    | 443 | 
 | 
  
    | 444 | // Function for page footer
 | 
  
    | 445 | if (!function_exists('page_footer')) {
 | 
  
    | 446 | 	function page_footer($date_format = 'Y') {
 | 
  
    | 447 | 		global $starttime;
 | 
  
    | 448 | 		$vars = array('[YEAR]', '[PROCESS_TIME]');
 | 
  
    | 449 | 		$processtime=array_sum(explode(" ",microtime()))-$starttime;
 | 
  
    | 450 | 		$values = array(gmdate($date_format),$processtime);
 | 
  
    | 451 | 		echo str_replace($vars, $values, WEBSITE_FOOTER);
 | 
  
    | 452 | 	}
 | 
  
    | 453 | }
 | 
  
    | 454 | 
 | 
  
    | 455 | function bind_jquery ($file_id='jquery')
 | 
  
    | 456 | {
 | 
  
    | 457 | 
 | 
  
    | 458 |         $jquery_links = '';
 | 
  
    | 459 | 		/* include the Javascript jquery api  */
 | 
  
    | 460 | 		if( $file_id == 'jquery' AND file_exists(WB_PATH .'/include/jquery/jquery-min.js'))
 | 
  
    | 461 |         {
 | 
  
    | 462 |             $wbpath = str_replace('\\','/',WB_PATH);  // fixed localhost problem with ie
 | 
  
    | 463 | 			$jquery_links .= "<script type=\"text/javascript\">\n"
 | 
  
    | 464 |                 ."var URL = '".WB_URL."';\n"
 | 
  
    | 465 |                /* ."var WB_PATH = '".$wbpath."';\n" */
 | 
  
    | 466 |                 ."var WB_URL = '".WB_URL."';\n"
 | 
  
    | 467 |                 ."var TEMPLATE_DIR = '".TEMPLATE_DIR."';\n"
 | 
  
    | 468 |                 ."</script>\n";
 | 
  
    | 469 | 
 | 
  
    | 470 | 			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-min.js" type="text/javascript"></script>'."\n";
 | 
  
    | 471 | 			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-insert.js" type="text/javascript"></script>'."\n";
 | 
  
    | 472 | 			$jquery_links .= '<script src="'.WB_URL.'/include/jquery/jquery-include.js" type="text/javascript"></script>'."\n";
 | 
  
    | 473 |             /* workout to insert ui.css and theme */
 | 
  
    | 474 |             $jquery_theme =  WB_PATH.'/modules/jquery/jquery_theme.js';
 | 
  
    | 475 | 			$jquery_links .=  file_exists($jquery_theme)
 | 
  
    | 476 |                 ? '<script src="'.WB_URL.'/modules/jquery/jquery_theme.js" type="text/javascript"></script>'."\n"
 | 
  
    | 477 |                 : '<script src="'.WB_URL.'/include/jquery/jquery_theme.js" type="text/javascript"></script>'."\n";
 | 
  
    | 478 |             /* workout to insert plugins functions, set in templatedir */
 | 
  
    | 479 |             $jquery_frontend_file = TEMPLATE_DIR.'/jquery_frontend.js';
 | 
  
    | 480 | 			$jquery_links .= file_exists(str_replace( WB_URL, WB_PATH, $jquery_frontend_file))
 | 
  
    | 481 |                 ? '<script src="'.$jquery_frontend_file.'" type="text/javascript"></script>'."\n"
 | 
  
    | 482 |                 : '';
 | 
  
    | 483 | 		}
 | 
  
    | 484 |     return $jquery_links;
 | 
  
    | 485 | }
 | 
  
    | 486 | 
 | 
  
    | 487 | // Function to add optional module Javascript into the <body> section of the frontend
 | 
  
    | 488 | if(!function_exists('register_frontend_modfiles_body'))
 | 
  
    | 489 | {
 | 
  
    | 490 | 	function register_frontend_modfiles_body($file_id="js")
 | 
  
    | 491 |     {
 | 
  
    | 492 | 		// sanity check of parameter passed to the function
 | 
  
    | 493 | 		$file_id = strtolower($file_id);
 | 
  
    | 494 | 		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js" && $file_id !== "jquery")
 | 
  
    | 495 |         {
 | 
  
    | 496 | 			return;
 | 
  
    | 497 | 		}
 | 
  
    | 498 | 
 | 
  
    | 499 |        // define constant indicating that the register_frontent_files was invoked
 | 
  
    | 500 |        if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);
 | 
  
    | 501 | 		global $wb, $database, $include_body_links;
 | 
  
    | 502 | 		// define default baselink and filename for optional module javascript files
 | 
  
    | 503 | 		$body_links = "";
 | 
  
    | 504 | 
 | 
  
    | 505 | 		/* include the Javascript jquery api  */
 | 
  
    | 506 |         $body_links .= bind_jquery($file_id);
 | 
  
    | 507 | 
 | 
  
    | 508 | 		if($file_id !== "css" && $file_id == "js" && $file_id !== "jquery")
 | 
  
    | 509 |         {
 | 
  
    | 510 |     		$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend_body.js" type="text/javascript"></script>';
 | 
  
    | 511 |     		$base_file = "frontend_body.js";
 | 
  
    | 512 | 
 | 
  
    | 513 | 			// ensure that frontend_body.js is only added once per module type
 | 
  
    | 514 |     		if(!empty($include_body_links))
 | 
  
    | 515 |             {
 | 
  
    | 516 |     			if(strpos($body_links, $include_body_links) === false)
 | 
  
    | 517 |                 {
 | 
  
    | 518 |     				$body_links .= $include_body_links;
 | 
  
    | 519 |     			}
 | 
  
    | 520 |     			$include_body_links = '';
 | 
  
    | 521 |     		}
 | 
  
    | 522 | 
 | 
  
    | 523 |     		// gather information for all models embedded on actual page
 | 
  
    | 524 |     		$page_id = $wb->page_id;
 | 
  
    | 525 | 			$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
 | 
  
    | 526 | 			$sql .= 'WHERE `page_id` = '.(int)$page_id.' AND `module`<>\'wysiwyg\'';
 | 
  
    | 527 |     		if( ($query_modules = $database->query($sql)) )
 | 
  
    | 528 | 			{
 | 
  
    | 529 | 	    		while($row = $query_modules->fetchRow())
 | 
  
    | 530 | 	            {
 | 
  
    | 531 | 	    			// check if page module directory contains a frontend_body.js file
 | 
  
    | 532 | 	    			if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file"))
 | 
  
    | 533 | 	                {
 | 
  
    | 534 | 	    			// create link with frontend_body.js source for the current module
 | 
  
    | 535 | 	    				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
 | 
  
    | 536 | 
 | 
  
    | 537 | 	    				// define constant indicating that the register_frontent_files_body was invoked
 | 
  
    | 538 | 	    					if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) { define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);}
 | 
  
    | 539 | 
 | 
  
    | 540 | 	    				// ensure that frontend_body.js is only added once per module type
 | 
  
    | 541 | 	    				if(strpos($body_links, $tmp_link) === false)
 | 
  
    | 542 | 	                    {
 | 
  
    | 543 | 	    					$body_links .= $tmp_link;
 | 
  
    | 544 | 	    				}
 | 
  
    | 545 | 	    			}
 | 
  
    | 546 | 	    		}
 | 
  
    | 547 |             }
 | 
  
    | 548 |         }
 | 
  
    | 549 | 
 | 
  
    | 550 | 		print $body_links."\n"; ;
 | 
  
    | 551 | 	}
 | 
  
    | 552 | }
 | 
  
    | 553 | 
 | 
  
    | 554 | 
 | 
  
    | 555 | // Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend
 | 
  
    | 556 | if(!function_exists('register_frontend_modfiles'))
 | 
  
    | 557 | {
 | 
  
    | 558 | 	function register_frontend_modfiles($file_id="css")
 | 
  
    | 559 |     {
 | 
  
    | 560 | 		// sanity check of parameter passed to the function
 | 
  
    | 561 | 		$file_id = strtolower($file_id);
 | 
  
    | 562 | 		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js" && $file_id !== "jquery")
 | 
  
    | 563 |         {
 | 
  
    | 564 | 			return;
 | 
  
    | 565 | 		}
 | 
  
    | 566 | 
 | 
  
    | 567 | 		global $wb, $database, $include_head_link_css, $include_head_links;
 | 
  
    | 568 | 		// define default baselink and filename for optional module javascript and stylesheet files
 | 
  
    | 569 | 		$head_links = "";
 | 
  
    | 570 | 
 | 
  
    | 571 |         switch ($file_id)
 | 
  
    | 572 |         {
 | 
  
    | 573 |             case 'css':
 | 
  
    | 574 | 			$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"';
 | 
  
    | 575 | 			$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
 | 
  
    | 576 | 			$base_file = "frontend.css";
 | 
  
    | 577 |     		if(!empty($include_head_link_css))
 | 
  
    | 578 |             {
 | 
  
    | 579 |               $head_links .=  !strpos($head_links, $include_head_link_css) ? $include_head_link_css : '';
 | 
  
    | 580 |               $include_head_link_css = '';
 | 
  
    | 581 |             }
 | 
  
    | 582 |             break;
 | 
  
    | 583 |             case 'jquery':
 | 
  
    | 584 |             $head_links .= bind_jquery($file_id);
 | 
  
    | 585 |             break;
 | 
  
    | 586 |             case 'js':
 | 
  
    | 587 | 			$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js" type="text/javascript"></script>';
 | 
  
    | 588 | 			$base_file = "frontend.js";
 | 
  
    | 589 |     		if(!empty($include_head_links))
 | 
  
    | 590 |             {
 | 
  
    | 591 |               $head_links .= !strpos($head_links, $include_head_links) ? $include_head_links : '';
 | 
  
    | 592 |               $include_head_links = '';
 | 
  
    | 593 |             }
 | 
  
    | 594 |             break;
 | 
  
    | 595 |             default:
 | 
  
    | 596 |             break;
 | 
  
    | 597 | 		}
 | 
  
    | 598 | 
 | 
  
    | 599 |         if( $file_id != 'jquery')
 | 
  
    | 600 |         {
 | 
  
    | 601 |     		// gather information for all models embedded on actual page
 | 
  
    | 602 |     		$page_id = $wb->page_id;
 | 
  
    | 603 | 			$sql  = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
 | 
  
    | 604 | 			$sql .= 'WHERE `page_id` = '.(int)$page_id.' AND `module`<>\'wysiwyg\'';
 | 
  
    | 605 |     		if( ($query_modules = $database->query($sql)) )
 | 
  
    | 606 | 			{
 | 
  
    | 607 | 	    		while($row = $query_modules->fetchRow())
 | 
  
    | 608 | 	            {
 | 
  
    | 609 | 	    			// check if page module directory contains a frontend.js or frontend.css file
 | 
  
    | 610 | 	    			if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file"))
 | 
  
    | 611 | 	                {
 | 
  
    | 612 | 	    			// create link with frontend.js or frontend.css source for the current module
 | 
  
    | 613 | 	    				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
 | 
  
    | 614 | 
 | 
  
    | 615 | 	    				// define constant indicating that the register_frontent_files was invoked
 | 
  
    | 616 | 	    				if($file_id == 'css')
 | 
  
    | 617 | 	                    {
 | 
  
    | 618 | 	    					if(!defined('MOD_FRONTEND_CSS_REGISTERED')) define('MOD_FRONTEND_CSS_REGISTERED', true);
 | 
  
    | 619 | 	    				} else
 | 
  
    | 620 | 	                    {
 | 
  
    | 621 | 	    					if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_JAVASCRIPT_REGISTERED', true);
 | 
  
    | 622 | 	    				}
 | 
  
    | 623 | 	    				// ensure that frontend.js or frontend.css is only added once per module type
 | 
  
    | 624 | 	    				if(strpos($head_links, $tmp_link) === false)
 | 
  
    | 625 | 	                    {
 | 
  
    | 626 | 	    					$head_links .= $tmp_link."\n";
 | 
  
    | 627 | 	    				}
 | 
  
    | 628 | 	    			};
 | 
  
    | 629 | 	    		}
 | 
  
    | 630 | 			}
 | 
  
    | 631 |        		// include the Javascript email protection function
 | 
  
    | 632 |        		if( $file_id != 'css' && file_exists(WB_PATH .'/modules/droplets/js/mdcr.js'))
 | 
  
    | 633 |                {
 | 
  
    | 634 |        			$head_links .= '<script src="'.WB_URL.'/modules/droplets/js/mdcr.js" type="text/javascript"></script>'."\n";
 | 
  
    | 635 |        		}
 | 
  
    | 636 |                elseif( $file_id != 'css' && file_exists(WB_PATH .'/modules/output_filter/js/mdcr.js'))
 | 
  
    | 637 |                {
 | 
  
    | 638 |        			$head_links .= '<script src="'.WB_URL.'/modules/output_filter/js/mdcr.js" type="text/javascript"></script>'."\n";
 | 
  
    | 639 |        		}
 | 
  
    | 640 |         }
 | 
  
    | 641 |         print $head_links;
 | 
  
    | 642 |     }
 | 
  
    | 643 | }
 | 
  
    | 644 | /*
 | 
  
    | 645 | 	function moveCssToHead($content) {
 | 
  
    | 646 | 		// move css definitions into head section
 | 
  
    | 647 | 		$pattern1 = '/(?:<body.*?)(<link[^>]*?\"text\/css\".*?\/>)/si';
 | 
  
    | 648 | 		$pattern2 = '/(?:<body.*?)(<style[^>]*?\"text\/css\"[^>]* ?>.*?<\/style>)/si';
 | 
  
    | 649 | 		while(preg_match($pattern1, $content, $matches)==1) {
 | 
  
    | 650 | 		// loop through all linked CSS
 | 
  
    | 651 | 			$insert = $matches[1];
 | 
  
    | 652 | 			$content = str_replace($insert, '', $content);
 | 
  
    | 653 | 			$insert = "\n".$insert."\n</head>\n<body";
 | 
  
    | 654 | 			$content = preg_replace('/<\/head>.*?<body/si', $insert, $content);
 | 
  
    | 655 | 		}
 | 
  
    | 656 | 		while(preg_match($pattern2, $content, $matches)==1) {
 | 
  
    | 657 | 		// loop through all inline CSS
 | 
  
    | 658 | 			$insert = $matches[1];
 | 
  
    | 659 | 			$content = str_replace($insert, '', $content);
 | 
  
    | 660 | 			$insert = "\n".$insert."\n</head>\n<body";
 | 
  
    | 661 | 			$content = preg_replace('/<\/head>.*?<body/si', $insert, $content);
 | 
  
    | 662 | 		}
 | 
  
    | 663 | 		return $content;
 | 
  
    | 664 | 	}
 | 
  
    | 665 | */
 |