Smarty_Compiler.class.php

This commit is contained in:
messju
2004-04-16 07:53:37 +00:00
parent d85cbe84ec
commit 729ebe26ed
10 changed files with 46 additions and 20 deletions

View File

@@ -183,6 +183,9 @@ class Smarty
*/ */
var $cache_modified_check = false; var $cache_modified_check = false;
var $volatile_plugins = array('volatile'=>true,
'insert_f' => '*');
/** /**
* This determines how Smarty handles "<?php ... ?>" tags in templates. * This determines how Smarty handles "<?php ... ?>" tags in templates.
* possible values: * possible values:
@@ -1223,6 +1226,14 @@ class Smarty
header("Last-Modified: ".gmdate('D, d M Y H:i:s', time()).' GMT'); header("Last-Modified: ".gmdate('D, d M Y H:i:s', time()).' GMT');
} }
} }
if (isset($this->_cache_info['expires'])) {
$expires = $this->_cache_info['expires'];
} else {
$expires = 0;
}
header("Expires: " . gmdate('D, d M Y H:i:s', $expires) . ' GMT');
} }
// load filters that are marked as autoload // load filters that are marked as autoload
@@ -1447,7 +1458,7 @@ class Smarty
} }
$smarty_compiler = new $this->compiler_class; $smarty_compiler =& new $this->compiler_class();
$smarty_compiler->template_dir = $this->template_dir; $smarty_compiler->template_dir = $this->template_dir;
$smarty_compiler->compile_dir = $this->compile_dir; $smarty_compiler->compile_dir = $this->compile_dir;

View File

@@ -1017,7 +1017,7 @@ class Smarty_Compiler extends Smarty {
$this->_syntax_error("missing section name", E_USER_ERROR, __FILE__, __LINE__); $this->_syntax_error("missing section name", E_USER_ERROR, __FILE__, __LINE__);
} }
$output .= "if (isset(\$this->_sections[$section_name])) unset(\$this->_sections[$section_name]);\n"; $output .= "unset(\$this->_sections[$section_name]);\n";
$section_props = "\$this->_sections[$section_name]"; $section_props = "\$this->_sections[$section_name]";
foreach ($attrs as $attr_name => $attr_value) { foreach ($attrs as $attr_name => $attr_value) {

View File

@@ -29,11 +29,6 @@ function smarty_core_assemble_plugin_filepath($params, &$smarty)
// see if path is relative // see if path is relative
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) { if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) {
$_relative_paths[] = $_plugin_dir; $_relative_paths[] = $_plugin_dir;
// relative path, see if it is in the SMARTY_DIR
if (@is_readable(SMARTY_DIR . $_plugin_filepath)) {
$_return = SMARTY_DIR . $_plugin_filepath;
break;
}
} }
// try relative to cwd (or absolute) // try relative to cwd (or absolute)
if (@is_readable($_plugin_filepath)) { if (@is_readable($_plugin_filepath)) {
@@ -55,6 +50,12 @@ function smarty_core_assemble_plugin_filepath($params, &$smarty)
$_return = $_params['new_file_path']; $_return = $_params['new_file_path'];
break; break;
} }
// maybe it is in the SMARTY_DIR
if (@is_readable(SMARTY_DIR . $_plugin_filepath)) {
$_return = SMARTY_DIR . $_plugin_filepath;
break;
}
} }
} }
} }

View File

@@ -41,6 +41,7 @@ function smarty_core_read_cache_file(&$params, &$smarty)
$_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']); $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
$_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id); $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);
$params['results'] = $smarty->_read_file($_cache_file); $params['results'] = $smarty->_read_file($_cache_file);
# $params['results'] = file_get_contents($_cache_file);
} }
if (empty($params['results'])) { if (empty($params['results'])) {
@@ -52,6 +53,8 @@ function smarty_core_read_cache_file(&$params, &$smarty)
$cache_header = $cache_split[0]; $cache_header = $cache_split[0];
$_cache_info = unserialize($cache_header); $_cache_info = unserialize($cache_header);
if (!isset($_cache_info['expires']))
$_cache_info['expires'] = time() + $smarty->cache_lifetime;
if ($smarty->caching == 2 && isset ($_cache_info['expires'])){ if ($smarty->caching == 2 && isset ($_cache_info['expires'])){
// caching by expiration time // caching by expiration time

View File

@@ -25,7 +25,9 @@ function smarty_core_write_file($params, &$smarty)
// write to tmp file, then rename it to avoid // write to tmp file, then rename it to avoid
// file locking race condition // file locking race condition
$_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid(''); # $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('');
$_tmp_file = tempnam($_dirname , '_tmp');
# $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('', true);
if (!($fd = @fopen($_tmp_file, 'w'))) { if (!($fd = @fopen($_tmp_file, 'w'))) {
$smarty->trigger_error("problem writing temporary file '$_tmp_file'"); $smarty->trigger_error("problem writing temporary file '$_tmp_file'");

View File

@@ -29,14 +29,14 @@
</BODY></HTML> </BODY></HTML>
{else} {else}
<SCRIPT language=javascript> <SCRIPT language=javascript>
if( self.name == '' ) {ldelim} if( !self.name || ( self.name == '' ) ) {ldelim}
var title = 'Console'; var title = 'Console';
{rdelim} {rdelim}
else {ldelim} else {ldelim}
var title = 'Console_' + self.name; var title = 'Console_' + self.name;
{rdelim} {rdelim}
_smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes"); _smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes");
_smarty_console.document.write("<HTML><TITLE>Smarty Debug Console_"+self.name+"</TITLE><BODY bgcolor=#ffffff>"); _smarty_console.document.write("<HTML><TITLE>Smarty Debug " +title+"</TITLE><BODY bgcolor=#ffffff>");
_smarty_console.document.write("<table border=0 width=100%>"); _smarty_console.document.write("<table border=0 width=100%>");
_smarty_console.document.write("<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>"); _smarty_console.document.write("<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>");
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files (load time in seconds):</b></td></tr>"); _smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files (load time in seconds):</b></td></tr>");

View File

@@ -20,7 +20,7 @@
function smarty_function_eval($params, &$smarty) function smarty_function_eval($params, &$smarty)
{ {
if (!isset($params['var'])) { if (!array_key_exists('var', $params)) {
$smarty->trigger_error("eval: missing 'var' parameter"); $smarty->trigger_error("eval: missing 'var' parameter");
return; return;
} }

View File

@@ -99,7 +99,9 @@ function smarty_function_popup($params, &$smarty)
if (empty($trigger)) { $trigger = "onmouseover"; } if (empty($trigger)) { $trigger = "onmouseover"; }
$retval = $trigger . '="return overlib(\''.preg_replace(array("!'!","![\r\n]!"),array("\'",'\r'),$text).'\''; $retval = $trigger . '="' . htmlspecialchars(
'return overlib(\''.preg_replace(array("!'!","![\r\n]!"),
array("\'",'\r'),$text).'\'');
$retval .= $append . ');" onmouseout="nd();"'; $retval .= $append . ');" onmouseout="nd();"';
return $retval; return $retval;

View File

@@ -51,7 +51,12 @@ function smarty_modifier_escape($string, $esc_type = 'html')
case 'javascript': case 'javascript':
// escape quotes and backslashes and newlines // escape quotes and backslashes and newlines
return strtr($string, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n')); $return = strtr($string, array(
"\x08" => '\\b', "\x09" => '\\t', "\n" => '\\n',
"\x0b" => '\\v', "\x0c" => '\\f', "\r" => '\\r',
'"' => '\\"', '\'' => '\\\'', '\\' => '\\\\'));
return preg_replace('!<(/\w)!', "<\\\\$1", $return);
default: default:
return $string; return $string;

View File

@@ -16,18 +16,20 @@
function smarty_make_timestamp($string) function smarty_make_timestamp($string)
{ {
if(empty($string)) { if(empty($string)) {
$string = "now"; // now
} $time = -1;
$time = strtotime($string);
if (is_numeric($time) && $time != -1)
return $time;
} elseif (preg_match('/^\d{14}$/', $string)) {
// is mysql timestamp format of YYYYMMDDHHMMSS? // is mysql timestamp format of YYYYMMDDHHMMSS?
if (preg_match('/^\d{14}$/', $string)) {
$time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2), $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2),
substr($string,4,2),substr($string,6,2),substr($string,0,4)); substr($string,4,2),substr($string,6,2),substr($string,0,4));
return $time; return $time;
} else {
$time = strtotime($string);
if (is_numeric($time) && $time != -1)
return $time;
} }
// couldn't recognize it, try to return a time // couldn't recognize it, try to return a time