@@ -11,37 +11,37 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Smarty_Internal_Method_GetGlobal |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Valid for all objects |
|
| 16 | - * |
|
| 17 | - * @var int |
|
| 18 | - */ |
|
| 19 | - public $objMap = 7; |
|
| 14 | + /** |
|
| 15 | + * Valid for all objects |
|
| 16 | + * |
|
| 17 | + * @var int |
|
| 18 | + */ |
|
| 19 | + public $objMap = 7; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Returns a single or all global variables |
|
| 23 | - * |
|
| 24 | - * @api Smarty::getGlobal() |
|
| 25 | - * |
|
| 26 | - * @param \Smarty_Internal_Data $data |
|
| 27 | - * @param string $varName variable name or null |
|
| 28 | - * |
|
| 29 | - * @return string variable value or or array of variables |
|
| 30 | - */ |
|
| 31 | - public function getGlobal(Smarty_Internal_Data $data, $varName = null) |
|
| 32 | - { |
|
| 33 | - if (isset($varName)) { |
|
| 34 | - if (isset(Smarty::$global_tpl_vars[ $varName ])) { |
|
| 35 | - return Smarty::$global_tpl_vars[ $varName ]->value; |
|
| 36 | - } else { |
|
| 37 | - return ''; |
|
| 38 | - } |
|
| 39 | - } else { |
|
| 40 | - $_result = array(); |
|
| 41 | - foreach (Smarty::$global_tpl_vars AS $key => $var) { |
|
| 42 | - $_result[ $key ] = $var->value; |
|
| 43 | - } |
|
| 44 | - return $_result; |
|
| 45 | - } |
|
| 46 | - } |
|
| 21 | + /** |
|
| 22 | + * Returns a single or all global variables |
|
| 23 | + * |
|
| 24 | + * @api Smarty::getGlobal() |
|
| 25 | + * |
|
| 26 | + * @param \Smarty_Internal_Data $data |
|
| 27 | + * @param string $varName variable name or null |
|
| 28 | + * |
|
| 29 | + * @return string variable value or or array of variables |
|
| 30 | + */ |
|
| 31 | + public function getGlobal(Smarty_Internal_Data $data, $varName = null) |
|
| 32 | + { |
|
| 33 | + if (isset($varName)) { |
|
| 34 | + if (isset(Smarty::$global_tpl_vars[ $varName ])) { |
|
| 35 | + return Smarty::$global_tpl_vars[ $varName ]->value; |
|
| 36 | + } else { |
|
| 37 | + return ''; |
|
| 38 | + } |
|
| 39 | + } else { |
|
| 40 | + $_result = array(); |
|
| 41 | + foreach (Smarty::$global_tpl_vars AS $key => $var) { |
|
| 42 | + $_result[ $key ] = $var->value; |
|
| 43 | + } |
|
| 44 | + return $_result; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | \ No newline at end of file |
@@ -31,15 +31,15 @@ |
||
| 31 | 31 | public function getGlobal(Smarty_Internal_Data $data, $varName = null) |
| 32 | 32 | { |
| 33 | 33 | if (isset($varName)) { |
| 34 | - if (isset(Smarty::$global_tpl_vars[ $varName ])) { |
|
| 35 | - return Smarty::$global_tpl_vars[ $varName ]->value; |
|
| 34 | + if (isset(Smarty::$global_tpl_vars[$varName])) { |
|
| 35 | + return Smarty::$global_tpl_vars[$varName]->value; |
|
| 36 | 36 | } else { |
| 37 | 37 | return ''; |
| 38 | 38 | } |
| 39 | 39 | } else { |
| 40 | 40 | $_result = array(); |
| 41 | 41 | foreach (Smarty::$global_tpl_vars AS $key => $var) { |
| 42 | - $_result[ $key ] = $var->value; |
|
| 42 | + $_result[$key] = $var->value; |
|
| 43 | 43 | } |
| 44 | 44 | return $_result; |
| 45 | 45 | } |
@@ -16,34 +16,34 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | abstract class Smarty_Resource_Uncompiled extends Smarty_Resource |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Flag that it's an uncompiled resource |
|
| 21 | - * |
|
| 22 | - * @var bool |
|
| 23 | - */ |
|
| 24 | - public $uncompiled = true; |
|
| 19 | + /** |
|
| 20 | + * Flag that it's an uncompiled resource |
|
| 21 | + * |
|
| 22 | + * @var bool |
|
| 23 | + */ |
|
| 24 | + public $uncompiled = true; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Resource does implement populateCompiledFilepath() method |
|
| 28 | - * |
|
| 29 | - * @var bool |
|
| 30 | - */ |
|
| 31 | - public $hasCompiledHandler = true; |
|
| 26 | + /** |
|
| 27 | + * Resource does implement populateCompiledFilepath() method |
|
| 28 | + * |
|
| 29 | + * @var bool |
|
| 30 | + */ |
|
| 31 | + public $hasCompiledHandler = true; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * populate compiled object with compiled filepath |
|
| 35 | - * |
|
| 36 | - * @param Smarty_Template_Compiled $compiled compiled object |
|
| 37 | - * @param Smarty_Internal_Template $_template template object |
|
| 38 | - */ |
|
| 39 | - public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) |
|
| 40 | - { |
|
| 41 | - $compiled->filepath = $_template->source->filepath; |
|
| 42 | - $compiled->timestamp = $_template->source->timestamp; |
|
| 43 | - $compiled->exists = $_template->source->exists; |
|
| 44 | - if ($_template->smarty->merge_compiled_includes || $_template->source->handler->checkTimestamps()) { |
|
| 45 | - $compiled->file_dependency[ $_template->source->uid ] = |
|
| 46 | - array($compiled->filepath, $compiled->timestamp, $_template->source->type,); |
|
| 47 | - } |
|
| 48 | - } |
|
| 33 | + /** |
|
| 34 | + * populate compiled object with compiled filepath |
|
| 35 | + * |
|
| 36 | + * @param Smarty_Template_Compiled $compiled compiled object |
|
| 37 | + * @param Smarty_Internal_Template $_template template object |
|
| 38 | + */ |
|
| 39 | + public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) |
|
| 40 | + { |
|
| 41 | + $compiled->filepath = $_template->source->filepath; |
|
| 42 | + $compiled->timestamp = $_template->source->timestamp; |
|
| 43 | + $compiled->exists = $_template->source->exists; |
|
| 44 | + if ($_template->smarty->merge_compiled_includes || $_template->source->handler->checkTimestamps()) { |
|
| 45 | + $compiled->file_dependency[ $_template->source->uid ] = |
|
| 46 | + array($compiled->filepath, $compiled->timestamp, $_template->source->type,); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | $compiled->timestamp = $_template->source->timestamp; |
| 43 | 43 | $compiled->exists = $_template->source->exists; |
| 44 | 44 | if ($_template->smarty->merge_compiled_includes || $_template->source->handler->checkTimestamps()) { |
| 45 | - $compiled->file_dependency[ $_template->source->uid ] = |
|
| 45 | + $compiled->file_dependency[$_template->source->uid] = |
|
| 46 | 46 | array($compiled->filepath, $compiled->timestamp, $_template->source->type,); |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -33,115 +33,115 @@ |
||
| 33 | 33 | class Smarty_Internal_Extension_Handler |
| 34 | 34 | { |
| 35 | 35 | |
| 36 | - public $objType = null; |
|
| 36 | + public $objType = null; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Cache for property information from generic getter/setter |
|
| 40 | - * Preloaded with names which should not use with generic getter/setter |
|
| 41 | - * |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - private $_property_info = array('AutoloadFilters' => 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0, |
|
| 45 | - 'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0, |
|
| 46 | - 'TemplateVars' => 0,);# |
|
| 38 | + /** |
|
| 39 | + * Cache for property information from generic getter/setter |
|
| 40 | + * Preloaded with names which should not use with generic getter/setter |
|
| 41 | + * |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + private $_property_info = array('AutoloadFilters' => 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0, |
|
| 45 | + 'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0, |
|
| 46 | + 'TemplateVars' => 0,);# |
|
| 47 | 47 | |
| 48 | - private $resolvedProperties = array(); |
|
| 48 | + private $resolvedProperties = array(); |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Call external Method |
|
| 52 | - * |
|
| 53 | - * @param \Smarty_Internal_Data $data |
|
| 54 | - * @param string $name external method names |
|
| 55 | - * @param array $args argument array |
|
| 56 | - * |
|
| 57 | - * @return mixed |
|
| 58 | - * @throws SmartyException |
|
| 59 | - */ |
|
| 60 | - public function _callExternalMethod(Smarty_Internal_Data $data, $name, $args) |
|
| 61 | - { |
|
| 62 | - /* @var Smarty $data ->smarty */ |
|
| 63 | - $smarty = isset($data->smarty) ? $data->smarty : $data; |
|
| 64 | - if (!isset($smarty->ext->$name)) { |
|
| 65 | - $class = 'Smarty_Internal_Method_' . ucfirst($name); |
|
| 66 | - if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) { |
|
| 67 | - if (!isset($this->_property_info[ $prop = $match[ 2 ] ])) { |
|
| 68 | - // convert camel case to underscored name |
|
| 69 | - $this->resolvedProperties[ $prop ] = $pn = strtolower(join('_', |
|
| 70 | - preg_split('/([A-Z][^A-Z]*)/', $prop, |
|
| 71 | - - 1, PREG_SPLIT_NO_EMPTY | |
|
| 72 | - PREG_SPLIT_DELIM_CAPTURE))); |
|
| 73 | - $this->_property_info[ $prop ] = property_exists($data, $pn) ? 1 : |
|
| 74 | - ($data->_objType == 2 && property_exists($smarty, $pn) ? 2 : 0); |
|
| 75 | - } |
|
| 76 | - if ($this->_property_info[ $prop ]) { |
|
| 77 | - $pn = $this->resolvedProperties[ $prop ]; |
|
| 78 | - if ($match[ 1 ] == 'get') { |
|
| 79 | - return $this->_property_info[ $prop ] == 1 ? $data->$pn : $data->smarty->$pn; |
|
| 80 | - } else { |
|
| 81 | - return $this->_property_info[ $prop ] == 1 ? $data->$pn = $args[ 0 ] : |
|
| 82 | - $data->smarty->$pn = $args[ 0 ]; |
|
| 83 | - } |
|
| 84 | - } elseif (!class_exists($class)) { |
|
| 85 | - throw new SmartyException("property '$pn' does not exist."); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - if (class_exists($class)) { |
|
| 89 | - $callback = array($smarty->ext->$name = new $class(), $name); |
|
| 90 | - } |
|
| 91 | - } else { |
|
| 92 | - $callback = array($smarty->ext->$name, $name); |
|
| 93 | - } |
|
| 94 | - array_unshift($args, $data); |
|
| 95 | - if (isset($callback) && $callback[ 0 ]->objMap | $data->_objType) { |
|
| 96 | - return call_user_func_array($callback, $args); |
|
| 97 | - } |
|
| 98 | - return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), $args); |
|
| 99 | - } |
|
| 50 | + /** |
|
| 51 | + * Call external Method |
|
| 52 | + * |
|
| 53 | + * @param \Smarty_Internal_Data $data |
|
| 54 | + * @param string $name external method names |
|
| 55 | + * @param array $args argument array |
|
| 56 | + * |
|
| 57 | + * @return mixed |
|
| 58 | + * @throws SmartyException |
|
| 59 | + */ |
|
| 60 | + public function _callExternalMethod(Smarty_Internal_Data $data, $name, $args) |
|
| 61 | + { |
|
| 62 | + /* @var Smarty $data ->smarty */ |
|
| 63 | + $smarty = isset($data->smarty) ? $data->smarty : $data; |
|
| 64 | + if (!isset($smarty->ext->$name)) { |
|
| 65 | + $class = 'Smarty_Internal_Method_' . ucfirst($name); |
|
| 66 | + if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) { |
|
| 67 | + if (!isset($this->_property_info[ $prop = $match[ 2 ] ])) { |
|
| 68 | + // convert camel case to underscored name |
|
| 69 | + $this->resolvedProperties[ $prop ] = $pn = strtolower(join('_', |
|
| 70 | + preg_split('/([A-Z][^A-Z]*)/', $prop, |
|
| 71 | + - 1, PREG_SPLIT_NO_EMPTY | |
|
| 72 | + PREG_SPLIT_DELIM_CAPTURE))); |
|
| 73 | + $this->_property_info[ $prop ] = property_exists($data, $pn) ? 1 : |
|
| 74 | + ($data->_objType == 2 && property_exists($smarty, $pn) ? 2 : 0); |
|
| 75 | + } |
|
| 76 | + if ($this->_property_info[ $prop ]) { |
|
| 77 | + $pn = $this->resolvedProperties[ $prop ]; |
|
| 78 | + if ($match[ 1 ] == 'get') { |
|
| 79 | + return $this->_property_info[ $prop ] == 1 ? $data->$pn : $data->smarty->$pn; |
|
| 80 | + } else { |
|
| 81 | + return $this->_property_info[ $prop ] == 1 ? $data->$pn = $args[ 0 ] : |
|
| 82 | + $data->smarty->$pn = $args[ 0 ]; |
|
| 83 | + } |
|
| 84 | + } elseif (!class_exists($class)) { |
|
| 85 | + throw new SmartyException("property '$pn' does not exist."); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + if (class_exists($class)) { |
|
| 89 | + $callback = array($smarty->ext->$name = new $class(), $name); |
|
| 90 | + } |
|
| 91 | + } else { |
|
| 92 | + $callback = array($smarty->ext->$name, $name); |
|
| 93 | + } |
|
| 94 | + array_unshift($args, $data); |
|
| 95 | + if (isset($callback) && $callback[ 0 ]->objMap | $data->_objType) { |
|
| 96 | + return call_user_func_array($callback, $args); |
|
| 97 | + } |
|
| 98 | + return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), $args); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * set extension property |
|
| 103 | - * |
|
| 104 | - * @param string $property_name property name |
|
| 105 | - * @param mixed $value value |
|
| 106 | - * |
|
| 107 | - * @throws SmartyException |
|
| 108 | - */ |
|
| 109 | - public function __set($property_name, $value) |
|
| 110 | - { |
|
| 111 | - $this->$property_name = $value; |
|
| 112 | - } |
|
| 101 | + /** |
|
| 102 | + * set extension property |
|
| 103 | + * |
|
| 104 | + * @param string $property_name property name |
|
| 105 | + * @param mixed $value value |
|
| 106 | + * |
|
| 107 | + * @throws SmartyException |
|
| 108 | + */ |
|
| 109 | + public function __set($property_name, $value) |
|
| 110 | + { |
|
| 111 | + $this->$property_name = $value; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * get extension object |
|
| 116 | - * |
|
| 117 | - * @param string $property_name property name |
|
| 118 | - * |
|
| 119 | - * @return mixed|Smarty_Template_Cached |
|
| 120 | - * @throws SmartyException |
|
| 121 | - */ |
|
| 122 | - public function __get($property_name) |
|
| 123 | - { |
|
| 124 | - // object properties of runtime template extensions will start with '_' |
|
| 125 | - if ($property_name[ 0 ] == '_') { |
|
| 126 | - $class = 'Smarty_Internal_Runtime_' . ucfirst(substr($property_name, 1)); |
|
| 127 | - } else { |
|
| 128 | - $class = 'Smarty_Internal_Method_' . ucfirst($property_name); |
|
| 129 | - } |
|
| 130 | - return $this->$property_name = new $class(); |
|
| 131 | - } |
|
| 114 | + /** |
|
| 115 | + * get extension object |
|
| 116 | + * |
|
| 117 | + * @param string $property_name property name |
|
| 118 | + * |
|
| 119 | + * @return mixed|Smarty_Template_Cached |
|
| 120 | + * @throws SmartyException |
|
| 121 | + */ |
|
| 122 | + public function __get($property_name) |
|
| 123 | + { |
|
| 124 | + // object properties of runtime template extensions will start with '_' |
|
| 125 | + if ($property_name[ 0 ] == '_') { |
|
| 126 | + $class = 'Smarty_Internal_Runtime_' . ucfirst(substr($property_name, 1)); |
|
| 127 | + } else { |
|
| 128 | + $class = 'Smarty_Internal_Method_' . ucfirst($property_name); |
|
| 129 | + } |
|
| 130 | + return $this->$property_name = new $class(); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Call error handler for undefined method |
|
| 135 | - * |
|
| 136 | - * @param string $name unknown method-name |
|
| 137 | - * @param array $args argument array |
|
| 138 | - * |
|
| 139 | - * @return mixed |
|
| 140 | - * @throws SmartyException |
|
| 141 | - */ |
|
| 142 | - public function __call($name, $args) |
|
| 143 | - { |
|
| 144 | - return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), array($this)); |
|
| 145 | - } |
|
| 133 | + /** |
|
| 134 | + * Call error handler for undefined method |
|
| 135 | + * |
|
| 136 | + * @param string $name unknown method-name |
|
| 137 | + * @param array $args argument array |
|
| 138 | + * |
|
| 139 | + * @return mixed |
|
| 140 | + * @throws SmartyException |
|
| 141 | + */ |
|
| 142 | + public function __call($name, $args) |
|
| 143 | + { |
|
| 144 | + return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), array($this)); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | 147 | } |
| 148 | 148 | \ No newline at end of file |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | private $_property_info = array('AutoloadFilters' => 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0, |
| 45 | 45 | 'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0, |
| 46 | - 'TemplateVars' => 0,);# |
|
| 46 | + 'TemplateVars' => 0,); # |
|
| 47 | 47 | |
| 48 | 48 | private $resolvedProperties = array(); |
| 49 | 49 | |
@@ -64,22 +64,20 @@ discard block |
||
| 64 | 64 | if (!isset($smarty->ext->$name)) { |
| 65 | 65 | $class = 'Smarty_Internal_Method_' . ucfirst($name); |
| 66 | 66 | if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) { |
| 67 | - if (!isset($this->_property_info[ $prop = $match[ 2 ] ])) { |
|
| 67 | + if (!isset($this->_property_info[$prop = $match[2]])) { |
|
| 68 | 68 | // convert camel case to underscored name |
| 69 | - $this->resolvedProperties[ $prop ] = $pn = strtolower(join('_', |
|
| 69 | + $this->resolvedProperties[$prop] = $pn = strtolower(join('_', |
|
| 70 | 70 | preg_split('/([A-Z][^A-Z]*)/', $prop, |
| 71 | 71 | - 1, PREG_SPLIT_NO_EMPTY | |
| 72 | 72 | PREG_SPLIT_DELIM_CAPTURE))); |
| 73 | - $this->_property_info[ $prop ] = property_exists($data, $pn) ? 1 : |
|
| 74 | - ($data->_objType == 2 && property_exists($smarty, $pn) ? 2 : 0); |
|
| 73 | + $this->_property_info[$prop] = property_exists($data, $pn) ? 1 : ($data->_objType == 2 && property_exists($smarty, $pn) ? 2 : 0); |
|
| 75 | 74 | } |
| 76 | - if ($this->_property_info[ $prop ]) { |
|
| 77 | - $pn = $this->resolvedProperties[ $prop ]; |
|
| 78 | - if ($match[ 1 ] == 'get') { |
|
| 79 | - return $this->_property_info[ $prop ] == 1 ? $data->$pn : $data->smarty->$pn; |
|
| 75 | + if ($this->_property_info[$prop]) { |
|
| 76 | + $pn = $this->resolvedProperties[$prop]; |
|
| 77 | + if ($match[1] == 'get') { |
|
| 78 | + return $this->_property_info[$prop] == 1 ? $data->$pn : $data->smarty->$pn; |
|
| 80 | 79 | } else { |
| 81 | - return $this->_property_info[ $prop ] == 1 ? $data->$pn = $args[ 0 ] : |
|
| 82 | - $data->smarty->$pn = $args[ 0 ]; |
|
| 80 | + return $this->_property_info[$prop] == 1 ? $data->$pn = $args[0] : $data->smarty->$pn = $args[0]; |
|
| 83 | 81 | } |
| 84 | 82 | } elseif (!class_exists($class)) { |
| 85 | 83 | throw new SmartyException("property '$pn' does not exist."); |
@@ -92,7 +90,7 @@ discard block |
||
| 92 | 90 | $callback = array($smarty->ext->$name, $name); |
| 93 | 91 | } |
| 94 | 92 | array_unshift($args, $data); |
| 95 | - if (isset($callback) && $callback[ 0 ]->objMap | $data->_objType) { |
|
| 93 | + if (isset($callback) && $callback[0]->objMap | $data->_objType) { |
|
| 96 | 94 | return call_user_func_array($callback, $args); |
| 97 | 95 | } |
| 98 | 96 | return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), $args); |
@@ -122,7 +120,7 @@ discard block |
||
| 122 | 120 | public function __get($property_name) |
| 123 | 121 | { |
| 124 | 122 | // object properties of runtime template extensions will start with '_' |
| 125 | - if ($property_name[ 0 ] == '_') { |
|
| 123 | + if ($property_name[0] == '_') { |
|
| 126 | 124 | $class = 'Smarty_Internal_Runtime_' . ucfirst(substr($property_name, 1)); |
| 127 | 125 | } else { |
| 128 | 126 | $class = 'Smarty_Internal_Method_' . ucfirst($property_name); |
@@ -12,41 +12,41 @@ |
||
| 12 | 12 | class Smarty_Internal_Method_AddAutoloadFilters extends Smarty_Internal_Method_SetAutoloadFilters |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Add autoload filters |
|
| 17 | - * |
|
| 18 | - * @api Smarty::setAutoloadFilters() |
|
| 19 | - * |
|
| 20 | - * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 21 | - * @param array $filters filters to load automatically |
|
| 22 | - * @param string $type "pre", "output", … specify the |
|
| 23 | - * filter type to set. Defaults to |
|
| 24 | - * none treating $filters' keys as |
|
| 25 | - * the appropriate types |
|
| 26 | - * |
|
| 27 | - * @return \Smarty|\Smarty_Internal_Template |
|
| 28 | - */ |
|
| 29 | - public function addAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null) |
|
| 30 | - { |
|
| 31 | - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 32 | - if ($type !== null) { |
|
| 33 | - $this->_checkFilterType($type); |
|
| 34 | - if (!empty($smarty->autoload_filters[ $type ])) { |
|
| 35 | - $smarty->autoload_filters[ $type ] = array_merge($smarty->autoload_filters[ $type ], (array) $filters); |
|
| 36 | - } else { |
|
| 37 | - $smarty->autoload_filters[ $type ] = (array) $filters; |
|
| 38 | - } |
|
| 39 | - } else { |
|
| 40 | - foreach ((array) $filters as $type => $value) { |
|
| 41 | - $this->_checkFilterType($type); |
|
| 42 | - if (!empty($smarty->autoload_filters[ $type ])) { |
|
| 43 | - $smarty->autoload_filters[ $type ] = |
|
| 44 | - array_merge($smarty->autoload_filters[ $type ], (array) $value); |
|
| 45 | - } else { |
|
| 46 | - $smarty->autoload_filters[ $type ] = (array) $value; |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - return $obj; |
|
| 51 | - } |
|
| 15 | + /** |
|
| 16 | + * Add autoload filters |
|
| 17 | + * |
|
| 18 | + * @api Smarty::setAutoloadFilters() |
|
| 19 | + * |
|
| 20 | + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 21 | + * @param array $filters filters to load automatically |
|
| 22 | + * @param string $type "pre", "output", … specify the |
|
| 23 | + * filter type to set. Defaults to |
|
| 24 | + * none treating $filters' keys as |
|
| 25 | + * the appropriate types |
|
| 26 | + * |
|
| 27 | + * @return \Smarty|\Smarty_Internal_Template |
|
| 28 | + */ |
|
| 29 | + public function addAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null) |
|
| 30 | + { |
|
| 31 | + $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 32 | + if ($type !== null) { |
|
| 33 | + $this->_checkFilterType($type); |
|
| 34 | + if (!empty($smarty->autoload_filters[ $type ])) { |
|
| 35 | + $smarty->autoload_filters[ $type ] = array_merge($smarty->autoload_filters[ $type ], (array) $filters); |
|
| 36 | + } else { |
|
| 37 | + $smarty->autoload_filters[ $type ] = (array) $filters; |
|
| 38 | + } |
|
| 39 | + } else { |
|
| 40 | + foreach ((array) $filters as $type => $value) { |
|
| 41 | + $this->_checkFilterType($type); |
|
| 42 | + if (!empty($smarty->autoload_filters[ $type ])) { |
|
| 43 | + $smarty->autoload_filters[ $type ] = |
|
| 44 | + array_merge($smarty->autoload_filters[ $type ], (array) $value); |
|
| 45 | + } else { |
|
| 46 | + $smarty->autoload_filters[ $type ] = (array) $value; |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + return $obj; |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -31,19 +31,19 @@ |
||
| 31 | 31 | $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
| 32 | 32 | if ($type !== null) { |
| 33 | 33 | $this->_checkFilterType($type); |
| 34 | - if (!empty($smarty->autoload_filters[ $type ])) { |
|
| 35 | - $smarty->autoload_filters[ $type ] = array_merge($smarty->autoload_filters[ $type ], (array) $filters); |
|
| 34 | + if (!empty($smarty->autoload_filters[$type])) { |
|
| 35 | + $smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $filters); |
|
| 36 | 36 | } else { |
| 37 | - $smarty->autoload_filters[ $type ] = (array) $filters; |
|
| 37 | + $smarty->autoload_filters[$type] = (array) $filters; |
|
| 38 | 38 | } |
| 39 | 39 | } else { |
| 40 | 40 | foreach ((array) $filters as $type => $value) { |
| 41 | 41 | $this->_checkFilterType($type); |
| 42 | - if (!empty($smarty->autoload_filters[ $type ])) { |
|
| 43 | - $smarty->autoload_filters[ $type ] = |
|
| 44 | - array_merge($smarty->autoload_filters[ $type ], (array) $value); |
|
| 42 | + if (!empty($smarty->autoload_filters[$type])) { |
|
| 43 | + $smarty->autoload_filters[$type] = |
|
| 44 | + array_merge($smarty->autoload_filters[$type], (array) $value); |
|
| 45 | 45 | } else { |
| 46 | - $smarty->autoload_filters[ $type ] = (array) $value; |
|
| 46 | + $smarty->autoload_filters[$type] = (array) $value; |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -11,30 +11,30 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Smarty_Internal_Method_UnregisterCacheResource |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Valid for Smarty and template object |
|
| 16 | - * |
|
| 17 | - * @var int |
|
| 18 | - */ |
|
| 19 | - public $objMap = 3; |
|
| 14 | + /** |
|
| 15 | + * Valid for Smarty and template object |
|
| 16 | + * |
|
| 17 | + * @var int |
|
| 18 | + */ |
|
| 19 | + public $objMap = 3; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Registers a resource to fetch a template |
|
| 23 | - * |
|
| 24 | - * @api Smarty::unregisterCacheResource() |
|
| 25 | - * @link http://www.smarty.net/docs/en/api.unregister.cacheresource.tpl |
|
| 26 | - * |
|
| 27 | - * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 28 | - * @param $name |
|
| 29 | - * |
|
| 30 | - * @return \Smarty|\Smarty_Internal_Template |
|
| 31 | - */ |
|
| 32 | - public function unregisterCacheResource(Smarty_Internal_TemplateBase $obj, $name) |
|
| 33 | - { |
|
| 34 | - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 35 | - if (isset($smarty->registered_cache_resources[ $name ])) { |
|
| 36 | - unset($smarty->registered_cache_resources[ $name ]); |
|
| 37 | - } |
|
| 38 | - return $obj; |
|
| 39 | - } |
|
| 21 | + /** |
|
| 22 | + * Registers a resource to fetch a template |
|
| 23 | + * |
|
| 24 | + * @api Smarty::unregisterCacheResource() |
|
| 25 | + * @link http://www.smarty.net/docs/en/api.unregister.cacheresource.tpl |
|
| 26 | + * |
|
| 27 | + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 28 | + * @param $name |
|
| 29 | + * |
|
| 30 | + * @return \Smarty|\Smarty_Internal_Template |
|
| 31 | + */ |
|
| 32 | + public function unregisterCacheResource(Smarty_Internal_TemplateBase $obj, $name) |
|
| 33 | + { |
|
| 34 | + $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 35 | + if (isset($smarty->registered_cache_resources[ $name ])) { |
|
| 36 | + unset($smarty->registered_cache_resources[ $name ]); |
|
| 37 | + } |
|
| 38 | + return $obj; |
|
| 39 | + } |
|
| 40 | 40 | } |
| 41 | 41 | \ No newline at end of file |
@@ -32,8 +32,8 @@ |
||
| 32 | 32 | public function unregisterCacheResource(Smarty_Internal_TemplateBase $obj, $name) |
| 33 | 33 | { |
| 34 | 34 | $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
| 35 | - if (isset($smarty->registered_cache_resources[ $name ])) { |
|
| 36 | - unset($smarty->registered_cache_resources[ $name ]); |
|
| 35 | + if (isset($smarty->registered_cache_resources[$name])) { |
|
| 36 | + unset($smarty->registered_cache_resources[$name]); |
|
| 37 | 37 | } |
| 38 | 38 | return $obj; |
| 39 | 39 | } |
@@ -11,41 +11,41 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Smarty_Internal_Method_MustCompile |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Valid for template object |
|
| 16 | - * |
|
| 17 | - * @var int |
|
| 18 | - */ |
|
| 19 | - public $objMap = 2; |
|
| 14 | + /** |
|
| 15 | + * Valid for template object |
|
| 16 | + * |
|
| 17 | + * @var int |
|
| 18 | + */ |
|
| 19 | + public $objMap = 2; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Returns if the current template must be compiled by the Smarty compiler |
|
| 23 | - * It does compare the timestamps of template source and the compiled templates and checks the force compile |
|
| 24 | - * configuration |
|
| 25 | - * |
|
| 26 | - * @param \Smarty_Internal_Template $_template |
|
| 27 | - * |
|
| 28 | - * @return bool |
|
| 29 | - * @throws \SmartyException |
|
| 30 | - */ |
|
| 31 | - public function mustCompile(Smarty_Internal_Template $_template) |
|
| 32 | - { |
|
| 33 | - if (!$_template->source->exists) { |
|
| 34 | - if (isset($_template->parent) && $_template->parent->_objType == 2) { |
|
| 35 | - $parent_resource = " in '$_template->parent->template_resource}'"; |
|
| 36 | - } else { |
|
| 37 | - $parent_resource = ''; |
|
| 38 | - } |
|
| 39 | - throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}"); |
|
| 40 | - } |
|
| 41 | - if ($_template->mustCompile === null) { |
|
| 42 | - $_template->mustCompile = (!$_template->source->handler->uncompiled && |
|
| 43 | - ($_template->smarty->force_compile || $_template->source->handler->recompiled || |
|
| 44 | - !$_template->compiled->exists || ($_template->smarty->compile_check && |
|
| 45 | - $_template->compiled->getTimeStamp() < |
|
| 46 | - $_template->source->getTimeStamp()))); |
|
| 47 | - } |
|
| 21 | + /** |
|
| 22 | + * Returns if the current template must be compiled by the Smarty compiler |
|
| 23 | + * It does compare the timestamps of template source and the compiled templates and checks the force compile |
|
| 24 | + * configuration |
|
| 25 | + * |
|
| 26 | + * @param \Smarty_Internal_Template $_template |
|
| 27 | + * |
|
| 28 | + * @return bool |
|
| 29 | + * @throws \SmartyException |
|
| 30 | + */ |
|
| 31 | + public function mustCompile(Smarty_Internal_Template $_template) |
|
| 32 | + { |
|
| 33 | + if (!$_template->source->exists) { |
|
| 34 | + if (isset($_template->parent) && $_template->parent->_objType == 2) { |
|
| 35 | + $parent_resource = " in '$_template->parent->template_resource}'"; |
|
| 36 | + } else { |
|
| 37 | + $parent_resource = ''; |
|
| 38 | + } |
|
| 39 | + throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}"); |
|
| 40 | + } |
|
| 41 | + if ($_template->mustCompile === null) { |
|
| 42 | + $_template->mustCompile = (!$_template->source->handler->uncompiled && |
|
| 43 | + ($_template->smarty->force_compile || $_template->source->handler->recompiled || |
|
| 44 | + !$_template->compiled->exists || ($_template->smarty->compile_check && |
|
| 45 | + $_template->compiled->getTimeStamp() < |
|
| 46 | + $_template->source->getTimeStamp()))); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return $_template->mustCompile; |
|
| 50 | - } |
|
| 49 | + return $_template->mustCompile; |
|
| 50 | + } |
|
| 51 | 51 | } |
| 52 | 52 | \ No newline at end of file |
@@ -17,141 +17,141 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBase |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Compiles code for modifier execution |
|
| 22 | - * |
|
| 23 | - * @param array $args array with attributes from parser |
|
| 24 | - * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object |
|
| 25 | - * @param array $parameter array with compilation parameter |
|
| 26 | - * |
|
| 27 | - * @return string compiled code |
|
| 28 | - * @throws \SmartyCompilerException |
|
| 29 | - */ |
|
| 30 | - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) |
|
| 31 | - { |
|
| 32 | - // check and get attributes |
|
| 33 | - $_attr = $this->getAttributes($compiler, $args); |
|
| 34 | - $output = $parameter[ 'value' ]; |
|
| 35 | - // loop over list of modifiers |
|
| 36 | - foreach ($parameter[ 'modifierlist' ] as $single_modifier) { |
|
| 37 | - $modifier = $single_modifier[ 0 ]; |
|
| 38 | - $single_modifier[ 0 ] = $output; |
|
| 39 | - $params = implode(',', $single_modifier); |
|
| 40 | - // check if we know already the type of modifier |
|
| 41 | - if (isset($compiler->known_modifier_type[ $modifier ])) { |
|
| 42 | - $modifier_types = array($compiler->known_modifier_type[ $modifier ]); |
|
| 43 | - } else { |
|
| 44 | - $modifier_types = array(1, 2, 3, 4, 5, 6); |
|
| 45 | - } |
|
| 46 | - foreach ($modifier_types as $type) { |
|
| 47 | - switch ($type) { |
|
| 48 | - case 1: |
|
| 49 | - // registered modifier |
|
| 50 | - if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) { |
|
| 51 | - $function = |
|
| 52 | - $compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ]; |
|
| 53 | - if (!is_array($function)) { |
|
| 54 | - $output = "{$function}({$params})"; |
|
| 55 | - } else { |
|
| 56 | - if (is_object($function[ 0 ])) { |
|
| 57 | - $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . |
|
| 58 | - $modifier . '\'][0][0]->' . $function[ 1 ] . '(' . $params . ')'; |
|
| 59 | - } else { |
|
| 60 | - $output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')'; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 64 | - break 2; |
|
| 65 | - } |
|
| 66 | - break; |
|
| 67 | - case 2: |
|
| 68 | - // registered modifier compiler |
|
| 69 | - if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ])) { |
|
| 70 | - $output = |
|
| 71 | - call_user_func($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ], |
|
| 72 | - $single_modifier, $compiler->smarty); |
|
| 73 | - $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 74 | - break 2; |
|
| 75 | - } |
|
| 76 | - break; |
|
| 77 | - case 3: |
|
| 78 | - // modifiercompiler plugin |
|
| 79 | - if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) { |
|
| 80 | - // check if modifier allowed |
|
| 81 | - if (!is_object($compiler->smarty->security_policy) || |
|
| 82 | - $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) |
|
| 83 | - ) { |
|
| 84 | - $plugin = 'smarty_modifiercompiler_' . $modifier; |
|
| 85 | - $output = $plugin($single_modifier, $compiler); |
|
| 86 | - } |
|
| 87 | - $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 88 | - break 2; |
|
| 89 | - } |
|
| 90 | - break; |
|
| 91 | - case 4: |
|
| 92 | - // modifier plugin |
|
| 93 | - if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) { |
|
| 94 | - // check if modifier allowed |
|
| 95 | - if (!is_object($compiler->smarty->security_policy) || |
|
| 96 | - $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) |
|
| 97 | - ) { |
|
| 98 | - $output = "{$function}({$params})"; |
|
| 99 | - } |
|
| 100 | - $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 101 | - break 2; |
|
| 102 | - } |
|
| 103 | - break; |
|
| 104 | - case 5: |
|
| 105 | - // PHP function |
|
| 106 | - if (is_callable($modifier)) { |
|
| 107 | - // check if modifier allowed |
|
| 108 | - if (!is_object($compiler->smarty->security_policy) || |
|
| 109 | - $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler) |
|
| 110 | - ) { |
|
| 111 | - $output = "{$modifier}({$params})"; |
|
| 112 | - } |
|
| 113 | - $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 114 | - break 2; |
|
| 115 | - } |
|
| 116 | - break; |
|
| 117 | - case 6: |
|
| 118 | - // default plugin handler |
|
| 119 | - if (isset($compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ]) || |
|
| 120 | - (is_callable($compiler->smarty->default_plugin_handler_func) && |
|
| 121 | - $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER)) |
|
| 122 | - ) { |
|
| 123 | - $function = $compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ]; |
|
| 124 | - // check if modifier allowed |
|
| 125 | - if (!is_object($compiler->smarty->security_policy) || |
|
| 126 | - $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) |
|
| 127 | - ) { |
|
| 128 | - if (!is_array($function)) { |
|
| 129 | - $output = "{$function}({$params})"; |
|
| 130 | - } else { |
|
| 131 | - if (is_object($function[ 0 ])) { |
|
| 132 | - $output = $function[ 0 ] . '->'. $function[ 1 ] . '(' . $params . ')'; |
|
| 133 | - } else { |
|
| 134 | - $output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')'; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - if (isset($compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) || |
|
| 139 | - isset($compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) |
|
| 140 | - ) { |
|
| 141 | - // was a plugin |
|
| 142 | - $compiler->known_modifier_type[ $modifier ] = 4; |
|
| 143 | - } else { |
|
| 144 | - $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 145 | - } |
|
| 146 | - break 2; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - if (!isset($compiler->known_modifier_type[ $modifier ])) { |
|
| 151 | - $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", null, true); |
|
| 152 | - } |
|
| 153 | - } |
|
| 20 | + /** |
|
| 21 | + * Compiles code for modifier execution |
|
| 22 | + * |
|
| 23 | + * @param array $args array with attributes from parser |
|
| 24 | + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object |
|
| 25 | + * @param array $parameter array with compilation parameter |
|
| 26 | + * |
|
| 27 | + * @return string compiled code |
|
| 28 | + * @throws \SmartyCompilerException |
|
| 29 | + */ |
|
| 30 | + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) |
|
| 31 | + { |
|
| 32 | + // check and get attributes |
|
| 33 | + $_attr = $this->getAttributes($compiler, $args); |
|
| 34 | + $output = $parameter[ 'value' ]; |
|
| 35 | + // loop over list of modifiers |
|
| 36 | + foreach ($parameter[ 'modifierlist' ] as $single_modifier) { |
|
| 37 | + $modifier = $single_modifier[ 0 ]; |
|
| 38 | + $single_modifier[ 0 ] = $output; |
|
| 39 | + $params = implode(',', $single_modifier); |
|
| 40 | + // check if we know already the type of modifier |
|
| 41 | + if (isset($compiler->known_modifier_type[ $modifier ])) { |
|
| 42 | + $modifier_types = array($compiler->known_modifier_type[ $modifier ]); |
|
| 43 | + } else { |
|
| 44 | + $modifier_types = array(1, 2, 3, 4, 5, 6); |
|
| 45 | + } |
|
| 46 | + foreach ($modifier_types as $type) { |
|
| 47 | + switch ($type) { |
|
| 48 | + case 1: |
|
| 49 | + // registered modifier |
|
| 50 | + if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) { |
|
| 51 | + $function = |
|
| 52 | + $compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ]; |
|
| 53 | + if (!is_array($function)) { |
|
| 54 | + $output = "{$function}({$params})"; |
|
| 55 | + } else { |
|
| 56 | + if (is_object($function[ 0 ])) { |
|
| 57 | + $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . |
|
| 58 | + $modifier . '\'][0][0]->' . $function[ 1 ] . '(' . $params . ')'; |
|
| 59 | + } else { |
|
| 60 | + $output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')'; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 64 | + break 2; |
|
| 65 | + } |
|
| 66 | + break; |
|
| 67 | + case 2: |
|
| 68 | + // registered modifier compiler |
|
| 69 | + if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ])) { |
|
| 70 | + $output = |
|
| 71 | + call_user_func($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ], |
|
| 72 | + $single_modifier, $compiler->smarty); |
|
| 73 | + $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 74 | + break 2; |
|
| 75 | + } |
|
| 76 | + break; |
|
| 77 | + case 3: |
|
| 78 | + // modifiercompiler plugin |
|
| 79 | + if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) { |
|
| 80 | + // check if modifier allowed |
|
| 81 | + if (!is_object($compiler->smarty->security_policy) || |
|
| 82 | + $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) |
|
| 83 | + ) { |
|
| 84 | + $plugin = 'smarty_modifiercompiler_' . $modifier; |
|
| 85 | + $output = $plugin($single_modifier, $compiler); |
|
| 86 | + } |
|
| 87 | + $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 88 | + break 2; |
|
| 89 | + } |
|
| 90 | + break; |
|
| 91 | + case 4: |
|
| 92 | + // modifier plugin |
|
| 93 | + if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) { |
|
| 94 | + // check if modifier allowed |
|
| 95 | + if (!is_object($compiler->smarty->security_policy) || |
|
| 96 | + $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) |
|
| 97 | + ) { |
|
| 98 | + $output = "{$function}({$params})"; |
|
| 99 | + } |
|
| 100 | + $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 101 | + break 2; |
|
| 102 | + } |
|
| 103 | + break; |
|
| 104 | + case 5: |
|
| 105 | + // PHP function |
|
| 106 | + if (is_callable($modifier)) { |
|
| 107 | + // check if modifier allowed |
|
| 108 | + if (!is_object($compiler->smarty->security_policy) || |
|
| 109 | + $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler) |
|
| 110 | + ) { |
|
| 111 | + $output = "{$modifier}({$params})"; |
|
| 112 | + } |
|
| 113 | + $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 114 | + break 2; |
|
| 115 | + } |
|
| 116 | + break; |
|
| 117 | + case 6: |
|
| 118 | + // default plugin handler |
|
| 119 | + if (isset($compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ]) || |
|
| 120 | + (is_callable($compiler->smarty->default_plugin_handler_func) && |
|
| 121 | + $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER)) |
|
| 122 | + ) { |
|
| 123 | + $function = $compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ]; |
|
| 124 | + // check if modifier allowed |
|
| 125 | + if (!is_object($compiler->smarty->security_policy) || |
|
| 126 | + $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) |
|
| 127 | + ) { |
|
| 128 | + if (!is_array($function)) { |
|
| 129 | + $output = "{$function}({$params})"; |
|
| 130 | + } else { |
|
| 131 | + if (is_object($function[ 0 ])) { |
|
| 132 | + $output = $function[ 0 ] . '->'. $function[ 1 ] . '(' . $params . ')'; |
|
| 133 | + } else { |
|
| 134 | + $output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')'; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + if (isset($compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) || |
|
| 139 | + isset($compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) |
|
| 140 | + ) { |
|
| 141 | + // was a plugin |
|
| 142 | + $compiler->known_modifier_type[ $modifier ] = 4; |
|
| 143 | + } else { |
|
| 144 | + $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 145 | + } |
|
| 146 | + break 2; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + if (!isset($compiler->known_modifier_type[ $modifier ])) { |
|
| 151 | + $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", null, true); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - return $output; |
|
| 156 | - } |
|
| 155 | + return $output; |
|
| 156 | + } |
|
| 157 | 157 | } |
@@ -31,15 +31,15 @@ discard block |
||
| 31 | 31 | { |
| 32 | 32 | // check and get attributes |
| 33 | 33 | $_attr = $this->getAttributes($compiler, $args); |
| 34 | - $output = $parameter[ 'value' ]; |
|
| 34 | + $output = $parameter['value']; |
|
| 35 | 35 | // loop over list of modifiers |
| 36 | - foreach ($parameter[ 'modifierlist' ] as $single_modifier) { |
|
| 37 | - $modifier = $single_modifier[ 0 ]; |
|
| 38 | - $single_modifier[ 0 ] = $output; |
|
| 36 | + foreach ($parameter['modifierlist'] as $single_modifier) { |
|
| 37 | + $modifier = $single_modifier[0]; |
|
| 38 | + $single_modifier[0] = $output; |
|
| 39 | 39 | $params = implode(',', $single_modifier); |
| 40 | 40 | // check if we know already the type of modifier |
| 41 | - if (isset($compiler->known_modifier_type[ $modifier ])) { |
|
| 42 | - $modifier_types = array($compiler->known_modifier_type[ $modifier ]); |
|
| 41 | + if (isset($compiler->known_modifier_type[$modifier])) { |
|
| 42 | + $modifier_types = array($compiler->known_modifier_type[$modifier]); |
|
| 43 | 43 | } else { |
| 44 | 44 | $modifier_types = array(1, 2, 3, 4, 5, 6); |
| 45 | 45 | } |
@@ -47,30 +47,30 @@ discard block |
||
| 47 | 47 | switch ($type) { |
| 48 | 48 | case 1: |
| 49 | 49 | // registered modifier |
| 50 | - if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) { |
|
| 50 | + if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) { |
|
| 51 | 51 | $function = |
| 52 | - $compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ]; |
|
| 52 | + $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; |
|
| 53 | 53 | if (!is_array($function)) { |
| 54 | 54 | $output = "{$function}({$params})"; |
| 55 | 55 | } else { |
| 56 | - if (is_object($function[ 0 ])) { |
|
| 56 | + if (is_object($function[0])) { |
|
| 57 | 57 | $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . |
| 58 | - $modifier . '\'][0][0]->' . $function[ 1 ] . '(' . $params . ')'; |
|
| 58 | + $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; |
|
| 59 | 59 | } else { |
| 60 | - $output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')'; |
|
| 60 | + $output = $function[0] . '::' . $function[1] . '(' . $params . ')'; |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | - $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 63 | + $compiler->known_modifier_type[$modifier] = $type; |
|
| 64 | 64 | break 2; |
| 65 | 65 | } |
| 66 | 66 | break; |
| 67 | 67 | case 2: |
| 68 | 68 | // registered modifier compiler |
| 69 | - if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ])) { |
|
| 69 | + if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) { |
|
| 70 | 70 | $output = |
| 71 | - call_user_func($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ], |
|
| 71 | + call_user_func($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], |
|
| 72 | 72 | $single_modifier, $compiler->smarty); |
| 73 | - $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 73 | + $compiler->known_modifier_type[$modifier] = $type; |
|
| 74 | 74 | break 2; |
| 75 | 75 | } |
| 76 | 76 | break; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $plugin = 'smarty_modifiercompiler_' . $modifier; |
| 85 | 85 | $output = $plugin($single_modifier, $compiler); |
| 86 | 86 | } |
| 87 | - $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 87 | + $compiler->known_modifier_type[$modifier] = $type; |
|
| 88 | 88 | break 2; |
| 89 | 89 | } |
| 90 | 90 | break; |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | ) { |
| 98 | 98 | $output = "{$function}({$params})"; |
| 99 | 99 | } |
| 100 | - $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 100 | + $compiler->known_modifier_type[$modifier] = $type; |
|
| 101 | 101 | break 2; |
| 102 | 102 | } |
| 103 | 103 | break; |
@@ -110,17 +110,17 @@ discard block |
||
| 110 | 110 | ) { |
| 111 | 111 | $output = "{$modifier}({$params})"; |
| 112 | 112 | } |
| 113 | - $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 113 | + $compiler->known_modifier_type[$modifier] = $type; |
|
| 114 | 114 | break 2; |
| 115 | 115 | } |
| 116 | 116 | break; |
| 117 | 117 | case 6: |
| 118 | 118 | // default plugin handler |
| 119 | - if (isset($compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ]) || |
|
| 119 | + if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || |
|
| 120 | 120 | (is_callable($compiler->smarty->default_plugin_handler_func) && |
| 121 | 121 | $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER)) |
| 122 | 122 | ) { |
| 123 | - $function = $compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ]; |
|
| 123 | + $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; |
|
| 124 | 124 | // check if modifier allowed |
| 125 | 125 | if (!is_object($compiler->smarty->security_policy) || |
| 126 | 126 | $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) |
@@ -128,26 +128,26 @@ discard block |
||
| 128 | 128 | if (!is_array($function)) { |
| 129 | 129 | $output = "{$function}({$params})"; |
| 130 | 130 | } else { |
| 131 | - if (is_object($function[ 0 ])) { |
|
| 132 | - $output = $function[ 0 ] . '->'. $function[ 1 ] . '(' . $params . ')'; |
|
| 131 | + if (is_object($function[0])) { |
|
| 132 | + $output = $function[0] . '->' . $function[1] . '(' . $params . ')'; |
|
| 133 | 133 | } else { |
| 134 | - $output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')'; |
|
| 134 | + $output = $function[0] . '::' . $function[1] . '(' . $params . ')'; |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | - if (isset($compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) || |
|
| 139 | - isset($compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) |
|
| 138 | + if (isset($compiler->parent_compiler->template->compiled->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || |
|
| 139 | + isset($compiler->parent_compiler->template->compiled->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) |
|
| 140 | 140 | ) { |
| 141 | 141 | // was a plugin |
| 142 | - $compiler->known_modifier_type[ $modifier ] = 4; |
|
| 142 | + $compiler->known_modifier_type[$modifier] = 4; |
|
| 143 | 143 | } else { |
| 144 | - $compiler->known_modifier_type[ $modifier ] = $type; |
|
| 144 | + $compiler->known_modifier_type[$modifier] = $type; |
|
| 145 | 145 | } |
| 146 | 146 | break 2; |
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | - if (!isset($compiler->known_modifier_type[ $modifier ])) { |
|
| 150 | + if (!isset($compiler->known_modifier_type[$modifier])) { |
|
| 151 | 151 | $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", null, true); |
| 152 | 152 | } |
| 153 | 153 | } |
@@ -18,82 +18,82 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Smarty_Internal_Resource_Registered extends Smarty_Resource |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * populate Source Object with meta data from Resource |
|
| 23 | - * |
|
| 24 | - * @param Smarty_Template_Source $source source object |
|
| 25 | - * @param Smarty_Internal_Template $_template template object |
|
| 26 | - * |
|
| 27 | - * @return void |
|
| 28 | - */ |
|
| 29 | - public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) |
|
| 30 | - { |
|
| 31 | - $source->filepath = $source->type . ':' . $source->name; |
|
| 32 | - $source->uid = sha1($source->filepath . $source->smarty->_joined_template_dir); |
|
| 33 | - $source->timestamp = $this->getTemplateTimestamp($source); |
|
| 34 | - $source->exists = !!$source->timestamp; |
|
| 35 | - } |
|
| 21 | + /** |
|
| 22 | + * populate Source Object with meta data from Resource |
|
| 23 | + * |
|
| 24 | + * @param Smarty_Template_Source $source source object |
|
| 25 | + * @param Smarty_Internal_Template $_template template object |
|
| 26 | + * |
|
| 27 | + * @return void |
|
| 28 | + */ |
|
| 29 | + public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) |
|
| 30 | + { |
|
| 31 | + $source->filepath = $source->type . ':' . $source->name; |
|
| 32 | + $source->uid = sha1($source->filepath . $source->smarty->_joined_template_dir); |
|
| 33 | + $source->timestamp = $this->getTemplateTimestamp($source); |
|
| 34 | + $source->exists = !!$source->timestamp; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * populate Source Object with timestamp and exists from Resource |
|
| 39 | - * |
|
| 40 | - * @param Smarty_Template_Source $source source object |
|
| 41 | - * |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function populateTimestamp(Smarty_Template_Source $source) |
|
| 45 | - { |
|
| 46 | - $source->timestamp = $this->getTemplateTimestamp($source); |
|
| 47 | - $source->exists = !!$source->timestamp; |
|
| 48 | - } |
|
| 37 | + /** |
|
| 38 | + * populate Source Object with timestamp and exists from Resource |
|
| 39 | + * |
|
| 40 | + * @param Smarty_Template_Source $source source object |
|
| 41 | + * |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function populateTimestamp(Smarty_Template_Source $source) |
|
| 45 | + { |
|
| 46 | + $source->timestamp = $this->getTemplateTimestamp($source); |
|
| 47 | + $source->exists = !!$source->timestamp; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Get timestamp (epoch) the template source was modified |
|
| 52 | - * |
|
| 53 | - * @param Smarty_Template_Source $source source object |
|
| 54 | - * |
|
| 55 | - * @return integer|boolean timestamp (epoch) the template was modified, false if resources has no timestamp |
|
| 56 | - */ |
|
| 57 | - public function getTemplateTimestamp(Smarty_Template_Source $source) |
|
| 58 | - { |
|
| 59 | - // return timestamp |
|
| 60 | - $time_stamp = false; |
|
| 61 | - call_user_func_array($source->smarty->registered_resources[ $source->type ][ 0 ][ 1 ], |
|
| 62 | - array($source->name, &$time_stamp, $source->smarty)); |
|
| 50 | + /** |
|
| 51 | + * Get timestamp (epoch) the template source was modified |
|
| 52 | + * |
|
| 53 | + * @param Smarty_Template_Source $source source object |
|
| 54 | + * |
|
| 55 | + * @return integer|boolean timestamp (epoch) the template was modified, false if resources has no timestamp |
|
| 56 | + */ |
|
| 57 | + public function getTemplateTimestamp(Smarty_Template_Source $source) |
|
| 58 | + { |
|
| 59 | + // return timestamp |
|
| 60 | + $time_stamp = false; |
|
| 61 | + call_user_func_array($source->smarty->registered_resources[ $source->type ][ 0 ][ 1 ], |
|
| 62 | + array($source->name, &$time_stamp, $source->smarty)); |
|
| 63 | 63 | |
| 64 | - return is_numeric($time_stamp) ? (int) $time_stamp : $time_stamp; |
|
| 65 | - } |
|
| 64 | + return is_numeric($time_stamp) ? (int) $time_stamp : $time_stamp; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Load template's source by invoking the registered callback into current template object |
|
| 69 | - * |
|
| 70 | - * @param Smarty_Template_Source $source source object |
|
| 71 | - * |
|
| 72 | - * @return string template source |
|
| 73 | - * @throws SmartyException if source cannot be loaded |
|
| 74 | - */ |
|
| 75 | - public function getContent(Smarty_Template_Source $source) |
|
| 76 | - { |
|
| 77 | - // return template string |
|
| 78 | - $content = null; |
|
| 79 | - $t = call_user_func_array($source->smarty->registered_resources[ $source->type ][ 0 ][ 0 ], |
|
| 80 | - array($source->name, &$content, $source->smarty)); |
|
| 81 | - if (is_bool($t) && !$t) { |
|
| 82 | - throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); |
|
| 83 | - } |
|
| 67 | + /** |
|
| 68 | + * Load template's source by invoking the registered callback into current template object |
|
| 69 | + * |
|
| 70 | + * @param Smarty_Template_Source $source source object |
|
| 71 | + * |
|
| 72 | + * @return string template source |
|
| 73 | + * @throws SmartyException if source cannot be loaded |
|
| 74 | + */ |
|
| 75 | + public function getContent(Smarty_Template_Source $source) |
|
| 76 | + { |
|
| 77 | + // return template string |
|
| 78 | + $content = null; |
|
| 79 | + $t = call_user_func_array($source->smarty->registered_resources[ $source->type ][ 0 ][ 0 ], |
|
| 80 | + array($source->name, &$content, $source->smarty)); |
|
| 81 | + if (is_bool($t) && !$t) { |
|
| 82 | + throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - return $content; |
|
| 86 | - } |
|
| 85 | + return $content; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Determine basename for compiled filename |
|
| 90 | - * |
|
| 91 | - * @param Smarty_Template_Source $source source object |
|
| 92 | - * |
|
| 93 | - * @return string resource's basename |
|
| 94 | - */ |
|
| 95 | - public function getBasename(Smarty_Template_Source $source) |
|
| 96 | - { |
|
| 97 | - return basename($source->name); |
|
| 98 | - } |
|
| 88 | + /** |
|
| 89 | + * Determine basename for compiled filename |
|
| 90 | + * |
|
| 91 | + * @param Smarty_Template_Source $source source object |
|
| 92 | + * |
|
| 93 | + * @return string resource's basename |
|
| 94 | + */ |
|
| 95 | + public function getBasename(Smarty_Template_Source $source) |
|
| 96 | + { |
|
| 97 | + return basename($source->name); |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | { |
| 59 | 59 | // return timestamp |
| 60 | 60 | $time_stamp = false; |
| 61 | - call_user_func_array($source->smarty->registered_resources[ $source->type ][ 0 ][ 1 ], |
|
| 61 | + call_user_func_array($source->smarty->registered_resources[$source->type][0][1], |
|
| 62 | 62 | array($source->name, &$time_stamp, $source->smarty)); |
| 63 | 63 | |
| 64 | 64 | return is_numeric($time_stamp) ? (int) $time_stamp : $time_stamp; |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | { |
| 77 | 77 | // return template string |
| 78 | 78 | $content = null; |
| 79 | - $t = call_user_func_array($source->smarty->registered_resources[ $source->type ][ 0 ][ 0 ], |
|
| 79 | + $t = call_user_func_array($source->smarty->registered_resources[$source->type][0][0], |
|
| 80 | 80 | array($source->name, &$content, $source->smarty)); |
| 81 | 81 | if (is_bool($t) && !$t) { |
| 82 | 82 | throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); |
@@ -17,160 +17,160 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Smarty_Internal_Resource_File extends Smarty_Resource |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * build template filepath by traversing the template_dir array |
|
| 22 | - * |
|
| 23 | - * @param Smarty_Template_Source $source source object |
|
| 24 | - * @param Smarty_Internal_Template $_template template object |
|
| 25 | - * |
|
| 26 | - * @return string fully qualified filepath |
|
| 27 | - * @throws SmartyException |
|
| 28 | - */ |
|
| 29 | - protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) |
|
| 30 | - { |
|
| 31 | - $file = $source->name; |
|
| 32 | - // absolute file ? |
|
| 33 | - if ($file[ 0 ] == '/' || $file[ 1 ] == ':') { |
|
| 34 | - $file = $source->smarty->_realpath($file, true); |
|
| 35 | - return is_file($file) ? $file : false; |
|
| 36 | - } |
|
| 37 | - // go relative to a given template? |
|
| 38 | - if ($file[ 0 ] == '.' && $_template && isset($_template->parent) && $_template->parent->_objType == 2 && |
|
| 39 | - preg_match('#^[.]{1,2}[\\\/]#', $file) |
|
| 40 | - ) { |
|
| 41 | - if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && |
|
| 42 | - !isset($_template->parent->_cache[ 'allow_relative_path' ]) |
|
| 43 | - ) { |
|
| 44 | - throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); |
|
| 45 | - } |
|
| 46 | - // normalize path |
|
| 47 | - $path = $source->smarty->_realpath(dirname($_template->parent->source->filepath) . DS . $file); |
|
| 48 | - // files relative to a template only get one shot |
|
| 49 | - return is_file($path) ? $path : false; |
|
| 50 | - } |
|
| 51 | - // normalize DS |
|
| 52 | - if (strpos($file, DS == '/' ? '\\' : '/') !== false) { |
|
| 53 | - $file = str_replace(DS == '/' ? '\\' : '/', DS, $file); |
|
| 54 | - } |
|
| 20 | + /** |
|
| 21 | + * build template filepath by traversing the template_dir array |
|
| 22 | + * |
|
| 23 | + * @param Smarty_Template_Source $source source object |
|
| 24 | + * @param Smarty_Internal_Template $_template template object |
|
| 25 | + * |
|
| 26 | + * @return string fully qualified filepath |
|
| 27 | + * @throws SmartyException |
|
| 28 | + */ |
|
| 29 | + protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) |
|
| 30 | + { |
|
| 31 | + $file = $source->name; |
|
| 32 | + // absolute file ? |
|
| 33 | + if ($file[ 0 ] == '/' || $file[ 1 ] == ':') { |
|
| 34 | + $file = $source->smarty->_realpath($file, true); |
|
| 35 | + return is_file($file) ? $file : false; |
|
| 36 | + } |
|
| 37 | + // go relative to a given template? |
|
| 38 | + if ($file[ 0 ] == '.' && $_template && isset($_template->parent) && $_template->parent->_objType == 2 && |
|
| 39 | + preg_match('#^[.]{1,2}[\\\/]#', $file) |
|
| 40 | + ) { |
|
| 41 | + if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && |
|
| 42 | + !isset($_template->parent->_cache[ 'allow_relative_path' ]) |
|
| 43 | + ) { |
|
| 44 | + throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); |
|
| 45 | + } |
|
| 46 | + // normalize path |
|
| 47 | + $path = $source->smarty->_realpath(dirname($_template->parent->source->filepath) . DS . $file); |
|
| 48 | + // files relative to a template only get one shot |
|
| 49 | + return is_file($path) ? $path : false; |
|
| 50 | + } |
|
| 51 | + // normalize DS |
|
| 52 | + if (strpos($file, DS == '/' ? '\\' : '/') !== false) { |
|
| 53 | + $file = str_replace(DS == '/' ? '\\' : '/', DS, $file); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $_directories = $source->smarty->getTemplateDir(null, $source->isConfig); |
|
| 57 | - // template_dir index? |
|
| 58 | - if ($file[ 0 ] == '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) { |
|
| 59 | - $file = $fileMatch[ 2 ]; |
|
| 60 | - $_indices = explode(',', $fileMatch[ 1 ]); |
|
| 61 | - $_index_dirs = array(); |
|
| 62 | - foreach ($_indices as $index) { |
|
| 63 | - $index = trim($index); |
|
| 64 | - // try string indexes |
|
| 65 | - if (isset($_directories[ $index ])) { |
|
| 66 | - $_index_dirs[] = $_directories[ $index ]; |
|
| 67 | - } elseif (is_numeric($index)) { |
|
| 68 | - // try numeric index |
|
| 69 | - $index = (int) $index; |
|
| 70 | - if (isset($_directories[ $index ])) { |
|
| 71 | - $_index_dirs[] = $_directories[ $index ]; |
|
| 72 | - } else { |
|
| 73 | - // try at location index |
|
| 74 | - $keys = array_keys($_directories); |
|
| 75 | - if (isset($_directories[ $keys[ $index ] ])) { |
|
| 76 | - $_index_dirs[] = $_directories[ $keys[ $index ] ]; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - if (empty($_index_dirs)) { |
|
| 82 | - // index not found |
|
| 83 | - return false; |
|
| 84 | - } else { |
|
| 85 | - $_directories = $_index_dirs; |
|
| 86 | - } |
|
| 87 | - } |
|
| 56 | + $_directories = $source->smarty->getTemplateDir(null, $source->isConfig); |
|
| 57 | + // template_dir index? |
|
| 58 | + if ($file[ 0 ] == '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) { |
|
| 59 | + $file = $fileMatch[ 2 ]; |
|
| 60 | + $_indices = explode(',', $fileMatch[ 1 ]); |
|
| 61 | + $_index_dirs = array(); |
|
| 62 | + foreach ($_indices as $index) { |
|
| 63 | + $index = trim($index); |
|
| 64 | + // try string indexes |
|
| 65 | + if (isset($_directories[ $index ])) { |
|
| 66 | + $_index_dirs[] = $_directories[ $index ]; |
|
| 67 | + } elseif (is_numeric($index)) { |
|
| 68 | + // try numeric index |
|
| 69 | + $index = (int) $index; |
|
| 70 | + if (isset($_directories[ $index ])) { |
|
| 71 | + $_index_dirs[] = $_directories[ $index ]; |
|
| 72 | + } else { |
|
| 73 | + // try at location index |
|
| 74 | + $keys = array_keys($_directories); |
|
| 75 | + if (isset($_directories[ $keys[ $index ] ])) { |
|
| 76 | + $_index_dirs[] = $_directories[ $keys[ $index ] ]; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + if (empty($_index_dirs)) { |
|
| 82 | + // index not found |
|
| 83 | + return false; |
|
| 84 | + } else { |
|
| 85 | + $_directories = $_index_dirs; |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - // relative file name? |
|
| 90 | - foreach ($_directories as $_directory) { |
|
| 91 | - $path = $_directory . $file; |
|
| 92 | - if (is_file($path)) { |
|
| 93 | - return (strpos($path, '.' . DS) !== false) ? $source->smarty->_realpath($path) : $path; |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - if (!isset($_index_dirs)) { |
|
| 97 | - // Could be relative to cwd |
|
| 98 | - $path = $source->smarty->_realpath($file, true); |
|
| 99 | - if (is_file($path)) { |
|
| 100 | - return $path; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - // Use include path ? |
|
| 104 | - if ($source->smarty->use_include_path) { |
|
| 105 | - return $source->smarty->ext->_getIncludePath->getIncludePath($_directories, $file, $source->smarty); |
|
| 106 | - } |
|
| 107 | - return false; |
|
| 108 | - } |
|
| 89 | + // relative file name? |
|
| 90 | + foreach ($_directories as $_directory) { |
|
| 91 | + $path = $_directory . $file; |
|
| 92 | + if (is_file($path)) { |
|
| 93 | + return (strpos($path, '.' . DS) !== false) ? $source->smarty->_realpath($path) : $path; |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + if (!isset($_index_dirs)) { |
|
| 97 | + // Could be relative to cwd |
|
| 98 | + $path = $source->smarty->_realpath($file, true); |
|
| 99 | + if (is_file($path)) { |
|
| 100 | + return $path; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + // Use include path ? |
|
| 104 | + if ($source->smarty->use_include_path) { |
|
| 105 | + return $source->smarty->ext->_getIncludePath->getIncludePath($_directories, $file, $source->smarty); |
|
| 106 | + } |
|
| 107 | + return false; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * populate Source Object with meta data from Resource |
|
| 112 | - * |
|
| 113 | - * @param Smarty_Template_Source $source source object |
|
| 114 | - * @param Smarty_Internal_Template $_template template object |
|
| 115 | - */ |
|
| 116 | - public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) |
|
| 117 | - { |
|
| 118 | - $source->filepath = $this->buildFilepath($source, $_template); |
|
| 110 | + /** |
|
| 111 | + * populate Source Object with meta data from Resource |
|
| 112 | + * |
|
| 113 | + * @param Smarty_Template_Source $source source object |
|
| 114 | + * @param Smarty_Internal_Template $_template template object |
|
| 115 | + */ |
|
| 116 | + public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) |
|
| 117 | + { |
|
| 118 | + $source->filepath = $this->buildFilepath($source, $_template); |
|
| 119 | 119 | |
| 120 | - if ($source->filepath !== false) { |
|
| 121 | - if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) { |
|
| 122 | - $source->smarty->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig); |
|
| 123 | - } |
|
| 124 | - $source->exists = true; |
|
| 125 | - $source->uid = sha1($source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir : |
|
| 126 | - $source->smarty->_joined_template_dir)); |
|
| 127 | - $source->timestamp = filemtime($source->filepath); |
|
| 128 | - } else { |
|
| 129 | - $source->timestamp = $source->exists = false; |
|
| 130 | - } |
|
| 131 | - } |
|
| 120 | + if ($source->filepath !== false) { |
|
| 121 | + if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) { |
|
| 122 | + $source->smarty->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig); |
|
| 123 | + } |
|
| 124 | + $source->exists = true; |
|
| 125 | + $source->uid = sha1($source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir : |
|
| 126 | + $source->smarty->_joined_template_dir)); |
|
| 127 | + $source->timestamp = filemtime($source->filepath); |
|
| 128 | + } else { |
|
| 129 | + $source->timestamp = $source->exists = false; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * populate Source Object with timestamp and exists from Resource |
|
| 135 | - * |
|
| 136 | - * @param Smarty_Template_Source $source source object |
|
| 137 | - */ |
|
| 138 | - public function populateTimestamp(Smarty_Template_Source $source) |
|
| 139 | - { |
|
| 140 | - if (!$source->exists) { |
|
| 141 | - $source->timestamp = $source->exists = is_file($source->filepath); |
|
| 142 | - } |
|
| 143 | - if ($source->exists) { |
|
| 144 | - $source->timestamp = filemtime($source->filepath); |
|
| 145 | - } |
|
| 146 | - } |
|
| 133 | + /** |
|
| 134 | + * populate Source Object with timestamp and exists from Resource |
|
| 135 | + * |
|
| 136 | + * @param Smarty_Template_Source $source source object |
|
| 137 | + */ |
|
| 138 | + public function populateTimestamp(Smarty_Template_Source $source) |
|
| 139 | + { |
|
| 140 | + if (!$source->exists) { |
|
| 141 | + $source->timestamp = $source->exists = is_file($source->filepath); |
|
| 142 | + } |
|
| 143 | + if ($source->exists) { |
|
| 144 | + $source->timestamp = filemtime($source->filepath); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Load template's source from file into current template object |
|
| 150 | - * |
|
| 151 | - * @param Smarty_Template_Source $source source object |
|
| 152 | - * |
|
| 153 | - * @return string template source |
|
| 154 | - * @throws SmartyException if source cannot be loaded |
|
| 155 | - */ |
|
| 156 | - public function getContent(Smarty_Template_Source $source) |
|
| 157 | - { |
|
| 158 | - if ($source->exists) { |
|
| 159 | - return file_get_contents($source->filepath); |
|
| 160 | - } |
|
| 161 | - throw new SmartyException('Unable to read ' . ($source->isConfig ? 'config' : 'template') . |
|
| 162 | - " {$source->type} '{$source->name}'"); |
|
| 163 | - } |
|
| 148 | + /** |
|
| 149 | + * Load template's source from file into current template object |
|
| 150 | + * |
|
| 151 | + * @param Smarty_Template_Source $source source object |
|
| 152 | + * |
|
| 153 | + * @return string template source |
|
| 154 | + * @throws SmartyException if source cannot be loaded |
|
| 155 | + */ |
|
| 156 | + public function getContent(Smarty_Template_Source $source) |
|
| 157 | + { |
|
| 158 | + if ($source->exists) { |
|
| 159 | + return file_get_contents($source->filepath); |
|
| 160 | + } |
|
| 161 | + throw new SmartyException('Unable to read ' . ($source->isConfig ? 'config' : 'template') . |
|
| 162 | + " {$source->type} '{$source->name}'"); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Determine basename for compiled filename |
|
| 167 | - * |
|
| 168 | - * @param Smarty_Template_Source $source source object |
|
| 169 | - * |
|
| 170 | - * @return string resource's basename |
|
| 171 | - */ |
|
| 172 | - public function getBasename(Smarty_Template_Source $source) |
|
| 173 | - { |
|
| 174 | - return basename($source->filepath); |
|
| 175 | - } |
|
| 165 | + /** |
|
| 166 | + * Determine basename for compiled filename |
|
| 167 | + * |
|
| 168 | + * @param Smarty_Template_Source $source source object |
|
| 169 | + * |
|
| 170 | + * @return string resource's basename |
|
| 171 | + */ |
|
| 172 | + public function getBasename(Smarty_Template_Source $source) |
|
| 173 | + { |
|
| 174 | + return basename($source->filepath); |
|
| 175 | + } |
|
| 176 | 176 | } |
@@ -30,16 +30,16 @@ discard block |
||
| 30 | 30 | { |
| 31 | 31 | $file = $source->name; |
| 32 | 32 | // absolute file ? |
| 33 | - if ($file[ 0 ] == '/' || $file[ 1 ] == ':') { |
|
| 33 | + if ($file[0] == '/' || $file[1] == ':') { |
|
| 34 | 34 | $file = $source->smarty->_realpath($file, true); |
| 35 | 35 | return is_file($file) ? $file : false; |
| 36 | 36 | } |
| 37 | 37 | // go relative to a given template? |
| 38 | - if ($file[ 0 ] == '.' && $_template && isset($_template->parent) && $_template->parent->_objType == 2 && |
|
| 38 | + if ($file[0] == '.' && $_template && isset($_template->parent) && $_template->parent->_objType == 2 && |
|
| 39 | 39 | preg_match('#^[.]{1,2}[\\\/]#', $file) |
| 40 | 40 | ) { |
| 41 | 41 | if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && |
| 42 | - !isset($_template->parent->_cache[ 'allow_relative_path' ]) |
|
| 42 | + !isset($_template->parent->_cache['allow_relative_path']) |
|
| 43 | 43 | ) { |
| 44 | 44 | throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); |
| 45 | 45 | } |
@@ -55,25 +55,25 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | $_directories = $source->smarty->getTemplateDir(null, $source->isConfig); |
| 57 | 57 | // template_dir index? |
| 58 | - if ($file[ 0 ] == '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) { |
|
| 59 | - $file = $fileMatch[ 2 ]; |
|
| 60 | - $_indices = explode(',', $fileMatch[ 1 ]); |
|
| 58 | + if ($file[0] == '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) { |
|
| 59 | + $file = $fileMatch[2]; |
|
| 60 | + $_indices = explode(',', $fileMatch[1]); |
|
| 61 | 61 | $_index_dirs = array(); |
| 62 | 62 | foreach ($_indices as $index) { |
| 63 | 63 | $index = trim($index); |
| 64 | 64 | // try string indexes |
| 65 | - if (isset($_directories[ $index ])) { |
|
| 66 | - $_index_dirs[] = $_directories[ $index ]; |
|
| 65 | + if (isset($_directories[$index])) { |
|
| 66 | + $_index_dirs[] = $_directories[$index]; |
|
| 67 | 67 | } elseif (is_numeric($index)) { |
| 68 | 68 | // try numeric index |
| 69 | 69 | $index = (int) $index; |
| 70 | - if (isset($_directories[ $index ])) { |
|
| 71 | - $_index_dirs[] = $_directories[ $index ]; |
|
| 70 | + if (isset($_directories[$index])) { |
|
| 71 | + $_index_dirs[] = $_directories[$index]; |
|
| 72 | 72 | } else { |
| 73 | 73 | // try at location index |
| 74 | 74 | $keys = array_keys($_directories); |
| 75 | - if (isset($_directories[ $keys[ $index ] ])) { |
|
| 76 | - $_index_dirs[] = $_directories[ $keys[ $index ] ]; |
|
| 75 | + if (isset($_directories[$keys[$index]])) { |
|
| 76 | + $_index_dirs[] = $_directories[$keys[$index]]; |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | } |
@@ -122,8 +122,7 @@ discard block |
||
| 122 | 122 | $source->smarty->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig); |
| 123 | 123 | } |
| 124 | 124 | $source->exists = true; |
| 125 | - $source->uid = sha1($source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir : |
|
| 126 | - $source->smarty->_joined_template_dir)); |
|
| 125 | + $source->uid = sha1($source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir : $source->smarty->_joined_template_dir)); |
|
| 127 | 126 | $source->timestamp = filemtime($source->filepath); |
| 128 | 127 | } else { |
| 129 | 128 | $source->timestamp = $source->exists = false; |