Changeset 702 for trunk/forum/includes/template.php
- Timestamp:
- Mar 31, 2010, 6:32:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/forum/includes/template.php
r400 r702 3 3 * 4 4 * @package phpBB3 5 * @version $Id : template.php 8943 2008-09-26 13:09:56Z acydburn$5 * @version $Id$ 6 6 * @copyright (c) 2005 phpBB Group, sections (c) 2001 ispi of Lincoln Inc 7 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License … … 40 40 var $files_template = array(); 41 41 var $inherit_root = ''; 42 var $orig_tpl_storedb; 43 var $orig_tpl_inherits_id; 42 44 43 45 // this will hash handle names to the compiled/uncompiled code for that handle. … … 56 58 $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template'; 57 59 $this->cachepath = $phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $user->theme['template_path']) . '_'; 58 60 61 if ($this->orig_tpl_storedb === null) 62 { 63 $this->orig_tpl_storedb = $user->theme['template_storedb']; 64 } 65 66 if ($this->orig_tpl_inherits_id === null) 67 { 68 $this->orig_tpl_inherits_id = $user->theme['template_inherits_id']; 69 } 70 71 $user->theme['template_storedb'] = $this->orig_tpl_storedb; 72 $user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id; 73 59 74 if ($user->theme['template_inherits_id']) 60 75 { … … 76 91 * @access public 77 92 */ 78 function set_custom_template($template_path, $template_name) 79 { 80 global $phpbb_root_path; 93 function set_custom_template($template_path, $template_name, $fallback_template_path = false) 94 { 95 global $phpbb_root_path, $user; 96 97 // Make sure $template_path has no ending slash 98 if (substr($template_path, -1) == '/') 99 { 100 $template_path = substr($template_path, 0, -1); 101 } 81 102 82 103 $this->root = $template_path; 83 104 $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_'; 84 105 106 if ($fallback_template_path !== false) 107 { 108 if (substr($fallback_template_path, -1) == '/') 109 { 110 $fallback_template_path = substr($fallback_template_path, 0, -1); 111 } 112 113 $this->inherit_root = $fallback_template_path; 114 $this->orig_tpl_inherits_id = true; 115 } 116 else 117 { 118 $this->orig_tpl_inherits_id = false; 119 } 120 121 // the database does not store the path or name of a custom template 122 // so there is no way we can properly store custom templates there 123 $this->orig_tpl_storedb = false; 124 125 $this->_rootref = &$this->_tpldata['.'][0]; 126 85 127 return true; 86 128 } … … 106 148 $this->filename[$handle] = $filename; 107 149 $this->files[$handle] = $this->root . '/' . $filename; 108 150 109 151 if ($this->inherit_root) 110 152 { … … 112 154 } 113 155 } 114 156 115 157 return true; 116 158 } … … 123 165 { 124 166 $this->_tpldata = array('.' => array(0 => array())); 167 $this->_rootref = &$this->_tpldata['.'][0]; 125 168 } 126 169 … … 210 253 return true; 211 254 } 212 255 213 256 /** 214 257 * Load a compiled template if possible, if not, recompile it … … 219 262 global $user, $phpEx, $config; 220 263 264 if (!isset($this->filename[$handle])) 265 { 266 trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR); 267 } 268 269 // reload these settings to have the values they had when this object was initialised 270 // using set_template or set_custom_template, they might otherwise have been overwritten 271 // by other template class instances in between. 272 $user->theme['template_storedb'] = $this->orig_tpl_storedb; 273 $user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id; 274 221 275 $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx; 222 $this->files_template[$handle] = $user->theme['template_id'];223 276 $this->files_template[$handle] = (isset($user->theme['template_id'])) ? $user->theme['template_id'] : 0; 277 224 278 $recompile = false; 225 279 if (!file_exists($filename) || @filesize($filename) === 0) … … 237 291 $recompile = (@filemtime($filename) < filemtime($this->files[$handle])) ? true : false; 238 292 } 239 293 240 294 // Recompile page if the original template is newer, otherwise load the compiled version 241 295 if (!$recompile) … … 250 304 include($phpbb_root_path . 'includes/functions_template.' . $phpEx); 251 305 } 252 306 253 307 // Inheritance - we point to another template file for this one. Equality is also used for store_db 254 308 if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($this->files[$handle])) … … 257 311 $this->files_template[$handle] = $user->theme['template_inherits_id']; 258 312 } 259 313 260 314 $compile = new template_compile($this); 261 315 … … 283 337 } 284 338 $ids[] = $user->theme['template_id']; 285 339 286 340 foreach ($ids as $id) 287 341 { … … 291 345 AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "' 292 346 OR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')'; 293 347 294 348 $result = $db->sql_query($sql); 295 349 while ($row = $db->sql_fetchrow($result)) … … 299 353 $db->sql_freeresult($result); 300 354 } 301 355 302 356 if (sizeof($rows)) 303 357 { … … 327 381 $this->files_template[$row['template_filename']] = $user->theme['template_id']; 328 382 } 329 383 330 384 if ($force_reload || $row['template_mtime'] < filemtime($file)) 331 385 { … … 469 523 unset($this->_tpldata[$blockname][($s_row_count - 1)]['S_LAST_ROW']); 470 524 } 471 525 472 526 // Add a new iteration to this block with the variable assignments we were given. 473 527 $this->_tpldata[$blockname][] = $vararray; … … 512 566 return false; 513 567 } 514 568 515 569 // Change key to zero (change first position) if false and to last position if true 516 570 if ($key === false || $key === true) … … 615 669 } 616 670 } 671 672 /** 673 * Include a php-file 674 * @access private 675 */ 676 function _php_include($filename) 677 { 678 global $phpbb_root_path; 679 680 $file = $phpbb_root_path . $filename; 681 682 if (!file_exists($file)) 683 { 684 // trigger_error cannot be used here, as the output already started 685 echo 'template->_php_include(): File ' . htmlspecialchars($file) . ' does not exist or is empty'; 686 return; 687 } 688 include($file); 689 } 617 690 } 618 691
Note:
See TracChangeset
for help on using the changeset viewer.