Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/template.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: template.php 8943 2008-09-26 13:09:56Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group, sections (c) 2001 ispi of Lincoln Inc
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    4040        var $files_template = array();
    4141        var $inherit_root = '';
     42        var $orig_tpl_storedb;
     43        var $orig_tpl_inherits_id;
    4244
    4345        // this will hash handle names to the compiled/uncompiled code for that handle.
     
    5658                        $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template';
    5759                        $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
    5974                        if ($user->theme['template_inherits_id'])
    6075                        {
     
    7691        * @access public
    7792        */
    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                }
    81102
    82103                $this->root = $template_path;
    83104                $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_';
    84105
     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
    85127                return true;
    86128        }
     
    106148                        $this->filename[$handle] = $filename;
    107149                        $this->files[$handle] = $this->root . '/' . $filename;
    108                        
     150
    109151                        if ($this->inherit_root)
    110152                        {
     
    112154                        }
    113155                }
    114                
     156
    115157                return true;
    116158        }
     
    123165        {
    124166                $this->_tpldata = array('.' => array(0 => array()));
     167                $this->_rootref = &$this->_tpldata['.'][0];
    125168        }
    126169
     
    210253                return true;
    211254        }
    212        
     255
    213256        /**
    214257        * Load a compiled template if possible, if not, recompile it
     
    219262                global $user, $phpEx, $config;
    220263
     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
    221275                $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
    224278                $recompile = false;
    225279                if (!file_exists($filename) || @filesize($filename) === 0)
     
    237291                        $recompile = (@filemtime($filename) < filemtime($this->files[$handle])) ? true : false;
    238292                }
    239                
     293
    240294                // Recompile page if the original template is newer, otherwise load the compiled version
    241295                if (!$recompile)
     
    250304                        include($phpbb_root_path . 'includes/functions_template.' . $phpEx);
    251305                }
    252                
     306
    253307                // Inheritance - we point to another template file for this one. Equality is also used for store_db
    254308                if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($this->files[$handle]))
     
    257311                        $this->files_template[$handle] = $user->theme['template_inherits_id'];
    258312                }
    259                
     313
    260314                $compile = new template_compile($this);
    261315
     
    283337                        }
    284338                        $ids[] = $user->theme['template_id'];
    285                        
     339
    286340                        foreach ($ids as $id)
    287341                        {
     
    291345                                        AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "'
    292346                                                OR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')';
    293                        
     347
    294348                                $result = $db->sql_query($sql);
    295349                                while ($row = $db->sql_fetchrow($result))
     
    299353                                $db->sql_freeresult($result);
    300354                        }
    301                                        
     355
    302356                        if (sizeof($rows))
    303357                        {
     
    327381                                                $this->files_template[$row['template_filename']] = $user->theme['template_id'];
    328382                                        }
    329                                        
     383
    330384                                        if ($force_reload || $row['template_mtime'] < filemtime($file))
    331385                                        {
     
    469523                                unset($this->_tpldata[$blockname][($s_row_count - 1)]['S_LAST_ROW']);
    470524                        }
    471                        
     525
    472526                        // Add a new iteration to this block with the variable assignments we were given.
    473527                        $this->_tpldata[$blockname][] = $vararray;
     
    512566                        return false;
    513567                }
    514                
     568
    515569                // Change key to zero (change first position) if false and to last position if true
    516570                if ($key === false || $key === true)
     
    615669                }
    616670        }
     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        }
    617690}
    618691
Note: See TracChangeset for help on using the changeset viewer.