phpBB

Code Changes

File: includes/functions_template.php

  Unmodified   Added   Modified   Removed
Line 74Line 74
			global $db, $user;

$sql_ary = array(

			global $db, $user;

$sql_ary = array(

				'template_id'			=> $user->theme['template_id'],

				'template_id'			=> $this->template->files_template[$handle],

				'template_filename'		=> $this->template->filename[$handle],
'template_included' => '',
'template_mtime' => time(),

				'template_filename'		=> $this->template->filename[$handle],
'template_included' => '',
'template_mtime' => time(),

Line 128Line 128
		$php_blocks = $matches[1];
$code = preg_replace('#<!-- PHP -->.*?<!-- ENDPHP -->#s', '<!-- PHP -->', $code);


		$php_blocks = $matches[1];
$code = preg_replace('#<!-- PHP -->.*?<!-- ENDPHP -->#s', '<!-- PHP -->', $code);


		preg_match_all('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);

		preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);

		$include_blocks = $matches[1];

		$include_blocks = $matches[1];

		$code = preg_replace('#<!-- INCLUDE [a-zA-Z0-9\_\-\+\./]+ -->#', '<!-- INCLUDE -->', $code);

		$code = preg_replace('#<!-- INCLUDE (?:\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', '<!-- INCLUDE -->', $code);


preg_match_all('#<!-- INCLUDEPHP ([a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
$includephp_blocks = $matches[1];


preg_match_all('#<!-- INCLUDEPHP ([a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
$includephp_blocks = $matches[1];

Line 193Line 193

case 'INCLUDE':
$temp = array_shift($include_blocks);


case 'INCLUDE':
$temp = array_shift($include_blocks);

 

// Dynamic includes
// Cheap match rather than a full blown regexp, we already know
// the format of the input so just use string manipulation.
if ($temp[0] == '{')
{
$file = false;

if ($temp[1] == '$')
{
$var = substr($temp, 2, -1);
//$file = $this->template->_tpldata['DEFINE']['.'][$var];
$temp = "\$this->_tpldata['DEFINE']['.']['$var']";
}
else
{
$var = substr($temp, 1, -1);
//$file = $this->template->_rootref[$var];
$temp = "\$this->_rootref['$var']";
}
}
else
{
$file = $temp;
}


					$compile_blocks[] = '<?php ' . $this->compile_tag_include($temp) . ' ?>';

					$compile_blocks[] = '<?php ' . $this->compile_tag_include($temp) . ' ?>';

					$this->template->_tpl_include($temp, false);







// No point in checking variable includes
if ($file)
{
$this->template->_tpl_include($file, false);
}

				break;

case 'INCLUDEPHP':

				break;

case 'INCLUDEPHP':

Line 219Line 250
			$trim_check_text = trim($text_blocks[$i]);
$template_php .= (!$no_echo) ? (($trim_check_text != '') ? $text_blocks[$i] : '') . ((isset($compile_blocks[$i])) ? $compile_blocks[$i] : '') : (($trim_check_text != '') ? $text_blocks[$i] : '') . ((isset($compile_blocks[$i])) ? $compile_blocks[$i] : '');
}

			$trim_check_text = trim($text_blocks[$i]);
$template_php .= (!$no_echo) ? (($trim_check_text != '') ? $text_blocks[$i] : '') . ((isset($compile_blocks[$i])) ? $compile_blocks[$i] : '') : (($trim_check_text != '') ? $text_blocks[$i] : '') . ((isset($compile_blocks[$i])) ? $compile_blocks[$i] : '');
}

 

// Remove unused opening/closing tags
$template_php = str_replace(' ?><?php ', ' ', $template_php);

// Now add a newline after each php closing tag which already has a newline
// 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
$template_php = preg_replace('#\?\>([\r\n])#', '?>\1\1', $template_php);


// There will be a number of occasions where we switch into and out of
// PHP mode instantaneously. Rather than "burden" the parser with this
// we'll strip out such occurences, minimising such switching


// There will be a number of occasions where we switch into and out of
// PHP mode instantaneously. Rather than "burden" the parser with this
// we'll strip out such occurences, minimising such switching

		$template_php = str_replace(' ?><?php ', ' ', $template_php);




		if ($no_echo)
{
return "\$$echo_var .= '" . $template_php . "'";
}





		return (!$no_echo) ? $template_php : "\$$echo_var .= '" . $template_php . "'";

		return $template_php;

	}

/**

	}

/**

Line 253Line 294
		// transform vars prefixed by L_ into their language variable pendant if nothing is set within the tpldata array
if (strpos($text_blocks, '{L_') !== false)
{

		// transform vars prefixed by L_ into their language variable pendant if nothing is set within the tpldata array
if (strpos($text_blocks, '{L_') !== false)
{

			$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);

			$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);

		}

// Handle addslashed language variables prefixed with LA_
// If a template variable already exist, it will be used in favor of it...
if (strpos($text_blocks, '{LA_') !== false)
{

		}

// Handle addslashed language variables prefixed with LA_
// If a template variable already exist, it will be used in favor of it...
if (strpos($text_blocks, '{LA_') !== false)
{

			$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);

			$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);

		}

// Handle remaining varrefs

		}

// Handle remaining varrefs

		$text_blocks = preg_replace('#\{([a-z0-9\-_]*)\}#is', "<?php echo (isset(\$this->_rootref['\\1'])) ? \$this->_rootref['\\1'] : ''; ?>", $text_blocks);
$text_blocks = preg_replace('#\{\$([a-z0-9\-_]*)\}#is', "<?php echo (isset(\$this->_tpldata['DEFINE']['.']['\\1'])) ? \$this->_tpldata['DEFINE']['.']['\\1'] : ''; ?>", $text_blocks);

		$text_blocks = preg_replace('#\{([A-Z0-9\-_]+)\}#', "<?php echo (isset(\$this->_rootref['\\1'])) ? \$this->_rootref['\\1'] : ''; ?>", $text_blocks);
$text_blocks = preg_replace('#\{\$([A-Z0-9\-_]+)\}#', "<?php echo (isset(\$this->_tpldata['DEFINE']['.']['\\1'])) ? \$this->_tpldata['DEFINE']['.']['\\1'] : ''; ?>", $text_blocks);


return;
}


return;
}

Line 281Line 322
		// Is the designer wanting to call another loop in a loop?
if (strpos($tag_args, '!') === 0)
{

		// Is the designer wanting to call another loop in a loop?
if (strpos($tag_args, '!') === 0)
{

			// Count the number if ! occurrences (not allowed in vars)

			// Count the number of ! occurrences (not allowed in vars)

			$no_nesting = substr_count($tag_args, '!');
$tag_args = substr($tag_args, $no_nesting);
}

			$no_nesting = substr_count($tag_args, '!');
$tag_args = substr($tag_args, $no_nesting);
}

Line 514Line 555
							$varref .= "['" . $blocks[0] . "']";
}
$token = "sizeof($varref)";

							$varref .= "['" . $blocks[0] . "']";
}
$token = "sizeof($varref)";

 
					}
else if (!empty($token))
{
$token = '(' . $token . ')';

					}

break;
}
}


					}

break;
}
}


 
		// If there are no valid tokens left or only control/compare characters left, we do skip this statement
if (!sizeof($tokens) || str_replace(array(' ', '=', '!', '<', '>', '&', '|', '%', '(', ')'), '', implode('', $tokens)) == '')
{
$tokens = array('false');
}

		return (($elseif) ? '} else if (' : 'if (') . (implode(' ', $tokens) . ') { ');
}


		return (($elseif) ? '} else if (' : 'if (') . (implode(' ', $tokens) . ') { ');
}


Line 582Line 632
	*/
function compile_tag_include($tag_args)
{

	*/
function compile_tag_include($tag_args)
{

 
		// Process dynamic includes
if ($tag_args[0] == '$')
{
return "if (isset($tag_args)) { \$this->_tpl_include($tag_args); }";
}


		return "\$this->_tpl_include('$tag_args');";
}


		return "\$this->_tpl_include('$tag_args');";
}


Line 591Line 647
	*/
function compile_tag_include_php($tag_args)
{

	*/
function compile_tag_include_php($tag_args)
{

		return "include('" . $tag_args . "');";

		return "\$this->_php_include('$tag_args');";

	}

/**

	}

/**

Line 738Line 794
		global $phpEx;

$filename = $this->template->cachepath . str_replace('/', '.', $this->template->filename[$handle]) . '.' . $phpEx;

		global $phpEx;

$filename = $this->template->cachepath . str_replace('/', '.', $this->template->filename[$handle]) . '.' . $phpEx;

 

$data = "<?php if (!defined('IN_PHPBB')) exit;" . ((strpos($data, '<?php') === 0) ? substr($data, 5) : ' ?>' . $data);


if ($fp = @fopen($filename, 'wb'))
{


if ($fp = @fopen($filename, 'wb'))
{

Line 746Line 804
			@flock($fp, LOCK_UN);
@fclose($fp);


			@flock($fp, LOCK_UN);
@fclose($fp);


			@chmod($filename, 0666);

			phpbb_chmod($filename, CHMOD_READ | CHMOD_WRITE);

		}

return;

		}

return;