/includes/template.php
PHP | 3430 lines | 2340 code | 452 blank | 638 comment | 391 complexity | 64bfb35a8d199d6f57077d3ffa51c932 MD5 | raw file
Possible License(s): GPL-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
- * Copyright (C) 2006-2009 Dan Fuhry
- *
- * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
- */
-
- class template
- {
- var $tpl_strings, $tpl_bool, $vars_assign_history, $theme, $style, $no_headers, $additional_headers, $sidebar_extra, $sidebar_widgets, $toolbar_menu, $theme_list, $named_theme_list, $default_theme, $default_style, $plugin_blocks, $plugin_blocks_content, $namespace_string, $style_list, $theme_loaded;
-
- var $theme_initted = false;
- var $page_initted = false;
- var $elements = false;
- var $page_id = false;
- var $namespace = false;
- var $js_preload = array();
- var $js_append = '';
-
- /**
- * Page action conditions
- * @var array
- */
-
- var $conds = array();
-
- /**
- * The PageProcessor for the current page
- * @var object
- */
-
- var $page = false;
-
- /**
- * The list of themes that are critical for Enano operation. This doesn't include oxygen which
- * remains a user theme. By default this is admin and printable which have to be loaded on demand.
- * @var array
- */
-
- var $system_themes = array('admin', 'printable');
-
- /**
- * Set to true if the site is disabled and thus a message needs to be shown. This should ONLY be changed by common.php.
- * @var bool
- * @access private
- */
-
- var $site_disabled = false;
-
- /**
- * One of the absolute best parts of Enano :-P
- * @var string
- */
-
- var $fading_button = '';
-
- /**
- * Context stack. You can save and restore the var set.
- * @var array
- */
- var $context_stack = array('bool' => array(), 'str' => array(), 'history' => array());
-
- function __construct()
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $cache;
-
- $this->tpl_bool = Array();
- $this->tpl_strings = Array();
- $this->sidebar_extra = '';
- $this->toolbar_menu = '';
- $this->additional_headers = '';
- $this->plugin_blocks = Array();
- $this->plugin_blocks_content = array();
- $this->theme_loaded = false;
-
- $this->theme_list = Array();
- $this->named_theme_list = Array();
-
- $this->vars_assign_history = array(
- 'strings' => array(),
- 'bool' => array()
- );
-
- if ( defined('IN_ENANO_UPGRADE') )
- {
- return $this->construct_compat();
- }
-
- if ( !$this->theme_list = $cache->fetch('themes') )
- {
- $q = $db->sql_query('SELECT theme_id, theme_name, enabled, default_style, group_policy, group_list FROM ' . table_prefix . 'themes;');
- if ( !$q )
- $db->_die('template.php selecting theme list');
-
- $i = 0;
- while ( $row = $db->fetchrow() )
- {
- $this->theme_list[$i] = $row;
- $i++;
- }
- unset($theme);
- $this->theme_list = array_values($this->theme_list);
- $cache->store('themes', $this->theme_list, -1);
- }
-
- // Create associative array of themes
- foreach ( $this->theme_list as $i => &$theme )
- $this->named_theme_list[ $theme['theme_id'] ] =& $this->theme_list[$i];
-
- unset($theme);
-
- $this->default_theme = ( $_ = getConfig('theme_default') ) ? $_ : $this->theme_list[0]['theme_id'];
- $this->named_theme_list[ $this->default_theme ]['css'] = $this->get_theme_css_files($this->default_theme);
- // Come up with the default style. If the CSS file specified in default_style exists, we're good, just
- // use that. Otherwise, use the first stylesheet that comes to mind.
- $df_data =& $this->named_theme_list[ $this->default_theme ];
- $this->default_style = ( in_array($df_data['default_style'], $df_data['css']) ) ? $df_data['default_style'] : $df_data['css'][0];
- }
-
- /**
- * Save the current context and start a blank one.
- */
-
- function context_push()
- {
- array_push($this->context_stack['str'], $this->tpl_strings);
- array_push($this->context_stack['bool'], $this->tpl_bool);
- array_push($this->context_stack['history'], $this->vars_assign_history);
- }
-
- function context_pop()
- {
- $this->tpl_strings = array_pop($this->context_stack['str']);
- $this->tpl_bool = array_pop($this->context_stack['bool']);
- $this->vars_assign_history = array_pop($this->context_stack['history']);
- }
-
- /**
- * Gets the list of available CSS files (styles) for the specified theme.
- * @param string Theme ID
- * @return array
- */
-
- function get_theme_css_files($theme_id)
- {
- $css = array();
- $dir = ENANO_ROOT . "/themes/{$theme_id}/css";
- if ( $dh = @opendir($dir) )
- {
- while ( ( $file = @readdir($dh) ) !== false )
- {
- if ( preg_match('/\.css$/', $file) )
- $css[] = preg_replace('/\.css$/', '', $file);
- }
- closedir($dh);
- }
- // No CSS files? If so, nuke it.
- if ( count($css) < 1 )
- {
- unset($this->theme_list[$theme_id]);
- }
- return $css;
- }
-
- /**
- * Failsafe constructor for upgrades.
- */
-
- function construct_compat()
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- $this->tpl_bool = Array();
- $this->tpl_strings = Array();
- $this->sidebar_extra = '';
- $this->toolbar_menu = '';
- $this->additional_headers = '';
- $this->plugin_blocks = Array();
- $this->theme_loaded = false;
-
- $this->fading_button = '<div style="background-image: url('.scriptPath.'/images/about-powered-enano-hover.png); background-repeat: no-repeat; width: 88px; height: 31px; margin: 0 auto 5px auto;">
- <a style="background-image: none; padding-right: 0;" href="http://enanocms.org/" onclick="window.open(this.href); return false;"><img style="border-width: 0;" alt=" " src="'.scriptPath.'/images/about-powered-enano.png" onmouseover="domOpacity(this, 100, 0, 500);" onmouseout="domOpacity(this, 0, 100, 500);" /></a>
- </div>';
-
- $this->theme_list = Array();
- $this->named_theme_list = Array();
-
- $q = $db->sql_query('SELECT theme_id, theme_name, enabled, default_style FROM ' . table_prefix . 'themes;');
- if ( !$q )
- $db->_die('template.php selecting theme list');
-
- $i = 0;
- while ( $row = $db->fetchrow() )
- {
- $this->theme_list[$i] = $row;
- $i++;
- }
- // List out all CSS files for this theme
- foreach ( $this->theme_list as $i => &$theme )
- {
- $theme['css'] = array();
- $dir = ENANO_ROOT . "/themes/{$theme['theme_id']}/css";
- if ( $dh = @opendir($dir) )
- {
- while ( ( $file = @readdir($dh) ) !== false )
- {
- if ( preg_match('/\.css$/', $file) )
- $theme['css'][] = preg_replace('/\.css$/', '', $file);
- }
- closedir($dh);
- }
- // No CSS files? If so, nuke it.
- if ( count($theme['css']) < 1 )
- {
- unset($this->theme_list[$i]);
- }
- }
- $this->theme_list = array_values($this->theme_list);
- // Create associative array of themes
- foreach ( $this->theme_list as $i => &$theme )
- $this->named_theme_list[ $theme['theme_id'] ] =& $this->theme_list[$i];
-
- $this->default_theme = ( $_ = getConfig('theme_default') ) ? $_ : $this->theme_list[0]['theme_id'];
- // Come up with the default style. If the CSS file specified in default_style exists, we're good, just
- // use that. Otherwise, use the first stylesheet that comes to mind.
- $df_data =& $this->named_theme_list[ $this->default_theme ];
- $this->default_style = ( in_array($df_data['default_style'], $df_data['css']) ) ? $df_data['default_style'] : $df_data['css'][0];
- }
-
- /**
- * Systematically deletes themes from available list if they're blocked by theme security settings. Called when session->start() finishes.
- */
-
- function process_theme_acls()
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
-
- // generate the fading button - needs to be done after sessions are started
- $admintitle = ( $session->user_level >= USER_LEVEL_ADMIN && is_object(@$lang) ) ? ' title="' . $lang->get('sidebar_btn_enanopowered_admin_tip') . '"' : '';
- $this->fading_button = '<div style="background-image: url('.cdnPath.'/images/about-powered-enano-hover.png); background-repeat: no-repeat; width: 88px; height: 31px; margin: 0 auto 5px auto;">
- <a style="background-image: none; padding-right: 0;" href="http://enanocms.org/" onclick="window.open(this.href); return false;"' . $admintitle . '><img style="border-width: 0;" alt=" " src="'.cdnPath.'/images/about-powered-enano.png" onmouseover="domOpacity(this, 100, 0, 500);" onmouseout="domOpacity(this, 0, 100, 500);" /></a>
- </div>';
-
- // For each theme, check ACLs and delete from RAM if not authorized
- foreach ( $this->theme_list as $i => $theme )
- {
- if ( !@$theme['group_list'] )
- continue;
- if ( $theme['theme_id'] === getConfig('theme_default') )
- continue;
- switch ( $theme['group_policy'] )
- {
- case 'allow_all':
- // Unconditionally allowed
- continue;
- break;
- case 'whitelist':
- // If we're not on the list, off to the left please
- $list = enano_json_decode($theme['group_list']);
- $allowed = false;
- foreach ( $list as $acl )
- {
- if ( !preg_match('/^(u|g):([0-9]+)$/', $acl, $match) )
- // Invalid list entry, silently allow (maybe not a good idea but
- // really, these things are checked before they're inserted)
- continue 2;
- $mode = $match[1];
- $id = intval($match[2]);
- switch ( $mode )
- {
- case 'u':
- $allowed = ( $id == $session->user_id );
- if ( $allowed )
- break 2;
- break;
- case 'g':
- $allowed = ( isset($session->groups[$id]) );
- if ( $allowed )
- break 2;
- }
- }
- if ( !$allowed )
- {
- unset($this->theme_list[$i]);
- }
- break;
- case 'blacklist':
- // If we're ON the list, off to the left please
- $list = enano_json_decode($theme['group_list']);
- $allowed = true;
- foreach ( $list as $acl )
- {
- if ( !preg_match('/^(u|g):([0-9]+)$/', $acl, $match) )
- // Invalid list entry, silently allow (maybe not a good idea but
- // really, these things are checked before they're inserted)
- continue 2;
- $mode = $match[1];
- $id = intval($match[2]);
- switch ( $mode )
- {
- case 'u':
- $allowed = ( $id != $session->user_id );
- if ( !$allowed )
- break 2;
- break;
- case 'g':
- $allowed = ( !isset($session->groups[$id]) );
- if ( !$allowed )
- break 2;
- }
- }
- if ( !$allowed )
- {
- unset($this->theme_list[$i]);
- }
- break;
- }
- }
-
- $this->theme_list = array_values($this->theme_list);
-
- // Rebuild associative theme list
- $this->named_theme_list = array();
- foreach ( $this->theme_list as $i => &$theme )
- $this->named_theme_list[ $theme['theme_id'] ] =& $this->theme_list[$i];
- }
-
- /**
- * Register a new sidebar block.
- * @param string Block title
- * @param string Block HTML
- * @param bool If true, the class of the block will be the same as the one used for blocks that are a list of links instead of HTML content. This can do some wacky things like make all your <a>s block level.
- */
-
- function sidebar_widget($t, $h, $use_normal_section = false)
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- if ( !$this->theme_loaded )
- {
- $this->load_theme($session->theme, $session->style);
- }
- if(!$this->sidebar_widgets)
- $this->sidebar_widgets = '';
- $tplvars = $this->extract_vars('elements.tpl');
-
- if ( $use_normal_section )
- {
- $parser = $this->makeParserText($tplvars['sidebar_section']);
- }
- else
- {
- $parser = $this->makeParserText($tplvars['sidebar_section_raw']);
- }
-
- $parser->assign_vars(Array('TITLE' => '{TITLE}','CONTENT' => $h));
- $this->plugin_blocks[$t] = $parser->run();
- $this->plugin_blocks_content[$t] = $h;
- $this->sidebar_widgets .= $parser->run();
- }
- function add_header($html)
- {
- /* debug only **
- $bt = debug_backtrace();
- $bt = $bt[1];
- $this->additional_headers .= "\n <!-- {$bt['file']}:{$bt['line']} -->\n " . $html;
- */
- $this->additional_headers .= "\n " . $html;
- }
- function get_css($s = false)
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- $this->init_vars();
-
- $path = ( $s ) ? 'css/'.$s : 'css/'.$this->style.'.css';
-
- if ( !file_exists(ENANO_ROOT . '/themes/' . $this->theme . '/' . $path) )
- {
- echo "/* WARNING: Falling back to default file because file $path does not exist */\n";
- $path = 'css/' . $this->style_list[0] . '.css';
- }
-
- return $this->process_template($path);
- }
- function load_theme($name = false, $css = false)
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- $this->theme = ( $name ) ? $name : $session->theme;
- $this->style = ( $css ) ? $css : $session->style;
- if ( !$this->theme )
- {
- $this->theme = $this->theme_list[0]['theme_id'];
- $this->style = preg_replace('/\.css$/', '', $this->theme_list[0]['default_style']);
- }
- // Make sure we're allowed to use this theme.
- if ( (
- // If it was removed, it's probably blocked by an ACL, or it was uninstalled
- !isset($this->named_theme_list[$this->theme]) ||
- // Check if the theme is disabled
- ( isset($this->named_theme_list[$this->theme]) && isset($this->named_theme_list[$this->theme]['enabled']) && $this->named_theme_list[$this->theme]['enabled'] == 0 ) )
- // Above all, if it's a system theme, don't inhibit the loading process.
- && !in_array($this->theme, $this->system_themes)
- )
- {
- // No, something is preventing it - fall back to site default
- $this->theme = $this->default_theme;
-
- // Come up with the default style. If the CSS file specified in default_style exists, we're good, just
- // use that. Otherwise, use the first stylesheet that comes to mind.
- $df_data =& $this->named_theme_list[ $this->theme ];
- $this->style = ( in_array($df_data['default_style'], $df_data['css']) ) ? $df_data['default_style'] : $df_data['css'][0];
- }
- // The list of styles for the currently selected theme
- $this->style_list =& $this->named_theme_list[ $this->theme ]['css'];
- $this->theme_loaded = true;
- }
-
- /**
- * Change the theme we're supposed to display.
- * @param string Theme name
- * @param string Style name; optional
- */
-
- function set_theme($theme = false, $style = false)
- {
- $this->theme_initted = false;
- $this->load_theme($theme, $style);
- }
-
- /**
- * Change the page we're supposed to generate for
- * @param mixed Page ID *or* PageProcessor. If a PageProcessor, pulls permission info and such from that; if not, starts a PageProcessor. YOU SHOULD USE A PageProcessor WHENEVER POSSIBLE! It improves efficiency.
- * @param string Namespace; not required if including a PageProcessor.
- */
-
- function set_page($page_id_or_pp, $namespace = false)
- {
- global $paths;
-
- if ( is_object($page_id_or_pp) && get_class($page_id_or_pp) === 'PageProcessor' )
- {
- $this->page_initted = false;
- $page =& $page_id_or_pp;
- $this->page = $page;
- $this->page_id = $page->page_id;
- $this->namespace = $page->namespace;
- }
- else if ( is_string($page_id_or_pp) )
- {
- if ( !is_string($namespace) )
- return false;
-
- if ( $page_id_or_pp === $this->page_id && $namespace === $this->namespace )
- return true;
-
- $this->page_initted = false;
- $this->page = false;
- $this->page_id = sanitize_page_id($page_id_or_pp);
- $this->namespace = $namespace;
- }
- else
- {
- return false;
- }
- $this->assign_vars(array(
- 'PAGE_URLNAME' => $paths->get_pathskey($this->page_id, $this->namespace)
- ));
- return true;
- }
-
- /**
- * Queue a Javascript file to be loaded with the page instead of on demand.
- * @param mixed Javascript file string or array thereof, extensions are optional
- * @example
- <code>
- $template->preload_js(array('jquery', 'jquery-ui'));
- $template->preload_js('admin-menu.js');
- </code>
- * @return null
- */
-
- function preload_js($filemixed)
- {
- if ( is_string($filemixed) )
- $files = array($filemixed);
- else if ( is_array($filemixed) )
- $files = $filemixed;
- else
- // :-/
- return null;
-
- $this->js_preload = array_values(array_merge($this->js_preload, $files));
- }
-
- /**
- * Queue some HTML to be inserted after the Javascript runtime.
- * @param string HTML glob
- */
-
- function add_header_js($html)
- {
- $this->js_append .= "$html\n ";
- }
-
- /**
- * Global, only-called-once init. Goes to all themes.
- */
-
- function init_global_vars()
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
- global $email;
-
- $is_opera = (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'Opera')) ? true : false;
- $is_msie = (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) ? true : false;
-
- $this->assign_bool(array(
- 'auth_admin' => $session->user_level >= USER_LEVEL_ADMIN ? true : false,
- 'user_logged_in' => $session->user_logged_in,
- 'opera' => $is_opera,
- 'msie' => $is_msie,
- 'registration_disabled' => getConfig('account_activation', 'none') === 'disable'
- ));
-
- if ( $session->sid_super )
- {
- $ash = '&auth=' . $session->sid_super;
- $asq = "?auth=" . $session->sid_super;
- $asa = "&auth=" . $session->sid_super;
- $as2 = htmlspecialchars(urlSeparator) . 'auth='.$session->sid_super;
- }
- else
- {
- $asq = '';
- $asa = '';
- $as2 = '';
- $ash = '';
- }
-
- // Append the Enano version to URLs to break the cache on upgrades
- $enano_version = enano_version();
-
- // Set up javascript includes
- // these depend heavily on whether we have a CDN to work with or not
- if ( getConfig('cdn_path') )
- {
- // we're on a CDN, point to static includes
- // CLI javascript compression script: includes/clientside/jscompress.php
- $js_head = '<script type="text/javascript" src="' . cdnPath . '/includes/clientside/static/enano-lib-basic.js?' . $enano_version . '"></script>';
-
- if ( !empty($this->js_preload) )
- {
- $loadlines = array();
-
- // make unique
- foreach ( $this->js_preload as &$script )
- {
- $script = preg_replace('/\.js$/', '', $script) . '.js';
- }
- unset($script);
- $this->js_preload = array_unique($this->js_preload);
-
- foreach ( $this->js_preload as $script )
- {
- $js_head .= "\n <script type=\"text/javascript\" src=\"" . cdnPath . "/includes/clientside/static/$script?$enano_version\"></script>";
- // special case for l10n: also load strings
- if ( $script == 'l10n.js' )
- {
- global $lang;
- $js_head .= "\n <script type=\"text/javascript\" src=\"" . makeUrlNS("Special", "LangExportJSON/$lang->lang_id", "$enano_version") . "\"></script>";
- }
- $loadlines[] = "loaded_components['$script'] = true;";
- }
-
- // tell the system that this stuff is already loaded
- $loadlines = implode("\n ", $loadlines);
- $js_head .= "\n <script type=\"text/javascript\">
- var loaded_components = loaded_components || {};
- $loadlines
- </script>";
- }
-
- $js_foot = <<<JSEOF
- <script type="text/javascript">
- // This initializes the Javascript runtime when the DOM is ready - not when the page is
- // done loading, because enano-lib-basic still has to load some 15 other script files
- // check for the init function - this is a KHTML fix
- // This doesn't seem to work properly in IE in 1.1.x - there are some problems with
- // tinyMCE and l10n.
- if ( typeof ( enano_init ) == 'function' && !IE )
- {
- enano_init();
- window.onload = function(e) { };
- }
- </script>
- $this->js_append
- JSEOF;
- }
- else
- {
- $cdnpath = cdnPath;
- $js_head = '';
-
- // point to jsres compressor
- $js_head .= <<<JSEOF
- <!-- Only load a basic set of functions for now. Let the rest of the API load when the page is finished. -->
- <script type="text/javascript" src="$cdnpath/includes/clientside/jsres.php?early&$enano_version"></script>
- JSEOF;
- $js_foot = '';
-
- if ( !empty($this->js_preload) )
- {
- foreach ( $this->js_preload as &$script )
- {
- $script = preg_replace('/\.js$/', '', $script) . '.js';
- }
- $this->js_preload = array_unique($this->js_preload);
- if ( in_array('l10n.js', $this->js_preload) )
- {
- // special case for l10n: also load strings
- global $lang;
- $js_foot .= "\n <script type=\"text/javascript\" src=\"" . makeUrlNS("Special", "LangExportJSON/$lang->lang_id", $enano_version, true) . "\"></script>";
- }
- $scripts = implode(',', $this->js_preload);
- $js_foot .= "\n <script type=\"text/javascript\" src=\"" . cdnPath . "/includes/clientside/jsres.php?f=$scripts&$enano_version\"></script>";
-
- }
-
- $js_foot .= <<<JSEOF
- <!-- jsres.php is a wrapper script that compresses and caches single JS files to minimize requests -->
- <script type="text/javascript" src="$cdnpath/includes/clientside/jsres.php?$enano_version"></script>
- <script type="text/javascript">//<![CDATA[
- // This initializes the Javascript runtime when the DOM is ready - not when the page is
- // done loading, because enano-lib-basic still has to load some 15 other script files
- // check for the init function - this is a KHTML fix
- // This doesn't seem to work properly in IE in 1.1.x - there are some problems with
- // tinyMCE and l10n.
- if ( typeof ( enano_init ) == 'function' && !IE )
- {
- enano_init();
- window.onload = function(e) { };
- }
- //]]></script>
- $this->js_append
- JSEOF;
- }
-
-
- $this->assign_bool(array(
- 'fixed_menus' => false,
- 'export' => false,
- 'right_sidebar' => true,
- 'enable_uploads' => ( getConfig('enable_uploads') == '1' && $session->get_permissions('upload_files') ) ? true : false,
- 'stupid_mode' => false,
- ));
-
- // Add the e-mail address client code to the header
- $this->add_header($email->jscode());
-
- // Assign our main variables
- $this->assign_vars(array(
- 'SITE_NAME' => htmlspecialchars(getConfig('site_name')),
- 'USERNAME' => $session->username,
- 'SITE_DESC' => htmlspecialchars(getConfig('site_desc')),
- 'SCRIPTPATH' => scriptPath,
- 'CONTENTPATH' => contentPath,
- 'CDNPATH' => cdnPath,
- 'ADMIN_SID_QUES' => $asq,
- 'ADMIN_SID_AMP' => $asa,
- 'ADMIN_SID_AMP_HTML' => $ash,
- 'ADMIN_SID_AUTO' => $as2,
- 'ADMIN_SID_RAW' => ( is_string($session->sid_super) ? $session->sid_super : '' ),
- 'CSRF_TOKEN' => $session->csrf_token,
- 'COPYRIGHT' => RenderMan::parse_internal_links(getConfig('copyright_notice')),
- 'REQUEST_URI' => ( defined('ENANO_CLI') ? '' : $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ),
- 'SEARCH_ACTION' => makeUrlNS('Special', 'Search'),
- 'INPUT_TITLE' => ( urlSeparator == '&' ? '<input type="hidden" name="title" value="' . htmlspecialchars( $paths->get_pathskey($this->page_id, $this->namespace) ) . '" />' : ''),
- 'INPUT_AUTH' => ( $session->sid_super ? '<input type="hidden" name="auth" value="' . $session->sid_super . '" />' : ''),
- 'MAIN_PAGE' => get_main_page(),
- 'UNREAD_PMS' => $session->unread_pms,
- 'JS_HEADER' => $js_head,
- 'JS_FOOTER' => $js_foot,
- 'URL_ABOUT_ENANO' => makeUrlNS('Special', 'About_Enano', '', true),
- 'ENANO_VERSION' => enano_version()
- ), true);
-
- $tpl_strings = array();
- foreach ( $paths->nslist as $ns_id => $ns_prefix )
- {
- $tpl_strings[ 'NS_' . strtoupper($ns_id) ] = $ns_prefix;
- }
-
- $this->assign_vars($tpl_strings, true);
- }
-
- /**
- * Init theme vars, like sidebar, global JS, that kind of stuff.
- */
-
- function init_theme_vars()
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
-
- // allows conditional testing of the theme ID (a bit crude, came from my NSIS days)
- $this->assign_bool(array(
- "theme_is_{$this->theme}" => true
- ));
-
- $this->elements = $this->extract_vars('elements.tpl');
-
- // Generate the code for the Administration and Edit Sidebar buttons
- // Once again, the new template parsing system can be used here
-
- $parser = $this->makeParserText($this->elements['sidebar_button']);
-
- $parser->assign_vars(Array(
- 'HREF'=>makeUrlNS('Special', 'Administration'),
- 'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { void(ajaxStartAdminLogin()); return false; }"',
- 'TEXT'=>$lang->get('sidebar_btn_administration'),
- ));
-
- $admin_link = $parser->run();
-
- // We're leaving this in for now, just blanked out, to avoid compatibility issues.
- $sidebar_link = '';
-
- $this->assign_vars(array(
- 'ADMIN_LINK' => $admin_link,
- 'SIDEBAR_LINK' => $sidebar_link,
- 'THEME_ID' => $this->theme,
- 'STYLE_ID' => $this->style
- ));
-
- // Add the site description sidebar block
- $this->sidebar_widget($lang->get('sidebar_title_about'), '<p>' . htmlspecialchars(getConfig('site_desc')) . '</p>');
-
- $this->theme_initted = true;
- }
-
- /**
- * Init page vars, like the toolbar, local JS, etc.
- */
-
- function init_page_vars()
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
-
- if ( !$this->page )
- {
- $this->page = new PageProcessor($this->page_id, $this->namespace);
- }
-
- $conds = $this->page->ns->get_conds();
-
- $this->assign_bool(array(
- 'in_admin' => ( ( $this->page_id == 'Administration' && $this->namespace == 'Special' ) || $this->namespace == 'Admin' ),
- 'auth_rename' => ( $conds['rename'] )
- ));
-
- // Get the "article" button text (depends on namespace)
- switch ( $this->namespace )
- {
- case "Article":
- default:
- $ns = $lang->get('onpage_lbl_page_article');
- break;
- case "Admin":
- $ns = $lang->get('onpage_lbl_page_admin');
- break;
- case "System":
- $ns = $lang->get('onpage_lbl_page_system');
- break;
- case "File":
- $ns = $lang->get('onpage_lbl_page_file');
- break;
- case "Help":
- $ns = $lang->get('onpage_lbl_page_help');
- break;
- case "User":
- $ns = $lang->get('onpage_lbl_page_user');
- break;
- case "Special":
- $ns = $lang->get('onpage_lbl_page_special');
- break;
- case "Template":
- $ns = $lang->get('onpage_lbl_page_template');
- break;
- case "Project":
- $ns = $lang->get('onpage_lbl_page_project');
- break;
- case "Category":
- $ns = $lang->get('onpage_lbl_page_category');
- break;
- case "API":
- $ns = $lang->get('onpage_lbl_page_external');
- break;
- }
- $this->namespace_string = $ns;
- unset($ns);
- // compatibility
- $local_namespace =& $this->namespace;
- $local_page_id =& $this->page_id;
- $code = $plugins->setHook('page_type_string_set');
- foreach ( $code as $cmd )
- {
- eval($cmd);
- }
- $ns =& $this->namespace_string;
-
- //
- // PAGE TOOLBAR (on-page controls/actions)
- //
-
- $local_page = $paths->get_pathskey($this->page_id, $this->namespace);
- $local_cdata = $this->page->ns->get_cdata();
-
- // Initialize the toolbar
- $tb = '';
- $this->toolbar_menu = '';
-
- // Create "xx page" button
-
- $btn_selected = ( isset($this->elements['toolbar_button_selected'])) ? $this->elements['toolbar_button_selected'] : $this->elements['toolbar_button'];
- $parser = $this->makeParserText($btn_selected);
-
- if ( $conds['article'] )
- {
- $parser->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxReset()); return false; }" title="' . $lang->get('onpage_tip_article') . '" accesskey="a"',
- 'PARENTFLAGS' => 'id="mdgToolbar_article"',
- 'HREF' => makeUrl($local_page, null, true),
- 'TEXT' => $this->namespace_string
- ));
-
- $tb .= $parser->run();
- }
-
- $button = $this->makeParserText($this->elements['toolbar_button']);
-
- // Page toolbar
- // Comments button
- if ( $conds['comments'] )
- {
- $cdata = $this->page->ns->get_cdata();
- if ( isset($cdata['comments_approved']) )
- {
- $approval_counts = array(
- COMMENT_APPROVED => $cdata['comments_approved'],
- COMMENT_UNAPPROVED => $cdata['comments_unapproved'],
- COMMENT_SPAM => $cdata['comments_spam']
- );
- $num_comments = $session->check_acl_scope('mod_comments', $this->namespace) && $this->page->perms->get_permissions('mod_comments')
- ? array_sum($approval_counts)
- : $approval_counts[COMMENT_APPROVED];
- }
- else
- {
- $e = $db->sql_query('SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$this->page_id.'\' AND namespace=\''.$this->namespace.'\';');
- if ( !$e )
- {
- $db->_die();
- }
- $num_comments = $db->numrows();
- $approval_counts = array(COMMENT_UNAPPROVED => 0, COMMENT_APPROVED => 0, COMMENT_SPAM => 0);
-
- while ( $r = $db->fetchrow() )
- {
- $approval_counts[$r['approved']]++;
- }
- }
-
- $db->free_result();
- // $n = ( $session->check_acl_scope('mod_comments', $this->namespace) && $perms->get_permissions('mod_comments') ) ? (string)$num_comments : (string)$na;
- if ( $session->check_acl_scope('mod_comments', $this->namespace) && $this->page->perms->get_permissions('mod_comments') && ( $approval_counts[COMMENT_UNAPPROVED] + $approval_counts[COMMENT_SPAM] ) > 0 )
- {
- $subst = array(
- 'num_comments' => $num_comments,
- 'num_app' => $approval_counts[COMMENT_APPROVED],
- 'num_unapp' => $approval_counts[COMMENT_UNAPPROVED],
- 'num_spam' => $approval_counts[COMMENT_SPAM]
- );
- $btn_text = $lang->get('onpage_btn_discussion_unapp', $subst);
- }
- else
- {
- $subst = array(
- 'num_comments' => $num_comments
- );
- $btn_text = $lang->get('onpage_btn_discussion', $subst);
- }
-
- $button->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxComments()); return false; }" title="' . $lang->get('onpage_tip_comments') . '" accesskey="c"',
- 'PARENTFLAGS' => 'id="mdgToolbar_discussion"',
- 'HREF' => makeUrl($local_page, 'do=comments', true),
- 'TEXT' => $btn_text,
- ));
-
- $tb .= $button->run();
- }
- // Edit button
- if( $conds['edit'] )
- {
- $button->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="' . $lang->get('onpage_tip_edit') . '" accesskey="e"',
- 'PARENTFLAGS' => 'id="mdgToolbar_edit"',
- 'HREF' => makeUrl($local_page, 'do=edit', true),
- 'TEXT' => $lang->get('onpage_btn_edit')
- ));
- $tb .= $button->run();
- // View source button
- }
- else if ( $conds['viewsource'] )
- {
- $button->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="' . $lang->get('onpage_tip_viewsource') . '" accesskey="e"',
- 'PARENTFLAGS' => 'id="mdgToolbar_edit"',
- 'HREF' => makeUrl($local_page, 'do=viewsource', true),
- 'TEXT' => $lang->get('onpage_btn_viewsource')
- ));
- $tb .= $button->run();
- }
- // History button
- if ( $conds['history'] )
- {
- $button->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxHistory()); return false; }" title="' . $lang->get('onpage_tip_history') . '" accesskey="h"',
- 'PARENTFLAGS' => 'id="mdgToolbar_history"',
- 'HREF' => makeUrl($local_page, 'do=history', true),
- 'TEXT' => $lang->get('onpage_btn_history')
- ));
- $tb .= $button->run();
- }
-
- $menubtn = $this->makeParserText($this->elements['toolbar_menu_button']);
-
- // Additional actions menu
- // Rename button
- if ( $conds['rename'] )
- {
- $menubtn->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxRename()); return false; }" title="' . $lang->get('onpage_tip_rename') . '" accesskey="r"',
- 'HREF' => makeUrl($local_page, 'do=rename', true),
- 'TEXT' => $lang->get('onpage_btn_rename'),
- ));
- $this->toolbar_menu .= $menubtn->run();
- }
-
- // Vote-to-delete button
- if ( $conds['delvote'] )
- {
- $menubtn->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDelVote()); return false; }" title="' . $lang->get('onpage_tip_delvote') . '" accesskey="d"',
- 'HREF' => makeUrl($local_page, 'do=delvote', true),
- 'TEXT' => $lang->get('onpage_btn_votedelete'),
- ));
- $this->toolbar_menu .= $menubtn->run();
- }
-
- // Clear-votes button
- if ( $conds['resetvotes'] )
- {
- $menubtn->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxResetDelVotes()); return false; }" title="' . $lang->get('onpage_tip_resetvotes') . '" accesskey="y"',
- 'HREF' => makeUrl($local_page, 'do=resetvotes', true),
- 'TEXT' => $lang->get('onpage_btn_votedelete_reset'),
- ));
- $this->toolbar_menu .= $menubtn->run();
- }
-
- // Printable page button
- if ( $conds['printable'] )
- {
- $menubtn->assign_vars(array(
- 'FLAGS' => 'title="' . $lang->get('onpage_tip_printable') . '"',
- 'HREF' => makeUrl($local_page, 'printable=yes', true),
- 'TEXT' => $lang->get('onpage_btn_printable'),
- ));
- $this->toolbar_menu .= $menubtn->run();
- }
-
- // Protect button
- if ( $conds['protect'] )
- {
- switch($this->page->ns->cdata['protected'])
- {
- case PROTECT_FULL: $protect_status = $lang->get('onpage_btn_protect_on'); break;
- case PROTECT_SEMI: $protect_status = $lang->get('onpage_btn_protect_semi'); break;
- case PROTECT_NONE: $protect_status = $lang->get('onpage_btn_protect_off'); break;
- }
-
- $label = $this->makeParserText($this->elements['toolbar_label']);
- $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_protect') . ' ' . "<b><span id=\"tb_ajax_protect_status\">$protect_status</span></b>"));
- $t0 = $label->run();
-
- $menubtn->assign_vars(array(
- 'FLAGS' => 'accesskey="p" onclick="ajaxProtect(' . $this->page->ns->cdata['protected'] . '); return false;" id="tb_ajax_protect_btn" title="' . $lang->get('onpage_tip_protect') . '"',
- 'HREF' => makeUrl($local_page, 'do=protect', true),
- 'TEXT' => $lang->get('onpage_btn_protect_change')
- ));
- $t1 = $menubtn->run();
-
- $this->toolbar_menu .= ' <table border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td>'.$t0.'</td>
- <td>'.$t1.'</td>
- </tr>
- </table>';
- }
-
- // Wiki mode button
- if ( $conds['setwikimode'] )
- {
- // label at start
- $label = $this->makeParserText($this->elements['toolbar_label']);
- $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_wikimode')));
- $t0 = $label->run();
-
- // on button
- $ctmp = '';
- if ( $local_cdata['wiki_mode'] == 1 )
- {
- $ctmp = ' style="text-decoration: underline;"';
- }
- $menubtn->assign_vars(array(
- 'FLAGS' => $ctmp,
- 'HREF' => makeUrl($local_page, 'do=setwikimode&level=1', true),
- 'TEXT' => $lang->get('onpage_btn_wikimode_on')
- ));
- $t1 = $menubtn->run();
-
- // off button
- $ctmp = '';
- if ( $local_cdata['wiki_mode'] == 0 )
- {
- $ctmp=' style="text-decoration: underline;"';
- }
- $menubtn->assign_vars(array(
- 'FLAGS' => $ctmp,
- 'HREF' => makeUrl($local_page, 'do=setwikimode&level=0', true),
- 'TEXT' => $lang->get('onpage_btn_wikimode_off')
- ));
- $t2 = $menubtn->run();
-
- // global button
- $ctmp = '';
- if ( $local_cdata['wiki_mode'] == 2 )
- {
- $ctmp=' style="text-decoration: underline;"';
- }
- $menubtn->assign_vars(array(
- 'FLAGS' => $ctmp,
- 'HREF' => makeUrl($local_page, 'do=setwikimode&level=2', true),
- 'TEXT' => $lang->get('onpage_btn_wikimode_global')
- ));
- $t3 = $menubtn->run();
-
- // Tack it onto the list of buttons that are already there...
- $this->toolbar_menu .= ' <table border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td>'.$t0.'</td>
- <td>'.$t1.'</td>
- <td>'.$t2.'</td>
- <td>'.$t3.'</td>
- </tr>
- </table>';
- }
-
- // Clear logs button
- if ( $conds['clearlogs'] )
- {
- $menubtn->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxClearLogs()); return false; }" title="' . $lang->get('onpage_tip_flushlogs') . '" accesskey="l"',
- 'HREF' => makeUrl($local_page, 'do=flushlogs', true),
- 'TEXT' => $lang->get('onpage_btn_clearlogs'),
- ));
- $this->toolbar_menu .= $menubtn->run();
- }
-
- // Delete page button
- if ( $conds['delete'] )
- {
- $s = $lang->get('onpage_btn_deletepage');
- if ( $this->page->ns->cdata['delvotes'] == 1 )
- {
- $subst = array(
- 'num_votes' => $this->page->ns->cdata['delvotes'],
- 'plural' => ''
- );
- $s .= $lang->get('onpage_btn_deletepage_votes', $subst);
- }
- else if ( $this->page->ns->cdata['delvotes'] > 1 )
- {
- $subst = array(
- 'num_votes' => $this->page->ns->cdata['delvotes'],
- 'plural' => $lang->get('meta_plural')
- );
- $s .= $lang->get('onpage_btn_deletepage_votes', $subst);
- }
-
- $menubtn->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDeletePage()); return false; }" title="' . $lang->get('onpage_tip_deletepage') . '" accesskey="k"',
- 'HREF' => makeUrl($local_page, 'do=deletepage', true),
- 'TEXT' => $s,
- ));
- $this->toolbar_menu .= $menubtn->run();
-
- }
-
- // Password-protect button
- if ( $conds['password'] )
- {
- // label at start
- $label = $this->makeParserText($this->elements['toolbar_label']);
- $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_password')));
- $t0 = $label->run();
-
- $menubtn->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxSetPassword()); return false; }" title="' . $lang->get('onpage_tip_password') . '"',
- 'HREF' => '#',
- 'TEXT' => $lang->get('onpage_btn_password_set'),
- ));
- $t = $menubtn->run();
-
- $this->toolbar_menu .= '<table border="0" cellspacing="0" cellpadding="0"><tr><td>'.$t0.'</td><td><input type="password" id="mdgPassSetField" size="10" /></td><td>'.$t.'</td></tr></table>';
- }
-
- // Manage ACLs button
- if ( $conds['acledit'] )
- {
- $menubtn->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { var s = ajaxOpenACLManager(); console.debug(s); return false; }" title="' . $lang->get('onpage_tip_aclmanager') . '" accesskey="m"',
- 'HREF' => makeUrl($local_page, 'do=aclmanager', true),
- 'TEXT' => $lang->get('onpage_btn_acl'),
- ));
- $this->toolbar_menu .= $menubtn->run();
- }
-
- // Administer page button
- if ( $conds['adminpage'] )
- {
- $menubtn->assign_vars(array(
- 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxAdminPage()); return false; }" title="' . $lang->get('onpage_tip_adminoptions') . '" accesskey="g"',
- 'HREF' => makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'PageManager', true),
- 'TEXT' => $lang->get('onpage_btn_admin'),
- ));
- $this->toolbar_menu .= $menubtn->run();
- }
-
- if ( strlen($this->toolbar_menu) > 0 )
- {
- $button->assign_vars(array(
- 'FLAGS' => 'id="mdgToolbar_moreoptions" onclick="if ( !KILL_SWITCH ) { return false; }" title="' . $lang->get('onpage_tip_moreoptions') . '"',
- 'PARENTFLAGS' => '',
- 'HREF' => makeUrl($local_page, 'do=moreoptions', true),
- 'TEXT' => $lang->get('onpage_btn_moreoptions')
- ));
- $tb .= $button->run();
- }
-
- // Generate the code for the Log in, Log out, Change theme, Administration, and Edit Sidebar buttons
- // Once again, the new template parsing system can be used here
-
- $parser = $this->makeParserText($this->elements['sidebar_button']);
-
- $parser->assign_vars(Array(
- 'HREF'=>makeUrlNS('Special', "Logout/{$session->csrf_token}/{$local_page}"),
- 'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { mb_logout(); return false; }"',
- 'TEXT'=>$lang->get('sidebar_btn_logout'),
- ));
-
- $logout_link = $parser->run();
-
- $parser->assign_vars(Array(
- 'HREF'=>makeUrlNS('Special', 'Login/' . $local_page),
- 'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { ajaxStartLogin(); return false; }"' . ( $local_page_id == 'Login' && $local_namespace == 'Special' ? ' class="currentpage"' : '' ),
- 'TEXT'=>$lang->get('sidebar_btn_login'),
- ));
-
- $login_link = $parser->run();
-
- $parser->assign_vars(Array(
- 'HREF'=>makeUrlNS('Special', 'ChangeStyle/'.$local_page),
- 'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { ajaxChangeStyle(); return false; }"' . ( $local_page_id == 'ChangeStyle' && $local_namespace == 'Special' ? ' class="currentpage"' : '' ),
- 'TEXT'=>$lang->get('sidebar_btn_changestyle'),
- ));
-
- $theme_link = $parser->run();
-
- // Run hooks
- $code = $plugins->setHook('tpl_compile_toolbar');
- foreach ( $code as $cmd )
- {
- eval($cmd);
- }
-
- //
- // ASSIGN VARIABLES
- //
-
- $this->assign_vars(array(
- 'PAGE_NAME' => htmlspecialchars($this->page->ns->cdata['name']),
- 'PAGE_URLNAME' => $paths->nslist[$this->namespace] . sanitize_page_id($this->page_id),
- 'TOOLBAR' => $tb,
- 'TOOLBAR_EXTRAS' => $this->toolbar_menu,
- 'STYLE_LINK' => makeUrlNS('Special', 'CSS', null, true), //contentPath.$paths->nslist['Special'].'CSS' . $p,
- 'LOGIN_LINK' => $login_link,
- 'LOGOUT_LINK' => $logout_link,
- 'THEME_LINK' => $theme_link
- ), true);
- $this->page_initted = true;
- }
-
- /**
- * Generates and assigns the Javascript system variables
- */
-
- function generate_js_header()
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
-
- $SID = ($session->sid_super) ? $session->sid_super : '';
-
- $local_page = $paths->get_pathskey($this->page_id, $this->namespace);
- $local_fullpage = $paths->get_pathskey($this->page_id, $this->namespace) . substr($paths->fullpage, strlen($paths->page));
-
- $urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($local_fullpage)));
- $urlname_clean = strtr( $urlname_clean, array( '<' => '<', '>' => '>' ) );
-
- $urlname_jssafe = sanitize_page_id($local_fullpage);
- $physical_urlname_jssafe = sanitize_page_id($paths->fullpage);
-
- $protected = is_object($this->page) ? $this->page->ns->cdata['really_protected'] : false;
-
- // Generate the dynamic javascript vars
- // Sorry. I know. This block is a mess.
- $js_dynamic = ' <script type="text/javascript">// <![CDATA[
- // This section defines some basic and very important variables that are used later in the static Javascript library.
- // SKIN DEVELOPERS: The template variable for this code block is {JS_DYNAMIC_VARS}. This MUST be inserted BEFORE the tag that links to the main Javascript lib.
- var title = \''. $urlname_jssafe .'\';
- var physical_title = \'' . $physical_urlname_jssafe . '\';
- var on_main_page = ' . ( $local_page == get_main_page() ? 'true' : 'false' ) . ';
- var main_page_members = \'' . addslashes(get_main_page(true)) . '\';
- var page_exists = '. ( ( is_object($this->page) ? $this->page->ns->exists() : true ) ? 'true' : 'false' ) .';
- var scriptPath = \'' . addslashes(scriptPath) . '\';
- var contentPath = \'' . addslashes(contentPath) . '\';
- var cdnPath = \'' . addslashes(cdnPath) . '\';
- var ENANO_SID = \'' . $SID . '\';
- var user_level = ' . $session->user_level . ';
- var auth_level = ' . $session->auth_level . ';
- var USER_LEVEL_GUEST = ' . USER_LEVEL_GUEST . ';
- var USER_LEVEL_MEMBER = ' . USER_LEVEL_MEMBER . ';
- var USER_LEVEL_CHPREF = ' . USER_LEVEL_CHPREF . ';
- var USER_LEVEL_MOD = ' . USER_LEVEL_MOD . ';
- var USER_LEVEL_ADMIN = ' . USER_LEVEL_ADMIN . ';
- var disable_redirect = ' . ( isset($_GET['redirect']) && $_GET['redirect'] == 'no' ? 'true' : 'false' ) . ';
- var pref_disable_js_fx = ' . ( @$session->user_extra['disable_js_fx'] == 1 ? 'true' : 'false' ) . ';
- var csrf_token = "' . $session->csrf_token . '";
- var prot = ' . ( ($protected) ? 'true' : 'false' ) .';
- var ENANO_SPECIAL_CREATEPAGE = \''. makeUrl($paths->nslist['Special'].'CreatePage') .'\';
- var ENANO_CREATEPAGE_PARAMS = \'_do=&pagename='. $this->page_id .'&namespace=' . $this->namespace . '\';
- var ENANO_SPECIAL_CHANGESTYLE = \''. makeUrlNS('Special', 'ChangeStyle') .'\';
- var namespace_list = [];
- var msg_loading_component = \'' . addslashes($lang->get('ajax_msg_loading_component')) . '\';
- var AES_BITS = '.AES_BITS.';
- var AES_BLOCKSIZE = '.AES_BLOCKSIZE.';
- var pagepass = \''. ( ( isset($_REQUEST['pagepass']) ) ? sha1($_REQUEST['pagepass']) : '' ) .'\';
- var ENANO_LANG_ID = ' . $lang->lang_id . ';
- var ENANO_PAGE_TYPE = "' . addslashes($this->namespace_string) . '";
- var enano_version = "' . enano_version() . '";';
-
- foreach ( $paths->nslist as $k => $c )
- {
- $js_dynamic .= "namespace_list['{$k}'] = '" . addslashes($c) . "';";
- }
- $js_dynamic .= "\n //]]>\n </script>";
-
- $this->assign_vars(array(
- 'JS_DYNAMIC_VARS' => $js_dynamic,
- 'REPORT_URI' => makeUrl($local_fullpage, 'do=sql_report', true)
- ), true);
- }
-
- /**
- * Fetches, parses, and assigns the sidebar.
- */
-
- function assign_sidebar()
- {
- //
- // COMPILE THE SIDEBAR
- //
-
- // This is done after the big assign_vars() so that sidebar code has access to the newly assigned variables
-
- list($this->tpl_strings['SIDEBAR_LEFT'], $this->tpl_strings['SIDEBAR_RIGHT'], $min) = $this->fetch_sidebar();
- $this->tpl_bool['sidebar_left'] = ( $this->tpl_strings['SIDEBAR_LEFT'] != $min) ? true : false;
- $this->tpl_bool['sidebar_right'] = ( $this->tpl_strings['SIDEBAR_RIGHT'] != $min) ? true : false;
- $this->tpl_bool['right_sidebar'] = $this->tpl_bool['sidebar_right']; // backward compatibility
- }
-
- /**
- * Initializes all variables related to on-page content. This includes sidebars and what have you.
- * @param object Optional PageProcessor object to use for passing metadata and permissions on. If omitted, uses information from $paths and $session.
- * @param bool If true, re-inits even if already initted with this page_id and namespace
- */
-
- function init_vars($page = false, $force_init = false)
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
-
- $need_shared_init = ( !$this->theme_initted || !$this->page_initted );
-
- if ( $need_shared_init )
- {
- if ( !$this->theme || !$this->style )
- {
- $this->load_theme();
- }
- $code = $plugins->setHook('compile_template', true);
- foreach ( $code as $cmd )
- {
- eval($cmd);
- }
- }
-
- if ( !$this->theme_loaded )
- $this->load_theme();
-
- require(ENANO_ROOT . "/themes/{$this->theme}/theme.cfg");
-
- if ( !$this->page_id || !$this->namespace )
- {
- $this->page_id = $paths->page_id;
- $this->namespace = $paths->namespace;
- }
-
- profiler_log('template: prepped for var set (loaded theme, ran compile_template hook)');
-
- $this->init_global_vars();
- profiler_log('template: global vars set');
-
- if ( !$this->theme_initted )
- $this->init_theme_vars();
-
- profiler_log('template: theme vars set');
-
- if ( !$this->page_initted && !empty($this->namespace) )
- {
- profiler_log('template: page vars set');
- $this->init_page_vars();
- }
- else
- {
- profiler_message('template: skipped setting page vars');
- }
-
- // Perform shared init (combine javascript, etc.)
- if ( $need_shared_init )
- {
- $this->generate_js_header();
- $this->assign_sidebar();
- profiler_log('template: assigned sidebar and JS');
- }
-
- // and finally one string value that needs to be symlinked...
- if ( !isset($this->tpl_strings['ADDITIONAL_HEADERS']) )
- {
- $this->tpl_strings['ADDITIONAL_HEADERS'] =& $this->additional_headers;
- }
-
- // done!
- $code = $plugins->setHook('template_var_init_end');
- foreach ( $code as $cmd )
- {
- eval($cmd);
- }
- }
-
- function header($simple = false)
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
-
- define('ENANO_HEADERS_SENT', true);
-
- echo $this->getHeader($simple);
- }
-
- function footer($simple = false)
- {
- echo $this->getFooter($simple);
- }
-
- function getHeader($simple = false)
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
-
- if ( !$this->theme_loaded )
- {
- $this->load_theme($session->theme, $session->style);
- }
-
- if ( !$this->page_initted || !$this->theme_initted )
- $this->init_vars();
-
- // I feel awful doing this.
- if ( preg_match('/^W3C_Validator/', @$_SERVER['HTTP_USER_AGENT']) )
- {
- header('Content-type: application/xhtml+xml');
- }
-
- $header = '';
-
- if ( !$this->no_headers )
- {
- $header = ( $simple ) ?
- $this->process_template('simple-header.tpl') :
- $this->process_template('header.tpl');
- }
- if ( !$simple && $session->user_logged_in && $session->unread_pms > 0 )
- {
- $header .= $this->notify_unread_pms();
- }
- if ( !$simple && $session->sw_timed_out )
- {
- $login_link = makeUrlNS('Special', 'Login/' . $paths->fullpage, 'level=' . $session->user_level, true);
- $header .= '<div class="usermessage">';
- $header .= $lang->get('user_msg_elev_timed_out', array( 'login_link' => $login_link ));
- $header .= '</div>';
- }
- if ( $this->site_disabled && $session->user_level >= USER_LEVEL_ADMIN && ( $paths->page != $paths->nslist['Special'] . 'Administration' ) )
- {
- $admin_link = makeUrlNS('Special', 'Administration', 'module=' . $paths->nslist['Admin'] . 'GeneralConfig', true);
- $header .= '<div class="usermessage"><b>' . $lang->get('page_sitedisabled_admin_msg_title') . '</b><br />
- ' . $lang->get('page_sitedisabled_admin_msg_body', array('admin_link' => $admin_link)) . '
- </div>';
- }
-
- return $header;
- }
-
- function getFooter($simple = false)
- {
- global $db, $session, $paths, $template, $plugins; // Common objects
- global $lang;
- if ( !$this->no_headers )
- {
-
- global $_starttime;
- if(isset($_GET['sqldbg']) && $session->get_permissions('mod_misc'))
- {
- echo '<h3>' . $lang->get('page_heading_sql_list') . '</h3><pre style="margin-left: 1em">';
- echo htmlspecialchars($db->sql_backtrace());
- echo '</pre>';
- }
-
- $t = ( $simple ) ? $this->process_template('simple-footer.tpl') : $this->process_template('footer.tpl');
-
- $f = microtime_float();
- $f = $f - $_starttime;
- $f = sprintf("%.02f", $f);
-
- $t_loc = $lang->get('page_msg_stats_gentime_short', array('time' => $f));
- $t_loc_long = $lang->get('page_msg_stats_gentime_long', array('time' => $f));
- …
Large files files are truncated, but you can click here to view the full file