@@ -23,19 +23,19 @@ |
||
23 | 23 | */ |
24 | 24 | function Dwoo_Plugin_regex_replace(Dwoo_Core $dwoo, $value, $search, $replace) |
25 | 25 | { |
26 | - $search = (array) $search; |
|
27 | - $cnt = count($search); |
|
26 | + $search = (array) $search; |
|
27 | + $cnt = count($search); |
|
28 | 28 | |
29 | - for ($i = 0; $i < $cnt; ++$i) { |
|
30 | - // Credits for this to Monte Ohrt who made smarty's regex_replace modifier |
|
31 | - if (($pos = strpos($search[$i], "\0")) !== false) { |
|
32 | - $search[$i] = substr($search[$i], 0, $pos); |
|
33 | - } |
|
29 | + for ($i = 0; $i < $cnt; ++$i) { |
|
30 | + // Credits for this to Monte Ohrt who made smarty's regex_replace modifier |
|
31 | + if (($pos = strpos($search[$i], "\0")) !== false) { |
|
32 | + $search[$i] = substr($search[$i], 0, $pos); |
|
33 | + } |
|
34 | 34 | |
35 | - if (preg_match('#[a-z\s]+$#is', $search[$i], $m) && (strpos($m[0], 'e') !== false)) { |
|
36 | - $search[$i] = substr($search[$i], 0, -strlen($m[0])).str_replace(array('e', ' '), '', $m[0]); |
|
37 | - } |
|
38 | - } |
|
35 | + if (preg_match('#[a-z\s]+$#is', $search[$i], $m) && (strpos($m[0], 'e') !== false)) { |
|
36 | + $search[$i] = substr($search[$i], 0, -strlen($m[0])).str_replace(array('e', ' '), '', $m[0]); |
|
37 | + } |
|
38 | + } |
|
39 | 39 | |
40 | - return preg_replace($search, $replace, $value); |
|
40 | + return preg_replace($search, $replace, $value); |
|
41 | 41 | } |
@@ -23,55 +23,55 @@ |
||
23 | 23 | */ |
24 | 24 | function Dwoo_Plugin_tif_compile(Dwoo_Compiler $compiler, array $rest, array $tokens) |
25 | 25 | { |
26 | - // load if plugin |
|
27 | - if (!class_exists('Dwoo_Plugin_if', false)) { |
|
28 | - try { |
|
29 | - $compiler->getDwoo()->getLoader()->loadPlugin('if'); |
|
30 | - } catch (Exception $e) { |
|
31 | - throw new Dwoo_Compilation_Exception($compiler, 'Tif: the if plugin is required to use Tif'); |
|
32 | - } |
|
33 | - } |
|
26 | + // load if plugin |
|
27 | + if (!class_exists('Dwoo_Plugin_if', false)) { |
|
28 | + try { |
|
29 | + $compiler->getDwoo()->getLoader()->loadPlugin('if'); |
|
30 | + } catch (Exception $e) { |
|
31 | + throw new Dwoo_Compilation_Exception($compiler, 'Tif: the if plugin is required to use Tif'); |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | - if (count($rest) == 1) { |
|
36 | - return $rest[0]; |
|
37 | - } |
|
35 | + if (count($rest) == 1) { |
|
36 | + return $rest[0]; |
|
37 | + } |
|
38 | 38 | |
39 | - // fetch false result and remove the ":" if it was present |
|
40 | - $falseResult = array_pop($rest); |
|
39 | + // fetch false result and remove the ":" if it was present |
|
40 | + $falseResult = array_pop($rest); |
|
41 | 41 | |
42 | - if (trim(end($rest), '"\'') === ':') { |
|
43 | - // remove the ':' if present |
|
44 | - array_pop($rest); |
|
45 | - } elseif (trim(end($rest), '"\'') === '?' || count($rest) === 1) { |
|
46 | - if ($falseResult === '?' || $falseResult === ':') { |
|
47 | - throw new Dwoo_Compilation_Exception($compiler, 'Tif: incomplete tif statement, value missing after '.$falseResult); |
|
48 | - } |
|
49 | - // there was in fact no false result provided, so we move it to be the true result instead |
|
50 | - $trueResult = $falseResult; |
|
51 | - $falseResult = "''"; |
|
52 | - } |
|
42 | + if (trim(end($rest), '"\'') === ':') { |
|
43 | + // remove the ':' if present |
|
44 | + array_pop($rest); |
|
45 | + } elseif (trim(end($rest), '"\'') === '?' || count($rest) === 1) { |
|
46 | + if ($falseResult === '?' || $falseResult === ':') { |
|
47 | + throw new Dwoo_Compilation_Exception($compiler, 'Tif: incomplete tif statement, value missing after '.$falseResult); |
|
48 | + } |
|
49 | + // there was in fact no false result provided, so we move it to be the true result instead |
|
50 | + $trueResult = $falseResult; |
|
51 | + $falseResult = "''"; |
|
52 | + } |
|
53 | 53 | |
54 | - // fetch true result if needed |
|
55 | - if (!isset($trueResult)) { |
|
56 | - $trueResult = array_pop($rest); |
|
57 | - // no true result provided so we use the expression arg |
|
58 | - if ($trueResult === '?') { |
|
59 | - $trueResult = true; |
|
60 | - } |
|
61 | - } |
|
54 | + // fetch true result if needed |
|
55 | + if (!isset($trueResult)) { |
|
56 | + $trueResult = array_pop($rest); |
|
57 | + // no true result provided so we use the expression arg |
|
58 | + if ($trueResult === '?') { |
|
59 | + $trueResult = true; |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - // remove the '?' if present |
|
64 | - if (trim(end($rest), '"\'') === '?') { |
|
65 | - array_pop($rest); |
|
66 | - } |
|
63 | + // remove the '?' if present |
|
64 | + if (trim(end($rest), '"\'') === '?') { |
|
65 | + array_pop($rest); |
|
66 | + } |
|
67 | 67 | |
68 | - // check params were correctly provided |
|
69 | - if (empty($rest) || $trueResult === null || $falseResult === null) { |
|
70 | - throw new Dwoo_Compilation_Exception($compiler, 'Tif: you must provide three parameters serving as <expression> ? <true value> : <false value>'); |
|
71 | - } |
|
68 | + // check params were correctly provided |
|
69 | + if (empty($rest) || $trueResult === null || $falseResult === null) { |
|
70 | + throw new Dwoo_Compilation_Exception($compiler, 'Tif: you must provide three parameters serving as <expression> ? <true value> : <false value>'); |
|
71 | + } |
|
72 | 72 | |
73 | - // parse condition |
|
74 | - $condition = Dwoo_Plugin_if::replaceKeywords($rest, $tokens, $compiler); |
|
73 | + // parse condition |
|
74 | + $condition = Dwoo_Plugin_if::replaceKeywords($rest, $tokens, $compiler); |
|
75 | 75 | |
76 | - return '(('.implode(' ', $condition).') ? '.($trueResult === true ? implode(' ', $condition) : $trueResult).' : '.$falseResult.')'; |
|
76 | + return '(('.implode(' ', $condition).') ? '.($trueResult === true ? implode(' ', $condition) : $trueResult).' : '.$falseResult.')'; |
|
77 | 77 | } |
@@ -20,56 +20,56 @@ |
||
20 | 20 | */ |
21 | 21 | class Dwoo_Processor_smarty_compat extends Dwoo_Processor |
22 | 22 | { |
23 | - public function process($input) |
|
24 | - { |
|
25 | - list($l, $r) = $this->compiler->getDelimiters(); |
|
23 | + public function process($input) |
|
24 | + { |
|
25 | + list($l, $r) = $this->compiler->getDelimiters(); |
|
26 | 26 | |
27 | - $rl = preg_quote($l, '/'); |
|
28 | - $rr = preg_quote($r, '/'); |
|
29 | - $sectionParam = '(?:(name|loop|start|step|max|show)\s*=\s*(\S+))?\s*'; |
|
30 | - $input = preg_replace_callback('/'.$rl.'\s*section '.str_repeat($sectionParam, 6).'\s*'.$rr.'(.+?)(?:'.$rl.'\s*sectionelse\s*'.$rr.'(.+?))?'.$rl.'\s*\/section\s*'.$rr.'/is', array($this, 'convertSection'), $input); |
|
31 | - $input = str_replace('$smarty.section.', '$smarty.for.', $input); |
|
27 | + $rl = preg_quote($l, '/'); |
|
28 | + $rr = preg_quote($r, '/'); |
|
29 | + $sectionParam = '(?:(name|loop|start|step|max|show)\s*=\s*(\S+))?\s*'; |
|
30 | + $input = preg_replace_callback('/'.$rl.'\s*section '.str_repeat($sectionParam, 6).'\s*'.$rr.'(.+?)(?:'.$rl.'\s*sectionelse\s*'.$rr.'(.+?))?'.$rl.'\s*\/section\s*'.$rr.'/is', array($this, 'convertSection'), $input); |
|
31 | + $input = str_replace('$smarty.section.', '$smarty.for.', $input); |
|
32 | 32 | |
33 | - $smarty = array( |
|
34 | - '/'.$rl.'\s*ldelim\s*'.$rr.'/', |
|
35 | - '/'.$rl.'\s*rdelim\s*'.$rr.'/', |
|
36 | - '/'.$rl.'\s*\$smarty\.ldelim\s*'.$rr.'/', |
|
37 | - '/'.$rl.'\s*\$smarty\.rdelim\s*'.$rr.'/', |
|
38 | - '/\$smarty\./', |
|
39 | - '/'.$rl.'\s*php\s*'.$rr.'/', |
|
40 | - '/'.$rl.'\s*\/php\s*'.$rr.'/', |
|
41 | - '/\|(@?)strip(\||'.$rr.')/', |
|
42 | - '/'.$rl.'\s*sectionelse\s*'.$rr.'/', |
|
43 | - ); |
|
33 | + $smarty = array( |
|
34 | + '/'.$rl.'\s*ldelim\s*'.$rr.'/', |
|
35 | + '/'.$rl.'\s*rdelim\s*'.$rr.'/', |
|
36 | + '/'.$rl.'\s*\$smarty\.ldelim\s*'.$rr.'/', |
|
37 | + '/'.$rl.'\s*\$smarty\.rdelim\s*'.$rr.'/', |
|
38 | + '/\$smarty\./', |
|
39 | + '/'.$rl.'\s*php\s*'.$rr.'/', |
|
40 | + '/'.$rl.'\s*\/php\s*'.$rr.'/', |
|
41 | + '/\|(@?)strip(\||'.$rr.')/', |
|
42 | + '/'.$rl.'\s*sectionelse\s*'.$rr.'/', |
|
43 | + ); |
|
44 | 44 | |
45 | - $dwoo = array( |
|
46 | - '\\'.$l, |
|
47 | - $r, |
|
48 | - '\\'.$l, |
|
49 | - $r, |
|
50 | - '$dwoo.', |
|
51 | - '<?php ', |
|
52 | - ' ?>', |
|
53 | - '|$1whitespace$2', |
|
54 | - $l.'else'.$r, |
|
55 | - ); |
|
45 | + $dwoo = array( |
|
46 | + '\\'.$l, |
|
47 | + $r, |
|
48 | + '\\'.$l, |
|
49 | + $r, |
|
50 | + '$dwoo.', |
|
51 | + '<?php ', |
|
52 | + ' ?>', |
|
53 | + '|$1whitespace$2', |
|
54 | + $l.'else'.$r, |
|
55 | + ); |
|
56 | 56 | |
57 | - if (preg_match('{\|@([a-z][a-z0-9_]*)}i', $input, $matches)) { |
|
58 | - trigger_error('The Smarty Compatibility Module has detected that you use |@'.$matches[1].' in your template, this might lead to problems as Dwoo interprets the @ operator differently than Smarty, see http://wiki.dwoo.org/index.php/Syntax#The_.40_Operator', E_USER_NOTICE); |
|
59 | - } |
|
57 | + if (preg_match('{\|@([a-z][a-z0-9_]*)}i', $input, $matches)) { |
|
58 | + trigger_error('The Smarty Compatibility Module has detected that you use |@'.$matches[1].' in your template, this might lead to problems as Dwoo interprets the @ operator differently than Smarty, see http://wiki.dwoo.org/index.php/Syntax#The_.40_Operator', E_USER_NOTICE); |
|
59 | + } |
|
60 | 60 | |
61 | - return preg_replace($smarty, $dwoo, $input); |
|
62 | - } |
|
61 | + return preg_replace($smarty, $dwoo, $input); |
|
62 | + } |
|
63 | 63 | |
64 | - protected function convertSection(array $matches) |
|
65 | - { |
|
66 | - $params = array(); |
|
67 | - $index = 1; |
|
68 | - while (!empty($matches[$index]) && $index < 13) { |
|
69 | - $params[$matches[$index]] = $matches[$index + 1]; |
|
70 | - $index += 2; |
|
71 | - } |
|
64 | + protected function convertSection(array $matches) |
|
65 | + { |
|
66 | + $params = array(); |
|
67 | + $index = 1; |
|
68 | + while (!empty($matches[$index]) && $index < 13) { |
|
69 | + $params[$matches[$index]] = $matches[$index + 1]; |
|
70 | + $index += 2; |
|
71 | + } |
|
72 | 72 | |
73 | - return str_replace('['.trim($params['name'], '"\'').']', '[$'.trim($params['name'], '"\'').']', $matches[0]); |
|
74 | - } |
|
73 | + return str_replace('['.trim($params['name'], '"\'').']', '[$'.trim($params['name'], '"\'').']', $matches[0]); |
|
74 | + } |
|
75 | 75 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | $params = array(); |
67 | 67 | $index = 1; |
68 | 68 | while (!empty($matches[$index]) && $index < 13) { |
69 | - $params[$matches[$index]] = $matches[$index + 1]; |
|
69 | + $params[$matches[$index]] = $matches[$index+1]; |
|
70 | 70 | $index += 2; |
71 | 71 | } |
72 | 72 |