@@ -31,5 +31,5 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | function PluginWordwrapCompile(Compiler $compiler, $value, $length = 80, $break = "\n", $cut = false) |
| 33 | 33 | { |
| 34 | - return 'wordwrap(' . $value . ',' . $length . ',' . $break . ',' . $cut . ')'; |
|
| 34 | + return 'wordwrap(' . $value . ',' . $length . ',' . $break . ',' . $cut . ')'; |
|
| 35 | 35 | } |
@@ -28,5 +28,5 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | function PluginCountSentencesCompile(Compiler $compiler, $value) |
| 30 | 30 | { |
| 31 | - return "preg_match_all('#[\w\pL]\.(?![\w\pL])#u', $value, \$tmp)"; |
|
| 31 | + return "preg_match_all('#[\w\pL]\.(?![\w\pL])#u', $value, \$tmp)"; |
|
| 32 | 32 | } |
@@ -33,25 +33,25 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | function PluginTruncate(Core $dwoo, $value, $length = 80, $etc = '...', $break = false, $middle = false) |
| 35 | 35 | { |
| 36 | - if ($length == 0) { |
|
| 37 | - return ''; |
|
| 38 | - } |
|
| 36 | + if ($length == 0) { |
|
| 37 | + return ''; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - $value = (string)$value; |
|
| 41 | - $etc = (string)$etc; |
|
| 42 | - $length = (int)$length; |
|
| 40 | + $value = (string)$value; |
|
| 41 | + $etc = (string)$etc; |
|
| 42 | + $length = (int)$length; |
|
| 43 | 43 | |
| 44 | - if (strlen($value) < $length) { |
|
| 45 | - return $value; |
|
| 46 | - } |
|
| 44 | + if (strlen($value) < $length) { |
|
| 45 | + return $value; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - $length = max($length - strlen($etc), 0); |
|
| 49 | - if ($break === false && $middle === false) { |
|
| 50 | - $value = preg_replace('#\s+(\S*)?$#', '', substr($value, 0, $length + 1)); |
|
| 51 | - } |
|
| 52 | - if ($middle === false) { |
|
| 53 | - return substr($value, 0, $length) . $etc; |
|
| 54 | - } |
|
| 48 | + $length = max($length - strlen($etc), 0); |
|
| 49 | + if ($break === false && $middle === false) { |
|
| 50 | + $value = preg_replace('#\s+(\S*)?$#', '', substr($value, 0, $length + 1)); |
|
| 51 | + } |
|
| 52 | + if ($middle === false) { |
|
| 53 | + return substr($value, 0, $length) . $etc; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return substr($value, 0, ceil($length / 2)) . $etc . substr($value, - floor($length / 2)); |
|
| 56 | + return substr($value, 0, ceil($length / 2)) . $etc . substr($value, - floor($length / 2)); |
|
| 57 | 57 | } |
@@ -34,56 +34,56 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | function PluginTifCompile(Compiler $compiler, array $rest, array $tokens) |
| 36 | 36 | { |
| 37 | - // load if plugin |
|
| 38 | - if (!class_exists(Core::NAMESPACE_PLUGINS_BLOCKS . 'PluginIf')) { |
|
| 39 | - try { |
|
| 40 | - $compiler->getDwoo()->getLoader()->loadPlugin('if'); |
|
| 41 | - } |
|
| 42 | - catch (Exception $e) { |
|
| 43 | - throw new CompilationException($compiler, 'Tif: the if plugin is required to use Tif'); |
|
| 44 | - } |
|
| 45 | - } |
|
| 37 | + // load if plugin |
|
| 38 | + if (!class_exists(Core::NAMESPACE_PLUGINS_BLOCKS . 'PluginIf')) { |
|
| 39 | + try { |
|
| 40 | + $compiler->getDwoo()->getLoader()->loadPlugin('if'); |
|
| 41 | + } |
|
| 42 | + catch (Exception $e) { |
|
| 43 | + throw new CompilationException($compiler, 'Tif: the if plugin is required to use Tif'); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - if (count($rest) == 1) { |
|
| 48 | - return $rest[0]; |
|
| 49 | - } |
|
| 47 | + if (count($rest) == 1) { |
|
| 48 | + return $rest[0]; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - // fetch false result and remove the ":" if it was present |
|
| 52 | - $falseResult = array_pop($rest); |
|
| 51 | + // fetch false result and remove the ":" if it was present |
|
| 52 | + $falseResult = array_pop($rest); |
|
| 53 | 53 | |
| 54 | - if (trim(end($rest), '"\'') === ':') { |
|
| 55 | - // remove the ':' if present |
|
| 56 | - array_pop($rest); |
|
| 57 | - } elseif (trim(end($rest), '"\'') === '?' || count($rest) === 1) { |
|
| 58 | - if ($falseResult === '?' || $falseResult === ':') { |
|
| 59 | - throw new CompilationException($compiler, 'Tif: incomplete tif statement, value missing after ' . $falseResult); |
|
| 60 | - } |
|
| 61 | - // there was in fact no false result provided, so we move it to be the true result instead |
|
| 62 | - $trueResult = $falseResult; |
|
| 63 | - $falseResult = "''"; |
|
| 64 | - } |
|
| 54 | + if (trim(end($rest), '"\'') === ':') { |
|
| 55 | + // remove the ':' if present |
|
| 56 | + array_pop($rest); |
|
| 57 | + } elseif (trim(end($rest), '"\'') === '?' || count($rest) === 1) { |
|
| 58 | + if ($falseResult === '?' || $falseResult === ':') { |
|
| 59 | + throw new CompilationException($compiler, 'Tif: incomplete tif statement, value missing after ' . $falseResult); |
|
| 60 | + } |
|
| 61 | + // there was in fact no false result provided, so we move it to be the true result instead |
|
| 62 | + $trueResult = $falseResult; |
|
| 63 | + $falseResult = "''"; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - // fetch true result if needed |
|
| 67 | - if (!isset($trueResult)) { |
|
| 68 | - $trueResult = array_pop($rest); |
|
| 69 | - // no true result provided so we use the expression arg |
|
| 70 | - if ($trueResult === '?') { |
|
| 71 | - $trueResult = true; |
|
| 72 | - } |
|
| 73 | - } |
|
| 66 | + // fetch true result if needed |
|
| 67 | + if (!isset($trueResult)) { |
|
| 68 | + $trueResult = array_pop($rest); |
|
| 69 | + // no true result provided so we use the expression arg |
|
| 70 | + if ($trueResult === '?') { |
|
| 71 | + $trueResult = true; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - // remove the '?' if present |
|
| 76 | - if (trim(end($rest), '"\'') === '?') { |
|
| 77 | - array_pop($rest); |
|
| 78 | - } |
|
| 75 | + // remove the '?' if present |
|
| 76 | + if (trim(end($rest), '"\'') === '?') { |
|
| 77 | + array_pop($rest); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - // check params were correctly provided |
|
| 81 | - if (empty($rest) || $trueResult === null || $falseResult === null) { |
|
| 82 | - throw new CompilationException($compiler, 'Tif: you must provide three parameters serving as <expression> ? <true value> : <false value>'); |
|
| 83 | - } |
|
| 80 | + // check params were correctly provided |
|
| 81 | + if (empty($rest) || $trueResult === null || $falseResult === null) { |
|
| 82 | + throw new CompilationException($compiler, 'Tif: you must provide three parameters serving as <expression> ? <true value> : <false value>'); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // parse condition |
|
| 86 | - $condition = PluginIf::replaceKeywords($rest, $tokens, $compiler); |
|
| 85 | + // parse condition |
|
| 86 | + $condition = PluginIf::replaceKeywords($rest, $tokens, $compiler); |
|
| 87 | 87 | |
| 88 | - return '((' . implode(' ', $condition) . ') ? ' . ($trueResult === true ? implode(' ', $condition) : $trueResult) . ' : ' . $falseResult . ')'; |
|
| 88 | + return '((' . implode(' ', $condition) . ') ? ' . ($trueResult === true ? implode(' ', $condition) : $trueResult) . ' : ' . $falseResult . ')'; |
|
| 89 | 89 | } |
@@ -30,9 +30,9 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | function PluginReplaceCompile(Compiler $compiler, $value, $search, $replace, $case_sensitive = true) |
| 32 | 32 | { |
| 33 | - if ($case_sensitive == 'false' || (bool)$case_sensitive === false) { |
|
| 34 | - return 'str_ireplace(' . $search . ', ' . $replace . ', ' . $value . ')'; |
|
| 35 | - } else { |
|
| 36 | - return 'str_replace(' . $search . ', ' . $replace . ', ' . $value . ')'; |
|
| 37 | - } |
|
| 33 | + if ($case_sensitive == 'false' || (bool)$case_sensitive === false) { |
|
| 34 | + return 'str_ireplace(' . $search . ', ' . $replace . ', ' . $value . ')'; |
|
| 35 | + } else { |
|
| 36 | + return 'str_replace(' . $search . ', ' . $replace . ', ' . $value . ')'; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -28,5 +28,5 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | function PluginCountParagraphsCompile(Compiler $compiler, $value) |
| 30 | 30 | { |
| 31 | - return '(preg_match_all(\'#[\r\n]+#\', ' . $value . ', $tmp)+1)'; |
|
| 31 | + return '(preg_match_all(\'#[\r\n]+#\', ' . $value . ', $tmp)+1)'; |
|
| 32 | 32 | } |
@@ -30,40 +30,40 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | function PluginFetch(Core $dwoo, $file, $assign = null) |
| 32 | 32 | { |
| 33 | - if ($file === '') { |
|
| 34 | - return ''; |
|
| 35 | - } |
|
| 33 | + if ($file === '') { |
|
| 34 | + return ''; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - if ($policy = $dwoo->getSecurityPolicy()) { |
|
| 38 | - while (true) { |
|
| 39 | - if (preg_match('{^([a-z]+?)://}i', $file)) { |
|
| 40 | - $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING); |
|
| 41 | - } |
|
| 37 | + if ($policy = $dwoo->getSecurityPolicy()) { |
|
| 38 | + while (true) { |
|
| 39 | + if (preg_match('{^([a-z]+?)://}i', $file)) { |
|
| 40 | + $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $file = realpath($file); |
|
| 44 | - $dirs = $policy->getAllowedDirectories(); |
|
| 45 | - foreach ($dirs as $dir => $dummy) { |
|
| 46 | - if (strpos($file, $dir) === 0) { |
|
| 47 | - break 2; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - $dwoo->triggerError('The security policy prevents you to read <em>' . $file . '</em>', E_USER_WARNING); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - $file = str_replace(array( |
|
| 54 | - "\t", |
|
| 55 | - "\n", |
|
| 56 | - "\r" |
|
| 57 | - ), array( |
|
| 58 | - '\\t', |
|
| 59 | - '\\n', |
|
| 60 | - '\\r' |
|
| 61 | - ), $file); |
|
| 43 | + $file = realpath($file); |
|
| 44 | + $dirs = $policy->getAllowedDirectories(); |
|
| 45 | + foreach ($dirs as $dir => $dummy) { |
|
| 46 | + if (strpos($file, $dir) === 0) { |
|
| 47 | + break 2; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + $dwoo->triggerError('The security policy prevents you to read <em>' . $file . '</em>', E_USER_WARNING); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + $file = str_replace(array( |
|
| 54 | + "\t", |
|
| 55 | + "\n", |
|
| 56 | + "\r" |
|
| 57 | + ), array( |
|
| 58 | + '\\t', |
|
| 59 | + '\\n', |
|
| 60 | + '\\r' |
|
| 61 | + ), $file); |
|
| 62 | 62 | |
| 63 | - $out = file_get_contents($file); |
|
| 63 | + $out = file_get_contents($file); |
|
| 64 | 64 | |
| 65 | - if ($assign === null) { |
|
| 66 | - return $out; |
|
| 67 | - } |
|
| 68 | - $dwoo->assignInScope($out, $assign); |
|
| 65 | + if ($assign === null) { |
|
| 66 | + return $out; |
|
| 67 | + } |
|
| 68 | + $dwoo->assignInScope($out, $assign); |
|
| 69 | 69 | } |
@@ -29,5 +29,5 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | function PluginSpacifyCompile(Compiler $compiler, $value, $space_char = ' ') |
| 31 | 31 | { |
| 32 | - return 'implode(' . $space_char . ', str_split(' . $value . ', 1))'; |
|
| 32 | + return 'implode(' . $space_char . ', str_split(' . $value . ', 1))'; |
|
| 33 | 33 | } |
@@ -28,5 +28,5 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | function PluginLowerCompile(Compiler $compiler, $value) |
| 30 | 30 | { |
| 31 | - return 'mb_strtolower((string) ' . $value . ', $this->charset)'; |
|
| 31 | + return 'mb_strtolower((string) ' . $value . ', $this->charset)'; |
|
| 32 | 32 | } |