mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 09:54:27 +02:00
PHP 8.1 compatibility
This commit is contained in:
@@ -306,11 +306,36 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
|
||||
$_html_months .= '<option value="">' . (isset($month_empty) ? $month_empty : $all_empty) . '</option>' .
|
||||
$option_separator;
|
||||
}
|
||||
|
||||
$formatter = null;
|
||||
$format_compare = '%m';
|
||||
if (class_exists('IntlDateFormatter')) {
|
||||
$format_compare = 'm';
|
||||
$patterns = array('%b', '%h', '%B', '%m');
|
||||
$replacement = array('MMM', 'MMM', 'MMMM', 'MM');
|
||||
$month_format = str_replace($patterns, $replacement, $month_format);
|
||||
$month_value_format = str_replace($patterns, $replacement, $month_value_format);
|
||||
$formatter = new IntlDateFormatter(
|
||||
setlocale(LC_TIME, '0'),
|
||||
IntlDateFormatter::NONE,
|
||||
IntlDateFormatter::NONE)
|
||||
;
|
||||
}
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
if (null !== $formatter) {
|
||||
$formatter->setPattern($month_format);
|
||||
$_text = $formatter->format($_month_timestamps[ $i ]);
|
||||
$formatter->setPattern($month_value_format);
|
||||
$_value = $formatter->format($_month_timestamps[ $i ]);
|
||||
} else {
|
||||
$_text = strftime($month_format, $_month_timestamps[ $i ]);
|
||||
$_value = strftime($month_value_format, $_month_timestamps[ $i ]);
|
||||
}
|
||||
|
||||
$_val = sprintf('%02d', $i);
|
||||
$_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[ $i ]) :
|
||||
($month_format === '%m' ? $_val : strftime($month_format, $_month_timestamps[ $i ]));
|
||||
$_value = $month_value_format === '%m' ? $_val : strftime($month_value_format, $_month_timestamps[ $i ]);
|
||||
($month_format === $format_compare ? $_val : $_text);
|
||||
$_value = $month_value_format === $format_compare ? $_val : $_value;
|
||||
$_html_months .= '<option value="' . $_value . '"' . ($_val == $_month ? ' selected="selected"' : '') .
|
||||
'>' . $_text . '</option>' . $option_separator;
|
||||
}
|
||||
|
@@ -196,8 +196,8 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
||||
*/
|
||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
clearstatcache(true, $cached->lock_id);
|
||||
if (is_file($cached->lock_id)) {
|
||||
clearstatcache(true, $cached->lock_id ?? '');
|
||||
if (null !== $cached->lock_id && is_file($cached->lock_id)) {
|
||||
$t = filemtime($cached->lock_id);
|
||||
return $t && (time() - $t < $smarty->locking_timeout);
|
||||
} else {
|
||||
|
@@ -157,7 +157,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
|
||||
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n";
|
||||
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>";
|
||||
$output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash, ob_get_clean());\n";
|
||||
$output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash ?? '', ob_get_clean());\n";
|
||||
$output .= "}\n}\n";
|
||||
$output .= "/*/ {$_funcName}_nocache */\n\n";
|
||||
$output .= "?>\n";
|
||||
|
@@ -158,7 +158,7 @@ class Smarty_Internal_Config_File_Compiler
|
||||
}
|
||||
// template header code
|
||||
$template_header =
|
||||
"<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") .
|
||||
"<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . date("Y-m-d H:i:s") .
|
||||
"\n";
|
||||
$template_header .= " compiled from '{$this->template->source->filepath}' */ ?>\n";
|
||||
$code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
|
||||
|
@@ -45,7 +45,7 @@ class Smarty_Internal_Runtime_CodeFrame
|
||||
$properties[ 'cache_lifetime' ] = $_template->cache_lifetime;
|
||||
}
|
||||
$output = "<?php\n";
|
||||
$output .= "/* Smarty version {$properties[ 'version' ]}, created on " . strftime("%Y-%m-%d %H:%M:%S") .
|
||||
$output .= "/* Smarty version {$properties[ 'version' ]}, created on " . date("Y-m-d H:i:s") .
|
||||
"\n from '" . str_replace('*/', '* /', $_template->source->filepath) . "' */\n\n";
|
||||
$output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
|
||||
$dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' .
|
||||
|
@@ -1135,7 +1135,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
flush();
|
||||
}
|
||||
$e = new SmartyCompilerException($error_text);
|
||||
$e->line = $line;
|
||||
$e->setLine($line);
|
||||
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ]));
|
||||
$e->desc = $args;
|
||||
$e->template = $this->template->source->filepath;
|
||||
|
@@ -16,12 +16,12 @@ class SmartyCompilerException extends SmartyException
|
||||
}
|
||||
|
||||
/**
|
||||
* The line number of the template error
|
||||
*
|
||||
* @type int|null
|
||||
* @param int $line
|
||||
*/
|
||||
public $line = null;
|
||||
|
||||
public function setLine($line)
|
||||
{
|
||||
$this->line = $line;
|
||||
}
|
||||
/**
|
||||
* The template source snippet relating to the error
|
||||
*
|
||||
|
@@ -30,7 +30,8 @@ class CacheResourceTestCommon extends PHPUnit_Smarty
|
||||
|
||||
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
|
||||
{
|
||||
return str_replace('#', $tpl->getTemplateVars('test'), $text);
|
||||
$replace = $tpl->getTemplateVars('test');
|
||||
return str_replace('#', $replace ?? '', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -234,7 +234,7 @@ class ResourceStream
|
||||
$v = &$GLOBALS[$this->varname];
|
||||
$l = strlen($data);
|
||||
$p = &$this->position;
|
||||
$v = substr($v, 0, $p) . $data . substr($v, $p += $l);
|
||||
$v = substr($v ?? '', 0, $p) . $data . substr($v ?? '', $p += $l);
|
||||
|
||||
return $l;
|
||||
}
|
||||
|
@@ -394,7 +394,7 @@ class ResourceStreamSecurity
|
||||
$v = &$GLOBALS[$this->varname];
|
||||
$l = strlen($data);
|
||||
$p = &$this->position;
|
||||
$v = substr($v, 0, $p) . $data . substr($v, $p += $l);
|
||||
$v = substr($v ?? '', 0, $p) . $data . substr($v ?? '', $p += $l);
|
||||
|
||||
return $l;
|
||||
}
|
||||
|
@@ -96,7 +96,7 @@ class VariableStream
|
||||
$v = &$GLOBALS[$this->varname];
|
||||
$l = strlen($data);
|
||||
$p = &$this->position;
|
||||
$v = substr($v, 0, $p) . $data . substr($v, $p += $l);
|
||||
$v = substr($v ?? '', 0, $p) . $data . substr($v ?? '', $p += $l);
|
||||
|
||||
return $l;
|
||||
}
|
||||
|
Reference in New Issue
Block a user