Test Failed
Pull Request — 1.2 (#90)
by
unknown
02:45
created
lib/plugins/builtin/blocks/section.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -19,74 +19,74 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class Dwoo_Plugin_section extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block, Dwoo_IElseable
21 21
 {
22
-    public static $cnt = 0;
23
-
24
-    public function init($name, $loop, $start = null, $step = null, $max = null, $show = true)
25
-    {
26
-    }
27
-
28
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
29
-    {
30
-        return '';
31
-    }
32
-
33
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
34
-    {
35
-        $output = Dwoo_Compiler::PHP_OPEN;
36
-        $params = $compiler->getCompiledParams($params);
37
-
38
-        // assigns params
39
-        $loop = $params['loop'];
40
-        $start = $params['start'];
41
-        $max = $params['max'];
42
-        $name = $params['name'];
43
-        $step = $params['step'];
44
-        $show = $params['show'];
45
-
46
-        // gets unique id
47
-        $cnt = self::$cnt++;
48
-
49
-        $output .= '$this->globals[\'section\']['.$name.'] = array();'."\n".
50
-        '$_section'.$cnt.' =& $this->globals[\'section\']['.$name.'];'."\n";
51
-
52
-        if ($loop !== 'null') {
53
-            $output .= '$_section'.$cnt.'[\'loop\'] = is_array($tmp = '.$loop.') ? count($tmp) : max(0, (int) $tmp);'."\n";
54
-        } else {
55
-            $output .= '$_section'.$cnt.'[\'loop\'] = 1;'."\n";
56
-        }
57
-
58
-        if ($show !== 'null') {
59
-            $output .= '$_section'.$cnt.'[\'show\'] = '.$show.";\n";
60
-        } else {
61
-            $output .= '$_section'.$cnt.'[\'show\'] = true;'."\n";
62
-        }
63
-
64
-        if ($name !== 'null') {
65
-            $output .= '$_section'.$cnt.'[\'name\'] = '.$name.";\n";
66
-        } else {
67
-            $output .= '$_section'.$cnt.'[\'name\'] = true;'."\n";
68
-        }
69
-
70
-        if ($max !== 'null') {
71
-            $output .= '$_section'.$cnt.'[\'max\'] = (int)'.$max.";\n".
72
-                        'if($_section'.$cnt.'[\'max\'] < 0) { $_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\']; }'."\n";
73
-        } else {
74
-            $output .= '$_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\'];'."\n";
75
-        }
76
-
77
-        if ($step !== 'null') {
78
-            $output .= '$_section'.$cnt.'[\'step\'] = (int)'.$step.' == 0 ? 1 : (int) '.$step.";\n";
79
-        } else {
80
-            $output .= '$_section'.$cnt.'[\'step\'] = 1;'."\n";
81
-        }
82
-
83
-        if ($start !== 'null') {
84
-            $output .= '$_section'.$cnt.'[\'start\'] = (int)'.$start.";\n";
85
-        } else {
86
-            $output .= '$_section'.$cnt.'[\'start\'] = $_section'.$cnt.'[\'step\'] > 0 ? 0 : $_section'.$cnt.'[\'loop\'] - 1;'."\n".
87
-                        'if ($_section'.$cnt.'[\'start\'] < 0) { $_section'.$cnt.'[\'start\'] = max($_section'.$cnt.'[\'step\'] > 0 ? 0 : -1, $_section'.$cnt.'[\'loop\'] + $_section'.$cnt.'[\'start\']); } '."\n".
88
-                        'else { $_section'.$cnt.'[\'start\'] = min($_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] : $_section'.$cnt.'[\'loop\'] -1); }'."\n";
89
-        }
22
+	public static $cnt = 0;
23
+
24
+	public function init($name, $loop, $start = null, $step = null, $max = null, $show = true)
25
+	{
26
+	}
27
+
28
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
29
+	{
30
+		return '';
31
+	}
32
+
33
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
34
+	{
35
+		$output = Dwoo_Compiler::PHP_OPEN;
36
+		$params = $compiler->getCompiledParams($params);
37
+
38
+		// assigns params
39
+		$loop = $params['loop'];
40
+		$start = $params['start'];
41
+		$max = $params['max'];
42
+		$name = $params['name'];
43
+		$step = $params['step'];
44
+		$show = $params['show'];
45
+
46
+		// gets unique id
47
+		$cnt = self::$cnt++;
48
+
49
+		$output .= '$this->globals[\'section\']['.$name.'] = array();'."\n".
50
+		'$_section'.$cnt.' =& $this->globals[\'section\']['.$name.'];'."\n";
51
+
52
+		if ($loop !== 'null') {
53
+			$output .= '$_section'.$cnt.'[\'loop\'] = is_array($tmp = '.$loop.') ? count($tmp) : max(0, (int) $tmp);'."\n";
54
+		} else {
55
+			$output .= '$_section'.$cnt.'[\'loop\'] = 1;'."\n";
56
+		}
57
+
58
+		if ($show !== 'null') {
59
+			$output .= '$_section'.$cnt.'[\'show\'] = '.$show.";\n";
60
+		} else {
61
+			$output .= '$_section'.$cnt.'[\'show\'] = true;'."\n";
62
+		}
63
+
64
+		if ($name !== 'null') {
65
+			$output .= '$_section'.$cnt.'[\'name\'] = '.$name.";\n";
66
+		} else {
67
+			$output .= '$_section'.$cnt.'[\'name\'] = true;'."\n";
68
+		}
69
+
70
+		if ($max !== 'null') {
71
+			$output .= '$_section'.$cnt.'[\'max\'] = (int)'.$max.";\n".
72
+						'if($_section'.$cnt.'[\'max\'] < 0) { $_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\']; }'."\n";
73
+		} else {
74
+			$output .= '$_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\'];'."\n";
75
+		}
76
+
77
+		if ($step !== 'null') {
78
+			$output .= '$_section'.$cnt.'[\'step\'] = (int)'.$step.' == 0 ? 1 : (int) '.$step.";\n";
79
+		} else {
80
+			$output .= '$_section'.$cnt.'[\'step\'] = 1;'."\n";
81
+		}
82
+
83
+		if ($start !== 'null') {
84
+			$output .= '$_section'.$cnt.'[\'start\'] = (int)'.$start.";\n";
85
+		} else {
86
+			$output .= '$_section'.$cnt.'[\'start\'] = $_section'.$cnt.'[\'step\'] > 0 ? 0 : $_section'.$cnt.'[\'loop\'] - 1;'."\n".
87
+						'if ($_section'.$cnt.'[\'start\'] < 0) { $_section'.$cnt.'[\'start\'] = max($_section'.$cnt.'[\'step\'] > 0 ? 0 : -1, $_section'.$cnt.'[\'loop\'] + $_section'.$cnt.'[\'start\']); } '."\n".
88
+						'else { $_section'.$cnt.'[\'start\'] = min($_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] : $_section'.$cnt.'[\'loop\'] -1); }'."\n";
89
+		}
90 90
 
91 91
 /*		if ($usesAny) {
92 92
             $output .= "\n".'$this->globals["section"]['.$name.'] = array'."\n(";
@@ -100,35 +100,35 @@  discard block
 block discarded – undo
100 100
         }
101 101
 */
102 102
 
103
-        $output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n";
104
-        if ($start === 'null' && $step === 'null' && $max === 'null') {
105
-            $output .= '	$_section'.$cnt.'[\'total\'] = $_section'.$cnt.'[\'loop\'];'."\n";
106
-        } else {
107
-            $output .= '	$_section'.$cnt.'[\'total\'] = min(ceil(($_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] - $_section'.$cnt.'[\'start\'] : $_section'.$cnt.'[\'start\'] + 1) / abs($_section'.$cnt.'[\'step\'])), $_section'.$cnt.'[\'max\']);'."\n";
108
-        }
109
-        $output .= '	if ($_section'.$cnt.'[\'total\'] == 0) {'."\n".
110
-                   '		$_section'.$cnt.'[\'show\'] = false;'."\n".
111
-                   '	}'."\n".
112
-                   '} else {'."\n".
113
-                   '	$_section'.$cnt.'[\'total\'] = 0;'."\n}\n";
114
-        $output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n";
115
-        $output .= "\t".'for ($this->scope['.$name.'] = $_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'iteration\'] = 1; '.
116
-                    '$_section'.$cnt.'[\'iteration\'] <= $_section'.$cnt.'[\'total\']; '.
117
-                    '$this->scope['.$name.'] += $_section'.$cnt.'[\'step\'], $_section'.$cnt.'[\'iteration\']++) {'."\n";
118
-        $output .= "\t\t".'$_section'.$cnt.'[\'rownum\'] = $_section'.$cnt.'[\'iteration\'];'."\n";
119
-        $output .= "\t\t".'$_section'.$cnt.'[\'index_prev\'] = $this->scope['.$name.'] - $_section'.$cnt.'[\'step\'];'."\n";
120
-        $output .= "\t\t".'$_section'.$cnt.'[\'index_next\'] = $this->scope['.$name.'] + $_section'.$cnt.'[\'step\'];'."\n";
121
-        $output .= "\t\t".'$_section'.$cnt.'[\'first\']      = ($_section'.$cnt.'[\'iteration\'] == 1);'."\n";
122
-        $output .= "\t\t".'$_section'.$cnt.'[\'last\']       = ($_section'.$cnt.'[\'iteration\'] == $_section'.$cnt.'[\'total\']);'."\n";
123
-
124
-        $output .= Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN;
125
-
126
-        $output .= "\n\t}\n} ".Dwoo_Compiler::PHP_CLOSE;
127
-
128
-        if (isset($params['hasElse'])) {
129
-            $output .= $params['hasElse'];
130
-        }
131
-
132
-        return $output;
133
-    }
103
+		$output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n";
104
+		if ($start === 'null' && $step === 'null' && $max === 'null') {
105
+			$output .= '	$_section'.$cnt.'[\'total\'] = $_section'.$cnt.'[\'loop\'];'."\n";
106
+		} else {
107
+			$output .= '	$_section'.$cnt.'[\'total\'] = min(ceil(($_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] - $_section'.$cnt.'[\'start\'] : $_section'.$cnt.'[\'start\'] + 1) / abs($_section'.$cnt.'[\'step\'])), $_section'.$cnt.'[\'max\']);'."\n";
108
+		}
109
+		$output .= '	if ($_section'.$cnt.'[\'total\'] == 0) {'."\n".
110
+				   '		$_section'.$cnt.'[\'show\'] = false;'."\n".
111
+				   '	}'."\n".
112
+				   '} else {'."\n".
113
+				   '	$_section'.$cnt.'[\'total\'] = 0;'."\n}\n";
114
+		$output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n";
115
+		$output .= "\t".'for ($this->scope['.$name.'] = $_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'iteration\'] = 1; '.
116
+					'$_section'.$cnt.'[\'iteration\'] <= $_section'.$cnt.'[\'total\']; '.
117
+					'$this->scope['.$name.'] += $_section'.$cnt.'[\'step\'], $_section'.$cnt.'[\'iteration\']++) {'."\n";
118
+		$output .= "\t\t".'$_section'.$cnt.'[\'rownum\'] = $_section'.$cnt.'[\'iteration\'];'."\n";
119
+		$output .= "\t\t".'$_section'.$cnt.'[\'index_prev\'] = $this->scope['.$name.'] - $_section'.$cnt.'[\'step\'];'."\n";
120
+		$output .= "\t\t".'$_section'.$cnt.'[\'index_next\'] = $this->scope['.$name.'] + $_section'.$cnt.'[\'step\'];'."\n";
121
+		$output .= "\t\t".'$_section'.$cnt.'[\'first\']      = ($_section'.$cnt.'[\'iteration\'] == 1);'."\n";
122
+		$output .= "\t\t".'$_section'.$cnt.'[\'last\']       = ($_section'.$cnt.'[\'iteration\'] == $_section'.$cnt.'[\'total\']);'."\n";
123
+
124
+		$output .= Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN;
125
+
126
+		$output .= "\n\t}\n} ".Dwoo_Compiler::PHP_CLOSE;
127
+
128
+		if (isset($params['hasElse'])) {
129
+			$output .= $params['hasElse'];
130
+		}
131
+
132
+		return $output;
133
+	}
134 134
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/else.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -32,40 +32,40 @@
 block discarded – undo
32 32
  */
33 33
 class Dwoo_Plugin_else extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
34 34
 {
35
-    public function init()
36
-    {
37
-    }
35
+	public function init()
36
+	{
37
+	}
38 38
 
39
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
40
-    {
41
-        $preContent = '';
42
-        while (true) {
43
-            $preContent .= $compiler->removeTopBlock();
44
-            $block = &$compiler->getCurrentBlock();
45
-            if (!$block) {
46
-                throw new Dwoo_Compilation_Exception($compiler, 'An else block was found but it was not preceded by an if or other else-able construct');
47
-            }
48
-            $interfaces = class_implements($block['class'], false);
49
-            if (in_array('Dwoo_IElseable', $interfaces) !== false) {
50
-                break;
51
-            }
52
-        }
39
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
40
+	{
41
+		$preContent = '';
42
+		while (true) {
43
+			$preContent .= $compiler->removeTopBlock();
44
+			$block = &$compiler->getCurrentBlock();
45
+			if (!$block) {
46
+				throw new Dwoo_Compilation_Exception($compiler, 'An else block was found but it was not preceded by an if or other else-able construct');
47
+			}
48
+			$interfaces = class_implements($block['class'], false);
49
+			if (in_array('Dwoo_IElseable', $interfaces) !== false) {
50
+				break;
51
+			}
52
+		}
53 53
 
54
-        $params['initialized'] = true;
55
-        $compiler->injectBlock($type, $params);
54
+		$params['initialized'] = true;
55
+		$compiler->injectBlock($type, $params);
56 56
 
57
-        return $preContent;
58
-    }
57
+		return $preContent;
58
+	}
59 59
 
60
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
61
-    {
62
-        if (!isset($params['initialized'])) {
63
-            return '';
64
-        }
60
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
61
+	{
62
+		if (!isset($params['initialized'])) {
63
+			return '';
64
+		}
65 65
 
66
-        $block = &$compiler->getCurrentBlock();
67
-        $block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE;
66
+		$block = &$compiler->getCurrentBlock();
67
+		$block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE;
68 68
 
69
-        return '';
70
-    }
69
+		return '';
70
+	}
71 71
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/a.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -37,34 +37,34 @@
 block discarded – undo
37 37
  */
38 38
 class Dwoo_Plugin_a extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
39 39
 {
40
-    public function init($href, array $rest = array())
41
-    {
42
-    }
40
+	public function init($href, array $rest = array())
41
+	{
42
+	}
43 43
 
44
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
45
-    {
46
-        $p = $compiler->getCompiledParams($params);
44
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
45
+	{
46
+		$p = $compiler->getCompiledParams($params);
47 47
 
48
-        $out = Dwoo_Compiler::PHP_OPEN.'echo \'<a '.self::paramsToAttributes($p, "'", $compiler);
48
+		$out = Dwoo_Compiler::PHP_OPEN.'echo \'<a '.self::paramsToAttributes($p, "'", $compiler);
49 49
 
50
-        return $out.'>\';'.Dwoo_Compiler::PHP_CLOSE;
51
-    }
50
+		return $out.'>\';'.Dwoo_Compiler::PHP_CLOSE;
51
+	}
52 52
 
53
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
54
-    {
55
-        $p = $compiler->getCompiledParams($params);
53
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
54
+	{
55
+		$p = $compiler->getCompiledParams($params);
56 56
 
57
-        // no content was provided so use the url as display text
58
-        if ($content == '') {
59
-            // merge </a> into the href if href is a string
60
-            if (substr($p['href'], -1) === '"' || substr($p['href'], -1) === '\'') {
61
-                return Dwoo_Compiler::PHP_OPEN.'echo '.substr($p['href'], 0, -1).'</a>'.substr($p['href'], -1).';'.Dwoo_Compiler::PHP_CLOSE;
62
-            }
63
-            // otherwise append
64
-            return Dwoo_Compiler::PHP_OPEN.'echo '.$p['href'].'.\'</a>\';'.Dwoo_Compiler::PHP_CLOSE;
65
-        }
57
+		// no content was provided so use the url as display text
58
+		if ($content == '') {
59
+			// merge </a> into the href if href is a string
60
+			if (substr($p['href'], -1) === '"' || substr($p['href'], -1) === '\'') {
61
+				return Dwoo_Compiler::PHP_OPEN.'echo '.substr($p['href'], 0, -1).'</a>'.substr($p['href'], -1).';'.Dwoo_Compiler::PHP_CLOSE;
62
+			}
63
+			// otherwise append
64
+			return Dwoo_Compiler::PHP_OPEN.'echo '.$p['href'].'.\'</a>\';'.Dwoo_Compiler::PHP_CLOSE;
65
+		}
66 66
 
67
-        // return content
68
-        return $content.'</a>';
69
-    }
67
+		// return content
68
+		return $content.'</a>';
69
+	}
70 70
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/for.php 1 patch
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -24,137 +24,137 @@
 block discarded – undo
24 24
  */
25 25
 class Dwoo_Plugin_for extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block, Dwoo_IElseable
26 26
 {
27
-    public static $cnt = 0;
28
-
29
-    public function init($name, $from, $to = null, $step = 1, $skip = 0)
30
-    {
31
-    }
32
-
33
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
34
-    {
35
-        // get block params and save the current template pointer to use it in the postProcessing method
36
-        $currentBlock = &$compiler->getCurrentBlock();
37
-        $currentBlock['params']['tplPointer'] = $compiler->getPointer();
38
-
39
-        return '';
40
-    }
41
-
42
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
43
-    {
44
-        $params = $compiler->getCompiledParams($params);
45
-        $tpl = $compiler->getTemplateSource($params['tplPointer']);
46
-
47
-        // assigns params
48
-        $from = $params['from'];
49
-        $name = $params['name'];
50
-        $step = $params['step'];
51
-        $to = $params['to'];
52
-
53
-        // evaluates which global variables have to be computed
54
-        $varName = '$dwoo.for.'.trim($name, '"\'').'.';
55
-        $shortVarName = '$.for.'.trim($name, '"\'').'.';
56
-        $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
57
-        $usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false;
58
-        $usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false;
59
-        $usesIndex = strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false;
60
-        $usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false;
61
-        $usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false;
62
-        $usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false;
63
-
64
-        if (strpos($name, '$this->scope[') !== false) {
65
-            $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
66
-        }
67
-
68
-        // gets foreach id
69
-        $cnt = self::$cnt++;
70
-
71
-        // builds pre processing output for
72
-        $out = Dwoo_Compiler::PHP_OPEN."\n".'$_for'.$cnt.'_from = '.$from.';'.
73
-                                        "\n".'$_for'.$cnt.'_to = '.$to.';'.
74
-                                        "\n".'$_for'.$cnt.'_step = abs('.$step.');'.
75
-                                        "\n".'if (is_numeric($_for'.$cnt.'_from) && !is_numeric($_for'.$cnt.'_to)) { $this->triggerError(\'For requires the <em>to</em> parameter when using a numerical <em>from</em>\'); }'.
76
-                                        "\n".'$tmp_shows = $this->isArray($_for'.$cnt.'_from, true) || (is_numeric($_for'.$cnt.'_from) && (abs(($_for'.$cnt.'_from - $_for'.$cnt.'_to)/$_for'.$cnt.'_step) !== 0 || $_for'.$cnt.'_from == $_for'.$cnt.'_to));';
77
-        // adds for properties
78
-        if ($usesAny) {
79
-            $out .= "\n".'$this->globals["for"]['.$name.'] = array'."\n(";
80
-            if ($usesIndex) {
81
-                $out .= "\n\t".'"index"		=> 0,';
82
-            }
83
-            if ($usesIteration) {
84
-                $out .= "\n\t".'"iteration"		=> 1,';
85
-            }
86
-            if ($usesFirst) {
87
-                $out .= "\n\t".'"first"		=> null,';
88
-            }
89
-            if ($usesLast) {
90
-                $out .= "\n\t".'"last"		=> null,';
91
-            }
92
-            if ($usesShow) {
93
-                $out .= "\n\t".'"show"		=> $tmp_shows,';
94
-            }
95
-            if ($usesTotal) {
96
-                $out .= "\n\t".'"total"		=> $this->isArray($_for'.$cnt.'_from) ? floor($this->count($_for'.$cnt.'_from) / $_for'.$cnt.'_step) : (is_numeric($_for'.$cnt.'_from) ? abs(($_for'.$cnt.'_to + 1 - $_for'.$cnt.'_from)/$_for'.$cnt.'_step) : 0),';
97
-            }
98
-            $out .= "\n);\n".'$_for'.$cnt.'_glob =& $this->globals["for"]['.$name.'];';
99
-        }
100
-        // checks if for must be looped
101
-        $out .= "\n".'if ($tmp_shows)'."\n{";
102
-        // set from/to to correct values if an array was given
103
-        $out .= "\n\t".'if ($this->isArray($_for'.$cnt.'_from'.(isset($params['hasElse']) ? ', true' : '').') == true) {
27
+	public static $cnt = 0;
28
+
29
+	public function init($name, $from, $to = null, $step = 1, $skip = 0)
30
+	{
31
+	}
32
+
33
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
34
+	{
35
+		// get block params and save the current template pointer to use it in the postProcessing method
36
+		$currentBlock = &$compiler->getCurrentBlock();
37
+		$currentBlock['params']['tplPointer'] = $compiler->getPointer();
38
+
39
+		return '';
40
+	}
41
+
42
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
43
+	{
44
+		$params = $compiler->getCompiledParams($params);
45
+		$tpl = $compiler->getTemplateSource($params['tplPointer']);
46
+
47
+		// assigns params
48
+		$from = $params['from'];
49
+		$name = $params['name'];
50
+		$step = $params['step'];
51
+		$to = $params['to'];
52
+
53
+		// evaluates which global variables have to be computed
54
+		$varName = '$dwoo.for.'.trim($name, '"\'').'.';
55
+		$shortVarName = '$.for.'.trim($name, '"\'').'.';
56
+		$usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
57
+		$usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false;
58
+		$usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false;
59
+		$usesIndex = strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false;
60
+		$usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false;
61
+		$usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false;
62
+		$usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false;
63
+
64
+		if (strpos($name, '$this->scope[') !== false) {
65
+			$usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
66
+		}
67
+
68
+		// gets foreach id
69
+		$cnt = self::$cnt++;
70
+
71
+		// builds pre processing output for
72
+		$out = Dwoo_Compiler::PHP_OPEN."\n".'$_for'.$cnt.'_from = '.$from.';'.
73
+										"\n".'$_for'.$cnt.'_to = '.$to.';'.
74
+										"\n".'$_for'.$cnt.'_step = abs('.$step.');'.
75
+										"\n".'if (is_numeric($_for'.$cnt.'_from) && !is_numeric($_for'.$cnt.'_to)) { $this->triggerError(\'For requires the <em>to</em> parameter when using a numerical <em>from</em>\'); }'.
76
+										"\n".'$tmp_shows = $this->isArray($_for'.$cnt.'_from, true) || (is_numeric($_for'.$cnt.'_from) && (abs(($_for'.$cnt.'_from - $_for'.$cnt.'_to)/$_for'.$cnt.'_step) !== 0 || $_for'.$cnt.'_from == $_for'.$cnt.'_to));';
77
+		// adds for properties
78
+		if ($usesAny) {
79
+			$out .= "\n".'$this->globals["for"]['.$name.'] = array'."\n(";
80
+			if ($usesIndex) {
81
+				$out .= "\n\t".'"index"		=> 0,';
82
+			}
83
+			if ($usesIteration) {
84
+				$out .= "\n\t".'"iteration"		=> 1,';
85
+			}
86
+			if ($usesFirst) {
87
+				$out .= "\n\t".'"first"		=> null,';
88
+			}
89
+			if ($usesLast) {
90
+				$out .= "\n\t".'"last"		=> null,';
91
+			}
92
+			if ($usesShow) {
93
+				$out .= "\n\t".'"show"		=> $tmp_shows,';
94
+			}
95
+			if ($usesTotal) {
96
+				$out .= "\n\t".'"total"		=> $this->isArray($_for'.$cnt.'_from) ? floor($this->count($_for'.$cnt.'_from) / $_for'.$cnt.'_step) : (is_numeric($_for'.$cnt.'_from) ? abs(($_for'.$cnt.'_to + 1 - $_for'.$cnt.'_from)/$_for'.$cnt.'_step) : 0),';
97
+			}
98
+			$out .= "\n);\n".'$_for'.$cnt.'_glob =& $this->globals["for"]['.$name.'];';
99
+		}
100
+		// checks if for must be looped
101
+		$out .= "\n".'if ($tmp_shows)'."\n{";
102
+		// set from/to to correct values if an array was given
103
+		$out .= "\n\t".'if ($this->isArray($_for'.$cnt.'_from'.(isset($params['hasElse']) ? ', true' : '').') == true) {
104 104
 		$_for'.$cnt.'_to = is_numeric($_for'.$cnt.'_to) ? $_for'.$cnt.'_to - $_for'.$cnt.'_step : $this->count($_for'.$cnt.'_from) - 1;
105 105
 		$_for'.$cnt.'_from = 0;
106 106
 	}';
107 107
 
108
-        // if input are pure numbers it shouldn't reorder them, if it's variables it gets too messy though so in that case a counter should be used
109
-        $reverse = false;
110
-        $condition = '<=';
111
-        $incrementer = '+';
112
-
113
-        if (preg_match('{^(["\']?)([0-9]+)\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\1$}', $to, $mN2)) {
114
-            $from = (int) $mN1[2];
115
-            $to = (int) $mN2[2];
116
-            if ($from > $to) {
117
-                $reverse = true;
118
-                $condition = '>=';
119
-                $incrementer = '-';
120
-            }
121
-        }
122
-
123
-        // reverse from and to if needed
124
-        if (!$reverse) {
125
-            $out .= "\n\t".'if ($_for'.$cnt.'_from > $_for'.$cnt.'_to) {
108
+		// if input are pure numbers it shouldn't reorder them, if it's variables it gets too messy though so in that case a counter should be used
109
+		$reverse = false;
110
+		$condition = '<=';
111
+		$incrementer = '+';
112
+
113
+		if (preg_match('{^(["\']?)([0-9]+)\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\1$}', $to, $mN2)) {
114
+			$from = (int) $mN1[2];
115
+			$to = (int) $mN2[2];
116
+			if ($from > $to) {
117
+				$reverse = true;
118
+				$condition = '>=';
119
+				$incrementer = '-';
120
+			}
121
+		}
122
+
123
+		// reverse from and to if needed
124
+		if (!$reverse) {
125
+			$out .= "\n\t".'if ($_for'.$cnt.'_from > $_for'.$cnt.'_to) {
126 126
 				$tmp = $_for'.$cnt.'_from;
127 127
 				$_for'.$cnt.'_from = $_for'.$cnt.'_to;
128 128
 				$_for'.$cnt.'_to = $tmp;
129 129
 			}';
130
-        }
131
-
132
-        $out .= "\n\t".'for ($this->scope['.$name.'] = $_for'.$cnt.'_from; $this->scope['.$name.'] '.$condition.' $_for'.$cnt.'_to; $this->scope['.$name.'] '.$incrementer.'= $_for'.$cnt.'_step)'."\n\t{";
133
-        // updates properties
134
-        if ($usesIndex) {
135
-            $out .= "\n\t\t".'$_for'.$cnt.'_glob["index"] = $this->scope['.$name.'];';
136
-        }
137
-        if ($usesFirst) {
138
-            $out .= "\n\t\t".'$_for'.$cnt.'_glob["first"] = (string) ($_for'.$cnt.'_glob["iteration"] === 1);';
139
-        }
140
-        if ($usesLast) {
141
-            $out .= "\n\t\t".'$_for'.$cnt.'_glob["last"] = (string) ($_for'.$cnt.'_glob["iteration"] === $_for'.$cnt.'_glob["total"]);';
142
-        }
143
-        $out .= "\n/* -- for start output */\n".Dwoo_Compiler::PHP_CLOSE;
144
-
145
-        // build post processing output and cache it
146
-        $postOut = Dwoo_Compiler::PHP_OPEN.'/* -- for end output */';
147
-        // update properties
148
-        if ($usesIteration) {
149
-            $postOut .= "\n\t\t".'$_for'.$cnt.'_glob["iteration"]+=1;';
150
-        }
151
-        // end loop
152
-        $postOut .= "\n\t}\n}\n".Dwoo_Compiler::PHP_CLOSE;
153
-
154
-        if (isset($params['hasElse'])) {
155
-            $postOut .= $params['hasElse'];
156
-        }
157
-
158
-        return $out.$content.$postOut;
159
-    }
130
+		}
131
+
132
+		$out .= "\n\t".'for ($this->scope['.$name.'] = $_for'.$cnt.'_from; $this->scope['.$name.'] '.$condition.' $_for'.$cnt.'_to; $this->scope['.$name.'] '.$incrementer.'= $_for'.$cnt.'_step)'."\n\t{";
133
+		// updates properties
134
+		if ($usesIndex) {
135
+			$out .= "\n\t\t".'$_for'.$cnt.'_glob["index"] = $this->scope['.$name.'];';
136
+		}
137
+		if ($usesFirst) {
138
+			$out .= "\n\t\t".'$_for'.$cnt.'_glob["first"] = (string) ($_for'.$cnt.'_glob["iteration"] === 1);';
139
+		}
140
+		if ($usesLast) {
141
+			$out .= "\n\t\t".'$_for'.$cnt.'_glob["last"] = (string) ($_for'.$cnt.'_glob["iteration"] === $_for'.$cnt.'_glob["total"]);';
142
+		}
143
+		$out .= "\n/* -- for start output */\n".Dwoo_Compiler::PHP_CLOSE;
144
+
145
+		// build post processing output and cache it
146
+		$postOut = Dwoo_Compiler::PHP_OPEN.'/* -- for end output */';
147
+		// update properties
148
+		if ($usesIteration) {
149
+			$postOut .= "\n\t\t".'$_for'.$cnt.'_glob["iteration"]+=1;';
150
+		}
151
+		// end loop
152
+		$postOut .= "\n\t}\n}\n".Dwoo_Compiler::PHP_CLOSE;
153
+
154
+		if (isset($params['hasElse'])) {
155
+			$postOut .= $params['hasElse'];
156
+		}
157
+
158
+		return $out.$content.$postOut;
159
+	}
160 160
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/strip.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -23,30 +23,30 @@
 block discarded – undo
23 23
  */
24 24
 class Dwoo_Plugin_strip extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
25 25
 {
26
-    public function init($mode = 'default')
27
-    {
28
-    }
26
+	public function init($mode = 'default')
27
+	{
28
+	}
29 29
 
30
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
31
-    {
32
-        return '';
33
-    }
30
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
31
+	{
32
+		return '';
33
+	}
34 34
 
35
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
36
-    {
37
-        $params = $compiler->getCompiledParams($params);
35
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
36
+	{
37
+		$params = $compiler->getCompiledParams($params);
38 38
 
39
-        $mode = trim($params['mode'], '"\'');
40
-        switch ($mode) {
41
-            case 'js':
42
-            case 'javascript':
43
-                $content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content);
39
+		$mode = trim($params['mode'], '"\'');
40
+		switch ($mode) {
41
+			case 'js':
42
+			case 'javascript':
43
+				$content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content);
44 44
 
45
-            case 'default':
46
-            default:
47
-        }
48
-        $content = preg_replace(array("/\n/", "/\r/", '/(<\?(?:php)?|<%)\s*/'), array('', '', '$1 '), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content));
45
+			case 'default':
46
+			default:
47
+		}
48
+		$content = preg_replace(array("/\n/", "/\r/", '/(<\?(?:php)?|<%)\s*/'), array('', '', '$1 '), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content));
49 49
 
50
-        return $content;
51
-    }
50
+		return $content;
51
+	}
52 52
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/foreach.php 1 patch
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -34,134 +34,134 @@
 block discarded – undo
