| @@ -41,233 +41,233 @@ | ||
| 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 | 63 |  	foreach($params as $k => $v) { | 
| 64 | - $v = (string)$v; | |
| 65 | -            if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { | |
| 66 | - $vmod = strtolower(substr($v, 1, - 1)); | |
| 67 | -            } else { | |
| 68 | - $vmod = strtolower($v); | |
| 69 | - } | |
| 70 | -            switch ($vmod) { | |
| 64 | + $v = (string)$v; | |
| 65 | +			if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { | |
| 66 | + $vmod = strtolower(substr($v, 1, - 1)); | |
| 67 | +			} else { | |
| 68 | + $vmod = strtolower($v); | |
| 69 | + } | |
| 70 | +			switch ($vmod) { | |
| 71 | 71 | |
| 72 | - case 'and': | |
| 73 | -                    if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 74 | - $p[] = '&&'; | |
| 75 | -                    } else { | |
| 76 | - $p[] = $v; | |
| 77 | - } | |
| 78 | - break; | |
| 79 | - case 'or': | |
| 80 | -                    if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 81 | - $p[] = '||'; | |
| 82 | -                    } else { | |
| 83 | - $p[] = $v; | |
| 84 | - } | |
| 85 | - break; | |
| 86 | - case 'xor': | |
| 87 | -                    if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 88 | - $p[] = '^'; | |
| 89 | -                    } else { | |
| 90 | - $p[] = $v; | |
| 91 | - } | |
| 92 | - break; | |
| 93 | - case 'eq': | |
| 94 | -                    if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 95 | - $p[] = '=='; | |
| 96 | -                    } else { | |
| 97 | - $p[] = $v; | |
| 98 | - } | |
| 99 | - break; | |
| 100 | - case 'ne': | |
| 101 | - case 'neq': | |
| 102 | -                    if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 103 | - $p[] = '!='; | |
| 104 | -                    } else { | |
| 105 | - $p[] = $v; | |
| 106 | - } | |
| 107 | - break; | |
| 108 | - case 'gte': | |
| 109 | - case 'ge': | |
| 110 | -                    if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 111 | - $p[] = '>='; | |
| 112 | -                    } else { | |
| 113 | - $p[] = $v; | |
| 114 | - } | |
| 115 | - break; | |
| 116 | - case 'lte': | |
| 117 | - case 'le': | |
| 118 | -                    if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 119 | - $p[] = '<='; | |
| 120 | -                    } else { | |
| 121 | - $p[] = $v; | |
| 122 | - } | |
| 123 | - break; | |
| 124 | - case 'gt': | |
| 125 | -                    if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 126 | - $p[] = '>'; | |
| 127 | -                    } else { | |
| 128 | - $p[] = $v; | |
| 129 | - } | |
| 130 | - break; | |
| 131 | - case 'lt': | |
| 132 | -                    if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 133 | - $p[] = '<'; | |
| 134 | -                    } else { | |
| 135 | - $p[] = $v; | |
| 136 | - } | |
| 137 | - break; | |
| 138 | - case 'mod': | |
| 139 | -                    if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 140 | - $p[] = '%'; | |
| 141 | -                    } else { | |
| 142 | - $p[] = $v; | |
| 143 | - } | |
| 144 | - break; | |
| 145 | - case 'not': | |
| 146 | -                    if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 147 | - $p[] = '!'; | |
| 148 | -                    } else { | |
| 149 | - $p[] = $v; | |
| 150 | - } | |
| 151 | - break; | |
| 152 | - case '<>': | |
| 153 | - $p[] = '!='; | |
| 154 | - break; | |
| 155 | - case '==': | |
| 156 | - case '!=': | |
| 157 | - case '>=': | |
| 158 | - case '<=': | |
| 159 | - case '>': | |
| 160 | - case '<': | |
| 161 | - case '===': | |
| 162 | - case '!==': | |
| 163 | - case '%': | |
| 164 | - case '!': | |
| 165 | - case '^': | |
| 166 | - $p[] = $vmod; | |
| 167 | - break; | |
| 168 | - case 'is': | |
| 169 | -                    if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { | |
| 170 | - $p[] = $v; | |
| 171 | - break; | |
| 172 | - } | |
| 173 | -                    if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { | |
| 174 | - $negate = true; | |
| 175 | - next($params); | |
| 176 | -                    } else { | |
| 177 | - $negate = false; | |
| 178 | - } | |
| 179 | - $ptr = 1 + (int)$negate; | |
| 180 | -                    if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { | |
| 181 | - break; | |
| 182 | - } | |
| 183 | -                    if (!isset($params[$k + $ptr])) { | |
| 184 | - $params[$k + $ptr] = ''; | |
| 185 | -                    } else { | |
| 186 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); | |
| 187 | - } | |
| 188 | -                    switch ($params[$k + $ptr]) { | |
| 72 | + case 'and': | |
| 73 | +					if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 74 | + $p[] = '&&'; | |
| 75 | +					} else { | |
| 76 | + $p[] = $v; | |
| 77 | + } | |
| 78 | + break; | |
| 79 | + case 'or': | |
| 80 | +					if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 81 | + $p[] = '||'; | |
| 82 | +					} else { | |
| 83 | + $p[] = $v; | |
| 84 | + } | |
| 85 | + break; | |
| 86 | + case 'xor': | |
| 87 | +					if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 88 | + $p[] = '^'; | |
| 89 | +					} else { | |
| 90 | + $p[] = $v; | |
| 91 | + } | |
| 92 | + break; | |
| 93 | + case 'eq': | |
| 94 | +					if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 95 | + $p[] = '=='; | |
| 96 | +					} else { | |
| 97 | + $p[] = $v; | |
| 98 | + } | |
| 99 | + break; | |
| 100 | + case 'ne': | |
| 101 | + case 'neq': | |
| 102 | +					if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 103 | + $p[] = '!='; | |
| 104 | +					} else { | |
| 105 | + $p[] = $v; | |
| 106 | + } | |
| 107 | + break; | |
| 108 | + case 'gte': | |
| 109 | + case 'ge': | |
| 110 | +					if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 111 | + $p[] = '>='; | |
| 112 | +					} else { | |
| 113 | + $p[] = $v; | |
| 114 | + } | |
| 115 | + break; | |
| 116 | + case 'lte': | |
| 117 | + case 'le': | |
| 118 | +					if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 119 | + $p[] = '<='; | |
| 120 | +					} else { | |
| 121 | + $p[] = $v; | |
| 122 | + } | |
| 123 | + break; | |
| 124 | + case 'gt': | |
| 125 | +					if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 126 | + $p[] = '>'; | |
| 127 | +					} else { | |
| 128 | + $p[] = $v; | |
| 129 | + } | |
| 130 | + break; | |
| 131 | + case 'lt': | |
| 132 | +					if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 133 | + $p[] = '<'; | |
| 134 | +					} else { | |
| 135 | + $p[] = $v; | |
| 136 | + } | |
| 137 | + break; | |
| 138 | + case 'mod': | |
| 139 | +					if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 140 | + $p[] = '%'; | |
| 141 | +					} else { | |
| 142 | + $p[] = $v; | |
| 143 | + } | |
| 144 | + break; | |
| 145 | + case 'not': | |
| 146 | +					if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { | |
| 147 | + $p[] = '!'; | |
| 148 | +					} else { | |
| 149 | + $p[] = $v; | |
| 150 | + } | |
| 151 | + break; | |
| 152 | + case '<>': | |
| 153 | + $p[] = '!='; | |
| 154 | + break; | |
| 155 | + case '==': | |
| 156 | + case '!=': | |
| 157 | + case '>=': | |
| 158 | + case '<=': | |
| 159 | + case '>': | |
| 160 | + case '<': | |
| 161 | + case '===': | |
| 162 | + case '!==': | |
| 163 | + case '%': | |
| 164 | + case '!': | |
| 165 | + case '^': | |
| 166 | + $p[] = $vmod; | |
| 167 | + break; | |
| 168 | + case 'is': | |
| 169 | +					if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { | |
| 170 | + $p[] = $v; | |
| 171 | + break; | |
| 172 | + } | |
| 173 | +					if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { | |
| 174 | + $negate = true; | |
| 175 | + next($params); | |
| 176 | +					} else { | |
| 177 | + $negate = false; | |
| 178 | + } | |
| 179 | + $ptr = 1 + (int)$negate; | |
| 180 | +					if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { | |
| 181 | + break; | |
| 182 | + } | |
| 183 | +					if (!isset($params[$k + $ptr])) { | |
| 184 | + $params[$k + $ptr] = ''; | |
| 185 | +					} else { | |
| 186 | + $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); | |
| 187 | + } | |
| 188 | +					switch ($params[$k + $ptr]) { | |
| 189 | 189 | |
| 190 | - case 'div': | |
| 191 | -                            if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { | |
| 192 | - $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; | |
| 193 | - next($params); | |
| 194 | - next($params); | |
| 195 | - next($params); | |
| 196 | -                            } else { | |
| 197 | - 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]); | |
| 198 | - } | |
| 199 | - break; | |
| 200 | - case 'even': | |
| 201 | - $a = array_pop($p); | |
| 202 | -                            if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { | |
| 203 | - $b = $params[$k + $ptr + 2]; | |
| 204 | -                                $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; | |
| 205 | - next($params); | |
| 206 | - next($params); | |
| 207 | -                            } else { | |
| 208 | - $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; | |
| 209 | - } | |
| 210 | - next($params); | |
| 211 | - break; | |
| 212 | - case 'odd': | |
| 213 | - $a = array_pop($p); | |
| 214 | -                            if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { | |
| 215 | - $b = $params[$k + $ptr + 2]; | |
| 216 | -                                $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; | |
| 217 | - next($params); | |
| 218 | - next($params); | |
| 219 | -                            } else { | |
| 220 | - $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; | |
| 221 | - } | |
| 222 | - next($params); | |
| 223 | - break; | |
| 224 | - default: | |
| 225 | - 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]); | |
| 226 | - } | |
| 227 | - break; | |
| 228 | - default: | |
| 229 | - $p[] = $v; | |
| 230 | - } | |
| 231 | - } | |
| 190 | + case 'div': | |
| 191 | +							if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { | |
| 192 | + $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; | |
| 193 | + next($params); | |
| 194 | + next($params); | |
| 195 | + next($params); | |
| 196 | +							} else { | |
| 197 | + 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]); | |
| 198 | + } | |
| 199 | + break; | |
| 200 | + case 'even': | |
| 201 | + $a = array_pop($p); | |
| 202 | +							if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { | |
| 203 | + $b = $params[$k + $ptr + 2]; | |
| 204 | +								$p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; | |
| 205 | + next($params); | |
| 206 | + next($params); | |
| 207 | +							} else { | |
| 208 | + $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; | |
| 209 | + } | |
| 210 | + next($params); | |
| 211 | + break; | |
| 212 | + case 'odd': | |
| 213 | + $a = array_pop($p); | |
| 214 | +							if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { | |
| 215 | + $b = $params[$k + $ptr + 2]; | |
| 216 | +								$p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; | |
| 217 | + next($params); | |
| 218 | + next($params); | |
| 219 | +							} else { | |
| 220 | + $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; | |
| 221 | + } | |
| 222 | + next($params); | |
| 223 | + break; | |
| 224 | + default: | |
| 225 | + 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]); | |
| 226 | + } | |
| 227 | + break; | |
| 228 | + default: | |
| 229 | + $p[] = $v; | |
| 230 | + } | |
| 231 | + } | |
| 232 | 232 | |
| 233 | - return $p; | |
| 234 | - } | |
| 233 | + return $p; | |
| 234 | + } | |
| 235 | 235 | |
| 236 | - /** | |
| 237 | - * @param Compiler $compiler | |
| 238 | - * @param array $params | |
| 239 | - * @param string $prepend | |
| 240 | - * @param string $append | |
| 241 | - * @param string $type | |
| 242 | - * | |
| 243 | - * @return string | |
| 244 | - */ | |
| 245 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) | |
| 246 | -    { | |
| 247 | - return ''; | |
| 248 | - } | |
| 236 | + /** | |
| 237 | + * @param Compiler $compiler | |
| 238 | + * @param array $params | |
| 239 | + * @param string $prepend | |
| 240 | + * @param string $append | |
| 241 | + * @param string $type | |
| 242 | + * | |
| 243 | + * @return string | |
| 244 | + */ | |
| 245 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) | |
| 246 | +	{ | |
| 247 | + return ''; | |
| 248 | + } | |
| 249 | 249 | |
| 250 | - /** | |
| 251 | - * @param Compiler $compiler | |
| 252 | - * @param array $params | |
| 253 | - * @param string $prepend | |
| 254 | - * @param string $append | |
| 255 | - * @param string $content | |
| 256 | - * | |
| 257 | - * @return string | |
| 258 | - */ | |
| 259 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) | |
| 260 | -    { | |
| 261 | - $tokens = $compiler->getParamTokens($params); | |
| 262 | - $params = $compiler->getCompiledParams($params); | |
| 263 | -        $pre    = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; | |
| 250 | + /** | |
| 251 | + * @param Compiler $compiler | |
| 252 | + * @param array $params | |
| 253 | + * @param string $prepend | |
| 254 | + * @param string $append | |
| 255 | + * @param string $content | |
| 256 | + * | |
| 257 | + * @return string | |
| 258 | + */ | |
| 259 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) | |
| 260 | +	{ | |
| 261 | + $tokens = $compiler->getParamTokens($params); | |
| 262 | + $params = $compiler->getCompiledParams($params); | |
| 263 | +		$pre    = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; | |
| 264 | 264 | |
| 265 | - $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; | |
| 265 | + $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; | |
| 266 | 266 | |
| 267 | -        if (isset($params['hasElse'])) { | |
| 268 | - $post .= $params['hasElse']; | |
| 269 | - } | |
| 267 | +		if (isset($params['hasElse'])) { | |
| 268 | + $post .= $params['hasElse']; | |
| 269 | + } | |
| 270 | 270 | |
| 271 | - return $pre . $content . $post; | |
| 272 | - } | |
| 271 | + return $pre . $content . $post; | |
| 272 | + } | |
| 273 | 273 | } | 
| @@ -60,8 +60,8 @@ discard block | ||
| 60 | 60 |      { | 
| 61 | 61 | $p = array(); | 
| 62 | 62 | |
| 63 | -	foreach($params as $k => $v) { | |
| 64 | - $v = (string)$v; | |
| 63 | +	foreach ($params as $k => $v) { | |
| 64 | + $v = (string) $v; | |
| 65 | 65 |              if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { | 
| 66 | 66 | $vmod = strtolower(substr($v, 1, - 1)); | 
| 67 | 67 |              } else { | 
| @@ -170,59 +170,59 @@ discard block | ||
| 170 | 170 | $p[] = $v; | 
| 171 | 171 | break; | 
| 172 | 172 | } | 
| 173 | -                    if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { | |
| 173 | +                    if (isset($params[$k+1]) && strtolower(trim($params[$k+1], '"\'')) === 'not' && $tokens[$k+1] === Compiler::T_UNQUOTED_STRING) { | |
| 174 | 174 | $negate = true; | 
| 175 | 175 | next($params); | 
| 176 | 176 |                      } else { | 
| 177 | 177 | $negate = false; | 
| 178 | 178 | } | 
| 179 | - $ptr = 1 + (int)$negate; | |
| 180 | -                    if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { | |
| 179 | + $ptr = 1+(int) $negate; | |
| 180 | +                    if ($tokens[$k+$ptr] !== Compiler::T_UNQUOTED_STRING) { | |
| 181 | 181 | break; | 
| 182 | 182 | } | 
| 183 | -                    if (!isset($params[$k + $ptr])) { | |
| 184 | - $params[$k + $ptr] = ''; | |
| 183 | +                    if (!isset($params[$k+$ptr])) { | |
| 184 | + $params[$k+$ptr] = ''; | |
| 185 | 185 |                      } else { | 
| 186 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); | |
| 186 | + $params[$k+$ptr] = trim($params[$k+$ptr], '"\''); | |
| 187 | 187 | } | 
| 188 | -                    switch ($params[$k + $ptr]) { | |
| 188 | +                    switch ($params[$k+$ptr]) { | |
| 189 | 189 | |
| 190 | 190 | case 'div': | 
| 191 | -                            if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { | |
| 192 | - $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; | |
| 191 | +                            if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { | |
| 192 | + $p[] = ' % '.$params[$k+$ptr+2].' '.($negate ? '!' : '=').'== 0'; | |
| 193 | 193 | next($params); | 
| 194 | 194 | next($params); | 
| 195 | 195 | next($params); | 
| 196 | 196 |                              } else { | 
| 197 | - 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]); | |
| 197 | + 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]); | |
| 198 | 198 | } | 
| 199 | 199 | break; | 
| 200 | 200 | case 'even': | 
| 201 | 201 | $a = array_pop($p); | 
| 202 | -                            if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { | |
| 203 | - $b = $params[$k + $ptr + 2]; | |
| 204 | -                                $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; | |
| 202 | +                            if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { | |
| 203 | + $b = $params[$k+$ptr+2]; | |
| 204 | +                                $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '!' : '=').'== 0'; | |
| 205 | 205 | next($params); | 
| 206 | 206 | next($params); | 
| 207 | 207 |                              } else { | 
| 208 | - $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; | |
| 208 | + $p[] = $a.' % 2 '.($negate ? '!' : '=').'== 0'; | |
| 209 | 209 | } | 
| 210 | 210 | next($params); | 
| 211 | 211 | break; | 
| 212 | 212 | case 'odd': | 
| 213 | 213 | $a = array_pop($p); | 
| 214 | -                            if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { | |
| 215 | - $b = $params[$k + $ptr + 2]; | |
| 216 | -                                $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; | |
| 214 | +                            if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { | |
| 215 | + $b = $params[$k+$ptr+2]; | |
| 216 | +                                $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '=' : '!').'== 0'; | |
| 217 | 217 | next($params); | 
| 218 | 218 | next($params); | 
| 219 | 219 |                              } else { | 
| 220 | - $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; | |
| 220 | + $p[] = $a.' % 2 '.($negate ? '=' : '!').'== 0'; | |
| 221 | 221 | } | 
| 222 | 222 | next($params); | 
| 223 | 223 | break; | 
| 224 | 224 | default: | 
| 225 | - 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]); | |
| 225 | + 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]); | |
| 226 | 226 | } | 
| 227 | 227 | break; | 
| 228 | 228 | default: | 
| @@ -260,14 +260,14 @@ discard block | ||
| 260 | 260 |      { | 
| 261 | 261 | $tokens = $compiler->getParamTokens($params); | 
| 262 | 262 | $params = $compiler->getCompiledParams($params); | 
| 263 | -        $pre    = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; | |
| 263 | +        $pre    = Compiler::PHP_OPEN.'if ('.implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)).") {\n".Compiler::PHP_CLOSE; | |
| 264 | 264 | |
| 265 | - $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; | |
| 265 | + $post = Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; | |
| 266 | 266 | |
| 267 | 267 |          if (isset($params['hasElse'])) { | 
| 268 | 268 | $post .= $params['hasElse']; | 
| 269 | 269 | } | 
| 270 | 270 | |
| 271 | - return $pre . $content . $post; | |
| 271 | + return $pre.$content.$post; | |
| 272 | 272 | } | 
| 273 | 273 | } | 
| @@ -36,84 +36,84 @@ | ||
| 36 | 36 | */ | 
| 37 | 37 | class PluginTextformat extends BlockPlugin | 
| 38 | 38 |  { | 
| 39 | - protected $wrap; | |
| 40 | - protected $wrapChar; | |
| 41 | - protected $wrapCut; | |
| 42 | - protected $indent; | |
| 43 | - protected $indChar; | |
| 44 | - protected $indFirst; | |
| 45 | - protected $assign; | |
| 39 | + protected $wrap; | |
| 40 | + protected $wrapChar; | |
| 41 | + protected $wrapCut; | |
| 42 | + protected $indent; | |
| 43 | + protected $indChar; | |
| 44 | + protected $indFirst; | |
| 45 | + protected $assign; | |
| 46 | 46 | |
| 47 | - /** | |
| 48 | - * @param int $wrap | |
| 49 | - * @param string $wrap_char | |
| 50 | - * @param bool $wrap_cut | |
| 51 | - * @param int $indent | |
| 52 | - * @param string $indent_char | |
| 53 | - * @param int $indent_first | |
| 54 | - * @param string $style | |
| 55 | - * @param string $assign | |
| 56 | - */ | |
| 57 | - public function init($wrap = 80, $wrap_char = "\r\n", $wrap_cut = false, $indent = 0, $indent_char = ' ', $indent_first = 0, $style = '', $assign = '') | |
| 58 | -    { | |
| 59 | -        if ($indent_char === 'tab') { | |
| 60 | - $indent_char = "\t"; | |
| 61 | - } | |
| 47 | + /** | |
| 48 | + * @param int $wrap | |
| 49 | + * @param string $wrap_char | |
| 50 | + * @param bool $wrap_cut | |
| 51 | + * @param int $indent | |
| 52 | + * @param string $indent_char | |
| 53 | + * @param int $indent_first | |
| 54 | + * @param string $style | |
| 55 | + * @param string $assign | |
| 56 | + */ | |
| 57 | + public function init($wrap = 80, $wrap_char = "\r\n", $wrap_cut = false, $indent = 0, $indent_char = ' ', $indent_first = 0, $style = '', $assign = '') | |
| 58 | +	{ | |
| 59 | +		if ($indent_char === 'tab') { | |
| 60 | + $indent_char = "\t"; | |
| 61 | + } | |
| 62 | 62 | |
| 63 | -        switch ($style) { | |
| 63 | +		switch ($style) { | |
| 64 | 64 | |
| 65 | - case 'email': | |
| 66 | - $wrap = 72; | |
| 67 | - $indent_first = 0; | |
| 68 | - break; | |
| 69 | - case 'html': | |
| 70 | - $wrap_char = '<br />'; | |
| 71 | - $indent_char = $indent_char == "\t" ? '    ' : ' '; | |
| 72 | - break; | |
| 73 | - } | |
| 65 | + case 'email': | |
| 66 | + $wrap = 72; | |
| 67 | + $indent_first = 0; | |
| 68 | + break; | |
| 69 | + case 'html': | |
| 70 | + $wrap_char = '<br />'; | |
| 71 | + $indent_char = $indent_char == "\t" ? '    ' : ' '; | |
| 72 | + break; | |
| 73 | + } | |
| 74 | 74 | |
| 75 | - $this->wrap = (int)$wrap; | |
| 76 | - $this->wrapChar = (string)$wrap_char; | |
| 77 | - $this->wrapCut = (bool)$wrap_cut; | |
| 78 | - $this->indent = (int)$indent; | |
| 79 | - $this->indChar = (string)$indent_char; | |
| 80 | - $this->indFirst = (int)$indent_first + $this->indent; | |
| 81 | - $this->assign = (string)$assign; | |
| 82 | - } | |
| 75 | + $this->wrap = (int)$wrap; | |
| 76 | + $this->wrapChar = (string)$wrap_char; | |
| 77 | + $this->wrapCut = (bool)$wrap_cut; | |
| 78 | + $this->indent = (int)$indent; | |
| 79 | + $this->indChar = (string)$indent_char; | |
| 80 | + $this->indFirst = (int)$indent_first + $this->indent; | |
| 81 | + $this->assign = (string)$assign; | |
| 82 | + } | |
| 83 | 83 | |
| 84 | - /** | |
| 85 | - * @return string | |
| 86 | - */ | |
| 87 | - public function process() | |
| 88 | -    { | |
| 89 | - // gets paragraphs | |
| 90 | -        $pgs = explode("\n", str_replace(array( | |
| 91 | - "\r\n", | |
| 92 | - "\r" | |
| 93 | - ), "\n", $this->buffer)); | |
| 84 | + /** | |
| 85 | + * @return string | |
| 86 | + */ | |
| 87 | + public function process() | |
| 88 | +	{ | |
| 89 | + // gets paragraphs | |
| 90 | +		$pgs = explode("\n", str_replace(array( | |
| 91 | + "\r\n", | |
| 92 | + "\r" | |
| 93 | + ), "\n", $this->buffer)); | |
| 94 | 94 | |
| 95 | 95 |  	foreach($pgs as $i => $v) { | 
| 96 | -            if (empty($pgs[$i])) { | |
| 97 | - continue; | |
| 98 | - } | |
| 96 | +			if (empty($pgs[$i])) { | |
| 97 | + continue; | |
| 98 | + } | |
| 99 | 99 | |
| 100 | - // removes line breaks and extensive white space | |
| 101 | - $pgs[$i] = preg_replace(array( | |
| 102 | - '#\s+#', | |
| 103 | - '#^\s*(.+?)\s*$#m' | |
| 104 | - ), array( | |
| 105 | - ' ', | |
| 106 | - '$1' | |
| 107 | -            ), str_replace("\n", '', $pgs[$i])); | |
| 100 | + // removes line breaks and extensive white space | |
| 101 | + $pgs[$i] = preg_replace(array( | |
| 102 | + '#\s+#', | |
| 103 | + '#^\s*(.+?)\s*$#m' | |
| 104 | + ), array( | |
| 105 | + ' ', | |
| 106 | + '$1' | |
| 107 | +			), str_replace("\n", '', $pgs[$i])); | |
| 108 | 108 | |
| 109 | - // wordwraps + indents lines | |
| 110 | - $pgs[$i] = str_repeat($this->indChar, $this->indFirst) . wordwrap($pgs[$i], max($this->wrap - $this->indent, 1), $this->wrapChar . str_repeat($this->indChar, $this->indent), $this->wrapCut); | |
| 111 | - } | |
| 109 | + // wordwraps + indents lines | |
| 110 | + $pgs[$i] = str_repeat($this->indChar, $this->indFirst) . wordwrap($pgs[$i], max($this->wrap - $this->indent, 1), $this->wrapChar . str_repeat($this->indChar, $this->indent), $this->wrapCut); | |
| 111 | + } | |
| 112 | 112 | |
| 113 | -        if ($this->assign !== '') { | |
| 114 | - $this->core->assignInScope(implode($this->wrapChar . $this->wrapChar, $pgs), $this->assign); | |
| 115 | -        } else { | |
| 116 | - return implode($this->wrapChar . $this->wrapChar, $pgs); | |
| 117 | - } | |
| 118 | - } | |
| 113 | +		if ($this->assign !== '') { | |
| 114 | + $this->core->assignInScope(implode($this->wrapChar . $this->wrapChar, $pgs), $this->assign); | |
| 115 | +		} else { | |
| 116 | + return implode($this->wrapChar . $this->wrapChar, $pgs); | |
| 117 | + } | |
| 118 | + } | |
| 119 | 119 | } | 
| @@ -72,13 +72,13 @@ discard block | ||
| 72 | 72 | break; | 
| 73 | 73 | } | 
| 74 | 74 | |
| 75 | - $this->wrap = (int)$wrap; | |
| 76 | - $this->wrapChar = (string)$wrap_char; | |
| 77 | - $this->wrapCut = (bool)$wrap_cut; | |
| 78 | - $this->indent = (int)$indent; | |
| 79 | - $this->indChar = (string)$indent_char; | |
| 80 | - $this->indFirst = (int)$indent_first + $this->indent; | |
| 81 | - $this->assign = (string)$assign; | |
| 75 | + $this->wrap = (int) $wrap; | |
| 76 | + $this->wrapChar = (string) $wrap_char; | |
| 77 | + $this->wrapCut = (bool) $wrap_cut; | |
| 78 | + $this->indent = (int) $indent; | |
| 79 | + $this->indChar = (string) $indent_char; | |
| 80 | + $this->indFirst = (int) $indent_first+$this->indent; | |
| 81 | + $this->assign = (string) $assign; | |
| 82 | 82 | } | 
| 83 | 83 | |
| 84 | 84 | /** | 
| @@ -92,7 +92,7 @@ discard block | ||
| 92 | 92 | "\r" | 
| 93 | 93 | ), "\n", $this->buffer)); | 
| 94 | 94 | |
| 95 | -	foreach($pgs as $i => $v) { | |
| 95 | +	foreach ($pgs as $i => $v) { | |
| 96 | 96 |              if (empty($pgs[$i])) { | 
| 97 | 97 | continue; | 
| 98 | 98 | } | 
| @@ -107,13 +107,13 @@ discard block | ||
| 107 | 107 |              ), str_replace("\n", '', $pgs[$i])); | 
| 108 | 108 | |
| 109 | 109 | // wordwraps + indents lines | 
| 110 | - $pgs[$i] = str_repeat($this->indChar, $this->indFirst) . wordwrap($pgs[$i], max($this->wrap - $this->indent, 1), $this->wrapChar . str_repeat($this->indChar, $this->indent), $this->wrapCut); | |
| 110 | + $pgs[$i] = str_repeat($this->indChar, $this->indFirst).wordwrap($pgs[$i], max($this->wrap-$this->indent, 1), $this->wrapChar.str_repeat($this->indChar, $this->indent), $this->wrapCut); | |
| 111 | 111 | } | 
| 112 | 112 | |
| 113 | 113 |          if ($this->assign !== '') { | 
| 114 | - $this->core->assignInScope(implode($this->wrapChar . $this->wrapChar, $pgs), $this->assign); | |
| 114 | + $this->core->assignInScope(implode($this->wrapChar.$this->wrapChar, $pgs), $this->assign); | |
| 115 | 115 |          } else { | 
| 116 | - return implode($this->wrapChar . $this->wrapChar, $pgs); | |
| 116 | + return implode($this->wrapChar.$this->wrapChar, $pgs); | |
| 117 | 117 | } | 
| 118 | 118 | } | 
| 119 | 119 | } |