@@ -34,61 +34,61 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class PluginCounter extends Plugin |
| 36 | 36 | { |
| 37 | - protected $counters = array(); |
|
| 37 | + protected $counters = array(); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param string $name |
|
| 41 | - * @param null $start |
|
| 42 | - * @param null $skip |
|
| 43 | - * @param null $direction |
|
| 44 | - * @param null $print |
|
| 45 | - * @param null $assign |
|
| 46 | - * |
|
| 47 | - * @return mixed |
|
| 48 | - */ |
|
| 49 | - public function process($name = 'default', $start = null, $skip = null, $direction = null, $print = null, $assign = null) |
|
| 50 | - { |
|
| 51 | - // init counter |
|
| 52 | - if (!isset($this->counters[$name])) { |
|
| 53 | - $this->counters[$name] = array( |
|
| 54 | - 'count' => $start === null ? 1 : (int)$start, |
|
| 55 | - 'skip' => $skip === null ? 1 : (int)$skip, |
|
| 56 | - 'print' => $print === null ? true : (bool)$print, |
|
| 57 | - 'assign' => $assign === null ? null : (string)$assign, |
|
| 58 | - 'direction' => strtolower($direction) === 'down' ? - 1 : 1, |
|
| 59 | - ); |
|
| 60 | - } // increment |
|
| 61 | - else { |
|
| 62 | - // override setting if present |
|
| 63 | - if ($skip !== null) { |
|
| 64 | - $this->counters[$name]['skip'] = (int)$skip; |
|
| 65 | - } |
|
| 39 | + /** |
|
| 40 | + * @param string $name |
|
| 41 | + * @param null $start |
|
| 42 | + * @param null $skip |
|
| 43 | + * @param null $direction |
|
| 44 | + * @param null $print |
|
| 45 | + * @param null $assign |
|
| 46 | + * |
|
| 47 | + * @return mixed |
|
| 48 | + */ |
|
| 49 | + public function process($name = 'default', $start = null, $skip = null, $direction = null, $print = null, $assign = null) |
|
| 50 | + { |
|
| 51 | + // init counter |
|
| 52 | + if (!isset($this->counters[$name])) { |
|
| 53 | + $this->counters[$name] = array( |
|
| 54 | + 'count' => $start === null ? 1 : (int)$start, |
|
| 55 | + 'skip' => $skip === null ? 1 : (int)$skip, |
|
| 56 | + 'print' => $print === null ? true : (bool)$print, |
|
| 57 | + 'assign' => $assign === null ? null : (string)$assign, |
|
| 58 | + 'direction' => strtolower($direction) === 'down' ? - 1 : 1, |
|
| 59 | + ); |
|
| 60 | + } // increment |
|
| 61 | + else { |
|
| 62 | + // override setting if present |
|
| 63 | + if ($skip !== null) { |
|
| 64 | + $this->counters[$name]['skip'] = (int)$skip; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - if ($direction !== null) { |
|
| 68 | - $this->counters[$name]['direction'] = strtolower($direction) === 'down' ? - 1 : 1; |
|
| 69 | - } |
|
| 67 | + if ($direction !== null) { |
|
| 68 | + $this->counters[$name]['direction'] = strtolower($direction) === 'down' ? - 1 : 1; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - if ($print !== null) { |
|
| 72 | - $this->counters[$name]['print'] = (bool)$print; |
|
| 73 | - } |
|
| 71 | + if ($print !== null) { |
|
| 72 | + $this->counters[$name]['print'] = (bool)$print; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - if ($assign !== null) { |
|
| 76 | - $this->counters[$name]['assign'] = (string)$assign; |
|
| 77 | - } |
|
| 75 | + if ($assign !== null) { |
|
| 76 | + $this->counters[$name]['assign'] = (string)$assign; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - if ($start !== null) { |
|
| 80 | - $this->counters[$name]['count'] = (int)$start; |
|
| 81 | - } else { |
|
| 82 | - $this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']); |
|
| 83 | - } |
|
| 84 | - } |
|
| 79 | + if ($start !== null) { |
|
| 80 | + $this->counters[$name]['count'] = (int)$start; |
|
| 81 | + } else { |
|
| 82 | + $this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - $out = $this->counters[$name]['count']; |
|
| 86 | + $out = $this->counters[$name]['count']; |
|
| 87 | 87 | |
| 88 | - if ($this->counters[$name]['assign'] !== null) { |
|
| 89 | - $this->core->assignInScope($out, $this->counters[$name]['assign']); |
|
| 90 | - } elseif ($this->counters[$name]['print'] === true) { |
|
| 91 | - return $out; |
|
| 92 | - } |
|
| 93 | - } |
|
| 88 | + if ($this->counters[$name]['assign'] !== null) { |
|
| 89 | + $this->core->assignInScope($out, $this->counters[$name]['assign']); |
|
| 90 | + } elseif ($this->counters[$name]['print'] === true) { |
|
| 91 | + return $out; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -30,22 +30,22 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | function PluginRegexReplace(Core $dwoo, $value, $search, $replace) |
| 32 | 32 | { |
| 33 | - $search = (array)$search; |
|
| 34 | - $cnt = count($search); |
|
| 33 | + $search = (array)$search; |
|
| 34 | + $cnt = count($search); |
|
| 35 | 35 | |
| 36 | - for ($i = 0; $i < $cnt; ++ $i) { |
|
| 37 | - // Credits for this to Monte Ohrt who made smarty's regex_replace modifier |
|
| 38 | - if (($pos = strpos($search[$i], "\0")) !== false) { |
|
| 39 | - $search[$i] = substr($search[$i], 0, $pos); |
|
| 40 | - } |
|
| 36 | + for ($i = 0; $i < $cnt; ++ $i) { |
|
| 37 | + // Credits for this to Monte Ohrt who made smarty's regex_replace modifier |
|
| 38 | + if (($pos = strpos($search[$i], "\0")) !== false) { |
|
| 39 | + $search[$i] = substr($search[$i], 0, $pos); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - if (preg_match('#[a-z\s]+$#is', $search[$i], $m) && (strpos($m[0], 'e') !== false)) { |
|
| 43 | - $search[$i] = substr($search[$i], 0, - strlen($m[0])) . str_replace(array( |
|
| 44 | - 'e', |
|
| 45 | - ' ' |
|
| 46 | - ), '', $m[0]); |
|
| 47 | - } |
|
| 48 | - } |
|
| 42 | + if (preg_match('#[a-z\s]+$#is', $search[$i], $m) && (strpos($m[0], 'e') !== false)) { |
|
| 43 | + $search[$i] = substr($search[$i], 0, - strlen($m[0])) . str_replace(array( |
|
| 44 | + 'e', |
|
| 45 | + ' ' |
|
| 46 | + ), '', $m[0]); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return preg_replace($search, $replace, $value); |
|
| 50 | + return preg_replace($search, $replace, $value); |
|
| 51 | 51 | } |
@@ -30,52 +30,52 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | function PluginDateFormat(Core $dwoo, $value, $format = '%b %e, %Y', $default = null) |
| 32 | 32 | { |
| 33 | - if (!empty($value)) { |
|
| 34 | - // convert if it's not a valid unix timestamp |
|
| 35 | - if (preg_match('#^-?\d{1,10}$#', $value) === 0) { |
|
| 36 | - $value = strtotime($value); |
|
| 37 | - } |
|
| 38 | - } elseif (!empty($default)) { |
|
| 39 | - // convert if it's not a valid unix timestamp |
|
| 40 | - if (preg_match('#^-?\d{1,10}$#', $default) === 0) { |
|
| 41 | - $value = strtotime($default); |
|
| 42 | - } else { |
|
| 43 | - $value = $default; |
|
| 44 | - } |
|
| 45 | - } else { |
|
| 46 | - return ''; |
|
| 47 | - } |
|
| 33 | + if (!empty($value)) { |
|
| 34 | + // convert if it's not a valid unix timestamp |
|
| 35 | + if (preg_match('#^-?\d{1,10}$#', $value) === 0) { |
|
| 36 | + $value = strtotime($value); |
|
| 37 | + } |
|
| 38 | + } elseif (!empty($default)) { |
|
| 39 | + // convert if it's not a valid unix timestamp |
|
| 40 | + if (preg_match('#^-?\d{1,10}$#', $default) === 0) { |
|
| 41 | + $value = strtotime($default); |
|
| 42 | + } else { |
|
| 43 | + $value = $default; |
|
| 44 | + } |
|
| 45 | + } else { |
|
| 46 | + return ''; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - // Credits for that windows compat block to Monte Ohrt who made smarty's date_format plugin |
|
| 50 | - if (DIRECTORY_SEPARATOR == '\\') { |
|
| 51 | - $_win_from = array( |
|
| 52 | - '%D', |
|
| 53 | - '%h', |
|
| 54 | - '%n', |
|
| 55 | - '%r', |
|
| 56 | - '%R', |
|
| 57 | - '%t', |
|
| 58 | - '%T' |
|
| 59 | - ); |
|
| 60 | - $_win_to = array( |
|
| 61 | - '%m/%d/%y', |
|
| 62 | - '%b', |
|
| 63 | - "\n", |
|
| 64 | - '%I:%M:%S %p', |
|
| 65 | - '%H:%M', |
|
| 66 | - "\t", |
|
| 67 | - '%H:%M:%S' |
|
| 68 | - ); |
|
| 69 | - if (strpos($format, '%e') !== false) { |
|
| 70 | - $_win_from[] = '%e'; |
|
| 71 | - $_win_to[] = sprintf('%\' 2d', date('j', $value)); |
|
| 72 | - } |
|
| 73 | - if (strpos($format, '%l') !== false) { |
|
| 74 | - $_win_from[] = '%l'; |
|
| 75 | - $_win_to[] = sprintf('%\' 2d', date('h', $value)); |
|
| 76 | - } |
|
| 77 | - $format = str_replace($_win_from, $_win_to, $format); |
|
| 78 | - } |
|
| 49 | + // Credits for that windows compat block to Monte Ohrt who made smarty's date_format plugin |
|
| 50 | + if (DIRECTORY_SEPARATOR == '\\') { |
|
| 51 | + $_win_from = array( |
|
| 52 | + '%D', |
|
| 53 | + '%h', |
|
| 54 | + '%n', |
|
| 55 | + '%r', |
|
| 56 | + '%R', |
|
| 57 | + '%t', |
|
| 58 | + '%T' |
|
| 59 | + ); |
|
| 60 | + $_win_to = array( |
|
| 61 | + '%m/%d/%y', |
|
| 62 | + '%b', |
|
| 63 | + "\n", |
|
| 64 | + '%I:%M:%S %p', |
|
| 65 | + '%H:%M', |
|
| 66 | + "\t", |
|
| 67 | + '%H:%M:%S' |
|
| 68 | + ); |
|
| 69 | + if (strpos($format, '%e') !== false) { |
|
| 70 | + $_win_from[] = '%e'; |
|
| 71 | + $_win_to[] = sprintf('%\' 2d', date('j', $value)); |
|
| 72 | + } |
|
| 73 | + if (strpos($format, '%l') !== false) { |
|
| 74 | + $_win_from[] = '%l'; |
|
| 75 | + $_win_to[] = sprintf('%\' 2d', date('h', $value)); |
|
| 76 | + } |
|
| 77 | + $format = str_replace($_win_from, $_win_to, $format); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - return strftime($format, $value); |
|
| 80 | + return strftime($format, $value); |
|
| 81 | 81 | } |
@@ -38,13 +38,13 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | function PluginArrayCompile(Compiler $compiler, array $rest = array()) |
| 40 | 40 | { |
| 41 | - $out = array(); |
|
| 42 | - foreach ($rest as $key => $value) { |
|
| 43 | - if (!is_numeric($key) && !strstr($key, '$this->scope')) { |
|
| 44 | - $key = "'" . $key . "'"; |
|
| 45 | - } |
|
| 46 | - $out[] = $key . '=>' . $value; |
|
| 47 | - } |
|
| 41 | + $out = array(); |
|
| 42 | + foreach ($rest as $key => $value) { |
|
| 43 | + if (!is_numeric($key) && !strstr($key, '$this->scope')) { |
|
| 44 | + $key = "'" . $key . "'"; |
|
| 45 | + } |
|
| 46 | + $out[] = $key . '=>' . $value; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return 'array(' . implode(', ', $out) . ')'; |
|
| 49 | + return 'array(' . implode(', ', $out) . ')'; |
|
| 50 | 50 | } |
@@ -27,47 +27,47 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class PluginForeachelse extends BlockPlugin implements ICompilableBlock |
| 29 | 29 | { |
| 30 | - public function init() |
|
| 31 | - { |
|
| 32 | - } |
|
| 30 | + public function init() |
|
| 31 | + { |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param Compiler $compiler |
|
| 36 | - * @param array $params |
|
| 37 | - * @param string $prepend |
|
| 38 | - * @param string $append |
|
| 39 | - * @param string $type |
|
| 40 | - * |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 44 | - { |
|
| 45 | - $with = &$compiler->findBlock('foreach', true); |
|
| 34 | + /** |
|
| 35 | + * @param Compiler $compiler |
|
| 36 | + * @param array $params |
|
| 37 | + * @param string $prepend |
|
| 38 | + * @param string $append |
|
| 39 | + * @param string $type |
|
| 40 | + * |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 44 | + { |
|
| 45 | + $with = &$compiler->findBlock('foreach', true); |
|
| 46 | 46 | |
| 47 | - $params['initialized'] = true; |
|
| 48 | - $compiler->injectBlock($type, $params); |
|
| 47 | + $params['initialized'] = true; |
|
| 48 | + $compiler->injectBlock($type, $params); |
|
| 49 | 49 | |
| 50 | - return ''; |
|
| 51 | - } |
|
| 50 | + return ''; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param Compiler $compiler |
|
| 55 | - * @param array $params |
|
| 56 | - * @param string $prepend |
|
| 57 | - * @param string $append |
|
| 58 | - * @param string $content |
|
| 59 | - * |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 63 | - { |
|
| 64 | - if (!isset($params['initialized'])) { |
|
| 65 | - return ''; |
|
| 66 | - } |
|
| 53 | + /** |
|
| 54 | + * @param Compiler $compiler |
|
| 55 | + * @param array $params |
|
| 56 | + * @param string $prepend |
|
| 57 | + * @param string $append |
|
| 58 | + * @param string $content |
|
| 59 | + * |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 63 | + { |
|
| 64 | + if (!isset($params['initialized'])) { |
|
| 65 | + return ''; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $block = &$compiler->getCurrentBlock(); |
|
| 69 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
| 68 | + $block = &$compiler->getCurrentBlock(); |
|
| 69 | + $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
| 70 | 70 | |
| 71 | - return ''; |
|
| 72 | - } |
|
| 71 | + return ''; |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -41,234 +41,234 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class PluginIf extends BlockPlugin implements ICompilableBlock, IElseable |
| 43 | 43 | { |
| 44 | - /** |
|
| 45 | - * @param array $rest |
|
| 46 | - */ |
|
| 47 | - public function init(array $rest) |
|
| 48 | - { |
|
| 49 | - } |
|
| 44 | + /** |
|
| 45 | + * @param array $rest |
|
| 46 | + */ |
|
| 47 | + public function init(array $rest) |
|
| 48 | + { |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param array $params |
|
| 53 | - * @param array $tokens |
|
| 54 | - * @param Compiler $compiler |
|
| 55 | - * |
|
| 56 | - * @return array |
|
| 57 | - * @throws CompilationException |
|
| 58 | - */ |
|
| 59 | - public static function replaceKeywords(array $params, array $tokens, Compiler $compiler) |
|
| 60 | - { |
|
| 61 | - $p = array(); |
|
| 51 | + /** |
|
| 52 | + * @param array $params |
|
| 53 | + * @param array $tokens |
|
| 54 | + * @param Compiler $compiler |
|
| 55 | + * |
|
| 56 | + * @return array |
|
| 57 | + * @throws CompilationException |
|
| 58 | + */ |
|
| 59 | + public static function replaceKeywords(array $params, array $tokens, Compiler $compiler) |
|
| 60 | + { |
|
| 61 | + $p = array(); |
|
| 62 | 62 | |
| 63 | - reset($params); |
|
| 64 | - while (list($k, $v) = each($params)) { |
|
| 65 | - $v = (string)$v; |
|
| 66 | - if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
|
| 67 | - $vmod = strtolower(substr($v, 1, - 1)); |
|
| 68 | - } else { |
|
| 69 | - $vmod = strtolower($v); |
|
| 70 | - } |
|
| 71 | - switch ($vmod) { |
|
| 63 | + reset($params); |
|
| 64 | + while (list($k, $v) = each($params)) { |
|
| 65 | + $v = (string)$v; |
|
| 66 | + if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
|
| 67 | + $vmod = strtolower(substr($v, 1, - 1)); |
|
| 68 | + } else { |
|
| 69 | + $vmod = strtolower($v); |
|
| 70 | + } |
|
| 71 | + switch ($vmod) { |
|
| 72 | 72 | |
| 73 | - case 'and': |
|
| 74 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 75 | - $p[] = '&&'; |
|
| 76 | - } else { |
|
| 77 | - $p[] = $v; |
|
| 78 | - } |
|
| 79 | - break; |
|
| 80 | - case 'or': |
|
| 81 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 82 | - $p[] = '||'; |
|
| 83 | - } else { |
|
| 84 | - $p[] = $v; |
|
| 85 | - } |
|
| 86 | - break; |
|
| 87 | - case 'xor': |
|
| 88 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 89 | - $p[] = '^'; |
|
| 90 | - } else { |
|
| 91 | - $p[] = $v; |
|
| 92 | - } |
|
| 93 | - break; |
|
| 94 | - case 'eq': |
|
| 95 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 96 | - $p[] = '=='; |
|
| 97 | - } else { |
|
| 98 | - $p[] = $v; |
|
| 99 | - } |
|
| 100 | - break; |
|
| 101 | - case 'ne': |
|
| 102 | - case 'neq': |
|
| 103 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 104 | - $p[] = '!='; |
|
| 105 | - } else { |
|
| 106 | - $p[] = $v; |
|
| 107 | - } |
|
| 108 | - break; |
|
| 109 | - case 'gte': |
|
| 110 | - case 'ge': |
|
| 111 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 112 | - $p[] = '>='; |
|
| 113 | - } else { |
|
| 114 | - $p[] = $v; |
|
| 115 | - } |
|
| 116 | - break; |
|
| 117 | - case 'lte': |
|
| 118 | - case 'le': |
|
| 119 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 120 | - $p[] = '<='; |
|
| 121 | - } else { |
|
| 122 | - $p[] = $v; |
|
| 123 | - } |
|
| 124 | - break; |
|
| 125 | - case 'gt': |
|
| 126 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 127 | - $p[] = '>'; |
|
| 128 | - } else { |
|
| 129 | - $p[] = $v; |
|
| 130 | - } |
|
| 131 | - break; |
|
| 132 | - case 'lt': |
|
| 133 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 134 | - $p[] = '<'; |
|
| 135 | - } else { |
|
| 136 | - $p[] = $v; |
|
| 137 | - } |
|
| 138 | - break; |
|
| 139 | - case 'mod': |
|
| 140 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 141 | - $p[] = '%'; |
|
| 142 | - } else { |
|
| 143 | - $p[] = $v; |
|
| 144 | - } |
|
| 145 | - break; |
|
| 146 | - case 'not': |
|
| 147 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 148 | - $p[] = '!'; |
|
| 149 | - } else { |
|
| 150 | - $p[] = $v; |
|
| 151 | - } |
|
| 152 | - break; |
|
| 153 | - case '<>': |
|
| 154 | - $p[] = '!='; |
|
| 155 | - break; |
|
| 156 | - case '==': |
|
| 157 | - case '!=': |
|
| 158 | - case '>=': |
|
| 159 | - case '<=': |
|
| 160 | - case '>': |
|
| 161 | - case '<': |
|
| 162 | - case '===': |
|
| 163 | - case '!==': |
|
| 164 | - case '%': |
|
| 165 | - case '!': |
|
| 166 | - case '^': |
|
| 167 | - $p[] = $vmod; |
|
| 168 | - break; |
|
| 169 | - case 'is': |
|
| 170 | - if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
| 171 | - $p[] = $v; |
|
| 172 | - break; |
|
| 173 | - } |
|
| 174 | - if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
| 175 | - $negate = true; |
|
| 176 | - next($params); |
|
| 177 | - } else { |
|
| 178 | - $negate = false; |
|
| 179 | - } |
|
| 180 | - $ptr = 1 + (int)$negate; |
|
| 181 | - if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
| 182 | - break; |
|
| 183 | - } |
|
| 184 | - if (!isset($params[$k + $ptr])) { |
|
| 185 | - $params[$k + $ptr] = ''; |
|
| 186 | - } else { |
|
| 187 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
| 188 | - } |
|
| 189 | - switch ($params[$k + $ptr]) { |
|
| 73 | + case 'and': |
|
| 74 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 75 | + $p[] = '&&'; |
|
| 76 | + } else { |
|
| 77 | + $p[] = $v; |
|
| 78 | + } |
|
| 79 | + break; |
|
| 80 | + case 'or': |
|
| 81 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 82 | + $p[] = '||'; |
|
| 83 | + } else { |
|
| 84 | + $p[] = $v; |
|
| 85 | + } |
|
| 86 | + break; |
|
| 87 | + case 'xor': |
|
| 88 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 89 | + $p[] = '^'; |
|
| 90 | + } else { |
|
| 91 | + $p[] = $v; |
|
| 92 | + } |
|
| 93 | + break; |
|
| 94 | + case 'eq': |
|
| 95 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 96 | + $p[] = '=='; |
|
| 97 | + } else { |
|
| 98 | + $p[] = $v; |
|
| 99 | + } |
|
| 100 | + break; |
|
| 101 | + case 'ne': |
|
| 102 | + case 'neq': |
|
| 103 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 104 | + $p[] = '!='; |
|
| 105 | + } else { |
|
| 106 | + $p[] = $v; |
|
| 107 | + } |
|
| 108 | + break; |
|
| 109 | + case 'gte': |
|
| 110 | + case 'ge': |
|
| 111 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 112 | + $p[] = '>='; |
|
| 113 | + } else { |
|
| 114 | + $p[] = $v; |
|
| 115 | + } |
|
| 116 | + break; |
|
| 117 | + case 'lte': |
|
| 118 | + case 'le': |
|
| 119 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 120 | + $p[] = '<='; |
|
| 121 | + } else { |
|
| 122 | + $p[] = $v; |
|
| 123 | + } |
|
| 124 | + break; |
|
| 125 | + case 'gt': |
|
| 126 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 127 | + $p[] = '>'; |
|
| 128 | + } else { |
|
| 129 | + $p[] = $v; |
|
| 130 | + } |
|
| 131 | + break; |
|
| 132 | + case 'lt': |
|
| 133 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 134 | + $p[] = '<'; |
|
| 135 | + } else { |
|
| 136 | + $p[] = $v; |
|
| 137 | + } |
|
| 138 | + break; |
|
| 139 | + case 'mod': |
|
| 140 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 141 | + $p[] = '%'; |
|
| 142 | + } else { |
|
| 143 | + $p[] = $v; |
|
| 144 | + } |
|
| 145 | + break; |
|
| 146 | + case 'not': |
|
| 147 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 148 | + $p[] = '!'; |
|
| 149 | + } else { |
|
| 150 | + $p[] = $v; |
|
| 151 | + } |
|
| 152 | + break; |
|
| 153 | + case '<>': |
|
| 154 | + $p[] = '!='; |
|
| 155 | + break; |
|
| 156 | + case '==': |
|
| 157 | + case '!=': |
|
| 158 | + case '>=': |
|
| 159 | + case '<=': |
|
| 160 | + case '>': |
|
| 161 | + case '<': |
|
| 162 | + case '===': |
|
| 163 | + case '!==': |
|
| 164 | + case '%': |
|
| 165 | + case '!': |
|
| 166 | + case '^': |
|
| 167 | + $p[] = $vmod; |
|
| 168 | + break; |
|
| 169 | + case 'is': |
|
| 170 | + if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
| 171 | + $p[] = $v; |
|
| 172 | + break; |
|
| 173 | + } |
|
| 174 | + if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
| 175 | + $negate = true; |
|
| 176 | + next($params); |
|
| 177 | + } else { |
|
| 178 | + $negate = false; |
|
| 179 | + } |
|
| 180 | + $ptr = 1 + (int)$negate; |
|
| 181 | + if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
| 182 | + break; |
|
| 183 | + } |
|
| 184 | + if (!isset($params[$k + $ptr])) { |
|
| 185 | + $params[$k + $ptr] = ''; |
|
| 186 | + } else { |
|
| 187 | + $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
| 188 | + } |
|
| 189 | + switch ($params[$k + $ptr]) { |
|
| 190 | 190 | |
| 191 | - case 'div': |
|
| 192 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 193 | - $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
| 194 | - next($params); |
|
| 195 | - next($params); |
|
| 196 | - next($params); |
|
| 197 | - } else { |
|
| 198 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
| 199 | - } |
|
| 200 | - break; |
|
| 201 | - case 'even': |
|
| 202 | - $a = array_pop($p); |
|
| 203 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 204 | - $b = $params[$k + $ptr + 2]; |
|
| 205 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 206 | - next($params); |
|
| 207 | - next($params); |
|
| 208 | - } else { |
|
| 209 | - $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 210 | - } |
|
| 211 | - next($params); |
|
| 212 | - break; |
|
| 213 | - case 'odd': |
|
| 214 | - $a = array_pop($p); |
|
| 215 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 216 | - $b = $params[$k + $ptr + 2]; |
|
| 217 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 218 | - next($params); |
|
| 219 | - next($params); |
|
| 220 | - } else { |
|
| 221 | - $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 222 | - } |
|
| 223 | - next($params); |
|
| 224 | - break; |
|
| 225 | - default: |
|
| 226 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
| 227 | - } |
|
| 228 | - break; |
|
| 229 | - default: |
|
| 230 | - $p[] = $v; |
|
| 231 | - } |
|
| 232 | - } |
|
| 191 | + case 'div': |
|
| 192 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 193 | + $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
| 194 | + next($params); |
|
| 195 | + next($params); |
|
| 196 | + next($params); |
|
| 197 | + } else { |
|
| 198 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
| 199 | + } |
|
| 200 | + break; |
|
| 201 | + case 'even': |
|
| 202 | + $a = array_pop($p); |
|
| 203 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 204 | + $b = $params[$k + $ptr + 2]; |
|
| 205 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 206 | + next($params); |
|
| 207 | + next($params); |
|
| 208 | + } else { |
|
| 209 | + $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 210 | + } |
|
| 211 | + next($params); |
|
| 212 | + break; |
|
| 213 | + case 'odd': |
|
| 214 | + $a = array_pop($p); |
|
| 215 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 216 | + $b = $params[$k + $ptr + 2]; |
|
| 217 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 218 | + next($params); |
|
| 219 | + next($params); |
|
| 220 | + } else { |
|
| 221 | + $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 222 | + } |
|
| 223 | + next($params); |
|
| 224 | + break; |
|
| 225 | + default: |
|
| 226 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
| 227 | + } |
|
| 228 | + break; |
|
| 229 | + default: |
|
| 230 | + $p[] = $v; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - return $p; |
|
| 235 | - } |
|
| 234 | + return $p; |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * @param Compiler $compiler |
|
| 239 | - * @param array $params |
|
| 240 | - * @param string $prepend |
|
| 241 | - * @param string $append |
|
| 242 | - * @param string $type |
|
| 243 | - * |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 247 | - { |
|
| 248 | - return ''; |
|
| 249 | - } |
|
| 237 | + /** |
|
| 238 | + * @param Compiler $compiler |
|
| 239 | + * @param array $params |
|
| 240 | + * @param string $prepend |
|
| 241 | + * @param string $append |
|
| 242 | + * @param string $type |
|
| 243 | + * |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 247 | + { |
|
| 248 | + return ''; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * @param Compiler $compiler |
|
| 253 | - * @param array $params |
|
| 254 | - * @param string $prepend |
|
| 255 | - * @param string $append |
|
| 256 | - * @param string $content |
|
| 257 | - * |
|
| 258 | - * @return string |
|
| 259 | - */ |
|
| 260 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 261 | - { |
|
| 262 | - $tokens = $compiler->getParamTokens($params); |
|
| 263 | - $params = $compiler->getCompiledParams($params); |
|
| 264 | - $pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
| 251 | + /** |
|
| 252 | + * @param Compiler $compiler |
|
| 253 | + * @param array $params |
|
| 254 | + * @param string $prepend |
|
| 255 | + * @param string $append |
|
| 256 | + * @param string $content |
|
| 257 | + * |
|
| 258 | + * @return string |
|
| 259 | + */ |
|
| 260 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 261 | + { |
|
| 262 | + $tokens = $compiler->getParamTokens($params); |
|
| 263 | + $params = $compiler->getCompiledParams($params); |
|
| 264 | + $pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
| 265 | 265 | |
| 266 | - $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
| 266 | + $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
| 267 | 267 | |
| 268 | - if (isset($params['hasElse'])) { |
|
| 269 | - $post .= $params['hasElse']; |
|
| 270 | - } |
|
| 268 | + if (isset($params['hasElse'])) { |
|
| 269 | + $post .= $params['hasElse']; |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - return $pre . $content . $post; |
|
| 273 | - } |
|
| 272 | + return $pre . $content . $post; |
|
| 273 | + } |
|
| 274 | 274 | } |
@@ -29,38 +29,38 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class PluginBlock extends BlockPlugin implements ICompilableBlock |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * @param string $name |
|
| 34 | - */ |
|
| 35 | - public function init($name = '') |
|
| 36 | - { |
|
| 37 | - } |
|
| 32 | + /** |
|
| 33 | + * @param string $name |
|
| 34 | + */ |
|
| 35 | + public function init($name = '') |
|
| 36 | + { |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param Compiler $compiler |
|
| 41 | - * @param array $params |
|
| 42 | - * @param string $prepend |
|
| 43 | - * @param string $append |
|
| 44 | - * @param string $type |
|
| 45 | - * |
|
| 46 | - * @return string |
|
| 47 | - */ |
|
| 48 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 49 | - { |
|
| 50 | - return ''; |
|
| 51 | - } |
|
| 39 | + /** |
|
| 40 | + * @param Compiler $compiler |
|
| 41 | + * @param array $params |
|
| 42 | + * @param string $prepend |
|
| 43 | + * @param string $append |
|
| 44 | + * @param string $type |
|
| 45 | + * |
|
| 46 | + * @return string |
|
| 47 | + */ |
|
| 48 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 49 | + { |
|
| 50 | + return ''; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param Compiler $compiler |
|
| 55 | - * @param array $params |
|
| 56 | - * @param string $prepend |
|
| 57 | - * @param string $append |
|
| 58 | - * @param string $content |
|
| 59 | - * |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 63 | - { |
|
| 64 | - return $content; |
|
| 65 | - } |
|
| 53 | + /** |
|
| 54 | + * @param Compiler $compiler |
|
| 55 | + * @param array $params |
|
| 56 | + * @param string $prepend |
|
| 57 | + * @param string $append |
|
| 58 | + * @param string $content |
|
| 59 | + * |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 63 | + { |
|
| 64 | + return $content; |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -28,69 +28,69 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class PluginSmartyinterface extends BlockPlugin implements ICompilableBlock |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * @param $__funcname |
|
| 33 | - * @param $__functype |
|
| 34 | - * @param array $rest |
|
| 35 | - */ |
|
| 36 | - public function init($__funcname, $__functype, array $rest = array()) |
|
| 37 | - { |
|
| 38 | - } |
|
| 31 | + /** |
|
| 32 | + * @param $__funcname |
|
| 33 | + * @param $__functype |
|
| 34 | + * @param array $rest |
|
| 35 | + */ |
|
| 36 | + public function init($__funcname, $__functype, array $rest = array()) |
|
| 37 | + { |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param Compiler $compiler |
|
| 42 | - * @param array $params |
|
| 43 | - * @param string $prepend |
|
| 44 | - * @param string $append |
|
| 45 | - * @param string $type |
|
| 46 | - * |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 50 | - { |
|
| 51 | - $params = $compiler->getCompiledParams($params); |
|
| 52 | - $func = $params['__funcname']; |
|
| 53 | - $pluginType = $params['__functype']; |
|
| 54 | - $params = $params['*']; |
|
| 40 | + /** |
|
| 41 | + * @param Compiler $compiler |
|
| 42 | + * @param array $params |
|
| 43 | + * @param string $prepend |
|
| 44 | + * @param string $append |
|
| 45 | + * @param string $type |
|
| 46 | + * |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 50 | + { |
|
| 51 | + $params = $compiler->getCompiledParams($params); |
|
| 52 | + $func = $params['__funcname']; |
|
| 53 | + $pluginType = $params['__functype']; |
|
| 54 | + $params = $params['*']; |
|
| 55 | 55 | |
| 56 | - if ($pluginType & Core::CUSTOM_PLUGIN) { |
|
| 57 | - $customPlugins = $compiler->getDwoo()->getCustomPlugins(); |
|
| 58 | - $callback = $customPlugins[$func]['callback']; |
|
| 59 | - if (is_array($callback)) { |
|
| 60 | - if (is_object($callback[0])) { |
|
| 61 | - $callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '('; |
|
| 62 | - } else { |
|
| 63 | - $callback = '' . $callback[0] . '::' . $callback[1] . '('; |
|
| 64 | - } |
|
| 65 | - } else { |
|
| 66 | - $callback = $callback . '('; |
|
| 67 | - } |
|
| 68 | - } else { |
|
| 69 | - $callback = 'smarty_block_' . $func . '('; |
|
| 70 | - } |
|
| 56 | + if ($pluginType & Core::CUSTOM_PLUGIN) { |
|
| 57 | + $customPlugins = $compiler->getDwoo()->getCustomPlugins(); |
|
| 58 | + $callback = $customPlugins[$func]['callback']; |
|
| 59 | + if (is_array($callback)) { |
|
| 60 | + if (is_object($callback[0])) { |
|
| 61 | + $callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '('; |
|
| 62 | + } else { |
|
| 63 | + $callback = '' . $callback[0] . '::' . $callback[1] . '('; |
|
| 64 | + } |
|
| 65 | + } else { |
|
| 66 | + $callback = $callback . '('; |
|
| 67 | + } |
|
| 68 | + } else { |
|
| 69 | + $callback = 'smarty_block_' . $func . '('; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $paramsOut = ''; |
|
| 73 | - foreach ($params as $i => $p) { |
|
| 74 | - $paramsOut .= var_export($i, true) . ' => ' . $p . ','; |
|
| 75 | - } |
|
| 72 | + $paramsOut = ''; |
|
| 73 | + foreach ($params as $i => $p) { |
|
| 74 | + $paramsOut .= var_export($i, true) . ' => ' . $p . ','; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - $curBlock = &$compiler->getCurrentBlock(); |
|
| 78 | - $curBlock['params']['postOut'] = Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Compiler::PHP_CLOSE; |
|
| 77 | + $curBlock = &$compiler->getCurrentBlock(); |
|
| 78 | + $curBlock['params']['postOut'] = Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Compiler::PHP_CLOSE; |
|
| 79 | 79 | |
| 80 | - return Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Compiler::PHP_CLOSE; |
|
| 81 | - } |
|
| 80 | + return Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Compiler::PHP_CLOSE; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @param Compiler $compiler |
|
| 85 | - * @param array $params |
|
| 86 | - * @param string $prepend |
|
| 87 | - * @param string $append |
|
| 88 | - * @param string $content |
|
| 89 | - * |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 93 | - { |
|
| 94 | - return $content . $params['postOut']; |
|
| 95 | - } |
|
| 83 | + /** |
|
| 84 | + * @param Compiler $compiler |
|
| 85 | + * @param array $params |
|
| 86 | + * @param string $prepend |
|
| 87 | + * @param string $append |
|
| 88 | + * @param string $content |
|
| 89 | + * |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 93 | + { |
|
| 94 | + return $content . $params['postOut']; |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -28,89 +28,89 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class PluginDynamic extends BlockPlugin implements ICompilableBlock |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * |
|
| 33 | - */ |
|
| 34 | - public function init() |
|
| 35 | - { |
|
| 36 | - } |
|
| 31 | + /** |
|
| 32 | + * |
|
| 33 | + */ |
|
| 34 | + public function init() |
|
| 35 | + { |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param Compiler $compiler |
|
| 40 | - * @param array $params |
|
| 41 | - * @param string $prepend |
|
| 42 | - * @param string $append |
|
| 43 | - * @param string $type |
|
| 44 | - * |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 48 | - { |
|
| 49 | - return ''; |
|
| 50 | - } |
|
| 38 | + /** |
|
| 39 | + * @param Compiler $compiler |
|
| 40 | + * @param array $params |
|
| 41 | + * @param string $prepend |
|
| 42 | + * @param string $append |
|
| 43 | + * @param string $type |
|
| 44 | + * |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 48 | + { |
|
| 49 | + return ''; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param Compiler $compiler |
|
| 54 | - * @param array $params |
|
| 55 | - * @param string $prepend |
|
| 56 | - * @param string $append |
|
| 57 | - * @param string $content |
|
| 58 | - * |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 62 | - { |
|
| 63 | - try { |
|
| 64 | - $compiler->findBlock('dynamic'); |
|
| 52 | + /** |
|
| 53 | + * @param Compiler $compiler |
|
| 54 | + * @param array $params |
|
| 55 | + * @param string $prepend |
|
| 56 | + * @param string $append |
|
| 57 | + * @param string $content |
|
| 58 | + * |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 62 | + { |
|
| 63 | + try { |
|
| 64 | + $compiler->findBlock('dynamic'); |
|
| 65 | 65 | |
| 66 | - return $content; |
|
| 67 | - } |
|
| 68 | - catch (CompilationException $e) { |
|
| 69 | - } |
|
| 70 | - $output = Compiler::PHP_OPEN . 'if($doCache) {' . "\n\t" . 'echo \'<dwoo:dynamic_\'.$dynamicId.\'>' . str_replace('\'', '\\\'', $content) . '</dwoo:dynamic_\'.$dynamicId.\'>\';' . "\n} else {\n\t"; |
|
| 71 | - if (substr($content, 0, strlen(Compiler::PHP_OPEN)) == Compiler::PHP_OPEN) { |
|
| 72 | - $output .= substr($content, strlen(Compiler::PHP_OPEN)); |
|
| 73 | - } else { |
|
| 74 | - $output .= Compiler::PHP_CLOSE . $content; |
|
| 75 | - } |
|
| 76 | - if (substr($output, - strlen(Compiler::PHP_CLOSE)) == Compiler::PHP_CLOSE) { |
|
| 77 | - $output = substr($output, 0, - strlen(Compiler::PHP_CLOSE)); |
|
| 78 | - } else { |
|
| 79 | - $output .= Compiler::PHP_OPEN; |
|
| 80 | - } |
|
| 81 | - $output .= "\n}" . Compiler::PHP_CLOSE; |
|
| 66 | + return $content; |
|
| 67 | + } |
|
| 68 | + catch (CompilationException $e) { |
|
| 69 | + } |
|
| 70 | + $output = Compiler::PHP_OPEN . 'if($doCache) {' . "\n\t" . 'echo \'<dwoo:dynamic_\'.$dynamicId.\'>' . str_replace('\'', '\\\'', $content) . '</dwoo:dynamic_\'.$dynamicId.\'>\';' . "\n} else {\n\t"; |
|
| 71 | + if (substr($content, 0, strlen(Compiler::PHP_OPEN)) == Compiler::PHP_OPEN) { |
|
| 72 | + $output .= substr($content, strlen(Compiler::PHP_OPEN)); |
|
| 73 | + } else { |
|
| 74 | + $output .= Compiler::PHP_CLOSE . $content; |
|
| 75 | + } |
|
| 76 | + if (substr($output, - strlen(Compiler::PHP_CLOSE)) == Compiler::PHP_CLOSE) { |
|
| 77 | + $output = substr($output, 0, - strlen(Compiler::PHP_CLOSE)); |
|
| 78 | + } else { |
|
| 79 | + $output .= Compiler::PHP_OPEN; |
|
| 80 | + } |
|
| 81 | + $output .= "\n}" . Compiler::PHP_CLOSE; |
|
| 82 | 82 | |
| 83 | - return $output; |
|
| 84 | - } |
|
| 83 | + return $output; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @param $output |
|
| 88 | - * @param $dynamicId |
|
| 89 | - * @param $compiledFile |
|
| 90 | - * |
|
| 91 | - * @return mixed|string |
|
| 92 | - */ |
|
| 93 | - public static function unescape($output, $dynamicId, $compiledFile) |
|
| 94 | - { |
|
| 95 | - $output = preg_replace_callback('/<dwoo:dynamic_(' . $dynamicId . ')>(.+?)<\/dwoo:dynamic_' . $dynamicId . '>/s', array( |
|
| 96 | - 'self', |
|
| 97 | - 'unescapePhp' |
|
| 98 | - ), $output, - 1, $count); |
|
| 99 | - // re-add the includes on top of the file |
|
| 100 | - if ($count && preg_match('#/\* template head \*/(.+?)/\* end template head \*/#s', file_get_contents($compiledFile), $m)) { |
|
| 101 | - $output = '<?php ' . $m[1] . ' ?>' . $output; |
|
| 102 | - } |
|
| 86 | + /** |
|
| 87 | + * @param $output |
|
| 88 | + * @param $dynamicId |
|
| 89 | + * @param $compiledFile |
|
| 90 | + * |
|
| 91 | + * @return mixed|string |
|
| 92 | + */ |
|
| 93 | + public static function unescape($output, $dynamicId, $compiledFile) |
|
| 94 | + { |
|
| 95 | + $output = preg_replace_callback('/<dwoo:dynamic_(' . $dynamicId . ')>(.+?)<\/dwoo:dynamic_' . $dynamicId . '>/s', array( |
|
| 96 | + 'self', |
|
| 97 | + 'unescapePhp' |
|
| 98 | + ), $output, - 1, $count); |
|
| 99 | + // re-add the includes on top of the file |
|
| 100 | + if ($count && preg_match('#/\* template head \*/(.+?)/\* end template head \*/#s', file_get_contents($compiledFile), $m)) { |
|
| 101 | + $output = '<?php ' . $m[1] . ' ?>' . $output; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - return $output; |
|
| 105 | - } |
|
| 104 | + return $output; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @param $match |
|
| 109 | - * |
|
| 110 | - * @return mixed |
|
| 111 | - */ |
|
| 112 | - public static function unescapePhp($match) |
|
| 113 | - { |
|
| 114 | - return preg_replace('{<\?php /\*' . $match[1] . '\*/ echo \'(.+?)\'; \?>}s', '$1', $match[2]); |
|
| 115 | - } |
|
| 107 | + /** |
|
| 108 | + * @param $match |
|
| 109 | + * |
|
| 110 | + * @return mixed |
|
| 111 | + */ |
|
| 112 | + public static function unescapePhp($match) |
|
| 113 | + { |
|
| 114 | + return preg_replace('{<\?php /\*' . $match[1] . '\*/ echo \'(.+?)\'; \?>}s', '$1', $match[2]); |
|
| 115 | + } |
|
| 116 | 116 | } |