diff -r d52dfa1f08da -r 323c4cd1aa37 includes/template.php --- a/includes/template.php Mon May 04 23:07:00 2009 -0400 +++ b/includes/template.php Tue May 05 00:10:26 2009 -0400 @@ -14,12 +14,27 @@ 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, $initted_to_page_id, $initted_to_namespace; + 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 $initted_to_theme = array( - 'theme' => false, - 'style' => false - ); + /** + * 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 @@ -287,7 +302,7 @@ function sidebar_widget($t, $h, $use_normal_section = false) { global $db, $session, $paths, $template, $plugins; // Common objects - if(!defined('ENANO_TEMPLATE_LOADED')) + if ( !$this->theme_loaded ) { $this->load_theme($session->theme, $session->style); } @@ -365,141 +380,65 @@ } /** - * 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 + * 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 init_vars($page = false, $force_init = false) + function set_page($page_id_or_pp, $namespace = false) { - global $db, $session, $paths, $template, $plugins; // Common objects - global $email; - global $lang; - - if(!$this->theme || !$this->style) + if ( is_object($page_id_or_pp) && get_class($page_id_or_pp) === 'PageProcessor' ) { - $this->load_theme(); - } - - if ( defined('ENANO_TEMPLATE_LOADED') ) - { - // trigger_error("\$template->init_vars() called more than once", E_USER_WARNING); - // die_semicritical('Illegal call', '

$template->init_vars() was called multiple times, this is not supposed to happen. Exiting with fatal error.

'); - } - else - { - @define('ENANO_TEMPLATE_LOADED', ''); + $this->page_initted = false; + $page =& $page_id_or_pp; + $this->page = $page; + $this->page_id = $page->page_id; + $this->namespace = $page->namespace; } - - if ( is_object($page) && ( @get_class($page) == 'PageProcessor' || preg_match('/^Namespace_/', @get_class($page)) ) ) + else if ( is_string($page_id_or_pp) ) { - $page_append = substr($paths->fullpage, strlen($paths->page)); - if ( isset($paths->nslist[$page->namespace]) ) - { - $local_page = $paths->nslist[$page->namespace] . $page->page_id; - } - else - { - $local_page = $page->namespace . substr($paths->nslist['Special'], -1) . $page->page_id . $page_append; - } - $local_fullpage = $local_page . $page_append; - $local_page_id =& $page->page_id; - $local_namespace =& $page->namespace; - $local_page_exists = $page->exists(); - $perms =& $page->perms; - if ( !is_object($perms) ) - { - unset($perms); - $perms = $session->fetch_page_acl($local_page_id, $local_namespace); - } + 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 { - $local_page =& $paths->page; - $local_page_id =& $paths->page_id; - $local_fullpage =& $paths->fullpage; - $local_namespace =& $paths->namespace; - $local_page_exists =& $paths->page_exists; - $local_page_protected =& $paths->page_protected; - $perms =& $session; - } - - if ( $local_page_id === $this->initted_to_page_id && $local_namespace === $this->initted_to_namespace && $this->theme === $this->initted_to_theme['theme'] && $this->style === $this->initted_to_theme['style'] && !$force_init ) - { - // we're already initted with this page. - return true; - } - - profiler_log("template: starting var init"); - - $this->initted_to_page_id = $local_page_id; - $this->initted_to_namespace = $local_namespace; - $this->initted_to_theme = array( - 'theme' => $this->theme, - 'style' => $this->style - ); - - require(ENANO_ROOT . "/themes/{$this->theme}/theme.cfg"); - - if ( $local_page_exists && isPage($local_page) ) - { - $local_cdata =& $paths->pages[$local_page]; + return false; } - else - { - // if the page doesn't exist but we're trying to load it, it was requested manually and $paths->cpage should match it. - if ( $paths->page_id == $local_page_id ) - { - // load metadata from cpage - $local_cdata =& $paths->cpage; - } - else - { - // generate our own failsafe metadata - $local_cdata = array( - 'urlname' => $local_page, - 'urlname_nons' => $local_page_id, - 'namespace' => $local_namespace, - 'name' => get_page_title_ns($local_page_id, $local_namespace), - 'comments_on' => 0, - 'protected' => 0, - 'wiki_mode' => 2, - 'delvotes' => 0, - 'delvote_ips' => serialize(array()) - ); - } - } + return true; + } + + /** + * 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; - // calculate protection - if ( !isset($local_page_protected) ) - { - if ( $local_cdata['protected'] == 0 ) - { - $local_page_protected = false; - } - else if ( $local_cdata['protected'] == 1 ) - { - $local_page_protected = true; - } - else if ( $local_cdata['protected'] == 2 ) - { - if ( - ( !$session->user_logged_in || // Is the user logged in? - ( $session->user_logged_in && $session->reg_time + ( 4 * 86400 ) >= time() ) ) // If so, have they been registered for 4 days? - && !$perms->get_permissions('even_when_protected') ) // And of course, is there an ACL that overrides semi-protection? - { - $local_page_protected = true; - } - else - { - $local_page_protected = false; - } - } - } - - $tplvars = $this->extract_vars('elements.tpl'); - - if(isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) + // IE PNG fixing code + if ( isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) { $this->add_header('