@@ -11,32 +11,32 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Smarty_Internal_Method_RegisterDefaultConfigHandler |
| 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 | - * Register config default handler |
|
| 23 | - * |
|
| 24 | - * @api Smarty::registerDefaultConfigHandler() |
|
| 25 | - * |
|
| 26 | - * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 27 | - * @param callable $callback class/method name |
|
| 28 | - * |
|
| 29 | - * @return \Smarty|\Smarty_Internal_Template |
|
| 30 | - * @throws SmartyException if $callback is not callable |
|
| 31 | - */ |
|
| 32 | - public function registerDefaultConfigHandler(Smarty_Internal_TemplateBase $obj, $callback) |
|
| 33 | - { |
|
| 34 | - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 35 | - if (is_callable($callback)) { |
|
| 36 | - $smarty->default_config_handler_func = $callback; |
|
| 37 | - } else { |
|
| 38 | - throw new SmartyException("Default config handler not callable"); |
|
| 39 | - } |
|
| 40 | - return $obj; |
|
| 41 | - } |
|
| 21 | + /** |
|
| 22 | + * Register config default handler |
|
| 23 | + * |
|
| 24 | + * @api Smarty::registerDefaultConfigHandler() |
|
| 25 | + * |
|
| 26 | + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 27 | + * @param callable $callback class/method name |
|
| 28 | + * |
|
| 29 | + * @return \Smarty|\Smarty_Internal_Template |
|
| 30 | + * @throws SmartyException if $callback is not callable |
|
| 31 | + */ |
|
| 32 | + public function registerDefaultConfigHandler(Smarty_Internal_TemplateBase $obj, $callback) |
|
| 33 | + { |
|
| 34 | + $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 35 | + if (is_callable($callback)) { |
|
| 36 | + $smarty->default_config_handler_func = $callback; |
|
| 37 | + } else { |
|
| 38 | + throw new SmartyException("Default config handler not callable"); |
|
| 39 | + } |
|
| 40 | + return $obj; |
|
| 41 | + } |
|
| 42 | 42 | } |
| 43 | 43 | \ No newline at end of file |
@@ -11,31 +11,31 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Smarty_Internal_Method_SetDebugTemplate |
| 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 | - * set the debug template |
|
| 23 | - * |
|
| 24 | - * @api Smarty::setDebugTemplate() |
|
| 25 | - * |
|
| 26 | - * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 27 | - * @param string $tpl_name |
|
| 28 | - * |
|
| 29 | - * @return \Smarty|\Smarty_Internal_Template |
|
| 30 | - * @throws SmartyException if file is not readable |
|
| 31 | - */ |
|
| 32 | - public function setDebugTemplate(Smarty_Internal_TemplateBase $obj, $tpl_name) |
|
| 33 | - { |
|
| 34 | - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 35 | - if (!is_readable($tpl_name)) { |
|
| 36 | - throw new SmartyException("Unknown file '{$tpl_name}'"); |
|
| 37 | - } |
|
| 38 | - $smarty->debug_tpl = $tpl_name; |
|
| 39 | - return $obj; |
|
| 40 | - } |
|
| 21 | + /** |
|
| 22 | + * set the debug template |
|
| 23 | + * |
|
| 24 | + * @api Smarty::setDebugTemplate() |
|
| 25 | + * |
|
| 26 | + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 27 | + * @param string $tpl_name |
|
| 28 | + * |
|
| 29 | + * @return \Smarty|\Smarty_Internal_Template |
|
| 30 | + * @throws SmartyException if file is not readable |
|
| 31 | + */ |
|
| 32 | + public function setDebugTemplate(Smarty_Internal_TemplateBase $obj, $tpl_name) |
|
| 33 | + { |
|
| 34 | + $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 35 | + if (!is_readable($tpl_name)) { |
|
| 36 | + throw new SmartyException("Unknown file '{$tpl_name}'"); |
|
| 37 | + } |
|
| 38 | + $smarty->debug_tpl = $tpl_name; |
|
| 39 | + return $obj; |
|
| 40 | + } |
|
| 41 | 41 | } |
| 42 | 42 | \ No newline at end of file |
@@ -11,34 +11,34 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Smarty_Internal_Method_RegisterResource |
| 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::registerResource() |
|
| 25 | - * @link http://www.smarty.net/docs/en/api.register.resource.tpl |
|
| 26 | - * |
|
| 27 | - * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 28 | - * @param string $name name of resource type |
|
| 29 | - * @param Smarty_Resource|array $resource_handler or instance of |
|
| 30 | - * Smarty_Resource, or |
|
| 31 | - * array of callbacks to |
|
| 32 | - * handle resource |
|
| 33 | - * (deprecated) |
|
| 34 | - * |
|
| 35 | - * @return \Smarty|\Smarty_Internal_Template |
|
| 36 | - */ |
|
| 37 | - public function registerResource(Smarty_Internal_TemplateBase $obj, $name, $resource_handler) |
|
| 38 | - { |
|
| 39 | - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 40 | - $smarty->registered_resources[ $name ] = |
|
| 41 | - $resource_handler instanceof Smarty_Resource ? $resource_handler : array($resource_handler, false); |
|
| 42 | - return $obj; |
|
| 43 | - } |
|
| 21 | + /** |
|
| 22 | + * Registers a resource to fetch a template |
|
| 23 | + * |
|
| 24 | + * @api Smarty::registerResource() |
|
| 25 | + * @link http://www.smarty.net/docs/en/api.register.resource.tpl |
|
| 26 | + * |
|
| 27 | + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 28 | + * @param string $name name of resource type |
|
| 29 | + * @param Smarty_Resource|array $resource_handler or instance of |
|
| 30 | + * Smarty_Resource, or |
|
| 31 | + * array of callbacks to |
|
| 32 | + * handle resource |
|
| 33 | + * (deprecated) |
|
| 34 | + * |
|
| 35 | + * @return \Smarty|\Smarty_Internal_Template |
|
| 36 | + */ |
|
| 37 | + public function registerResource(Smarty_Internal_TemplateBase $obj, $name, $resource_handler) |
|
| 38 | + { |
|
| 39 | + $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 40 | + $smarty->registered_resources[ $name ] = |
|
| 41 | + $resource_handler instanceof Smarty_Resource ? $resource_handler : array($resource_handler, false); |
|
| 42 | + return $obj; |
|
| 43 | + } |
|
| 44 | 44 | } |
| 45 | 45 | \ No newline at end of file |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | public function registerResource(Smarty_Internal_TemplateBase $obj, $name, $resource_handler) |
| 38 | 38 | { |
| 39 | 39 | $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
| 40 | - $smarty->registered_resources[ $name ] = |
|
| 40 | + $smarty->registered_resources[$name] = |
|
| 41 | 41 | $resource_handler instanceof Smarty_Resource ? $resource_handler : array($resource_handler, false); |
| 42 | 42 | return $obj; |
| 43 | 43 | } |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | } else { |
| 45 | 45 | $handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[2]); |
| 46 | 46 | if ($handler->checkTimestamps()) { |
| 47 | - $source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]); |
|
| 47 | + $source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[0]); |
|
| 48 | 48 | $mtime = $source->getTimeStamp(); |
| 49 | 49 | } else { |
| 50 | 50 | continue; |
@@ -10,75 +10,75 @@ |
||
| 10 | 10 | **/ |
| 11 | 11 | class Smarty_Internal_Runtime_ValidateCompiled |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * This function is executed automatically when a compiled or cached template file is included |
|
| 15 | - * - Decode saved properties from compiled template and cache files |
|
| 16 | - * - Check if compiled or cache file is valid |
|
| 17 | - * |
|
| 18 | - * @param array $properties special template properties |
|
| 19 | - * @param bool $cache flag if called from cache file |
|
| 20 | - * |
|
| 21 | - * @return bool flag if compiled or cache file is valid |
|
| 22 | - */ |
|
| 23 | - public function decodeProperties(Smarty_Internal_Template $tpl, $properties, $cache = false) |
|
| 24 | - { |
|
| 25 | - $is_valid = true; |
|
| 26 | - if (Smarty::SMARTY_VERSION != $properties['version']) { |
|
| 27 | - // new version must rebuild |
|
| 28 | - $is_valid = false; |
|
| 29 | - } elseif ($is_valid && !empty($properties['file_dependency']) && |
|
| 30 | - ((!$cache && $tpl->smarty->compile_check) || $tpl->smarty->compile_check == 1) |
|
| 31 | - ) { |
|
| 32 | - // check file dependencies at compiled code |
|
| 33 | - foreach ($properties['file_dependency'] as $_file_to_check) { |
|
| 34 | - if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') { |
|
| 35 | - if ($tpl->source->filepath == $_file_to_check[0]) { |
|
| 36 | - // do not recheck current template |
|
| 37 | - continue; |
|
| 38 | - } else { |
|
| 39 | - // file and php types can be checked without loading the respective resource handlers |
|
| 40 | - $mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false; |
|
| 41 | - } |
|
| 42 | - } elseif ($_file_to_check[2] == 'string') { |
|
| 43 | - continue; |
|
| 44 | - } else { |
|
| 45 | - $handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[2]); |
|
| 46 | - if ($handler->checkTimestamps()) { |
|
| 47 | - $source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]); |
|
| 48 | - $mtime = $source->getTimeStamp(); |
|
| 49 | - } else { |
|
| 50 | - continue; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - if (!$mtime || $mtime > $_file_to_check[1]) { |
|
| 54 | - $is_valid = false; |
|
| 55 | - break; |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - if ($cache) { |
|
| 60 | - // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc |
|
| 61 | - if ($tpl->caching === Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0 && |
|
| 62 | - (time() > ($tpl->cached->timestamp + $properties['cache_lifetime'])) |
|
| 63 | - ) { |
|
| 64 | - $is_valid = false; |
|
| 65 | - } |
|
| 66 | - $tpl->cached->cache_lifetime = $properties['cache_lifetime']; |
|
| 67 | - $tpl->cached->valid = $is_valid; |
|
| 68 | - $resource = $tpl->cached; |
|
| 69 | - } else { |
|
| 70 | - $tpl->mustCompile = !$is_valid; |
|
| 71 | - $resource = $tpl->compiled; |
|
| 72 | - $resource->includes = isset($properties['includes']) ? $properties['includes'] : array(); |
|
| 73 | - } |
|
| 74 | - if ($is_valid) { |
|
| 75 | - $resource->unifunc = $properties['unifunc']; |
|
| 76 | - $resource->has_nocache_code = $properties['has_nocache_code']; |
|
| 77 | - $resource->file_dependency = $properties['file_dependency']; |
|
| 78 | - if (isset($properties['tpl_function'])) { |
|
| 79 | - $tpl->tpl_function = $properties['tpl_function']; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - return $is_valid && !function_exists($properties['unifunc']); |
|
| 83 | - } |
|
| 13 | + /** |
|
| 14 | + * This function is executed automatically when a compiled or cached template file is included |
|
| 15 | + * - Decode saved properties from compiled template and cache files |
|
| 16 | + * - Check if compiled or cache file is valid |
|
| 17 | + * |
|
| 18 | + * @param array $properties special template properties |
|
| 19 | + * @param bool $cache flag if called from cache file |
|
| 20 | + * |
|
| 21 | + * @return bool flag if compiled or cache file is valid |
|
| 22 | + */ |
|
| 23 | + public function decodeProperties(Smarty_Internal_Template $tpl, $properties, $cache = false) |
|
| 24 | + { |
|
| 25 | + $is_valid = true; |
|
| 26 | + if (Smarty::SMARTY_VERSION != $properties['version']) { |
|
| 27 | + // new version must rebuild |
|
| 28 | + $is_valid = false; |
|
| 29 | + } elseif ($is_valid && !empty($properties['file_dependency']) && |
|
| 30 | + ((!$cache && $tpl->smarty->compile_check) || $tpl->smarty->compile_check == 1) |
|
| 31 | + ) { |
|
| 32 | + // check file dependencies at compiled code |
|
| 33 | + foreach ($properties['file_dependency'] as $_file_to_check) { |
|
| 34 | + if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') { |
|
| 35 | + if ($tpl->source->filepath == $_file_to_check[0]) { |
|
| 36 | + // do not recheck current template |
|
| 37 | + continue; |
|
| 38 | + } else { |
|
| 39 | + // file and php types can be checked without loading the respective resource handlers |
|
| 40 | + $mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false; |
|
| 41 | + } |
|
| 42 | + } elseif ($_file_to_check[2] == 'string') { |
|
| 43 | + continue; |
|
| 44 | + } else { |
|
| 45 | + $handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[2]); |
|
| 46 | + if ($handler->checkTimestamps()) { |
|
| 47 | + $source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]); |
|
| 48 | + $mtime = $source->getTimeStamp(); |
|
| 49 | + } else { |
|
| 50 | + continue; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + if (!$mtime || $mtime > $_file_to_check[1]) { |
|
| 54 | + $is_valid = false; |
|
| 55 | + break; |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + if ($cache) { |
|
| 60 | + // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc |
|
| 61 | + if ($tpl->caching === Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0 && |
|
| 62 | + (time() > ($tpl->cached->timestamp + $properties['cache_lifetime'])) |
|
| 63 | + ) { |
|
| 64 | + $is_valid = false; |
|
| 65 | + } |
|
| 66 | + $tpl->cached->cache_lifetime = $properties['cache_lifetime']; |
|
| 67 | + $tpl->cached->valid = $is_valid; |
|
| 68 | + $resource = $tpl->cached; |
|
| 69 | + } else { |
|
| 70 | + $tpl->mustCompile = !$is_valid; |
|
| 71 | + $resource = $tpl->compiled; |
|
| 72 | + $resource->includes = isset($properties['includes']) ? $properties['includes'] : array(); |
|
| 73 | + } |
|
| 74 | + if ($is_valid) { |
|
| 75 | + $resource->unifunc = $properties['unifunc']; |
|
| 76 | + $resource->has_nocache_code = $properties['has_nocache_code']; |
|
| 77 | + $resource->file_dependency = $properties['file_dependency']; |
|
| 78 | + if (isset($properties['tpl_function'])) { |
|
| 79 | + $tpl->tpl_function = $properties['tpl_function']; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + return $is_valid && !function_exists($properties['unifunc']); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -11,62 +11,62 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Smarty_Internal_Method_RegisterObject |
| 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 object to be used in templates |
|
| 23 | - * |
|
| 24 | - * @api Smarty::registerObject() |
|
| 25 | - * @link http://www.smarty.net/docs/en/api.register.object.tpl |
|
| 26 | - * |
|
| 27 | - * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 28 | - * @param string $object_name |
|
| 29 | - * @param object $object the |
|
| 30 | - * referenced |
|
| 31 | - * PHP object to |
|
| 32 | - * register |
|
| 33 | - * @param array $allowed_methods_properties list of |
|
| 34 | - * allowed |
|
| 35 | - * methods |
|
| 36 | - * (empty = all) |
|
| 37 | - * @param bool $format smarty |
|
| 38 | - * argument |
|
| 39 | - * format, else |
|
| 40 | - * traditional |
|
| 41 | - * @param array $block_methods list of |
|
| 42 | - * block-methods |
|
| 43 | - * |
|
| 44 | - * @return \Smarty|\Smarty_Internal_Template |
|
| 45 | - * @throws \SmartyException |
|
| 46 | - */ |
|
| 47 | - public function registerObject(Smarty_Internal_TemplateBase $obj, $object_name, $object, |
|
| 48 | - $allowed_methods_properties = array(), $format = true, $block_methods = array()) |
|
| 49 | - { |
|
| 50 | - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 51 | - // test if allowed methods callable |
|
| 52 | - if (!empty($allowed_methods_properties)) { |
|
| 53 | - foreach ((array) $allowed_methods_properties as $method) { |
|
| 54 | - if (!is_callable(array($object, $method)) && !property_exists($object, $method)) { |
|
| 55 | - throw new SmartyException("Undefined method or property '$method' in registered object"); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - // test if block methods callable |
|
| 60 | - if (!empty($block_methods)) { |
|
| 61 | - foreach ((array) $block_methods as $method) { |
|
| 62 | - if (!is_callable(array($object, $method))) { |
|
| 63 | - throw new SmartyException("Undefined method '$method' in registered object"); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - // register the object |
|
| 68 | - $smarty->registered_objects[ $object_name ] = |
|
| 69 | - array($object, (array) $allowed_methods_properties, (boolean) $format, (array) $block_methods); |
|
| 70 | - return $obj; |
|
| 71 | - } |
|
| 21 | + /** |
|
| 22 | + * Registers object to be used in templates |
|
| 23 | + * |
|
| 24 | + * @api Smarty::registerObject() |
|
| 25 | + * @link http://www.smarty.net/docs/en/api.register.object.tpl |
|
| 26 | + * |
|
| 27 | + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 28 | + * @param string $object_name |
|
| 29 | + * @param object $object the |
|
| 30 | + * referenced |
|
| 31 | + * PHP object to |
|
| 32 | + * register |
|
| 33 | + * @param array $allowed_methods_properties list of |
|
| 34 | + * allowed |
|
| 35 | + * methods |
|
| 36 | + * (empty = all) |
|
| 37 | + * @param bool $format smarty |
|
| 38 | + * argument |
|
| 39 | + * format, else |
|
| 40 | + * traditional |
|
| 41 | + * @param array $block_methods list of |
|
| 42 | + * block-methods |
|
| 43 | + * |
|
| 44 | + * @return \Smarty|\Smarty_Internal_Template |
|
| 45 | + * @throws \SmartyException |
|
| 46 | + */ |
|
| 47 | + public function registerObject(Smarty_Internal_TemplateBase $obj, $object_name, $object, |
|
| 48 | + $allowed_methods_properties = array(), $format = true, $block_methods = array()) |
|
| 49 | + { |
|
| 50 | + $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 51 | + // test if allowed methods callable |
|
| 52 | + if (!empty($allowed_methods_properties)) { |
|
| 53 | + foreach ((array) $allowed_methods_properties as $method) { |
|
| 54 | + if (!is_callable(array($object, $method)) && !property_exists($object, $method)) { |
|
| 55 | + throw new SmartyException("Undefined method or property '$method' in registered object"); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + // test if block methods callable |
|
| 60 | + if (!empty($block_methods)) { |
|
| 61 | + foreach ((array) $block_methods as $method) { |
|
| 62 | + if (!is_callable(array($object, $method))) { |
|
| 63 | + throw new SmartyException("Undefined method '$method' in registered object"); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + // register the object |
|
| 68 | + $smarty->registered_objects[ $object_name ] = |
|
| 69 | + array($object, (array) $allowed_methods_properties, (boolean) $format, (array) $block_methods); |
|
| 70 | + return $obj; |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | \ No newline at end of file |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | // register the object |
| 68 | - $smarty->registered_objects[ $object_name ] = |
|
| 68 | + $smarty->registered_objects[$object_name] = |
|
| 69 | 69 | array($object, (array) $allowed_methods_properties, (boolean) $format, (array) $block_methods); |
| 70 | 70 | return $obj; |
| 71 | 71 | } |
@@ -10,24 +10,24 @@ |
||
| 10 | 10 | **/ |
| 11 | 11 | class Smarty_Internal_Runtime_Var |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Template code runtime function to create a local Smarty variable for array assignments |
|
| 15 | - * |
|
| 16 | - * @param \Smarty_Internal_Template $tpl template object |
|
| 17 | - * @param string $varName template variable name |
|
| 18 | - * @param bool $nocache cache mode of variable |
|
| 19 | - */ |
|
| 20 | - public function createLocalArrayVariable(Smarty_Internal_Template $tpl, $varName, $nocache = false) |
|
| 21 | - { |
|
| 22 | - if (!isset($tpl->tpl_vars[$varName])) { |
|
| 23 | - $tpl->tpl_vars[$varName] = new Smarty_Variable(array(), $nocache); |
|
| 24 | - } else { |
|
| 25 | - $tpl->tpl_vars[$varName] = clone $tpl->tpl_vars[$varName]; |
|
| 26 | - if (!(is_array($tpl->tpl_vars[$varName]->value) || |
|
| 27 | - $tpl->tpl_vars[$varName]->value instanceof ArrayAccess) |
|
| 28 | - ) { |
|
| 29 | - settype($tpl->tpl_vars[$varName]->value, 'array'); |
|
| 30 | - } |
|
| 31 | - } |
|
| 32 | - } |
|
| 13 | + /** |
|
| 14 | + * Template code runtime function to create a local Smarty variable for array assignments |
|
| 15 | + * |
|
| 16 | + * @param \Smarty_Internal_Template $tpl template object |
|
| 17 | + * @param string $varName template variable name |
|
| 18 | + * @param bool $nocache cache mode of variable |
|
| 19 | + */ |
|
| 20 | + public function createLocalArrayVariable(Smarty_Internal_Template $tpl, $varName, $nocache = false) |
|
| 21 | + { |
|
| 22 | + if (!isset($tpl->tpl_vars[$varName])) { |
|
| 23 | + $tpl->tpl_vars[$varName] = new Smarty_Variable(array(), $nocache); |
|
| 24 | + } else { |
|
| 25 | + $tpl->tpl_vars[$varName] = clone $tpl->tpl_vars[$varName]; |
|
| 26 | + if (!(is_array($tpl->tpl_vars[$varName]->value) || |
|
| 27 | + $tpl->tpl_vars[$varName]->value instanceof ArrayAccess) |
|
| 28 | + ) { |
|
| 29 | + settype($tpl->tpl_vars[$varName]->value, 'array'); |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -16,27 +16,27 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Internal_Compile_Private_Block_Plugin |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Setup callback and parameter array |
|
| 21 | - * |
|
| 22 | - * @param \Smarty_Internal_TemplateCompilerBase $compiler |
|
| 23 | - * @param array $_attr attributes |
|
| 24 | - * @param string $tag |
|
| 25 | - * @param string $method |
|
| 26 | - * |
|
| 27 | - * @return array |
|
| 28 | - */ |
|
| 29 | - public function setup(Smarty_Internal_TemplateCompilerBase $compiler, $_attr, $tag, $method) |
|
| 30 | - { |
|
| 31 | - $_paramsArray = array(); |
|
| 32 | - foreach ($_attr as $_key => $_value) { |
|
| 33 | - if (is_int($_key)) { |
|
| 34 | - $_paramsArray[] = "$_key=>$_value"; |
|
| 35 | - } else { |
|
| 36 | - $_paramsArray[] = "'$_key'=>$_value"; |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - $callback = array("\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]", "->{$method}"); |
|
| 40 | - return array($callback, $_paramsArray, "array(\$_block_plugin{$this->nesting}, '{$method}')"); |
|
| 41 | - } |
|
| 19 | + /** |
|
| 20 | + * Setup callback and parameter array |
|
| 21 | + * |
|
| 22 | + * @param \Smarty_Internal_TemplateCompilerBase $compiler |
|
| 23 | + * @param array $_attr attributes |
|
| 24 | + * @param string $tag |
|
| 25 | + * @param string $method |
|
| 26 | + * |
|
| 27 | + * @return array |
|
| 28 | + */ |
|
| 29 | + public function setup(Smarty_Internal_TemplateCompilerBase $compiler, $_attr, $tag, $method) |
|
| 30 | + { |
|
| 31 | + $_paramsArray = array(); |
|
| 32 | + foreach ($_attr as $_key => $_value) { |
|
| 33 | + if (is_int($_key)) { |
|
| 34 | + $_paramsArray[] = "$_key=>$_value"; |
|
| 35 | + } else { |
|
| 36 | + $_paramsArray[] = "'$_key'=>$_value"; |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + $callback = array("\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]", "->{$method}"); |
|
| 40 | + return array($callback, $_paramsArray, "array(\$_block_plugin{$this->nesting}, '{$method}')"); |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -11,67 +11,67 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Smarty_Internal_Method_LoadFilter |
| 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 | - * Valid filter types |
|
| 23 | - * |
|
| 24 | - * @var array |
|
| 25 | - */ |
|
| 26 | - private $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true); |
|
| 21 | + /** |
|
| 22 | + * Valid filter types |
|
| 23 | + * |
|
| 24 | + * @var array |
|
| 25 | + */ |
|
| 26 | + private $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * load a filter of specified type and name |
|
| 30 | - * |
|
| 31 | - * @api Smarty::loadFilter() |
|
| 32 | - * |
|
| 33 | - * @link http://www.smarty.net/docs/en/api.load.filter.tpl |
|
| 34 | - * |
|
| 35 | - * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 36 | - * @param string $type filter type |
|
| 37 | - * @param string $name filter name |
|
| 38 | - * |
|
| 39 | - * @return bool |
|
| 40 | - * @throws SmartyException if filter could not be loaded |
|
| 41 | - */ |
|
| 42 | - public function loadFilter(Smarty_Internal_TemplateBase $obj, $type, $name) |
|
| 43 | - { |
|
| 44 | - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 45 | - $this->_checkFilterType($type); |
|
| 46 | - $_plugin = "smarty_{$type}filter_{$name}"; |
|
| 47 | - $_filter_name = $_plugin; |
|
| 48 | - if (is_callable($_plugin)) { |
|
| 49 | - $smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin; |
|
| 50 | - return true; |
|
| 51 | - } |
|
| 52 | - if ($smarty->loadPlugin($_plugin)) { |
|
| 53 | - if (class_exists($_plugin, false)) { |
|
| 54 | - $_plugin = array($_plugin, 'execute'); |
|
| 55 | - } |
|
| 56 | - if (is_callable($_plugin)) { |
|
| 57 | - $smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin; |
|
| 58 | - return true; |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - throw new SmartyException("{$type}filter \"{$name}\" not found or callable"); |
|
| 62 | - } |
|
| 28 | + /** |
|
| 29 | + * load a filter of specified type and name |
|
| 30 | + * |
|
| 31 | + * @api Smarty::loadFilter() |
|
| 32 | + * |
|
| 33 | + * @link http://www.smarty.net/docs/en/api.load.filter.tpl |
|
| 34 | + * |
|
| 35 | + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 36 | + * @param string $type filter type |
|
| 37 | + * @param string $name filter name |
|
| 38 | + * |
|
| 39 | + * @return bool |
|
| 40 | + * @throws SmartyException if filter could not be loaded |
|
| 41 | + */ |
|
| 42 | + public function loadFilter(Smarty_Internal_TemplateBase $obj, $type, $name) |
|
| 43 | + { |
|
| 44 | + $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 45 | + $this->_checkFilterType($type); |
|
| 46 | + $_plugin = "smarty_{$type}filter_{$name}"; |
|
| 47 | + $_filter_name = $_plugin; |
|
| 48 | + if (is_callable($_plugin)) { |
|
| 49 | + $smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin; |
|
| 50 | + return true; |
|
| 51 | + } |
|
| 52 | + if ($smarty->loadPlugin($_plugin)) { |
|
| 53 | + if (class_exists($_plugin, false)) { |
|
| 54 | + $_plugin = array($_plugin, 'execute'); |
|
| 55 | + } |
|
| 56 | + if (is_callable($_plugin)) { |
|
| 57 | + $smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin; |
|
| 58 | + return true; |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + throw new SmartyException("{$type}filter \"{$name}\" not found or callable"); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Check if filter type is valid |
|
| 66 | - * |
|
| 67 | - * @param string $type |
|
| 68 | - * |
|
| 69 | - * @throws \SmartyException |
|
| 70 | - */ |
|
| 71 | - public function _checkFilterType($type) |
|
| 72 | - { |
|
| 73 | - if (!isset($this->filterTypes[ $type ])) { |
|
| 74 | - throw new SmartyException("Illegal filter type \"{$type}\""); |
|
| 75 | - } |
|
| 76 | - } |
|
| 64 | + /** |
|
| 65 | + * Check if filter type is valid |
|
| 66 | + * |
|
| 67 | + * @param string $type |
|
| 68 | + * |
|
| 69 | + * @throws \SmartyException |
|
| 70 | + */ |
|
| 71 | + public function _checkFilterType($type) |
|
| 72 | + { |
|
| 73 | + if (!isset($this->filterTypes[ $type ])) { |
|
| 74 | + throw new SmartyException("Illegal filter type \"{$type}\""); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | } |
| 78 | 78 | \ No newline at end of file |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $_plugin = "smarty_{$type}filter_{$name}"; |
| 47 | 47 | $_filter_name = $_plugin; |
| 48 | 48 | if (is_callable($_plugin)) { |
| 49 | - $smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin; |
|
| 49 | + $smarty->registered_filters[$type][$_filter_name] = $_plugin; |
|
| 50 | 50 | return true; |
| 51 | 51 | } |
| 52 | 52 | if ($smarty->loadPlugin($_plugin)) { |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $_plugin = array($_plugin, 'execute'); |
| 55 | 55 | } |
| 56 | 56 | if (is_callable($_plugin)) { |
| 57 | - $smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin; |
|
| 57 | + $smarty->registered_filters[$type][$_filter_name] = $_plugin; |
|
| 58 | 58 | return true; |
| 59 | 59 | } |
| 60 | 60 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | public function _checkFilterType($type) |
| 72 | 72 | { |
| 73 | - if (!isset($this->filterTypes[ $type ])) { |
|
| 73 | + if (!isset($this->filterTypes[$type])) { |
|
| 74 | 74 | throw new SmartyException("Illegal filter type \"{$type}\""); |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -16,242 +16,242 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_ForeachSection |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Attribute definition: Overwrites base class. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - * @see Smarty_Internal_CompileBase |
|
| 24 | - */ |
|
| 25 | - public $required_attributes = array('from', 'item'); |
|
| 19 | + /** |
|
| 20 | + * Attribute definition: Overwrites base class. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + * @see Smarty_Internal_CompileBase |
|
| 24 | + */ |
|
| 25 | + public $required_attributes = array('from', 'item'); |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Attribute definition: Overwrites base class. |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - * @see Smarty_Internal_CompileBase |
|
| 32 | - */ |
|
| 33 | - public $optional_attributes = array('name', 'key', 'properties'); |
|
| 27 | + /** |
|
| 28 | + * Attribute definition: Overwrites base class. |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + * @see Smarty_Internal_CompileBase |
|
| 32 | + */ |
|
| 33 | + public $optional_attributes = array('name', 'key', 'properties'); |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Attribute definition: Overwrites base class. |
|
| 37 | - * |
|
| 38 | - * @var array |
|
| 39 | - * @see Smarty_Internal_CompileBase |
|
| 40 | - */ |
|
| 41 | - public $shorttag_order = array('from', 'item', 'key', 'name'); |
|
| 35 | + /** |
|
| 36 | + * Attribute definition: Overwrites base class. |
|
| 37 | + * |
|
| 38 | + * @var array |
|
| 39 | + * @see Smarty_Internal_CompileBase |
|
| 40 | + */ |
|
| 41 | + public $shorttag_order = array('from', 'item', 'key', 'name'); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * counter |
|
| 45 | - * |
|
| 46 | - * @var int |
|
| 47 | - */ |
|
| 48 | - public $counter = 0; |
|
| 43 | + /** |
|
| 44 | + * counter |
|
| 45 | + * |
|
| 46 | + * @var int |
|
| 47 | + */ |
|
| 48 | + public $counter = 0; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Name of this tag |
|
| 52 | - * |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 55 | - public $tagName = 'foreach'; |
|
| 50 | + /** |
|
| 51 | + * Name of this tag |
|
| 52 | + * |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | + public $tagName = 'foreach'; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Valid properties of $smarty.foreach.name.xxx variable |
|
| 59 | - * |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 62 | - public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total'); |
|
| 57 | + /** |
|
| 58 | + * Valid properties of $smarty.foreach.name.xxx variable |
|
| 59 | + * |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | + public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total'); |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Valid properties of $item@xxx variable |
|
| 66 | - * |
|
| 67 | - * @var array |
|
| 68 | - */ |
|
| 69 | - public $itemProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'key'); |
|
| 64 | + /** |
|
| 65 | + * Valid properties of $item@xxx variable |
|
| 66 | + * |
|
| 67 | + * @var array |
|
| 68 | + */ |
|
| 69 | + public $itemProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'key'); |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Flag if tag had name attribute |
|
| 73 | - * |
|
| 74 | - * @var bool |
|
| 75 | - */ |
|
| 76 | - public $isNamed = false; |
|
| 71 | + /** |
|
| 72 | + * Flag if tag had name attribute |
|
| 73 | + * |
|
| 74 | + * @var bool |
|
| 75 | + */ |
|
| 76 | + public $isNamed = false; |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Compiles code for the {foreach} tag |
|
| 80 | - * |
|
| 81 | - * @param array $args array with attributes from parser |
|
| 82 | - * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object |
|
| 83 | - * @param array $parameter array with compilation parameter |
|
| 84 | - * |
|
| 85 | - * @return string compiled code |
|
| 86 | - * @throws \SmartyCompilerException |
|
| 87 | - */ |
|
| 88 | - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) |
|
| 89 | - { |
|
| 90 | - $compiler->loopNesting ++; |
|
| 91 | - // init |
|
| 92 | - $this->isNamed = false; |
|
| 93 | - // check and get attributes |
|
| 94 | - $_attr = $this->getAttributes($compiler, $args); |
|
| 95 | - $from = $_attr[ 'from' ]; |
|
| 96 | - $item = $compiler->getId($_attr[ 'item' ]); |
|
| 97 | - if ($item === false) { |
|
| 98 | - $item = $compiler->getVariableName($_attr[ 'item' ]); |
|
| 99 | - } |
|
| 100 | - $key = $name = null; |
|
| 101 | - $attributes = array('item' => $item); |
|
| 102 | - if (isset($_attr[ 'key' ])) { |
|
| 103 | - $key = $compiler->getId($_attr[ 'key' ]); |
|
| 104 | - if ($key === false) { |
|
| 105 | - $key = $compiler->getVariableName($_attr[ 'key' ]); |
|
| 106 | - } |
|
| 107 | - $attributes[ 'key' ] = $key; |
|
| 108 | - } |
|
| 109 | - if (isset($_attr[ 'name' ])) { |
|
| 110 | - $this->isNamed = true; |
|
| 111 | - $name = $attributes[ 'name' ] = $compiler->getId($_attr[ 'name' ]); |
|
| 112 | - } |
|
| 113 | - foreach ($attributes as $a => $v) { |
|
| 114 | - if ($v === false) { |
|
| 115 | - $compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - $fromName = $compiler->getVariableName($_attr[ 'from' ]); |
|
| 119 | - if ($fromName) { |
|
| 120 | - foreach (array('item', 'key') as $a) { |
|
| 121 | - if (isset($attributes[ $a ]) && $attributes[ $a ] == $fromName) { |
|
| 122 | - $compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'", |
|
| 123 | - null, true); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - } |
|
| 78 | + /** |
|
| 79 | + * Compiles code for the {foreach} tag |
|
| 80 | + * |
|
| 81 | + * @param array $args array with attributes from parser |
|
| 82 | + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object |
|
| 83 | + * @param array $parameter array with compilation parameter |
|
| 84 | + * |
|
| 85 | + * @return string compiled code |
|
| 86 | + * @throws \SmartyCompilerException |
|
| 87 | + */ |
|
| 88 | + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) |
|
| 89 | + { |
|
| 90 | + $compiler->loopNesting ++; |
|
| 91 | + // init |
|
| 92 | + $this->isNamed = false; |
|
| 93 | + // check and get attributes |
|
| 94 | + $_attr = $this->getAttributes($compiler, $args); |
|
| 95 | + $from = $_attr[ 'from' ]; |
|
| 96 | + $item = $compiler->getId($_attr[ 'item' ]); |
|
| 97 | + if ($item === false) { |
|
| 98 | + $item = $compiler->getVariableName($_attr[ 'item' ]); |
|
| 99 | + } |
|
| 100 | + $key = $name = null; |
|
| 101 | + $attributes = array('item' => $item); |
|
| 102 | + if (isset($_attr[ 'key' ])) { |
|
| 103 | + $key = $compiler->getId($_attr[ 'key' ]); |
|
| 104 | + if ($key === false) { |
|
| 105 | + $key = $compiler->getVariableName($_attr[ 'key' ]); |
|
| 106 | + } |
|
| 107 | + $attributes[ 'key' ] = $key; |
|
| 108 | + } |
|
| 109 | + if (isset($_attr[ 'name' ])) { |
|
| 110 | + $this->isNamed = true; |
|
| 111 | + $name = $attributes[ 'name' ] = $compiler->getId($_attr[ 'name' ]); |
|
| 112 | + } |
|
| 113 | + foreach ($attributes as $a => $v) { |
|
| 114 | + if ($v === false) { |
|
| 115 | + $compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + $fromName = $compiler->getVariableName($_attr[ 'from' ]); |
|
| 119 | + if ($fromName) { |
|
| 120 | + foreach (array('item', 'key') as $a) { |
|
| 121 | + if (isset($attributes[ $a ]) && $attributes[ $a ] == $fromName) { |
|
| 122 | + $compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'", |
|
| 123 | + null, true); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - $itemVar = "\$_smarty_tpl->tpl_vars['{$item}']"; |
|
| 129 | - $local = '$__foreach_' . $attributes[ 'item' ] . '_' . $this->counter ++ . '_'; |
|
| 130 | - // search for used tag attributes |
|
| 131 | - $itemAttr = array(); |
|
| 132 | - $namedAttr = array(); |
|
| 133 | - $this->scanForProperties($attributes, $compiler); |
|
| 134 | - if (!empty($this->matchResults[ 'item' ])) { |
|
| 135 | - $itemAttr = $this->matchResults[ 'item' ]; |
|
| 136 | - } |
|
| 137 | - if (!empty($this->matchResults[ 'named' ])) { |
|
| 138 | - $namedAttr = $this->matchResults[ 'named' ]; |
|
| 139 | - } |
|
| 140 | - if (isset($_attr[ 'properties' ]) && preg_match_all("/['](.*?)[']/", $_attr[ 'properties' ], $match)) { |
|
| 141 | - foreach ($match[ 1 ] as $prop) { |
|
| 142 | - if (in_array($prop, $this->itemProperties)) { |
|
| 143 | - $itemAttr[ $prop ] = true; |
|
| 144 | - } else { |
|
| 145 | - $compiler->trigger_template_error("Invalid property '{$prop}'", null, true); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - if ($this->isNamed) { |
|
| 149 | - foreach ($match[ 1 ] as $prop) { |
|
| 150 | - if (in_array($prop, $this->nameProperties)) { |
|
| 151 | - $nameAttr[ $prop ] = true; |
|
| 152 | - } else { |
|
| 153 | - $compiler->trigger_template_error("Invalid property '{$prop}'", null, true); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - if (isset($itemAttr[ 'first' ])) { |
|
| 159 | - $itemAttr[ 'index' ] = true; |
|
| 160 | - } |
|
| 161 | - if (isset($namedAttr[ 'first' ])) { |
|
| 162 | - $namedAttr[ 'index' ] = true; |
|
| 163 | - } |
|
| 164 | - if (isset($namedAttr[ 'last' ])) { |
|
| 165 | - $namedAttr[ 'iteration' ] = true; |
|
| 166 | - $namedAttr[ 'total' ] = true; |
|
| 167 | - } |
|
| 168 | - if (isset($itemAttr[ 'last' ])) { |
|
| 169 | - $itemAttr[ 'iteration' ] = true; |
|
| 170 | - $itemAttr[ 'total' ] = true; |
|
| 171 | - } |
|
| 172 | - if (isset($namedAttr[ 'show' ])) { |
|
| 173 | - $namedAttr[ 'total' ] = true; |
|
| 174 | - } |
|
| 175 | - if (isset($itemAttr[ 'show' ])) { |
|
| 176 | - $itemAttr[ 'total' ] = true; |
|
| 177 | - } |
|
| 178 | - $keyTerm = ''; |
|
| 179 | - if (isset($attributes[ 'key' ])) { |
|
| 180 | - $keyTerm = "\$_smarty_tpl->tpl_vars['{$key}']->value => "; |
|
| 181 | - } |
|
| 182 | - if (isset($itemAttr[ 'key' ])) { |
|
| 183 | - $keyTerm = "{$itemVar}->key => "; |
|
| 184 | - } |
|
| 185 | - if ($this->isNamed) { |
|
| 186 | - $foreachVar = "\$_smarty_tpl->tpl_vars['__smarty_foreach_{$attributes['name']}']"; |
|
| 187 | - } |
|
| 188 | - $needTotal = isset($itemAttr[ 'total' ]); |
|
| 189 | - // Register tag |
|
| 190 | - $this->openTag($compiler, 'foreach', |
|
| 191 | - array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2)); |
|
| 192 | - // maybe nocache because of nocache variables |
|
| 193 | - $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |
|
| 194 | - // generate output code |
|
| 195 | - $output = "<?php\n"; |
|
| 196 | - $output .= "\$_from = \$_smarty_tpl->smarty->ext->_foreach->init(\$_smarty_tpl, $from, " . |
|
| 197 | - var_export($item, true); |
|
| 198 | - if ($name || $needTotal || $key) { |
|
| 199 | - $output .= ', ' . var_export($needTotal, true); |
|
| 200 | - } |
|
| 201 | - if ($name || $key) { |
|
| 202 | - $output .= ', ' . var_export($key, true); |
|
| 203 | - } |
|
| 204 | - if ($name) { |
|
| 205 | - $output .= ', ' . var_export($name, true) . ', ' . var_export($namedAttr, true); |
|
| 206 | - } |
|
| 207 | - $output .= ");\n"; |
|
| 208 | - if (isset($itemAttr[ 'show' ])) { |
|
| 209 | - $output .= "{$itemVar}->show = ({$itemVar}->total > 0);\n"; |
|
| 210 | - } |
|
| 211 | - if (isset($itemAttr[ 'iteration' ])) { |
|
| 212 | - $output .= "{$itemVar}->iteration = 0;\n"; |
|
| 213 | - } |
|
| 214 | - if (isset($itemAttr[ 'index' ])) { |
|
| 215 | - $output .= "{$itemVar}->index = -1;\n"; |
|
| 216 | - } |
|
| 217 | - $output .= "if (\$_from !== null) {\n"; |
|
| 218 | - $output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n"; |
|
| 219 | - if (isset($attributes[ 'key' ]) && isset($itemAttr[ 'key' ])) { |
|
| 220 | - $output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n"; |
|
| 221 | - } |
|
| 222 | - if (isset($itemAttr[ 'iteration' ])) { |
|
| 223 | - $output .= "{$itemVar}->iteration++;\n"; |
|
| 224 | - } |
|
| 225 | - if (isset($itemAttr[ 'index' ])) { |
|
| 226 | - $output .= "{$itemVar}->index++;\n"; |
|
| 227 | - } |
|
| 228 | - if (isset($itemAttr[ 'first' ])) { |
|
| 229 | - $output .= "{$itemVar}->first = !{$itemVar}->index;\n"; |
|
| 230 | - } |
|
| 231 | - if (isset($itemAttr[ 'last' ])) { |
|
| 232 | - $output .= "{$itemVar}->last = {$itemVar}->iteration == {$itemVar}->total;\n"; |
|
| 233 | - } |
|
| 234 | - if ($this->isNamed) { |
|
| 235 | - if (isset($namedAttr[ 'iteration' ])) { |
|
| 236 | - $output .= "{$foreachVar}->value['iteration']++;\n"; |
|
| 237 | - } |
|
| 238 | - if (isset($namedAttr[ 'index' ])) { |
|
| 239 | - $output .= "{$foreachVar}->value['index']++;\n"; |
|
| 240 | - } |
|
| 241 | - if (isset($namedAttr[ 'first' ])) { |
|
| 242 | - $output .= "{$foreachVar}->value['first'] = !{$foreachVar}->value['index'];\n"; |
|
| 243 | - } |
|
| 244 | - if (isset($namedAttr[ 'last' ])) { |
|
| 245 | - $output .= "{$foreachVar}->value['last'] = {$foreachVar}->value['iteration'] == {$foreachVar}->value['total'];\n"; |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - if (!empty($itemAttr)) { |
|
| 249 | - $output .= "{$local}saved = {$itemVar};\n"; |
|
| 250 | - } |
|
| 251 | - $output .= "?>"; |
|
| 128 | + $itemVar = "\$_smarty_tpl->tpl_vars['{$item}']"; |
|
| 129 | + $local = '$__foreach_' . $attributes[ 'item' ] . '_' . $this->counter ++ . '_'; |
|
| 130 | + // search for used tag attributes |
|
| 131 | + $itemAttr = array(); |
|
| 132 | + $namedAttr = array(); |
|
| 133 | + $this->scanForProperties($attributes, $compiler); |
|
| 134 | + if (!empty($this->matchResults[ 'item' ])) { |
|
| 135 | + $itemAttr = $this->matchResults[ 'item' ]; |
|
| 136 | + } |
|
| 137 | + if (!empty($this->matchResults[ 'named' ])) { |
|
| 138 | + $namedAttr = $this->matchResults[ 'named' ]; |
|
| 139 | + } |
|
| 140 | + if (isset($_attr[ 'properties' ]) && preg_match_all("/['](.*?)[']/", $_attr[ 'properties' ], $match)) { |
|
| 141 | + foreach ($match[ 1 ] as $prop) { |
|
| 142 | + if (in_array($prop, $this->itemProperties)) { |
|
| 143 | + $itemAttr[ $prop ] = true; |
|
| 144 | + } else { |
|
| 145 | + $compiler->trigger_template_error("Invalid property '{$prop}'", null, true); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + if ($this->isNamed) { |
|
| 149 | + foreach ($match[ 1 ] as $prop) { |
|
| 150 | + if (in_array($prop, $this->nameProperties)) { |
|
| 151 | + $nameAttr[ $prop ] = true; |
|
| 152 | + } else { |
|
| 153 | + $compiler->trigger_template_error("Invalid property '{$prop}'", null, true); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + if (isset($itemAttr[ 'first' ])) { |
|
| 159 | + $itemAttr[ 'index' ] = true; |
|
| 160 | + } |
|
| 161 | + if (isset($namedAttr[ 'first' ])) { |
|
| 162 | + $namedAttr[ 'index' ] = true; |
|
| 163 | + } |
|
| 164 | + if (isset($namedAttr[ 'last' ])) { |
|
| 165 | + $namedAttr[ 'iteration' ] = true; |
|
| 166 | + $namedAttr[ 'total' ] = true; |
|
| 167 | + } |
|
| 168 | + if (isset($itemAttr[ 'last' ])) { |
|
| 169 | + $itemAttr[ 'iteration' ] = true; |
|
| 170 | + $itemAttr[ 'total' ] = true; |
|
| 171 | + } |
|
| 172 | + if (isset($namedAttr[ 'show' ])) { |
|
| 173 | + $namedAttr[ 'total' ] = true; |
|
| 174 | + } |
|
| 175 | + if (isset($itemAttr[ 'show' ])) { |
|
| 176 | + $itemAttr[ 'total' ] = true; |
|
| 177 | + } |
|
| 178 | + $keyTerm = ''; |
|
| 179 | + if (isset($attributes[ 'key' ])) { |
|
| 180 | + $keyTerm = "\$_smarty_tpl->tpl_vars['{$key}']->value => "; |
|
| 181 | + } |
|
| 182 | + if (isset($itemAttr[ 'key' ])) { |
|
| 183 | + $keyTerm = "{$itemVar}->key => "; |
|
| 184 | + } |
|
| 185 | + if ($this->isNamed) { |
|
| 186 | + $foreachVar = "\$_smarty_tpl->tpl_vars['__smarty_foreach_{$attributes['name']}']"; |
|
| 187 | + } |
|
| 188 | + $needTotal = isset($itemAttr[ 'total' ]); |
|
| 189 | + // Register tag |
|
| 190 | + $this->openTag($compiler, 'foreach', |
|
| 191 | + array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2)); |
|
| 192 | + // maybe nocache because of nocache variables |
|
| 193 | + $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |
|
| 194 | + // generate output code |
|
| 195 | + $output = "<?php\n"; |
|
| 196 | + $output .= "\$_from = \$_smarty_tpl->smarty->ext->_foreach->init(\$_smarty_tpl, $from, " . |
|
| 197 | + var_export($item, true); |
|
| 198 | + if ($name || $needTotal || $key) { |
|
| 199 | + $output .= ', ' . var_export($needTotal, true); |
|
| 200 | + } |
|
| 201 | + if ($name || $key) { |
|
| 202 | + $output .= ', ' . var_export($key, true); |
|
| 203 | + } |
|
| 204 | + if ($name) { |
|
| 205 | + $output .= ', ' . var_export($name, true) . ', ' . var_export($namedAttr, true); |
|
| 206 | + } |
|
| 207 | + $output .= ");\n"; |
|
| 208 | + if (isset($itemAttr[ 'show' ])) { |
|
| 209 | + $output .= "{$itemVar}->show = ({$itemVar}->total > 0);\n"; |
|
| 210 | + } |
|
| 211 | + if (isset($itemAttr[ 'iteration' ])) { |
|
| 212 | + $output .= "{$itemVar}->iteration = 0;\n"; |
|
| 213 | + } |
|
| 214 | + if (isset($itemAttr[ 'index' ])) { |
|
| 215 | + $output .= "{$itemVar}->index = -1;\n"; |
|
| 216 | + } |
|
| 217 | + $output .= "if (\$_from !== null) {\n"; |
|
| 218 | + $output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n"; |
|
| 219 | + if (isset($attributes[ 'key' ]) && isset($itemAttr[ 'key' ])) { |
|
| 220 | + $output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n"; |
|
| 221 | + } |
|
| 222 | + if (isset($itemAttr[ 'iteration' ])) { |
|
| 223 | + $output .= "{$itemVar}->iteration++;\n"; |
|
| 224 | + } |
|
| 225 | + if (isset($itemAttr[ 'index' ])) { |
|
| 226 | + $output .= "{$itemVar}->index++;\n"; |
|
| 227 | + } |
|
| 228 | + if (isset($itemAttr[ 'first' ])) { |
|
| 229 | + $output .= "{$itemVar}->first = !{$itemVar}->index;\n"; |
|
| 230 | + } |
|
| 231 | + if (isset($itemAttr[ 'last' ])) { |
|
| 232 | + $output .= "{$itemVar}->last = {$itemVar}->iteration == {$itemVar}->total;\n"; |
|
| 233 | + } |
|
| 234 | + if ($this->isNamed) { |
|
| 235 | + if (isset($namedAttr[ 'iteration' ])) { |
|
| 236 | + $output .= "{$foreachVar}->value['iteration']++;\n"; |
|
| 237 | + } |
|
| 238 | + if (isset($namedAttr[ 'index' ])) { |
|
| 239 | + $output .= "{$foreachVar}->value['index']++;\n"; |
|
| 240 | + } |
|
| 241 | + if (isset($namedAttr[ 'first' ])) { |
|
| 242 | + $output .= "{$foreachVar}->value['first'] = !{$foreachVar}->value['index'];\n"; |
|
| 243 | + } |
|
| 244 | + if (isset($namedAttr[ 'last' ])) { |
|
| 245 | + $output .= "{$foreachVar}->value['last'] = {$foreachVar}->value['iteration'] == {$foreachVar}->value['total'];\n"; |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + if (!empty($itemAttr)) { |
|
| 249 | + $output .= "{$local}saved = {$itemVar};\n"; |
|
| 250 | + } |
|
| 251 | + $output .= "?>"; |
|
| 252 | 252 | |
| 253 | - return $output; |
|
| 254 | - } |
|
| 253 | + return $output; |
|
| 254 | + } |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
@@ -262,29 +262,29 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase |
| 264 | 264 | { |
| 265 | - /** |
|
| 266 | - * Compiles code for the {foreachelse} tag |
|
| 267 | - * |
|
| 268 | - * @param array $args array with attributes from parser |
|
| 269 | - * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object |
|
| 270 | - * @param array $parameter array with compilation parameter |
|
| 271 | - * |
|
| 272 | - * @return string compiled code |
|
| 273 | - */ |
|
| 274 | - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) |
|
| 275 | - { |
|
| 276 | - // check and get attributes |
|
| 277 | - $_attr = $this->getAttributes($compiler, $args); |
|
| 265 | + /** |
|
| 266 | + * Compiles code for the {foreachelse} tag |
|
| 267 | + * |
|
| 268 | + * @param array $args array with attributes from parser |
|
| 269 | + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object |
|
| 270 | + * @param array $parameter array with compilation parameter |
|
| 271 | + * |
|
| 272 | + * @return string compiled code |
|
| 273 | + */ |
|
| 274 | + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) |
|
| 275 | + { |
|
| 276 | + // check and get attributes |
|
| 277 | + $_attr = $this->getAttributes($compiler, $args); |
|
| 278 | 278 | |
| 279 | - list($openTag, $nocache, $local, $itemVar, $restore) = $this->closeTag($compiler, array('foreach')); |
|
| 280 | - $this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $itemVar, 0)); |
|
| 281 | - $output = "<?php\n"; |
|
| 282 | - if ($restore == 2) { |
|
| 283 | - $output .= "{$itemVar} = {$local}saved;\n"; |
|
| 284 | - } |
|
| 285 | - $output .= "}\n} else {\n?>\n"; |
|
| 286 | - return $output; |
|
| 287 | - } |
|
| 279 | + list($openTag, $nocache, $local, $itemVar, $restore) = $this->closeTag($compiler, array('foreach')); |
|
| 280 | + $this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $itemVar, 0)); |
|
| 281 | + $output = "<?php\n"; |
|
| 282 | + if ($restore == 2) { |
|
| 283 | + $output .= "{$itemVar} = {$local}saved;\n"; |
|
| 284 | + } |
|
| 285 | + $output .= "}\n} else {\n?>\n"; |
|
| 286 | + return $output; |
|
| 287 | + } |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -295,36 +295,36 @@ discard block |
||
| 295 | 295 | */ |
| 296 | 296 | class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase |
| 297 | 297 | { |
| 298 | - /** |
|
| 299 | - * Compiles code for the {/foreach} tag |
|
| 300 | - * |
|
| 301 | - * @param array $args array with attributes from parser |
|
| 302 | - * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object |
|
| 303 | - * @param array $parameter array with compilation parameter |
|
| 304 | - * |
|
| 305 | - * @return string compiled code |
|
| 306 | - */ |
|
| 307 | - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) |
|
| 308 | - { |
|
| 309 | - $compiler->loopNesting --; |
|
| 310 | - // must endblock be nocache? |
|
| 311 | - if ($compiler->nocache) { |
|
| 312 | - $compiler->tag_nocache = true; |
|
| 313 | - } |
|
| 298 | + /** |
|
| 299 | + * Compiles code for the {/foreach} tag |
|
| 300 | + * |
|
| 301 | + * @param array $args array with attributes from parser |
|
| 302 | + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object |
|
| 303 | + * @param array $parameter array with compilation parameter |
|
| 304 | + * |
|
| 305 | + * @return string compiled code |
|
| 306 | + */ |
|
| 307 | + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) |
|
| 308 | + { |
|
| 309 | + $compiler->loopNesting --; |
|
| 310 | + // must endblock be nocache? |
|
| 311 | + if ($compiler->nocache) { |
|
| 312 | + $compiler->tag_nocache = true; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - list($openTag, $compiler->nocache, $local, $itemVar, $restore) = |
|
| 316 | - $this->closeTag($compiler, array('foreach', 'foreachelse')); |
|
| 317 | - $output = "<?php\n"; |
|
| 315 | + list($openTag, $compiler->nocache, $local, $itemVar, $restore) = |
|
| 316 | + $this->closeTag($compiler, array('foreach', 'foreachelse')); |
|
| 317 | + $output = "<?php\n"; |
|
| 318 | 318 | |
| 319 | - if ($restore == 2) { |
|
| 320 | - $output .= "{$itemVar} = {$local}saved;\n"; |
|
| 321 | - } |
|
| 322 | - if ($restore > 0) { |
|
| 323 | - $output .= "}\n"; |
|
| 324 | - } |
|
| 325 | - $output .= "}\n"; |
|
| 326 | - $output .= "\$_smarty_tpl->smarty->ext->_foreach->restore(\$_smarty_tpl);\n"; |
|
| 327 | - $output .= "?>\n"; |
|
| 328 | - return $output; |
|
| 329 | - } |
|
| 319 | + if ($restore == 2) { |
|
| 320 | + $output .= "{$itemVar} = {$local}saved;\n"; |
|
| 321 | + } |
|
| 322 | + if ($restore > 0) { |
|
| 323 | + $output .= "}\n"; |
|
| 324 | + } |
|
| 325 | + $output .= "}\n"; |
|
| 326 | + $output .= "\$_smarty_tpl->smarty->ext->_foreach->restore(\$_smarty_tpl);\n"; |
|
| 327 | + $output .= "?>\n"; |
|
| 328 | + return $output; |
|
| 329 | + } |
|
| 330 | 330 | } |
@@ -87,38 +87,38 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) |
| 89 | 89 | { |
| 90 | - $compiler->loopNesting ++; |
|
| 90 | + $compiler->loopNesting++; |
|
| 91 | 91 | // init |
| 92 | 92 | $this->isNamed = false; |
| 93 | 93 | // check and get attributes |
| 94 | 94 | $_attr = $this->getAttributes($compiler, $args); |
| 95 | - $from = $_attr[ 'from' ]; |
|
| 96 | - $item = $compiler->getId($_attr[ 'item' ]); |
|
| 95 | + $from = $_attr['from']; |
|
| 96 | + $item = $compiler->getId($_attr['item']); |
|
| 97 | 97 | if ($item === false) { |
| 98 | - $item = $compiler->getVariableName($_attr[ 'item' ]); |
|
| 98 | + $item = $compiler->getVariableName($_attr['item']); |
|
| 99 | 99 | } |
| 100 | 100 | $key = $name = null; |
| 101 | 101 | $attributes = array('item' => $item); |
| 102 | - if (isset($_attr[ 'key' ])) { |
|
| 103 | - $key = $compiler->getId($_attr[ 'key' ]); |
|
| 102 | + if (isset($_attr['key'])) { |
|
| 103 | + $key = $compiler->getId($_attr['key']); |
|
| 104 | 104 | if ($key === false) { |
| 105 | - $key = $compiler->getVariableName($_attr[ 'key' ]); |
|
| 105 | + $key = $compiler->getVariableName($_attr['key']); |
|
| 106 | 106 | } |
| 107 | - $attributes[ 'key' ] = $key; |
|
| 107 | + $attributes['key'] = $key; |
|
| 108 | 108 | } |
| 109 | - if (isset($_attr[ 'name' ])) { |
|
| 109 | + if (isset($_attr['name'])) { |
|
| 110 | 110 | $this->isNamed = true; |
| 111 | - $name = $attributes[ 'name' ] = $compiler->getId($_attr[ 'name' ]); |
|
| 111 | + $name = $attributes['name'] = $compiler->getId($_attr['name']); |
|
| 112 | 112 | } |
| 113 | 113 | foreach ($attributes as $a => $v) { |
| 114 | 114 | if ($v === false) { |
| 115 | 115 | $compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true); |
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | - $fromName = $compiler->getVariableName($_attr[ 'from' ]); |
|
| 118 | + $fromName = $compiler->getVariableName($_attr['from']); |
|
| 119 | 119 | if ($fromName) { |
| 120 | 120 | foreach (array('item', 'key') as $a) { |
| 121 | - if (isset($attributes[ $a ]) && $attributes[ $a ] == $fromName) { |
|
| 121 | + if (isset($attributes[$a]) && $attributes[$a] == $fromName) { |
|
| 122 | 122 | $compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'", |
| 123 | 123 | null, true); |
| 124 | 124 | } |
@@ -126,66 +126,66 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | $itemVar = "\$_smarty_tpl->tpl_vars['{$item}']"; |
| 129 | - $local = '$__foreach_' . $attributes[ 'item' ] . '_' . $this->counter ++ . '_'; |
|
| 129 | + $local = '$__foreach_' . $attributes['item'] . '_' . $this->counter++ . '_'; |
|
| 130 | 130 | // search for used tag attributes |
| 131 | 131 | $itemAttr = array(); |
| 132 | 132 | $namedAttr = array(); |
| 133 | 133 | $this->scanForProperties($attributes, $compiler); |
| 134 | - if (!empty($this->matchResults[ 'item' ])) { |
|
| 135 | - $itemAttr = $this->matchResults[ 'item' ]; |
|
| 134 | + if (!empty($this->matchResults['item'])) { |
|
| 135 | + $itemAttr = $this->matchResults['item']; |
|
| 136 | 136 | } |
| 137 | - if (!empty($this->matchResults[ 'named' ])) { |
|
| 138 | - $namedAttr = $this->matchResults[ 'named' ]; |
|
| 137 | + if (!empty($this->matchResults['named'])) { |
|
| 138 | + $namedAttr = $this->matchResults['named']; |
|
| 139 | 139 | } |
| 140 | - if (isset($_attr[ 'properties' ]) && preg_match_all("/['](.*?)[']/", $_attr[ 'properties' ], $match)) { |
|
| 141 | - foreach ($match[ 1 ] as $prop) { |
|
| 140 | + if (isset($_attr['properties']) && preg_match_all("/['](.*?)[']/", $_attr['properties'], $match)) { |
|
| 141 | + foreach ($match[1] as $prop) { |
|
| 142 | 142 | if (in_array($prop, $this->itemProperties)) { |
| 143 | - $itemAttr[ $prop ] = true; |
|
| 143 | + $itemAttr[$prop] = true; |
|
| 144 | 144 | } else { |
| 145 | 145 | $compiler->trigger_template_error("Invalid property '{$prop}'", null, true); |
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | if ($this->isNamed) { |
| 149 | - foreach ($match[ 1 ] as $prop) { |
|
| 149 | + foreach ($match[1] as $prop) { |
|
| 150 | 150 | if (in_array($prop, $this->nameProperties)) { |
| 151 | - $nameAttr[ $prop ] = true; |
|
| 151 | + $nameAttr[$prop] = true; |
|
| 152 | 152 | } else { |
| 153 | 153 | $compiler->trigger_template_error("Invalid property '{$prop}'", null, true); |
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | - if (isset($itemAttr[ 'first' ])) { |
|
| 159 | - $itemAttr[ 'index' ] = true; |
|
| 158 | + if (isset($itemAttr['first'])) { |
|
| 159 | + $itemAttr['index'] = true; |
|
| 160 | 160 | } |
| 161 | - if (isset($namedAttr[ 'first' ])) { |
|
| 162 | - $namedAttr[ 'index' ] = true; |
|
| 161 | + if (isset($namedAttr['first'])) { |
|
| 162 | + $namedAttr['index'] = true; |
|
| 163 | 163 | } |
| 164 | - if (isset($namedAttr[ 'last' ])) { |
|
| 165 | - $namedAttr[ 'iteration' ] = true; |
|
| 166 | - $namedAttr[ 'total' ] = true; |
|
| 164 | + if (isset($namedAttr['last'])) { |
|
| 165 | + $namedAttr['iteration'] = true; |
|
| 166 | + $namedAttr['total'] = true; |
|
| 167 | 167 | } |
| 168 | - if (isset($itemAttr[ 'last' ])) { |
|
| 169 | - $itemAttr[ 'iteration' ] = true; |
|
| 170 | - $itemAttr[ 'total' ] = true; |
|
| 168 | + if (isset($itemAttr['last'])) { |
|
| 169 | + $itemAttr['iteration'] = true; |
|
| 170 | + $itemAttr['total'] = true; |
|
| 171 | 171 | } |
| 172 | - if (isset($namedAttr[ 'show' ])) { |
|
| 173 | - $namedAttr[ 'total' ] = true; |
|
| 172 | + if (isset($namedAttr['show'])) { |
|
| 173 | + $namedAttr['total'] = true; |
|
| 174 | 174 | } |
| 175 | - if (isset($itemAttr[ 'show' ])) { |
|
| 176 | - $itemAttr[ 'total' ] = true; |
|
| 175 | + if (isset($itemAttr['show'])) { |
|
| 176 | + $itemAttr['total'] = true; |
|
| 177 | 177 | } |
| 178 | 178 | $keyTerm = ''; |
| 179 | - if (isset($attributes[ 'key' ])) { |
|
| 179 | + if (isset($attributes['key'])) { |
|
| 180 | 180 | $keyTerm = "\$_smarty_tpl->tpl_vars['{$key}']->value => "; |
| 181 | 181 | } |
| 182 | - if (isset($itemAttr[ 'key' ])) { |
|
| 182 | + if (isset($itemAttr['key'])) { |
|
| 183 | 183 | $keyTerm = "{$itemVar}->key => "; |
| 184 | 184 | } |
| 185 | 185 | if ($this->isNamed) { |
| 186 | 186 | $foreachVar = "\$_smarty_tpl->tpl_vars['__smarty_foreach_{$attributes['name']}']"; |
| 187 | 187 | } |
| 188 | - $needTotal = isset($itemAttr[ 'total' ]); |
|
| 188 | + $needTotal = isset($itemAttr['total']); |
|
| 189 | 189 | // Register tag |
| 190 | 190 | $this->openTag($compiler, 'foreach', |
| 191 | 191 | array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2)); |
@@ -205,43 +205,43 @@ discard block |
||
| 205 | 205 | $output .= ', ' . var_export($name, true) . ', ' . var_export($namedAttr, true); |
| 206 | 206 | } |
| 207 | 207 | $output .= ");\n"; |
| 208 | - if (isset($itemAttr[ 'show' ])) { |
|
| 208 | + if (isset($itemAttr['show'])) { |
|
| 209 | 209 | $output .= "{$itemVar}->show = ({$itemVar}->total > 0);\n"; |
| 210 | 210 | } |
| 211 | - if (isset($itemAttr[ 'iteration' ])) { |
|
| 211 | + if (isset($itemAttr['iteration'])) { |
|
| 212 | 212 | $output .= "{$itemVar}->iteration = 0;\n"; |
| 213 | 213 | } |
| 214 | - if (isset($itemAttr[ 'index' ])) { |
|
| 214 | + if (isset($itemAttr['index'])) { |
|
| 215 | 215 | $output .= "{$itemVar}->index = -1;\n"; |
| 216 | 216 | } |
| 217 | 217 | $output .= "if (\$_from !== null) {\n"; |
| 218 | 218 | $output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n"; |
| 219 | - if (isset($attributes[ 'key' ]) && isset($itemAttr[ 'key' ])) { |
|
| 219 | + if (isset($attributes['key']) && isset($itemAttr['key'])) { |
|
| 220 | 220 | $output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n"; |
| 221 | 221 | } |
| 222 | - if (isset($itemAttr[ 'iteration' ])) { |
|
| 222 | + if (isset($itemAttr['iteration'])) { |
|
| 223 | 223 | $output .= "{$itemVar}->iteration++;\n"; |
| 224 | 224 | } |
| 225 | - if (isset($itemAttr[ 'index' ])) { |
|
| 225 | + if (isset($itemAttr['index'])) { |
|
| 226 | 226 | $output .= "{$itemVar}->index++;\n"; |
| 227 | 227 | } |
| 228 | - if (isset($itemAttr[ 'first' ])) { |
|
| 228 | + if (isset($itemAttr['first'])) { |
|
| 229 | 229 | $output .= "{$itemVar}->first = !{$itemVar}->index;\n"; |
| 230 | 230 | } |
| 231 | - if (isset($itemAttr[ 'last' ])) { |
|
| 231 | + if (isset($itemAttr['last'])) { |
|
| 232 | 232 | $output .= "{$itemVar}->last = {$itemVar}->iteration == {$itemVar}->total;\n"; |
| 233 | 233 | } |
| 234 | 234 | if ($this->isNamed) { |
| 235 | - if (isset($namedAttr[ 'iteration' ])) { |
|
| 235 | + if (isset($namedAttr['iteration'])) { |
|
| 236 | 236 | $output .= "{$foreachVar}->value['iteration']++;\n"; |
| 237 | 237 | } |
| 238 | - if (isset($namedAttr[ 'index' ])) { |
|
| 238 | + if (isset($namedAttr['index'])) { |
|
| 239 | 239 | $output .= "{$foreachVar}->value['index']++;\n"; |
| 240 | 240 | } |
| 241 | - if (isset($namedAttr[ 'first' ])) { |
|
| 241 | + if (isset($namedAttr['first'])) { |
|
| 242 | 242 | $output .= "{$foreachVar}->value['first'] = !{$foreachVar}->value['index'];\n"; |
| 243 | 243 | } |
| 244 | - if (isset($namedAttr[ 'last' ])) { |
|
| 244 | + if (isset($namedAttr['last'])) { |
|
| 245 | 245 | $output .= "{$foreachVar}->value['last'] = {$foreachVar}->value['iteration'] == {$foreachVar}->value['total'];\n"; |
| 246 | 246 | } |
| 247 | 247 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | */ |
| 307 | 307 | public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) |
| 308 | 308 | { |
| 309 | - $compiler->loopNesting --; |
|
| 309 | + $compiler->loopNesting--; |
|
| 310 | 310 | // must endblock be nocache? |
| 311 | 311 | if ($compiler->nocache) { |
| 312 | 312 | $compiler->tag_nocache = true; |