@@ -40,16 +40,16 @@ discard block |
||
40 | 40 | */ |
41 | 41 | class Dwoo_Plugin_loop extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block, Dwoo_IElseable |
42 | 42 | { |
43 | - public static $cnt=0; |
|
43 | + public static $cnt = 0; |
|
44 | 44 | |
45 | - public function init($from, $name='default') |
|
45 | + public function init($from, $name = 'default') |
|
46 | 46 | { |
47 | 47 | } |
48 | 48 | |
49 | 49 | public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
50 | 50 | { |
51 | 51 | // get block params and save the current template pointer to use it in the postProcessing method |
52 | - $currentBlock =& $compiler->getCurrentBlock(); |
|
52 | + $currentBlock = & $compiler->getCurrentBlock(); |
|
53 | 53 | $currentBlock['params']['tplPointer'] = $compiler->getPointer(); |
54 | 54 | |
55 | 55 | return ''; |
@@ -83,17 +83,17 @@ discard block |
||
83 | 83 | $cnt = self::$cnt++; |
84 | 84 | |
85 | 85 | // builds pre processing output |
86 | - $pre = Dwoo_Compiler::PHP_OPEN . "\n".'$_loop'.$cnt.'_data = '.$src.';'; |
|
86 | + $pre = Dwoo_Compiler::PHP_OPEN."\n".'$_loop'.$cnt.'_data = '.$src.';'; |
|
87 | 87 | // adds foreach properties |
88 | 88 | if ($usesAny) { |
89 | 89 | $pre .= "\n".'$this->globals["loop"]['.$name.'] = array'."\n("; |
90 | - if ($usesIndex) $pre .="\n\t".'"index" => 0,'; |
|
91 | - if ($usesIteration) $pre .="\n\t".'"iteration" => 1,'; |
|
92 | - if ($usesFirst) $pre .="\n\t".'"first" => null,'; |
|
93 | - if ($usesLast) $pre .="\n\t".'"last" => null,'; |
|
94 | - if ($usesShow) $pre .="\n\t".'"show" => $this->isTraversable($_loop'.$cnt.'_data, true),'; |
|
95 | - if ($usesTotal) $pre .="\n\t".'"total" => $this->count($_loop'.$cnt.'_data),'; |
|
96 | - $pre.="\n);\n".'$_loop'.$cnt.'_glob =& $this->globals["loop"]['.$name.'];'; |
|
90 | + if ($usesIndex) $pre .= "\n\t".'"index" => 0,'; |
|
91 | + if ($usesIteration) $pre .= "\n\t".'"iteration" => 1,'; |
|
92 | + if ($usesFirst) $pre .= "\n\t".'"first" => null,'; |
|
93 | + if ($usesLast) $pre .= "\n\t".'"last" => null,'; |
|
94 | + if ($usesShow) $pre .= "\n\t".'"show" => $this->isTraversable($_loop'.$cnt.'_data, true),'; |
|
95 | + if ($usesTotal) $pre .= "\n\t".'"total" => $this->count($_loop'.$cnt.'_data),'; |
|
96 | + $pre .= "\n);\n".'$_loop'.$cnt.'_glob =& $this->globals["loop"]['.$name.'];'; |
|
97 | 97 | } |
98 | 98 | // checks if the loop must be looped |
99 | 99 | $pre .= "\n".'if ($this->isTraversable($_loop'.$cnt.'_data'.(isset($params['hasElse']) ? ', true' : '').') == true)'."\n{"; |
@@ -106,23 +106,23 @@ discard block |
||
106 | 106 | if ($usesLast) { |
107 | 107 | $pre .= "\n\t\t".'$_loop'.$cnt.'_glob["last"] = (string) ($_loop'.$cnt.'_glob["iteration"] === $_loop'.$cnt.'_glob["total"]);'; |
108 | 108 | } |
109 | - $pre .= "\n\t\t".'$_loop'.$cnt.'_scope = $this->setScope(array("-loop-"));' . "\n/* -- loop start output */\n".Dwoo_Compiler::PHP_CLOSE; |
|
109 | + $pre .= "\n\t\t".'$_loop'.$cnt.'_scope = $this->setScope(array("-loop-"));'."\n/* -- loop start output */\n".Dwoo_Compiler::PHP_CLOSE; |
|
110 | 110 | |
111 | 111 | // build post processing output and cache it |
112 | - $post = Dwoo_Compiler::PHP_OPEN . "\n".'/* -- loop end output */'."\n\t\t".'$this->setScope($_loop'.$cnt.'_scope, true);'; |
|
112 | + $post = Dwoo_Compiler::PHP_OPEN."\n".'/* -- loop end output */'."\n\t\t".'$this->setScope($_loop'.$cnt.'_scope, true);'; |
|
113 | 113 | // update properties |
114 | 114 | if ($usesIndex) { |
115 | - $post.="\n\t\t".'$_loop'.$cnt.'_glob["index"]+=1;'; |
|
115 | + $post .= "\n\t\t".'$_loop'.$cnt.'_glob["index"]+=1;'; |
|
116 | 116 | } |
117 | 117 | if ($usesIteration) { |
118 | - $post.="\n\t\t".'$_loop'.$cnt.'_glob["iteration"]+=1;'; |
|
118 | + $post .= "\n\t\t".'$_loop'.$cnt.'_glob["iteration"]+=1;'; |
|
119 | 119 | } |
120 | 120 | // end loop |
121 | - $post .= "\n\t}\n}\n" . Dwoo_Compiler::PHP_CLOSE; |
|
121 | + $post .= "\n\t}\n}\n".Dwoo_Compiler::PHP_CLOSE; |
|
122 | 122 | if (isset($params['hasElse'])) { |
123 | 123 | $post .= $params['hasElse']; |
124 | 124 | } |
125 | 125 | |
126 | - return $pre . $content . $post; |
|
126 | + return $pre.$content.$post; |
|
127 | 127 | } |
128 | 128 | } |
@@ -87,12 +87,24 @@ |
||
87 | 87 | // adds foreach properties |
88 | 88 | if ($usesAny) { |
89 | 89 | $pre .= "\n".'$this->globals["loop"]['.$name.'] = array'."\n("; |
90 | - if ($usesIndex) $pre .="\n\t".'"index" => 0,'; |
|
91 | - if ($usesIteration) $pre .="\n\t".'"iteration" => 1,'; |
|
92 | - if ($usesFirst) $pre .="\n\t".'"first" => null,'; |
|
93 | - if ($usesLast) $pre .="\n\t".'"last" => null,'; |
|
94 | - if ($usesShow) $pre .="\n\t".'"show" => $this->isTraversable($_loop'.$cnt.'_data, true),'; |
|
95 | - if ($usesTotal) $pre .="\n\t".'"total" => $this->count($_loop'.$cnt.'_data),'; |
|
90 | + if ($usesIndex) { |
|
91 | + $pre .="\n\t".'"index" => 0,'; |
|
92 | + } |
|
93 | + if ($usesIteration) { |
|
94 | + $pre .="\n\t".'"iteration" => 1,'; |
|
95 | + } |
|
96 | + if ($usesFirst) { |
|
97 | + $pre .="\n\t".'"first" => null,'; |
|
98 | + } |
|
99 | + if ($usesLast) { |
|
100 | + $pre .="\n\t".'"last" => null,'; |
|
101 | + } |
|
102 | + if ($usesShow) { |
|
103 | + $pre .="\n\t".'"show" => $this->isTraversable($_loop'.$cnt.'_data, true),'; |
|
104 | + } |
|
105 | + if ($usesTotal) { |
|
106 | + $pre .="\n\t".'"total" => $this->count($_loop'.$cnt.'_data),'; |
|
107 | + } |
|
96 | 108 | $pre.="\n);\n".'$_loop'.$cnt.'_glob =& $this->globals["loop"]['.$name.'];'; |
97 | 109 | } |
98 | 110 | // checks if the loop must be looped |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) |
24 | 24 | { |
25 | - $with =& $compiler->findBlock('with', true); |
|
25 | + $with = & $compiler->findBlock('with', true); |
|
26 | 26 | |
27 | 27 | $params['initialized'] = true; |
28 | 28 | $compiler->injectBlock($type, $params); |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | return ''; |
37 | 37 | } |
38 | 38 | |
39 | - $block =& $compiler->getCurrentBlock(); |
|
40 | - $block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE . $content . Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE; |
|
39 | + $block = & $compiler->getCurrentBlock(); |
|
40 | + $block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE; |
|
41 | 41 | return ''; |
42 | 42 | } |
43 | 43 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | * @date 2008-10-23 |
24 | 24 | * @package Dwoo |
25 | 25 | */ |
26 | -function Dwoo_Plugin_array_compile(Dwoo_Compiler $compiler, array $rest=array()) |
|
26 | +function Dwoo_Plugin_array_compile(Dwoo_Compiler $compiler, array $rest = array()) |
|
27 | 27 | { |
28 | 28 | $out = array(); |
29 | 29 | foreach ($rest as $key => $value) { |
@@ -21,14 +21,13 @@ discard block |
||
21 | 21 | { |
22 | 22 | list($l, $r) = $this->compiler->getDelimiters(); |
23 | 23 | |
24 | - $rl = preg_quote($l,'/'); |
|
25 | - $rr = preg_quote($r,'/'); |
|
24 | + $rl = preg_quote($l, '/'); |
|
25 | + $rr = preg_quote($r, '/'); |
|
26 | 26 | $sectionParam = '(?:(name|loop|start|step|max|show)\s*=\s*(\S+))?\s*'; |
27 | 27 | $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); |
28 | 28 | $input = str_replace('$smarty.section.', '$smarty.for.', $input); |
29 | 29 | |
30 | - $smarty = array |
|
31 | - ( |
|
30 | + $smarty = array( |
|
32 | 31 | '/'.$rl.'\s*ldelim\s*'.$rr.'/', |
33 | 32 | '/'.$rl.'\s*rdelim\s*'.$rr.'/', |
34 | 33 | '/'.$rl.'\s*\$smarty\.ldelim\s*'.$rr.'/', |
@@ -40,8 +39,7 @@ discard block |
||
40 | 39 | '/'.$rl.'\s*sectionelse\s*'.$rr.'/', |
41 | 40 | ); |
42 | 41 | |
43 | - $dwoo = array |
|
44 | - ( |
|
42 | + $dwoo = array( |
|
45 | 43 | '\\'.$l, |
46 | 44 | $r, |
47 | 45 | '\\'.$l, |
@@ -18,16 +18,16 @@ discard block |
||
18 | 18 | * @date 2008-12-24 |
19 | 19 | * @package Dwoo |
20 | 20 | */ |
21 | -function Dwoo_Plugin_date_format(Dwoo_Core $dwoo, $value, $format='%b %e, %Y', $default=null) |
|
21 | +function Dwoo_Plugin_date_format(Dwoo_Core $dwoo, $value, $format = '%b %e, %Y', $default = null) |
|
22 | 22 | { |
23 | 23 | if (!empty($value)) { |
24 | 24 | // convert if it's not a valid unix timestamp |
25 | - if (preg_match('#^-?\d{1,10}$#', $value)===0) { |
|
25 | + if (preg_match('#^-?\d{1,10}$#', $value) === 0) { |
|
26 | 26 | $value = strtotime($value); |
27 | 27 | } |
28 | 28 | } elseif (!empty($default)) { |
29 | 29 | // convert if it's not a valid unix timestamp |
30 | - if (preg_match('#^-?\d{1,10}$#', $default)===0) { |
|
30 | + if (preg_match('#^-?\d{1,10}$#', $default) === 0) { |
|
31 | 31 | $value = strtotime($default); |
32 | 32 | } else { |
33 | 33 | $value = $default; |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | // Credits for that windows compat block to Monte Ohrt who made smarty's date_format plugin |
40 | 40 | if (DIRECTORY_SEPARATOR == '\\') { |
41 | - $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T'); |
|
41 | + $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T'); |
|
42 | 42 | $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S'); |
43 | 43 | if (strpos($format, '%e') !== false) { |
44 | 44 | $_win_from[] = '%e'; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | $out .= $this->export($var, $scope); |
54 | 54 | |
55 | - return $out .'</div></div>'; |
|
55 | + return $out.'</div></div>'; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | protected function export($var, $scope) |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | $out = ''; |
61 | 61 | foreach ($var as $i=>$v) { |
62 | 62 | if (is_array($v) || (is_object($v) && $v instanceof Iterator)) { |
63 | - $out .= $i.' ('.(is_array($v) ? 'array':'object: '.get_class($v)).')'; |
|
64 | - if ($v===$scope) { |
|
63 | + $out .= $i.' ('.(is_array($v) ? 'array' : 'object: '.get_class($v)).')'; |
|
64 | + if ($v === $scope) { |
|
65 | 65 | $out .= ' (current scope):<div style="background:#ccc;padding-left:20px;">'.$this->export($v, $scope).'</div>'; |
66 | 66 | } else { |
67 | 67 | $out .= ':<div style="padding-left:20px;">'.$this->export($v, $scope).'</div>'; |
@@ -91,14 +91,14 @@ discard block |
||
91 | 91 | protected function exportObj($i, $obj) |
92 | 92 | { |
93 | 93 | if (array_search($obj, $this->outputObjects, true) !== false) { |
94 | - return $i . ' [recursion, skipped]<br />'; |
|
94 | + return $i.' [recursion, skipped]<br />'; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | $this->outputObjects[] = $obj; |
98 | 98 | |
99 | 99 | $list = (array) $obj; |
100 | 100 | |
101 | - $protectedLength = strlen(get_class($obj)) + 2; |
|
101 | + $protectedLength = strlen(get_class($obj))+2; |
|
102 | 102 | |
103 | 103 | $out = array(); |
104 | 104 | |
@@ -116,17 +116,17 @@ discard block |
||
116 | 116 | |
117 | 117 | $params = array(); |
118 | 118 | foreach ($method->getParameters() as $param) { |
119 | - $params[] = ($param->isPassedByReference() ? '&':'') . '$'.$param->getName() . ($param->isOptional() ? ' = '.var_export($param->getDefaultValue(), true) : ''); |
|
119 | + $params[] = ($param->isPassedByReference() ? '&' : '').'$'.$param->getName().($param->isOptional() ? ' = '.var_export($param->getDefaultValue(), true) : ''); |
|
120 | 120 | } |
121 | 121 | |
122 | - $out['method'] .= '(method) ' . $method->getName() .'('.implode(', ', $params).')<br />'; |
|
122 | + $out['method'] .= '(method) '.$method->getName().'('.implode(', ', $params).')<br />'; |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | 126 | foreach ($list as $attributeName => $attributeValue) { |
127 | - if(property_exists($obj, $attributeName)) { |
|
127 | + if (property_exists($obj, $attributeName)) { |
|
128 | 128 | $key = 'public'; |
129 | - } elseif(substr($attributeName, 0, 3) === "\0*\0") { |
|
129 | + } elseif (substr($attributeName, 0, 3) === "\0*\0") { |
|
130 | 130 | $key = 'protected'; |
131 | 131 | $attributeName = substr($attributeName, 3); |
132 | 132 | } else { |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
153 | - $return = $i . '<br /><div style="padding-left:20px;">'; |
|
153 | + $return = $i.'<br /><div style="padding-left:20px;">'; |
|
154 | 154 | |
155 | 155 | if (!empty($out['method'])) { |
156 | 156 | $return .= $out['method']; |
@@ -168,6 +168,6 @@ discard block |
||
168 | 168 | $return .= $out['private']; |
169 | 169 | } |
170 | 170 | |
171 | - return $return . '</div>'; |
|
171 | + return $return.'</div>'; |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | \ No newline at end of file |
@@ -17,7 +17,7 @@ |
||
17 | 17 | * @date 2008-10-23 |
18 | 18 | * @package Dwoo |
19 | 19 | */ |
20 | -function Dwoo_Plugin_spacify_compile(Dwoo_Compiler $compiler, $value, $space_char=' ') |
|
20 | +function Dwoo_Plugin_spacify_compile(Dwoo_Compiler $compiler, $value, $space_char = ' ') |
|
21 | 21 | { |
22 | 22 | return 'implode('.$space_char.', str_split('.$value.', 1))'; |
23 | 23 | } |
@@ -18,13 +18,13 @@ discard block |
||
18 | 18 | * @date 2008-10-23 |
19 | 19 | * @package Dwoo |
20 | 20 | */ |
21 | -function Dwoo_Plugin_escape(Dwoo_Core $dwoo, $value='', $format='html', $charset=null) |
|
21 | +function Dwoo_Plugin_escape(Dwoo_Core $dwoo, $value = '', $format = 'html', $charset = null) |
|
22 | 22 | { |
23 | 23 | if ($charset === null) { |
24 | 24 | $charset = $dwoo->getCharset(); |
25 | 25 | } |
26 | 26 | |
27 | - switch($format) |
|
27 | + switch ($format) |
|
28 | 28 | { |
29 | 29 | |
30 | 30 | case 'html': |
@@ -40,18 +40,18 @@ discard block |
||
40 | 40 | case 'hex': |
41 | 41 | $out = ''; |
42 | 42 | $cnt = strlen((string) $value); |
43 | - for ($i=0; $i < $cnt; $i++) { |
|
44 | - $out .= '%' . bin2hex((string) $value[$i]); |
|
43 | + for ($i = 0; $i < $cnt; $i++) { |
|
44 | + $out .= '%'.bin2hex((string) $value[$i]); |
|
45 | 45 | } |
46 | 46 | return $out; |
47 | 47 | case 'hexentity': |
48 | 48 | $out = ''; |
49 | 49 | $cnt = strlen((string) $value); |
50 | - for ($i=0; $i < $cnt; $i++) |
|
51 | - $out .= '&#x' . bin2hex((string) $value[$i]) . ';'; |
|
50 | + for ($i = 0; $i < $cnt; $i++) |
|
51 | + $out .= '&#x'.bin2hex((string) $value[$i]).';'; |
|
52 | 52 | return $out; |
53 | 53 | case 'javascript': |
54 | - return strtr((string) $value, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/')); |
|
54 | + return strtr((string) $value, array('\\'=>'\\\\', "'"=>"\\'", '"'=>'\\"', "\r"=>'\\r', "\n"=>'\\n', '</'=>'<\/')); |
|
55 | 55 | case 'mail': |
56 | 56 | return str_replace(array('@', '.'), array(' (AT) ', ' (DOT) '), (string) $value); |
57 | 57 | default: |
@@ -47,8 +47,9 @@ |
||
47 | 47 | case 'hexentity': |
48 | 48 | $out = ''; |
49 | 49 | $cnt = strlen((string) $value); |
50 | - for ($i=0; $i < $cnt; $i++) |
|
51 | - $out .= '&#x' . bin2hex((string) $value[$i]) . ';'; |
|
50 | + for ($i=0; $i < $cnt; $i++) { |
|
51 | + $out .= '&#x' . bin2hex((string) $value[$i]) . ';'; |
|
52 | + } |
|
52 | 53 | return $out; |
53 | 54 | case 'javascript': |
54 | 55 | return strtr((string) $value, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/')); |
@@ -29,13 +29,12 @@ discard block |
||
29 | 29 | { |
30 | 30 | // init counter |
31 | 31 | if (!isset($this->counters[$name])) { |
32 | - $this->counters[$name] = array |
|
33 | - ( |
|
34 | - 'count' => $start===null ? 1 : (int) $start, |
|
35 | - 'skip' => $skip===null ? 1 : (int) $skip, |
|
36 | - 'print' => $print===null ? true : (bool) $print, |
|
37 | - 'assign' => $assign===null ? null : (string) $assign, |
|
38 | - 'direction' => strtolower($direction)==='down' ? -1 : 1, |
|
32 | + $this->counters[$name] = array( |
|
33 | + 'count' => $start === null ? 1 : (int) $start, |
|
34 | + 'skip' => $skip === null ? 1 : (int) $skip, |
|
35 | + 'print' => $print === null ? true : (bool) $print, |
|
36 | + 'assign' => $assign === null ? null : (string) $assign, |
|
37 | + 'direction' => strtolower($direction) === 'down' ? -1 : 1, |
|
39 | 38 | ); |
40 | 39 | } |
41 | 40 | // increment |
@@ -47,7 +46,7 @@ discard block |
||
47 | 46 | } |
48 | 47 | |
49 | 48 | if ($direction !== null) { |
50 | - $this->counters[$name]['direction'] = strtolower($direction)==='down' ? -1 : 1; |
|
49 | + $this->counters[$name]['direction'] = strtolower($direction) === 'down' ? -1 : 1; |
|
51 | 50 | } |
52 | 51 | |
53 | 52 | if ($print !== null) { |
@@ -61,7 +60,7 @@ discard block |
||
61 | 60 | if ($start !== null) { |
62 | 61 | $this->counters[$name]['count'] = (int) $start; |
63 | 62 | } else { |
64 | - $this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']); |
|
63 | + $this->counters[$name]['count'] += ($this->counters[$name]['skip']*$this->counters[$name]['direction']); |
|
65 | 64 | } |
66 | 65 | } |
67 | 66 |