| <?php |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| if (!defined('IN_PHPBB')) |
| { |
| exit; |
| } |
| |
| |
| |
| |
| |
| class template |
| { |
| |
| |
| |
| |
| |
| |
| var $_tpldata = array('.' => array(0 => array())); |
| var $_rootref; |
| |
| |
| var $root = ''; |
| var $cachepath = ''; |
| var $files = array(); |
| var $filename = array(); |
| var $files_inherit = array(); |
| var $files_template = array(); |
| var $inherit_root = ''; |
| |
| |
| var $compiled_code = array(); |
| |
| |
| |
| |
| |
| function set_template() |
| { |
| global $phpbb_root_path, $user; |
| |
| if (file_exists($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template')) |
| { |
| $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template'; |
| $this->cachepath = $phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $user->theme['template_path']) . '_'; |
| |
| if ($user->theme['template_inherits_id']) |
| { |
| $this->inherit_root = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template'; |
| } |
| } |
| else |
| { |
| trigger_error('Template path could not be found: styles/' . $user->theme['template_path'] . '/template', E_USER_ERROR); |
| } |
| |
| $this->_rootref = &$this->_tpldata['.'][0]; |
| |
| return true; |
| } |
| |
| |
| |
| |
| |
| function set_custom_template($template_path, $template_name) |
| { |
| global $phpbb_root_path; |
| |
| $this->root = $template_path; |
| $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_'; |
| |
| return true; |
| } |
| |
| |
| |
| |
| |
| |
| function set_filenames($filename_array) |
| { |
| if (!is_array($filename_array)) |
| { |
| return false; |
| } |
| foreach ($filename_array as $handle => $filename) |
| { |
| if (empty($filename)) |
| { |
| trigger_error("template->set_filenames: Empty filename specified for $handle", E_USER_ERROR); |
| } |
| |
| $this->filename[$handle] = $filename; |
| $this->files[$handle] = $this->root . '/' . $filename; |
| |
| if ($this->inherit_root) |
| { |
| $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename; |
| } |
| } |
| |
| return true; |
| } |
| |
| |
| |
| |
| |
| function destroy() |
| { |
| $this->_tpldata = array('.' => array(0 => array())); |
| } |
| |
| |
| |
| |
| |
| function destroy_block_vars($blockname) |
| { |
| if (strpos($blockname, '.') !== false) |
| { |
| |
| $blocks = explode('.', $blockname); |
| $blockcount = sizeof($blocks) - 1; |
| |
| $str = &$this->_tpldata; |
| for ($i = 0; $i < $blockcount; $i++) |
| { |
| $str = &$str[$blocks[$i]]; |
| $str = &$str[sizeof($str) - 1]; |
| } |
| |
| unset($str[$blocks[$blockcount]]); |
| } |
| else |
| { |
| |
| unset($this->_tpldata[$blockname]); |
| } |
| |
| return true; |
| } |
| |
| |
| |
| |
| |
| function display($handle, $include_once = true) |
| { |
| global $user, $phpbb_hook; |
| |
| if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, __FUNCTION__), $handle, $include_once)) |
| { |
| if ($phpbb_hook->hook_return(array(__CLASS__, __FUNCTION__))) |
| { |
| return $phpbb_hook->hook_return_result(array(__CLASS__, __FUNCTION__)); |
| } |
| } |
| |
| if (defined('IN_ERROR_HANDLER')) |
| { |
| if ((E_NOTICE & error_reporting()) == E_NOTICE) |
| { |
| error_reporting(error_reporting() ^ E_NOTICE); |
| } |
| } |
| |
| if ($filename = $this->_tpl_load($handle)) |
| { |
| ($include_once) ? include_once($filename) : include($filename); |
| } |
| else |
| { |
| eval(' ?>' . $this->compiled_code[$handle] . '<?php '); |
| } |
| |
| return true; |
| } |
| |
| |
| |
| |
| |
| function assign_display($handle, $template_var = '', $return_content = true, $include_once = false) |
| { |
| ob_start(); |
| $this->display($handle, $include_once); |
| $contents = ob_get_clean(); |
| |
| if ($return_content) |
| { |
| return $contents; |
| } |
| |
| $this->assign_var($template_var, $contents); |
| |
| return true; |
| } |
| |
| |
| |
| |
| |
| function _tpl_load(&$handle) |
| { |
| global $user, $phpEx, $config; |
| |
| $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx; |
| $this->files_template[$handle] = $user->theme['template_id']; |
| |
| $recompile = false; |
| if (!file_exists($filename) || @filesize($filename) === 0) |
| { |
| $recompile = true; |
| } |
| else if ($config['load_tplcompile']) |
| { |
| |
| if ($user->theme['template_inherits_id'] && !file_exists($this->files[$handle])) |
| { |
| $this->files[$handle] = $this->files_inherit[$handle]; |
| $this->files_template[$handle] = $user->theme['template_inherits_id']; |
| } |
| $recompile = (@filemtime($filename) < filemtime($this->files[$handle])) ? true : false; |
| } |
| |
| |
| if (!$recompile) |
| { |
| return $filename; |
| } |
| |
| global $db, $phpbb_root_path; |
| |
| if (!class_exists('template_compile')) |
| { |
| include($phpbb_root_path . 'includes/functions_template.' . $phpEx); |
| } |
| |
| |
| if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($this->files[$handle])) |
| { |
| $this->files[$handle] = $this->files_inherit[$handle]; |
| $this->files_template[$handle] = $user->theme['template_inherits_id']; |
| } |
| |
| $compile = new template_compile($this); |
| |
| |
| if (!isset($this->files[$handle])) |
| { |
| trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR); |
| } |
| |
| |
| if (!$user) |
| { |
| $compile->_tpl_load_file($handle); |
| return false; |
| } |
| |
| if (isset($user->theme['template_storedb']) && $user->theme['template_storedb']) |
| { |
| $rows = array(); |
| $ids = array(); |
| |
| if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id']) |
| { |
| $ids[] = $user->theme['template_inherits_id']; |
| } |
| $ids[] = $user->theme['template_id']; |
| |
| foreach ($ids as $id) |
| { |
| $sql = 'SELECT * |
| FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' |
| WHERE template_id = ' . $id . " |
| AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "' |
| OR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')'; |
| |
| $result = $db->sql_query($sql); |
| while ($row = $db->sql_fetchrow($result)) |
| { |
| $rows[$row['template_filename']] = $row; |
| } |
| $db->sql_freeresult($result); |
| } |
| |
| if (sizeof($rows)) |
| { |
| foreach ($rows as $row) |
| { |
| $file = $this->root . '/' . $row['template_filename']; |
| $force_reload = false; |
| if ($row['template_id'] != $user->theme['template_id']) |
| { |
| |
| if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file)) |
| { |
| $file = $this->inherit_root . '/' . $row['template_filename']; |
| $this->files[$row['template_filename']] = $file; |
| $this->files_inherit[$row['template_filename']] = $file; |
| $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id']; |
| } |
| else if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id']) |
| { |
| |
| $force_reload = true; |
| $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id']; |
| } |
| } |
| else |
| { |
| $this->files_template[$row['template_filename']] = $user->theme['template_id']; |
| } |
| |
| if ($force_reload || $row['template_mtime'] < filemtime($file)) |
| { |
| if ($row['template_filename'] == $this->filename[$handle]) |
| { |
| $compile->_tpl_load_file($handle, true); |
| } |
| else |
| { |
| $this->files[$row['template_filename']] = $file; |
| $this->filename[$row['template_filename']] = $row['template_filename']; |
| $compile->_tpl_load_file($row['template_filename'], true); |
| unset($this->compiled_code[$row['template_filename']]); |
| unset($this->files[$row['template_filename']]); |
| unset($this->filename[$row['template_filename']]); |
| } |
| } |
| |
| if ($row['template_filename'] == $this->filename[$handle]) |
| { |
| $this->compiled_code[$handle] = $compile->compile(trim($row['template_data'])); |
| $compile->compile_write($handle, $this->compiled_code[$handle]); |
| } |
| else |
| { |
| |
| if (!file_exists($this->cachepath . str_replace('/', '.', $row['template_filename']) . '.' . $phpEx)) |
| { |
| $this->filename[$row['template_filename']] = $row['template_filename']; |
| $compile->compile_write($row['template_filename'], $compile->compile(trim($row['template_data']))); |
| unset($this->filename[$row['template_filename']]); |
| } |
| } |
| } |
| } |
| else |
| { |
| $file = $this->root . '/' . $row['template_filename']; |
| |
| if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file)) |
| { |
| $file = $this->inherit_root . '/' . $row['template_filename']; |
| $this->files[$row['template_filename']] = $file; |
| $this->files_inherit[$row['template_filename']] = $file; |
| $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id']; |
| } |
| |
| $compile->_tpl_load_file($handle, true); |
| return false; |
| } |
| |
| return false; |
| } |
| |
| $compile->_tpl_load_file($handle); |
| return false; |
| } |
| |
| |
| |
| |
| |
| function assign_vars($vararray) |
| { |
| foreach ($vararray as $key => $val) |
| { |
| $this->_rootref[$key] = $val; |
| } |
| |
| return true; |
| } |
| |
| |
| |
| |
| |
| function assign_var($varname, $varval) |
| { |
| $this->_rootref[$varname] = $varval; |
| |
| return true; |
| } |
| |
| |
| |
| |
| |
| function assign_block_vars($blockname, $vararray) |
| { |
| if (strpos($blockname, '.') !== false) |
| { |
| |
| $blocks = explode('.', $blockname); |
| $blockcount = sizeof($blocks) - 1; |
| |
| $str = &$this->_tpldata; |
| for ($i = 0; $i < $blockcount; $i++) |
| { |
| $str = &$str[$blocks[$i]]; |
| $str = &$str[sizeof($str) - 1]; |
| } |
| |
| $s_row_count = isset($str[$blocks[$blockcount]]) ? sizeof($str[$blocks[$blockcount]]) : 0; |
| $vararray['S_ROW_COUNT'] = $s_row_count; |
| |
| |
| if (!$s_row_count) |
| { |
| $vararray['S_FIRST_ROW'] = true; |
| } |
| |
| |
| |
| $vararray['S_LAST_ROW'] = true; |
| if ($s_row_count > 0) |
| { |
| unset($str[$blocks[$blockcount]][($s_row_count - 1)]['S_LAST_ROW']); |
| } |
| |
| |
| |
| |
| $str[$blocks[$blockcount]][] = $vararray; |
| } |
| else |
| { |
| |
| $s_row_count = (isset($this->_tpldata[$blockname])) ? sizeof($this->_tpldata[$blockname]) : 0; |
| $vararray['S_ROW_COUNT'] = $s_row_count; |
| |
| |
| if (!$s_row_count) |
| { |
| $vararray['S_FIRST_ROW'] = true; |
| } |
| |
| |
| $vararray['S_LAST_ROW'] = true; |
| if ($s_row_count > 0) |
| { |
| unset($this->_tpldata[$blockname][($s_row_count - 1)]['S_LAST_ROW']); |
| } |
| |
| |
| $this->_tpldata[$blockname][] = $vararray; |
| } |
| |
| return true; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function alter_block_array($blockname, $vararray, $key = false, $mode = 'insert') |
| { |
| if (strpos($blockname, '.') !== false) |
| { |
| |
| return false; |
| } |
| |
| |
| if ($key === false || $key === true) |
| { |
| $key = ($key === false) ? 0 : sizeof($this->_tpldata[$blockname]); |
| } |
| |
| |
| if (is_array($key)) |
| { |
| |
| list($search_key, $search_value) = @each($key); |
| |
| $key = NULL; |
| foreach ($this->_tpldata[$blockname] as $i => $val_ary) |
| { |
| if ($val_ary[$search_key] === $search_value) |
| { |
| $key = $i; |
| break; |
| } |
| } |
| |
| |
| if ($key === NULL) |
| { |
| return false; |
| } |
| } |
| |
| |
| if ($mode == 'insert') |
| { |
| |
| if ($key >= sizeof($this->_tpldata[$blockname])) |
| { |
| $key = sizeof($this->_tpldata[$blockname]); |
| unset($this->_tpldata[$blockname][($key - 1)]['S_LAST_ROW']); |
| $vararray['S_LAST_ROW'] = true; |
| } |
| else if ($key === 0) |
| { |
| unset($this->_tpldata[$blockname][0]['S_FIRST_ROW']); |
| $vararray['S_FIRST_ROW'] = true; |
| } |
| |
| |
| for ($i = sizeof($this->_tpldata[$blockname]); $i > $key; $i--) |
| { |
| $this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i-1]; |
| $this->_tpldata[$blockname][$i]['S_ROW_COUNT'] = $i; |
| } |
| |
| |
| $vararray['S_ROW_COUNT'] = $key; |
| $this->_tpldata[$blockname][$key] = $vararray; |
| |
| return true; |
| } |
| |
| |
| if ($mode == 'change') |
| { |
| if ($key == sizeof($this->_tpldata[$blockname])) |
| { |
| $key--; |
| } |
| |
| $this->_tpldata[$blockname][$key] = array_merge($this->_tpldata[$blockname][$key], $vararray); |
| return true; |
| } |
| |
| return false; |
| } |
| |
| |
| |
| |
| |
| function _tpl_include($filename, $include = true) |
| { |
| $handle = $filename; |
| $this->filename[$handle] = $filename; |
| $this->files[$handle] = $this->root . '/' . $filename; |
| if ($this->inherit_root) |
| { |
| $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename; |
| } |
| |
| $filename = $this->_tpl_load($handle); |
| |
| if ($include) |
| { |
| global $user; |
| |
| if ($filename) |
| { |
| include($filename); |
| return; |
| } |
| eval(' ?>' . $this->compiled_code[$handle] . '<?php '); |
| } |
| } |
| } |
| |
| ?> |