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/functions_template.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_template.php 8813 2008-09-04 11:52:01Z aptx $
     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
     
    129129                $code = preg_replace('#<!-- PHP -->.*?<!-- ENDPHP -->#s', '<!-- PHP -->', $code);
    130130
    131                 preg_match_all('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
     131                preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
    132132                $include_blocks = $matches[1];
    133                 $code = preg_replace('#<!-- INCLUDE [a-zA-Z0-9\_\-\+\./]+ -->#', '<!-- INCLUDE -->', $code);
     133                $code = preg_replace('#<!-- INCLUDE (?:\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', '<!-- INCLUDE -->', $code);
    134134
    135135                preg_match_all('#<!-- INCLUDEPHP ([a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
     
    194194                                case 'INCLUDE':
    195195                                        $temp = array_shift($include_blocks);
     196
     197                                        // Dynamic includes
     198                                        // Cheap match rather than a full blown regexp, we already know
     199                                        // the format of the input so just use string manipulation.
     200                                        if ($temp[0] == '{')
     201                                        {
     202                                                $file = false;
     203
     204                                                if ($temp[1] == '$')
     205                                                {
     206                                                        $var = substr($temp, 2, -1);
     207                                                        //$file = $this->template->_tpldata['DEFINE']['.'][$var];
     208                                                        $temp = "\$this->_tpldata['DEFINE']['.']['$var']";
     209                                                }
     210                                                else
     211                                                {
     212                                                        $var = substr($temp, 1, -1);
     213                                                        //$file = $this->template->_rootref[$var];
     214                                                        $temp = "\$this->_rootref['$var']";
     215                                                }
     216                                        }
     217                                        else
     218                                        {
     219                                                $file = $temp;
     220                                        }
     221
    196222                                        $compile_blocks[] = '<?php ' . $this->compile_tag_include($temp) . ' ?>';
    197                                         $this->template->_tpl_include($temp, false);
     223
     224                                        // No point in checking variable includes
     225                                        if ($file)
     226                                        {
     227                                                $this->template->_tpl_include($file, false);
     228                                        }
    198229                                break;
    199230
     
    221252                }
    222253
     254                // Remove unused opening/closing tags
     255                $template_php = str_replace(' ?><?php ', ' ', $template_php);
     256
     257                // Now add a newline after each php closing tag which already has a newline
     258                // PHP itself strips a newline if a closing tag is used (this is documented behaviour) and it is mostly not intended by style authors to remove newlines
     259                $template_php = preg_replace('#\?\>([\r\n])#', '?>\1\1', $template_php);
     260
    223261                // There will be a number of occasions where we switch into and out of
    224262                // PHP mode instantaneously. Rather than "burden" the parser with this
    225263                // we'll strip out such occurences, minimising such switching
    226                 $template_php = str_replace(' ?><?php ', ' ', $template_php);
    227 
    228                 return (!$no_echo) ? $template_php : "\$$echo_var .= '" . $template_php . "'";
     264                if ($no_echo)
     265                {
     266                        return "\$$echo_var .= '" . $template_php . "'";
     267                }
     268
     269                return $template_php;
    229270        }
    230271
     
    254295                if (strpos($text_blocks, '{L_') !== false)
    255296                {
    256                         $text_blocks = preg_replace('#\{L_([a-z0-9\-_]*)\}#is', "<?php echo ((isset(\$this->_rootref['L_\\1'])) ? \$this->_rootref['L_\\1'] : ((isset(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '{ \\1 }')); ?>", $text_blocks);
     297                        $text_blocks = preg_replace('#\{L_([A-Z0-9\-_]+)\}#', "<?php echo ((isset(\$this->_rootref['L_\\1'])) ? \$this->_rootref['L_\\1'] : ((isset(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '{ \\1 }')); ?>", $text_blocks);
    257298                }
    258299
     
    261302                if (strpos($text_blocks, '{LA_') !== false)
    262303                {
    263                         $text_blocks = preg_replace('#\{LA_([a-z0-9\-_]*)\}#is', "<?php echo ((isset(\$this->_rootref['LA_\\1'])) ? \$this->_rootref['LA_\\1'] : ((isset(\$this->_rootref['L_\\1'])) ? addslashes(\$this->_rootref['L_\\1']) : ((isset(\$user->lang['\\1'])) ? addslashes(\$user->lang['\\1']) : '{ \\1 }'))); ?>", $text_blocks);
     304                        $text_blocks = preg_replace('#\{LA_([A-Z0-9\-_]+)\}#', "<?php echo ((isset(\$this->_rootref['LA_\\1'])) ? \$this->_rootref['LA_\\1'] : ((isset(\$this->_rootref['L_\\1'])) ? addslashes(\$this->_rootref['L_\\1']) : ((isset(\$user->lang['\\1'])) ? addslashes(\$user->lang['\\1']) : '{ \\1 }'))); ?>", $text_blocks);
    264305                }
    265306
    266307                // Handle remaining varrefs
    267                 $text_blocks = preg_replace('#\{([a-z0-9\-_]+)\}#is', "<?php echo (isset(\$this->_rootref['\\1'])) ? \$this->_rootref['\\1'] : ''; ?>", $text_blocks);
    268                 $text_blocks = preg_replace('#\{\$([a-z0-9\-_]+)\}#is', "<?php echo (isset(\$this->_tpldata['DEFINE']['.']['\\1'])) ? \$this->_tpldata['DEFINE']['.']['\\1'] : ''; ?>", $text_blocks);
     308                $text_blocks = preg_replace('#\{([A-Z0-9\-_]+)\}#', "<?php echo (isset(\$this->_rootref['\\1'])) ? \$this->_rootref['\\1'] : ''; ?>", $text_blocks);
     309                $text_blocks = preg_replace('#\{\$([A-Z0-9\-_]+)\}#', "<?php echo (isset(\$this->_tpldata['DEFINE']['.']['\\1'])) ? \$this->_tpldata['DEFINE']['.']['\\1'] : ''; ?>", $text_blocks);
    269310
    270311                return;
     
    592633        function compile_tag_include($tag_args)
    593634        {
     635                // Process dynamic includes
     636                if ($tag_args[0] == '$')
     637                {
     638                        return "if (isset($tag_args)) { \$this->_tpl_include($tag_args); }";
     639                }
     640
    594641                return "\$this->_tpl_include('$tag_args');";
    595642        }
     
    601648        function compile_tag_include_php($tag_args)
    602649        {
    603                 return "include('" . $tag_args . "');";
     650                return "\$this->_php_include('$tag_args');";
    604651        }
    605652
     
    749796                $filename = $this->template->cachepath . str_replace('/', '.', $this->template->filename[$handle]) . '.' . $phpEx;
    750797
     798                $data = "<?php if (!defined('IN_PHPBB')) exit;" . ((strpos($data, '<?php') === 0) ? substr($data, 5) : ' ?>' . $data);
     799
    751800                if ($fp = @fopen($filename, 'wb'))
    752801                {
     
    756805                        @fclose($fp);
    757806
    758                         phpbb_chmod($filename, CHMOD_WRITE);
     807                        phpbb_chmod($filename, CHMOD_READ | CHMOD_WRITE);
    759808                }
    760809
Note: See TracChangeset for help on using the changeset viewer.