34 34
  */
35 35
 class Dwoo_Plugin_foreach extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block, Dwoo_IElseable
36 36
 {
37
-    public static $cnt = 0;
38
-
39
-    public function init($from, $key = null, $item = null, $name = 'default', $implode = null)
40
-    {
41
-    }
42
-
43
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
44
-    {
45
-        // get block params and save the current template pointer to use it in the postProcessing method
46
-        $currentBlock = &$compiler->getCurrentBlock();
47
-        $currentBlock['params']['tplPointer'] = $compiler->getPointer();
48
-
49
-        return '';
50
-    }
51
-
52
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
53
-    {
54
-        $params = $compiler->getCompiledParams($params);
55
-        $tpl = $compiler->getTemplateSource($params['tplPointer']);
56
-
57
-        // assigns params
58
-        $src = $params['from'];
59
-
60
-        if ($params['item'] !== 'null') {
61
-            if ($params['key'] !== 'null') {
62
-                $key = $params['key'];
63
-            }
64
-            $val = $params['item'];
65
-        } elseif ($params['key'] !== 'null') {
66
-            $val = $params['key'];
67
-        } else {
68
-            throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>item</em> parameter missing');
69
-        }
70
-        $name = $params['name'];
71
-
72
-        if (substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') {
73
-            throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>item</em> parameter must be of type string');
74
-        }
75
-        if (isset($key) && substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') {
76
-            throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>key</em> parameter must be of type string');
77
-        }
78
-
79
-        // evaluates which global variables have to be computed
80
-        $varName = '$dwoo.foreach.'.trim($name, '"\'').'.';
81
-        $shortVarName = '$.foreach.'.trim($name, '"\'').'.';
82
-        $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
83
-        $usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false;
84
-        $usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false;
85
-        $usesIndex = $usesFirst || strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false;
86
-        $usesIteration = $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false;
87
-        $usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false;
88
-        $usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false;
89
-
90
-        if (strpos($name, '$this->scope[') !== false) {
91
-            $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
92
-        }
93
-
94
-        // override globals vars if implode is used
95
-        if ($params['implode'] !== 'null') {
96
-            $implode = $params['implode'];
97
-            $usesAny = true;
98
-            $usesLast = true;
99
-            $usesIteration = true;
100
-            $usesTotal = true;
101
-        }
102
-
103
-        // gets foreach id
104
-        $cnt = self::$cnt++;
105
-
106
-        // build pre content output
107
-        $pre = Dwoo_Compiler::PHP_OPEN."\n".'$_fh'.$cnt.'_data = '.$src.';';
108
-        // adds foreach properties
109
-        if ($usesAny) {
110
-            $pre .= "\n".'$this->globals["foreach"]['.$name.'] = array'."\n(";
111
-            if ($usesIndex) {
112
-                $pre .= "\n\t".'"index"		=> 0,';
113
-            }
114
-            if ($usesIteration) {
115
-                $pre .= "\n\t".'"iteration"		=> 1,';
116
-            }
117
-            if ($usesFirst) {
118
-                $pre .= "\n\t".'"first"		=> null,';
119
-            }
120
-            if ($usesLast) {
121
-                $pre .= "\n\t".'"last"		=> null,';
122
-            }
123
-            if ($usesShow) {
124
-                $pre .= "\n\t".'"show"		=> $this->isArray($_fh'.$cnt.'_data, true),';
125
-            }
126
-            if ($usesTotal) {
127
-                $pre .= "\n\t".'"total"		=> $this->count($_fh'.$cnt.'_data),';
128
-            }
129
-            $pre .= "\n);\n".'$_fh'.$cnt.'_glob =& $this->globals["foreach"]['.$name.'];';
130
-        }
131
-        // checks if foreach must be looped
132
-        $pre .= "\n".'if ($this->isTraversable($_fh'.$cnt.'_data'.(isset($params['hasElse']) ? ', true' : '').') == true)'."\n{";
133
-        // iterates over keys
134
-        $pre .= "\n\t".'foreach ($_fh'.$cnt.'_data as '.(isset($key) ? '$this->scope['.$key.']=>' : '').'$this->scope['.$val.'])'."\n\t{";
135
-        // updates properties
136
-        if ($usesFirst) {
137
-            $pre .= "\n\t\t".'$_fh'.$cnt.'_glob["first"] = (string) ($_fh'.$cnt.'_glob["index"] === 0);';
138
-        }
139
-        if ($usesLast) {
140
-            $pre .= "\n\t\t".'$_fh'.$cnt.'_glob["last"] = (string) ($_fh'.$cnt.'_glob["iteration"] === $_fh'.$cnt.'_glob["total"]);';
141
-        }
142
-        $pre .= "\n/* -- foreach start output */\n".Dwoo_Compiler::PHP_CLOSE;
143
-
144
-        // build post content output
145
-        $post = Dwoo_Compiler::PHP_OPEN."\n";
146
-
147
-        if (isset($implode)) {
148
-            $post .= '/* -- implode */'."\n".'if (!$_fh'.$cnt.'_glob["last"]) {'.
149
-                "\n\t".'echo '.$implode.";\n}\n";
150
-        }
151
-        $post .= '/* -- foreach end output */';
152
-        // update properties
153
-        if ($usesIndex) {
154
-            $post .= "\n\t\t".'$_fh'.$cnt.'_glob["index"]+=1;';
155
-        }
156
-        if ($usesIteration) {
157
-            $post .= "\n\t\t".'$_fh'.$cnt.'_glob["iteration"]+=1;';
158
-        }
159
-        // end loop
160
-        $post .= "\n\t}\n}".Dwoo_Compiler::PHP_CLOSE;
161
-        if (isset($params['hasElse'])) {
162
-            $post .= $params['hasElse'];
163
-        }
164
-
165
-        return $pre.$content.$post;
166
-    }
37
+	public static $cnt = 0;
38
+
39
+	public function init($from, $key = null, $item = null, $name = 'default', $implode = null)
40
+	{
41
+	}
42
+
43
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
44
+	{
45
+		// get block params and save the current template pointer to use it in the postProcessing method
46
+		$currentBlock = &$compiler->getCurrentBlock();
47
+		$currentBlock['params']['tplPointer'] = $compiler->getPointer();
48
+
49
+		return '';
50
+	}
51
+
52
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
53
+	{
54
+		$params = $compiler->getCompiledParams($params);
55
+		$tpl = $compiler->getTemplateSource($params['tplPointer']);
56
+
57
+		// assigns params
58
+		$src = $params['from'];
59
+
60
+		if ($params['item'] !== 'null') {
61
+			if ($params['key'] !== 'null') {
62
+				$key = $params['key'];
63
+			}
64
+			$val = $params['item'];
65
+		} elseif ($params['key'] !== 'null') {
66
+			$val = $params['key'];
67
+		} else {
68
+			throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>item</em> parameter missing');
69
+		}
70
+		$name = $params['name'];
71
+
72
+		if (substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') {
73
+			throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>item</em> parameter must be of type string');
74
+		}
75
+		if (isset($key) && substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') {
76
+			throw new Dwoo_Compilation_Exception($compiler, 'Foreach <em>key</em> parameter must be of type string');
77
+		}
78
+
79
+		// evaluates which global variables have to be computed
80
+		$varName = '$dwoo.foreach.'.trim($name, '"\'').'.';
81
+		$shortVarName = '$.foreach.'.trim($name, '"\'').'.';
82
+		$usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
83
+		$usesFirst = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false;
84
+		$usesLast = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false;
85
+		$usesIndex = $usesFirst || strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false;
86
+		$usesIteration = $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false;
87
+		$usesShow = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false;
88
+		$usesTotal = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false;
89
+
90
+		if (strpos($name, '$this->scope[') !== false) {
91
+			$usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
92
+		}
93
+
94
+		// override globals vars if implode is used
95
+		if ($params['implode'] !== 'null') {
96
+			$implode = $params['implode'];
97
+			$usesAny = true;
98
+			$usesLast = true;
99
+			$usesIteration = true;
100
+			$usesTotal = true;
101
+		}
102
+
103
+		// gets foreach id
104
+		$cnt = self::$cnt++;
105
+
106
+		// build pre content output
107
+		$pre = Dwoo_Compiler::PHP_OPEN."\n".'$_fh'.$cnt.'_data = '.$src.';';
108
+		// adds foreach properties
109
+		if ($usesAny) {
110
+			$pre .= "\n".'$this->globals["foreach"]['.$name.'] = array'."\n(";
111
+			if ($usesIndex) {
112
+				$pre .= "\n\t".'"index"		=> 0,';
113
+			}
114
+			if ($usesIteration) {
115
+				$pre .= "\n\t".'"iteration"		=> 1,';
116
+			}
117
+			if ($usesFirst) {
118
+				$pre .= "\n\t".'"first"		=> null,';
119
+			}
120
+			if ($usesLast) {
121
+				$pre .= "\n\t".'"last"		=> null,';
122
+			}
123
+			if ($usesShow) {
124
+				$pre .= "\n\t".'"show"		=> $this->isArray($_fh'.$cnt.'_data, true),';
125
+			}
126
+			if ($usesTotal) {
127
+				$pre .= "\n\t".'"total"		=> $this->count($_fh'.$cnt.'_data),';
128
+			}
129
+			$pre .= "\n);\n".'$_fh'.$cnt.'_glob =& $this->globals["foreach"]['.$name.'];';
130
+		}
131
+		// checks if foreach must be looped
132
+		$pre .= "\n".'if ($this->isTraversable($_fh'.$cnt.'_data'.(isset($params['hasElse']) ? ', true' : '').') == true)'."\n{";
133
+		// iterates over keys
134
+		$pre .= "\n\t".'foreach ($_fh'.$cnt.'_data as '.(isset($key) ? '$this->scope['.$key.']=>' : '').'$this->scope['.$val.'])'."\n\t{";
135
+		// updates properties
136
+		if ($usesFirst) {
137
+			$pre .= "\n\t\t".'$_fh'.$cnt.'_glob["first"] = (string) ($_fh'.$cnt.'_glob["index"] === 0);';
138
+		}
139
+		if ($usesLast) {
140
+			$pre .= "\n\t\t".'$_fh'.$cnt.'_glob["last"] = (string) ($_fh'.$cnt.'_glob["iteration"] === $_fh'.$cnt.'_glob["total"]);';
141
+		}
142
+		$pre .= "\n/* -- foreach start output */\n".Dwoo_Compiler::PHP_CLOSE;
143
+
144
+		// build post content output
145
+		$post = Dwoo_Compiler::PHP_OPEN."\n";
146
+
147
+		if (isset($implode)) {
148
+			$post .= '/* -- implode */'."\n".'if (!$_fh'.$cnt.'_glob["last"]) {'.
149
+				"\n\t".'echo '.$implode.";\n}\n";
150
+		}
151
+		$post .= '/* -- foreach end output */';
152
+		// update properties
153
+		if ($usesIndex) {
154
+			$post .= "\n\t\t".'$_fh'.$cnt.'_glob["index"]+=1;';
155
+		}
156
+		if ($usesIteration) {
157
+			$post .= "\n\t\t".'$_fh'.$cnt.'_glob["iteration"]+=1;';
158
+		}
159
+		// end loop
160
+		$post .= "\n\t}\n}".Dwoo_Compiler::PHP_CLOSE;
161
+		if (isset($params['hasElse'])) {
162
+			$post .= $params['hasElse'];
163
+		}
164
+
165
+		return $pre.$content.$post;
166
+	}
167 167
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/textformat.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -29,69 +29,69 @@
 block discarded – undo
29 29
  */
30 30
 class Dwoo_Plugin_textformat extends Dwoo_Block_Plugin
31 31
 {
32
-    protected $wrap;
33
-    protected $wrapChar;
34
-    protected $wrapCut;
35
-    protected $indent;
36
-    protected $indChar;
37
-    protected $indFirst;
38
-    protected $assign;
32
+	protected $wrap;
33
+	protected $wrapChar;
34
+	protected $wrapCut;
35
+	protected $indent;
36
+	protected $indChar;
37
+	protected $indFirst;
38
+	protected $assign;
39 39
 
40
-    public function init($wrap = 80, $wrap_char = "\r\n", $wrap_cut = false, $indent = 0, $indent_char = ' ', $indent_first = 0, $style = '', $assign = '')
41
-    {
42
-        if ($indent_char === 'tab') {
43
-            $indent_char = "\t";
44
-        }
40
+	public function init($wrap = 80, $wrap_char = "\r\n", $wrap_cut = false, $indent = 0, $indent_char = ' ', $indent_first = 0, $style = '', $assign = '')
41
+	{
42
+		if ($indent_char === 'tab') {
43
+			$indent_char = "\t";
44
+		}
45 45
 
46
-        switch ($style) {
46
+		switch ($style) {
47 47
 
48
-        case 'email':
49
-            $wrap = 72;
50
-            $indent_first = 0;
51
-            break;
52
-        case 'html':
53
-            $wrap_char = '<br />';
54
-            $indent_char = $indent_char == "\t" ? '&nbsp;&nbsp;&nbsp;&nbsp;' : '&nbsp;';
55
-            break;
48
+		case 'email':
49
+			$wrap = 72;
50
+			$indent_first = 0;
51
+			break;
52
+		case 'html':
53
+			$wrap_char = '<br />';
54
+			$indent_char = $indent_char == "\t" ? '&nbsp;&nbsp;&nbsp;&nbsp;' : '&nbsp;';
55
+			break;
56 56
 
57
-        }
57
+		}
58 58
 
59
-        $this->wrap = (int) $wrap;
60
-        $this->wrapChar = (string) $wrap_char;
61
-        $this->wrapCut = (bool) $wrap_cut;
62
-        $this->indent = (int) $indent;
63
-        $this->indChar = (string) $indent_char;
64
-        $this->indFirst = (int) $indent_first + $this->indent;
65
-        $this->assign = (string) $assign;
66
-    }
59
+		$this->wrap = (int) $wrap;
60
+		$this->wrapChar = (string) $wrap_char;
61
+		$this->wrapCut = (bool) $wrap_cut;
62
+		$this->indent = (int) $indent;
63
+		$this->indChar = (string) $indent_char;
64
+		$this->indFirst = (int) $indent_first + $this->indent;
65
+		$this->assign = (string) $assign;
66
+	}
67 67
 
68
-    public function process()
69
-    {
70
-        // gets paragraphs
71
-        $pgs = explode("\n", str_replace(array("\r\n", "\r"), "\n", $this->buffer));
68
+	public function process()
69
+	{
70
+		// gets paragraphs
71
+		$pgs = explode("\n", str_replace(array("\r\n", "\r"), "\n", $this->buffer));
72 72
 
73
-        while (list($i) = each($pgs)) {
74
-            if (empty($pgs[$i])) {
75
-                continue;
76
-            }
73
+		while (list($i) = each($pgs)) {
74
+			if (empty($pgs[$i])) {
75
+				continue;
76
+			}
77 77
 
78
-            // removes line breaks and extensive white space
79
-            $pgs[$i] = preg_replace(array('#\s+#', '#^\s*(.+?)\s*$#m'), array(' ', '$1'), str_replace("\n", '', $pgs[$i]));
78
+			// removes line breaks and extensive white space
79
+			$pgs[$i] = preg_replace(array('#\s+#', '#^\s*(.+?)\s*$#m'), array(' ', '$1'), str_replace("\n", '', $pgs[$i]));
80 80
 
81
-            // wordwraps + indents lines
82
-            $pgs[$i] = str_repeat($this->indChar, $this->indFirst).
83
-                    wordwrap(
84
-                            $pgs[$i],
85
-                            max($this->wrap - $this->indent, 1),
86
-                            $this->wrapChar.str_repeat($this->indChar, $this->indent),
87
-                            $this->wrapCut
88
-                    );
89
-        }
81
+			// wordwraps + indents lines
82
+			$pgs[$i] = str_repeat($this->indChar, $this->indFirst).
83
+					wordwrap(
84
+							$pgs[$i],
85
+							max($this->wrap - $this->indent, 1),
86
+							$this->wrapChar.str_repeat($this->indChar, $this->indent),
87
+							$this->wrapCut
88
+					);
89
+		}
90 90
 
91
-        if ($this->assign !== '') {
92
-            $this->dwoo->assignInScope(implode($this->wrapChar.$this->wrapChar, $pgs), $this->assign);
93
-        } else {
94
-            return implode($this->wrapChar.$this->wrapChar, $pgs);
95
-        }
96
-    }
91
+		if ($this->assign !== '') {
92
+			$this->dwoo->assignInScope(implode($this->wrapChar.$this->wrapChar, $pgs), $this->assign);
93
+		} else {
94
+			return implode($this->wrapChar.$this->wrapChar, $pgs);
95
+		}
96
+	}
97 97
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/elseif.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -20,47 +20,47 @@
 block discarded – undo
20 20
  */
21 21
 class Dwoo_Plugin_elseif extends Dwoo_Plugin_if implements Dwoo_ICompilable_Block, Dwoo_IElseable
22 22
 {
23
-    public function init(array $rest)
24
-    {
25
-    }
23
+	public function init(array $rest)
24
+	{
25
+	}
26 26
 
27
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
28
-    {
29
-        $preContent = '';
30
-        while (true) {
31
-            $preContent .= $compiler->removeTopBlock();
32
-            $block = &$compiler->getCurrentBlock();
33
-            $interfaces = class_implements($block['class'], false);
34
-            if (in_array('Dwoo_IElseable', $interfaces) !== false) {
35
-                break;
36
-            }
37
-        }
27
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
28
+	{
29
+		$preContent = '';
30
+		while (true) {
31
+			$preContent .= $compiler->removeTopBlock();
32
+			$block = &$compiler->getCurrentBlock();
33
+			$interfaces = class_implements($block['class'], false);
34
+			if (in_array('Dwoo_IElseable', $interfaces) !== false) {
35
+				break;
36
+			}
37
+		}
38 38
 
39
-        $params['initialized'] = true;
40
-        $compiler->injectBlock($type, $params);
39
+		$params['initialized'] = true;
40
+		$compiler->injectBlock($type, $params);
41 41
 
42
-        return $preContent;
43
-    }
42
+		return $preContent;
43
+	}
44 44
 
45
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
46
-    {
47
-        if (!isset($params['initialized'])) {
48
-            return '';
49
-        }
45
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
46
+	{
47
+		if (!isset($params['initialized'])) {
48
+			return '';
49
+		}
50 50
 
51
-        $tokens = $compiler->getParamTokens($params);
52
-        $params = $compiler->getCompiledParams($params);
51
+		$tokens = $compiler->getParamTokens($params);
52
+		$params = $compiler->getCompiledParams($params);
53 53
 
54
-        $pre = Dwoo_Compiler::PHP_OPEN.'elseif ('.implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)).") {\n".Dwoo_Compiler::PHP_CLOSE;
55
-        $post = Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE;
54
+		$pre = Dwoo_Compiler::PHP_OPEN.'elseif ('.implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)).") {\n".Dwoo_Compiler::PHP_CLOSE;
55
+		$post = Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE;
56 56
 
57
-        if (isset($params['hasElse'])) {
58
-            $post .= $params['hasElse'];
59
-        }
57
+		if (isset($params['hasElse'])) {
58
+			$post .= $params['hasElse'];
59
+		}
60 60
 
61
-        $block = &$compiler->getCurrentBlock();
62
-        $block['params']['hasElse'] = $pre.$content.$post;
61
+		$block = &$compiler->getCurrentBlock();
62
+		$block['params']['hasElse'] = $pre.$content.$post;
63 63
 
64
-        return '';
65
-    }
64
+		return '';
65
+	}
66 66
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/capture.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -36,30 +36,30 @@
 block discarded – undo
