@@ -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 |
@@ -22,72 +22,72 @@ |
||
22 | 22 | */ |
23 | 23 | class Dwoo_Plugin_template extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block |
24 | 24 | { |
25 | - public function init($name, array $rest = array()) |
|
26 | - { |
|
27 | - } |
|
25 | + public function init($name, array $rest = array()) |
|
26 | + { |
|
27 | + } |
|
28 | 28 | |
29 | - public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
30 | - { |
|
31 | - $params = $compiler->getCompiledParams($params); |
|
32 | - $parsedParams = array(); |
|
33 | - if (!isset($params['*'])) { |
|
34 | - $params['*'] = array(); |
|
35 | - } |
|
36 | - foreach ($params['*'] as $param => $defValue) { |
|
37 | - if (is_numeric($param)) { |
|
38 | - $param = $defValue; |
|
39 | - $defValue = null; |
|
40 | - } |
|
41 | - $param = trim($param, '\'"'); |
|
42 | - if (!preg_match('#^[a-z0-9_]+$#i', $param)) { |
|
43 | - throw new Dwoo_Compilation_Exception($compiler, 'Function : parameter names must contain only A-Z, 0-9 or _'); |
|
44 | - } |
|
45 | - $parsedParams[$param] = $defValue; |
|
46 | - } |
|
47 | - $params['name'] = substr($params['name'], 1, -1); |
|
48 | - $params['*'] = $parsedParams; |
|
49 | - $params['uuid'] = uniqid(); |
|
50 | - $compiler->addTemplatePlugin($params['name'], $parsedParams, $params['uuid']); |
|
51 | - $currentBlock = &$compiler->getCurrentBlock(); |
|
52 | - $currentBlock['params'] = $params; |
|
29 | + public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
|
30 | + { |
|
31 | + $params = $compiler->getCompiledParams($params); |
|
32 | + $parsedParams = array(); |
|
33 | + if (!isset($params['*'])) { |
|
34 | + $params['*'] = array(); |
|
35 | + } |
|
36 | + foreach ($params['*'] as $param => $defValue) { |
|
37 | + if (is_numeric($param)) { |
|
38 | + $param = $defValue; |
|
39 | + $defValue = null; |
|
40 | + } |
|
41 | + $param = trim($param, '\'"'); |
|
42 | + if (!preg_match('#^[a-z0-9_]+$#i', $param)) { |
|
43 | + throw new Dwoo_Compilation_Exception($compiler, 'Function : parameter names must contain only A-Z, 0-9 or _'); |
|
44 | + } |
|
45 | + $parsedParams[$param] = $defValue; |
|
46 | + } |
|
47 | + $params['name'] = substr($params['name'], 1, -1); |
|
48 | + $params['*'] = $parsedParams; |
|
49 | + $params['uuid'] = uniqid(); |
|
50 | + $compiler->addTemplatePlugin($params['name'], $parsedParams, $params['uuid']); |
|
51 | + $currentBlock = &$compiler->getCurrentBlock(); |
|
52 | + $currentBlock['params'] = $params; |
|
53 | 53 | |
54 | - return ''; |
|
55 | - } |
|
54 | + return ''; |
|
55 | + } |
|
56 | 56 | |
57 | - public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
58 | - { |
|
59 | - $paramstr = 'Dwoo_Core $dwoo'; |
|
60 | - $init = 'static $_callCnt = 0;'."\n". |
|
61 | - '$dwoo->scope[\' '.$params['uuid'].'\'.$_callCnt] = array();'."\n". |
|
62 | - '$_scope = $dwoo->setScope(array(\' '.$params['uuid'].'\'.($_callCnt++)));'."\n"; |
|
63 | - $cleanup = '/* -- template end output */ $dwoo->setScope($_scope, true);'; |
|
64 | - foreach ($params['*'] as $param => $defValue) { |
|
65 | - if ($defValue === null) { |
|
66 | - $paramstr .= ', $'.$param; |
|
67 | - } else { |
|
68 | - $paramstr .= ', $'.$param.' = '.$defValue; |
|
69 | - } |
|
70 | - $init .= '$dwoo->scope[\''.$param.'\'] = $'.$param.";\n"; |
|
71 | - } |
|
72 | - $init .= '/* -- template start output */'; |
|
57 | + public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) |
|
58 | + { |
|
59 | + $paramstr = 'Dwoo_Core $dwoo'; |
|
60 | + $init = 'static $_callCnt = 0;'."\n". |
|
61 | + '$dwoo->scope[\' '.$params['uuid'].'\'.$_callCnt] = array();'."\n". |
|
62 | + '$_scope = $dwoo->setScope(array(\' '.$params['uuid'].'\'.($_callCnt++)));'."\n"; |
|
63 | + $cleanup = '/* -- template end output */ $dwoo->setScope($_scope, true);'; |
|
64 | + foreach ($params['*'] as $param => $defValue) { |
|
65 | + if ($defValue === null) { |
|
66 | + $paramstr .= ', $'.$param; |
|
67 | + } else { |
|
68 | + $paramstr .= ', $'.$param.' = '.$defValue; |
|
69 | + } |
|
70 | + $init .= '$dwoo->scope[\''.$param.'\'] = $'.$param.";\n"; |
|
71 | + } |
|
72 | + $init .= '/* -- template start output */'; |
|
73 | 73 | |
74 | - $funcName = 'Dwoo_Plugin_'.$params['name']; |
|
74 | + $funcName = 'Dwoo_Plugin_'.$params['name']; |
|
75 | 75 | |
76 | - $search = array( |
|
77 | - '$this->charset', |
|
78 | - '$this->', |
|
79 | - '$this,', |
|
80 | - ); |
|
81 | - $replacement = array( |
|
82 | - '$dwoo->getCharset()', |
|
83 | - '$dwoo->', |
|
84 | - '$dwoo,', |
|
85 | - ); |
|
86 | - $content = str_replace($search, $replacement, $content); |
|
76 | + $search = array( |
|
77 | + '$this->charset', |
|
78 | + '$this->', |
|
79 | + '$this,', |
|
80 | + ); |
|
81 | + $replacement = array( |
|
82 | + '$dwoo->getCharset()', |
|
83 | + '$dwoo->', |
|
84 | + '$dwoo,', |
|
85 | + ); |
|
86 | + $content = str_replace($search, $replacement, $content); |
|
87 | 87 | |
88 | - $body = 'if (!function_exists(\''.$funcName."')) {\nfunction ".$funcName.'('.$paramstr.') {'."\n$init".Dwoo_Compiler::PHP_CLOSE. |
|
89 | - $prepend.$content.$append. |
|
90 | - Dwoo_Compiler::PHP_OPEN.$cleanup."\n}\n}"; |
|
91 | - $compiler->addTemplatePlugin($params['name'], $params['*'], $params['uuid'], $body); |
|
92 | - } |
|
88 | + $body = 'if (!function_exists(\''.$funcName."')) {\nfunction ".$funcName.'('.$paramstr.') {'."\n$init".Dwoo_Compiler::PHP_CLOSE. |
|
89 | + $prepend.$content.$append. |
|
90 | + Dwoo_Compiler::PHP_OPEN.$cleanup."\n}\n}"; |
|
91 | + $compiler->addTemplatePlugin($params['name'], $params['*'], $params['uuid'], $body); |
|
92 | + } |
|
93 | 93 | } |