@@ -26,35 +26,35 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | final class PluginTopLevelBlock extends BlockPlugin implements ICompilableBlock |
| 28 | 28 | { |
| 29 | - public function init() |
|
| 30 | - { |
|
| 31 | - } |
|
| 29 | + public function init() |
|
| 30 | + { |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param Compiler $compiler |
|
| 35 | - * @param array $params |
|
| 36 | - * @param string $prepend |
|
| 37 | - * @param string $append |
|
| 38 | - * @param string $type |
|
| 39 | - * |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 43 | - { |
|
| 44 | - return '/* end template head */ ob_start(); /* template body */ ' . Compiler::PHP_CLOSE; |
|
| 45 | - } |
|
| 33 | + /** |
|
| 34 | + * @param Compiler $compiler |
|
| 35 | + * @param array $params |
|
| 36 | + * @param string $prepend |
|
| 37 | + * @param string $append |
|
| 38 | + * @param string $type |
|
| 39 | + * |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 43 | + { |
|
| 44 | + return '/* end template head */ ob_start(); /* template body */ ' . Compiler::PHP_CLOSE; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param Compiler $compiler |
|
| 49 | - * @param array $params |
|
| 50 | - * @param string $prepend |
|
| 51 | - * @param string $append |
|
| 52 | - * @param string $content |
|
| 53 | - * |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 56 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 57 | - { |
|
| 58 | - return $content . Compiler::PHP_OPEN . ' /* end template body */' . "\n" . 'return $this->buffer . ob_get_clean();'; |
|
| 59 | - } |
|
| 47 | + /** |
|
| 48 | + * @param Compiler $compiler |
|
| 49 | + * @param array $params |
|
| 50 | + * @param string $prepend |
|
| 51 | + * @param string $append |
|
| 52 | + * @param string $content |
|
| 53 | + * |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 57 | + { |
|
| 58 | + return $content . Compiler::PHP_OPEN . ' /* end template body */' . "\n" . 'return $this->buffer . ob_get_clean();'; |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -30,161 +30,161 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class PluginHtmlFormat extends Filter |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * tab count to auto-indent the source. |
|
| 35 | - * |
|
| 36 | - * @var int |
|
| 37 | - */ |
|
| 38 | - protected static $tabCount = - 1; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * stores the additional data (following a tag) of the last call to open/close/singleTag. |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - protected static $lastCallAdd = ''; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * formats the input using the singleTag/closeTag/openTag functions. |
|
| 49 | - * It is auto indenting the whole code, excluding <textarea>, <code> and <pre> tags that must be kept intact. |
|
| 50 | - * Those tags must however contain only htmlentities-escaped text for everything to work properly. |
|
| 51 | - * Inline tags are presented on a single line with their content |
|
| 52 | - * |
|
| 53 | - * @param string $input the xhtml to format |
|
| 54 | - * |
|
| 55 | - * @return string formatted xhtml |
|
| 56 | - */ |
|
| 57 | - public function process($input) |
|
| 58 | - { |
|
| 59 | - self::$tabCount = - 1; |
|
| 60 | - |
|
| 61 | - // auto indent all but textareas & pre (or we have weird tabs inside) |
|
| 62 | - $input = preg_replace_callback("#(<[^>]+>)(\s*)([^<]*)#", array( |
|
| 63 | - 'self', |
|
| 64 | - 'tagDispatcher' |
|
| 65 | - ), $input); |
|
| 66 | - |
|
| 67 | - return $input; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * helper function for format()'s preg_replace call. |
|
| 72 | - * |
|
| 73 | - * @param array $input array of matches (1=>tag, 2=>whitespace(optional), 3=>additional non-html content) |
|
| 74 | - * |
|
| 75 | - * @return string the indented tag |
|
| 76 | - */ |
|
| 77 | - protected static function tagDispatcher($input) |
|
| 78 | - { |
|
| 79 | - // textarea, pre, code tags and comments are to be left alone to avoid any non-wanted whitespace inside them so it just outputs them as they were |
|
| 80 | - if (substr($input[1], 0, 9) == '<textarea' || substr($input[1], 0, 4) == '<pre' || substr($input[1], 0, 5) == '<code' || substr($input[1], 0, 4) == '<!--' || substr($input[1], 0, 9) == '<![CDATA[') { |
|
| 81 | - return $input[1] . $input[3]; |
|
| 82 | - } |
|
| 83 | - // closing textarea, code and pre tags and self-closed tags (i.e. <br />) are printed as singleTags because we didn't use openTag for the formers and the latter is a single tag |
|
| 84 | - if (substr($input[1], 0, 10) == '</textarea' || substr($input[1], 0, 5) == '</pre' || substr($input[1], 0, 6) == '</code' || substr($input[1], - 2) == '/>') { |
|
| 85 | - return self::singleTag($input[1], $input[3], $input[2]); |
|
| 86 | - } |
|
| 87 | - // it's the closing tag |
|
| 88 | - if ($input[0][1] == '/') { |
|
| 89 | - return self::closeTag($input[1], $input[3], $input[2]); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // opening tag |
|
| 93 | - return self::openTag($input[1], $input[3], $input[2]); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * returns an open tag and adds a tab into the auto indenting. |
|
| 98 | - * |
|
| 99 | - * @param string $tag content of the tag |
|
| 100 | - * @param string $add additional data (anything before the following tag) |
|
| 101 | - * @param string $whitespace white space between the tag and the additional data |
|
| 102 | - * |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - protected static function openTag($tag, $add, $whitespace) |
|
| 106 | - { |
|
| 107 | - $tabs = str_pad('', self::$tabCount ++, "\t"); |
|
| 108 | - |
|
| 109 | - if (preg_match('#^<(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)(?: [^>]*|)>#', $tag)) { |
|
| 110 | - // if it's one of those tag it's inline so it does not require a leading line break |
|
| 111 | - $result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add); |
|
| 112 | - } elseif (substr($tag, 0, 9) == '<!DOCTYPE') { |
|
| 113 | - // it's the doctype declaration so no line break here either |
|
| 114 | - $result = $tabs . $tag; |
|
| 115 | - } else { |
|
| 116 | - // normal block tag |
|
| 117 | - $result = "\n" . $tabs . $tag; |
|
| 118 | - |
|
| 119 | - if (!empty($add)) { |
|
| 120 | - $result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - self::$lastCallAdd = $add; |
|
| 125 | - |
|
| 126 | - return $result; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * returns a closing tag and removes a tab from the auto indenting. |
|
| 131 | - * |
|
| 132 | - * @param string $tag content of the tag |
|
| 133 | - * @param string $add additional data (anything before the following tag) |
|
| 134 | - * @param string $whitespace white space between the tag and the additional data |
|
| 135 | - * |
|
| 136 | - * @return string |
|
| 137 | - */ |
|
| 138 | - protected static function closeTag($tag, $add, $whitespace) |
|
| 139 | - { |
|
| 140 | - $tabs = str_pad('', -- self::$tabCount, "\t"); |
|
| 141 | - |
|
| 142 | - // if it's one of those tag it's inline so it does not require a leading line break |
|
| 143 | - if (preg_match('#^</(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)>#', $tag)) { |
|
| 144 | - $result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add); |
|
| 145 | - } else { |
|
| 146 | - $result = "\n" . $tabs . $tag; |
|
| 147 | - |
|
| 148 | - if (!empty($add)) { |
|
| 149 | - $result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - self::$lastCallAdd = $add; |
|
| 154 | - |
|
| 155 | - return $result; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * returns a single tag with auto indenting. |
|
| 160 | - * |
|
| 161 | - * @param string $tag content of the tag |
|
| 162 | - * @param string $add additional data (anything before the following tag) |
|
| 163 | - * |
|
| 164 | - * @return string |
|
| 165 | - */ |
|
| 166 | - protected static function singleTag($tag, $add, $whitespace) |
|
| 167 | - { |
|
| 168 | - $tabs = str_pad('', self::$tabCount, "\t"); |
|
| 169 | - |
|
| 170 | - // if it's img, br it's inline so it does not require a leading line break |
|
| 171 | - // if it's a closing textarea, code or pre tag, it does not require a leading line break either or it creates whitespace at the end of those blocks |
|
| 172 | - if (preg_match('#^<(img|br|/textarea|/pre|/code)(?: [^>]*|)>#', $tag)) { |
|
| 173 | - $result = $tag . $whitespace; |
|
| 174 | - |
|
| 175 | - if (!empty($add)) { |
|
| 176 | - $result .= str_replace("\n", "\n" . $tabs, $add); |
|
| 177 | - } |
|
| 178 | - } else { |
|
| 179 | - $result = "\n" . $tabs . $tag; |
|
| 180 | - |
|
| 181 | - if (!empty($add)) { |
|
| 182 | - $result .= "\n" . $tabs . str_replace("\n", "\n" . $tabs, $add); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - self::$lastCallAdd = $add; |
|
| 187 | - |
|
| 188 | - return $result; |
|
| 189 | - } |
|
| 33 | + /** |
|
| 34 | + * tab count to auto-indent the source. |
|
| 35 | + * |
|
| 36 | + * @var int |
|
| 37 | + */ |
|
| 38 | + protected static $tabCount = - 1; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * stores the additional data (following a tag) of the last call to open/close/singleTag. |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + protected static $lastCallAdd = ''; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * formats the input using the singleTag/closeTag/openTag functions. |
|
| 49 | + * It is auto indenting the whole code, excluding <textarea>, <code> and <pre> tags that must be kept intact. |
|
| 50 | + * Those tags must however contain only htmlentities-escaped text for everything to work properly. |
|
| 51 | + * Inline tags are presented on a single line with their content |
|
| 52 | + * |
|
| 53 | + * @param string $input the xhtml to format |
|
| 54 | + * |
|
| 55 | + * @return string formatted xhtml |
|
| 56 | + */ |
|
| 57 | + public function process($input) |
|
| 58 | + { |
|
| 59 | + self::$tabCount = - 1; |
|
| 60 | + |
|
| 61 | + // auto indent all but textareas & pre (or we have weird tabs inside) |
|
| 62 | + $input = preg_replace_callback("#(<[^>]+>)(\s*)([^<]*)#", array( |
|
| 63 | + 'self', |
|
| 64 | + 'tagDispatcher' |
|
| 65 | + ), $input); |
|
| 66 | + |
|
| 67 | + return $input; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * helper function for format()'s preg_replace call. |
|
| 72 | + * |
|
| 73 | + * @param array $input array of matches (1=>tag, 2=>whitespace(optional), 3=>additional non-html content) |
|
| 74 | + * |
|
| 75 | + * @return string the indented tag |
|
| 76 | + */ |
|
| 77 | + protected static function tagDispatcher($input) |
|
| 78 | + { |
|
| 79 | + // textarea, pre, code tags and comments are to be left alone to avoid any non-wanted whitespace inside them so it just outputs them as they were |
|
| 80 | + if (substr($input[1], 0, 9) == '<textarea' || substr($input[1], 0, 4) == '<pre' || substr($input[1], 0, 5) == '<code' || substr($input[1], 0, 4) == '<!--' || substr($input[1], 0, 9) == '<![CDATA[') { |
|
| 81 | + return $input[1] . $input[3]; |
|
| 82 | + } |
|
| 83 | + // closing textarea, code and pre tags and self-closed tags (i.e. <br />) are printed as singleTags because we didn't use openTag for the formers and the latter is a single tag |
|
| 84 | + if (substr($input[1], 0, 10) == '</textarea' || substr($input[1], 0, 5) == '</pre' || substr($input[1], 0, 6) == '</code' || substr($input[1], - 2) == '/>') { |
|
| 85 | + return self::singleTag($input[1], $input[3], $input[2]); |
|
| 86 | + } |
|
| 87 | + // it's the closing tag |
|
| 88 | + if ($input[0][1] == '/') { |
|
| 89 | + return self::closeTag($input[1], $input[3], $input[2]); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // opening tag |
|
| 93 | + return self::openTag($input[1], $input[3], $input[2]); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * returns an open tag and adds a tab into the auto indenting. |
|
| 98 | + * |
|
| 99 | + * @param string $tag content of the tag |
|
| 100 | + * @param string $add additional data (anything before the following tag) |
|
| 101 | + * @param string $whitespace white space between the tag and the additional data |
|
| 102 | + * |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + protected static function openTag($tag, $add, $whitespace) |
|
| 106 | + { |
|
| 107 | + $tabs = str_pad('', self::$tabCount ++, "\t"); |
|
| 108 | + |
|
| 109 | + if (preg_match('#^<(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)(?: [^>]*|)>#', $tag)) { |
|
| 110 | + // if it's one of those tag it's inline so it does not require a leading line break |
|
| 111 | + $result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add); |
|
| 112 | + } elseif (substr($tag, 0, 9) == '<!DOCTYPE') { |
|
| 113 | + // it's the doctype declaration so no line break here either |
|
| 114 | + $result = $tabs . $tag; |
|
| 115 | + } else { |
|
| 116 | + // normal block tag |
|
| 117 | + $result = "\n" . $tabs . $tag; |
|
| 118 | + |
|
| 119 | + if (!empty($add)) { |
|
| 120 | + $result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + self::$lastCallAdd = $add; |
|
| 125 | + |
|
| 126 | + return $result; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * returns a closing tag and removes a tab from the auto indenting. |
|
| 131 | + * |
|
| 132 | + * @param string $tag content of the tag |
|
| 133 | + * @param string $add additional data (anything before the following tag) |
|
| 134 | + * @param string $whitespace white space between the tag and the additional data |
|
| 135 | + * |
|
| 136 | + * @return string |
|
| 137 | + */ |
|
| 138 | + protected static function closeTag($tag, $add, $whitespace) |
|
| 139 | + { |
|
| 140 | + $tabs = str_pad('', -- self::$tabCount, "\t"); |
|
| 141 | + |
|
| 142 | + // if it's one of those tag it's inline so it does not require a leading line break |
|
| 143 | + if (preg_match('#^</(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)>#', $tag)) { |
|
| 144 | + $result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add); |
|
| 145 | + } else { |
|
| 146 | + $result = "\n" . $tabs . $tag; |
|
| 147 | + |
|
| 148 | + if (!empty($add)) { |
|
| 149 | + $result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + self::$lastCallAdd = $add; |
|
| 154 | + |
|
| 155 | + return $result; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * returns a single tag with auto indenting. |
|
| 160 | + * |
|
| 161 | + * @param string $tag content of the tag |
|
| 162 | + * @param string $add additional data (anything before the following tag) |
|
| 163 | + * |
|
| 164 | + * @return string |
|
| 165 | + */ |
|
| 166 | + protected static function singleTag($tag, $add, $whitespace) |
|
| 167 | + { |
|
| 168 | + $tabs = str_pad('', self::$tabCount, "\t"); |
|
| 169 | + |
|
| 170 | + // if it's img, br it's inline so it does not require a leading line break |
|
| 171 | + // if it's a closing textarea, code or pre tag, it does not require a leading line break either or it creates whitespace at the end of those blocks |
|
| 172 | + if (preg_match('#^<(img|br|/textarea|/pre|/code)(?: [^>]*|)>#', $tag)) { |
|
| 173 | + $result = $tag . $whitespace; |
|
| 174 | + |
|
| 175 | + if (!empty($add)) { |
|
| 176 | + $result .= str_replace("\n", "\n" . $tabs, $add); |
|
| 177 | + } |
|
| 178 | + } else { |
|
| 179 | + $result = "\n" . $tabs . $tag; |
|
| 180 | + |
|
| 181 | + if (!empty($add)) { |
|
| 182 | + $result .= "\n" . $tabs . str_replace("\n", "\n" . $tabs, $add); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + self::$lastCallAdd = $add; |
|
| 187 | + |
|
| 188 | + return $result; |
|
| 189 | + } |
|
| 190 | 190 | } |
@@ -25,298 +25,298 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class Policy |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * Php handling constants, defaults to PHP_REMOVE |
|
| 30 | - * PHP_ENCODE : run htmlentities over them |
|
| 31 | - * PHP_REMOVE : remove all <?php ?> (+ short tags if your short tags option is on) from the input template |
|
| 32 | - * PHP_ALLOW : leave them as they are |
|
| 33 | - * |
|
| 34 | - * @var int |
|
| 35 | - */ |
|
| 36 | - const PHP_ENCODE = 1; |
|
| 37 | - const PHP_REMOVE = 2; |
|
| 38 | - const PHP_ALLOW = 3; |
|
| 28 | + /** |
|
| 29 | + * Php handling constants, defaults to PHP_REMOVE |
|
| 30 | + * PHP_ENCODE : run htmlentities over them |
|
| 31 | + * PHP_REMOVE : remove all <?php ?> (+ short tags if your short tags option is on) from the input template |
|
| 32 | + * PHP_ALLOW : leave them as they are |
|
| 33 | + * |
|
| 34 | + * @var int |
|
| 35 | + */ |
|
| 36 | + const PHP_ENCODE = 1; |
|
| 37 | + const PHP_REMOVE = 2; |
|
| 38 | + const PHP_ALLOW = 3; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Constant handling constants, defaults to CONST_DISALLOW |
|
| 42 | - * CONST_DISALLOW : throw an error if {$dwoo.const.*} is used in the template |
|
| 43 | - * CONST_ALLOW : allow {$dwoo.const.*} calls |
|
| 44 | - */ |
|
| 45 | - const CONST_DISALLOW = false; |
|
| 46 | - const CONST_ALLOW = true; |
|
| 40 | + /** |
|
| 41 | + * Constant handling constants, defaults to CONST_DISALLOW |
|
| 42 | + * CONST_DISALLOW : throw an error if {$dwoo.const.*} is used in the template |
|
| 43 | + * CONST_ALLOW : allow {$dwoo.const.*} calls |
|
| 44 | + */ |
|
| 45 | + const CONST_DISALLOW = false; |
|
| 46 | + const CONST_ALLOW = true; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Php functions that are allowed to be used within the template. |
|
| 50 | - * |
|
| 51 | - * @var array |
|
| 52 | - */ |
|
| 53 | - protected $allowedPhpFunctions = array( |
|
| 54 | - 'str_repeat' => true, |
|
| 55 | - 'number_format' => true, |
|
| 56 | - 'htmlentities' => true, |
|
| 57 | - 'htmlspecialchars' => true, |
|
| 58 | - 'long2ip' => true, |
|
| 59 | - 'strlen' => true, |
|
| 60 | - 'list' => true, |
|
| 61 | - 'empty' => true, |
|
| 62 | - 'count' => true, |
|
| 63 | - 'sizeof' => true, |
|
| 64 | - 'in_array' => true, |
|
| 65 | - 'is_array' => true, |
|
| 66 | - ); |
|
| 48 | + /** |
|
| 49 | + * Php functions that are allowed to be used within the template. |
|
| 50 | + * |
|
| 51 | + * @var array |
|
| 52 | + */ |
|
| 53 | + protected $allowedPhpFunctions = array( |
|
| 54 | + 'str_repeat' => true, |
|
| 55 | + 'number_format' => true, |
|
| 56 | + 'htmlentities' => true, |
|
| 57 | + 'htmlspecialchars' => true, |
|
| 58 | + 'long2ip' => true, |
|
| 59 | + 'strlen' => true, |
|
| 60 | + 'list' => true, |
|
| 61 | + 'empty' => true, |
|
| 62 | + 'count' => true, |
|
| 63 | + 'sizeof' => true, |
|
| 64 | + 'in_array' => true, |
|
| 65 | + 'is_array' => true, |
|
| 66 | + ); |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Methods that are allowed to be used within the template. |
|
| 70 | - * |
|
| 71 | - * @var array |
|
| 72 | - */ |
|
| 73 | - protected $allowedMethods = array(); |
|
| 68 | + /** |
|
| 69 | + * Methods that are allowed to be used within the template. |
|
| 70 | + * |
|
| 71 | + * @var array |
|
| 72 | + */ |
|
| 73 | + protected $allowedMethods = array(); |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Paths that are safe to use with include or other file-access plugins. |
|
| 77 | - * |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 80 | - protected $allowedDirectories = array(); |
|
| 75 | + /** |
|
| 76 | + * Paths that are safe to use with include or other file-access plugins. |
|
| 77 | + * |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | + protected $allowedDirectories = array(); |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Stores the php handling level. |
|
| 84 | - * defaults to self::PHP_REMOVE |
|
| 85 | - * |
|
| 86 | - * @var int |
|
| 87 | - */ |
|
| 88 | - protected $phpHandling = self::PHP_REMOVE; |
|
| 82 | + /** |
|
| 83 | + * Stores the php handling level. |
|
| 84 | + * defaults to self::PHP_REMOVE |
|
| 85 | + * |
|
| 86 | + * @var int |
|
| 87 | + */ |
|
| 88 | + protected $phpHandling = self::PHP_REMOVE; |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Stores the constant handling level. |
|
| 92 | - * defaults to self::CONST_DISALLOW |
|
| 93 | - * |
|
| 94 | - * @var bool |
|
| 95 | - */ |
|
| 96 | - protected $constHandling = self::CONST_DISALLOW; |
|
| 90 | + /** |
|
| 91 | + * Stores the constant handling level. |
|
| 92 | + * defaults to self::CONST_DISALLOW |
|
| 93 | + * |
|
| 94 | + * @var bool |
|
| 95 | + */ |
|
| 96 | + protected $constHandling = self::CONST_DISALLOW; |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Adds a php function to the allowed list. |
|
| 100 | - * |
|
| 101 | - * @param mixed $func function name or array of function names |
|
| 102 | - */ |
|
| 103 | - public function allowPhpFunction($func) |
|
| 104 | - { |
|
| 105 | - if (is_array($func)) { |
|
| 106 | - foreach ($func as $fname) { |
|
| 107 | - $this->allowedPhpFunctions[strtolower($fname)] = true; |
|
| 108 | - } |
|
| 109 | - } else { |
|
| 110 | - $this->allowedPhpFunctions[strtolower($func)] = true; |
|
| 111 | - } |
|
| 112 | - } |
|
| 98 | + /** |
|
| 99 | + * Adds a php function to the allowed list. |
|
| 100 | + * |
|
| 101 | + * @param mixed $func function name or array of function names |
|
| 102 | + */ |
|
| 103 | + public function allowPhpFunction($func) |
|
| 104 | + { |
|
| 105 | + if (is_array($func)) { |
|
| 106 | + foreach ($func as $fname) { |
|
| 107 | + $this->allowedPhpFunctions[strtolower($fname)] = true; |
|
| 108 | + } |
|
| 109 | + } else { |
|
| 110 | + $this->allowedPhpFunctions[strtolower($func)] = true; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Removes a php function from the allowed list. |
|
| 116 | - * |
|
| 117 | - * @param mixed $func function name or array of function names |
|
| 118 | - */ |
|
| 119 | - public function disallowPhpFunction($func) |
|
| 120 | - { |
|
| 121 | - if (is_array($func)) { |
|
| 122 | - foreach ($func as $fname) { |
|
| 123 | - unset($this->allowedPhpFunctions[strtolower($fname)]); |
|
| 124 | - } |
|
| 125 | - } else { |
|
| 126 | - unset($this->allowedPhpFunctions[strtolower($func)]); |
|
| 127 | - } |
|
| 128 | - } |
|
| 114 | + /** |
|
| 115 | + * Removes a php function from the allowed list. |
|
| 116 | + * |
|
| 117 | + * @param mixed $func function name or array of function names |
|
| 118 | + */ |
|
| 119 | + public function disallowPhpFunction($func) |
|
| 120 | + { |
|
| 121 | + if (is_array($func)) { |
|
| 122 | + foreach ($func as $fname) { |
|
| 123 | + unset($this->allowedPhpFunctions[strtolower($fname)]); |
|
| 124 | + } |
|
| 125 | + } else { |
|
| 126 | + unset($this->allowedPhpFunctions[strtolower($func)]); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Returns the list of php functions allowed to run, note that the function names |
|
| 132 | - * are stored in the array keys and not values. |
|
| 133 | - * |
|
| 134 | - * @return array |
|
| 135 | - */ |
|
| 136 | - public function getAllowedPhpFunctions() |
|
| 137 | - { |
|
| 138 | - return $this->allowedPhpFunctions; |
|
| 139 | - } |
|
| 130 | + /** |
|
| 131 | + * Returns the list of php functions allowed to run, note that the function names |
|
| 132 | + * are stored in the array keys and not values. |
|
| 133 | + * |
|
| 134 | + * @return array |
|
| 135 | + */ |
|
| 136 | + public function getAllowedPhpFunctions() |
|
| 137 | + { |
|
| 138 | + return $this->allowedPhpFunctions; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Adds a class method to the allowed list, this must be used for |
|
| 143 | - * both static and non static method by providing the class name |
|
| 144 | - * and method name to use. |
|
| 145 | - * |
|
| 146 | - * @param mixed $class class name or array of array('class', 'method') couples |
|
| 147 | - * @param string $method method name |
|
| 148 | - */ |
|
| 149 | - public function allowMethod($class, $method = null) |
|
| 150 | - { |
|
| 151 | - if (is_array($class)) { |
|
| 152 | - foreach ($class as $elem) { |
|
| 153 | - $this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])] = true; |
|
| 154 | - } |
|
| 155 | - } else { |
|
| 156 | - $this->allowedMethods[strtolower($class)][strtolower($method)] = true; |
|
| 157 | - } |
|
| 158 | - } |
|
| 141 | + /** |
|
| 142 | + * Adds a class method to the allowed list, this must be used for |
|
| 143 | + * both static and non static method by providing the class name |
|
| 144 | + * and method name to use. |
|
| 145 | + * |
|
| 146 | + * @param mixed $class class name or array of array('class', 'method') couples |
|
| 147 | + * @param string $method method name |
|
| 148 | + */ |
|
| 149 | + public function allowMethod($class, $method = null) |
|
| 150 | + { |
|
| 151 | + if (is_array($class)) { |
|
| 152 | + foreach ($class as $elem) { |
|
| 153 | + $this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])] = true; |
|
| 154 | + } |
|
| 155 | + } else { |
|
| 156 | + $this->allowedMethods[strtolower($class)][strtolower($method)] = true; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * Removes a class method from the allowed list. |
|
| 162 | - * |
|
| 163 | - * @param mixed $class class name or array of array('class', 'method') couples |
|
| 164 | - * @param string $method method name |
|
| 165 | - */ |
|
| 166 | - public function disallowMethod($class, $method = null) |
|
| 167 | - { |
|
| 168 | - if (is_array($class)) { |
|
| 169 | - foreach ($class as $elem) { |
|
| 170 | - unset($this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])]); |
|
| 171 | - } |
|
| 172 | - } else { |
|
| 173 | - unset($this->allowedMethods[strtolower($class)][strtolower($method)]); |
|
| 174 | - } |
|
| 175 | - } |
|
| 160 | + /** |
|
| 161 | + * Removes a class method from the allowed list. |
|
| 162 | + * |
|
| 163 | + * @param mixed $class class name or array of array('class', 'method') couples |
|
| 164 | + * @param string $method method name |
|
| 165 | + */ |
|
| 166 | + public function disallowMethod($class, $method = null) |
|
| 167 | + { |
|
| 168 | + if (is_array($class)) { |
|
| 169 | + foreach ($class as $elem) { |
|
| 170 | + unset($this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])]); |
|
| 171 | + } |
|
| 172 | + } else { |
|
| 173 | + unset($this->allowedMethods[strtolower($class)][strtolower($method)]); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Returns the list of class methods allowed to run, note that the class names |
|
| 179 | - * and method names are stored in the array keys and not values. |
|
| 180 | - * |
|
| 181 | - * @return array |
|
| 182 | - */ |
|
| 183 | - public function getAllowedMethods() |
|
| 184 | - { |
|
| 185 | - return $this->allowedMethods; |
|
| 186 | - } |
|
| 177 | + /** |
|
| 178 | + * Returns the list of class methods allowed to run, note that the class names |
|
| 179 | + * and method names are stored in the array keys and not values. |
|
| 180 | + * |
|
| 181 | + * @return array |
|
| 182 | + */ |
|
| 183 | + public function getAllowedMethods() |
|
| 184 | + { |
|
| 185 | + return $this->allowedMethods; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Adds a directory to the safelist for includes and other file-access plugins. |
|
| 190 | - * note that all the includePath directories you provide to the Dwoo_Template_File class |
|
| 191 | - * are automatically marked as safe |
|
| 192 | - * |
|
| 193 | - * @param mixed $path a path name or an array of paths |
|
| 194 | - */ |
|
| 195 | - public function allowDirectory($path) |
|
| 196 | - { |
|
| 197 | - if (is_array($path)) { |
|
| 198 | - foreach ($path as $dir) { |
|
| 199 | - $this->allowedDirectories[realpath($dir)] = true; |
|
| 200 | - } |
|
| 201 | - } else { |
|
| 202 | - $this->allowedDirectories[realpath($path)] = true; |
|
| 203 | - } |
|
| 204 | - } |
|
| 188 | + /** |
|
| 189 | + * Adds a directory to the safelist for includes and other file-access plugins. |
|
| 190 | + * note that all the includePath directories you provide to the Dwoo_Template_File class |
|
| 191 | + * are automatically marked as safe |
|
| 192 | + * |
|
| 193 | + * @param mixed $path a path name or an array of paths |
|
| 194 | + */ |
|
| 195 | + public function allowDirectory($path) |
|
| 196 | + { |
|
| 197 | + if (is_array($path)) { |
|
| 198 | + foreach ($path as $dir) { |
|
| 199 | + $this->allowedDirectories[realpath($dir)] = true; |
|
| 200 | + } |
|
| 201 | + } else { |
|
| 202 | + $this->allowedDirectories[realpath($path)] = true; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * Removes a directory from the safe list. |
|
| 208 | - * |
|
| 209 | - * @param mixed $path a path name or an array of paths |
|
| 210 | - */ |
|
| 211 | - public function disallowDirectory($path) |
|
| 212 | - { |
|
| 213 | - if (is_array($path)) { |
|
| 214 | - foreach ($path as $dir) { |
|
| 215 | - unset($this->allowedDirectories[realpath($dir)]); |
|
| 216 | - } |
|
| 217 | - } else { |
|
| 218 | - unset($this->allowedDirectories[realpath($path)]); |
|
| 219 | - } |
|
| 220 | - } |
|
| 206 | + /** |
|
| 207 | + * Removes a directory from the safe list. |
|
| 208 | + * |
|
| 209 | + * @param mixed $path a path name or an array of paths |
|
| 210 | + */ |
|
| 211 | + public function disallowDirectory($path) |
|
| 212 | + { |
|
| 213 | + if (is_array($path)) { |
|
| 214 | + foreach ($path as $dir) { |
|
| 215 | + unset($this->allowedDirectories[realpath($dir)]); |
|
| 216 | + } |
|
| 217 | + } else { |
|
| 218 | + unset($this->allowedDirectories[realpath($path)]); |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * Returns the list of safe paths, note that the paths are stored in the array |
|
| 224 | - * keys and not values. |
|
| 225 | - * |
|
| 226 | - * @return array |
|
| 227 | - */ |
|
| 228 | - public function getAllowedDirectories() |
|
| 229 | - { |
|
| 230 | - return $this->allowedDirectories; |
|
| 231 | - } |
|
| 222 | + /** |
|
| 223 | + * Returns the list of safe paths, note that the paths are stored in the array |
|
| 224 | + * keys and not values. |
|
| 225 | + * |
|
| 226 | + * @return array |
|
| 227 | + */ |
|
| 228 | + public function getAllowedDirectories() |
|
| 229 | + { |
|
| 230 | + return $this->allowedDirectories; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * Sets the php handling level, defaults to REMOVE. |
|
| 235 | - * |
|
| 236 | - * @param int $level one of the Dwoo_Security_Policy::PHP_* constants |
|
| 237 | - */ |
|
| 238 | - public function setPhpHandling($level = self::PHP_REMOVE) |
|
| 239 | - { |
|
| 240 | - $this->phpHandling = $level; |
|
| 241 | - } |
|
| 233 | + /** |
|
| 234 | + * Sets the php handling level, defaults to REMOVE. |
|
| 235 | + * |
|
| 236 | + * @param int $level one of the Dwoo_Security_Policy::PHP_* constants |
|
| 237 | + */ |
|
| 238 | + public function setPhpHandling($level = self::PHP_REMOVE) |
|
| 239 | + { |
|
| 240 | + $this->phpHandling = $level; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * Returns the php handling level. |
|
| 245 | - * |
|
| 246 | - * @return int the current level, one of the Dwoo_Security_Policy::PHP_* constants |
|
| 247 | - */ |
|
| 248 | - public function getPhpHandling() |
|
| 249 | - { |
|
| 250 | - return $this->phpHandling; |
|
| 251 | - } |
|
| 243 | + /** |
|
| 244 | + * Returns the php handling level. |
|
| 245 | + * |
|
| 246 | + * @return int the current level, one of the Dwoo_Security_Policy::PHP_* constants |
|
| 247 | + */ |
|
| 248 | + public function getPhpHandling() |
|
| 249 | + { |
|
| 250 | + return $this->phpHandling; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Sets the constant handling level, defaults to CONST_DISALLOW. |
|
| 255 | - * |
|
| 256 | - * @param bool $level one of the Dwoo_Security_Policy::CONST_* constants |
|
| 257 | - */ |
|
| 258 | - public function setConstantHandling($level = self::CONST_DISALLOW) |
|
| 259 | - { |
|
| 260 | - $this->constHandling = $level; |
|
| 261 | - } |
|
| 253 | + /** |
|
| 254 | + * Sets the constant handling level, defaults to CONST_DISALLOW. |
|
| 255 | + * |
|
| 256 | + * @param bool $level one of the Dwoo_Security_Policy::CONST_* constants |
|
| 257 | + */ |
|
| 258 | + public function setConstantHandling($level = self::CONST_DISALLOW) |
|
| 259 | + { |
|
| 260 | + $this->constHandling = $level; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Returns the constant handling level. |
|
| 265 | - * |
|
| 266 | - * @return bool the current level, one of the Dwoo_Security_Policy::CONST_* constants |
|
| 267 | - */ |
|
| 268 | - public function getConstantHandling() |
|
| 269 | - { |
|
| 270 | - return $this->constHandling; |
|
| 271 | - } |
|
| 263 | + /** |
|
| 264 | + * Returns the constant handling level. |
|
| 265 | + * |
|
| 266 | + * @return bool the current level, one of the Dwoo_Security_Policy::CONST_* constants |
|
| 267 | + */ |
|
| 268 | + public function getConstantHandling() |
|
| 269 | + { |
|
| 270 | + return $this->constHandling; |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * This is used at run time to check whether method calls are allowed or not. |
|
| 275 | - * |
|
| 276 | - * @param Core $dwoo dwoo instance that calls this |
|
| 277 | - * @param object $obj any object on which the method must be called |
|
| 278 | - * @param string $method lowercased method name |
|
| 279 | - * @param array $args arguments array |
|
| 280 | - * |
|
| 281 | - * @return mixed result of method call or unll + E_USER_NOTICE if not allowed |
|
| 282 | - */ |
|
| 283 | - public function callMethod(Core $dwoo, $obj, $method, $args) |
|
| 284 | - { |
|
| 285 | - foreach ($this->allowedMethods as $class => $methods) { |
|
| 286 | - if (!isset($methods[$method])) { |
|
| 287 | - continue; |
|
| 288 | - } |
|
| 289 | - if ($obj instanceof $class) { |
|
| 290 | - return call_user_func_array(array($obj, $method), $args); |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - $dwoo->triggerError('The current security policy prevents you from calling ' . get_class($obj) . '::' . $method . '()'); |
|
| 273 | + /** |
|
| 274 | + * This is used at run time to check whether method calls are allowed or not. |
|
| 275 | + * |
|
| 276 | + * @param Core $dwoo dwoo instance that calls this |
|
| 277 | + * @param object $obj any object on which the method must be called |
|
| 278 | + * @param string $method lowercased method name |
|
| 279 | + * @param array $args arguments array |
|
| 280 | + * |
|
| 281 | + * @return mixed result of method call or unll + E_USER_NOTICE if not allowed |
|
| 282 | + */ |
|
| 283 | + public function callMethod(Core $dwoo, $obj, $method, $args) |
|
| 284 | + { |
|
| 285 | + foreach ($this->allowedMethods as $class => $methods) { |
|
| 286 | + if (!isset($methods[$method])) { |
|
| 287 | + continue; |
|
| 288 | + } |
|
| 289 | + if ($obj instanceof $class) { |
|
| 290 | + return call_user_func_array(array($obj, $method), $args); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + $dwoo->triggerError('The current security policy prevents you from calling ' . get_class($obj) . '::' . $method . '()'); |
|
| 294 | 294 | |
| 295 | - return null; |
|
| 296 | - } |
|
| 295 | + return null; |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * This is used at compile time to check whether static method calls are allowed or not. |
|
| 300 | - * |
|
| 301 | - * @param mixed $class lowercased class name or array('class', 'method') couple |
|
| 302 | - * @param string $method lowercased method name |
|
| 303 | - * |
|
| 304 | - * @return bool |
|
| 305 | - */ |
|
| 306 | - public function isMethodAllowed($class, $method = null) |
|
| 307 | - { |
|
| 308 | - if (is_array($class)) { |
|
| 309 | - list($class, $method) = $class; |
|
| 310 | - } |
|
| 311 | - foreach ($this->allowedMethods as $allowedClass => $methods) { |
|
| 312 | - if (!isset($methods[$method])) { |
|
| 313 | - continue; |
|
| 314 | - } |
|
| 315 | - if ($class === $allowedClass || is_subclass_of($class, $allowedClass)) { |
|
| 316 | - return true; |
|
| 317 | - } |
|
| 318 | - } |
|
| 298 | + /** |
|
| 299 | + * This is used at compile time to check whether static method calls are allowed or not. |
|
| 300 | + * |
|
| 301 | + * @param mixed $class lowercased class name or array('class', 'method') couple |
|
| 302 | + * @param string $method lowercased method name |
|
| 303 | + * |
|
| 304 | + * @return bool |
|
| 305 | + */ |
|
| 306 | + public function isMethodAllowed($class, $method = null) |
|
| 307 | + { |
|
| 308 | + if (is_array($class)) { |
|
| 309 | + list($class, $method) = $class; |
|
| 310 | + } |
|
| 311 | + foreach ($this->allowedMethods as $allowedClass => $methods) { |
|
| 312 | + if (!isset($methods[$method])) { |
|
| 313 | + continue; |
|
| 314 | + } |
|
| 315 | + if ($class === $allowedClass || is_subclass_of($class, $allowedClass)) { |
|
| 316 | + return true; |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - return false; |
|
| 321 | - } |
|
| 320 | + return false; |
|
| 321 | + } |
|
| 322 | 322 | } |
@@ -30,14 +30,14 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class PluginIsset extends Plugin implements ICompilable |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * @param Compiler $compiler |
|
| 35 | - * @param mixed $var |
|
| 36 | - * |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - public static function compile(Compiler $compiler, $var) |
|
| 40 | - { |
|
| 41 | - return '(' . $var . ' !== null)'; |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * @param Compiler $compiler |
|
| 35 | + * @param mixed $var |
|
| 36 | + * |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + public static function compile(Compiler $compiler, $var) |
|
| 40 | + { |
|
| 41 | + return '(' . $var . ' !== null)'; |
|
| 42 | + } |
|
| 43 | 43 | } |
| 44 | 44 | \ No newline at end of file |
@@ -31,62 +31,62 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class PluginDateFormat extends Plugin |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * @param mixed $value |
|
| 36 | - * @param string $format |
|
| 37 | - * @param null $default |
|
| 38 | - * |
|
| 39 | - * @return string |
|
| 40 | - */ |
|
| 41 | - public function process($value, $format = '%b %e, %Y', $default = null) |
|
| 42 | - { |
|
| 43 | - if (!empty($value)) { |
|
| 44 | - // convert if it's not a valid unix timestamp |
|
| 45 | - if (preg_match('#^-?\d{1,10}$#', $value) === 0) { |
|
| 46 | - $value = strtotime($value); |
|
| 47 | - } |
|
| 48 | - } elseif (!empty($default)) { |
|
| 49 | - // convert if it's not a valid unix timestamp |
|
| 50 | - if (preg_match('#^-?\d{1,10}$#', $default) === 0) { |
|
| 51 | - $value = strtotime($default); |
|
| 52 | - } else { |
|
| 53 | - $value = $default; |
|
| 54 | - } |
|
| 55 | - } else { |
|
| 56 | - return ''; |
|
| 57 | - } |
|
| 34 | + /** |
|
| 35 | + * @param mixed $value |
|
| 36 | + * @param string $format |
|
| 37 | + * @param null $default |
|
| 38 | + * |
|
| 39 | + * @return string |
|
| 40 | + */ |
|
| 41 | + public function process($value, $format = '%b %e, %Y', $default = null) |
|
| 42 | + { |
|
| 43 | + if (!empty($value)) { |
|
| 44 | + // convert if it's not a valid unix timestamp |
|
| 45 | + if (preg_match('#^-?\d{1,10}$#', $value) === 0) { |
|
| 46 | + $value = strtotime($value); |
|
| 47 | + } |
|
| 48 | + } elseif (!empty($default)) { |
|
| 49 | + // convert if it's not a valid unix timestamp |
|
| 50 | + if (preg_match('#^-?\d{1,10}$#', $default) === 0) { |
|
| 51 | + $value = strtotime($default); |
|
| 52 | + } else { |
|
| 53 | + $value = $default; |
|
| 54 | + } |
|
| 55 | + } else { |
|
| 56 | + return ''; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - // Credits for that windows compat block to Monte Ohrt who made smarty's date_format plugin |
|
| 60 | - if (DIRECTORY_SEPARATOR == '\\') { |
|
| 61 | - $_win_from = array( |
|
| 62 | - '%D', |
|
| 63 | - '%h', |
|
| 64 | - '%n', |
|
| 65 | - '%r', |
|
| 66 | - '%R', |
|
| 67 | - '%t', |
|
| 68 | - '%T' |
|
| 69 | - ); |
|
| 70 | - $_win_to = array( |
|
| 71 | - '%m/%d/%y', |
|
| 72 | - '%b', |
|
| 73 | - "\n", |
|
| 74 | - '%I:%M:%S %p', |
|
| 75 | - '%H:%M', |
|
| 76 | - "\t", |
|
| 77 | - '%H:%M:%S' |
|
| 78 | - ); |
|
| 79 | - if (strpos($format, '%e') !== false) { |
|
| 80 | - $_win_from[] = '%e'; |
|
| 81 | - $_win_to[] = sprintf('%\' 2d', date('j', $value)); |
|
| 82 | - } |
|
| 83 | - if (strpos($format, '%l') !== false) { |
|
| 84 | - $_win_from[] = '%l'; |
|
| 85 | - $_win_to[] = sprintf('%\' 2d', date('h', $value)); |
|
| 86 | - } |
|
| 87 | - $format = str_replace($_win_from, $_win_to, $format); |
|
| 88 | - } |
|
| 59 | + // Credits for that windows compat block to Monte Ohrt who made smarty's date_format plugin |
|
| 60 | + if (DIRECTORY_SEPARATOR == '\\') { |
|
| 61 | + $_win_from = array( |
|
| 62 | + '%D', |
|
| 63 | + '%h', |
|
| 64 | + '%n', |
|
| 65 | + '%r', |
|
| 66 | + '%R', |
|
| 67 | + '%t', |
|
| 68 | + '%T' |
|
| 69 | + ); |
|
| 70 | + $_win_to = array( |
|
| 71 | + '%m/%d/%y', |
|
| 72 | + '%b', |
|
| 73 | + "\n", |
|
| 74 | + '%I:%M:%S %p', |
|
| 75 | + '%H:%M', |
|
| 76 | + "\t", |
|
| 77 | + '%H:%M:%S' |
|
| 78 | + ); |
|
| 79 | + if (strpos($format, '%e') !== false) { |
|
| 80 | + $_win_from[] = '%e'; |
|
| 81 | + $_win_to[] = sprintf('%\' 2d', date('j', $value)); |
|
| 82 | + } |
|
| 83 | + if (strpos($format, '%l') !== false) { |
|
| 84 | + $_win_from[] = '%l'; |
|
| 85 | + $_win_to[] = sprintf('%\' 2d', date('h', $value)); |
|
| 86 | + } |
|
| 87 | + $format = str_replace($_win_from, $_win_to, $format); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - return strftime($format, $value); |
|
| 91 | - } |
|
| 90 | + return strftime($format, $value); |
|
| 91 | + } |
|
| 92 | 92 | } |
| 93 | 93 | \ No newline at end of file |
@@ -36,19 +36,19 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class PluginReturn extends Plugin implements ICompilable |
| 38 | 38 | { |
| 39 | - /** |
|
| 40 | - * @param Compiler $compiler |
|
| 41 | - * @param array $rest |
|
| 42 | - * |
|
| 43 | - * @return string |
|
| 44 | - */ |
|
| 45 | - public static function compile(Compiler $compiler, array $rest = array()) |
|
| 46 | - { |
|
| 47 | - $out = array(); |
|
| 48 | - foreach ($rest as $var => $val) { |
|
| 49 | - $out[] = '$this->setReturnValue(' . var_export($var, true) . ', ' . $val . ')'; |
|
| 50 | - } |
|
| 39 | + /** |
|
| 40 | + * @param Compiler $compiler |
|
| 41 | + * @param array $rest |
|
| 42 | + * |
|
| 43 | + * @return string |
|
| 44 | + */ |
|
| 45 | + public static function compile(Compiler $compiler, array $rest = array()) |
|
| 46 | + { |
|
| 47 | + $out = array(); |
|
| 48 | + foreach ($rest as $var => $val) { |
|
| 49 | + $out[] = '$this->setReturnValue(' . var_export($var, true) . ', ' . $val . ')'; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - return '(' . implode('.', $out) . ')'; |
|
| 53 | - } |
|
| 52 | + return '(' . implode('.', $out) . ')'; |
|
| 53 | + } |
|
| 54 | 54 | } |
| 55 | 55 | \ No newline at end of file |
@@ -39,15 +39,15 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class PluginWhitespace extends Plugin implements ICompilable |
| 41 | 41 | { |
| 42 | - /** |
|
| 43 | - * @param Compiler $compiler |
|
| 44 | - * @param string $value |
|
| 45 | - * @param string $with |
|
| 46 | - * |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public static function compile(Compiler $compiler, $value, $with = ' ') |
|
| 50 | - { |
|
| 51 | - return "preg_replace('#\s+#'.(strcasecmp(\$this->charset, 'utf-8')===0?'u':''), $with, $value)"; |
|
| 52 | - } |
|
| 42 | + /** |
|
| 43 | + * @param Compiler $compiler |
|
| 44 | + * @param string $value |
|
| 45 | + * @param string $with |
|
| 46 | + * |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public static function compile(Compiler $compiler, $value, $with = ' ') |
|
| 50 | + { |
|
| 51 | + return "preg_replace('#\s+#'.(strcasecmp(\$this->charset, 'utf-8')===0?'u':''), $with, $value)"; |
|
| 52 | + } |
|
| 53 | 53 | } |
| 54 | 54 | \ No newline at end of file |
@@ -30,8 +30,8 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class PluginCountWords extends Plugin implements ICompilable |
| 32 | 32 | { |
| 33 | - public static function compile(Compiler $compiler, $value) |
|
| 34 | - { |
|
| 35 | - return 'preg_match_all(strcasecmp($this->charset, \'utf-8\')===0 ? \'#[\w\pL]+#u\' : \'#\w+#\', ' . $value . ', $tmp)'; |
|
| 36 | - } |
|
| 33 | + public static function compile(Compiler $compiler, $value) |
|
| 34 | + { |
|
| 35 | + return 'preg_match_all(strcasecmp($this->charset, \'utf-8\')===0 ? \'#[\w\pL]+#u\' : \'#\w+#\', ' . $value . ', $tmp)'; |
|
| 36 | + } |
|
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -29,26 +29,26 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class PluginReverse extends Plugin |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * @param string $value |
|
| 34 | - * @param bool $preserve_keys |
|
| 35 | - * |
|
| 36 | - * @return array|string |
|
| 37 | - */ |
|
| 38 | - public function process($value, $preserve_keys = false) |
|
| 39 | - { |
|
| 40 | - if (is_array($value)) { |
|
| 41 | - return array_reverse($value, $preserve_keys); |
|
| 42 | - } elseif (($charset = $this->core->getCharset()) === 'iso-8859-1') { |
|
| 43 | - return strrev((string)$value); |
|
| 44 | - } |
|
| 32 | + /** |
|
| 33 | + * @param string $value |
|
| 34 | + * @param bool $preserve_keys |
|
| 35 | + * |
|
| 36 | + * @return array|string |
|
| 37 | + */ |
|
| 38 | + public function process($value, $preserve_keys = false) |
|
| 39 | + { |
|
| 40 | + if (is_array($value)) { |
|
| 41 | + return array_reverse($value, $preserve_keys); |
|
| 42 | + } elseif (($charset = $this->core->getCharset()) === 'iso-8859-1') { |
|
| 43 | + return strrev((string)$value); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - $strlen = mb_strlen($value); |
|
| 47 | - $out = ''; |
|
| 48 | - while ($strlen --) { |
|
| 49 | - $out .= mb_substr($value, $strlen, 1, $charset); |
|
| 50 | - } |
|
| 46 | + $strlen = mb_strlen($value); |
|
| 47 | + $out = ''; |
|
| 48 | + while ($strlen --) { |
|
| 49 | + $out .= mb_substr($value, $strlen, 1, $charset); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - return $out; |
|
| 53 | - } |
|
| 52 | + return $out; |
|
| 53 | + } |
|
| 54 | 54 | } |
| 55 | 55 | \ No newline at end of file |