+++ /dev/null
-<?php\r
-\r
-/***************************************************************************\r
- * template.php\r
- * ------------------\r
- * copyright : (C) 2001 The phpBB Group\r
- * email : support@phpbb.com\r
- *\r
- * phpBB version : 2.0.x\r
- * eXtreme Styles mod : 2.3.1\r
- * Support : http://www.phpbbstyles.com\r
- *\r
- * file revision : 77\r
- * project revision : 78\r
- * last modified : 05 Dec 2005 13:54:54\r
- *\r
- ***************************************************************************/\r
-\r
-/***************************************************************************\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- ***************************************************************************/\r
-\r
-/**\r
- *\r
- * Template class. By Nathan Codding of the phpBB group.\r
- * The interface was originally inspired by PHPLib templates,\r
- * and the template file formats are quite similar.\r
- *\r
- * eXtreme Styles mod by CyberAlien.\r
- *\r
- * IF, ELSEIF, ENDIF tags are backported from phpBB 2.2\r
- *\r
- * Documentation for this mod can be found here:\r
- * http://www.phpbbstyles.com\r
- *\r
- * Support for eXtreme Styles mod is provided at http://www.phpbbstyles.com\r
- *\r
- * Thanks to DMaJ007 for idea on how to include some extra tags.\r
- *\r
- */\r
-\r
-define('XS_SEPARATOR', '.');\r
-define('XS_DIR_CACHE', 'cache');\r
-define('XS_USE_ISSET', '1');\r
-\r
-// cache filenames prefix\r
-define('XS_TPL_PREFIX', 'tpl_');\r
-define('XS_TPL_PREFIX2', 'tpl2_');\r
-\r
-// templates directory\r
-define('XS_TPL_START', 'templates/');\r
-define('XS_TPL_ANY', '/templates/');\r
-\r
-// internal xs mod definitions. do not edit.\r
-define('XS_TAG_NONE', 0);\r
-define('XS_TAG_PHP', 1);\r
-define('XS_TAG_BEGIN', 2);\r
-define('XS_TAG_END', 3);\r
-define('XS_TAG_INCLUDE', 4);\r
-define('XS_TAG_IF', 5);\r
-define('XS_TAG_ELSE', 6);\r
-define('XS_TAG_ELSEIF', 7);\r
-define('XS_TAG_ENDIF', 8);\r
-define('XS_TAG_DEFINE', 9);\r
-define('XS_TAG_UNDEFINE', 10);\r
-define('XS_TAG_BEGINELSE', 11);\r
-\r
-\r
-class Template {\r
- var $classname = "Template";\r
-\r
- // variable that holds all the data we'll be substituting into\r
- // the compiled templates.\r
- // ...\r
- // This will end up being a multi-dimensional array like this:\r
- // $this->_tpldata[block.][iteration#][child.][iteration#][child2.][iteration#][variablename] == value\r
- // if it's a root-level variable, it'll be like this:\r
- // $this->vars[varname] == value or $this->_tpldata['.'][0][varname] == value\r
- // array "vars" is added for easier access to data\r
- var $_tpldata = array('.' => array(0 => array()));\r
- var $vars;\r
-\r
- // Hash of filenames for each template handle.\r
- var $files = array();\r
- var $files_cache = array(); // array of cache files that exists\r
- var $files_cache2 = array(); // array of cache files (exists or not exists)\r
-\r
- // Root template directory.\r
- var $root = '';\r
-\r
- // Cache directory (compatible with default cache mod)\r
- var $cachedir = '';\r
-\r
- // Search/replace for unknown files\r
- var $cache_search = array();\r
- var $cache_replace = array();\r
-\r
- // Template root directory (generated by set_rootdir)\r
- var $tpldir = '';\r
- var $tpldir_len = 0;\r
-\r
- // Default template directory.\r
- // If file for default template isn't found file from this template is used.\r
- var $tpldef = 'subSilver';\r
-\r
- // this will hash handle names to the compiled code for that handle.\r
- var $compiled_code = array();\r
-\r
- // This will hold the uncompiled code for that handle.\r
- var $uncompiled_code = array();\r
-\r
- // Cache settings\r
- var $use_cache = 1;\r
- var $cache_writable = 1;\r
-\r
- // Auto-compile setting\r
- var $auto_compile = 1;\r
-\r
- // Current template name\r
- var $tpl = '';\r
-\r
- // List of replacements. tpl files in this list will be replaced with other tpl files\r
- // according to configuration in xs.cfg\r
- var $replace = array();\r
-\r
- // counter for include\r
- var $include_count = 0;\r
-\r
- // php extension. will be replaced by $phpEx in Template() function unless you disable it there\r
- var $php = 'php';\r
-\r
- // True if check switches\r
- var $xs_check_switches = 1;\r
-\r
- // eXtreme Styles variables\r
- var $xs_started = 0;\r
- var $xs_version = 8; // number version. internal. do not change.\r
- var $xs_versiontxt = '2.3.1'; // text version\r
-\r
- // These handles will be parsed if pparse() is executed.\r
- // Can be used to automatically include header/footer if there is any content.\r
- var $preparse = '';\r
- var $postparse = '';\r
-\r
- // subtemplates mod detection\r
- var $subtemplates = false;\r
-\r
- // style configuration\r
- var $style_config = array();\r
-\r
- // list of switches that are known typos in some mods.\r
- // when error checking is enabled these errors will be auto-fixed.\r
- // format:\r
- // array(start_tag, end_tag)\r
- var $bugs = array(\r
- // ezportal typo:\r
- array('fetchpost_row', 'fetch_post_row'),\r
- // mycalendar 2.2.7 typos:\r
- array('date_cell', 'date_cells'),\r
- array('date_row', 'date_rows'),\r
- // history mod typo:\r
- array('site_today', 'site_week'),\r
- );\r
-\r
- /**\r
- * Constructor. Installs XS mod on first run or updates it and sets the root dir.\r
- */\r
- function Template($root = '.')\r
- {\r
- // setting pointer "vars"\r
- $this->vars = &$this->_tpldata['.'][0];\r
- // load configuration\r
- $this->load_config($root, true);\r
- }\r
-\r
- /**\r
- * Load mod configuration\r
- */\r
- function load_config($root, $edit_db)\r
- {\r
- global $board_config, $phpbb_root_path, $phpEx;\r
- // getting mod version from config and comparing with real data\r
- $ver = isset($board_config['xs_version']) ? $board_config['xs_version'] : 0;\r
- // check configuration\r
- // set config values if there aren't any\r
- $add = array();\r
- $del = array();\r
- $up = array();\r
- // list of outdated variables\r
- $outdated = array(\r
- 'xs_versoin', // was a typo in one of previous versions\r
- 'xs_separator', // no longer used\r
- 'xs_cache_dir_absolute', // no longer used\r
- 'xs_cache_dir', // no longer used\r
- 'xs_use_isset', // no longer used\r
- );\r
- // list of default values\r
- $default = array(\r
- 'xs_auto_compile' => 1,\r
- 'xs_auto_recompile' => 1,\r
- 'xs_use_cache' => 1,\r
- 'xs_php' => $phpEx,\r
- 'xs_def_template' => 'subSilver',\r
- 'xs_check_switches' => 1,\r
- 'xs_warn_includes' => 1,\r
- 'xs_add_comments' => 0,\r
- 'xs_ftp_host' => '',\r
- 'xs_ftp_login' => '',\r
- 'xs_ftp_path' => '',\r
- 'xs_downloads_count' => '0',\r
- 'xs_downloads_default' => '0',\r
- 'xs_shownav' => '1',\r
- 'xs_template_time' => '0',\r
- );\r
- // checking if all variables exist\r
- foreach($default as $var => $value)\r
- {\r
- if(!isset($board_config[$var]))\r
- {\r
- $board_config[$var] = $value;\r
- $add[] = $var;\r
- }\r
- }\r
- // checking if there are any outdated variables that should be deleted\r
- for($i=0; $i<count($outdated); $i++)\r
- {\r
- if(isset($board_config[$outdated[$i]]))\r
- {\r
- $del[] = $outdated[$i];\r
- }\r
- }\r
- if(!isset($board_config['xs_version']))\r
- {\r
- $board_config['xs_version'] = $this->xs_version;\r
- $add[] = 'xs_version';\r
- }\r
- elseif($board_config['xs_version'] != $this->xs_version)\r
- {\r
- $board_config['xs_version'] = $this->xs_version;\r
- $up[] = 'xs_version';\r
- }\r
- // check config\r
- if(!empty($board_config['xs_auto_recompile']))\r
- {\r
- if(!$board_config['xs_auto_compile'])\r
- {\r
- $board_config['xs_auto_compile'] = 1;\r
- if(!in_array('xs_auto_compile', $up) && !in_array('xs_auto_compile', $add))\r
- {\r
- $up[] = 'xs_auto_compile';\r
- }\r
- }\r
- }\r
- // install/upgrade\r
- if($edit_db && ((count($add) > 0) || (count($up) > 0) || (count($del) > 0)))\r
- {\r
- $board_config['xs_template_time'] = time();\r
- if(!in_array('xs_template_time', $up))\r
- {\r
- $up[] = 'xs_template_time';\r
- }\r
- global $db;\r
- if(!empty($db))\r
- {\r
- // adding new config values\r
- for($i=0; $i<count($add); $i++)\r
- {\r
- $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('" . $add[$i] . "', '" . str_replace('\\\'', '\'\'', addslashes($board_config[$add[$i]])) . "')";\r
- $db->sql_query($sql);\r
- }\r
- // removing old configuration variables that aren't used\r
- for($i=0; $i<count($del); $i++)\r
- {\r
- $sql = "DELETE FROM " . CONFIG_TABLE . " WHERE config_name='" . $del[$i] . "'";\r
- $db->sql_query($sql);\r
- }\r
- // updating variables that should be overwritten\r
- for($i=0; $i<count($up); $i++)\r
- {\r
- $sql = "UPDATE " . CONFIG_TABLE . " SET config_value='" . str_replace('\\\'', '\'\'', addslashes($board_config[$up[$i]])) . "' WHERE config_name='" . $up[$i] . "'";\r
- $db->sql_query($sql);\r
- }\r
- // recache config table for cat_hierarchy 2.1.0\r
- global $config;\r
- if(isset($config->data) && $config->data === $board_config && isset($config->data['mod_cat_hierarchy']))\r
- {\r
- $config->read(true);\r
- }\r
- }\r
- }\r
- $this->php = $board_config['xs_php'];\r
- $this->tpldef = $board_config['xs_def_template'];\r
- $this->use_cache = $board_config['xs_use_cache'];\r
- $this->auto_compile = $board_config['xs_auto_compile'];\r
- $this->xs_check_switches = $board_config['xs_check_switches'];\r
- $this->cache_search = array('.', '\\', '/', '_tpl');\r
- $this->cache_replace = array('_', XS_SEPARATOR, XS_SEPARATOR, '.'.$this->php);\r
- $old_root = $this->root;\r
- $this->set_rootdir($root);\r
- if(!empty($this->tpl))\r
- {\r
- $this->load_replacements($this->tpldir . $this->tpl . '/xs.cfg');\r
- }\r
- if($old_root !== $this->root)\r
- {\r
- $this->clear_files();\r
- }\r
- }\r
-\r
- /**\r
- * Sets the template root directory for this Template object.\r
- */\r
- function set_rootdir($dir)\r
- {\r
- global $board_config, $phpbb_root_path;\r
- if (!@is_dir($dir))\r
- {\r
- return false;\r
- }\r
- $dir = str_replace('\\', '/', $dir);\r
- // creating absolute path for cache\r
- $this->cachedir = $phpbb_root_path . XS_DIR_CACHE . '/';\r
- // creating absolute path for current template and root dir\r
- $this->tpldir = $phpbb_root_path . 'templates/';\r
- $this->tpldir_len = strlen($this->tpldir);\r
- $this->root = $dir;\r
- $this->tpl = $this->template_name($dir);\r
- // check configuration\r
- $this->get_config();\r
- // check subtemplates mod\r
- $sub_templates_cfg = $this->root . '/sub_templates.cfg';\r
- if(defined('LANG_EXTEND_DONE') && @file_exists($sub_templates_cfg))\r
- {\r
- $this->subtemplates = true;\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Destroys this template object. Should be called when you're done with it, in order\r
- * to clear out the template data so you can load/parse a new template set.\r
- */\r
- function destroy()\r
- {\r
- $this->_tpldata = array('.' => array(0 => array()));\r
- $this->vars = &$this->_tpldata['.'][0];\r
- $this->xs_started = 0;\r
- }\r
-\r
- /**\r
- * Clears list of compiled files.\r
- */\r
- function clear_files()\r
- {\r
- $this->files = array();\r
- $this->files_cache = array();\r
- $this->files_cache2 = array();\r
- $this->compiled_code = array();\r
- $this->uncompiled_code = array();\r
- }\r
-\r
- /**\r
- * Loads replacements from .cfg file\r
- */\r
- function load_replacements($file)\r
- {\r
- if(@file_exists($file))\r
- {\r
- $replace = array();\r
- @include($file);\r
- $this->replace = array_merge($this->replace, $replace);\r
- }\r
- }\r
-\r
- /**\r
- * Extracts template name from path\r
- */\r
- function template_name($dir)\r
- {\r
- $tpl = XS_TPL_ANY; // can start at any position\r
- $tpl_null = XS_TPL_START; // can start only at zero position\r
- // searching for 'templates/' and removing everything before it\r
- $pos = strpos($dir, $tpl);\r
- if($pos === false)\r
- {\r
- if(substr($dir, 0, strlen($tpl_null)) !== $tpl_null)\r
- {\r
- return '';\r
- }\r
- $str = substr($dir, strlen($tpl_null), strlen($dir));\r
- }\r
- else\r
- {\r
- $str = substr($dir, $pos + strlen($tpl), strlen($dir));\r
- }\r
- // searching for one more 'templates/'\r
- // that can happen if full path is like /home/some_dude/templates/phpbb/templates/subSilver/\r
- $dir = $this->template_name($str);\r
- if(!$dir)\r
- {\r
- $dir = $str;\r
- }\r
- if(strpos($str, $tpl) !== false)\r
- {\r
- $dir = $this->template_name($str);\r
- }\r
- // check for another subdirectory\r
- $pos = strpos($dir, '/');\r
- if($pos)\r
- {\r
- $dir = substr($dir, 0, $pos);\r
- }\r
- return $dir;\r
- }\r
-\r
- function subtemplates_make_filename($filename)\r
- {\r
- global $HTTP_GET_VARS, $HTTP_POST_VARS, $db, $board_config, $images, $theme;\r
- global $sub_template_key_image, $sub_templates;\r
- global $tree;\r
-\r
- // initiate the sub-template image pack that will be use\r
- $sub_template_key_image = POST_CAT_URL . '0';\r
-\r
- // Check if sub_templates are defined for this theme\r
- if ( $board_config['version'] > '.0.5' )\r
- {\r
- $sub_templates_cfg = @phpbb_realpath($this->root . '/sub_templates.cfg');\r
- }\r
- else\r
- {\r
- $sub_templates_cfg = $this->root . '/sub_templates.cfg';\r
- }\r
- @include($sub_templates_cfg);\r
- if ( isset($sub_templates) )\r
- {\r
- // search an id\r
- $cat_id = 0;\r
- $forum_id = 0;\r
- $topic_id = 0;\r
- $post_id = 0;\r
-\r
- if ( !defined('IN_PRIVMSG') && ( isset($HTTP_GET_VARS[POST_POST_URL]) || isset($HTTP_POST_VARS[POST_POST_URL]) ) )\r
- {\r
- $post_id = isset($HTTP_GET_VARS[POST_POST_URL]) ? intval($HTTP_GET_VARS[POST_POST_URL]) : intval($HTTP_POST_VARS[POST_POST_URL]);\r
- }\r
-\r
- if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) || isset($HTTP_POST_VARS[POST_TOPIC_URL]) )\r
- {\r
- $topic_id = intval($HTTP_GET_VARS[POST_TOPIC_URL]) ? intval($HTTP_GET_VARS[POST_TOPIC_URL]) : intval($HTTP_POST_VARS[POST_TOPIC_URL]);\r
- }\r
-\r
- if ( isset($HTTP_GET_VARS[POST_FORUM_URL]) || isset($HTTP_POST_VARS[POST_FORUM_URL]) )\r
- {\r
- $forum_id = isset($HTTP_GET_VARS[POST_FORUM_URL]) ? intval($HTTP_GET_VARS[POST_FORUM_URL]) : intval($HTTP_POST_VARS[POST_FORUM_URL]);\r
- }\r
-\r
- if ( isset($HTTP_GET_VARS[POST_CAT_URL]) || isset($HTTP_POST_VARS[POST_CAT_URL]) )\r
- {\r
- $cat_id = isset($HTTP_GET_VARS[POST_CAT_URL]) ? intval($HTTP_GET_VARS[POST_CAT_URL]) : intval($HTTP_POST_VARS[POST_CAT_URL]);\r
- }\r
-\r
- if ( isset($HTTP_GET_VARS['selected_id']) || isset($HTTP_POST_VARS['selected_id']) )\r
- {\r
- $selected_id = isset($HTTP_GET_VARS['selected_id']) ? $HTTP_GET_VARS['selected_id'] : $HTTP_POST_VARS['selected_id'];\r
- $type = substr($selected_id, 0, 1);\r
- $id = intval(substr($selected_id, 1));\r
- if (!empty($id)) switch ($type)\r
- {\r
- case POST_CAT_URL:\r
- $cat_id = $id;\r
- break;\r
- case POST_FORUM_URL:\r
- $forum_id = $id;\r
- break;\r
- case POST_TOPIC_URL:\r
- $topic_id = $id;\r
- break;\r
- case POST_POST_URL:\r
- if ( !defined('IN_PRIVMSG') )\r
- {\r
- $post_id = $id;\r
- break;\r
- }\r
- default:\r
- break;\r
- }\r
- }\r
-\r
- // find the forum\r
- if ( ($forum_id <= 0) && ($cat_id <= 0) )\r
- {\r
- if ($post_id > 0)\r
- {\r
- $sql = "SELECT * FROM " . POSTS_TABLE . " WHERE post_id=$post_id"; \r
- if ( !($result = $db->sql_query($sql)) )\r
- {\r
- message_die(GENERAL_ERROR, 'Wasn\'t able to access posts', '', __LINE__, __FILE__, $sql);\r
- }\r
- if ( $row = $db->sql_fetchrow($result) )\r
- {\r
- $forum_id = $row['forum_id'];\r
- }\r
- }\r
-\r
- if ($topic_id > 0)\r
- {\r
- $sql = "SELECT * FROM " . TOPICS_TABLE . " WHERE topic_id=$topic_id"; \r
- if ( !($result = $db->sql_query($sql)) )\r
- {\r
- message_die(GENERAL_ERROR, 'Wasn\'t able to access topics', '', __LINE__, __FILE__, $sql);\r
- }\r
- if ( $row = $db->sql_fetchrow($result) )\r
- {\r
- $forum_id = $row['forum_id'];\r
- }\r
- }\r
- }\r
-\r
- // is the categories hierarchy v 2 installed ?\r
- $cat_hierarchy = function_exists('get_auth_keys');\r
-\r
- // get the ids (forums and cats)\r
- $fids = array();\r
- if (!$cat_hierarchy)\r
- {\r
- if ($forum_id > 0)\r
- {\r
- // add the forum_id\r
- $fids[] = POST_FORUM_URL . $forum_id;\r
-\r
- // get the cat_id\r
- $sql = "SELECT * FROM " . FORUMS_TABLE . " WHERE forum_id=$forum_id";\r
- if ( !($result = $db->sql_query($sql)) )\r
- {\r
- message_die(GENERAL_ERROR, 'Wasn\'t able to access forums', '', __LINE__, __FILE__, $sql);\r
- }\r
- if ( $row = $db->sql_fetchrow($result) )\r
- {\r
- $cat_id = $row['cat_id'];\r
- }\r
- }\r
-\r
- // add the cat_id\r
- if ($cat_id > 0)\r
- {\r
- $fids[] = POST_CAT_URL . $cat_id;\r
- }\r
-\r
- // add the root level\r
- $fids[] = 'Root';\r
- }\r
- else\r
- {\r
- // categories hierarchy v 2 compliancy\r
- $cur = 'Root';\r
- if ($forum_id > 0)\r
- {\r
- $cur = POST_FORUM_URL . $forum_id;\r
- }\r
- else if ($cat_id > 0)\r
- {\r
- $cur = POST_CAT_URL . $cat_id;\r
- }\r
-\r
- // add start\r
- $fids[] = $cur;\r
- while ( ($cur != 'Root') && !empty($cur) )\r
- {\r
- // get parent level\r
- $cur = (isset($tree['main'][ $tree['keys'][$cur] ])) ? $tree['main'][ $tree['keys'][$cur] ] : 'Root';\r
-\r
- // add the parent level\r
- if ( !empty($cur) )\r
- {\r
- $fids[] = $cur;\r
- }\r
- }\r
- }\r
-\r
- // search if this file is part of a sub-template\r
- $sub_tpl_file = '';\r
- $sub_css_file = '';\r
- $sub_img_file = '';\r
- $sub_img_path = '';\r
- $template_path = 'templates/';\r
- $template_name = substr( $this->root, strpos($this->root, $template_path) + strlen($template_path) );\r
- $real_root = $this->root;\r
- if ( $board_config['version'] > '.0.5' )\r
- {\r
- $real_root = @phpbb_realpath($this->root);\r
- }\r
- if (substr($filename, 0, 1) != '/')\r
- {\r
- $found = false;\r
- $num_fids = count($fids);\r
- for ($i = 0; !$found && ($i < $num_fids); $i++)\r
- {\r
- $key = $fids[$i];\r
-\r
- // convert root into c0 category\r
- if ( ($key == 'Root') || empty($key) )\r
- {\r
- $key = POST_CAT_URL . '0';\r
- }\r
-\r
- if ( isset($sub_templates[$key]) )\r
- {\r
- // get the sub-template path\r
- $current_template_path = $template_path . $template_name . '/' . $sub_templates[$key]['dir'];\r
- $root_template_path = $real_root . '/' . $sub_templates[$key]['dir'];\r
-\r
- // set the filename\r
- if ( empty($sub_tpl_file) && file_exists($root_template_path . '/' . $filename) )\r
- {\r
- $found = true;\r
- $sub_tpl_file = $sub_templates[$key]['dir'] . '/' . $filename;\r
- break;\r
- }\r
- }\r
- }\r
-\r
- // set the css file name\r
- $found = false;\r
- $num_fids = count($fids);\r
- for ($i = 0; !$found && ($i < $num_fids); $i++)\r
- {\r
- $key = $fids[$i];\r
-\r
- // convert root into c0 category\r
- if ( ($key == 'Root') || empty($key) )\r
- {\r
- $key = POST_CAT_URL . '0';\r
- }\r
-\r
- if ( isset($sub_templates[$key]) )\r
- {\r
- // get the sub-template path\r
- $current_template_path = $template_path . $template_name . '/' . $sub_templates[$key]['dir'];\r
- $root_template_path = $real_root . '/' . $sub_templates[$key]['dir'];\r
- if ( empty($sub_css_file) && isset($sub_templates[$key]['head_stylesheet']) && file_exists($root_template_path . '/' . $sub_templates[$key]['head_stylesheet']) )\r
- {\r
- $found = true;\r
- $sub_css_file = $sub_templates[$key]['dir'] . '/' . $sub_templates[$key]['head_stylesheet'];\r
- break;\r
- }\r
- }\r
- }\r
-\r
- // set the img file name\r
- $found = false;\r
- $num_fids = count($fids);\r
- for ($i = 0; !$found && ($i < $num_fids); $i++)\r
- {\r
- $key = $fids[$i];\r
-\r
- // convert root into c0 category\r
- if ( ($key == 'Root') || empty($key) )\r
- {\r
- $key = POST_CAT_URL . '0';\r
- }\r
-\r
- if ( isset($sub_templates[$key]) )\r
- {\r
- // get the sub-template path\r
- $current_template_path = $template_path . $template_name . '/' . $sub_templates[$key]['dir'];\r
- $root_template_path = $real_root . '/' . $sub_templates[$key]['dir'];\r
- if ( isset($sub_templates[$key]['imagefile']) && file_exists($root_template_path . '/' . $sub_templates[$key]['imagefile']) )\r
- {\r
- $sub_img_path = $sub_templates[$key]['dir'];\r
- $sub_img_file = $sub_templates[$key]['imagefile'];\r
-\r
- // send back the lowest level of the images file\r
- $found = true;\r
- $sub_template_key_image = $key;\r
- break;\r
- }\r
- }\r
- }\r
- }\r
-\r
- // set the tpl file\r
- if ( !empty($sub_tpl_file) )\r
- {\r
- $filename = $sub_tpl_file;\r
- }\r
-\r
- // set the css file\r
- if ( !empty($sub_css_file) )\r
- {\r
- $theme['head_stylesheet'] = $sub_css_file;\r
- }\r
-\r
- // get the root level images\r
- $key = POST_CAT_URL . '0';\r
- if ( isset($sub_templates[$key]) )\r
- {\r
- // get the sub-template path\r
- $current_template_path = $template_path . $template_name . '/' . $sub_templates[$key]['dir'];\r
- $root_template_path = $real_root . '/' . $sub_templates[$key]['dir'];\r
- if ( isset($sub_templates[$key]['imagefile']) && file_exists($root_template_path . '/' . $sub_templates[$key]['imagefile']) )\r
- {\r
- $sav_images = $images;\r
- $images = array();\r
- @include($root_template_path . '/' . $sub_templates[$key]['imagefile']);\r
- $img_lang = ( file_exists($root_template_path . '/images/lang_' . $board_config['default_lang']) ) ? $board_config['default_lang'] : 'english';\r
- foreach($images as $key => $value)\r
- {\r
- if ( !is_array($value) )\r
- {\r
- $images[$key] = str_replace('{LANG}', 'lang_' . $img_lang, $value);\r
- }\r
- $sav_images[$key] = $images[$key];\r
- }\r
- $images = $sav_images;\r
- $sav_images = array();\r
- }\r
- }\r
-\r
- // get the current images\r
- if ( !empty($sub_template_key_image) && ($sub_template_key_image != POST_CAT_URL . '0') )\r
- {\r
- $key = $sub_template_key_image;\r
-\r
- // get the sub-template path\r
- $current_template_path = $template_path . $template_name . '/' . $sub_templates[$key]['dir'];\r
- $root_template_path = $real_root . '/' . $sub_templates[$key]['dir'];\r
- if ( isset($sub_templates[$key]['imagefile']) && file_exists($root_template_path . '/' . $sub_templates[$key]['imagefile']) )\r
- {\r
- $sav_images = $images;\r
- $images = array();\r
- @include($root_template_path . '/' . $sub_templates[$key]['imagefile']);\r
- $img_lang = ( file_exists($root_template_path . '/images/lang_' . $board_config['default_lang']) ) ? $board_config['default_lang'] : 'english';\r
- foreach($images as $key => $value)\r
- {\r
- if ( !is_array($value) )\r
- {\r
- $images[$key] = str_replace('{LANG}', 'lang_' . $img_lang, $value);\r
- }\r
- $sav_images[$key] = $images[$key];\r
- }\r
- $images = $sav_images;\r
- $sav_images = array();\r
- }\r
- }\r
- }\r
- return $filename;\r
- }\r
-\r
- /**\r
- * Generates a full path+filename for the given filename, which can either\r
- * be an absolute name, or a name relative to the rootdir for this Template\r
- * object.\r
- */\r
- function make_filename($filename, $xs_include = false)\r
- {\r
- if($this->subtemplates)\r
- {\r
- $filename = $this->subtemplates_make_filename($filename);\r
- }\r
- // Check replacements list\r
- if(!$xs_include && isset($this->replace[$filename]))\r
- {\r
- $filename = $this->replace[$filename];\r
- }\r
- // Check if it's an absolute or relative path.\r
- if ((substr($filename, 0, 1) !== '/') && (substr($filename, 1, 1) !== ':'))\r
- {\r
- return $this->root . '/' . $filename;\r
- }\r
- else\r
- {\r
- return str_replace('\\', '/', $filename);\r
- }\r
- }\r
-\r
- /**\r
- * Converts template filename to cache filename.\r
- * Returns empty string if non-cachable (for tpl files outside of root dir).\r
- * $file should be absolute filename\r
- */\r
- function make_filename_cache($file)\r
- {\r
- $str = str_replace($this->cache_search, $this->cache_replace, $file);\r
- if(substr($file, 0, $this->tpldir_len) !== $this->tpldir || empty($this->tpl))\r
- {\r
- return $this->cachedir . XS_TPL_PREFIX2 . $str;\r
- }\r
- // removing not needed part\r
- $file = substr($file, $this->tpldir_len, strlen($file));\r
- // creating filename\r
- return $this->cachedir . XS_TPL_PREFIX . str_replace($this->cache_search, $this->cache_replace, $file);\r
- }\r
-\r
- /**\r
- * Sets the template filenames for handles. $filename_array\r
- * should be a hash of handle => filename pairs.\r
- */\r
- function set_filenames($filename_array)\r
- {\r
- if (!is_array($filename_array))\r
- {\r
- return false;\r
- }\r
-\r
- foreach($filename_array as $handle => $filename)\r
- {\r
- $this->set_filename($handle, $filename);\r
- }\r
-\r
- return true;\r
- }\r
-\r
-\r
- /**\r
- * Assigns template filename for handle.\r
- */\r
- function set_filename($handle, $filename, $xs_include = false, $quiet = false)\r
- {\r
- global $board_config;\r
- $can_cache = $this->use_cache;\r
- if(strpos($filename, '..') !== false)\r
- {\r
- $can_cache = false;\r
- }\r
- $this->files[$handle] = $this->make_filename($filename, $xs_include);\r
- $this->files_cache[$handle] = '';\r
- $this->files_cache2[$handle] = '';\r
- // check if we are in admin control panel and override extreme styles mod controls if needed\r
- if(defined('XS_ADMIN_OVERRIDE') && XS_ADMIN_OVERRIDE === true && @function_exists('xs_admin_override'))\r
- {\r
- xs_admin_override();\r
- }\r
- // checking if we have valid filename\r
- if(!$this->files[$handle])\r
- {\r
- if($xs_include || $quiet)\r
- {\r
- return false;\r
- }\r
- else\r
- {\r
- die("Template->make_filename(): Error - invalid template $filename");\r
- }\r
- }\r
- // creating cache filename\r
- if($can_cache)\r
- {\r
- $this->files_cache2[$handle] = $this->make_filename_cache($this->files[$handle]);\r
- if(@file_exists($this->files_cache2[$handle]))\r
- {\r
- $this->files_cache[$handle] = $this->files_cache2[$handle];\r
- }\r
- }\r
- // checking if tpl and/or php file exists\r
- if(empty($this->files_cache[$handle]) && !@file_exists($this->files[$handle]))\r
- {\r
- // trying to load alternative filename (usually subSilver)\r
- if(!empty($this->tpldef) && !empty($this->tpl) && ($this->tpldef !== $this->tpl))\r
- {\r
- $this->files[$handle] = '';\r
- // save old configuration\r
- $root = $this->root;\r
- $tpl_name = $this->tpl;\r
- // set temporary configuration\r
- $this->root = $this->tpldir . $this->tpldef;\r
- $this->tpl = $this->tpldef;\r
- // recursively run set_filename\r
- $res = $this->set_filename($handle, $filename, $xs_include, $quiet);\r
- // restore old configuration\r
- $this->root = $root;\r
- $this->tpl = $tpl_name;\r
- return $res;\r
- }\r
- if($quiet)\r
- {\r
- return false;\r
- }\r
- if($xs_include)\r
- {\r
- if($board_config['xs_warn_includes'])\r
- {\r
- die('Template->make_filename(): Error - included template file not found: ' . $filename);\r
- }\r
- return false;\r
- }\r
- else\r
- {\r
- die('Template->make_filename(): Error - template file not found: ' . $filename);\r
- }\r
- }\r
- // checking if we should recompile cache\r
- if(!empty($this->files_cache[$handle]) && !empty($board_config['xs_auto_recompile']))\r
- {\r
- $cache_time = @filemtime($this->files_cache[$handle]);\r
- if(@filemtime($this->files[$handle]) > $cache_time || $board_config['xs_template_time'] > $cache_time)\r
- { \r
- // file was changed. don't use cache file (will be recompled if configuration allowes it)\r
- $this->files_cache[$handle] = '';\r
- }\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * includes file or executes code\r
- */\r
- function execute($filename, $code, $handle)\r
- {\r
- global $lang, $theme, $board_config;\r
- $template = $theme['template_name'];\r
- global $$template;\r
- $theme_info = &$$template;\r
- if($board_config['xs_add_comments'] && $handle)\r
- {\r
- echo '<!-- template ', $this->files[$handle], ' start -->';\r
- }\r
- if($filename)\r
- {\r
- include($filename);\r
- }\r
- else\r
- {\r
- eval($code);\r
- }\r
- if($board_config['xs_add_comments'] && $handle)\r
- {\r
- echo '<!-- template ', $this->files[$handle], ' end -->';\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Load the file for the handle, compile the file,\r
- * and run the compiled code. This will print out\r
- * the results of executing the template.\r
- */\r
- function pparse($handle)\r
- {\r
- global $board_config;\r
- // parsing header if there is one\r
- if($this->preparse || $this->postparse)\r
- {\r
- $preparse = $this->preparse;\r
- $postparse = $this->postparse;\r
- $this->preparse = '';\r
- $this->postparse = '';\r
- if($preparse)\r
- {\r
- $this->pparse($preparse);\r
- }\r
- if($postparse)\r
- {\r
- $str = $handle;\r
- $handle = $postparse;\r
- $this->pparse($str);\r
- }\r
- }\r
- // checking if handle exists\r
- if (empty($this->files[$handle]) && empty($this->files_cache[$handle]))\r
- {\r
- die("Template->loadfile(): No files found for handle $handle");\r
- }\r
- $this->xs_startup();\r
- $force_recompile = empty($this->uncompiled_code[$handle]) ? false : true;\r
- // checking if php file exists.\r
- if (!empty($this->files_cache[$handle]) && !$force_recompile)\r
- {\r
- // php file exists - running it instead of tpl\r
- $this->execute($this->files_cache[$handle], '', $handle);\r
- return true;\r
- }\r
- if (!$this->loadfile($handle))\r
- {\r
- die("Template->pparse(): Couldn't load template file for handle $handle");\r
- }\r
- // actually compile the template now.\r
- if (empty($this->compiled_code[$handle]))\r
- {\r
- // Actually compile the code now.\r
- if(!empty($this->files_cache2[$handle]) && empty($this->files_cache[$handle]) && !$force_recompile)\r
- {\r
- $this->compiled_code[$handle] = $this->compile2($this->uncompiled_code[$handle], $handle, $this->files_cache2[$handle]);\r
- }\r
- else\r
- {\r
- $this->compiled_code[$handle] = $this->compile2($this->uncompiled_code[$handle], '', '');\r
- }\r
- }\r
- // Run the compiled code.\r
- if (empty($this->files_cache[$handle]) || $force_recompile)\r
- {\r
- $this->execute('', $this->compiled_code[$handle], $handle);\r
- }\r
- else\r
- {\r
- $this->execute($this->files_cache[$handle], '', $handle);\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Precompile file\r
- */\r
- function precompile($template, $filename)\r
- {\r
- global $precompile_num, $board_config;\r
- if(empty($precompile_num))\r
- {\r
- $precompile_num = 0;\r
- }\r
- $precompile_num ++;\r
- $handle = 'precompile_' . $precompile_num;\r
- // save old configuration\r
- $root = $this->root;\r
- $tpl_name = $this->tpl;\r
- $old_config = $this->use_cache;\r
- $old_autosave = $this->auto_compile;\r
- // set temporary configuration\r
- $this->root = $this->tpldir . $template;\r
- $this->tpl = $template;\r
- $this->use_cache = 1;\r
- $this->auto_compile = 1;\r
- // set filename\r
- $res = $this->set_filename($handle, $filename, true, true);\r
- if(!$res || !$this->files_cache2[$handle])\r
- {\r
- $this->root = $root;\r
- $this->tpl = $tpl_name;\r
- $this->use_cache = $old_config;\r
- $this->auto_compile = $old_autosave;\r
- return false;\r
- }\r
- $this->files_cache[$handle] = '';\r
- // load template\r
- $res = $this->loadfile($handle);\r
- if(!$res || empty($this->uncompiled_code[$handle]))\r
- {\r
- $this->root = $root;\r
- $this->tpl = $tpl_name;\r
- $this->use_cache = $old_config;\r
- $this->auto_compile = $old_autosave;\r
- return false;\r
- }\r
- // compile the code\r
- $this->compile2($this->uncompiled_code[$handle], $handle, $this->files_cache2[$handle]);\r
- // restore confirugation\r
- $this->root = $root;\r
- $this->tpl = $tpl_name;\r
- $this->use_cache = $old_config;\r
- $this->auto_compile = $old_autosave;\r
- return true;\r
- }\r
-\r
- /**\r
- * Inserts the uncompiled code for $handle as the\r
- * value of $varname in the root-level. This can be used\r
- * to effectively include a template in the middle of another\r
- * template.\r
- * Note that all desired assignments to the variables in $handle should be done\r
- * BEFORE calling this function.\r
- */\r
- function assign_var_from_handle($varname, $handle)\r
- {\r
- ob_start();\r
- $res = $this->pparse($handle);\r
- $this->vars[$varname] = ob_get_contents();\r
- ob_end_clean();\r
- return $res;\r
- }\r
-\r
- /**\r
- * Block-level variable assignment. Adds a new block iteration with the given\r
- * variable assignments. Note that this should only be called once per block\r
- * iteration.\r
- */\r
- function assign_block_vars($blockname, $vararray)\r
- {\r
- if (strstr($blockname, '.'))\r
- {\r
- // Nested block.\r
- $blocks = explode('.', $blockname);\r
- $blockcount = sizeof($blocks) - 1;\r
-\r
- $str = &$this->_tpldata; \r
- for($i = 0; $i < $blockcount; $i++) \r
- { \r
- $str = &$str[$blocks[$i].'.']; \r
- $str = &$str[sizeof($str)-1]; \r
- } \r
- // Now we add the block that we're actually assigning to. \r
- // We're adding a new iteration to this block with the given \r
- // variable assignments. \r
- $str[$blocks[$blockcount].'.'][] = $vararray;\r
- }\r
- else\r
- {\r
- // Top-level block.\r
- // Add a new iteration to this block with the variable assignments\r
- // we were given.\r
- $this->_tpldata[$blockname.'.'][] = $vararray;\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Root-level variable assignment. Adds to current assignments, overriding\r
- * any existing variable assignment with the same name.\r
- */\r
- function assign_vars($vararray)\r
- {\r
- foreach($vararray as $key => $val)\r
- {\r
- $this->vars[$key] = $val;\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Root-level variable assignment. Adds to current assignments, overriding\r
- * any existing variable assignment with the same name.\r
- */\r
- function assign_var($varname, $varval)\r
- {\r
- $this->vars[$varname] = $varval;\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * If not already done, load the file for the given handle and populate\r
- * the uncompiled_code[] hash with its code. Do not compile.\r
- */\r
- function loadfile($handle)\r
- {\r
- global $board_config;\r
- // If cached file exists do nothing - it will be included via include()\r
- if(!empty($this->files_cache[$handle]))\r
- {\r
- return true;\r
- }\r
-\r
- // If the file for this handle is already loaded and compiled, do nothing.\r
- if (!empty($this->uncompiled_code[$handle]))\r
- {\r
- return true;\r
- }\r
-\r
- // If we don't have a file assigned to this handle, die.\r
- if (empty($this->files[$handle]))\r
- {\r
- die("Template->loadfile(): No file specified for handle $handle");\r
- }\r
-\r
- $filename = $this->files[$handle];\r
-\r
- $str = implode('', @file($filename));\r
- if (empty($str))\r
- {\r
- die("Template->loadfile(): File $filename for handle $handle is empty");\r
- }\r
-\r
- $this->uncompiled_code[$handle] = $str;\r
-\r
- return true;\r
- }\r
-\r
-\r
-\r
- /**\r
- * Generates a reference to the given variable inside the given (possibly nested)\r
- * block namespace. This is a string of the form:\r
- * ' . $this->_tpldata['parent.'][$_parent_i]['$child1.'][$_child1_i]['$child2.'][$_child2_i]...['varname'] . '\r
- * It's ready to be inserted into an "echo" line in one of the templates.\r
- * NOTE: expects a trailing "." on the namespace.\r
- */\r
- function generate_block_varref($namespace, $varname, $use_isset = true)\r
- {\r
- // Strip the trailing period.\r
- $namespace = substr($namespace, 0, strlen($namespace) - 1);\r
-\r
- // Get a reference to the data block for this namespace.\r
- $varref = $this->generate_block_data_ref($namespace, true);\r
- // Prepend the necessary code to stick this in an echo line.\r
-\r
- // Append the variable reference.\r
- $varref .= '[\'' . $varname . '\']';\r
-\r
- if($use_isset)\r
- {\r
- $varref = '<'.'?php echo isset(' . $varref . ') ? ' . $varref . ' : \'\'; ?'.'>';\r
- }\r
- else\r
- {\r
- $varref = '<'.'?php echo ' . $varref . '; ?'.'>';\r
- }\r
-\r
- return $varref;\r
-\r
- }\r
-\r
-\r
- /**\r
- * Generates a reference to the array of data values for the given\r
- * (possibly nested) block namespace. This is a string of the form:\r
- * $this->_tpldata['parent.'][$_parent_i]['$child1.'][$_child1_i]['$child2.'][$_child2_i]...['$childN.']\r
- *\r
- * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above.\r
- * NOTE: does not expect a trailing "." on the blockname.\r
- */\r
- function generate_block_data_ref($blockname, $include_last_iterator, $defop = false)\r
- {\r
- // Get an array of the blocks involved.\r
- $blocks = explode('.', $blockname);\r
- $blockcount = sizeof($blocks) - 1;\r
- if($defop)\r
- {\r
- $varref = '$this->_tpldata[\'DEFINE\']';\r
- // Build up the string with everything but the last child.\r
- for ($i = 0; $i < $blockcount; $i++)\r
- {\r
- $varref .= "['" . $blocks[$i] . ".'][\$" . $blocks[$i] . '_i]';\r
- }\r
- // Add the block reference for the last child.\r
- $varref .= "['" . $blocks[$blockcount] . ".']";\r
- // Add the iterator for the last child if requried.\r
- if ($include_last_iterator)\r
- {\r
- $varref .= '[$' . $blocks[$blockcount] . '_i]';\r
- }\r
- return $varref;\r
- }\r
- if($include_last_iterator)\r
- {\r
- return '$'. $blocks[$blockcount]. '_item';\r
- }\r
- else\r
- {\r
- return '$'. $blocks[$blockcount-1]. '_item[\''. $blocks[$blockcount]. '.\']';\r
- }\r
- }\r
-\r
- function compile_code($filename, $code, $use_isset = false)\r
- {\r
- // $filename - file to load code from. used if $code is empty\r
- // $code - tpl code\r
- // $use_isset - if false then compiled code looks more beautiful and easier\r
- // to understand and it adds error_reporting() to supress php warnings.\r
- // if true then isset() is used to check variables instead of supressing\r
- // php warnings. note: for extreme styles mod 2.x it works only for\r
- // block variables and for usual variables its always true.\r
-\r
- // load code from file\r
- if(!$code && !empty($filename))\r
- {\r
- $code = @implode('', @file($filename));\r
- }\r
-\r
- // Replace phpBB 2.2 <!-- (END)PHP --> tags\r
- $search = array('<!-- PHP -->', '<!-- ENDPHP -->');\r
- $replace = array('<'.'?php ', ' ?'.'>');\r
- $code = str_replace($search, $replace, $code);\r
-\r
- // Break it up into lines and put " -->" back.\r
- $code_lines = explode(' -->', $code);\r
- $count = count($code_lines);\r
- for ($i = 0; $i < ($count - 1); $i++)\r
- {\r
- $code_lines[$i] .= ' -->';\r
- }\r
-\r
- $block_nesting_level = 0;\r
- $block_names = array();\r
- $block_names[0] = ".";\r
- $block_items = array();\r
- $count_if = 0;\r
-\r
- // prepare array for compiled code\r
- $compiled = array();\r
- $count_bugs = count($this->bugs);\r
-\r
- // array of switches\r
- $sw = array();\r
-\r
- // replace all short php tags\r
- $new_code = array();\r
- $line_count = count($code_lines);\r
- for($i=0; $i<$line_count; $i++)\r
- {\r
- $line = $code_lines[$i];\r
- $pos = strpos($line, '<?');\r
- if($pos === false)\r
- {\r
- $new_code[] = $line;\r
- continue;\r
- }\r
- if(substr($line, $pos, 5) === '<?php')\r
- {\r
- // valid php tag. skip it\r
- $new_code[] = substr($line, 0, $pos + 5);\r
- $code_lines[$i] = substr($line, $pos + 5);\r
- $i --;\r
- continue;\r
- }\r
- // invalid php tag\r
- $new_code[] = substr($line, 0, $pos) . '<?php echo \'<?\'; ?>';\r
- $code_lines[$i] = substr($line, $pos + 2);\r
- $i --;\r
- }\r
- $code_lines = $new_code;\r
-\r
- // main loop\r
- $line_count = count($code_lines);\r
- for($i=0; $i<$line_count; $i++)\r
- {\r
- $line = $code_lines[$i];\r
- // reset keyword type\r
- $keyword_type = XS_TAG_NONE;\r
- // check if we have valid keyword in current line\r
- $pos1 = strpos($line, '<!-- ');\r
- if($pos1 === false)\r
- {\r
- // no keywords in this line\r
- $compiled[] = $this->_compile_text($line, $use_isset);\r
- continue;\r
- }\r
- // find end of html comment\r
- $pos2 = strpos($line, ' -->', $pos1);\r
- if($pos2 !== false)\r
- {\r
- // find end of keyword in comment\r
- $pos3 = strpos($line, ' ', $pos1 + 5);\r
- if($pos3 !== false && $pos3 <= $pos2)\r
- {\r
- $keyword = substr($line, $pos1 + 5, $pos3 - $pos1 - 5);\r
- // check keyword against list of supported keywords. case-sensitive\r
- if($keyword === 'BEGIN')\r
- {\r
- $keyword_type = XS_TAG_BEGIN;\r
- }\r
- elseif($keyword === 'END')\r
- {\r
- $keyword_type = XS_TAG_END;\r
- }\r
- elseif($keyword === 'INCLUDE')\r
- {\r
- $keyword_type = XS_TAG_INCLUDE;\r
- }\r
- elseif($keyword === 'IF')\r
- {\r
- $keyword_type = XS_TAG_IF;\r
- }\r
- elseif($keyword === 'ELSE')\r
- {\r
- $keyword_type = XS_TAG_ELSE;\r
- }\r
- elseif($keyword === 'ELSEIF')\r
- {\r
- $keyword_type = XS_TAG_ELSEIF;\r
- }\r
- elseif($keyword === 'ENDIF')\r
- {\r
- $keyword_type = XS_TAG_ENDIF;\r
- }\r
- elseif($keyword === 'DEFINE')\r
- {\r
- $keyword_type = XS_TAG_DEFINE;\r
- }\r
- elseif($keyword === 'UNDEFINE')\r
- {\r
- $keyword_type = XS_TAG_UNDEFINE;\r
- }\r
- elseif($keyword === 'BEGINELSE')\r
- {\r
- $keyword_type = XS_TAG_BEGINELSE;\r
- }\r
- }\r
- }\r
- if(!$keyword_type)\r
- {\r
- // not valid keyword. process the rest of line\r
- $compiled[] = $this->_compile_text(substr($line, 0, $pos1 + 4), $use_isset);\r
- $code_lines[$i] = substr($line, $pos1 + 4);\r
- $i --;\r
- continue;\r
- }\r
- // remove code before keyword\r
- if($pos1 > 0)\r
- {\r
- $compiled[] = $this->_compile_text(substr($line, 0, $pos1), $use_isset);\r
- }\r
- // remove keyword\r
- $keyword_str = substr($line, $pos1, $pos2 - $pos1 + 4);\r
- $params_str = $pos2 == $pos3 ? '' : substr($line, $pos3 + 1, $pos2 - $pos3 - 1);\r
- $code_lines[$i] = substr($line, $pos2 + 4);\r
- $i--;\r
- // Check keywords\r
-\r
- /*\r
- * <!-- BEGIN -->\r
- */\r
- if($keyword_type == XS_TAG_BEGIN)\r
- {\r
- $params = explode(' ', $params_str);\r
- $num_params = count($params);\r
- // get variable name\r
- if($num_params == 1)\r
- {\r
- $var = $params[0];\r
- }\r
- elseif($num_params == 2)\r
- {\r
- if($params[0] === '')\r
- {\r
- $var = $params[1];\r
- }\r
- elseif($params[1] === '')\r
- {\r
- $var = $params[0];\r
- }\r
- else\r
- {\r
- // invalid tag\r
- $compiled[] = $keyword_str;\r
- continue;\r
- }\r
- }\r
- else\r
- {\r
- // invalid tag\r
- $compiled[] = $keyword_str;\r
- continue;\r
- }\r
- // check variable for matching end\r
- if($this->xs_check_switches)\r
- {\r
- $found = 0;\r
- $str = '<!-- END ' . $var . ' -->';\r
- for ($j = $i+1; ($j < $line_count) && !$found; $j++)\r
- {\r
- $pos = strpos($code_lines[$j], $str);\r
- if($pos !== false)\r
- {\r
- $found = 1;\r
- $found_var = $var;\r
- }\r
- }\r
- if(!$found && ($this->xs_check_switches == 1))\r
- {\r
- // checking list of known buggy switches\r
- $item = -1;\r
- for($j=0; $j<$count_bugs; $j++)\r
- {\r
- if($this->bugs[$j][0] === $var)\r
- {\r
- $item = $j;\r
- }\r
- }\r
- if($item >= 0)\r
- {\r
- $str1 = '<!-- END ' . $this->bugs[$item][1] . ' -->';\r
- for ($j = $i+1; ($j < $line_count) && !$found; $j++)\r
- {\r
- $pos = strpos($code_lines[$j], $str1);\r
- if($pos !== false)\r
- {\r
- $found_var = $this->bugs[$item][1];\r
- $found = 1;\r
- $code_lines[$j] = str_replace($str, $str1, $code_lines[$j]);\r
- }\r
- }\r
- }\r
- }\r
- if(!$found)\r
- {\r
- $compiled[] = $keyword_str;\r
- continue;\r
- }\r
- // adding to list of switches\r
- if(isset($sw[$found_var]))\r
- {\r
- $sw[$found_var] ++;\r
- }\r
- else\r
- {\r
- $sw[$found_var] = 1;\r
- }\r
- }\r
- // adding code\r
- $block_nesting_level++;\r
- $block_names[$block_nesting_level] = $var;\r
- if(isset($block_items[$var]))\r
- {\r
- $block_items[$var] ++;\r
- }\r
- else\r
- {\r
- $block_items[$var] = 1;\r
- }\r
- if ($block_nesting_level < 2)\r
- {\r
- // Block is not nested.\r
- $line = '<'."?php\n\n";\r
- if($use_isset)\r
- {\r
- $line .= '$'. $var. '_count = ( isset($this->_tpldata[\''. $var. '.\']) ) ? sizeof($this->_tpldata[\''. $var. '.\']) : 0;';\r
- }\r
- else\r
- {\r
- $line .= '$'. $var. '_count = sizeof($this->_tpldata[\''. $var. '.\']);';\r
- }\r
- $line .= "\n" . 'for ($'. $var. '_i = 0; $'. $var. '_i < $'. $var. '_count; $'. $var. '_i++)';\r
- $line .= "\n". '{'. "\n";\r
- $line .= ' $'. $var. '_item = &$this->_tpldata[\''. $var. '.\'][$'. $var. '_i];'."\n";\r
- $line .= " \${$var}_item['S_ROW_COUNT'] = \${$var}_i;\n";\r
- $line .= " \${$var}_item['S_NUM_ROWS'] = \${$var}_count;\n";\r
- $line .= "\n?".">";\r
- }\r
- else\r
- {\r
- // This block is nested.\r
- // Generate a namespace string for this block.\r
- $namespace = implode('.', $block_names);\r
- // strip leading period from root level..\r
- $namespace = substr($namespace, 2);\r
- // Get a reference to the data array for this block that depends on the\r
- // current indices of all parent blocks.\r
- $varref = $this->generate_block_data_ref($namespace, false);\r
- // Create the for loop code to iterate over this block.\r
- $line = '<'."?php\n\n";\r
- if($use_isset)\r
- {\r
- $line .= '$'. $var. '_count = ( isset('. $varref. ') ) ? sizeof('. $varref. ') : 0;';\r
- }\r
- else\r
- {\r
- $line .= '$'. $var. '_count = sizeof('. $varref. ');';\r
- }\r
- $line .= "\n". 'for ($'. $var. '_i = 0; $'. $var. '_i < $'. $var. '_count; $'. $var. '_i++)';\r
- $line .= "\n". '{'. "\n";\r
- $line .= ' $'. $var. '_item = &'. $varref. '[$'. $var. '_i];'."\n";\r
- $line .= " \${$var}_item['S_ROW_COUNT'] = \${$var}_i;\n";\r
- $line .= " \${$var}_item['S_NUM_ROWS'] = \${$var}_count;\n";\r
- $line .= "\n?".">";\r
- }\r
- $compiled[] = $line;\r
- continue;\r
- }\r
- /*\r
- * <!-- END -->\r
- */\r
- if($keyword_type == XS_TAG_END)\r
- {\r
- $params = explode(' ', $params_str);\r
- $num_params = count($params);\r
- if($num_params == 1)\r
- {\r
- $var = $params[0];\r
- }\r
- elseif($num_params == 2 && $params[0] === '')\r
- {\r
- $var = $params[1];\r
- }\r
- elseif($num_params == 2 && $params[1] === '')\r
- {\r
- $var = $params[0];\r
- }\r
- else\r
- {\r
- $compiled[] = $keyword_str;\r
- continue;\r
- }\r
- if($this->xs_check_switches)\r
- { \r
- // checking if this switch was opened\r
- if(!isset($sw[$var]) || ($sw[$var] < 1))\r
- { \r
- // there is no opening switch\r
- $compiled[] = $keyword_str;\r
- continue;\r
- }\r
- $sw[$var] --;\r
- }\r
- // We have the end of a block.\r
- $line = '<'."?php\n\n";\r
- $line .= '} // END ' . $var . "\n\n";\r
- $line .= 'if(isset($' . $var . '_item)) { unset($' . $var . '_item); } ';\r
- $line .= "\n\n?".">";\r
- if(isset($block_items[$var]))\r
- {\r
- $block_items[$var] --;\r
- }\r
- else\r
- {\r
- $block_items[$var] = -1;\r
- }\r
- unset($block_names[$block_nesting_level]);\r
- $block_nesting_level--;\r
- $compiled[] = $line;\r
- continue;\r
- }\r
- /*\r
- * <!-- BEGINELSE -->\r
- */\r
- if($keyword_type == XS_TAG_BEGINELSE)\r
- {\r
- if($block_nesting_level)\r
- {\r
- $var = $block_names[$block_nesting_level];\r
- $compiled[] = '<' . '?php } if(!$' . $var . '_count) { ?' . '>';\r
- }\r
- else\r
- {\r
- $compiled[] = $keyword_str;\r
- continue;\r
- }\r
- }\r
- /*\r
- * <!-- INCLUDE -->\r
- */\r
- if($keyword_type == XS_TAG_INCLUDE)\r
- {\r
- $params = explode(' ', $params_str);\r
- $num_params = count($params);\r
- if($num_params != 1)\r
- {\r
- $compiled[] = $keyword_str;\r
- continue;\r
- }\r
- $line = '<'.'?php ';\r
- $filehash = md5($params_str . $this->include_count . time());\r
- $line .= ' $this->set_filename(\'xs_include_' . $filehash . '\', \'' . $params_str .'\', true); ';\r
- $line .= ' $this->pparse(\'xs_include_' . $filehash . '\'); ';\r
- $line .= ' ?'.'>';\r
- $this->include_count ++;\r
- $compiled[] = $line;\r
- continue;\r
- }\r
- /*\r
- * <!-- IF -->\r
- */\r
- if($keyword_type == XS_TAG_IF || $keyword_type == XS_TAG_ELSEIF)\r
- {\r
- if(!$count_if)\r
- {\r
- $keyword_type = XS_TAG_IF;\r
- }\r
- $str = $this->compile_tag_if($params_str, $keyword_type == XS_TAG_IF ? false : true);\r
- if($str)\r
- {\r
- $compiled[] = '<?php ' . $str . ' ?>';\r
- if($keyword_type == XS_TAG_IF)\r
- {\r
- $count_if ++;\r
- }\r
- }\r
- else\r
- {\r
- $compiled[] = $keyword_str;\r
- }\r
- continue;\r
- }\r
- /*\r
- * <!-- ELSE -->\r
- */\r
- if($keyword_type == XS_TAG_ELSE && $count_if > 0)\r
- {\r
- $compiled[] = '<?php } else { ?>';\r
- continue;\r
- }\r
- /*\r
- * <!-- ENDIF -->\r
- */\r
- if($keyword_type == XS_TAG_ENDIF && $count_if > 0)\r
- {\r
- $compiled[] = '<?php } ?>';\r
- $count_if --;\r
- continue;\r
- }\r
- /*\r
- * <!-- DEFINE -->\r
- */\r
- if($keyword_type == XS_TAG_DEFINE)\r
- {\r
- $str = $this->compile_tag_define($params_str);\r
- if($str)\r
- {\r
- $compiled[] = '<?php ' . $str . ' ?>';\r
- }\r
- else\r
- {\r
- $compiled[] = $keyword_str;\r
- }\r
- }\r
- /*\r
- * <!-- UNDEFINE -->\r
- */\r
- if($keyword_type == XS_TAG_UNDEFINE)\r
- {\r
- $str = $this->compile_tag_undefine($params_str);\r
- if($str)\r
- {\r
- $compiled[] = '<?php ' . $str . ' ?>';\r
- }\r
- else\r
- {\r
- $compiled[] = $keyword_str;\r
- }\r
- }\r
- }\r
- \r
- // bring it back into a single string.\r
- $code_header = '';\r
- $code_footer = '';\r
- if(!$use_isset)\r
- {\r
- $code_header = "<". "?php\n\$old_level = @error_reporting(E_ERROR | E_WARNING | E_PARSE); \n?".">";\r
- $code_footer = '<'."?php @error_reporting(\$old_level); ?".'>';\r
- }\r
-\r
- return $code_header . implode('', $compiled) . $code_footer;\r
- }\r
-\r
- /*\r
- * Compile code between tags\r
- */\r
- function _compile_text($code, $use_isset)\r
- {\r
- if(strlen($code) < 3)\r
- {\r
- return $code;\r
- }\r
- // change template varrefs into PHP varrefs\r
- // This one will handle varrefs WITH namespaces\r
- $varrefs = array();\r
- preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $code, $varrefs);\r
- $varcount = sizeof($varrefs[1]);\r
- $search = array();\r
- $replace = array();\r
- for ($i = 0; $i < $varcount; $i++)\r
- {\r
- $namespace = $varrefs[1][$i];\r
- $varname = $varrefs[3][$i];\r
- $new = $this->generate_block_varref($namespace, $varname, $use_isset);\r
- $search[] = $varrefs[0][$i];\r
- $replace[] = $new;\r
- }\r
- if(count($search) > 0)\r
- {\r
- $code = str_replace($search, $replace, $code);\r
- }\r
- // This will handle the remaining root-level varrefs\r
- $code = preg_replace('#\{([a-z0-9\-_]*?)\}#is', '<'.'?php echo isset($this->vars[\'\1\']) ? $this->vars[\'\1\'] : $this->lang(\'\1\'); ?'.'>', $code);\r
- $code = preg_replace('#\{\$([a-z0-9\-_]*?)\}#is', '<'.'?php echo isset($this->_tpldata[\'DEFINE\'][\'.\'][\'\\1\']) ? $this->_tpldata[\'DEFINE\'][\'.\'][\'\\1\'] : \'\'; ?'.'>', $code);\r
- return $code;\r
- }\r
-\r
- //\r
- // Compile IF tags - much of this is from Smarty with\r
- // some adaptions for our block level methods\r
- //\r
- function compile_tag_if($tag_args, $elseif)\r
- {\r
- /* Tokenize args for 'if' tag. */\r
- preg_match_all('/(?:\r
- "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" |\r
- \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' |\r
- [(),] |\r
- [^\s(),]+)/x', $tag_args, $match);\r
-\r
- $tokens = $match[0];\r
- $is_arg_stack = array();\r
-\r
- for ($i = 0; $i < count($tokens); $i++)\r
- {\r
- $token = &$tokens[$i];\r
-\r
- switch ($token)\r
- {\r
- case '!':\r
- case '%':\r
- case '!==':\r
- case '==':\r
- case '===':\r
- case '>':\r
- case '<':\r
- case '!=':\r
- case '<>':\r
- case '<<':\r
- case '>>':\r
- case '<=':\r
- case '>=':\r
- case '&&':\r
- case '||':\r
- case '|':\r
- case '^':\r
- case '&':\r
- case '~':\r
- case ')':\r
- case ',':\r
- case '+':\r
- case '-':\r
- case '*':\r
- case '/':\r
- case '@':\r
- break; \r
-\r
- case 'eq':\r
- $token = '==';\r
- break;\r
-\r
- case 'ne':\r
- case 'neq':\r
- $token = '!=';\r
- break;\r
-\r
- case 'lt':\r
- $token = '<';\r
- break;\r
-\r
- case 'le':\r
- case 'lte':\r
- $token = '<=';\r
- break;\r
-\r
- case 'gt':\r
- $token = '>';\r
- break;\r
-\r
- case 'ge':\r
- case 'gte':\r
- $token = '>=';\r
- break;\r
-\r
- case 'and':\r
- $token = '&&';\r
- break;\r
-\r
- case 'or':\r
- $token = '||';\r
- break;\r
-\r
- case 'not':\r
- $token = '!';\r
- break;\r
-\r
- case 'mod':\r
- $token = '%';\r
- break;\r
-\r
- case '(':\r
- array_push($is_arg_stack, $i);\r
- break;\r
-\r
- case 'is':\r
- $is_arg_start = ($tokens[$i-1] == ')') ? array_pop($is_arg_stack) : $i-1;\r
- $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start));\r
-\r
- $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1));\r
-\r
- array_splice($tokens, $is_arg_start, count($tokens), $new_tokens);\r
-\r
- $i = $is_arg_start;\r
-\r
- default:\r
- if (preg_match('#^(([a-z0-9\-_]+?\.)+?)?(\$)?([A-Z]+[A-Z0-9\-_]+)$#s', $token, $varrefs))\r
- {\r
- $token = (!empty($varrefs[1])) ? $this->generate_block_data_ref(substr($varrefs[1], 0, -1), true, $varrefs[3]) . '[\'' . $varrefs[4] . '\']' : (($varrefs[3]) ? '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $varrefs[4] . '\']' : '$this->vars[\'' . $varrefs[4] . '\']');\r
- }\r
- break;\r
- }\r
- }\r
-\r
- $code = (($elseif) ? '} elseif (' : 'if (') . (implode(' ', $tokens) . ') { ');\r
- \r
- return $code;\r
- }\r
-\r
- // This is from Smarty\r
- function _parse_is_expr($is_arg, $tokens)\r
- {\r
- $expr_end = 0;\r
- $negate_expr = false;\r
-\r
- if (($first_token = array_shift($tokens)) == 'not')\r
- {\r
- $negate_expr = true;\r
- $expr_type = array_shift($tokens);\r
- }\r
- else\r
- {\r
- $expr_type = $first_token;\r
- }\r
-\r
- switch ($expr_type)\r
- {\r
- case 'even':\r
- if (@$tokens[$expr_end] == 'by')\r
- {\r
- $expr_end++;\r
- $expr_arg = $tokens[$expr_end++];\r
- $expr = "!(($is_arg / $expr_arg) % $expr_arg)";\r
- }\r
- else\r
- {\r
- $expr = "!($is_arg % 2)";\r
- }\r
- break;\r
-\r
- case 'odd':\r
- if (@$tokens[$expr_end] == 'by')\r
- {\r
- $expr_end++;\r
- $expr_arg = $tokens[$expr_end++];\r
- $expr = "(($is_arg / $expr_arg) % $expr_arg)";\r
- }\r
- else\r
- {\r
- $expr = "($is_arg % 2)";\r
- }\r
- break;\r
-\r
- case 'div':\r
- if (@$tokens[$expr_end] == 'by')\r
- {\r
- $expr_end++;\r
- $expr_arg = $tokens[$expr_end++];\r
- $expr = "!($is_arg % $expr_arg)";\r
- }\r
- break;\r
-\r
- default:\r
- break;\r
- }\r
-\r
- if ($negate_expr)\r
- {\r
- $expr = "!($expr)";\r
- }\r
-\r
- array_splice($tokens, 0, $expr_end, $expr);\r
-\r
- return $tokens;\r
- }\r
-\r
-\r
- function compile_tag_define($tag_args)\r
- {\r
- preg_match('#^(([a-z0-9\-_]+?\.)+?)?\$([A-Z][A-Z0-9_\-]*?) = (\'?)(.*?)(\'?)$#', $tag_args, $match);\r
-\r
- if (empty($match[3]) || empty($match[5]))\r
- {\r
- return '';\r
- }\r
-\r
- // Are we a string?\r
- if ($match[4] && $match[6])\r
- {\r
- $match[5] = "'" . addslashes(str_replace(array('\\\'', '\\\\'), array('\'', '\\'), $match[5])) . "'";\r
- }\r
- else\r
- {\r
- preg_match('#(true|false|\.)#i', $match[5], $type);\r
-\r
- switch (strtolower($type[1]))\r
- {\r
- case 'true':\r
- case 'false':\r
- $match[5] = strtoupper($match[5]);\r
- break;\r
- case '.';\r
- $match[5] = doubleval($match[5]);\r
- break;\r
- default:\r
- $match[5] = intval($match[5]);\r
- break;\r
- }\r
- }\r
-\r
- return (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[3] . '\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[3] . '\']') . ' = ' . $match[5] . ';';\r
- }\r
-\r
- function compile_tag_undefine($tag_args)\r
- {\r
- preg_match('#^(([a-z0-9\-_]+?\.)+?)?\$([A-Z][A-Z0-9_\-]*?)$#', $tag_args, $match);\r
- if (empty($match[3]))\r
- {\r
- return '';\r
- }\r
- return 'unset(' . (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[3] . '\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[3] . '\']') . ');';\r
- }\r
-\r
- /**\r
- * Compiles code and writes to cache if needed\r
- */\r
- function compile2($code, $handle, $cache_file)\r
- {\r
- $code = $this->compile_code('', $code, XS_USE_ISSET);\r
- if($cache_file && !empty($this->use_cache) && !empty($this->auto_compile))\r
- {\r
- $res = $this->write_cache($cache_file, $code);\r
- if($handle && $res)\r
- {\r
- $this->files_cache[$handle] = $cache_file;\r
- }\r
- }\r
- $code = '?'.'>'.$code.'<'."?php\n";\r
- return $code;\r
- }\r
-\r
- /**\r
- * Compiles the given string of code, and returns\r
- * the result in a string.\r
- * If "do_not_echo" is true, the returned code will not be directly\r
- * executable, but can be used as part of a variable assignment\r
- * for use in assign_code_from_handle().\r
- * This function isn't used and kept only for compatibility with original template.php\r
- */\r
- function compile($code, $do_not_echo = false, $retvar = '')\r
- {\r
- $code = ' ?'.'>' . $this->compile_code('', $code, true) . '<'."?php \n";\r
- if($do_not_echo)\r
- {\r
- $code = "ob_start();\n". $code. "\n\${$retvar} = ob_get_contents();\nob_end_clean();\n";\r
- }\r
- return $code;\r
- }\r
-\r
- /**\r
- * Write cache to disk\r
- */\r
- function write_cache($filename, $code)\r
- {\r
- // check if cache is writable\r
- if(!$this->cache_writable)\r
- {\r
- return false;\r
- }\r
- // check if filename is valid\r
- if(substr($filename, 0, strlen($this->cachedir)) !== $this->cachedir)\r
- {\r
- return false;\r
- }\r
- // try to open file\r
- $file = @fopen($filename, 'w');\r
- if(!$file)\r
- {\r
- // try to create directories\r
- $dir = substr($filename, strlen($this->cachedir), strlen($filename));\r
- $dirs = explode('/', $dir);\r
- $path = $this->cachedir; \r
- @umask(0);\r
- if(!@is_dir($path))\r
- {\r
- if(!@mkdir($path))\r
- {\r
- $this->cache_writable = 0;\r
- return false;\r
- }\r
- else\r
- {\r
- @chmod($path, 0777);\r
- }\r
- }\r
- $count = count($dirs);\r
- if($count > 0)\r
- for($i=0; $i<$count-1; $i++)\r
- {\r
- if($i>0)\r
- {\r
- $path .= '/';\r
- }\r
- $path .= $dirs[$i];\r
- if(!@is_dir($path))\r
- {\r
- if(!@mkdir($path))\r
- {\r
- $this->cache_writable = 0;\r
- return false;\r
- }\r
- else\r
- {\r
- @chmod($path, 0777);\r
- }\r
- }\r
- }\r
- // try to open file again after directories were created\r
- $file = @fopen($filename, 'w');\r
- }\r
- if(!$file)\r
- {\r
- $this->cache_writable = 0;\r
- return false;\r
- }\r
- fputs($file, "<?php\n\n// eXtreme Styles mod cache. Generated on " . date('r') . " (time=" . time() . ")\n\n?>");\r
- fputs($file, $code);\r
- fclose($file);\r
- @chmod($filename, 0777);\r
- return true;\r
- }\r
-\r
- function xs_startup()\r
- {\r
- global $phpEx, $board_config, $phpbb_root_path;\r
- if(empty($this->xs_started))\r
- { // adding predefined variables\r
- $this->xs_started = 1;\r
- // file extension with session ID (eg: "php?sid=123&" or "php?")\r
- // can be used to make custom URLs without modding phpbb\r
- // contains "&" or "?" at the end so you can easily append paramenters\r
- $php = append_sid($phpEx);\r
- if(strpos($php, '?'))\r
- {\r
- $php .= '&';\r
- }\r
- else\r
- {\r
- $php .= '?';\r
- }\r
- $this->vars['PHP'] = isset($this->vars['PHP']) ? $this->vars['PHP'] : $php;\r
- // adding language variable (eg: "english" or "german")\r
- // can be used to make truly multi-lingual templates\r
- $this->vars['LANG'] = isset($this->vars['LANG']) ? $this->vars['LANG'] : $board_config['default_lang'];\r
- // adding current template\r
- $tpl = $this->root . '/'; // $phpbb_root_path . 'templates/' . $this->tpl . '/';\r
- if(substr($tpl, 0, 2) === './')\r
- {\r
- $tpl = substr($tpl, 2, strlen($tpl));\r
- }\r
- $this->vars['TEMPLATE'] = isset($this->vars['TEMPLATE']) ? $this->vars['TEMPLATE'] : $tpl;\r
- $this->vars['TEMPLATE_NAME'] = isset($this->vars['TEMPLATE_NAME']) ? $this->vars['TEMPLATE_NAME'] : $this->tpl;\r
- $this->_tpldata['switch_xs_enabled.'] = array(array('version' => $this->xs_versiontxt));\r
- }\r
- }\r
-\r
- /**\r
- * Checks for empty variable and shows language variable if possible.\r
- */\r
- function lang($var)\r
- {\r
- global $lang;\r
- if(substr($var, 0, 2) === 'L_')\r
- {\r
- $var = substr($var, 2);\r
- // check variable as it is\r
- if(isset($lang[$var]))\r
- {\r
- return $lang[$var];\r
- }\r
- // check variable in lower case\r
- if(isset($lang[strtolower($var)]))\r
- {\r
- return $lang[strtolower($var)];\r
- }\r
- // check variable with first letter in upper case\r
- $str = ucfirst(strtolower($var));\r
- if(isset($lang[$str]))\r
- {\r
- return $lang[$str];\r
- }\r
- return ''; //str_replace('_', ' ', $var);\r
- }\r
- return '';\r
- }\r
-\r
- //\r
- //\r
- // Functions added for USERGROUP MOD (optimized)\r
- //\r
- //\r
- function append_var_from_handle_to_block($blockname, $varname, $handle)\r
- {\r
- $this->assign_var_from_handle('_tmp', $handle);\r
- // assign the value of the generated variable to the given varname.\r
- $this->append_block_vars($blockname, array($varname => $this->vars['_tmp']));\r
- return true;\r
- }\r
-\r
- function append_block_vars($blockname, $vararray)\r
- {\r
- if(strstr($blockname, '.'))\r
- {\r
- // Nested block.\r
- $blocks = explode('.', $blockname);\r
- $blockcount = sizeof($blocks) - 1;\r
- $str = &$this->_tpldata;\r
- for($i = 0; $i < $blockcount; $i++)\r
- {\r
- $str = &$str[$blocks[$i].'.'];\r
- $str = &$str[sizeof($str)-1];\r
- }\r
- // Now we add the block that we're actually assigning to.\r
- // We're adding a new iteration to this block with the given\r
- // variable assignments.\r
- $str = &$str[$blocks[$blockcount].'.'];\r
- $count = sizeof($str) - 1;\r
- if($count >= 0)\r
- {\r
- // adding only if there is at least one item\r
- $str[$count] = array_merge($str[$count], $vararray);\r
- }\r
- }\r
- else\r
- {\r
- // Top-level block.\r
- // Add a new iteration to this block with the variable assignments\r
- // we were given.\r
- $str = &$this->_tpldata[$blockname.'.'];\r
- $count = sizeof($str) - 1;\r
- if($count >= 0)\r
- {\r
- // adding only if there is at least one item\r
- $str[$count] = array_merge($str[$count], $vararray);\r
- }\r
- }\r
- return true;\r
- }\r
-\r
- /*\r
- * Flush a root level block, so it becomes empty.\r
- */\r
- function flush_block_vars($blockname)\r
- {\r
- // Top-level block.\r
- // flush a existing block we were given.\r
- $current_iteration = sizeof($this->_tpldata[$blockname . '.']) - 1;\r
- unset($this->_tpldata[$blockname . '.']);\r
- return true;\r
- }\r
-\r
- /*\r
- * Add style configuration\r
- */\r
- function _add_config($tpl, $add_vars = true)\r
- {\r
- global $phpbb_root_path;\r
- if(@file_exists($phpbb_root_path . 'templates/' . $tpl . '/xs_config.cfg'))\r
- {\r
- $style_config = array();\r
- include($phpbb_root_path . 'templates/' . $tpl . '/xs_config.cfg');\r
- if(count($style_config))\r
- {\r
- global $board_config, $db;\r
- for($i=0; $i<count($style_config); $i++)\r
- {\r
- $this->style_config[$style_config[$i]['var']] = $style_config[$i]['default'];\r
- if($add_vars)\r
- {\r
- $this->vars['TPL_CFG_' . strtoupper($style_config[$i]['var'])] = $style_config[$i]['default'];\r
- }\r
- }\r
- $str = $this->_serialize($this->style_config);\r
- $config_name = 'xs_style_' . $tpl;\r
- $board_config[$config_name] = $str;\r
- $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('" . str_replace('\\\'', '\'\'', addslashes($config_name)) . "', '" . str_replace('\\\'', '\'\'', addslashes($str)) . "')";\r
- $db->sql_query($sql);\r
- // recache config table for cat_hierarchy 2.1.0\r
- global $config;\r
- if(isset($config->data) && $config->data === $board_config && isset($config->data['mod_cat_hierarchy']))\r
- {\r
- $config->read(true);\r
- }\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
-\r
- function add_config($tpl)\r
- {\r
- $config_name = 'xs_style_' . $tpl;\r
- global $board_config;\r
- $result = false;\r
- if(empty($board_config[$config_name]))\r
- {\r
- $old = $this->style_config;\r
- $result = $this->_add_config($tpl, false);\r
- $this->style_config = $old;\r
- }\r
- return $result;\r
- }\r
-\r
- /*\r
- * Refresh config data\r
- */\r
- function _refresh_config($tpl, $add_vars = false)\r
- {\r
- global $phpbb_root_path;\r
- if(@file_exists($phpbb_root_path . 'templates/' . $tpl . '/xs_config.cfg'))\r
- {\r
- $style_config = array();\r
- include($phpbb_root_path . 'templates/' . $tpl . '/xs_config.cfg');\r
- if(count($style_config))\r
- {\r
- global $board_config, $db;\r
- for($i=0; $i<count($style_config); $i++)\r
- {\r
- if(!isset($this->style_config[$style_config[$i]['var']]))\r
- {\r
- $this->style_config[$style_config[$i]['var']] = $style_config[$i]['default'];\r
- if($add_vars)\r
- {\r
- $this->vars['TPL_CFG_' . strtoupper($style_config[$i]['var'])] = $style_config[$i]['default'];\r
- }\r
- }\r
- }\r
- $str = $this->_serialize($this->style_config);\r
- $config_name = 'xs_style_' . $tpl;\r
- if(isset($board_config[$config_name]))\r
- {\r
- $sql = "UPDATE " . CONFIG_TABLE . " SET config_value='" . str_replace('\\\'', '\'\'', addslashes($str)) . "' WHERE config_name='" . str_replace('\\\'', '\'\'', addslashes($config_name)) . "'";\r
- }\r
- else\r
- {\r
- $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('" . str_replace('\\\'', '\'\'', addslashes($config_name)) . "', '" . str_replace('\\\'', '\'\'', addslashes($str)) . "')";\r
- }\r
- $db->sql_query($sql);\r
- $board_config[$config_name] = $str;\r
- // recache config table for cat_hierarchy 2.1.0\r
- global $config;\r
- if(isset($config->data) && $config->data === $board_config && isset($config->data['mod_cat_hierarchy']))\r
- {\r
- $config->read(true);\r
- }\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
-\r
- function refresh_config($tpl = '')\r
- {\r
- if($tpl === '')\r
- {\r
- $tpl = $this->tpl;\r
- }\r
- if($tpl == $this->tpl)\r
- {\r
- $result = $this->_refresh_config($tpl, true);\r
- }\r
- else\r
- {\r
- $old = $this->style_config;\r
- $result = $this->_refresh_config($tpl, false);\r
- $this->style_config = $old;\r
- }\r
- return $result;\r
- }\r
-\r
- /*\r
- * Get style configuration\r
- */\r
- function _get_config($tpl, $add_config)\r
- {\r
- $this->style_config = array();\r
- if(empty($tpl))\r
- {\r
- $tpl = $this->tpl;\r
- }\r
- $config_name = 'xs_style_' . $tpl;\r
- global $board_config;\r
- if(empty($board_config[$config_name]))\r
- {\r
- if($add_config)\r
- {\r
- $this->_add_config($tpl, $tpl === $this->tpl ? true : false);\r
- }\r
- return $this->style_config;\r
- }\r
- $this->style_config = $this->_unserialize($board_config[$config_name]);\r
- if($tpl === $this->tpl)\r
- {\r
- foreach($this->style_config as $var => $value)\r
- {\r
- $this->vars['TPL_CFG_' . strtoupper($var)] = $value;\r
- }\r
- }\r
- return $this->style_config;\r
- }\r
-\r
- function get_config($tpl = '', $add_config = true)\r
- {\r
- if(empty($tpl))\r
- {\r
- if(empty($this->tpl))\r
- {\r
- return array();\r
- }\r
- $this->_get_config($this->tpl, $add_config);\r
- return $this->style_config;\r
- }\r
- else\r
- {\r
- $old_config = $this->style_config;\r
- $result = $this->_get_config($tpl, $add_config);\r
- $this->style_config = $old_config;\r
- return $result;\r
- }\r
- }\r
-\r
- /*\r
- * Split/merge config data.\r
- * Using this function instead of (un)serialize because it generates smaller string so it can be stored in phpbb_config\r
- */\r
- function _serialize($array)\r
- {\r
- if(!is_array($array))\r
- {\r
- return '';\r
- }\r
- $str = '';\r
- foreach($array as $var => $value)\r
- {\r
- if($str)\r
- {\r
- $str .= '|';\r
- }\r
- $str .= $var . '=' . str_replace('|', '', $value);\r
- }\r
- return $str;\r
- }\r
- function _unserialize($str)\r
- {\r
- $array = array();\r
- $list = explode('|', $str);\r
- for($i=0; $i<count($list); $i++)\r
- {\r
- $row = explode('=', $list[$i], 2);\r
- if(count($row) == 2)\r
- {\r
- $array[$row[0]] = $row[1];\r
- }\r
- }\r
- return $array;\r
- }\r
-\r
-}\r
-\r
-function xs_switch($tpl, $name)\r
-{\r
- return (isset($tpl->_tpldata[$name.'.']) && count($tpl->_tpldata[$name.'.']) > 0);\r
-}\r
-\r
-?>
\ No newline at end of file