@@ -22,7 +22,7 @@ |
||
| 22 | 22 | * @param string $type filter type |
| 23 | 23 | * @param string $name filter name |
| 24 | 24 | * |
| 25 | - * @return bool |
|
| 25 | + * @return Smarty_Internal_TemplateBase |
|
| 26 | 26 | */ |
| 27 | 27 | public function unloadFilter(Smarty_Internal_TemplateBase $obj, $type, $name) |
| 28 | 28 | { |
@@ -11,32 +11,32 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Smarty_Internal_Method_UnloadFilter extends Smarty_Internal_Method_LoadFilter |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * load a filter of specified type and name |
|
| 16 | - * |
|
| 17 | - * @api Smarty::unloadFilter() |
|
| 18 | - * |
|
| 19 | - * @link http://www.smarty.net/docs/en/api.unload.filter.tpl |
|
| 20 | - * |
|
| 21 | - * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 22 | - * @param string $type filter type |
|
| 23 | - * @param string $name filter name |
|
| 24 | - * |
|
| 25 | - * @return bool |
|
| 26 | - */ |
|
| 27 | - public function unloadFilter(Smarty_Internal_TemplateBase $obj, $type, $name) |
|
| 28 | - { |
|
| 29 | - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 30 | - $this->_checkFilterType($type); |
|
| 31 | - if (isset($smarty->registered_filters[ $type ])) { |
|
| 32 | - $_filter_name = "smarty_{$type}filter_{$name}"; |
|
| 33 | - if (isset($smarty->registered_filters[ $type ][ $_filter_name ])) { |
|
| 34 | - unset ($smarty->registered_filters[ $type ][ $_filter_name ]); |
|
| 35 | - if (empty($smarty->registered_filters[ $type ])) { |
|
| 36 | - unset($smarty->registered_filters[ $type ]); |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - return $obj; |
|
| 41 | - } |
|
| 14 | + /** |
|
| 15 | + * load a filter of specified type and name |
|
| 16 | + * |
|
| 17 | + * @api Smarty::unloadFilter() |
|
| 18 | + * |
|
| 19 | + * @link http://www.smarty.net/docs/en/api.unload.filter.tpl |
|
| 20 | + * |
|
| 21 | + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj |
|
| 22 | + * @param string $type filter type |
|
| 23 | + * @param string $name filter name |
|
| 24 | + * |
|
| 25 | + * @return bool |
|
| 26 | + */ |
|
| 27 | + public function unloadFilter(Smarty_Internal_TemplateBase $obj, $type, $name) |
|
| 28 | + { |
|
| 29 | + $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
|
| 30 | + $this->_checkFilterType($type); |
|
| 31 | + if (isset($smarty->registered_filters[ $type ])) { |
|
| 32 | + $_filter_name = "smarty_{$type}filter_{$name}"; |
|
| 33 | + if (isset($smarty->registered_filters[ $type ][ $_filter_name ])) { |
|
| 34 | + unset ($smarty->registered_filters[ $type ][ $_filter_name ]); |
|
| 35 | + if (empty($smarty->registered_filters[ $type ])) { |
|
| 36 | + unset($smarty->registered_filters[ $type ]); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + return $obj; |
|
| 41 | + } |
|
| 42 | 42 | } |
| 43 | 43 | \ No newline at end of file |
@@ -28,12 +28,12 @@ |
||
| 28 | 28 | { |
| 29 | 29 | $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |
| 30 | 30 | $this->_checkFilterType($type); |
| 31 | - if (isset($smarty->registered_filters[ $type ])) { |
|
| 31 | + if (isset($smarty->registered_filters[$type])) { |
|
| 32 | 32 | $_filter_name = "smarty_{$type}filter_{$name}"; |
| 33 | - if (isset($smarty->registered_filters[ $type ][ $_filter_name ])) { |
|
| 34 | - unset ($smarty->registered_filters[ $type ][ $_filter_name ]); |
|
| 35 | - if (empty($smarty->registered_filters[ $type ])) { |
|
| 36 | - unset($smarty->registered_filters[ $type ]); |
|
| 33 | + if (isset($smarty->registered_filters[$type][$_filter_name])) { |
|
| 34 | + unset ($smarty->registered_filters[$type][$_filter_name]); |
|
| 35 | + if (empty($smarty->registered_filters[$type])) { |
|
| 36 | + unset($smarty->registered_filters[$type]); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | } |
@@ -135,7 +135,7 @@ |
||
| 135 | 135 | * @param \Smarty_Internal_Template $_template |
| 136 | 136 | * @param $name |
| 137 | 137 | * |
| 138 | - * @return null |
|
| 138 | + * @return string|null |
|
| 139 | 139 | */ |
| 140 | 140 | public function getBuffer(Smarty_Internal_Template $_template, $name) |
| 141 | 141 | { |
@@ -9,153 +9,153 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class Smarty_Internal_Runtime_Capture |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Flag that this instance will not be cached |
|
| 14 | - * |
|
| 15 | - * @var bool |
|
| 16 | - */ |
|
| 17 | - public $isPrivateExtension = true; |
|
| 12 | + /** |
|
| 13 | + * Flag that this instance will not be cached |
|
| 14 | + * |
|
| 15 | + * @var bool |
|
| 16 | + */ |
|
| 17 | + public $isPrivateExtension = true; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Stack of capture parameter |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - private $captureStack = array(); |
|
| 19 | + /** |
|
| 20 | + * Stack of capture parameter |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + private $captureStack = array(); |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Current open capture sections |
|
| 28 | - * |
|
| 29 | - * @var int |
|
| 30 | - */ |
|
| 31 | - private $captureCount = 0; |
|
| 26 | + /** |
|
| 27 | + * Current open capture sections |
|
| 28 | + * |
|
| 29 | + * @var int |
|
| 30 | + */ |
|
| 31 | + private $captureCount = 0; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Count stack |
|
| 35 | - * |
|
| 36 | - * @var int[] |
|
| 37 | - */ |
|
| 38 | - private $countStack = array(); |
|
| 33 | + /** |
|
| 34 | + * Count stack |
|
| 35 | + * |
|
| 36 | + * @var int[] |
|
| 37 | + */ |
|
| 38 | + private $countStack = array(); |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Named buffer |
|
| 42 | - * |
|
| 43 | - * @var string[] |
|
| 44 | - */ |
|
| 45 | - private $namedBuffer = array(); |
|
| 40 | + /** |
|
| 41 | + * Named buffer |
|
| 42 | + * |
|
| 43 | + * @var string[] |
|
| 44 | + */ |
|
| 45 | + private $namedBuffer = array(); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Flag if callbacks are registered |
|
| 49 | - * |
|
| 50 | - * @var bool |
|
| 51 | - */ |
|
| 52 | - private $isRegistered = false; |
|
| 47 | + /** |
|
| 48 | + * Flag if callbacks are registered |
|
| 49 | + * |
|
| 50 | + * @var bool |
|
| 51 | + */ |
|
| 52 | + private $isRegistered = false; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Open capture section |
|
| 56 | - * |
|
| 57 | - * @param \Smarty_Internal_Template $_template |
|
| 58 | - * @param string $buffer capture name |
|
| 59 | - * @param string $assign variable name |
|
| 60 | - * @param string $append variable name |
|
| 61 | - */ |
|
| 62 | - public function open(Smarty_Internal_Template $_template, $buffer, $assign, $append) |
|
| 63 | - { |
|
| 64 | - if (!$this->isRegistered) { |
|
| 65 | - $this->register($_template); |
|
| 66 | - } |
|
| 67 | - $this->captureStack[] = array($buffer, $assign, $append); |
|
| 68 | - $this->captureCount ++; |
|
| 69 | - ob_start(); |
|
| 70 | - } |
|
| 54 | + /** |
|
| 55 | + * Open capture section |
|
| 56 | + * |
|
| 57 | + * @param \Smarty_Internal_Template $_template |
|
| 58 | + * @param string $buffer capture name |
|
| 59 | + * @param string $assign variable name |
|
| 60 | + * @param string $append variable name |
|
| 61 | + */ |
|
| 62 | + public function open(Smarty_Internal_Template $_template, $buffer, $assign, $append) |
|
| 63 | + { |
|
| 64 | + if (!$this->isRegistered) { |
|
| 65 | + $this->register($_template); |
|
| 66 | + } |
|
| 67 | + $this->captureStack[] = array($buffer, $assign, $append); |
|
| 68 | + $this->captureCount ++; |
|
| 69 | + ob_start(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Register callbacks in template class |
|
| 74 | - * |
|
| 75 | - * @param \Smarty_Internal_Template $_template |
|
| 76 | - */ |
|
| 77 | - private function register(Smarty_Internal_Template $_template) |
|
| 78 | - { |
|
| 79 | - $_template->startRenderCallbacks[] = array($this, 'startRender'); |
|
| 80 | - $_template->endRenderCallbacks[] = array($this, 'endRender'); |
|
| 81 | - $this->startRender($_template); |
|
| 82 | - $this->isRegistered = true; |
|
| 83 | - } |
|
| 72 | + /** |
|
| 73 | + * Register callbacks in template class |
|
| 74 | + * |
|
| 75 | + * @param \Smarty_Internal_Template $_template |
|
| 76 | + */ |
|
| 77 | + private function register(Smarty_Internal_Template $_template) |
|
| 78 | + { |
|
| 79 | + $_template->startRenderCallbacks[] = array($this, 'startRender'); |
|
| 80 | + $_template->endRenderCallbacks[] = array($this, 'endRender'); |
|
| 81 | + $this->startRender($_template); |
|
| 82 | + $this->isRegistered = true; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Start render callback |
|
| 87 | - * |
|
| 88 | - * @param \Smarty_Internal_Template $_template |
|
| 89 | - */ |
|
| 90 | - public function startRender(Smarty_Internal_Template $_template) |
|
| 91 | - { |
|
| 92 | - $this->countStack[] = $this->captureCount; |
|
| 93 | - $this->captureCount = 0; |
|
| 94 | - } |
|
| 85 | + /** |
|
| 86 | + * Start render callback |
|
| 87 | + * |
|
| 88 | + * @param \Smarty_Internal_Template $_template |
|
| 89 | + */ |
|
| 90 | + public function startRender(Smarty_Internal_Template $_template) |
|
| 91 | + { |
|
| 92 | + $this->countStack[] = $this->captureCount; |
|
| 93 | + $this->captureCount = 0; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Close capture section |
|
| 98 | - * |
|
| 99 | - * @param \Smarty_Internal_Template $_template |
|
| 100 | - * |
|
| 101 | - * @throws \SmartyException |
|
| 102 | - */ |
|
| 103 | - public function close(Smarty_Internal_Template $_template) |
|
| 104 | - { |
|
| 105 | - if ($this->captureCount) { |
|
| 106 | - list($buffer, $assign, $append) = array_pop($this->captureStack); |
|
| 107 | - $this->captureCount --; |
|
| 108 | - if (isset($assign)) { |
|
| 109 | - $_template->assign($assign, ob_get_contents()); |
|
| 110 | - } |
|
| 111 | - if (isset($append)) { |
|
| 112 | - $_template->append($append, ob_get_contents()); |
|
| 113 | - } |
|
| 114 | - $this->namedBuffer[ $buffer ] = ob_get_clean(); |
|
| 115 | - } else { |
|
| 116 | - $this->error($_template); |
|
| 117 | - } |
|
| 118 | - } |
|
| 96 | + /** |
|
| 97 | + * Close capture section |
|
| 98 | + * |
|
| 99 | + * @param \Smarty_Internal_Template $_template |
|
| 100 | + * |
|
| 101 | + * @throws \SmartyException |
|
| 102 | + */ |
|
| 103 | + public function close(Smarty_Internal_Template $_template) |
|
| 104 | + { |
|
| 105 | + if ($this->captureCount) { |
|
| 106 | + list($buffer, $assign, $append) = array_pop($this->captureStack); |
|
| 107 | + $this->captureCount --; |
|
| 108 | + if (isset($assign)) { |
|
| 109 | + $_template->assign($assign, ob_get_contents()); |
|
| 110 | + } |
|
| 111 | + if (isset($append)) { |
|
| 112 | + $_template->append($append, ob_get_contents()); |
|
| 113 | + } |
|
| 114 | + $this->namedBuffer[ $buffer ] = ob_get_clean(); |
|
| 115 | + } else { |
|
| 116 | + $this->error($_template); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Error exception on not matching {capture}{/capture} |
|
| 122 | - * |
|
| 123 | - * @param \Smarty_Internal_Template $_template |
|
| 124 | - * |
|
| 125 | - * @throws \SmartyException |
|
| 126 | - */ |
|
| 127 | - public function error(Smarty_Internal_Template $_template) |
|
| 128 | - { |
|
| 129 | - throw new SmartyException("Not matching {capture}{/capture} in \"{$_template->template_resource}\""); |
|
| 130 | - } |
|
| 120 | + /** |
|
| 121 | + * Error exception on not matching {capture}{/capture} |
|
| 122 | + * |
|
| 123 | + * @param \Smarty_Internal_Template $_template |
|
| 124 | + * |
|
| 125 | + * @throws \SmartyException |
|
| 126 | + */ |
|
| 127 | + public function error(Smarty_Internal_Template $_template) |
|
| 128 | + { |
|
| 129 | + throw new SmartyException("Not matching {capture}{/capture} in \"{$_template->template_resource}\""); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * Return content of named capture buffer |
|
| 134 | - * |
|
| 135 | - * @param \Smarty_Internal_Template $_template |
|
| 136 | - * @param $name |
|
| 137 | - * |
|
| 138 | - * @return null |
|
| 139 | - */ |
|
| 140 | - public function getBuffer(Smarty_Internal_Template $_template, $name) |
|
| 141 | - { |
|
| 142 | - return isset($this->namedBuffer[ $name ]) ? $this->namedBuffer[ $name ] : null; |
|
| 143 | - } |
|
| 132 | + /** |
|
| 133 | + * Return content of named capture buffer |
|
| 134 | + * |
|
| 135 | + * @param \Smarty_Internal_Template $_template |
|
| 136 | + * @param $name |
|
| 137 | + * |
|
| 138 | + * @return null |
|
| 139 | + */ |
|
| 140 | + public function getBuffer(Smarty_Internal_Template $_template, $name) |
|
| 141 | + { |
|
| 142 | + return isset($this->namedBuffer[ $name ]) ? $this->namedBuffer[ $name ] : null; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * End render callback |
|
| 147 | - * |
|
| 148 | - * @param \Smarty_Internal_Template $_template |
|
| 149 | - * |
|
| 150 | - * @throws \SmartyException |
|
| 151 | - */ |
|
| 152 | - public function endRender(Smarty_Internal_Template $_template) |
|
| 153 | - { |
|
| 154 | - if ($this->captureCount) { |
|
| 155 | - $this->error($_template); |
|
| 156 | - } else { |
|
| 157 | - $this->captureCount = array_pop($this->countStack); |
|
| 158 | - } |
|
| 159 | - } |
|
| 145 | + /** |
|
| 146 | + * End render callback |
|
| 147 | + * |
|
| 148 | + * @param \Smarty_Internal_Template $_template |
|
| 149 | + * |
|
| 150 | + * @throws \SmartyException |
|
| 151 | + */ |
|
| 152 | + public function endRender(Smarty_Internal_Template $_template) |
|
| 153 | + { |
|
| 154 | + if ($this->captureCount) { |
|
| 155 | + $this->error($_template); |
|
| 156 | + } else { |
|
| 157 | + $this->captureCount = array_pop($this->countStack); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | 161 | } |
| 162 | 162 | \ No newline at end of file |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $this->register($_template); |
| 66 | 66 | } |
| 67 | 67 | $this->captureStack[] = array($buffer, $assign, $append); |
| 68 | - $this->captureCount ++; |
|
| 68 | + $this->captureCount++; |
|
| 69 | 69 | ob_start(); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -104,14 +104,14 @@ discard block |
||
| 104 | 104 | { |
| 105 | 105 | if ($this->captureCount) { |
| 106 | 106 | list($buffer, $assign, $append) = array_pop($this->captureStack); |
| 107 | - $this->captureCount --; |
|
| 107 | + $this->captureCount--; |
|
| 108 | 108 | if (isset($assign)) { |
| 109 | 109 | $_template->assign($assign, ob_get_contents()); |
| 110 | 110 | } |
| 111 | 111 | if (isset($append)) { |
| 112 | 112 | $_template->append($append, ob_get_contents()); |
| 113 | 113 | } |
| 114 | - $this->namedBuffer[ $buffer ] = ob_get_clean(); |
|
| 114 | + $this->namedBuffer[$buffer] = ob_get_clean(); |
|
| 115 | 115 | } else { |
| 116 | 116 | $this->error($_template); |
| 117 | 117 | } |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function getBuffer(Smarty_Internal_Template $_template, $name) |
| 141 | 141 | { |
| 142 | - return isset($this->namedBuffer[ $name ]) ? $this->namedBuffer[ $name ] : null; |
|
| 142 | + return isset($this->namedBuffer[$name]) ? $this->namedBuffer[$name] : null; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -115,7 +115,7 @@ |
||
| 115 | 115 | * @param string $file |
| 116 | 116 | * @param \Smarty $smarty |
| 117 | 117 | * |
| 118 | - * @return bool|string full filepath or false |
|
| 118 | + * @return string|false full filepath or false |
|
| 119 | 119 | * |
| 120 | 120 | */ |
| 121 | 121 | public function getIncludePath($dirs, $file, Smarty $smarty) |
@@ -15,168 +15,168 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Smarty_Internal_Runtime_GetIncludePath |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * include path cache |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - public $_include_path = ''; |
|
| 18 | + /** |
|
| 19 | + * include path cache |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + public $_include_path = ''; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * include path directory cache |
|
| 27 | - * |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - public $_include_dirs = array(); |
|
| 25 | + /** |
|
| 26 | + * include path directory cache |
|
| 27 | + * |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + public $_include_dirs = array(); |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * include path directory cache |
|
| 34 | - * |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - public $_user_dirs = array(); |
|
| 32 | + /** |
|
| 33 | + * include path directory cache |
|
| 34 | + * |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + public $_user_dirs = array(); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * stream cache |
|
| 41 | - * |
|
| 42 | - * @var string[] |
|
| 43 | - */ |
|
| 44 | - public $isFile = array(); |
|
| 39 | + /** |
|
| 40 | + * stream cache |
|
| 41 | + * |
|
| 42 | + * @var string[] |
|
| 43 | + */ |
|
| 44 | + public $isFile = array(); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * stream cache |
|
| 48 | - * |
|
| 49 | - * @var string[] |
|
| 50 | - */ |
|
| 51 | - public $isPath = array(); |
|
| 46 | + /** |
|
| 47 | + * stream cache |
|
| 48 | + * |
|
| 49 | + * @var string[] |
|
| 50 | + */ |
|
| 51 | + public $isPath = array(); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * stream cache |
|
| 55 | - * |
|
| 56 | - * @var int[] |
|
| 57 | - */ |
|
| 58 | - public $number = array(); |
|
| 53 | + /** |
|
| 54 | + * stream cache |
|
| 55 | + * |
|
| 56 | + * @var int[] |
|
| 57 | + */ |
|
| 58 | + public $number = array(); |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * status cache |
|
| 62 | - * |
|
| 63 | - * @var bool |
|
| 64 | - */ |
|
| 65 | - public $_has_stream_include = null; |
|
| 60 | + /** |
|
| 61 | + * status cache |
|
| 62 | + * |
|
| 63 | + * @var bool |
|
| 64 | + */ |
|
| 65 | + public $_has_stream_include = null; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Number for array index |
|
| 69 | - * |
|
| 70 | - * @var int |
|
| 71 | - */ |
|
| 72 | - public $counter = 0; |
|
| 67 | + /** |
|
| 68 | + * Number for array index |
|
| 69 | + * |
|
| 70 | + * @var int |
|
| 71 | + */ |
|
| 72 | + public $counter = 0; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Check if include path was updated |
|
| 76 | - * |
|
| 77 | - * @param \Smarty $smarty |
|
| 78 | - * |
|
| 79 | - * @return bool |
|
| 80 | - */ |
|
| 81 | - public function isNewIncludePath(Smarty $smarty) |
|
| 82 | - { |
|
| 83 | - $_i_path = get_include_path(); |
|
| 84 | - if ($this->_include_path != $_i_path) { |
|
| 85 | - $this->_include_dirs = array(); |
|
| 86 | - $this->_include_path = $_i_path; |
|
| 87 | - $_dirs = (array) explode(PATH_SEPARATOR, $_i_path); |
|
| 88 | - foreach ($_dirs as $_path) { |
|
| 89 | - if (is_dir($_path)) { |
|
| 90 | - $this->_include_dirs[] = $smarty->_realpath($_path . DS, true); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - return true; |
|
| 94 | - } |
|
| 95 | - return false; |
|
| 96 | - } |
|
| 74 | + /** |
|
| 75 | + * Check if include path was updated |
|
| 76 | + * |
|
| 77 | + * @param \Smarty $smarty |
|
| 78 | + * |
|
| 79 | + * @return bool |
|
| 80 | + */ |
|
| 81 | + public function isNewIncludePath(Smarty $smarty) |
|
| 82 | + { |
|
| 83 | + $_i_path = get_include_path(); |
|
| 84 | + if ($this->_include_path != $_i_path) { |
|
| 85 | + $this->_include_dirs = array(); |
|
| 86 | + $this->_include_path = $_i_path; |
|
| 87 | + $_dirs = (array) explode(PATH_SEPARATOR, $_i_path); |
|
| 88 | + foreach ($_dirs as $_path) { |
|
| 89 | + if (is_dir($_path)) { |
|
| 90 | + $this->_include_dirs[] = $smarty->_realpath($_path . DS, true); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + return true; |
|
| 94 | + } |
|
| 95 | + return false; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * return array with include path directories |
|
| 100 | - * |
|
| 101 | - * @param \Smarty $smarty |
|
| 102 | - * |
|
| 103 | - * @return array |
|
| 104 | - */ |
|
| 105 | - public function getIncludePathDirs(Smarty $smarty) |
|
| 106 | - { |
|
| 107 | - $this->isNewIncludePath($smarty); |
|
| 108 | - return $this->_include_dirs; |
|
| 109 | - } |
|
| 98 | + /** |
|
| 99 | + * return array with include path directories |
|
| 100 | + * |
|
| 101 | + * @param \Smarty $smarty |
|
| 102 | + * |
|
| 103 | + * @return array |
|
| 104 | + */ |
|
| 105 | + public function getIncludePathDirs(Smarty $smarty) |
|
| 106 | + { |
|
| 107 | + $this->isNewIncludePath($smarty); |
|
| 108 | + return $this->_include_dirs; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Return full file path from PHP include_path |
|
| 113 | - * |
|
| 114 | - * @param string[] $dirs |
|
| 115 | - * @param string $file |
|
| 116 | - * @param \Smarty $smarty |
|
| 117 | - * |
|
| 118 | - * @return bool|string full filepath or false |
|
| 119 | - * |
|
| 120 | - */ |
|
| 121 | - public function getIncludePath($dirs, $file, Smarty $smarty) |
|
| 122 | - { |
|
| 123 | - //if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : $this->_has_stream_include = false)) { |
|
| 124 | - if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : |
|
| 125 | - $this->_has_stream_include = function_exists('stream_resolve_include_path')) |
|
| 126 | - ) { |
|
| 127 | - $this->isNewIncludePath($smarty); |
|
| 128 | - } |
|
| 129 | - // try PHP include_path |
|
| 130 | - foreach ($dirs as $dir) { |
|
| 131 | - $dir_n = isset($this->number[ $dir ]) ? $this->number[ $dir ] : $this->number[ $dir ] = $this->counter ++; |
|
| 132 | - if (isset($this->isFile[ $dir_n ][ $file ])) { |
|
| 133 | - if ($this->isFile[ $dir_n ][ $file ]) { |
|
| 134 | - return $this->isFile[ $dir_n ][ $file ]; |
|
| 135 | - } else { |
|
| 136 | - continue; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - if (isset($this->_user_dirs[ $dir_n ])) { |
|
| 140 | - if (false === $this->_user_dirs[ $dir_n ]) { |
|
| 141 | - continue; |
|
| 142 | - } else { |
|
| 143 | - $dir = $this->_user_dirs[ $dir_n ]; |
|
| 144 | - } |
|
| 145 | - } else { |
|
| 146 | - if ($dir[ 0 ] == '/' || $dir[ 1 ] == ':') { |
|
| 147 | - $dir = str_ireplace(getcwd(), '.', $dir); |
|
| 148 | - if ($dir[ 0 ] == '/' || $dir[ 1 ] == ':') { |
|
| 149 | - $this->_user_dirs[ $dir_n ] = false; |
|
| 150 | - continue; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - $dir = substr($dir, 2); |
|
| 154 | - $this->_user_dirs[ $dir_n ] = $dir; |
|
| 155 | - } |
|
| 156 | - if ($this->_has_stream_include) { |
|
| 157 | - $path = stream_resolve_include_path($dir . (isset($file) ? $file : '')); |
|
| 158 | - if ($path) { |
|
| 159 | - return $this->isFile[ $dir_n ][ $file ] = $path; |
|
| 160 | - } |
|
| 161 | - } else { |
|
| 162 | - foreach ($this->_include_dirs as $key => $_i_path) { |
|
| 163 | - $path = isset($this->isPath[ $key ][ $dir_n ]) ? $this->isPath[ $key ][ $dir_n ] : |
|
| 164 | - $this->isPath[ $key ][ $dir_n ] = is_dir($_dir_path = $_i_path . $dir) ? $_dir_path : false; |
|
| 165 | - if ($path === false) { |
|
| 166 | - continue; |
|
| 167 | - } |
|
| 168 | - if (isset($file)) { |
|
| 169 | - $_file = $this->isFile[ $dir_n ][ $file ] = (is_file($path . $file)) ? $path . $file : false; |
|
| 170 | - if ($_file) { |
|
| 171 | - return $_file; |
|
| 172 | - } |
|
| 173 | - } else { |
|
| 174 | - // no file was given return directory path |
|
| 175 | - return $path; |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 111 | + /** |
|
| 112 | + * Return full file path from PHP include_path |
|
| 113 | + * |
|
| 114 | + * @param string[] $dirs |
|
| 115 | + * @param string $file |
|
| 116 | + * @param \Smarty $smarty |
|
| 117 | + * |
|
| 118 | + * @return bool|string full filepath or false |
|
| 119 | + * |
|
| 120 | + */ |
|
| 121 | + public function getIncludePath($dirs, $file, Smarty $smarty) |
|
| 122 | + { |
|
| 123 | + //if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : $this->_has_stream_include = false)) { |
|
| 124 | + if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : |
|
| 125 | + $this->_has_stream_include = function_exists('stream_resolve_include_path')) |
|
| 126 | + ) { |
|
| 127 | + $this->isNewIncludePath($smarty); |
|
| 128 | + } |
|
| 129 | + // try PHP include_path |
|
| 130 | + foreach ($dirs as $dir) { |
|
| 131 | + $dir_n = isset($this->number[ $dir ]) ? $this->number[ $dir ] : $this->number[ $dir ] = $this->counter ++; |
|
| 132 | + if (isset($this->isFile[ $dir_n ][ $file ])) { |
|
| 133 | + if ($this->isFile[ $dir_n ][ $file ]) { |
|
| 134 | + return $this->isFile[ $dir_n ][ $file ]; |
|
| 135 | + } else { |
|
| 136 | + continue; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + if (isset($this->_user_dirs[ $dir_n ])) { |
|
| 140 | + if (false === $this->_user_dirs[ $dir_n ]) { |
|
| 141 | + continue; |
|
| 142 | + } else { |
|
| 143 | + $dir = $this->_user_dirs[ $dir_n ]; |
|
| 144 | + } |
|
| 145 | + } else { |
|
| 146 | + if ($dir[ 0 ] == '/' || $dir[ 1 ] == ':') { |
|
| 147 | + $dir = str_ireplace(getcwd(), '.', $dir); |
|
| 148 | + if ($dir[ 0 ] == '/' || $dir[ 1 ] == ':') { |
|
| 149 | + $this->_user_dirs[ $dir_n ] = false; |
|
| 150 | + continue; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + $dir = substr($dir, 2); |
|
| 154 | + $this->_user_dirs[ $dir_n ] = $dir; |
|
| 155 | + } |
|
| 156 | + if ($this->_has_stream_include) { |
|
| 157 | + $path = stream_resolve_include_path($dir . (isset($file) ? $file : '')); |
|
| 158 | + if ($path) { |
|
| 159 | + return $this->isFile[ $dir_n ][ $file ] = $path; |
|
| 160 | + } |
|
| 161 | + } else { |
|
| 162 | + foreach ($this->_include_dirs as $key => $_i_path) { |
|
| 163 | + $path = isset($this->isPath[ $key ][ $dir_n ]) ? $this->isPath[ $key ][ $dir_n ] : |
|
| 164 | + $this->isPath[ $key ][ $dir_n ] = is_dir($_dir_path = $_i_path . $dir) ? $_dir_path : false; |
|
| 165 | + if ($path === false) { |
|
| 166 | + continue; |
|
| 167 | + } |
|
| 168 | + if (isset($file)) { |
|
| 169 | + $_file = $this->isFile[ $dir_n ][ $file ] = (is_file($path . $file)) ? $path . $file : false; |
|
| 170 | + if ($_file) { |
|
| 171 | + return $_file; |
|
| 172 | + } |
|
| 173 | + } else { |
|
| 174 | + // no file was given return directory path |
|
| 175 | + return $path; |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | 182 | } |
@@ -121,52 +121,50 @@ |
||
| 121 | 121 | public function getIncludePath($dirs, $file, Smarty $smarty) |
| 122 | 122 | { |
| 123 | 123 | //if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : $this->_has_stream_include = false)) { |
| 124 | - if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : |
|
| 125 | - $this->_has_stream_include = function_exists('stream_resolve_include_path')) |
|
| 124 | + if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : $this->_has_stream_include = function_exists('stream_resolve_include_path')) |
|
| 126 | 125 | ) { |
| 127 | 126 | $this->isNewIncludePath($smarty); |
| 128 | 127 | } |
| 129 | 128 | // try PHP include_path |
| 130 | 129 | foreach ($dirs as $dir) { |
| 131 | - $dir_n = isset($this->number[ $dir ]) ? $this->number[ $dir ] : $this->number[ $dir ] = $this->counter ++; |
|
| 132 | - if (isset($this->isFile[ $dir_n ][ $file ])) { |
|
| 133 | - if ($this->isFile[ $dir_n ][ $file ]) { |
|
| 134 | - return $this->isFile[ $dir_n ][ $file ]; |
|
| 130 | + $dir_n = isset($this->number[$dir]) ? $this->number[$dir] : $this->number[$dir] = $this->counter++; |
|
| 131 | + if (isset($this->isFile[$dir_n][$file])) { |
|
| 132 | + if ($this->isFile[$dir_n][$file]) { |
|
| 133 | + return $this->isFile[$dir_n][$file]; |
|
| 135 | 134 | } else { |
| 136 | 135 | continue; |
| 137 | 136 | } |
| 138 | 137 | } |
| 139 | - if (isset($this->_user_dirs[ $dir_n ])) { |
|
| 140 | - if (false === $this->_user_dirs[ $dir_n ]) { |
|
| 138 | + if (isset($this->_user_dirs[$dir_n])) { |
|
| 139 | + if (false === $this->_user_dirs[$dir_n]) { |
|
| 141 | 140 | continue; |
| 142 | 141 | } else { |
| 143 | - $dir = $this->_user_dirs[ $dir_n ]; |
|
| 142 | + $dir = $this->_user_dirs[$dir_n]; |
|
| 144 | 143 | } |
| 145 | 144 | } else { |
| 146 | - if ($dir[ 0 ] == '/' || $dir[ 1 ] == ':') { |
|
| 145 | + if ($dir[0] == '/' || $dir[1] == ':') { |
|
| 147 | 146 | $dir = str_ireplace(getcwd(), '.', $dir); |
| 148 | - if ($dir[ 0 ] == '/' || $dir[ 1 ] == ':') { |
|
| 149 | - $this->_user_dirs[ $dir_n ] = false; |
|
| 147 | + if ($dir[0] == '/' || $dir[1] == ':') { |
|
| 148 | + $this->_user_dirs[$dir_n] = false; |
|
| 150 | 149 | continue; |
| 151 | 150 | } |
| 152 | 151 | } |
| 153 | 152 | $dir = substr($dir, 2); |
| 154 | - $this->_user_dirs[ $dir_n ] = $dir; |
|
| 153 | + $this->_user_dirs[$dir_n] = $dir; |
|
| 155 | 154 | } |
| 156 | 155 | if ($this->_has_stream_include) { |
| 157 | 156 | $path = stream_resolve_include_path($dir . (isset($file) ? $file : '')); |
| 158 | 157 | if ($path) { |
| 159 | - return $this->isFile[ $dir_n ][ $file ] = $path; |
|
| 158 | + return $this->isFile[$dir_n][$file] = $path; |
|
| 160 | 159 | } |
| 161 | 160 | } else { |
| 162 | 161 | foreach ($this->_include_dirs as $key => $_i_path) { |
| 163 | - $path = isset($this->isPath[ $key ][ $dir_n ]) ? $this->isPath[ $key ][ $dir_n ] : |
|
| 164 | - $this->isPath[ $key ][ $dir_n ] = is_dir($_dir_path = $_i_path . $dir) ? $_dir_path : false; |
|
| 162 | + $path = isset($this->isPath[$key][$dir_n]) ? $this->isPath[$key][$dir_n] : $this->isPath[$key][$dir_n] = is_dir($_dir_path = $_i_path . $dir) ? $_dir_path : false; |
|
| 165 | 163 | if ($path === false) { |
| 166 | 164 | continue; |
| 167 | 165 | } |
| 168 | 166 | if (isset($file)) { |
| 169 | - $_file = $this->isFile[ $dir_n ][ $file ] = (is_file($path . $file)) ? $path . $file : false; |
|
| 167 | + $_file = $this->isFile[$dir_n][$file] = (is_file($path . $file)) ? $path . $file : false; |
|
| 170 | 168 | if ($_file) { |
| 171 | 169 | return $_file; |
| 172 | 170 | } |
@@ -76,7 +76,7 @@ |
||
| 76 | 76 | * |
| 77 | 77 | * @param \Smarty_Template_Cached $cached |
| 78 | 78 | * @param \Smarty_Internal_Template $_template |
| 79 | - * @param $no_output_filter |
|
| 79 | + * @param boolean $no_output_filter |
|
| 80 | 80 | * |
| 81 | 81 | * @throws \Exception |
| 82 | 82 | */ |
@@ -10,156 +10,156 @@ |
||
| 10 | 10 | **/ |
| 11 | 11 | class Smarty_Internal_Runtime_UpdateCache |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * check client side cache |
|
| 15 | - * |
|
| 16 | - * @param \Smarty_Template_Cached $cached |
|
| 17 | - * @param Smarty_Internal_Template $_template |
|
| 18 | - * @param string $content |
|
| 19 | - */ |
|
| 20 | - public function cacheModifiedCheck(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content) |
|
| 21 | - { |
|
| 22 | - } |
|
| 13 | + /** |
|
| 14 | + * check client side cache |
|
| 15 | + * |
|
| 16 | + * @param \Smarty_Template_Cached $cached |
|
| 17 | + * @param Smarty_Internal_Template $_template |
|
| 18 | + * @param string $content |
|
| 19 | + */ |
|
| 20 | + public function cacheModifiedCheck(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content) |
|
| 21 | + { |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Sanitize content and write it to cache resource |
|
| 26 | - * |
|
| 27 | - * @param \Smarty_Template_Cached $cached |
|
| 28 | - * @param Smarty_Internal_Template $_template |
|
| 29 | - * @param bool $no_output_filter |
|
| 30 | - * |
|
| 31 | - * @throws \SmartyException |
|
| 32 | - */ |
|
| 33 | - public function removeNoCacheHash(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, |
|
| 34 | - $no_output_filter) |
|
| 35 | - { |
|
| 36 | - $content = ob_get_clean(); |
|
| 37 | - unset($cached->hashes[ $_template->compiled->nocache_hash ]); |
|
| 38 | - if (!empty($cached->hashes)) { |
|
| 39 | - $hash_array = array(); |
|
| 40 | - foreach ($cached->hashes as $hash => $foo) { |
|
| 41 | - $hash_array[] = "/{$hash}/"; |
|
| 42 | - } |
|
| 43 | - $content = preg_replace($hash_array, $_template->compiled->nocache_hash, $content); |
|
| 44 | - } |
|
| 45 | - $_template->cached->has_nocache_code = false; |
|
| 46 | - // get text between non-cached items |
|
| 47 | - $cache_split = |
|
| 48 | - preg_split("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s", |
|
| 49 | - $content); |
|
| 50 | - // get non-cached items |
|
| 51 | - preg_match_all("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s", |
|
| 52 | - $content, $cache_parts); |
|
| 53 | - $content = ''; |
|
| 54 | - // loop over items, stitch back together |
|
| 55 | - foreach ($cache_split as $curr_idx => $curr_split) { |
|
| 56 | - // escape PHP tags in template content |
|
| 57 | - $content .= preg_replace('/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/', |
|
| 58 | - "<?php echo '\$1'; ?>\n", $curr_split); |
|
| 59 | - if (isset($cache_parts[ 0 ][ $curr_idx ])) { |
|
| 60 | - $_template->cached->has_nocache_code = true; |
|
| 61 | - $content .= $cache_parts[ 1 ][ $curr_idx ]; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - if (!$no_output_filter && !$_template->cached->has_nocache_code && |
|
| 65 | - (isset($_template->smarty->autoload_filters[ 'output' ]) || |
|
| 66 | - isset($_template->smarty->registered_filters[ 'output' ])) |
|
| 67 | - ) { |
|
| 68 | - $content = $_template->smarty->ext->_filterHandler->runFilter('output', $content, $_template); |
|
| 69 | - } |
|
| 70 | - // write cache file content |
|
| 71 | - $this->writeCachedContent($cached, $_template, $content); |
|
| 72 | - } |
|
| 24 | + /** |
|
| 25 | + * Sanitize content and write it to cache resource |
|
| 26 | + * |
|
| 27 | + * @param \Smarty_Template_Cached $cached |
|
| 28 | + * @param Smarty_Internal_Template $_template |
|
| 29 | + * @param bool $no_output_filter |
|
| 30 | + * |
|
| 31 | + * @throws \SmartyException |
|
| 32 | + */ |
|
| 33 | + public function removeNoCacheHash(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, |
|
| 34 | + $no_output_filter) |
|
| 35 | + { |
|
| 36 | + $content = ob_get_clean(); |
|
| 37 | + unset($cached->hashes[ $_template->compiled->nocache_hash ]); |
|
| 38 | + if (!empty($cached->hashes)) { |
|
| 39 | + $hash_array = array(); |
|
| 40 | + foreach ($cached->hashes as $hash => $foo) { |
|
| 41 | + $hash_array[] = "/{$hash}/"; |
|
| 42 | + } |
|
| 43 | + $content = preg_replace($hash_array, $_template->compiled->nocache_hash, $content); |
|
| 44 | + } |
|
| 45 | + $_template->cached->has_nocache_code = false; |
|
| 46 | + // get text between non-cached items |
|
| 47 | + $cache_split = |
|
| 48 | + preg_split("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s", |
|
| 49 | + $content); |
|
| 50 | + // get non-cached items |
|
| 51 | + preg_match_all("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s", |
|
| 52 | + $content, $cache_parts); |
|
| 53 | + $content = ''; |
|
| 54 | + // loop over items, stitch back together |
|
| 55 | + foreach ($cache_split as $curr_idx => $curr_split) { |
|
| 56 | + // escape PHP tags in template content |
|
| 57 | + $content .= preg_replace('/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/', |
|
| 58 | + "<?php echo '\$1'; ?>\n", $curr_split); |
|
| 59 | + if (isset($cache_parts[ 0 ][ $curr_idx ])) { |
|
| 60 | + $_template->cached->has_nocache_code = true; |
|
| 61 | + $content .= $cache_parts[ 1 ][ $curr_idx ]; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + if (!$no_output_filter && !$_template->cached->has_nocache_code && |
|
| 65 | + (isset($_template->smarty->autoload_filters[ 'output' ]) || |
|
| 66 | + isset($_template->smarty->registered_filters[ 'output' ])) |
|
| 67 | + ) { |
|
| 68 | + $content = $_template->smarty->ext->_filterHandler->runFilter('output', $content, $_template); |
|
| 69 | + } |
|
| 70 | + // write cache file content |
|
| 71 | + $this->writeCachedContent($cached, $_template, $content); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Cache was invalid , so render from compiled and write to cache |
|
| 76 | - * |
|
| 77 | - * @param \Smarty_Template_Cached $cached |
|
| 78 | - * @param \Smarty_Internal_Template $_template |
|
| 79 | - * @param $no_output_filter |
|
| 80 | - * |
|
| 81 | - * @throws \Exception |
|
| 82 | - */ |
|
| 83 | - public function updateCache(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $no_output_filter) |
|
| 84 | - { |
|
| 85 | - ob_start(); |
|
| 86 | - if (!isset($_template->compiled)) { |
|
| 87 | - $_template->loadCompiled(); |
|
| 88 | - } |
|
| 89 | - $_template->compiled->render($_template); |
|
| 90 | - if ($_template->smarty->debugging) { |
|
| 91 | - $_template->smarty->_debug->start_cache($_template); |
|
| 92 | - } |
|
| 93 | - $this->removeNoCacheHash($cached, $_template, $no_output_filter); |
|
| 94 | - $compile_check = $_template->smarty->compile_check; |
|
| 95 | - $_template->smarty->compile_check = false; |
|
| 96 | - if (isset($_template->parent) && $_template->parent->_objType == 2) { |
|
| 97 | - $_template->compiled->unifunc = $_template->parent->compiled->unifunc; |
|
| 98 | - } |
|
| 99 | - if (!$_template->cached->processed) { |
|
| 100 | - $_template->cached->process($_template, true); |
|
| 101 | - } |
|
| 102 | - $_template->smarty->compile_check = $compile_check; |
|
| 103 | - $cached->getRenderedTemplateCode($_template); |
|
| 104 | - if ($_template->smarty->debugging) { |
|
| 105 | - $_template->smarty->_debug->end_cache($_template); |
|
| 106 | - } |
|
| 107 | - } |
|
| 74 | + /** |
|
| 75 | + * Cache was invalid , so render from compiled and write to cache |
|
| 76 | + * |
|
| 77 | + * @param \Smarty_Template_Cached $cached |
|
| 78 | + * @param \Smarty_Internal_Template $_template |
|
| 79 | + * @param $no_output_filter |
|
| 80 | + * |
|
| 81 | + * @throws \Exception |
|
| 82 | + */ |
|
| 83 | + public function updateCache(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $no_output_filter) |
|
| 84 | + { |
|
| 85 | + ob_start(); |
|
| 86 | + if (!isset($_template->compiled)) { |
|
| 87 | + $_template->loadCompiled(); |
|
| 88 | + } |
|
| 89 | + $_template->compiled->render($_template); |
|
| 90 | + if ($_template->smarty->debugging) { |
|
| 91 | + $_template->smarty->_debug->start_cache($_template); |
|
| 92 | + } |
|
| 93 | + $this->removeNoCacheHash($cached, $_template, $no_output_filter); |
|
| 94 | + $compile_check = $_template->smarty->compile_check; |
|
| 95 | + $_template->smarty->compile_check = false; |
|
| 96 | + if (isset($_template->parent) && $_template->parent->_objType == 2) { |
|
| 97 | + $_template->compiled->unifunc = $_template->parent->compiled->unifunc; |
|
| 98 | + } |
|
| 99 | + if (!$_template->cached->processed) { |
|
| 100 | + $_template->cached->process($_template, true); |
|
| 101 | + } |
|
| 102 | + $_template->smarty->compile_check = $compile_check; |
|
| 103 | + $cached->getRenderedTemplateCode($_template); |
|
| 104 | + if ($_template->smarty->debugging) { |
|
| 105 | + $_template->smarty->_debug->end_cache($_template); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Writes the content to cache resource |
|
| 111 | - * |
|
| 112 | - * @param \Smarty_Template_Cached $cached |
|
| 113 | - * @param Smarty_Internal_Template $_template |
|
| 114 | - * @param string $content |
|
| 115 | - * |
|
| 116 | - * @return bool |
|
| 117 | - */ |
|
| 118 | - public function writeCachedContent(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content) |
|
| 119 | - { |
|
| 120 | - if ($_template->source->handler->recompiled || !($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || |
|
| 121 | - $_template->caching == Smarty::CACHING_LIFETIME_SAVED) |
|
| 122 | - ) { |
|
| 123 | - // don't write cache file |
|
| 124 | - return false; |
|
| 125 | - } |
|
| 126 | - $content = $_template->smarty->ext->_codeFrame->create($_template, $content, '', true); |
|
| 127 | - return $this->write($cached, $_template, $content); |
|
| 128 | - } |
|
| 109 | + /** |
|
| 110 | + * Writes the content to cache resource |
|
| 111 | + * |
|
| 112 | + * @param \Smarty_Template_Cached $cached |
|
| 113 | + * @param Smarty_Internal_Template $_template |
|
| 114 | + * @param string $content |
|
| 115 | + * |
|
| 116 | + * @return bool |
|
| 117 | + */ |
|
| 118 | + public function writeCachedContent(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content) |
|
| 119 | + { |
|
| 120 | + if ($_template->source->handler->recompiled || !($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || |
|
| 121 | + $_template->caching == Smarty::CACHING_LIFETIME_SAVED) |
|
| 122 | + ) { |
|
| 123 | + // don't write cache file |
|
| 124 | + return false; |
|
| 125 | + } |
|
| 126 | + $content = $_template->smarty->ext->_codeFrame->create($_template, $content, '', true); |
|
| 127 | + return $this->write($cached, $_template, $content); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Write this cache object to handler |
|
| 132 | - * |
|
| 133 | - * @param \Smarty_Template_Cached $cached |
|
| 134 | - * @param Smarty_Internal_Template $_template template object |
|
| 135 | - * @param string $content content to cache |
|
| 136 | - * |
|
| 137 | - * @return bool success |
|
| 138 | - */ |
|
| 139 | - public function write(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content) |
|
| 140 | - { |
|
| 141 | - if (!$_template->source->handler->recompiled) { |
|
| 142 | - if ($cached->handler->writeCachedContent($_template, $content)) { |
|
| 143 | - $cached->content = null; |
|
| 144 | - $cached->timestamp = time(); |
|
| 145 | - $cached->exists = true; |
|
| 146 | - $cached->valid = true; |
|
| 147 | - $cached->cache_lifetime = $_template->cache_lifetime; |
|
| 148 | - $cached->processed = false; |
|
| 149 | - if ($_template->smarty->cache_locking) { |
|
| 150 | - $cached->handler->releaseLock($_template->smarty, $cached); |
|
| 151 | - } |
|
| 130 | + /** |
|
| 131 | + * Write this cache object to handler |
|
| 132 | + * |
|
| 133 | + * @param \Smarty_Template_Cached $cached |
|
| 134 | + * @param Smarty_Internal_Template $_template template object |
|
| 135 | + * @param string $content content to cache |
|
| 136 | + * |
|
| 137 | + * @return bool success |
|
| 138 | + */ |
|
| 139 | + public function write(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content) |
|
| 140 | + { |
|
| 141 | + if (!$_template->source->handler->recompiled) { |
|
| 142 | + if ($cached->handler->writeCachedContent($_template, $content)) { |
|
| 143 | + $cached->content = null; |
|
| 144 | + $cached->timestamp = time(); |
|
| 145 | + $cached->exists = true; |
|
| 146 | + $cached->valid = true; |
|
| 147 | + $cached->cache_lifetime = $_template->cache_lifetime; |
|
| 148 | + $cached->processed = false; |
|
| 149 | + if ($_template->smarty->cache_locking) { |
|
| 150 | + $cached->handler->releaseLock($_template->smarty, $cached); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return true; |
|
| 154 | - } |
|
| 155 | - $cached->content = null; |
|
| 156 | - $cached->timestamp = false; |
|
| 157 | - $cached->exists = false; |
|
| 158 | - $cached->valid = false; |
|
| 159 | - $cached->processed = false; |
|
| 160 | - } |
|
| 153 | + return true; |
|
| 154 | + } |
|
| 155 | + $cached->content = null; |
|
| 156 | + $cached->timestamp = false; |
|
| 157 | + $cached->exists = false; |
|
| 158 | + $cached->valid = false; |
|
| 159 | + $cached->processed = false; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return false; |
|
| 163 | - } |
|
| 162 | + return false; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | 165 | } |
| 166 | 166 | \ No newline at end of file |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $no_output_filter) |
| 35 | 35 | { |
| 36 | 36 | $content = ob_get_clean(); |
| 37 | - unset($cached->hashes[ $_template->compiled->nocache_hash ]); |
|
| 37 | + unset($cached->hashes[$_template->compiled->nocache_hash]); |
|
| 38 | 38 | if (!empty($cached->hashes)) { |
| 39 | 39 | $hash_array = array(); |
| 40 | 40 | foreach ($cached->hashes as $hash => $foo) { |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | // escape PHP tags in template content |
| 57 | 57 | $content .= preg_replace('/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/', |
| 58 | 58 | "<?php echo '\$1'; ?>\n", $curr_split); |
| 59 | - if (isset($cache_parts[ 0 ][ $curr_idx ])) { |
|
| 59 | + if (isset($cache_parts[0][$curr_idx])) { |
|
| 60 | 60 | $_template->cached->has_nocache_code = true; |
| 61 | - $content .= $cache_parts[ 1 ][ $curr_idx ]; |
|
| 61 | + $content .= $cache_parts[1][$curr_idx]; |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | if (!$no_output_filter && !$_template->cached->has_nocache_code && |
| 65 | - (isset($_template->smarty->autoload_filters[ 'output' ]) || |
|
| 66 | - isset($_template->smarty->registered_filters[ 'output' ])) |
|
| 65 | + (isset($_template->smarty->autoload_filters['output']) || |
|
| 66 | + isset($_template->smarty->registered_filters['output'])) |
|
| 67 | 67 | ) { |
| 68 | 68 | $content = $_template->smarty->ext->_filterHandler->runFilter('output', $content, $_template); |
| 69 | 69 | } |
@@ -79,7 +79,7 @@ |
||
| 79 | 79 | * @param mixed $_content template source |
| 80 | 80 | * @param bool $isTemplateSource |
| 81 | 81 | * |
| 82 | - * @return bool true if compiling succeeded, false if it failed |
|
| 82 | + * @return string true if compiling succeeded, false if it failed |
|
| 83 | 83 | * @throws \SmartyCompilerException |
| 84 | 84 | */ |
| 85 | 85 | protected function doCompile($_content, $isTemplateSource = false) |
@@ -16,155 +16,155 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCompilerBase |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Lexer class name |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - public $lexer_class; |
|
| 19 | + /** |
|
| 20 | + * Lexer class name |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + public $lexer_class; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Parser class name |
|
| 28 | - * |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - public $parser_class; |
|
| 26 | + /** |
|
| 27 | + * Parser class name |
|
| 28 | + * |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + public $parser_class; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * array of vars which can be compiled in local scope |
|
| 35 | - * |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - public $local_var = array(); |
|
| 33 | + /** |
|
| 34 | + * array of vars which can be compiled in local scope |
|
| 35 | + * |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + public $local_var = array(); |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * array of callbacks called when the normal compile process of template is finished |
|
| 42 | - * |
|
| 43 | - * @var array |
|
| 44 | - */ |
|
| 45 | - public $postCompileCallbacks = array(); |
|
| 40 | + /** |
|
| 41 | + * array of callbacks called when the normal compile process of template is finished |
|
| 42 | + * |
|
| 43 | + * @var array |
|
| 44 | + */ |
|
| 45 | + public $postCompileCallbacks = array(); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * prefix code |
|
| 49 | - * |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - public $prefixCompiledCode = ''; |
|
| 47 | + /** |
|
| 48 | + * prefix code |
|
| 49 | + * |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + public $prefixCompiledCode = ''; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * postfix code |
|
| 56 | - * |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - public $postfixCompiledCode = ''; |
|
| 54 | + /** |
|
| 55 | + * postfix code |
|
| 56 | + * |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + public $postfixCompiledCode = ''; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Initialize compiler |
|
| 63 | - * |
|
| 64 | - * @param string $lexer_class class name |
|
| 65 | - * @param string $parser_class class name |
|
| 66 | - * @param Smarty $smarty global instance |
|
| 67 | - */ |
|
| 68 | - public function __construct($lexer_class, $parser_class, Smarty $smarty) |
|
| 69 | - { |
|
| 70 | - parent::__construct($smarty); |
|
| 71 | - // get required plugins |
|
| 72 | - $this->lexer_class = $lexer_class; |
|
| 73 | - $this->parser_class = $parser_class; |
|
| 74 | - } |
|
| 61 | + /** |
|
| 62 | + * Initialize compiler |
|
| 63 | + * |
|
| 64 | + * @param string $lexer_class class name |
|
| 65 | + * @param string $parser_class class name |
|
| 66 | + * @param Smarty $smarty global instance |
|
| 67 | + */ |
|
| 68 | + public function __construct($lexer_class, $parser_class, Smarty $smarty) |
|
| 69 | + { |
|
| 70 | + parent::__construct($smarty); |
|
| 71 | + // get required plugins |
|
| 72 | + $this->lexer_class = $lexer_class; |
|
| 73 | + $this->parser_class = $parser_class; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * method to compile a Smarty template |
|
| 78 | - * |
|
| 79 | - * @param mixed $_content template source |
|
| 80 | - * @param bool $isTemplateSource |
|
| 81 | - * |
|
| 82 | - * @return bool true if compiling succeeded, false if it failed |
|
| 83 | - * @throws \SmartyCompilerException |
|
| 84 | - */ |
|
| 85 | - protected function doCompile($_content, $isTemplateSource = false) |
|
| 86 | - { |
|
| 87 | - /* here is where the compiling takes place. Smarty |
|
| 76 | + /** |
|
| 77 | + * method to compile a Smarty template |
|
| 78 | + * |
|
| 79 | + * @param mixed $_content template source |
|
| 80 | + * @param bool $isTemplateSource |
|
| 81 | + * |
|
| 82 | + * @return bool true if compiling succeeded, false if it failed |
|
| 83 | + * @throws \SmartyCompilerException |
|
| 84 | + */ |
|
| 85 | + protected function doCompile($_content, $isTemplateSource = false) |
|
| 86 | + { |
|
| 87 | + /* here is where the compiling takes place. Smarty |
|
| 88 | 88 | tags in the templates are replaces with PHP code, |
| 89 | 89 | then written to compiled files. */ |
| 90 | - // init the lexer/parser to compile the template |
|
| 91 | - $this->parser = |
|
| 92 | - new $this->parser_class(new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $_content), $this), |
|
| 93 | - $this); |
|
| 94 | - if ($isTemplateSource && $this->template->caching) { |
|
| 95 | - $this->parser->insertPhpCode("<?php\n\$_smarty_tpl->compiled->nocache_hash = '{$this->nocache_hash}';\n?>\n"); |
|
| 96 | - } |
|
| 97 | - if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { |
|
| 98 | - $mbEncoding = mb_internal_encoding(); |
|
| 99 | - mb_internal_encoding('ASCII'); |
|
| 100 | - } else { |
|
| 101 | - $mbEncoding = null; |
|
| 102 | - } |
|
| 90 | + // init the lexer/parser to compile the template |
|
| 91 | + $this->parser = |
|
| 92 | + new $this->parser_class(new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $_content), $this), |
|
| 93 | + $this); |
|
| 94 | + if ($isTemplateSource && $this->template->caching) { |
|
| 95 | + $this->parser->insertPhpCode("<?php\n\$_smarty_tpl->compiled->nocache_hash = '{$this->nocache_hash}';\n?>\n"); |
|
| 96 | + } |
|
| 97 | + if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { |
|
| 98 | + $mbEncoding = mb_internal_encoding(); |
|
| 99 | + mb_internal_encoding('ASCII'); |
|
| 100 | + } else { |
|
| 101 | + $mbEncoding = null; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - if ($this->smarty->_parserdebug) { |
|
| 105 | - $this->parser->PrintTrace(); |
|
| 106 | - $this->parser->lex->PrintTrace(); |
|
| 107 | - } |
|
| 108 | - // get tokens from lexer and parse them |
|
| 109 | - while ($this->parser->lex->yylex()) { |
|
| 110 | - if ($this->smarty->_parserdebug) { |
|
| 111 | - echo "<pre>Line {$this->parser->lex->line} Parsing {$this->parser->yyTokenName[$this->parser->lex->token]} Token " . |
|
| 112 | - htmlentities($this->parser->lex->value) . "</pre>"; |
|
| 113 | - } |
|
| 114 | - $this->parser->doParse($this->parser->lex->token, $this->parser->lex->value); |
|
| 115 | - } |
|
| 104 | + if ($this->smarty->_parserdebug) { |
|
| 105 | + $this->parser->PrintTrace(); |
|
| 106 | + $this->parser->lex->PrintTrace(); |
|
| 107 | + } |
|
| 108 | + // get tokens from lexer and parse them |
|
| 109 | + while ($this->parser->lex->yylex()) { |
|
| 110 | + if ($this->smarty->_parserdebug) { |
|
| 111 | + echo "<pre>Line {$this->parser->lex->line} Parsing {$this->parser->yyTokenName[$this->parser->lex->token]} Token " . |
|
| 112 | + htmlentities($this->parser->lex->value) . "</pre>"; |
|
| 113 | + } |
|
| 114 | + $this->parser->doParse($this->parser->lex->token, $this->parser->lex->value); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - // finish parsing process |
|
| 118 | - $this->parser->doParse(0, 0); |
|
| 119 | - if ($mbEncoding) { |
|
| 120 | - mb_internal_encoding($mbEncoding); |
|
| 121 | - } |
|
| 122 | - // check for unclosed tags |
|
| 123 | - if (count($this->_tag_stack) > 0) { |
|
| 124 | - // get stacked info |
|
| 125 | - list($openTag, $_data) = array_pop($this->_tag_stack); |
|
| 126 | - $this->trigger_template_error("unclosed {$this->smarty->left_delimiter}" . $openTag . |
|
| 127 | - "{$this->smarty->right_delimiter} tag"); |
|
| 128 | - } |
|
| 129 | - // call post compile callbacks |
|
| 130 | - foreach ($this->postCompileCallbacks as $cb) { |
|
| 131 | - $parameter = $cb; |
|
| 132 | - $parameter[ 0 ] = $this; |
|
| 133 | - call_user_func_array($cb[ 0 ], $parameter); |
|
| 134 | - } |
|
| 135 | - // return compiled code |
|
| 136 | - return $this->prefixCompiledCode . $this->parser->retvalue . $this->postfixCompiledCode; |
|
| 137 | - } |
|
| 117 | + // finish parsing process |
|
| 118 | + $this->parser->doParse(0, 0); |
|
| 119 | + if ($mbEncoding) { |
|
| 120 | + mb_internal_encoding($mbEncoding); |
|
| 121 | + } |
|
| 122 | + // check for unclosed tags |
|
| 123 | + if (count($this->_tag_stack) > 0) { |
|
| 124 | + // get stacked info |
|
| 125 | + list($openTag, $_data) = array_pop($this->_tag_stack); |
|
| 126 | + $this->trigger_template_error("unclosed {$this->smarty->left_delimiter}" . $openTag . |
|
| 127 | + "{$this->smarty->right_delimiter} tag"); |
|
| 128 | + } |
|
| 129 | + // call post compile callbacks |
|
| 130 | + foreach ($this->postCompileCallbacks as $cb) { |
|
| 131 | + $parameter = $cb; |
|
| 132 | + $parameter[ 0 ] = $this; |
|
| 133 | + call_user_func_array($cb[ 0 ], $parameter); |
|
| 134 | + } |
|
| 135 | + // return compiled code |
|
| 136 | + return $this->prefixCompiledCode . $this->parser->retvalue . $this->postfixCompiledCode; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Register a post compile callback |
|
| 141 | - * - when the callback is called after template compiling the compiler object will be inserted as first parameter |
|
| 142 | - * |
|
| 143 | - * @param callback $callback |
|
| 144 | - * @param array $parameter optional parameter array |
|
| 145 | - * @param string $key optional key for callback |
|
| 146 | - * @param bool $replace if true replace existing keyed callback |
|
| 147 | - * |
|
| 148 | - */ |
|
| 149 | - public function registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false) |
|
| 150 | - { |
|
| 151 | - array_unshift($parameter, $callback); |
|
| 152 | - if (isset($key)) { |
|
| 153 | - if ($replace || !isset($this->postCompileCallbacks[ $key ])) { |
|
| 154 | - $this->postCompileCallbacks[ $key ] = $parameter; |
|
| 155 | - } |
|
| 156 | - } else { |
|
| 157 | - $this->postCompileCallbacks[] = $parameter; |
|
| 158 | - } |
|
| 159 | - } |
|
| 139 | + /** |
|
| 140 | + * Register a post compile callback |
|
| 141 | + * - when the callback is called after template compiling the compiler object will be inserted as first parameter |
|
| 142 | + * |
|
| 143 | + * @param callback $callback |
|
| 144 | + * @param array $parameter optional parameter array |
|
| 145 | + * @param string $key optional key for callback |
|
| 146 | + * @param bool $replace if true replace existing keyed callback |
|
| 147 | + * |
|
| 148 | + */ |
|
| 149 | + public function registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false) |
|
| 150 | + { |
|
| 151 | + array_unshift($parameter, $callback); |
|
| 152 | + if (isset($key)) { |
|
| 153 | + if ($replace || !isset($this->postCompileCallbacks[ $key ])) { |
|
| 154 | + $this->postCompileCallbacks[ $key ] = $parameter; |
|
| 155 | + } |
|
| 156 | + } else { |
|
| 157 | + $this->postCompileCallbacks[] = $parameter; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Remove a post compile callback |
|
| 163 | - * |
|
| 164 | - * @param string $key callback key |
|
| 165 | - */ |
|
| 166 | - public function unregisterPostCompileCallback($key) |
|
| 167 | - { |
|
| 168 | - unset($this->postCompileCallbacks[ $key ]); |
|
| 169 | - } |
|
| 161 | + /** |
|
| 162 | + * Remove a post compile callback |
|
| 163 | + * |
|
| 164 | + * @param string $key callback key |
|
| 165 | + */ |
|
| 166 | + public function unregisterPostCompileCallback($key) |
|
| 167 | + { |
|
| 168 | + unset($this->postCompileCallbacks[ $key ]); |
|
| 169 | + } |
|
| 170 | 170 | } |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | // call post compile callbacks |
| 130 | 130 | foreach ($this->postCompileCallbacks as $cb) { |
| 131 | 131 | $parameter = $cb; |
| 132 | - $parameter[ 0 ] = $this; |
|
| 133 | - call_user_func_array($cb[ 0 ], $parameter); |
|
| 132 | + $parameter[0] = $this; |
|
| 133 | + call_user_func_array($cb[0], $parameter); |
|
| 134 | 134 | } |
| 135 | 135 | // return compiled code |
| 136 | 136 | return $this->prefixCompiledCode . $this->parser->retvalue . $this->postfixCompiledCode; |
@@ -150,8 +150,8 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | array_unshift($parameter, $callback); |
| 152 | 152 | if (isset($key)) { |
| 153 | - if ($replace || !isset($this->postCompileCallbacks[ $key ])) { |
|
| 154 | - $this->postCompileCallbacks[ $key ] = $parameter; |
|
| 153 | + if ($replace || !isset($this->postCompileCallbacks[$key])) { |
|
| 154 | + $this->postCompileCallbacks[$key] = $parameter; |
|
| 155 | 155 | } |
| 156 | 156 | } else { |
| 157 | 157 | $this->postCompileCallbacks[] = $parameter; |
@@ -165,6 +165,6 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public function unregisterPostCompileCallback($key) |
| 167 | 167 | { |
| 168 | - unset($this->postCompileCallbacks[ $key ]); |
|
| 168 | + unset($this->postCompileCallbacks[$key]); |
|
| 169 | 169 | } |
| 170 | 170 | } |
@@ -120,9 +120,9 @@ |
||
| 120 | 120 | * @api Smarty::isCached() |
| 121 | 121 | * @link http://www.smarty.net/docs/en/api.is.cached.tpl |
| 122 | 122 | * |
| 123 | - * @param null|string|\Smarty_Internal_Template $template the resource handle of the template file or template object |
|
| 124 | - * @param mixed $cache_id cache id to be used with this template |
|
| 125 | - * @param mixed $compile_id compile id to be used with this template |
|
| 123 | + * @param string $template the resource handle of the template file or template object |
|
| 124 | + * @param string|null $cache_id cache id to be used with this template |
|
| 125 | + * @param string|null $compile_id compile id to be used with this template |
|
| 126 | 126 | * @param object $parent next higher level of Smarty variables |
| 127 | 127 | * |
| 128 | 128 | * @return boolean cache status |
@@ -45,294 +45,294 @@ |
||
| 45 | 45 | */ |
| 46 | 46 | abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data |
| 47 | 47 | { |
| 48 | - /** |
|
| 49 | - * Set this if you want different sets of cache files for the same |
|
| 50 | - * templates. |
|
| 51 | - * |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - public $cache_id = null; |
|
| 48 | + /** |
|
| 49 | + * Set this if you want different sets of cache files for the same |
|
| 50 | + * templates. |
|
| 51 | + * |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + public $cache_id = null; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Set this if you want different sets of compiled files for the same |
|
| 58 | - * templates. |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - public $compile_id = null; |
|
| 56 | + /** |
|
| 57 | + * Set this if you want different sets of compiled files for the same |
|
| 58 | + * templates. |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + public $compile_id = null; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * caching enabled |
|
| 66 | - * |
|
| 67 | - * @var boolean |
|
| 68 | - */ |
|
| 69 | - public $caching = false; |
|
| 64 | + /** |
|
| 65 | + * caching enabled |
|
| 66 | + * |
|
| 67 | + * @var boolean |
|
| 68 | + */ |
|
| 69 | + public $caching = false; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * cache lifetime in seconds |
|
| 73 | - * |
|
| 74 | - * @var integer |
|
| 75 | - */ |
|
| 76 | - public $cache_lifetime = 3600; |
|
| 71 | + /** |
|
| 72 | + * cache lifetime in seconds |
|
| 73 | + * |
|
| 74 | + * @var integer |
|
| 75 | + */ |
|
| 76 | + public $cache_lifetime = 3600; |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * universal cache |
|
| 80 | - * |
|
| 81 | - * @var array() |
|
| 82 | - */ |
|
| 83 | - public $_cache = array(); |
|
| 78 | + /** |
|
| 79 | + * universal cache |
|
| 80 | + * |
|
| 81 | + * @var array() |
|
| 82 | + */ |
|
| 83 | + public $_cache = array(); |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * fetches a rendered Smarty template |
|
| 87 | - * |
|
| 88 | - * @param string $template the resource handle of the template file or template object |
|
| 89 | - * @param mixed $cache_id cache id to be used with this template |
|
| 90 | - * @param mixed $compile_id compile id to be used with this template |
|
| 91 | - * @param object $parent next higher level of Smarty variables |
|
| 92 | - * |
|
| 93 | - * @throws Exception |
|
| 94 | - * @throws SmartyException |
|
| 95 | - * @return string rendered template output |
|
| 96 | - */ |
|
| 97 | - public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null) |
|
| 98 | - { |
|
| 99 | - $result = $this->_execute($template, $cache_id, $compile_id, $parent, 0); |
|
| 100 | - return $result === null ? ob_get_clean() : $result; |
|
| 101 | - } |
|
| 85 | + /** |
|
| 86 | + * fetches a rendered Smarty template |
|
| 87 | + * |
|
| 88 | + * @param string $template the resource handle of the template file or template object |
|
| 89 | + * @param mixed $cache_id cache id to be used with this template |
|
| 90 | + * @param mixed $compile_id compile id to be used with this template |
|
| 91 | + * @param object $parent next higher level of Smarty variables |
|
| 92 | + * |
|
| 93 | + * @throws Exception |
|
| 94 | + * @throws SmartyException |
|
| 95 | + * @return string rendered template output |
|
| 96 | + */ |
|
| 97 | + public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null) |
|
| 98 | + { |
|
| 99 | + $result = $this->_execute($template, $cache_id, $compile_id, $parent, 0); |
|
| 100 | + return $result === null ? ob_get_clean() : $result; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * displays a Smarty template |
|
| 105 | - * |
|
| 106 | - * @param string $template the resource handle of the template file or template object |
|
| 107 | - * @param mixed $cache_id cache id to be used with this template |
|
| 108 | - * @param mixed $compile_id compile id to be used with this template |
|
| 109 | - * @param object $parent next higher level of Smarty variables |
|
| 110 | - */ |
|
| 111 | - public function display($template = null, $cache_id = null, $compile_id = null, $parent = null) |
|
| 112 | - { |
|
| 113 | - // display template |
|
| 114 | - $this->_execute($template, $cache_id, $compile_id, $parent, 1); |
|
| 115 | - } |
|
| 103 | + /** |
|
| 104 | + * displays a Smarty template |
|
| 105 | + * |
|
| 106 | + * @param string $template the resource handle of the template file or template object |
|
| 107 | + * @param mixed $cache_id cache id to be used with this template |
|
| 108 | + * @param mixed $compile_id compile id to be used with this template |
|
| 109 | + * @param object $parent next higher level of Smarty variables |
|
| 110 | + */ |
|
| 111 | + public function display($template = null, $cache_id = null, $compile_id = null, $parent = null) |
|
| 112 | + { |
|
| 113 | + // display template |
|
| 114 | + $this->_execute($template, $cache_id, $compile_id, $parent, 1); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * test if cache is valid |
|
| 119 | - * |
|
| 120 | - * @api Smarty::isCached() |
|
| 121 | - * @link http://www.smarty.net/docs/en/api.is.cached.tpl |
|
| 122 | - * |
|
| 123 | - * @param null|string|\Smarty_Internal_Template $template the resource handle of the template file or template object |
|
| 124 | - * @param mixed $cache_id cache id to be used with this template |
|
| 125 | - * @param mixed $compile_id compile id to be used with this template |
|
| 126 | - * @param object $parent next higher level of Smarty variables |
|
| 127 | - * |
|
| 128 | - * @return boolean cache status |
|
| 129 | - */ |
|
| 130 | - public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null) |
|
| 131 | - { |
|
| 132 | - return $this->_execute($template, $cache_id, $compile_id, $parent, 2); |
|
| 133 | - } |
|
| 117 | + /** |
|
| 118 | + * test if cache is valid |
|
| 119 | + * |
|
| 120 | + * @api Smarty::isCached() |
|
| 121 | + * @link http://www.smarty.net/docs/en/api.is.cached.tpl |
|
| 122 | + * |
|
| 123 | + * @param null|string|\Smarty_Internal_Template $template the resource handle of the template file or template object |
|
| 124 | + * @param mixed $cache_id cache id to be used with this template |
|
| 125 | + * @param mixed $compile_id compile id to be used with this template |
|
| 126 | + * @param object $parent next higher level of Smarty variables |
|
| 127 | + * |
|
| 128 | + * @return boolean cache status |
|
| 129 | + */ |
|
| 130 | + public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null) |
|
| 131 | + { |
|
| 132 | + return $this->_execute($template, $cache_id, $compile_id, $parent, 2); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * fetches a rendered Smarty template |
|
| 137 | - * |
|
| 138 | - * @param string $template the resource handle of the template file or template object |
|
| 139 | - * @param mixed $cache_id cache id to be used with this template |
|
| 140 | - * @param mixed $compile_id compile id to be used with this template |
|
| 141 | - * @param object $parent next higher level of Smarty variables |
|
| 142 | - * @param string $function function type 0 = fetch, 1 = display, 2 = isCache |
|
| 143 | - * |
|
| 144 | - * @return mixed |
|
| 145 | - * @throws \Exception |
|
| 146 | - * @throws \SmartyException |
|
| 147 | - */ |
|
| 148 | - private function _execute($template, $cache_id, $compile_id, $parent, $function) |
|
| 149 | - { |
|
| 150 | - $smarty = $this->_objType == 1 ? $this : $this->smarty; |
|
| 151 | - $saveVars = true; |
|
| 152 | - if ($template === null) { |
|
| 153 | - if ($this->_objType != 2) { |
|
| 154 | - throw new SmartyException($function . '():Missing \'$template\' parameter'); |
|
| 155 | - } else { |
|
| 156 | - $template = $this; |
|
| 157 | - } |
|
| 158 | - } elseif (is_object($template)) { |
|
| 159 | - if (!isset($template->_objType) || $template->_objType != 2) { |
|
| 160 | - throw new SmartyException($function . '():Template object expected'); |
|
| 161 | - } |
|
| 162 | - } else { |
|
| 163 | - // get template object |
|
| 164 | - /* @var Smarty_Internal_Template $template */ |
|
| 165 | - $saveVars = false; |
|
| 135 | + /** |
|
| 136 | + * fetches a rendered Smarty template |
|
| 137 | + * |
|
| 138 | + * @param string $template the resource handle of the template file or template object |
|
| 139 | + * @param mixed $cache_id cache id to be used with this template |
|
| 140 | + * @param mixed $compile_id compile id to be used with this template |
|
| 141 | + * @param object $parent next higher level of Smarty variables |
|
| 142 | + * @param string $function function type 0 = fetch, 1 = display, 2 = isCache |
|
| 143 | + * |
|
| 144 | + * @return mixed |
|
| 145 | + * @throws \Exception |
|
| 146 | + * @throws \SmartyException |
|
| 147 | + */ |
|
| 148 | + private function _execute($template, $cache_id, $compile_id, $parent, $function) |
|
| 149 | + { |
|
| 150 | + $smarty = $this->_objType == 1 ? $this : $this->smarty; |
|
| 151 | + $saveVars = true; |
|
| 152 | + if ($template === null) { |
|
| 153 | + if ($this->_objType != 2) { |
|
| 154 | + throw new SmartyException($function . '():Missing \'$template\' parameter'); |
|
| 155 | + } else { |
|
| 156 | + $template = $this; |
|
| 157 | + } |
|
| 158 | + } elseif (is_object($template)) { |
|
| 159 | + if (!isset($template->_objType) || $template->_objType != 2) { |
|
| 160 | + throw new SmartyException($function . '():Template object expected'); |
|
| 161 | + } |
|
| 162 | + } else { |
|
| 163 | + // get template object |
|
| 164 | + /* @var Smarty_Internal_Template $template */ |
|
| 165 | + $saveVars = false; |
|
| 166 | 166 | |
| 167 | - $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false); |
|
| 168 | - if ($this->_objType == 1) { |
|
| 169 | - // set caching in template object |
|
| 170 | - $template->caching = $this->caching; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - // fetch template content |
|
| 174 | - $level = ob_get_level(); |
|
| 175 | - try { |
|
| 176 | - $_smarty_old_error_level = |
|
| 177 | - isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null; |
|
| 178 | - if ($function == 2) { |
|
| 179 | - if ($template->caching) { |
|
| 180 | - // return cache status of template |
|
| 181 | - if (!isset($template->cached)) { |
|
| 182 | - $template->loadCached(); |
|
| 183 | - } |
|
| 184 | - $result = $template->cached->isCached($template); |
|
| 185 | - $template->smarty->_cache[ 'isCached' ][ $template->_getTemplateId() ] = $template; |
|
| 186 | - } else { |
|
| 187 | - return false; |
|
| 188 | - } |
|
| 189 | - } else { |
|
| 190 | - if ($saveVars) { |
|
| 191 | - $savedTplVars = $template->tpl_vars; |
|
| 192 | - $savedConfigVars = $template->config_vars; |
|
| 193 | - } |
|
| 194 | - ob_start(); |
|
| 195 | - $template->_mergeVars(); |
|
| 196 | - if (!empty(Smarty::$global_tpl_vars)) { |
|
| 197 | - $template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars); |
|
| 198 | - } |
|
| 199 | - $result = $template->render(false, $function); |
|
| 200 | - $template->_cleanUp(); |
|
| 201 | - if ($saveVars) { |
|
| 202 | - $template->tpl_vars = $savedTplVars; |
|
| 203 | - $template->config_vars = $savedConfigVars; |
|
| 204 | - } else { |
|
| 205 | - if (!$function && !isset($smarty->_cache[ 'tplObjects' ][ $template->templateId ])) { |
|
| 206 | - $template->parent = null; |
|
| 207 | - $template->tpl_vars = $template->config_vars = array(); |
|
| 208 | - $smarty->_cache[ 'tplObjects' ][ $template->templateId ] = $template; |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - if (isset($_smarty_old_error_level)) { |
|
| 213 | - error_reporting($_smarty_old_error_level); |
|
| 214 | - } |
|
| 215 | - return $result; |
|
| 216 | - } |
|
| 217 | - catch (Exception $e) { |
|
| 218 | - while (ob_get_level() > $level) { |
|
| 219 | - ob_end_clean(); |
|
| 220 | - } |
|
| 221 | - if (isset($_smarty_old_error_level)) { |
|
| 222 | - error_reporting($_smarty_old_error_level); |
|
| 223 | - } |
|
| 224 | - throw $e; |
|
| 225 | - } |
|
| 226 | - } |
|
| 167 | + $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false); |
|
| 168 | + if ($this->_objType == 1) { |
|
| 169 | + // set caching in template object |
|
| 170 | + $template->caching = $this->caching; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + // fetch template content |
|
| 174 | + $level = ob_get_level(); |
|
| 175 | + try { |
|
| 176 | + $_smarty_old_error_level = |
|
| 177 | + isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null; |
|
| 178 | + if ($function == 2) { |
|
| 179 | + if ($template->caching) { |
|
| 180 | + // return cache status of template |
|
| 181 | + if (!isset($template->cached)) { |
|
| 182 | + $template->loadCached(); |
|
| 183 | + } |
|
| 184 | + $result = $template->cached->isCached($template); |
|
| 185 | + $template->smarty->_cache[ 'isCached' ][ $template->_getTemplateId() ] = $template; |
|
| 186 | + } else { |
|
| 187 | + return false; |
|
| 188 | + } |
|
| 189 | + } else { |
|
| 190 | + if ($saveVars) { |
|
| 191 | + $savedTplVars = $template->tpl_vars; |
|
| 192 | + $savedConfigVars = $template->config_vars; |
|
| 193 | + } |
|
| 194 | + ob_start(); |
|
| 195 | + $template->_mergeVars(); |
|
| 196 | + if (!empty(Smarty::$global_tpl_vars)) { |
|
| 197 | + $template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars); |
|
| 198 | + } |
|
| 199 | + $result = $template->render(false, $function); |
|
| 200 | + $template->_cleanUp(); |
|
| 201 | + if ($saveVars) { |
|
| 202 | + $template->tpl_vars = $savedTplVars; |
|
| 203 | + $template->config_vars = $savedConfigVars; |
|
| 204 | + } else { |
|
| 205 | + if (!$function && !isset($smarty->_cache[ 'tplObjects' ][ $template->templateId ])) { |
|
| 206 | + $template->parent = null; |
|
| 207 | + $template->tpl_vars = $template->config_vars = array(); |
|
| 208 | + $smarty->_cache[ 'tplObjects' ][ $template->templateId ] = $template; |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + if (isset($_smarty_old_error_level)) { |
|
| 213 | + error_reporting($_smarty_old_error_level); |
|
| 214 | + } |
|
| 215 | + return $result; |
|
| 216 | + } |
|
| 217 | + catch (Exception $e) { |
|
| 218 | + while (ob_get_level() > $level) { |
|
| 219 | + ob_end_clean(); |
|
| 220 | + } |
|
| 221 | + if (isset($_smarty_old_error_level)) { |
|
| 222 | + error_reporting($_smarty_old_error_level); |
|
| 223 | + } |
|
| 224 | + throw $e; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * Registers plugin to be used in templates |
|
| 230 | - * |
|
| 231 | - * @api Smarty::registerPlugin() |
|
| 232 | - * @link http://www.smarty.net/docs/en/api.register.plugin.tpl |
|
| 233 | - * |
|
| 234 | - * @param string $type plugin type |
|
| 235 | - * @param string $name name of template tag |
|
| 236 | - * @param callback $callback PHP callback to register |
|
| 237 | - * @param bool $cacheable if true (default) this function is cache able |
|
| 238 | - * @param mixed $cache_attr caching attributes if any |
|
| 239 | - * |
|
| 240 | - * @return \Smarty|\Smarty_Internal_Template |
|
| 241 | - * @throws SmartyException when the plugin tag is invalid |
|
| 242 | - */ |
|
| 243 | - public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null) |
|
| 244 | - { |
|
| 245 | - return $this->ext->registerPlugin->registerPlugin($this, $type, $name, $callback, $cacheable, $cache_attr); |
|
| 246 | - } |
|
| 228 | + /** |
|
| 229 | + * Registers plugin to be used in templates |
|
| 230 | + * |
|
| 231 | + * @api Smarty::registerPlugin() |
|
| 232 | + * @link http://www.smarty.net/docs/en/api.register.plugin.tpl |
|
| 233 | + * |
|
| 234 | + * @param string $type plugin type |
|
| 235 | + * @param string $name name of template tag |
|
| 236 | + * @param callback $callback PHP callback to register |
|
| 237 | + * @param bool $cacheable if true (default) this function is cache able |
|
| 238 | + * @param mixed $cache_attr caching attributes if any |
|
| 239 | + * |
|
| 240 | + * @return \Smarty|\Smarty_Internal_Template |
|
| 241 | + * @throws SmartyException when the plugin tag is invalid |
|
| 242 | + */ |
|
| 243 | + public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null) |
|
| 244 | + { |
|
| 245 | + return $this->ext->registerPlugin->registerPlugin($this, $type, $name, $callback, $cacheable, $cache_attr); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * load a filter of specified type and name |
|
| 250 | - * |
|
| 251 | - * @api Smarty::loadFilter() |
|
| 252 | - * @link http://www.smarty.net/docs/en/api.load.filter.tpl |
|
| 253 | - * |
|
| 254 | - * @param string $type filter type |
|
| 255 | - * @param string $name filter name |
|
| 256 | - * |
|
| 257 | - * @return bool |
|
| 258 | - * @throws SmartyException if filter could not be loaded |
|
| 259 | - */ |
|
| 260 | - public function loadFilter($type, $name) |
|
| 261 | - { |
|
| 262 | - return $this->ext->loadFilter->loadFilter($this, $type, $name); |
|
| 263 | - } |
|
| 248 | + /** |
|
| 249 | + * load a filter of specified type and name |
|
| 250 | + * |
|
| 251 | + * @api Smarty::loadFilter() |
|
| 252 | + * @link http://www.smarty.net/docs/en/api.load.filter.tpl |
|
| 253 | + * |
|
| 254 | + * @param string $type filter type |
|
| 255 | + * @param string $name filter name |
|
| 256 | + * |
|
| 257 | + * @return bool |
|
| 258 | + * @throws SmartyException if filter could not be loaded |
|
| 259 | + */ |
|
| 260 | + public function loadFilter($type, $name) |
|
| 261 | + { |
|
| 262 | + return $this->ext->loadFilter->loadFilter($this, $type, $name); |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * Registers a filter function |
|
| 267 | - * |
|
| 268 | - * @api Smarty::registerFilter() |
|
| 269 | - * @link http://www.smarty.net/docs/en/api.register.filter.tpl |
|
| 270 | - * |
|
| 271 | - * @param string $type filter type |
|
| 272 | - * @param callback $callback |
|
| 273 | - * @param string|null $name optional filter name |
|
| 274 | - * |
|
| 275 | - * @return \Smarty|\Smarty_Internal_Template |
|
| 276 | - * @throws \SmartyException |
|
| 277 | - */ |
|
| 278 | - public function registerFilter($type, $callback, $name = null) |
|
| 279 | - { |
|
| 280 | - return $this->ext->registerFilter->registerFilter($this, $type, $callback, $name); |
|
| 281 | - } |
|
| 265 | + /** |
|
| 266 | + * Registers a filter function |
|
| 267 | + * |
|
| 268 | + * @api Smarty::registerFilter() |
|
| 269 | + * @link http://www.smarty.net/docs/en/api.register.filter.tpl |
|
| 270 | + * |
|
| 271 | + * @param string $type filter type |
|
| 272 | + * @param callback $callback |
|
| 273 | + * @param string|null $name optional filter name |
|
| 274 | + * |
|
| 275 | + * @return \Smarty|\Smarty_Internal_Template |
|
| 276 | + * @throws \SmartyException |
|
| 277 | + */ |
|
| 278 | + public function registerFilter($type, $callback, $name = null) |
|
| 279 | + { |
|
| 280 | + return $this->ext->registerFilter->registerFilter($this, $type, $callback, $name); |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * Registers object to be used in templates |
|
| 285 | - * |
|
| 286 | - * @api Smarty::registerObject() |
|
| 287 | - * @link http://www.smarty.net/docs/en/api.register.object.tpl |
|
| 288 | - * |
|
| 289 | - * @param string $object_name |
|
| 290 | - * @param object $object the referenced PHP object to register |
|
| 291 | - * @param array $allowed_methods_properties list of allowed methods (empty = all) |
|
| 292 | - * @param bool $format smarty argument format, else traditional |
|
| 293 | - * @param array $block_methods list of block-methods |
|
| 294 | - * |
|
| 295 | - * @return \Smarty|\Smarty_Internal_Template |
|
| 296 | - * @throws \SmartyException |
|
| 297 | - */ |
|
| 298 | - public function registerObject($object_name, $object, $allowed_methods_properties = array(), $format = true, |
|
| 299 | - $block_methods = array()) |
|
| 300 | - { |
|
| 301 | - return $this->ext->registerObject->registerObject($this, $object_name, $object, $allowed_methods_properties, |
|
| 302 | - $format, $block_methods); |
|
| 303 | - } |
|
| 283 | + /** |
|
| 284 | + * Registers object to be used in templates |
|
| 285 | + * |
|
| 286 | + * @api Smarty::registerObject() |
|
| 287 | + * @link http://www.smarty.net/docs/en/api.register.object.tpl |
|
| 288 | + * |
|
| 289 | + * @param string $object_name |
|
| 290 | + * @param object $object the referenced PHP object to register |
|
| 291 | + * @param array $allowed_methods_properties list of allowed methods (empty = all) |
|
| 292 | + * @param bool $format smarty argument format, else traditional |
|
| 293 | + * @param array $block_methods list of block-methods |
|
| 294 | + * |
|
| 295 | + * @return \Smarty|\Smarty_Internal_Template |
|
| 296 | + * @throws \SmartyException |
|
| 297 | + */ |
|
| 298 | + public function registerObject($object_name, $object, $allowed_methods_properties = array(), $format = true, |
|
| 299 | + $block_methods = array()) |
|
| 300 | + { |
|
| 301 | + return $this->ext->registerObject->registerObject($this, $object_name, $object, $allowed_methods_properties, |
|
| 302 | + $format, $block_methods); |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | - /** |
|
| 306 | - * @param boolean $caching |
|
| 307 | - */ |
|
| 308 | - public function setCaching($caching) |
|
| 309 | - { |
|
| 310 | - $this->caching = $caching; |
|
| 311 | - } |
|
| 305 | + /** |
|
| 306 | + * @param boolean $caching |
|
| 307 | + */ |
|
| 308 | + public function setCaching($caching) |
|
| 309 | + { |
|
| 310 | + $this->caching = $caching; |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - /** |
|
| 314 | - * @param int $cache_lifetime |
|
| 315 | - */ |
|
| 316 | - public function setCacheLifetime($cache_lifetime) |
|
| 317 | - { |
|
| 318 | - $this->cache_lifetime = $cache_lifetime; |
|
| 319 | - } |
|
| 313 | + /** |
|
| 314 | + * @param int $cache_lifetime |
|
| 315 | + */ |
|
| 316 | + public function setCacheLifetime($cache_lifetime) |
|
| 317 | + { |
|
| 318 | + $this->cache_lifetime = $cache_lifetime; |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | - /** |
|
| 322 | - * @param string $compile_id |
|
| 323 | - */ |
|
| 324 | - public function setCompileId($compile_id) |
|
| 325 | - { |
|
| 326 | - $this->compile_id = $compile_id; |
|
| 327 | - } |
|
| 321 | + /** |
|
| 322 | + * @param string $compile_id |
|
| 323 | + */ |
|
| 324 | + public function setCompileId($compile_id) |
|
| 325 | + { |
|
| 326 | + $this->compile_id = $compile_id; |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - /** |
|
| 330 | - * @param string $cache_id |
|
| 331 | - */ |
|
| 332 | - public function setCacheId($cache_id) |
|
| 333 | - { |
|
| 334 | - $this->cache_id = $cache_id; |
|
| 335 | - } |
|
| 329 | + /** |
|
| 330 | + * @param string $cache_id |
|
| 331 | + */ |
|
| 332 | + public function setCacheId($cache_id) |
|
| 333 | + { |
|
| 334 | + $this->cache_id = $cache_id; |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | 337 | } |
| 338 | 338 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | $template->loadCached(); |
| 183 | 183 | } |
| 184 | 184 | $result = $template->cached->isCached($template); |
| 185 | - $template->smarty->_cache[ 'isCached' ][ $template->_getTemplateId() ] = $template; |
|
| 185 | + $template->smarty->_cache['isCached'][$template->_getTemplateId()] = $template; |
|
| 186 | 186 | } else { |
| 187 | 187 | return false; |
| 188 | 188 | } |
@@ -202,10 +202,10 @@ discard block |
||
| 202 | 202 | $template->tpl_vars = $savedTplVars; |
| 203 | 203 | $template->config_vars = $savedConfigVars; |
| 204 | 204 | } else { |
| 205 | - if (!$function && !isset($smarty->_cache[ 'tplObjects' ][ $template->templateId ])) { |
|
| 205 | + if (!$function && !isset($smarty->_cache['tplObjects'][$template->templateId])) { |
|
| 206 | 206 | $template->parent = null; |
| 207 | 207 | $template->tpl_vars = $template->config_vars = array(); |
| 208 | - $smarty->_cache[ 'tplObjects' ][ $template->templateId ] = $template; |
|
| 208 | + $smarty->_cache['tplObjects'][$template->templateId] = $template; |
|
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | } |
@@ -213,8 +213,7 @@ |
||
| 213 | 213 | error_reporting($_smarty_old_error_level); |
| 214 | 214 | } |
| 215 | 215 | return $result; |
| 216 | - } |
|
| 217 | - catch (Exception $e) { |
|
| 216 | + } catch (Exception $e) { |
|
| 218 | 217 | while (ob_get_level() > $level) { |
| 219 | 218 | ob_end_clean(); |
| 220 | 219 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | /** |
| 300 | 300 | * method to compile a Smarty template |
| 301 | 301 | * |
| 302 | - * @param mixed $_content template source |
|
| 302 | + * @param string $_content template source |
|
| 303 | 303 | * @param bool $isTemplateSource |
| 304 | 304 | * |
| 305 | 305 | * @return bool true if compiling succeeded, false if it failed |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | * @param bool $nocache true is shall be compiled in nocache mode |
| 325 | 325 | * @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler |
| 326 | 326 | * |
| 327 | - * @return bool true if compiling succeeded, false if it failed |
|
| 327 | + * @return string true if compiling succeeded, false if it failed |
|
| 328 | 328 | * @throws \Exception |
| 329 | 329 | */ |
| 330 | 330 | public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | * @param string $tag tag name |
| 842 | 842 | * @param array $args list of tag attributes |
| 843 | 843 | * @param mixed $param1 optional parameter |
| 844 | - * @param mixed $param2 optional parameter |
|
| 844 | + * @param string $param2 optional parameter |
|
| 845 | 845 | * @param mixed $param3 optional parameter |
| 846 | 846 | * |
| 847 | 847 | * @return string compiled code |
@@ -1052,7 +1052,7 @@ discard block |
||
| 1052 | 1052 | * |
| 1053 | 1053 | * @param string $input |
| 1054 | 1054 | * |
| 1055 | - * @return bool|string |
|
| 1055 | + * @return string|false |
|
| 1056 | 1056 | */ |
| 1057 | 1057 | public function getId($input) |
| 1058 | 1058 | { |
@@ -1067,7 +1067,7 @@ discard block |
||
| 1067 | 1067 | * |
| 1068 | 1068 | * @param string $input |
| 1069 | 1069 | * |
| 1070 | - * @return bool|string |
|
| 1070 | + * @return string|false |
|
| 1071 | 1071 | */ |
| 1072 | 1072 | public function getVariableName($input) |
| 1073 | 1073 | { |
@@ -23,1273 +23,1273 @@ |
||
| 23 | 23 | abstract class Smarty_Internal_TemplateCompilerBase |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Smarty object |
|
| 28 | - * |
|
| 29 | - * @var Smarty |
|
| 30 | - */ |
|
| 31 | - public $smarty = null; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Parser object |
|
| 35 | - * |
|
| 36 | - * @var Smarty_Internal_Templateparser |
|
| 37 | - */ |
|
| 38 | - public $parser = null; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * hash for nocache sections |
|
| 42 | - * |
|
| 43 | - * @var mixed |
|
| 44 | - */ |
|
| 45 | - public $nocache_hash = null; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * suppress generation of nocache code |
|
| 49 | - * |
|
| 50 | - * @var bool |
|
| 51 | - */ |
|
| 52 | - public $suppressNocacheProcessing = false; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * compile tag objects cache |
|
| 56 | - * |
|
| 57 | - * @var array |
|
| 58 | - */ |
|
| 59 | - static $_tag_objects = array(); |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * tag stack |
|
| 63 | - * |
|
| 64 | - * @var array |
|
| 65 | - */ |
|
| 66 | - public $_tag_stack = array(); |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * current template |
|
| 70 | - * |
|
| 71 | - * @var Smarty_Internal_Template |
|
| 72 | - */ |
|
| 73 | - public $template = null; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * merged included sub template data |
|
| 77 | - * |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 80 | - public $mergedSubTemplatesData = array(); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * merged sub template code |
|
| 84 | - * |
|
| 85 | - * @var array |
|
| 86 | - */ |
|
| 87 | - public $mergedSubTemplatesCode = array(); |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * collected template properties during compilation |
|
| 91 | - * |
|
| 92 | - * @var array |
|
| 93 | - */ |
|
| 94 | - public $templateProperties = array(); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * source line offset for error messages |
|
| 98 | - * |
|
| 99 | - * @var int |
|
| 100 | - */ |
|
| 101 | - public $trace_line_offset = 0; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * trace uid |
|
| 105 | - * |
|
| 106 | - * @var string |
|
| 107 | - */ |
|
| 108 | - public $trace_uid = ''; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * trace file path |
|
| 112 | - * |
|
| 113 | - * @var string |
|
| 114 | - */ |
|
| 115 | - public $trace_filepath = ''; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * stack for tracing file and line of nested {block} tags |
|
| 119 | - * |
|
| 120 | - * @var array |
|
| 121 | - */ |
|
| 122 | - public $trace_stack = array(); |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * plugins loaded by default plugin handler |
|
| 126 | - * |
|
| 127 | - * @var array |
|
| 128 | - */ |
|
| 129 | - public $default_handler_plugins = array(); |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * saved preprocessed modifier list |
|
| 133 | - * |
|
| 134 | - * @var mixed |
|
| 135 | - */ |
|
| 136 | - public $default_modifier_list = null; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * force compilation of complete template as nocache |
|
| 140 | - * |
|
| 141 | - * @var boolean |
|
| 142 | - */ |
|
| 143 | - public $forceNocache = false; |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * flag if compiled template file shall we written |
|
| 147 | - * |
|
| 148 | - * @var bool |
|
| 149 | - */ |
|
| 150 | - public $write_compiled_code = true; |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Template functions |
|
| 154 | - * |
|
| 155 | - * @var array |
|
| 156 | - */ |
|
| 157 | - public $tpl_function = array(); |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * called sub functions from template function |
|
| 161 | - * |
|
| 162 | - * @var array |
|
| 163 | - */ |
|
| 164 | - public $called_functions = array(); |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * compiled template or block function code |
|
| 168 | - * |
|
| 169 | - * @var string |
|
| 170 | - */ |
|
| 171 | - public $blockOrFunctionCode = ''; |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * php_handling setting either from Smarty or security |
|
| 175 | - * |
|
| 176 | - * @var int |
|
| 177 | - */ |
|
| 178 | - public $php_handling = 0; |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * flags for used modifier plugins |
|
| 182 | - * |
|
| 183 | - * @var array |
|
| 184 | - */ |
|
| 185 | - public $modifier_plugins = array(); |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * type of already compiled modifier |
|
| 189 | - * |
|
| 190 | - * @var array |
|
| 191 | - */ |
|
| 192 | - public $known_modifier_type = array(); |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * parent compiler object for merged subtemplates and template functions |
|
| 196 | - * |
|
| 197 | - * @var Smarty_Internal_TemplateCompilerBase |
|
| 198 | - */ |
|
| 199 | - public $parent_compiler = null; |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Flag true when compiling nocache section |
|
| 203 | - * |
|
| 204 | - * @var bool |
|
| 205 | - */ |
|
| 206 | - public $nocache = false; |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Flag true when tag is compiled as nocache |
|
| 210 | - * |
|
| 211 | - * @var bool |
|
| 212 | - */ |
|
| 213 | - public $tag_nocache = false; |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Compiled tag prefix code |
|
| 217 | - * |
|
| 218 | - * @var array |
|
| 219 | - */ |
|
| 220 | - public $prefix_code = array(); |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Prefix code stack |
|
| 224 | - * |
|
| 225 | - * @var array |
|
| 226 | - */ |
|
| 227 | - public $prefixCodeStack = array(); |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Tag has compiled code |
|
| 231 | - * |
|
| 232 | - * @var bool |
|
| 233 | - */ |
|
| 234 | - public $has_code = false; |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * A variable string was compiled |
|
| 238 | - * |
|
| 239 | - * @var bool |
|
| 240 | - */ |
|
| 241 | - public $has_variable_string = false; |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Tag creates output |
|
| 245 | - * |
|
| 246 | - * @var bool |
|
| 247 | - */ |
|
| 248 | - public $has_output = false; |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Stack for {setfilter} {/setfilter} |
|
| 252 | - * |
|
| 253 | - * @var array |
|
| 254 | - */ |
|
| 255 | - public $variable_filter_stack = array(); |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * variable filters for {setfilter} {/setfilter} |
|
| 259 | - * |
|
| 260 | - * @var array |
|
| 261 | - */ |
|
| 262 | - public $variable_filters = array(); |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Nesting count of looping tags like {foreach}, {for}, {section}, {while} |
|
| 266 | - * |
|
| 267 | - * @var int |
|
| 268 | - */ |
|
| 269 | - public $loopNesting = 0; |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Strip preg pattern |
|
| 273 | - * |
|
| 274 | - * @var string |
|
| 275 | - */ |
|
| 276 | - public $stripRegEx = '![\t ]*[\r\n]+[\t ]*!'; |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * plugin search order |
|
| 280 | - * |
|
| 281 | - * @var array |
|
| 282 | - */ |
|
| 283 | - public $plugin_search_order = array('function', 'block', 'compiler', 'class'); |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * General storage area for tag compiler plugins |
|
| 287 | - * |
|
| 288 | - * @var array |
|
| 289 | - */ |
|
| 290 | - public $_cache = array(); |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * counter for prefix variable number |
|
| 294 | - * |
|
| 295 | - * @var int |
|
| 296 | - */ |
|
| 297 | - public static $prefixVariableNumber = 0; |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * method to compile a Smarty template |
|
| 301 | - * |
|
| 302 | - * @param mixed $_content template source |
|
| 303 | - * @param bool $isTemplateSource |
|
| 304 | - * |
|
| 305 | - * @return bool true if compiling succeeded, false if it failed |
|
| 306 | - */ |
|
| 307 | - abstract protected function doCompile($_content, $isTemplateSource = false); |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Initialize compiler |
|
| 311 | - * |
|
| 312 | - * @param Smarty $smarty global instance |
|
| 313 | - */ |
|
| 314 | - public function __construct(Smarty $smarty) |
|
| 315 | - { |
|
| 316 | - $this->smarty = $smarty; |
|
| 317 | - $this->nocache_hash = str_replace(array('.', ','), '_', uniqid(rand(), true)); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Method to compile a Smarty template |
|
| 322 | - * |
|
| 323 | - * @param Smarty_Internal_Template $template template object to compile |
|
| 324 | - * @param bool $nocache true is shall be compiled in nocache mode |
|
| 325 | - * @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler |
|
| 326 | - * |
|
| 327 | - * @return bool true if compiling succeeded, false if it failed |
|
| 328 | - * @throws \Exception |
|
| 329 | - */ |
|
| 330 | - public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, |
|
| 331 | - Smarty_Internal_TemplateCompilerBase $parent_compiler = null) |
|
| 332 | - { |
|
| 333 | - // get code frame of compiled template |
|
| 334 | - $_compiled_code = $template->smarty->ext->_codeFrame->create($template, |
|
| 335 | - $this->compileTemplateSource($template, $nocache, |
|
| 336 | - $parent_compiler), |
|
| 337 | - $this->postFilter($this->blockOrFunctionCode) . |
|
| 338 | - join('', $this->mergedSubTemplatesCode), false, |
|
| 339 | - $this); |
|
| 340 | - return $_compiled_code; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Compile template source and run optional post filter |
|
| 345 | - * |
|
| 346 | - * @param \Smarty_Internal_Template $template |
|
| 347 | - * @param null|bool $nocache flag if template must be compiled in nocache mode |
|
| 348 | - * @param \Smarty_Internal_TemplateCompilerBase $parent_compiler |
|
| 349 | - * |
|
| 350 | - * @return string |
|
| 351 | - * @throws \Exception |
|
| 352 | - */ |
|
| 353 | - public function compileTemplateSource(Smarty_Internal_Template $template, $nocache = null, |
|
| 354 | - Smarty_Internal_TemplateCompilerBase $parent_compiler = null) |
|
| 355 | - { |
|
| 356 | - try { |
|
| 357 | - // save template object in compiler class |
|
| 358 | - $this->template = $template; |
|
| 359 | - if (property_exists($this->template->smarty, 'plugin_search_order')) { |
|
| 360 | - $this->plugin_search_order = $this->template->smarty->plugin_search_order; |
|
| 361 | - } |
|
| 362 | - if ($this->smarty->debugging) { |
|
| 363 | - if (!isset($this->smarty->_debug)) { |
|
| 364 | - $this->smarty->_debug = new Smarty_Internal_Debug(); |
|
| 365 | - } |
|
| 366 | - $this->smarty->_debug->start_compile($this->template); |
|
| 367 | - } |
|
| 368 | - if (isset($this->template->smarty->security_policy)) { |
|
| 369 | - $this->php_handling = $this->template->smarty->security_policy->php_handling; |
|
| 370 | - } else { |
|
| 371 | - $this->php_handling = $this->template->smarty->php_handling; |
|
| 372 | - } |
|
| 373 | - $this->parent_compiler = $parent_compiler ? $parent_compiler : $this; |
|
| 374 | - $nocache = isset($nocache) ? $nocache : false; |
|
| 375 | - if (empty($template->compiled->nocache_hash)) { |
|
| 376 | - $template->compiled->nocache_hash = $this->nocache_hash; |
|
| 377 | - } else { |
|
| 378 | - $this->nocache_hash = $template->compiled->nocache_hash; |
|
| 379 | - } |
|
| 380 | - // flag for nocache sections |
|
| 381 | - $this->nocache = $nocache; |
|
| 382 | - $this->tag_nocache = false; |
|
| 383 | - // reset has nocache code flag |
|
| 384 | - $this->template->compiled->has_nocache_code = false; |
|
| 385 | - $this->has_variable_string = false; |
|
| 386 | - $this->prefix_code = array(); |
|
| 387 | - // add file dependency |
|
| 388 | - if ($this->smarty->merge_compiled_includes || $this->template->source->handler->checkTimestamps()) { |
|
| 389 | - $this->parent_compiler->template->compiled->file_dependency[ $this->template->source->uid ] = |
|
| 390 | - array($this->template->source->filepath, $this->template->source->getTimeStamp(), |
|
| 391 | - $this->template->source->type,); |
|
| 392 | - } |
|
| 393 | - $this->smarty->_current_file = $this->template->source->filepath; |
|
| 394 | - // get template source |
|
| 395 | - if (!empty($this->template->source->components)) { |
|
| 396 | - // we have array of inheritance templates by extends: resource |
|
| 397 | - // generate corresponding source code sequence |
|
| 398 | - $_content = |
|
| 399 | - Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template->source->components); |
|
| 400 | - } else { |
|
| 401 | - // get template source |
|
| 402 | - $_content = $this->template->source->getContent(); |
|
| 403 | - } |
|
| 404 | - $_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true)); |
|
| 405 | - } |
|
| 406 | - catch (Exception $e) { |
|
| 407 | - if ($this->smarty->debugging) { |
|
| 408 | - $this->smarty->_debug->end_compile($this->template); |
|
| 409 | - } |
|
| 410 | - $this->_tag_stack = array(); |
|
| 411 | - // free memory |
|
| 412 | - $this->parent_compiler = null; |
|
| 413 | - $this->template = null; |
|
| 414 | - $this->parser = null; |
|
| 415 | - throw $e; |
|
| 416 | - } |
|
| 417 | - if ($this->smarty->debugging) { |
|
| 418 | - $this->smarty->_debug->end_compile($this->template); |
|
| 419 | - } |
|
| 420 | - $this->parent_compiler = null; |
|
| 421 | - $this->parser = null; |
|
| 422 | - return $_compiled_code; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * Optionally process compiled code by post filter |
|
| 427 | - * |
|
| 428 | - * @param string $code compiled code |
|
| 429 | - * |
|
| 430 | - * @return string |
|
| 431 | - * @throws \SmartyException |
|
| 432 | - */ |
|
| 433 | - public function postFilter($code) |
|
| 434 | - { |
|
| 435 | - // run post filter if on code |
|
| 436 | - if (!empty($code) && |
|
| 437 | - (isset($this->smarty->autoload_filters[ 'post' ]) || isset($this->smarty->registered_filters[ 'post' ])) |
|
| 438 | - ) { |
|
| 439 | - return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template); |
|
| 440 | - } else { |
|
| 441 | - return $code; |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Run optional prefilter |
|
| 447 | - * |
|
| 448 | - * @param string $_content template source |
|
| 449 | - * |
|
| 450 | - * @return string |
|
| 451 | - * @throws \SmartyException |
|
| 452 | - */ |
|
| 453 | - public function preFilter($_content) |
|
| 454 | - { |
|
| 455 | - // run pre filter if required |
|
| 456 | - if ($_content != '' && |
|
| 457 | - ((isset($this->smarty->autoload_filters[ 'pre' ]) || isset($this->smarty->registered_filters[ 'pre' ]))) |
|
| 458 | - ) { |
|
| 459 | - return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template); |
|
| 460 | - } else { |
|
| 461 | - return $_content; |
|
| 462 | - } |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Compile Tag |
|
| 467 | - * This is a call back from the lexer/parser |
|
| 468 | - * |
|
| 469 | - * Save current prefix code |
|
| 470 | - * Compile tag |
|
| 471 | - * Merge tag prefix code with saved one |
|
| 472 | - * (required nested tags in attributes) |
|
| 473 | - * |
|
| 474 | - * @param string $tag tag name |
|
| 475 | - * @param array $args array with tag attributes |
|
| 476 | - * @param array $parameter array with compilation parameter |
|
| 477 | - * |
|
| 478 | - * @throws SmartyCompilerException |
|
| 479 | - * @throws SmartyException |
|
| 480 | - * @return string compiled code |
|
| 481 | - */ |
|
| 482 | - public function compileTag($tag, $args, $parameter = array()) |
|
| 483 | - { |
|
| 484 | - $this->prefixCodeStack[] = $this->prefix_code; |
|
| 485 | - $this->prefix_code = array(); |
|
| 486 | - $result = $this->compileTag2($tag, $args, $parameter); |
|
| 487 | - $this->prefix_code = array_merge($this->prefix_code, array_pop($this->prefixCodeStack)); |
|
| 488 | - return $result; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * Compile Tag |
|
| 493 | - * |
|
| 494 | - * @param string $tag tag name |
|
| 495 | - * @param array $args array with tag attributes |
|
| 496 | - * @param array $parameter array with compilation parameter |
|
| 497 | - * |
|
| 498 | - * @throws SmartyCompilerException |
|
| 499 | - * @throws SmartyException |
|
| 500 | - * @return string compiled code |
|
| 501 | - */ |
|
| 502 | - private function compileTag2($tag, $args, $parameter) |
|
| 503 | - { |
|
| 504 | - $plugin_type = ''; |
|
| 505 | - // $args contains the attributes parsed and compiled by the lexer/parser |
|
| 506 | - // assume that tag does compile into code, but creates no HTML output |
|
| 507 | - $this->has_code = true; |
|
| 508 | - $this->has_output = false; |
|
| 509 | - // log tag/attributes |
|
| 510 | - if (isset($this->smarty->_cache[ 'get_used_tags' ])) { |
|
| 511 | - $this->template->_cache[ 'used_tags' ][] = array($tag, $args); |
|
| 512 | - } |
|
| 513 | - // check nocache option flag |
|
| 514 | - foreach ($args as $arg) { |
|
| 515 | - if (!is_array($arg)) { |
|
| 516 | - if ($arg == "'nocache'") { |
|
| 517 | - $this->tag_nocache = true; |
|
| 518 | - } |
|
| 519 | - } else { |
|
| 520 | - foreach ($arg as $k => $v) { |
|
| 521 | - if ($k == "'nocache'" && (trim($v, "'\" ") == 'true')) { |
|
| 522 | - $this->tag_nocache = true; |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - // compile the smarty tag (required compile classes to compile the tag are auto loaded) |
|
| 528 | - if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) { |
|
| 529 | - if (isset($this->parent_compiler->tpl_function[ $tag ])) { |
|
| 530 | - // template defined by {template} tag |
|
| 531 | - $args[ '_attr' ][ 'name' ] = "'" . $tag . "'"; |
|
| 532 | - $_output = $this->callTagCompiler('call', $args, $parameter); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - if ($_output !== false) { |
|
| 536 | - if ($_output !== true) { |
|
| 537 | - // did we get compiled code |
|
| 538 | - if ($this->has_code) { |
|
| 539 | - // Does it create output? |
|
| 540 | - if ($this->has_output) { |
|
| 541 | - $_output .= "\n"; |
|
| 542 | - } |
|
| 543 | - // return compiled code |
|
| 544 | - return $_output; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - // tag did not produce compiled code |
|
| 548 | - return null; |
|
| 549 | - } else { |
|
| 550 | - // map_named attributes |
|
| 551 | - if (isset($args[ '_attr' ])) { |
|
| 552 | - foreach ($args[ '_attr' ] as $key => $attribute) { |
|
| 553 | - if (is_array($attribute)) { |
|
| 554 | - $args = array_merge($args, $attribute); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - } |
|
| 558 | - // not an internal compiler tag |
|
| 559 | - if (strlen($tag) < 6 || substr($tag, - 5) != 'close') { |
|
| 560 | - // check if tag is a registered object |
|
| 561 | - if (isset($this->smarty->registered_objects[ $tag ]) && isset($parameter[ 'object_method' ])) { |
|
| 562 | - $method = $parameter[ 'object_method' ]; |
|
| 563 | - if (!in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ]) && |
|
| 564 | - (empty($this->smarty->registered_objects[ $tag ][ 1 ]) || |
|
| 565 | - in_array($method, $this->smarty->registered_objects[ $tag ][ 1 ])) |
|
| 566 | - ) { |
|
| 567 | - return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method); |
|
| 568 | - } elseif (in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ])) { |
|
| 569 | - return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, |
|
| 570 | - $method); |
|
| 571 | - } else { |
|
| 572 | - // throw exception |
|
| 573 | - $this->trigger_template_error('not allowed method "' . $method . '" in registered object "' . |
|
| 574 | - $tag . '"', null, true); |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - // check if tag is registered |
|
| 578 | - foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK,) as $plugin_type) |
|
| 579 | - { |
|
| 580 | - if (isset($this->smarty->registered_plugins[ $plugin_type ][ $tag ])) { |
|
| 581 | - // if compiler function plugin call it now |
|
| 582 | - if ($plugin_type == Smarty::PLUGIN_COMPILER) { |
|
| 583 | - $new_args = array(); |
|
| 584 | - foreach ($args as $key => $mixed) { |
|
| 585 | - if (is_array($mixed)) { |
|
| 586 | - $new_args = array_merge($new_args, $mixed); |
|
| 587 | - } else { |
|
| 588 | - $new_args[ $key ] = $mixed; |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - if (!$this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 1 ]) { |
|
| 592 | - $this->tag_nocache = true; |
|
| 593 | - } |
|
| 594 | - return call_user_func_array($this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 0 ], |
|
| 595 | - array($new_args, $this)); |
|
| 596 | - } |
|
| 597 | - // compile registered function or block function |
|
| 598 | - if ($plugin_type == Smarty::PLUGIN_FUNCTION || $plugin_type == Smarty::PLUGIN_BLOCK) { |
|
| 599 | - return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, |
|
| 600 | - $tag); |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - // check plugins from plugins folder |
|
| 605 | - foreach ($this->plugin_search_order as $plugin_type) { |
|
| 606 | - if ($plugin_type == Smarty::PLUGIN_COMPILER && |
|
| 607 | - $this->smarty->loadPlugin('smarty_compiler_' . $tag) && |
|
| 608 | - (!isset($this->smarty->security_policy) || |
|
| 609 | - $this->smarty->security_policy->isTrustedTag($tag, $this)) |
|
| 610 | - ) { |
|
| 611 | - $plugin = 'smarty_compiler_' . $tag; |
|
| 612 | - if (is_callable($plugin)) { |
|
| 613 | - // convert arguments format for old compiler plugins |
|
| 614 | - $new_args = array(); |
|
| 615 | - foreach ($args as $key => $mixed) { |
|
| 616 | - if (is_array($mixed)) { |
|
| 617 | - $new_args = array_merge($new_args, $mixed); |
|
| 618 | - } else { |
|
| 619 | - $new_args[ $key ] = $mixed; |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - return $plugin($new_args, $this->smarty); |
|
| 624 | - } |
|
| 625 | - if (class_exists($plugin, false)) { |
|
| 626 | - $plugin_object = new $plugin; |
|
| 627 | - if (method_exists($plugin_object, 'compile')) { |
|
| 628 | - return $plugin_object->compile($args, $this); |
|
| 629 | - } |
|
| 630 | - } |
|
| 631 | - throw new SmartyException("Plugin \"{$tag}\" not callable"); |
|
| 632 | - } else { |
|
| 633 | - if ($function = $this->getPlugin($tag, $plugin_type)) { |
|
| 634 | - if (!isset($this->smarty->security_policy) || |
|
| 635 | - $this->smarty->security_policy->isTrustedTag($tag, $this) |
|
| 636 | - ) { |
|
| 637 | - return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, |
|
| 638 | - $tag, $function); |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - if (is_callable($this->smarty->default_plugin_handler_func)) { |
|
| 644 | - $found = false; |
|
| 645 | - // look for already resolved tags |
|
| 646 | - foreach ($this->plugin_search_order as $plugin_type) { |
|
| 647 | - if (isset($this->default_handler_plugins[ $plugin_type ][ $tag ])) { |
|
| 648 | - $found = true; |
|
| 649 | - break; |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - if (!$found) { |
|
| 653 | - // call default handler |
|
| 654 | - foreach ($this->plugin_search_order as $plugin_type) { |
|
| 655 | - if ($this->getPluginFromDefaultHandler($tag, $plugin_type)) { |
|
| 656 | - $found = true; |
|
| 657 | - break; |
|
| 658 | - } |
|
| 659 | - } |
|
| 660 | - } |
|
| 661 | - if ($found) { |
|
| 662 | - // if compiler function plugin call it now |
|
| 663 | - if ($plugin_type == Smarty::PLUGIN_COMPILER) { |
|
| 664 | - $new_args = array(); |
|
| 665 | - foreach ($args as $mixed) { |
|
| 666 | - $new_args = array_merge($new_args, $mixed); |
|
| 667 | - } |
|
| 668 | - return call_user_func_array($this->default_handler_plugins[ $plugin_type ][ $tag ][ 0 ], |
|
| 669 | - array($new_args, $this)); |
|
| 670 | - } else { |
|
| 671 | - return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, |
|
| 672 | - $tag); |
|
| 673 | - } |
|
| 674 | - } |
|
| 675 | - } |
|
| 676 | - } else { |
|
| 677 | - // compile closing tag of block function |
|
| 678 | - $base_tag = substr($tag, 0, - 5); |
|
| 679 | - // check if closing tag is a registered object |
|
| 680 | - if (isset($this->smarty->registered_objects[ $base_tag ]) && isset($parameter[ 'object_method' ])) { |
|
| 681 | - $method = $parameter[ 'object_method' ]; |
|
| 682 | - if (in_array($method, $this->smarty->registered_objects[ $base_tag ][ 3 ])) { |
|
| 683 | - return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, |
|
| 684 | - $method); |
|
| 685 | - } else { |
|
| 686 | - // throw exception |
|
| 687 | - $this->trigger_template_error('not allowed closing tag method "' . $method . |
|
| 688 | - '" in registered object "' . $base_tag . '"', null, true); |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - // registered block tag ? |
|
| 692 | - if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ]) || |
|
| 693 | - isset($this->default_handler_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ]) |
|
| 694 | - ) { |
|
| 695 | - return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag); |
|
| 696 | - } |
|
| 697 | - // registered function tag ? |
|
| 698 | - if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ])) { |
|
| 699 | - return $this->callTagCompiler('private_registered_function', $args, $parameter, $tag); |
|
| 700 | - } |
|
| 701 | - // block plugin? |
|
| 702 | - if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) { |
|
| 703 | - return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function); |
|
| 704 | - } |
|
| 705 | - // function plugin? |
|
| 706 | - if ($function = $this->getPlugin($tag, Smarty::PLUGIN_FUNCTION)) { |
|
| 707 | - if (!isset($this->smarty->security_policy) || |
|
| 708 | - $this->smarty->security_policy->isTrustedTag($tag, $this) |
|
| 709 | - ) { |
|
| 710 | - return $this->callTagCompiler('private_function_plugin', $args, $parameter, $tag, $function); |
|
| 711 | - } |
|
| 712 | - } |
|
| 713 | - // registered compiler plugin ? |
|
| 714 | - if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ])) { |
|
| 715 | - // if compiler function plugin call it now |
|
| 716 | - $args = array(); |
|
| 717 | - if (!$this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 1 ]) { |
|
| 718 | - $this->tag_nocache = true; |
|
| 719 | - } |
|
| 720 | - return call_user_func_array($this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 0 ], |
|
| 721 | - array($args, $this)); |
|
| 722 | - } |
|
| 723 | - if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) { |
|
| 724 | - $plugin = 'smarty_compiler_' . $tag; |
|
| 725 | - if (is_callable($plugin)) { |
|
| 726 | - return $plugin($args, $this->smarty); |
|
| 727 | - } |
|
| 728 | - if (class_exists($plugin, false)) { |
|
| 729 | - $plugin_object = new $plugin; |
|
| 730 | - if (method_exists($plugin_object, 'compile')) { |
|
| 731 | - return $plugin_object->compile($args, $this); |
|
| 732 | - } |
|
| 733 | - } |
|
| 734 | - throw new SmartyException("Plugin \"{$tag}\" not callable"); |
|
| 735 | - } |
|
| 736 | - } |
|
| 737 | - $this->trigger_template_error("unknown tag \"" . $tag . "\"", null, true); |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - /** |
|
| 742 | - * compile variable |
|
| 743 | - * |
|
| 744 | - * @param string $variable |
|
| 745 | - * |
|
| 746 | - * @return string |
|
| 747 | - */ |
|
| 748 | - public function compileVariable($variable) |
|
| 749 | - { |
|
| 750 | - if (strpos($variable, '(') == 0) { |
|
| 751 | - // not a variable variable |
|
| 752 | - $var = trim($variable, '\''); |
|
| 753 | - $this->tag_nocache = $this->tag_nocache | |
|
| 754 | - $this->template->ext->getTemplateVars->_getVariable($this->template, $var, null, true, |
|
| 755 | - false)->nocache; |
|
| 756 | - // todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache; |
|
| 757 | - } |
|
| 758 | - return '$_smarty_tpl->tpl_vars[' . $variable . ']->value'; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - /** |
|
| 762 | - * compile config variable |
|
| 763 | - * |
|
| 764 | - * @param string $variable |
|
| 765 | - * |
|
| 766 | - * @return string |
|
| 767 | - */ |
|
| 768 | - public function compileConfigVariable($variable) |
|
| 769 | - { |
|
| 770 | - // return '$_smarty_tpl->config_vars[' . $variable . ']'; |
|
| 771 | - return '$_smarty_tpl->smarty->ext->configLoad->_getConfigVariable($_smarty_tpl, ' . $variable . ')'; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - /** |
|
| 775 | - * This method is called from parser to process a text content section |
|
| 776 | - * - remove text from inheritance child templates as they may generate output |
|
| 777 | - * - strip text if strip is enabled |
|
| 778 | - * |
|
| 779 | - * @param string $text |
|
| 780 | - * |
|
| 781 | - * @return null|\Smarty_Internal_ParseTree_Text |
|
| 782 | - */ |
|
| 783 | - public function processText($text) |
|
| 784 | - { |
|
| 785 | - if ((string) $text != '') { |
|
| 786 | - $store = array(); |
|
| 787 | - $_store = 0; |
|
| 788 | - if ($this->parser->strip) { |
|
| 789 | - if (strpos($text, '<') !== false) { |
|
| 790 | - // capture html elements not to be messed with |
|
| 791 | - $_offset = 0; |
|
| 792 | - if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is', |
|
| 793 | - $text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { |
|
| 794 | - foreach ($matches as $match) { |
|
| 795 | - $store[] = $match[ 0 ][ 0 ]; |
|
| 796 | - $_length = strlen($match[ 0 ][ 0 ]); |
|
| 797 | - $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; |
|
| 798 | - $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] - $_offset, $_length); |
|
| 799 | - |
|
| 800 | - $_offset += $_length - strlen($replace); |
|
| 801 | - $_store ++; |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - $expressions = array(// replace multiple spaces between tags by a single space |
|
| 805 | - '#(:SMARTY@!@|>)[\040\011]+(?=@!@SMARTY:|<)#s' => '\1 \2', |
|
| 806 | - // remove newline between tags |
|
| 807 | - '#(:SMARTY@!@|>)[\040\011]*[\n]\s*(?=@!@SMARTY:|<)#s' => '\1\2', |
|
| 808 | - // remove multiple spaces between attributes (but not in attribute values!) |
|
| 809 | - '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', |
|
| 810 | - '#>[\040\011]+$#Ss' => '> ', '#>[\040\011]*[\n]\s*$#Ss' => '>', |
|
| 811 | - $this->stripRegEx => '',); |
|
| 812 | - |
|
| 813 | - $text = preg_replace(array_keys($expressions), array_values($expressions), $text); |
|
| 814 | - $_offset = 0; |
|
| 815 | - if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $text, $matches, |
|
| 816 | - PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { |
|
| 817 | - foreach ($matches as $match) { |
|
| 818 | - $_length = strlen($match[ 0 ][ 0 ]); |
|
| 819 | - $replace = $store[ $match[ 1 ][ 0 ] ]; |
|
| 820 | - $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length); |
|
| 821 | - |
|
| 822 | - $_offset += strlen($replace) - $_length; |
|
| 823 | - $_store ++; |
|
| 824 | - } |
|
| 825 | - } |
|
| 826 | - } else { |
|
| 827 | - $text = preg_replace($this->stripRegEx, '', $text); |
|
| 828 | - } |
|
| 829 | - } |
|
| 830 | - return new Smarty_Internal_ParseTree_Text($text); |
|
| 831 | - } |
|
| 832 | - return null; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * lazy loads internal compile plugin for tag and calls the compile method |
|
| 837 | - * compile objects cached for reuse. |
|
| 838 | - * class name format: Smarty_Internal_Compile_TagName |
|
| 839 | - * plugin filename format: Smarty_Internal_TagName.php |
|
| 840 | - * |
|
| 841 | - * @param string $tag tag name |
|
| 842 | - * @param array $args list of tag attributes |
|
| 843 | - * @param mixed $param1 optional parameter |
|
| 844 | - * @param mixed $param2 optional parameter |
|
| 845 | - * @param mixed $param3 optional parameter |
|
| 846 | - * |
|
| 847 | - * @return string compiled code |
|
| 848 | - */ |
|
| 849 | - public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) |
|
| 850 | - { |
|
| 851 | - // re-use object if already exists |
|
| 852 | - if (!isset(self::$_tag_objects[ $tag ])) { |
|
| 853 | - // lazy load internal compiler plugin |
|
| 854 | - $_tag = explode('_', $tag); |
|
| 855 | - $_tag = array_map('ucfirst', $_tag); |
|
| 856 | - $class_name = 'Smarty_Internal_Compile_' . implode('_', $_tag); |
|
| 857 | - if (class_exists($class_name) && |
|
| 858 | - (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) |
|
| 859 | - ) { |
|
| 860 | - self::$_tag_objects[ $tag ] = new $class_name; |
|
| 861 | - } else { |
|
| 862 | - self::$_tag_objects[ $tag ] = false; |
|
| 863 | - return false; |
|
| 864 | - } |
|
| 865 | - } |
|
| 866 | - // compile this tag |
|
| 867 | - return self::$_tag_objects[ $tag ] === false ? false : |
|
| 868 | - self::$_tag_objects[ $tag ]->compile($args, $this, $param1, $param2, $param3); |
|
| 869 | - } |
|
| 870 | - |
|
| 871 | - /** |
|
| 872 | - * Check for plugins and return function name |
|
| 873 | - * |
|
| 874 | - * @param $plugin_name |
|
| 875 | - * @param string $plugin_type type of plugin |
|
| 876 | - * |
|
| 877 | - * @return string call name of function |
|
| 878 | - */ |
|
| 879 | - public function getPlugin($plugin_name, $plugin_type) |
|
| 880 | - { |
|
| 881 | - $function = null; |
|
| 882 | - if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { |
|
| 883 | - if (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) { |
|
| 884 | - $function = |
|
| 885 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ]; |
|
| 886 | - } elseif (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) { |
|
| 887 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] = |
|
| 888 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ]; |
|
| 889 | - $function = |
|
| 890 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ]; |
|
| 891 | - } |
|
| 892 | - } else { |
|
| 893 | - if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) { |
|
| 894 | - $function = |
|
| 895 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ]; |
|
| 896 | - } elseif (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) { |
|
| 897 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] = |
|
| 898 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ]; |
|
| 899 | - $function = |
|
| 900 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ]; |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - if (isset($function)) { |
|
| 904 | - if ($plugin_type == 'modifier') { |
|
| 905 | - $this->modifier_plugins[ $plugin_name ] = true; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - return $function; |
|
| 909 | - } |
|
| 910 | - // loop through plugin dirs and find the plugin |
|
| 911 | - $function = 'smarty_' . $plugin_type . '_' . $plugin_name; |
|
| 912 | - $file = $this->smarty->loadPlugin($function, false); |
|
| 913 | - |
|
| 914 | - if (is_string($file)) { |
|
| 915 | - if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { |
|
| 916 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'file' ] = |
|
| 917 | - $file; |
|
| 918 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ] = |
|
| 919 | - $function; |
|
| 920 | - } else { |
|
| 921 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'file' ] = |
|
| 922 | - $file; |
|
| 923 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ] = |
|
| 924 | - $function; |
|
| 925 | - } |
|
| 926 | - if ($plugin_type == 'modifier') { |
|
| 927 | - $this->modifier_plugins[ $plugin_name ] = true; |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - return $function; |
|
| 931 | - } |
|
| 932 | - if (is_callable($function)) { |
|
| 933 | - // plugin function is defined in the script |
|
| 934 | - return $function; |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - return false; |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - /** |
|
| 941 | - * Check for plugins by default plugin handler |
|
| 942 | - * |
|
| 943 | - * @param string $tag name of tag |
|
| 944 | - * @param string $plugin_type type of plugin |
|
| 945 | - * |
|
| 946 | - * @return boolean true if found |
|
| 947 | - */ |
|
| 948 | - public function getPluginFromDefaultHandler($tag, $plugin_type) |
|
| 949 | - { |
|
| 950 | - $callback = null; |
|
| 951 | - $script = null; |
|
| 952 | - $cacheable = true; |
|
| 953 | - $result = call_user_func_array($this->smarty->default_plugin_handler_func, |
|
| 954 | - array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable,)); |
|
| 955 | - if ($result) { |
|
| 956 | - $this->tag_nocache = $this->tag_nocache || !$cacheable; |
|
| 957 | - if ($script !== null) { |
|
| 958 | - if (is_file($script)) { |
|
| 959 | - if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { |
|
| 960 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'file' ] = |
|
| 961 | - $script; |
|
| 962 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'function' ] = |
|
| 963 | - $callback; |
|
| 964 | - } else { |
|
| 965 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'file' ] = |
|
| 966 | - $script; |
|
| 967 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'function' ] = |
|
| 968 | - $callback; |
|
| 969 | - } |
|
| 970 | - require_once $script; |
|
| 971 | - } else { |
|
| 972 | - $this->trigger_template_error("Default plugin handler: Returned script file \"{$script}\" for \"{$tag}\" not found"); |
|
| 973 | - } |
|
| 974 | - } |
|
| 975 | - if (is_callable($callback)) { |
|
| 976 | - $this->default_handler_plugins[ $plugin_type ][ $tag ] = array($callback, true, array()); |
|
| 977 | - |
|
| 978 | - return true; |
|
| 979 | - } else { |
|
| 980 | - $this->trigger_template_error("Default plugin handler: Returned callback for \"{$tag}\" not callable"); |
|
| 981 | - } |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - return false; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - /** |
|
| 988 | - * Append code segments and remove unneeded ?> <?php transitions |
|
| 989 | - * |
|
| 990 | - * @param string $left |
|
| 991 | - * @param string $right |
|
| 992 | - * |
|
| 993 | - * @return string |
|
| 994 | - */ |
|
| 995 | - public function appendCode($left, $right) |
|
| 996 | - { |
|
| 997 | - if (preg_match('/\s*\?>\s*$/', $left) && preg_match('/^\s*<\?php\s+/', $right)) { |
|
| 998 | - $left = preg_replace('/\s*\?>\s*$/', "\n", $left); |
|
| 999 | - $left .= preg_replace('/^\s*<\?php\s+/', '', $right); |
|
| 1000 | - } else { |
|
| 1001 | - $left .= $right; |
|
| 1002 | - } |
|
| 1003 | - return $left; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * Inject inline code for nocache template sections |
|
| 1008 | - * This method gets the content of each template element from the parser. |
|
| 1009 | - * If the content is compiled code and it should be not cached the code is injected |
|
| 1010 | - * into the rendered output. |
|
| 1011 | - * |
|
| 1012 | - * @param string $content content of template element |
|
| 1013 | - * @param boolean $is_code true if content is compiled code |
|
| 1014 | - * |
|
| 1015 | - * @return string content |
|
| 1016 | - */ |
|
| 1017 | - public function processNocacheCode($content, $is_code) |
|
| 1018 | - { |
|
| 1019 | - // If the template is not evaluated and we have a nocache section and or a nocache tag |
|
| 1020 | - if ($is_code && !empty($content)) { |
|
| 1021 | - // generate replacement code |
|
| 1022 | - if ((!($this->template->source->handler->recompiled) || $this->forceNocache) && $this->template->caching && |
|
| 1023 | - !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache) |
|
| 1024 | - ) { |
|
| 1025 | - $this->template->compiled->has_nocache_code = true; |
|
| 1026 | - $_output = addcslashes($content, '\'\\'); |
|
| 1027 | - $_output = str_replace("^#^", "'", $_output); |
|
| 1028 | - $_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output . |
|
| 1029 | - "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n"; |
|
| 1030 | - // make sure we include modifier plugins for nocache code |
|
| 1031 | - foreach ($this->modifier_plugins as $plugin_name => $dummy) { |
|
| 1032 | - if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ])) { |
|
| 1033 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ 'modifier' ] = |
|
| 1034 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ]; |
|
| 1035 | - } |
|
| 1036 | - } |
|
| 1037 | - } else { |
|
| 1038 | - $_output = $content; |
|
| 1039 | - } |
|
| 1040 | - } else { |
|
| 1041 | - $_output = $content; |
|
| 1042 | - } |
|
| 1043 | - $this->modifier_plugins = array(); |
|
| 1044 | - $this->suppressNocacheProcessing = false; |
|
| 1045 | - $this->tag_nocache = false; |
|
| 1046 | - |
|
| 1047 | - return $_output; |
|
| 1048 | - } |
|
| 1049 | - |
|
| 1050 | - /** |
|
| 1051 | - * Get Id |
|
| 1052 | - * |
|
| 1053 | - * @param string $input |
|
| 1054 | - * |
|
| 1055 | - * @return bool|string |
|
| 1056 | - */ |
|
| 1057 | - public function getId($input) |
|
| 1058 | - { |
|
| 1059 | - if (preg_match('~^([\'"]*)([0-9]*[a-zA-Z_]\w*)\1$~', $input, $match)) { |
|
| 1060 | - return $match[ 2 ]; |
|
| 1061 | - } |
|
| 1062 | - return false; |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - /** |
|
| 1066 | - * Get variable name from string |
|
| 1067 | - * |
|
| 1068 | - * @param string $input |
|
| 1069 | - * |
|
| 1070 | - * @return bool|string |
|
| 1071 | - */ |
|
| 1072 | - public function getVariableName($input) |
|
| 1073 | - { |
|
| 1074 | - if (preg_match('~^[$]_smarty_tpl->tpl_vars\[[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*\]->value$~', $input, $match)) { |
|
| 1075 | - return $match[ 1 ]; |
|
| 1076 | - } |
|
| 1077 | - return false; |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - /** |
|
| 1081 | - * Set nocache flag in variable or create new variable |
|
| 1082 | - * |
|
| 1083 | - * @param string $varName |
|
| 1084 | - */ |
|
| 1085 | - public function setNocacheInVariable($varName) |
|
| 1086 | - { |
|
| 1087 | - // create nocache var to make it know for further compiling |
|
| 1088 | - if ($_var = $this->getId($varName)) { |
|
| 1089 | - if (isset($this->template->tpl_vars[ $_var ])) { |
|
| 1090 | - $this->template->tpl_vars[ $_var ] = clone $this->template->tpl_vars[ $_var ]; |
|
| 1091 | - $this->template->tpl_vars[ $_var ]->nocache = true; |
|
| 1092 | - } else { |
|
| 1093 | - $this->template->tpl_vars[ $_var ] = new Smarty_Variable(null, true); |
|
| 1094 | - } |
|
| 1095 | - } |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - /** |
|
| 1099 | - * @param array $_attr tag attributes |
|
| 1100 | - * @param array $validScopes |
|
| 1101 | - * |
|
| 1102 | - * @return int|string |
|
| 1103 | - * @throws \SmartyCompilerException |
|
| 1104 | - */ |
|
| 1105 | - public function convertScope($_attr, $validScopes) |
|
| 1106 | - { |
|
| 1107 | - $_scope = 0; |
|
| 1108 | - if (isset($_attr[ 'scope' ])) { |
|
| 1109 | - $_scopeName = trim($_attr[ 'scope' ], "'\""); |
|
| 1110 | - if (is_numeric($_scopeName) && in_array($_scopeName, $validScopes)) { |
|
| 1111 | - $_scope = $_scopeName; |
|
| 1112 | - } elseif (is_string($_scopeName)) { |
|
| 1113 | - $_scopeName = trim($_scopeName, "'\""); |
|
| 1114 | - $_scope = isset($validScopes[ $_scopeName ]) ? $validScopes[ $_scopeName ] : false; |
|
| 1115 | - } else { |
|
| 1116 | - $_scope = false; |
|
| 1117 | - } |
|
| 1118 | - if ($_scope === false) { |
|
| 1119 | - $err = var_export($_scopeName, true); |
|
| 1120 | - $this->trigger_template_error("illegal value '{$err}' for \"scope\" attribute", null, true); |
|
| 1121 | - } |
|
| 1122 | - } |
|
| 1123 | - return $_scope; |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - /** |
|
| 1127 | - * Generate nocache code string |
|
| 1128 | - * |
|
| 1129 | - * @param string $code PHP code |
|
| 1130 | - * |
|
| 1131 | - * @return string |
|
| 1132 | - */ |
|
| 1133 | - public function makeNocacheCode($code) |
|
| 1134 | - { |
|
| 1135 | - return "echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/<?php " . |
|
| 1136 | - str_replace("^#^", "'", addcslashes($code, '\'\\')) . |
|
| 1137 | - "?>/*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n"; |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - /** |
|
| 1141 | - * display compiler error messages without dying |
|
| 1142 | - * If parameter $args is empty it is a parser detected syntax error. |
|
| 1143 | - * In this case the parser is called to obtain information about expected tokens. |
|
| 1144 | - * If parameter $args contains a string this is used as error message |
|
| 1145 | - * |
|
| 1146 | - * @param string $args individual error message or null |
|
| 1147 | - * @param string $line line-number |
|
| 1148 | - * @param null|bool $tagline if true the line number of last tag |
|
| 1149 | - * |
|
| 1150 | - * @throws \SmartyCompilerException when an unexpected token is found |
|
| 1151 | - */ |
|
| 1152 | - public function trigger_template_error($args = null, $line = null, $tagline = null) |
|
| 1153 | - { |
|
| 1154 | - $lex = $this->parser->lex; |
|
| 1155 | - if ($tagline === true) { |
|
| 1156 | - // get line number of Tag |
|
| 1157 | - $line = $lex->taglineno; |
|
| 1158 | - } elseif (!isset($line)) { |
|
| 1159 | - // get template source line which has error |
|
| 1160 | - $line = $lex->line; |
|
| 1161 | - } else { |
|
| 1162 | - $line = (int) $line; |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - if (in_array($this->template->source->type, array('eval', 'string'))) { |
|
| 1166 | - $templateName = $this->template->source->type . ':' . trim(preg_replace('![\t\r\n]+!', ' ', |
|
| 1167 | - strlen($lex->data) > 40 ? |
|
| 1168 | - substr($lex->data, 0, 40) . |
|
| 1169 | - '...' : $lex->data)); |
|
| 1170 | - } else { |
|
| 1171 | - $templateName = $this->template->source->type . ':' . $this->template->source->filepath; |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - // $line += $this->trace_line_offset; |
|
| 1175 | - $match = preg_split("/\n/", $lex->data); |
|
| 1176 | - $error_text = |
|
| 1177 | - 'Syntax error in template "' . (empty($this->trace_filepath) ? $templateName : $this->trace_filepath) . |
|
| 1178 | - '" on line ' . ($line + $this->trace_line_offset) . ' "' . |
|
| 1179 | - trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ])) . '" '; |
|
| 1180 | - if (isset($args)) { |
|
| 1181 | - // individual error message |
|
| 1182 | - $error_text .= $args; |
|
| 1183 | - } else { |
|
| 1184 | - $expect = array(); |
|
| 1185 | - // expected token from parser |
|
| 1186 | - $error_text .= ' - Unexpected "' . $lex->value . '"'; |
|
| 1187 | - if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) { |
|
| 1188 | - foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { |
|
| 1189 | - $exp_token = $this->parser->yyTokenName[ $token ]; |
|
| 1190 | - if (isset($lex->smarty_token_names[ $exp_token ])) { |
|
| 1191 | - // token type from lexer |
|
| 1192 | - $expect[] = '"' . $lex->smarty_token_names[ $exp_token ] . '"'; |
|
| 1193 | - } else { |
|
| 1194 | - // otherwise internal token name |
|
| 1195 | - $expect[] = $this->parser->yyTokenName[ $token ]; |
|
| 1196 | - } |
|
| 1197 | - } |
|
| 1198 | - $error_text .= ', expected one of: ' . implode(' , ', $expect); |
|
| 1199 | - } |
|
| 1200 | - } |
|
| 1201 | - $e = new SmartyCompilerException($error_text); |
|
| 1202 | - $e->line = $line; |
|
| 1203 | - $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ])); |
|
| 1204 | - $e->desc = $args; |
|
| 1205 | - $e->template = $this->template->source->filepath; |
|
| 1206 | - throw $e; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - /** |
|
| 1210 | - * Return var_export() value with all white spaces removed |
|
| 1211 | - * |
|
| 1212 | - * @param mixed $value |
|
| 1213 | - * |
|
| 1214 | - * @return string |
|
| 1215 | - */ |
|
| 1216 | - public function getVarExport($value) |
|
| 1217 | - { |
|
| 1218 | - return preg_replace('/\s/', '', var_export($value, true)); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - /** |
|
| 1222 | - * Check if $value contains variable elements |
|
| 1223 | - * |
|
| 1224 | - * @param mixed $value |
|
| 1225 | - * |
|
| 1226 | - * @return bool|int |
|
| 1227 | - */ |
|
| 1228 | - public function isVariable($value) |
|
| 1229 | - { |
|
| 1230 | - if (is_string($value)) { |
|
| 1231 | - return preg_match('/[$(]/', $value); |
|
| 1232 | - } |
|
| 1233 | - if (is_bool($value) || is_numeric($value)) { |
|
| 1234 | - return false; |
|
| 1235 | - } |
|
| 1236 | - if (is_array($value)) { |
|
| 1237 | - foreach ($value as $k => $v) { |
|
| 1238 | - if ($this->isVariable($k) || $this->isVariable($v)) { |
|
| 1239 | - return true; |
|
| 1240 | - } |
|
| 1241 | - } |
|
| 1242 | - return false; |
|
| 1243 | - } |
|
| 1244 | - return false; |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - /** |
|
| 1248 | - * Get new prefix variable name |
|
| 1249 | - * |
|
| 1250 | - * @return string |
|
| 1251 | - */ |
|
| 1252 | - public function getNewPrefixVariable() |
|
| 1253 | - { |
|
| 1254 | - self::$prefixVariableNumber ++; |
|
| 1255 | - return $this->getPrefixVariable(); |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - /** |
|
| 1259 | - * Get current prefix variable name |
|
| 1260 | - * |
|
| 1261 | - * @return string |
|
| 1262 | - */ |
|
| 1263 | - public function getPrefixVariable() |
|
| 1264 | - { |
|
| 1265 | - return '$_prefixVariable' . self::$prefixVariableNumber; |
|
| 1266 | - } |
|
| 1267 | - |
|
| 1268 | - /** |
|
| 1269 | - * append code to prefix buffer |
|
| 1270 | - * |
|
| 1271 | - * @param string $code |
|
| 1272 | - */ |
|
| 1273 | - public function appendPrefixCode($code) |
|
| 1274 | - { |
|
| 1275 | - $this->prefix_code[] = $code; |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * get prefix code string |
|
| 1280 | - * |
|
| 1281 | - * @return string |
|
| 1282 | - */ |
|
| 1283 | - public function getPrefixCode() |
|
| 1284 | - { |
|
| 1285 | - $code = ''; |
|
| 1286 | - $prefixArray = array_merge($this->prefix_code, array_pop($this->prefixCodeStack)); |
|
| 1287 | - $this->prefixCodeStack[] = array(); |
|
| 1288 | - foreach ($prefixArray as $c) { |
|
| 1289 | - $code = $this->appendCode($code, $c); |
|
| 1290 | - } |
|
| 1291 | - $this->prefix_code = array(); |
|
| 1292 | - return $code; |
|
| 1293 | - } |
|
| 26 | + /** |
|
| 27 | + * Smarty object |
|
| 28 | + * |
|
| 29 | + * @var Smarty |
|
| 30 | + */ |
|
| 31 | + public $smarty = null; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Parser object |
|
| 35 | + * |
|
| 36 | + * @var Smarty_Internal_Templateparser |
|
| 37 | + */ |
|
| 38 | + public $parser = null; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * hash for nocache sections |
|
| 42 | + * |
|
| 43 | + * @var mixed |
|
| 44 | + */ |
|
| 45 | + public $nocache_hash = null; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * suppress generation of nocache code |
|
| 49 | + * |
|
| 50 | + * @var bool |
|
| 51 | + */ |
|
| 52 | + public $suppressNocacheProcessing = false; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * compile tag objects cache |
|
| 56 | + * |
|
| 57 | + * @var array |
|
| 58 | + */ |
|
| 59 | + static $_tag_objects = array(); |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * tag stack |
|
| 63 | + * |
|
| 64 | + * @var array |
|
| 65 | + */ |
|
| 66 | + public $_tag_stack = array(); |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * current template |
|
| 70 | + * |
|
| 71 | + * @var Smarty_Internal_Template |
|
| 72 | + */ |
|
| 73 | + public $template = null; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * merged included sub template data |
|
| 77 | + * |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | + public $mergedSubTemplatesData = array(); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * merged sub template code |
|
| 84 | + * |
|
| 85 | + * @var array |
|
| 86 | + */ |
|
| 87 | + public $mergedSubTemplatesCode = array(); |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * collected template properties during compilation |
|
| 91 | + * |
|
| 92 | + * @var array |
|
| 93 | + */ |
|
| 94 | + public $templateProperties = array(); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * source line offset for error messages |
|
| 98 | + * |
|
| 99 | + * @var int |
|
| 100 | + */ |
|
| 101 | + public $trace_line_offset = 0; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * trace uid |
|
| 105 | + * |
|
| 106 | + * @var string |
|
| 107 | + */ |
|
| 108 | + public $trace_uid = ''; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * trace file path |
|
| 112 | + * |
|
| 113 | + * @var string |
|
| 114 | + */ |
|
| 115 | + public $trace_filepath = ''; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * stack for tracing file and line of nested {block} tags |
|
| 119 | + * |
|
| 120 | + * @var array |
|
| 121 | + */ |
|
| 122 | + public $trace_stack = array(); |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * plugins loaded by default plugin handler |
|
| 126 | + * |
|
| 127 | + * @var array |
|
| 128 | + */ |
|
| 129 | + public $default_handler_plugins = array(); |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * saved preprocessed modifier list |
|
| 133 | + * |
|
| 134 | + * @var mixed |
|
| 135 | + */ |
|
| 136 | + public $default_modifier_list = null; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * force compilation of complete template as nocache |
|
| 140 | + * |
|
| 141 | + * @var boolean |
|
| 142 | + */ |
|
| 143 | + public $forceNocache = false; |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * flag if compiled template file shall we written |
|
| 147 | + * |
|
| 148 | + * @var bool |
|
| 149 | + */ |
|
| 150 | + public $write_compiled_code = true; |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Template functions |
|
| 154 | + * |
|
| 155 | + * @var array |
|
| 156 | + */ |
|
| 157 | + public $tpl_function = array(); |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * called sub functions from template function |
|
| 161 | + * |
|
| 162 | + * @var array |
|
| 163 | + */ |
|
| 164 | + public $called_functions = array(); |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * compiled template or block function code |
|
| 168 | + * |
|
| 169 | + * @var string |
|
| 170 | + */ |
|
| 171 | + public $blockOrFunctionCode = ''; |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * php_handling setting either from Smarty or security |
|
| 175 | + * |
|
| 176 | + * @var int |
|
| 177 | + */ |
|
| 178 | + public $php_handling = 0; |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * flags for used modifier plugins |
|
| 182 | + * |
|
| 183 | + * @var array |
|
| 184 | + */ |
|
| 185 | + public $modifier_plugins = array(); |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * type of already compiled modifier |
|
| 189 | + * |
|
| 190 | + * @var array |
|
| 191 | + */ |
|
| 192 | + public $known_modifier_type = array(); |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * parent compiler object for merged subtemplates and template functions |
|
| 196 | + * |
|
| 197 | + * @var Smarty_Internal_TemplateCompilerBase |
|
| 198 | + */ |
|
| 199 | + public $parent_compiler = null; |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Flag true when compiling nocache section |
|
| 203 | + * |
|
| 204 | + * @var bool |
|
| 205 | + */ |
|
| 206 | + public $nocache = false; |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Flag true when tag is compiled as nocache |
|
| 210 | + * |
|
| 211 | + * @var bool |
|
| 212 | + */ |
|
| 213 | + public $tag_nocache = false; |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Compiled tag prefix code |
|
| 217 | + * |
|
| 218 | + * @var array |
|
| 219 | + */ |
|
| 220 | + public $prefix_code = array(); |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Prefix code stack |
|
| 224 | + * |
|
| 225 | + * @var array |
|
| 226 | + */ |
|
| 227 | + public $prefixCodeStack = array(); |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Tag has compiled code |
|
| 231 | + * |
|
| 232 | + * @var bool |
|
| 233 | + */ |
|
| 234 | + public $has_code = false; |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * A variable string was compiled |
|
| 238 | + * |
|
| 239 | + * @var bool |
|
| 240 | + */ |
|
| 241 | + public $has_variable_string = false; |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Tag creates output |
|
| 245 | + * |
|
| 246 | + * @var bool |
|
| 247 | + */ |
|
| 248 | + public $has_output = false; |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Stack for {setfilter} {/setfilter} |
|
| 252 | + * |
|
| 253 | + * @var array |
|
| 254 | + */ |
|
| 255 | + public $variable_filter_stack = array(); |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * variable filters for {setfilter} {/setfilter} |
|
| 259 | + * |
|
| 260 | + * @var array |
|
| 261 | + */ |
|
| 262 | + public $variable_filters = array(); |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Nesting count of looping tags like {foreach}, {for}, {section}, {while} |
|
| 266 | + * |
|
| 267 | + * @var int |
|
| 268 | + */ |
|
| 269 | + public $loopNesting = 0; |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Strip preg pattern |
|
| 273 | + * |
|
| 274 | + * @var string |
|
| 275 | + */ |
|
| 276 | + public $stripRegEx = '![\t ]*[\r\n]+[\t ]*!'; |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * plugin search order |
|
| 280 | + * |
|
| 281 | + * @var array |
|
| 282 | + */ |
|
| 283 | + public $plugin_search_order = array('function', 'block', 'compiler', 'class'); |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * General storage area for tag compiler plugins |
|
| 287 | + * |
|
| 288 | + * @var array |
|
| 289 | + */ |
|
| 290 | + public $_cache = array(); |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * counter for prefix variable number |
|
| 294 | + * |
|
| 295 | + * @var int |
|
| 296 | + */ |
|
| 297 | + public static $prefixVariableNumber = 0; |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * method to compile a Smarty template |
|
| 301 | + * |
|
| 302 | + * @param mixed $_content template source |
|
| 303 | + * @param bool $isTemplateSource |
|
| 304 | + * |
|
| 305 | + * @return bool true if compiling succeeded, false if it failed |
|
| 306 | + */ |
|
| 307 | + abstract protected function doCompile($_content, $isTemplateSource = false); |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Initialize compiler |
|
| 311 | + * |
|
| 312 | + * @param Smarty $smarty global instance |
|
| 313 | + */ |
|
| 314 | + public function __construct(Smarty $smarty) |
|
| 315 | + { |
|
| 316 | + $this->smarty = $smarty; |
|
| 317 | + $this->nocache_hash = str_replace(array('.', ','), '_', uniqid(rand(), true)); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Method to compile a Smarty template |
|
| 322 | + * |
|
| 323 | + * @param Smarty_Internal_Template $template template object to compile |
|
| 324 | + * @param bool $nocache true is shall be compiled in nocache mode |
|
| 325 | + * @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler |
|
| 326 | + * |
|
| 327 | + * @return bool true if compiling succeeded, false if it failed |
|
| 328 | + * @throws \Exception |
|
| 329 | + */ |
|
| 330 | + public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, |
|
| 331 | + Smarty_Internal_TemplateCompilerBase $parent_compiler = null) |
|
| 332 | + { |
|
| 333 | + // get code frame of compiled template |
|
| 334 | + $_compiled_code = $template->smarty->ext->_codeFrame->create($template, |
|
| 335 | + $this->compileTemplateSource($template, $nocache, |
|
| 336 | + $parent_compiler), |
|
| 337 | + $this->postFilter($this->blockOrFunctionCode) . |
|
| 338 | + join('', $this->mergedSubTemplatesCode), false, |
|
| 339 | + $this); |
|
| 340 | + return $_compiled_code; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Compile template source and run optional post filter |
|
| 345 | + * |
|
| 346 | + * @param \Smarty_Internal_Template $template |
|
| 347 | + * @param null|bool $nocache flag if template must be compiled in nocache mode |
|
| 348 | + * @param \Smarty_Internal_TemplateCompilerBase $parent_compiler |
|
| 349 | + * |
|
| 350 | + * @return string |
|
| 351 | + * @throws \Exception |
|
| 352 | + */ |
|
| 353 | + public function compileTemplateSource(Smarty_Internal_Template $template, $nocache = null, |
|
| 354 | + Smarty_Internal_TemplateCompilerBase $parent_compiler = null) |
|
| 355 | + { |
|
| 356 | + try { |
|
| 357 | + // save template object in compiler class |
|
| 358 | + $this->template = $template; |
|
| 359 | + if (property_exists($this->template->smarty, 'plugin_search_order')) { |
|
| 360 | + $this->plugin_search_order = $this->template->smarty->plugin_search_order; |
|
| 361 | + } |
|
| 362 | + if ($this->smarty->debugging) { |
|
| 363 | + if (!isset($this->smarty->_debug)) { |
|
| 364 | + $this->smarty->_debug = new Smarty_Internal_Debug(); |
|
| 365 | + } |
|
| 366 | + $this->smarty->_debug->start_compile($this->template); |
|
| 367 | + } |
|
| 368 | + if (isset($this->template->smarty->security_policy)) { |
|
| 369 | + $this->php_handling = $this->template->smarty->security_policy->php_handling; |
|
| 370 | + } else { |
|
| 371 | + $this->php_handling = $this->template->smarty->php_handling; |
|
| 372 | + } |
|
| 373 | + $this->parent_compiler = $parent_compiler ? $parent_compiler : $this; |
|
| 374 | + $nocache = isset($nocache) ? $nocache : false; |
|
| 375 | + if (empty($template->compiled->nocache_hash)) { |
|
| 376 | + $template->compiled->nocache_hash = $this->nocache_hash; |
|
| 377 | + } else { |
|
| 378 | + $this->nocache_hash = $template->compiled->nocache_hash; |
|
| 379 | + } |
|
| 380 | + // flag for nocache sections |
|
| 381 | + $this->nocache = $nocache; |
|
| 382 | + $this->tag_nocache = false; |
|
| 383 | + // reset has nocache code flag |
|
| 384 | + $this->template->compiled->has_nocache_code = false; |
|
| 385 | + $this->has_variable_string = false; |
|
| 386 | + $this->prefix_code = array(); |
|
| 387 | + // add file dependency |
|
| 388 | + if ($this->smarty->merge_compiled_includes || $this->template->source->handler->checkTimestamps()) { |
|
| 389 | + $this->parent_compiler->template->compiled->file_dependency[ $this->template->source->uid ] = |
|
| 390 | + array($this->template->source->filepath, $this->template->source->getTimeStamp(), |
|
| 391 | + $this->template->source->type,); |
|
| 392 | + } |
|
| 393 | + $this->smarty->_current_file = $this->template->source->filepath; |
|
| 394 | + // get template source |
|
| 395 | + if (!empty($this->template->source->components)) { |
|
| 396 | + // we have array of inheritance templates by extends: resource |
|
| 397 | + // generate corresponding source code sequence |
|
| 398 | + $_content = |
|
| 399 | + Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template->source->components); |
|
| 400 | + } else { |
|
| 401 | + // get template source |
|
| 402 | + $_content = $this->template->source->getContent(); |
|
| 403 | + } |
|
| 404 | + $_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true)); |
|
| 405 | + } |
|
| 406 | + catch (Exception $e) { |
|
| 407 | + if ($this->smarty->debugging) { |
|
| 408 | + $this->smarty->_debug->end_compile($this->template); |
|
| 409 | + } |
|
| 410 | + $this->_tag_stack = array(); |
|
| 411 | + // free memory |
|
| 412 | + $this->parent_compiler = null; |
|
| 413 | + $this->template = null; |
|
| 414 | + $this->parser = null; |
|
| 415 | + throw $e; |
|
| 416 | + } |
|
| 417 | + if ($this->smarty->debugging) { |
|
| 418 | + $this->smarty->_debug->end_compile($this->template); |
|
| 419 | + } |
|
| 420 | + $this->parent_compiler = null; |
|
| 421 | + $this->parser = null; |
|
| 422 | + return $_compiled_code; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * Optionally process compiled code by post filter |
|
| 427 | + * |
|
| 428 | + * @param string $code compiled code |
|
| 429 | + * |
|
| 430 | + * @return string |
|
| 431 | + * @throws \SmartyException |
|
| 432 | + */ |
|
| 433 | + public function postFilter($code) |
|
| 434 | + { |
|
| 435 | + // run post filter if on code |
|
| 436 | + if (!empty($code) && |
|
| 437 | + (isset($this->smarty->autoload_filters[ 'post' ]) || isset($this->smarty->registered_filters[ 'post' ])) |
|
| 438 | + ) { |
|
| 439 | + return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template); |
|
| 440 | + } else { |
|
| 441 | + return $code; |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Run optional prefilter |
|
| 447 | + * |
|
| 448 | + * @param string $_content template source |
|
| 449 | + * |
|
| 450 | + * @return string |
|
| 451 | + * @throws \SmartyException |
|
| 452 | + */ |
|
| 453 | + public function preFilter($_content) |
|
| 454 | + { |
|
| 455 | + // run pre filter if required |
|
| 456 | + if ($_content != '' && |
|
| 457 | + ((isset($this->smarty->autoload_filters[ 'pre' ]) || isset($this->smarty->registered_filters[ 'pre' ]))) |
|
| 458 | + ) { |
|
| 459 | + return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template); |
|
| 460 | + } else { |
|
| 461 | + return $_content; |
|
| 462 | + } |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Compile Tag |
|
| 467 | + * This is a call back from the lexer/parser |
|
| 468 | + * |
|
| 469 | + * Save current prefix code |
|
| 470 | + * Compile tag |
|
| 471 | + * Merge tag prefix code with saved one |
|
| 472 | + * (required nested tags in attributes) |
|
| 473 | + * |
|
| 474 | + * @param string $tag tag name |
|
| 475 | + * @param array $args array with tag attributes |
|
| 476 | + * @param array $parameter array with compilation parameter |
|
| 477 | + * |
|
| 478 | + * @throws SmartyCompilerException |
|
| 479 | + * @throws SmartyException |
|
| 480 | + * @return string compiled code |
|
| 481 | + */ |
|
| 482 | + public function compileTag($tag, $args, $parameter = array()) |
|
| 483 | + { |
|
| 484 | + $this->prefixCodeStack[] = $this->prefix_code; |
|
| 485 | + $this->prefix_code = array(); |
|
| 486 | + $result = $this->compileTag2($tag, $args, $parameter); |
|
| 487 | + $this->prefix_code = array_merge($this->prefix_code, array_pop($this->prefixCodeStack)); |
|
| 488 | + return $result; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Compile Tag |
|
| 493 | + * |
|
| 494 | + * @param string $tag tag name |
|
| 495 | + * @param array $args array with tag attributes |
|
| 496 | + * @param array $parameter array with compilation parameter |
|
| 497 | + * |
|
| 498 | + * @throws SmartyCompilerException |
|
| 499 | + * @throws SmartyException |
|
| 500 | + * @return string compiled code |
|
| 501 | + */ |
|
| 502 | + private function compileTag2($tag, $args, $parameter) |
|
| 503 | + { |
|
| 504 | + $plugin_type = ''; |
|
| 505 | + // $args contains the attributes parsed and compiled by the lexer/parser |
|
| 506 | + // assume that tag does compile into code, but creates no HTML output |
|
| 507 | + $this->has_code = true; |
|
| 508 | + $this->has_output = false; |
|
| 509 | + // log tag/attributes |
|
| 510 | + if (isset($this->smarty->_cache[ 'get_used_tags' ])) { |
|
| 511 | + $this->template->_cache[ 'used_tags' ][] = array($tag, $args); |
|
| 512 | + } |
|
| 513 | + // check nocache option flag |
|
| 514 | + foreach ($args as $arg) { |
|
| 515 | + if (!is_array($arg)) { |
|
| 516 | + if ($arg == "'nocache'") { |
|
| 517 | + $this->tag_nocache = true; |
|
| 518 | + } |
|
| 519 | + } else { |
|
| 520 | + foreach ($arg as $k => $v) { |
|
| 521 | + if ($k == "'nocache'" && (trim($v, "'\" ") == 'true')) { |
|
| 522 | + $this->tag_nocache = true; |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + // compile the smarty tag (required compile classes to compile the tag are auto loaded) |
|
| 528 | + if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) { |
|
| 529 | + if (isset($this->parent_compiler->tpl_function[ $tag ])) { |
|
| 530 | + // template defined by {template} tag |
|
| 531 | + $args[ '_attr' ][ 'name' ] = "'" . $tag . "'"; |
|
| 532 | + $_output = $this->callTagCompiler('call', $args, $parameter); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + if ($_output !== false) { |
|
| 536 | + if ($_output !== true) { |
|
| 537 | + // did we get compiled code |
|
| 538 | + if ($this->has_code) { |
|
| 539 | + // Does it create output? |
|
| 540 | + if ($this->has_output) { |
|
| 541 | + $_output .= "\n"; |
|
| 542 | + } |
|
| 543 | + // return compiled code |
|
| 544 | + return $_output; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + // tag did not produce compiled code |
|
| 548 | + return null; |
|
| 549 | + } else { |
|
| 550 | + // map_named attributes |
|
| 551 | + if (isset($args[ '_attr' ])) { |
|
| 552 | + foreach ($args[ '_attr' ] as $key => $attribute) { |
|
| 553 | + if (is_array($attribute)) { |
|
| 554 | + $args = array_merge($args, $attribute); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | + // not an internal compiler tag |
|
| 559 | + if (strlen($tag) < 6 || substr($tag, - 5) != 'close') { |
|
| 560 | + // check if tag is a registered object |
|
| 561 | + if (isset($this->smarty->registered_objects[ $tag ]) && isset($parameter[ 'object_method' ])) { |
|
| 562 | + $method = $parameter[ 'object_method' ]; |
|
| 563 | + if (!in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ]) && |
|
| 564 | + (empty($this->smarty->registered_objects[ $tag ][ 1 ]) || |
|
| 565 | + in_array($method, $this->smarty->registered_objects[ $tag ][ 1 ])) |
|
| 566 | + ) { |
|
| 567 | + return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method); |
|
| 568 | + } elseif (in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ])) { |
|
| 569 | + return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, |
|
| 570 | + $method); |
|
| 571 | + } else { |
|
| 572 | + // throw exception |
|
| 573 | + $this->trigger_template_error('not allowed method "' . $method . '" in registered object "' . |
|
| 574 | + $tag . '"', null, true); |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + // check if tag is registered |
|
| 578 | + foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK,) as $plugin_type) |
|
| 579 | + { |
|
| 580 | + if (isset($this->smarty->registered_plugins[ $plugin_type ][ $tag ])) { |
|
| 581 | + // if compiler function plugin call it now |
|
| 582 | + if ($plugin_type == Smarty::PLUGIN_COMPILER) { |
|
| 583 | + $new_args = array(); |
|
| 584 | + foreach ($args as $key => $mixed) { |
|
| 585 | + if (is_array($mixed)) { |
|
| 586 | + $new_args = array_merge($new_args, $mixed); |
|
| 587 | + } else { |
|
| 588 | + $new_args[ $key ] = $mixed; |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + if (!$this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 1 ]) { |
|
| 592 | + $this->tag_nocache = true; |
|
| 593 | + } |
|
| 594 | + return call_user_func_array($this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 0 ], |
|
| 595 | + array($new_args, $this)); |
|
| 596 | + } |
|
| 597 | + // compile registered function or block function |
|
| 598 | + if ($plugin_type == Smarty::PLUGIN_FUNCTION || $plugin_type == Smarty::PLUGIN_BLOCK) { |
|
| 599 | + return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, |
|
| 600 | + $tag); |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + // check plugins from plugins folder |
|
| 605 | + foreach ($this->plugin_search_order as $plugin_type) { |
|
| 606 | + if ($plugin_type == Smarty::PLUGIN_COMPILER && |
|
| 607 | + $this->smarty->loadPlugin('smarty_compiler_' . $tag) && |
|
| 608 | + (!isset($this->smarty->security_policy) || |
|
| 609 | + $this->smarty->security_policy->isTrustedTag($tag, $this)) |
|
| 610 | + ) { |
|
| 611 | + $plugin = 'smarty_compiler_' . $tag; |
|
| 612 | + if (is_callable($plugin)) { |
|
| 613 | + // convert arguments format for old compiler plugins |
|
| 614 | + $new_args = array(); |
|
| 615 | + foreach ($args as $key => $mixed) { |
|
| 616 | + if (is_array($mixed)) { |
|
| 617 | + $new_args = array_merge($new_args, $mixed); |
|
| 618 | + } else { |
|
| 619 | + $new_args[ $key ] = $mixed; |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + return $plugin($new_args, $this->smarty); |
|
| 624 | + } |
|
| 625 | + if (class_exists($plugin, false)) { |
|
| 626 | + $plugin_object = new $plugin; |
|
| 627 | + if (method_exists($plugin_object, 'compile')) { |
|
| 628 | + return $plugin_object->compile($args, $this); |
|
| 629 | + } |
|
| 630 | + } |
|
| 631 | + throw new SmartyException("Plugin \"{$tag}\" not callable"); |
|
| 632 | + } else { |
|
| 633 | + if ($function = $this->getPlugin($tag, $plugin_type)) { |
|
| 634 | + if (!isset($this->smarty->security_policy) || |
|
| 635 | + $this->smarty->security_policy->isTrustedTag($tag, $this) |
|
| 636 | + ) { |
|
| 637 | + return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, |
|
| 638 | + $tag, $function); |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + if (is_callable($this->smarty->default_plugin_handler_func)) { |
|
| 644 | + $found = false; |
|
| 645 | + // look for already resolved tags |
|
| 646 | + foreach ($this->plugin_search_order as $plugin_type) { |
|
| 647 | + if (isset($this->default_handler_plugins[ $plugin_type ][ $tag ])) { |
|
| 648 | + $found = true; |
|
| 649 | + break; |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + if (!$found) { |
|
| 653 | + // call default handler |
|
| 654 | + foreach ($this->plugin_search_order as $plugin_type) { |
|
| 655 | + if ($this->getPluginFromDefaultHandler($tag, $plugin_type)) { |
|
| 656 | + $found = true; |
|
| 657 | + break; |
|
| 658 | + } |
|
| 659 | + } |
|
| 660 | + } |
|
| 661 | + if ($found) { |
|
| 662 | + // if compiler function plugin call it now |
|
| 663 | + if ($plugin_type == Smarty::PLUGIN_COMPILER) { |
|
| 664 | + $new_args = array(); |
|
| 665 | + foreach ($args as $mixed) { |
|
| 666 | + $new_args = array_merge($new_args, $mixed); |
|
| 667 | + } |
|
| 668 | + return call_user_func_array($this->default_handler_plugins[ $plugin_type ][ $tag ][ 0 ], |
|
| 669 | + array($new_args, $this)); |
|
| 670 | + } else { |
|
| 671 | + return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, |
|
| 672 | + $tag); |
|
| 673 | + } |
|
| 674 | + } |
|
| 675 | + } |
|
| 676 | + } else { |
|
| 677 | + // compile closing tag of block function |
|
| 678 | + $base_tag = substr($tag, 0, - 5); |
|
| 679 | + // check if closing tag is a registered object |
|
| 680 | + if (isset($this->smarty->registered_objects[ $base_tag ]) && isset($parameter[ 'object_method' ])) { |
|
| 681 | + $method = $parameter[ 'object_method' ]; |
|
| 682 | + if (in_array($method, $this->smarty->registered_objects[ $base_tag ][ 3 ])) { |
|
| 683 | + return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, |
|
| 684 | + $method); |
|
| 685 | + } else { |
|
| 686 | + // throw exception |
|
| 687 | + $this->trigger_template_error('not allowed closing tag method "' . $method . |
|
| 688 | + '" in registered object "' . $base_tag . '"', null, true); |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + // registered block tag ? |
|
| 692 | + if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ]) || |
|
| 693 | + isset($this->default_handler_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ]) |
|
| 694 | + ) { |
|
| 695 | + return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag); |
|
| 696 | + } |
|
| 697 | + // registered function tag ? |
|
| 698 | + if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ])) { |
|
| 699 | + return $this->callTagCompiler('private_registered_function', $args, $parameter, $tag); |
|
| 700 | + } |
|
| 701 | + // block plugin? |
|
| 702 | + if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) { |
|
| 703 | + return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function); |
|
| 704 | + } |
|
| 705 | + // function plugin? |
|
| 706 | + if ($function = $this->getPlugin($tag, Smarty::PLUGIN_FUNCTION)) { |
|
| 707 | + if (!isset($this->smarty->security_policy) || |
|
| 708 | + $this->smarty->security_policy->isTrustedTag($tag, $this) |
|
| 709 | + ) { |
|
| 710 | + return $this->callTagCompiler('private_function_plugin', $args, $parameter, $tag, $function); |
|
| 711 | + } |
|
| 712 | + } |
|
| 713 | + // registered compiler plugin ? |
|
| 714 | + if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ])) { |
|
| 715 | + // if compiler function plugin call it now |
|
| 716 | + $args = array(); |
|
| 717 | + if (!$this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 1 ]) { |
|
| 718 | + $this->tag_nocache = true; |
|
| 719 | + } |
|
| 720 | + return call_user_func_array($this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 0 ], |
|
| 721 | + array($args, $this)); |
|
| 722 | + } |
|
| 723 | + if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) { |
|
| 724 | + $plugin = 'smarty_compiler_' . $tag; |
|
| 725 | + if (is_callable($plugin)) { |
|
| 726 | + return $plugin($args, $this->smarty); |
|
| 727 | + } |
|
| 728 | + if (class_exists($plugin, false)) { |
|
| 729 | + $plugin_object = new $plugin; |
|
| 730 | + if (method_exists($plugin_object, 'compile')) { |
|
| 731 | + return $plugin_object->compile($args, $this); |
|
| 732 | + } |
|
| 733 | + } |
|
| 734 | + throw new SmartyException("Plugin \"{$tag}\" not callable"); |
|
| 735 | + } |
|
| 736 | + } |
|
| 737 | + $this->trigger_template_error("unknown tag \"" . $tag . "\"", null, true); |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + /** |
|
| 742 | + * compile variable |
|
| 743 | + * |
|
| 744 | + * @param string $variable |
|
| 745 | + * |
|
| 746 | + * @return string |
|
| 747 | + */ |
|
| 748 | + public function compileVariable($variable) |
|
| 749 | + { |
|
| 750 | + if (strpos($variable, '(') == 0) { |
|
| 751 | + // not a variable variable |
|
| 752 | + $var = trim($variable, '\''); |
|
| 753 | + $this->tag_nocache = $this->tag_nocache | |
|
| 754 | + $this->template->ext->getTemplateVars->_getVariable($this->template, $var, null, true, |
|
| 755 | + false)->nocache; |
|
| 756 | + // todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache; |
|
| 757 | + } |
|
| 758 | + return '$_smarty_tpl->tpl_vars[' . $variable . ']->value'; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + /** |
|
| 762 | + * compile config variable |
|
| 763 | + * |
|
| 764 | + * @param string $variable |
|
| 765 | + * |
|
| 766 | + * @return string |
|
| 767 | + */ |
|
| 768 | + public function compileConfigVariable($variable) |
|
| 769 | + { |
|
| 770 | + // return '$_smarty_tpl->config_vars[' . $variable . ']'; |
|
| 771 | + return '$_smarty_tpl->smarty->ext->configLoad->_getConfigVariable($_smarty_tpl, ' . $variable . ')'; |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + /** |
|
| 775 | + * This method is called from parser to process a text content section |
|
| 776 | + * - remove text from inheritance child templates as they may generate output |
|
| 777 | + * - strip text if strip is enabled |
|
| 778 | + * |
|
| 779 | + * @param string $text |
|
| 780 | + * |
|
| 781 | + * @return null|\Smarty_Internal_ParseTree_Text |
|
| 782 | + */ |
|
| 783 | + public function processText($text) |
|
| 784 | + { |
|
| 785 | + if ((string) $text != '') { |
|
| 786 | + $store = array(); |
|
| 787 | + $_store = 0; |
|
| 788 | + if ($this->parser->strip) { |
|
| 789 | + if (strpos($text, '<') !== false) { |
|
| 790 | + // capture html elements not to be messed with |
|
| 791 | + $_offset = 0; |
|
| 792 | + if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is', |
|
| 793 | + $text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { |
|
| 794 | + foreach ($matches as $match) { |
|
| 795 | + $store[] = $match[ 0 ][ 0 ]; |
|
| 796 | + $_length = strlen($match[ 0 ][ 0 ]); |
|
| 797 | + $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; |
|
| 798 | + $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] - $_offset, $_length); |
|
| 799 | + |
|
| 800 | + $_offset += $_length - strlen($replace); |
|
| 801 | + $_store ++; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + $expressions = array(// replace multiple spaces between tags by a single space |
|
| 805 | + '#(:SMARTY@!@|>)[\040\011]+(?=@!@SMARTY:|<)#s' => '\1 \2', |
|
| 806 | + // remove newline between tags |
|
| 807 | + '#(:SMARTY@!@|>)[\040\011]*[\n]\s*(?=@!@SMARTY:|<)#s' => '\1\2', |
|
| 808 | + // remove multiple spaces between attributes (but not in attribute values!) |
|
| 809 | + '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', |
|
| 810 | + '#>[\040\011]+$#Ss' => '> ', '#>[\040\011]*[\n]\s*$#Ss' => '>', |
|
| 811 | + $this->stripRegEx => '',); |
|
| 812 | + |
|
| 813 | + $text = preg_replace(array_keys($expressions), array_values($expressions), $text); |
|
| 814 | + $_offset = 0; |
|
| 815 | + if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $text, $matches, |
|
| 816 | + PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { |
|
| 817 | + foreach ($matches as $match) { |
|
| 818 | + $_length = strlen($match[ 0 ][ 0 ]); |
|
| 819 | + $replace = $store[ $match[ 1 ][ 0 ] ]; |
|
| 820 | + $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length); |
|
| 821 | + |
|
| 822 | + $_offset += strlen($replace) - $_length; |
|
| 823 | + $_store ++; |
|
| 824 | + } |
|
| 825 | + } |
|
| 826 | + } else { |
|
| 827 | + $text = preg_replace($this->stripRegEx, '', $text); |
|
| 828 | + } |
|
| 829 | + } |
|
| 830 | + return new Smarty_Internal_ParseTree_Text($text); |
|
| 831 | + } |
|
| 832 | + return null; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * lazy loads internal compile plugin for tag and calls the compile method |
|
| 837 | + * compile objects cached for reuse. |
|
| 838 | + * class name format: Smarty_Internal_Compile_TagName |
|
| 839 | + * plugin filename format: Smarty_Internal_TagName.php |
|
| 840 | + * |
|
| 841 | + * @param string $tag tag name |
|
| 842 | + * @param array $args list of tag attributes |
|
| 843 | + * @param mixed $param1 optional parameter |
|
| 844 | + * @param mixed $param2 optional parameter |
|
| 845 | + * @param mixed $param3 optional parameter |
|
| 846 | + * |
|
| 847 | + * @return string compiled code |
|
| 848 | + */ |
|
| 849 | + public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) |
|
| 850 | + { |
|
| 851 | + // re-use object if already exists |
|
| 852 | + if (!isset(self::$_tag_objects[ $tag ])) { |
|
| 853 | + // lazy load internal compiler plugin |
|
| 854 | + $_tag = explode('_', $tag); |
|
| 855 | + $_tag = array_map('ucfirst', $_tag); |
|
| 856 | + $class_name = 'Smarty_Internal_Compile_' . implode('_', $_tag); |
|
| 857 | + if (class_exists($class_name) && |
|
| 858 | + (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) |
|
| 859 | + ) { |
|
| 860 | + self::$_tag_objects[ $tag ] = new $class_name; |
|
| 861 | + } else { |
|
| 862 | + self::$_tag_objects[ $tag ] = false; |
|
| 863 | + return false; |
|
| 864 | + } |
|
| 865 | + } |
|
| 866 | + // compile this tag |
|
| 867 | + return self::$_tag_objects[ $tag ] === false ? false : |
|
| 868 | + self::$_tag_objects[ $tag ]->compile($args, $this, $param1, $param2, $param3); |
|
| 869 | + } |
|
| 870 | + |
|
| 871 | + /** |
|
| 872 | + * Check for plugins and return function name |
|
| 873 | + * |
|
| 874 | + * @param $plugin_name |
|
| 875 | + * @param string $plugin_type type of plugin |
|
| 876 | + * |
|
| 877 | + * @return string call name of function |
|
| 878 | + */ |
|
| 879 | + public function getPlugin($plugin_name, $plugin_type) |
|
| 880 | + { |
|
| 881 | + $function = null; |
|
| 882 | + if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { |
|
| 883 | + if (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) { |
|
| 884 | + $function = |
|
| 885 | + $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ]; |
|
| 886 | + } elseif (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) { |
|
| 887 | + $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] = |
|
| 888 | + $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ]; |
|
| 889 | + $function = |
|
| 890 | + $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ]; |
|
| 891 | + } |
|
| 892 | + } else { |
|
| 893 | + if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) { |
|
| 894 | + $function = |
|
| 895 | + $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ]; |
|
| 896 | + } elseif (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) { |
|
| 897 | + $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] = |
|
| 898 | + $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ]; |
|
| 899 | + $function = |
|
| 900 | + $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ]; |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + if (isset($function)) { |
|
| 904 | + if ($plugin_type == 'modifier') { |
|
| 905 | + $this->modifier_plugins[ $plugin_name ] = true; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + return $function; |
|
| 909 | + } |
|
| 910 | + // loop through plugin dirs and find the plugin |
|
| 911 | + $function = 'smarty_' . $plugin_type . '_' . $plugin_name; |
|
| 912 | + $file = $this->smarty->loadPlugin($function, false); |
|
| 913 | + |
|
| 914 | + if (is_string($file)) { |
|
| 915 | + if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { |
|
| 916 | + $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'file' ] = |
|
| 917 | + $file; |
|
| 918 | + $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ] = |
|
| 919 | + $function; |
|
| 920 | + } else { |
|
| 921 | + $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'file' ] = |
|
| 922 | + $file; |
|
| 923 | + $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ] = |
|
| 924 | + $function; |
|
| 925 | + } |
|
| 926 | + if ($plugin_type == 'modifier') { |
|
| 927 | + $this->modifier_plugins[ $plugin_name ] = true; |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + return $function; |
|
| 931 | + } |
|
| 932 | + if (is_callable($function)) { |
|
| 933 | + // plugin function is defined in the script |
|
| 934 | + return $function; |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + return false; |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + /** |
|
| 941 | + * Check for plugins by default plugin handler |
|
| 942 | + * |
|
| 943 | + * @param string $tag name of tag |
|
| 944 | + * @param string $plugin_type type of plugin |
|
| 945 | + * |
|
| 946 | + * @return boolean true if found |
|
| 947 | + */ |
|
| 948 | + public function getPluginFromDefaultHandler($tag, $plugin_type) |
|
| 949 | + { |
|
| 950 | + $callback = null; |
|
| 951 | + $script = null; |
|
| 952 | + $cacheable = true; |
|
| 953 | + $result = call_user_func_array($this->smarty->default_plugin_handler_func, |
|
| 954 | + array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable,)); |
|
| 955 | + if ($result) { |
|
| 956 | + $this->tag_nocache = $this->tag_nocache || !$cacheable; |
|
| 957 | + if ($script !== null) { |
|
| 958 | + if (is_file($script)) { |
|
| 959 | + if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { |
|
| 960 | + $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'file' ] = |
|
| 961 | + $script; |
|
| 962 | + $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'function' ] = |
|
| 963 | + $callback; |
|
| 964 | + } else { |
|
| 965 | + $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'file' ] = |
|
| 966 | + $script; |
|
| 967 | + $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'function' ] = |
|
| 968 | + $callback; |
|
| 969 | + } |
|
| 970 | + require_once $script; |
|
| 971 | + } else { |
|
| 972 | + $this->trigger_template_error("Default plugin handler: Returned script file \"{$script}\" for \"{$tag}\" not found"); |
|
| 973 | + } |
|
| 974 | + } |
|
| 975 | + if (is_callable($callback)) { |
|
| 976 | + $this->default_handler_plugins[ $plugin_type ][ $tag ] = array($callback, true, array()); |
|
| 977 | + |
|
| 978 | + return true; |
|
| 979 | + } else { |
|
| 980 | + $this->trigger_template_error("Default plugin handler: Returned callback for \"{$tag}\" not callable"); |
|
| 981 | + } |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + return false; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + /** |
|
| 988 | + * Append code segments and remove unneeded ?> <?php transitions |
|
| 989 | + * |
|
| 990 | + * @param string $left |
|
| 991 | + * @param string $right |
|
| 992 | + * |
|
| 993 | + * @return string |
|
| 994 | + */ |
|
| 995 | + public function appendCode($left, $right) |
|
| 996 | + { |
|
| 997 | + if (preg_match('/\s*\?>\s*$/', $left) && preg_match('/^\s*<\?php\s+/', $right)) { |
|
| 998 | + $left = preg_replace('/\s*\?>\s*$/', "\n", $left); |
|
| 999 | + $left .= preg_replace('/^\s*<\?php\s+/', '', $right); |
|
| 1000 | + } else { |
|
| 1001 | + $left .= $right; |
|
| 1002 | + } |
|
| 1003 | + return $left; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * Inject inline code for nocache template sections |
|
| 1008 | + * This method gets the content of each template element from the parser. |
|
| 1009 | + * If the content is compiled code and it should be not cached the code is injected |
|
| 1010 | + * into the rendered output. |
|
| 1011 | + * |
|
| 1012 | + * @param string $content content of template element |
|
| 1013 | + * @param boolean $is_code true if content is compiled code |
|
| 1014 | + * |
|
| 1015 | + * @return string content |
|
| 1016 | + */ |
|
| 1017 | + public function processNocacheCode($content, $is_code) |
|
| 1018 | + { |
|
| 1019 | + // If the template is not evaluated and we have a nocache section and or a nocache tag |
|
| 1020 | + if ($is_code && !empty($content)) { |
|
| 1021 | + // generate replacement code |
|
| 1022 | + if ((!($this->template->source->handler->recompiled) || $this->forceNocache) && $this->template->caching && |
|
| 1023 | + !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache) |
|
| 1024 | + ) { |
|
| 1025 | + $this->template->compiled->has_nocache_code = true; |
|
| 1026 | + $_output = addcslashes($content, '\'\\'); |
|
| 1027 | + $_output = str_replace("^#^", "'", $_output); |
|
| 1028 | + $_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output . |
|
| 1029 | + "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n"; |
|
| 1030 | + // make sure we include modifier plugins for nocache code |
|
| 1031 | + foreach ($this->modifier_plugins as $plugin_name => $dummy) { |
|
| 1032 | + if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ])) { |
|
| 1033 | + $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ 'modifier' ] = |
|
| 1034 | + $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ]; |
|
| 1035 | + } |
|
| 1036 | + } |
|
| 1037 | + } else { |
|
| 1038 | + $_output = $content; |
|
| 1039 | + } |
|
| 1040 | + } else { |
|
| 1041 | + $_output = $content; |
|
| 1042 | + } |
|
| 1043 | + $this->modifier_plugins = array(); |
|
| 1044 | + $this->suppressNocacheProcessing = false; |
|
| 1045 | + $this->tag_nocache = false; |
|
| 1046 | + |
|
| 1047 | + return $_output; |
|
| 1048 | + } |
|
| 1049 | + |
|
| 1050 | + /** |
|
| 1051 | + * Get Id |
|
| 1052 | + * |
|
| 1053 | + * @param string $input |
|
| 1054 | + * |
|
| 1055 | + * @return bool|string |
|
| 1056 | + */ |
|
| 1057 | + public function getId($input) |
|
| 1058 | + { |
|
| 1059 | + if (preg_match('~^([\'"]*)([0-9]*[a-zA-Z_]\w*)\1$~', $input, $match)) { |
|
| 1060 | + return $match[ 2 ]; |
|
| 1061 | + } |
|
| 1062 | + return false; |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + /** |
|
| 1066 | + * Get variable name from string |
|
| 1067 | + * |
|
| 1068 | + * @param string $input |
|
| 1069 | + * |
|
| 1070 | + * @return bool|string |
|
| 1071 | + */ |
|
| 1072 | + public function getVariableName($input) |
|
| 1073 | + { |
|
| 1074 | + if (preg_match('~^[$]_smarty_tpl->tpl_vars\[[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*\]->value$~', $input, $match)) { |
|
| 1075 | + return $match[ 1 ]; |
|
| 1076 | + } |
|
| 1077 | + return false; |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + /** |
|
| 1081 | + * Set nocache flag in variable or create new variable |
|
| 1082 | + * |
|
| 1083 | + * @param string $varName |
|
| 1084 | + */ |
|
| 1085 | + public function setNocacheInVariable($varName) |
|
| 1086 | + { |
|
| 1087 | + // create nocache var to make it know for further compiling |
|
| 1088 | + if ($_var = $this->getId($varName)) { |
|
| 1089 | + if (isset($this->template->tpl_vars[ $_var ])) { |
|
| 1090 | + $this->template->tpl_vars[ $_var ] = clone $this->template->tpl_vars[ $_var ]; |
|
| 1091 | + $this->template->tpl_vars[ $_var ]->nocache = true; |
|
| 1092 | + } else { |
|
| 1093 | + $this->template->tpl_vars[ $_var ] = new Smarty_Variable(null, true); |
|
| 1094 | + } |
|
| 1095 | + } |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + /** |
|
| 1099 | + * @param array $_attr tag attributes |
|
| 1100 | + * @param array $validScopes |
|
| 1101 | + * |
|
| 1102 | + * @return int|string |
|
| 1103 | + * @throws \SmartyCompilerException |
|
| 1104 | + */ |
|
| 1105 | + public function convertScope($_attr, $validScopes) |
|
| 1106 | + { |
|
| 1107 | + $_scope = 0; |
|
| 1108 | + if (isset($_attr[ 'scope' ])) { |
|
| 1109 | + $_scopeName = trim($_attr[ 'scope' ], "'\""); |
|
| 1110 | + if (is_numeric($_scopeName) && in_array($_scopeName, $validScopes)) { |
|
| 1111 | + $_scope = $_scopeName; |
|
| 1112 | + } elseif (is_string($_scopeName)) { |
|
| 1113 | + $_scopeName = trim($_scopeName, "'\""); |
|
| 1114 | + $_scope = isset($validScopes[ $_scopeName ]) ? $validScopes[ $_scopeName ] : false; |
|
| 1115 | + } else { |
|
| 1116 | + $_scope = false; |
|
| 1117 | + } |
|
| 1118 | + if ($_scope === false) { |
|
| 1119 | + $err = var_export($_scopeName, true); |
|
| 1120 | + $this->trigger_template_error("illegal value '{$err}' for \"scope\" attribute", null, true); |
|
| 1121 | + } |
|
| 1122 | + } |
|
| 1123 | + return $_scope; |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + /** |
|
| 1127 | + * Generate nocache code string |
|
| 1128 | + * |
|
| 1129 | + * @param string $code PHP code |
|
| 1130 | + * |
|
| 1131 | + * @return string |
|
| 1132 | + */ |
|
| 1133 | + public function makeNocacheCode($code) |
|
| 1134 | + { |
|
| 1135 | + return "echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/<?php " . |
|
| 1136 | + str_replace("^#^", "'", addcslashes($code, '\'\\')) . |
|
| 1137 | + "?>/*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n"; |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + /** |
|
| 1141 | + * display compiler error messages without dying |
|
| 1142 | + * If parameter $args is empty it is a parser detected syntax error. |
|
| 1143 | + * In this case the parser is called to obtain information about expected tokens. |
|
| 1144 | + * If parameter $args contains a string this is used as error message |
|
| 1145 | + * |
|
| 1146 | + * @param string $args individual error message or null |
|
| 1147 | + * @param string $line line-number |
|
| 1148 | + * @param null|bool $tagline if true the line number of last tag |
|
| 1149 | + * |
|
| 1150 | + * @throws \SmartyCompilerException when an unexpected token is found |
|
| 1151 | + */ |
|
| 1152 | + public function trigger_template_error($args = null, $line = null, $tagline = null) |
|
| 1153 | + { |
|
| 1154 | + $lex = $this->parser->lex; |
|
| 1155 | + if ($tagline === true) { |
|
| 1156 | + // get line number of Tag |
|
| 1157 | + $line = $lex->taglineno; |
|
| 1158 | + } elseif (!isset($line)) { |
|
| 1159 | + // get template source line which has error |
|
| 1160 | + $line = $lex->line; |
|
| 1161 | + } else { |
|
| 1162 | + $line = (int) $line; |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + if (in_array($this->template->source->type, array('eval', 'string'))) { |
|
| 1166 | + $templateName = $this->template->source->type . ':' . trim(preg_replace('![\t\r\n]+!', ' ', |
|
| 1167 | + strlen($lex->data) > 40 ? |
|
| 1168 | + substr($lex->data, 0, 40) . |
|
| 1169 | + '...' : $lex->data)); |
|
| 1170 | + } else { |
|
| 1171 | + $templateName = $this->template->source->type . ':' . $this->template->source->filepath; |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + // $line += $this->trace_line_offset; |
|
| 1175 | + $match = preg_split("/\n/", $lex->data); |
|
| 1176 | + $error_text = |
|
| 1177 | + 'Syntax error in template "' . (empty($this->trace_filepath) ? $templateName : $this->trace_filepath) . |
|
| 1178 | + '" on line ' . ($line + $this->trace_line_offset) . ' "' . |
|
| 1179 | + trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ])) . '" '; |
|
| 1180 | + if (isset($args)) { |
|
| 1181 | + // individual error message |
|
| 1182 | + $error_text .= $args; |
|
| 1183 | + } else { |
|
| 1184 | + $expect = array(); |
|
| 1185 | + // expected token from parser |
|
| 1186 | + $error_text .= ' - Unexpected "' . $lex->value . '"'; |
|
| 1187 | + if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) { |
|
| 1188 | + foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { |
|
| 1189 | + $exp_token = $this->parser->yyTokenName[ $token ]; |
|
| 1190 | + if (isset($lex->smarty_token_names[ $exp_token ])) { |
|
| 1191 | + // token type from lexer |
|
| 1192 | + $expect[] = '"' . $lex->smarty_token_names[ $exp_token ] . '"'; |
|
| 1193 | + } else { |
|
| 1194 | + // otherwise internal token name |
|
| 1195 | + $expect[] = $this->parser->yyTokenName[ $token ]; |
|
| 1196 | + } |
|
| 1197 | + } |
|
| 1198 | + $error_text .= ', expected one of: ' . implode(' , ', $expect); |
|
| 1199 | + } |
|
| 1200 | + } |
|
| 1201 | + $e = new SmartyCompilerException($error_text); |
|
| 1202 | + $e->line = $line; |
|
| 1203 | + $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ])); |
|
| 1204 | + $e->desc = $args; |
|
| 1205 | + $e->template = $this->template->source->filepath; |
|
| 1206 | + throw $e; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + /** |
|
| 1210 | + * Return var_export() value with all white spaces removed |
|
| 1211 | + * |
|
| 1212 | + * @param mixed $value |
|
| 1213 | + * |
|
| 1214 | + * @return string |
|
| 1215 | + */ |
|
| 1216 | + public function getVarExport($value) |
|
| 1217 | + { |
|
| 1218 | + return preg_replace('/\s/', '', var_export($value, true)); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + /** |
|
| 1222 | + * Check if $value contains variable elements |
|
| 1223 | + * |
|
| 1224 | + * @param mixed $value |
|
| 1225 | + * |
|
| 1226 | + * @return bool|int |
|
| 1227 | + */ |
|
| 1228 | + public function isVariable($value) |
|
| 1229 | + { |
|
| 1230 | + if (is_string($value)) { |
|
| 1231 | + return preg_match('/[$(]/', $value); |
|
| 1232 | + } |
|
| 1233 | + if (is_bool($value) || is_numeric($value)) { |
|
| 1234 | + return false; |
|
| 1235 | + } |
|
| 1236 | + if (is_array($value)) { |
|
| 1237 | + foreach ($value as $k => $v) { |
|
| 1238 | + if ($this->isVariable($k) || $this->isVariable($v)) { |
|
| 1239 | + return true; |
|
| 1240 | + } |
|
| 1241 | + } |
|
| 1242 | + return false; |
|
| 1243 | + } |
|
| 1244 | + return false; |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + /** |
|
| 1248 | + * Get new prefix variable name |
|
| 1249 | + * |
|
| 1250 | + * @return string |
|
| 1251 | + */ |
|
| 1252 | + public function getNewPrefixVariable() |
|
| 1253 | + { |
|
| 1254 | + self::$prefixVariableNumber ++; |
|
| 1255 | + return $this->getPrefixVariable(); |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + /** |
|
| 1259 | + * Get current prefix variable name |
|
| 1260 | + * |
|
| 1261 | + * @return string |
|
| 1262 | + */ |
|
| 1263 | + public function getPrefixVariable() |
|
| 1264 | + { |
|
| 1265 | + return '$_prefixVariable' . self::$prefixVariableNumber; |
|
| 1266 | + } |
|
| 1267 | + |
|
| 1268 | + /** |
|
| 1269 | + * append code to prefix buffer |
|
| 1270 | + * |
|
| 1271 | + * @param string $code |
|
| 1272 | + */ |
|
| 1273 | + public function appendPrefixCode($code) |
|
| 1274 | + { |
|
| 1275 | + $this->prefix_code[] = $code; |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + /** |
|
| 1279 | + * get prefix code string |
|
| 1280 | + * |
|
| 1281 | + * @return string |
|
| 1282 | + */ |
|
| 1283 | + public function getPrefixCode() |
|
| 1284 | + { |
|
| 1285 | + $code = ''; |
|
| 1286 | + $prefixArray = array_merge($this->prefix_code, array_pop($this->prefixCodeStack)); |
|
| 1287 | + $this->prefixCodeStack[] = array(); |
|
| 1288 | + foreach ($prefixArray as $c) { |
|
| 1289 | + $code = $this->appendCode($code, $c); |
|
| 1290 | + } |
|
| 1291 | + $this->prefix_code = array(); |
|
| 1292 | + return $code; |
|
| 1293 | + } |
|
| 1294 | 1294 | |
| 1295 | 1295 | } |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | $this->prefix_code = array(); |
| 387 | 387 | // add file dependency |
| 388 | 388 | if ($this->smarty->merge_compiled_includes || $this->template->source->handler->checkTimestamps()) { |
| 389 | - $this->parent_compiler->template->compiled->file_dependency[ $this->template->source->uid ] = |
|
| 389 | + $this->parent_compiler->template->compiled->file_dependency[$this->template->source->uid] = |
|
| 390 | 390 | array($this->template->source->filepath, $this->template->source->getTimeStamp(), |
| 391 | 391 | $this->template->source->type,); |
| 392 | 392 | } |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | { |
| 435 | 435 | // run post filter if on code |
| 436 | 436 | if (!empty($code) && |
| 437 | - (isset($this->smarty->autoload_filters[ 'post' ]) || isset($this->smarty->registered_filters[ 'post' ])) |
|
| 437 | + (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) |
|
| 438 | 438 | ) { |
| 439 | 439 | return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template); |
| 440 | 440 | } else { |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | { |
| 455 | 455 | // run pre filter if required |
| 456 | 456 | if ($_content != '' && |
| 457 | - ((isset($this->smarty->autoload_filters[ 'pre' ]) || isset($this->smarty->registered_filters[ 'pre' ]))) |
|
| 457 | + ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre']))) |
|
| 458 | 458 | ) { |
| 459 | 459 | return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template); |
| 460 | 460 | } else { |
@@ -507,8 +507,8 @@ discard block |
||
| 507 | 507 | $this->has_code = true; |
| 508 | 508 | $this->has_output = false; |
| 509 | 509 | // log tag/attributes |
| 510 | - if (isset($this->smarty->_cache[ 'get_used_tags' ])) { |
|
| 511 | - $this->template->_cache[ 'used_tags' ][] = array($tag, $args); |
|
| 510 | + if (isset($this->smarty->_cache['get_used_tags'])) { |
|
| 511 | + $this->template->_cache['used_tags'][] = array($tag, $args); |
|
| 512 | 512 | } |
| 513 | 513 | // check nocache option flag |
| 514 | 514 | foreach ($args as $arg) { |
@@ -526,9 +526,9 @@ discard block |
||
| 526 | 526 | } |
| 527 | 527 | // compile the smarty tag (required compile classes to compile the tag are auto loaded) |
| 528 | 528 | if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) { |
| 529 | - if (isset($this->parent_compiler->tpl_function[ $tag ])) { |
|
| 529 | + if (isset($this->parent_compiler->tpl_function[$tag])) { |
|
| 530 | 530 | // template defined by {template} tag |
| 531 | - $args[ '_attr' ][ 'name' ] = "'" . $tag . "'"; |
|
| 531 | + $args['_attr']['name'] = "'" . $tag . "'"; |
|
| 532 | 532 | $_output = $this->callTagCompiler('call', $args, $parameter); |
| 533 | 533 | } |
| 534 | 534 | } |
@@ -548,8 +548,8 @@ discard block |
||
| 548 | 548 | return null; |
| 549 | 549 | } else { |
| 550 | 550 | // map_named attributes |
| 551 | - if (isset($args[ '_attr' ])) { |
|
| 552 | - foreach ($args[ '_attr' ] as $key => $attribute) { |
|
| 551 | + if (isset($args['_attr'])) { |
|
| 552 | + foreach ($args['_attr'] as $key => $attribute) { |
|
| 553 | 553 | if (is_array($attribute)) { |
| 554 | 554 | $args = array_merge($args, $attribute); |
| 555 | 555 | } |
@@ -558,14 +558,14 @@ discard block |
||
| 558 | 558 | // not an internal compiler tag |
| 559 | 559 | if (strlen($tag) < 6 || substr($tag, - 5) != 'close') { |
| 560 | 560 | // check if tag is a registered object |
| 561 | - if (isset($this->smarty->registered_objects[ $tag ]) && isset($parameter[ 'object_method' ])) { |
|
| 562 | - $method = $parameter[ 'object_method' ]; |
|
| 563 | - if (!in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ]) && |
|
| 564 | - (empty($this->smarty->registered_objects[ $tag ][ 1 ]) || |
|
| 565 | - in_array($method, $this->smarty->registered_objects[ $tag ][ 1 ])) |
|
| 561 | + if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_method'])) { |
|
| 562 | + $method = $parameter['object_method']; |
|
| 563 | + if (!in_array($method, $this->smarty->registered_objects[$tag][3]) && |
|
| 564 | + (empty($this->smarty->registered_objects[$tag][1]) || |
|
| 565 | + in_array($method, $this->smarty->registered_objects[$tag][1])) |
|
| 566 | 566 | ) { |
| 567 | 567 | return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method); |
| 568 | - } elseif (in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ])) { |
|
| 568 | + } elseif (in_array($method, $this->smarty->registered_objects[$tag][3])) { |
|
| 569 | 569 | return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, |
| 570 | 570 | $method); |
| 571 | 571 | } else { |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | // check if tag is registered |
| 578 | 578 | foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK,) as $plugin_type) |
| 579 | 579 | { |
| 580 | - if (isset($this->smarty->registered_plugins[ $plugin_type ][ $tag ])) { |
|
| 580 | + if (isset($this->smarty->registered_plugins[$plugin_type][$tag])) { |
|
| 581 | 581 | // if compiler function plugin call it now |
| 582 | 582 | if ($plugin_type == Smarty::PLUGIN_COMPILER) { |
| 583 | 583 | $new_args = array(); |
@@ -585,13 +585,13 @@ discard block |
||
| 585 | 585 | if (is_array($mixed)) { |
| 586 | 586 | $new_args = array_merge($new_args, $mixed); |
| 587 | 587 | } else { |
| 588 | - $new_args[ $key ] = $mixed; |
|
| 588 | + $new_args[$key] = $mixed; |
|
| 589 | 589 | } |
| 590 | 590 | } |
| 591 | - if (!$this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 1 ]) { |
|
| 591 | + if (!$this->smarty->registered_plugins[$plugin_type][$tag][1]) { |
|
| 592 | 592 | $this->tag_nocache = true; |
| 593 | 593 | } |
| 594 | - return call_user_func_array($this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 0 ], |
|
| 594 | + return call_user_func_array($this->smarty->registered_plugins[$plugin_type][$tag][0], |
|
| 595 | 595 | array($new_args, $this)); |
| 596 | 596 | } |
| 597 | 597 | // compile registered function or block function |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | if (is_array($mixed)) { |
| 617 | 617 | $new_args = array_merge($new_args, $mixed); |
| 618 | 618 | } else { |
| 619 | - $new_args[ $key ] = $mixed; |
|
| 619 | + $new_args[$key] = $mixed; |
|
| 620 | 620 | } |
| 621 | 621 | } |
| 622 | 622 | |
@@ -644,7 +644,7 @@ discard block |
||
| 644 | 644 | $found = false; |
| 645 | 645 | // look for already resolved tags |
| 646 | 646 | foreach ($this->plugin_search_order as $plugin_type) { |
| 647 | - if (isset($this->default_handler_plugins[ $plugin_type ][ $tag ])) { |
|
| 647 | + if (isset($this->default_handler_plugins[$plugin_type][$tag])) { |
|
| 648 | 648 | $found = true; |
| 649 | 649 | break; |
| 650 | 650 | } |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | foreach ($args as $mixed) { |
| 666 | 666 | $new_args = array_merge($new_args, $mixed); |
| 667 | 667 | } |
| 668 | - return call_user_func_array($this->default_handler_plugins[ $plugin_type ][ $tag ][ 0 ], |
|
| 668 | + return call_user_func_array($this->default_handler_plugins[$plugin_type][$tag][0], |
|
| 669 | 669 | array($new_args, $this)); |
| 670 | 670 | } else { |
| 671 | 671 | return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, |
@@ -677,9 +677,9 @@ discard block |
||
| 677 | 677 | // compile closing tag of block function |
| 678 | 678 | $base_tag = substr($tag, 0, - 5); |
| 679 | 679 | // check if closing tag is a registered object |
| 680 | - if (isset($this->smarty->registered_objects[ $base_tag ]) && isset($parameter[ 'object_method' ])) { |
|
| 681 | - $method = $parameter[ 'object_method' ]; |
|
| 682 | - if (in_array($method, $this->smarty->registered_objects[ $base_tag ][ 3 ])) { |
|
| 680 | + if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_method'])) { |
|
| 681 | + $method = $parameter['object_method']; |
|
| 682 | + if (in_array($method, $this->smarty->registered_objects[$base_tag][3])) { |
|
| 683 | 683 | return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, |
| 684 | 684 | $method); |
| 685 | 685 | } else { |
@@ -689,13 +689,13 @@ discard block |
||
| 689 | 689 | } |
| 690 | 690 | } |
| 691 | 691 | // registered block tag ? |
| 692 | - if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ]) || |
|
| 693 | - isset($this->default_handler_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ]) |
|
| 692 | + if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag]) || |
|
| 693 | + isset($this->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag]) |
|
| 694 | 694 | ) { |
| 695 | 695 | return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag); |
| 696 | 696 | } |
| 697 | 697 | // registered function tag ? |
| 698 | - if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ])) { |
|
| 698 | + if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) { |
|
| 699 | 699 | return $this->callTagCompiler('private_registered_function', $args, $parameter, $tag); |
| 700 | 700 | } |
| 701 | 701 | // block plugin? |
@@ -711,13 +711,13 @@ discard block |
||
| 711 | 711 | } |
| 712 | 712 | } |
| 713 | 713 | // registered compiler plugin ? |
| 714 | - if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ])) { |
|
| 714 | + if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag])) { |
|
| 715 | 715 | // if compiler function plugin call it now |
| 716 | 716 | $args = array(); |
| 717 | - if (!$this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 1 ]) { |
|
| 717 | + if (!$this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][1]) { |
|
| 718 | 718 | $this->tag_nocache = true; |
| 719 | 719 | } |
| 720 | - return call_user_func_array($this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 0 ], |
|
| 720 | + return call_user_func_array($this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][0], |
|
| 721 | 721 | array($args, $this)); |
| 722 | 722 | } |
| 723 | 723 | if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) { |
@@ -792,13 +792,13 @@ discard block |
||
| 792 | 792 | if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is', |
| 793 | 793 | $text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { |
| 794 | 794 | foreach ($matches as $match) { |
| 795 | - $store[] = $match[ 0 ][ 0 ]; |
|
| 796 | - $_length = strlen($match[ 0 ][ 0 ]); |
|
| 795 | + $store[] = $match[0][0]; |
|
| 796 | + $_length = strlen($match[0][0]); |
|
| 797 | 797 | $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; |
| 798 | - $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] - $_offset, $_length); |
|
| 798 | + $text = substr_replace($text, $replace, $match[0][1] - $_offset, $_length); |
|
| 799 | 799 | |
| 800 | 800 | $_offset += $_length - strlen($replace); |
| 801 | - $_store ++; |
|
| 801 | + $_store++; |
|
| 802 | 802 | } |
| 803 | 803 | } |
| 804 | 804 | $expressions = array(// replace multiple spaces between tags by a single space |
@@ -815,12 +815,12 @@ discard block |
||
| 815 | 815 | if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $text, $matches, |
| 816 | 816 | PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { |
| 817 | 817 | foreach ($matches as $match) { |
| 818 | - $_length = strlen($match[ 0 ][ 0 ]); |
|
| 819 | - $replace = $store[ $match[ 1 ][ 0 ] ]; |
|
| 820 | - $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length); |
|
| 818 | + $_length = strlen($match[0][0]); |
|
| 819 | + $replace = $store[$match[1][0]]; |
|
| 820 | + $text = substr_replace($text, $replace, $match[0][1] + $_offset, $_length); |
|
| 821 | 821 | |
| 822 | 822 | $_offset += strlen($replace) - $_length; |
| 823 | - $_store ++; |
|
| 823 | + $_store++; |
|
| 824 | 824 | } |
| 825 | 825 | } |
| 826 | 826 | } else { |
@@ -849,7 +849,7 @@ discard block |
||
| 849 | 849 | public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) |
| 850 | 850 | { |
| 851 | 851 | // re-use object if already exists |
| 852 | - if (!isset(self::$_tag_objects[ $tag ])) { |
|
| 852 | + if (!isset(self::$_tag_objects[$tag])) { |
|
| 853 | 853 | // lazy load internal compiler plugin |
| 854 | 854 | $_tag = explode('_', $tag); |
| 855 | 855 | $_tag = array_map('ucfirst', $_tag); |
@@ -857,15 +857,14 @@ discard block |
||
| 857 | 857 | if (class_exists($class_name) && |
| 858 | 858 | (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) |
| 859 | 859 | ) { |
| 860 | - self::$_tag_objects[ $tag ] = new $class_name; |
|
| 860 | + self::$_tag_objects[$tag] = new $class_name; |
|
| 861 | 861 | } else { |
| 862 | - self::$_tag_objects[ $tag ] = false; |
|
| 862 | + self::$_tag_objects[$tag] = false; |
|
| 863 | 863 | return false; |
| 864 | 864 | } |
| 865 | 865 | } |
| 866 | 866 | // compile this tag |
| 867 | - return self::$_tag_objects[ $tag ] === false ? false : |
|
| 868 | - self::$_tag_objects[ $tag ]->compile($args, $this, $param1, $param2, $param3); |
|
| 867 | + return self::$_tag_objects[$tag] === false ? false : self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3); |
|
| 869 | 868 | } |
| 870 | 869 | |
| 871 | 870 | /** |
@@ -880,29 +879,29 @@ discard block |
||
| 880 | 879 | { |
| 881 | 880 | $function = null; |
| 882 | 881 | if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { |
| 883 | - if (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) { |
|
| 882 | + if (isset($this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type])) { |
|
| 884 | 883 | $function = |
| 885 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ]; |
|
| 886 | - } elseif (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) { |
|
| 887 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] = |
|
| 888 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ]; |
|
| 884 | + $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; |
|
| 885 | + } elseif (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type])) { |
|
| 886 | + $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type] = |
|
| 887 | + $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]; |
|
| 889 | 888 | $function = |
| 890 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ]; |
|
| 889 | + $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; |
|
| 891 | 890 | } |
| 892 | 891 | } else { |
| 893 | - if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) { |
|
| 892 | + if (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type])) { |
|
| 894 | 893 | $function = |
| 895 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ]; |
|
| 896 | - } elseif (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) { |
|
| 897 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] = |
|
| 898 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ]; |
|
| 894 | + $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; |
|
| 895 | + } elseif (isset($this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type])) { |
|
| 896 | + $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type] = |
|
| 897 | + $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]; |
|
| 899 | 898 | $function = |
| 900 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ]; |
|
| 899 | + $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; |
|
| 901 | 900 | } |
| 902 | 901 | } |
| 903 | 902 | if (isset($function)) { |
| 904 | 903 | if ($plugin_type == 'modifier') { |
| 905 | - $this->modifier_plugins[ $plugin_name ] = true; |
|
| 904 | + $this->modifier_plugins[$plugin_name] = true; |
|
| 906 | 905 | } |
| 907 | 906 | |
| 908 | 907 | return $function; |
@@ -913,18 +912,18 @@ discard block |
||
| 913 | 912 | |
| 914 | 913 | if (is_string($file)) { |
| 915 | 914 | if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { |
| 916 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'file' ] = |
|
| 915 | + $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = |
|
| 917 | 916 | $file; |
| 918 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ] = |
|
| 917 | + $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = |
|
| 919 | 918 | $function; |
| 920 | 919 | } else { |
| 921 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'file' ] = |
|
| 920 | + $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] = |
|
| 922 | 921 | $file; |
| 923 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ] = |
|
| 922 | + $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = |
|
| 924 | 923 | $function; |
| 925 | 924 | } |
| 926 | 925 | if ($plugin_type == 'modifier') { |
| 927 | - $this->modifier_plugins[ $plugin_name ] = true; |
|
| 926 | + $this->modifier_plugins[$plugin_name] = true; |
|
| 928 | 927 | } |
| 929 | 928 | |
| 930 | 929 | return $function; |
@@ -957,14 +956,14 @@ discard block |
||
| 957 | 956 | if ($script !== null) { |
| 958 | 957 | if (is_file($script)) { |
| 959 | 958 | if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { |
| 960 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'file' ] = |
|
| 959 | + $this->parent_compiler->template->compiled->required_plugins['nocache'][$tag][$plugin_type]['file'] = |
|
| 961 | 960 | $script; |
| 962 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'function' ] = |
|
| 961 | + $this->parent_compiler->template->compiled->required_plugins['nocache'][$tag][$plugin_type]['function'] = |
|
| 963 | 962 | $callback; |
| 964 | 963 | } else { |
| 965 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'file' ] = |
|
| 964 | + $this->parent_compiler->template->compiled->required_plugins['compiled'][$tag][$plugin_type]['file'] = |
|
| 966 | 965 | $script; |
| 967 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'function' ] = |
|
| 966 | + $this->parent_compiler->template->compiled->required_plugins['compiled'][$tag][$plugin_type]['function'] = |
|
| 968 | 967 | $callback; |
| 969 | 968 | } |
| 970 | 969 | require_once $script; |
@@ -973,7 +972,7 @@ discard block |
||
| 973 | 972 | } |
| 974 | 973 | } |
| 975 | 974 | if (is_callable($callback)) { |
| 976 | - $this->default_handler_plugins[ $plugin_type ][ $tag ] = array($callback, true, array()); |
|
| 975 | + $this->default_handler_plugins[$plugin_type][$tag] = array($callback, true, array()); |
|
| 977 | 976 | |
| 978 | 977 | return true; |
| 979 | 978 | } else { |
@@ -1029,9 +1028,9 @@ discard block |
||
| 1029 | 1028 | "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n"; |
| 1030 | 1029 | // make sure we include modifier plugins for nocache code |
| 1031 | 1030 | foreach ($this->modifier_plugins as $plugin_name => $dummy) { |
| 1032 | - if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ])) { |
|
| 1033 | - $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ 'modifier' ] = |
|
| 1034 | - $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ]; |
|
| 1031 | + if (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name]['modifier'])) { |
|
| 1032 | + $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name]['modifier'] = |
|
| 1033 | + $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name]['modifier']; |
|
| 1035 | 1034 | } |
| 1036 | 1035 | } |
| 1037 | 1036 | } else { |
@@ -1057,7 +1056,7 @@ discard block |
||
| 1057 | 1056 | public function getId($input) |
| 1058 | 1057 | { |
| 1059 | 1058 | if (preg_match('~^([\'"]*)([0-9]*[a-zA-Z_]\w*)\1$~', $input, $match)) { |
| 1060 | - return $match[ 2 ]; |
|
| 1059 | + return $match[2]; |
|
| 1061 | 1060 | } |
| 1062 | 1061 | return false; |
| 1063 | 1062 | } |
@@ -1072,7 +1071,7 @@ discard block |
||
| 1072 | 1071 | public function getVariableName($input) |
| 1073 | 1072 | { |
| 1074 | 1073 | if (preg_match('~^[$]_smarty_tpl->tpl_vars\[[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*\]->value$~', $input, $match)) { |
| 1075 | - return $match[ 1 ]; |
|
| 1074 | + return $match[1]; |
|
| 1076 | 1075 | } |
| 1077 | 1076 | return false; |
| 1078 | 1077 | } |
@@ -1086,11 +1085,11 @@ discard block |
||
| 1086 | 1085 | { |
| 1087 | 1086 | // create nocache var to make it know for further compiling |
| 1088 | 1087 | if ($_var = $this->getId($varName)) { |
| 1089 | - if (isset($this->template->tpl_vars[ $_var ])) { |
|
| 1090 | - $this->template->tpl_vars[ $_var ] = clone $this->template->tpl_vars[ $_var ]; |
|
| 1091 | - $this->template->tpl_vars[ $_var ]->nocache = true; |
|
| 1088 | + if (isset($this->template->tpl_vars[$_var])) { |
|
| 1089 | + $this->template->tpl_vars[$_var] = clone $this->template->tpl_vars[$_var]; |
|
| 1090 | + $this->template->tpl_vars[$_var]->nocache = true; |
|
| 1092 | 1091 | } else { |
| 1093 | - $this->template->tpl_vars[ $_var ] = new Smarty_Variable(null, true); |
|
| 1092 | + $this->template->tpl_vars[$_var] = new Smarty_Variable(null, true); |
|
| 1094 | 1093 | } |
| 1095 | 1094 | } |
| 1096 | 1095 | } |
@@ -1105,13 +1104,13 @@ discard block |
||
| 1105 | 1104 | public function convertScope($_attr, $validScopes) |
| 1106 | 1105 | { |
| 1107 | 1106 | $_scope = 0; |
| 1108 | - if (isset($_attr[ 'scope' ])) { |
|
| 1109 | - $_scopeName = trim($_attr[ 'scope' ], "'\""); |
|
| 1107 | + if (isset($_attr['scope'])) { |
|
| 1108 | + $_scopeName = trim($_attr['scope'], "'\""); |
|
| 1110 | 1109 | if (is_numeric($_scopeName) && in_array($_scopeName, $validScopes)) { |
| 1111 | 1110 | $_scope = $_scopeName; |
| 1112 | 1111 | } elseif (is_string($_scopeName)) { |
| 1113 | 1112 | $_scopeName = trim($_scopeName, "'\""); |
| 1114 | - $_scope = isset($validScopes[ $_scopeName ]) ? $validScopes[ $_scopeName ] : false; |
|
| 1113 | + $_scope = isset($validScopes[$_scopeName]) ? $validScopes[$_scopeName] : false; |
|
| 1115 | 1114 | } else { |
| 1116 | 1115 | $_scope = false; |
| 1117 | 1116 | } |
@@ -1176,7 +1175,7 @@ discard block |
||
| 1176 | 1175 | $error_text = |
| 1177 | 1176 | 'Syntax error in template "' . (empty($this->trace_filepath) ? $templateName : $this->trace_filepath) . |
| 1178 | 1177 | '" on line ' . ($line + $this->trace_line_offset) . ' "' . |
| 1179 | - trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ])) . '" '; |
|
| 1178 | + trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])) . '" '; |
|
| 1180 | 1179 | if (isset($args)) { |
| 1181 | 1180 | // individual error message |
| 1182 | 1181 | $error_text .= $args; |
@@ -1186,13 +1185,13 @@ discard block |
||
| 1186 | 1185 | $error_text .= ' - Unexpected "' . $lex->value . '"'; |
| 1187 | 1186 | if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) { |
| 1188 | 1187 | foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { |
| 1189 | - $exp_token = $this->parser->yyTokenName[ $token ]; |
|
| 1190 | - if (isset($lex->smarty_token_names[ $exp_token ])) { |
|
| 1188 | + $exp_token = $this->parser->yyTokenName[$token]; |
|
| 1189 | + if (isset($lex->smarty_token_names[$exp_token])) { |
|
| 1191 | 1190 | // token type from lexer |
| 1192 | - $expect[] = '"' . $lex->smarty_token_names[ $exp_token ] . '"'; |
|
| 1191 | + $expect[] = '"' . $lex->smarty_token_names[$exp_token] . '"'; |
|
| 1193 | 1192 | } else { |
| 1194 | 1193 | // otherwise internal token name |
| 1195 | - $expect[] = $this->parser->yyTokenName[ $token ]; |
|
| 1194 | + $expect[] = $this->parser->yyTokenName[$token]; |
|
| 1196 | 1195 | } |
| 1197 | 1196 | } |
| 1198 | 1197 | $error_text .= ', expected one of: ' . implode(' , ', $expect); |
@@ -1200,7 +1199,7 @@ discard block |
||
| 1200 | 1199 | } |
| 1201 | 1200 | $e = new SmartyCompilerException($error_text); |
| 1202 | 1201 | $e->line = $line; |
| 1203 | - $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ])); |
|
| 1202 | + $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])); |
|
| 1204 | 1203 | $e->desc = $args; |
| 1205 | 1204 | $e->template = $this->template->source->filepath; |
| 1206 | 1205 | throw $e; |
@@ -1251,7 +1250,7 @@ discard block |
||
| 1251 | 1250 | */ |
| 1252 | 1251 | public function getNewPrefixVariable() |
| 1253 | 1252 | { |
| 1254 | - self::$prefixVariableNumber ++; |
|
| 1253 | + self::$prefixVariableNumber++; |
|
| 1255 | 1254 | return $this->getPrefixVariable(); |
| 1256 | 1255 | } |
| 1257 | 1256 | |
@@ -213,8 +213,7 @@ |
||
| 213 | 213 | error_reporting($_smarty_old_error_level); |
| 214 | 214 | } |
| 215 | 215 | return $result; |
| 216 | - } |
|
| 217 | - catch (Exception $e) { |
|
| 216 | + } catch (Exception $e) { |
|
| 218 | 217 | while (ob_get_level() > $level) { |
| 219 | 218 | ob_end_clean(); |
| 220 | 219 | } |
@@ -241,6 +241,9 @@ discard block |
||
| 241 | 241 | return $this->{'yylex' . $this->_yy_state}(); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | + /** |
|
| 245 | + * @param integer $state |
|
| 246 | + */ |
|
| 244 | 247 | public function yypushstate($state) |
| 245 | 248 | { |
| 246 | 249 | if ($this->yyTraceFILE) { |
@@ -272,6 +275,9 @@ discard block |
||
| 272 | 275 | } |
| 273 | 276 | } |
| 274 | 277 | |
| 278 | + /** |
|
| 279 | + * @param integer $state |
|
| 280 | + */ |
|
| 275 | 281 | public function yybegin($state) |
| 276 | 282 | { |
| 277 | 283 | $this->_yy_state = $state; |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | $this->data = $data; |
| 205 | 205 | $this->counter = 0; |
| 206 | 206 | if (preg_match('/^\xEF\xBB\xBF/i', $this->data, $match)) { |
| 207 | - $this->counter += strlen($match[ 0 ]); |
|
| 207 | + $this->counter += strlen($match[0]); |
|
| 208 | 208 | } |
| 209 | 209 | $this->line = 1; |
| 210 | 210 | $this->smarty = $compiler->smarty; |
@@ -213,8 +213,8 @@ discard block |
||
| 213 | 213 | $this->ldel_length = strlen($this->smarty->left_delimiter); |
| 214 | 214 | $this->rdel = preg_quote($this->smarty->right_delimiter, '/'); |
| 215 | 215 | $this->rdel_length = strlen($this->smarty->right_delimiter); |
| 216 | - $this->smarty_token_names[ 'LDEL' ] = $this->smarty->left_delimiter; |
|
| 217 | - $this->smarty_token_names[ 'RDEL' ] = $this->smarty->right_delimiter; |
|
| 216 | + $this->smarty_token_names['LDEL'] = $this->smarty->left_delimiter; |
|
| 217 | + $this->smarty_token_names['RDEL'] = $this->smarty->right_delimiter; |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | public function PrintTrace() |
@@ -228,8 +228,8 @@ discard block |
||
| 228 | 228 | */ |
| 229 | 229 | public function isAutoLiteral() |
| 230 | 230 | { |
| 231 | - return $this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 232 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false; |
|
| 231 | + return $this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? |
|
| 232 | + strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | private $_yy_state = 1; |
@@ -245,15 +245,13 @@ discard block |
||
| 245 | 245 | { |
| 246 | 246 | if ($this->yyTraceFILE) { |
| 247 | 247 | fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, |
| 248 | - isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 249 | - $this->_yy_state); |
|
| 248 | + isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); |
|
| 250 | 249 | } |
| 251 | 250 | array_push($this->_yy_stack, $this->_yy_state); |
| 252 | 251 | $this->_yy_state = $state; |
| 253 | 252 | if ($this->yyTraceFILE) { |
| 254 | 253 | fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, |
| 255 | - isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 256 | - $this->_yy_state); |
|
| 254 | + isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); |
|
| 257 | 255 | } |
| 258 | 256 | } |
| 259 | 257 | |
@@ -261,14 +259,12 @@ discard block |
||
| 261 | 259 | { |
| 262 | 260 | if ($this->yyTraceFILE) { |
| 263 | 261 | fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, |
| 264 | - isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 265 | - $this->_yy_state); |
|
| 262 | + isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); |
|
| 266 | 263 | } |
| 267 | 264 | $this->_yy_state = array_pop($this->_yy_stack); |
| 268 | 265 | if ($this->yyTraceFILE) { |
| 269 | 266 | fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, |
| 270 | - isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 271 | - $this->_yy_state); |
|
| 267 | + isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); |
|
| 272 | 268 | } |
| 273 | 269 | } |
| 274 | 270 | |
@@ -277,8 +273,7 @@ discard block |
||
| 277 | 273 | $this->_yy_state = $state; |
| 278 | 274 | if ($this->yyTraceFILE) { |
| 279 | 275 | fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, |
| 280 | - isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 281 | - $this->_yy_state); |
|
| 276 | + isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); |
|
| 282 | 277 | } |
| 283 | 278 | } |
| 284 | 279 | |
@@ -298,7 +293,7 @@ discard block |
||
| 298 | 293 | do { |
| 299 | 294 | if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, null, $this->counter)) { |
| 300 | 295 | $yysubmatches = $yymatches; |
| 301 | - if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 296 | + if (strlen($yysubmatches[0]) < 200) { |
|
| 302 | 297 | $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
| 303 | 298 | } else { |
| 304 | 299 | $yymatches = array_filter($yymatches, 'strlen'); |
@@ -330,7 +325,7 @@ discard block |
||
| 330 | 325 | continue; |
| 331 | 326 | } |
| 332 | 327 | } else { |
| 333 | - throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 328 | + throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); |
|
| 334 | 329 | } |
| 335 | 330 | break; |
| 336 | 331 | } |
@@ -349,8 +344,8 @@ discard block |
||
| 349 | 344 | { |
| 350 | 345 | |
| 351 | 346 | preg_match("/[*]{$this->rdel}/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); |
| 352 | - if (isset($match[ 0 ][ 1 ])) { |
|
| 353 | - $to = $match[ 0 ][ 1 ] + strlen($match[ 0 ][ 0 ]); |
|
| 347 | + if (isset($match[0][1])) { |
|
| 348 | + $to = $match[0][1] + strlen($match[0][0]); |
|
| 354 | 349 | } else { |
| 355 | 350 | $this->compiler->trigger_template_error("missing or misspelled comment closing tag '*{$this->smarty->right_delimiter}'"); |
| 356 | 351 | } |
@@ -368,8 +363,8 @@ discard block |
||
| 368 | 363 | function yy_r1_7() |
| 369 | 364 | { |
| 370 | 365 | |
| 371 | - if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 372 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 366 | + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? |
|
| 367 | + strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false |
|
| 373 | 368 | ) { |
| 374 | 369 | $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
| 375 | 370 | } else { |
@@ -381,8 +376,8 @@ discard block |
||
| 381 | 376 | function yy_r1_8() |
| 382 | 377 | { |
| 383 | 378 | |
| 384 | - if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 385 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 379 | + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? |
|
| 380 | + strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false |
|
| 386 | 381 | ) { |
| 387 | 382 | $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
| 388 | 383 | } else { |
@@ -410,8 +405,8 @@ discard block |
||
| 410 | 405 | $to = strlen($this->data); |
| 411 | 406 | preg_match("/($this->ldel)|(<[?]((php\s+|=)|\s+))|(<[%])|(<[?]xml\s+)|(<script\s+language\s*=\s*[\"']?\s*php\s*[\"']?\s*>)|([?][>])|([%][>])/i", |
| 412 | 407 | $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); |
| 413 | - if (isset($match[ 0 ][ 1 ])) { |
|
| 414 | - $to = $match[ 0 ][ 1 ]; |
|
| 408 | + if (isset($match[0][1])) { |
|
| 409 | + $to = $match[0][1]; |
|
| 415 | 410 | } |
| 416 | 411 | $this->value = substr($this->data, $this->counter, $to - $this->counter); |
| 417 | 412 | $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
@@ -435,7 +430,7 @@ discard block |
||
| 435 | 430 | do { |
| 436 | 431 | if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, null, $this->counter)) { |
| 437 | 432 | $yysubmatches = $yymatches; |
| 438 | - if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 433 | + if (strlen($yysubmatches[0]) < 200) { |
|
| 439 | 434 | $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
| 440 | 435 | } else { |
| 441 | 436 | $yymatches = array_filter($yymatches, 'strlen'); |
@@ -467,7 +462,7 @@ discard block |
||
| 467 | 462 | continue; |
| 468 | 463 | } |
| 469 | 464 | } else { |
| 470 | - throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 465 | + throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); |
|
| 471 | 466 | } |
| 472 | 467 | break; |
| 473 | 468 | } |
@@ -535,7 +530,7 @@ discard block |
||
| 535 | 530 | function yy_r2_10() |
| 536 | 531 | { |
| 537 | 532 | |
| 538 | - if ($this->_yy_stack[ count($this->_yy_stack) - 1 ] == self::TEXT) { |
|
| 533 | + if ($this->_yy_stack[count($this->_yy_stack) - 1] == self::TEXT) { |
|
| 539 | 534 | $this->yypopstate(); |
| 540 | 535 | $this->token = Smarty_Internal_Templateparser::TP_SIMPELOUTPUT; |
| 541 | 536 | $this->taglineno = $this->line; |
@@ -576,7 +571,7 @@ discard block |
||
| 576 | 571 | do { |
| 577 | 572 | if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, null, $this->counter)) { |
| 578 | 573 | $yysubmatches = $yymatches; |
| 579 | - if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 574 | + if (strlen($yysubmatches[0]) < 200) { |
|
| 580 | 575 | $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
| 581 | 576 | } else { |
| 582 | 577 | $yymatches = array_filter($yymatches, 'strlen'); |
@@ -608,7 +603,7 @@ discard block |
||
| 608 | 603 | continue; |
| 609 | 604 | } |
| 610 | 605 | } else { |
| 611 | - throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 606 | + throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); |
|
| 612 | 607 | } |
| 613 | 608 | break; |
| 614 | 609 | } |
@@ -627,8 +622,8 @@ discard block |
||
| 627 | 622 | function yy_r3_2() |
| 628 | 623 | { |
| 629 | 624 | |
| 630 | - if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 631 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 625 | + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? |
|
| 626 | + strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false |
|
| 632 | 627 | ) { |
| 633 | 628 | $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
| 634 | 629 | } else { |
@@ -815,7 +810,7 @@ discard block |
||
| 815 | 810 | $this->smarty->right_delimiter |
| 816 | 811 | ) { |
| 817 | 812 | preg_match("/\s+/", $this->value, $match); |
| 818 | - $this->value = $match[ 0 ]; |
|
| 813 | + $this->value = $match[0]; |
|
| 819 | 814 | $this->token = Smarty_Internal_Templateparser::TP_SPACE; |
| 820 | 815 | } else { |
| 821 | 816 | $this->token = Smarty_Internal_Templateparser::TP_ATTR; |
@@ -921,7 +916,7 @@ discard block |
||
| 921 | 916 | do { |
| 922 | 917 | if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, null, $this->counter)) { |
| 923 | 918 | $yysubmatches = $yymatches; |
| 924 | - if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 919 | + if (strlen($yysubmatches[0]) < 200) { |
|
| 925 | 920 | $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
| 926 | 921 | } else { |
| 927 | 922 | $yymatches = array_filter($yymatches, 'strlen'); |
@@ -953,7 +948,7 @@ discard block |
||
| 953 | 948 | continue; |
| 954 | 949 | } |
| 955 | 950 | } else { |
| 956 | - throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 951 | + throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); |
|
| 957 | 952 | } |
| 958 | 953 | break; |
| 959 | 954 | } |
@@ -965,7 +960,7 @@ discard block |
||
| 965 | 960 | function yy_r4_1() |
| 966 | 961 | { |
| 967 | 962 | |
| 968 | - $this->literal_cnt ++; |
|
| 963 | + $this->literal_cnt++; |
|
| 969 | 964 | $this->token = Smarty_Internal_Templateparser::TP_LITERAL; |
| 970 | 965 | } |
| 971 | 966 | |
@@ -973,7 +968,7 @@ discard block |
||
| 973 | 968 | { |
| 974 | 969 | |
| 975 | 970 | if ($this->literal_cnt) { |
| 976 | - $this->literal_cnt --; |
|
| 971 | + $this->literal_cnt--; |
|
| 977 | 972 | $this->token = Smarty_Internal_Templateparser::TP_LITERAL; |
| 978 | 973 | } else { |
| 979 | 974 | $this->token = Smarty_Internal_Templateparser::TP_LITERALEND; |
@@ -987,8 +982,8 @@ discard block |
||
| 987 | 982 | $to = strlen($this->data); |
| 988 | 983 | preg_match("/{$this->ldel}[\/]?literal{$this->rdel}/i", $this->data, $match, PREG_OFFSET_CAPTURE, |
| 989 | 984 | $this->counter); |
| 990 | - if (isset($match[ 0 ][ 1 ])) { |
|
| 991 | - $to = $match[ 0 ][ 1 ]; |
|
| 985 | + if (isset($match[0][1])) { |
|
| 986 | + $to = $match[0][1]; |
|
| 992 | 987 | } else { |
| 993 | 988 | $this->compiler->trigger_template_error("missing or misspelled literal closing tag"); |
| 994 | 989 | } |
@@ -1013,7 +1008,7 @@ discard block |
||
| 1013 | 1008 | do { |
| 1014 | 1009 | if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, null, $this->counter)) { |
| 1015 | 1010 | $yysubmatches = $yymatches; |
| 1016 | - if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 1011 | + if (strlen($yysubmatches[0]) < 200) { |
|
| 1017 | 1012 | $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
| 1018 | 1013 | } else { |
| 1019 | 1014 | $yymatches = array_filter($yymatches, 'strlen'); |
@@ -1045,7 +1040,7 @@ discard block |
||
| 1045 | 1040 | continue; |
| 1046 | 1041 | } |
| 1047 | 1042 | } else { |
| 1048 | - throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 1043 | + throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); |
|
| 1049 | 1044 | } |
| 1050 | 1045 | break; |
| 1051 | 1046 | } |
@@ -1069,8 +1064,8 @@ discard block |
||
| 1069 | 1064 | function yy_r5_3() |
| 1070 | 1065 | { |
| 1071 | 1066 | |
| 1072 | - if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 1073 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 1067 | + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? |
|
| 1068 | + strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false |
|
| 1074 | 1069 | ) { |
| 1075 | 1070 | $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
| 1076 | 1071 | } else { |
@@ -1082,8 +1077,8 @@ discard block |
||
| 1082 | 1077 | function yy_r5_4() |
| 1083 | 1078 | { |
| 1084 | 1079 | |
| 1085 | - if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 1086 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 1080 | + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? |
|
| 1081 | + strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false |
|
| 1087 | 1082 | ) { |
| 1088 | 1083 | $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
| 1089 | 1084 | } else { |
@@ -1095,8 +1090,8 @@ discard block |
||
| 1095 | 1090 | function yy_r5_5() |
| 1096 | 1091 | { |
| 1097 | 1092 | |
| 1098 | - if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 1099 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 1093 | + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? |
|
| 1094 | + strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false |
|
| 1100 | 1095 | ) { |
| 1101 | 1096 | $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
| 1102 | 1097 | } else { |
@@ -18,1136 +18,1136 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Smarty_Internal_Templatelexer |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Source |
|
| 23 | - * |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - public $data; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * byte counter |
|
| 30 | - * |
|
| 31 | - * @var int |
|
| 32 | - */ |
|
| 33 | - public $counter; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * token number |
|
| 37 | - * |
|
| 38 | - * @var int |
|
| 39 | - */ |
|
| 40 | - public $token; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * token value |
|
| 44 | - * |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - public $value; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * current line |
|
| 51 | - * |
|
| 52 | - * @var int |
|
| 53 | - */ |
|
| 54 | - public $line; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * tag start line |
|
| 58 | - * |
|
| 59 | - * @var |
|
| 60 | - */ |
|
| 61 | - public $taglineno; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * php code type |
|
| 65 | - * |
|
| 66 | - * @var string |
|
| 67 | - */ |
|
| 68 | - public $phpType = ''; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * escaped left delimiter |
|
| 72 | - * |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - public $ldel = ''; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * escaped left delimiter length |
|
| 79 | - * |
|
| 80 | - * @var int |
|
| 81 | - */ |
|
| 82 | - public $ldel_length = 0; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * escaped right delimiter |
|
| 86 | - * |
|
| 87 | - * @var string |
|
| 88 | - */ |
|
| 89 | - public $rdel = ''; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * escaped right delimiter length |
|
| 93 | - * |
|
| 94 | - * @var int |
|
| 95 | - */ |
|
| 96 | - public $rdel_length = 0; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * state number |
|
| 100 | - * |
|
| 101 | - * @var int |
|
| 102 | - */ |
|
| 103 | - public $state = 1; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Smarty object |
|
| 107 | - * |
|
| 108 | - * @var Smarty |
|
| 109 | - */ |
|
| 110 | - public $smarty = null; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * compiler object |
|
| 114 | - * |
|
| 115 | - * @var Smarty_Internal_TemplateCompilerBase |
|
| 116 | - */ |
|
| 117 | - public $compiler = null; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * literal tag nesting level |
|
| 121 | - * |
|
| 122 | - * @var int |
|
| 123 | - */ |
|
| 124 | - private $literal_cnt = 0; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * PHP start tag string |
|
| 128 | - * |
|
| 129 | - * @var string |
|
| 130 | - */ |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * trace file |
|
| 134 | - * |
|
| 135 | - * @var resource |
|
| 136 | - */ |
|
| 137 | - public $yyTraceFILE; |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * trace prompt |
|
| 141 | - * |
|
| 142 | - * @var string |
|
| 143 | - */ |
|
| 144 | - public $yyTracePrompt; |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * XML flag true while processing xml |
|
| 148 | - * |
|
| 149 | - * @var bool |
|
| 150 | - */ |
|
| 151 | - public $is_xml = false; |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * state names |
|
| 155 | - * |
|
| 156 | - * @var array |
|
| 157 | - */ |
|
| 158 | - public $state_name = array(1 => 'TEXT', 2 => 'TAG', 3 => 'TAGBODY', 4 => 'LITERAL', 5 => 'DOUBLEQUOTEDSTRING',); |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * storage for assembled token patterns |
|
| 162 | - * |
|
| 163 | - * @var string |
|
| 164 | - */ |
|
| 165 | - private $yy_global_pattern1 = null; |
|
| 166 | - |
|
| 167 | - private $yy_global_pattern2 = null; |
|
| 168 | - |
|
| 169 | - private $yy_global_pattern3 = null; |
|
| 170 | - |
|
| 171 | - private $yy_global_pattern4 = null; |
|
| 172 | - |
|
| 173 | - private $yy_global_pattern5 = null; |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * token names |
|
| 177 | - * |
|
| 178 | - * @var array |
|
| 179 | - */ |
|
| 180 | - public $smarty_token_names = array( // Text for parser error messages |
|
| 181 | - 'NOT' => '(!,not)', 'OPENP' => '(', 'CLOSEP' => ')', 'OPENB' => '[', |
|
| 182 | - 'CLOSEB' => ']', 'PTR' => '->', 'APTR' => '=>', 'EQUAL' => '=', |
|
| 183 | - 'NUMBER' => 'number', 'UNIMATH' => '+" , "-', 'MATH' => '*" , "/" , "%', |
|
| 184 | - 'INCDEC' => '++" , "--', 'SPACE' => ' ', 'DOLLAR' => '$', |
|
| 185 | - 'SEMICOLON' => ';', 'COLON' => ':', 'DOUBLECOLON' => '::', 'AT' => '@', |
|
| 186 | - 'HATCH' => '#', 'QUOTE' => '"', 'BACKTICK' => '`', |
|
| 187 | - 'VERT' => '"|" modifier', 'DOT' => '.', 'COMMA' => '","', |
|
| 188 | - 'QMARK' => '"?"', 'ID' => 'id, name', 'TEXT' => 'text', |
|
| 189 | - 'LDELSLASH' => '{/..} closing tag', 'LDEL' => '{...} Smarty tag', |
|
| 190 | - 'COMMENT' => 'comment', 'AS' => 'as', 'TO' => 'to', |
|
| 191 | - 'PHP' => '"<?php", "<%", "{php}" tag', |
|
| 192 | - 'LOGOP' => '"<", "==" ... logical operator', |
|
| 193 | - 'TLOGOP' => '"lt", "eq" ... logical operator; "is div by" ... if condition', |
|
| 194 | - 'SCOND' => '"is even" ... if condition',); |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * constructor |
|
| 198 | - * |
|
| 199 | - * @param string $data template source |
|
| 200 | - * @param Smarty_Internal_TemplateCompilerBase $compiler |
|
| 201 | - */ |
|
| 202 | - public function __construct($data, Smarty_Internal_TemplateCompilerBase $compiler) |
|
| 203 | - { |
|
| 204 | - $this->data = $data; |
|
| 205 | - $this->counter = 0; |
|
| 206 | - if (preg_match('/^\xEF\xBB\xBF/i', $this->data, $match)) { |
|
| 207 | - $this->counter += strlen($match[ 0 ]); |
|
| 208 | - } |
|
| 209 | - $this->line = 1; |
|
| 210 | - $this->smarty = $compiler->smarty; |
|
| 211 | - $this->compiler = $compiler; |
|
| 212 | - $this->ldel = preg_quote($this->smarty->left_delimiter, '/'); |
|
| 213 | - $this->ldel_length = strlen($this->smarty->left_delimiter); |
|
| 214 | - $this->rdel = preg_quote($this->smarty->right_delimiter, '/'); |
|
| 215 | - $this->rdel_length = strlen($this->smarty->right_delimiter); |
|
| 216 | - $this->smarty_token_names[ 'LDEL' ] = $this->smarty->left_delimiter; |
|
| 217 | - $this->smarty_token_names[ 'RDEL' ] = $this->smarty->right_delimiter; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - public function PrintTrace() |
|
| 221 | - { |
|
| 222 | - $this->yyTraceFILE = fopen('php://output', 'w'); |
|
| 223 | - $this->yyTracePrompt = '<br>'; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /* |
|
| 21 | + /** |
|
| 22 | + * Source |
|
| 23 | + * |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + public $data; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * byte counter |
|
| 30 | + * |
|
| 31 | + * @var int |
|
| 32 | + */ |
|
| 33 | + public $counter; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * token number |
|
| 37 | + * |
|
| 38 | + * @var int |
|
| 39 | + */ |
|
| 40 | + public $token; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * token value |
|
| 44 | + * |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + public $value; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * current line |
|
| 51 | + * |
|
| 52 | + * @var int |
|
| 53 | + */ |
|
| 54 | + public $line; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * tag start line |
|
| 58 | + * |
|
| 59 | + * @var |
|
| 60 | + */ |
|
| 61 | + public $taglineno; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * php code type |
|
| 65 | + * |
|
| 66 | + * @var string |
|
| 67 | + */ |
|
| 68 | + public $phpType = ''; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * escaped left delimiter |
|
| 72 | + * |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + public $ldel = ''; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * escaped left delimiter length |
|
| 79 | + * |
|
| 80 | + * @var int |
|
| 81 | + */ |
|
| 82 | + public $ldel_length = 0; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * escaped right delimiter |
|
| 86 | + * |
|
| 87 | + * @var string |
|
| 88 | + */ |
|
| 89 | + public $rdel = ''; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * escaped right delimiter length |
|
| 93 | + * |
|
| 94 | + * @var int |
|
| 95 | + */ |
|
| 96 | + public $rdel_length = 0; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * state number |
|
| 100 | + * |
|
| 101 | + * @var int |
|
| 102 | + */ |
|
| 103 | + public $state = 1; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Smarty object |
|
| 107 | + * |
|
| 108 | + * @var Smarty |
|
| 109 | + */ |
|
| 110 | + public $smarty = null; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * compiler object |
|
| 114 | + * |
|
| 115 | + * @var Smarty_Internal_TemplateCompilerBase |
|
| 116 | + */ |
|
| 117 | + public $compiler = null; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * literal tag nesting level |
|
| 121 | + * |
|
| 122 | + * @var int |
|
| 123 | + */ |
|
| 124 | + private $literal_cnt = 0; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * PHP start tag string |
|
| 128 | + * |
|
| 129 | + * @var string |
|
| 130 | + */ |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * trace file |
|
| 134 | + * |
|
| 135 | + * @var resource |
|
| 136 | + */ |
|
| 137 | + public $yyTraceFILE; |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * trace prompt |
|
| 141 | + * |
|
| 142 | + * @var string |
|
| 143 | + */ |
|
| 144 | + public $yyTracePrompt; |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * XML flag true while processing xml |
|
| 148 | + * |
|
| 149 | + * @var bool |
|
| 150 | + */ |
|
| 151 | + public $is_xml = false; |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * state names |
|
| 155 | + * |
|
| 156 | + * @var array |
|
| 157 | + */ |
|
| 158 | + public $state_name = array(1 => 'TEXT', 2 => 'TAG', 3 => 'TAGBODY', 4 => 'LITERAL', 5 => 'DOUBLEQUOTEDSTRING',); |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * storage for assembled token patterns |
|
| 162 | + * |
|
| 163 | + * @var string |
|
| 164 | + */ |
|
| 165 | + private $yy_global_pattern1 = null; |
|
| 166 | + |
|
| 167 | + private $yy_global_pattern2 = null; |
|
| 168 | + |
|
| 169 | + private $yy_global_pattern3 = null; |
|
| 170 | + |
|
| 171 | + private $yy_global_pattern4 = null; |
|
| 172 | + |
|
| 173 | + private $yy_global_pattern5 = null; |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * token names |
|
| 177 | + * |
|
| 178 | + * @var array |
|
| 179 | + */ |
|
| 180 | + public $smarty_token_names = array( // Text for parser error messages |
|
| 181 | + 'NOT' => '(!,not)', 'OPENP' => '(', 'CLOSEP' => ')', 'OPENB' => '[', |
|
| 182 | + 'CLOSEB' => ']', 'PTR' => '->', 'APTR' => '=>', 'EQUAL' => '=', |
|
| 183 | + 'NUMBER' => 'number', 'UNIMATH' => '+" , "-', 'MATH' => '*" , "/" , "%', |
|
| 184 | + 'INCDEC' => '++" , "--', 'SPACE' => ' ', 'DOLLAR' => '$', |
|
| 185 | + 'SEMICOLON' => ';', 'COLON' => ':', 'DOUBLECOLON' => '::', 'AT' => '@', |
|
| 186 | + 'HATCH' => '#', 'QUOTE' => '"', 'BACKTICK' => '`', |
|
| 187 | + 'VERT' => '"|" modifier', 'DOT' => '.', 'COMMA' => '","', |
|
| 188 | + 'QMARK' => '"?"', 'ID' => 'id, name', 'TEXT' => 'text', |
|
| 189 | + 'LDELSLASH' => '{/..} closing tag', 'LDEL' => '{...} Smarty tag', |
|
| 190 | + 'COMMENT' => 'comment', 'AS' => 'as', 'TO' => 'to', |
|
| 191 | + 'PHP' => '"<?php", "<%", "{php}" tag', |
|
| 192 | + 'LOGOP' => '"<", "==" ... logical operator', |
|
| 193 | + 'TLOGOP' => '"lt", "eq" ... logical operator; "is div by" ... if condition', |
|
| 194 | + 'SCOND' => '"is even" ... if condition',); |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * constructor |
|
| 198 | + * |
|
| 199 | + * @param string $data template source |
|
| 200 | + * @param Smarty_Internal_TemplateCompilerBase $compiler |
|
| 201 | + */ |
|
| 202 | + public function __construct($data, Smarty_Internal_TemplateCompilerBase $compiler) |
|
| 203 | + { |
|
| 204 | + $this->data = $data; |
|
| 205 | + $this->counter = 0; |
|
| 206 | + if (preg_match('/^\xEF\xBB\xBF/i', $this->data, $match)) { |
|
| 207 | + $this->counter += strlen($match[ 0 ]); |
|
| 208 | + } |
|
| 209 | + $this->line = 1; |
|
| 210 | + $this->smarty = $compiler->smarty; |
|
| 211 | + $this->compiler = $compiler; |
|
| 212 | + $this->ldel = preg_quote($this->smarty->left_delimiter, '/'); |
|
| 213 | + $this->ldel_length = strlen($this->smarty->left_delimiter); |
|
| 214 | + $this->rdel = preg_quote($this->smarty->right_delimiter, '/'); |
|
| 215 | + $this->rdel_length = strlen($this->smarty->right_delimiter); |
|
| 216 | + $this->smarty_token_names[ 'LDEL' ] = $this->smarty->left_delimiter; |
|
| 217 | + $this->smarty_token_names[ 'RDEL' ] = $this->smarty->right_delimiter; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + public function PrintTrace() |
|
| 221 | + { |
|
| 222 | + $this->yyTraceFILE = fopen('php://output', 'w'); |
|
| 223 | + $this->yyTracePrompt = '<br>'; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /* |
|
| 227 | 227 | * Check if this tag is autoliteral |
| 228 | 228 | */ |
| 229 | - public function isAutoLiteral() |
|
| 230 | - { |
|
| 231 | - return $this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 232 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - private $_yy_state = 1; |
|
| 236 | - |
|
| 237 | - private $_yy_stack = array(); |
|
| 238 | - |
|
| 239 | - public function yylex() |
|
| 240 | - { |
|
| 241 | - return $this->{'yylex' . $this->_yy_state}(); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - public function yypushstate($state) |
|
| 245 | - { |
|
| 246 | - if ($this->yyTraceFILE) { |
|
| 247 | - fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, |
|
| 248 | - isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 249 | - $this->_yy_state); |
|
| 250 | - } |
|
| 251 | - array_push($this->_yy_stack, $this->_yy_state); |
|
| 252 | - $this->_yy_state = $state; |
|
| 253 | - if ($this->yyTraceFILE) { |
|
| 254 | - fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, |
|
| 255 | - isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 256 | - $this->_yy_state); |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - public function yypopstate() |
|
| 261 | - { |
|
| 262 | - if ($this->yyTraceFILE) { |
|
| 263 | - fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, |
|
| 264 | - isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 265 | - $this->_yy_state); |
|
| 266 | - } |
|
| 267 | - $this->_yy_state = array_pop($this->_yy_stack); |
|
| 268 | - if ($this->yyTraceFILE) { |
|
| 269 | - fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, |
|
| 270 | - isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 271 | - $this->_yy_state); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - public function yybegin($state) |
|
| 276 | - { |
|
| 277 | - $this->_yy_state = $state; |
|
| 278 | - if ($this->yyTraceFILE) { |
|
| 279 | - fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, |
|
| 280 | - isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 281 | - $this->_yy_state); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - public function yylex1() |
|
| 286 | - { |
|
| 287 | - if (!isset($this->yy_global_pattern1)) { |
|
| 288 | - $this->yy_global_pattern1 = |
|
| 289 | - "/\G([{][}])|\G(" . $this->ldel . "[*])|\G((" . $this->ldel . "\\s*php([ ].*?)?" . $this->rdel . ")|(" . |
|
| 290 | - $this->ldel . "\\s*[\/]php" . $this->rdel . "))|\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . |
|
| 291 | - ")|\G(" . $this->ldel . "\\s*)|\G(\\s*" . $this->rdel . |
|
| 292 | - ")|\G((<[?]((php\\s+|=)|\\s+))|(<[%])|(<[?]xml\\s+)|(<script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*>)|([?][>])|([%][>]))|\G([\S\s])/isS"; |
|
| 293 | - } |
|
| 294 | - if ($this->counter >= strlen($this->data)) { |
|
| 295 | - return false; // end of input |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - do { |
|
| 299 | - if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, null, $this->counter)) { |
|
| 300 | - $yysubmatches = $yymatches; |
|
| 301 | - if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 302 | - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
|
| 303 | - } else { |
|
| 304 | - $yymatches = array_filter($yymatches, 'strlen'); |
|
| 305 | - } |
|
| 306 | - if (empty($yymatches)) { |
|
| 307 | - throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . |
|
| 308 | - substr($this->data, $this->counter, 5) . '... state TEXT'); |
|
| 309 | - } |
|
| 310 | - next($yymatches); // skip global match |
|
| 311 | - $this->token = key($yymatches); // token number |
|
| 312 | - $this->value = current($yymatches); // token value |
|
| 313 | - $r = $this->{'yy_r1_' . $this->token}(); |
|
| 314 | - if ($r === null) { |
|
| 315 | - $this->counter += strlen($this->value); |
|
| 316 | - $this->line += substr_count($this->value, "\n"); |
|
| 317 | - // accept this token |
|
| 318 | - return true; |
|
| 319 | - } elseif ($r === true) { |
|
| 320 | - // we have changed state |
|
| 321 | - // process this token in the new state |
|
| 322 | - return $this->yylex(); |
|
| 323 | - } elseif ($r === false) { |
|
| 324 | - $this->counter += strlen($this->value); |
|
| 325 | - $this->line += substr_count($this->value, "\n"); |
|
| 326 | - if ($this->counter >= strlen($this->data)) { |
|
| 327 | - return false; // end of input |
|
| 328 | - } |
|
| 329 | - // skip this token |
|
| 330 | - continue; |
|
| 331 | - } |
|
| 332 | - } else { |
|
| 333 | - throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 334 | - } |
|
| 335 | - break; |
|
| 336 | - } |
|
| 337 | - while (true); |
|
| 338 | - } // end function |
|
| 339 | - |
|
| 340 | - const TEXT = 1; |
|
| 341 | - |
|
| 342 | - public function yy_r1_1() |
|
| 343 | - { |
|
| 344 | - |
|
| 345 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - public function yy_r1_2() |
|
| 349 | - { |
|
| 350 | - |
|
| 351 | - preg_match("/[*]{$this->rdel}/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); |
|
| 352 | - if (isset($match[ 0 ][ 1 ])) { |
|
| 353 | - $to = $match[ 0 ][ 1 ] + strlen($match[ 0 ][ 0 ]); |
|
| 354 | - } else { |
|
| 355 | - $this->compiler->trigger_template_error("missing or misspelled comment closing tag '*{$this->smarty->right_delimiter}'"); |
|
| 356 | - } |
|
| 357 | - $this->value = substr($this->data, $this->counter, $to - $this->counter); |
|
| 358 | - return false; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - public function yy_r1_3() |
|
| 362 | - { |
|
| 363 | - |
|
| 364 | - $obj = new Smarty_Internal_Compile_Private_Php(); |
|
| 365 | - $obj->parsePhp($this); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - public function yy_r1_7() |
|
| 369 | - { |
|
| 370 | - |
|
| 371 | - if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 372 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 373 | - ) { |
|
| 374 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 375 | - } else { |
|
| 376 | - $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; |
|
| 377 | - $this->yypushstate(self::LITERAL); |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - public function yy_r1_8() |
|
| 382 | - { |
|
| 383 | - |
|
| 384 | - if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 385 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 386 | - ) { |
|
| 387 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 388 | - } else { |
|
| 389 | - $this->yypushstate(self::TAG); |
|
| 390 | - return true; |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - public function yy_r1_9() |
|
| 395 | - { |
|
| 396 | - |
|
| 397 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - public function yy_r1_10() |
|
| 401 | - { |
|
| 402 | - |
|
| 403 | - $obj = new Smarty_Internal_Compile_Private_Php(); |
|
| 404 | - $obj->parsePhp($this); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - public function yy_r1_19() |
|
| 408 | - { |
|
| 409 | - |
|
| 410 | - $to = strlen($this->data); |
|
| 411 | - preg_match("/($this->ldel)|(<[?]((php\s+|=)|\s+))|(<[%])|(<[?]xml\s+)|(<script\s+language\s*=\s*[\"']?\s*php\s*[\"']?\s*>)|([?][>])|([%][>])/i", |
|
| 412 | - $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); |
|
| 413 | - if (isset($match[ 0 ][ 1 ])) { |
|
| 414 | - $to = $match[ 0 ][ 1 ]; |
|
| 415 | - } |
|
| 416 | - $this->value = substr($this->data, $this->counter, $to - $this->counter); |
|
| 417 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - public function yylex2() |
|
| 421 | - { |
|
| 422 | - if (!isset($this->yy_global_pattern2)) { |
|
| 423 | - $this->yy_global_pattern2 = |
|
| 424 | - "/\G(" . $this->ldel . "\\s*(if|elseif|else if|while)\\s+)|\G(" . $this->ldel . "\\s*for\\s+)|\G(" . |
|
| 425 | - $this->ldel . "\\s*foreach(?![^\s]))|\G(" . $this->ldel . "\\s*setfilter\\s+)|\G(" . $this->ldel . |
|
| 426 | - "\\s*make_nocache\\s+)|\G(" . $this->ldel . "\\s*[0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*" . $this->rdel . |
|
| 427 | - ")|\G(" . $this->ldel . "\\s*[\/](?:(?!block)[0-9]*[a-zA-Z_]\\w*)\\s*" . $this->rdel . ")|\G(" . |
|
| 428 | - $this->ldel . "\\s*[$][0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*" . $this->rdel . ")|\G(" . $this->ldel . |
|
| 429 | - "\\s*[\/])|\G(" . $this->ldel . "\\s*)/isS"; |
|
| 430 | - } |
|
| 431 | - if ($this->counter >= strlen($this->data)) { |
|
| 432 | - return false; // end of input |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - do { |
|
| 436 | - if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, null, $this->counter)) { |
|
| 437 | - $yysubmatches = $yymatches; |
|
| 438 | - if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 439 | - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
|
| 440 | - } else { |
|
| 441 | - $yymatches = array_filter($yymatches, 'strlen'); |
|
| 442 | - } |
|
| 443 | - if (empty($yymatches)) { |
|
| 444 | - throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . |
|
| 445 | - substr($this->data, $this->counter, 5) . '... state TAG'); |
|
| 446 | - } |
|
| 447 | - next($yymatches); // skip global match |
|
| 448 | - $this->token = key($yymatches); // token number |
|
| 449 | - $this->value = current($yymatches); // token value |
|
| 450 | - $r = $this->{'yy_r2_' . $this->token}(); |
|
| 451 | - if ($r === null) { |
|
| 452 | - $this->counter += strlen($this->value); |
|
| 453 | - $this->line += substr_count($this->value, "\n"); |
|
| 454 | - // accept this token |
|
| 455 | - return true; |
|
| 456 | - } elseif ($r === true) { |
|
| 457 | - // we have changed state |
|
| 458 | - // process this token in the new state |
|
| 459 | - return $this->yylex(); |
|
| 460 | - } elseif ($r === false) { |
|
| 461 | - $this->counter += strlen($this->value); |
|
| 462 | - $this->line += substr_count($this->value, "\n"); |
|
| 463 | - if ($this->counter >= strlen($this->data)) { |
|
| 464 | - return false; // end of input |
|
| 465 | - } |
|
| 466 | - // skip this token |
|
| 467 | - continue; |
|
| 468 | - } |
|
| 469 | - } else { |
|
| 470 | - throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 471 | - } |
|
| 472 | - break; |
|
| 473 | - } |
|
| 474 | - while (true); |
|
| 475 | - } // end function |
|
| 476 | - |
|
| 477 | - const TAG = 2; |
|
| 478 | - |
|
| 479 | - public function yy_r2_1() |
|
| 480 | - { |
|
| 481 | - |
|
| 482 | - $this->token = Smarty_Internal_Templateparser::TP_LDELIF; |
|
| 483 | - $this->yybegin(self::TAGBODY); |
|
| 484 | - $this->taglineno = $this->line; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - public function yy_r2_3() |
|
| 488 | - { |
|
| 489 | - |
|
| 490 | - $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; |
|
| 491 | - $this->yybegin(self::TAGBODY); |
|
| 492 | - $this->taglineno = $this->line; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - public function yy_r2_4() |
|
| 496 | - { |
|
| 497 | - |
|
| 498 | - $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; |
|
| 499 | - $this->yybegin(self::TAGBODY); |
|
| 500 | - $this->taglineno = $this->line; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - public function yy_r2_5() |
|
| 504 | - { |
|
| 505 | - |
|
| 506 | - $this->token = Smarty_Internal_Templateparser::TP_LDELSETFILTER; |
|
| 507 | - $this->yybegin(self::TAGBODY); |
|
| 508 | - $this->taglineno = $this->line; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - public function yy_r2_6() |
|
| 512 | - { |
|
| 513 | - |
|
| 514 | - $this->token = Smarty_Internal_Templateparser::TP_LDELMAKENOCACHE; |
|
| 515 | - $this->yybegin(self::TAGBODY); |
|
| 516 | - $this->taglineno = $this->line; |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - public function yy_r2_7() |
|
| 520 | - { |
|
| 521 | - |
|
| 522 | - $this->yypopstate(); |
|
| 523 | - $this->token = Smarty_Internal_Templateparser::TP_SIMPLETAG; |
|
| 524 | - $this->taglineno = $this->line; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - public function yy_r2_9() |
|
| 528 | - { |
|
| 529 | - |
|
| 530 | - $this->yypopstate(); |
|
| 531 | - $this->token = Smarty_Internal_Templateparser::TP_CLOSETAG; |
|
| 532 | - $this->taglineno = $this->line; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - public function yy_r2_10() |
|
| 536 | - { |
|
| 537 | - |
|
| 538 | - if ($this->_yy_stack[ count($this->_yy_stack) - 1 ] == self::TEXT) { |
|
| 539 | - $this->yypopstate(); |
|
| 540 | - $this->token = Smarty_Internal_Templateparser::TP_SIMPELOUTPUT; |
|
| 541 | - $this->taglineno = $this->line; |
|
| 542 | - } else { |
|
| 543 | - $this->value = $this->smarty->left_delimiter; |
|
| 544 | - $this->token = Smarty_Internal_Templateparser::TP_LDEL; |
|
| 545 | - $this->yybegin(self::TAGBODY); |
|
| 546 | - $this->taglineno = $this->line; |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - public function yy_r2_12() |
|
| 551 | - { |
|
| 552 | - |
|
| 553 | - $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; |
|
| 554 | - $this->yybegin(self::TAGBODY); |
|
| 555 | - $this->taglineno = $this->line; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - public function yy_r2_13() |
|
| 559 | - { |
|
| 560 | - |
|
| 561 | - $this->token = Smarty_Internal_Templateparser::TP_LDEL; |
|
| 562 | - $this->yybegin(self::TAGBODY); |
|
| 563 | - $this->taglineno = $this->line; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - public function yylex3() |
|
| 567 | - { |
|
| 568 | - if (!isset($this->yy_global_pattern3)) { |
|
| 569 | - $this->yy_global_pattern3 = "/\G(\\s*" . $this->rdel . ")|\G(" . $this->ldel . |
|
| 570 | - "\\s*)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$]smarty\\.block\\.(child|parent))|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*(([!=][=]{1,2})|([<][=>]?)|([>][=]?)|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\\s+)|\G(\\s+(is\\s+(not\\s+)?(odd|even|div)\\s+by)\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G(([!]\\s*)|(not\\s+))|\G([(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\\s*)|\G(\\s*[(]\\s*)|\G(\\s*[)])|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*[-][>]\\s*)|\G(\\s*[=][>]\\s*)|\G(\\s*[=]\\s*)|\G(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|])|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS"; |
|
| 571 | - } |
|
| 572 | - if ($this->counter >= strlen($this->data)) { |
|
| 573 | - return false; // end of input |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - do { |
|
| 577 | - if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, null, $this->counter)) { |
|
| 578 | - $yysubmatches = $yymatches; |
|
| 579 | - if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 580 | - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
|
| 581 | - } else { |
|
| 582 | - $yymatches = array_filter($yymatches, 'strlen'); |
|
| 583 | - } |
|
| 584 | - if (empty($yymatches)) { |
|
| 585 | - throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . |
|
| 586 | - substr($this->data, $this->counter, 5) . '... state TAGBODY'); |
|
| 587 | - } |
|
| 588 | - next($yymatches); // skip global match |
|
| 589 | - $this->token = key($yymatches); // token number |
|
| 590 | - $this->value = current($yymatches); // token value |
|
| 591 | - $r = $this->{'yy_r3_' . $this->token}(); |
|
| 592 | - if ($r === null) { |
|
| 593 | - $this->counter += strlen($this->value); |
|
| 594 | - $this->line += substr_count($this->value, "\n"); |
|
| 595 | - // accept this token |
|
| 596 | - return true; |
|
| 597 | - } elseif ($r === true) { |
|
| 598 | - // we have changed state |
|
| 599 | - // process this token in the new state |
|
| 600 | - return $this->yylex(); |
|
| 601 | - } elseif ($r === false) { |
|
| 602 | - $this->counter += strlen($this->value); |
|
| 603 | - $this->line += substr_count($this->value, "\n"); |
|
| 604 | - if ($this->counter >= strlen($this->data)) { |
|
| 605 | - return false; // end of input |
|
| 606 | - } |
|
| 607 | - // skip this token |
|
| 608 | - continue; |
|
| 609 | - } |
|
| 610 | - } else { |
|
| 611 | - throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 612 | - } |
|
| 613 | - break; |
|
| 614 | - } |
|
| 615 | - while (true); |
|
| 616 | - } // end function |
|
| 617 | - |
|
| 618 | - const TAGBODY = 3; |
|
| 619 | - |
|
| 620 | - public function yy_r3_1() |
|
| 621 | - { |
|
| 622 | - |
|
| 623 | - $this->token = Smarty_Internal_Templateparser::TP_RDEL; |
|
| 624 | - $this->yypopstate(); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - public function yy_r3_2() |
|
| 628 | - { |
|
| 629 | - |
|
| 630 | - if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 631 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 632 | - ) { |
|
| 633 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 634 | - } else { |
|
| 635 | - $this->yypushstate(self::TAG); |
|
| 636 | - return true; |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - public function yy_r3_3() |
|
| 641 | - { |
|
| 642 | - |
|
| 643 | - $this->token = Smarty_Internal_Templateparser::TP_QUOTE; |
|
| 644 | - $this->yypushstate(self::DOUBLEQUOTEDSTRING); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - public function yy_r3_4() |
|
| 648 | - { |
|
| 649 | - |
|
| 650 | - $this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - public function yy_r3_5() |
|
| 654 | - { |
|
| 655 | - |
|
| 656 | - $this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT; |
|
| 657 | - $this->taglineno = $this->line; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - public function yy_r3_7() |
|
| 661 | - { |
|
| 662 | - |
|
| 663 | - $this->token = Smarty_Internal_Templateparser::TP_DOLLARID; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - public function yy_r3_8() |
|
| 667 | - { |
|
| 668 | - |
|
| 669 | - $this->token = Smarty_Internal_Templateparser::TP_DOLLAR; |
|
| 670 | - } |
|
| 229 | + public function isAutoLiteral() |
|
| 230 | + { |
|
| 231 | + return $this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 232 | + strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + private $_yy_state = 1; |
|
| 236 | + |
|
| 237 | + private $_yy_stack = array(); |
|
| 238 | + |
|
| 239 | + public function yylex() |
|
| 240 | + { |
|
| 241 | + return $this->{'yylex' . $this->_yy_state}(); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + public function yypushstate($state) |
|
| 245 | + { |
|
| 246 | + if ($this->yyTraceFILE) { |
|
| 247 | + fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, |
|
| 248 | + isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 249 | + $this->_yy_state); |
|
| 250 | + } |
|
| 251 | + array_push($this->_yy_stack, $this->_yy_state); |
|
| 252 | + $this->_yy_state = $state; |
|
| 253 | + if ($this->yyTraceFILE) { |
|
| 254 | + fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, |
|
| 255 | + isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 256 | + $this->_yy_state); |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + public function yypopstate() |
|
| 261 | + { |
|
| 262 | + if ($this->yyTraceFILE) { |
|
| 263 | + fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, |
|
| 264 | + isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 265 | + $this->_yy_state); |
|
| 266 | + } |
|
| 267 | + $this->_yy_state = array_pop($this->_yy_stack); |
|
| 268 | + if ($this->yyTraceFILE) { |
|
| 269 | + fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, |
|
| 270 | + isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 271 | + $this->_yy_state); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + public function yybegin($state) |
|
| 276 | + { |
|
| 277 | + $this->_yy_state = $state; |
|
| 278 | + if ($this->yyTraceFILE) { |
|
| 279 | + fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, |
|
| 280 | + isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : |
|
| 281 | + $this->_yy_state); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + public function yylex1() |
|
| 286 | + { |
|
| 287 | + if (!isset($this->yy_global_pattern1)) { |
|
| 288 | + $this->yy_global_pattern1 = |
|
| 289 | + "/\G([{][}])|\G(" . $this->ldel . "[*])|\G((" . $this->ldel . "\\s*php([ ].*?)?" . $this->rdel . ")|(" . |
|
| 290 | + $this->ldel . "\\s*[\/]php" . $this->rdel . "))|\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . |
|
| 291 | + ")|\G(" . $this->ldel . "\\s*)|\G(\\s*" . $this->rdel . |
|
| 292 | + ")|\G((<[?]((php\\s+|=)|\\s+))|(<[%])|(<[?]xml\\s+)|(<script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*>)|([?][>])|([%][>]))|\G([\S\s])/isS"; |
|
| 293 | + } |
|
| 294 | + if ($this->counter >= strlen($this->data)) { |
|
| 295 | + return false; // end of input |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + do { |
|
| 299 | + if (preg_match($this->yy_global_pattern1, $this->data, $yymatches, null, $this->counter)) { |
|
| 300 | + $yysubmatches = $yymatches; |
|
| 301 | + if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 302 | + $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
|
| 303 | + } else { |
|
| 304 | + $yymatches = array_filter($yymatches, 'strlen'); |
|
| 305 | + } |
|
| 306 | + if (empty($yymatches)) { |
|
| 307 | + throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . |
|
| 308 | + substr($this->data, $this->counter, 5) . '... state TEXT'); |
|
| 309 | + } |
|
| 310 | + next($yymatches); // skip global match |
|
| 311 | + $this->token = key($yymatches); // token number |
|
| 312 | + $this->value = current($yymatches); // token value |
|
| 313 | + $r = $this->{'yy_r1_' . $this->token}(); |
|
| 314 | + if ($r === null) { |
|
| 315 | + $this->counter += strlen($this->value); |
|
| 316 | + $this->line += substr_count($this->value, "\n"); |
|
| 317 | + // accept this token |
|
| 318 | + return true; |
|
| 319 | + } elseif ($r === true) { |
|
| 320 | + // we have changed state |
|
| 321 | + // process this token in the new state |
|
| 322 | + return $this->yylex(); |
|
| 323 | + } elseif ($r === false) { |
|
| 324 | + $this->counter += strlen($this->value); |
|
| 325 | + $this->line += substr_count($this->value, "\n"); |
|
| 326 | + if ($this->counter >= strlen($this->data)) { |
|
| 327 | + return false; // end of input |
|
| 328 | + } |
|
| 329 | + // skip this token |
|
| 330 | + continue; |
|
| 331 | + } |
|
| 332 | + } else { |
|
| 333 | + throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 334 | + } |
|
| 335 | + break; |
|
| 336 | + } |
|
| 337 | + while (true); |
|
| 338 | + } // end function |
|
| 339 | + |
|
| 340 | + const TEXT = 1; |
|
| 341 | + |
|
| 342 | + public function yy_r1_1() |
|
| 343 | + { |
|
| 344 | + |
|
| 345 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + public function yy_r1_2() |
|
| 349 | + { |
|
| 350 | + |
|
| 351 | + preg_match("/[*]{$this->rdel}/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); |
|
| 352 | + if (isset($match[ 0 ][ 1 ])) { |
|
| 353 | + $to = $match[ 0 ][ 1 ] + strlen($match[ 0 ][ 0 ]); |
|
| 354 | + } else { |
|
| 355 | + $this->compiler->trigger_template_error("missing or misspelled comment closing tag '*{$this->smarty->right_delimiter}'"); |
|
| 356 | + } |
|
| 357 | + $this->value = substr($this->data, $this->counter, $to - $this->counter); |
|
| 358 | + return false; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + public function yy_r1_3() |
|
| 362 | + { |
|
| 363 | + |
|
| 364 | + $obj = new Smarty_Internal_Compile_Private_Php(); |
|
| 365 | + $obj->parsePhp($this); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + public function yy_r1_7() |
|
| 369 | + { |
|
| 370 | + |
|
| 371 | + if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 372 | + strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 373 | + ) { |
|
| 374 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 375 | + } else { |
|
| 376 | + $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; |
|
| 377 | + $this->yypushstate(self::LITERAL); |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + public function yy_r1_8() |
|
| 382 | + { |
|
| 383 | + |
|
| 384 | + if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 385 | + strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 386 | + ) { |
|
| 387 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 388 | + } else { |
|
| 389 | + $this->yypushstate(self::TAG); |
|
| 390 | + return true; |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + public function yy_r1_9() |
|
| 395 | + { |
|
| 396 | + |
|
| 397 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + public function yy_r1_10() |
|
| 401 | + { |
|
| 402 | + |
|
| 403 | + $obj = new Smarty_Internal_Compile_Private_Php(); |
|
| 404 | + $obj->parsePhp($this); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + public function yy_r1_19() |
|
| 408 | + { |
|
| 409 | + |
|
| 410 | + $to = strlen($this->data); |
|
| 411 | + preg_match("/($this->ldel)|(<[?]((php\s+|=)|\s+))|(<[%])|(<[?]xml\s+)|(<script\s+language\s*=\s*[\"']?\s*php\s*[\"']?\s*>)|([?][>])|([%][>])/i", |
|
| 412 | + $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); |
|
| 413 | + if (isset($match[ 0 ][ 1 ])) { |
|
| 414 | + $to = $match[ 0 ][ 1 ]; |
|
| 415 | + } |
|
| 416 | + $this->value = substr($this->data, $this->counter, $to - $this->counter); |
|
| 417 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + public function yylex2() |
|
| 421 | + { |
|
| 422 | + if (!isset($this->yy_global_pattern2)) { |
|
| 423 | + $this->yy_global_pattern2 = |
|
| 424 | + "/\G(" . $this->ldel . "\\s*(if|elseif|else if|while)\\s+)|\G(" . $this->ldel . "\\s*for\\s+)|\G(" . |
|
| 425 | + $this->ldel . "\\s*foreach(?![^\s]))|\G(" . $this->ldel . "\\s*setfilter\\s+)|\G(" . $this->ldel . |
|
| 426 | + "\\s*make_nocache\\s+)|\G(" . $this->ldel . "\\s*[0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*" . $this->rdel . |
|
| 427 | + ")|\G(" . $this->ldel . "\\s*[\/](?:(?!block)[0-9]*[a-zA-Z_]\\w*)\\s*" . $this->rdel . ")|\G(" . |
|
| 428 | + $this->ldel . "\\s*[$][0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*" . $this->rdel . ")|\G(" . $this->ldel . |
|
| 429 | + "\\s*[\/])|\G(" . $this->ldel . "\\s*)/isS"; |
|
| 430 | + } |
|
| 431 | + if ($this->counter >= strlen($this->data)) { |
|
| 432 | + return false; // end of input |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + do { |
|
| 436 | + if (preg_match($this->yy_global_pattern2, $this->data, $yymatches, null, $this->counter)) { |
|
| 437 | + $yysubmatches = $yymatches; |
|
| 438 | + if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 439 | + $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
|
| 440 | + } else { |
|
| 441 | + $yymatches = array_filter($yymatches, 'strlen'); |
|
| 442 | + } |
|
| 443 | + if (empty($yymatches)) { |
|
| 444 | + throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . |
|
| 445 | + substr($this->data, $this->counter, 5) . '... state TAG'); |
|
| 446 | + } |
|
| 447 | + next($yymatches); // skip global match |
|
| 448 | + $this->token = key($yymatches); // token number |
|
| 449 | + $this->value = current($yymatches); // token value |
|
| 450 | + $r = $this->{'yy_r2_' . $this->token}(); |
|
| 451 | + if ($r === null) { |
|
| 452 | + $this->counter += strlen($this->value); |
|
| 453 | + $this->line += substr_count($this->value, "\n"); |
|
| 454 | + // accept this token |
|
| 455 | + return true; |
|
| 456 | + } elseif ($r === true) { |
|
| 457 | + // we have changed state |
|
| 458 | + // process this token in the new state |
|
| 459 | + return $this->yylex(); |
|
| 460 | + } elseif ($r === false) { |
|
| 461 | + $this->counter += strlen($this->value); |
|
| 462 | + $this->line += substr_count($this->value, "\n"); |
|
| 463 | + if ($this->counter >= strlen($this->data)) { |
|
| 464 | + return false; // end of input |
|
| 465 | + } |
|
| 466 | + // skip this token |
|
| 467 | + continue; |
|
| 468 | + } |
|
| 469 | + } else { |
|
| 470 | + throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 471 | + } |
|
| 472 | + break; |
|
| 473 | + } |
|
| 474 | + while (true); |
|
| 475 | + } // end function |
|
| 476 | + |
|
| 477 | + const TAG = 2; |
|
| 478 | + |
|
| 479 | + public function yy_r2_1() |
|
| 480 | + { |
|
| 481 | + |
|
| 482 | + $this->token = Smarty_Internal_Templateparser::TP_LDELIF; |
|
| 483 | + $this->yybegin(self::TAGBODY); |
|
| 484 | + $this->taglineno = $this->line; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + public function yy_r2_3() |
|
| 488 | + { |
|
| 489 | + |
|
| 490 | + $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; |
|
| 491 | + $this->yybegin(self::TAGBODY); |
|
| 492 | + $this->taglineno = $this->line; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + public function yy_r2_4() |
|
| 496 | + { |
|
| 497 | + |
|
| 498 | + $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; |
|
| 499 | + $this->yybegin(self::TAGBODY); |
|
| 500 | + $this->taglineno = $this->line; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + public function yy_r2_5() |
|
| 504 | + { |
|
| 505 | + |
|
| 506 | + $this->token = Smarty_Internal_Templateparser::TP_LDELSETFILTER; |
|
| 507 | + $this->yybegin(self::TAGBODY); |
|
| 508 | + $this->taglineno = $this->line; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + public function yy_r2_6() |
|
| 512 | + { |
|
| 513 | + |
|
| 514 | + $this->token = Smarty_Internal_Templateparser::TP_LDELMAKENOCACHE; |
|
| 515 | + $this->yybegin(self::TAGBODY); |
|
| 516 | + $this->taglineno = $this->line; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + public function yy_r2_7() |
|
| 520 | + { |
|
| 521 | + |
|
| 522 | + $this->yypopstate(); |
|
| 523 | + $this->token = Smarty_Internal_Templateparser::TP_SIMPLETAG; |
|
| 524 | + $this->taglineno = $this->line; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + public function yy_r2_9() |
|
| 528 | + { |
|
| 529 | + |
|
| 530 | + $this->yypopstate(); |
|
| 531 | + $this->token = Smarty_Internal_Templateparser::TP_CLOSETAG; |
|
| 532 | + $this->taglineno = $this->line; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + public function yy_r2_10() |
|
| 536 | + { |
|
| 537 | + |
|
| 538 | + if ($this->_yy_stack[ count($this->_yy_stack) - 1 ] == self::TEXT) { |
|
| 539 | + $this->yypopstate(); |
|
| 540 | + $this->token = Smarty_Internal_Templateparser::TP_SIMPELOUTPUT; |
|
| 541 | + $this->taglineno = $this->line; |
|
| 542 | + } else { |
|
| 543 | + $this->value = $this->smarty->left_delimiter; |
|
| 544 | + $this->token = Smarty_Internal_Templateparser::TP_LDEL; |
|
| 545 | + $this->yybegin(self::TAGBODY); |
|
| 546 | + $this->taglineno = $this->line; |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + public function yy_r2_12() |
|
| 551 | + { |
|
| 552 | + |
|
| 553 | + $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; |
|
| 554 | + $this->yybegin(self::TAGBODY); |
|
| 555 | + $this->taglineno = $this->line; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + public function yy_r2_13() |
|
| 559 | + { |
|
| 560 | + |
|
| 561 | + $this->token = Smarty_Internal_Templateparser::TP_LDEL; |
|
| 562 | + $this->yybegin(self::TAGBODY); |
|
| 563 | + $this->taglineno = $this->line; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + public function yylex3() |
|
| 567 | + { |
|
| 568 | + if (!isset($this->yy_global_pattern3)) { |
|
| 569 | + $this->yy_global_pattern3 = "/\G(\\s*" . $this->rdel . ")|\G(" . $this->ldel . |
|
| 570 | + "\\s*)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$]smarty\\.block\\.(child|parent))|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*(([!=][=]{1,2})|([<][=>]?)|([>][=]?)|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\\s+)|\G(\\s+(is\\s+(not\\s+)?(odd|even|div)\\s+by)\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G(([!]\\s*)|(not\\s+))|\G([(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\\s*)|\G(\\s*[(]\\s*)|\G(\\s*[)])|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*[-][>]\\s*)|\G(\\s*[=][>]\\s*)|\G(\\s*[=]\\s*)|\G(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|])|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS"; |
|
| 571 | + } |
|
| 572 | + if ($this->counter >= strlen($this->data)) { |
|
| 573 | + return false; // end of input |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + do { |
|
| 577 | + if (preg_match($this->yy_global_pattern3, $this->data, $yymatches, null, $this->counter)) { |
|
| 578 | + $yysubmatches = $yymatches; |
|
| 579 | + if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 580 | + $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
|
| 581 | + } else { |
|
| 582 | + $yymatches = array_filter($yymatches, 'strlen'); |
|
| 583 | + } |
|
| 584 | + if (empty($yymatches)) { |
|
| 585 | + throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . |
|
| 586 | + substr($this->data, $this->counter, 5) . '... state TAGBODY'); |
|
| 587 | + } |
|
| 588 | + next($yymatches); // skip global match |
|
| 589 | + $this->token = key($yymatches); // token number |
|
| 590 | + $this->value = current($yymatches); // token value |
|
| 591 | + $r = $this->{'yy_r3_' . $this->token}(); |
|
| 592 | + if ($r === null) { |
|
| 593 | + $this->counter += strlen($this->value); |
|
| 594 | + $this->line += substr_count($this->value, "\n"); |
|
| 595 | + // accept this token |
|
| 596 | + return true; |
|
| 597 | + } elseif ($r === true) { |
|
| 598 | + // we have changed state |
|
| 599 | + // process this token in the new state |
|
| 600 | + return $this->yylex(); |
|
| 601 | + } elseif ($r === false) { |
|
| 602 | + $this->counter += strlen($this->value); |
|
| 603 | + $this->line += substr_count($this->value, "\n"); |
|
| 604 | + if ($this->counter >= strlen($this->data)) { |
|
| 605 | + return false; // end of input |
|
| 606 | + } |
|
| 607 | + // skip this token |
|
| 608 | + continue; |
|
| 609 | + } |
|
| 610 | + } else { |
|
| 611 | + throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 612 | + } |
|
| 613 | + break; |
|
| 614 | + } |
|
| 615 | + while (true); |
|
| 616 | + } // end function |
|
| 617 | + |
|
| 618 | + const TAGBODY = 3; |
|
| 619 | + |
|
| 620 | + public function yy_r3_1() |
|
| 621 | + { |
|
| 622 | + |
|
| 623 | + $this->token = Smarty_Internal_Templateparser::TP_RDEL; |
|
| 624 | + $this->yypopstate(); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + public function yy_r3_2() |
|
| 628 | + { |
|
| 629 | + |
|
| 630 | + if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 631 | + strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 632 | + ) { |
|
| 633 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 634 | + } else { |
|
| 635 | + $this->yypushstate(self::TAG); |
|
| 636 | + return true; |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + public function yy_r3_3() |
|
| 641 | + { |
|
| 642 | + |
|
| 643 | + $this->token = Smarty_Internal_Templateparser::TP_QUOTE; |
|
| 644 | + $this->yypushstate(self::DOUBLEQUOTEDSTRING); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + public function yy_r3_4() |
|
| 648 | + { |
|
| 649 | + |
|
| 650 | + $this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + public function yy_r3_5() |
|
| 654 | + { |
|
| 655 | + |
|
| 656 | + $this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT; |
|
| 657 | + $this->taglineno = $this->line; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + public function yy_r3_7() |
|
| 661 | + { |
|
| 662 | + |
|
| 663 | + $this->token = Smarty_Internal_Templateparser::TP_DOLLARID; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + public function yy_r3_8() |
|
| 667 | + { |
|
| 668 | + |
|
| 669 | + $this->token = Smarty_Internal_Templateparser::TP_DOLLAR; |
|
| 670 | + } |
|
| 671 | 671 | |
| 672 | - public function yy_r3_9() |
|
| 673 | - { |
|
| 672 | + public function yy_r3_9() |
|
| 673 | + { |
|
| 674 | 674 | |
| 675 | - $this->token = Smarty_Internal_Templateparser::TP_ISIN; |
|
| 676 | - } |
|
| 675 | + $this->token = Smarty_Internal_Templateparser::TP_ISIN; |
|
| 676 | + } |
|
| 677 | 677 | |
| 678 | - public function yy_r3_10() |
|
| 679 | - { |
|
| 678 | + public function yy_r3_10() |
|
| 679 | + { |
|
| 680 | 680 | |
| 681 | - $this->token = Smarty_Internal_Templateparser::TP_AS; |
|
| 682 | - } |
|
| 681 | + $this->token = Smarty_Internal_Templateparser::TP_AS; |
|
| 682 | + } |
|
| 683 | 683 | |
| 684 | - public function yy_r3_11() |
|
| 685 | - { |
|
| 684 | + public function yy_r3_11() |
|
| 685 | + { |
|
| 686 | 686 | |
| 687 | - $this->token = Smarty_Internal_Templateparser::TP_TO; |
|
| 688 | - } |
|
| 687 | + $this->token = Smarty_Internal_Templateparser::TP_TO; |
|
| 688 | + } |
|
| 689 | 689 | |
| 690 | - public function yy_r3_12() |
|
| 691 | - { |
|
| 690 | + public function yy_r3_12() |
|
| 691 | + { |
|
| 692 | 692 | |
| 693 | - $this->token = Smarty_Internal_Templateparser::TP_STEP; |
|
| 694 | - } |
|
| 693 | + $this->token = Smarty_Internal_Templateparser::TP_STEP; |
|
| 694 | + } |
|
| 695 | 695 | |
| 696 | - public function yy_r3_13() |
|
| 697 | - { |
|
| 696 | + public function yy_r3_13() |
|
| 697 | + { |
|
| 698 | 698 | |
| 699 | - $this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF; |
|
| 700 | - } |
|
| 699 | + $this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF; |
|
| 700 | + } |
|
| 701 | 701 | |
| 702 | - public function yy_r3_14() |
|
| 703 | - { |
|
| 702 | + public function yy_r3_14() |
|
| 703 | + { |
|
| 704 | 704 | |
| 705 | - $this->token = Smarty_Internal_Templateparser::TP_LOGOP; |
|
| 706 | - } |
|
| 705 | + $this->token = Smarty_Internal_Templateparser::TP_LOGOP; |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | - public function yy_r3_19() |
|
| 709 | - { |
|
| 708 | + public function yy_r3_19() |
|
| 709 | + { |
|
| 710 | 710 | |
| 711 | - $this->token = Smarty_Internal_Templateparser::TP_SLOGOP; |
|
| 712 | - } |
|
| 711 | + $this->token = Smarty_Internal_Templateparser::TP_SLOGOP; |
|
| 712 | + } |
|
| 713 | 713 | |
| 714 | - public function yy_r3_21() |
|
| 715 | - { |
|
| 714 | + public function yy_r3_21() |
|
| 715 | + { |
|
| 716 | 716 | |
| 717 | - $this->token = Smarty_Internal_Templateparser::TP_TLOGOP; |
|
| 718 | - } |
|
| 717 | + $this->token = Smarty_Internal_Templateparser::TP_TLOGOP; |
|
| 718 | + } |
|
| 719 | 719 | |
| 720 | - public function yy_r3_25() |
|
| 721 | - { |
|
| 720 | + public function yy_r3_25() |
|
| 721 | + { |
|
| 722 | 722 | |
| 723 | - $this->token = Smarty_Internal_Templateparser::TP_SINGLECOND; |
|
| 724 | - } |
|
| 723 | + $this->token = Smarty_Internal_Templateparser::TP_SINGLECOND; |
|
| 724 | + } |
|
| 725 | 725 | |
| 726 | - public function yy_r3_28() |
|
| 727 | - { |
|
| 726 | + public function yy_r3_28() |
|
| 727 | + { |
|
| 728 | 728 | |
| 729 | - $this->token = Smarty_Internal_Templateparser::TP_NOT; |
|
| 730 | - } |
|
| 729 | + $this->token = Smarty_Internal_Templateparser::TP_NOT; |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | - public function yy_r3_31() |
|
| 733 | - { |
|
| 732 | + public function yy_r3_31() |
|
| 733 | + { |
|
| 734 | 734 | |
| 735 | - $this->token = Smarty_Internal_Templateparser::TP_TYPECAST; |
|
| 736 | - } |
|
| 735 | + $this->token = Smarty_Internal_Templateparser::TP_TYPECAST; |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | - public function yy_r3_35() |
|
| 739 | - { |
|
| 738 | + public function yy_r3_35() |
|
| 739 | + { |
|
| 740 | 740 | |
| 741 | - $this->token = Smarty_Internal_Templateparser::TP_OPENP; |
|
| 742 | - } |
|
| 741 | + $this->token = Smarty_Internal_Templateparser::TP_OPENP; |
|
| 742 | + } |
|
| 743 | 743 | |
| 744 | - public function yy_r3_36() |
|
| 745 | - { |
|
| 744 | + public function yy_r3_36() |
|
| 745 | + { |
|
| 746 | 746 | |
| 747 | - $this->token = Smarty_Internal_Templateparser::TP_CLOSEP; |
|
| 748 | - } |
|
| 747 | + $this->token = Smarty_Internal_Templateparser::TP_CLOSEP; |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | - public function yy_r3_37() |
|
| 751 | - { |
|
| 750 | + public function yy_r3_37() |
|
| 751 | + { |
|
| 752 | 752 | |
| 753 | - $this->token = Smarty_Internal_Templateparser::TP_OPENB; |
|
| 754 | - } |
|
| 753 | + $this->token = Smarty_Internal_Templateparser::TP_OPENB; |
|
| 754 | + } |
|
| 755 | 755 | |
| 756 | - public function yy_r3_38() |
|
| 757 | - { |
|
| 756 | + public function yy_r3_38() |
|
| 757 | + { |
|
| 758 | 758 | |
| 759 | - $this->token = Smarty_Internal_Templateparser::TP_CLOSEB; |
|
| 760 | - } |
|
| 759 | + $this->token = Smarty_Internal_Templateparser::TP_CLOSEB; |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | - public function yy_r3_39() |
|
| 763 | - { |
|
| 762 | + public function yy_r3_39() |
|
| 763 | + { |
|
| 764 | 764 | |
| 765 | - $this->token = Smarty_Internal_Templateparser::TP_PTR; |
|
| 766 | - } |
|
| 765 | + $this->token = Smarty_Internal_Templateparser::TP_PTR; |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | - public function yy_r3_40() |
|
| 769 | - { |
|
| 768 | + public function yy_r3_40() |
|
| 769 | + { |
|
| 770 | 770 | |
| 771 | - $this->token = Smarty_Internal_Templateparser::TP_APTR; |
|
| 772 | - } |
|
| 771 | + $this->token = Smarty_Internal_Templateparser::TP_APTR; |
|
| 772 | + } |
|
| 773 | 773 | |
| 774 | - public function yy_r3_41() |
|
| 775 | - { |
|
| 774 | + public function yy_r3_41() |
|
| 775 | + { |
|
| 776 | 776 | |
| 777 | - $this->token = Smarty_Internal_Templateparser::TP_EQUAL; |
|
| 778 | - } |
|
| 777 | + $this->token = Smarty_Internal_Templateparser::TP_EQUAL; |
|
| 778 | + } |
|
| 779 | 779 | |
| 780 | - public function yy_r3_42() |
|
| 781 | - { |
|
| 780 | + public function yy_r3_42() |
|
| 781 | + { |
|
| 782 | 782 | |
| 783 | - $this->token = Smarty_Internal_Templateparser::TP_INCDEC; |
|
| 784 | - } |
|
| 783 | + $this->token = Smarty_Internal_Templateparser::TP_INCDEC; |
|
| 784 | + } |
|
| 785 | 785 | |
| 786 | - public function yy_r3_44() |
|
| 787 | - { |
|
| 786 | + public function yy_r3_44() |
|
| 787 | + { |
|
| 788 | 788 | |
| 789 | - $this->token = Smarty_Internal_Templateparser::TP_UNIMATH; |
|
| 790 | - } |
|
| 789 | + $this->token = Smarty_Internal_Templateparser::TP_UNIMATH; |
|
| 790 | + } |
|
| 791 | 791 | |
| 792 | - public function yy_r3_46() |
|
| 793 | - { |
|
| 792 | + public function yy_r3_46() |
|
| 793 | + { |
|
| 794 | 794 | |
| 795 | - $this->token = Smarty_Internal_Templateparser::TP_MATH; |
|
| 796 | - } |
|
| 795 | + $this->token = Smarty_Internal_Templateparser::TP_MATH; |
|
| 796 | + } |
|
| 797 | 797 | |
| 798 | - public function yy_r3_48() |
|
| 799 | - { |
|
| 798 | + public function yy_r3_48() |
|
| 799 | + { |
|
| 800 | 800 | |
| 801 | - $this->token = Smarty_Internal_Templateparser::TP_AT; |
|
| 802 | - } |
|
| 801 | + $this->token = Smarty_Internal_Templateparser::TP_AT; |
|
| 802 | + } |
|
| 803 | 803 | |
| 804 | - public function yy_r3_49() |
|
| 805 | - { |
|
| 804 | + public function yy_r3_49() |
|
| 805 | + { |
|
| 806 | 806 | |
| 807 | - $this->token = Smarty_Internal_Templateparser::TP_HATCH; |
|
| 808 | - } |
|
| 807 | + $this->token = Smarty_Internal_Templateparser::TP_HATCH; |
|
| 808 | + } |
|
| 809 | 809 | |
| 810 | - public function yy_r3_50() |
|
| 811 | - { |
|
| 810 | + public function yy_r3_50() |
|
| 811 | + { |
|
| 812 | 812 | |
| 813 | - // resolve conflicts with shorttag and right_delimiter starting with '=' |
|
| 814 | - if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->rdel_length) == |
|
| 815 | - $this->smarty->right_delimiter |
|
| 816 | - ) { |
|
| 817 | - preg_match("/\s+/", $this->value, $match); |
|
| 818 | - $this->value = $match[ 0 ]; |
|
| 819 | - $this->token = Smarty_Internal_Templateparser::TP_SPACE; |
|
| 820 | - } else { |
|
| 821 | - $this->token = Smarty_Internal_Templateparser::TP_ATTR; |
|
| 822 | - } |
|
| 823 | - } |
|
| 813 | + // resolve conflicts with shorttag and right_delimiter starting with '=' |
|
| 814 | + if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->rdel_length) == |
|
| 815 | + $this->smarty->right_delimiter |
|
| 816 | + ) { |
|
| 817 | + preg_match("/\s+/", $this->value, $match); |
|
| 818 | + $this->value = $match[ 0 ]; |
|
| 819 | + $this->token = Smarty_Internal_Templateparser::TP_SPACE; |
|
| 820 | + } else { |
|
| 821 | + $this->token = Smarty_Internal_Templateparser::TP_ATTR; |
|
| 822 | + } |
|
| 823 | + } |
|
| 824 | 824 | |
| 825 | - public function yy_r3_51() |
|
| 826 | - { |
|
| 825 | + public function yy_r3_51() |
|
| 826 | + { |
|
| 827 | 827 | |
| 828 | - $this->token = Smarty_Internal_Templateparser::TP_NAMESPACE; |
|
| 829 | - } |
|
| 828 | + $this->token = Smarty_Internal_Templateparser::TP_NAMESPACE; |
|
| 829 | + } |
|
| 830 | 830 | |
| 831 | - public function yy_r3_54() |
|
| 832 | - { |
|
| 831 | + public function yy_r3_54() |
|
| 832 | + { |
|
| 833 | 833 | |
| 834 | - $this->token = Smarty_Internal_Templateparser::TP_ID; |
|
| 835 | - } |
|
| 834 | + $this->token = Smarty_Internal_Templateparser::TP_ID; |
|
| 835 | + } |
|
| 836 | 836 | |
| 837 | - public function yy_r3_55() |
|
| 838 | - { |
|
| 837 | + public function yy_r3_55() |
|
| 838 | + { |
|
| 839 | 839 | |
| 840 | - $this->token = Smarty_Internal_Templateparser::TP_INTEGER; |
|
| 841 | - } |
|
| 840 | + $this->token = Smarty_Internal_Templateparser::TP_INTEGER; |
|
| 841 | + } |
|
| 842 | 842 | |
| 843 | - public function yy_r3_56() |
|
| 844 | - { |
|
| 843 | + public function yy_r3_56() |
|
| 844 | + { |
|
| 845 | 845 | |
| 846 | - $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; |
|
| 847 | - $this->yypopstate(); |
|
| 848 | - } |
|
| 846 | + $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; |
|
| 847 | + $this->yypopstate(); |
|
| 848 | + } |
|
| 849 | 849 | |
| 850 | - public function yy_r3_57() |
|
| 851 | - { |
|
| 850 | + public function yy_r3_57() |
|
| 851 | + { |
|
| 852 | 852 | |
| 853 | - $this->token = Smarty_Internal_Templateparser::TP_VERT; |
|
| 854 | - } |
|
| 853 | + $this->token = Smarty_Internal_Templateparser::TP_VERT; |
|
| 854 | + } |
|
| 855 | 855 | |
| 856 | - public function yy_r3_58() |
|
| 857 | - { |
|
| 858 | - |
|
| 859 | - $this->token = Smarty_Internal_Templateparser::TP_DOT; |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - public function yy_r3_59() |
|
| 863 | - { |
|
| 864 | - |
|
| 865 | - $this->token = Smarty_Internal_Templateparser::TP_COMMA; |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - public function yy_r3_60() |
|
| 869 | - { |
|
| 870 | - |
|
| 871 | - $this->token = Smarty_Internal_Templateparser::TP_SEMICOLON; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - public function yy_r3_61() |
|
| 875 | - { |
|
| 876 | - |
|
| 877 | - $this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON; |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - public function yy_r3_62() |
|
| 881 | - { |
|
| 882 | - |
|
| 883 | - $this->token = Smarty_Internal_Templateparser::TP_COLON; |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - public function yy_r3_63() |
|
| 887 | - { |
|
| 888 | - |
|
| 889 | - $this->token = Smarty_Internal_Templateparser::TP_QMARK; |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - public function yy_r3_64() |
|
| 893 | - { |
|
| 894 | - |
|
| 895 | - $this->token = Smarty_Internal_Templateparser::TP_HEX; |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - public function yy_r3_65() |
|
| 899 | - { |
|
| 900 | - |
|
| 901 | - $this->token = Smarty_Internal_Templateparser::TP_SPACE; |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - public function yy_r3_66() |
|
| 905 | - { |
|
| 906 | - |
|
| 907 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - public function yylex4() |
|
| 911 | - { |
|
| 912 | - if (!isset($this->yy_global_pattern4)) { |
|
| 913 | - $this->yy_global_pattern4 = |
|
| 914 | - "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/]literal\\s*" . |
|
| 915 | - $this->rdel . ")|\G([\S\s])/isS"; |
|
| 916 | - } |
|
| 917 | - if ($this->counter >= strlen($this->data)) { |
|
| 918 | - return false; // end of input |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - do { |
|
| 922 | - if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, null, $this->counter)) { |
|
| 923 | - $yysubmatches = $yymatches; |
|
| 924 | - if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 925 | - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
|
| 926 | - } else { |
|
| 927 | - $yymatches = array_filter($yymatches, 'strlen'); |
|
| 928 | - } |
|
| 929 | - if (empty($yymatches)) { |
|
| 930 | - throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . |
|
| 931 | - substr($this->data, $this->counter, 5) . '... state LITERAL'); |
|
| 932 | - } |
|
| 933 | - next($yymatches); // skip global match |
|
| 934 | - $this->token = key($yymatches); // token number |
|
| 935 | - $this->value = current($yymatches); // token value |
|
| 936 | - $r = $this->{'yy_r4_' . $this->token}(); |
|
| 937 | - if ($r === null) { |
|
| 938 | - $this->counter += strlen($this->value); |
|
| 939 | - $this->line += substr_count($this->value, "\n"); |
|
| 940 | - // accept this token |
|
| 941 | - return true; |
|
| 942 | - } elseif ($r === true) { |
|
| 943 | - // we have changed state |
|
| 944 | - // process this token in the new state |
|
| 945 | - return $this->yylex(); |
|
| 946 | - } elseif ($r === false) { |
|
| 947 | - $this->counter += strlen($this->value); |
|
| 948 | - $this->line += substr_count($this->value, "\n"); |
|
| 949 | - if ($this->counter >= strlen($this->data)) { |
|
| 950 | - return false; // end of input |
|
| 951 | - } |
|
| 952 | - // skip this token |
|
| 953 | - continue; |
|
| 954 | - } |
|
| 955 | - } else { |
|
| 956 | - throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 957 | - } |
|
| 958 | - break; |
|
| 959 | - } |
|
| 960 | - while (true); |
|
| 961 | - } // end function |
|
| 962 | - |
|
| 963 | - const LITERAL = 4; |
|
| 964 | - |
|
| 965 | - public function yy_r4_1() |
|
| 966 | - { |
|
| 967 | - |
|
| 968 | - $this->literal_cnt ++; |
|
| 969 | - $this->token = Smarty_Internal_Templateparser::TP_LITERAL; |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - public function yy_r4_2() |
|
| 973 | - { |
|
| 974 | - |
|
| 975 | - if ($this->literal_cnt) { |
|
| 976 | - $this->literal_cnt --; |
|
| 977 | - $this->token = Smarty_Internal_Templateparser::TP_LITERAL; |
|
| 978 | - } else { |
|
| 979 | - $this->token = Smarty_Internal_Templateparser::TP_LITERALEND; |
|
| 980 | - $this->yypopstate(); |
|
| 981 | - } |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - public function yy_r4_3() |
|
| 985 | - { |
|
| 986 | - |
|
| 987 | - $to = strlen($this->data); |
|
| 988 | - preg_match("/{$this->ldel}[\/]?literal{$this->rdel}/i", $this->data, $match, PREG_OFFSET_CAPTURE, |
|
| 989 | - $this->counter); |
|
| 990 | - if (isset($match[ 0 ][ 1 ])) { |
|
| 991 | - $to = $match[ 0 ][ 1 ]; |
|
| 992 | - } else { |
|
| 993 | - $this->compiler->trigger_template_error("missing or misspelled literal closing tag"); |
|
| 994 | - } |
|
| 995 | - $this->value = substr($this->data, $this->counter, $to - $this->counter); |
|
| 996 | - $this->token = Smarty_Internal_Templateparser::TP_LITERAL; |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - public function yylex5() |
|
| 1000 | - { |
|
| 1001 | - if (!isset($this->yy_global_pattern5)) { |
|
| 1002 | - $this->yy_global_pattern5 = |
|
| 1003 | - "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/]literal\\s*" . |
|
| 1004 | - $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/])|\G(" . $this->ldel . "\\s*[0-9]*[a-zA-Z_]\\w*)|\G(" . |
|
| 1005 | - $this->ldel . |
|
| 1006 | - "\\s*)|\G([\"])|\G([`][$])|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=(" . |
|
| 1007 | - $this->ldel . "|\\$|`\\$|\")))|\G([\S\s])/isS"; |
|
| 1008 | - } |
|
| 1009 | - if ($this->counter >= strlen($this->data)) { |
|
| 1010 | - return false; // end of input |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - do { |
|
| 1014 | - if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, null, $this->counter)) { |
|
| 1015 | - $yysubmatches = $yymatches; |
|
| 1016 | - if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 1017 | - $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
|
| 1018 | - } else { |
|
| 1019 | - $yymatches = array_filter($yymatches, 'strlen'); |
|
| 1020 | - } |
|
| 1021 | - if (empty($yymatches)) { |
|
| 1022 | - throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . |
|
| 1023 | - substr($this->data, $this->counter, 5) . '... state DOUBLEQUOTEDSTRING'); |
|
| 1024 | - } |
|
| 1025 | - next($yymatches); // skip global match |
|
| 1026 | - $this->token = key($yymatches); // token number |
|
| 1027 | - $this->value = current($yymatches); // token value |
|
| 1028 | - $r = $this->{'yy_r5_' . $this->token}(); |
|
| 1029 | - if ($r === null) { |
|
| 1030 | - $this->counter += strlen($this->value); |
|
| 1031 | - $this->line += substr_count($this->value, "\n"); |
|
| 1032 | - // accept this token |
|
| 1033 | - return true; |
|
| 1034 | - } elseif ($r === true) { |
|
| 1035 | - // we have changed state |
|
| 1036 | - // process this token in the new state |
|
| 1037 | - return $this->yylex(); |
|
| 1038 | - } elseif ($r === false) { |
|
| 1039 | - $this->counter += strlen($this->value); |
|
| 1040 | - $this->line += substr_count($this->value, "\n"); |
|
| 1041 | - if ($this->counter >= strlen($this->data)) { |
|
| 1042 | - return false; // end of input |
|
| 1043 | - } |
|
| 1044 | - // skip this token |
|
| 1045 | - continue; |
|
| 1046 | - } |
|
| 1047 | - } else { |
|
| 1048 | - throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 1049 | - } |
|
| 1050 | - break; |
|
| 1051 | - } |
|
| 1052 | - while (true); |
|
| 1053 | - } // end function |
|
| 1054 | - |
|
| 1055 | - const DOUBLEQUOTEDSTRING = 5; |
|
| 1056 | - |
|
| 1057 | - public function yy_r5_1() |
|
| 1058 | - { |
|
| 1059 | - |
|
| 1060 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - public function yy_r5_2() |
|
| 1064 | - { |
|
| 1065 | - |
|
| 1066 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1067 | - } |
|
| 1068 | - |
|
| 1069 | - public function yy_r5_3() |
|
| 1070 | - { |
|
| 1071 | - |
|
| 1072 | - if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 1073 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 1074 | - ) { |
|
| 1075 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1076 | - } else { |
|
| 1077 | - $this->yypushstate(self::TAG); |
|
| 1078 | - return true; |
|
| 1079 | - } |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - public function yy_r5_4() |
|
| 1083 | - { |
|
| 1084 | - |
|
| 1085 | - if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 1086 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 1087 | - ) { |
|
| 1088 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1089 | - } else { |
|
| 1090 | - $this->yypushstate(self::TAG); |
|
| 1091 | - return true; |
|
| 1092 | - } |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - public function yy_r5_5() |
|
| 1096 | - { |
|
| 1097 | - |
|
| 1098 | - if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 1099 | - strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 1100 | - ) { |
|
| 1101 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1102 | - } else { |
|
| 1103 | - $this->token = Smarty_Internal_Templateparser::TP_LDEL; |
|
| 1104 | - $this->taglineno = $this->line; |
|
| 1105 | - $this->yypushstate(self::TAGBODY); |
|
| 1106 | - } |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - public function yy_r5_6() |
|
| 1110 | - { |
|
| 1111 | - |
|
| 1112 | - $this->token = Smarty_Internal_Templateparser::TP_QUOTE; |
|
| 1113 | - $this->yypopstate(); |
|
| 1114 | - } |
|
| 1115 | - |
|
| 1116 | - public function yy_r5_7() |
|
| 1117 | - { |
|
| 1118 | - |
|
| 1119 | - $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; |
|
| 1120 | - $this->value = substr($this->value, 0, - 1); |
|
| 1121 | - $this->yypushstate(self::TAGBODY); |
|
| 1122 | - $this->taglineno = $this->line; |
|
| 1123 | - } |
|
| 1124 | - |
|
| 1125 | - public function yy_r5_8() |
|
| 1126 | - { |
|
| 1127 | - |
|
| 1128 | - $this->token = Smarty_Internal_Templateparser::TP_DOLLARID; |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - public function yy_r5_9() |
|
| 1132 | - { |
|
| 1133 | - |
|
| 1134 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1135 | - } |
|
| 1136 | - |
|
| 1137 | - public function yy_r5_10() |
|
| 1138 | - { |
|
| 1139 | - |
|
| 1140 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - public function yy_r5_14() |
|
| 1144 | - { |
|
| 1145 | - |
|
| 1146 | - $to = strlen($this->data); |
|
| 1147 | - $this->value = substr($this->data, $this->counter, $to - $this->counter); |
|
| 1148 | - $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1149 | - } |
|
| 856 | + public function yy_r3_58() |
|
| 857 | + { |
|
| 858 | + |
|
| 859 | + $this->token = Smarty_Internal_Templateparser::TP_DOT; |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + public function yy_r3_59() |
|
| 863 | + { |
|
| 864 | + |
|
| 865 | + $this->token = Smarty_Internal_Templateparser::TP_COMMA; |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + public function yy_r3_60() |
|
| 869 | + { |
|
| 870 | + |
|
| 871 | + $this->token = Smarty_Internal_Templateparser::TP_SEMICOLON; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + public function yy_r3_61() |
|
| 875 | + { |
|
| 876 | + |
|
| 877 | + $this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON; |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + public function yy_r3_62() |
|
| 881 | + { |
|
| 882 | + |
|
| 883 | + $this->token = Smarty_Internal_Templateparser::TP_COLON; |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + public function yy_r3_63() |
|
| 887 | + { |
|
| 888 | + |
|
| 889 | + $this->token = Smarty_Internal_Templateparser::TP_QMARK; |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + public function yy_r3_64() |
|
| 893 | + { |
|
| 894 | + |
|
| 895 | + $this->token = Smarty_Internal_Templateparser::TP_HEX; |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + public function yy_r3_65() |
|
| 899 | + { |
|
| 900 | + |
|
| 901 | + $this->token = Smarty_Internal_Templateparser::TP_SPACE; |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + public function yy_r3_66() |
|
| 905 | + { |
|
| 906 | + |
|
| 907 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + public function yylex4() |
|
| 911 | + { |
|
| 912 | + if (!isset($this->yy_global_pattern4)) { |
|
| 913 | + $this->yy_global_pattern4 = |
|
| 914 | + "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/]literal\\s*" . |
|
| 915 | + $this->rdel . ")|\G([\S\s])/isS"; |
|
| 916 | + } |
|
| 917 | + if ($this->counter >= strlen($this->data)) { |
|
| 918 | + return false; // end of input |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + do { |
|
| 922 | + if (preg_match($this->yy_global_pattern4, $this->data, $yymatches, null, $this->counter)) { |
|
| 923 | + $yysubmatches = $yymatches; |
|
| 924 | + if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 925 | + $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
|
| 926 | + } else { |
|
| 927 | + $yymatches = array_filter($yymatches, 'strlen'); |
|
| 928 | + } |
|
| 929 | + if (empty($yymatches)) { |
|
| 930 | + throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . |
|
| 931 | + substr($this->data, $this->counter, 5) . '... state LITERAL'); |
|
| 932 | + } |
|
| 933 | + next($yymatches); // skip global match |
|
| 934 | + $this->token = key($yymatches); // token number |
|
| 935 | + $this->value = current($yymatches); // token value |
|
| 936 | + $r = $this->{'yy_r4_' . $this->token}(); |
|
| 937 | + if ($r === null) { |
|
| 938 | + $this->counter += strlen($this->value); |
|
| 939 | + $this->line += substr_count($this->value, "\n"); |
|
| 940 | + // accept this token |
|
| 941 | + return true; |
|
| 942 | + } elseif ($r === true) { |
|
| 943 | + // we have changed state |
|
| 944 | + // process this token in the new state |
|
| 945 | + return $this->yylex(); |
|
| 946 | + } elseif ($r === false) { |
|
| 947 | + $this->counter += strlen($this->value); |
|
| 948 | + $this->line += substr_count($this->value, "\n"); |
|
| 949 | + if ($this->counter >= strlen($this->data)) { |
|
| 950 | + return false; // end of input |
|
| 951 | + } |
|
| 952 | + // skip this token |
|
| 953 | + continue; |
|
| 954 | + } |
|
| 955 | + } else { |
|
| 956 | + throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 957 | + } |
|
| 958 | + break; |
|
| 959 | + } |
|
| 960 | + while (true); |
|
| 961 | + } // end function |
|
| 962 | + |
|
| 963 | + const LITERAL = 4; |
|
| 964 | + |
|
| 965 | + public function yy_r4_1() |
|
| 966 | + { |
|
| 967 | + |
|
| 968 | + $this->literal_cnt ++; |
|
| 969 | + $this->token = Smarty_Internal_Templateparser::TP_LITERAL; |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + public function yy_r4_2() |
|
| 973 | + { |
|
| 974 | + |
|
| 975 | + if ($this->literal_cnt) { |
|
| 976 | + $this->literal_cnt --; |
|
| 977 | + $this->token = Smarty_Internal_Templateparser::TP_LITERAL; |
|
| 978 | + } else { |
|
| 979 | + $this->token = Smarty_Internal_Templateparser::TP_LITERALEND; |
|
| 980 | + $this->yypopstate(); |
|
| 981 | + } |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + public function yy_r4_3() |
|
| 985 | + { |
|
| 986 | + |
|
| 987 | + $to = strlen($this->data); |
|
| 988 | + preg_match("/{$this->ldel}[\/]?literal{$this->rdel}/i", $this->data, $match, PREG_OFFSET_CAPTURE, |
|
| 989 | + $this->counter); |
|
| 990 | + if (isset($match[ 0 ][ 1 ])) { |
|
| 991 | + $to = $match[ 0 ][ 1 ]; |
|
| 992 | + } else { |
|
| 993 | + $this->compiler->trigger_template_error("missing or misspelled literal closing tag"); |
|
| 994 | + } |
|
| 995 | + $this->value = substr($this->data, $this->counter, $to - $this->counter); |
|
| 996 | + $this->token = Smarty_Internal_Templateparser::TP_LITERAL; |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + public function yylex5() |
|
| 1000 | + { |
|
| 1001 | + if (!isset($this->yy_global_pattern5)) { |
|
| 1002 | + $this->yy_global_pattern5 = |
|
| 1003 | + "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/]literal\\s*" . |
|
| 1004 | + $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/])|\G(" . $this->ldel . "\\s*[0-9]*[a-zA-Z_]\\w*)|\G(" . |
|
| 1005 | + $this->ldel . |
|
| 1006 | + "\\s*)|\G([\"])|\G([`][$])|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=(" . |
|
| 1007 | + $this->ldel . "|\\$|`\\$|\")))|\G([\S\s])/isS"; |
|
| 1008 | + } |
|
| 1009 | + if ($this->counter >= strlen($this->data)) { |
|
| 1010 | + return false; // end of input |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + do { |
|
| 1014 | + if (preg_match($this->yy_global_pattern5, $this->data, $yymatches, null, $this->counter)) { |
|
| 1015 | + $yysubmatches = $yymatches; |
|
| 1016 | + if (strlen($yysubmatches[ 0 ]) < 200) { |
|
| 1017 | + $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |
|
| 1018 | + } else { |
|
| 1019 | + $yymatches = array_filter($yymatches, 'strlen'); |
|
| 1020 | + } |
|
| 1021 | + if (empty($yymatches)) { |
|
| 1022 | + throw new Exception('Error: lexing failed because a rule matched' . ' an empty string. Input "' . |
|
| 1023 | + substr($this->data, $this->counter, 5) . '... state DOUBLEQUOTEDSTRING'); |
|
| 1024 | + } |
|
| 1025 | + next($yymatches); // skip global match |
|
| 1026 | + $this->token = key($yymatches); // token number |
|
| 1027 | + $this->value = current($yymatches); // token value |
|
| 1028 | + $r = $this->{'yy_r5_' . $this->token}(); |
|
| 1029 | + if ($r === null) { |
|
| 1030 | + $this->counter += strlen($this->value); |
|
| 1031 | + $this->line += substr_count($this->value, "\n"); |
|
| 1032 | + // accept this token |
|
| 1033 | + return true; |
|
| 1034 | + } elseif ($r === true) { |
|
| 1035 | + // we have changed state |
|
| 1036 | + // process this token in the new state |
|
| 1037 | + return $this->yylex(); |
|
| 1038 | + } elseif ($r === false) { |
|
| 1039 | + $this->counter += strlen($this->value); |
|
| 1040 | + $this->line += substr_count($this->value, "\n"); |
|
| 1041 | + if ($this->counter >= strlen($this->data)) { |
|
| 1042 | + return false; // end of input |
|
| 1043 | + } |
|
| 1044 | + // skip this token |
|
| 1045 | + continue; |
|
| 1046 | + } |
|
| 1047 | + } else { |
|
| 1048 | + throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[ $this->counter ]); |
|
| 1049 | + } |
|
| 1050 | + break; |
|
| 1051 | + } |
|
| 1052 | + while (true); |
|
| 1053 | + } // end function |
|
| 1054 | + |
|
| 1055 | + const DOUBLEQUOTEDSTRING = 5; |
|
| 1056 | + |
|
| 1057 | + public function yy_r5_1() |
|
| 1058 | + { |
|
| 1059 | + |
|
| 1060 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + public function yy_r5_2() |
|
| 1064 | + { |
|
| 1065 | + |
|
| 1066 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1067 | + } |
|
| 1068 | + |
|
| 1069 | + public function yy_r5_3() |
|
| 1070 | + { |
|
| 1071 | + |
|
| 1072 | + if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 1073 | + strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 1074 | + ) { |
|
| 1075 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1076 | + } else { |
|
| 1077 | + $this->yypushstate(self::TAG); |
|
| 1078 | + return true; |
|
| 1079 | + } |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + public function yy_r5_4() |
|
| 1083 | + { |
|
| 1084 | + |
|
| 1085 | + if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 1086 | + strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 1087 | + ) { |
|
| 1088 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1089 | + } else { |
|
| 1090 | + $this->yypushstate(self::TAG); |
|
| 1091 | + return true; |
|
| 1092 | + } |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + public function yy_r5_5() |
|
| 1096 | + { |
|
| 1097 | + |
|
| 1098 | + if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? |
|
| 1099 | + strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false |
|
| 1100 | + ) { |
|
| 1101 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1102 | + } else { |
|
| 1103 | + $this->token = Smarty_Internal_Templateparser::TP_LDEL; |
|
| 1104 | + $this->taglineno = $this->line; |
|
| 1105 | + $this->yypushstate(self::TAGBODY); |
|
| 1106 | + } |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + public function yy_r5_6() |
|
| 1110 | + { |
|
| 1111 | + |
|
| 1112 | + $this->token = Smarty_Internal_Templateparser::TP_QUOTE; |
|
| 1113 | + $this->yypopstate(); |
|
| 1114 | + } |
|
| 1115 | + |
|
| 1116 | + public function yy_r5_7() |
|
| 1117 | + { |
|
| 1118 | + |
|
| 1119 | + $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; |
|
| 1120 | + $this->value = substr($this->value, 0, - 1); |
|
| 1121 | + $this->yypushstate(self::TAGBODY); |
|
| 1122 | + $this->taglineno = $this->line; |
|
| 1123 | + } |
|
| 1124 | + |
|
| 1125 | + public function yy_r5_8() |
|
| 1126 | + { |
|
| 1127 | + |
|
| 1128 | + $this->token = Smarty_Internal_Templateparser::TP_DOLLARID; |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + public function yy_r5_9() |
|
| 1132 | + { |
|
| 1133 | + |
|
| 1134 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1135 | + } |
|
| 1136 | + |
|
| 1137 | + public function yy_r5_10() |
|
| 1138 | + { |
|
| 1139 | + |
|
| 1140 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + public function yy_r5_14() |
|
| 1144 | + { |
|
| 1145 | + |
|
| 1146 | + $to = strlen($this->data); |
|
| 1147 | + $this->value = substr($this->data, $this->counter, $to - $this->counter); |
|
| 1148 | + $this->token = Smarty_Internal_Templateparser::TP_TEXT; |
|
| 1149 | + } |
|
| 1150 | 1150 | |
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | - |
|
| 1154 | 1153 | \ No newline at end of file |
| 1154 | + |
|
| 1155 | 1155 | \ No newline at end of file |
@@ -183,7 +183,7 @@ |
||
| 183 | 183 | * @param string $resource_name template_resource or config_resource to parse |
| 184 | 184 | * @param string $default_resource the default resource_type defined in $smarty |
| 185 | 185 | * |
| 186 | - * @return array with parsed resource name and type |
|
| 186 | + * @return string[] with parsed resource name and type |
|
| 187 | 187 | */ |
| 188 | 188 | public static function parseResourceName($resource_name, $default_resource) |
| 189 | 189 | { |
@@ -129,28 +129,28 @@ discard block |
||
| 129 | 129 | public static function load(Smarty $smarty, $type) |
| 130 | 130 | { |
| 131 | 131 | // try smarty's cache |
| 132 | - if (isset($smarty->_cache[ 'resource_handlers' ][ $type ])) { |
|
| 133 | - return $smarty->_cache[ 'resource_handlers' ][ $type ]; |
|
| 132 | + if (isset($smarty->_cache['resource_handlers'][$type])) { |
|
| 133 | + return $smarty->_cache['resource_handlers'][$type]; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // try registered resource |
| 137 | - if (isset($smarty->registered_resources[ $type ])) { |
|
| 138 | - return $smarty->_cache[ 'resource_handlers' ][ $type ] = |
|
| 139 | - $smarty->registered_resources[ $type ] instanceof Smarty_Resource ? |
|
| 140 | - $smarty->registered_resources[ $type ] : new Smarty_Internal_Resource_Registered(); |
|
| 137 | + if (isset($smarty->registered_resources[$type])) { |
|
| 138 | + return $smarty->_cache['resource_handlers'][$type] = |
|
| 139 | + $smarty->registered_resources[$type] instanceof Smarty_Resource ? |
|
| 140 | + $smarty->registered_resources[$type] : new Smarty_Internal_Resource_Registered(); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | // try sysplugins dir |
| 144 | - if (isset(self::$sysplugins[ $type ])) { |
|
| 144 | + if (isset(self::$sysplugins[$type])) { |
|
| 145 | 145 | $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type); |
| 146 | - return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class(); |
|
| 146 | + return $smarty->_cache['resource_handlers'][$type] = new $_resource_class(); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | // try plugins dir |
| 150 | 150 | $_resource_class = 'Smarty_Resource_' . ucfirst($type); |
| 151 | 151 | if ($smarty->loadPlugin($_resource_class)) { |
| 152 | 152 | if (class_exists($_resource_class, false)) { |
| 153 | - return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class(); |
|
| 153 | + return $smarty->_cache['resource_handlers'][$type] = new $_resource_class(); |
|
| 154 | 154 | } else { |
| 155 | 155 | $smarty->registerResource($type, |
| 156 | 156 | array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp", |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | if (is_object($smarty->security_policy)) { |
| 168 | 168 | $smarty->security_policy->isTrustedStream($type); |
| 169 | 169 | } |
| 170 | - return $smarty->_cache[ 'resource_handlers' ][ $type ] = new Smarty_Internal_Resource_Stream(); |
|
| 170 | + return $smarty->_cache['resource_handlers'][$type] = new Smarty_Internal_Resource_Stream(); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // TODO: try default_(template|config)_handler |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | public static function parseResourceName($resource_name, $default_resource) |
| 189 | 189 | { |
| 190 | 190 | if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]/', $resource_name, $match)) { |
| 191 | - $type = $match[ 1 ]; |
|
| 192 | - $name = substr($resource_name, strlen($match[ 0 ])); |
|
| 191 | + $type = $match[1]; |
|
| 192 | + $name = substr($resource_name, strlen($match[0])); |
|
| 193 | 193 | } else { |
| 194 | 194 | // no resource given, use default |
| 195 | 195 | // or single character before the colon is not a resource type, but part of the filepath |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | // TODO: optimize for Smarty's internal resource types |
| 215 | 215 | $resource = Smarty_Resource::load($smarty, $type); |
| 216 | 216 | // go relative to a given template? |
| 217 | - $_file_is_dotted = $name[ 0 ] == '.' && ($name[ 1 ] == '.' || $name[ 1 ] == '/'); |
|
| 217 | + $_file_is_dotted = $name[0] == '.' && ($name[1] == '.' || $name[1] == '/'); |
|
| 218 | 218 | if ($obj->_objType == 2 && $_file_is_dotted && |
| 219 | 219 | ($obj->source->type == 'file' || $obj->parent->source->type == 'extends') |
| 220 | 220 | ) { |
@@ -20,231 +20,231 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | abstract class Smarty_Resource |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Source is bypassing compiler |
|
| 25 | - * |
|
| 26 | - * @var boolean |
|
| 27 | - */ |
|
| 28 | - public $uncompiled = false; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Source must be recompiled on every occasion |
|
| 32 | - * |
|
| 33 | - * @var boolean |
|
| 34 | - */ |
|
| 35 | - public $recompiled = false; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * resource types provided by the core |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - public static $sysplugins = array('file' => 'smarty_internal_resource_file.php', |
|
| 43 | - 'string' => 'smarty_internal_resource_string.php', |
|
| 44 | - 'extends' => 'smarty_internal_resource_extends.php', |
|
| 45 | - 'stream' => 'smarty_internal_resource_stream.php', |
|
| 46 | - 'eval' => 'smarty_internal_resource_eval.php', |
|
| 47 | - 'php' => 'smarty_internal_resource_php.php'); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Flag if resource does implement populateCompiledFilepath() method |
|
| 51 | - * |
|
| 52 | - * @var bool |
|
| 53 | - */ |
|
| 54 | - public $hasCompiledHandler = false; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Load template's source into current template object |
|
| 58 | - * |
|
| 59 | - * @param Smarty_Template_Source $source source object |
|
| 60 | - * |
|
| 61 | - * @return string template source |
|
| 62 | - * @throws SmartyException if source cannot be loaded |
|
| 63 | - */ |
|
| 64 | - abstract public function getContent(Smarty_Template_Source $source); |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * populate Source Object with meta data from Resource |
|
| 68 | - * |
|
| 69 | - * @param Smarty_Template_Source $source source object |
|
| 70 | - * @param Smarty_Internal_Template $_template template object |
|
| 71 | - */ |
|
| 72 | - abstract public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * populate Source Object with timestamp and exists from Resource |
|
| 76 | - * |
|
| 77 | - * @param Smarty_Template_Source $source source object |
|
| 78 | - */ |
|
| 79 | - public function populateTimestamp(Smarty_Template_Source $source) |
|
| 80 | - { |
|
| 81 | - // intentionally left blank |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * modify resource_name according to resource handlers specifications |
|
| 86 | - * |
|
| 87 | - * @param Smarty $smarty Smarty instance |
|
| 88 | - * @param string $resource_name resource_name to make unique |
|
| 89 | - * @param boolean $isConfig flag for config resource |
|
| 90 | - * |
|
| 91 | - * @return string unique resource name |
|
| 92 | - */ |
|
| 93 | - public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) |
|
| 94 | - { |
|
| 95 | - if ($isConfig) { |
|
| 96 | - if (!isset($smarty->_joined_config_dir)) { |
|
| 97 | - $smarty->getTemplateDir(null, true); |
|
| 98 | - } |
|
| 99 | - return get_class($this) . '#' . $smarty->_joined_config_dir . '#' . $resource_name; |
|
| 100 | - } else { |
|
| 101 | - if (!isset($smarty->_joined_template_dir)) { |
|
| 102 | - $smarty->getTemplateDir(); |
|
| 103 | - } |
|
| 104 | - return get_class($this) . '#' . $smarty->_joined_template_dir . '#' . $resource_name; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Determine basename for compiled filename |
|
| 110 | - * |
|
| 111 | - * @param Smarty_Template_Source $source source object |
|
| 112 | - * |
|
| 113 | - * @return string resource's basename |
|
| 114 | - */ |
|
| 115 | - public function getBasename(Smarty_Template_Source $source) |
|
| 116 | - { |
|
| 117 | - return basename(preg_replace('![^\w]+!', '_', $source->name)); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Load Resource Handler |
|
| 122 | - * |
|
| 123 | - * @param Smarty $smarty smarty object |
|
| 124 | - * @param string $type name of the resource |
|
| 125 | - * |
|
| 126 | - * @throws SmartyException |
|
| 127 | - * @return Smarty_Resource Resource Handler |
|
| 128 | - */ |
|
| 129 | - public static function load(Smarty $smarty, $type) |
|
| 130 | - { |
|
| 131 | - // try smarty's cache |
|
| 132 | - if (isset($smarty->_cache[ 'resource_handlers' ][ $type ])) { |
|
| 133 | - return $smarty->_cache[ 'resource_handlers' ][ $type ]; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // try registered resource |
|
| 137 | - if (isset($smarty->registered_resources[ $type ])) { |
|
| 138 | - return $smarty->_cache[ 'resource_handlers' ][ $type ] = |
|
| 139 | - $smarty->registered_resources[ $type ] instanceof Smarty_Resource ? |
|
| 140 | - $smarty->registered_resources[ $type ] : new Smarty_Internal_Resource_Registered(); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // try sysplugins dir |
|
| 144 | - if (isset(self::$sysplugins[ $type ])) { |
|
| 145 | - $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type); |
|
| 146 | - return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class(); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // try plugins dir |
|
| 150 | - $_resource_class = 'Smarty_Resource_' . ucfirst($type); |
|
| 151 | - if ($smarty->loadPlugin($_resource_class)) { |
|
| 152 | - if (class_exists($_resource_class, false)) { |
|
| 153 | - return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class(); |
|
| 154 | - } else { |
|
| 155 | - $smarty->registerResource($type, |
|
| 156 | - array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp", |
|
| 157 | - "smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted")); |
|
| 158 | - // give it another try, now that the resource is registered properly |
|
| 159 | - return self::load($smarty, $type); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // try streams |
|
| 164 | - $_known_stream = stream_get_wrappers(); |
|
| 165 | - if (in_array($type, $_known_stream)) { |
|
| 166 | - // is known stream |
|
| 167 | - if (is_object($smarty->security_policy)) { |
|
| 168 | - $smarty->security_policy->isTrustedStream($type); |
|
| 169 | - } |
|
| 170 | - return $smarty->_cache[ 'resource_handlers' ][ $type ] = new Smarty_Internal_Resource_Stream(); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - throw new SmartyException("Unknown resource type '{$type}'"); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * extract resource_type and resource_name from template_resource and config_resource |
|
| 178 | - * @note "C:/foo.tpl" was forced to file resource up till Smarty 3.1.3 (including). |
|
| 179 | - * |
|
| 180 | - * @param string $resource_name template_resource or config_resource to parse |
|
| 181 | - * @param string $default_resource the default resource_type defined in $smarty |
|
| 182 | - * |
|
| 183 | - * @return array with parsed resource name and type |
|
| 184 | - */ |
|
| 185 | - public static function parseResourceName($resource_name, $default_resource) |
|
| 186 | - { |
|
| 187 | - if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]/', $resource_name, $match)) { |
|
| 188 | - $type = $match[ 1 ]; |
|
| 189 | - $name = substr($resource_name, strlen($match[ 0 ])); |
|
| 190 | - } else { |
|
| 191 | - // no resource given, use default |
|
| 192 | - // or single character before the colon is not a resource type, but part of the filepath |
|
| 193 | - $type = $default_resource; |
|
| 194 | - $name = $resource_name; |
|
| 195 | - } |
|
| 196 | - return array($name, $type); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * modify template_resource according to resource handlers specifications |
|
| 201 | - * |
|
| 202 | - * @param \Smarty_Internal_Template|\Smarty $obj Smarty instance |
|
| 203 | - * @param string $template_resource template_resource to extract resource handler and name of |
|
| 204 | - * |
|
| 205 | - * @return string unique resource name |
|
| 206 | - */ |
|
| 207 | - public static function getUniqueTemplateName($obj, $template_resource) |
|
| 208 | - { |
|
| 209 | - $smarty = $obj->_objType == 2 ? $obj->smarty : $obj; |
|
| 210 | - list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type); |
|
| 211 | - $resource = Smarty_Resource::load($smarty, $type); |
|
| 212 | - // go relative to a given template? |
|
| 213 | - $_file_is_dotted = $name[ 0 ] == '.' && ($name[ 1 ] == '.' || $name[ 1 ] == '/'); |
|
| 214 | - if ($obj->_objType == 2 && $_file_is_dotted && |
|
| 215 | - ($obj->source->type == 'file' || $obj->parent->source->type == 'extends') |
|
| 216 | - ) { |
|
| 217 | - $name = $smarty->_realpath(dirname($obj->parent->source->filepath) . DS . $name); |
|
| 218 | - } |
|
| 219 | - return $resource->buildUniqueResourceName($smarty, $name); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /* |
|
| 23 | + /** |
|
| 24 | + * Source is bypassing compiler |
|
| 25 | + * |
|
| 26 | + * @var boolean |
|
| 27 | + */ |
|
| 28 | + public $uncompiled = false; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Source must be recompiled on every occasion |
|
| 32 | + * |
|
| 33 | + * @var boolean |
|
| 34 | + */ |
|
| 35 | + public $recompiled = false; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * resource types provided by the core |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + public static $sysplugins = array('file' => 'smarty_internal_resource_file.php', |
|
| 43 | + 'string' => 'smarty_internal_resource_string.php', |
|
| 44 | + 'extends' => 'smarty_internal_resource_extends.php', |
|
| 45 | + 'stream' => 'smarty_internal_resource_stream.php', |
|
| 46 | + 'eval' => 'smarty_internal_resource_eval.php', |
|
| 47 | + 'php' => 'smarty_internal_resource_php.php'); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Flag if resource does implement populateCompiledFilepath() method |
|
| 51 | + * |
|
| 52 | + * @var bool |
|
| 53 | + */ |
|
| 54 | + public $hasCompiledHandler = false; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Load template's source into current template object |
|
| 58 | + * |
|
| 59 | + * @param Smarty_Template_Source $source source object |
|
| 60 | + * |
|
| 61 | + * @return string template source |
|
| 62 | + * @throws SmartyException if source cannot be loaded |
|
| 63 | + */ |
|
| 64 | + abstract public function getContent(Smarty_Template_Source $source); |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * populate Source Object with meta data from Resource |
|
| 68 | + * |
|
| 69 | + * @param Smarty_Template_Source $source source object |
|
| 70 | + * @param Smarty_Internal_Template $_template template object |
|
| 71 | + */ |
|
| 72 | + abstract public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * populate Source Object with timestamp and exists from Resource |
|
| 76 | + * |
|
| 77 | + * @param Smarty_Template_Source $source source object |
|
| 78 | + */ |
|
| 79 | + public function populateTimestamp(Smarty_Template_Source $source) |
|
| 80 | + { |
|
| 81 | + // intentionally left blank |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * modify resource_name according to resource handlers specifications |
|
| 86 | + * |
|
| 87 | + * @param Smarty $smarty Smarty instance |
|
| 88 | + * @param string $resource_name resource_name to make unique |
|
| 89 | + * @param boolean $isConfig flag for config resource |
|
| 90 | + * |
|
| 91 | + * @return string unique resource name |
|
| 92 | + */ |
|
| 93 | + public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) |
|
| 94 | + { |
|
| 95 | + if ($isConfig) { |
|
| 96 | + if (!isset($smarty->_joined_config_dir)) { |
|
| 97 | + $smarty->getTemplateDir(null, true); |
|
| 98 | + } |
|
| 99 | + return get_class($this) . '#' . $smarty->_joined_config_dir . '#' . $resource_name; |
|
| 100 | + } else { |
|
| 101 | + if (!isset($smarty->_joined_template_dir)) { |
|
| 102 | + $smarty->getTemplateDir(); |
|
| 103 | + } |
|
| 104 | + return get_class($this) . '#' . $smarty->_joined_template_dir . '#' . $resource_name; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Determine basename for compiled filename |
|
| 110 | + * |
|
| 111 | + * @param Smarty_Template_Source $source source object |
|
| 112 | + * |
|
| 113 | + * @return string resource's basename |
|
| 114 | + */ |
|
| 115 | + public function getBasename(Smarty_Template_Source $source) |
|
| 116 | + { |
|
| 117 | + return basename(preg_replace('![^\w]+!', '_', $source->name)); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Load Resource Handler |
|
| 122 | + * |
|
| 123 | + * @param Smarty $smarty smarty object |
|
| 124 | + * @param string $type name of the resource |
|
| 125 | + * |
|
| 126 | + * @throws SmartyException |
|
| 127 | + * @return Smarty_Resource Resource Handler |
|
| 128 | + */ |
|
| 129 | + public static function load(Smarty $smarty, $type) |
|
| 130 | + { |
|
| 131 | + // try smarty's cache |
|
| 132 | + if (isset($smarty->_cache[ 'resource_handlers' ][ $type ])) { |
|
| 133 | + return $smarty->_cache[ 'resource_handlers' ][ $type ]; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // try registered resource |
|
| 137 | + if (isset($smarty->registered_resources[ $type ])) { |
|
| 138 | + return $smarty->_cache[ 'resource_handlers' ][ $type ] = |
|
| 139 | + $smarty->registered_resources[ $type ] instanceof Smarty_Resource ? |
|
| 140 | + $smarty->registered_resources[ $type ] : new Smarty_Internal_Resource_Registered(); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // try sysplugins dir |
|
| 144 | + if (isset(self::$sysplugins[ $type ])) { |
|
| 145 | + $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type); |
|
| 146 | + return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class(); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // try plugins dir |
|
| 150 | + $_resource_class = 'Smarty_Resource_' . ucfirst($type); |
|
| 151 | + if ($smarty->loadPlugin($_resource_class)) { |
|
| 152 | + if (class_exists($_resource_class, false)) { |
|
| 153 | + return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class(); |
|
| 154 | + } else { |
|
| 155 | + $smarty->registerResource($type, |
|
| 156 | + array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp", |
|
| 157 | + "smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted")); |
|
| 158 | + // give it another try, now that the resource is registered properly |
|
| 159 | + return self::load($smarty, $type); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // try streams |
|
| 164 | + $_known_stream = stream_get_wrappers(); |
|
| 165 | + if (in_array($type, $_known_stream)) { |
|
| 166 | + // is known stream |
|
| 167 | + if (is_object($smarty->security_policy)) { |
|
| 168 | + $smarty->security_policy->isTrustedStream($type); |
|
| 169 | + } |
|
| 170 | + return $smarty->_cache[ 'resource_handlers' ][ $type ] = new Smarty_Internal_Resource_Stream(); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + throw new SmartyException("Unknown resource type '{$type}'"); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * extract resource_type and resource_name from template_resource and config_resource |
|
| 178 | + * @note "C:/foo.tpl" was forced to file resource up till Smarty 3.1.3 (including). |
|
| 179 | + * |
|
| 180 | + * @param string $resource_name template_resource or config_resource to parse |
|
| 181 | + * @param string $default_resource the default resource_type defined in $smarty |
|
| 182 | + * |
|
| 183 | + * @return array with parsed resource name and type |
|
| 184 | + */ |
|
| 185 | + public static function parseResourceName($resource_name, $default_resource) |
|
| 186 | + { |
|
| 187 | + if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]/', $resource_name, $match)) { |
|
| 188 | + $type = $match[ 1 ]; |
|
| 189 | + $name = substr($resource_name, strlen($match[ 0 ])); |
|
| 190 | + } else { |
|
| 191 | + // no resource given, use default |
|
| 192 | + // or single character before the colon is not a resource type, but part of the filepath |
|
| 193 | + $type = $default_resource; |
|
| 194 | + $name = $resource_name; |
|
| 195 | + } |
|
| 196 | + return array($name, $type); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * modify template_resource according to resource handlers specifications |
|
| 201 | + * |
|
| 202 | + * @param \Smarty_Internal_Template|\Smarty $obj Smarty instance |
|
| 203 | + * @param string $template_resource template_resource to extract resource handler and name of |
|
| 204 | + * |
|
| 205 | + * @return string unique resource name |
|
| 206 | + */ |
|
| 207 | + public static function getUniqueTemplateName($obj, $template_resource) |
|
| 208 | + { |
|
| 209 | + $smarty = $obj->_objType == 2 ? $obj->smarty : $obj; |
|
| 210 | + list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type); |
|
| 211 | + $resource = Smarty_Resource::load($smarty, $type); |
|
| 212 | + // go relative to a given template? |
|
| 213 | + $_file_is_dotted = $name[ 0 ] == '.' && ($name[ 1 ] == '.' || $name[ 1 ] == '/'); |
|
| 214 | + if ($obj->_objType == 2 && $_file_is_dotted && |
|
| 215 | + ($obj->source->type == 'file' || $obj->parent->source->type == 'extends') |
|
| 216 | + ) { |
|
| 217 | + $name = $smarty->_realpath(dirname($obj->parent->source->filepath) . DS . $name); |
|
| 218 | + } |
|
| 219 | + return $resource->buildUniqueResourceName($smarty, $name); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /* |
|
| 223 | 223 | * Check if resource must check time stamps when when loading complied or cached templates. |
| 224 | 224 | * Resources like 'extends' which use source components my disable timestamp checks on own resource. |
| 225 | 225 | * |
| 226 | 226 | * @return bool |
| 227 | 227 | */ |
| 228 | - public function checkTimestamps() |
|
| 229 | - { |
|
| 230 | - return true; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * initialize Source Object for given resource |
|
| 235 | - * wrapper for backward compatibility to versions < 3.1.22 |
|
| 236 | - * Either [$_template] or [$smarty, $template_resource] must be specified |
|
| 237 | - * |
|
| 238 | - * @param Smarty_Internal_Template $_template template object |
|
| 239 | - * @param Smarty $smarty smarty object |
|
| 240 | - * @param string $template_resource resource identifier |
|
| 241 | - * |
|
| 242 | - * @return Smarty_Template_Source Source Object |
|
| 243 | - */ |
|
| 244 | - public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null, |
|
| 245 | - $template_resource = null) |
|
| 246 | - { |
|
| 247 | - return Smarty_Template_Source::load($_template, $smarty, $template_resource); |
|
| 248 | - } |
|
| 228 | + public function checkTimestamps() |
|
| 229 | + { |
|
| 230 | + return true; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * initialize Source Object for given resource |
|
| 235 | + * wrapper for backward compatibility to versions < 3.1.22 |
|
| 236 | + * Either [$_template] or [$smarty, $template_resource] must be specified |
|
| 237 | + * |
|
| 238 | + * @param Smarty_Internal_Template $_template template object |
|
| 239 | + * @param Smarty $smarty smarty object |
|
| 240 | + * @param string $template_resource resource identifier |
|
| 241 | + * |
|
| 242 | + * @return Smarty_Template_Source Source Object |
|
| 243 | + */ |
|
| 244 | + public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null, |
|
| 245 | + $template_resource = null) |
|
| 246 | + { |
|
| 247 | + return Smarty_Template_Source::load($_template, $smarty, $template_resource); |
|
| 248 | + } |
|
| 249 | 249 | } |
| 250 | 250 | |