# HG changeset patch # User Dan # Date 1237129648 14400 # Node ID 7f8262b2004a97016b27c56a8a2a01225c1c9172 # Parent 09c3ba4f6fbf5ab0186773e616f6b2cc779317e4 New template feature: template hooks () diff -r 09c3ba4f6fbf -r 7f8262b2004a includes/clientside/jsres.php --- a/includes/clientside/jsres.php Sat Mar 14 15:26:33 2009 -0400 +++ b/includes/clientside/jsres.php Sun Mar 15 11:07:28 2009 -0400 @@ -54,10 +54,7 @@ // // We need to see if this is a specially marked Enano development server. You can create an Enano -// development server by cloning the Mercurial repository into a directory named repo, and then -// using symlinks to reference the original files so as to segregate unique files from non-unique -// and distribution-standard ones. Enano will pivot its root directory accordingly if the file -// .enanodev is found in the Enano root (not /repo/). +// development server using the script found on hg.enanocms.org. if ( strpos(__FILE__, '/repo/') && ( file_exists('../../.enanodev') || file_exists('../../../.enanodev') ) ) { // We have a development directory. Remove /repo/ from the picture. diff -r 09c3ba4f6fbf -r 7f8262b2004a includes/clientside/static/dropdown.js --- a/includes/clientside/static/dropdown.js Sat Mar 14 15:26:33 2009 -0400 +++ b/includes/clientside/static/dropdown.js Sun Mar 15 11:07:28 2009 -0400 @@ -456,6 +456,8 @@ if(!type) type = '*'; ret = new Array(); + if ( !parent ) + return ret; el = parent.getElementsByTagName(type); for ( var i = 0; i < el.length; i++ ) { diff -r 09c3ba4f6fbf -r 7f8262b2004a includes/template.php --- a/includes/template.php Sat Mar 14 15:26:33 2009 -0400 +++ b/includes/template.php Sun Mar 15 11:07:28 2009 -0400 @@ -1014,7 +1014,7 @@ $js_foot = << - + //]]> JSEOF; } @@ -1195,6 +1195,7 @@ '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')), 'TOOLBAR_EXTRAS' => $this->toolbar_menu, 'REQUEST_URI' => ( defined('ENANO_CLI') ? '' : $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ), @@ -1271,9 +1272,20 @@ global $db, $session, $paths, $template, $plugins; // Common objects global $lang; - ob_start(); + 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) + if ( !$this->theme_loaded ) { $this->load_theme($session->theme, $session->style); } @@ -1296,36 +1308,23 @@ } if ( !$simple && $session->user_logged_in && $session->unread_pms > 0 ) { - echo $this->notify_unread_pms(); + $header .= $this->notify_unread_pms(); } if ( !$simple && $session->sw_timed_out ) { $login_link = makeUrlNS('Special', 'Login/' . $paths->fullpage, 'level=' . $session->user_level, true); - echo '
'; - echo $lang->get('user_msg_elev_timed_out', array( 'login_link' => $login_link )); - echo '
'; + $header .= '
'; + $header .= $lang->get('user_msg_elev_timed_out', array( 'login_link' => $login_link )); + $header .= '
'; } 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); - echo '
' . $lang->get('page_sitedisabled_admin_msg_title') . '
+ $header .= '
' . $lang->get('page_sitedisabled_admin_msg_title') . '
' . $lang->get('page_sitedisabled_admin_msg_body', array('admin_link' => $admin_link)) . '
'; } } - - function footer($simple = false) - { - echo $this->getFooter($simple); - } - - function getHeader() - { - $headers_sent = true; - if(!defined('ENANO_HEADERS_SENT')) - define('ENANO_HEADERS_SENT', ''); - if(!$this->no_headers) return $this->process_template('header.tpl'); - } function getFooter($simple = false) { global $db, $session, $paths, $template, $plugins; // Common objects @@ -1644,21 +1643,30 @@ /** * Post-processor for template code. Basically what this does is it localizes {lang:foo} blocks. * @param string Mostly-processed TPL code + * @param bool Post-eval switch. If true, does not escape code. * @return string */ - function compile_template_text_post($text) + function compile_template_text_post($text, $post_eval = false) { + global $db, $session, $paths, $template, $plugins; // Common objects global $lang; + + // Language strings preg_match_all('/\{lang:([a-z0-9]+_[a-z0-9_]+)\}/', $text, $matches); foreach ( $matches[1] as $i => $string_id ) { $string = $lang->get($string_id); - $string = str_replace('\\', '\\\\', $string); - $string = str_replace('\'', '\\\'', $string); + if ( !$post_eval ) + { + $string = str_replace('\\', '\\\\', $string); + $string = str_replace('\'', '\\\'', $string); + } $text = str_replace_once($matches[0][$i], $string, $text); } - preg_match_all('/\{url:([A-z0-9]+):([\w\.\/:;\(\)@\[\]_=-]+)(?::([^\s\}]+))?(?:\|(escape))?\}/', $text, $matches); + + // URLs + preg_match_all('/\{url:([A-z0-9]+):([^\s\}]+?)(?:;([^\s\}]+?))?(?:\|(escape))?\}/i', $text, $matches); foreach ( $matches[1] as $i => $string_id ) { $namespace =& $matches[1][$i]; @@ -1672,11 +1680,47 @@ $result = makeUrlNS($namespace, $page_id, $params, $escape); + if ( !$post_eval ) + { + $result = str_replace('\\', '\\\\', $result); + $result = str_replace('\'', '\\\'', $result); + } + $text = str_replace_once($matches[0][$i], $result, $text); } + + $code = $plugins->setHook('compie_template_text_post'); + foreach ( $code as $cmd ) + { + eval($cmd); + } + return $text; } + /** + * Returns the output of a theme hook + * @param string Hook name + * @return string + */ + + function get_theme_hook($hook) + { + global $db, $session, $paths, $template, $plugins; // Common objects + global $lang; + + ob_start(); + $code = $plugins->setHook($hook); + foreach ( $code as $cmd ) + { + eval($cmd); + } + $out = ob_get_contents(); + ob_end_clean(); + + return $out; + } + // n00bish comments removed from here. 2008-03-13 @ 12:02AM when I had nothing else to do. /** @@ -2601,6 +2645,9 @@ // System messages $text = preg_replace('//is', '\' . $template->tplWikiFormat($paths->sysMsg(\'\\1\')) . \'', $text); + // Hooks + $text = preg_replace('//', '\' . $this->get_theme_hook(\'\\1\') . \'', $text); + // only do this if the plugins API is loaded if ( is_object(@$plugins) ) {