36 36
  */
37 37
 class Dwoo_Plugin_capture extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
38 38
 {
39
-    public function init($name = 'default', $assign = null, $cat = false, $trim = false)
40
-    {
41
-    }
39
+	public function init($name = 'default', $assign = null, $cat = false, $trim = false)
40
+	{
41
+	}
42 42
 
43
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
44
-    {
45
-        return Dwoo_Compiler::PHP_OPEN.$prepend.'ob_start();'.$append.Dwoo_Compiler::PHP_CLOSE;
46
-    }
43
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
44
+	{
45
+		return Dwoo_Compiler::PHP_OPEN.$prepend.'ob_start();'.$append.Dwoo_Compiler::PHP_CLOSE;
46
+	}
47 47
 
48
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
49
-    {
50
-        $params = $compiler->getCompiledParams($params);
48
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
49
+	{
50
+		$params = $compiler->getCompiledParams($params);
51 51
 
52
-        $out = $content.Dwoo_Compiler::PHP_OPEN.$prepend."\n".'$tmp = ob_get_clean();';
53
-        if ($params['trim'] !== 'false' && $params['trim'] !== 0) {
54
-            $out .= "\n".'$tmp = trim($tmp);';
55
-        }
56
-        if ($params['cat'] === 'true' || $params['cat'] === 1) {
57
-            $out .= "\n".'$tmp = $this->readVar(\'dwoo.capture.\'.'.$params['name'].') . $tmp;';
58
-        }
59
-        if ($params['assign'] !== 'null') {
60
-            $out .= "\n".'$this->scope['.$params['assign'].'] = $tmp;';
61
-        }
52
+		$out = $content.Dwoo_Compiler::PHP_OPEN.$prepend."\n".'$tmp = ob_get_clean();';
53
+		if ($params['trim'] !== 'false' && $params['trim'] !== 0) {
54
+			$out .= "\n".'$tmp = trim($tmp);';
55
+		}
56
+		if ($params['cat'] === 'true' || $params['cat'] === 1) {
57
+			$out .= "\n".'$tmp = $this->readVar(\'dwoo.capture.\'.'.$params['name'].') . $tmp;';
58
+		}
59
+		if ($params['assign'] !== 'null') {
60
+			$out .= "\n".'$this->scope['.$params['assign'].'] = $tmp;';
61
+		}
62 62
 
63
-        return $out."\n".'$this->globals[\'capture\']['.$params['name'].'] = $tmp;'.$append.Dwoo_Compiler::PHP_CLOSE;
64
-    }
63
+		return $out."\n".'$this->globals[\'capture\']['.$params['name'].'] = $tmp;'.$append.Dwoo_Compiler::PHP_CLOSE;
64
+	}
65 65
 }
Please login to merge, or discard this patch.