mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 09:54:27 +02:00
src/Template/* to PSR-4
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
use Smarty\Template\Source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends All Resource
|
* Extends All Resource
|
||||||
* Resource Implementation modifying the extends-Resource to walk
|
* Resource Implementation modifying the extends-Resource to walk
|
||||||
@@ -13,12 +16,12 @@ class Smarty_Resource_Extendsall extends \Smarty\Resource\ExtendsPlugin
|
|||||||
/**
|
/**
|
||||||
* populate Source Object with meta data from Resource
|
* populate Source Object with meta data from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
public function populate(Source $source, Template $_template = null)
|
||||||
{
|
{
|
||||||
$uid = '';
|
$uid = '';
|
||||||
$sources = array();
|
$sources = array();
|
||||||
|
@@ -70,7 +70,7 @@ cannot have both custom function `{func}` and block function
|
|||||||
* Purpose: translate a block of text
|
* Purpose: translate a block of text
|
||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
function smarty_block_translate($params, $content, Smarty_Internal_Template $template, &$repeat)
|
function smarty_block_translate($params, $content, \Smarty\Template $template, &$repeat)
|
||||||
{
|
{
|
||||||
// only output on the closing tag
|
// only output on the closing tag
|
||||||
if(!$repeat){
|
if(!$repeat){
|
||||||
|
@@ -14,18 +14,18 @@ template you\'re addressing: `foobarxyz:yourtemplate.tpl`.
|
|||||||
If a Resource\'s templates should not be run through the Smarty
|
If a Resource\'s templates should not be run through the Smarty
|
||||||
compiler, the Custom Resource may extend `Smarty_Resource_Uncompiled`.
|
compiler, the Custom Resource may extend `Smarty_Resource_Uncompiled`.
|
||||||
The Resource Handler must then implement the function
|
The Resource Handler must then implement the function
|
||||||
`renderUncompiled(Smarty_Internal_Template $_template)`. `$_template` is
|
`renderUncompiled(\Smarty\Template $_template)`. `$_template` is
|
||||||
a reference to the current template and contains all assigned variables
|
a reference to the current template and contains all assigned variables
|
||||||
which the implementor can access via
|
which the implementor can access via
|
||||||
`$_template->smarty->getTemplateVars()`. These Resources simply echo
|
`$_template->smarty->getTemplateVars()`. These Resources simply echo
|
||||||
their rendered content to the output stream. The rendered output will be
|
their rendered content to the output stream. The rendered output will be
|
||||||
output-cached if the Smarty instance was configured accordingly. See
|
output-cached if the Smarty instance was configured accordingly. See
|
||||||
`libs/sysplugins/smarty_internal_resource_php.php` for an example.
|
`src/Resource/PhpPlugin.php` for an example.
|
||||||
|
|
||||||
If the Resource\'s compiled templates should not be cached on disk, the
|
If the Resource\'s compiled templates should not be cached on disk, the
|
||||||
Custom Resource may extend `Smarty_Resource_Recompiled`. These Resources
|
Custom Resource may extend `Smarty_Resource_Recompiled`. These Resources
|
||||||
are compiled every time they are accessed. This may be an expensive
|
are compiled every time they are accessed. This may be an expensive
|
||||||
overhead. See `libs/sysplugins/smarty_internal_resource_eval.php` for an
|
overhead. See `src/Resource/StringEval.php` for an
|
||||||
example.
|
example.
|
||||||
|
|
||||||
|
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsBlock
|
* @subpackage PluginsBlock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {textformat}{/textformat} block plugin
|
* Smarty {textformat}{/textformat} block plugin
|
||||||
* Type: block function
|
* Type: block function
|
||||||
@@ -25,14 +28,14 @@
|
|||||||
*
|
*
|
||||||
* @param array $params parameters
|
* @param array $params parameters
|
||||||
* @param string $content contents of the block
|
* @param string $content contents of the block
|
||||||
* @param Smarty_Internal_Template $template template object
|
* @param Template $template template object
|
||||||
* @param boolean &$repeat repeat flag
|
* @param boolean &$repeat repeat flag
|
||||||
*
|
*
|
||||||
* @return string content re-formatted
|
* @return string content re-formatted
|
||||||
* @author Monte Ohrt <monte at ohrt dot com>
|
* @author Monte Ohrt <monte at ohrt dot com>
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
function smarty_block_textformat($params, $content, Smarty_Internal_Template $template, &$repeat)
|
function smarty_block_textformat($params, $content, Template $template, &$repeat)
|
||||||
{
|
{
|
||||||
if (is_null($content)) {
|
if (is_null($content)) {
|
||||||
return;
|
return;
|
||||||
|
@@ -5,20 +5,23 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsFunction
|
* @subpackage PluginsFunction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {counter} function plugin
|
* Smarty {counter} function plugin
|
||||||
* Type: function
|
* Type: function
|
||||||
* Name: counter
|
* Name: counter
|
||||||
* Purpose: print out a counter value
|
* Purpose: print out a counter value
|
||||||
*
|
*
|
||||||
* @author Monte Ohrt <monte at ohrt dot com>
|
|
||||||
* @link https://www.smarty.net/manual/en/language.function.counter.php {counter}
|
|
||||||
* (Smarty online manual)
|
|
||||||
*
|
|
||||||
* @param array $params parameters
|
* @param array $params parameters
|
||||||
* @param Smarty_Internal_Template $template template object
|
* @param Template $template template object
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
|
*@link https://www.smarty.net/manual/en/language.function.counter.php {counter}
|
||||||
|
* (Smarty online manual)
|
||||||
|
*
|
||||||
|
* @author Monte Ohrt <monte at ohrt dot com>
|
||||||
*/
|
*/
|
||||||
function smarty_function_counter($params, $template)
|
function smarty_function_counter($params, $template)
|
||||||
{
|
{
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsFunction
|
* @subpackage PluginsFunction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {cycle} function plugin
|
* Smarty {cycle} function plugin
|
||||||
* Type: function
|
* Type: function
|
||||||
@@ -37,7 +40,7 @@
|
|||||||
* @version 1.3
|
* @version 1.3
|
||||||
*
|
*
|
||||||
* @param array $params parameters
|
* @param array $params parameters
|
||||||
* @param Smarty_Internal_Template $template template object
|
* @param Template $template template object
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsFunction
|
* @subpackage PluginsFunction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {fetch} plugin
|
* Smarty {fetch} plugin
|
||||||
* Type: function
|
* Type: function
|
||||||
@@ -16,7 +19,7 @@
|
|||||||
* @author Monte Ohrt <monte at ohrt dot com>
|
* @author Monte Ohrt <monte at ohrt dot com>
|
||||||
*
|
*
|
||||||
* @param array $params parameters
|
* @param array $params parameters
|
||||||
* @param Smarty_Internal_Template $template template object
|
* @param Template $template template object
|
||||||
*
|
*
|
||||||
* @throws SmartyException
|
* @throws SmartyException
|
||||||
* @return string|null if the assign parameter is passed, Smarty assigns the result to a template variable
|
* @return string|null if the assign parameter is passed, Smarty assigns the result to a template variable
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsFunction
|
* @subpackage PluginsFunction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {html_checkboxes} function plugin
|
* Smarty {html_checkboxes} function plugin
|
||||||
* File: function.html_checkboxes.php
|
* File: function.html_checkboxes.php
|
||||||
@@ -36,13 +39,13 @@
|
|||||||
* @version 1.0
|
* @version 1.0
|
||||||
*
|
*
|
||||||
* @param array $params parameters
|
* @param array $params parameters
|
||||||
* @param Smarty_Internal_Template $template template object
|
* @param Template $template template object
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @uses smarty_function_escape_special_chars()
|
* @uses smarty_function_escape_special_chars()
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template)
|
function smarty_function_html_checkboxes($params, Template $template)
|
||||||
{
|
{
|
||||||
$name = 'checkbox';
|
$name = 'checkbox';
|
||||||
$values = null;
|
$values = null;
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsFunction
|
* @subpackage PluginsFunction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {html_image} function plugin
|
* Smarty {html_image} function plugin
|
||||||
* Type: function
|
* Type: function
|
||||||
@@ -28,13 +31,13 @@
|
|||||||
* @version 1.0
|
* @version 1.0
|
||||||
*
|
*
|
||||||
* @param array $params parameters
|
* @param array $params parameters
|
||||||
* @param Smarty_Internal_Template $template template object
|
* @param Template $template template object
|
||||||
*
|
*
|
||||||
* @throws SmartyException
|
* @throws SmartyException
|
||||||
* @return string
|
* @return string
|
||||||
* @uses smarty_function_escape_special_chars()
|
* @uses smarty_function_escape_special_chars()
|
||||||
*/
|
*/
|
||||||
function smarty_function_html_image($params, Smarty_Internal_Template $template)
|
function smarty_function_html_image($params, Template $template)
|
||||||
{
|
{
|
||||||
$alt = '';
|
$alt = '';
|
||||||
$file = '';
|
$file = '';
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsFunction
|
* @subpackage PluginsFunction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {html_options} function plugin
|
* Smarty {html_options} function plugin
|
||||||
* Type: function
|
* Type: function
|
||||||
@@ -28,13 +31,13 @@
|
|||||||
*
|
*
|
||||||
* @param array $params parameters
|
* @param array $params parameters
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @uses smarty_function_escape_special_chars()
|
* @uses smarty_function_escape_special_chars()
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
function smarty_function_html_options($params, Smarty_Internal_Template $template)
|
function smarty_function_html_options($params, Template $template)
|
||||||
{
|
{
|
||||||
$name = null;
|
$name = null;
|
||||||
$values = null;
|
$values = null;
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsFunction
|
* @subpackage PluginsFunction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {html_radios} function plugin
|
* Smarty {html_radios} function plugin
|
||||||
* File: function.html_radios.php
|
* File: function.html_radios.php
|
||||||
@@ -36,13 +39,13 @@
|
|||||||
* @version 1.0
|
* @version 1.0
|
||||||
*
|
*
|
||||||
* @param array $params parameters
|
* @param array $params parameters
|
||||||
* @param Smarty_Internal_Template $template template object
|
* @param Template $template template object
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @uses smarty_function_escape_special_chars()
|
* @uses smarty_function_escape_special_chars()
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
function smarty_function_html_radios($params, Smarty_Internal_Template $template)
|
function smarty_function_html_radios($params, Template $template)
|
||||||
{
|
{
|
||||||
$name = 'radio';
|
$name = 'radio';
|
||||||
$values = null;
|
$values = null;
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsFunction
|
* @subpackage PluginsFunction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {html_select_date} plugin
|
* Smarty {html_select_date} plugin
|
||||||
* Type: function
|
* Type: function
|
||||||
@@ -37,12 +40,12 @@
|
|||||||
*
|
*
|
||||||
* @param array $params parameters
|
* @param array $params parameters
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
function smarty_function_html_select_date($params, Smarty_Internal_Template $template)
|
function smarty_function_html_select_date($params, Template $template)
|
||||||
{
|
{
|
||||||
// generate timestamps used for month names only
|
// generate timestamps used for month names only
|
||||||
static $_month_timestamps = null;
|
static $_month_timestamps = null;
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsFunction
|
* @subpackage PluginsFunction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {html_select_time} function plugin
|
* Smarty {html_select_time} function plugin
|
||||||
* Type: function
|
* Type: function
|
||||||
@@ -18,13 +21,13 @@
|
|||||||
*
|
*
|
||||||
* @param array $params parameters
|
* @param array $params parameters
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @uses smarty_make_timestamp()
|
* @uses smarty_make_timestamp()
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
function smarty_function_html_select_time($params, Smarty_Internal_Template $template)
|
function smarty_function_html_select_time($params, Template $template)
|
||||||
{
|
{
|
||||||
$prefix = 'Time_';
|
$prefix = 'Time_';
|
||||||
$field_array = null;
|
$field_array = null;
|
||||||
@@ -139,7 +142,7 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
|
|||||||
isset($params[ 'time' ][ $prefix . 'Meridian' ]) ? (' ' . $params[ 'time' ][ $prefix . 'Meridian' ]) :
|
isset($params[ 'time' ][ $prefix . 'Meridian' ]) ? (' ' . $params[ 'time' ][ $prefix . 'Meridian' ]) :
|
||||||
'';
|
'';
|
||||||
$time = strtotime($_hour . ':' . $_minute . ':' . $_second . $_meridian);
|
$time = strtotime($_hour . ':' . $_minute . ':' . $_second . $_meridian);
|
||||||
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
|
[$_hour, $_minute, $_second] = $time = explode('-', date('H-i-s', $time));
|
||||||
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Hour' ])) {
|
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Hour' ])) {
|
||||||
// $_REQUEST given
|
// $_REQUEST given
|
||||||
foreach (array(
|
foreach (array(
|
||||||
@@ -154,19 +157,19 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
|
|||||||
$_meridian = isset($params[ 'time' ][ $field_array ][ $prefix . 'Meridian' ]) ?
|
$_meridian = isset($params[ 'time' ][ $field_array ][ $prefix . 'Meridian' ]) ?
|
||||||
(' ' . $params[ 'time' ][ $field_array ][ $prefix . 'Meridian' ]) : '';
|
(' ' . $params[ 'time' ][ $field_array ][ $prefix . 'Meridian' ]) : '';
|
||||||
$time = strtotime($_hour . ':' . $_minute . ':' . $_second . $_meridian);
|
$time = strtotime($_hour . ':' . $_minute . ':' . $_second . $_meridian);
|
||||||
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
|
[$_hour, $_minute, $_second] = $time = explode('-', date('H-i-s', $time));
|
||||||
} else {
|
} else {
|
||||||
// no date found, use NOW
|
// no date found, use NOW
|
||||||
list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d'));
|
[$_year, $_month, $_day] = $time = explode('-', date('Y-m-d'));
|
||||||
}
|
}
|
||||||
} elseif ($time === null) {
|
} elseif ($time === null) {
|
||||||
if (array_key_exists('time', $params)) {
|
if (array_key_exists('time', $params)) {
|
||||||
$_hour = $_minute = $_second = $time = null;
|
$_hour = $_minute = $_second = $time = null;
|
||||||
} else {
|
} else {
|
||||||
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s'));
|
[$_hour, $_minute, $_second] = $time = explode('-', date('H-i-s'));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
|
[$_hour, $_minute, $_second] = $time = explode('-', date('H-i-s', $time));
|
||||||
}
|
}
|
||||||
// generate hour <select>
|
// generate hour <select>
|
||||||
if ($display_hours) {
|
if ($display_hours) {
|
||||||
|
@@ -6,6 +6,9 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsFunction
|
* @subpackage PluginsFunction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {math} function plugin
|
* Smarty {math} function plugin
|
||||||
* Type: function
|
* Type: function
|
||||||
@@ -17,7 +20,7 @@
|
|||||||
* @author Monte Ohrt <monte at ohrt dot com>
|
* @author Monte Ohrt <monte at ohrt dot com>
|
||||||
*
|
*
|
||||||
* @param array $params parameters
|
* @param array $params parameters
|
||||||
* @param Smarty_Internal_Template $template template object
|
* @param Template $template template object
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
|
@@ -5,15 +5,18 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PluginsFilter
|
* @subpackage PluginsFilter
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty htmlspecialchars variablefilter plugin
|
* Smarty htmlspecialchars variablefilter plugin
|
||||||
*
|
*
|
||||||
* @param string $source input string
|
* @param string $source input string
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
*
|
*
|
||||||
* @return string filtered output
|
* @return string filtered output
|
||||||
*/
|
*/
|
||||||
function smarty_variablefilter_htmlspecialchars($source, Smarty_Internal_Template $template)
|
function smarty_variablefilter_htmlspecialchars($source, Template $template)
|
||||||
{
|
{
|
||||||
return htmlspecialchars($source, ENT_QUOTES, \Smarty\Smarty::$_CHARSET);
|
return htmlspecialchars($source, ENT_QUOTES, \Smarty\Smarty::$_CHARSET);
|
||||||
}
|
}
|
||||||
|
@@ -84,9 +84,9 @@ class Block
|
|||||||
/**
|
/**
|
||||||
* Compiled block code overloaded by {block} class
|
* Compiled block code overloaded by {block} class
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $tpl
|
* @param \Smarty\Template $tpl
|
||||||
*/
|
*/
|
||||||
public function callBlock(\Smarty_Internal_Template $tpl)
|
public function callBlock(\Smarty\Template $tpl)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,8 +3,8 @@
|
|||||||
namespace Smarty\Cacheresource;
|
namespace Smarty\Cacheresource;
|
||||||
|
|
||||||
use Smarty\Smarty;
|
use Smarty\Smarty;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use Smarty_Template_Cached;
|
use Smarty\Template\Cached;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin
|
* Smarty Internal Plugin
|
||||||
@@ -32,64 +32,64 @@ abstract class Base
|
|||||||
/**
|
/**
|
||||||
* populate Cached Object with meta data from Resource
|
* populate Cached Object with meta data from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Cached $cached cached object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
abstract public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template);
|
abstract public function populate(Cached $cached, Template $_template);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* populate Cached Object with timestamp and exists from Resource
|
* populate Cached Object with timestamp and exists from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Cached $cached
|
* @param Cached $cached
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
abstract public function populateTimestamp(Smarty_Template_Cached $cached);
|
abstract public function populateTimestamp(Cached $cached);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the cached template and process header
|
* Read the cached template and process header
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Cached $cached cached object
|
||||||
* @param boolean $update flag if called because cache update
|
* @param boolean $update flag if called because cache update
|
||||||
*
|
*
|
||||||
* @return boolean true or false if the cached content does not exist
|
* @return boolean true or false if the cached content does not exist
|
||||||
*/
|
*/
|
||||||
abstract public function process(
|
abstract public function process(
|
||||||
Smarty_Internal_Template $_template,
|
Template $_template,
|
||||||
Smarty_Template_Cached $cached = null,
|
Cached $cached = null,
|
||||||
$update = false
|
$update = false
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the rendered template output to cache
|
* Write the rendered template output to cache
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
* @param string $content content to cache
|
* @param string $content content to cache
|
||||||
*
|
*
|
||||||
* @return boolean success
|
* @return boolean success
|
||||||
*/
|
*/
|
||||||
abstract public function storeCachedContent(Smarty_Internal_Template $_template, $content);
|
abstract public function storeCachedContent(Template $_template, $content);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read cached template from cache
|
* Read cached template from cache
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return string content
|
* @return string content
|
||||||
*/
|
*/
|
||||||
abstract public function retrieveCachedContent(Smarty_Internal_Template $_template);
|
abstract public function retrieveCachedContent(Template $_template);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return cached content
|
* Return cached content
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return null|string
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
public function getCachedContent(Smarty_Internal_Template $_template)
|
public function getCachedContent(Template $_template)
|
||||||
{
|
{
|
||||||
if ($_template->cached->handler->process($_template)) {
|
if ($_template->cached->handler->process($_template)) {
|
||||||
ob_start();
|
ob_start();
|
||||||
@@ -125,11 +125,11 @@ abstract class Base
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Smarty $smarty
|
* @param Smarty $smarty
|
||||||
* @param Smarty_Template_Cached $cached
|
* @param Cached $cached
|
||||||
*
|
*
|
||||||
* @return bool|null
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function locked(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function locked(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
// theoretically locking_timeout should be checked against time_limit (max_execution_time)
|
// theoretically locking_timeout should be checked against time_limit (max_execution_time)
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
@@ -149,11 +149,11 @@ abstract class Base
|
|||||||
* Check is cache is locked for this template
|
* Check is cache is locked for this template
|
||||||
*
|
*
|
||||||
* @param Smarty $smarty
|
* @param Smarty $smarty
|
||||||
* @param Smarty_Template_Cached $cached
|
* @param Cached $cached
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function hasLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
// check if lock exists
|
// check if lock exists
|
||||||
return false;
|
return false;
|
||||||
@@ -163,11 +163,11 @@ abstract class Base
|
|||||||
* Lock cache for this template
|
* Lock cache for this template
|
||||||
*
|
*
|
||||||
* @param Smarty $smarty
|
* @param Smarty $smarty
|
||||||
* @param Smarty_Template_Cached $cached
|
* @param Cached $cached
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function acquireLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
// create lock
|
// create lock
|
||||||
return true;
|
return true;
|
||||||
@@ -177,11 +177,11 @@ abstract class Base
|
|||||||
* Unlock cache for this template
|
* Unlock cache for this template
|
||||||
*
|
*
|
||||||
* @param Smarty $smarty
|
* @param Smarty $smarty
|
||||||
* @param Smarty_Template_Cached $cached
|
* @param Cached $cached
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function releaseLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
// release lock
|
// release lock
|
||||||
return true;
|
return true;
|
||||||
|
@@ -9,7 +9,7 @@ namespace Smarty\Cacheresource;
|
|||||||
* @subpackage Cacher
|
* @subpackage Cacher
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache Handler API
|
* Cache Handler API
|
||||||
@@ -80,12 +80,12 @@ abstract class Custom extends Base
|
|||||||
/**
|
/**
|
||||||
* populate Cached Object with metadata from Resource
|
* populate Cached Object with metadata from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param \Smarty\Template\Cached $cached cached object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
|
public function populate(\Smarty\Template\Cached $cached, Template $_template)
|
||||||
{
|
{
|
||||||
$_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null;
|
$_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null;
|
||||||
$_compile_id = isset($cached->compile_id) ? preg_replace('![^\w]+!', '_', $cached->compile_id) : null;
|
$_compile_id = isset($cached->compile_id) ? preg_replace('![^\w]+!', '_', $cached->compile_id) : null;
|
||||||
@@ -100,11 +100,11 @@ abstract class Custom extends Base
|
|||||||
/**
|
/**
|
||||||
* populate Cached Object with timestamp and exists from Resource
|
* populate Cached Object with timestamp and exists from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Cached $cached
|
* @param \Smarty\Template\Cached $cached
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function populateTimestamp(Smarty_Template_Cached $cached)
|
public function populateTimestamp(\Smarty\Template\Cached $cached)
|
||||||
{
|
{
|
||||||
$mtime =
|
$mtime =
|
||||||
$this->fetchTimestamp($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id);
|
$this->fetchTimestamp($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id);
|
||||||
@@ -129,16 +129,16 @@ abstract class Custom extends Base
|
|||||||
/**
|
/**
|
||||||
* Read the cached template and process the header
|
* Read the cached template and process the header
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
* @param \Smarty\Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Smarty_Template_Cached $cached cached object
|
||||||
* @param boolean $update flag if called because cache update
|
* @param boolean $update flag if called because cache update
|
||||||
*
|
*
|
||||||
* @return boolean true or false if the cached content does not exist
|
* @return boolean true or false if the cached content does not exist
|
||||||
*/
|
*/
|
||||||
public function process(
|
public function process(
|
||||||
Smarty_Internal_Template $_smarty_tpl,
|
Template $_smarty_tpl,
|
||||||
Smarty_Template_Cached $cached = null,
|
Smarty_Template_Cached $cached = null,
|
||||||
$update = false
|
$update = false
|
||||||
) {
|
) {
|
||||||
if (!$cached) {
|
if (!$cached) {
|
||||||
$cached = $_smarty_tpl->cached;
|
$cached = $_smarty_tpl->cached;
|
||||||
@@ -166,12 +166,12 @@ abstract class Custom extends Base
|
|||||||
/**
|
/**
|
||||||
* Write the rendered template output to cache
|
* Write the rendered template output to cache
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
* @param string $content content to cache
|
* @param string $content content to cache
|
||||||
*
|
*
|
||||||
* @return boolean success
|
* @return boolean success
|
||||||
*/
|
*/
|
||||||
public function storeCachedContent(Smarty_Internal_Template $_template, $content)
|
public function storeCachedContent(Template $_template, $content)
|
||||||
{
|
{
|
||||||
return $this->save(
|
return $this->save(
|
||||||
$_template->cached->filepath,
|
$_template->cached->filepath,
|
||||||
@@ -186,11 +186,11 @@ abstract class Custom extends Base
|
|||||||
/**
|
/**
|
||||||
* Read cached template from cache
|
* Read cached template from cache
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return string|boolean content
|
* @return string|boolean content
|
||||||
*/
|
*/
|
||||||
public function retrieveCachedContent(Smarty_Internal_Template $_template)
|
public function retrieveCachedContent(Template $_template)
|
||||||
{
|
{
|
||||||
$content = $_template->cached->content ?: null;
|
$content = $_template->cached->content ?: null;
|
||||||
if ($content === null) {
|
if ($content === null) {
|
||||||
|
@@ -3,8 +3,8 @@
|
|||||||
namespace Smarty\Cacheresource;
|
namespace Smarty\Cacheresource;
|
||||||
|
|
||||||
use Smarty\Smarty;
|
use Smarty\Smarty;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use Smarty_Template_Cached;
|
use Smarty\Template\Cached;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin CacheResource File
|
* Smarty Internal Plugin CacheResource File
|
||||||
@@ -27,12 +27,12 @@ class File extends Base
|
|||||||
/**
|
/**
|
||||||
* populate Cached Object with metadata from Resource
|
* populate Cached Object with metadata from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Cached $cached cached object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
|
public function populate(Cached $cached, Template $_template)
|
||||||
{
|
{
|
||||||
$source = &$_template->source;
|
$source = &$_template->source;
|
||||||
$smarty = &$_template->smarty;
|
$smarty = &$_template->smarty;
|
||||||
@@ -80,11 +80,11 @@ class File extends Base
|
|||||||
/**
|
/**
|
||||||
* populate Cached Object with timestamp and exists from Resource
|
* populate Cached Object with timestamp and exists from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Cached $cached cached object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function populateTimestamp(Smarty_Template_Cached $cached)
|
public function populateTimestamp(Cached $cached)
|
||||||
{
|
{
|
||||||
$cached->timestamp = $cached->exists = is_file($cached->filepath);
|
$cached->timestamp = $cached->exists = is_file($cached->filepath);
|
||||||
if ($cached->exists) {
|
if ($cached->exists) {
|
||||||
@@ -95,16 +95,16 @@ class File extends Base
|
|||||||
/**
|
/**
|
||||||
* Read the cached template and process its header
|
* Read the cached template and process its header
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
* @param Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||||
* @param Smarty_Template_Cached|null $cached cached object
|
* @param Cached|null $cached cached object
|
||||||
* @param bool $update flag if called because cache update
|
* @param bool $update flag if called because cache update
|
||||||
*
|
*
|
||||||
* @return boolean true or false if the cached content does not exist
|
* @return boolean true or false if the cached content does not exist
|
||||||
*/
|
*/
|
||||||
public function process(
|
public function process(
|
||||||
Smarty_Internal_Template $_smarty_tpl,
|
Template $_smarty_tpl,
|
||||||
Smarty_Template_Cached $cached = null,
|
Cached $cached = null,
|
||||||
$update = false
|
$update = false
|
||||||
) {
|
) {
|
||||||
$_smarty_tpl->cached->valid = false;
|
$_smarty_tpl->cached->valid = false;
|
||||||
if ($update && defined('HHVM_VERSION')) {
|
if ($update && defined('HHVM_VERSION')) {
|
||||||
@@ -118,13 +118,13 @@ class File extends Base
|
|||||||
/**
|
/**
|
||||||
* Write the rendered template output to cache
|
* Write the rendered template output to cache
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
* @param string $content content to cache
|
* @param string $content content to cache
|
||||||
*
|
*
|
||||||
* @return bool success
|
* @return bool success
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function storeCachedContent(Smarty_Internal_Template $_template, $content)
|
public function storeCachedContent(Template $_template, $content)
|
||||||
{
|
{
|
||||||
if ($_template->smarty->writeFile($_template->cached->filepath, $content) === true) {
|
if ($_template->smarty->writeFile($_template->cached->filepath, $content) === true) {
|
||||||
if (function_exists('opcache_invalidate')
|
if (function_exists('opcache_invalidate')
|
||||||
@@ -147,11 +147,11 @@ class File extends Base
|
|||||||
/**
|
/**
|
||||||
* Read cached template from cache
|
* Read cached template from cache
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return string content
|
* @return string content
|
||||||
*/
|
*/
|
||||||
public function retrieveCachedContent(Smarty_Internal_Template $_template)
|
public function retrieveCachedContent(Template $_template)
|
||||||
{
|
{
|
||||||
if (is_file($_template->cached->filepath)) {
|
if (is_file($_template->cached->filepath)) {
|
||||||
return file_get_contents($_template->cached->filepath);
|
return file_get_contents($_template->cached->filepath);
|
||||||
@@ -298,11 +298,11 @@ class File extends Base
|
|||||||
* Check is cache is locked for this template
|
* Check is cache is locked for this template
|
||||||
*
|
*
|
||||||
* @param Smarty $smarty Smarty object
|
* @param Smarty $smarty Smarty object
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Cached $cached cached object
|
||||||
*
|
*
|
||||||
* @return boolean true or false if cache is locked
|
* @return boolean true or false if cache is locked
|
||||||
*/
|
*/
|
||||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function hasLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
clearstatcache(true, $cached->lock_id ?? '');
|
clearstatcache(true, $cached->lock_id ?? '');
|
||||||
if (null !== $cached->lock_id && is_file($cached->lock_id)) {
|
if (null !== $cached->lock_id && is_file($cached->lock_id)) {
|
||||||
@@ -317,11 +317,11 @@ class File extends Base
|
|||||||
* Lock cache for this template
|
* Lock cache for this template
|
||||||
*
|
*
|
||||||
* @param Smarty $smarty Smarty object
|
* @param Smarty $smarty Smarty object
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Cached $cached cached object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function acquireLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
$cached->is_locked = true;
|
$cached->is_locked = true;
|
||||||
touch($cached->lock_id);
|
touch($cached->lock_id);
|
||||||
@@ -331,11 +331,11 @@ class File extends Base
|
|||||||
* Unlock cache for this template
|
* Unlock cache for this template
|
||||||
*
|
*
|
||||||
* @param Smarty $smarty Smarty object
|
* @param Smarty $smarty Smarty object
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Cached $cached cached object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function releaseLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
$cached->is_locked = false;
|
$cached->is_locked = false;
|
||||||
@unlink($cached->lock_id);
|
@unlink($cached->lock_id);
|
||||||
|
@@ -3,8 +3,8 @@
|
|||||||
namespace Smarty\Cacheresource;
|
namespace Smarty\Cacheresource;
|
||||||
|
|
||||||
use Smarty\Smarty;
|
use Smarty\Smarty;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use Smarty_Template_Cached;
|
use Smarty\Template\Cached;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin
|
* Smarty Internal Plugin
|
||||||
@@ -54,12 +54,12 @@ abstract class KeyValueStore extends Base
|
|||||||
/**
|
/**
|
||||||
* populate Cached Object with meta data from Resource
|
* populate Cached Object with meta data from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Cached $cached cached object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
|
public function populate(Cached $cached, Template $_template)
|
||||||
{
|
{
|
||||||
$cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' .
|
$cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' .
|
||||||
$this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
|
$this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
|
||||||
@@ -69,11 +69,11 @@ abstract class KeyValueStore extends Base
|
|||||||
/**
|
/**
|
||||||
* populate Cached Object with timestamp and exists from Resource
|
* populate Cached Object with timestamp and exists from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Cached $cached cached object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function populateTimestamp(Smarty_Template_Cached $cached)
|
public function populateTimestamp(Cached $cached)
|
||||||
{
|
{
|
||||||
if (!$this->fetch(
|
if (!$this->fetch(
|
||||||
$cached->filepath,
|
$cached->filepath,
|
||||||
@@ -95,16 +95,16 @@ abstract class KeyValueStore extends Base
|
|||||||
/**
|
/**
|
||||||
* Read the cached template and process the header
|
* Read the cached template and process the header
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
* @param Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||||
* @param Smarty_Template_Cached|null $cached cached object
|
* @param Cached|null $cached cached object
|
||||||
* @param boolean $update flag if called because cache update
|
* @param boolean $update flag if called because cache update
|
||||||
*
|
*
|
||||||
* @return boolean true or false if the cached content does not exist
|
* @return boolean true or false if the cached content does not exist
|
||||||
*/
|
*/
|
||||||
public function process(
|
public function process(
|
||||||
Smarty_Internal_Template $_smarty_tpl,
|
Template $_smarty_tpl,
|
||||||
Smarty_Template_Cached $cached = null,
|
Cached $cached = null,
|
||||||
$update = false
|
$update = false
|
||||||
) {
|
) {
|
||||||
if (!$cached) {
|
if (!$cached) {
|
||||||
$cached = $_smarty_tpl->cached;
|
$cached = $_smarty_tpl->cached;
|
||||||
@@ -135,12 +135,12 @@ abstract class KeyValueStore extends Base
|
|||||||
/**
|
/**
|
||||||
* Write the rendered template output to cache
|
* Write the rendered template output to cache
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
* @param string $content content to cache
|
* @param string $content content to cache
|
||||||
*
|
*
|
||||||
* @return boolean success
|
* @return boolean success
|
||||||
*/
|
*/
|
||||||
public function storeCachedContent(Smarty_Internal_Template $_template, $content)
|
public function storeCachedContent(Template $_template, $content)
|
||||||
{
|
{
|
||||||
$this->addMetaTimestamp($content);
|
$this->addMetaTimestamp($content);
|
||||||
return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime);
|
return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime);
|
||||||
@@ -149,11 +149,11 @@ abstract class KeyValueStore extends Base
|
|||||||
/**
|
/**
|
||||||
* Read cached template from cache
|
* Read cached template from cache
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return string|false content
|
* @return string|false content
|
||||||
*/
|
*/
|
||||||
public function retrieveCachedContent(Smarty_Internal_Template $_template)
|
public function retrieveCachedContent(Template $_template)
|
||||||
{
|
{
|
||||||
$content = $_template->cached->content ? $_template->cached->content : null;
|
$content = $_template->cached->content ? $_template->cached->content : null;
|
||||||
$timestamp = null;
|
$timestamp = null;
|
||||||
@@ -460,11 +460,11 @@ abstract class KeyValueStore extends Base
|
|||||||
* Check is cache is locked for this template
|
* Check is cache is locked for this template
|
||||||
*
|
*
|
||||||
* @param Smarty $smarty Smarty object
|
* @param Smarty $smarty Smarty object
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Cached $cached cached object
|
||||||
*
|
*
|
||||||
* @return boolean true or false if cache is locked
|
* @return boolean true or false if cache is locked
|
||||||
*/
|
*/
|
||||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function hasLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
$key = 'LOCK#' . $cached->filepath;
|
$key = 'LOCK#' . $cached->filepath;
|
||||||
$data = $this->read(array($key));
|
$data = $this->read(array($key));
|
||||||
@@ -475,11 +475,11 @@ abstract class KeyValueStore extends Base
|
|||||||
* Lock cache for this template
|
* Lock cache for this template
|
||||||
*
|
*
|
||||||
* @param Smarty $smarty Smarty object
|
* @param Smarty $smarty Smarty object
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Cached $cached cached object
|
||||||
*
|
*
|
||||||
* @return bool|void
|
* @return bool|void
|
||||||
*/
|
*/
|
||||||
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function acquireLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
$cached->is_locked = true;
|
$cached->is_locked = true;
|
||||||
$key = 'LOCK#' . $cached->filepath;
|
$key = 'LOCK#' . $cached->filepath;
|
||||||
@@ -490,11 +490,11 @@ abstract class KeyValueStore extends Base
|
|||||||
* Unlock cache for this template
|
* Unlock cache for this template
|
||||||
*
|
*
|
||||||
* @param Smarty $smarty Smarty object
|
* @param Smarty $smarty Smarty object
|
||||||
* @param Smarty_Template_Cached $cached cached object
|
* @param Cached $cached cached object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function releaseLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
$cached->is_locked = false;
|
$cached->is_locked = false;
|
||||||
$key = 'LOCK#' . $cached->filepath;
|
$key = 'LOCK#' . $cached->filepath;
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
namespace Smarty\Compile;
|
namespace Smarty\Compile;
|
||||||
|
|
||||||
use Smarty_Internal_Template;
|
|
||||||
use Smarty\Compiler\Template;
|
use Smarty\Compiler\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,11 +143,11 @@ class ExtendsTag extends Inheritance {
|
|||||||
/**
|
/**
|
||||||
* Create source code for {extends} from source components array
|
* Create source code for {extends} from source components array
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function extendsSourceArrayCode(Smarty_Internal_Template $template) {
|
public static function extendsSourceArrayCode(\Smarty\Template $template) {
|
||||||
$resources = [];
|
$resources = [];
|
||||||
foreach ($template->source->components as $source) {
|
foreach ($template->source->components as $source) {
|
||||||
$resources[] = $source->resource;
|
$resources[] = $source->resource;
|
||||||
|
@@ -10,9 +10,6 @@
|
|||||||
|
|
||||||
namespace Smarty\Compile;
|
namespace Smarty\Compile;
|
||||||
|
|
||||||
use Smarty_Internal_Compile_Foreach;
|
|
||||||
use Smarty\Compiler\Template;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin Compile Foreachclose Class
|
* Smarty Internal Plugin Compile Foreachclose Class
|
||||||
*
|
*
|
||||||
@@ -44,7 +41,7 @@ class ForeachClose extends Base {
|
|||||||
$output .= "{$itemVar} = {$local}saved;\n";
|
$output .= "{$itemVar} = {$local}saved;\n";
|
||||||
}
|
}
|
||||||
$output .= "}\n";
|
$output .= "}\n";
|
||||||
/* @var \Smarty\Compile\Smarty_Internal_Compile_Foreach $foreachCompiler */
|
/* @var \Smarty\Compile\ForeachTag $foreachCompiler */
|
||||||
$foreachCompiler = $compiler->getTagCompiler('foreach');
|
$foreachCompiler = $compiler->getTagCompiler('foreach');
|
||||||
$output .= $foreachCompiler->compileRestore(1);
|
$output .= $foreachCompiler->compileRestore(1);
|
||||||
$output .= "?>";
|
$output .= "?>";
|
||||||
|
@@ -12,9 +12,8 @@ namespace Smarty\Compile;
|
|||||||
|
|
||||||
use Smarty\Compiler\Template;
|
use Smarty\Compiler\Template;
|
||||||
use Smarty\Smarty;
|
use Smarty\Smarty;
|
||||||
use Smarty_Internal_Template;
|
|
||||||
use Smarty\Compile\Base;
|
use Smarty\Compile\Base;
|
||||||
use Smarty_Template_Compiled;
|
use Smarty\Template\Compiled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin Compile Include Class
|
* Smarty Internal Plugin Compile Include Class
|
||||||
@@ -207,7 +206,7 @@ class IncludeTag extends Base {
|
|||||||
// we must observe different compile_id and caching
|
// we must observe different compile_id and caching
|
||||||
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
|
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
|
||||||
$compiler->smarty->allow_ambiguous_resources = true;
|
$compiler->smarty->allow_ambiguous_resources = true;
|
||||||
/* @var Smarty_Internal_Template $tpl */
|
/* @var \Smarty\Template $tpl */
|
||||||
$tpl = new $compiler->smarty->template_class(
|
$tpl = new $compiler->smarty->template_class(
|
||||||
trim($fullResourceName, '"\''),
|
trim($fullResourceName, '"\''),
|
||||||
$compiler->smarty,
|
$compiler->smarty,
|
||||||
@@ -288,7 +287,7 @@ class IncludeTag extends Base {
|
|||||||
* Compile inline sub template
|
* Compile inline sub template
|
||||||
*
|
*
|
||||||
* @param \Smarty\Compiler\Template $compiler
|
* @param \Smarty\Compiler\Template $compiler
|
||||||
* @param \Smarty_Internal_Template $tpl
|
* @param \Smarty\Template $tpl
|
||||||
* @param string $t_hash
|
* @param string $t_hash
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -296,9 +295,9 @@ class IncludeTag extends Base {
|
|||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
private function compileInlineTemplate(
|
private function compileInlineTemplate(
|
||||||
Template $compiler,
|
Template $compiler,
|
||||||
Smarty_Internal_Template $tpl,
|
\Smarty\Template $tpl,
|
||||||
$t_hash
|
$t_hash
|
||||||
) {
|
) {
|
||||||
$uid = $tpl->source->type . $tpl->source->uid;
|
$uid = $tpl->source->type . $tpl->source->uid;
|
||||||
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
|
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
|
||||||
@@ -306,7 +305,7 @@ class IncludeTag extends Base {
|
|||||||
if (isset($compiler->template->inheritance)) {
|
if (isset($compiler->template->inheritance)) {
|
||||||
$tpl->inheritance = clone $compiler->template->inheritance;
|
$tpl->inheritance = clone $compiler->template->inheritance;
|
||||||
}
|
}
|
||||||
$tpl->compiled = new Smarty_Template_Compiled();
|
$tpl->compiled = new Compiled();
|
||||||
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
|
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
|
||||||
$tpl->loadCompiler();
|
$tpl->loadCompiler();
|
||||||
// save unique function name
|
// save unique function name
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Smarty\Template;
|
namespace Smarty\Compiler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Extension
|
* Smarty Internal Extension
|
||||||
@@ -13,10 +13,19 @@ namespace Smarty\Template;
|
|||||||
*/
|
*/
|
||||||
class CodeFrame
|
class CodeFrame
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
|
/**
|
||||||
|
* @var \Smarty\Template
|
||||||
|
*/
|
||||||
|
private $_template;
|
||||||
|
|
||||||
|
public function __construct(\Smarty\Template $_template) {
|
||||||
|
$this->_template = $_template;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Create code frame for compiled and cached templates
|
* Create code frame for compiled and cached templates
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $_template
|
|
||||||
* @param string $content optional template content
|
* @param string $content optional template content
|
||||||
* @param string $functions compiled template function and block code
|
* @param string $functions compiled template function and block code
|
||||||
* @param bool $cache flag for cache file
|
* @param bool $cache flag for cache file
|
||||||
@@ -25,7 +34,6 @@ class CodeFrame
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function create(
|
public function create(
|
||||||
\Smarty_Internal_Template $_template,
|
|
||||||
$content = '',
|
$content = '',
|
||||||
$functions = '',
|
$functions = '',
|
||||||
$cache = false,
|
$cache = false,
|
||||||
@@ -35,19 +43,19 @@ class CodeFrame
|
|||||||
$properties[ 'version' ] = \Smarty::SMARTY_VERSION;
|
$properties[ 'version' ] = \Smarty::SMARTY_VERSION;
|
||||||
$properties[ 'unifunc' ] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
$properties[ 'unifunc' ] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
||||||
if (!$cache) {
|
if (!$cache) {
|
||||||
$properties[ 'has_nocache_code' ] = $_template->compiled->has_nocache_code;
|
$properties[ 'has_nocache_code' ] = $this->_template->compiled->has_nocache_code;
|
||||||
$properties[ 'file_dependency' ] = $_template->compiled->file_dependency;
|
$properties[ 'file_dependency' ] = $this->_template->compiled->file_dependency;
|
||||||
$properties[ 'includes' ] = $_template->compiled->includes;
|
$properties[ 'includes' ] = $this->_template->compiled->includes;
|
||||||
} else {
|
} else {
|
||||||
$properties[ 'has_nocache_code' ] = $_template->cached->has_nocache_code;
|
$properties[ 'has_nocache_code' ] = $this->_template->cached->has_nocache_code;
|
||||||
$properties[ 'file_dependency' ] = $_template->cached->file_dependency;
|
$properties[ 'file_dependency' ] = $this->_template->cached->file_dependency;
|
||||||
$properties[ 'cache_lifetime' ] = $_template->cache_lifetime;
|
$properties[ 'cache_lifetime' ] = $this->_template->cache_lifetime;
|
||||||
}
|
}
|
||||||
$output = sprintf(
|
$output = sprintf(
|
||||||
"<?php\n/* Smarty version %s, created on %s\n from '%s' */\n\n",
|
"<?php\n/* Smarty version %s, created on %s\n from '%s' */\n\n",
|
||||||
$properties[ 'version' ],
|
$properties[ 'version' ],
|
||||||
date("Y-m-d H:i:s"),
|
date("Y-m-d H:i:s"),
|
||||||
str_replace('*/', '* /', $_template->source->filepath)
|
str_replace('*/', '* /', $this->_template->source->filepath)
|
||||||
);
|
);
|
||||||
$output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
|
$output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
|
||||||
$dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' .
|
$dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' .
|
||||||
@@ -55,13 +63,13 @@ class CodeFrame
|
|||||||
$output .= "if ({$dec}) {\n";
|
$output .= "if ({$dec}) {\n";
|
||||||
$output .= "function {$properties['unifunc']} (Smarty_Internal_Template \$_smarty_tpl) {\n";
|
$output .= "function {$properties['unifunc']} (Smarty_Internal_Template \$_smarty_tpl) {\n";
|
||||||
if (!$cache && !empty($compiler->tpl_function)) {
|
if (!$cache && !empty($compiler->tpl_function)) {
|
||||||
$output .= '$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions($_smarty_tpl, ';
|
$output .= '$_smarty_tpl->smarty->getRuntime(\'TplFunction\')->registerTplFunctions($_smarty_tpl, ';
|
||||||
$output .= var_export($compiler->tpl_function, true);
|
$output .= var_export($compiler->tpl_function, true);
|
||||||
$output .= ");\n";
|
$output .= ");\n";
|
||||||
}
|
}
|
||||||
if ($cache && isset($_template->smarty->ext->_tplFunction)) {
|
if ($cache && $this->_template->smarty->hasRuntime('TplFunction')) {
|
||||||
$output .= "\$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " .
|
$output .= "\$_smarty_tpl->smarty->getRuntime('TplFunction')->registerTplFunctions(\$_smarty_tpl, " .
|
||||||
var_export($_template->smarty->ext->_tplFunction->getTplFunction($_template), true) . ");\n";
|
var_export($this->_template->smarty->getRuntime('TplFunction')->getTplFunction($this->_template), true) . ");\n";
|
||||||
}
|
}
|
||||||
$output .= "?>";
|
$output .= "?>";
|
||||||
$output .= $content;
|
$output .= $content;
|
||||||
|
@@ -13,7 +13,7 @@ namespace Smarty\Compiler;
|
|||||||
use Smarty;
|
use Smarty;
|
||||||
use Smarty_Internal_ConfigFileLexer;
|
use Smarty_Internal_ConfigFileLexer;
|
||||||
use Smarty_Internal_ConfigFileParser;
|
use Smarty_Internal_ConfigFileParser;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use SmartyCompilerException;
|
use SmartyCompilerException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +62,7 @@ class ConfigFile {
|
|||||||
/**
|
/**
|
||||||
* Smarty object
|
* Smarty object
|
||||||
*
|
*
|
||||||
* @var Smarty_Internal_Template object
|
* @var Template object
|
||||||
*/
|
*/
|
||||||
public $template;
|
public $template;
|
||||||
|
|
||||||
@@ -93,12 +93,12 @@ class ConfigFile {
|
|||||||
/**
|
/**
|
||||||
* Method to compile Smarty config source.
|
* Method to compile Smarty config source.
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $template
|
* @param Template $template
|
||||||
*
|
*
|
||||||
* @return bool true if compiling succeeded, false if it failed
|
* @return bool true if compiling succeeded, false if it failed
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function compileTemplate(Smarty_Internal_Template $template) {
|
public function compileTemplate(Template $template) {
|
||||||
$this->template = $template;
|
$this->template = $template;
|
||||||
$this->template->compiled->file_dependency[$this->template->source->uid] =
|
$this->template->compiled->file_dependency[$this->template->source->uid] =
|
||||||
[
|
[
|
||||||
@@ -161,9 +161,9 @@ class ConfigFile {
|
|||||||
date("Y-m-d H:i:s"),
|
date("Y-m-d H:i:s"),
|
||||||
str_replace('*/', '* /', $this->template->source->filepath)
|
str_replace('*/', '* /', $this->template->source->filepath)
|
||||||
);
|
);
|
||||||
$code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
|
$code = '<?php $_smarty_tpl->_loadConfigVars(' .
|
||||||
var_export($this->config_data, true) . '); ?>';
|
var_export($this->config_data, true) . '); ?>';
|
||||||
return $template_header . $this->createCodeFrame($code);
|
return $template_header . $this->template->createCodeFrame($code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -386,7 +386,7 @@ class Template {
|
|||||||
/**
|
/**
|
||||||
* Compile template source and run optional post filter
|
* Compile template source and run optional post filter
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
* @param null|bool $nocache flag if template must be compiled in nocache mode
|
* @param null|bool $nocache flag if template must be compiled in nocache mode
|
||||||
* @param \Smarty\Compiler\Template $parent_compiler
|
* @param \Smarty\Compiler\Template $parent_compiler
|
||||||
*
|
*
|
||||||
@@ -473,7 +473,7 @@ class Template {
|
|||||||
public function postFilter($code) {
|
public function postFilter($code) {
|
||||||
// run post filter if on code
|
// run post filter if on code
|
||||||
if (!empty($code) && isset($this->smarty->registered_filters['post'])) {
|
if (!empty($code) && isset($this->smarty->registered_filters['post'])) {
|
||||||
return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template);
|
return $this->smarty->runFilter('post', $code, $this->template);
|
||||||
} else {
|
} else {
|
||||||
return $code;
|
return $code;
|
||||||
}
|
}
|
||||||
@@ -490,7 +490,7 @@ class Template {
|
|||||||
public function preFilter($_content) {
|
public function preFilter($_content) {
|
||||||
// run pre filter if required
|
// run pre filter if required
|
||||||
if ($_content !== '' && isset($this->smarty->registered_filters['pre'])) {
|
if ($_content !== '' && isset($this->smarty->registered_filters['pre'])) {
|
||||||
return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template);
|
return $this->smarty->runFilter('pre', $_content, $this->template);
|
||||||
} else {
|
} else {
|
||||||
return $_content;
|
return $_content;
|
||||||
}
|
}
|
||||||
@@ -1375,8 +1375,8 @@ class Template {
|
|||||||
// compile the smarty tag (required compile classes to compile the tag are auto loaded)
|
// compile the smarty tag (required compile classes to compile the tag are auto loaded)
|
||||||
if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
|
if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
|
||||||
if (isset($this->parent_compiler->tpl_function[$tag])
|
if (isset($this->parent_compiler->tpl_function[$tag])
|
||||||
|| (isset($this->template->smarty->ext->_tplFunction)
|
|| ($this->template->smarty->hasRuntime('TplFunction')
|
||||||
&& $this->template->smarty->ext->_tplFunction->getTplFunction($this->template, $tag) !== false)
|
&& $this->template->smarty->getRuntime('TplFunction')->getTplFunction($this->template, $tag) !== false)
|
||||||
) {
|
) {
|
||||||
// template defined by {template} tag
|
// template defined by {template} tag
|
||||||
$args['_attr']['name'] = "'{$tag}'";
|
$args['_attr']['name'] = "'{$tag}'";
|
||||||
|
10
src/Data.php
10
src/Data.php
@@ -36,7 +36,7 @@ abstract class Data
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $template_class = 'Smarty_Internal_Template';
|
public $template_class = 'Smarty\Template';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* template variables
|
* template variables
|
||||||
@@ -48,7 +48,7 @@ abstract class Data
|
|||||||
/**
|
/**
|
||||||
* parent template (if any)
|
* parent template (if any)
|
||||||
*
|
*
|
||||||
* @var Smarty|Smarty_Internal_Template|Smarty_Data
|
* @var Smarty|Template|Smarty_Data
|
||||||
*/
|
*/
|
||||||
public $parent = null;
|
public $parent = null;
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ abstract class Data
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @var Smarty_Internal_Template $this
|
* @var Template $this
|
||||||
*/
|
*/
|
||||||
$this->_assignInScope($tpl_var, $value, $nocache);
|
$this->_assignInScope($tpl_var, $value, $nocache);
|
||||||
} else {
|
} else {
|
||||||
@@ -461,8 +461,8 @@ abstract class Data
|
|||||||
{
|
{
|
||||||
/* @var \Smarty $smarty */
|
/* @var \Smarty $smarty */
|
||||||
$smarty = $this->_getSmartyObj();
|
$smarty = $this->_getSmartyObj();
|
||||||
/* @var \Smarty_Internal_Template $confObj */
|
/* @var \Smarty\Template $confObj */
|
||||||
$confObj = new Smarty_Internal_Template($config_file, $smarty, $this, null, null, null, null, true);
|
$confObj = new Template($config_file, $smarty, $this, null, null, null, null, true);
|
||||||
$confObj->caching = Smarty::CACHING_OFF;
|
$confObj->caching = Smarty::CACHING_OFF;
|
||||||
$confObj->source->config_sections = $sections;
|
$confObj->source->config_sections = $sections;
|
||||||
$confObj->source->scope = $scope;
|
$confObj->source->scope = $scope;
|
||||||
|
@@ -50,10 +50,10 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Start logging template
|
* Start logging template
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template template
|
* @param \Smarty\Template $template template
|
||||||
* @param null $mode true: display false: fetch null: subtemplate
|
* @param null $mode true: display false: fetch null: subtemplate
|
||||||
*/
|
*/
|
||||||
public function start_template(\Smarty_Internal_Template $template, $mode = null)
|
public function start_template(\Smarty\Template $template, $mode = null)
|
||||||
{
|
{
|
||||||
if (isset($mode) && !$template->_isSubTpl()) {
|
if (isset($mode) && !$template->_isSubTpl()) {
|
||||||
$this->index++;
|
$this->index++;
|
||||||
@@ -67,9 +67,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* End logging of cache time
|
* End logging of cache time
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template cached template
|
* @param \Smarty\Template $template cached template
|
||||||
*/
|
*/
|
||||||
public function end_template(\Smarty_Internal_Template $template)
|
public function end_template(\Smarty\Template $template)
|
||||||
{
|
{
|
||||||
$key = $this->get_key($template);
|
$key = $this->get_key($template);
|
||||||
$this->template_data[ $this->index ][ $key ][ 'total_time' ] +=
|
$this->template_data[ $this->index ][ $key ][ 'total_time' ] +=
|
||||||
@@ -79,9 +79,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Start logging of compile time
|
* Start logging of compile time
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
*/
|
*/
|
||||||
public function start_compile(\Smarty_Internal_Template $template)
|
public function start_compile(\Smarty\Template $template)
|
||||||
{
|
{
|
||||||
static $_is_stringy = array('string' => true, 'eval' => true);
|
static $_is_stringy = array('string' => true, 'eval' => true);
|
||||||
if (!empty($template->compiler->trace_uid)) {
|
if (!empty($template->compiler->trace_uid)) {
|
||||||
@@ -101,9 +101,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* End logging of compile time
|
* End logging of compile time
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
*/
|
*/
|
||||||
public function end_compile(\Smarty_Internal_Template $template)
|
public function end_compile(\Smarty\Template $template)
|
||||||
{
|
{
|
||||||
if (!empty($template->compiler->trace_uid)) {
|
if (!empty($template->compiler->trace_uid)) {
|
||||||
$key = $template->compiler->trace_uid;
|
$key = $template->compiler->trace_uid;
|
||||||
@@ -120,9 +120,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Start logging of render time
|
* Start logging of render time
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
*/
|
*/
|
||||||
public function start_render(\Smarty_Internal_Template $template)
|
public function start_render(\Smarty\Template $template)
|
||||||
{
|
{
|
||||||
$key = $this->get_key($template);
|
$key = $this->get_key($template);
|
||||||
$this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
|
$this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
|
||||||
@@ -131,9 +131,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* End logging of compile time
|
* End logging of compile time
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
*/
|
*/
|
||||||
public function end_render(\Smarty_Internal_Template $template)
|
public function end_render(\Smarty\Template $template)
|
||||||
{
|
{
|
||||||
$key = $this->get_key($template);
|
$key = $this->get_key($template);
|
||||||
$this->template_data[ $this->index ][ $key ][ 'render_time' ] +=
|
$this->template_data[ $this->index ][ $key ][ 'render_time' ] +=
|
||||||
@@ -143,9 +143,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Start logging of cache time
|
* Start logging of cache time
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template cached template
|
* @param \Smarty\Template $template cached template
|
||||||
*/
|
*/
|
||||||
public function start_cache(\Smarty_Internal_Template $template)
|
public function start_cache(\Smarty\Template $template)
|
||||||
{
|
{
|
||||||
$key = $this->get_key($template);
|
$key = $this->get_key($template);
|
||||||
$this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
|
$this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
|
||||||
@@ -154,9 +154,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* End logging of cache time
|
* End logging of cache time
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template cached template
|
* @param \Smarty\Template $template cached template
|
||||||
*/
|
*/
|
||||||
public function end_cache(\Smarty_Internal_Template $template)
|
public function end_cache(\Smarty\Template $template)
|
||||||
{
|
{
|
||||||
$key = $this->get_key($template);
|
$key = $this->get_key($template);
|
||||||
$this->template_data[ $this->index ][ $key ][ 'cache_time' ] +=
|
$this->template_data[ $this->index ][ $key ][ 'cache_time' ] +=
|
||||||
@@ -166,9 +166,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Register template object
|
* Register template object
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template cached template
|
* @param \Smarty\Template $template cached template
|
||||||
*/
|
*/
|
||||||
public function register_template(\Smarty_Internal_Template $template)
|
public function register_template(\Smarty\Template $template)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Opens a window for the Smarty Debugging Console and display the data
|
* Opens a window for the Smarty Debugging Console and display the data
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template|\Smarty $obj object to debug
|
* @param \Smarty\Template|\Smarty $obj object to debug
|
||||||
* @param bool $full
|
* @param bool $full
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
@@ -228,7 +228,7 @@ class Debug extends Data
|
|||||||
$_config_vars = $ptr->config_vars;
|
$_config_vars = $ptr->config_vars;
|
||||||
ksort($_config_vars);
|
ksort($_config_vars);
|
||||||
$debugging = $smarty->debugging;
|
$debugging = $smarty->debugging;
|
||||||
$_template = new \Smarty_Internal_Template($debObj->debug_tpl, $debObj);
|
$_template = new \Smarty\Template($debObj->debug_tpl, $debObj);
|
||||||
if ($obj->_isTplObj()) {
|
if ($obj->_isTplObj()) {
|
||||||
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
|
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Recursively gets variables from all template/data scopes
|
* Recursively gets variables from all template/data scopes
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template|\Smarty_Data $obj object to debug
|
* @param \Smarty\Template|\Smarty_Data $obj object to debug
|
||||||
*
|
*
|
||||||
* @return \StdClass
|
* @return \StdClass
|
||||||
*/
|
*/
|
||||||
@@ -338,11 +338,11 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Return key into $template_data for template
|
* Return key into $template_data for template
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template template object
|
* @param \Smarty\Template $template template object
|
||||||
*
|
*
|
||||||
* @return string key into $template_data
|
* @return string key into $template_data
|
||||||
*/
|
*/
|
||||||
private function get_key(\Smarty_Internal_Template $template)
|
private function get_key(\Smarty\Template $template)
|
||||||
{
|
{
|
||||||
static $_is_stringy = array('string' => true, 'eval' => true);
|
static $_is_stringy = array('string' => true, 'eval' => true);
|
||||||
// calculate Uid if not already done
|
// calculate Uid if not already done
|
||||||
@@ -362,9 +362,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Ignore template
|
* Ignore template
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
*/
|
*/
|
||||||
public function ignore(\Smarty_Internal_Template $template)
|
public function ignore(\Smarty\Template $template)
|
||||||
{
|
{
|
||||||
// calculate Uid if not already done
|
// calculate Uid if not already done
|
||||||
if ($template->source->uid === '') {
|
if ($template->source->uid === '') {
|
||||||
@@ -407,12 +407,12 @@ class Debug extends Data
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $_is_stringy
|
* @param array $_is_stringy
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
* @param string $key
|
* @param string $key
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function saveTemplateData(array $_is_stringy, \Smarty_Internal_Template $template, string $key): void {
|
private function saveTemplateData(array $_is_stringy, \Smarty\Template $template, string $key): void {
|
||||||
if (isset($_is_stringy[$template->source->type])) {
|
if (isset($_is_stringy[$template->source->type])) {
|
||||||
$this->template_data[$this->index][$key]['name'] =
|
$this->template_data[$this->index][$key]['name'] =
|
||||||
'\'' . substr($template->source->name, 0, 25) . '...\'';
|
'\'' . substr($template->source->name, 0, 25) . '...\'';
|
||||||
|
@@ -138,7 +138,7 @@ abstract class BasePlugin
|
|||||||
/**
|
/**
|
||||||
* modify template_resource according to resource handlers specifications
|
* modify template_resource according to resource handlers specifications
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template|\Smarty $obj Smarty instance
|
* @param \Smarty\Template|\Smarty $obj Smarty instance
|
||||||
* @param string $template_resource template_resource to extract resource handler and
|
* @param string $template_resource template_resource to extract resource handler and
|
||||||
* name of
|
* name of
|
||||||
*
|
*
|
||||||
@@ -166,45 +166,45 @@ abstract class BasePlugin
|
|||||||
* wrapper for backward compatibility to versions < 3.1.22
|
* wrapper for backward compatibility to versions < 3.1.22
|
||||||
* Either [$_template] or [$smarty, $template_resource] must be specified
|
* Either [$_template] or [$smarty, $template_resource] must be specified
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $_template template object
|
* @param \Smarty\Template $_template template object
|
||||||
* @param \Smarty $smarty smarty object
|
* @param \Smarty $smarty smarty object
|
||||||
* @param string $template_resource resource identifier
|
* @param string $template_resource resource identifier
|
||||||
*
|
*
|
||||||
* @return \Smarty_Template_Source Source Object
|
* @return \Smarty\Template\Source Source Object
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public static function source(
|
public static function source(
|
||||||
\Smarty_Internal_Template $_template = null,
|
\Smarty\Template $_template = null,
|
||||||
\Smarty $smarty = null,
|
\Smarty $smarty = null,
|
||||||
$template_resource = null
|
$template_resource = null
|
||||||
) {
|
) {
|
||||||
return \Smarty_Template_Source::load($_template, $smarty, $template_resource);
|
return \Smarty\Template\Source::load($_template, $smarty, $template_resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load template's source into current template object
|
* Load template's source into current template object
|
||||||
*
|
*
|
||||||
* @param \Smarty_Template_Source $source source object
|
* @param \Smarty\Template\Source $source source object
|
||||||
*
|
*
|
||||||
* @return string template source
|
* @return string template source
|
||||||
* @throws \SmartyException if source cannot be loaded
|
* @throws \SmartyException if source cannot be loaded
|
||||||
*/
|
*/
|
||||||
abstract public function getContent(\Smarty_Template_Source $source);
|
abstract public function getContent(\Smarty\Template\Source $source);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* populate Source Object with meta data from Resource
|
* populate Source Object with meta data from Resource
|
||||||
*
|
*
|
||||||
* @param \Smarty_Template_Source $source source object
|
* @param \Smarty\Template\Source $source source object
|
||||||
* @param \Smarty_Internal_Template $_template template object
|
* @param \Smarty\Template $_template template object
|
||||||
*/
|
*/
|
||||||
abstract public function populate(\Smarty_Template_Source $source, \Smarty_Internal_Template $_template = null);
|
abstract public function populate(\Smarty\Template\Source $source, \Smarty\Template $_template = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* populate Source Object with timestamp and exists from Resource
|
* populate Source Object with timestamp and exists from Resource
|
||||||
*
|
*
|
||||||
* @param \Smarty_Template_Source $source source object
|
* @param \Smarty\Template\Source $source source object
|
||||||
*/
|
*/
|
||||||
public function populateTimestamp(\Smarty_Template_Source $source)
|
public function populateTimestamp(\Smarty\Template\Source $source)
|
||||||
{
|
{
|
||||||
// intentionally left blank
|
// intentionally left blank
|
||||||
}
|
}
|
||||||
@@ -242,11 +242,11 @@ abstract class BasePlugin
|
|||||||
/**
|
/**
|
||||||
* Determine basename for compiled filename
|
* Determine basename for compiled filename
|
||||||
*
|
*
|
||||||
* @param \Smarty_Template_Source $source source object
|
* @param \Smarty\Template\Source $source source object
|
||||||
*
|
*
|
||||||
* @return string resource's basename
|
* @return string resource's basename
|
||||||
*/
|
*/
|
||||||
public function getBasename(\Smarty_Template_Source $source)
|
public function getBasename(\Smarty\Template\Source $source)
|
||||||
{
|
{
|
||||||
return basename(preg_replace('![^\w]+!', '_', $source->name));
|
return basename(preg_replace('![^\w]+!', '_', $source->name));
|
||||||
}
|
}
|
||||||
|
@@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
namespace Smarty\Resource;
|
namespace Smarty\Resource;
|
||||||
use Smarty;
|
use Smarty;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use Smarty_Template_Source;
|
use Smarty\Template\Source;
|
||||||
use SmartyException;
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,7 +20,7 @@ use SmartyException;
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage TemplateResources
|
* @subpackage TemplateResources
|
||||||
*/
|
*/
|
||||||
abstract class CustomPlugin extends Smarty\Resource\BasePlugin {
|
abstract class CustomPlugin extends BasePlugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetch template and its modification time from data source
|
* fetch template and its modification time from data source
|
||||||
@@ -47,10 +47,10 @@ abstract class CustomPlugin extends Smarty\Resource\BasePlugin {
|
|||||||
/**
|
/**
|
||||||
* populate Source Object with meta data from Resource
|
* populate Source Object with meta data from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
public function populate(Source $source, Template $_template = null) {
|
||||||
$source->filepath = $source->type . ':' . $this->generateSafeName($source->name);
|
$source->filepath = $source->type . ':' . $this->generateSafeName($source->name);
|
||||||
$source->uid = sha1($source->type . ':' . $source->name);
|
$source->uid = sha1($source->type . ':' . $source->name);
|
||||||
$mtime = $this->fetchTimestamp($source->name);
|
$mtime = $this->fetchTimestamp($source->name);
|
||||||
@@ -69,12 +69,12 @@ abstract class CustomPlugin extends Smarty\Resource\BasePlugin {
|
|||||||
/**
|
/**
|
||||||
* Load template's source into current template object
|
* Load template's source into current template object
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
*
|
*
|
||||||
* @return string template source
|
* @return string template source
|
||||||
* @throws SmartyException if source cannot be loaded
|
* @throws SmartyException if source cannot be loaded
|
||||||
*/
|
*/
|
||||||
public function getContent(Smarty_Template_Source $source) {
|
public function getContent(Source $source) {
|
||||||
$this->fetch($source->name, $content, $timestamp);
|
$this->fetch($source->name, $content, $timestamp);
|
||||||
if (isset($content)) {
|
if (isset($content)) {
|
||||||
return $content;
|
return $content;
|
||||||
@@ -85,11 +85,11 @@ abstract class CustomPlugin extends Smarty\Resource\BasePlugin {
|
|||||||
/**
|
/**
|
||||||
* Determine basename for compiled filename
|
* Determine basename for compiled filename
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
*
|
*
|
||||||
* @return string resource's basename
|
* @return string resource's basename
|
||||||
*/
|
*/
|
||||||
public function getBasename(Smarty_Template_Source $source) {
|
public function getBasename(Source $source) {
|
||||||
return basename($this->generateSafeName($source->name));
|
return basename($this->generateSafeName($source->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,12 +24,12 @@ class ExtendsPlugin extends BasePlugin
|
|||||||
/**
|
/**
|
||||||
* populate Source Object with metadata from Resource
|
* populate Source Object with metadata from Resource
|
||||||
*
|
*
|
||||||
* @param \Smarty_Template_Source $source source object
|
* @param \Smarty\Template\Source $source source object
|
||||||
* @param \Smarty_Internal_Template $_template template object
|
* @param \Smarty\Template $_template template object
|
||||||
*
|
*
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function populate(\Smarty_Template_Source $source, \Smarty_Internal_Template $_template = null)
|
public function populate(\Smarty\Template\Source $source, \Smarty\Template $_template = null)
|
||||||
{
|
{
|
||||||
$uid = '';
|
$uid = '';
|
||||||
$sources = array();
|
$sources = array();
|
||||||
@@ -37,8 +37,8 @@ class ExtendsPlugin extends BasePlugin
|
|||||||
$smarty = &$source->smarty;
|
$smarty = &$source->smarty;
|
||||||
$exists = true;
|
$exists = true;
|
||||||
foreach ($components as $component) {
|
foreach ($components as $component) {
|
||||||
/* @var \Smarty_Template_Source $_s */
|
/* @var \Smarty\Template\Source $_s */
|
||||||
$_s = \Smarty_Template_Source::load(null, $smarty, $component);
|
$_s = \Smarty\Template\Source::load(null, $smarty, $component);
|
||||||
if ($_s->type === 'php') {
|
if ($_s->type === 'php') {
|
||||||
throw new \SmartyException("Resource type {$_s->type} cannot be used with the extends resource type");
|
throw new \SmartyException("Resource type {$_s->type} cannot be used with the extends resource type");
|
||||||
}
|
}
|
||||||
@@ -60,12 +60,12 @@ class ExtendsPlugin extends BasePlugin
|
|||||||
/**
|
/**
|
||||||
* populate Source Object with timestamp and exists from Resource
|
* populate Source Object with timestamp and exists from Resource
|
||||||
*
|
*
|
||||||
* @param \Smarty_Template_Source $source source object
|
* @param \Smarty\Template\Source $source source object
|
||||||
*/
|
*/
|
||||||
public function populateTimestamp(\Smarty_Template_Source $source)
|
public function populateTimestamp(\Smarty\Template\Source $source)
|
||||||
{
|
{
|
||||||
$source->exists = true;
|
$source->exists = true;
|
||||||
/* @var \Smarty_Template_Source $_s */
|
/* @var \Smarty\Template\Source $_s */
|
||||||
foreach ($source->components as $_s) {
|
foreach ($source->components as $_s) {
|
||||||
$source->exists = $source->exists && $_s->exists;
|
$source->exists = $source->exists && $_s->exists;
|
||||||
}
|
}
|
||||||
@@ -75,19 +75,19 @@ class ExtendsPlugin extends BasePlugin
|
|||||||
/**
|
/**
|
||||||
* Load template's source from files into current template object
|
* Load template's source from files into current template object
|
||||||
*
|
*
|
||||||
* @param \Smarty_Template_Source $source source object
|
* @param \Smarty\Template\Source $source source object
|
||||||
*
|
*
|
||||||
* @return string template source
|
* @return string template source
|
||||||
* @throws \SmartyException if source cannot be loaded
|
* @throws \SmartyException if source cannot be loaded
|
||||||
*/
|
*/
|
||||||
public function getContent(\Smarty_Template_Source $source)
|
public function getContent(\Smarty\Template\Source $source)
|
||||||
{
|
{
|
||||||
if (!$source->exists) {
|
if (!$source->exists) {
|
||||||
throw new \SmartyException("Unable to load template '{$source->type}:{$source->name}'");
|
throw new \SmartyException("Unable to load template '{$source->type}:{$source->name}'");
|
||||||
}
|
}
|
||||||
$_components = array_reverse($source->components);
|
$_components = array_reverse($source->components);
|
||||||
$_content = '';
|
$_content = '';
|
||||||
/* @var \Smarty_Template_Source $_s */
|
/* @var \Smarty\Template\Source $_s */
|
||||||
foreach ($_components as $_s) {
|
foreach ($_components as $_s) {
|
||||||
// read content
|
// read content
|
||||||
$_content .= $_s->getContent();
|
$_content .= $_s->getContent();
|
||||||
@@ -98,11 +98,11 @@ class ExtendsPlugin extends BasePlugin
|
|||||||
/**
|
/**
|
||||||
* Determine basename for compiled filename
|
* Determine basename for compiled filename
|
||||||
*
|
*
|
||||||
* @param \Smarty_Template_Source $source source object
|
* @param \Smarty\Template\Source $source source object
|
||||||
*
|
*
|
||||||
* @return string resource's basename
|
* @return string resource's basename
|
||||||
*/
|
*/
|
||||||
public function getBasename(\Smarty_Template_Source $source)
|
public function getBasename(\Smarty\Template\Source $source)
|
||||||
{
|
{
|
||||||
return str_replace(':', '.', basename($source->filepath));
|
return str_replace(':', '.', basename($source->filepath));
|
||||||
}
|
}
|
||||||
|
@@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
namespace Smarty\Resource;
|
namespace Smarty\Resource;
|
||||||
use Smarty;
|
use Smarty;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use Smarty_Template_Source;
|
use Smarty\Template\Source;
|
||||||
use SmartyException;
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,17 +21,17 @@ use SmartyException;
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage TemplateResources
|
* @subpackage TemplateResources
|
||||||
*/
|
*/
|
||||||
class FilePlugin extends Smarty\Resource\BasePlugin {
|
class FilePlugin extends BasePlugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* populate Source Object with meta data from Resource
|
* populate Source Object with meta data from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
public function populate(Source $source, Template $_template = null) {
|
||||||
$source->filepath = $this->buildFilepath($source, $_template);
|
$source->filepath = $this->buildFilepath($source, $_template);
|
||||||
if ($source->filepath !== false) {
|
if ($source->filepath !== false) {
|
||||||
if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) {
|
if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) {
|
||||||
@@ -51,9 +51,9 @@ class FilePlugin extends Smarty\Resource\BasePlugin {
|
|||||||
/**
|
/**
|
||||||
* populate Source Object with timestamp and exists from Resource
|
* populate Source Object with timestamp and exists from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
*/
|
*/
|
||||||
public function populateTimestamp(Smarty_Template_Source $source) {
|
public function populateTimestamp(Source $source) {
|
||||||
if (!$source->exists) {
|
if (!$source->exists) {
|
||||||
$source->timestamp = $source->exists = is_file($source->filepath);
|
$source->timestamp = $source->exists = is_file($source->filepath);
|
||||||
}
|
}
|
||||||
@@ -65,12 +65,12 @@ class FilePlugin extends Smarty\Resource\BasePlugin {
|
|||||||
/**
|
/**
|
||||||
* Load template's source from file into current template object
|
* Load template's source from file into current template object
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
*
|
*
|
||||||
* @return string template source
|
* @return string template source
|
||||||
* @throws SmartyException if source cannot be loaded
|
* @throws SmartyException if source cannot be loaded
|
||||||
*/
|
*/
|
||||||
public function getContent(Smarty_Template_Source $source) {
|
public function getContent(Source $source) {
|
||||||
if ($source->exists) {
|
if ($source->exists) {
|
||||||
return file_get_contents($source->filepath);
|
return file_get_contents($source->filepath);
|
||||||
}
|
}
|
||||||
@@ -83,24 +83,24 @@ class FilePlugin extends Smarty\Resource\BasePlugin {
|
|||||||
/**
|
/**
|
||||||
* Determine basename for compiled filename
|
* Determine basename for compiled filename
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
*
|
*
|
||||||
* @return string resource's basename
|
* @return string resource's basename
|
||||||
*/
|
*/
|
||||||
public function getBasename(Smarty_Template_Source $source) {
|
public function getBasename(Source $source) {
|
||||||
return basename($source->filepath);
|
return basename($source->filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* build template filepath by traversing the template_dir array
|
* build template filepath by traversing the template_dir array
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return string fully qualified filepath
|
* @return string fully qualified filepath
|
||||||
* @throws SmartyException
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
protected function buildFilepath(Source $source, Template $_template = null) {
|
||||||
$file = $source->name;
|
$file = $source->name;
|
||||||
// absolute file ?
|
// absolute file ?
|
||||||
if ($file[0] === '/' || $file[1] === ':') {
|
if ($file[0] === '/' || $file[1] === ':') {
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace Smarty\Resource;
|
namespace Smarty\Resource;
|
||||||
|
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use Smarty_Template_Compiled;
|
use Smarty\Template\Source;
|
||||||
use Smarty_Template_Source;
|
use Smarty\Template\Compiled;
|
||||||
use SmartyException;
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,12 +49,12 @@ class PhpPlugin extends FilePlugin {
|
|||||||
/**
|
/**
|
||||||
* Load template's source from file into current template object
|
* Load template's source from file into current template object
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
*
|
*
|
||||||
* @return string template source
|
* @return string template source
|
||||||
* @throws SmartyException if source cannot be loaded
|
* @throws SmartyException if source cannot be loaded
|
||||||
*/
|
*/
|
||||||
public function getContent(Smarty_Template_Source $source) {
|
public function getContent(Source $source) {
|
||||||
if ($source->exists) {
|
if ($source->exists) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@@ -64,10 +64,10 @@ class PhpPlugin extends FilePlugin {
|
|||||||
/**
|
/**
|
||||||
* populate compiled object with compiled filepath
|
* populate compiled object with compiled filepath
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Compiled $compiled compiled object
|
* @param Compiled $compiled compiled object
|
||||||
* @param Smarty_Internal_Template $_template template object (is ignored)
|
* @param Template $_template template object (is ignored)
|
||||||
*/
|
*/
|
||||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) {
|
public function populateCompiledFilepath(Compiled $compiled, Template $_template) {
|
||||||
$compiled->filepath = $_template->source->filepath;
|
$compiled->filepath = $_template->source->filepath;
|
||||||
$compiled->timestamp = $_template->source->timestamp;
|
$compiled->timestamp = $_template->source->timestamp;
|
||||||
$compiled->exists = $_template->source->exists;
|
$compiled->exists = $_template->source->exists;
|
||||||
@@ -82,13 +82,13 @@ class PhpPlugin extends FilePlugin {
|
|||||||
/**
|
/**
|
||||||
* Render and output the template (without using the compiler)
|
* Render and output the template (without using the compiler)
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
|
* @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
|
||||||
*/
|
*/
|
||||||
public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template) {
|
public function renderUncompiled(Source $source, Template $_template) {
|
||||||
if (!$source->smarty->allow_php_templates) {
|
if (!$source->smarty->allow_php_templates) {
|
||||||
throw new SmartyException('PHP templates are disabled');
|
throw new SmartyException('PHP templates are disabled');
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ class PhpPlugin extends FilePlugin {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @var Smarty_Internal_Template $_smarty_template
|
* @var Template $_smarty_template
|
||||||
* used in included file
|
* used in included file
|
||||||
*/
|
*/
|
||||||
$_smarty_template = $_template;
|
$_smarty_template = $_template;
|
||||||
|
@@ -10,8 +10,8 @@
|
|||||||
namespace Smarty\Resource;
|
namespace Smarty\Resource;
|
||||||
|
|
||||||
use Smarty;
|
use Smarty;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use Smarty_Template_Compiled;
|
use Smarty\Template\Compiled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Resource Plugin
|
* Smarty Resource Plugin
|
||||||
@@ -39,11 +39,11 @@ abstract class RecompiledPlugin extends BasePlugin {
|
|||||||
/**
|
/**
|
||||||
* compile template from source
|
* compile template from source
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
* @param Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function process(Smarty_Internal_Template $_smarty_tpl) {
|
public function process(Template $_smarty_tpl) {
|
||||||
$compiled = &$_smarty_tpl->compiled;
|
$compiled = &$_smarty_tpl->compiled;
|
||||||
$compiled->file_dependency = [];
|
$compiled->file_dependency = [];
|
||||||
$compiled->includes = [];
|
$compiled->includes = [];
|
||||||
@@ -72,12 +72,12 @@ abstract class RecompiledPlugin extends BasePlugin {
|
|||||||
/**
|
/**
|
||||||
* populate Compiled Object with compiled filepath
|
* populate Compiled Object with compiled filepath
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Compiled $compiled compiled object
|
* @param Compiled $compiled compiled object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) {
|
public function populateCompiledFilepath(Compiled $compiled, Template $_template) {
|
||||||
$compiled->filepath = false;
|
$compiled->filepath = false;
|
||||||
$compiled->timestamp = false;
|
$compiled->timestamp = false;
|
||||||
$compiled->exists = false;
|
$compiled->exists = false;
|
||||||
|
@@ -12,8 +12,8 @@
|
|||||||
namespace Smarty\Resource;
|
namespace Smarty\Resource;
|
||||||
|
|
||||||
use Smarty;
|
use Smarty;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use Smarty_Template_Source;
|
use Smarty\Template\Source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin Resource Stream
|
* Smarty Internal Plugin Resource Stream
|
||||||
@@ -28,12 +28,12 @@ class StreamPlugin extends RecompiledPlugin {
|
|||||||
/**
|
/**
|
||||||
* populate Source Object with meta data from Resource
|
* populate Source Object with meta data from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
public function populate(Source $source, Template $_template = null) {
|
||||||
if (strpos($source->resource, '://') !== false) {
|
if (strpos($source->resource, '://') !== false) {
|
||||||
$source->filepath = $source->resource;
|
$source->filepath = $source->resource;
|
||||||
} else {
|
} else {
|
||||||
@@ -47,11 +47,11 @@ class StreamPlugin extends RecompiledPlugin {
|
|||||||
/**
|
/**
|
||||||
* Load template's source from stream into current template object
|
* Load template's source from stream into current template object
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
*
|
*
|
||||||
* @return string template source
|
* @return string template source
|
||||||
*/
|
*/
|
||||||
public function getContent(Smarty_Template_Source $source) {
|
public function getContent(Source $source) {
|
||||||
$t = '';
|
$t = '';
|
||||||
// the availability of the stream has already been checked in Smarty\Resource\Base::fetch()
|
// the availability of the stream has already been checked in Smarty\Resource\Base::fetch()
|
||||||
$fp = fopen($source->filepath, 'r+');
|
$fp = fopen($source->filepath, 'r+');
|
||||||
|
@@ -24,12 +24,12 @@ class StringEval extends Recompiled
|
|||||||
/**
|
/**
|
||||||
* populate Source Object with meta data from Resource
|
* populate Source Object with meta data from Resource
|
||||||
*
|
*
|
||||||
* @param \Smarty_Template_Source $source source object
|
* @param \Smarty\Template\Source $source source object
|
||||||
* @param \Smarty_Internal_Template $_template template object
|
* @param \Smarty\Template $_template template object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function populate(\Smarty_Template_Source $source, \Smarty_Internal_Template $_template = null)
|
public function populate(\Smarty\Template\Source $source, \Smarty\Template $_template = null)
|
||||||
{
|
{
|
||||||
$source->uid = $source->filepath = sha1($source->name);
|
$source->uid = $source->filepath = sha1($source->name);
|
||||||
$source->timestamp = $source->exists = true;
|
$source->timestamp = $source->exists = true;
|
||||||
@@ -38,13 +38,13 @@ class StringEval extends Recompiled
|
|||||||
/**
|
/**
|
||||||
* Load template's source from $resource_name into current template object
|
* Load template's source from $resource_name into current template object
|
||||||
*
|
*
|
||||||
* @uses decode() to decode base64 and urlencoded template_resources
|
* @param \Smarty\Template\Source $source source object
|
||||||
*
|
|
||||||
* @param \Smarty_Template_Source $source source object
|
|
||||||
*
|
*
|
||||||
* @return string template source
|
* @return string template source
|
||||||
|
*@uses decode() to decode base64 and urlencoded template_resources
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function getContent(\Smarty_Template_Source $source)
|
public function getContent(\Smarty\Template\Source $source)
|
||||||
{
|
{
|
||||||
return $this->decode($source->name);
|
return $this->decode($source->name);
|
||||||
}
|
}
|
||||||
@@ -86,11 +86,11 @@ class StringEval extends Recompiled
|
|||||||
/**
|
/**
|
||||||
* Determine basename for compiled filename
|
* Determine basename for compiled filename
|
||||||
*
|
*
|
||||||
* @param \Smarty_Template_Source $source source object
|
* @param \Smarty\Template\Source $source source object
|
||||||
*
|
*
|
||||||
* @return string resource's basename
|
* @return string resource's basename
|
||||||
*/
|
*/
|
||||||
public function getBasename(\Smarty_Template_Source $source)
|
public function getBasename(\Smarty\Template\Source $source)
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
namespace Smarty\Resource;
|
namespace Smarty\Resource;
|
||||||
use Smarty;
|
use Smarty;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use Smarty_Template_Source;
|
use Smarty\Template\Source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin Resource String
|
* Smarty Internal Plugin Resource String
|
||||||
@@ -21,17 +21,17 @@ use Smarty_Template_Source;
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage TemplateResources
|
* @subpackage TemplateResources
|
||||||
*/
|
*/
|
||||||
class StringPlugin extends Smarty\Resource\BasePlugin {
|
class StringPlugin extends BasePlugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* populate Source Object with meta data from Resource
|
* populate Source Object with meta data from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
public function populate(Source $source, Template $_template = null) {
|
||||||
$source->uid = $source->filepath = sha1($source->name . $source->smarty->_joined_template_dir);
|
$source->uid = $source->filepath = sha1($source->name . $source->smarty->_joined_template_dir);
|
||||||
$source->timestamp = $source->exists = true;
|
$source->timestamp = $source->exists = true;
|
||||||
}
|
}
|
||||||
@@ -39,13 +39,13 @@ class StringPlugin extends Smarty\Resource\BasePlugin {
|
|||||||
/**
|
/**
|
||||||
* Load template's source from $resource_name into current template object
|
* Load template's source from $resource_name into current template object
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
*
|
*
|
||||||
* @return string template source
|
* @return string template source
|
||||||
* @uses decode() to decode base64 and urlencoded template_resources
|
* @uses decode() to decode base64 and urlencoded template_resources
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getContent(Smarty_Template_Source $source) {
|
public function getContent(Source $source) {
|
||||||
return $this->decode($source->name);
|
return $this->decode($source->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,11 +85,11 @@ class StringPlugin extends Smarty\Resource\BasePlugin {
|
|||||||
* Determine basename for compiled filename
|
* Determine basename for compiled filename
|
||||||
* Always returns an empty string.
|
* Always returns an empty string.
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
*
|
*
|
||||||
* @return string resource's basename
|
* @return string resource's basename
|
||||||
*/
|
*/
|
||||||
public function getBasename(Smarty_Template_Source $source) {
|
public function getBasename(Source $source) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,8 +10,8 @@
|
|||||||
namespace Smarty\Resource;
|
namespace Smarty\Resource;
|
||||||
|
|
||||||
use Smarty;
|
use Smarty;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use Smarty_Template_Compiled;
|
use Smarty\Template\Compiled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Resource Plugin
|
* Smarty Resource Plugin
|
||||||
@@ -20,7 +20,7 @@ use Smarty_Template_Compiled;
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage TemplateResources
|
* @subpackage TemplateResources
|
||||||
*/
|
*/
|
||||||
abstract class UncompiledPlugin extends asePlugin {
|
abstract class UncompiledPlugin extends BasePlugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag that it's an uncompiled resource
|
* Flag that it's an uncompiled resource
|
||||||
@@ -39,10 +39,10 @@ abstract class UncompiledPlugin extends asePlugin {
|
|||||||
/**
|
/**
|
||||||
* populate compiled object with compiled filepath
|
* populate compiled object with compiled filepath
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Compiled $compiled compiled object
|
* @param Compiled $compiled compiled object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*/
|
*/
|
||||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) {
|
public function populateCompiledFilepath(Compiled $compiled, Template $_template) {
|
||||||
$compiled->filepath = $_template->source->filepath;
|
$compiled->filepath = $_template->source->filepath;
|
||||||
$compiled->timestamp = $_template->source->timestamp;
|
$compiled->timestamp = $_template->source->timestamp;
|
||||||
$compiled->exists = $_template->source->exists;
|
$compiled->exists = $_template->source->exists;
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Smarty\Runtime;
|
namespace Smarty\Runtime;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runtime Extension Capture
|
* Runtime Extension Capture
|
||||||
@@ -50,12 +50,12 @@ class CaptureRuntime {
|
|||||||
/**
|
/**
|
||||||
* Open capture section
|
* Open capture section
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $_template
|
* @param \Smarty\Template $_template
|
||||||
* @param string $buffer capture name
|
* @param string $buffer capture name
|
||||||
* @param string $assign variable name
|
* @param string $assign variable name
|
||||||
* @param string $append variable name
|
* @param string $append variable name
|
||||||
*/
|
*/
|
||||||
public function open(Smarty_Internal_Template $_template, $buffer, $assign, $append) {
|
public function open(Template $_template, $buffer, $assign, $append) {
|
||||||
if (!$this->isRegistered) {
|
if (!$this->isRegistered) {
|
||||||
$this->register($_template);
|
$this->register($_template);
|
||||||
}
|
}
|
||||||
@@ -71,9 +71,9 @@ class CaptureRuntime {
|
|||||||
/**
|
/**
|
||||||
* Register callbacks in template class
|
* Register callbacks in template class
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $_template
|
* @param \Smarty\Template $_template
|
||||||
*/
|
*/
|
||||||
private function register(Smarty_Internal_Template $_template) {
|
private function register(Template $_template) {
|
||||||
$_template->startRenderCallbacks[] = [
|
$_template->startRenderCallbacks[] = [
|
||||||
$this,
|
$this,
|
||||||
'startRender',
|
'startRender',
|
||||||
@@ -89,9 +89,9 @@ class CaptureRuntime {
|
|||||||
/**
|
/**
|
||||||
* Start render callback
|
* Start render callback
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $_template
|
* @param \Smarty\Template $_template
|
||||||
*/
|
*/
|
||||||
public function startRender(Smarty_Internal_Template $_template) {
|
public function startRender(Template $_template) {
|
||||||
$this->countStack[] = $this->captureCount;
|
$this->countStack[] = $this->captureCount;
|
||||||
$this->captureCount = 0;
|
$this->captureCount = 0;
|
||||||
}
|
}
|
||||||
@@ -99,11 +99,11 @@ class CaptureRuntime {
|
|||||||
/**
|
/**
|
||||||
* Close capture section
|
* Close capture section
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $_template
|
* @param \Smarty\Template $_template
|
||||||
*
|
*
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function close(Smarty_Internal_Template $_template) {
|
public function close(Template $_template) {
|
||||||
if ($this->captureCount) {
|
if ($this->captureCount) {
|
||||||
[$buffer, $assign, $append] = array_pop($this->captureStack);
|
[$buffer, $assign, $append] = array_pop($this->captureStack);
|
||||||
$this->captureCount--;
|
$this->captureCount--;
|
||||||
@@ -122,23 +122,23 @@ class CaptureRuntime {
|
|||||||
/**
|
/**
|
||||||
* Error exception on not matching {capture}{/capture}
|
* Error exception on not matching {capture}{/capture}
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $_template
|
* @param \Smarty\Template $_template
|
||||||
*
|
*
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function error(Smarty_Internal_Template $_template) {
|
public function error(Template $_template) {
|
||||||
throw new SmartyException("Not matching {capture}{/capture} in '{$_template->template_resource}'");
|
throw new SmartyException("Not matching {capture}{/capture} in '{$_template->template_resource}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return content of named capture buffer by key or as array
|
* Return content of named capture buffer by key or as array
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $_template
|
* @param \Smarty\Template $_template
|
||||||
* @param string|null $name
|
* @param string|null $name
|
||||||
*
|
*
|
||||||
* @return string|string[]|null
|
* @return string|string[]|null
|
||||||
*/
|
*/
|
||||||
public function getBuffer(Smarty_Internal_Template $_template, $name = null) {
|
public function getBuffer(Template $_template, $name = null) {
|
||||||
if (isset($name)) {
|
if (isset($name)) {
|
||||||
return $this->namedBuffer[$name] ?? null;
|
return $this->namedBuffer[$name] ?? null;
|
||||||
} else {
|
} else {
|
||||||
@@ -149,11 +149,11 @@ class CaptureRuntime {
|
|||||||
/**
|
/**
|
||||||
* End render callback
|
* End render callback
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $_template
|
* @param \Smarty\Template $_template
|
||||||
*
|
*
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function endRender(Smarty_Internal_Template $_template) {
|
public function endRender(Template $_template) {
|
||||||
if ($this->captureCount) {
|
if ($this->captureCount) {
|
||||||
$this->error($_template);
|
$this->error($_template);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Smarty\Runtime;
|
namespace Smarty\Runtime;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Foreach Runtime Methods count(), init(), restore()
|
* Foreach Runtime Methods count(), init(), restore()
|
||||||
@@ -25,7 +25,7 @@ class ForeachRuntime {
|
|||||||
* - init item and key variables, named foreach property data if required
|
* - init item and key variables, named foreach property data if required
|
||||||
* - count total if required
|
* - count total if required
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $tpl
|
* @param \Smarty\Template $tpl
|
||||||
* @param mixed $from values to loop over
|
* @param mixed $from values to loop over
|
||||||
* @param string $item variable name
|
* @param string $item variable name
|
||||||
* @param bool $needTotal flag if we need to count values
|
* @param bool $needTotal flag if we need to count values
|
||||||
@@ -36,13 +36,13 @@ class ForeachRuntime {
|
|||||||
* @return mixed $from
|
* @return mixed $from
|
||||||
*/
|
*/
|
||||||
public function init(
|
public function init(
|
||||||
Smarty_Internal_Template $tpl,
|
Template $tpl,
|
||||||
$from,
|
$from,
|
||||||
$item,
|
$item,
|
||||||
$needTotal = false,
|
$needTotal = false,
|
||||||
$key = null,
|
$key = null,
|
||||||
$name = null,
|
$name = null,
|
||||||
$properties = []
|
$properties = []
|
||||||
) {
|
) {
|
||||||
$needTotal = $needTotal || isset($properties['total']);
|
$needTotal = $needTotal || isset($properties['total']);
|
||||||
$saveVars = [];
|
$saveVars = [];
|
||||||
@@ -139,10 +139,10 @@ class ForeachRuntime {
|
|||||||
*
|
*
|
||||||
* will be called by {break n} or {continue n} for the required number of levels
|
* will be called by {break n} or {continue n} for the required number of levels
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $tpl
|
* @param \Smarty\Template $tpl
|
||||||
* @param int $levels number of levels
|
* @param int $levels number of levels
|
||||||
*/
|
*/
|
||||||
public function restore(Smarty_Internal_Template $tpl, $levels = 1) {
|
public function restore(Template $tpl, $levels = 1) {
|
||||||
while ($levels) {
|
while ($levels) {
|
||||||
$saveVars = array_pop($this->stack);
|
$saveVars = array_pop($this->stack);
|
||||||
if (!empty($saveVars)) {
|
if (!empty($saveVars)) {
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Smarty\Runtime;
|
namespace Smarty\Runtime;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use Smarty_Template_Source;
|
use Smarty\Template\Source;
|
||||||
use SmartyException;
|
use SmartyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,25 +50,25 @@ class InheritanceRuntime {
|
|||||||
/**
|
/**
|
||||||
* Array of template source objects
|
* Array of template source objects
|
||||||
*
|
*
|
||||||
* @var Smarty_Template_Source[]
|
* @var Source[]
|
||||||
*/
|
*/
|
||||||
public $sources = [];
|
public $sources = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stack of source objects while executing block code
|
* Stack of source objects while executing block code
|
||||||
*
|
*
|
||||||
* @var Smarty_Template_Source[]
|
* @var Source[]
|
||||||
*/
|
*/
|
||||||
public $sourceStack = [];
|
public $sourceStack = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize inheritance
|
* Initialize inheritance
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $tpl template object of caller
|
* @param \Smarty\Template $tpl template object of caller
|
||||||
* @param bool $initChild if true init for child template
|
* @param bool $initChild if true init for child template
|
||||||
* @param array $blockNames outer level block name
|
* @param array $blockNames outer level block name
|
||||||
*/
|
*/
|
||||||
public function init(Smarty_Internal_Template $tpl, $initChild, $blockNames = []) {
|
public function init(Template $tpl, $initChild, $blockNames = []) {
|
||||||
// if called while executing parent template it must be a sub-template with new inheritance root
|
// if called while executing parent template it must be a sub-template with new inheritance root
|
||||||
if ($initChild && $this->state === 3 && (strpos($tpl->template_resource, 'extendsall') === false)) {
|
if ($initChild && $this->state === 3 && (strpos($tpl->template_resource, 'extendsall') === false)) {
|
||||||
$tpl->inheritance = new InheritanceRuntime();
|
$tpl->inheritance = new InheritanceRuntime();
|
||||||
@@ -98,7 +98,7 @@ class InheritanceRuntime {
|
|||||||
* End of child template(s)
|
* End of child template(s)
|
||||||
* - if outer level is reached flush output buffer and switch to wait for parent template state
|
* - if outer level is reached flush output buffer and switch to wait for parent template state
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $tpl
|
* @param \Smarty\Template $tpl
|
||||||
* @param null|string $template optional name of inheritance parent template
|
* @param null|string $template optional name of inheritance parent template
|
||||||
* @param null|string $uid uid of inline template
|
* @param null|string $uid uid of inline template
|
||||||
* @param null|string $func function call name of inline template
|
* @param null|string $func function call name of inline template
|
||||||
@@ -106,7 +106,7 @@ class InheritanceRuntime {
|
|||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function endChild(Smarty_Internal_Template $tpl, $template = null, $uid = null, $func = null) {
|
public function endChild(Template $tpl, $template = null, $uid = null, $func = null) {
|
||||||
--$this->inheritanceLevel;
|
--$this->inheritanceLevel;
|
||||||
if (!$this->inheritanceLevel) {
|
if (!$this->inheritanceLevel) {
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
@@ -135,14 +135,14 @@ class InheritanceRuntime {
|
|||||||
* - if outer level {block} of child template ($state === 1) save it as child root block
|
* - if outer level {block} of child template ($state === 1) save it as child root block
|
||||||
* - otherwise process inheritance and render
|
* - otherwise process inheritance and render
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $tpl
|
* @param \Smarty\Template $tpl
|
||||||
* @param $className
|
* @param $className
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param int|null $tplIndex index of outer level {block} if nested
|
* @param int|null $tplIndex index of outer level {block} if nested
|
||||||
*
|
*
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function instanceBlock(Smarty_Internal_Template $tpl, $className, $name, $tplIndex = null) {
|
public function instanceBlock(Template $tpl, $className, $name, $tplIndex = null) {
|
||||||
$block = new $className($name, isset($tplIndex) ? $tplIndex : $this->tplIndex);
|
$block = new $className($name, isset($tplIndex) ? $tplIndex : $this->tplIndex);
|
||||||
if (isset($this->childRoot[$name])) {
|
if (isset($this->childRoot[$name])) {
|
||||||
$block->child = $this->childRoot[$name];
|
$block->child = $this->childRoot[$name];
|
||||||
@@ -161,16 +161,16 @@ class InheritanceRuntime {
|
|||||||
/**
|
/**
|
||||||
* Goto child block or render this
|
* Goto child block or render this
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $tpl
|
* @param Template $tpl
|
||||||
* @param \Smarty\Block $block
|
* @param \Smarty\Block $block
|
||||||
* @param \Smarty\Block|null $parent
|
* @param \Smarty\Block|null $parent
|
||||||
*
|
*
|
||||||
* @throws SmartyException
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
public function process(
|
public function process(
|
||||||
Smarty_Internal_Template $tpl,
|
Template $tpl,
|
||||||
\Smarty\Block $block,
|
\Smarty\Block $block,
|
||||||
\Smarty\Block $parent = null
|
\Smarty\Block $parent = null
|
||||||
) {
|
) {
|
||||||
if ($block->hide && !isset($block->child)) {
|
if ($block->hide && !isset($block->child)) {
|
||||||
return;
|
return;
|
||||||
@@ -205,13 +205,13 @@ class InheritanceRuntime {
|
|||||||
/**
|
/**
|
||||||
* Render child on \$smarty.block.child
|
* Render child on \$smarty.block.child
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $tpl
|
* @param Template $tpl
|
||||||
* @param \Smarty\Block $block
|
* @param \Smarty\Block $block
|
||||||
*
|
*
|
||||||
* @return null|string block content
|
* @return null|string block content
|
||||||
* @throws SmartyException
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
public function callChild(Smarty_Internal_Template $tpl, \Smarty\Block $block) {
|
public function callChild(Template $tpl, \Smarty\Block $block) {
|
||||||
if (isset($block->child)) {
|
if (isset($block->child)) {
|
||||||
$this->process($tpl, $block->child, $block);
|
$this->process($tpl, $block->child, $block);
|
||||||
}
|
}
|
||||||
@@ -220,14 +220,14 @@ class InheritanceRuntime {
|
|||||||
/**
|
/**
|
||||||
* Render parent block on \$smarty.block.parent or {block append/prepend}
|
* Render parent block on \$smarty.block.parent or {block append/prepend}
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $tpl
|
* @param Template $tpl
|
||||||
* @param \Smarty\Block $block
|
* @param \Smarty\Block $block
|
||||||
* @param string $tag
|
* @param string $tag
|
||||||
*
|
*
|
||||||
* @return null|string block content
|
* @return null|string block content
|
||||||
* @throws SmartyException
|
* @throws SmartyException
|
||||||
*/
|
*/
|
||||||
public function callParent(Smarty_Internal_Template $tpl, \Smarty\Block $block, $tag) {
|
public function callParent(Template $tpl, \Smarty\Block $block, $tag) {
|
||||||
if (isset($block->parent)) {
|
if (isset($block->parent)) {
|
||||||
$this->callBlock($block->parent, $tpl);
|
$this->callBlock($block->parent, $tpl);
|
||||||
} else {
|
} else {
|
||||||
@@ -239,9 +239,9 @@ class InheritanceRuntime {
|
|||||||
* render block
|
* render block
|
||||||
*
|
*
|
||||||
* @param \Smarty\Block $block
|
* @param \Smarty\Block $block
|
||||||
* @param Smarty_Internal_Template $tpl
|
* @param Template $tpl
|
||||||
*/
|
*/
|
||||||
public function callBlock(\Smarty\Block $block, Smarty_Internal_Template $tpl) {
|
public function callBlock(\Smarty\Block $block, Template $tpl) {
|
||||||
$this->sourceStack[] = $tpl->source;
|
$this->sourceStack[] = $tpl->source;
|
||||||
$tpl->source = $this->sources[$block->tplIndex];
|
$tpl->source = $this->sources[$block->tplIndex];
|
||||||
$block->callBlock($tpl);
|
$block->callBlock($tpl);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Smarty\Runtime;
|
namespace Smarty\Runtime;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {make_nocache} Runtime Methods save(), store()
|
* {make_nocache} Runtime Methods save(), store()
|
||||||
@@ -16,12 +16,12 @@ class MakeNocacheRuntime {
|
|||||||
* Save current variable value while rendering compiled template and inject nocache code to
|
* Save current variable value while rendering compiled template and inject nocache code to
|
||||||
* assign variable value in cached template
|
* assign variable value in cached template
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $tpl
|
* @param \Smarty\Template $tpl
|
||||||
* @param string $var variable name
|
* @param string $var variable name
|
||||||
*
|
*
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function save(Smarty_Internal_Template $tpl, $var) {
|
public function save(Template $tpl, $var) {
|
||||||
if (isset($tpl->tpl_vars[$var])) {
|
if (isset($tpl->tpl_vars[$var])) {
|
||||||
$export =
|
$export =
|
||||||
preg_replace('/^\\\\Smarty\\\\Variable::__set_state[(]|[)]$/', '', var_export($tpl->tpl_vars[$var], true));
|
preg_replace('/^\\\\Smarty\\\\Variable::__set_state[(]|[)]$/', '', var_export($tpl->tpl_vars[$var], true));
|
||||||
@@ -37,11 +37,11 @@ class MakeNocacheRuntime {
|
|||||||
/**
|
/**
|
||||||
* Store variable value saved while rendering compiled template in cached template context
|
* Store variable value saved while rendering compiled template in cached template context
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $tpl
|
* @param \Smarty\Template $tpl
|
||||||
* @param string $var variable name
|
* @param string $var variable name
|
||||||
* @param array $properties
|
* @param array $properties
|
||||||
*/
|
*/
|
||||||
public function store(Smarty_Internal_Template $tpl, $var, $properties) {
|
public function store(Template $tpl, $var, $properties) {
|
||||||
// do not overwrite existing nocache variables
|
// do not overwrite existing nocache variables
|
||||||
if (!isset($tpl->tpl_vars[$var]) || !$tpl->tpl_vars[$var]->nocache) {
|
if (!isset($tpl->tpl_vars[$var]) || !$tpl->tpl_vars[$var]->nocache) {
|
||||||
$newVar = new \Smarty\Variable();
|
$newVar = new \Smarty\Variable();
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Smarty\Runtime;
|
namespace Smarty\Runtime;
|
||||||
use Smarty_Internal_Template;
|
use Smarty\Template;
|
||||||
use Smarty_Internal_TemplateBase;
|
use Smarty\TemplateBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TplFunction Runtime Methods callTemplateFunction
|
* TplFunction Runtime Methods callTemplateFunction
|
||||||
@@ -16,14 +16,14 @@ class TplFunctionRuntime {
|
|||||||
/**
|
/**
|
||||||
* Call template function
|
* Call template function
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $tpl template object
|
* @param \Smarty\Template $tpl template object
|
||||||
* @param string $name template function name
|
* @param string $name template function name
|
||||||
* @param array $params parameter array
|
* @param array $params parameter array
|
||||||
* @param bool $nocache true if called nocache
|
* @param bool $nocache true if called nocache
|
||||||
*
|
*
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function callTemplateFunction(Smarty_Internal_Template $tpl, $name, $params, $nocache) {
|
public function callTemplateFunction(Template $tpl, $name, $params, $nocache) {
|
||||||
$funcParam = $tpl->tplFunctions[$name] ?? ($tpl->smarty->tplFunctions[$name] ?? null);
|
$funcParam = $tpl->tplFunctions[$name] ?? ($tpl->smarty->tplFunctions[$name] ?? null);
|
||||||
if (isset($funcParam)) {
|
if (isset($funcParam)) {
|
||||||
if (!$tpl->caching || ($tpl->caching && $nocache)) {
|
if (!$tpl->caching || ($tpl->caching && $nocache)) {
|
||||||
@@ -55,14 +55,14 @@ class TplFunctionRuntime {
|
|||||||
/**
|
/**
|
||||||
* Register template functions defined by template
|
* Register template functions defined by template
|
||||||
*
|
*
|
||||||
* @param \Smarty|\Smarty_Internal_Template|\Smarty_Internal_TemplateBase $obj
|
* @param \Smarty|\Smarty\Template|\Smarty\TemplateBase $obj
|
||||||
* @param array $tplFunctions source information array of
|
* @param array $tplFunctions source information array of
|
||||||
* template functions defined
|
* template functions defined
|
||||||
* in template
|
* in template
|
||||||
* @param bool $override if true replace existing
|
* @param bool $override if true replace existing
|
||||||
* functions with same name
|
* functions with same name
|
||||||
*/
|
*/
|
||||||
public function registerTplFunctions(Smarty_Internal_TemplateBase $obj, $tplFunctions, $override = true) {
|
public function registerTplFunctions(TemplateBase $obj, $tplFunctions, $override = true) {
|
||||||
$obj->tplFunctions =
|
$obj->tplFunctions =
|
||||||
$override ? array_merge($obj->tplFunctions, $tplFunctions) : array_merge($tplFunctions, $obj->tplFunctions);
|
$override ? array_merge($obj->tplFunctions, $tplFunctions) : array_merge($tplFunctions, $obj->tplFunctions);
|
||||||
// make sure that the template functions are known in parent templates
|
// make sure that the template functions are known in parent templates
|
||||||
@@ -77,12 +77,12 @@ class TplFunctionRuntime {
|
|||||||
/**
|
/**
|
||||||
* Return source parameter array for single or all template functions
|
* Return source parameter array for single or all template functions
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $tpl template object
|
* @param \Smarty\Template $tpl template object
|
||||||
* @param null|string $name template function name
|
* @param null|string $name template function name
|
||||||
*
|
*
|
||||||
* @return array|bool|mixed
|
* @return array|bool|mixed
|
||||||
*/
|
*/
|
||||||
public function getTplFunction(Smarty_Internal_Template $tpl, $name = null) {
|
public function getTplFunction(Template $tpl, $name = null) {
|
||||||
if (isset($name)) {
|
if (isset($name)) {
|
||||||
return $tpl->tplFunctions[$name] ?? ($tpl->smarty->tplFunctions[$name] ?? false);
|
return $tpl->tplFunctions[$name] ?? ($tpl->smarty->tplFunctions[$name] ?? false);
|
||||||
} else {
|
} else {
|
||||||
@@ -93,13 +93,13 @@ class TplFunctionRuntime {
|
|||||||
/**
|
/**
|
||||||
* Add template function to cache file for nocache calls
|
* Add template function to cache file for nocache calls
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $tpl
|
* @param Template $tpl
|
||||||
* @param string $_name template function name
|
* @param string $_name template function name
|
||||||
* @param string $_function PHP function name
|
* @param string $_function PHP function name
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function addTplFuncToCache(Smarty_Internal_Template $tpl, $_name, $_function) {
|
public function addTplFuncToCache(Template $tpl, $_name, $_function) {
|
||||||
$funcParam = $tpl->tplFunctions[$_name];
|
$funcParam = $tpl->tplFunctions[$_name];
|
||||||
if (is_file($funcParam['compiled_filepath'])) {
|
if (is_file($funcParam['compiled_filepath'])) {
|
||||||
// read compiled file
|
// read compiled file
|
||||||
@@ -149,10 +149,10 @@ class TplFunctionRuntime {
|
|||||||
/**
|
/**
|
||||||
* Save current template variables on stack
|
* Save current template variables on stack
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $tpl
|
* @param \Smarty\Template $tpl
|
||||||
* @param string $name stack name
|
* @param string $name stack name
|
||||||
*/
|
*/
|
||||||
public function saveTemplateVariables(Smarty_Internal_Template $tpl, $name) {
|
public function saveTemplateVariables(Template $tpl, $name) {
|
||||||
$tpl->_var_stack[] =
|
$tpl->_var_stack[] =
|
||||||
['tpl' => $tpl->tpl_vars, 'config' => $tpl->config_vars, 'name' => "_tplFunction_{$name}"];
|
['tpl' => $tpl->tpl_vars, 'config' => $tpl->config_vars, 'name' => "_tplFunction_{$name}"];
|
||||||
}
|
}
|
||||||
@@ -160,10 +160,10 @@ class TplFunctionRuntime {
|
|||||||
/**
|
/**
|
||||||
* Restore saved variables into template objects
|
* Restore saved variables into template objects
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $tpl
|
* @param \Smarty\Template $tpl
|
||||||
* @param string $name stack name
|
* @param string $name stack name
|
||||||
*/
|
*/
|
||||||
public function restoreTemplateVariables(Smarty_Internal_Template $tpl, $name) {
|
public function restoreTemplateVariables(Template $tpl, $name) {
|
||||||
if (isset($tpl->_var_stack)) {
|
if (isset($tpl->_var_stack)) {
|
||||||
$vars = array_pop($tpl->_var_stack);
|
$vars = array_pop($tpl->_var_stack);
|
||||||
$tpl->tpl_vars = $vars['tpl'];
|
$tpl->tpl_vars = $vars['tpl'];
|
||||||
|
@@ -41,7 +41,7 @@ use Smarty\Smarty\Runtime\TplFunctionRuntime;
|
|||||||
/**
|
/**
|
||||||
* This is the main Smarty class
|
* This is the main Smarty class
|
||||||
*/
|
*/
|
||||||
class Smarty extends \Smarty_Internal_TemplateBase
|
class Smarty extends \Smarty\TemplateBase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
@@ -597,7 +597,7 @@ class Smarty extends \Smarty_Internal_TemplateBase
|
|||||||
public function templateExists($resource_name)
|
public function templateExists($resource_name)
|
||||||
{
|
{
|
||||||
// create source object
|
// create source object
|
||||||
$source = \Smarty_Template_Source::load(null, $this, $resource_name);
|
$source = Template\Source::load(null, $this, $resource_name);
|
||||||
return $source->exists;
|
return $source->exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -844,7 +844,7 @@ class Smarty extends \Smarty_Internal_TemplateBase
|
|||||||
* @param object $parent next higher level of Smarty variables
|
* @param object $parent next higher level of Smarty variables
|
||||||
* @param boolean $do_clone flag is Smarty object shall be cloned
|
* @param boolean $do_clone flag is Smarty object shall be cloned
|
||||||
*
|
*
|
||||||
* @return \Smarty_Internal_Template template object
|
* @return \Smarty\Template template object
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)
|
public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)
|
||||||
@@ -864,17 +864,17 @@ class Smarty extends \Smarty_Internal_TemplateBase
|
|||||||
}
|
}
|
||||||
$_templateId = $this->_getTemplateId($template, $cache_id, $compile_id);
|
$_templateId = $this->_getTemplateId($template, $cache_id, $compile_id);
|
||||||
$tpl = null;
|
$tpl = null;
|
||||||
if ($this->caching && isset(\Smarty_Internal_Template::$isCacheTplObj[ $_templateId ])) {
|
if ($this->caching && isset(\Smarty\Template::$isCacheTplObj[ $_templateId ])) {
|
||||||
$tpl = $do_clone ? clone \Smarty_Internal_Template::$isCacheTplObj[ $_templateId ] :
|
$tpl = $do_clone ? clone \Smarty\Template::$isCacheTplObj[ $_templateId ] :
|
||||||
\Smarty_Internal_Template::$isCacheTplObj[ $_templateId ];
|
\Smarty\Template::$isCacheTplObj[ $_templateId ];
|
||||||
$tpl->inheritance = null;
|
$tpl->inheritance = null;
|
||||||
$tpl->tpl_vars = $tpl->config_vars = array();
|
$tpl->tpl_vars = $tpl->config_vars = array();
|
||||||
} elseif (!$do_clone && isset(\Smarty_Internal_Template::$tplObjCache[ $_templateId ])) {
|
} elseif (!$do_clone && isset(\Smarty\Template::$tplObjCache[ $_templateId ])) {
|
||||||
$tpl = clone \Smarty_Internal_Template::$tplObjCache[ $_templateId ];
|
$tpl = clone \Smarty\Template::$tplObjCache[ $_templateId ];
|
||||||
$tpl->inheritance = null;
|
$tpl->inheritance = null;
|
||||||
$tpl->tpl_vars = $tpl->config_vars = array();
|
$tpl->tpl_vars = $tpl->config_vars = array();
|
||||||
} else {
|
} else {
|
||||||
/* @var \Smarty_Internal_Template $tpl */
|
/* @var \Smarty\Template $tpl */
|
||||||
$tpl = new $this->template_class($template, $this, null, $cache_id, $compile_id, null, null);
|
$tpl = new $this->template_class($template, $this, null, $cache_id, $compile_id, null, null);
|
||||||
$tpl->templateId = $_templateId;
|
$tpl->templateId = $_templateId;
|
||||||
}
|
}
|
||||||
@@ -906,17 +906,17 @@ class Smarty extends \Smarty_Internal_TemplateBase
|
|||||||
* @param null|mixed $cache_id
|
* @param null|mixed $cache_id
|
||||||
* @param null|mixed $compile_id
|
* @param null|mixed $compile_id
|
||||||
* @param null $caching
|
* @param null $caching
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function _getTemplateId(
|
public function _getTemplateId(
|
||||||
$template_name,
|
$template_name,
|
||||||
$cache_id = null,
|
$cache_id = null,
|
||||||
$compile_id = null,
|
$compile_id = null,
|
||||||
$caching = null,
|
$caching = null,
|
||||||
\Smarty_Internal_Template $template = null
|
\Smarty\Template $template = null
|
||||||
) {
|
) {
|
||||||
$template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
|
$template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
|
||||||
$template_name;
|
$template_name;
|
||||||
@@ -985,8 +985,8 @@ class Smarty extends \Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public function _clearTemplateCache()
|
public function _clearTemplateCache()
|
||||||
{
|
{
|
||||||
\Smarty_Internal_Template::$isCacheTplObj = array();
|
\Smarty\Template::$isCacheTplObj = array();
|
||||||
\Smarty_Internal_Template::$tplObjCache = array();
|
\Smarty\Template::$tplObjCache = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1294,7 +1294,7 @@ class Smarty extends \Smarty_Internal_TemplateBase
|
|||||||
if (isset($resource_name)) {
|
if (isset($resource_name)) {
|
||||||
$_save_stat = $this->caching;
|
$_save_stat = $this->caching;
|
||||||
$this->caching = \Smarty\Smarty::CACHING_OFF;
|
$this->caching = \Smarty\Smarty::CACHING_OFF;
|
||||||
/* @var Smarty_Internal_Template $tpl */
|
/* @var Template $tpl */
|
||||||
$tpl = $this->createTemplate($resource_name);
|
$tpl = $this->createTemplate($resource_name);
|
||||||
$this->caching = $_save_stat;
|
$this->caching = $_save_stat;
|
||||||
if (!$tpl->source->handler->uncompiled && !$tpl->source->handler->recompiled && $tpl->source->exists) {
|
if (!$tpl->source->handler->uncompiled && !$tpl->source->handler->recompiled && $tpl->source->exists) {
|
||||||
@@ -1472,7 +1472,7 @@ class Smarty extends \Smarty_Internal_TemplateBase
|
|||||||
$_smarty->_cache = array();
|
$_smarty->_cache = array();
|
||||||
$_smarty->force_compile = $force_compile;
|
$_smarty->force_compile = $force_compile;
|
||||||
try {
|
try {
|
||||||
/* @var Smarty_Internal_Template $_tpl */
|
/* @var Template $_tpl */
|
||||||
$_tpl = new $this->template_class($_file, $_smarty);
|
$_tpl = new $this->template_class($_file, $_smarty);
|
||||||
$_tpl->caching = self::CACHING_OFF;
|
$_tpl->caching = self::CACHING_OFF;
|
||||||
$_tpl->source =
|
$_tpl->source =
|
||||||
@@ -1506,14 +1506,14 @@ class Smarty extends \Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* check client side cache
|
* check client side cache
|
||||||
*
|
*
|
||||||
* @param \Smarty_Template_Cached $cached
|
* @param \Smarty\Template\Cached $cached
|
||||||
* @param \Smarty_Internal_Template $_template
|
* @param \Smarty\Template $_template
|
||||||
* @param string $content
|
* @param string $content
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @throws \SmartyException
|
* @throws \SmartyException
|
||||||
*/
|
*/
|
||||||
public function cacheModifiedCheck(\Smarty_Template_Cached $cached, \Smarty_Internal_Template $_template, $content)
|
public function cacheModifiedCheck(Template\Cached $cached, \Smarty\Template $_template, $content)
|
||||||
{
|
{
|
||||||
$_isCached = $_template->isCached() && !$_template->compiled->has_nocache_code;
|
$_isCached = $_template->isCached() && !$_template->compiled->has_nocache_code;
|
||||||
$_last_modified_date =
|
$_last_modified_date =
|
||||||
@@ -1569,12 +1569,12 @@ class Smarty extends \Smarty_Internal_TemplateBase
|
|||||||
*
|
*
|
||||||
* @param string $type the type of filter ('pre','post','output') which shall run
|
* @param string $type the type of filter ('pre','post','output') which shall run
|
||||||
* @param string $content the content which shall be processed by the filters
|
* @param string $content the content which shall be processed by the filters
|
||||||
* @param Smarty_Internal_Template $template template object
|
* @param Template $template template object
|
||||||
*
|
*
|
||||||
* @throws SmartyException
|
|
||||||
* @return string the filtered content
|
* @return string the filtered content
|
||||||
|
*@throws SmartyException
|
||||||
*/
|
*/
|
||||||
public function runFilter($type, $content, Smarty_Internal_Template $template)
|
public function runFilter($type, $content, Template $template)
|
||||||
{
|
{
|
||||||
// loop over registered filters of specified type
|
// loop over registered filters of specified type
|
||||||
if (!empty($this->registered_filters[ $type ])) {
|
if (!empty($this->registered_filters[ $type ])) {
|
||||||
|
910
src/Template.php
Normal file
910
src/Template.php
Normal file
@@ -0,0 +1,910 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Smarty Internal Plugin Template
|
||||||
|
* This file contains the Smarty template engine
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage Template
|
||||||
|
* @author Uwe Tews
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Smarty;
|
||||||
|
|
||||||
|
use Smarty;
|
||||||
|
use Smarty\Runtime\InheritanceRuntime;
|
||||||
|
use Smarty\Template\Source;
|
||||||
|
use Smarty\Template\Cached;
|
||||||
|
use Smarty\Template\Compiled;
|
||||||
|
use Smarty\Template\Config;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main class with template data structures and methods
|
||||||
|
*
|
||||||
|
* @property Compiled $compiled
|
||||||
|
* @property Cached $cached
|
||||||
|
* @property \Smarty\Compiler\Template $compiler
|
||||||
|
* @property mixed|\Smarty\Template\Cached registered_plugins
|
||||||
|
*/
|
||||||
|
#[\AllowDynamicProperties]
|
||||||
|
class Template extends TemplateBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template object cache
|
||||||
|
*
|
||||||
|
* @var Template[]
|
||||||
|
*/
|
||||||
|
public static $tplObjCache = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template object cache for Smarty::isCached() === true
|
||||||
|
*
|
||||||
|
* @var Template[]
|
||||||
|
*/
|
||||||
|
public static $isCacheTplObj = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sub template Info Cache
|
||||||
|
* - index name
|
||||||
|
* - value use count
|
||||||
|
*
|
||||||
|
* @var int[]
|
||||||
|
*/
|
||||||
|
public static $subTplInfo = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This object type (Smarty = 1, template = 2, data = 4)
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $_objType = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source instance
|
||||||
|
*
|
||||||
|
* @var Source|Config
|
||||||
|
*/
|
||||||
|
public $source = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inheritance runtime extension
|
||||||
|
*
|
||||||
|
* @var InheritanceRuntime
|
||||||
|
*/
|
||||||
|
public $inheritance = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template resource
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $template_resource = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* flag if compiled template is invalid and must be (re)compiled
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $mustCompile = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template Id
|
||||||
|
*
|
||||||
|
* @var null|string
|
||||||
|
*/
|
||||||
|
public $templateId = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope in which variables shall be assigned
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $scope = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag which is set while rending a cache file
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $isRenderingCache = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callbacks called before rendering template
|
||||||
|
*
|
||||||
|
* @var callback[]
|
||||||
|
*/
|
||||||
|
public $startRenderCallbacks = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callbacks called after rendering template
|
||||||
|
*
|
||||||
|
* @var callback[]
|
||||||
|
*/
|
||||||
|
public $endRenderCallbacks = [];
|
||||||
|
/**
|
||||||
|
* @var \Smarty\Compiler\CodeFrame
|
||||||
|
*/
|
||||||
|
private $codeFrameCompiler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create template data object
|
||||||
|
* Some of the global Smarty settings copied to template scope
|
||||||
|
* It load the required template resources and caching plugins
|
||||||
|
*
|
||||||
|
* @param string $template_resource template resource string
|
||||||
|
* @param Smarty $smarty Smarty instance
|
||||||
|
* @param null|\Smarty_Internal_Template|\Smarty|\Smarty\Data $_parent back pointer to parent
|
||||||
|
* object with variables or
|
||||||
|
* null
|
||||||
|
* @param mixed $_cache_id cache id or null
|
||||||
|
* @param mixed $_compile_id compile id or null
|
||||||
|
* @param bool|int|null $_caching use caching?
|
||||||
|
* @param int|null $_cache_lifetime cache life-time in
|
||||||
|
* seconds
|
||||||
|
* @param bool $_isConfig
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
$template_resource,
|
||||||
|
Smarty $smarty,
|
||||||
|
\Smarty\Data $_parent = null,
|
||||||
|
$_cache_id = null,
|
||||||
|
$_compile_id = null,
|
||||||
|
$_caching = null,
|
||||||
|
$_cache_lifetime = null,
|
||||||
|
$_isConfig = false
|
||||||
|
) {
|
||||||
|
$this->smarty = $smarty;
|
||||||
|
// Smarty parameter
|
||||||
|
$this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
|
||||||
|
$this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
|
||||||
|
$this->caching = (int)($_caching === null ? $this->smarty->caching : $_caching);
|
||||||
|
$this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime;
|
||||||
|
$this->compile_check = (int)$smarty->compile_check;
|
||||||
|
$this->parent = $_parent;
|
||||||
|
// Template resource
|
||||||
|
$this->template_resource = $template_resource;
|
||||||
|
$this->source = $_isConfig ? Config::load($this) : Source::load($this);
|
||||||
|
parent::__construct();
|
||||||
|
if ($smarty->security_policy && method_exists($smarty->security_policy, 'registerCallBacks')) {
|
||||||
|
$smarty->security_policy->registerCallBacks($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->codeFrameCompiler = new Smarty\Compiler\CodeFrame($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* render template
|
||||||
|
*
|
||||||
|
* @param bool $no_output_filter if true do not run output filter
|
||||||
|
* @param null|bool $display true: display, false: fetch null: sub-template
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function render($no_output_filter = true, $display = null) {
|
||||||
|
if ($this->smarty->debugging) {
|
||||||
|
if (!isset($this->smarty->_debug)) {
|
||||||
|
$this->smarty->_debug = new \Smarty\Debug();
|
||||||
|
}
|
||||||
|
$this->smarty->_debug->start_template($this, $display);
|
||||||
|
}
|
||||||
|
// checks if template exists
|
||||||
|
if (!$this->source->exists) {
|
||||||
|
throw new SmartyException(
|
||||||
|
"Unable to load template '{$this->source->type}:{$this->source->name}'" .
|
||||||
|
($this->_isSubTpl() ? " in '{$this->parent->template_resource}'" : '')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// disable caching for evaluated code
|
||||||
|
if ($this->source->handler->recompiled) {
|
||||||
|
$this->caching = \Smarty\Smarty::CACHING_OFF;
|
||||||
|
}
|
||||||
|
// read from cache or render
|
||||||
|
if ($this->caching === \Smarty\Smarty::CACHING_LIFETIME_CURRENT || $this->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED) {
|
||||||
|
if (!isset($this->cached) || $this->cached->cache_id !== $this->cache_id
|
||||||
|
|| $this->cached->compile_id !== $this->compile_id
|
||||||
|
) {
|
||||||
|
$this->loadCached(true);
|
||||||
|
}
|
||||||
|
$this->cached->render($this, $no_output_filter);
|
||||||
|
} else {
|
||||||
|
if (!isset($this->compiled) || $this->compiled->compile_id !== $this->compile_id) {
|
||||||
|
$this->loadCompiled(true);
|
||||||
|
}
|
||||||
|
$this->compiled->render($this);
|
||||||
|
}
|
||||||
|
// display or fetch
|
||||||
|
if ($display) {
|
||||||
|
if ($this->caching && $this->smarty->cache_modified_check) {
|
||||||
|
$this->smarty->cacheModifiedCheck(
|
||||||
|
$this->cached,
|
||||||
|
$this,
|
||||||
|
isset($content) ? $content : ob_get_clean()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
|
||||||
|
&& !$no_output_filter && isset($this->smarty->registered_filters['output'])
|
||||||
|
) {
|
||||||
|
echo $this->smarty->runFilter('output', ob_get_clean(), $this);
|
||||||
|
} else {
|
||||||
|
echo ob_get_clean();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($this->smarty->debugging) {
|
||||||
|
$this->smarty->_debug->end_template($this);
|
||||||
|
// debug output
|
||||||
|
$this->smarty->_debug->display_debug($this, true);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
} else {
|
||||||
|
if ($this->smarty->debugging) {
|
||||||
|
$this->smarty->_debug->end_template($this);
|
||||||
|
if ($this->smarty->debugging === 2 && $display === false) {
|
||||||
|
$this->smarty->_debug->display_debug($this, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!$no_output_filter
|
||||||
|
&& (!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
|
||||||
|
&& isset($this->smarty->registered_filters['output'])
|
||||||
|
) {
|
||||||
|
return $this->smarty->runFilter('output', ob_get_clean(), $this);
|
||||||
|
}
|
||||||
|
// return cache content
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runtime function to render sub-template
|
||||||
|
*
|
||||||
|
* @param string $template template name
|
||||||
|
* @param mixed $cache_id cache id
|
||||||
|
* @param mixed $compile_id compile id
|
||||||
|
* @param integer $caching cache mode
|
||||||
|
* @param integer $cache_lifetime life time of cache data
|
||||||
|
* @param array $data passed parameter template variables
|
||||||
|
* @param int $scope scope in which {include} should execute
|
||||||
|
* @param bool $forceTplCache cache template object
|
||||||
|
* @param string $uid file dependency uid
|
||||||
|
* @param string $content_func function name
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function _subTemplateRender(
|
||||||
|
$template,
|
||||||
|
$cache_id,
|
||||||
|
$compile_id,
|
||||||
|
$caching,
|
||||||
|
$cache_lifetime,
|
||||||
|
$data,
|
||||||
|
$scope,
|
||||||
|
$forceTplCache,
|
||||||
|
$uid = null,
|
||||||
|
$content_func = null
|
||||||
|
) {
|
||||||
|
$tpl = clone $this;
|
||||||
|
$tpl->parent = $this;
|
||||||
|
$smarty = &$this->smarty;
|
||||||
|
$_templateId = $smarty->_getTemplateId($template, $cache_id, $compile_id, $caching, $tpl);
|
||||||
|
// recursive call ?
|
||||||
|
if ((isset($tpl->templateId) ? $tpl->templateId : $tpl->_getTemplateId()) !== $_templateId) {
|
||||||
|
// already in template cache?
|
||||||
|
if (isset(self::$tplObjCache[$_templateId])) {
|
||||||
|
// copy data from cached object
|
||||||
|
$cachedTpl = &self::$tplObjCache[$_templateId];
|
||||||
|
$tpl->templateId = $cachedTpl->templateId;
|
||||||
|
$tpl->template_resource = $cachedTpl->template_resource;
|
||||||
|
$tpl->cache_id = $cachedTpl->cache_id;
|
||||||
|
$tpl->compile_id = $cachedTpl->compile_id;
|
||||||
|
$tpl->source = $cachedTpl->source;
|
||||||
|
if (isset($cachedTpl->compiled)) {
|
||||||
|
$tpl->compiled = $cachedTpl->compiled;
|
||||||
|
} else {
|
||||||
|
unset($tpl->compiled);
|
||||||
|
}
|
||||||
|
if ($caching !== 9999 && isset($cachedTpl->cached)) {
|
||||||
|
$tpl->cached = $cachedTpl->cached;
|
||||||
|
} else {
|
||||||
|
unset($tpl->cached);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$tpl->templateId = $_templateId;
|
||||||
|
$tpl->template_resource = $template;
|
||||||
|
$tpl->cache_id = $cache_id;
|
||||||
|
$tpl->compile_id = $compile_id;
|
||||||
|
if (isset($uid)) {
|
||||||
|
// for inline templates we can get all resource information from file dependency
|
||||||
|
[$filepath, $timestamp, $type] = $tpl->compiled->file_dependency[$uid];
|
||||||
|
$tpl->source = new Source($smarty, $filepath, $type, $filepath);
|
||||||
|
$tpl->source->filepath = $filepath;
|
||||||
|
$tpl->source->timestamp = $timestamp;
|
||||||
|
$tpl->source->exists = true;
|
||||||
|
$tpl->source->uid = $uid;
|
||||||
|
} else {
|
||||||
|
$tpl->source = Source::load($tpl);
|
||||||
|
unset($tpl->compiled);
|
||||||
|
}
|
||||||
|
if ($caching !== 9999) {
|
||||||
|
unset($tpl->cached);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// on recursive calls force caching
|
||||||
|
$forceTplCache = true;
|
||||||
|
}
|
||||||
|
$tpl->caching = $caching;
|
||||||
|
$tpl->cache_lifetime = $cache_lifetime;
|
||||||
|
// set template scope
|
||||||
|
$tpl->scope = $scope;
|
||||||
|
if (!isset(self::$tplObjCache[$tpl->templateId]) && !$tpl->source->handler->recompiled) {
|
||||||
|
// check if template object should be cached
|
||||||
|
if ($forceTplCache || (isset(self::$subTplInfo[$tpl->template_resource])
|
||||||
|
&& self::$subTplInfo[$tpl->template_resource] > 1)
|
||||||
|
|| ($tpl->_isSubTpl() && isset(self::$tplObjCache[$tpl->parent->templateId]))
|
||||||
|
) {
|
||||||
|
self::$tplObjCache[$tpl->templateId] = $tpl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($data)) {
|
||||||
|
// set up variable values
|
||||||
|
foreach ($data as $_key => $_val) {
|
||||||
|
$tpl->tpl_vars[$_key] = new \Smarty\Variable($_val, $this->isRenderingCache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($tpl->caching === 9999) {
|
||||||
|
if (!isset($tpl->compiled)) {
|
||||||
|
$tpl->loadCompiled(true);
|
||||||
|
}
|
||||||
|
if ($tpl->compiled->has_nocache_code) {
|
||||||
|
$this->cached->hashes[$tpl->compiled->nocache_hash] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$tpl->_cache = [];
|
||||||
|
if (isset($uid)) {
|
||||||
|
if ($smarty->debugging) {
|
||||||
|
if (!isset($smarty->_debug)) {
|
||||||
|
$smarty->_debug = new \Smarty\Debug();
|
||||||
|
}
|
||||||
|
$smarty->_debug->start_template($tpl);
|
||||||
|
$smarty->_debug->start_render($tpl);
|
||||||
|
}
|
||||||
|
$tpl->compiled->getRenderedTemplateCode($tpl, $content_func);
|
||||||
|
if ($smarty->debugging) {
|
||||||
|
$smarty->_debug->end_template($tpl);
|
||||||
|
$smarty->_debug->end_render($tpl);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isset($tpl->compiled)) {
|
||||||
|
$tpl->compiled->render($tpl);
|
||||||
|
} else {
|
||||||
|
$tpl->render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get called sub-templates and save call count
|
||||||
|
*/
|
||||||
|
public function _subTemplateRegister() {
|
||||||
|
foreach ($this->compiled->includes as $name => $count) {
|
||||||
|
if (isset(self::$subTplInfo[$name])) {
|
||||||
|
self::$subTplInfo[$name] += $count;
|
||||||
|
} else {
|
||||||
|
self::$subTplInfo[$name] = $count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this is a sub template
|
||||||
|
*
|
||||||
|
* @return bool true is sub template
|
||||||
|
*/
|
||||||
|
public function _isSubTpl() {
|
||||||
|
return isset($this->parent) && $this->parent->_isTplObj();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign variable in scope
|
||||||
|
*
|
||||||
|
* @param string $varName variable name
|
||||||
|
* @param mixed $value value
|
||||||
|
* @param bool $nocache nocache flag
|
||||||
|
* @param int $scope scope into which variable shall be assigned
|
||||||
|
*/
|
||||||
|
public function _assignInScope($varName, $value, $nocache = false, $scope = 0) {
|
||||||
|
if (isset($this->tpl_vars[$varName])) {
|
||||||
|
$this->tpl_vars[$varName] = clone $this->tpl_vars[$varName];
|
||||||
|
$this->tpl_vars[$varName]->value = $value;
|
||||||
|
if ($nocache || $this->isRenderingCache) {
|
||||||
|
$this->tpl_vars[$varName]->nocache = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->tpl_vars[$varName] = new \Smarty\Variable($value, $nocache || $this->isRenderingCache);
|
||||||
|
}
|
||||||
|
if ($scope >= 0) {
|
||||||
|
if ($scope > 0 || $this->scope > 0) {
|
||||||
|
$this->_updateScope($varName, $scope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is executed automatically when a compiled or cached template file is included
|
||||||
|
* - Decode saved properties from compiled template and cache files
|
||||||
|
* - Check if compiled or cache file is valid
|
||||||
|
*
|
||||||
|
* @param \Smarty_Internal_Template $tpl
|
||||||
|
* @param array $properties special template properties
|
||||||
|
* @param bool $cache flag if called from cache file
|
||||||
|
*
|
||||||
|
* @return bool flag if compiled or cache file is valid
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function _decodeProperties(Template $tpl, $properties, $cache = false) {
|
||||||
|
// on cache resources other than file check version stored in cache code
|
||||||
|
if (!isset($properties['version']) || \Smarty\Smarty::SMARTY_VERSION !== $properties['version']) {
|
||||||
|
if ($cache) {
|
||||||
|
$tpl->smarty->clearAllCache();
|
||||||
|
} else {
|
||||||
|
$tpl->smarty->clearCompiledTemplate();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$is_valid = true;
|
||||||
|
if (!empty($properties['file_dependency'])
|
||||||
|
&& ((!$cache && $tpl->compile_check) || $tpl->compile_check === \Smarty\Smarty::COMPILECHECK_ON)
|
||||||
|
) {
|
||||||
|
// check file dependencies at compiled code
|
||||||
|
foreach ($properties['file_dependency'] as $_file_to_check) {
|
||||||
|
if ($_file_to_check[2] === 'file' || $_file_to_check[2] === 'php') {
|
||||||
|
if ($tpl->source->filepath === $_file_to_check[0]) {
|
||||||
|
// do not recheck current template
|
||||||
|
continue;
|
||||||
|
//$mtime = $tpl->source->getTimeStamp();
|
||||||
|
} else {
|
||||||
|
// file and php types can be checked without loading the respective resource handlers
|
||||||
|
$mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$handler = Smarty\Resource\BasePlugin::load($tpl->smarty, $_file_to_check[2]);
|
||||||
|
if ($handler->checkTimestamps()) {
|
||||||
|
$source = Source::load($tpl, $tpl->smarty, $_file_to_check[0]);
|
||||||
|
$mtime = $source->getTimeStamp();
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($mtime === false || $mtime > $_file_to_check[1]) {
|
||||||
|
$is_valid = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($cache) {
|
||||||
|
// CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
|
||||||
|
if ($tpl->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0
|
||||||
|
&& (time() > ($tpl->cached->timestamp + $properties['cache_lifetime']))
|
||||||
|
) {
|
||||||
|
$is_valid = false;
|
||||||
|
}
|
||||||
|
$tpl->cached->cache_lifetime = $properties['cache_lifetime'];
|
||||||
|
$tpl->cached->valid = $is_valid;
|
||||||
|
$resource = $tpl->cached;
|
||||||
|
} else {
|
||||||
|
$tpl->mustCompile = !$is_valid;
|
||||||
|
$resource = $tpl->compiled;
|
||||||
|
$resource->includes = isset($properties['includes']) ? $properties['includes'] : [];
|
||||||
|
}
|
||||||
|
if ($is_valid) {
|
||||||
|
$resource->unifunc = $properties['unifunc'];
|
||||||
|
$resource->has_nocache_code = $properties['has_nocache_code'];
|
||||||
|
$resource->file_dependency = $properties['file_dependency'];
|
||||||
|
}
|
||||||
|
return $is_valid && !function_exists($properties['unifunc']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiles the template
|
||||||
|
* If the template is not evaluated the compiled template is saved on disk
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function compileTemplateSource() {
|
||||||
|
return $this->compiled->compileTemplateSource($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the content to cache resource
|
||||||
|
*
|
||||||
|
* @param string $content
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function writeCachedContent($content) {
|
||||||
|
if ($this->source->handler->recompiled || !$this->caching
|
||||||
|
) {
|
||||||
|
// don't write cache file
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!isset($this->cached)) {
|
||||||
|
$this->loadCached();
|
||||||
|
}
|
||||||
|
$codeframe = $this->createCodeFrame($content, '', true);
|
||||||
|
return $this->cached->writeCache($this, $codeframe);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get unique template id
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function _getTemplateId() {
|
||||||
|
return $this->templateId ?? $this->templateId =
|
||||||
|
$this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* runtime error not matching capture tags
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function capture_error() {
|
||||||
|
throw new SmartyException("Not matching {capture} open/close in '{$this->template_resource}'");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load compiled object
|
||||||
|
*
|
||||||
|
* @param bool $force force new compiled object
|
||||||
|
*/
|
||||||
|
public function loadCompiled($force = false) {
|
||||||
|
if ($force || !isset($this->compiled)) {
|
||||||
|
$this->compiled = Compiled::load($this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load cached object
|
||||||
|
*
|
||||||
|
* @param bool $force force new cached object
|
||||||
|
*/
|
||||||
|
public function loadCached($force = false) {
|
||||||
|
if ($force || !isset($this->cached)) {
|
||||||
|
$this->cached = Cached::load($this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load inheritance object
|
||||||
|
*/
|
||||||
|
public function _loadInheritance() {
|
||||||
|
if (!isset($this->inheritance)) {
|
||||||
|
$this->inheritance = new InheritanceRuntime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unload inheritance object
|
||||||
|
*/
|
||||||
|
public function _cleanUp() {
|
||||||
|
$this->startRenderCallbacks = [];
|
||||||
|
$this->endRenderCallbacks = [];
|
||||||
|
$this->inheritance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load compiler object
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function loadCompiler() {
|
||||||
|
$this->compiler =
|
||||||
|
new $this->source->compiler_class(
|
||||||
|
$this->source->template_lexer_class,
|
||||||
|
$this->source->template_parser_class,
|
||||||
|
$this->smarty
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create code frame for compiled and cached templates
|
||||||
|
*
|
||||||
|
* @param string $content optional template content
|
||||||
|
* @param string $functions compiled template function and block code
|
||||||
|
* @param bool $cache flag for cache file
|
||||||
|
* @param \Smarty\Compiler\Template $compiler
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function createCodeFrame($content = '', $functions = '', $cache = false, \Smarty\Compiler\Template $compiler = null) {
|
||||||
|
return $this->codeFrameCompiler->create($content, $functions, $cache, $compiler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle unknown class methods
|
||||||
|
*
|
||||||
|
* @param string $name unknown method-name
|
||||||
|
* @param array $args argument array
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function __call($name, $args) {
|
||||||
|
// method of Smarty object?
|
||||||
|
if (method_exists($this->smarty, $name)) {
|
||||||
|
return call_user_func_array([$this->smarty, $name], $args);
|
||||||
|
}
|
||||||
|
// parent
|
||||||
|
return parent::__call($name, $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get Smarty property in template context
|
||||||
|
*
|
||||||
|
* @param string $property_name property name
|
||||||
|
*
|
||||||
|
* @return mixed|Cached
|
||||||
|
* @throws SmartyException
|
||||||
|
*/
|
||||||
|
public function __get($property_name) {
|
||||||
|
switch ($property_name) {
|
||||||
|
case 'compiled':
|
||||||
|
$this->loadCompiled();
|
||||||
|
return $this->compiled;
|
||||||
|
case 'cached':
|
||||||
|
$this->loadCached();
|
||||||
|
return $this->cached;
|
||||||
|
case 'compiler':
|
||||||
|
$this->loadCompiler();
|
||||||
|
return $this->compiler;
|
||||||
|
default:
|
||||||
|
// Smarty property ?
|
||||||
|
if (property_exists($this->smarty, $property_name)) {
|
||||||
|
return $this->smarty->$property_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new SmartyException("template property '$property_name' does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set Smarty property in template context
|
||||||
|
*
|
||||||
|
* @param string $property_name property name
|
||||||
|
* @param mixed $value value
|
||||||
|
*
|
||||||
|
* @throws SmartyException
|
||||||
|
*/
|
||||||
|
public function __set($property_name, $value) {
|
||||||
|
switch ($property_name) {
|
||||||
|
case 'compiled':
|
||||||
|
case 'cached':
|
||||||
|
case 'compiler':
|
||||||
|
$this->$property_name = $value;
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
// Smarty property ?
|
||||||
|
if (property_exists($this->smarty, $property_name)) {
|
||||||
|
$this->smarty->$property_name = $value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new SmartyException("invalid template property '$property_name'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template data object destructor
|
||||||
|
*/
|
||||||
|
public function __destruct() {
|
||||||
|
if ($this->smarty->cache_locking && isset($this->cached) && $this->cached->is_locked) {
|
||||||
|
$this->cached->handler->releaseLock($this->smarty, $this->cached);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* load config variables into template object
|
||||||
|
*
|
||||||
|
* @param \Smarty_Internal_Template $tpl
|
||||||
|
* @param array $new_config_vars
|
||||||
|
*/
|
||||||
|
public function _loadConfigVars($new_config_vars) {
|
||||||
|
$this->_assignConfigVars($this->parent->config_vars, $new_config_vars);
|
||||||
|
$tagScope = $this->source->scope;
|
||||||
|
if ($tagScope >= 0) {
|
||||||
|
if ($tagScope === \Smarty\Smarty::SCOPE_LOCAL) {
|
||||||
|
$this->_updateConfigVarStack($new_config_vars);
|
||||||
|
$tagScope = 0;
|
||||||
|
if (!$this->scope) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($this->parent->_isTplObj() && ($tagScope || $this->parent->scope)) {
|
||||||
|
$mergedScope = $tagScope | $this->scope;
|
||||||
|
if ($mergedScope) {
|
||||||
|
// update scopes
|
||||||
|
/* @var \Smarty_Internal_Template|\Smarty|Data $ptr */
|
||||||
|
foreach ($this->parent->_getAffectedScopes($mergedScope) as $ptr) {
|
||||||
|
$this->_assignConfigVars($ptr->config_vars, $new_config_vars);
|
||||||
|
if ($tagScope && $ptr->_isTplObj() && isset($this->_var_stack)) {
|
||||||
|
$this->_updateConfigVarStack($new_config_vars);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign all config variables in given scope
|
||||||
|
*
|
||||||
|
* @param array $config_vars config variables in scope
|
||||||
|
* @param array $new_config_vars loaded config variables
|
||||||
|
*/
|
||||||
|
private function _assignConfigVars(&$config_vars, $new_config_vars) {
|
||||||
|
// copy global config vars
|
||||||
|
foreach ($new_config_vars['vars'] as $variable => $value) {
|
||||||
|
if ($this->smarty->config_overwrite || !isset($config_vars[$variable])) {
|
||||||
|
$config_vars[$variable] = $value;
|
||||||
|
} else {
|
||||||
|
$config_vars[$variable] = array_merge((array)$config_vars[$variable], (array)$value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// scan sections
|
||||||
|
$sections = $this->source->config_sections;
|
||||||
|
if (!empty($sections)) {
|
||||||
|
foreach ((array)$sections as $tpl_section) {
|
||||||
|
if (isset($new_config_vars['sections'][$tpl_section])) {
|
||||||
|
foreach ($new_config_vars['sections'][$tpl_section]['vars'] as $variable => $value) {
|
||||||
|
if ($this->smarty->config_overwrite || !isset($config_vars[$variable])) {
|
||||||
|
$config_vars[$variable] = $value;
|
||||||
|
} else {
|
||||||
|
$config_vars[$variable] = array_merge((array)$config_vars[$variable], (array)$value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update config variables in template local variable stack
|
||||||
|
*
|
||||||
|
* @param array $config_vars
|
||||||
|
*/
|
||||||
|
private function _updateConfigVarStack($config_vars) {
|
||||||
|
$i = 0;
|
||||||
|
while (isset($this->_var_stack[$i])) {
|
||||||
|
$this->_assignConfigVars($this->_var_stack[$i]['config'], $config_vars);
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if the current template must be compiled by the Smarty compiler
|
||||||
|
* It does compare the timestamps of template source and the compiled templates and checks the force compile
|
||||||
|
* configuration
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function mustCompile() {
|
||||||
|
if (!$this->source->exists) {
|
||||||
|
if ($this->_isSubTpl()) {
|
||||||
|
$parent_resource = " in '{$this->parent->template_resource}'";
|
||||||
|
} else {
|
||||||
|
$parent_resource = '';
|
||||||
|
}
|
||||||
|
throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
|
||||||
|
}
|
||||||
|
if ($this->mustCompile === null) {
|
||||||
|
$this->mustCompile = (!$this->source->handler->uncompiled &&
|
||||||
|
($this->smarty->force_compile || $this->source->handler->recompiled ||
|
||||||
|
!$this->compiled->exists || ($this->compile_check &&
|
||||||
|
$this->compiled->getTimeStamp() <
|
||||||
|
$this->source->getTimeStamp())));
|
||||||
|
}
|
||||||
|
return $this->mustCompile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update new assigned template or config variable in other effected scopes
|
||||||
|
*
|
||||||
|
* @param string|null $varName variable name
|
||||||
|
* @param int $tagScope tag scope to which bubble up variable value
|
||||||
|
*/
|
||||||
|
protected function _updateScope($varName, $tagScope = 0) {
|
||||||
|
if ($tagScope) {
|
||||||
|
$this->_updateVarStack($this, $varName);
|
||||||
|
$tagScope = $tagScope & ~\Smarty\Smarty::SCOPE_LOCAL;
|
||||||
|
if (!$this->scope && !$tagScope) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$mergedScope = $tagScope | $this->scope;
|
||||||
|
if ($mergedScope) {
|
||||||
|
if ($mergedScope & \Smarty\Smarty::SCOPE_GLOBAL && $varName) {
|
||||||
|
\Smarty\Smarty::$global_tpl_vars[$varName] = $this->tpl_vars[$varName];
|
||||||
|
}
|
||||||
|
// update scopes
|
||||||
|
foreach ($this->_getAffectedScopes($mergedScope) as $ptr) {
|
||||||
|
$this->_updateVariableInOtherScope($ptr->tpl_vars, $varName);
|
||||||
|
if ($tagScope && $ptr->_isTplObj() && isset($this->_var_stack)) {
|
||||||
|
$this->_updateVarStack($ptr, $varName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get array of objects which needs to be updated by given scope value
|
||||||
|
*
|
||||||
|
* @param int $mergedScope merged tag and template scope to which bubble up variable value
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function _getAffectedScopes($mergedScope) {
|
||||||
|
$_stack = [];
|
||||||
|
$ptr = $this->parent;
|
||||||
|
if ($mergedScope && isset($ptr) && $ptr->_isTplObj()) {
|
||||||
|
$_stack[] = $ptr;
|
||||||
|
$mergedScope = $mergedScope & ~\Smarty\Smarty::SCOPE_PARENT;
|
||||||
|
if (!$mergedScope) {
|
||||||
|
// only parent was set, we are done
|
||||||
|
return $_stack;
|
||||||
|
}
|
||||||
|
$ptr = $ptr->parent;
|
||||||
|
}
|
||||||
|
while (isset($ptr) && $ptr->_isTplObj()) {
|
||||||
|
$_stack[] = $ptr;
|
||||||
|
$ptr = $ptr->parent;
|
||||||
|
}
|
||||||
|
if ($mergedScope & \Smarty\Smarty::SCOPE_SMARTY) {
|
||||||
|
if (isset($this->smarty)) {
|
||||||
|
$_stack[] = $this->smarty;
|
||||||
|
}
|
||||||
|
} elseif ($mergedScope & \Smarty\Smarty::SCOPE_ROOT) {
|
||||||
|
while (isset($ptr)) {
|
||||||
|
if (!$ptr->_isTplObj()) {
|
||||||
|
$_stack[] = $ptr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$ptr = $ptr->parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $_stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update variable in other scope
|
||||||
|
*
|
||||||
|
* @param array $tpl_vars template variable array
|
||||||
|
* @param string $varName variable name
|
||||||
|
*/
|
||||||
|
private function _updateVariableInOtherScope(&$tpl_vars, $varName) {
|
||||||
|
if (!isset($tpl_vars[$varName])) {
|
||||||
|
$tpl_vars[$varName] = clone $this->tpl_vars[$varName];
|
||||||
|
} else {
|
||||||
|
$tpl_vars[$varName] = clone $tpl_vars[$varName];
|
||||||
|
$tpl_vars[$varName]->value = $this->tpl_vars[$varName]->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update variable in template local variable stack
|
||||||
|
*
|
||||||
|
* @param \Smarty_Internal_Template $tpl
|
||||||
|
* @param string|null $varName variable name or null for config variables
|
||||||
|
*/
|
||||||
|
private function _updateVarStack(Template $tpl, $varName) {
|
||||||
|
$i = 0;
|
||||||
|
while (isset($tpl->_var_stack[$i])) {
|
||||||
|
$this->_updateVariableInOtherScope($tpl->_var_stack[$i]['tpl'], $varName);
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
379
src/Template/Cached.php
Normal file
379
src/Template/Cached.php
Normal file
@@ -0,0 +1,379 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Smarty\Template;
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
use Smarty\Template\ResourceBase;
|
||||||
|
use Smarty\Template\Source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty Resource Data Object
|
||||||
|
* Cache Data Container for Template Files
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage TemplateResources
|
||||||
|
* @author Rodney Rehm
|
||||||
|
*/
|
||||||
|
class Cached extends ResourceBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache Is Valid
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
public $valid = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CacheResource Handler
|
||||||
|
*
|
||||||
|
* @var \Smarty\Cacheresource\Base
|
||||||
|
*/
|
||||||
|
public $handler = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template Cache Id (\Smarty\Template::$cache_id)
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $cache_id = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saved cache lifetime in seconds
|
||||||
|
*
|
||||||
|
* @var integer
|
||||||
|
*/
|
||||||
|
public $cache_lifetime = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Id for cache locking
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $lock_id = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* flag that cache is locked by this instance
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $is_locked = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source Object
|
||||||
|
*
|
||||||
|
* @var Source
|
||||||
|
*/
|
||||||
|
public $source = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nocache hash codes of processed compiled templates
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $hashes = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag if this is a cache resource
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $isCache = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create Cached Object container
|
||||||
|
*
|
||||||
|
* @param Template $_template template object
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function __construct(Template $_template) {
|
||||||
|
$this->compile_id = $_template->compile_id;
|
||||||
|
$this->cache_id = $_template->cache_id;
|
||||||
|
$this->source = $_template->source;
|
||||||
|
$this->handler = \Smarty\Cacheresource\Base::load($_template->smarty);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Template $_template
|
||||||
|
*
|
||||||
|
* @return Cached
|
||||||
|
*/
|
||||||
|
public static function load(Template $_template) {
|
||||||
|
$_template->cached = new Cached($_template);
|
||||||
|
$_template->cached->handler->populate($_template->cached, $_template);
|
||||||
|
// caching enabled ?
|
||||||
|
if (!$_template->caching || $_template->source->handler->recompiled
|
||||||
|
) {
|
||||||
|
$_template->cached->valid = false;
|
||||||
|
}
|
||||||
|
return $_template->cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render cache template
|
||||||
|
*
|
||||||
|
* @param \Smarty\Template $_template
|
||||||
|
* @param bool $no_output_filter
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function render(Template $_template, $no_output_filter = true) {
|
||||||
|
if ($this->isCached($_template)) {
|
||||||
|
if ($_template->smarty->debugging) {
|
||||||
|
if (!isset($_template->smarty->_debug)) {
|
||||||
|
$_template->smarty->_debug = new \Smarty\Debug();
|
||||||
|
}
|
||||||
|
$_template->smarty->_debug->start_cache($_template);
|
||||||
|
}
|
||||||
|
if (!$this->processed) {
|
||||||
|
$this->process($_template);
|
||||||
|
}
|
||||||
|
$this->getRenderedTemplateCode($_template);
|
||||||
|
if ($_template->smarty->debugging) {
|
||||||
|
$_template->smarty->_debug->end_cache($_template);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
$this->updateCache($_template, $no_output_filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if cache is valid, lock cache if required
|
||||||
|
*
|
||||||
|
* @param \Smarty\Template $_template
|
||||||
|
*
|
||||||
|
* @return bool flag true if cache is valid
|
||||||
|
*/
|
||||||
|
public function isCached(Template $_template) {
|
||||||
|
if ($this->valid !== null) {
|
||||||
|
return $this->valid;
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
while (true) {
|
||||||
|
if ($this->exists === false || $_template->smarty->force_compile || $_template->smarty->force_cache) {
|
||||||
|
$this->valid = false;
|
||||||
|
} else {
|
||||||
|
$this->valid = true;
|
||||||
|
}
|
||||||
|
if ($this->valid && $_template->caching === \Smarty\Smarty::CACHING_LIFETIME_CURRENT
|
||||||
|
&& $_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)
|
||||||
|
) {
|
||||||
|
// lifetime expired
|
||||||
|
$this->valid = false;
|
||||||
|
}
|
||||||
|
if ($this->valid && $_template->compile_check === \Smarty\Smarty::COMPILECHECK_ON
|
||||||
|
&& $_template->source->getTimeStamp() > $this->timestamp
|
||||||
|
) {
|
||||||
|
$this->valid = false;
|
||||||
|
}
|
||||||
|
if ($this->valid || !$_template->smarty->cache_locking) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!$this->handler->locked($_template->smarty, $this)) {
|
||||||
|
$this->handler->acquireLock($_template->smarty, $this);
|
||||||
|
break 2;
|
||||||
|
}
|
||||||
|
$this->handler->populate($this, $_template);
|
||||||
|
}
|
||||||
|
if ($this->valid) {
|
||||||
|
if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) {
|
||||||
|
// load cache file for the following checks
|
||||||
|
if ($_template->smarty->debugging) {
|
||||||
|
$_template->smarty->_debug->start_cache($_template);
|
||||||
|
}
|
||||||
|
if ($this->handler->process($_template, $this) === false) {
|
||||||
|
$this->valid = false;
|
||||||
|
} else {
|
||||||
|
$this->processed = true;
|
||||||
|
}
|
||||||
|
if ($_template->smarty->debugging) {
|
||||||
|
$_template->smarty->_debug->end_cache($_template);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->is_locked = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->valid;
|
||||||
|
}
|
||||||
|
if ($this->valid && $_template->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED
|
||||||
|
&& $_template->cached->cache_lifetime >= 0
|
||||||
|
&& (time() > ($_template->cached->timestamp + $_template->cached->cache_lifetime))
|
||||||
|
) {
|
||||||
|
$this->valid = false;
|
||||||
|
}
|
||||||
|
if ($_template->smarty->cache_locking) {
|
||||||
|
if (!$this->valid) {
|
||||||
|
$this->handler->acquireLock($_template->smarty, $this);
|
||||||
|
} elseif ($this->is_locked) {
|
||||||
|
$this->handler->releaseLock($_template->smarty, $this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->valid;
|
||||||
|
}
|
||||||
|
return $this->valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process cached template
|
||||||
|
*
|
||||||
|
* @param Template $_template template object
|
||||||
|
* @param bool $update flag if called because cache update
|
||||||
|
*/
|
||||||
|
public function process(Template $_template, $update = false) {
|
||||||
|
if ($this->handler->process($_template, $this, $update) === false) {
|
||||||
|
$this->valid = false;
|
||||||
|
}
|
||||||
|
if ($this->valid) {
|
||||||
|
$this->processed = true;
|
||||||
|
} else {
|
||||||
|
$this->processed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read cache content from handler
|
||||||
|
*
|
||||||
|
* @param Template $_template template object
|
||||||
|
*
|
||||||
|
* @return string|false content
|
||||||
|
*/
|
||||||
|
public function readCache(Template $_template) {
|
||||||
|
if (!$_template->source->handler->recompiled) {
|
||||||
|
return $this->handler->retrieveCachedContent($_template);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write this cache object to handler
|
||||||
|
*
|
||||||
|
* @param string $content content to cache
|
||||||
|
*
|
||||||
|
* @return bool success
|
||||||
|
*/
|
||||||
|
public function writeCache(Template $_template, $content) {
|
||||||
|
if (!$_template->source->handler->recompiled) {
|
||||||
|
if ($this->handler->storeCachedContent($_template, $content)) {
|
||||||
|
$this->content = null;
|
||||||
|
$this->timestamp = time();
|
||||||
|
$this->exists = true;
|
||||||
|
$this->valid = true;
|
||||||
|
$this->cache_lifetime = $_template->cache_lifetime;
|
||||||
|
$this->processed = false;
|
||||||
|
if ($_template->smarty->cache_locking) {
|
||||||
|
$this->handler->releaseLock($_template->smarty, $this);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$this->content = null;
|
||||||
|
$this->timestamp = false;
|
||||||
|
$this->exists = false;
|
||||||
|
$this->valid = false;
|
||||||
|
$this->processed = false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache was invalid , so render from compiled and write to cache
|
||||||
|
*
|
||||||
|
* @param Template $_template
|
||||||
|
* @param bool $no_output_filter
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function updateCache(Template $_template, $no_output_filter) {
|
||||||
|
ob_start();
|
||||||
|
if (!isset($_template->compiled)) {
|
||||||
|
$_template->loadCompiled();
|
||||||
|
}
|
||||||
|
$_template->compiled->render($_template);
|
||||||
|
if ($_template->smarty->debugging) {
|
||||||
|
$_template->smarty->_debug->start_cache($_template);
|
||||||
|
}
|
||||||
|
$this->removeNoCacheHash($_template, $no_output_filter);
|
||||||
|
$compile_check = (int)$_template->compile_check;
|
||||||
|
$_template->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
|
||||||
|
if ($_template->_isSubTpl()) {
|
||||||
|
$_template->compiled->unifunc = $_template->parent->compiled->unifunc;
|
||||||
|
}
|
||||||
|
if (!$_template->cached->processed) {
|
||||||
|
$_template->cached->process($_template, true);
|
||||||
|
}
|
||||||
|
$_template->compile_check = $compile_check;
|
||||||
|
$this->getRenderedTemplateCode($_template);
|
||||||
|
if ($_template->smarty->debugging) {
|
||||||
|
$_template->smarty->_debug->end_cache($_template);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize content and write it to cache resource
|
||||||
|
*
|
||||||
|
* @param Template $_template
|
||||||
|
* @param bool $no_output_filter
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
private function removeNoCacheHash(Template $_template, $no_output_filter) {
|
||||||
|
$php_pattern = '/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/';
|
||||||
|
$content = ob_get_clean();
|
||||||
|
$hash_array = $this->hashes;
|
||||||
|
$hash_array[$_template->compiled->nocache_hash] = true;
|
||||||
|
$hash_array = array_keys($hash_array);
|
||||||
|
$nocache_hash = '(' . implode('|', $hash_array) . ')';
|
||||||
|
$_template->cached->has_nocache_code = false;
|
||||||
|
// get text between non-cached items
|
||||||
|
$cache_split =
|
||||||
|
preg_split(
|
||||||
|
"!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s",
|
||||||
|
$content
|
||||||
|
);
|
||||||
|
// get non-cached items
|
||||||
|
preg_match_all(
|
||||||
|
"!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s",
|
||||||
|
$content,
|
||||||
|
$cache_parts
|
||||||
|
);
|
||||||
|
$content = '';
|
||||||
|
// loop over items, stitch back together
|
||||||
|
foreach ($cache_split as $curr_idx => $curr_split) {
|
||||||
|
if (preg_match($php_pattern, $curr_split)) {
|
||||||
|
// escape PHP tags in template content
|
||||||
|
$php_split = preg_split(
|
||||||
|
$php_pattern,
|
||||||
|
$curr_split
|
||||||
|
);
|
||||||
|
preg_match_all(
|
||||||
|
$php_pattern,
|
||||||
|
$curr_split,
|
||||||
|
$php_parts
|
||||||
|
);
|
||||||
|
foreach ($php_split as $idx_php => $curr_php) {
|
||||||
|
$content .= $curr_php;
|
||||||
|
if (isset($php_parts[0][$idx_php])) {
|
||||||
|
$content .= "<?php echo '{$php_parts[ 1 ][ $idx_php ]}'; ?>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$content .= $curr_split;
|
||||||
|
}
|
||||||
|
if (isset($cache_parts[0][$curr_idx])) {
|
||||||
|
$_template->cached->has_nocache_code = true;
|
||||||
|
$content .= $cache_parts[2][$curr_idx];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!$no_output_filter
|
||||||
|
&& !$_template->cached->has_nocache_code
|
||||||
|
&& isset($_template->smarty->registered_filters['output'])
|
||||||
|
) {
|
||||||
|
$content = $_template->smarty->runFilter('output', $content, $_template);
|
||||||
|
}
|
||||||
|
// write cache file content
|
||||||
|
$_template->writeCachedContent($content);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
253
src/Template/Compiled.php
Normal file
253
src/Template/Compiled.php
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Smarty\Template;
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty Resource Data Object
|
||||||
|
* Meta Data Container for Template Files
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage TemplateResources
|
||||||
|
* @author Rodney Rehm
|
||||||
|
* @property string $content compiled content
|
||||||
|
*/
|
||||||
|
class Compiled extends ResourceBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nocache hash
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
public $nocache_hash = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get a Compiled Object of this source
|
||||||
|
*
|
||||||
|
* @param Template $_template template object
|
||||||
|
*
|
||||||
|
* @return Compiled compiled object
|
||||||
|
*/
|
||||||
|
public static function load($_template) {
|
||||||
|
$compiled = new Compiled();
|
||||||
|
if ($_template->source->handler->hasCompiledHandler) {
|
||||||
|
$_template->source->handler->populateCompiledFilepath($compiled, $_template);
|
||||||
|
} else {
|
||||||
|
$compiled->populateCompiledFilepath($_template);
|
||||||
|
}
|
||||||
|
return $compiled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* populate Compiled Object with compiled filepath
|
||||||
|
*
|
||||||
|
* @param Template $_template template object
|
||||||
|
**/
|
||||||
|
public function populateCompiledFilepath(Template $_template) {
|
||||||
|
$source = &$_template->source;
|
||||||
|
$smarty = &$_template->smarty;
|
||||||
|
$this->filepath = $smarty->getCompileDir();
|
||||||
|
if (isset($_template->compile_id)) {
|
||||||
|
$this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) .
|
||||||
|
($smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^');
|
||||||
|
}
|
||||||
|
// if use_sub_dirs, break file into directories
|
||||||
|
if ($smarty->use_sub_dirs) {
|
||||||
|
$this->filepath .= $source->uid[0] . $source->uid[1] . DIRECTORY_SEPARATOR . $source->uid[2] .
|
||||||
|
$source->uid[3] . DIRECTORY_SEPARATOR . $source->uid[4] . $source->uid[5] .
|
||||||
|
DIRECTORY_SEPARATOR;
|
||||||
|
}
|
||||||
|
$this->filepath .= $source->uid . '_';
|
||||||
|
if ($source->isConfig) {
|
||||||
|
$this->filepath .= (int)$smarty->config_read_hidden + (int)$smarty->config_booleanize * 2 +
|
||||||
|
(int)$smarty->config_overwrite * 4;
|
||||||
|
} else {
|
||||||
|
$this->filepath .= (int)$smarty->merge_compiled_includes + (int)$smarty->escape_html * 2 +
|
||||||
|
(($smarty->merge_compiled_includes && $source->type === 'extends') ?
|
||||||
|
(int)$smarty->extends_recursion * 4 : 0);
|
||||||
|
}
|
||||||
|
$this->filepath .= '.' . $source->type;
|
||||||
|
$basename = $source->handler->getBasename($source);
|
||||||
|
if (!empty($basename)) {
|
||||||
|
$this->filepath .= '.' . $basename;
|
||||||
|
}
|
||||||
|
if ($_template->caching) {
|
||||||
|
$this->filepath .= '.cache';
|
||||||
|
}
|
||||||
|
$this->filepath .= '.php';
|
||||||
|
$this->timestamp = $this->exists = is_file($this->filepath);
|
||||||
|
if ($this->exists) {
|
||||||
|
$this->timestamp = filemtime($this->filepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* render compiled template code
|
||||||
|
*
|
||||||
|
* @param Template $_template
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function render(Template $_template) {
|
||||||
|
// checks if template exists
|
||||||
|
if (!$_template->source->exists) {
|
||||||
|
$type = $_template->source->isConfig ? 'config' : 'template';
|
||||||
|
throw new SmartyException("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'");
|
||||||
|
}
|
||||||
|
if ($_template->smarty->debugging) {
|
||||||
|
if (!isset($_template->smarty->_debug)) {
|
||||||
|
$_template->smarty->_debug = new \Smarty\Debug();
|
||||||
|
}
|
||||||
|
$_template->smarty->_debug->start_render($_template);
|
||||||
|
}
|
||||||
|
if (!$this->processed) {
|
||||||
|
$this->process($_template);
|
||||||
|
}
|
||||||
|
if (isset($_template->cached)) {
|
||||||
|
$_template->cached->file_dependency =
|
||||||
|
array_merge($_template->cached->file_dependency, $this->file_dependency);
|
||||||
|
}
|
||||||
|
if ($_template->source->handler->uncompiled) {
|
||||||
|
$_template->source->handler->renderUncompiled($_template->source, $_template);
|
||||||
|
} else {
|
||||||
|
$this->getRenderedTemplateCode($_template);
|
||||||
|
}
|
||||||
|
if ($_template->caching && $this->has_nocache_code) {
|
||||||
|
$_template->cached->hashes[$this->nocache_hash] = true;
|
||||||
|
}
|
||||||
|
if ($_template->smarty->debugging) {
|
||||||
|
$_template->smarty->_debug->end_render($_template);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* load compiled template or compile from source
|
||||||
|
*
|
||||||
|
* @param Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function process(Template $_smarty_tpl) {
|
||||||
|
$source = &$_smarty_tpl->source;
|
||||||
|
$smarty = &$_smarty_tpl->smarty;
|
||||||
|
if ($source->handler->recompiled) {
|
||||||
|
$source->handler->process($_smarty_tpl);
|
||||||
|
} elseif (!$source->handler->uncompiled) {
|
||||||
|
if (!$this->exists || $smarty->force_compile
|
||||||
|
|| ($_smarty_tpl->compile_check && $source->getTimeStamp() > $this->getTimeStamp())
|
||||||
|
) {
|
||||||
|
$this->compileTemplateSource($_smarty_tpl);
|
||||||
|
$compileCheck = $_smarty_tpl->compile_check;
|
||||||
|
$_smarty_tpl->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
|
||||||
|
$this->loadCompiledTemplate($_smarty_tpl);
|
||||||
|
$_smarty_tpl->compile_check = $compileCheck;
|
||||||
|
} else {
|
||||||
|
$_smarty_tpl->mustCompile = true;
|
||||||
|
@include $this->filepath;
|
||||||
|
if ($_smarty_tpl->mustCompile) {
|
||||||
|
$this->compileTemplateSource($_smarty_tpl);
|
||||||
|
$compileCheck = $_smarty_tpl->compile_check;
|
||||||
|
$_smarty_tpl->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
|
||||||
|
$this->loadCompiledTemplate($_smarty_tpl);
|
||||||
|
$_smarty_tpl->compile_check = $compileCheck;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$_smarty_tpl->_subTemplateRegister();
|
||||||
|
$this->processed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* compile template from source
|
||||||
|
*
|
||||||
|
* @param Template $_template
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function compileTemplateSource(Template $_template) {
|
||||||
|
$this->file_dependency = [];
|
||||||
|
$this->includes = [];
|
||||||
|
$this->nocache_hash = null;
|
||||||
|
$this->unifunc = null;
|
||||||
|
// compile locking
|
||||||
|
if ($saved_timestamp = (!$_template->source->handler->recompiled && is_file($this->filepath))) {
|
||||||
|
$saved_timestamp = $this->getTimeStamp();
|
||||||
|
touch($this->filepath);
|
||||||
|
}
|
||||||
|
// compile locking
|
||||||
|
try {
|
||||||
|
// call compiler
|
||||||
|
$_template->loadCompiler();
|
||||||
|
$this->write($_template, $_template->compiler->compileTemplate($_template));
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// restore old timestamp in case of error
|
||||||
|
if ($saved_timestamp && is_file($this->filepath)) {
|
||||||
|
touch($this->filepath, $saved_timestamp);
|
||||||
|
}
|
||||||
|
unset($_template->compiler);
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
// release compiler object to free memory
|
||||||
|
unset($_template->compiler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write compiled code by handler
|
||||||
|
*
|
||||||
|
* @param Template $_template template object
|
||||||
|
* @param string $code compiled code
|
||||||
|
*
|
||||||
|
* @return bool success
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function write(Template $_template, $code) {
|
||||||
|
if (!$_template->source->handler->recompiled) {
|
||||||
|
if ($_template->smarty->writeFile($this->filepath, $code) === true) {
|
||||||
|
$this->timestamp = $this->exists = is_file($this->filepath);
|
||||||
|
if ($this->exists) {
|
||||||
|
$this->timestamp = filemtime($this->filepath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read compiled content from handler
|
||||||
|
*
|
||||||
|
* @param Template $_template template object
|
||||||
|
*
|
||||||
|
* @return string content
|
||||||
|
*/
|
||||||
|
public function read(Template $_template) {
|
||||||
|
if (!$_template->source->handler->recompiled) {
|
||||||
|
return file_get_contents($this->filepath);
|
||||||
|
}
|
||||||
|
return isset($this->content) ? $this->content : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load fresh compiled template by including the PHP file
|
||||||
|
* HHVM requires a work around because of a PHP incompatibility
|
||||||
|
*
|
||||||
|
* @param \Smarty\Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||||
|
*/
|
||||||
|
private function loadCompiledTemplate(Template $_smarty_tpl) {
|
||||||
|
if (function_exists('opcache_invalidate')
|
||||||
|
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
|
||||||
|
) {
|
||||||
|
opcache_invalidate($this->filepath, true);
|
||||||
|
} elseif (function_exists('apc_compile_file')) {
|
||||||
|
apc_compile_file($this->filepath);
|
||||||
|
}
|
||||||
|
if (defined('HHVM_VERSION')) {
|
||||||
|
eval('?>' . file_get_contents($this->filepath));
|
||||||
|
} else {
|
||||||
|
include $this->filepath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
97
src/Template/Config.php
Normal file
97
src/Template/Config.php
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Smarty\Template;
|
||||||
|
|
||||||
|
use Smarty;
|
||||||
|
use Smarty\Template;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty Config Resource Data Object
|
||||||
|
* Meta Data Container for Config Files
|
||||||
|
*
|
||||||
|
* @author Uwe Tews
|
||||||
|
*/
|
||||||
|
class Config extends Source {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* array of section names, single section or null
|
||||||
|
*
|
||||||
|
* @var null|string|array
|
||||||
|
*/
|
||||||
|
public $config_sections = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* scope into which the config variables shall be loaded
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $scope = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag that source is a config file
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $isConfig = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the Class to compile this resource's contents with
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $compiler_class = 'Smarty\Compiler\ConfigFile';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the Class to tokenize this resource's contents with
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $template_lexer_class = 'Smarty_Internal_Configfilelexer';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the Class to parse this resource's contents with
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $template_parser_class = 'Smarty_Internal_Configfileparser';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize Source Object for given resource
|
||||||
|
* Either [$_template] or [$smarty, $template_resource] must be specified
|
||||||
|
*
|
||||||
|
* @param Template $_template template object
|
||||||
|
* @param Smarty $smarty smarty object
|
||||||
|
* @param string $template_resource resource identifier
|
||||||
|
*
|
||||||
|
* @return Config Source Object
|
||||||
|
* @throws SmartyException
|
||||||
|
*/
|
||||||
|
public static function load(
|
||||||
|
Template $_template = null,
|
||||||
|
Smarty $smarty = null,
|
||||||
|
$template_resource = null
|
||||||
|
) {
|
||||||
|
static $_incompatible_resources = ['extends' => true, 'php' => true];
|
||||||
|
if ($_template) {
|
||||||
|
$smarty = $_template->smarty;
|
||||||
|
$template_resource = $_template->template_resource;
|
||||||
|
}
|
||||||
|
if (empty($template_resource)) {
|
||||||
|
throw new SmartyException('Source: Missing name');
|
||||||
|
}
|
||||||
|
// parse resource_name, load resource handler
|
||||||
|
[$name, $type] = Smarty\Resource\BasePlugin::parseResourceName($template_resource, $smarty->default_config_type);
|
||||||
|
// make sure configs are not loaded via anything smarty can't handle
|
||||||
|
if (isset($_incompatible_resources[$type])) {
|
||||||
|
throw new SmartyException("Unable to use resource '{$type}' for config");
|
||||||
|
}
|
||||||
|
$source = new Config($smarty, $template_resource, $type, $name);
|
||||||
|
$source->handler->populate($source, $_template);
|
||||||
|
if (!$source->exists && isset($smarty->default_config_handler_func)) {
|
||||||
|
$source->_getDefaultTemplate($smarty->default_config_handler_func);
|
||||||
|
$source->handler->populate($source, $_template);
|
||||||
|
}
|
||||||
|
return $source;
|
||||||
|
}
|
||||||
|
}
|
154
src/Template/ResourceBase.php
Normal file
154
src/Template/ResourceBase.php
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Smarty\Template;
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty Template Resource Base Object
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage TemplateResources
|
||||||
|
* @author Rodney Rehm
|
||||||
|
*/
|
||||||
|
abstract class ResourceBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiled Filepath
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $filepath = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiled Timestamp
|
||||||
|
*
|
||||||
|
* @var integer|bool
|
||||||
|
*/
|
||||||
|
public $timestamp = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiled Existence
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
public $exists = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template Compile Id (\Smarty\Template::$compile_id)
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $compile_id = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiled Content Loaded
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
public $processed = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unique function name for compiled template code
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $unifunc = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* flag if template does contain nocache code sections
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $has_nocache_code = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resource file dependency
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $file_dependency = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content buffer
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $content = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Included sub templates
|
||||||
|
* - index name
|
||||||
|
* - value use count
|
||||||
|
*
|
||||||
|
* @var int[]
|
||||||
|
*/
|
||||||
|
public $includes = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag if this is a cache resource
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $isCache = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process resource
|
||||||
|
*
|
||||||
|
* @param Template $_template template object
|
||||||
|
*/
|
||||||
|
abstract public function process(Template $_template);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get rendered template content by calling compiled or cached template code
|
||||||
|
*
|
||||||
|
* @param \Smarty\Template $_template
|
||||||
|
* @param string $unifunc function with template code
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function getRenderedTemplateCode(Template $_template, $unifunc = null) {
|
||||||
|
$smarty = &$_template->smarty;
|
||||||
|
$_template->isRenderingCache = $this->isCache;
|
||||||
|
$level = ob_get_level();
|
||||||
|
try {
|
||||||
|
if (!isset($unifunc)) {
|
||||||
|
$unifunc = $this->unifunc;
|
||||||
|
}
|
||||||
|
if (empty($unifunc) || !function_exists($unifunc)) {
|
||||||
|
throw new \SmartyException("Invalid compiled template for '{$_template->template_resource}'");
|
||||||
|
}
|
||||||
|
if ($_template->startRenderCallbacks) {
|
||||||
|
foreach ($_template->startRenderCallbacks as $callback) {
|
||||||
|
call_user_func($callback, $_template);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$unifunc($_template);
|
||||||
|
foreach ($_template->endRenderCallbacks as $callback) {
|
||||||
|
call_user_func($callback, $_template);
|
||||||
|
}
|
||||||
|
$_template->isRenderingCache = false;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$_template->isRenderingCache = false;
|
||||||
|
while (ob_get_level() > $level) {
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
if (isset($smarty->security_policy)) {
|
||||||
|
$smarty->security_policy->endTemplate();
|
||||||
|
}
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get compiled time stamp
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getTimeStamp() {
|
||||||
|
if ($this->exists && !$this->timestamp) {
|
||||||
|
$this->timestamp = filemtime($this->filepath);
|
||||||
|
}
|
||||||
|
return $this->timestamp;
|
||||||
|
}
|
||||||
|
}
|
253
src/Template/Source.php
Normal file
253
src/Template/Source.php
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Smarty\Template;
|
||||||
|
|
||||||
|
use Smarty;
|
||||||
|
use Smarty\Template;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty Resource Data Object
|
||||||
|
* Meta Data Container for Template Files
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage TemplateResources
|
||||||
|
* @author Rodney Rehm
|
||||||
|
*/
|
||||||
|
class Source {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unique Template ID
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $uid = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template Resource (Smarty_Internal_Template::$template_resource)
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $resource = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resource Type
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $type = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resource Name
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $name = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source Filepath
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $filepath = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source Timestamp
|
||||||
|
*
|
||||||
|
* @var integer
|
||||||
|
*/
|
||||||
|
public $timestamp = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source Existence
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
public $exists = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source File Base name
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $basename = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Components an extended template is made of
|
||||||
|
*
|
||||||
|
* @var \Smarty_Template_Source[]
|
||||||
|
*/
|
||||||
|
public $components = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resource Handler
|
||||||
|
*
|
||||||
|
* @var \Smarty\Resource\BasePlugin
|
||||||
|
*/
|
||||||
|
public $handler = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty instance
|
||||||
|
*
|
||||||
|
* @var Smarty
|
||||||
|
*/
|
||||||
|
public $smarty = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resource is source
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $isConfig = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template source content eventually set by default handler
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $content = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the Class to compile this resource's contents with
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $compiler_class = 'Smarty\Compiler\Template';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the Class to tokenize this resource's contents with
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the Class to parse this resource's contents with
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $template_parser_class = 'Smarty_Internal_Templateparser';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create Source Object container
|
||||||
|
*
|
||||||
|
* @param Smarty $smarty Smarty instance this source object belongs to
|
||||||
|
* @param string $resource full template_resource
|
||||||
|
* @param string $type type of resource
|
||||||
|
* @param string $name resource name
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
* @internal param \Smarty\Resource\Base $handler Resource Handler this source object communicates with
|
||||||
|
*/
|
||||||
|
public function __construct(Smarty $smarty, $resource, $type, $name) {
|
||||||
|
$this->handler = Smarty\Resource\BasePlugin::load($smarty, $type);
|
||||||
|
|
||||||
|
$this->smarty = $smarty;
|
||||||
|
$this->resource = $resource;
|
||||||
|
$this->type = $type;
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize Source Object for given resource
|
||||||
|
* Either [$_template] or [$smarty, $template_resource] must be specified
|
||||||
|
*
|
||||||
|
* @param Template $_template template object
|
||||||
|
* @param Smarty $smarty smarty object
|
||||||
|
* @param string $template_resource resource identifier
|
||||||
|
*
|
||||||
|
* @return Source Source Object
|
||||||
|
* @throws SmartyException
|
||||||
|
*/
|
||||||
|
public static function load(
|
||||||
|
Template $_template = null,
|
||||||
|
Smarty $smarty = null,
|
||||||
|
$template_resource = null
|
||||||
|
) {
|
||||||
|
if ($_template) {
|
||||||
|
$smarty = $_template->smarty;
|
||||||
|
$template_resource = $_template->template_resource;
|
||||||
|
}
|
||||||
|
if (empty($template_resource)) {
|
||||||
|
throw new SmartyException('Source: Missing name');
|
||||||
|
}
|
||||||
|
// parse resource_name, load resource handler, identify unique resource name
|
||||||
|
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) {
|
||||||
|
$type = $match[1];
|
||||||
|
$name = $match[2];
|
||||||
|
} else {
|
||||||
|
// no resource given, use default
|
||||||
|
// or single character before the colon is not a resource type, but part of the filepath
|
||||||
|
$type = $smarty->default_resource_type;
|
||||||
|
$name = $template_resource;
|
||||||
|
}
|
||||||
|
// create new source object
|
||||||
|
$source = new Source($smarty, $template_resource, $type, $name);
|
||||||
|
$source->handler->populate($source, $_template);
|
||||||
|
if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
|
||||||
|
$source->_getDefaultTemplate($_template->smarty->default_template_handler_func);
|
||||||
|
$source->handler->populate($source, $_template);
|
||||||
|
}
|
||||||
|
return $source;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get source time stamp
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getTimeStamp() {
|
||||||
|
if (!isset($this->timestamp)) {
|
||||||
|
$this->handler->populateTimestamp($this);
|
||||||
|
}
|
||||||
|
return $this->timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get source content
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function getContent() {
|
||||||
|
return isset($this->content) ? $this->content : $this->handler->getContent($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get default content from template or config resource handler
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function _getDefaultTemplate($default_handler) {
|
||||||
|
$_content = $_timestamp = null;
|
||||||
|
$_return = call_user_func_array(
|
||||||
|
$default_handler,
|
||||||
|
[$this->type, $this->name, &$_content, &$_timestamp, $this->smarty]
|
||||||
|
);
|
||||||
|
if (is_string($_return)) {
|
||||||
|
$this->exists = is_file($_return);
|
||||||
|
if ($this->exists) {
|
||||||
|
$this->timestamp = filemtime($_return);
|
||||||
|
} else {
|
||||||
|
throw new SmartyException(
|
||||||
|
'Default handler: Unable to load ' .
|
||||||
|
($this->isConfig ? 'config' : 'template') .
|
||||||
|
" default file '{$_return}' for '{$this->type}:{$this->name}'"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->name = $this->filepath = $_return;
|
||||||
|
$this->uid = sha1($this->filepath);
|
||||||
|
} elseif ($_return === true) {
|
||||||
|
$this->content = $_content;
|
||||||
|
$this->exists = true;
|
||||||
|
$this->uid = $this->name = sha1($_content);
|
||||||
|
$this->handler = Smarty\Resource\BasePlugin::load($this->smarty, 'eval');
|
||||||
|
} else {
|
||||||
|
$this->exists = false;
|
||||||
|
throw new SmartyException(
|
||||||
|
'Default handler: No ' . ($this->isConfig ? 'config' : 'template') .
|
||||||
|
" default content for '{$this->type}:{$this->name}'"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,387 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: Uwe Tews
|
|
||||||
* Date: 04.12.2014
|
|
||||||
* Time: 06:08
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty Resource Data Object
|
|
||||||
* Cache Data Container for Template Files
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage TemplateResources
|
|
||||||
* @author Rodney Rehm
|
|
||||||
*/
|
|
||||||
class Smarty_Template_Cached extends Smarty_Template_Resource_Base
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Cache Is Valid
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
public $valid = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CacheResource Handler
|
|
||||||
*
|
|
||||||
* @var \Smarty\Cacheresource\Base
|
|
||||||
*/
|
|
||||||
public $handler = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template Cache Id (Smarty_Internal_Template::$cache_id)
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $cache_id = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* saved cache lifetime in seconds
|
|
||||||
*
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
public $cache_lifetime = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Id for cache locking
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $lock_id = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* flag that cache is locked by this instance
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $is_locked = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Source Object
|
|
||||||
*
|
|
||||||
* @var Smarty_Template_Source
|
|
||||||
*/
|
|
||||||
public $source = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Nocache hash codes of processed compiled templates
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public $hashes = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag if this is a cache resource
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $isCache = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create Cached Object container
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template template object
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function __construct(Smarty_Internal_Template $_template)
|
|
||||||
{
|
|
||||||
$this->compile_id = $_template->compile_id;
|
|
||||||
$this->cache_id = $_template->cache_id;
|
|
||||||
$this->source = $_template->source;
|
|
||||||
$this->handler = \Smarty\Cacheresource\Base::load($_template->smarty);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Smarty_Internal_Template $_template
|
|
||||||
*
|
|
||||||
* @return Smarty_Template_Cached
|
|
||||||
*/
|
|
||||||
public static function load(Smarty_Internal_Template $_template)
|
|
||||||
{
|
|
||||||
$_template->cached = new Smarty_Template_Cached($_template);
|
|
||||||
$_template->cached->handler->populate($_template->cached, $_template);
|
|
||||||
// caching enabled ?
|
|
||||||
if (!$_template->caching || $_template->source->handler->recompiled
|
|
||||||
) {
|
|
||||||
$_template->cached->valid = false;
|
|
||||||
}
|
|
||||||
return $_template->cached;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render cache template
|
|
||||||
*
|
|
||||||
* @param \Smarty_Internal_Template $_template
|
|
||||||
* @param bool $no_output_filter
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function render(Smarty_Internal_Template $_template, $no_output_filter = true)
|
|
||||||
{
|
|
||||||
if ($this->isCached($_template)) {
|
|
||||||
if ($_template->smarty->debugging) {
|
|
||||||
if (!isset($_template->smarty->_debug)) {
|
|
||||||
$_template->smarty->_debug = new \Smarty\Debug();
|
|
||||||
}
|
|
||||||
$_template->smarty->_debug->start_cache($_template);
|
|
||||||
}
|
|
||||||
if (!$this->processed) {
|
|
||||||
$this->process($_template);
|
|
||||||
}
|
|
||||||
$this->getRenderedTemplateCode($_template);
|
|
||||||
if ($_template->smarty->debugging) {
|
|
||||||
$_template->smarty->_debug->end_cache($_template);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
$this->updateCache($_template, $no_output_filter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if cache is valid, lock cache if required
|
|
||||||
*
|
|
||||||
* @param \Smarty_Internal_Template $_template
|
|
||||||
*
|
|
||||||
* @return bool flag true if cache is valid
|
|
||||||
*/
|
|
||||||
public function isCached(Smarty_Internal_Template $_template)
|
|
||||||
{
|
|
||||||
if ($this->valid !== null) {
|
|
||||||
return $this->valid;
|
|
||||||
}
|
|
||||||
while (true) {
|
|
||||||
while (true) {
|
|
||||||
if ($this->exists === false || $_template->smarty->force_compile || $_template->smarty->force_cache) {
|
|
||||||
$this->valid = false;
|
|
||||||
} else {
|
|
||||||
$this->valid = true;
|
|
||||||
}
|
|
||||||
if ($this->valid && $_template->caching === \Smarty\Smarty::CACHING_LIFETIME_CURRENT
|
|
||||||
&& $_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)
|
|
||||||
) {
|
|
||||||
// lifetime expired
|
|
||||||
$this->valid = false;
|
|
||||||
}
|
|
||||||
if ($this->valid && $_template->compile_check === \Smarty\Smarty::COMPILECHECK_ON
|
|
||||||
&& $_template->source->getTimeStamp() > $this->timestamp
|
|
||||||
) {
|
|
||||||
$this->valid = false;
|
|
||||||
}
|
|
||||||
if ($this->valid || !$_template->smarty->cache_locking) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!$this->handler->locked($_template->smarty, $this)) {
|
|
||||||
$this->handler->acquireLock($_template->smarty, $this);
|
|
||||||
break 2;
|
|
||||||
}
|
|
||||||
$this->handler->populate($this, $_template);
|
|
||||||
}
|
|
||||||
if ($this->valid) {
|
|
||||||
if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) {
|
|
||||||
// load cache file for the following checks
|
|
||||||
if ($_template->smarty->debugging) {
|
|
||||||
$_template->smarty->_debug->start_cache($_template);
|
|
||||||
}
|
|
||||||
if ($this->handler->process($_template, $this) === false) {
|
|
||||||
$this->valid = false;
|
|
||||||
} else {
|
|
||||||
$this->processed = true;
|
|
||||||
}
|
|
||||||
if ($_template->smarty->debugging) {
|
|
||||||
$_template->smarty->_debug->end_cache($_template);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->is_locked = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return $this->valid;
|
|
||||||
}
|
|
||||||
if ($this->valid && $_template->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED
|
|
||||||
&& $_template->cached->cache_lifetime >= 0
|
|
||||||
&& (time() > ($_template->cached->timestamp + $_template->cached->cache_lifetime))
|
|
||||||
) {
|
|
||||||
$this->valid = false;
|
|
||||||
}
|
|
||||||
if ($_template->smarty->cache_locking) {
|
|
||||||
if (!$this->valid) {
|
|
||||||
$this->handler->acquireLock($_template->smarty, $this);
|
|
||||||
} elseif ($this->is_locked) {
|
|
||||||
$this->handler->releaseLock($_template->smarty, $this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->valid;
|
|
||||||
}
|
|
||||||
return $this->valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process cached template
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template template object
|
|
||||||
* @param bool $update flag if called because cache update
|
|
||||||
*/
|
|
||||||
public function process(Smarty_Internal_Template $_template, $update = false)
|
|
||||||
{
|
|
||||||
if ($this->handler->process($_template, $this, $update) === false) {
|
|
||||||
$this->valid = false;
|
|
||||||
}
|
|
||||||
if ($this->valid) {
|
|
||||||
$this->processed = true;
|
|
||||||
} else {
|
|
||||||
$this->processed = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read cache content from handler
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template template object
|
|
||||||
*
|
|
||||||
* @return string|false content
|
|
||||||
*/
|
|
||||||
public function readCache(Smarty_Internal_Template $_template)
|
|
||||||
{
|
|
||||||
if (!$_template->source->handler->recompiled) {
|
|
||||||
return $this->handler->retrieveCachedContent($_template);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write this cache object to handler
|
|
||||||
*
|
|
||||||
* @param string $content content to cache
|
|
||||||
*
|
|
||||||
* @return bool success
|
|
||||||
*/
|
|
||||||
public function writeCache(Smarty_Internal_Template $_template, $content)
|
|
||||||
{
|
|
||||||
if (!$_template->source->handler->recompiled) {
|
|
||||||
if ($this->handler->storeCachedContent($_template, $content)) {
|
|
||||||
$this->content = null;
|
|
||||||
$this->timestamp = time();
|
|
||||||
$this->exists = true;
|
|
||||||
$this->valid = true;
|
|
||||||
$this->cache_lifetime = $_template->cache_lifetime;
|
|
||||||
$this->processed = false;
|
|
||||||
if ($_template->smarty->cache_locking) {
|
|
||||||
$this->handler->releaseLock($_template->smarty, $this);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
$this->content = null;
|
|
||||||
$this->timestamp = false;
|
|
||||||
$this->exists = false;
|
|
||||||
$this->valid = false;
|
|
||||||
$this->processed = false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cache was invalid , so render from compiled and write to cache
|
|
||||||
*
|
|
||||||
* @param \Smarty_Template_Cached $cached
|
|
||||||
* @param $no_output_filter
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function updateCache(Smarty_Internal_Template $_template, $no_output_filter)
|
|
||||||
{
|
|
||||||
ob_start();
|
|
||||||
if (!isset($_template->compiled)) {
|
|
||||||
$_template->loadCompiled();
|
|
||||||
}
|
|
||||||
$_template->compiled->render($_template);
|
|
||||||
if ($_template->smarty->debugging) {
|
|
||||||
$_template->smarty->_debug->start_cache($_template);
|
|
||||||
}
|
|
||||||
$this->removeNoCacheHash($_template, $no_output_filter);
|
|
||||||
$compile_check = (int)$_template->compile_check;
|
|
||||||
$_template->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
|
|
||||||
if ($_template->_isSubTpl()) {
|
|
||||||
$_template->compiled->unifunc = $_template->parent->compiled->unifunc;
|
|
||||||
}
|
|
||||||
if (!$_template->cached->processed) {
|
|
||||||
$_template->cached->process($_template, true);
|
|
||||||
}
|
|
||||||
$_template->compile_check = $compile_check;
|
|
||||||
$this->getRenderedTemplateCode($_template);
|
|
||||||
if ($_template->smarty->debugging) {
|
|
||||||
$_template->smarty->_debug->end_cache($_template);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sanitize content and write it to cache resource
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template
|
|
||||||
* @param bool $no_output_filter
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
private function removeNoCacheHash(Smarty_Internal_Template $_template, $no_output_filter) {
|
|
||||||
$php_pattern = '/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/';
|
|
||||||
$content = ob_get_clean();
|
|
||||||
$hash_array = $this->hashes;
|
|
||||||
$hash_array[ $_template->compiled->nocache_hash ] = true;
|
|
||||||
$hash_array = array_keys($hash_array);
|
|
||||||
$nocache_hash = '(' . implode('|', $hash_array) . ')';
|
|
||||||
$_template->cached->has_nocache_code = false;
|
|
||||||
// get text between non-cached items
|
|
||||||
$cache_split =
|
|
||||||
preg_split(
|
|
||||||
"!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s",
|
|
||||||
$content
|
|
||||||
);
|
|
||||||
// get non-cached items
|
|
||||||
preg_match_all(
|
|
||||||
"!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s",
|
|
||||||
$content,
|
|
||||||
$cache_parts
|
|
||||||
);
|
|
||||||
$content = '';
|
|
||||||
// loop over items, stitch back together
|
|
||||||
foreach ($cache_split as $curr_idx => $curr_split) {
|
|
||||||
if (preg_match($php_pattern, $curr_split)) {
|
|
||||||
// escape PHP tags in template content
|
|
||||||
$php_split = preg_split(
|
|
||||||
$php_pattern,
|
|
||||||
$curr_split
|
|
||||||
);
|
|
||||||
preg_match_all(
|
|
||||||
$php_pattern,
|
|
||||||
$curr_split,
|
|
||||||
$php_parts
|
|
||||||
);
|
|
||||||
foreach ($php_split as $idx_php => $curr_php) {
|
|
||||||
$content .= $curr_php;
|
|
||||||
if (isset($php_parts[ 0 ][ $idx_php ])) {
|
|
||||||
$content .= "<?php echo '{$php_parts[ 1 ][ $idx_php ]}'; ?>\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$content .= $curr_split;
|
|
||||||
}
|
|
||||||
if (isset($cache_parts[ 0 ][ $curr_idx ])) {
|
|
||||||
$_template->cached->has_nocache_code = true;
|
|
||||||
$content .= $cache_parts[ 2 ][ $curr_idx ];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
!$no_output_filter
|
|
||||||
&& !$_template->cached->has_nocache_code
|
|
||||||
&& isset($_template->smarty->registered_filters[ 'output' ])
|
|
||||||
) {
|
|
||||||
$content = $_template->smarty->runFilter('output', $content, $_template);
|
|
||||||
}
|
|
||||||
// write cache file content
|
|
||||||
$_template->writeCachedContent($content);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,257 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty Resource Data Object
|
|
||||||
* Meta Data Container for Template Files
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage TemplateResources
|
|
||||||
* @author Rodney Rehm
|
|
||||||
* @property string $content compiled content
|
|
||||||
*/
|
|
||||||
class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* nocache hash
|
|
||||||
*
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
public $nocache_hash = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get a Compiled Object of this source
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template template object
|
|
||||||
*
|
|
||||||
* @return Smarty_Template_Compiled compiled object
|
|
||||||
*/
|
|
||||||
public static function load($_template)
|
|
||||||
{
|
|
||||||
$compiled = new Smarty_Template_Compiled();
|
|
||||||
if ($_template->source->handler->hasCompiledHandler) {
|
|
||||||
$_template->source->handler->populateCompiledFilepath($compiled, $_template);
|
|
||||||
} else {
|
|
||||||
$compiled->populateCompiledFilepath($_template);
|
|
||||||
}
|
|
||||||
return $compiled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* populate Compiled Object with compiled filepath
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template template object
|
|
||||||
**/
|
|
||||||
public function populateCompiledFilepath(Smarty_Internal_Template $_template)
|
|
||||||
{
|
|
||||||
$source = &$_template->source;
|
|
||||||
$smarty = &$_template->smarty;
|
|
||||||
$this->filepath = $smarty->getCompileDir();
|
|
||||||
if (isset($_template->compile_id)) {
|
|
||||||
$this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) .
|
|
||||||
($smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^');
|
|
||||||
}
|
|
||||||
// if use_sub_dirs, break file into directories
|
|
||||||
if ($smarty->use_sub_dirs) {
|
|
||||||
$this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . DIRECTORY_SEPARATOR . $source->uid[ 2 ] .
|
|
||||||
$source->uid[ 3 ] . DIRECTORY_SEPARATOR . $source->uid[ 4 ] . $source->uid[ 5 ] .
|
|
||||||
DIRECTORY_SEPARATOR;
|
|
||||||
}
|
|
||||||
$this->filepath .= $source->uid . '_';
|
|
||||||
if ($source->isConfig) {
|
|
||||||
$this->filepath .= (int)$smarty->config_read_hidden + (int)$smarty->config_booleanize * 2 +
|
|
||||||
(int)$smarty->config_overwrite * 4;
|
|
||||||
} else {
|
|
||||||
$this->filepath .= (int)$smarty->merge_compiled_includes + (int)$smarty->escape_html * 2 +
|
|
||||||
(($smarty->merge_compiled_includes && $source->type === 'extends') ?
|
|
||||||
(int)$smarty->extends_recursion * 4 : 0);
|
|
||||||
}
|
|
||||||
$this->filepath .= '.' . $source->type;
|
|
||||||
$basename = $source->handler->getBasename($source);
|
|
||||||
if (!empty($basename)) {
|
|
||||||
$this->filepath .= '.' . $basename;
|
|
||||||
}
|
|
||||||
if ($_template->caching) {
|
|
||||||
$this->filepath .= '.cache';
|
|
||||||
}
|
|
||||||
$this->filepath .= '.php';
|
|
||||||
$this->timestamp = $this->exists = is_file($this->filepath);
|
|
||||||
if ($this->exists) {
|
|
||||||
$this->timestamp = filemtime($this->filepath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* render compiled template code
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function render(Smarty_Internal_Template $_template)
|
|
||||||
{
|
|
||||||
// checks if template exists
|
|
||||||
if (!$_template->source->exists) {
|
|
||||||
$type = $_template->source->isConfig ? 'config' : 'template';
|
|
||||||
throw new SmartyException("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'");
|
|
||||||
}
|
|
||||||
if ($_template->smarty->debugging) {
|
|
||||||
if (!isset($_template->smarty->_debug)) {
|
|
||||||
$_template->smarty->_debug = new \Smarty\Debug();
|
|
||||||
}
|
|
||||||
$_template->smarty->_debug->start_render($_template);
|
|
||||||
}
|
|
||||||
if (!$this->processed) {
|
|
||||||
$this->process($_template);
|
|
||||||
}
|
|
||||||
if (isset($_template->cached)) {
|
|
||||||
$_template->cached->file_dependency =
|
|
||||||
array_merge($_template->cached->file_dependency, $this->file_dependency);
|
|
||||||
}
|
|
||||||
if ($_template->source->handler->uncompiled) {
|
|
||||||
$_template->source->handler->renderUncompiled($_template->source, $_template);
|
|
||||||
} else {
|
|
||||||
$this->getRenderedTemplateCode($_template);
|
|
||||||
}
|
|
||||||
if ($_template->caching && $this->has_nocache_code) {
|
|
||||||
$_template->cached->hashes[ $this->nocache_hash ] = true;
|
|
||||||
}
|
|
||||||
if ($_template->smarty->debugging) {
|
|
||||||
$_template->smarty->_debug->end_render($_template);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* load compiled template or compile from source
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function process(Smarty_Internal_Template $_smarty_tpl)
|
|
||||||
{
|
|
||||||
$source = &$_smarty_tpl->source;
|
|
||||||
$smarty = &$_smarty_tpl->smarty;
|
|
||||||
if ($source->handler->recompiled) {
|
|
||||||
$source->handler->process($_smarty_tpl);
|
|
||||||
} elseif (!$source->handler->uncompiled) {
|
|
||||||
if (!$this->exists || $smarty->force_compile
|
|
||||||
|| ($_smarty_tpl->compile_check && $source->getTimeStamp() > $this->getTimeStamp())
|
|
||||||
) {
|
|
||||||
$this->compileTemplateSource($_smarty_tpl);
|
|
||||||
$compileCheck = $_smarty_tpl->compile_check;
|
|
||||||
$_smarty_tpl->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
|
|
||||||
$this->loadCompiledTemplate($_smarty_tpl);
|
|
||||||
$_smarty_tpl->compile_check = $compileCheck;
|
|
||||||
} else {
|
|
||||||
$_smarty_tpl->mustCompile = true;
|
|
||||||
@include $this->filepath;
|
|
||||||
if ($_smarty_tpl->mustCompile) {
|
|
||||||
$this->compileTemplateSource($_smarty_tpl);
|
|
||||||
$compileCheck = $_smarty_tpl->compile_check;
|
|
||||||
$_smarty_tpl->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
|
|
||||||
$this->loadCompiledTemplate($_smarty_tpl);
|
|
||||||
$_smarty_tpl->compile_check = $compileCheck;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$_smarty_tpl->_subTemplateRegister();
|
|
||||||
$this->processed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* compile template from source
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function compileTemplateSource(Smarty_Internal_Template $_template)
|
|
||||||
{
|
|
||||||
$this->file_dependency = array();
|
|
||||||
$this->includes = array();
|
|
||||||
$this->nocache_hash = null;
|
|
||||||
$this->unifunc = null;
|
|
||||||
// compile locking
|
|
||||||
if ($saved_timestamp = (!$_template->source->handler->recompiled && is_file($this->filepath))) {
|
|
||||||
$saved_timestamp = $this->getTimeStamp();
|
|
||||||
touch($this->filepath);
|
|
||||||
}
|
|
||||||
// compile locking
|
|
||||||
try {
|
|
||||||
// call compiler
|
|
||||||
$_template->loadCompiler();
|
|
||||||
$this->write($_template, $_template->compiler->compileTemplate($_template));
|
|
||||||
} catch (Exception $e) {
|
|
||||||
// restore old timestamp in case of error
|
|
||||||
if ($saved_timestamp && is_file($this->filepath)) {
|
|
||||||
touch($this->filepath, $saved_timestamp);
|
|
||||||
}
|
|
||||||
unset($_template->compiler);
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
// release compiler object to free memory
|
|
||||||
unset($_template->compiler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write compiled code by handler
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template template object
|
|
||||||
* @param string $code compiled code
|
|
||||||
*
|
|
||||||
* @return bool success
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function write(Smarty_Internal_Template $_template, $code)
|
|
||||||
{
|
|
||||||
if (!$_template->source->handler->recompiled) {
|
|
||||||
if ($_template->smarty->writeFile($this->filepath, $code) === true) {
|
|
||||||
$this->timestamp = $this->exists = is_file($this->filepath);
|
|
||||||
if ($this->exists) {
|
|
||||||
$this->timestamp = filemtime($this->filepath);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read compiled content from handler
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template template object
|
|
||||||
*
|
|
||||||
* @return string content
|
|
||||||
*/
|
|
||||||
public function read(Smarty_Internal_Template $_template)
|
|
||||||
{
|
|
||||||
if (!$_template->source->handler->recompiled) {
|
|
||||||
return file_get_contents($this->filepath);
|
|
||||||
}
|
|
||||||
return isset($this->content) ? $this->content : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load fresh compiled template by including the PHP file
|
|
||||||
* HHVM requires a work around because of a PHP incompatibility
|
|
||||||
*
|
|
||||||
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
|
||||||
*/
|
|
||||||
private function loadCompiledTemplate(Smarty_Internal_Template $_smarty_tpl)
|
|
||||||
{
|
|
||||||
if (function_exists('opcache_invalidate')
|
|
||||||
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
|
|
||||||
) {
|
|
||||||
opcache_invalidate($this->filepath, true);
|
|
||||||
} elseif (function_exists('apc_compile_file')) {
|
|
||||||
apc_compile_file($this->filepath);
|
|
||||||
}
|
|
||||||
if (defined('HHVM_VERSION')) {
|
|
||||||
eval('?>' . file_get_contents($this->filepath));
|
|
||||||
} else {
|
|
||||||
include $this->filepath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,100 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Smarty Config Source Plugin
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage TemplateResources
|
|
||||||
* @author Uwe Tews
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty Config Resource Data Object
|
|
||||||
* Meta Data Container for Template Files
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage TemplateResources
|
|
||||||
* @author Uwe Tews
|
|
||||||
*/
|
|
||||||
class Smarty_Template_Config extends Smarty_Template_Source
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* array of section names, single section or null
|
|
||||||
*
|
|
||||||
* @var null|string|array
|
|
||||||
*/
|
|
||||||
public $config_sections = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* scope into which the config variables shall be loaded
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $scope = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag that source is a config file
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $isConfig = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of the Class to compile this resource's contents with
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $compiler_class = 'Smarty\Compiler\ConfigFile';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of the Class to tokenize this resource's contents with
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $template_lexer_class = 'Smarty_Internal_Configfilelexer';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of the Class to parse this resource's contents with
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $template_parser_class = 'Smarty_Internal_Configfileparser';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* initialize Source Object for given resource
|
|
||||||
* Either [$_template] or [$smarty, $template_resource] must be specified
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template template object
|
|
||||||
* @param Smarty $smarty smarty object
|
|
||||||
* @param string $template_resource resource identifier
|
|
||||||
*
|
|
||||||
* @return Smarty_Template_Config Source Object
|
|
||||||
* @throws SmartyException
|
|
||||||
*/
|
|
||||||
public static function load(
|
|
||||||
Smarty_Internal_Template $_template = null,
|
|
||||||
Smarty $smarty = null,
|
|
||||||
$template_resource = null
|
|
||||||
) {
|
|
||||||
static $_incompatible_resources = array('extends' => true, 'php' => true);
|
|
||||||
if ($_template) {
|
|
||||||
$smarty = $_template->smarty;
|
|
||||||
$template_resource = $_template->template_resource;
|
|
||||||
}
|
|
||||||
if (empty($template_resource)) {
|
|
||||||
throw new SmartyException('Source: Missing name');
|
|
||||||
}
|
|
||||||
// parse resource_name, load resource handler
|
|
||||||
list($name, $type) = Smarty\Resource\BasePlugin::parseResourceName($template_resource, $smarty->default_config_type);
|
|
||||||
// make sure configs are not loaded via anything smarty can't handle
|
|
||||||
if (isset($_incompatible_resources[ $type ])) {
|
|
||||||
throw new SmartyException("Unable to use resource '{$type}' for config");
|
|
||||||
}
|
|
||||||
$source = new Smarty_Template_Config($smarty, $template_resource, $type, $name);
|
|
||||||
$source->handler->populate($source, $_template);
|
|
||||||
if (!$source->exists && isset($smarty->default_config_handler_func)) {
|
|
||||||
$source->_getDefaultTemplate($smarty->default_config_handler_func);
|
|
||||||
$source->handler->populate($source, $_template);
|
|
||||||
}
|
|
||||||
return $source;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,152 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty Template Resource Base Object
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage TemplateResources
|
|
||||||
* @author Rodney Rehm
|
|
||||||
*/
|
|
||||||
abstract class Smarty_Template_Resource_Base
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Compiled Filepath
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $filepath = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compiled Timestamp
|
|
||||||
*
|
|
||||||
* @var integer|bool
|
|
||||||
*/
|
|
||||||
public $timestamp = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compiled Existence
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
public $exists = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template Compile Id (Smarty_Internal_Template::$compile_id)
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $compile_id = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compiled Content Loaded
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
public $processed = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* unique function name for compiled template code
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $unifunc = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* flag if template does contain nocache code sections
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $has_nocache_code = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* resource file dependency
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public $file_dependency = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Content buffer
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $content = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Included sub templates
|
|
||||||
* - index name
|
|
||||||
* - value use count
|
|
||||||
*
|
|
||||||
* @var int[]
|
|
||||||
*/
|
|
||||||
public $includes = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag if this is a cache resource
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $isCache = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process resource
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template template object
|
|
||||||
*/
|
|
||||||
abstract public function process(Smarty_Internal_Template $_template);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get rendered template content by calling compiled or cached template code
|
|
||||||
*
|
|
||||||
* @param \Smarty_Internal_Template $_template
|
|
||||||
* @param string $unifunc function with template code
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function getRenderedTemplateCode(Smarty_Internal_Template $_template, $unifunc = null)
|
|
||||||
{
|
|
||||||
$smarty = &$_template->smarty;
|
|
||||||
$_template->isRenderingCache = $this->isCache;
|
|
||||||
$level = ob_get_level();
|
|
||||||
try {
|
|
||||||
if (!isset($unifunc)) {
|
|
||||||
$unifunc = $this->unifunc;
|
|
||||||
}
|
|
||||||
if (empty($unifunc) || !function_exists($unifunc)) {
|
|
||||||
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
|
|
||||||
}
|
|
||||||
if ($_template->startRenderCallbacks) {
|
|
||||||
foreach ($_template->startRenderCallbacks as $callback) {
|
|
||||||
call_user_func($callback, $_template);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$unifunc($_template);
|
|
||||||
foreach ($_template->endRenderCallbacks as $callback) {
|
|
||||||
call_user_func($callback, $_template);
|
|
||||||
}
|
|
||||||
$_template->isRenderingCache = false;
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$_template->isRenderingCache = false;
|
|
||||||
while (ob_get_level() > $level) {
|
|
||||||
ob_end_clean();
|
|
||||||
}
|
|
||||||
if (isset($smarty->security_policy)) {
|
|
||||||
$smarty->security_policy->endTemplate();
|
|
||||||
}
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get compiled time stamp
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getTimeStamp()
|
|
||||||
{
|
|
||||||
if ($this->exists && !$this->timestamp) {
|
|
||||||
$this->timestamp = filemtime($this->filepath);
|
|
||||||
}
|
|
||||||
return $this->timestamp;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,251 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty Resource Data Object
|
|
||||||
* Meta Data Container for Template Files
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage TemplateResources
|
|
||||||
* @author Rodney Rehm
|
|
||||||
*/
|
|
||||||
class Smarty_Template_Source
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Unique Template ID
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $uid = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template Resource (Smarty_Internal_Template::$template_resource)
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $resource = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resource Type
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $type = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resource Name
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $name = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Source Filepath
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $filepath = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Source Timestamp
|
|
||||||
*
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
public $timestamp = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Source Existence
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
public $exists = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Source File Base name
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $basename = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Components an extended template is made of
|
|
||||||
*
|
|
||||||
* @var \Smarty_Template_Source[]
|
|
||||||
*/
|
|
||||||
public $components = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resource Handler
|
|
||||||
*
|
|
||||||
* @var \Smarty\Resource\BasePlugin
|
|
||||||
*/
|
|
||||||
public $handler = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty instance
|
|
||||||
*
|
|
||||||
* @var Smarty
|
|
||||||
*/
|
|
||||||
public $smarty = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resource is source
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $isConfig = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template source content eventually set by default handler
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $content = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of the Class to compile this resource's contents with
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $compiler_class = 'Smarty\Compiler\Template';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of the Class to tokenize this resource's contents with
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of the Class to parse this resource's contents with
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $template_parser_class = 'Smarty_Internal_Templateparser';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create Source Object container
|
|
||||||
*
|
|
||||||
* @param Smarty $smarty Smarty instance this source object belongs to
|
|
||||||
* @param string $resource full template_resource
|
|
||||||
* @param string $type type of resource
|
|
||||||
* @param string $name resource name
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
* @internal param \Smarty\Resource\Base $handler Resource Handler this source object communicates with
|
|
||||||
*/
|
|
||||||
public function __construct(Smarty $smarty, $resource, $type, $name)
|
|
||||||
{
|
|
||||||
$this->handler = Smarty\Resource\BasePlugin::load($smarty, $type);
|
|
||||||
|
|
||||||
$this->smarty = $smarty;
|
|
||||||
$this->resource = $resource;
|
|
||||||
$this->type = $type;
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* initialize Source Object for given resource
|
|
||||||
* Either [$_template] or [$smarty, $template_resource] must be specified
|
|
||||||
*
|
|
||||||
* @param Smarty_Internal_Template $_template template object
|
|
||||||
* @param Smarty $smarty smarty object
|
|
||||||
* @param string $template_resource resource identifier
|
|
||||||
*
|
|
||||||
* @return Smarty_Template_Source Source Object
|
|
||||||
* @throws SmartyException
|
|
||||||
*/
|
|
||||||
public static function load(
|
|
||||||
Smarty_Internal_Template $_template = null,
|
|
||||||
Smarty $smarty = null,
|
|
||||||
$template_resource = null
|
|
||||||
) {
|
|
||||||
if ($_template) {
|
|
||||||
$smarty = $_template->smarty;
|
|
||||||
$template_resource = $_template->template_resource;
|
|
||||||
}
|
|
||||||
if (empty($template_resource)) {
|
|
||||||
throw new SmartyException('Source: Missing name');
|
|
||||||
}
|
|
||||||
// parse resource_name, load resource handler, identify unique resource name
|
|
||||||
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) {
|
|
||||||
$type = $match[ 1 ];
|
|
||||||
$name = $match[ 2 ];
|
|
||||||
} else {
|
|
||||||
// no resource given, use default
|
|
||||||
// or single character before the colon is not a resource type, but part of the filepath
|
|
||||||
$type = $smarty->default_resource_type;
|
|
||||||
$name = $template_resource;
|
|
||||||
}
|
|
||||||
// create new source object
|
|
||||||
$source = new Smarty_Template_Source($smarty, $template_resource, $type, $name);
|
|
||||||
$source->handler->populate($source, $_template);
|
|
||||||
if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
|
|
||||||
$source->_getDefaultTemplate($_template->smarty->default_template_handler_func);
|
|
||||||
$source->handler->populate($source, $_template);
|
|
||||||
}
|
|
||||||
return $source;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get source time stamp
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getTimeStamp()
|
|
||||||
{
|
|
||||||
if (!isset($this->timestamp)) {
|
|
||||||
$this->handler->populateTimestamp($this);
|
|
||||||
}
|
|
||||||
return $this->timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get source content
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function getContent()
|
|
||||||
{
|
|
||||||
return isset($this->content) ? $this->content : $this->handler->getContent($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get default content from template or config resource handler
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function _getDefaultTemplate($default_handler)
|
|
||||||
{
|
|
||||||
$_content = $_timestamp = null;
|
|
||||||
$_return = call_user_func_array(
|
|
||||||
$default_handler,
|
|
||||||
array($this->type, $this->name, &$_content, &$_timestamp, $this->smarty)
|
|
||||||
);
|
|
||||||
if (is_string($_return)) {
|
|
||||||
$this->exists = is_file($_return);
|
|
||||||
if ($this->exists) {
|
|
||||||
$this->timestamp = filemtime($_return);
|
|
||||||
} else {
|
|
||||||
throw new SmartyException(
|
|
||||||
'Default handler: Unable to load ' .
|
|
||||||
($this->isConfig ? 'config' : 'template') .
|
|
||||||
" default file '{$_return}' for '{$this->type}:{$this->name}'"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$this->name = $this->filepath = $_return;
|
|
||||||
$this->uid = sha1($this->filepath);
|
|
||||||
} elseif ($_return === true) {
|
|
||||||
$this->content = $_content;
|
|
||||||
$this->exists = true;
|
|
||||||
$this->uid = $this->name = sha1($_content);
|
|
||||||
$this->handler = Smarty\Resource\BasePlugin::load($this->smarty, 'eval');
|
|
||||||
} else {
|
|
||||||
$this->exists = false;
|
|
||||||
throw new SmartyException(
|
|
||||||
'Default handler: No ' . ($this->isConfig ? 'config' : 'template') .
|
|
||||||
" default content for '{$this->type}:{$this->name}'"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
894
src/TemplateBase.php
Normal file
894
src/TemplateBase.php
Normal file
@@ -0,0 +1,894 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Smarty Internal Plugin Smarty Template Base
|
||||||
|
* This file contains the basic shared methods for template handling
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage Template
|
||||||
|
* @author Uwe Tews
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Smarty;
|
||||||
|
|
||||||
|
use Smarty\Cacheresource\Base;
|
||||||
|
use Smarty\Data;
|
||||||
|
use Smarty\Smarty;
|
||||||
|
use Smarty\Template;
|
||||||
|
use Smarty_Data;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class with shared smarty/template methods
|
||||||
|
*
|
||||||
|
* @property int $_objType
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
abstract class TemplateBase extends Data {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this if you want different sets of cache files for the same
|
||||||
|
* templates.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $cache_id = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this if you want different sets of compiled files for the same
|
||||||
|
* templates.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $compile_id = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* caching enabled
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $caching = \Smarty\Smarty::CACHING_OFF;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check template for modifications?
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $compile_check = \Smarty\Smarty::COMPILECHECK_ON;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cache lifetime in seconds
|
||||||
|
*
|
||||||
|
* @var integer
|
||||||
|
*/
|
||||||
|
public $cache_lifetime = 3600;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of source information for known template functions
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $tplFunctions = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When initialized to an (empty) array, this variable will hold a stack of template variables.
|
||||||
|
*
|
||||||
|
* @var null|array
|
||||||
|
*/
|
||||||
|
public $_var_stack = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Valid filter types
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $filterTypes = ['pre' => true, 'post' => true, 'output' => true, 'variable' => true];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fetches a rendered Smarty template
|
||||||
|
*
|
||||||
|
* @param string $template the resource handle of the template file or template object
|
||||||
|
* @param mixed $cache_id cache id to be used with this template
|
||||||
|
* @param mixed $compile_id compile id to be used with this template
|
||||||
|
* @param object $parent next higher level of Smarty variables
|
||||||
|
*
|
||||||
|
* @return string rendered template output
|
||||||
|
* @throws SmartyException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null) {
|
||||||
|
$result = $this->_execute($template, $cache_id, $compile_id, $parent, 0);
|
||||||
|
return $result === null ? ob_get_clean() : $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* displays a Smarty template
|
||||||
|
*
|
||||||
|
* @param string $template the resource handle of the template file or template object
|
||||||
|
* @param mixed $cache_id cache id to be used with this template
|
||||||
|
* @param mixed $compile_id compile id to be used with this template
|
||||||
|
* @param object $parent next higher level of Smarty variables
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null) {
|
||||||
|
// display template
|
||||||
|
$this->_execute($template, $cache_id, $compile_id, $parent, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if cache is valid
|
||||||
|
*
|
||||||
|
* @param null|string|\Smarty\Template $template the resource handle of the template file or template
|
||||||
|
* object
|
||||||
|
* @param mixed $cache_id cache id to be used with this template
|
||||||
|
* @param mixed $compile_id compile id to be used with this template
|
||||||
|
* @param object $parent next higher level of Smarty variables
|
||||||
|
*
|
||||||
|
* @return bool cache status
|
||||||
|
* @throws \Exception
|
||||||
|
* @throws \SmartyException
|
||||||
|
* @link https://www.smarty.net/docs/en/api.is.cached.tpl
|
||||||
|
*
|
||||||
|
* @api Smarty::isCached()
|
||||||
|
*/
|
||||||
|
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null) {
|
||||||
|
return $this->_execute($template, $cache_id, $compile_id, $parent, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fetches a rendered Smarty template
|
||||||
|
*
|
||||||
|
* @param string $template the resource handle of the template file or template object
|
||||||
|
* @param mixed $cache_id cache id to be used with this template
|
||||||
|
* @param mixed $compile_id compile id to be used with this template
|
||||||
|
* @param object $parent next higher level of Smarty variables
|
||||||
|
* @param string $function function type 0 = fetch, 1 = display, 2 = isCache
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
* @throws \Exception
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
private function _execute($template, $cache_id, $compile_id, $parent, $function) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
$saveVars = true;
|
||||||
|
if ($template === null) {
|
||||||
|
if (!$this->_isTplObj()) {
|
||||||
|
throw new SmartyException($function . '():Missing \'$template\' parameter');
|
||||||
|
} else {
|
||||||
|
$template = $this;
|
||||||
|
}
|
||||||
|
} elseif (is_object($template)) {
|
||||||
|
/* @var Template $template */
|
||||||
|
if (!isset($template->_objType) || !$template->_isTplObj()) {
|
||||||
|
throw new SmartyException($function . '():Template object expected');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// get template object
|
||||||
|
$saveVars = false;
|
||||||
|
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false);
|
||||||
|
if ($this->_objType === 1) {
|
||||||
|
// set caching in template object
|
||||||
|
$template->caching = $this->caching;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// make sure we have integer values
|
||||||
|
$template->caching = (int)$template->caching;
|
||||||
|
// fetch template content
|
||||||
|
$level = ob_get_level();
|
||||||
|
try {
|
||||||
|
$_smarty_old_error_level =
|
||||||
|
isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null;
|
||||||
|
|
||||||
|
if ($smarty->isMutingUndefinedOrNullWarnings()) {
|
||||||
|
$errorHandler = new \Smarty\ErrorHandler();
|
||||||
|
$errorHandler->activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->_objType === 2) {
|
||||||
|
/* @var Template $this */
|
||||||
|
$template->tplFunctions = $this->tplFunctions;
|
||||||
|
$template->inheritance = $this->inheritance;
|
||||||
|
}
|
||||||
|
/* @var Template $parent */
|
||||||
|
if (isset($parent->_objType) && ($parent->_objType === 2) && !empty($parent->tplFunctions)) {
|
||||||
|
$template->tplFunctions = array_merge($parent->tplFunctions, $template->tplFunctions);
|
||||||
|
}
|
||||||
|
if ($function === 2) {
|
||||||
|
if ($template->caching) {
|
||||||
|
// return cache status of template
|
||||||
|
if (!isset($template->cached)) {
|
||||||
|
$template->loadCached();
|
||||||
|
}
|
||||||
|
$result = $template->cached->isCached($template);
|
||||||
|
Template::$isCacheTplObj[$template->_getTemplateId()] = $template;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($saveVars) {
|
||||||
|
$savedTplVars = $template->tpl_vars;
|
||||||
|
$savedConfigVars = $template->config_vars;
|
||||||
|
}
|
||||||
|
ob_start();
|
||||||
|
$template->_mergeVars();
|
||||||
|
if (!empty(\Smarty\Smarty::$global_tpl_vars)) {
|
||||||
|
$template->tpl_vars = array_merge(\Smarty\Smarty::$global_tpl_vars, $template->tpl_vars);
|
||||||
|
}
|
||||||
|
$result = $template->render(false, $function);
|
||||||
|
$template->_cleanUp();
|
||||||
|
if ($saveVars) {
|
||||||
|
$template->tpl_vars = $savedTplVars;
|
||||||
|
$template->config_vars = $savedConfigVars;
|
||||||
|
} else {
|
||||||
|
if (!$function && !isset(Template::$tplObjCache[$template->templateId])) {
|
||||||
|
$template->parent = null;
|
||||||
|
$template->tpl_vars = $template->config_vars = [];
|
||||||
|
Template::$tplObjCache[$template->templateId] = $template;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($errorHandler)) {
|
||||||
|
$errorHandler->deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_smarty_old_error_level)) {
|
||||||
|
error_reporting($_smarty_old_error_level);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
while (ob_get_level() > $level) {
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
if (isset($errorHandler)) {
|
||||||
|
$errorHandler->deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_smarty_old_error_level)) {
|
||||||
|
error_reporting($_smarty_old_error_level);
|
||||||
|
}
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers plugin to be used in templates
|
||||||
|
*
|
||||||
|
* @param string $type plugin type
|
||||||
|
* @param string $name name of template tag
|
||||||
|
* @param callable $callback PHP callback to register
|
||||||
|
* @param bool $cacheable if true (default) this function is cache able
|
||||||
|
* @param mixed $cache_attr caching attributes if any
|
||||||
|
*
|
||||||
|
* @return \Smarty|\Smarty\Template
|
||||||
|
* @throws \SmartyException
|
||||||
|
* @link https://www.smarty.net/docs/en/api.register.plugin.tpl
|
||||||
|
*
|
||||||
|
* @api Smarty::registerPlugin()
|
||||||
|
*/
|
||||||
|
public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
if (isset($smarty->registered_plugins[$type][$name])) {
|
||||||
|
throw new SmartyException("Plugin tag '{$name}' already registered");
|
||||||
|
} elseif (!is_callable($callback)) {
|
||||||
|
throw new SmartyException("Plugin '{$name}' not callable");
|
||||||
|
} elseif ($cacheable && $cache_attr) {
|
||||||
|
throw new SmartyException("Cannot set caching attributes for plugin '{$name}' when it is cacheable.");
|
||||||
|
} else {
|
||||||
|
$smarty->registered_plugins[$type][$name] = [$callback, (bool)$cacheable, (array)$cache_attr];
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers plugin to be used in templates
|
||||||
|
*
|
||||||
|
* @param string $type plugin type
|
||||||
|
* @param string $name name of template tag
|
||||||
|
*
|
||||||
|
* @return \Smarty|\Smarty\Template
|
||||||
|
* @link https://www.smarty.net/docs/en/api.unregister.plugin.tpl
|
||||||
|
*
|
||||||
|
* @api Smarty::unregisterPlugin()
|
||||||
|
*/
|
||||||
|
public function unregisterPlugin($type, $name) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
if (isset($smarty->registered_plugins[$type][$name])) {
|
||||||
|
unset($smarty->registered_plugins[$type][$name]);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* load a filter of specified type and name
|
||||||
|
*
|
||||||
|
* @param string $type filter type
|
||||||
|
* @param string $name filter name
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
* @throws \SmartyException
|
||||||
|
* @api Smarty::loadFilter()
|
||||||
|
* @link https://www.smarty.net/docs/en/api.load.filter.tpl
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function loadFilter($type, $name) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
$this->_checkFilterType($type);
|
||||||
|
$_plugin = "smarty_{$type}filter_{$name}";
|
||||||
|
$_filter_name = $_plugin;
|
||||||
|
if (is_callable($_plugin)) {
|
||||||
|
$smarty->registered_filters[$type][$_filter_name] = $_plugin;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (class_exists($_plugin, false)) {
|
||||||
|
$_plugin = [$_plugin, 'execute'];
|
||||||
|
}
|
||||||
|
if (is_callable($_plugin)) {
|
||||||
|
$smarty->registered_filters[$type][$_filter_name] = $_plugin;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
throw new SmartyException("{$type}filter '{$name}' not found or callable");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* load a filter of specified type and name
|
||||||
|
*
|
||||||
|
* @param string $type filter type
|
||||||
|
* @param string $name filter name
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @throws \SmartyException
|
||||||
|
* @api Smarty::unloadFilter()
|
||||||
|
*
|
||||||
|
* @link https://www.smarty.net/docs/en/api.unload.filter.tpl
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function unloadFilter($type, $name) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
$this->_checkFilterType($type);
|
||||||
|
if (isset($smarty->registered_filters[$type])) {
|
||||||
|
$_filter_name = "smarty_{$type}filter_{$name}";
|
||||||
|
if (isset($smarty->registered_filters[$type][$_filter_name])) {
|
||||||
|
unset($smarty->registered_filters[$type][$_filter_name]);
|
||||||
|
if (empty($smarty->registered_filters[$type])) {
|
||||||
|
unset($smarty->registered_filters[$type]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a filter function
|
||||||
|
*
|
||||||
|
* @param string $type filter type
|
||||||
|
* @param callable $callback
|
||||||
|
* @param string|null $name optional filter name
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @throws \SmartyException
|
||||||
|
* @link https://www.smarty.net/docs/en/api.register.filter.tpl
|
||||||
|
*
|
||||||
|
* @api Smarty::registerFilter()
|
||||||
|
*/
|
||||||
|
public function registerFilter($type, $callback, $name = null) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
$this->_checkFilterType($type);
|
||||||
|
$name = isset($name) ? $name : $this->_getFilterName($callback);
|
||||||
|
if (!is_callable($callback)) {
|
||||||
|
throw new SmartyException("{$type}filter '{$name}' not callable");
|
||||||
|
}
|
||||||
|
$smarty->registered_filters[$type][$name] = $callback;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregisters a filter function
|
||||||
|
*
|
||||||
|
* @param string $type filter type
|
||||||
|
* @param callback|string $callback
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @throws \SmartyException
|
||||||
|
* @api Smarty::unregisterFilter()
|
||||||
|
*
|
||||||
|
* @link https://www.smarty.net/docs/en/api.unregister.filter.tpl
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function unregisterFilter($type, $callback) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
$this->_checkFilterType($type);
|
||||||
|
if (isset($smarty->registered_filters[$type])) {
|
||||||
|
$name = is_string($callback) ? $callback : $this->_getFilterName($callback);
|
||||||
|
if (isset($smarty->registered_filters[$type][$name])) {
|
||||||
|
unset($smarty->registered_filters[$type][$name]);
|
||||||
|
if (empty($smarty->registered_filters[$type])) {
|
||||||
|
unset($smarty->registered_filters[$type]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers object to be used in templates
|
||||||
|
*
|
||||||
|
* @param string $object_name
|
||||||
|
* @param object $object the referenced PHP object to register
|
||||||
|
* @param array $allowed_methods_properties list of allowed methods (empty = all)
|
||||||
|
* @param bool $format smarty argument format, else traditional
|
||||||
|
* @param array $block_methods list of block-methods
|
||||||
|
*
|
||||||
|
* @return \Smarty|\Smarty\Template
|
||||||
|
* @throws \SmartyException
|
||||||
|
* @link https://www.smarty.net/docs/en/api.register.object.tpl
|
||||||
|
*
|
||||||
|
* @api Smarty::registerObject()
|
||||||
|
*/
|
||||||
|
public function registerObject(
|
||||||
|
$object_name,
|
||||||
|
$object,
|
||||||
|
$allowed_methods_properties = [],
|
||||||
|
$format = true,
|
||||||
|
$block_methods = []
|
||||||
|
) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
// test if allowed methods callable
|
||||||
|
if (!empty($allowed_methods_properties)) {
|
||||||
|
foreach ((array)$allowed_methods_properties as $method) {
|
||||||
|
if (!is_callable([$object, $method]) && !property_exists($object, $method)) {
|
||||||
|
throw new SmartyException("Undefined method or property '$method' in registered object");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// test if block methods callable
|
||||||
|
if (!empty($block_methods)) {
|
||||||
|
foreach ((array)$block_methods as $method) {
|
||||||
|
if (!is_callable([$object, $method])) {
|
||||||
|
throw new SmartyException("Undefined method '$method' in registered object");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// register the object
|
||||||
|
$smarty->registered_objects[$object_name] =
|
||||||
|
[$object, (array)$allowed_methods_properties, (boolean)$format, (array)$block_methods];
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers plugin to be used in templates
|
||||||
|
*
|
||||||
|
* @param string $object_name name of object
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @api Smarty::unregisterObject()
|
||||||
|
* @link https://www.smarty.net/docs/en/api.unregister.object.tpl
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function unregisterObject($object_name) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
if (isset($smarty->registered_objects[$object_name])) {
|
||||||
|
unset($smarty->registered_objects[$object_name]);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $compile_check
|
||||||
|
*/
|
||||||
|
public function setCompileCheck($compile_check) {
|
||||||
|
$this->compile_check = (int)$compile_check;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $caching
|
||||||
|
*/
|
||||||
|
public function setCaching($caching) {
|
||||||
|
$this->caching = (int)$caching;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $cache_lifetime
|
||||||
|
*/
|
||||||
|
public function setCacheLifetime($cache_lifetime) {
|
||||||
|
$this->cache_lifetime = $cache_lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $compile_id
|
||||||
|
*/
|
||||||
|
public function setCompileId($compile_id) {
|
||||||
|
$this->compile_id = $compile_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $cache_id
|
||||||
|
*/
|
||||||
|
public function setCacheId($cache_id) {
|
||||||
|
$this->cache_id = $cache_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add default modifiers
|
||||||
|
*
|
||||||
|
* @param array|string $modifiers modifier or list of modifiers
|
||||||
|
* to add
|
||||||
|
*
|
||||||
|
* @return \Smarty|\Smarty\Template
|
||||||
|
* @api Smarty::addDefaultModifiers()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function addDefaultModifiers($modifiers) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
if (is_array($modifiers)) {
|
||||||
|
$smarty->default_modifiers = array_merge($smarty->default_modifiers, $modifiers);
|
||||||
|
} else {
|
||||||
|
$smarty->default_modifiers[] = $modifiers;
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a data object
|
||||||
|
*
|
||||||
|
* @param Data|null $parent next higher level of Smarty
|
||||||
|
* variables
|
||||||
|
* @param null $name optional data block name
|
||||||
|
*
|
||||||
|
* @return Smarty_Data data object
|
||||||
|
* @throws SmartyException
|
||||||
|
* @api Smarty::createData()
|
||||||
|
* @link https://www.smarty.net/docs/en/api.create.data.tpl
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function createData(Data $parent = null, $name = null) {
|
||||||
|
/* @var Smarty $smarty */
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
$dataObj = new Smarty_Data($parent, $smarty, $name);
|
||||||
|
if ($smarty->debugging) {
|
||||||
|
\Smarty\Debug::register_data($dataObj);
|
||||||
|
}
|
||||||
|
return $dataObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return name of debugging template
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @api Smarty::getDebugTemplate()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getDebugTemplate() {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
return $smarty->debug_tpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default modifiers
|
||||||
|
*
|
||||||
|
* @return array list of default modifiers
|
||||||
|
* @api Smarty::getDefaultModifiers()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getDefaultModifiers() {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
return $smarty->default_modifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return a reference to a registered object
|
||||||
|
*
|
||||||
|
* @param string $object_name object name
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
* @throws \SmartyException if no such object is found
|
||||||
|
* @link https://www.smarty.net/docs/en/api.get.registered.object.tpl
|
||||||
|
*
|
||||||
|
* @api Smarty::getRegisteredObject()
|
||||||
|
*/
|
||||||
|
public function getRegisteredObject($object_name) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
if (!isset($smarty->registered_objects[$object_name])) {
|
||||||
|
throw new SmartyException("'$object_name' is not a registered object");
|
||||||
|
}
|
||||||
|
if (!is_object($smarty->registered_objects[$object_name][0])) {
|
||||||
|
throw new SmartyException("registered '$object_name' is not an object");
|
||||||
|
}
|
||||||
|
return $smarty->registered_objects[$object_name][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get literals
|
||||||
|
*
|
||||||
|
* @return array list of literals
|
||||||
|
* @api Smarty::getLiterals()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getLiterals() {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
return (array)$smarty->literals;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add literals
|
||||||
|
*
|
||||||
|
* @param array|string $literals literal or list of literals
|
||||||
|
* to addto add
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @throws \SmartyException
|
||||||
|
* @api Smarty::addLiterals()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function addLiterals($literals = null) {
|
||||||
|
if (isset($literals)) {
|
||||||
|
$this->_setLiterals($this->_getSmartyObj(), (array)$literals);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set literals
|
||||||
|
*
|
||||||
|
* @param array|string $literals literal or list of literals
|
||||||
|
* to setto set
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @throws \SmartyException
|
||||||
|
* @api Smarty::setLiterals()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setLiterals($literals = null) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
$smarty->literals = [];
|
||||||
|
if (!empty($literals)) {
|
||||||
|
$this->_setLiterals($smarty, (array)$literals);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* common setter for literals for easier handling of duplicates the
|
||||||
|
* Smarty::$literals array gets filled with identical key values
|
||||||
|
*
|
||||||
|
* @param Smarty $smarty
|
||||||
|
* @param array $literals
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
private function _setLiterals(Smarty $smarty, $literals) {
|
||||||
|
$literals = array_combine($literals, $literals);
|
||||||
|
$error = isset($literals[$smarty->left_delimiter]) ? [$smarty->left_delimiter] : [];
|
||||||
|
$error = isset($literals[$smarty->right_delimiter]) ? $error[] = $smarty->right_delimiter : $error;
|
||||||
|
if (!empty($error)) {
|
||||||
|
throw new SmartyException(
|
||||||
|
'User defined literal(s) "' . $error .
|
||||||
|
'" may not be identical with left or right delimiter'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$smarty->literals = array_merge((array)$smarty->literals, (array)$literals);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if filter type is valid
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
*
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
private function _checkFilterType($type) {
|
||||||
|
if (!isset($this->filterTypes[$type])) {
|
||||||
|
throw new SmartyException("Illegal filter type '{$type}'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return internal filter name
|
||||||
|
*
|
||||||
|
* @param callback $function_name
|
||||||
|
*
|
||||||
|
* @return string internal filter name
|
||||||
|
*/
|
||||||
|
private function _getFilterName($function_name) {
|
||||||
|
if (is_array($function_name)) {
|
||||||
|
$_class_name = (is_object($function_name[0]) ? get_class($function_name[0]) : $function_name[0]);
|
||||||
|
return $_class_name . '_' . $function_name[1];
|
||||||
|
} elseif (is_string($function_name)) {
|
||||||
|
return $function_name;
|
||||||
|
} else {
|
||||||
|
return 'closure';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers static classes to be used in templates
|
||||||
|
*
|
||||||
|
* @param string $class_name
|
||||||
|
* @param string $class_impl the referenced PHP class to
|
||||||
|
* register
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @throws \SmartyException
|
||||||
|
* @api Smarty::registerClass()
|
||||||
|
* @link https://www.smarty.net/docs/en/api.register.class.tpl
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function registerClass($class_name, $class_impl) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
// test if exists
|
||||||
|
if (!class_exists($class_impl)) {
|
||||||
|
throw new SmartyException("Undefined class '$class_impl' in register template class");
|
||||||
|
}
|
||||||
|
// register the class
|
||||||
|
$smarty->registered_classes[$class_name] = $class_impl;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a resource to fetch a template
|
||||||
|
*
|
||||||
|
* @param string $name name of resource type
|
||||||
|
* @param Base $resource_handler
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @link https://www.smarty.net/docs/en/api.register.cacheresource.tpl
|
||||||
|
*
|
||||||
|
* @api Smarty::registerCacheResource()
|
||||||
|
*/
|
||||||
|
public function registerCacheResource($name, Base $resource_handler) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
$smarty->registered_cache_resources[$name] = $resource_handler;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregisters a resource to fetch a template
|
||||||
|
*
|
||||||
|
* @param $name
|
||||||
|
*
|
||||||
|
* @return \Smarty|\Smarty\Template
|
||||||
|
* @api Smarty::unregisterCacheResource()
|
||||||
|
* @link https://www.smarty.net/docs/en/api.unregister.cacheresource.tpl
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function unregisterCacheResource($name) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
if (isset($smarty->registered_cache_resources[$name])) {
|
||||||
|
unset($smarty->registered_cache_resources[$name]);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register config default handler
|
||||||
|
*
|
||||||
|
* @param callable $callback class/method name
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @throws SmartyException if $callback is not callable
|
||||||
|
* @api Smarty::registerDefaultConfigHandler()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function registerDefaultConfigHandler($callback) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
if (is_callable($callback)) {
|
||||||
|
$smarty->default_config_handler_func = $callback;
|
||||||
|
} else {
|
||||||
|
throw new SmartyException('Default config handler not callable');
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a default plugin handler
|
||||||
|
*
|
||||||
|
* @param callable $callback class/method name
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @throws SmartyException if $callback is not callable
|
||||||
|
* @link https://www.smarty.net/docs/en/api.register.default.plugin.handler.tpl
|
||||||
|
*
|
||||||
|
* @api Smarty::registerDefaultPluginHandler()
|
||||||
|
*/
|
||||||
|
public function registerDefaultPluginHandler($callback) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
if (is_callable($callback)) {
|
||||||
|
$smarty->default_plugin_handler_func = $callback;
|
||||||
|
} else {
|
||||||
|
throw new SmartyException("Default plugin handler '$callback' not callable");
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register template default handler
|
||||||
|
*
|
||||||
|
* @param callable $callback class/method name
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @throws SmartyException if $callback is not callable
|
||||||
|
* @api Smarty::registerDefaultTemplateHandler()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function registerDefaultTemplateHandler($callback) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
if (is_callable($callback)) {
|
||||||
|
$smarty->default_template_handler_func = $callback;
|
||||||
|
} else {
|
||||||
|
throw new SmartyException('Default template handler not callable');
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a resource to fetch a template
|
||||||
|
*
|
||||||
|
* @param string $name name of resource type
|
||||||
|
* @param Smarty\Resource\Base $resource_handler instance of Smarty\Resource\Base
|
||||||
|
*
|
||||||
|
* @return \Smarty|\Smarty\Template
|
||||||
|
* @link https://www.smarty.net/docs/en/api.register.resource.tpl
|
||||||
|
*
|
||||||
|
* @api Smarty::registerResource()
|
||||||
|
*/
|
||||||
|
public function registerResource($name, Smarty\Resource\Base $resource_handler) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
$smarty->registered_resources[$name] = $resource_handler;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregisters a resource to fetch a template
|
||||||
|
*
|
||||||
|
* @param string $type name of resource type
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @api Smarty::unregisterResource()
|
||||||
|
* @link https://www.smarty.net/docs/en/api.unregister.resource.tpl
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function unregisterResource($type) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
if (isset($smarty->registered_resources[$type])) {
|
||||||
|
unset($smarty->registered_resources[$type]);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the debug template
|
||||||
|
*
|
||||||
|
* @param string $tpl_name
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @throws SmartyException if file is not readable
|
||||||
|
* @api Smarty::setDebugTemplate()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setDebugTemplate($tpl_name) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
if (!is_readable($tpl_name)) {
|
||||||
|
throw new SmartyException("Unknown file '{$tpl_name}'");
|
||||||
|
}
|
||||||
|
$smarty->debug_tpl = $tpl_name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set default modifiers
|
||||||
|
*
|
||||||
|
* @param array|string $modifiers modifier or list of modifiers
|
||||||
|
* to set
|
||||||
|
*
|
||||||
|
* @return TemplateBase
|
||||||
|
* @api Smarty::setDefaultModifiers()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setDefaultModifiers($modifiers) {
|
||||||
|
$smarty = $this->_getSmartyObj();
|
||||||
|
$smarty->default_modifiers = (array)$modifiers;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* This file is part of the Smarty package.
|
|
||||||
*
|
|
||||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Load and register Smarty Autoloader
|
|
||||||
*/
|
|
||||||
if (!class_exists('Smarty_Autoloader')) {
|
|
||||||
include __DIR__ . '/Autoloader.php';
|
|
||||||
}
|
|
||||||
Smarty_Autoloader::register(true);
|
|
@@ -1,930 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Smarty Internal Plugin Template
|
|
||||||
* This file contains the Smarty template engine
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage Template
|
|
||||||
* @author Uwe Tews
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Smarty\Data;
|
|
||||||
use Smarty\Runtime\InheritanceRuntime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main class with template data structures and methods
|
|
||||||
*
|
|
||||||
* @property Smarty_Template_Compiled $compiled
|
|
||||||
* @property Smarty_Template_Cached $cached
|
|
||||||
* @property \Smarty\Compiler\Template $compiler
|
|
||||||
* @property mixed|\Smarty_Template_Cached registered_plugins
|
|
||||||
*/
|
|
||||||
#[\AllowDynamicProperties]
|
|
||||||
class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Template object cache
|
|
||||||
*
|
|
||||||
* @var Smarty_Internal_Template[]
|
|
||||||
*/
|
|
||||||
public static $tplObjCache = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template object cache for Smarty::isCached() === true
|
|
||||||
*
|
|
||||||
* @var Smarty_Internal_Template[]
|
|
||||||
*/
|
|
||||||
public static $isCacheTplObj = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sub template Info Cache
|
|
||||||
* - index name
|
|
||||||
* - value use count
|
|
||||||
*
|
|
||||||
* @var int[]
|
|
||||||
*/
|
|
||||||
public static $subTplInfo = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This object type (Smarty = 1, template = 2, data = 4)
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $_objType = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Source instance
|
|
||||||
*
|
|
||||||
* @var Smarty_Template_Source|Smarty_Template_Config
|
|
||||||
*/
|
|
||||||
public $source = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inheritance runtime extension
|
|
||||||
*
|
|
||||||
* @var InheritanceRuntime
|
|
||||||
*/
|
|
||||||
public $inheritance = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template resource
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $template_resource = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* flag if compiled template is invalid and must be (re)compiled
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $mustCompile = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template Id
|
|
||||||
*
|
|
||||||
* @var null|string
|
|
||||||
*/
|
|
||||||
public $templateId = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scope in which variables shall be assigned
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $scope = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag which is set while rending a cache file
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $isRenderingCache = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callbacks called before rendering template
|
|
||||||
*
|
|
||||||
* @var callback[]
|
|
||||||
*/
|
|
||||||
public $startRenderCallbacks = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callbacks called after rendering template
|
|
||||||
*
|
|
||||||
* @var callback[]
|
|
||||||
*/
|
|
||||||
public $endRenderCallbacks = array();
|
|
||||||
/**
|
|
||||||
* @var \Smarty\Compiler\CodeFrame
|
|
||||||
*/
|
|
||||||
private $codeFrameCompiler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create template data object
|
|
||||||
* Some of the global Smarty settings copied to template scope
|
|
||||||
* It load the required template resources and caching plugins
|
|
||||||
*
|
|
||||||
* @param string $template_resource template resource string
|
|
||||||
* @param Smarty $smarty Smarty instance
|
|
||||||
* @param null|\Smarty_Internal_Template|\Smarty|\Smarty\Data $_parent back pointer to parent
|
|
||||||
* object with variables or
|
|
||||||
* null
|
|
||||||
* @param mixed $_cache_id cache id or null
|
|
||||||
* @param mixed $_compile_id compile id or null
|
|
||||||
* @param bool|int|null $_caching use caching?
|
|
||||||
* @param int|null $_cache_lifetime cache life-time in
|
|
||||||
* seconds
|
|
||||||
* @param bool $_isConfig
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
$template_resource,
|
|
||||||
Smarty $smarty,
|
|
||||||
\Smarty\Data $_parent = null,
|
|
||||||
$_cache_id = null,
|
|
||||||
$_compile_id = null,
|
|
||||||
$_caching = null,
|
|
||||||
$_cache_lifetime = null,
|
|
||||||
$_isConfig = false
|
|
||||||
) {
|
|
||||||
$this->smarty = $smarty;
|
|
||||||
// Smarty parameter
|
|
||||||
$this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
|
|
||||||
$this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
|
|
||||||
$this->caching = (int)($_caching === null ? $this->smarty->caching : $_caching);
|
|
||||||
$this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime;
|
|
||||||
$this->compile_check = (int)$smarty->compile_check;
|
|
||||||
$this->parent = $_parent;
|
|
||||||
// Template resource
|
|
||||||
$this->template_resource = $template_resource;
|
|
||||||
$this->source = $_isConfig ? Smarty_Template_Config::load($this) : Smarty_Template_Source::load($this);
|
|
||||||
parent::__construct();
|
|
||||||
if ($smarty->security_policy && method_exists($smarty->security_policy, 'registerCallBacks')) {
|
|
||||||
$smarty->security_policy->registerCallBacks($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->codeFrameCompiler = new Smarty\Compiler\CodeFrame($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* render template
|
|
||||||
*
|
|
||||||
* @param bool $no_output_filter if true do not run output filter
|
|
||||||
* @param null|bool $display true: display, false: fetch null: sub-template
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
* @throws \Exception
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function render($no_output_filter = true, $display = null)
|
|
||||||
{
|
|
||||||
if ($this->smarty->debugging) {
|
|
||||||
if (!isset($this->smarty->_debug)) {
|
|
||||||
$this->smarty->_debug = new \Smarty\Debug();
|
|
||||||
}
|
|
||||||
$this->smarty->_debug->start_template($this, $display);
|
|
||||||
}
|
|
||||||
// checks if template exists
|
|
||||||
if (!$this->source->exists) {
|
|
||||||
throw new SmartyException(
|
|
||||||
"Unable to load template '{$this->source->type}:{$this->source->name}'" .
|
|
||||||
($this->_isSubTpl() ? " in '{$this->parent->template_resource}'" : '')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// disable caching for evaluated code
|
|
||||||
if ($this->source->handler->recompiled) {
|
|
||||||
$this->caching = \Smarty\Smarty::CACHING_OFF;
|
|
||||||
}
|
|
||||||
// read from cache or render
|
|
||||||
if ($this->caching === \Smarty\Smarty::CACHING_LIFETIME_CURRENT || $this->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED) {
|
|
||||||
if (!isset($this->cached) || $this->cached->cache_id !== $this->cache_id
|
|
||||||
|| $this->cached->compile_id !== $this->compile_id
|
|
||||||
) {
|
|
||||||
$this->loadCached(true);
|
|
||||||
}
|
|
||||||
$this->cached->render($this, $no_output_filter);
|
|
||||||
} else {
|
|
||||||
if (!isset($this->compiled) || $this->compiled->compile_id !== $this->compile_id) {
|
|
||||||
$this->loadCompiled(true);
|
|
||||||
}
|
|
||||||
$this->compiled->render($this);
|
|
||||||
}
|
|
||||||
// display or fetch
|
|
||||||
if ($display) {
|
|
||||||
if ($this->caching && $this->smarty->cache_modified_check) {
|
|
||||||
$this->smarty->cacheModifiedCheck(
|
|
||||||
$this->cached,
|
|
||||||
$this,
|
|
||||||
isset($content) ? $content : ob_get_clean()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
|
|
||||||
&& !$no_output_filter && isset($this->smarty->registered_filters[ 'output' ])
|
|
||||||
) {
|
|
||||||
echo $this->smarty->runFilter('output', ob_get_clean(), $this);
|
|
||||||
} else {
|
|
||||||
echo ob_get_clean();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($this->smarty->debugging) {
|
|
||||||
$this->smarty->_debug->end_template($this);
|
|
||||||
// debug output
|
|
||||||
$this->smarty->_debug->display_debug($this, true);
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
} else {
|
|
||||||
if ($this->smarty->debugging) {
|
|
||||||
$this->smarty->_debug->end_template($this);
|
|
||||||
if ($this->smarty->debugging === 2 && $display === false) {
|
|
||||||
$this->smarty->_debug->display_debug($this, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
!$no_output_filter
|
|
||||||
&& (!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
|
|
||||||
&& isset($this->smarty->registered_filters[ 'output' ])
|
|
||||||
) {
|
|
||||||
return $this->smarty->runFilter('output', ob_get_clean(), $this);
|
|
||||||
}
|
|
||||||
// return cache content
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runtime function to render sub-template
|
|
||||||
*
|
|
||||||
* @param string $template template name
|
|
||||||
* @param mixed $cache_id cache id
|
|
||||||
* @param mixed $compile_id compile id
|
|
||||||
* @param integer $caching cache mode
|
|
||||||
* @param integer $cache_lifetime life time of cache data
|
|
||||||
* @param array $data passed parameter template variables
|
|
||||||
* @param int $scope scope in which {include} should execute
|
|
||||||
* @param bool $forceTplCache cache template object
|
|
||||||
* @param string $uid file dependency uid
|
|
||||||
* @param string $content_func function name
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function _subTemplateRender(
|
|
||||||
$template,
|
|
||||||
$cache_id,
|
|
||||||
$compile_id,
|
|
||||||
$caching,
|
|
||||||
$cache_lifetime,
|
|
||||||
$data,
|
|
||||||
$scope,
|
|
||||||
$forceTplCache,
|
|
||||||
$uid = null,
|
|
||||||
$content_func = null
|
|
||||||
) {
|
|
||||||
$tpl = clone $this;
|
|
||||||
$tpl->parent = $this;
|
|
||||||
$smarty = &$this->smarty;
|
|
||||||
$_templateId = $smarty->_getTemplateId($template, $cache_id, $compile_id, $caching, $tpl);
|
|
||||||
// recursive call ?
|
|
||||||
if ((isset($tpl->templateId) ? $tpl->templateId : $tpl->_getTemplateId()) !== $_templateId) {
|
|
||||||
// already in template cache?
|
|
||||||
if (isset(self::$tplObjCache[ $_templateId ])) {
|
|
||||||
// copy data from cached object
|
|
||||||
$cachedTpl = &self::$tplObjCache[ $_templateId ];
|
|
||||||
$tpl->templateId = $cachedTpl->templateId;
|
|
||||||
$tpl->template_resource = $cachedTpl->template_resource;
|
|
||||||
$tpl->cache_id = $cachedTpl->cache_id;
|
|
||||||
$tpl->compile_id = $cachedTpl->compile_id;
|
|
||||||
$tpl->source = $cachedTpl->source;
|
|
||||||
if (isset($cachedTpl->compiled)) {
|
|
||||||
$tpl->compiled = $cachedTpl->compiled;
|
|
||||||
} else {
|
|
||||||
unset($tpl->compiled);
|
|
||||||
}
|
|
||||||
if ($caching !== 9999 && isset($cachedTpl->cached)) {
|
|
||||||
$tpl->cached = $cachedTpl->cached;
|
|
||||||
} else {
|
|
||||||
unset($tpl->cached);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$tpl->templateId = $_templateId;
|
|
||||||
$tpl->template_resource = $template;
|
|
||||||
$tpl->cache_id = $cache_id;
|
|
||||||
$tpl->compile_id = $compile_id;
|
|
||||||
if (isset($uid)) {
|
|
||||||
// for inline templates we can get all resource information from file dependency
|
|
||||||
[$filepath, $timestamp, $type] = $tpl->compiled->file_dependency[ $uid ];
|
|
||||||
$tpl->source = new Smarty_Template_Source($smarty, $filepath, $type, $filepath);
|
|
||||||
$tpl->source->filepath = $filepath;
|
|
||||||
$tpl->source->timestamp = $timestamp;
|
|
||||||
$tpl->source->exists = true;
|
|
||||||
$tpl->source->uid = $uid;
|
|
||||||
} else {
|
|
||||||
$tpl->source = Smarty_Template_Source::load($tpl);
|
|
||||||
unset($tpl->compiled);
|
|
||||||
}
|
|
||||||
if ($caching !== 9999) {
|
|
||||||
unset($tpl->cached);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// on recursive calls force caching
|
|
||||||
$forceTplCache = true;
|
|
||||||
}
|
|
||||||
$tpl->caching = $caching;
|
|
||||||
$tpl->cache_lifetime = $cache_lifetime;
|
|
||||||
// set template scope
|
|
||||||
$tpl->scope = $scope;
|
|
||||||
if (!isset(self::$tplObjCache[ $tpl->templateId ]) && !$tpl->source->handler->recompiled) {
|
|
||||||
// check if template object should be cached
|
|
||||||
if ($forceTplCache || (isset(self::$subTplInfo[ $tpl->template_resource ])
|
|
||||||
&& self::$subTplInfo[ $tpl->template_resource ] > 1)
|
|
||||||
|| ($tpl->_isSubTpl() && isset(self::$tplObjCache[ $tpl->parent->templateId ]))
|
|
||||||
) {
|
|
||||||
self::$tplObjCache[ $tpl->templateId ] = $tpl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!empty($data)) {
|
|
||||||
// set up variable values
|
|
||||||
foreach ($data as $_key => $_val) {
|
|
||||||
$tpl->tpl_vars[ $_key ] = new \Smarty\Variable($_val, $this->isRenderingCache);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($tpl->caching === 9999) {
|
|
||||||
if (!isset($tpl->compiled)) {
|
|
||||||
$tpl->loadCompiled(true);
|
|
||||||
}
|
|
||||||
if ($tpl->compiled->has_nocache_code) {
|
|
||||||
$this->cached->hashes[ $tpl->compiled->nocache_hash ] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$tpl->_cache = array();
|
|
||||||
if (isset($uid)) {
|
|
||||||
if ($smarty->debugging) {
|
|
||||||
if (!isset($smarty->_debug)) {
|
|
||||||
$smarty->_debug = new \Smarty\Debug();
|
|
||||||
}
|
|
||||||
$smarty->_debug->start_template($tpl);
|
|
||||||
$smarty->_debug->start_render($tpl);
|
|
||||||
}
|
|
||||||
$tpl->compiled->getRenderedTemplateCode($tpl, $content_func);
|
|
||||||
if ($smarty->debugging) {
|
|
||||||
$smarty->_debug->end_template($tpl);
|
|
||||||
$smarty->_debug->end_render($tpl);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isset($tpl->compiled)) {
|
|
||||||
$tpl->compiled->render($tpl);
|
|
||||||
} else {
|
|
||||||
$tpl->render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get called sub-templates and save call count
|
|
||||||
*/
|
|
||||||
public function _subTemplateRegister()
|
|
||||||
{
|
|
||||||
foreach ($this->compiled->includes as $name => $count) {
|
|
||||||
if (isset(self::$subTplInfo[ $name ])) {
|
|
||||||
self::$subTplInfo[ $name ] += $count;
|
|
||||||
} else {
|
|
||||||
self::$subTplInfo[ $name ] = $count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if this is a sub template
|
|
||||||
*
|
|
||||||
* @return bool true is sub template
|
|
||||||
*/
|
|
||||||
public function _isSubTpl()
|
|
||||||
{
|
|
||||||
return isset($this->parent) && $this->parent->_isTplObj();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assign variable in scope
|
|
||||||
*
|
|
||||||
* @param string $varName variable name
|
|
||||||
* @param mixed $value value
|
|
||||||
* @param bool $nocache nocache flag
|
|
||||||
* @param int $scope scope into which variable shall be assigned
|
|
||||||
*/
|
|
||||||
public function _assignInScope($varName, $value, $nocache = false, $scope = 0)
|
|
||||||
{
|
|
||||||
if (isset($this->tpl_vars[ $varName ])) {
|
|
||||||
$this->tpl_vars[ $varName ] = clone $this->tpl_vars[ $varName ];
|
|
||||||
$this->tpl_vars[ $varName ]->value = $value;
|
|
||||||
if ($nocache || $this->isRenderingCache) {
|
|
||||||
$this->tpl_vars[ $varName ]->nocache = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->tpl_vars[ $varName ] = new \Smarty\Variable($value, $nocache || $this->isRenderingCache);
|
|
||||||
}
|
|
||||||
if ($scope >= 0) {
|
|
||||||
if ($scope > 0 || $this->scope > 0) {
|
|
||||||
$this->_updateScope($varName, $scope);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function is executed automatically when a compiled or cached template file is included
|
|
||||||
* - Decode saved properties from compiled template and cache files
|
|
||||||
* - Check if compiled or cache file is valid
|
|
||||||
*
|
|
||||||
* @param \Smarty_Internal_Template $tpl
|
|
||||||
* @param array $properties special template properties
|
|
||||||
* @param bool $cache flag if called from cache file
|
|
||||||
*
|
|
||||||
* @return bool flag if compiled or cache file is valid
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function _decodeProperties(Smarty_Internal_Template $tpl, $properties, $cache = false)
|
|
||||||
{
|
|
||||||
// on cache resources other than file check version stored in cache code
|
|
||||||
if (!isset($properties[ 'version' ]) || \Smarty\Smarty::SMARTY_VERSION !== $properties[ 'version' ]) {
|
|
||||||
if ($cache) {
|
|
||||||
$tpl->smarty->clearAllCache();
|
|
||||||
} else {
|
|
||||||
$tpl->smarty->clearCompiledTemplate();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$is_valid = true;
|
|
||||||
if (!empty($properties[ 'file_dependency' ])
|
|
||||||
&& ((!$cache && $tpl->compile_check) || $tpl->compile_check === \Smarty\Smarty::COMPILECHECK_ON)
|
|
||||||
) {
|
|
||||||
// check file dependencies at compiled code
|
|
||||||
foreach ($properties[ 'file_dependency' ] as $_file_to_check) {
|
|
||||||
if ($_file_to_check[ 2 ] === 'file' || $_file_to_check[ 2 ] === 'php') {
|
|
||||||
if ($tpl->source->filepath === $_file_to_check[ 0 ]) {
|
|
||||||
// do not recheck current template
|
|
||||||
continue;
|
|
||||||
//$mtime = $tpl->source->getTimeStamp();
|
|
||||||
} else {
|
|
||||||
// file and php types can be checked without loading the respective resource handlers
|
|
||||||
$mtime = is_file($_file_to_check[ 0 ]) ? filemtime($_file_to_check[ 0 ]) : false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$handler = Smarty\Resource\BasePlugin::load($tpl->smarty, $_file_to_check[ 2 ]);
|
|
||||||
if ($handler->checkTimestamps()) {
|
|
||||||
$source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]);
|
|
||||||
$mtime = $source->getTimeStamp();
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($mtime === false || $mtime > $_file_to_check[ 1 ]) {
|
|
||||||
$is_valid = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($cache) {
|
|
||||||
// CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
|
|
||||||
if ($tpl->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED && $properties[ 'cache_lifetime' ] >= 0
|
|
||||||
&& (time() > ($tpl->cached->timestamp + $properties[ 'cache_lifetime' ]))
|
|
||||||
) {
|
|
||||||
$is_valid = false;
|
|
||||||
}
|
|
||||||
$tpl->cached->cache_lifetime = $properties[ 'cache_lifetime' ];
|
|
||||||
$tpl->cached->valid = $is_valid;
|
|
||||||
$resource = $tpl->cached;
|
|
||||||
} else {
|
|
||||||
$tpl->mustCompile = !$is_valid;
|
|
||||||
$resource = $tpl->compiled;
|
|
||||||
$resource->includes = isset($properties[ 'includes' ]) ? $properties[ 'includes' ] : array();
|
|
||||||
}
|
|
||||||
if ($is_valid) {
|
|
||||||
$resource->unifunc = $properties[ 'unifunc' ];
|
|
||||||
$resource->has_nocache_code = $properties[ 'has_nocache_code' ];
|
|
||||||
$resource->file_dependency = $properties[ 'file_dependency' ];
|
|
||||||
}
|
|
||||||
return $is_valid && !function_exists($properties[ 'unifunc' ]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compiles the template
|
|
||||||
* If the template is not evaluated the compiled template is saved on disk
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function compileTemplateSource()
|
|
||||||
{
|
|
||||||
return $this->compiled->compileTemplateSource($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the content to cache resource
|
|
||||||
*
|
|
||||||
* @param string $content
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function writeCachedContent($content)
|
|
||||||
{
|
|
||||||
if ($this->source->handler->recompiled || !$this->caching
|
|
||||||
) {
|
|
||||||
// don't write cache file
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!isset($this->cached)) {
|
|
||||||
$this->loadCached();
|
|
||||||
}
|
|
||||||
$codeframe = $this->createCodeFrame($content, '', true);
|
|
||||||
return $this->cached->writeCache($this, $codeframe);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get unique template id
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function _getTemplateId()
|
|
||||||
{
|
|
||||||
return $this->templateId ?? $this->templateId =
|
|
||||||
$this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* runtime error not matching capture tags
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function capture_error()
|
|
||||||
{
|
|
||||||
throw new SmartyException("Not matching {capture} open/close in '{$this->template_resource}'");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load compiled object
|
|
||||||
*
|
|
||||||
* @param bool $force force new compiled object
|
|
||||||
*/
|
|
||||||
public function loadCompiled($force = false)
|
|
||||||
{
|
|
||||||
if ($force || !isset($this->compiled)) {
|
|
||||||
$this->compiled = Smarty_Template_Compiled::load($this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load cached object
|
|
||||||
*
|
|
||||||
* @param bool $force force new cached object
|
|
||||||
*/
|
|
||||||
public function loadCached($force = false)
|
|
||||||
{
|
|
||||||
if ($force || !isset($this->cached)) {
|
|
||||||
$this->cached = Smarty_Template_Cached::load($this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load inheritance object
|
|
||||||
*/
|
|
||||||
public function _loadInheritance()
|
|
||||||
{
|
|
||||||
if (!isset($this->inheritance)) {
|
|
||||||
$this->inheritance = new InheritanceRuntime();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unload inheritance object
|
|
||||||
*/
|
|
||||||
public function _cleanUp()
|
|
||||||
{
|
|
||||||
$this->startRenderCallbacks = array();
|
|
||||||
$this->endRenderCallbacks = array();
|
|
||||||
$this->inheritance = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load compiler object
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function loadCompiler()
|
|
||||||
{
|
|
||||||
$this->compiler =
|
|
||||||
new $this->source->compiler_class(
|
|
||||||
$this->source->template_lexer_class,
|
|
||||||
$this->source->template_parser_class,
|
|
||||||
$this->smarty
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create code frame for compiled and cached templates
|
|
||||||
*
|
|
||||||
* @param string $content optional template content
|
|
||||||
* @param string $functions compiled template function and block code
|
|
||||||
* @param bool $cache flag for cache file
|
|
||||||
* @param \Smarty\Compiler\Template $compiler
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function createCodeFrame($content = '', $functions = '', $cache = false, \Smarty\Compiler\Template $compiler = null) {
|
|
||||||
return $this->codeFrameCompiler->create($content, $functions, $cache, $compiler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle unknown class methods
|
|
||||||
*
|
|
||||||
* @param string $name unknown method-name
|
|
||||||
* @param array $args argument array
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function __call($name, $args)
|
|
||||||
{
|
|
||||||
// method of Smarty object?
|
|
||||||
if (method_exists($this->smarty, $name)) {
|
|
||||||
return call_user_func_array(array($this->smarty, $name), $args);
|
|
||||||
}
|
|
||||||
// parent
|
|
||||||
return parent::__call($name, $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get Smarty property in template context
|
|
||||||
*
|
|
||||||
* @param string $property_name property name
|
|
||||||
*
|
|
||||||
* @return mixed|Smarty_Template_Cached
|
|
||||||
* @throws SmartyException
|
|
||||||
*/
|
|
||||||
public function __get($property_name)
|
|
||||||
{
|
|
||||||
switch ($property_name) {
|
|
||||||
case 'compiled':
|
|
||||||
$this->loadCompiled();
|
|
||||||
return $this->compiled;
|
|
||||||
case 'cached':
|
|
||||||
$this->loadCached();
|
|
||||||
return $this->cached;
|
|
||||||
case 'compiler':
|
|
||||||
$this->loadCompiler();
|
|
||||||
return $this->compiler;
|
|
||||||
default:
|
|
||||||
// Smarty property ?
|
|
||||||
if (property_exists($this->smarty, $property_name)) {
|
|
||||||
return $this->smarty->$property_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new SmartyException("template property '$property_name' does not exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set Smarty property in template context
|
|
||||||
*
|
|
||||||
* @param string $property_name property name
|
|
||||||
* @param mixed $value value
|
|
||||||
*
|
|
||||||
* @throws SmartyException
|
|
||||||
*/
|
|
||||||
public function __set($property_name, $value)
|
|
||||||
{
|
|
||||||
switch ($property_name) {
|
|
||||||
case 'compiled':
|
|
||||||
case 'cached':
|
|
||||||
case 'compiler':
|
|
||||||
$this->$property_name = $value;
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
// Smarty property ?
|
|
||||||
if (property_exists($this->smarty, $property_name)) {
|
|
||||||
$this->smarty->$property_name = $value;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new SmartyException("invalid template property '$property_name'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template data object destructor
|
|
||||||
*/
|
|
||||||
public function __destruct()
|
|
||||||
{
|
|
||||||
if ($this->smarty->cache_locking && isset($this->cached) && $this->cached->is_locked) {
|
|
||||||
$this->cached->handler->releaseLock($this->smarty, $this->cached);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* load config variables into template object
|
|
||||||
*
|
|
||||||
* @param \Smarty_Internal_Template $tpl
|
|
||||||
* @param array $new_config_vars
|
|
||||||
*/
|
|
||||||
public function _loadConfigVars($new_config_vars)
|
|
||||||
{
|
|
||||||
$this->_assignConfigVars($this->parent->config_vars, $new_config_vars);
|
|
||||||
$tagScope = $this->source->scope;
|
|
||||||
if ($tagScope >= 0) {
|
|
||||||
if ($tagScope === \Smarty\Smarty::SCOPE_LOCAL) {
|
|
||||||
$this->_updateConfigVarStack($new_config_vars);
|
|
||||||
$tagScope = 0;
|
|
||||||
if (!$this->scope) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($this->parent->_isTplObj() && ($tagScope || $this->parent->scope)) {
|
|
||||||
$mergedScope = $tagScope | $this->scope;
|
|
||||||
if ($mergedScope) {
|
|
||||||
// update scopes
|
|
||||||
/* @var \Smarty_Internal_Template|\Smarty|Data $ptr */
|
|
||||||
foreach ($this->parent->_getAffectedScopes($mergedScope) as $ptr) {
|
|
||||||
$this->_assignConfigVars($ptr->config_vars, $new_config_vars);
|
|
||||||
if ($tagScope && $ptr->_isTplObj() && isset($this->_var_stack)) {
|
|
||||||
$this->_updateConfigVarStack($new_config_vars);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assign all config variables in given scope
|
|
||||||
*
|
|
||||||
* @param array $config_vars config variables in scope
|
|
||||||
* @param array $new_config_vars loaded config variables
|
|
||||||
*/
|
|
||||||
private function _assignConfigVars(&$config_vars, $new_config_vars)
|
|
||||||
{
|
|
||||||
// copy global config vars
|
|
||||||
foreach ($new_config_vars[ 'vars' ] as $variable => $value) {
|
|
||||||
if ($this->smarty->config_overwrite || !isset($config_vars[ $variable ])) {
|
|
||||||
$config_vars[ $variable ] = $value;
|
|
||||||
} else {
|
|
||||||
$config_vars[ $variable ] = array_merge((array)$config_vars[ $variable ], (array)$value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// scan sections
|
|
||||||
$sections = $this->source->config_sections;
|
|
||||||
if (!empty($sections)) {
|
|
||||||
foreach ((array)$sections as $tpl_section) {
|
|
||||||
if (isset($new_config_vars[ 'sections' ][ $tpl_section ])) {
|
|
||||||
foreach ($new_config_vars[ 'sections' ][ $tpl_section ][ 'vars' ] as $variable => $value) {
|
|
||||||
if ($this->smarty->config_overwrite || !isset($config_vars[ $variable ])) {
|
|
||||||
$config_vars[ $variable ] = $value;
|
|
||||||
} else {
|
|
||||||
$config_vars[ $variable ] = array_merge((array)$config_vars[ $variable ], (array)$value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update config variables in template local variable stack
|
|
||||||
*
|
|
||||||
* @param array $config_vars
|
|
||||||
*/
|
|
||||||
private function _updateConfigVarStack($config_vars)
|
|
||||||
{
|
|
||||||
$i = 0;
|
|
||||||
while (isset($this->_var_stack[ $i ])) {
|
|
||||||
$this->_assignConfigVars($this->_var_stack[ $i ][ 'config' ], $config_vars);
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns if the current template must be compiled by the Smarty compiler
|
|
||||||
* It does compare the timestamps of template source and the compiled templates and checks the force compile
|
|
||||||
* configuration
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function mustCompile()
|
|
||||||
{
|
|
||||||
if (!$this->source->exists) {
|
|
||||||
if ($this->_isSubTpl()) {
|
|
||||||
$parent_resource = " in '{$this->parent->template_resource}'";
|
|
||||||
} else {
|
|
||||||
$parent_resource = '';
|
|
||||||
}
|
|
||||||
throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
|
|
||||||
}
|
|
||||||
if ($this->mustCompile === null) {
|
|
||||||
$this->mustCompile = (!$this->source->handler->uncompiled &&
|
|
||||||
($this->smarty->force_compile || $this->source->handler->recompiled ||
|
|
||||||
!$this->compiled->exists || ($this->compile_check &&
|
|
||||||
$this->compiled->getTimeStamp() <
|
|
||||||
$this->source->getTimeStamp())));
|
|
||||||
}
|
|
||||||
return $this->mustCompile;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update new assigned template or config variable in other effected scopes
|
|
||||||
*
|
|
||||||
* @param string|null $varName variable name
|
|
||||||
* @param int $tagScope tag scope to which bubble up variable value
|
|
||||||
*/
|
|
||||||
protected function _updateScope($varName, $tagScope = 0)
|
|
||||||
{
|
|
||||||
if ($tagScope) {
|
|
||||||
$this->_updateVarStack($this, $varName);
|
|
||||||
$tagScope = $tagScope & ~\Smarty\Smarty::SCOPE_LOCAL;
|
|
||||||
if (!$this->scope && !$tagScope) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$mergedScope = $tagScope | $this->scope;
|
|
||||||
if ($mergedScope) {
|
|
||||||
if ($mergedScope & \Smarty\Smarty::SCOPE_GLOBAL && $varName) {
|
|
||||||
\Smarty\Smarty::$global_tpl_vars[ $varName ] = $this->tpl_vars[ $varName ];
|
|
||||||
}
|
|
||||||
// update scopes
|
|
||||||
foreach ($this->_getAffectedScopes($mergedScope) as $ptr) {
|
|
||||||
$this->_updateVariableInOtherScope($ptr->tpl_vars, $varName);
|
|
||||||
if ($tagScope && $ptr->_isTplObj() && isset($this->_var_stack)) {
|
|
||||||
$this->_updateVarStack($ptr, $varName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get array of objects which needs to be updated by given scope value
|
|
||||||
*
|
|
||||||
* @param int $mergedScope merged tag and template scope to which bubble up variable value
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function _getAffectedScopes($mergedScope)
|
|
||||||
{
|
|
||||||
$_stack = array();
|
|
||||||
$ptr = $this->parent;
|
|
||||||
if ($mergedScope && isset($ptr) && $ptr->_isTplObj()) {
|
|
||||||
$_stack[] = $ptr;
|
|
||||||
$mergedScope = $mergedScope & ~\Smarty\Smarty::SCOPE_PARENT;
|
|
||||||
if (!$mergedScope) {
|
|
||||||
// only parent was set, we are done
|
|
||||||
return $_stack;
|
|
||||||
}
|
|
||||||
$ptr = $ptr->parent;
|
|
||||||
}
|
|
||||||
while (isset($ptr) && $ptr->_isTplObj()) {
|
|
||||||
$_stack[] = $ptr;
|
|
||||||
$ptr = $ptr->parent;
|
|
||||||
}
|
|
||||||
if ($mergedScope & \Smarty\Smarty::SCOPE_SMARTY) {
|
|
||||||
if (isset($this->smarty)) {
|
|
||||||
$_stack[] = $this->smarty;
|
|
||||||
}
|
|
||||||
} elseif ($mergedScope & \Smarty\Smarty::SCOPE_ROOT) {
|
|
||||||
while (isset($ptr)) {
|
|
||||||
if (!$ptr->_isTplObj()) {
|
|
||||||
$_stack[] = $ptr;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$ptr = $ptr->parent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $_stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update variable in other scope
|
|
||||||
*
|
|
||||||
* @param array $tpl_vars template variable array
|
|
||||||
* @param string $varName variable name
|
|
||||||
*/
|
|
||||||
private function _updateVariableInOtherScope(&$tpl_vars, $varName)
|
|
||||||
{
|
|
||||||
if (!isset($tpl_vars[ $varName ])) {
|
|
||||||
$tpl_vars[ $varName ] = clone $this->tpl_vars[ $varName ];
|
|
||||||
} else {
|
|
||||||
$tpl_vars[ $varName ] = clone $tpl_vars[ $varName ];
|
|
||||||
$tpl_vars[ $varName ]->value = $this->tpl_vars[ $varName ]->value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update variable in template local variable stack
|
|
||||||
*
|
|
||||||
* @param \Smarty_Internal_Template $tpl
|
|
||||||
* @param string|null $varName variable name or null for config variables
|
|
||||||
*/
|
|
||||||
private function _updateVarStack(Smarty_Internal_Template $tpl, $varName)
|
|
||||||
{
|
|
||||||
$i = 0;
|
|
||||||
while (isset($tpl->_var_stack[ $i ])) {
|
|
||||||
$this->_updateVariableInOtherScope($tpl->_var_stack[ $i ][ 'tpl' ], $varName);
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,927 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Smarty Internal Plugin Smarty Template Base
|
|
||||||
* This file contains the basic shared methods for template handling
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage Template
|
|
||||||
* @author Uwe Tews
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Smarty\Cacheresource\Base;
|
|
||||||
use Smarty\Data;
|
|
||||||
use Smarty\Smarty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class with shared smarty/template methods
|
|
||||||
*
|
|
||||||
* @property int $_objType
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
abstract class Smarty_Internal_TemplateBase extends Data
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Set this if you want different sets of cache files for the same
|
|
||||||
* templates.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $cache_id = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set this if you want different sets of compiled files for the same
|
|
||||||
* templates.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $compile_id = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* caching enabled
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $caching = \Smarty\Smarty::CACHING_OFF;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* check template for modifications?
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $compile_check = \Smarty\Smarty::COMPILECHECK_ON;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cache lifetime in seconds
|
|
||||||
*
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
public $cache_lifetime = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Array of source information for known template functions
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public $tplFunctions = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When initialized to an (empty) array, this variable will hold a stack of template variables.
|
|
||||||
*
|
|
||||||
* @var null|array
|
|
||||||
*/
|
|
||||||
public $_var_stack = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Valid filter types
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fetches a rendered Smarty template
|
|
||||||
*
|
|
||||||
* @param string $template the resource handle of the template file or template object
|
|
||||||
* @param mixed $cache_id cache id to be used with this template
|
|
||||||
* @param mixed $compile_id compile id to be used with this template
|
|
||||||
* @param object $parent next higher level of Smarty variables
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* @throws SmartyException
|
|
||||||
* @return string rendered template output
|
|
||||||
*/
|
|
||||||
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
|
||||||
{
|
|
||||||
$result = $this->_execute($template, $cache_id, $compile_id, $parent, 0);
|
|
||||||
return $result === null ? ob_get_clean() : $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* displays a Smarty template
|
|
||||||
*
|
|
||||||
* @param string $template the resource handle of the template file or template object
|
|
||||||
* @param mixed $cache_id cache id to be used with this template
|
|
||||||
* @param mixed $compile_id compile id to be used with this template
|
|
||||||
* @param object $parent next higher level of Smarty variables
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
|
||||||
{
|
|
||||||
// display template
|
|
||||||
$this->_execute($template, $cache_id, $compile_id, $parent, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test if cache is valid
|
|
||||||
*
|
|
||||||
* @api Smarty::isCached()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.is.cached.tpl
|
|
||||||
*
|
|
||||||
* @param null|string|\Smarty_Internal_Template $template the resource handle of the template file or template
|
|
||||||
* object
|
|
||||||
* @param mixed $cache_id cache id to be used with this template
|
|
||||||
* @param mixed $compile_id compile id to be used with this template
|
|
||||||
* @param object $parent next higher level of Smarty variables
|
|
||||||
*
|
|
||||||
* @return bool cache status
|
|
||||||
* @throws \Exception
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
|
||||||
{
|
|
||||||
return $this->_execute($template, $cache_id, $compile_id, $parent, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fetches a rendered Smarty template
|
|
||||||
*
|
|
||||||
* @param string $template the resource handle of the template file or template object
|
|
||||||
* @param mixed $cache_id cache id to be used with this template
|
|
||||||
* @param mixed $compile_id compile id to be used with this template
|
|
||||||
* @param object $parent next higher level of Smarty variables
|
|
||||||
* @param string $function function type 0 = fetch, 1 = display, 2 = isCache
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
* @throws \Exception
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
private function _execute($template, $cache_id, $compile_id, $parent, $function)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
$saveVars = true;
|
|
||||||
if ($template === null) {
|
|
||||||
if (!$this->_isTplObj()) {
|
|
||||||
throw new SmartyException($function . '():Missing \'$template\' parameter');
|
|
||||||
} else {
|
|
||||||
$template = $this;
|
|
||||||
}
|
|
||||||
} elseif (is_object($template)) {
|
|
||||||
/* @var Smarty_Internal_Template $template */
|
|
||||||
if (!isset($template->_objType) || !$template->_isTplObj()) {
|
|
||||||
throw new SmartyException($function . '():Template object expected');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// get template object
|
|
||||||
$saveVars = false;
|
|
||||||
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false);
|
|
||||||
if ($this->_objType === 1) {
|
|
||||||
// set caching in template object
|
|
||||||
$template->caching = $this->caching;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// make sure we have integer values
|
|
||||||
$template->caching = (int)$template->caching;
|
|
||||||
// fetch template content
|
|
||||||
$level = ob_get_level();
|
|
||||||
try {
|
|
||||||
$_smarty_old_error_level =
|
|
||||||
isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null;
|
|
||||||
|
|
||||||
if ($smarty->isMutingUndefinedOrNullWarnings()) {
|
|
||||||
$errorHandler = new \Smarty\ErrorHandler();
|
|
||||||
$errorHandler->activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->_objType === 2) {
|
|
||||||
/* @var Smarty_Internal_Template $this */
|
|
||||||
$template->tplFunctions = $this->tplFunctions;
|
|
||||||
$template->inheritance = $this->inheritance;
|
|
||||||
}
|
|
||||||
/* @var Smarty_Internal_Template $parent */
|
|
||||||
if (isset($parent->_objType) && ($parent->_objType === 2) && !empty($parent->tplFunctions)) {
|
|
||||||
$template->tplFunctions = array_merge($parent->tplFunctions, $template->tplFunctions);
|
|
||||||
}
|
|
||||||
if ($function === 2) {
|
|
||||||
if ($template->caching) {
|
|
||||||
// return cache status of template
|
|
||||||
if (!isset($template->cached)) {
|
|
||||||
$template->loadCached();
|
|
||||||
}
|
|
||||||
$result = $template->cached->isCached($template);
|
|
||||||
Smarty_Internal_Template::$isCacheTplObj[ $template->_getTemplateId() ] = $template;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($saveVars) {
|
|
||||||
$savedTplVars = $template->tpl_vars;
|
|
||||||
$savedConfigVars = $template->config_vars;
|
|
||||||
}
|
|
||||||
ob_start();
|
|
||||||
$template->_mergeVars();
|
|
||||||
if (!empty(\Smarty\Smarty::$global_tpl_vars)) {
|
|
||||||
$template->tpl_vars = array_merge(\Smarty\Smarty::$global_tpl_vars, $template->tpl_vars);
|
|
||||||
}
|
|
||||||
$result = $template->render(false, $function);
|
|
||||||
$template->_cleanUp();
|
|
||||||
if ($saveVars) {
|
|
||||||
$template->tpl_vars = $savedTplVars;
|
|
||||||
$template->config_vars = $savedConfigVars;
|
|
||||||
} else {
|
|
||||||
if (!$function && !isset(Smarty_Internal_Template::$tplObjCache[ $template->templateId ])) {
|
|
||||||
$template->parent = null;
|
|
||||||
$template->tpl_vars = $template->config_vars = array();
|
|
||||||
Smarty_Internal_Template::$tplObjCache[ $template->templateId ] = $template;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($errorHandler)) {
|
|
||||||
$errorHandler->deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_smarty_old_error_level)) {
|
|
||||||
error_reporting($_smarty_old_error_level);
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
} catch (Throwable $e) {
|
|
||||||
while (ob_get_level() > $level) {
|
|
||||||
ob_end_clean();
|
|
||||||
}
|
|
||||||
if (isset($errorHandler)) {
|
|
||||||
$errorHandler->deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_smarty_old_error_level)) {
|
|
||||||
error_reporting($_smarty_old_error_level);
|
|
||||||
}
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers plugin to be used in templates
|
|
||||||
*
|
|
||||||
* @api Smarty::registerPlugin()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.register.plugin.tpl
|
|
||||||
*
|
|
||||||
* @param string $type plugin type
|
|
||||||
* @param string $name name of template tag
|
|
||||||
* @param callable $callback PHP callback to register
|
|
||||||
* @param bool $cacheable if true (default) this function is cache able
|
|
||||||
* @param mixed $cache_attr caching attributes if any
|
|
||||||
*
|
|
||||||
* @return \Smarty|\Smarty_Internal_Template
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
if (isset($smarty->registered_plugins[ $type ][ $name ])) {
|
|
||||||
throw new SmartyException("Plugin tag '{$name}' already registered");
|
|
||||||
} elseif (!is_callable($callback)) {
|
|
||||||
throw new SmartyException("Plugin '{$name}' not callable");
|
|
||||||
} elseif ($cacheable && $cache_attr) {
|
|
||||||
throw new SmartyException("Cannot set caching attributes for plugin '{$name}' when it is cacheable.");
|
|
||||||
} else {
|
|
||||||
$smarty->registered_plugins[ $type ][ $name ] = array($callback, (bool)$cacheable, (array)$cache_attr);
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers plugin to be used in templates
|
|
||||||
*
|
|
||||||
* @api Smarty::unregisterPlugin()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.unregister.plugin.tpl
|
|
||||||
*
|
|
||||||
* @param string $type plugin type
|
|
||||||
* @param string $name name of template tag
|
|
||||||
*
|
|
||||||
* @return \Smarty|\Smarty_Internal_Template
|
|
||||||
*/
|
|
||||||
public function unregisterPlugin($type, $name)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
if (isset($smarty->registered_plugins[ $type ][ $name ])) {
|
|
||||||
unset($smarty->registered_plugins[ $type ][ $name ]);
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* load a filter of specified type and name
|
|
||||||
*
|
|
||||||
* @api Smarty::loadFilter()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.load.filter.tpl
|
|
||||||
*
|
|
||||||
* @param string $type filter type
|
|
||||||
* @param string $name filter name
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function loadFilter($type, $name)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
$this->_checkFilterType($type);
|
|
||||||
$_plugin = "smarty_{$type}filter_{$name}";
|
|
||||||
$_filter_name = $_plugin;
|
|
||||||
if (is_callable($_plugin)) {
|
|
||||||
$smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (class_exists($_plugin, false)) {
|
|
||||||
$_plugin = array($_plugin, 'execute');
|
|
||||||
}
|
|
||||||
if (is_callable($_plugin)) {
|
|
||||||
$smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
throw new SmartyException("{$type}filter '{$name}' not found or callable");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* load a filter of specified type and name
|
|
||||||
*
|
|
||||||
* @api Smarty::unloadFilter()
|
|
||||||
*
|
|
||||||
* @link https://www.smarty.net/docs/en/api.unload.filter.tpl
|
|
||||||
*
|
|
||||||
* @param string $type filter type
|
|
||||||
* @param string $name filter name
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function unloadFilter($type, $name)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
$this->_checkFilterType($type);
|
|
||||||
if (isset($smarty->registered_filters[ $type ])) {
|
|
||||||
$_filter_name = "smarty_{$type}filter_{$name}";
|
|
||||||
if (isset($smarty->registered_filters[ $type ][ $_filter_name ])) {
|
|
||||||
unset($smarty->registered_filters[ $type ][ $_filter_name ]);
|
|
||||||
if (empty($smarty->registered_filters[ $type ])) {
|
|
||||||
unset($smarty->registered_filters[ $type ]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a filter function
|
|
||||||
*
|
|
||||||
* @param string $type filter type
|
|
||||||
* @param callable $callback
|
|
||||||
* @param string|null $name optional filter name
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @throws \SmartyException
|
|
||||||
*@link https://www.smarty.net/docs/en/api.register.filter.tpl
|
|
||||||
*
|
|
||||||
* @api Smarty::registerFilter()
|
|
||||||
*/
|
|
||||||
public function registerFilter($type, $callback, $name = null)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
$this->_checkFilterType($type);
|
|
||||||
$name = isset($name) ? $name : $this->_getFilterName($callback);
|
|
||||||
if (!is_callable($callback)) {
|
|
||||||
throw new SmartyException("{$type}filter '{$name}' not callable");
|
|
||||||
}
|
|
||||||
$smarty->registered_filters[ $type ][ $name ] = $callback;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregisters a filter function
|
|
||||||
*
|
|
||||||
* @param string $type filter type
|
|
||||||
* @param callback|string $callback
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @throws \SmartyException
|
|
||||||
*@api Smarty::unregisterFilter()
|
|
||||||
*
|
|
||||||
* @link https://www.smarty.net/docs/en/api.unregister.filter.tpl
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function unregisterFilter($type, $callback)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
$this->_checkFilterType($type);
|
|
||||||
if (isset($smarty->registered_filters[ $type ])) {
|
|
||||||
$name = is_string($callback) ? $callback : $this->_getFilterName($callback);
|
|
||||||
if (isset($smarty->registered_filters[ $type ][ $name ])) {
|
|
||||||
unset($smarty->registered_filters[ $type ][ $name ]);
|
|
||||||
if (empty($smarty->registered_filters[ $type ])) {
|
|
||||||
unset($smarty->registered_filters[ $type ]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers object to be used in templates
|
|
||||||
*
|
|
||||||
* @api Smarty::registerObject()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.register.object.tpl
|
|
||||||
*
|
|
||||||
* @param string $object_name
|
|
||||||
* @param object $object the referenced PHP object to register
|
|
||||||
* @param array $allowed_methods_properties list of allowed methods (empty = all)
|
|
||||||
* @param bool $format smarty argument format, else traditional
|
|
||||||
* @param array $block_methods list of block-methods
|
|
||||||
*
|
|
||||||
* @return \Smarty|\Smarty_Internal_Template
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
public function registerObject(
|
|
||||||
$object_name,
|
|
||||||
$object,
|
|
||||||
$allowed_methods_properties = array(),
|
|
||||||
$format = true,
|
|
||||||
$block_methods = array()
|
|
||||||
) {
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
// test if allowed methods callable
|
|
||||||
if (!empty($allowed_methods_properties)) {
|
|
||||||
foreach ((array)$allowed_methods_properties as $method) {
|
|
||||||
if (!is_callable(array($object, $method)) && !property_exists($object, $method)) {
|
|
||||||
throw new SmartyException("Undefined method or property '$method' in registered object");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// test if block methods callable
|
|
||||||
if (!empty($block_methods)) {
|
|
||||||
foreach ((array)$block_methods as $method) {
|
|
||||||
if (!is_callable(array($object, $method))) {
|
|
||||||
throw new SmartyException("Undefined method '$method' in registered object");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// register the object
|
|
||||||
$smarty->registered_objects[ $object_name ] =
|
|
||||||
array($object, (array)$allowed_methods_properties, (boolean)$format, (array)$block_methods);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers plugin to be used in templates
|
|
||||||
*
|
|
||||||
* @param string $object_name name of object
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @api Smarty::unregisterObject()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.unregister.object.tpl
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function unregisterObject($object_name)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
if (isset($smarty->registered_objects[ $object_name ])) {
|
|
||||||
unset($smarty->registered_objects[ $object_name ]);
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $compile_check
|
|
||||||
*/
|
|
||||||
public function setCompileCheck($compile_check)
|
|
||||||
{
|
|
||||||
$this->compile_check = (int)$compile_check;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $caching
|
|
||||||
*/
|
|
||||||
public function setCaching($caching)
|
|
||||||
{
|
|
||||||
$this->caching = (int)$caching;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $cache_lifetime
|
|
||||||
*/
|
|
||||||
public function setCacheLifetime($cache_lifetime)
|
|
||||||
{
|
|
||||||
$this->cache_lifetime = $cache_lifetime;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $compile_id
|
|
||||||
*/
|
|
||||||
public function setCompileId($compile_id)
|
|
||||||
{
|
|
||||||
$this->compile_id = $compile_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $cache_id
|
|
||||||
*/
|
|
||||||
public function setCacheId($cache_id)
|
|
||||||
{
|
|
||||||
$this->cache_id = $cache_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add default modifiers
|
|
||||||
*
|
|
||||||
* @api Smarty::addDefaultModifiers()
|
|
||||||
*
|
|
||||||
* @param array|string $modifiers modifier or list of modifiers
|
|
||||||
* to add
|
|
||||||
*
|
|
||||||
* @return \Smarty|\Smarty_Internal_Template
|
|
||||||
*/
|
|
||||||
public function addDefaultModifiers($modifiers)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
if (is_array($modifiers)) {
|
|
||||||
$smarty->default_modifiers = array_merge($smarty->default_modifiers, $modifiers);
|
|
||||||
} else {
|
|
||||||
$smarty->default_modifiers[] = $modifiers;
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* creates a data object
|
|
||||||
*
|
|
||||||
* @param Data|null $parent next higher level of Smarty
|
|
||||||
* variables
|
|
||||||
* @param null $name optional data block name
|
|
||||||
*
|
|
||||||
* @return Smarty_Data data object
|
|
||||||
* @throws SmartyException
|
|
||||||
* @api Smarty::createData()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.create.data.tpl
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function createData(Data $parent = null, $name = null)
|
|
||||||
{
|
|
||||||
/* @var Smarty $smarty */
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
$dataObj = new Smarty_Data($parent, $smarty, $name);
|
|
||||||
if ($smarty->debugging) {
|
|
||||||
\Smarty\Debug::register_data($dataObj);
|
|
||||||
}
|
|
||||||
return $dataObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return name of debugging template
|
|
||||||
*
|
|
||||||
* @api Smarty::getDebugTemplate()
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getDebugTemplate()
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
return $smarty->debug_tpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get default modifiers
|
|
||||||
*
|
|
||||||
* @api Smarty::getDefaultModifiers()
|
|
||||||
*
|
|
||||||
* @return array list of default modifiers
|
|
||||||
*/
|
|
||||||
public function getDefaultModifiers()
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
return $smarty->default_modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return a reference to a registered object
|
|
||||||
*
|
|
||||||
* @api Smarty::getRegisteredObject()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.get.registered.object.tpl
|
|
||||||
*
|
|
||||||
* @param string $object_name object name
|
|
||||||
*
|
|
||||||
* @return object
|
|
||||||
* @throws \SmartyException if no such object is found
|
|
||||||
*/
|
|
||||||
public function getRegisteredObject($object_name)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
if (!isset($smarty->registered_objects[ $object_name ])) {
|
|
||||||
throw new SmartyException("'$object_name' is not a registered object");
|
|
||||||
}
|
|
||||||
if (!is_object($smarty->registered_objects[ $object_name ][ 0 ])) {
|
|
||||||
throw new SmartyException("registered '$object_name' is not an object");
|
|
||||||
}
|
|
||||||
return $smarty->registered_objects[ $object_name ][ 0 ];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get literals
|
|
||||||
*
|
|
||||||
* @api Smarty::getLiterals()
|
|
||||||
*
|
|
||||||
* @return array list of literals
|
|
||||||
*/
|
|
||||||
public function getLiterals()
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
return (array)$smarty->literals;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add literals
|
|
||||||
*
|
|
||||||
* @param array|string $literals literal or list of literals
|
|
||||||
* to addto add
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @throws \SmartyException
|
|
||||||
* @api Smarty::addLiterals()
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function addLiterals($literals = null)
|
|
||||||
{
|
|
||||||
if (isset($literals)) {
|
|
||||||
$this->_setLiterals($this->_getSmartyObj(), (array)$literals);
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set literals
|
|
||||||
*
|
|
||||||
* @param array|string $literals literal or list of literals
|
|
||||||
* to setto set
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @throws \SmartyException
|
|
||||||
* @api Smarty::setLiterals()
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function setLiterals($literals = null)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
$smarty->literals = array();
|
|
||||||
if (!empty($literals)) {
|
|
||||||
$this->_setLiterals($smarty, (array)$literals);
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* common setter for literals for easier handling of duplicates the
|
|
||||||
* Smarty::$literals array gets filled with identical key values
|
|
||||||
*
|
|
||||||
* @param Smarty $smarty
|
|
||||||
* @param array $literals
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
private function _setLiterals(Smarty $smarty, $literals)
|
|
||||||
{
|
|
||||||
$literals = array_combine($literals, $literals);
|
|
||||||
$error = isset($literals[ $smarty->left_delimiter ]) ? array($smarty->left_delimiter) : array();
|
|
||||||
$error = isset($literals[ $smarty->right_delimiter ]) ? $error[] = $smarty->right_delimiter : $error;
|
|
||||||
if (!empty($error)) {
|
|
||||||
throw new SmartyException(
|
|
||||||
'User defined literal(s) "' . $error .
|
|
||||||
'" may not be identical with left or right delimiter'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$smarty->literals = array_merge((array)$smarty->literals, (array)$literals);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if filter type is valid
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
*
|
|
||||||
* @throws \SmartyException
|
|
||||||
*/
|
|
||||||
private function _checkFilterType($type)
|
|
||||||
{
|
|
||||||
if (!isset($this->filterTypes[ $type ])) {
|
|
||||||
throw new SmartyException("Illegal filter type '{$type}'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return internal filter name
|
|
||||||
*
|
|
||||||
* @param callback $function_name
|
|
||||||
*
|
|
||||||
* @return string internal filter name
|
|
||||||
*/
|
|
||||||
private function _getFilterName($function_name)
|
|
||||||
{
|
|
||||||
if (is_array($function_name)) {
|
|
||||||
$_class_name = (is_object($function_name[ 0 ]) ? get_class($function_name[ 0 ]) : $function_name[ 0 ]);
|
|
||||||
return $_class_name . '_' . $function_name[ 1 ];
|
|
||||||
} elseif (is_string($function_name)) {
|
|
||||||
return $function_name;
|
|
||||||
} else {
|
|
||||||
return 'closure';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers static classes to be used in templates
|
|
||||||
*
|
|
||||||
* @param string $class_name
|
|
||||||
* @param string $class_impl the referenced PHP class to
|
|
||||||
* register
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @throws \SmartyException
|
|
||||||
*@api Smarty::registerClass()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.register.class.tpl
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function registerClass($class_name, $class_impl)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
// test if exists
|
|
||||||
if (!class_exists($class_impl)) {
|
|
||||||
throw new SmartyException("Undefined class '$class_impl' in register template class");
|
|
||||||
}
|
|
||||||
// register the class
|
|
||||||
$smarty->registered_classes[ $class_name ] = $class_impl;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a resource to fetch a template
|
|
||||||
*
|
|
||||||
* @param string $name name of resource type
|
|
||||||
* @param Base $resource_handler
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @link https://www.smarty.net/docs/en/api.register.cacheresource.tpl
|
|
||||||
*
|
|
||||||
* @api Smarty::registerCacheResource()
|
|
||||||
*/
|
|
||||||
public function registerCacheResource($name, Base $resource_handler) {
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
$smarty->registered_cache_resources[ $name ] = $resource_handler;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregisters a resource to fetch a template
|
|
||||||
*
|
|
||||||
* @api Smarty::unregisterCacheResource()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.unregister.cacheresource.tpl
|
|
||||||
*
|
|
||||||
* @param $name
|
|
||||||
*
|
|
||||||
* @return \Smarty|\Smarty_Internal_Template
|
|
||||||
*/
|
|
||||||
public function unregisterCacheResource($name)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
if (isset($smarty->registered_cache_resources[ $name ])) {
|
|
||||||
unset($smarty->registered_cache_resources[ $name ]);
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register config default handler
|
|
||||||
*
|
|
||||||
* @param callable $callback class/method name
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @throws SmartyException if $callback is not callable
|
|
||||||
*@api Smarty::registerDefaultConfigHandler()
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function registerDefaultConfigHandler($callback)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
if (is_callable($callback)) {
|
|
||||||
$smarty->default_config_handler_func = $callback;
|
|
||||||
} else {
|
|
||||||
throw new SmartyException('Default config handler not callable');
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a default plugin handler
|
|
||||||
*
|
|
||||||
* @param callable $callback class/method name
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @throws SmartyException if $callback is not callable
|
|
||||||
* @link https://www.smarty.net/docs/en/api.register.default.plugin.handler.tpl
|
|
||||||
*
|
|
||||||
* @api Smarty::registerDefaultPluginHandler()
|
|
||||||
*/
|
|
||||||
public function registerDefaultPluginHandler($callback)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
if (is_callable($callback)) {
|
|
||||||
$smarty->default_plugin_handler_func = $callback;
|
|
||||||
} else {
|
|
||||||
throw new SmartyException("Default plugin handler '$callback' not callable");
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register template default handler
|
|
||||||
*
|
|
||||||
* @param callable $callback class/method name
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @throws SmartyException if $callback is not callable
|
|
||||||
* @api Smarty::registerDefaultTemplateHandler()
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function registerDefaultTemplateHandler($callback)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
if (is_callable($callback)) {
|
|
||||||
$smarty->default_template_handler_func = $callback;
|
|
||||||
} else {
|
|
||||||
throw new SmartyException('Default template handler not callable');
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a resource to fetch a template
|
|
||||||
*
|
|
||||||
* @api Smarty::registerResource()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.register.resource.tpl
|
|
||||||
*
|
|
||||||
* @param string $name name of resource type
|
|
||||||
* @param Smarty\Resource\Base $resource_handler instance of Smarty\Resource\Base
|
|
||||||
*
|
|
||||||
* @return \Smarty|\Smarty_Internal_Template
|
|
||||||
*/
|
|
||||||
public function registerResource($name, Smarty\Resource\Base $resource_handler)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
$smarty->registered_resources[ $name ] = $resource_handler;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregisters a resource to fetch a template
|
|
||||||
*
|
|
||||||
* @param string $type name of resource type
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @api Smarty::unregisterResource()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.unregister.resource.tpl
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function unregisterResource($type)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
if (isset($smarty->registered_resources[ $type ])) {
|
|
||||||
unset($smarty->registered_resources[ $type ]);
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the debug template
|
|
||||||
*
|
|
||||||
* @param string $tpl_name
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @throws SmartyException if file is not readable
|
|
||||||
*@api Smarty::setDebugTemplate()
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function setDebugTemplate($tpl_name)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
if (!is_readable($tpl_name)) {
|
|
||||||
throw new SmartyException("Unknown file '{$tpl_name}'");
|
|
||||||
}
|
|
||||||
$smarty->debug_tpl = $tpl_name;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set default modifiers
|
|
||||||
*
|
|
||||||
* @param array|string $modifiers modifier or list of modifiers
|
|
||||||
* to set
|
|
||||||
*
|
|
||||||
* @return Smarty_Internal_TemplateBase
|
|
||||||
* @api Smarty::setDefaultModifiers()
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function setDefaultModifiers($modifiers)
|
|
||||||
{
|
|
||||||
$smarty = $this->_getSmartyObj();
|
|
||||||
$smarty->default_modifiers = (array)$modifiers;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -8,6 +8,8 @@
|
|||||||
* @author Uwe Tews
|
* @author Uwe Tews
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class for the Smarty data object
|
* class for the Smarty data object
|
||||||
* The Smarty data object will hold Smarty variables in the current scope
|
* The Smarty data object will hold Smarty variables in the current scope
|
||||||
@@ -42,7 +44,7 @@ class Smarty_Data extends \Smarty\Data
|
|||||||
* create Smarty data object
|
* create Smarty data object
|
||||||
*
|
*
|
||||||
* @param Smarty|array $_parent parent template
|
* @param Smarty|array $_parent parent template
|
||||||
* @param Smarty|Smarty_Internal_Template $smarty global smarty instance
|
* @param Smarty|Template $smarty global smarty instance
|
||||||
* @param string $name optional data block name
|
* @param string $name optional data block name
|
||||||
*
|
*
|
||||||
* @throws SmartyException
|
* @throws SmartyException
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
* as this would lead to (severe) performance penalty! how should this be handled?
|
* as this would lead to (severe) performance penalty! how should this be handled?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class does contain the security settings
|
* This class does contain the security settings
|
||||||
*/
|
*/
|
||||||
@@ -670,9 +672,9 @@ class Smarty_Security
|
|||||||
/**
|
/**
|
||||||
* Register callback functions call at start/end of template rendering
|
* Register callback functions call at start/end of template rendering
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template $template
|
* @param \Smarty\Template $template
|
||||||
*/
|
*/
|
||||||
public function registerCallBacks(Smarty_Internal_Template $template)
|
public function registerCallBacks(Template $template)
|
||||||
{
|
{
|
||||||
$template->startRenderCallbacks[] = array($this, 'startTemplate');
|
$template->startRenderCallbacks[] = array($this, 'startTemplate');
|
||||||
$template->endRenderCallbacks[] = array($this, 'endTemplate');
|
$template->endRenderCallbacks[] = array($this, 'endTemplate');
|
||||||
|
@@ -4,6 +4,9 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\TemplateBase;
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Test Case Fixture
|
* Smarty Test Case Fixture
|
||||||
*/
|
*/
|
||||||
@@ -352,7 +355,7 @@ KEY `name` (`name`)
|
|||||||
/**
|
/**
|
||||||
* Return source path
|
* Return source path
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_TemplateBase $tpl template object
|
* @param TemplateBase $tpl template object
|
||||||
* @param null|string $name optional template name
|
* @param null|string $name optional template name
|
||||||
* @param null|string $type optional template type
|
* @param null|string $type optional template type
|
||||||
* @param null|string $dir optional template folder
|
* @param null|string $dir optional template folder
|
||||||
@@ -384,7 +387,7 @@ KEY `name` (`name`)
|
|||||||
/**
|
/**
|
||||||
* Build template uid
|
* Build template uid
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_TemplateBase $tpl template object
|
* @param TemplateBase $tpl template object
|
||||||
* @param null|string $value
|
* @param null|string $value
|
||||||
* @param null|string $name optional template name
|
* @param null|string $name optional template name
|
||||||
* @param null|string $type optional template type
|
* @param null|string $type optional template type
|
||||||
@@ -457,13 +460,13 @@ KEY `name` (`name`)
|
|||||||
/**
|
/**
|
||||||
* Return base name
|
* Return base name
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template|\Smarty_Internal_TemplateBase $tpl template object
|
* @param \Smarty\Template|\Smarty\TemplateBase $tpl template object
|
||||||
* @param null|string $name optional template name
|
* @param null|string $name optional template name
|
||||||
* @param null|string $type optional template type
|
* @param null|string $type optional template type
|
||||||
*
|
*
|
||||||
* @return null|string
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
public function getBasename(Smarty_Internal_Template $tpl, $name = null, $type = null)
|
public function getBasename(Template $tpl, $name = null, $type = null)
|
||||||
{
|
{
|
||||||
$name = isset($name) ? $name : $tpl->source->name;
|
$name = isset($name) ? $name : $tpl->source->name;
|
||||||
$type = isset($type) ? $type : $tpl->source->type;
|
$type = isset($type) ? $type : $tpl->source->type;
|
||||||
@@ -487,7 +490,7 @@ KEY `name` (`name`)
|
|||||||
/**
|
/**
|
||||||
* Return compiled file path
|
* Return compiled file path
|
||||||
*
|
*
|
||||||
* @param \Smarty_Internal_Template|\Smarty_Internal_TemplateBase $tpl template object
|
* @param \Smarty\Template|\Smarty\TemplateBase $tpl template object
|
||||||
* @param bool $sub use sub directory flag
|
* @param bool $sub use sub directory flag
|
||||||
* @param bool $caching caching flag
|
* @param bool $caching caching flag
|
||||||
* @param null|string $compile_id optional compile id
|
* @param null|string $compile_id optional compile id
|
||||||
@@ -498,8 +501,8 @@ KEY `name` (`name`)
|
|||||||
* @return string
|
* @return string
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function buildCompiledPath(Smarty_Internal_Template $tpl, $sub = true, $caching = false, $compile_id = null,
|
public function buildCompiledPath(Template $tpl, $sub = true, $caching = false, $compile_id = null,
|
||||||
$name = null, $type = null, $dir = null)
|
$name = null, $type = null, $dir = null)
|
||||||
{
|
{
|
||||||
$sep = DIRECTORY_SEPARATOR;
|
$sep = DIRECTORY_SEPARATOR;
|
||||||
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
|
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
|
||||||
@@ -546,7 +549,7 @@ KEY `name` (`name`)
|
|||||||
/**
|
/**
|
||||||
* Return cache file path
|
* Return cache file path
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_TemplateBase $tpl template object
|
* @param TemplateBase $tpl template object
|
||||||
* @param bool $sub use sub directory flag
|
* @param bool $sub use sub directory flag
|
||||||
* @param null|string $cache_id optional cache id
|
* @param null|string $cache_id optional cache id
|
||||||
* @param null|string $compile_id optional compile id
|
* @param null|string $compile_id optional compile id
|
||||||
@@ -618,11 +621,11 @@ KEY `name` (`name`)
|
|||||||
* prefilter to insert test number
|
* prefilter to insert test number
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
* @param \Smarty_Internal_Template $tpl
|
* @param \Smarty\Template $tpl
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function prefilterTest($source, Smarty_Internal_Template $tpl)
|
public function prefilterTest($source, Template $tpl)
|
||||||
{
|
{
|
||||||
return str_replace('#test#', "test:{\$test nocache} compiled:{$tpl->getTemplateVars('test')} rendered:{\$test}",
|
return str_replace('#test#', "test:{\$test nocache} compiled:{$tpl->getTemplateVars('test')} rendered:{\$test}",
|
||||||
$source);
|
$source);
|
||||||
|
@@ -6,6 +6,8 @@
|
|||||||
* @author Uwe Tews
|
* @author Uwe Tews
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class for cache resource file tests
|
* class for cache resource file tests
|
||||||
*
|
*
|
||||||
@@ -28,7 +30,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty
|
|||||||
$this->assertEquals($a, $b);
|
$this->assertEquals($a, $b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
|
public function compiledPrefilter($text, Template $tpl)
|
||||||
{
|
{
|
||||||
$replace = $tpl->getTemplateVars('test');
|
$replace = $tpl->getTemplateVars('test');
|
||||||
return str_replace('#', $replace ?? '', $text);
|
return str_replace('#', $replace ?? '', $text);
|
||||||
|
@@ -1,12 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
use Smarty\Template\Cached;
|
||||||
|
|
||||||
require_once SMARTY_DIR . '../demo/plugins/cacheresource.apc.php';
|
require_once SMARTY_DIR . '../demo/plugins/cacheresource.apc.php';
|
||||||
|
|
||||||
class Smarty_CacheResource_Apctest extends Smarty_CacheResource_Apc
|
class Smarty_CacheResource_Apctest extends Smarty_CacheResource_Apc
|
||||||
{
|
{
|
||||||
public $lockTime = 0;
|
public $lockTime = 0;
|
||||||
|
|
||||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function hasLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
if ($this->lockTime) {
|
if ($this->lockTime) {
|
||||||
$this->lockTime--;
|
$this->lockTime--;
|
||||||
@@ -17,7 +20,7 @@ class Smarty_CacheResource_Apctest extends Smarty_CacheResource_Apc
|
|||||||
return parent::hasLock($smarty, $cached);
|
return parent::hasLock($smarty, $cached);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(Smarty_Internal_Template $_template)
|
public function get(Template $_template)
|
||||||
{
|
{
|
||||||
$this->contents = array();
|
$this->contents = array();
|
||||||
$this->timestamps = array();
|
$this->timestamps = array();
|
||||||
|
@@ -5,7 +5,7 @@ class Smarty_CacheResource_Filetest extends \Smarty\Cacheresource\File
|
|||||||
{
|
{
|
||||||
public $lockTime = 0;
|
public $lockTime = 0;
|
||||||
|
|
||||||
public function hasLock(\Smarty\Smarty $smarty, \Smarty_Template_Cached $cached)
|
public function hasLock(\Smarty\Smarty $smarty, \Smarty\Template\Cached $cached)
|
||||||
{
|
{
|
||||||
if ($this->lockTime) {
|
if ($this->lockTime) {
|
||||||
$this->lockTime--;
|
$this->lockTime--;
|
||||||
|
@@ -1,12 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
use Smarty\Template\Cached;
|
||||||
|
|
||||||
require_once SMARTY_DIR . '../demo/plugins/cacheresource.memcache.php';
|
require_once SMARTY_DIR . '../demo/plugins/cacheresource.memcache.php';
|
||||||
|
|
||||||
class Smarty_CacheResource_Memcachetest extends Smarty_CacheResource_Memcache
|
class Smarty_CacheResource_Memcachetest extends Smarty_CacheResource_Memcache
|
||||||
{
|
{
|
||||||
public $lockTime = 0;
|
public $lockTime = 0;
|
||||||
|
|
||||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function hasLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
if ($this->lockTime) {
|
if ($this->lockTime) {
|
||||||
$this->lockTime--;
|
$this->lockTime--;
|
||||||
@@ -17,7 +20,7 @@ class Smarty_CacheResource_Memcachetest extends Smarty_CacheResource_Memcache
|
|||||||
return parent::hasLock($smarty, $cached);
|
return parent::hasLock($smarty, $cached);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(Smarty_Internal_Template $_template)
|
public function get(Template $_template)
|
||||||
{
|
{
|
||||||
$this->contents = array();
|
$this->contents = array();
|
||||||
$this->timestamps = array();
|
$this->timestamps = array();
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Smarty\Template\Cached;
|
||||||
|
|
||||||
require_once SMARTY_DIR . '../demo/plugins/cacheresource.mysql.php';
|
require_once SMARTY_DIR . '../demo/plugins/cacheresource.mysql.php';
|
||||||
|
|
||||||
class Smarty_CacheResource_Mysqltest extends Smarty_CacheResource_Mysql
|
class Smarty_CacheResource_Mysqltest extends Smarty_CacheResource_Mysql
|
||||||
@@ -18,7 +20,7 @@ class Smarty_CacheResource_Mysqltest extends Smarty_CacheResource_Mysql
|
|||||||
VALUES (:id, :name, :cache_id, :compile_id, :content)');
|
VALUES (:id, :name, :cache_id, :compile_id, :content)');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function hasLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
if ($this->lockTime) {
|
if ($this->lockTime) {
|
||||||
$this->lockTime--;
|
$this->lockTime--;
|
||||||
|
@@ -1,12 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Smarty\Template\Cached;
|
||||||
|
|
||||||
require_once SMARTY_DIR . '../demo/plugins/cacheresource.pdo_gzip.php';
|
require_once SMARTY_DIR . '../demo/plugins/cacheresource.pdo_gzip.php';
|
||||||
|
|
||||||
class Smarty_CacheResource_Pdo_Gziptest extends Smarty_CacheResource_Pdo_Gzip
|
class Smarty_CacheResource_Pdo_Gziptest extends Smarty_CacheResource_Pdo_Gzip
|
||||||
{
|
{
|
||||||
public $lockTime = 0;
|
public $lockTime = 0;
|
||||||
|
|
||||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function hasLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
if ($this->lockTime) {
|
if ($this->lockTime) {
|
||||||
$this->lockTime--;
|
$this->lockTime--;
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Smarty\Template\Cached;
|
||||||
|
|
||||||
require_once SMARTY_DIR . '../demo/plugins/cacheresource.pdo.php';
|
require_once SMARTY_DIR . '../demo/plugins/cacheresource.pdo.php';
|
||||||
|
|
||||||
class Smarty_CacheResource_Pdotest extends Smarty_CacheResource_Pdo
|
class Smarty_CacheResource_Pdotest extends Smarty_CacheResource_Pdo
|
||||||
@@ -7,7 +9,7 @@ class Smarty_CacheResource_Pdotest extends Smarty_CacheResource_Pdo
|
|||||||
public $lockTime = 0;
|
public $lockTime = 0;
|
||||||
|
|
||||||
|
|
||||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function hasLock(Smarty $smarty, Cached $cached)
|
||||||
{
|
{
|
||||||
if ($this->lockTime) {
|
if ($this->lockTime) {
|
||||||
$this->lockTime--;
|
$this->lockTime--;
|
||||||
|
@@ -1,16 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Smarty\Resource\FilePlugin;
|
use Smarty\Resource\FilePlugin;
|
||||||
|
use Smarty\Template;
|
||||||
|
use Smarty\Template\Source;
|
||||||
|
|
||||||
class Smarty_Resource_FiletestPlugin extends FilePlugin
|
class Smarty_Resource_FiletestPlugin extends FilePlugin
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* populate Source Object with meta data from Resource
|
* populate Source Object with meta data from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
public function populate(Source $source, Template $_template = null)
|
||||||
{
|
{
|
||||||
parent::populate($source, $_template);
|
parent::populate($source, $_template);
|
||||||
if ($source->exists) {
|
if ($source->exists) {
|
||||||
|
@@ -10,9 +10,12 @@
|
|||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
use Smarty\Template\Source;
|
||||||
|
|
||||||
class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
|
class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
|
||||||
{
|
{
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
public function populate(Source $source, Template $_template = null)
|
||||||
{
|
{
|
||||||
$source->filepath = 'db4:';
|
$source->filepath = 'db4:';
|
||||||
$source->uid = sha1($source->resource);
|
$source->uid = sha1($source->resource);
|
||||||
@@ -20,7 +23,7 @@ class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
|
|||||||
$source->exists = true;
|
$source->exists = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContent(Smarty_Template_Source $source)
|
public function getContent(Source $source)
|
||||||
{
|
{
|
||||||
return "foo = 'bar'\n";
|
return "foo = 'bar'\n";
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Smarty\Resource\FilePlugin;
|
use Smarty\Resource\FilePlugin;
|
||||||
|
use Smarty\Template;
|
||||||
|
use Smarty\Template\Source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ambiguous Filename Custom Resource Example
|
* Ambiguous Filename Custom Resource Example
|
||||||
@@ -40,10 +42,10 @@ class Smarty_Resource_AmbiguousPlugin extends FilePlugin
|
|||||||
/**
|
/**
|
||||||
* populate Source Object with meta data from Resource
|
* populate Source Object with meta data from Resource
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Source $source source object
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Template $_template template object
|
||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
public function populate(Source $source, Template $_template = null)
|
||||||
{
|
{
|
||||||
$segment = '';
|
$segment = '';
|
||||||
if ($this->segment) {
|
if ($this->segment) {
|
||||||
|
@@ -6,6 +6,8 @@
|
|||||||
* @author Uwe Tews
|
* @author Uwe Tews
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class for extends resource tests
|
* class for extends resource tests
|
||||||
*
|
*
|
||||||
@@ -27,7 +29,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
|
|||||||
$this->cleanDirs();
|
$this->cleanDirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
|
public function compiledPrefilter($text, Template $tpl)
|
||||||
{
|
{
|
||||||
return str_replace('#', $tpl->getTemplateVars('test'), $text);
|
return str_replace('#', $tpl->getTemplateVars('test'), $text);
|
||||||
}
|
}
|
||||||
|
@@ -11,17 +11,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use Smarty\Resource\RecompiledPlugin;
|
use Smarty\Resource\RecompiledPlugin;
|
||||||
|
use Smarty\Template;
|
||||||
|
use Smarty\Template\Source;
|
||||||
|
|
||||||
class _DbPlugin extends RecompiledPlugin {
|
class _DbPlugin extends RecompiledPlugin {
|
||||||
|
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
public function populate(Source $source, Template $_template = null) {
|
||||||
$source->filepath = 'db:';
|
$source->filepath = 'db:';
|
||||||
$source->uid = sha1($source->resource);
|
$source->uid = sha1($source->resource);
|
||||||
$source->timestamp = 1000000000;
|
$source->timestamp = 1000000000;
|
||||||
$source->exists = true;
|
$source->exists = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContent(Smarty_Template_Source $source) {
|
public function getContent(Source $source) {
|
||||||
return '{$x="hello world"}{$x}';
|
return '{$x="hello world"}{$x}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,10 +11,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use Smarty\Resource\RecompiledPlugin;
|
use Smarty\Resource\RecompiledPlugin;
|
||||||
|
use Smarty\Template;
|
||||||
|
use Smarty\Template\Source;
|
||||||
|
|
||||||
class _Db2Plugin extends RecompiledPlugin
|
class _Db2Plugin extends RecompiledPlugin
|
||||||
{
|
{
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
public function populate(Source $source, Template $_template = null)
|
||||||
{
|
{
|
||||||
$source->filepath = 'db2:';
|
$source->filepath = 'db2:';
|
||||||
$source->uid = sha1($source->resource);
|
$source->uid = sha1($source->resource);
|
||||||
@@ -22,7 +24,7 @@ class _Db2Plugin extends RecompiledPlugin
|
|||||||
$source->exists = true;
|
$source->exists = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContent(Smarty_Template_Source $source)
|
public function getContent(Source $source)
|
||||||
{
|
{
|
||||||
return '{$x="hello world"}{$x}';
|
return '{$x="hello world"}{$x}';
|
||||||
}
|
}
|
||||||
|
@@ -10,9 +10,12 @@
|
|||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
use Smarty\Template\Source;
|
||||||
|
|
||||||
class Smarty_Resource_Db3 extends Smarty\Resource\BasePlugin
|
class Smarty_Resource_Db3 extends Smarty\Resource\BasePlugin
|
||||||
{
|
{
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
public function populate(Source $source, Template $_template = null)
|
||||||
{
|
{
|
||||||
$source->filepath = 'db3:';
|
$source->filepath = 'db3:';
|
||||||
$source->uid = sha1($source->resource);
|
$source->uid = sha1($source->resource);
|
||||||
@@ -20,12 +23,12 @@ class Smarty_Resource_Db3 extends Smarty\Resource\BasePlugin
|
|||||||
$source->exists = true;
|
$source->exists = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContent(Smarty_Template_Source $source)
|
public function getContent(Source $source)
|
||||||
{
|
{
|
||||||
return '{$x="hello world"}{$x}';
|
return '{$x="hello world"}{$x}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCompiledFilepath(Smarty_Internal_Template $_template)
|
public function getCompiledFilepath(Template $_template)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -10,9 +10,12 @@
|
|||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
use Smarty\Template\Source;
|
||||||
|
|
||||||
class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
|
class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
|
||||||
{
|
{
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
public function populate(Source $source, Template $_template = null)
|
||||||
{
|
{
|
||||||
$source->filepath = 'db4:';
|
$source->filepath = 'db4:';
|
||||||
$source->uid = sha1($source->resource);
|
$source->uid = sha1($source->resource);
|
||||||
@@ -20,7 +23,7 @@ class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
|
|||||||
$source->exists = true;
|
$source->exists = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContent(Smarty_Template_Source $source)
|
public function getContent(Source $source)
|
||||||
{
|
{
|
||||||
if ($source->is_config) {
|
if ($source->is_config) {
|
||||||
return "foo = 'bar'\n";
|
return "foo = 'bar'\n";
|
||||||
|
@@ -5,17 +5,20 @@
|
|||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage PHPunitPlugin
|
* @subpackage PHPunitPlugin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {testparameter}{/testparameter} block plugin
|
* Smarty {testparameter}{/testparameter} block plugin
|
||||||
*
|
*
|
||||||
* @param array $params parameter array
|
* @param array $params parameter array
|
||||||
* @param string $content contents of the block
|
* @param string $content contents of the block
|
||||||
* @param \Smarty_Internal_Template $template template object
|
* @param \Smarty\Template $template template object
|
||||||
* @param bool $repeat flag
|
* @param bool $repeat flag
|
||||||
*
|
*
|
||||||
* @return string content re-formatted
|
* @return string content re-formatted
|
||||||
*/
|
*/
|
||||||
function smarty_block_testparameter($params, $content, Smarty_Internal_Template $template, &$repeat)
|
function smarty_block_testparameter($params, $content, Template $template, &$repeat)
|
||||||
{
|
{
|
||||||
if (isset($content)) {
|
if (isset($content)) {
|
||||||
return $content;
|
return $content;
|
||||||
|
@@ -6,6 +6,8 @@
|
|||||||
* @author Uwe Tews
|
* @author Uwe Tews
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class for block extends compiler tests
|
* class for block extends compiler tests
|
||||||
*
|
*
|
||||||
@@ -21,7 +23,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
|
|||||||
//$this->smarty->setMergeCompiledIncludes(true);
|
//$this->smarty->setMergeCompiledIncludes(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
|
public function compiledPrefilter($text, Template $tpl)
|
||||||
{
|
{
|
||||||
return str_replace('#', $tpl->getTemplateVars('test'), $text);
|
return str_replace('#', $tpl->getTemplateVars('test'), $text);
|
||||||
}
|
}
|
||||||
@@ -1096,7 +1098,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
|
|||||||
*/
|
*/
|
||||||
public function testPostFilter_031()
|
public function testPostFilter_031()
|
||||||
{
|
{
|
||||||
function smarty_postfilter_test031($compiled, Smarty_Internal_Template $template)
|
function smarty_postfilter_test031($compiled, Template $template)
|
||||||
{
|
{
|
||||||
return str_replace("'foo'", "'bar'", $compiled);
|
return str_replace("'foo'", "'bar'", $compiled);
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,8 @@
|
|||||||
* @subpackage PHPunitPlugin
|
* @subpackage PHPunitPlugin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {checkconfigvar}
|
* Smarty {checkconfigvar}
|
||||||
*
|
*
|
||||||
@@ -24,7 +26,7 @@ function smarty_function_checkconfigvar($params, $template)
|
|||||||
$var = $params['var'];
|
$var = $params['var'];
|
||||||
$ptr = $template;
|
$ptr = $template;
|
||||||
while ($ptr) {
|
while ($ptr) {
|
||||||
if (in_array('template', $types) && $ptr instanceof Smarty_Internal_Template) {
|
if (in_array('template', $types) && $ptr instanceof Template) {
|
||||||
$output .= "#{$ptr->source->name}:\${$var} =";
|
$output .= "#{$ptr->source->name}:\${$var} =";
|
||||||
$output .= isset($ptr->config_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->config_vars[$var], true)) : 'null';
|
$output .= isset($ptr->config_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->config_vars[$var], true)) : 'null';
|
||||||
$ptr = $ptr->parent;
|
$ptr = $ptr->parent;
|
||||||
|
@@ -6,6 +6,8 @@
|
|||||||
* @subpackage PHPunitPlugin
|
* @subpackage PHPunitPlugin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {checkvar}
|
* Smarty {checkvar}
|
||||||
*
|
*
|
||||||
@@ -24,7 +26,7 @@ function smarty_function_checkvar($params, $template)
|
|||||||
$var = $params['var'];
|
$var = $params['var'];
|
||||||
$ptr = $template;
|
$ptr = $template;
|
||||||
while ($ptr) {
|
while ($ptr) {
|
||||||
if (in_array('template', $types) && $ptr instanceof Smarty_Internal_Template) {
|
if (in_array('template', $types) && $ptr instanceof Template) {
|
||||||
$output .= "#{$ptr->source->name}:\${$var} =";
|
$output .= "#{$ptr->source->name}:\${$var} =";
|
||||||
$output .= isset($ptr->tpl_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->tpl_vars[$var]->value, true)) : '>unassigned<';
|
$output .= isset($ptr->tpl_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->tpl_vars[$var]->value, true)) : '>unassigned<';
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
@@ -6,6 +6,8 @@
|
|||||||
* @subpackage PHPunitPlugin
|
* @subpackage PHPunitPlugin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {gatparams}
|
* Smarty {gatparams}
|
||||||
*
|
*
|
||||||
@@ -14,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function smarty_function_getparams($params, Smarty_Internal_Template $template)
|
function smarty_function_getparams($params, Template $template)
|
||||||
{
|
{
|
||||||
return var_export($params, true);
|
return var_export($params, true);
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,8 @@
|
|||||||
* @subpackage PHPunitPlugin
|
* @subpackage PHPunitPlugin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty {getvar}
|
* Smarty {getvar}
|
||||||
*
|
*
|
||||||
@@ -14,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function smarty_function_getvar($params, Smarty_Internal_Template $template)
|
function smarty_function_getvar($params, Template $template)
|
||||||
{
|
{
|
||||||
if (isset($params[ 'assign' ])) {
|
if (isset($params[ 'assign' ])) {
|
||||||
$template->assign($params[ 'assign' ], $template->getTemplateVars($params[ 'var' ]));
|
$template->assign($params[ 'assign' ], $template->getTemplateVars($params[ 'var' ]));
|
||||||
|
Reference in New Issue
Block a user