mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
fix path problems, rename some varibles from "template" to "file"
This commit is contained in:
@@ -1245,20 +1245,19 @@ reques * @var string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$_template_file_path = $this->template_dir . '/' . $tpl_file;
|
$_smarty_compile_path = $this->_get_compile_path($tpl_file);
|
||||||
$_smarty_compile_path = $this->_get_compile_path($_template_file_path);
|
|
||||||
|
|
||||||
// if we just need to display the results, don't perform output
|
// if we just need to display the results, don't perform output
|
||||||
// buffering - for speed
|
// buffering - for speed
|
||||||
if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {
|
if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {
|
||||||
if (!$this->_file_needs_compiling($_template_file_path, $_smarty_compile_path)
|
if (!$this->_is_compiled($tpl_file, $_smarty_compile_path)
|
||||||
|| $this->_compile_template($tpl_file, $_smarty_compile_path))
|
|| $this->_compile_template($tpl_file, $_smarty_compile_path))
|
||||||
{
|
{
|
||||||
include($_smarty_compile_path);
|
include($_smarty_compile_path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ob_start();
|
ob_start();
|
||||||
if (!$this->_file_needs_compiling($_template_file_path, $_smarty_compile_path)
|
if (!$this->_is_compiled($tpl_file, $_smarty_compile_path)
|
||||||
|| $this->_compile_template($tpl_file, $_smarty_compile_path))
|
|| $this->_compile_template($tpl_file, $_smarty_compile_path))
|
||||||
{
|
{
|
||||||
include($_smarty_compile_path);
|
include($_smarty_compile_path);
|
||||||
@@ -1410,7 +1409,7 @@ reques * @var string
|
|||||||
* @param string $compile_path
|
* @param string $compile_path
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function _file_needs_compiling($file_path, $compile_path)
|
function _is_compiled($file_path, $compile_path)
|
||||||
{
|
{
|
||||||
if (!$this->force_compile && file_exists($compile_path)) {
|
if (!$this->force_compile && file_exists($compile_path)) {
|
||||||
if (!$this->compile_check) {
|
if (!$this->compile_check) {
|
||||||
@@ -1425,7 +1424,7 @@ reques * @var string
|
|||||||
}
|
}
|
||||||
$_file_source = $_params['file_source'];
|
$_file_source = $_params['file_source'];
|
||||||
$_file_timestamp = $_params['file_timestamp'];
|
$_file_timestamp = $_params['file_timestamp'];
|
||||||
if ($_template_timestamp <= filemtime($compile_path)) {
|
if ($_file_timestamp <= filemtime($compile_path)) {
|
||||||
// template not expired, no recompile
|
// template not expired, no recompile
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -1448,8 +1447,9 @@ reques * @var string
|
|||||||
*/
|
*/
|
||||||
function _compile_template($tpl_file, $compile_path)
|
function _compile_template($tpl_file, $compile_path)
|
||||||
{
|
{
|
||||||
|
|
||||||
// compiled template does not exist, or forced compile
|
// compiled template does not exist, or forced compile
|
||||||
$_params = array('file_path' => $this->template_dir . '/' . $tpl_file);
|
$_params = array('file_path' => $tpl_file);
|
||||||
require_once(SMARTY_DIR . 'core/core.fetch_file_info.php');
|
require_once(SMARTY_DIR . 'core/core.fetch_file_info.php');
|
||||||
if (!smarty_core_fetch_file_info($_params, $this)) {
|
if (!smarty_core_fetch_file_info($_params, $this)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1491,7 +1491,7 @@ reques * @var string
|
|||||||
$smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals;
|
$smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals;
|
||||||
|
|
||||||
if ($smarty_compiler->_compile_file($tpl_file, $_file_source, $_file_compiled)) {
|
if ($smarty_compiler->_compile_file($tpl_file, $_file_source, $_file_compiled)) {
|
||||||
$_params = array('compile_path' => $compile_path, 'template_compiled' => $_file_compiled, 'template_timestamp' => $_file_timestamp);
|
$_params = array('compile_path' => $compile_path, 'file_compiled' => $_file_compiled, 'file_timestamp' => $_file_timestamp);
|
||||||
require_once(SMARTY_DIR . 'core/core.write_compiled_template.php');
|
require_once(SMARTY_DIR . 'core/core.write_compiled_template.php');
|
||||||
smarty_core_write_compiled_template($_params, $this);
|
smarty_core_write_compiled_template($_params, $this);
|
||||||
return true;
|
return true;
|
||||||
|
@@ -206,13 +206,13 @@ class Smarty_Compiler extends Smarty {
|
|||||||
/**
|
/**
|
||||||
* compile a template file
|
* compile a template file
|
||||||
*
|
*
|
||||||
* sets $template_compiled to the compiled source
|
* sets $file_compiled to the compiled source
|
||||||
* @param string $tpl_file
|
* @param string $tpl_file
|
||||||
* @param string $template_source
|
* @param string $file_source
|
||||||
* @param string $template_compiled
|
* @param string $file_compiled
|
||||||
* @return true
|
* @return true
|
||||||
*/
|
*/
|
||||||
function _compile_file($tpl_file, $template_source, &$template_compiled)
|
function _compile_file($tpl_file, $file_source, &$file_compiled)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->security) {
|
if ($this->security) {
|
||||||
@@ -235,8 +235,8 @@ class Smarty_Compiler extends Smarty {
|
|||||||
foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) {
|
foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) {
|
||||||
if ($prefilter === false) continue;
|
if ($prefilter === false) continue;
|
||||||
if ($prefilter[3] || $this->_plugin_implementation_exists($prefilter[0])) {
|
if ($prefilter[3] || $this->_plugin_implementation_exists($prefilter[0])) {
|
||||||
$template_source = call_user_func_array($prefilter[0],
|
$file_source = call_user_func_array($prefilter[0],
|
||||||
array($template_source, &$this));
|
array($file_source, &$this));
|
||||||
$this->_plugins['prefilter'][$filter_name][3] = true;
|
$this->_plugins['prefilter'][$filter_name][3] = true;
|
||||||
} else {
|
} else {
|
||||||
$this->_trigger_fatal_error("[plugin] prefilter '$filter_name' is not implemented");
|
$this->_trigger_fatal_error("[plugin] prefilter '$filter_name' is not implemented");
|
||||||
@@ -245,27 +245,27 @@ class Smarty_Compiler extends Smarty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Annihilate the comments. */
|
/* Annihilate the comments. */
|
||||||
$template_source = preg_replace("!({$ldq})\*(.*?)\*({$rdq})!se",
|
$file_source = preg_replace("!({$ldq})\*(.*?)\*({$rdq})!se",
|
||||||
"'\\1*'.str_repeat(\"\n\", substr_count('\\2', \"\n\")) .'*\\3'",
|
"'\\1*'.str_repeat(\"\n\", substr_count('\\2', \"\n\")) .'*\\3'",
|
||||||
$template_source);
|
$file_source);
|
||||||
|
|
||||||
/* Pull out the literal blocks. */
|
/* Pull out the literal blocks. */
|
||||||
preg_match_all("!{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}!s", $template_source, $_match);
|
preg_match_all("!{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}!s", $file_source, $_match);
|
||||||
$this->_literal_blocks = $_match[1];
|
$this->_literal_blocks = $_match[1];
|
||||||
$template_source = preg_replace("!{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}!s",
|
$file_source = preg_replace("!{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}!s",
|
||||||
$this->quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $template_source);
|
$this->quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $file_source);
|
||||||
|
|
||||||
/* Pull out the php code blocks. */
|
/* Pull out the php code blocks. */
|
||||||
preg_match_all("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", $template_source, $_match);
|
preg_match_all("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", $file_source, $_match);
|
||||||
$this->_php_blocks = $_match[1];
|
$this->_php_blocks = $_match[1];
|
||||||
$template_source = preg_replace("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s",
|
$file_source = preg_replace("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s",
|
||||||
$this->quote_replace($this->left_delimiter.'php'.$this->right_delimiter), $template_source);
|
$this->quote_replace($this->left_delimiter.'php'.$this->right_delimiter), $file_source);
|
||||||
|
|
||||||
/* Gather all template tags. */
|
/* Gather all template tags. */
|
||||||
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_source, $_match);
|
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $file_source, $_match);
|
||||||
$template_tags = $_match[1];
|
$template_tags = $_match[1];
|
||||||
/* Split content by template tags to obtain non-template content. */
|
/* Split content by template tags to obtain non-template content. */
|
||||||
$text_blocks = preg_split("!{$ldq}.*?{$rdq}!s", $template_source);
|
$text_blocks = preg_split("!{$ldq}.*?{$rdq}!s", $file_source);
|
||||||
|
|
||||||
/* loop through text blocks */
|
/* loop through text blocks */
|
||||||
for ($curr_tb = 0, $for_max = count($text_blocks); $curr_tb < $for_max; $curr_tb++) {
|
for ($curr_tb = 0, $for_max = count($text_blocks); $curr_tb < $for_max; $curr_tb++) {
|
||||||
@@ -305,7 +305,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$this->_current_line_no += substr_count($template_tags[$i], "\n");
|
$this->_current_line_no += substr_count($template_tags[$i], "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
$template_compiled = '';
|
$file_compiled = '';
|
||||||
|
|
||||||
/* Interleave the compiled contents and text blocks to get the final result. */
|
/* Interleave the compiled contents and text blocks to get the final result. */
|
||||||
for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) {
|
for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) {
|
||||||
@@ -313,25 +313,25 @@ class Smarty_Compiler extends Smarty {
|
|||||||
// tag result empty, remove first newline from following text block
|
// tag result empty, remove first newline from following text block
|
||||||
$text_blocks[$i+1] = preg_replace('!^(\r\n|\r|\n)!', '', $text_blocks[$i+1]);
|
$text_blocks[$i+1] = preg_replace('!^(\r\n|\r|\n)!', '', $text_blocks[$i+1]);
|
||||||
}
|
}
|
||||||
$template_compiled .= $text_blocks[$i].$compiled_tags[$i];
|
$file_compiled .= $text_blocks[$i].$compiled_tags[$i];
|
||||||
}
|
}
|
||||||
$template_compiled .= $text_blocks[$i];
|
$file_compiled .= $text_blocks[$i];
|
||||||
|
|
||||||
// remove \n from the end of the file, if any
|
// remove \n from the end of the file, if any
|
||||||
if ($template_compiled{strlen($template_compiled) - 1} == "\n" ) {
|
if ($file_compiled{strlen($file_compiled) - 1} == "\n" ) {
|
||||||
$template_compiled = substr($template_compiled, 0, -1);
|
$file_compiled = substr($file_compiled, 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove unnecessary close/open tags
|
// remove unnecessary close/open tags
|
||||||
$template_compiled = preg_replace('!\?>\n?<\?php!', '', $template_compiled);
|
$file_compiled = preg_replace('!\?>\n?<\?php!', '', $file_compiled);
|
||||||
|
|
||||||
// run compiled template through postfilter functions
|
// run compiled template through postfilter functions
|
||||||
if (count($this->_plugins['postfilter']) > 0) {
|
if (count($this->_plugins['postfilter']) > 0) {
|
||||||
foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) {
|
foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) {
|
||||||
if ($postfilter === false) continue;
|
if ($postfilter === false) continue;
|
||||||
if ($postfilter[3] || $this->_plugin_implementation_exists($postfilter[0])) {
|
if ($postfilter[3] || $this->_plugin_implementation_exists($postfilter[0])) {
|
||||||
$template_compiled = call_user_func_array($postfilter[0],
|
$file_compiled = call_user_func_array($postfilter[0],
|
||||||
array($template_compiled, &$this));
|
array($file_compiled, &$this));
|
||||||
$this->_plugins['postfilter'][$filter_name][3] = true;
|
$this->_plugins['postfilter'][$filter_name][3] = true;
|
||||||
} else {
|
} else {
|
||||||
$this->_trigger_fatal_error("Smarty plugin error: postfilter '$filter_name' is not implemented");
|
$this->_trigger_fatal_error("Smarty plugin error: postfilter '$filter_name' is not implemented");
|
||||||
@@ -363,7 +363,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$this->_init_smarty_vars = false;
|
$this->_init_smarty_vars = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$template_compiled = $template_header . $template_compiled;
|
$file_compiled = $template_header . $file_compiled;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -33,13 +33,11 @@ function smarty_core_display_debug_console($params, &$this)
|
|||||||
$this->left_delimiter = '{';
|
$this->left_delimiter = '{';
|
||||||
$this->right_delimiter = '}';
|
$this->right_delimiter = '}';
|
||||||
|
|
||||||
$_force_compile_orig = $this->force_compile;
|
|
||||||
$this->force_compile = true;
|
|
||||||
$_compile_id_orig = $this->_compile_id;
|
$_compile_id_orig = $this->_compile_id;
|
||||||
$this->_compile_id = null;
|
$this->_compile_id = null;
|
||||||
|
|
||||||
$_compile_path = $this->_get_compile_path($this->debug_tpl);
|
$_compile_path = $this->_get_compile_path($this->debug_tpl);
|
||||||
if ($this->_process_template($this->debug_tpl, $_compile_path))
|
if ($this->_compile_template($this->debug_tpl, $_compile_path))
|
||||||
{
|
{
|
||||||
ob_start();
|
ob_start();
|
||||||
include($_compile_path);
|
include($_compile_path);
|
||||||
@@ -49,7 +47,6 @@ function smarty_core_display_debug_console($params, &$this)
|
|||||||
$_results = '';
|
$_results = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->force_compile = $_force_compile_orig;
|
|
||||||
$this->_compile_id = $_compile_id_orig;
|
$this->_compile_id = $_compile_id_orig;
|
||||||
|
|
||||||
$this->left_delimiter = $_ldelim_orig;
|
$this->left_delimiter = $_ldelim_orig;
|
||||||
|
@@ -19,8 +19,6 @@
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// $tpl_path, &$template_source, &$template_timestamp, $get_source = true, $quiet = false
|
|
||||||
|
|
||||||
function smarty_core_fetch_file_info(&$params, &$this)
|
function smarty_core_fetch_file_info(&$params, &$this)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -77,7 +75,7 @@ function smarty_core_fetch_file_info(&$params, &$this)
|
|||||||
require_once(SMARTY_DIR . 'core/core.is_secure.php');
|
require_once(SMARTY_DIR . 'core/core.is_secure.php');
|
||||||
if (!$_return) {
|
if (!$_return) {
|
||||||
if (!$params['quiet']) {
|
if (!$params['quiet']) {
|
||||||
$this->trigger_error('unable to read template resource: "' . $params['file_path'] . '"');
|
$this->trigger_error('unable to read file resource: "' . $params['file_path'] . '"');
|
||||||
}
|
}
|
||||||
} else if ($_return && $this->security && !smarty_core_is_secure($_params, $this)) {
|
} else if ($_return && $this->security && !smarty_core_is_secure($_params, $this)) {
|
||||||
if (!$params['quiet'])
|
if (!$params['quiet'])
|
||||||
|
@@ -42,7 +42,7 @@ function smarty_core_parse_file_path(&$params, &$this)
|
|||||||
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $params['resource_name'])) {
|
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $params['resource_name'])) {
|
||||||
// relative pathname to $params['file_base_path']
|
// relative pathname to $params['file_base_path']
|
||||||
// use the first directory where the file is found
|
// use the first directory where the file is found
|
||||||
$_file_base_path = isset($params['file_base_path']) ? $params['file_base_path'] : array('.');
|
$_file_base_path = isset($params['file_base_path']) ? $params['file_base_path'] : array($this->template_dir, '.');
|
||||||
settype($_file_base_path, 'array');
|
settype($_file_base_path, 'array');
|
||||||
foreach ($_file_base_path as $_curr_path) {
|
foreach ($_file_base_path as $_curr_path) {
|
||||||
$_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name'];
|
$_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name'];
|
||||||
|
@@ -9,8 +9,8 @@
|
|||||||
* write the compiled template
|
* write the compiled template
|
||||||
*
|
*
|
||||||
* @param string $compile_path
|
* @param string $compile_path
|
||||||
* @param string $template_compiled
|
* @param string $file_compiled
|
||||||
* @param integer $template_timestamp
|
* @param integer $file_timestamp
|
||||||
* @return true
|
* @return true
|
||||||
*/
|
*/
|
||||||
function smarty_core_write_compiled_template($params, &$this)
|
function smarty_core_write_compiled_template($params, &$this)
|
||||||
@@ -25,10 +25,10 @@ function smarty_core_write_compiled_template($params, &$this)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$_params = array('filename' => $params['compile_path'], 'contents' => $params['template_compiled'], 'create_dirs' => true);
|
$_params = array('filename' => $params['compile_path'], 'contents' => $params['file_compiled'], 'create_dirs' => true);
|
||||||
require_once(SMARTY_DIR . 'core/core.write_file.php');
|
require_once(SMARTY_DIR . 'core/core.write_file.php');
|
||||||
smarty_core_write_file($_params, $this);
|
smarty_core_write_file($_params, $this);
|
||||||
touch($params['compile_path'], $params['template_timestamp']);
|
touch($params['compile_path'], $params['file_timestamp']);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -63,12 +63,13 @@ function smarty_function_config_load($params, &$smarty)
|
|||||||
$_config_dir = $_params['new_file_path'];
|
$_config_dir = $_params['new_file_path'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$_compile_file = $smarty->_get_compile_path($_config_dir . '/' . $_file);
|
$_file_path = $_config_dir . '/' . $_file;
|
||||||
|
$_compile_file = $smarty->_get_compile_path($_file_path);
|
||||||
|
|
||||||
if($smarty->force_compile
|
if($smarty->force_compile
|
||||||
|| !file_exists($_compile_file)
|
|| !file_exists($_compile_file)
|
||||||
|| ($smarty->compile_check
|
|| ($smarty->compile_check
|
||||||
&& $smarty->_file_needs_compiling($_config_dir . '/' . $_file, $_compile_file))) {
|
&& $smarty->_is_compiled($_file_path, $_compile_file))) {
|
||||||
// compile config file
|
// compile config file
|
||||||
if(!is_object($smarty->_conf_obj)) {
|
if(!is_object($smarty->_conf_obj)) {
|
||||||
require_once SMARTY_DIR . $smarty->config_class . '.class.php';
|
require_once SMARTY_DIR . $smarty->config_class . '.class.php';
|
||||||
@@ -86,7 +87,7 @@ function smarty_function_config_load($params, &$smarty)
|
|||||||
} else {
|
} else {
|
||||||
$_output = '<?php $_config_vars = unserialize(' . serialize($_config_vars) . '); ?>';
|
$_output = '<?php $_config_vars = unserialize(' . serialize($_config_vars) . '); ?>';
|
||||||
}
|
}
|
||||||
$_params = (array('compile_path' => $_compile_file, 'template_compiled' => $_output));
|
$_params = (array('compile_path' => $_compile_file, 'file_compiled' => $_output, 'file_timestamp' => filemtime($_file_path)));
|
||||||
require_once(SMARTY_DIR . 'core/core.write_compiled_template.php');
|
require_once(SMARTY_DIR . 'core/core.write_compiled_template.php');
|
||||||
smarty_core_write_compiled_template($_params, $smarty);
|
smarty_core_write_compiled_template($_params, $smarty);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user