Changeset 702 for trunk/forum/includes/functions_template.php
- Timestamp:
- Mar 31, 2010, 6:32:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/forum/includes/functions_template.php
r400 r702 3 3 * 4 4 * @package phpBB3 5 * @version $Id : functions_template.php 8813 2008-09-04 11:52:01Z aptx$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 … … 129 129 $code = preg_replace('#<!-- PHP -->.*?<!-- ENDPHP -->#s', '<!-- PHP -->', $code); 130 130 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); 132 132 $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); 134 134 135 135 preg_match_all('#<!-- INCLUDEPHP ([a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches); … … 194 194 case 'INCLUDE': 195 195 $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 196 222 $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 } 198 229 break; 199 230 … … 221 252 } 222 253 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 223 261 // There will be a number of occasions where we switch into and out of 224 262 // PHP mode instantaneously. Rather than "burden" the parser with this 225 263 // 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; 229 270 } 230 271 … … 254 295 if (strpos($text_blocks, '{L_') !== false) 255 296 { 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); 257 298 } 258 299 … … 261 302 if (strpos($text_blocks, '{LA_') !== false) 262 303 { 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); 264 305 } 265 306 266 307 // 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); 269 310 270 311 return; … … 592 633 function compile_tag_include($tag_args) 593 634 { 635 // Process dynamic includes 636 if ($tag_args[0] == '$') 637 { 638 return "if (isset($tag_args)) { \$this->_tpl_include($tag_args); }"; 639 } 640 594 641 return "\$this->_tpl_include('$tag_args');"; 595 642 } … … 601 648 function compile_tag_include_php($tag_args) 602 649 { 603 return " include('" . $tag_args . "');";650 return "\$this->_php_include('$tag_args');"; 604 651 } 605 652 … … 749 796 $filename = $this->template->cachepath . str_replace('/', '.', $this->template->filename[$handle]) . '.' . $phpEx; 750 797 798 $data = "<?php if (!defined('IN_PHPBB')) exit;" . ((strpos($data, '<?php') === 0) ? substr($data, 5) : ' ?>' . $data); 799 751 800 if ($fp = @fopen($filename, 'wb')) 752 801 { … … 756 805 @fclose($fp); 757 806 758 phpbb_chmod($filename, CHMOD_ WRITE);807 phpbb_chmod($filename, CHMOD_READ | CHMOD_WRITE); 759 808 } 760 809
Note:
See TracChangeset
for help on using the changeset viewer.