@@ -28,92 +28,92 @@ |
||
28 | 28 | */ |
29 | 29 | abstract class Plugin extends DwooPlugin |
30 | 30 | { |
31 | - /** |
|
32 | - * Stores the contents of the block while it runs. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $buffer = ''; |
|
31 | + /** |
|
32 | + * Stores the contents of the block while it runs. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $buffer = ''; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Buffers input, override only if necessary. |
|
40 | - * |
|
41 | - * @var string the content that must be buffered |
|
42 | - */ |
|
43 | - public function buffer($input) |
|
44 | - { |
|
45 | - $this->buffer .= $input; |
|
46 | - } |
|
38 | + /** |
|
39 | + * Buffers input, override only if necessary. |
|
40 | + * |
|
41 | + * @var string the content that must be buffered |
|
42 | + */ |
|
43 | + public function buffer($input) |
|
44 | + { |
|
45 | + $this->buffer .= $input; |
|
46 | + } |
|
47 | 47 | |
48 | - // initialization code, receives the parameters from {block param1 param2} |
|
49 | - // public function init($arg, $arg, ...); |
|
48 | + // initialization code, receives the parameters from {block param1 param2} |
|
49 | + // public function init($arg, $arg, ...); |
|
50 | 50 | |
51 | - /** |
|
52 | - * Called when the block ends, this is most of the time followed right away by a call |
|
53 | - * of <em>process()</em> but not always, so this should be used to do any shutdown operations on the |
|
54 | - * block object, if required. |
|
55 | - */ |
|
56 | - public function end() |
|
57 | - { |
|
58 | - } |
|
51 | + /** |
|
52 | + * Called when the block ends, this is most of the time followed right away by a call |
|
53 | + * of <em>process()</em> but not always, so this should be used to do any shutdown operations on the |
|
54 | + * block object, if required. |
|
55 | + */ |
|
56 | + public function end() |
|
57 | + { |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Called when the block output is required by a parent block. |
|
62 | - * this must read $this->buffer and return it processed |
|
63 | - * |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - public function process() |
|
67 | - { |
|
68 | - return $this->buffer; |
|
69 | - } |
|
60 | + /** |
|
61 | + * Called when the block output is required by a parent block. |
|
62 | + * this must read $this->buffer and return it processed |
|
63 | + * |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + public function process() |
|
67 | + { |
|
68 | + return $this->buffer; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Called at compile time to define what the block should output in the compiled template code, happens when the |
|
73 | - * block is declared basically this will replace the {block arg arg arg} tag in the template. |
|
74 | - * |
|
75 | - * @param DwooCompiler $compiler the compiler instance that calls this function |
|
76 | - * @param array $params an array containing original and compiled parameters |
|
77 | - * @param string $prepend that is just meant to allow a child class to call |
|
78 | - * parent::postProcessing($compiler, $params, "foo();") to add a command before the |
|
79 | - * default commands are executed parent::postProcessing($compiler, $params, "foo();") |
|
80 | - * to add a command before the default commands are executed |
|
81 | - * @param string $append that is just meant to allow a child class to call |
|
82 | - * parent::postProcessing($compiler, $params, null, "foo();") to add a command after |
|
83 | - * the default commands are executed parent::postProcessing($compiler, $params, null, |
|
84 | - * "foo();") to add a command after the default commands are executed |
|
85 | - * @param string $type the type is the plugin class name used |
|
86 | - * |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public static function preProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $type) |
|
90 | - { |
|
91 | - return DwooCompiler::PHP_OPEN . $prepend . '$this->addStack("' . $type . '", array(' . DwooCompiler::implode_r($compiler->getCompiledParams($params)) . '));' . $append . DwooCompiler::PHP_CLOSE; |
|
92 | - } |
|
71 | + /** |
|
72 | + * Called at compile time to define what the block should output in the compiled template code, happens when the |
|
73 | + * block is declared basically this will replace the {block arg arg arg} tag in the template. |
|
74 | + * |
|
75 | + * @param DwooCompiler $compiler the compiler instance that calls this function |
|
76 | + * @param array $params an array containing original and compiled parameters |
|
77 | + * @param string $prepend that is just meant to allow a child class to call |
|
78 | + * parent::postProcessing($compiler, $params, "foo();") to add a command before the |
|
79 | + * default commands are executed parent::postProcessing($compiler, $params, "foo();") |
|
80 | + * to add a command before the default commands are executed |
|
81 | + * @param string $append that is just meant to allow a child class to call |
|
82 | + * parent::postProcessing($compiler, $params, null, "foo();") to add a command after |
|
83 | + * the default commands are executed parent::postProcessing($compiler, $params, null, |
|
84 | + * "foo();") to add a command after the default commands are executed |
|
85 | + * @param string $type the type is the plugin class name used |
|
86 | + * |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public static function preProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $type) |
|
90 | + { |
|
91 | + return DwooCompiler::PHP_OPEN . $prepend . '$this->addStack("' . $type . '", array(' . DwooCompiler::implode_r($compiler->getCompiledParams($params)) . '));' . $append . DwooCompiler::PHP_CLOSE; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Called at compile time to define what the block should output in the compiled template code, happens when the |
|
96 | - * block is ended basically this will replace the {/block} tag in the template. |
|
97 | - * |
|
98 | - * @see preProcessing |
|
99 | - * |
|
100 | - * @param DwooCompiler $compiler the compiler instance that calls this function |
|
101 | - * @param array $params an array containing original and compiled parameters, see preProcessing() for more |
|
102 | - * details more details |
|
103 | - * @param string $prepend that is just meant to allow a child class to call |
|
104 | - * parent::postProcessing($compiler, $params, "foo();") to add a command before the |
|
105 | - * default commands are executed parent::postProcessing($compiler, $params, "foo();") |
|
106 | - * to add a command before the default commands are executed |
|
107 | - * @param string $append that is just meant to allow a child class to call |
|
108 | - * parent::postProcessing($compiler, $params, null, "foo();") to add a command after |
|
109 | - * the default commands are executed parent::postProcessing($compiler, $params, null, |
|
110 | - * "foo();") to add a command after the default commands are executed |
|
111 | - * @param string $content the entire content of the block being closed |
|
112 | - * |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - public static function postProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $content) |
|
116 | - { |
|
117 | - return $content . DwooCompiler::PHP_OPEN . $prepend . '$this->delStack();' . $append . DwooCompiler::PHP_CLOSE; |
|
118 | - } |
|
94 | + /** |
|
95 | + * Called at compile time to define what the block should output in the compiled template code, happens when the |
|
96 | + * block is ended basically this will replace the {/block} tag in the template. |
|
97 | + * |
|
98 | + * @see preProcessing |
|
99 | + * |
|
100 | + * @param DwooCompiler $compiler the compiler instance that calls this function |
|
101 | + * @param array $params an array containing original and compiled parameters, see preProcessing() for more |
|
102 | + * details more details |
|
103 | + * @param string $prepend that is just meant to allow a child class to call |
|
104 | + * parent::postProcessing($compiler, $params, "foo();") to add a command before the |
|
105 | + * default commands are executed parent::postProcessing($compiler, $params, "foo();") |
|
106 | + * to add a command before the default commands are executed |
|
107 | + * @param string $append that is just meant to allow a child class to call |
|
108 | + * parent::postProcessing($compiler, $params, null, "foo();") to add a command after |
|
109 | + * the default commands are executed parent::postProcessing($compiler, $params, null, |
|
110 | + * "foo();") to add a command after the default commands are executed |
|
111 | + * @param string $content the entire content of the block being closed |
|
112 | + * |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + public static function postProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $content) |
|
116 | + { |
|
117 | + return $content . DwooCompiler::PHP_OPEN . $prepend . '$this->delStack();' . $append . DwooCompiler::PHP_CLOSE; |
|
118 | + } |
|
119 | 119 | } |
@@ -26,69 +26,69 @@ |
||
26 | 26 | */ |
27 | 27 | class PluginSmartyCompatible extends Processor |
28 | 28 | { |
29 | - /** |
|
30 | - * @param string $input |
|
31 | - * |
|
32 | - * @return mixed |
|
33 | - */ |
|
34 | - public function process($input) |
|
35 | - { |
|
36 | - list($l, $r) = $this->compiler->getDelimiters(); |
|
29 | + /** |
|
30 | + * @param string $input |
|
31 | + * |
|
32 | + * @return mixed |
|
33 | + */ |
|
34 | + public function process($input) |
|
35 | + { |
|
36 | + list($l, $r) = $this->compiler->getDelimiters(); |
|
37 | 37 | |
38 | - $rl = preg_quote($l, '/'); |
|
39 | - $rr = preg_quote($r, '/'); |
|
40 | - $sectionParam = '(?:(name|loop|start|step|max|show)\s*=\s*(\S+))?\s*'; |
|
41 | - $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( |
|
42 | - $this, |
|
43 | - 'convertSection' |
|
44 | - ), $input); |
|
45 | - $input = str_replace('$smarty.section.', '$smarty.for.', $input); |
|
38 | + $rl = preg_quote($l, '/'); |
|
39 | + $rr = preg_quote($r, '/'); |
|
40 | + $sectionParam = '(?:(name|loop|start|step|max|show)\s*=\s*(\S+))?\s*'; |
|
41 | + $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( |
|
42 | + $this, |
|
43 | + 'convertSection' |
|
44 | + ), $input); |
|
45 | + $input = str_replace('$smarty.section.', '$smarty.for.', $input); |
|
46 | 46 | |
47 | - $smarty = array( |
|
48 | - '/' . $rl . '\s*ldelim\s*' . $rr . '/', |
|
49 | - '/' . $rl . '\s*rdelim\s*' . $rr . '/', |
|
50 | - '/' . $rl . '\s*\$smarty\.ldelim\s*' . $rr . '/', |
|
51 | - '/' . $rl . '\s*\$smarty\.rdelim\s*' . $rr . '/', |
|
52 | - '/\$smarty\./', |
|
53 | - '/' . $rl . '\s*php\s*' . $rr . '/', |
|
54 | - '/' . $rl . '\s*\/php\s*' . $rr . '/', |
|
55 | - '/\|(@?)strip(\||' . $rr . ')/', |
|
56 | - '/' . $rl . '\s*sectionelse\s*' . $rr . '/', |
|
57 | - ); |
|
47 | + $smarty = array( |
|
48 | + '/' . $rl . '\s*ldelim\s*' . $rr . '/', |
|
49 | + '/' . $rl . '\s*rdelim\s*' . $rr . '/', |
|
50 | + '/' . $rl . '\s*\$smarty\.ldelim\s*' . $rr . '/', |
|
51 | + '/' . $rl . '\s*\$smarty\.rdelim\s*' . $rr . '/', |
|
52 | + '/\$smarty\./', |
|
53 | + '/' . $rl . '\s*php\s*' . $rr . '/', |
|
54 | + '/' . $rl . '\s*\/php\s*' . $rr . '/', |
|
55 | + '/\|(@?)strip(\||' . $rr . ')/', |
|
56 | + '/' . $rl . '\s*sectionelse\s*' . $rr . '/', |
|
57 | + ); |
|
58 | 58 | |
59 | - $dwoo = array( |
|
60 | - '\\' . $l, |
|
61 | - $r, |
|
62 | - '\\' . $l, |
|
63 | - $r, |
|
64 | - '$dwoo.', |
|
65 | - '<?php ', |
|
66 | - ' ?>', |
|
67 | - '|$1whitespace$2', |
|
68 | - $l . 'else' . $r, |
|
69 | - ); |
|
59 | + $dwoo = array( |
|
60 | + '\\' . $l, |
|
61 | + $r, |
|
62 | + '\\' . $l, |
|
63 | + $r, |
|
64 | + '$dwoo.', |
|
65 | + '<?php ', |
|
66 | + ' ?>', |
|
67 | + '|$1whitespace$2', |
|
68 | + $l . 'else' . $r, |
|
69 | + ); |
|
70 | 70 | |
71 | - if (preg_match('{\|@([a-z][a-z0-9_]*)}i', $input, $matches)) { |
|
72 | - 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); |
|
73 | - } |
|
71 | + if (preg_match('{\|@([a-z][a-z0-9_]*)}i', $input, $matches)) { |
|
72 | + 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); |
|
73 | + } |
|
74 | 74 | |
75 | - return preg_replace($smarty, $dwoo, $input); |
|
76 | - } |
|
75 | + return preg_replace($smarty, $dwoo, $input); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param array $matches |
|
80 | - * |
|
81 | - * @return mixed |
|
82 | - */ |
|
83 | - protected function convertSection(array $matches) |
|
84 | - { |
|
85 | - $params = array(); |
|
86 | - $index = 1; |
|
87 | - while (!empty($matches[$index]) && $index < 13) { |
|
88 | - $params[$matches[$index]] = $matches[$index + 1]; |
|
89 | - $index += 2; |
|
90 | - } |
|
78 | + /** |
|
79 | + * @param array $matches |
|
80 | + * |
|
81 | + * @return mixed |
|
82 | + */ |
|
83 | + protected function convertSection(array $matches) |
|
84 | + { |
|
85 | + $params = array(); |
|
86 | + $index = 1; |
|
87 | + while (!empty($matches[$index]) && $index < 13) { |
|
88 | + $params[$matches[$index]] = $matches[$index + 1]; |
|
89 | + $index += 2; |
|
90 | + } |
|
91 | 91 | |
92 | - return str_replace('[' . trim($params['name'], '"\'') . ']', '[$' . trim($params['name'], '"\'') . ']', $matches[0]); |
|
93 | - } |
|
92 | + return str_replace('[' . trim($params['name'], '"\'') . ']', '[$' . trim($params['name'], '"\'') . ']', $matches[0]); |
|
93 | + } |
|
94 | 94 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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,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 | } |
@@ -27,47 +27,47 @@ |
||
27 | 27 | */ |
28 | 28 | class PluginWithelse 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('with', 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('with', 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 | } |
@@ -42,54 +42,54 @@ |
||
42 | 42 | */ |
43 | 43 | class PluginCapture extends BlockPlugin implements ICompilableBlock |
44 | 44 | { |
45 | - /** |
|
46 | - * @param string $name |
|
47 | - * @param null $assign |
|
48 | - * @param bool $cat |
|
49 | - * @param bool $trim |
|
50 | - */ |
|
51 | - public function init($name = 'default', $assign = null, $cat = false, $trim = false) |
|
52 | - { |
|
53 | - } |
|
45 | + /** |
|
46 | + * @param string $name |
|
47 | + * @param null $assign |
|
48 | + * @param bool $cat |
|
49 | + * @param bool $trim |
|
50 | + */ |
|
51 | + public function init($name = 'default', $assign = null, $cat = false, $trim = false) |
|
52 | + { |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param Compiler $compiler |
|
57 | - * @param array $params |
|
58 | - * @param string $prepend |
|
59 | - * @param string $append |
|
60 | - * @param string $type |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
65 | - { |
|
66 | - return Compiler::PHP_OPEN . $prepend . 'ob_start();' . $append . Compiler::PHP_CLOSE; |
|
67 | - } |
|
55 | + /** |
|
56 | + * @param Compiler $compiler |
|
57 | + * @param array $params |
|
58 | + * @param string $prepend |
|
59 | + * @param string $append |
|
60 | + * @param string $type |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
65 | + { |
|
66 | + return Compiler::PHP_OPEN . $prepend . 'ob_start();' . $append . Compiler::PHP_CLOSE; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param Compiler $compiler |
|
71 | - * @param array $params |
|
72 | - * @param string $prepend |
|
73 | - * @param string $append |
|
74 | - * @param string $content |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
79 | - { |
|
80 | - $params = $compiler->getCompiledParams($params); |
|
69 | + /** |
|
70 | + * @param Compiler $compiler |
|
71 | + * @param array $params |
|
72 | + * @param string $prepend |
|
73 | + * @param string $append |
|
74 | + * @param string $content |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
79 | + { |
|
80 | + $params = $compiler->getCompiledParams($params); |
|
81 | 81 | |
82 | - $out = $content . Compiler::PHP_OPEN . $prepend . "\n" . '$tmp = ob_get_clean();'; |
|
83 | - if ($params['trim'] !== 'false' && $params['trim'] !== 0) { |
|
84 | - $out .= "\n" . '$tmp = trim($tmp);'; |
|
85 | - } |
|
86 | - if ($params['cat'] === 'true' || $params['cat'] === 1) { |
|
87 | - $out .= "\n" . '$tmp = $this->readVar(\'dwoo.capture.\'.' . $params['name'] . ') . $tmp;'; |
|
88 | - } |
|
89 | - if ($params['assign'] !== 'null') { |
|
90 | - $out .= "\n" . '$this->scope[' . $params['assign'] . '] = $tmp;'; |
|
91 | - } |
|
82 | + $out = $content . Compiler::PHP_OPEN . $prepend . "\n" . '$tmp = ob_get_clean();'; |
|
83 | + if ($params['trim'] !== 'false' && $params['trim'] !== 0) { |
|
84 | + $out .= "\n" . '$tmp = trim($tmp);'; |
|
85 | + } |
|
86 | + if ($params['cat'] === 'true' || $params['cat'] === 1) { |
|
87 | + $out .= "\n" . '$tmp = $this->readVar(\'dwoo.capture.\'.' . $params['name'] . ') . $tmp;'; |
|
88 | + } |
|
89 | + if ($params['assign'] !== 'null') { |
|
90 | + $out .= "\n" . '$this->scope[' . $params['assign'] . '] = $tmp;'; |
|
91 | + } |
|
92 | 92 | |
93 | - return $out . "\n" . '$this->globals[\'capture\'][' . $params['name'] . '] = $tmp;' . $append . Compiler::PHP_CLOSE; |
|
94 | - } |
|
93 | + return $out . "\n" . '$this->globals[\'capture\'][' . $params['name'] . '] = $tmp;' . $append . Compiler::PHP_CLOSE; |
|
94 | + } |
|
95 | 95 | } |
@@ -28,68 +28,68 @@ |
||
28 | 28 | */ |
29 | 29 | class PluginElseif extends PluginIf implements ICompilableBlock, IElseable |
30 | 30 | { |
31 | - /** |
|
32 | - * @param array $rest |
|
33 | - */ |
|
34 | - public function init(array $rest) |
|
35 | - { |
|
36 | - } |
|
31 | + /** |
|
32 | + * @param array $rest |
|
33 | + */ |
|
34 | + public function init(array $rest) |
|
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 | - $preContent = ''; |
|
50 | - while (true) { |
|
51 | - $preContent .= $compiler->removeTopBlock(); |
|
52 | - $block = &$compiler->getCurrentBlock(); |
|
53 | - $interfaces = class_implements($block['class']); |
|
54 | - if (in_array('Dwoo\IElseable', $interfaces) !== false) { |
|
55 | - break; |
|
56 | - } |
|
57 | - } |
|
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 | + $preContent = ''; |
|
50 | + while (true) { |
|
51 | + $preContent .= $compiler->removeTopBlock(); |
|
52 | + $block = &$compiler->getCurrentBlock(); |
|
53 | + $interfaces = class_implements($block['class']); |
|
54 | + if (in_array('Dwoo\IElseable', $interfaces) !== false) { |
|
55 | + break; |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - $params['initialized'] = true; |
|
60 | - $compiler->injectBlock($type, $params); |
|
59 | + $params['initialized'] = true; |
|
60 | + $compiler->injectBlock($type, $params); |
|
61 | 61 | |
62 | - return $preContent; |
|
63 | - } |
|
62 | + return $preContent; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param Compiler $compiler |
|
67 | - * @param array $params |
|
68 | - * @param string $prepend |
|
69 | - * @param string $append |
|
70 | - * @param string $content |
|
71 | - * |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
75 | - { |
|
76 | - if (!isset($params['initialized'])) { |
|
77 | - return ''; |
|
78 | - } |
|
65 | + /** |
|
66 | + * @param Compiler $compiler |
|
67 | + * @param array $params |
|
68 | + * @param string $prepend |
|
69 | + * @param string $append |
|
70 | + * @param string $content |
|
71 | + * |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
75 | + { |
|
76 | + if (!isset($params['initialized'])) { |
|
77 | + return ''; |
|
78 | + } |
|
79 | 79 | |
80 | - $tokens = $compiler->getParamTokens($params); |
|
81 | - $params = $compiler->getCompiledParams($params); |
|
80 | + $tokens = $compiler->getParamTokens($params); |
|
81 | + $params = $compiler->getCompiledParams($params); |
|
82 | 82 | |
83 | - $pre = Compiler::PHP_OPEN . 'elseif (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
84 | - $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
83 | + $pre = Compiler::PHP_OPEN . 'elseif (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
84 | + $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
85 | 85 | |
86 | - if (isset($params['hasElse'])) { |
|
87 | - $post .= $params['hasElse']; |
|
88 | - } |
|
86 | + if (isset($params['hasElse'])) { |
|
87 | + $post .= $params['hasElse']; |
|
88 | + } |
|
89 | 89 | |
90 | - $block = &$compiler->getCurrentBlock(); |
|
91 | - $block['params']['hasElse'] = $pre . $content . $post; |
|
90 | + $block = &$compiler->getCurrentBlock(); |
|
91 | + $block['params']['hasElse'] = $pre . $content . $post; |
|
92 | 92 | |
93 | - return ''; |
|
94 | - } |
|
93 | + return ''; |
|
94 | + } |
|
95 | 95 | } |