Passed
Push — master ( 020752...f1625c )
by David
05:47 queued 02:32
created
lib/Dwoo/Plugins/Blocks/PluginLoop.php 2 patches
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -48,123 +48,123 @@
 block discarded – undo
48 48
  */
49 49
 class PluginLoop extends BlockPlugin implements ICompilableBlock, IElseable
50 50
 {
51
-    public static $cnt = 0;
51
+	public static $cnt = 0;
52 52
 
53
-    /**
54
-     * @param        $from
55
-     * @param string $name
56
-     */
57
-    public function init($from, $name = 'default')
58
-    {
59
-    }
53
+	/**
54
+	 * @param        $from
55
+	 * @param string $name
56
+	 */
57
+	public function init($from, $name = 'default')
58
+	{
59
+	}
60 60
 
61
-    /**
62
-     * @param Compiler $compiler
63
-     * @param array    $params
64
-     * @param string   $prepend
65
-     * @param string   $append
66
-     * @param string   $type
67
-     *
68
-     * @return string
69
-     */
70
-    public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
71
-    {
72
-        // get block params and save the current template pointer to use it in the postProcessing method
73
-        $currentBlock                         = &$compiler->getCurrentBlock();
74
-        $currentBlock['params']['tplPointer'] = $compiler->getPointer();
61
+	/**
62
+	 * @param Compiler $compiler
63
+	 * @param array    $params
64
+	 * @param string   $prepend
65
+	 * @param string   $append
66
+	 * @param string   $type
67
+	 *
68
+	 * @return string
69
+	 */
70
+	public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
71
+	{
72
+		// get block params and save the current template pointer to use it in the postProcessing method
73
+		$currentBlock                         = &$compiler->getCurrentBlock();
74
+		$currentBlock['params']['tplPointer'] = $compiler->getPointer();
75 75
 
76
-        return '';
77
-    }
76
+		return '';
77
+	}
78 78
 
79
-    /**
80
-     * @param Compiler $compiler
81
-     * @param array    $params
82
-     * @param string   $prepend
83
-     * @param string   $append
84
-     * @param string   $content
85
-     *
86
-     * @return string
87
-     */
88
-    public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
89
-    {
90
-        $params = $compiler->getCompiledParams($params);
91
-        $tpl    = $compiler->getTemplateSource($params['tplPointer']);
79
+	/**
80
+	 * @param Compiler $compiler
81
+	 * @param array    $params
82
+	 * @param string   $prepend
83
+	 * @param string   $append
84
+	 * @param string   $content
85
+	 *
86
+	 * @return string
87
+	 */
88
+	public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
89
+	{
90
+		$params = $compiler->getCompiledParams($params);
91
+		$tpl    = $compiler->getTemplateSource($params['tplPointer']);
92 92
 
93
-        // assigns params
94
-        $src  = $params['from'];
95
-        $name = $params['name'];
93
+		// assigns params
94
+		$src  = $params['from'];
95
+		$name = $params['name'];
96 96
 
97
-        // evaluates which global variables have to be computed
98
-        $varName       = '$dwoo.loop.' . trim($name, '"\'') . '.';
99
-        $shortVarName  = '$.loop.' . trim($name, '"\'') . '.';
100
-        $usesAny       = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
101
-        $usesFirst     = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false;
102
-        $usesLast      = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false;
103
-        $usesIndex     = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
104
-        $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false;
105
-        $usesShow      = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false;
106
-        $usesTotal     = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false;
97
+		// evaluates which global variables have to be computed
98
+		$varName       = '$dwoo.loop.' . trim($name, '"\'') . '.';
99
+		$shortVarName  = '$.loop.' . trim($name, '"\'') . '.';
100
+		$usesAny       = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
101
+		$usesFirst     = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false;
102
+		$usesLast      = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false;
103
+		$usesIndex     = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
104
+		$usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false;
105
+		$usesShow      = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false;
106
+		$usesTotal     = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false;
107 107
 
108
-        if (strpos($name, '$this->scope[') !== false) {
109
-            $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
110
-        }
108
+		if (strpos($name, '$this->scope[') !== false) {
109
+			$usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
110
+		}
111 111
 
112
-        // gets foreach id
113
-        $cnt = self::$cnt ++;
112
+		// gets foreach id
113
+		$cnt = self::$cnt ++;
114 114
 
115
-        // builds pre processing output
116
-        $pre = Compiler::PHP_OPEN . "\n" . '$_loop' . $cnt . '_data = ' . $src . ';';
117
-        // adds foreach properties
118
-        if ($usesAny) {
119
-            $pre .= "\n" . '$this->globals["loop"][' . $name . '] = array' . "\n(";
120
-            if ($usesIndex) {
121
-                $pre .= "\n\t" . '"index"		=> 0,';
122
-            }
123
-            if ($usesIteration) {
124
-                $pre .= "\n\t" . '"iteration"		=> 1,';
125
-            }
126
-            if ($usesFirst) {
127
-                $pre .= "\n\t" . '"first"		=> null,';
128
-            }
129
-            if ($usesLast) {
130
-                $pre .= "\n\t" . '"last"		=> null,';
131
-            }
132
-            if ($usesShow) {
133
-                $pre .= "\n\t" . '"show"		=> $this->isTraversable($_loop' . $cnt . '_data, true),';
134
-            }
135
-            if ($usesTotal) {
136
-                $pre .= "\n\t" . '"total"		=> $this->count($_loop' . $cnt . '_data),';
137
-            }
138
-            $pre .= "\n);\n" . '$_loop' . $cnt . '_glob =& $this->globals["loop"][' . $name . '];';
139
-        }
140
-        // checks if the loop must be looped
141
-        $pre .= "\n" . 'if ($this->isTraversable($_loop' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{";
142
-        // iterates over keys
143
-        $pre .= "\n\t" . 'foreach ($_loop' . $cnt . '_data as $tmp_key => $this->scope["-loop-"])' . "\n\t{";
144
-        // updates properties
145
-        if ($usesFirst) {
146
-            $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["first"] = (string) ($_loop' . $cnt . '_glob["index"] === 0);';
147
-        }
148
-        if ($usesLast) {
149
-            $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["last"] = (string) ($_loop' . $cnt . '_glob["iteration"] === $_loop' . $cnt . '_glob["total"]);';
150
-        }
151
-        $pre .= "\n\t\t" . '$_loop' . $cnt . '_scope = $this->setScope(array("-loop-"));' . "\n/* -- loop start output */\n" . Compiler::PHP_CLOSE;
115
+		// builds pre processing output
116
+		$pre = Compiler::PHP_OPEN . "\n" . '$_loop' . $cnt . '_data = ' . $src . ';';
117
+		// adds foreach properties
118
+		if ($usesAny) {
119
+			$pre .= "\n" . '$this->globals["loop"][' . $name . '] = array' . "\n(";
120
+			if ($usesIndex) {
121
+				$pre .= "\n\t" . '"index"		=> 0,';
122
+			}
123
+			if ($usesIteration) {
124
+				$pre .= "\n\t" . '"iteration"		=> 1,';
125
+			}
126
+			if ($usesFirst) {
127
+				$pre .= "\n\t" . '"first"		=> null,';
128
+			}
129
+			if ($usesLast) {
130
+				$pre .= "\n\t" . '"last"		=> null,';
131
+			}
132
+			if ($usesShow) {
133
+				$pre .= "\n\t" . '"show"		=> $this->isTraversable($_loop' . $cnt . '_data, true),';
134
+			}
135
+			if ($usesTotal) {
136
+				$pre .= "\n\t" . '"total"		=> $this->count($_loop' . $cnt . '_data),';
137
+			}
138
+			$pre .= "\n);\n" . '$_loop' . $cnt . '_glob =& $this->globals["loop"][' . $name . '];';
139
+		}
140
+		// checks if the loop must be looped
141
+		$pre .= "\n" . 'if ($this->isTraversable($_loop' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{";
142
+		// iterates over keys
143
+		$pre .= "\n\t" . 'foreach ($_loop' . $cnt . '_data as $tmp_key => $this->scope["-loop-"])' . "\n\t{";
144
+		// updates properties
145
+		if ($usesFirst) {
146
+			$pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["first"] = (string) ($_loop' . $cnt . '_glob["index"] === 0);';
147
+		}
148
+		if ($usesLast) {
149
+			$pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["last"] = (string) ($_loop' . $cnt . '_glob["iteration"] === $_loop' . $cnt . '_glob["total"]);';
150
+		}
151
+		$pre .= "\n\t\t" . '$_loop' . $cnt . '_scope = $this->setScope(array("-loop-"));' . "\n/* -- loop start output */\n" . Compiler::PHP_CLOSE;
152 152
 
153
-        // build post processing output and cache it
154
-        $post = Compiler::PHP_OPEN . "\n" . '/* -- loop end output */' . "\n\t\t" . '$this->setScope($_loop' . $cnt . '_scope, true);';
155
-        // update properties
156
-        if ($usesIndex) {
157
-            $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["index"]+=1;';
158
-        }
159
-        if ($usesIteration) {
160
-            $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["iteration"]+=1;';
161
-        }
162
-        // end loop
163
-        $post .= "\n\t}\n}\n" . Compiler::PHP_CLOSE;
164
-        if (isset($params['hasElse'])) {
165
-            $post .= $params['hasElse'];
166
-        }
153
+		// build post processing output and cache it
154
+		$post = Compiler::PHP_OPEN . "\n" . '/* -- loop end output */' . "\n\t\t" . '$this->setScope($_loop' . $cnt . '_scope, true);';
155
+		// update properties
156
+		if ($usesIndex) {
157
+			$post .= "\n\t\t" . '$_loop' . $cnt . '_glob["index"]+=1;';
158
+		}
159
+		if ($usesIteration) {
160
+			$post .= "\n\t\t" . '$_loop' . $cnt . '_glob["iteration"]+=1;';
161
+		}
162
+		// end loop
163
+		$post .= "\n\t}\n}\n" . Compiler::PHP_CLOSE;
164
+		if (isset($params['hasElse'])) {
165
+			$post .= $params['hasElse'];
166
+		}
167 167
 
168
-        return $pre . $content . $post;
169
-    }
168
+		return $pre . $content . $post;
169
+	}
170 170
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -95,76 +95,76 @@
 block discarded – undo
95 95
         $name = $params['name'];
96 96
 
97 97
         // evaluates which global variables have to be computed
98
-        $varName       = '$dwoo.loop.' . trim($name, '"\'') . '.';
99
-        $shortVarName  = '$.loop.' . trim($name, '"\'') . '.';
98
+        $varName       = '$dwoo.loop.'.trim($name, '"\'').'.';
99
+        $shortVarName  = '$.loop.'.trim($name, '"\'').'.';
100 100
         $usesAny       = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
101
-        $usesFirst     = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false;
102
-        $usesLast      = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false;
103
-        $usesIndex     = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
104
-        $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false;
105
-        $usesShow      = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false;
106
-        $usesTotal     = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false;
101
+        $usesFirst     = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false;
102
+        $usesLast      = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false;
103
+        $usesIndex     = $usesFirst || strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false;
104
+        $usesIteration = $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false;
105
+        $usesShow      = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false;
106
+        $usesTotal     = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false;
107 107
 
108 108
         if (strpos($name, '$this->scope[') !== false) {
109 109
             $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
110 110
         }
111 111
 
112 112
         // gets foreach id
113
-        $cnt = self::$cnt ++;
113
+        $cnt = self::$cnt++;
114 114
 
115 115
         // builds pre processing output
116
-        $pre = Compiler::PHP_OPEN . "\n" . '$_loop' . $cnt . '_data = ' . $src . ';';
116
+        $pre = Compiler::PHP_OPEN."\n".'$_loop'.$cnt.'_data = '.$src.';';
117 117
         // adds foreach properties
118 118
         if ($usesAny) {
119
-            $pre .= "\n" . '$this->globals["loop"][' . $name . '] = array' . "\n(";
119
+            $pre .= "\n".'$this->globals["loop"]['.$name.'] = array'."\n(";
120 120
             if ($usesIndex) {
121
-                $pre .= "\n\t" . '"index"		=> 0,';
121
+                $pre .= "\n\t".'"index"		=> 0,';
122 122
             }
123 123
             if ($usesIteration) {
124
-                $pre .= "\n\t" . '"iteration"		=> 1,';
124
+                $pre .= "\n\t".'"iteration"		=> 1,';
125 125
             }
126 126
             if ($usesFirst) {
127
-                $pre .= "\n\t" . '"first"		=> null,';
127
+                $pre .= "\n\t".'"first"		=> null,';
128 128
             }
129 129
             if ($usesLast) {
130
-                $pre .= "\n\t" . '"last"		=> null,';
130
+                $pre .= "\n\t".'"last"		=> null,';
131 131
             }
132 132
             if ($usesShow) {
133
-                $pre .= "\n\t" . '"show"		=> $this->isTraversable($_loop' . $cnt . '_data, true),';
133
+                $pre .= "\n\t".'"show"		=> $this->isTraversable($_loop'.$cnt.'_data, true),';
134 134
             }
135 135
             if ($usesTotal) {
136
-                $pre .= "\n\t" . '"total"		=> $this->count($_loop' . $cnt . '_data),';
136
+                $pre .= "\n\t".'"total"		=> $this->count($_loop'.$cnt.'_data),';
137 137
             }
138
-            $pre .= "\n);\n" . '$_loop' . $cnt . '_glob =& $this->globals["loop"][' . $name . '];';
138
+            $pre .= "\n);\n".'$_loop'.$cnt.'_glob =& $this->globals["loop"]['.$name.'];';
139 139
         }
140 140
         // checks if the loop must be looped
141
-        $pre .= "\n" . 'if ($this->isTraversable($_loop' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{";
141
+        $pre .= "\n".'if ($this->isTraversable($_loop'.$cnt.'_data'.(isset($params['hasElse']) ? ', true' : '').') == true)'."\n{";
142 142
         // iterates over keys
143
-        $pre .= "\n\t" . 'foreach ($_loop' . $cnt . '_data as $tmp_key => $this->scope["-loop-"])' . "\n\t{";
143
+        $pre .= "\n\t".'foreach ($_loop'.$cnt.'_data as $tmp_key => $this->scope["-loop-"])'."\n\t{";
144 144
         // updates properties
145 145
         if ($usesFirst) {
146
-            $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["first"] = (string) ($_loop' . $cnt . '_glob["index"] === 0);';
146
+            $pre .= "\n\t\t".'$_loop'.$cnt.'_glob["first"] = (string) ($_loop'.$cnt.'_glob["index"] === 0);';
147 147
         }
148 148
         if ($usesLast) {
149
-            $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["last"] = (string) ($_loop' . $cnt . '_glob["iteration"] === $_loop' . $cnt . '_glob["total"]);';
149
+            $pre .= "\n\t\t".'$_loop'.$cnt.'_glob["last"] = (string) ($_loop'.$cnt.'_glob["iteration"] === $_loop'.$cnt.'_glob["total"]);';
150 150
         }
151
-        $pre .= "\n\t\t" . '$_loop' . $cnt . '_scope = $this->setScope(array("-loop-"));' . "\n/* -- loop start output */\n" . Compiler::PHP_CLOSE;
151
+        $pre .= "\n\t\t".'$_loop'.$cnt.'_scope = $this->setScope(array("-loop-"));'."\n/* -- loop start output */\n".Compiler::PHP_CLOSE;
152 152
 
153 153
         // build post processing output and cache it
154
-        $post = Compiler::PHP_OPEN . "\n" . '/* -- loop end output */' . "\n\t\t" . '$this->setScope($_loop' . $cnt . '_scope, true);';
154
+        $post = Compiler::PHP_OPEN."\n".'/* -- loop end output */'."\n\t\t".'$this->setScope($_loop'.$cnt.'_scope, true);';
155 155
         // update properties
156 156
         if ($usesIndex) {
157
-            $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["index"]+=1;';
157
+            $post .= "\n\t\t".'$_loop'.$cnt.'_glob["index"]+=1;';
158 158
         }
159 159
         if ($usesIteration) {
160
-            $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["iteration"]+=1;';
160
+            $post .= "\n\t\t".'$_loop'.$cnt.'_glob["iteration"]+=1;';
161 161
         }
162 162
         // end loop
163
-        $post .= "\n\t}\n}\n" . Compiler::PHP_CLOSE;
163
+        $post .= "\n\t}\n}\n".Compiler::PHP_CLOSE;
164 164
         if (isset($params['hasElse'])) {
165 165
             $post .= $params['hasElse'];
166 166
         }
167 167
 
168
-        return $pre . $content . $post;
168
+        return $pre.$content.$post;
169 169
     }
170 170
 }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Blocks/PluginAutoEscape.php 3 patches
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -32,67 +32,67 @@
 block discarded – undo
32 32
  */
33 33
 class PluginAutoEscape extends BlockPlugin implements ICompilableBlock
34 34
 {
35
-    protected static $stack = array();
35
+	protected static $stack = array();
36 36
 
37
-    /**
38
-     * @param $enabled
39
-     */
40
-    public function init($enabled)
41
-    {
42
-    }
37
+	/**
38
+	 * @param $enabled
39
+	 */
40
+	public function init($enabled)
41
+	{
42
+	}
43 43
 
44
-    /**
45
-     * @param Compiler $compiler
46
-     * @param array    $params
47
-     * @param string   $prepend
48
-     * @param string   $append
49
-     * @param string   $type
50
-     *
51
-     * @return string
52
-     * @throws CompilationException
53
-     */
54
-    public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
55
-    {
56
-        $params = $compiler->getCompiledParams($params);
57
-        switch (strtolower(trim((string)$params['enabled'], '"\''))) {
44
+	/**
45
+	 * @param Compiler $compiler
46
+	 * @param array    $params
47
+	 * @param string   $prepend
48
+	 * @param string   $append
49
+	 * @param string   $type
50
+	 *
51
+	 * @return string
52
+	 * @throws CompilationException
53
+	 */
54
+	public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
55
+	{
56
+		$params = $compiler->getCompiledParams($params);
57
+		switch (strtolower(trim((string)$params['enabled'], '"\''))) {
58 58
 
59
-            case 'on':
60
-            case 'true':
61
-            case 'enabled':
62
-            case 'enable':
63
-            case '1':
64
-                $enable = true;
65
-                break;
66
-            case 'off':
67
-            case 'false':
68
-            case 'disabled':
69
-            case 'disable':
70
-            case '0':
71
-                $enable = false;
72
-                break;
73
-            default:
74
-                throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false');
75
-        }
59
+			case 'on':
60
+			case 'true':
61
+			case 'enabled':
62
+			case 'enable':
63
+			case '1':
64
+				$enable = true;
65
+				break;
66
+			case 'off':
67
+			case 'false':
68
+			case 'disabled':
69
+			case 'disable':
70
+			case '0':
71
+				$enable = false;
72
+				break;
73
+			default:
74
+				throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false');
75
+		}
76 76
 
77
-        self::$stack[] = $compiler->getAutoEscape();
78
-        $compiler->setAutoEscape($enable);
77
+		self::$stack[] = $compiler->getAutoEscape();
78
+		$compiler->setAutoEscape($enable);
79 79
 
80
-        return '';
81
-    }
80
+		return '';
81
+	}
82 82
 
83
-    /**
84
-     * @param Compiler $compiler
85
-     * @param array    $params
86
-     * @param string   $prepend
87
-     * @param string   $append
88
-     * @param string   $content
89
-     *
90
-     * @return string
91
-     */
92
-    public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
93
-    {
94
-        $compiler->setAutoEscape(array_pop(self::$stack));
83
+	/**
84
+	 * @param Compiler $compiler
85
+	 * @param array    $params
86
+	 * @param string   $prepend
87
+	 * @param string   $append
88
+	 * @param string   $content
89
+	 *
90
+	 * @return string
91
+	 */
92
+	public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
93
+	{
94
+		$compiler->setAutoEscape(array_pop(self::$stack));
95 95
 
96
-        return $content;
97
-    }
96
+		return $content;
97
+	}
98 98
 }
Please login to merge, or discard this patch.
Switch Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -56,22 +56,22 @@
 block discarded – undo
56 56
         $params = $compiler->getCompiledParams($params);
57 57
         switch (strtolower(trim((string)$params['enabled'], '"\''))) {
58 58
 
59
-            case 'on':
60
-            case 'true':
61
-            case 'enabled':
62
-            case 'enable':
63
-            case '1':
64
-                $enable = true;
65
-                break;
66
-            case 'off':
67
-            case 'false':
68
-            case 'disabled':
69
-            case 'disable':
70
-            case '0':
71
-                $enable = false;
72
-                break;
73
-            default:
74
-                throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false');
59
+        case 'on':
60
+        case 'true':
61
+        case 'enabled':
62
+        case 'enable':
63
+        case '1':
64
+            $enable = true;
65
+            break;
66
+        case 'off':
67
+        case 'false':
68
+        case 'disabled':
69
+        case 'disable':
70
+        case '0':
71
+            $enable = false;
72
+            break;
73
+        default:
74
+            throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false');
75 75
         }
76 76
 
77 77
         self::$stack[] = $compiler->getAutoEscape();
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
55 55
     {
56 56
         $params = $compiler->getCompiledParams($params);
57
-        switch (strtolower(trim((string)$params['enabled'], '"\''))) {
57
+        switch (strtolower(trim((string) $params['enabled'], '"\''))) {
58 58
 
59 59
             case 'on':
60 60
             case 'true':
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
                 $enable = false;
72 72
                 break;
73 73
             default:
74
-                throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false');
74
+                throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter ('.$params['enabled'].'), valid parameters are "enable"/true or "disable"/false');
75 75
         }
76 76
 
77 77
         self::$stack[] = $compiler->getAutoEscape();
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Blocks/PluginElse.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -38,59 +38,59 @@
 block discarded – undo
38 38
  */
39 39
 class PluginElse extends BlockPlugin implements ICompilableBlock
40 40
 {
41
-    public function init()
42
-    {
43
-    }
41
+	public function init()
42
+	{
43
+	}
44 44
 
45
-    /**
46
-     * @param Compiler $compiler
47
-     * @param array    $params
48
-     * @param string   $prepend
49
-     * @param string   $append
50
-     * @param string   $type
51
-     *
52
-     * @return string
53
-     * @throws CompilationException
54
-     */
55
-    public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
56
-    {
57
-        $preContent = '';
58
-        while (true) {
59
-            $preContent .= $compiler->removeTopBlock();
60
-            $block = &$compiler->getCurrentBlock();
61
-            if (!$block) {
62
-                throw new CompilationException($compiler, 'An else block was found but it was not preceded by an if or other else-able construct');
63
-            }
64
-            $interfaces = class_implements($block['class']);
65
-            if (in_array('Dwoo\IElseable', $interfaces) !== false) {
66
-                break;
67
-            }
68
-        }
45
+	/**
46
+	 * @param Compiler $compiler
47
+	 * @param array    $params
48
+	 * @param string   $prepend
49
+	 * @param string   $append
50
+	 * @param string   $type
51
+	 *
52
+	 * @return string
53
+	 * @throws CompilationException
54
+	 */
55
+	public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
56
+	{
57
+		$preContent = '';
58
+		while (true) {
59
+			$preContent .= $compiler->removeTopBlock();
60
+			$block = &$compiler->getCurrentBlock();
61
+			if (!$block) {
62
+				throw new CompilationException($compiler, 'An else block was found but it was not preceded by an if or other else-able construct');
63
+			}
64
+			$interfaces = class_implements($block['class']);
65
+			if (in_array('Dwoo\IElseable', $interfaces) !== false) {
66
+				break;
67
+			}
68
+		}
69 69
 
70
-        $params['initialized'] = true;
71
-        $compiler->injectBlock($type, $params);
70
+		$params['initialized'] = true;
71
+		$compiler->injectBlock($type, $params);
72 72
 
73
-        return $preContent;
74
-    }
73
+		return $preContent;
74
+	}
75 75
 
76
-    /**
77
-     * @param Compiler $compiler
78
-     * @param array    $params
79
-     * @param string   $prepend
80
-     * @param string   $append
81
-     * @param string   $content
82
-     *
83
-     * @return string
84
-     */
85
-    public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
86
-    {
87
-        if (!isset($params['initialized'])) {
88
-            return '';
89
-        }
76
+	/**
77
+	 * @param Compiler $compiler
78
+	 * @param array    $params
79
+	 * @param string   $prepend
80
+	 * @param string   $append
81
+	 * @param string   $content
82
+	 *
83
+	 * @return string
84
+	 */
85
+	public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
86
+	{
87
+		if (!isset($params['initialized'])) {
88
+			return '';
89
+		}
90 90
 
91
-        $block                      = &$compiler->getCurrentBlock();
92
-        $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
91
+		$block                      = &$compiler->getCurrentBlock();
92
+		$block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
93 93
 
94
-        return '';
95
-    }
94
+		return '';
95
+	}
96 96
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@
 block discarded – undo
66 66
         }
67 67
 
68 68
         $block                      = &$compiler->getCurrentBlock();
69
-        $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
69
+        $block['params']['hasElse'] = Compiler::PHP_OPEN."else {\n".Compiler::PHP_CLOSE.$content.Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE;
70 70
 
71 71
         return '';
72 72
     }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Blocks/PluginSection.php 2 patches
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -28,98 +28,98 @@  discard block
 block discarded – undo
28 28
  */
29 29
 class PluginSection extends BlockPlugin implements ICompilableBlock, IElseable
30 30
 {
31
-    public static $cnt = 0;
32
-
33
-    /**
34
-     * @param      $name
35
-     * @param      $loop
36
-     * @param null $start
37
-     * @param null $step
38
-     * @param null $max
39
-     * @param bool $show
40
-     */
41
-    public function init($name, $loop, $start = null, $step = null, $max = null, $show = true)
42
-    {
43
-    }
44
-
45
-    /**
46
-     * @param Compiler $compiler
47
-     * @param array    $params
48
-     * @param string   $prepend
49
-     * @param string   $append
50
-     * @param string   $type
51
-     *
52
-     * @return string
53
-     */
54
-    public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
55
-    {
56
-        return '';
57
-    }
58
-
59
-    /**
60
-     * @param Compiler $compiler
61
-     * @param array    $params
62
-     * @param string   $prepend
63
-     * @param string   $append
64
-     * @param string   $content
65
-     *
66
-     * @return string
67
-     */
68
-    public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
69
-    {
70
-        $output = Compiler::PHP_OPEN;
71
-        $params = $compiler->getCompiledParams($params);
72
-
73
-        // assigns params
74
-        $loop  = $params['loop'];
75
-        $start = $params['start'];
76
-        $max   = $params['max'];
77
-        $name  = $params['name'];
78
-        $step  = $params['step'];
79
-        $show  = $params['show'];
80
-
81
-        // gets unique id
82
-        $cnt = self::$cnt ++;
83
-
84
-        $output .= '$this->globals[\'section\'][' . $name . '] = array();' . "\n" . '$_section' . $cnt . ' =& $this->globals[\'section\'][' . $name . '];' . "\n";
85
-
86
-        if ($loop !== 'null') {
87
-            $output .= '$_section' . $cnt . '[\'loop\'] = is_array($tmp = ' . $loop . ') ? count($tmp) : max(0, (int) $tmp);' . "\n";
88
-        } else {
89
-            $output .= '$_section' . $cnt . '[\'loop\'] = 1;' . "\n";
90
-        }
91
-
92
-        if ($show !== 'null') {
93
-            $output .= '$_section' . $cnt . '[\'show\'] = ' . $show . ";\n";
94
-        } else {
95
-            $output .= '$_section' . $cnt . '[\'show\'] = true;' . "\n";
96
-        }
97
-
98
-        if ($name !== 'null') {
99
-            $output .= '$_section' . $cnt . '[\'name\'] = ' . $name . ";\n";
100
-        } else {
101
-            $output .= '$_section' . $cnt . '[\'name\'] = true;' . "\n";
102
-        }
103
-
104
-        if ($max !== 'null') {
105
-            $output .= '$_section' . $cnt . '[\'max\'] = (int)' . $max . ";\n" . 'if($_section' . $cnt . '[\'max\'] < 0) { $_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\']; }' . "\n";
106
-        } else {
107
-            $output .= '$_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\'];' . "\n";
108
-        }
109
-
110
-        if ($step !== 'null') {
111
-            $output .= '$_section' . $cnt . '[\'step\'] = (int)' . $step . ' == 0 ? 1 : (int) ' . $step . ";\n";
112
-        } else {
113
-            $output .= '$_section' . $cnt . '[\'step\'] = 1;' . "\n";
114
-        }
115
-
116
-        if ($start !== 'null') {
117
-            $output .= '$_section' . $cnt . '[\'start\'] = (int)' . $start . ";\n";
118
-        } else {
119
-            $output .= '$_section' . $cnt . '[\'start\'] = $_section' . $cnt . '[\'step\'] > 0 ? 0 : $_section' . $cnt . '[\'loop\'] - 1;' . "\n" . 'if ($_section' . $cnt . '[\'start\'] < 0) { $_section' . $cnt . '[\'start\'] = max($_section' . $cnt . '[\'step\'] > 0 ? 0 : -1, $_section' . $cnt . '[\'loop\'] + $_section' . $cnt . '[\'start\']); } ' . "\n" . 'else { $_section' . $cnt . '[\'start\'] = min($_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] : $_section' . $cnt . '[\'loop\'] -1); }' . "\n";
120
-        }
121
-
122
-        /*		if ($usesAny) {
31
+	public static $cnt = 0;
32
+
33
+	/**
34
+	 * @param      $name
35
+	 * @param      $loop
36
+	 * @param null $start
37
+	 * @param null $step
38
+	 * @param null $max
39
+	 * @param bool $show
40
+	 */
41
+	public function init($name, $loop, $start = null, $step = null, $max = null, $show = true)
42
+	{
43
+	}
44
+
45
+	/**
46
+	 * @param Compiler $compiler
47
+	 * @param array    $params
48
+	 * @param string   $prepend
49
+	 * @param string   $append
50
+	 * @param string   $type
51
+	 *
52
+	 * @return string
53
+	 */
54
+	public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
55
+	{
56
+		return '';
57
+	}
58
+
59
+	/**
60
+	 * @param Compiler $compiler
61
+	 * @param array    $params
62
+	 * @param string   $prepend
63
+	 * @param string   $append
64
+	 * @param string   $content
65
+	 *
66
+	 * @return string
67
+	 */
68
+	public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
69
+	{
70
+		$output = Compiler::PHP_OPEN;
71
+		$params = $compiler->getCompiledParams($params);
72
+
73
+		// assigns params
74
+		$loop  = $params['loop'];
75
+		$start = $params['start'];
76
+		$max   = $params['max'];
77
+		$name  = $params['name'];
78
+		$step  = $params['step'];
79
+		$show  = $params['show'];
80
+
81
+		// gets unique id
82
+		$cnt = self::$cnt ++;
83
+
84
+		$output .= '$this->globals[\'section\'][' . $name . '] = array();' . "\n" . '$_section' . $cnt . ' =& $this->globals[\'section\'][' . $name . '];' . "\n";
85
+
86
+		if ($loop !== 'null') {
87
+			$output .= '$_section' . $cnt . '[\'loop\'] = is_array($tmp = ' . $loop . ') ? count($tmp) : max(0, (int) $tmp);' . "\n";
88
+		} else {
89
+			$output .= '$_section' . $cnt . '[\'loop\'] = 1;' . "\n";
90
+		}
91
+
92
+		if ($show !== 'null') {
93
+			$output .= '$_section' . $cnt . '[\'show\'] = ' . $show . ";\n";
94
+		} else {
95
+			$output .= '$_section' . $cnt . '[\'show\'] = true;' . "\n";
96
+		}
97
+
98
+		if ($name !== 'null') {
99
+			$output .= '$_section' . $cnt . '[\'name\'] = ' . $name . ";\n";
100
+		} else {
101
+			$output .= '$_section' . $cnt . '[\'name\'] = true;' . "\n";
102
+		}
103
+
104
+		if ($max !== 'null') {
105
+			$output .= '$_section' . $cnt . '[\'max\'] = (int)' . $max . ";\n" . 'if($_section' . $cnt . '[\'max\'] < 0) { $_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\']; }' . "\n";
106
+		} else {
107
+			$output .= '$_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\'];' . "\n";
108
+		}
109
+
110
+		if ($step !== 'null') {
111
+			$output .= '$_section' . $cnt . '[\'step\'] = (int)' . $step . ' == 0 ? 1 : (int) ' . $step . ";\n";
112
+		} else {
113
+			$output .= '$_section' . $cnt . '[\'step\'] = 1;' . "\n";
114
+		}
115
+
116
+		if ($start !== 'null') {
117
+			$output .= '$_section' . $cnt . '[\'start\'] = (int)' . $start . ";\n";
118
+		} else {
119
+			$output .= '$_section' . $cnt . '[\'start\'] = $_section' . $cnt . '[\'step\'] > 0 ? 0 : $_section' . $cnt . '[\'loop\'] - 1;' . "\n" . 'if ($_section' . $cnt . '[\'start\'] < 0) { $_section' . $cnt . '[\'start\'] = max($_section' . $cnt . '[\'step\'] > 0 ? 0 : -1, $_section' . $cnt . '[\'loop\'] + $_section' . $cnt . '[\'start\']); } ' . "\n" . 'else { $_section' . $cnt . '[\'start\'] = min($_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] : $_section' . $cnt . '[\'loop\'] -1); }' . "\n";
120
+		}
121
+
122
+		/*		if ($usesAny) {
123 123
                     $output .= "\n".'$this->globals["section"]['.$name.'] = array'."\n(";
124 124
                     if ($usesIndex) $output .="\n\t".'"index"		=> 0,';
125 125
                     if ($usesIteration) $output .="\n\t".'"iteration"		=> 1,';
@@ -131,29 +131,29 @@  discard block
 block discarded – undo
131 131
                 }
132 132
         */
133 133
 
134
-        $output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n";
135
-        if ($start === 'null' && $step === 'null' && $max === 'null') {
136
-            $output .= '	$_section' . $cnt . '[\'total\'] = $_section' . $cnt . '[\'loop\'];' . "\n";
137
-        } else {
138
-            $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";
139
-        }
140
-        $output .= '	if ($_section' . $cnt . '[\'total\'] == 0) {' . "\n" . '		$_section' . $cnt . '[\'show\'] = false;' . "\n" . '	}' . "\n" . '} else {' . "\n" . '	$_section' . $cnt . '[\'total\'] = 0;' . "\n}\n";
141
-        $output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n";
142
-        $output .= "\t" . 'for ($this->scope[' . $name . '] = $_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'iteration\'] = 1; ' . '$_section' . $cnt . '[\'iteration\'] <= $_section' . $cnt . '[\'total\']; ' . '$this->scope[' . $name . '] += $_section' . $cnt . '[\'step\'], $_section' . $cnt . '[\'iteration\']++) {' . "\n";
143
-        $output .= "\t\t" . '$_section' . $cnt . '[\'rownum\'] = $_section' . $cnt . '[\'iteration\'];' . "\n";
144
-        $output .= "\t\t" . '$_section' . $cnt . '[\'index_prev\'] = $this->scope[' . $name . '] - $_section' . $cnt . '[\'step\'];' . "\n";
145
-        $output .= "\t\t" . '$_section' . $cnt . '[\'index_next\'] = $this->scope[' . $name . '] + $_section' . $cnt . '[\'step\'];' . "\n";
146
-        $output .= "\t\t" . '$_section' . $cnt . '[\'first\']      = ($_section' . $cnt . '[\'iteration\'] == 1);' . "\n";
147
-        $output .= "\t\t" . '$_section' . $cnt . '[\'last\']       = ($_section' . $cnt . '[\'iteration\'] == $_section' . $cnt . '[\'total\']);' . "\n";
148
-
149
-        $output .= Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN;
150
-
151
-        $output .= "\n\t}\n} " . Compiler::PHP_CLOSE;
152
-
153
-        if (isset($params['hasElse'])) {
154
-            $output .= $params['hasElse'];
155
-        }
156
-
157
-        return $output;
158
-    }
134
+		$output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n";
135
+		if ($start === 'null' && $step === 'null' && $max === 'null') {
136
+			$output .= '	$_section' . $cnt . '[\'total\'] = $_section' . $cnt . '[\'loop\'];' . "\n";
137
+		} else {
138
+			$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";
139
+		}
140
+		$output .= '	if ($_section' . $cnt . '[\'total\'] == 0) {' . "\n" . '		$_section' . $cnt . '[\'show\'] = false;' . "\n" . '	}' . "\n" . '} else {' . "\n" . '	$_section' . $cnt . '[\'total\'] = 0;' . "\n}\n";
141
+		$output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n";
142
+		$output .= "\t" . 'for ($this->scope[' . $name . '] = $_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'iteration\'] = 1; ' . '$_section' . $cnt . '[\'iteration\'] <= $_section' . $cnt . '[\'total\']; ' . '$this->scope[' . $name . '] += $_section' . $cnt . '[\'step\'], $_section' . $cnt . '[\'iteration\']++) {' . "\n";
143
+		$output .= "\t\t" . '$_section' . $cnt . '[\'rownum\'] = $_section' . $cnt . '[\'iteration\'];' . "\n";
144
+		$output .= "\t\t" . '$_section' . $cnt . '[\'index_prev\'] = $this->scope[' . $name . '] - $_section' . $cnt . '[\'step\'];' . "\n";
145
+		$output .= "\t\t" . '$_section' . $cnt . '[\'index_next\'] = $this->scope[' . $name . '] + $_section' . $cnt . '[\'step\'];' . "\n";
146
+		$output .= "\t\t" . '$_section' . $cnt . '[\'first\']      = ($_section' . $cnt . '[\'iteration\'] == 1);' . "\n";
147
+		$output .= "\t\t" . '$_section' . $cnt . '[\'last\']       = ($_section' . $cnt . '[\'iteration\'] == $_section' . $cnt . '[\'total\']);' . "\n";
148
+
149
+		$output .= Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN;
150
+
151
+		$output .= "\n\t}\n} " . Compiler::PHP_CLOSE;
152
+
153
+		if (isset($params['hasElse'])) {
154
+			$output .= $params['hasElse'];
155
+		}
156
+
157
+		return $output;
158
+	}
159 159
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -79,44 +79,44 @@  discard block
 block discarded – undo
79 79
         $show  = $params['show'];
80 80
 
81 81
         // gets unique id
82
-        $cnt = self::$cnt ++;
82
+        $cnt = self::$cnt++;
83 83
 
84
-        $output .= '$this->globals[\'section\'][' . $name . '] = array();' . "\n" . '$_section' . $cnt . ' =& $this->globals[\'section\'][' . $name . '];' . "\n";
84
+        $output .= '$this->globals[\'section\']['.$name.'] = array();'."\n".'$_section'.$cnt.' =& $this->globals[\'section\']['.$name.'];'."\n";
85 85
 
86 86
         if ($loop !== 'null') {
87
-            $output .= '$_section' . $cnt . '[\'loop\'] = is_array($tmp = ' . $loop . ') ? count($tmp) : max(0, (int) $tmp);' . "\n";
87
+            $output .= '$_section'.$cnt.'[\'loop\'] = is_array($tmp = '.$loop.') ? count($tmp) : max(0, (int) $tmp);'."\n";
88 88
         } else {
89
-            $output .= '$_section' . $cnt . '[\'loop\'] = 1;' . "\n";
89
+            $output .= '$_section'.$cnt.'[\'loop\'] = 1;'."\n";
90 90
         }
91 91
 
92 92
         if ($show !== 'null') {
93
-            $output .= '$_section' . $cnt . '[\'show\'] = ' . $show . ";\n";
93
+            $output .= '$_section'.$cnt.'[\'show\'] = '.$show.";\n";
94 94
         } else {
95
-            $output .= '$_section' . $cnt . '[\'show\'] = true;' . "\n";
95
+            $output .= '$_section'.$cnt.'[\'show\'] = true;'."\n";
96 96
         }
97 97
 
98 98
         if ($name !== 'null') {
99
-            $output .= '$_section' . $cnt . '[\'name\'] = ' . $name . ";\n";
99
+            $output .= '$_section'.$cnt.'[\'name\'] = '.$name.";\n";
100 100
         } else {
101
-            $output .= '$_section' . $cnt . '[\'name\'] = true;' . "\n";
101
+            $output .= '$_section'.$cnt.'[\'name\'] = true;'."\n";
102 102
         }
103 103
 
104 104
         if ($max !== 'null') {
105
-            $output .= '$_section' . $cnt . '[\'max\'] = (int)' . $max . ";\n" . 'if($_section' . $cnt . '[\'max\'] < 0) { $_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\']; }' . "\n";
105
+            $output .= '$_section'.$cnt.'[\'max\'] = (int)'.$max.";\n".'if($_section'.$cnt.'[\'max\'] < 0) { $_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\']; }'."\n";
106 106
         } else {
107
-            $output .= '$_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\'];' . "\n";
107
+            $output .= '$_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\'];'."\n";
108 108
         }
109 109
 
110 110
         if ($step !== 'null') {
111
-            $output .= '$_section' . $cnt . '[\'step\'] = (int)' . $step . ' == 0 ? 1 : (int) ' . $step . ";\n";
111
+            $output .= '$_section'.$cnt.'[\'step\'] = (int)'.$step.' == 0 ? 1 : (int) '.$step.";\n";
112 112
         } else {
113
-            $output .= '$_section' . $cnt . '[\'step\'] = 1;' . "\n";
113
+            $output .= '$_section'.$cnt.'[\'step\'] = 1;'."\n";
114 114
         }
115 115
 
116 116
         if ($start !== 'null') {
117
-            $output .= '$_section' . $cnt . '[\'start\'] = (int)' . $start . ";\n";
117
+            $output .= '$_section'.$cnt.'[\'start\'] = (int)'.$start.";\n";
118 118
         } else {
119
-            $output .= '$_section' . $cnt . '[\'start\'] = $_section' . $cnt . '[\'step\'] > 0 ? 0 : $_section' . $cnt . '[\'loop\'] - 1;' . "\n" . 'if ($_section' . $cnt . '[\'start\'] < 0) { $_section' . $cnt . '[\'start\'] = max($_section' . $cnt . '[\'step\'] > 0 ? 0 : -1, $_section' . $cnt . '[\'loop\'] + $_section' . $cnt . '[\'start\']); } ' . "\n" . 'else { $_section' . $cnt . '[\'start\'] = min($_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] : $_section' . $cnt . '[\'loop\'] -1); }' . "\n";
119
+            $output .= '$_section'.$cnt.'[\'start\'] = $_section'.$cnt.'[\'step\'] > 0 ? 0 : $_section'.$cnt.'[\'loop\'] - 1;'."\n".'if ($_section'.$cnt.'[\'start\'] < 0) { $_section'.$cnt.'[\'start\'] = max($_section'.$cnt.'[\'step\'] > 0 ? 0 : -1, $_section'.$cnt.'[\'loop\'] + $_section'.$cnt.'[\'start\']); } '."\n".'else { $_section'.$cnt.'[\'start\'] = min($_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] : $_section'.$cnt.'[\'loop\'] -1); }'."\n";
120 120
         }
121 121
 
122 122
         /*		if ($usesAny) {
@@ -131,24 +131,24 @@  discard block
 block discarded – undo
131 131
                 }
132 132
         */
133 133
 
134
-        $output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n";
134
+        $output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n";
135 135
         if ($start === 'null' && $step === 'null' && $max === 'null') {
136
-            $output .= '	$_section' . $cnt . '[\'total\'] = $_section' . $cnt . '[\'loop\'];' . "\n";
136
+            $output .= '	$_section'.$cnt.'[\'total\'] = $_section'.$cnt.'[\'loop\'];'."\n";
137 137
         } else {
138
-            $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";
138
+            $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";
139 139
         }
140
-        $output .= '	if ($_section' . $cnt . '[\'total\'] == 0) {' . "\n" . '		$_section' . $cnt . '[\'show\'] = false;' . "\n" . '	}' . "\n" . '} else {' . "\n" . '	$_section' . $cnt . '[\'total\'] = 0;' . "\n}\n";
141
-        $output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n";
142
-        $output .= "\t" . 'for ($this->scope[' . $name . '] = $_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'iteration\'] = 1; ' . '$_section' . $cnt . '[\'iteration\'] <= $_section' . $cnt . '[\'total\']; ' . '$this->scope[' . $name . '] += $_section' . $cnt . '[\'step\'], $_section' . $cnt . '[\'iteration\']++) {' . "\n";
143
-        $output .= "\t\t" . '$_section' . $cnt . '[\'rownum\'] = $_section' . $cnt . '[\'iteration\'];' . "\n";
144
-        $output .= "\t\t" . '$_section' . $cnt . '[\'index_prev\'] = $this->scope[' . $name . '] - $_section' . $cnt . '[\'step\'];' . "\n";
145
-        $output .= "\t\t" . '$_section' . $cnt . '[\'index_next\'] = $this->scope[' . $name . '] + $_section' . $cnt . '[\'step\'];' . "\n";
146
-        $output .= "\t\t" . '$_section' . $cnt . '[\'first\']      = ($_section' . $cnt . '[\'iteration\'] == 1);' . "\n";
147
-        $output .= "\t\t" . '$_section' . $cnt . '[\'last\']       = ($_section' . $cnt . '[\'iteration\'] == $_section' . $cnt . '[\'total\']);' . "\n";
148
-
149
-        $output .= Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN;
150
-
151
-        $output .= "\n\t}\n} " . Compiler::PHP_CLOSE;
140
+        $output .= '	if ($_section'.$cnt.'[\'total\'] == 0) {'."\n".'		$_section'.$cnt.'[\'show\'] = false;'."\n".'	}'."\n".'} else {'."\n".'	$_section'.$cnt.'[\'total\'] = 0;'."\n}\n";
141
+        $output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n";
142
+        $output .= "\t".'for ($this->scope['.$name.'] = $_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'iteration\'] = 1; '.'$_section'.$cnt.'[\'iteration\'] <= $_section'.$cnt.'[\'total\']; '.'$this->scope['.$name.'] += $_section'.$cnt.'[\'step\'], $_section'.$cnt.'[\'iteration\']++) {'."\n";
143
+        $output .= "\t\t".'$_section'.$cnt.'[\'rownum\'] = $_section'.$cnt.'[\'iteration\'];'."\n";
144
+        $output .= "\t\t".'$_section'.$cnt.'[\'index_prev\'] = $this->scope['.$name.'] - $_section'.$cnt.'[\'step\'];'."\n";
145
+        $output .= "\t\t".'$_section'.$cnt.'[\'index_next\'] = $this->scope['.$name.'] + $_section'.$cnt.'[\'step\'];'."\n";
146
+        $output .= "\t\t".'$_section'.$cnt.'[\'first\']      = ($_section'.$cnt.'[\'iteration\'] == 1);'."\n";
147
+        $output .= "\t\t".'$_section'.$cnt.'[\'last\']       = ($_section'.$cnt.'[\'iteration\'] == $_section'.$cnt.'[\'total\']);'."\n";
148
+
149
+        $output .= Compiler::PHP_CLOSE.$content.Compiler::PHP_OPEN;
150
+
151
+        $output .= "\n\t}\n} ".Compiler::PHP_CLOSE;
152 152
 
153 153
         if (isset($params['hasElse'])) {
154 154
             $output .= $params['hasElse'];
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Blocks/PluginFor.php 2 patches
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -35,158 +35,158 @@
 block discarded – undo
35 35
  */
36 36
 class PluginFor extends BlockPlugin implements ICompilableBlock, IElseable
37 37
 {
38
-    public static $cnt = 0;
39
-
40
-    /**
41
-     * @param      $name
42
-     * @param      $from
43
-     * @param null $to
44
-     * @param int  $step
45
-     * @param int  $skip
46
-     */
47
-    public function init($name, $from, $to = null, $step = 1, $skip = 0)
48
-    {
49
-    }
50
-
51
-    /**
52
-     * @param Compiler $compiler
53
-     * @param array    $params
54
-     * @param string   $prepend
55
-     * @param string   $append
56
-     * @param string   $type
57
-     *
58
-     * @return string
59
-     */
60
-    public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
61
-    {
62
-        // get block params and save the current template pointer to use it in the postProcessing method
63
-        $currentBlock                         = &$compiler->getCurrentBlock();
64
-        $currentBlock['params']['tplPointer'] = $compiler->getPointer();
65
-
66
-        return '';
67
-    }
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);
81
-        $tpl    = $compiler->getTemplateSource($params['tplPointer']);
82
-
83
-        // assigns params
84
-        $from = $params['from'];
85
-        $name = $params['name'];
86
-        $step = $params['step'];
87
-        $to   = $params['to'];
88
-
89
-        // evaluates which global variables have to be computed
90
-        $varName       = '$dwoo.for.' . trim($name, '"\'') . '.';
91
-        $shortVarName  = '$.for.' . trim($name, '"\'') . '.';
92
-        $usesAny       = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
93
-        $usesFirst     = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false;
94
-        $usesLast      = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false;
95
-        $usesIndex     = strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
96
-        $usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false;
97
-        $usesShow      = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false;
98
-        $usesTotal     = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false;
99
-
100
-        if (strpos($name, '$this->scope[') !== false) {
101
-            $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
102
-        }
103
-
104
-        // gets foreach id
105
-        $cnt = self::$cnt ++;
106
-
107
-        // builds pre processing output for
108
-        $out = Compiler::PHP_OPEN . "\n" . '$_for' . $cnt . '_from = ' . $from . ';' . "\n" . '$_for' . $cnt . '_to = ' . $to . ';' . "\n" . '$_for' . $cnt . '_step = abs(' . $step . ');' . "\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>\'); }' . "\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));';
109
-        // adds for properties
110
-        if ($usesAny) {
111
-            $out .= "\n" . '$this->globals["for"][' . $name . '] = array' . "\n(";
112
-            if ($usesIndex) {
113
-                $out .= "\n\t" . '"index"		=> 0,';
114
-            }
115
-            if ($usesIteration) {
116
-                $out .= "\n\t" . '"iteration"		=> 1,';
117
-            }
118
-            if ($usesFirst) {
119
-                $out .= "\n\t" . '"first"		=> null,';
120
-            }
121
-            if ($usesLast) {
122
-                $out .= "\n\t" . '"last"		=> null,';
123
-            }
124
-            if ($usesShow) {
125
-                $out .= "\n\t" . '"show"		=> $tmp_shows,';
126
-            }
127
-            if ($usesTotal) {
128
-                $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),';
129
-            }
130
-            $out .= "\n);\n" . '$_for' . $cnt . '_glob =& $this->globals["for"][' . $name . '];';
131
-        }
132
-        // checks if for must be looped
133
-        $out .= "\n" . 'if ($tmp_shows)' . "\n{";
134
-        // set from/to to correct values if an array was given
135
-        $out .= "\n\t" . 'if ($this->isArray($_for' . $cnt . '_from' . (isset($params['hasElse']) ? ', true' : '') . ') == true) {
38
+	public static $cnt = 0;
39
+
40
+	/**
41
+	 * @param      $name
42
+	 * @param      $from
43
+	 * @param null $to
44
+	 * @param int  $step
45
+	 * @param int  $skip
46
+	 */
47
+	public function init($name, $from, $to = null, $step = 1, $skip = 0)
48
+	{
49
+	}
50
+
51
+	/**
52
+	 * @param Compiler $compiler
53
+	 * @param array    $params
54
+	 * @param string   $prepend
55
+	 * @param string   $append
56
+	 * @param string   $type
57
+	 *
58
+	 * @return string
59
+	 */
60
+	public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
61
+	{
62
+		// get block params and save the current template pointer to use it in the postProcessing method
63
+		$currentBlock                         = &$compiler->getCurrentBlock();
64
+		$currentBlock['params']['tplPointer'] = $compiler->getPointer();
65
+
66
+		return '';
67
+	}
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);
81
+		$tpl    = $compiler->getTemplateSource($params['tplPointer']);
82
+
83
+		// assigns params
84
+		$from = $params['from'];
85
+		$name = $params['name'];
86
+		$step = $params['step'];
87
+		$to   = $params['to'];
88
+
89
+		// evaluates which global variables have to be computed
90
+		$varName       = '$dwoo.for.' . trim($name, '"\'') . '.';
91
+		$shortVarName  = '$.for.' . trim($name, '"\'') . '.';
92
+		$usesAny       = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
93
+		$usesFirst     = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false;
94
+		$usesLast      = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false;
95
+		$usesIndex     = strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
96
+		$usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false;
97
+		$usesShow      = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false;
98
+		$usesTotal     = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false;
99
+
100
+		if (strpos($name, '$this->scope[') !== false) {
101
+			$usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
102
+		}
103
+
104
+		// gets foreach id
105
+		$cnt = self::$cnt ++;
106
+
107
+		// builds pre processing output for
108
+		$out = Compiler::PHP_OPEN . "\n" . '$_for' . $cnt . '_from = ' . $from . ';' . "\n" . '$_for' . $cnt . '_to = ' . $to . ';' . "\n" . '$_for' . $cnt . '_step = abs(' . $step . ');' . "\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>\'); }' . "\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));';
109
+		// adds for properties
110
+		if ($usesAny) {
111
+			$out .= "\n" . '$this->globals["for"][' . $name . '] = array' . "\n(";
112
+			if ($usesIndex) {
113
+				$out .= "\n\t" . '"index"		=> 0,';
114
+			}
115
+			if ($usesIteration) {
116
+				$out .= "\n\t" . '"iteration"		=> 1,';
117
+			}
118
+			if ($usesFirst) {
119
+				$out .= "\n\t" . '"first"		=> null,';
120
+			}
121
+			if ($usesLast) {
122
+				$out .= "\n\t" . '"last"		=> null,';
123
+			}
124
+			if ($usesShow) {
125
+				$out .= "\n\t" . '"show"		=> $tmp_shows,';
126
+			}
127
+			if ($usesTotal) {
128
+				$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),';
129
+			}
130
+			$out .= "\n);\n" . '$_for' . $cnt . '_glob =& $this->globals["for"][' . $name . '];';
131
+		}
132
+		// checks if for must be looped
133
+		$out .= "\n" . 'if ($tmp_shows)' . "\n{";
134
+		// set from/to to correct values if an array was given
135
+		$out .= "\n\t" . 'if ($this->isArray($_for' . $cnt . '_from' . (isset($params['hasElse']) ? ', true' : '') . ') == true) {
136 136
 		$_for' . $cnt . '_to = is_numeric($_for' . $cnt . '_to) ? $_for' . $cnt . '_to - $_for' . $cnt . '_step : $this->count($_for' . $cnt . '_from) - 1;
137 137
 		$_for' . $cnt . '_from = 0;
138 138
 	}';
139 139
 
140
-        // 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
141
-        $reverse     = false;
142
-        $condition   = '<=';
143
-        $incrementer = '+';
144
-
145
-        if (preg_match('{^(["\']?)([0-9]+)\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\1$}', $to, $mN2)) {
146
-            $from = (int)$mN1[2];
147
-            $to   = (int)$mN2[2];
148
-            if ($from > $to) {
149
-                $reverse     = true;
150
-                $condition   = '>=';
151
-                $incrementer = '-';
152
-            }
153
-        }
154
-
155
-        // reverse from and to if needed
156
-        if (!$reverse) {
157
-            $out .= "\n\t" . 'if ($_for' . $cnt . '_from > $_for' . $cnt . '_to) {
140
+		// 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
141
+		$reverse     = false;
142
+		$condition   = '<=';
143
+		$incrementer = '+';
144
+
145
+		if (preg_match('{^(["\']?)([0-9]+)\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\1$}', $to, $mN2)) {
146
+			$from = (int)$mN1[2];
147
+			$to   = (int)$mN2[2];
148
+			if ($from > $to) {
149
+				$reverse     = true;
150
+				$condition   = '>=';
151
+				$incrementer = '-';
152
+			}
153
+		}
154
+
155
+		// reverse from and to if needed
156
+		if (!$reverse) {
157
+			$out .= "\n\t" . 'if ($_for' . $cnt . '_from > $_for' . $cnt . '_to) {
158 158
 				$tmp = $_for' . $cnt . '_from;
159 159
 				$_for' . $cnt . '_from = $_for' . $cnt . '_to;
160 160
 				$_for' . $cnt . '_to = $tmp;
161 161
 			}';
162
-        }
163
-
164
-        $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{";
165
-        // updates properties
166
-        if ($usesIndex) {
167
-            $out .= "\n\t\t" . '$_for' . $cnt . '_glob["index"] = $this->scope[' . $name . '];';
168
-        }
169
-        if ($usesFirst) {
170
-            $out .= "\n\t\t" . '$_for' . $cnt . '_glob["first"] = (string) ($_for' . $cnt . '_glob["iteration"] === 1);';
171
-        }
172
-        if ($usesLast) {
173
-            $out .= "\n\t\t" . '$_for' . $cnt . '_glob["last"] = (string) ($_for' . $cnt . '_glob["iteration"] === $_for' . $cnt . '_glob["total"]);';
174
-        }
175
-        $out .= "\n/* -- for start output */\n" . Compiler::PHP_CLOSE;
176
-
177
-        // build post processing output and cache it
178
-        $postOut = Compiler::PHP_OPEN . '/* -- for end output */';
179
-        // update properties
180
-        if ($usesIteration) {
181
-            $postOut .= "\n\t\t" . '$_for' . $cnt . '_glob["iteration"]+=1;';
182
-        }
183
-        // end loop
184
-        $postOut .= "\n\t}\n}\n" . Compiler::PHP_CLOSE;
185
-
186
-        if (isset($params['hasElse'])) {
187
-            $postOut .= $params['hasElse'];
188
-        }
189
-
190
-        return $out . $content . $postOut;
191
-    }
162
+		}
163
+
164
+		$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{";
165
+		// updates properties
166
+		if ($usesIndex) {
167
+			$out .= "\n\t\t" . '$_for' . $cnt . '_glob["index"] = $this->scope[' . $name . '];';
168
+		}
169
+		if ($usesFirst) {
170
+			$out .= "\n\t\t" . '$_for' . $cnt . '_glob["first"] = (string) ($_for' . $cnt . '_glob["iteration"] === 1);';
171
+		}
172
+		if ($usesLast) {
173
+			$out .= "\n\t\t" . '$_for' . $cnt . '_glob["last"] = (string) ($_for' . $cnt . '_glob["iteration"] === $_for' . $cnt . '_glob["total"]);';
174
+		}
175
+		$out .= "\n/* -- for start output */\n" . Compiler::PHP_CLOSE;
176
+
177
+		// build post processing output and cache it
178
+		$postOut = Compiler::PHP_OPEN . '/* -- for end output */';
179
+		// update properties
180
+		if ($usesIteration) {
181
+			$postOut .= "\n\t\t" . '$_for' . $cnt . '_glob["iteration"]+=1;';
182
+		}
183
+		// end loop
184
+		$postOut .= "\n\t}\n}\n" . Compiler::PHP_CLOSE;
185
+
186
+		if (isset($params['hasElse'])) {
187
+			$postOut .= $params['hasElse'];
188
+		}
189
+
190
+		return $out . $content . $postOut;
191
+	}
192 192
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -87,54 +87,54 @@  discard block
 block discarded – undo
87 87
         $to   = $params['to'];
88 88
 
89 89
         // evaluates which global variables have to be computed
90
-        $varName       = '$dwoo.for.' . trim($name, '"\'') . '.';
91
-        $shortVarName  = '$.for.' . trim($name, '"\'') . '.';
90
+        $varName       = '$dwoo.for.'.trim($name, '"\'').'.';
91
+        $shortVarName  = '$.for.'.trim($name, '"\'').'.';
92 92
         $usesAny       = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
93
-        $usesFirst     = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false;
94
-        $usesLast      = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false;
95
-        $usesIndex     = strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
96
-        $usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false;
97
-        $usesShow      = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false;
98
-        $usesTotal     = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false;
93
+        $usesFirst     = strpos($tpl, $varName.'first') !== false || strpos($tpl, $shortVarName.'first') !== false;
94
+        $usesLast      = strpos($tpl, $varName.'last') !== false || strpos($tpl, $shortVarName.'last') !== false;
95
+        $usesIndex     = strpos($tpl, $varName.'index') !== false || strpos($tpl, $shortVarName.'index') !== false;
96
+        $usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName.'iteration') !== false || strpos($tpl, $shortVarName.'iteration') !== false;
97
+        $usesShow      = strpos($tpl, $varName.'show') !== false || strpos($tpl, $shortVarName.'show') !== false;
98
+        $usesTotal     = $usesLast || strpos($tpl, $varName.'total') !== false || strpos($tpl, $shortVarName.'total') !== false;
99 99
 
100 100
         if (strpos($name, '$this->scope[') !== false) {
101 101
             $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
102 102
         }
103 103
 
104 104
         // gets foreach id
105
-        $cnt = self::$cnt ++;
105
+        $cnt = self::$cnt++;
106 106
 
107 107
         // builds pre processing output for
108
-        $out = Compiler::PHP_OPEN . "\n" . '$_for' . $cnt . '_from = ' . $from . ';' . "\n" . '$_for' . $cnt . '_to = ' . $to . ';' . "\n" . '$_for' . $cnt . '_step = abs(' . $step . ');' . "\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>\'); }' . "\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));';
108
+        $out = Compiler::PHP_OPEN."\n".'$_for'.$cnt.'_from = '.$from.';'."\n".'$_for'.$cnt.'_to = '.$to.';'."\n".'$_for'.$cnt.'_step = abs('.$step.');'."\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>\'); }'."\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));';
109 109
         // adds for properties
110 110
         if ($usesAny) {
111
-            $out .= "\n" . '$this->globals["for"][' . $name . '] = array' . "\n(";
111
+            $out .= "\n".'$this->globals["for"]['.$name.'] = array'."\n(";
112 112
             if ($usesIndex) {
113
-                $out .= "\n\t" . '"index"		=> 0,';
113
+                $out .= "\n\t".'"index"		=> 0,';
114 114
             }
115 115
             if ($usesIteration) {
116
-                $out .= "\n\t" . '"iteration"		=> 1,';
116
+                $out .= "\n\t".'"iteration"		=> 1,';
117 117
             }
118 118
             if ($usesFirst) {
119
-                $out .= "\n\t" . '"first"		=> null,';
119
+                $out .= "\n\t".'"first"		=> null,';
120 120
             }
121 121
             if ($usesLast) {
122
-                $out .= "\n\t" . '"last"		=> null,';
122
+                $out .= "\n\t".'"last"		=> null,';
123 123
             }
124 124
             if ($usesShow) {
125
-                $out .= "\n\t" . '"show"		=> $tmp_shows,';
125
+                $out .= "\n\t".'"show"		=> $tmp_shows,';
126 126
             }
127 127
             if ($usesTotal) {
128
-                $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),';
128
+                $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),';
129 129
             }
130
-            $out .= "\n);\n" . '$_for' . $cnt . '_glob =& $this->globals["for"][' . $name . '];';
130
+            $out .= "\n);\n".'$_for'.$cnt.'_glob =& $this->globals["for"]['.$name.'];';
131 131
         }
132 132
         // checks if for must be looped
133
-        $out .= "\n" . 'if ($tmp_shows)' . "\n{";
133
+        $out .= "\n".'if ($tmp_shows)'."\n{";
134 134
         // set from/to to correct values if an array was given
135
-        $out .= "\n\t" . 'if ($this->isArray($_for' . $cnt . '_from' . (isset($params['hasElse']) ? ', true' : '') . ') == true) {
136
-		$_for' . $cnt . '_to = is_numeric($_for' . $cnt . '_to) ? $_for' . $cnt . '_to - $_for' . $cnt . '_step : $this->count($_for' . $cnt . '_from) - 1;
137
-		$_for' . $cnt . '_from = 0;
135
+        $out .= "\n\t".'if ($this->isArray($_for'.$cnt.'_from'.(isset($params['hasElse']) ? ', true' : '').') == true) {
136
+		$_for' . $cnt.'_to = is_numeric($_for'.$cnt.'_to) ? $_for'.$cnt.'_to - $_for'.$cnt.'_step : $this->count($_for'.$cnt.'_from) - 1;
137
+		$_for' . $cnt.'_from = 0;
138 138
 	}';
139 139
 
140 140
         // 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
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
         $incrementer = '+';
144 144
 
145 145
         if (preg_match('{^(["\']?)([0-9]+)\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\1$}', $to, $mN2)) {
146
-            $from = (int)$mN1[2];
147
-            $to   = (int)$mN2[2];
146
+            $from = (int) $mN1[2];
147
+            $to   = (int) $mN2[2];
148 148
             if ($from > $to) {
149 149
                 $reverse     = true;
150 150
                 $condition   = '>=';
@@ -154,39 +154,39 @@  discard block
 block discarded – undo
154 154
 
155 155
         // reverse from and to if needed
156 156
         if (!$reverse) {
157
-            $out .= "\n\t" . 'if ($_for' . $cnt . '_from > $_for' . $cnt . '_to) {
158
-				$tmp = $_for' . $cnt . '_from;
159
-				$_for' . $cnt . '_from = $_for' . $cnt . '_to;
160
-				$_for' . $cnt . '_to = $tmp;
157
+            $out .= "\n\t".'if ($_for'.$cnt.'_from > $_for'.$cnt.'_to) {
158
+				$tmp = $_for' . $cnt.'_from;
159
+				$_for' . $cnt.'_from = $_for'.$cnt.'_to;
160
+				$_for' . $cnt.'_to = $tmp;
161 161
 			}';
162 162
         }
163 163
 
164
-        $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{";
164
+        $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{";
165 165
         // updates properties
166 166
         if ($usesIndex) {
167
-            $out .= "\n\t\t" . '$_for' . $cnt . '_glob["index"] = $this->scope[' . $name . '];';
167
+            $out .= "\n\t\t".'$_for'.$cnt.'_glob["index"] = $this->scope['.$name.'];';
168 168
         }
169 169
         if ($usesFirst) {
170
-            $out .= "\n\t\t" . '$_for' . $cnt . '_glob["first"] = (string) ($_for' . $cnt . '_glob["iteration"] === 1);';
170
+            $out .= "\n\t\t".'$_for'.$cnt.'_glob["first"] = (string) ($_for'.$cnt.'_glob["iteration"] === 1);';
171 171
         }
172 172
         if ($usesLast) {
173
-            $out .= "\n\t\t" . '$_for' . $cnt . '_glob["last"] = (string) ($_for' . $cnt . '_glob["iteration"] === $_for' . $cnt . '_glob["total"]);';
173
+            $out .= "\n\t\t".'$_for'.$cnt.'_glob["last"] = (string) ($_for'.$cnt.'_glob["iteration"] === $_for'.$cnt.'_glob["total"]);';
174 174
         }
175
-        $out .= "\n/* -- for start output */\n" . Compiler::PHP_CLOSE;
175
+        $out .= "\n/* -- for start output */\n".Compiler::PHP_CLOSE;
176 176
 
177 177
         // build post processing output and cache it
178
-        $postOut = Compiler::PHP_OPEN . '/* -- for end output */';
178
+        $postOut = Compiler::PHP_OPEN.'/* -- for end output */';
179 179
         // update properties
180 180
         if ($usesIteration) {
181
-            $postOut .= "\n\t\t" . '$_for' . $cnt . '_glob["iteration"]+=1;';
181
+            $postOut .= "\n\t\t".'$_for'.$cnt.'_glob["iteration"]+=1;';
182 182
         }
183 183
         // end loop
184
-        $postOut .= "\n\t}\n}\n" . Compiler::PHP_CLOSE;
184
+        $postOut .= "\n\t}\n}\n".Compiler::PHP_CLOSE;
185 185
 
186 186
         if (isset($params['hasElse'])) {
187 187
             $postOut .= $params['hasElse'];
188 188
         }
189 189
 
190
-        return $out . $content . $postOut;
190
+        return $out.$content.$postOut;
191 191
     }
192 192
 }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Blocks/PluginTopLevelBlock.php 2 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -26,35 +26,35 @@
 block discarded – undo
26 26
  */
27 27
 final class PluginTopLevelBlock extends BlockPlugin implements ICompilableBlock
28 28
 {
29
-    public function init()
30
-    {
31
-    }
29
+	public function init()
30
+	{
31
+	}
32 32
 
33
-    /**
34
-     * @param Compiler $compiler
35
-     * @param array    $params
36
-     * @param string   $prepend
37
-     * @param string   $append
38
-     * @param string   $type
39
-     *
40
-     * @return string
41
-     */
42
-    public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
43
-    {
44
-        return '/* end template head */ ob_start(); /* template body */ ' . Compiler::PHP_CLOSE;
45
-    }
33
+	/**
34
+	 * @param Compiler $compiler
35
+	 * @param array    $params
36
+	 * @param string   $prepend
37
+	 * @param string   $append
38
+	 * @param string   $type
39
+	 *
40
+	 * @return string
41
+	 */
42
+	public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
43
+	{
44
+		return '/* end template head */ ob_start(); /* template body */ ' . Compiler::PHP_CLOSE;
45
+	}
46 46
 
47
-    /**
48
-     * @param Compiler $compiler
49
-     * @param array    $params
50
-     * @param string   $prepend
51
-     * @param string   $append
52
-     * @param string   $content
53
-     *
54
-     * @return string
55
-     */
56
-    public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
57
-    {
58
-        return $content . Compiler::PHP_OPEN . ' /* end template body */' . "\n" . 'return $this->buffer . ob_get_clean();';
59
-    }
47
+	/**
48
+	 * @param Compiler $compiler
49
+	 * @param array    $params
50
+	 * @param string   $prepend
51
+	 * @param string   $append
52
+	 * @param string   $content
53
+	 *
54
+	 * @return string
55
+	 */
56
+	public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
57
+	{
58
+		return $content . Compiler::PHP_OPEN . ' /* end template body */' . "\n" . 'return $this->buffer . ob_get_clean();';
59
+	}
60 60
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
43 43
     {
44
-        return '/* end template head */ ob_start(); /* template body */ ' . Compiler::PHP_CLOSE;
44
+        return '/* end template head */ ob_start(); /* template body */ '.Compiler::PHP_CLOSE;
45 45
     }
46 46
 
47 47
     /**
@@ -55,6 +55,6 @@  discard block
 block discarded – undo
55 55
      */
56 56
     public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
57 57
     {
58
-        return $content . Compiler::PHP_OPEN . ' /* end template body */' . "\n" . 'return $this->buffer . ob_get_clean();';
58
+        return $content.Compiler::PHP_OPEN.' /* end template body */'."\n".'return $this->buffer . ob_get_clean();';
59 59
     }
60 60
 }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Filters/PluginHtmlFormat.php 2 patches
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -30,161 +30,161 @@
 block discarded – undo
30 30
  */
31 31
 class PluginHtmlFormat extends Filter
32 32
 {
33
-    /**
34
-     * tab count to auto-indent the source.
35
-     *
36
-     * @var int
37
-     */
38
-    protected static $tabCount = - 1;
39
-
40
-    /**
41
-     * stores the additional data (following a tag) of the last call to open/close/singleTag.
42
-     *
43
-     * @var string
44
-     */
45
-    protected static $lastCallAdd = '';
46
-
47
-    /**
48
-     * formats the input using the singleTag/closeTag/openTag functions.
49
-     * It is auto indenting the whole code, excluding <textarea>, <code> and <pre> tags that must be kept intact.
50
-     * Those tags must however contain only htmlentities-escaped text for everything to work properly.
51
-     * Inline tags are presented on a single line with their content
52
-     *
53
-     * @param string $input the xhtml to format
54
-     *
55
-     * @return string formatted xhtml
56
-     */
57
-    public function process($input)
58
-    {
59
-        self::$tabCount = - 1;
60
-
61
-        // auto indent all but textareas & pre (or we have weird tabs inside)
62
-        $input = preg_replace_callback("#(<[^>]+>)(\s*)([^<]*)#", array(
63
-            'self',
64
-            'tagDispatcher'
65
-        ), $input);
66
-
67
-        return $input;
68
-    }
69
-
70
-    /**
71
-     * helper function for format()'s preg_replace call.
72
-     *
73
-     * @param array $input array of matches (1=>tag, 2=>whitespace(optional), 3=>additional non-html content)
74
-     *
75
-     * @return string the indented tag
76
-     */
77
-    protected static function tagDispatcher($input)
78
-    {
79
-        // textarea, pre, code tags and comments are to be left alone to avoid any non-wanted whitespace inside them so it just outputs them as they were
80
-        if (substr($input[1], 0, 9) == '<textarea' || substr($input[1], 0, 4) == '<pre' || substr($input[1], 0, 5) == '<code' || substr($input[1], 0, 4) == '<!--' || substr($input[1], 0, 9) == '<![CDATA[') {
81
-            return $input[1] . $input[3];
82
-        }
83
-        // closing textarea, code and pre tags and self-closed tags (i.e. <br />) are printed as singleTags because we didn't use openTag for the formers and the latter is a single tag
84
-        if (substr($input[1], 0, 10) == '</textarea' || substr($input[1], 0, 5) == '</pre' || substr($input[1], 0, 6) == '</code' || substr($input[1], - 2) == '/>') {
85
-            return self::singleTag($input[1], $input[3], $input[2]);
86
-        }
87
-        // it's the closing tag
88
-        if ($input[0][1] == '/') {
89
-            return self::closeTag($input[1], $input[3], $input[2]);
90
-        }
91
-
92
-        // opening tag
93
-        return self::openTag($input[1], $input[3], $input[2]);
94
-    }
95
-
96
-    /**
97
-     * returns an open tag and adds a tab into the auto indenting.
98
-     *
99
-     * @param string $tag        content of the tag
100
-     * @param string $add        additional data (anything before the following tag)
101
-     * @param string $whitespace white space between the tag and the additional data
102
-     *
103
-     * @return string
104
-     */
105
-    protected static function openTag($tag, $add, $whitespace)
106
-    {
107
-        $tabs = str_pad('', self::$tabCount ++, "\t");
108
-
109
-        if (preg_match('#^<(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)(?: [^>]*|)>#', $tag)) {
110
-            // if it's one of those tag it's inline so it does not require a leading line break
111
-            $result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add);
112
-        } elseif (substr($tag, 0, 9) == '<!DOCTYPE') {
113
-            // it's the doctype declaration so no line break here either
114
-            $result = $tabs . $tag;
115
-        } else {
116
-            // normal block tag
117
-            $result = "\n" . $tabs . $tag;
118
-
119
-            if (!empty($add)) {
120
-                $result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add);
121
-            }
122
-        }
123
-
124
-        self::$lastCallAdd = $add;
125
-
126
-        return $result;
127
-    }
128
-
129
-    /**
130
-     * returns a closing tag and removes a tab from the auto indenting.
131
-     *
132
-     * @param string $tag        content of the tag
133
-     * @param string $add        additional data (anything before the following tag)
134
-     * @param string $whitespace white space between the tag and the additional data
135
-     *
136
-     * @return string
137
-     */
138
-    protected static function closeTag($tag, $add, $whitespace)
139
-    {
140
-        $tabs = str_pad('', -- self::$tabCount, "\t");
141
-
142
-        // if it's one of those tag it's inline so it does not require a leading line break
143
-        if (preg_match('#^</(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)>#', $tag)) {
144
-            $result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add);
145
-        } else {
146
-            $result = "\n" . $tabs . $tag;
147
-
148
-            if (!empty($add)) {
149
-                $result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add);
150
-            }
151
-        }
152
-
153
-        self::$lastCallAdd = $add;
154
-
155
-        return $result;
156
-    }
157
-
158
-    /**
159
-     * returns a single tag with auto indenting.
160
-     *
161
-     * @param string $tag content of the tag
162
-     * @param string $add additional data (anything before the following tag)
163
-     *
164
-     * @return string
165
-     */
166
-    protected static function singleTag($tag, $add, $whitespace)
167
-    {
168
-        $tabs = str_pad('', self::$tabCount, "\t");
169
-
170
-        // if it's img, br it's inline so it does not require a leading line break
171
-        // if it's a closing textarea, code or pre tag, it does not require a leading line break either or it creates whitespace at the end of those blocks
172
-        if (preg_match('#^<(img|br|/textarea|/pre|/code)(?: [^>]*|)>#', $tag)) {
173
-            $result = $tag . $whitespace;
174
-
175
-            if (!empty($add)) {
176
-                $result .= str_replace("\n", "\n" . $tabs, $add);
177
-            }
178
-        } else {
179
-            $result = "\n" . $tabs . $tag;
180
-
181
-            if (!empty($add)) {
182
-                $result .= "\n" . $tabs . str_replace("\n", "\n" . $tabs, $add);
183
-            }
184
-        }
185
-
186
-        self::$lastCallAdd = $add;
187
-
188
-        return $result;
189
-    }
33
+	/**
34
+	 * tab count to auto-indent the source.
35
+	 *
36
+	 * @var int
37
+	 */
38
+	protected static $tabCount = - 1;
39
+
40
+	/**
41
+	 * stores the additional data (following a tag) of the last call to open/close/singleTag.
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected static $lastCallAdd = '';
46
+
47
+	/**
48
+	 * formats the input using the singleTag/closeTag/openTag functions.
49
+	 * It is auto indenting the whole code, excluding <textarea>, <code> and <pre> tags that must be kept intact.
50
+	 * Those tags must however contain only htmlentities-escaped text for everything to work properly.
51
+	 * Inline tags are presented on a single line with their content
52
+	 *
53
+	 * @param string $input the xhtml to format
54
+	 *
55
+	 * @return string formatted xhtml
56
+	 */
57
+	public function process($input)
58
+	{
59
+		self::$tabCount = - 1;
60
+
61
+		// auto indent all but textareas & pre (or we have weird tabs inside)
62
+		$input = preg_replace_callback("#(<[^>]+>)(\s*)([^<]*)#", array(
63
+			'self',
64
+			'tagDispatcher'
65
+		), $input);
66
+
67
+		return $input;
68
+	}
69
+
70
+	/**
71
+	 * helper function for format()'s preg_replace call.
72
+	 *
73
+	 * @param array $input array of matches (1=>tag, 2=>whitespace(optional), 3=>additional non-html content)
74
+	 *
75
+	 * @return string the indented tag
76
+	 */
77
+	protected static function tagDispatcher($input)
78
+	{
79
+		// textarea, pre, code tags and comments are to be left alone to avoid any non-wanted whitespace inside them so it just outputs them as they were
80
+		if (substr($input[1], 0, 9) == '<textarea' || substr($input[1], 0, 4) == '<pre' || substr($input[1], 0, 5) == '<code' || substr($input[1], 0, 4) == '<!--' || substr($input[1], 0, 9) == '<![CDATA[') {
81
+			return $input[1] . $input[3];
82
+		}
83
+		// closing textarea, code and pre tags and self-closed tags (i.e. <br />) are printed as singleTags because we didn't use openTag for the formers and the latter is a single tag
84
+		if (substr($input[1], 0, 10) == '</textarea' || substr($input[1], 0, 5) == '</pre' || substr($input[1], 0, 6) == '</code' || substr($input[1], - 2) == '/>') {
85
+			return self::singleTag($input[1], $input[3], $input[2]);
86
+		}
87
+		// it's the closing tag
88
+		if ($input[0][1] == '/') {
89
+			return self::closeTag($input[1], $input[3], $input[2]);
90
+		}
91
+
92
+		// opening tag
93
+		return self::openTag($input[1], $input[3], $input[2]);
94
+	}
95
+
96
+	/**
97
+	 * returns an open tag and adds a tab into the auto indenting.
98
+	 *
99
+	 * @param string $tag        content of the tag
100
+	 * @param string $add        additional data (anything before the following tag)
101
+	 * @param string $whitespace white space between the tag and the additional data
102
+	 *
103
+	 * @return string
104
+	 */
105
+	protected static function openTag($tag, $add, $whitespace)
106
+	{
107
+		$tabs = str_pad('', self::$tabCount ++, "\t");
108
+
109
+		if (preg_match('#^<(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)(?: [^>]*|)>#', $tag)) {
110
+			// if it's one of those tag it's inline so it does not require a leading line break
111
+			$result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add);
112
+		} elseif (substr($tag, 0, 9) == '<!DOCTYPE') {
113
+			// it's the doctype declaration so no line break here either
114
+			$result = $tabs . $tag;
115
+		} else {
116
+			// normal block tag
117
+			$result = "\n" . $tabs . $tag;
118
+
119
+			if (!empty($add)) {
120
+				$result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add);
121
+			}
122
+		}
123
+
124
+		self::$lastCallAdd = $add;
125
+
126
+		return $result;
127
+	}
128
+
129
+	/**
130
+	 * returns a closing tag and removes a tab from the auto indenting.
131
+	 *
132
+	 * @param string $tag        content of the tag
133
+	 * @param string $add        additional data (anything before the following tag)
134
+	 * @param string $whitespace white space between the tag and the additional data
135
+	 *
136
+	 * @return string
137
+	 */
138
+	protected static function closeTag($tag, $add, $whitespace)
139
+	{
140
+		$tabs = str_pad('', -- self::$tabCount, "\t");
141
+
142
+		// if it's one of those tag it's inline so it does not require a leading line break
143
+		if (preg_match('#^</(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)>#', $tag)) {
144
+			$result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add);
145
+		} else {
146
+			$result = "\n" . $tabs . $tag;
147
+
148
+			if (!empty($add)) {
149
+				$result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add);
150
+			}
151
+		}
152
+
153
+		self::$lastCallAdd = $add;
154
+
155
+		return $result;
156
+	}
157
+
158
+	/**
159
+	 * returns a single tag with auto indenting.
160
+	 *
161
+	 * @param string $tag content of the tag
162
+	 * @param string $add additional data (anything before the following tag)
163
+	 *
164
+	 * @return string
165
+	 */
166
+	protected static function singleTag($tag, $add, $whitespace)
167
+	{
168
+		$tabs = str_pad('', self::$tabCount, "\t");
169
+
170
+		// if it's img, br it's inline so it does not require a leading line break
171
+		// if it's a closing textarea, code or pre tag, it does not require a leading line break either or it creates whitespace at the end of those blocks
172
+		if (preg_match('#^<(img|br|/textarea|/pre|/code)(?: [^>]*|)>#', $tag)) {
173
+			$result = $tag . $whitespace;
174
+
175
+			if (!empty($add)) {
176
+				$result .= str_replace("\n", "\n" . $tabs, $add);
177
+			}
178
+		} else {
179
+			$result = "\n" . $tabs . $tag;
180
+
181
+			if (!empty($add)) {
182
+				$result .= "\n" . $tabs . str_replace("\n", "\n" . $tabs, $add);
183
+			}
184
+		}
185
+
186
+		self::$lastCallAdd = $add;
187
+
188
+		return $result;
189
+	}
190 190
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     {
79 79
         // textarea, pre, code tags and comments are to be left alone to avoid any non-wanted whitespace inside them so it just outputs them as they were
80 80
         if (substr($input[1], 0, 9) == '<textarea' || substr($input[1], 0, 4) == '<pre' || substr($input[1], 0, 5) == '<code' || substr($input[1], 0, 4) == '<!--' || substr($input[1], 0, 9) == '<![CDATA[') {
81
-            return $input[1] . $input[3];
81
+            return $input[1].$input[3];
82 82
         }
83 83
         // closing textarea, code and pre tags and self-closed tags (i.e. <br />) are printed as singleTags because we didn't use openTag for the formers and the latter is a single tag
84 84
         if (substr($input[1], 0, 10) == '</textarea' || substr($input[1], 0, 5) == '</pre' || substr($input[1], 0, 6) == '</code' || substr($input[1], - 2) == '/>') {
@@ -104,20 +104,20 @@  discard block
 block discarded – undo
104 104
      */
105 105
     protected static function openTag($tag, $add, $whitespace)
106 106
     {
107
-        $tabs = str_pad('', self::$tabCount ++, "\t");
107
+        $tabs = str_pad('', self::$tabCount++, "\t");
108 108
 
109 109
         if (preg_match('#^<(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)(?: [^>]*|)>#', $tag)) {
110 110
             // if it's one of those tag it's inline so it does not require a leading line break
111
-            $result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add);
111
+            $result = $tag.$whitespace.str_replace("\n", "\n".$tabs, $add);
112 112
         } elseif (substr($tag, 0, 9) == '<!DOCTYPE') {
113 113
             // it's the doctype declaration so no line break here either
114
-            $result = $tabs . $tag;
114
+            $result = $tabs.$tag;
115 115
         } else {
116 116
             // normal block tag
117
-            $result = "\n" . $tabs . $tag;
117
+            $result = "\n".$tabs.$tag;
118 118
 
119 119
             if (!empty($add)) {
120
-                $result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add);
120
+                $result .= "\n".$tabs."\t".str_replace("\n", "\n\t".$tabs, $add);
121 121
             }
122 122
         }
123 123
 
@@ -141,12 +141,12 @@  discard block
 block discarded – undo
141 141
 
142 142
         // if it's one of those tag it's inline so it does not require a leading line break
143 143
         if (preg_match('#^</(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)>#', $tag)) {
144
-            $result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add);
144
+            $result = $tag.$whitespace.str_replace("\n", "\n".$tabs, $add);
145 145
         } else {
146
-            $result = "\n" . $tabs . $tag;
146
+            $result = "\n".$tabs.$tag;
147 147
 
148 148
             if (!empty($add)) {
149
-                $result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add);
149
+                $result .= "\n".$tabs."\t".str_replace("\n", "\n\t".$tabs, $add);
150 150
             }
151 151
         }
152 152
 
@@ -170,16 +170,16 @@  discard block
 block discarded – undo
170 170
         // if it's img, br it's inline so it does not require a leading line break
171 171
         // if it's a closing textarea, code or pre tag, it does not require a leading line break either or it creates whitespace at the end of those blocks
172 172
         if (preg_match('#^<(img|br|/textarea|/pre|/code)(?: [^>]*|)>#', $tag)) {
173
-            $result = $tag . $whitespace;
173
+            $result = $tag.$whitespace;
174 174
 
175 175
             if (!empty($add)) {
176
-                $result .= str_replace("\n", "\n" . $tabs, $add);
176
+                $result .= str_replace("\n", "\n".$tabs, $add);
177 177
             }
178 178
         } else {
179
-            $result = "\n" . $tabs . $tag;
179
+            $result = "\n".$tabs.$tag;
180 180
 
181 181
             if (!empty($add)) {
182
-                $result .= "\n" . $tabs . str_replace("\n", "\n" . $tabs, $add);
182
+                $result .= "\n".$tabs.str_replace("\n", "\n".$tabs, $add);
183 183
             }
184 184
         }
185 185
 
Please login to merge, or discard this patch.
lib/Dwoo/Security/Policy.php 2 patches
Indentation   +271 added lines, -271 removed lines patch added patch discarded remove patch
@@ -25,298 +25,298 @@
 block discarded – undo
25 25
  */
26 26
 class Policy
27 27
 {
28
-    /**
29
-     * Php handling constants, defaults to PHP_REMOVE
30
-     * PHP_ENCODE : run htmlentities over them
31
-     * PHP_REMOVE : remove all <?php ?> (+ short tags if your short tags option is on) from the input template
32
-     * PHP_ALLOW : leave them as they are
33
-     *
34
-     * @var int
35
-     */
36
-    const PHP_ENCODE = 1;
37
-    const PHP_REMOVE = 2;
38
-    const PHP_ALLOW  = 3;
28
+	/**
29
+	 * Php handling constants, defaults to PHP_REMOVE
30
+	 * PHP_ENCODE : run htmlentities over them
31
+	 * PHP_REMOVE : remove all <?php ?> (+ short tags if your short tags option is on) from the input template
32
+	 * PHP_ALLOW : leave them as they are
33
+	 *
34
+	 * @var int
35
+	 */
36
+	const PHP_ENCODE = 1;
37
+	const PHP_REMOVE = 2;
38
+	const PHP_ALLOW  = 3;
39 39
 
40
-    /**
41
-     * Constant handling constants, defaults to CONST_DISALLOW
42
-     * CONST_DISALLOW : throw an error if {$dwoo.const.*} is used in the template
43
-     * CONST_ALLOW : allow {$dwoo.const.*} calls
44
-     */
45
-    const CONST_DISALLOW = false;
46
-    const CONST_ALLOW    = true;
40
+	/**
41
+	 * Constant handling constants, defaults to CONST_DISALLOW
42
+	 * CONST_DISALLOW : throw an error if {$dwoo.const.*} is used in the template
43
+	 * CONST_ALLOW : allow {$dwoo.const.*} calls
44
+	 */
45
+	const CONST_DISALLOW = false;
46
+	const CONST_ALLOW    = true;
47 47
 
48
-    /**
49
-     * Php functions that are allowed to be used within the template.
50
-     *
51
-     * @var array
52
-     */
53
-    protected $allowedPhpFunctions = array(
54
-        'str_repeat'       => true,
55
-        'number_format'    => true,
56
-        'htmlentities'     => true,
57
-        'htmlspecialchars' => true,
58
-        'long2ip'          => true,
59
-        'strlen'           => true,
60
-        'list'             => true,
61
-        'empty'            => true,
62
-        'count'            => true,
63
-        'sizeof'           => true,
64
-        'in_array'         => true,
65
-        'is_array'         => true,
66
-    );
48
+	/**
49
+	 * Php functions that are allowed to be used within the template.
50
+	 *
51
+	 * @var array
52
+	 */
53
+	protected $allowedPhpFunctions = array(
54
+		'str_repeat'       => true,
55
+		'number_format'    => true,
56
+		'htmlentities'     => true,
57
+		'htmlspecialchars' => true,
58
+		'long2ip'          => true,
59
+		'strlen'           => true,
60
+		'list'             => true,
61
+		'empty'            => true,
62
+		'count'            => true,
63
+		'sizeof'           => true,
64
+		'in_array'         => true,
65
+		'is_array'         => true,
66
+	);
67 67
 
68
-    /**
69
-     * Methods that are allowed to be used within the template.
70
-     *
71
-     * @var array
72
-     */
73
-    protected $allowedMethods = array();
68
+	/**
69
+	 * Methods that are allowed to be used within the template.
70
+	 *
71
+	 * @var array
72
+	 */
73
+	protected $allowedMethods = array();
74 74
 
75
-    /**
76
-     * Paths that are safe to use with include or other file-access plugins.
77
-     *
78
-     * @var array
79
-     */
80
-    protected $allowedDirectories = array();
75
+	/**
76
+	 * Paths that are safe to use with include or other file-access plugins.
77
+	 *
78
+	 * @var array
79
+	 */
80
+	protected $allowedDirectories = array();
81 81
 
82
-    /**
83
-     * Stores the php handling level.
84
-     * defaults to self::PHP_REMOVE
85
-     *
86
-     * @var int
87
-     */
88
-    protected $phpHandling = self::PHP_REMOVE;
82
+	/**
83
+	 * Stores the php handling level.
84
+	 * defaults to self::PHP_REMOVE
85
+	 *
86
+	 * @var int
87
+	 */
88
+	protected $phpHandling = self::PHP_REMOVE;
89 89
 
90
-    /**
91
-     * Stores the constant handling level.
92
-     * defaults to self::CONST_DISALLOW
93
-     *
94
-     * @var bool
95
-     */
96
-    protected $constHandling = self::CONST_DISALLOW;
90
+	/**
91
+	 * Stores the constant handling level.
92
+	 * defaults to self::CONST_DISALLOW
93
+	 *
94
+	 * @var bool
95
+	 */
96
+	protected $constHandling = self::CONST_DISALLOW;
97 97
 
98
-    /**
99
-     * Adds a php function to the allowed list.
100
-     *
101
-     * @param mixed $func function name or array of function names
102
-     */
103
-    public function allowPhpFunction($func)
104
-    {
105
-        if (is_array($func)) {
106
-            foreach ($func as $fname) {
107
-                $this->allowedPhpFunctions[strtolower($fname)] = true;
108
-            }
109
-        } else {
110
-            $this->allowedPhpFunctions[strtolower($func)] = true;
111
-        }
112
-    }
98
+	/**
99
+	 * Adds a php function to the allowed list.
100
+	 *
101
+	 * @param mixed $func function name or array of function names
102
+	 */
103
+	public function allowPhpFunction($func)
104
+	{
105
+		if (is_array($func)) {
106
+			foreach ($func as $fname) {
107
+				$this->allowedPhpFunctions[strtolower($fname)] = true;
108
+			}
109
+		} else {
110
+			$this->allowedPhpFunctions[strtolower($func)] = true;
111
+		}
112
+	}
113 113
 
114
-    /**
115
-     * Removes a php function from the allowed list.
116
-     *
117
-     * @param mixed $func function name or array of function names
118
-     */
119
-    public function disallowPhpFunction($func)
120
-    {
121
-        if (is_array($func)) {
122
-            foreach ($func as $fname) {
123
-                unset($this->allowedPhpFunctions[strtolower($fname)]);
124
-            }
125
-        } else {
126
-            unset($this->allowedPhpFunctions[strtolower($func)]);
127
-        }
128
-    }
114
+	/**
115
+	 * Removes a php function from the allowed list.
116
+	 *
117
+	 * @param mixed $func function name or array of function names
118
+	 */
119
+	public function disallowPhpFunction($func)
120
+	{
121
+		if (is_array($func)) {
122
+			foreach ($func as $fname) {
123
+				unset($this->allowedPhpFunctions[strtolower($fname)]);
124
+			}
125
+		} else {
126
+			unset($this->allowedPhpFunctions[strtolower($func)]);
127
+		}
128
+	}
129 129
 
130
-    /**
131
-     * Returns the list of php functions allowed to run, note that the function names
132
-     * are stored in the array keys and not values.
133
-     *
134
-     * @return array
135
-     */
136
-    public function getAllowedPhpFunctions()
137
-    {
138
-        return $this->allowedPhpFunctions;
139
-    }
130
+	/**
131
+	 * Returns the list of php functions allowed to run, note that the function names
132
+	 * are stored in the array keys and not values.
133
+	 *
134
+	 * @return array
135
+	 */
136
+	public function getAllowedPhpFunctions()
137
+	{
138
+		return $this->allowedPhpFunctions;
139
+	}
140 140
 
141
-    /**
142
-     * Adds a class method to the allowed list, this must be used for
143
-     * both static and non static method by providing the class name
144
-     * and method name to use.
145
-     *
146
-     * @param mixed  $class  class name or array of array('class', 'method') couples
147
-     * @param string $method method name
148
-     */
149
-    public function allowMethod($class, $method = null)
150
-    {
151
-        if (is_array($class)) {
152
-            foreach ($class as $elem) {
153
-                $this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])] = true;
154
-            }
155
-        } else {
156
-            $this->allowedMethods[strtolower($class)][strtolower($method)] = true;
157
-        }
158
-    }
141
+	/**
142
+	 * Adds a class method to the allowed list, this must be used for
143
+	 * both static and non static method by providing the class name
144
+	 * and method name to use.
145
+	 *
146
+	 * @param mixed  $class  class name or array of array('class', 'method') couples
147
+	 * @param string $method method name
148
+	 */
149
+	public function allowMethod($class, $method = null)
150
+	{
151
+		if (is_array($class)) {
152
+			foreach ($class as $elem) {
153
+				$this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])] = true;
154
+			}
155
+		} else {
156
+			$this->allowedMethods[strtolower($class)][strtolower($method)] = true;
157
+		}
158
+	}
159 159
 
160
-    /**
161
-     * Removes a class method from the allowed list.
162
-     *
163
-     * @param mixed  $class  class name or array of array('class', 'method') couples
164
-     * @param string $method method name
165
-     */
166
-    public function disallowMethod($class, $method = null)
167
-    {
168
-        if (is_array($class)) {
169
-            foreach ($class as $elem) {
170
-                unset($this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])]);
171
-            }
172
-        } else {
173
-            unset($this->allowedMethods[strtolower($class)][strtolower($method)]);
174
-        }
175
-    }
160
+	/**
161
+	 * Removes a class method from the allowed list.
162
+	 *
163
+	 * @param mixed  $class  class name or array of array('class', 'method') couples
164
+	 * @param string $method method name
165
+	 */
166
+	public function disallowMethod($class, $method = null)
167
+	{
168
+		if (is_array($class)) {
169
+			foreach ($class as $elem) {
170
+				unset($this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])]);
171
+			}
172
+		} else {
173
+			unset($this->allowedMethods[strtolower($class)][strtolower($method)]);
174
+		}
175
+	}
176 176
 
177
-    /**
178
-     * Returns the list of class methods allowed to run, note that the class names
179
-     * and method names are stored in the array keys and not values.
180
-     *
181
-     * @return array
182
-     */
183
-    public function getAllowedMethods()
184
-    {
185
-        return $this->allowedMethods;
186
-    }
177
+	/**
178
+	 * Returns the list of class methods allowed to run, note that the class names
179
+	 * and method names are stored in the array keys and not values.
180
+	 *
181
+	 * @return array
182
+	 */
183
+	public function getAllowedMethods()
184
+	{
185
+		return $this->allowedMethods;
186
+	}
187 187
 
188
-    /**
189
-     * Adds a directory to the safelist for includes and other file-access plugins.
190
-     * note that all the includePath directories you provide to the Dwoo_Template_File class
191
-     * are automatically marked as safe
192
-     *
193
-     * @param mixed $path a path name or an array of paths
194
-     */
195
-    public function allowDirectory($path)
196
-    {
197
-        if (is_array($path)) {
198
-            foreach ($path as $dir) {
199
-                $this->allowedDirectories[realpath($dir)] = true;
200
-            }
201
-        } else {
202
-            $this->allowedDirectories[realpath($path)] = true;
203
-        }
204
-    }
188
+	/**
189
+	 * Adds a directory to the safelist for includes and other file-access plugins.
190
+	 * note that all the includePath directories you provide to the Dwoo_Template_File class
191
+	 * are automatically marked as safe
192
+	 *
193
+	 * @param mixed $path a path name or an array of paths
194
+	 */
195
+	public function allowDirectory($path)
196
+	{
197
+		if (is_array($path)) {
198
+			foreach ($path as $dir) {
199
+				$this->allowedDirectories[realpath($dir)] = true;
200
+			}
201
+		} else {
202
+			$this->allowedDirectories[realpath($path)] = true;
203
+		}
204
+	}
205 205
 
206
-    /**
207
-     * Removes a directory from the safe list.
208
-     *
209
-     * @param mixed $path a path name or an array of paths
210
-     */
211
-    public function disallowDirectory($path)
212
-    {
213
-        if (is_array($path)) {
214
-            foreach ($path as $dir) {
215
-                unset($this->allowedDirectories[realpath($dir)]);
216
-            }
217
-        } else {
218
-            unset($this->allowedDirectories[realpath($path)]);
219
-        }
220
-    }
206
+	/**
207
+	 * Removes a directory from the safe list.
208
+	 *
209
+	 * @param mixed $path a path name or an array of paths
210
+	 */
211
+	public function disallowDirectory($path)
212
+	{
213
+		if (is_array($path)) {
214
+			foreach ($path as $dir) {
215
+				unset($this->allowedDirectories[realpath($dir)]);
216
+			}
217
+		} else {
218
+			unset($this->allowedDirectories[realpath($path)]);
219
+		}
220
+	}
221 221
 
222
-    /**
223
-     * Returns the list of safe paths, note that the paths are stored in the array
224
-     * keys and not values.
225
-     *
226
-     * @return array
227
-     */
228
-    public function getAllowedDirectories()
229
-    {
230
-        return $this->allowedDirectories;
231
-    }
222
+	/**
223
+	 * Returns the list of safe paths, note that the paths are stored in the array
224
+	 * keys and not values.
225
+	 *
226
+	 * @return array
227
+	 */
228
+	public function getAllowedDirectories()
229
+	{
230
+		return $this->allowedDirectories;
231
+	}
232 232
 
233
-    /**
234
-     * Sets the php handling level, defaults to REMOVE.
235
-     *
236
-     * @param int $level one of the Dwoo_Security_Policy::PHP_* constants
237
-     */
238
-    public function setPhpHandling($level = self::PHP_REMOVE)
239
-    {
240
-        $this->phpHandling = $level;
241
-    }
233
+	/**
234
+	 * Sets the php handling level, defaults to REMOVE.
235
+	 *
236
+	 * @param int $level one of the Dwoo_Security_Policy::PHP_* constants
237
+	 */
238
+	public function setPhpHandling($level = self::PHP_REMOVE)
239
+	{
240
+		$this->phpHandling = $level;
241
+	}
242 242
 
243
-    /**
244
-     * Returns the php handling level.
245
-     *
246
-     * @return int the current level, one of the Dwoo_Security_Policy::PHP_* constants
247
-     */
248
-    public function getPhpHandling()
249
-    {
250
-        return $this->phpHandling;
251
-    }
243
+	/**
244
+	 * Returns the php handling level.
245
+	 *
246
+	 * @return int the current level, one of the Dwoo_Security_Policy::PHP_* constants
247
+	 */
248
+	public function getPhpHandling()
249
+	{
250
+		return $this->phpHandling;
251
+	}
252 252
 
253
-    /**
254
-     * Sets the constant handling level, defaults to CONST_DISALLOW.
255
-     *
256
-     * @param bool $level one of the Dwoo_Security_Policy::CONST_* constants
257
-     */
258
-    public function setConstantHandling($level = self::CONST_DISALLOW)
259
-    {
260
-        $this->constHandling = $level;
261
-    }
253
+	/**
254
+	 * Sets the constant handling level, defaults to CONST_DISALLOW.
255
+	 *
256
+	 * @param bool $level one of the Dwoo_Security_Policy::CONST_* constants
257
+	 */
258
+	public function setConstantHandling($level = self::CONST_DISALLOW)
259
+	{
260
+		$this->constHandling = $level;
261
+	}
262 262
 
263
-    /**
264
-     * Returns the constant handling level.
265
-     *
266
-     * @return bool the current level, one of the Dwoo_Security_Policy::CONST_* constants
267
-     */
268
-    public function getConstantHandling()
269
-    {
270
-        return $this->constHandling;
271
-    }
263
+	/**
264
+	 * Returns the constant handling level.
265
+	 *
266
+	 * @return bool the current level, one of the Dwoo_Security_Policy::CONST_* constants
267
+	 */
268
+	public function getConstantHandling()
269
+	{
270
+		return $this->constHandling;
271
+	}
272 272
 
273
-    /**
274
-     * This is used at run time to check whether method calls are allowed or not.
275
-     *
276
-     * @param Core   $dwoo   dwoo instance that calls this
277
-     * @param object $obj    any object on which the method must be called
278
-     * @param string $method lowercased method name
279
-     * @param array  $args   arguments array
280
-     *
281
-     * @return mixed result of method call or unll + E_USER_NOTICE if not allowed
282
-     */
283
-    public function callMethod(Core $dwoo, $obj, $method, $args)
284
-    {
285
-        foreach ($this->allowedMethods as $class => $methods) {
286
-            if (!isset($methods[$method])) {
287
-                continue;
288
-            }
289
-            if ($obj instanceof $class) {
290
-                return call_user_func_array(array($obj, $method), $args);
291
-            }
292
-        }
293
-        $dwoo->triggerError('The current security policy prevents you from calling ' . get_class($obj) . '::' . $method . '()');
273
+	/**
274
+	 * This is used at run time to check whether method calls are allowed or not.
275
+	 *
276
+	 * @param Core   $dwoo   dwoo instance that calls this
277
+	 * @param object $obj    any object on which the method must be called
278
+	 * @param string $method lowercased method name
279
+	 * @param array  $args   arguments array
280
+	 *
281
+	 * @return mixed result of method call or unll + E_USER_NOTICE if not allowed
282
+	 */
283
+	public function callMethod(Core $dwoo, $obj, $method, $args)
284
+	{
285
+		foreach ($this->allowedMethods as $class => $methods) {
286
+			if (!isset($methods[$method])) {
287
+				continue;
288
+			}
289
+			if ($obj instanceof $class) {
290
+				return call_user_func_array(array($obj, $method), $args);
291
+			}
292
+		}
293
+		$dwoo->triggerError('The current security policy prevents you from calling ' . get_class($obj) . '::' . $method . '()');
294 294
 
295
-        return null;
296
-    }
295
+		return null;
296
+	}
297 297
 
298
-    /**
299
-     * This is used at compile time to check whether static method calls are allowed or not.
300
-     *
301
-     * @param mixed  $class  lowercased class name or array('class', 'method') couple
302
-     * @param string $method lowercased method name
303
-     *
304
-     * @return bool
305
-     */
306
-    public function isMethodAllowed($class, $method = null)
307
-    {
308
-        if (is_array($class)) {
309
-            list($class, $method) = $class;
310
-        }
311
-        foreach ($this->allowedMethods as $allowedClass => $methods) {
312
-            if (!isset($methods[$method])) {
313
-                continue;
314
-            }
315
-            if ($class === $allowedClass || is_subclass_of($class, $allowedClass)) {
316
-                return true;
317
-            }
318
-        }
298
+	/**
299
+	 * This is used at compile time to check whether static method calls are allowed or not.
300
+	 *
301
+	 * @param mixed  $class  lowercased class name or array('class', 'method') couple
302
+	 * @param string $method lowercased method name
303
+	 *
304
+	 * @return bool
305
+	 */
306
+	public function isMethodAllowed($class, $method = null)
307
+	{
308
+		if (is_array($class)) {
309
+			list($class, $method) = $class;
310
+		}
311
+		foreach ($this->allowedMethods as $allowedClass => $methods) {
312
+			if (!isset($methods[$method])) {
313
+				continue;
314
+			}
315
+			if ($class === $allowedClass || is_subclass_of($class, $allowedClass)) {
316
+				return true;
317
+			}
318
+		}
319 319
 
320
-        return false;
321
-    }
320
+		return false;
321
+	}
322 322
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -290,7 +290,7 @@
 block discarded – undo
290 290
                 return call_user_func_array(array($obj, $method), $args);
291 291
             }
292 292
         }
293
-        $dwoo->triggerError('The current security policy prevents you from calling ' . get_class($obj) . '::' . $method . '()');
293
+        $dwoo->triggerError('The current security policy prevents you from calling '.get_class($obj).'::'.$method.'()');
294 294
 
295 295
         return null;
296 296
     }
Please login to merge, or discard this patch.
lib/Dwoo/Template/Str.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -293,7 +293,7 @@
 block discarded – undo
293 293
      * @param Core   $core   the dwoo instance that requests it
294 294
      * @param string $output the template output
295 295
      *
296
-     * @return mixed full path of the cached file or false upon failure
296
+     * @return false|string full path of the cached file or false upon failure
297 297
      */
298 298
     public function cache(Core $core, $output)
299 299
     {
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -124,13 +124,13 @@  discard block
 block discarded – undo
124 124
         $this->cacheTime = $cacheTime;
125 125
 
126 126
         if ($compileId !== null) {
127
-            $this->compileId = str_replace('../', '__', strtr($compileId, '\\%?=!:;' . PATH_SEPARATOR, '/-------'));
127
+            $this->compileId = str_replace('../', '__', strtr($compileId, '\\%?=!:;'.PATH_SEPARATOR, '/-------'));
128 128
         } else {
129 129
             $this->compileId = $templateString;
130 130
         }
131 131
 
132 132
         if ($cacheId !== null) {
133
-            $this->cacheId = str_replace('../', '__', strtr($cacheId, '\\%?=!:;' . PATH_SEPARATOR, '/-------'));
133
+            $this->cacheId = str_replace('../', '__', strtr($cacheId, '\\%?=!:;'.PATH_SEPARATOR, '/-------'));
134 134
         }
135 135
     }
136 136
 
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
         if (isset(self::$cache['cached'][$this->cacheId]) === true && file_exists($cachedFile)) {
278 278
             // already checked, return cache file
279 279
             return $cachedFile;
280
-        } elseif ($this->compilationEnforced !== true && file_exists($cachedFile) && ($cacheLength === - 1 || filemtime($cachedFile) > ($_SERVER['REQUEST_TIME'] - $cacheLength)) && $this->isValidCompiledFile($this->getCompiledFilename($core))) {
280
+        } elseif ($this->compilationEnforced !== true && file_exists($cachedFile) && ($cacheLength === - 1 || filemtime($cachedFile) > ($_SERVER['REQUEST_TIME']-$cacheLength)) && $this->isValidCompiledFile($this->getCompiledFilename($core))) {
281 281
             // cache is still valid and can be loaded
282 282
             self::$cache['cached'][$this->cacheId] = true;
283 283
 
@@ -305,9 +305,9 @@  discard block
 block discarded – undo
305 305
         // thanks for his help on avoiding concurency issues
306 306
         $temp = tempnam($cacheDir, 'temp');
307 307
         if (!($file = @fopen($temp, 'wb'))) {
308
-            $temp = $cacheDir . uniqid('temp');
308
+            $temp = $cacheDir.uniqid('temp');
309 309
             if (!($file = @fopen($temp, 'wb'))) {
310
-                trigger_error('Error writing temporary file \'' . $temp . '\'', E_USER_WARNING);
310
+                trigger_error('Error writing temporary file \''.$temp.'\'', E_USER_WARNING);
311 311
 
312 312
                 return false;
313 313
             }
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
     {
344 344
         $cachedFile = $this->getCacheFilename($core);
345 345
 
346
-        return !file_exists($cachedFile) || (filectime($cachedFile) < (time() - $olderThan) && unlink($cachedFile));
346
+        return !file_exists($cachedFile) || (filectime($cachedFile) < (time()-$olderThan) && unlink($cachedFile));
347 347
     }
348 348
 
349 349
     /**
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
      */
447 447
     protected function getCompiledFilename(Core $core)
448 448
     {
449
-        return $core->getCompileDir() . hash('md4', $this->compileId) . '.d' . Core::RELEASE_TAG . '.php';
449
+        return $core->getCompileDir().hash('md4', $this->compileId).'.d'.Core::RELEASE_TAG.'.php';
450 450
     }
451 451
 
452 452
     /**
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
             if (isset($_SERVER['REQUEST_URI']) === true) {
465 465
                 $cacheId = $_SERVER['REQUEST_URI'];
466 466
             } elseif (isset($_SERVER['SCRIPT_FILENAME']) && isset($_SERVER['argv'])) {
467
-                $cacheId = $_SERVER['SCRIPT_FILENAME'] . '-' . implode('-', $_SERVER['argv']);
467
+                $cacheId = $_SERVER['SCRIPT_FILENAME'].'-'.implode('-', $_SERVER['argv']);
468 468
             } else {
469 469
                 $cacheId = '';
470 470
             }
@@ -472,10 +472,10 @@  discard block
 block discarded – undo
472 472
             $this->getCompiledFilename($core);
473 473
 
474 474
             $this->cacheId = str_replace('../', '__',
475
-                $this->compileId . strtr($cacheId, '\\%?=!:;' . PATH_SEPARATOR, '/-------'));
475
+                $this->compileId.strtr($cacheId, '\\%?=!:;'.PATH_SEPARATOR, '/-------'));
476 476
         }
477 477
 
478
-        return $core->getCacheDir() . $this->cacheId . '.html';
478
+        return $core->getCacheDir().$this->cacheId.'.html';
479 479
     }
480 480
 
481 481
     /**
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
         }
513 513
 
514 514
         $retries = 3;
515
-        while ($retries --) {
515
+        while ($retries--) {
516 516
             @mkdir($path, $chmod, true);
517 517
             if (is_dir($path)) {
518 518
                 break;
@@ -525,9 +525,9 @@  discard block
 block discarded – undo
525 525
             $path    = strtr(str_replace($baseDir, '', $path), '\\', '/');
526 526
             $folders = explode('/', trim($path, '/'));
527 527
             foreach ($folders as $folder) {
528
-                $baseDir .= $folder . DIRECTORY_SEPARATOR;
528
+                $baseDir .= $folder.DIRECTORY_SEPARATOR;
529 529
                 if (!chmod($baseDir, $chmod)) {
530
-                    throw new Exception('Unable to chmod ' . "$baseDir to $chmod: " . print_r(error_get_last(), true));
530
+                    throw new Exception('Unable to chmod '."$baseDir to $chmod: ".print_r(error_get_last(), true));
531 531
                 }
532 532
             }
533 533
         }
Please login to merge, or discard this patch.
Indentation   +503 added lines, -503 removed lines patch added patch discarded remove patch
@@ -29,507 +29,507 @@
 block discarded – undo
29 29
  */
30 30
 class Str implements ITemplate
31 31
 {
32
-    /**
33
-     * Template name.
34
-     *
35
-     * @var string
36
-     */
37
-    protected $name;
38
-
39
-    /**
40
-     * Template compilation id.
41
-     *
42
-     * @var string
43
-     */
44
-    protected $compileId;
45
-
46
-    /**
47
-     * Template cache id, if not provided in the constructor, it is set to
48
-     * the md4 hash of the request_uri. it is however highly recommended to
49
-     * provide one that will fit your needs.
50
-     * in all cases, the compilation id is prepended to the cache id to separate
51
-     * templates with similar cache ids from one another
52
-     *
53
-     * @var string
54
-     */
55
-    protected $cacheId;
56
-
57
-    /**
58
-     * Validity duration of the generated cache file (in seconds).
59
-     * set to -1 for infinite cache, 0 to disable and null to inherit the Dwoo instance's cache time
60
-     *
61
-     * @var int
62
-     */
63
-    protected $cacheTime;
64
-
65
-    /**
66
-     * Boolean flag that defines whether the compilation should be enforced (once) or
67
-     * not use this if you have issues with the compiled templates not being updated
68
-     * but if you do need this it's most likely that you should file a bug report.
69
-     *
70
-     * @var bool
71
-     */
72
-    protected $compilationEnforced;
73
-
74
-    /**
75
-     * Caches the results of the file checks to save some time when the same
76
-     * templates is rendered several times.
77
-     *
78
-     * @var array
79
-     */
80
-    protected static $cache = array(
81
-        'cached'   => array(),
82
-        'compiled' => array()
83
-    );
84
-
85
-    /**
86
-     * Holds the compiler that built this template.
87
-     *
88
-     * @var ICompiler
89
-     */
90
-    protected $compiler;
91
-
92
-    /**
93
-     * Chmod value for all files written (cached or compiled ones).
94
-     * set to null if you don't want any chmod operation to happen
95
-     *
96
-     * @var int
97
-     */
98
-    protected $chmod = 0777;
99
-
100
-    /**
101
-     * Containing template string.
102
-     *
103
-     * @var string
104
-     */
105
-    protected $template;
106
-
107
-    /**
108
-     * Creates a template from a string.
109
-     *
110
-     * @param string $templateString the template to use
111
-     * @param int    $cacheTime      duration of the cache validity for this template,
112
-     *                               if null it defaults to the Dwoo instance that will
113
-     *                               render this template, set to -1 for infinite cache or 0 to disable
114
-     * @param string $cacheId        the unique cache identifier of this page or anything else that
115
-     *                               makes this template's content unique, if null it defaults
116
-     *                               to the current url
117
-     * @param string $compileId      the unique compiled identifier, which is used to distinguish this
118
-     *                               template from others, if null it defaults to the md4 hash of the template
119
-     */
120
-    public function __construct($templateString, $cacheTime = null, $cacheId = null, $compileId = null)
121
-    {
122
-        $this->template  = $templateString;
123
-        $this->name      = hash('md4', $templateString);
124
-        $this->cacheTime = $cacheTime;
125
-
126
-        if ($compileId !== null) {
127
-            $this->compileId = str_replace('../', '__', strtr($compileId, '\\%?=!:;' . PATH_SEPARATOR, '/-------'));
128
-        } else {
129
-            $this->compileId = $templateString;
130
-        }
131
-
132
-        if ($cacheId !== null) {
133
-            $this->cacheId = str_replace('../', '__', strtr($cacheId, '\\%?=!:;' . PATH_SEPARATOR, '/-------'));
134
-        }
135
-    }
136
-
137
-    /**
138
-     * Returns the cache duration for this template.
139
-     * defaults to null if it was not provided
140
-     *
141
-     * @return int|null
142
-     */
143
-    public function getCacheTime()
144
-    {
145
-        return $this->cacheTime;
146
-    }
147
-
148
-    /**
149
-     * Sets the cache duration for this template.
150
-     * can be used to set it after the object is created if you did not provide
151
-     * it in the constructor
152
-     *
153
-     * @param int $seconds duration of the cache validity for this template, if
154
-     *                     null it defaults to the Dwoo instance's cache time. 0 = disable and
155
-     *                     -1 = infinite cache
156
-     */
157
-    public function setCacheTime($seconds = null)
158
-    {
159
-        $this->cacheTime = $seconds;
160
-    }
161
-
162
-    /**
163
-     * Returns the chmod value for all files written (cached or compiled ones).
164
-     * defaults to 0777
165
-     *
166
-     * @return int|null
167
-     */
168
-    public function getChmod()
169
-    {
170
-        return $this->chmod;
171
-    }
172
-
173
-    /**
174
-     * Set the chmod value for all files written (cached or compiled ones).
175
-     * set to null if you don't want to do any chmod() operation
176
-     *
177
-     * @param int $mask new bitmask to use for all files
178
-     */
179
-    public function setChmod($mask = null)
180
-    {
181
-        $this->chmod = $mask;
182
-    }
183
-
184
-    /**
185
-     * Returns the template name.
186
-     *
187
-     * @return string
188
-     */
189
-    public function getName()
190
-    {
191
-        return $this->name;
192
-    }
193
-
194
-    /**
195
-     * Returns the resource name for this template class.
196
-     *
197
-     * @return string
198
-     */
199
-    public function getResourceName()
200
-    {
201
-        return 'string';
202
-    }
203
-
204
-    /**
205
-     * Returns the resource identifier for this template, false here as strings don't have identifiers.
206
-     *
207
-     * @return false
208
-     */
209
-    public function getResourceIdentifier()
210
-    {
211
-        return false;
212
-    }
213
-
214
-    /**
215
-     * Returns the template source of this template.
216
-     *
217
-     * @return string
218
-     */
219
-    public function getSource()
220
-    {
221
-        return $this->template;
222
-    }
223
-
224
-    /**
225
-     * Returns an unique value identifying the current version of this template,
226
-     * in this case it's the md4 hash of the content.
227
-     *
228
-     * @return string
229
-     */
230
-    public function getUid()
231
-    {
232
-        return $this->name;
233
-    }
234
-
235
-    /**
236
-     * Returns the compiler used by this template, if it was just compiled, or null.
237
-     *
238
-     * @return ICompiler
239
-     */
240
-    public function getCompiler()
241
-    {
242
-        return $this->compiler;
243
-    }
244
-
245
-    /**
246
-     * Marks this template as compile-forced, which means it will be recompiled even if it
247
-     * was already saved and wasn't modified since the last compilation. do not use this in production,
248
-     * it's only meant to be used in development (and the development of dwoo particularly).
249
-     */
250
-    public function forceCompilation()
251
-    {
252
-        $this->compilationEnforced = true;
253
-    }
254
-
255
-    /**
256
-     * Returns the cached template output file name, true if it's cache-able but not cached
257
-     * or false if it's not cached.
258
-     *
259
-     * @param Core $core the dwoo instance that requests it
260
-     *
261
-     * @return string|bool
262
-     */
263
-    public function getCachedTemplate(Core $core)
264
-    {
265
-        $cacheLength = $core->getCacheTime();
266
-        if ($this->cacheTime !== null) {
267
-            $cacheLength = $this->cacheTime;
268
-        }
269
-
270
-        // file is not cacheable
271
-        if ($cacheLength == 0) {
272
-            return false;
273
-        }
274
-
275
-        $cachedFile = $this->getCacheFilename($core);
276
-
277
-        if (isset(self::$cache['cached'][$this->cacheId]) === true && file_exists($cachedFile)) {
278
-            // already checked, return cache file
279
-            return $cachedFile;
280
-        } elseif ($this->compilationEnforced !== true && file_exists($cachedFile) && ($cacheLength === - 1 || filemtime($cachedFile) > ($_SERVER['REQUEST_TIME'] - $cacheLength)) && $this->isValidCompiledFile($this->getCompiledFilename($core))) {
281
-            // cache is still valid and can be loaded
282
-            self::$cache['cached'][$this->cacheId] = true;
283
-
284
-            return $cachedFile;
285
-        }
286
-
287
-        // file is cacheable
288
-        return true;
289
-    }
290
-
291
-    /**
292
-     * Caches the provided output into the cache file.
293
-     *
294
-     * @param Core   $core   the dwoo instance that requests it
295
-     * @param string $output the template output
296
-     *
297
-     * @return mixed full path of the cached file or false upon failure
298
-     */
299
-    public function cache(Core $core, $output)
300
-    {
301
-        $cacheDir   = $core->getCacheDir();
302
-        $cachedFile = $this->getCacheFilename($core);
303
-
304
-        // the code below is courtesy of Rasmus Schultz,
305
-        // thanks for his help on avoiding concurency issues
306
-        $temp = tempnam($cacheDir, 'temp');
307
-        if (!($file = @fopen($temp, 'wb'))) {
308
-            $temp = $cacheDir . uniqid('temp');
309
-            if (!($file = @fopen($temp, 'wb'))) {
310
-                trigger_error('Error writing temporary file \'' . $temp . '\'', E_USER_WARNING);
311
-
312
-                return false;
313
-            }
314
-        }
315
-
316
-        fwrite($file, $output);
317
-        fclose($file);
318
-
319
-        $this->makeDirectory(dirname($cachedFile), $cacheDir);
320
-        if (!@rename($temp, $cachedFile)) {
321
-            @unlink($cachedFile);
322
-            @rename($temp, $cachedFile);
323
-        }
324
-
325
-        if ($this->chmod !== null) {
326
-            chmod($cachedFile, $this->chmod);
327
-        }
328
-
329
-        self::$cache['cached'][$this->cacheId] = true;
330
-
331
-        return $cachedFile;
332
-    }
333
-
334
-    /**
335
-     * Clears the cached template if it's older than the given time.
336
-     *
337
-     * @param Core $core      the dwoo instance that was used to cache that template
338
-     * @param int  $olderThan minimum time (in seconds) required for the cache to be cleared
339
-     *
340
-     * @return bool true if the cache was not present or if it was deleted, false if it remains there
341
-     */
342
-    public function clearCache(Core $core, $olderThan = - 1)
343
-    {
344
-        $cachedFile = $this->getCacheFilename($core);
345
-
346
-        return !file_exists($cachedFile) || (filectime($cachedFile) < (time() - $olderThan) && unlink($cachedFile));
347
-    }
348
-
349
-    /**
350
-     * Returns the compiled template file name.
351
-     *
352
-     * @param Core      $core     the dwoo instance that requests it
353
-     * @param ICompiler $compiler the compiler that must be used
354
-     *
355
-     * @return string
356
-     */
357
-    public function getCompiledTemplate(Core $core, ICompiler $compiler = null)
358
-    {
359
-        $compiledFile = $this->getCompiledFilename($core);
360
-
361
-        if ($this->compilationEnforced !== true && isset(self::$cache['compiled'][$this->compileId]) === true) {
362
-            // already checked, return compiled file
363
-        } elseif ($this->compilationEnforced !== true && $this->isValidCompiledFile($compiledFile)) {
364
-            // template is compiled
365
-            self::$cache['compiled'][$this->compileId] = true;
366
-        } else {
367
-            // compiles the template
368
-            $this->compilationEnforced = false;
369
-
370
-            if ($compiler === null) {
371
-                $compiler = $core->getDefaultCompilerFactory($this->getResourceName());
372
-
373
-                if ($compiler === null || $compiler === array('Dwoo\Compiler', 'compilerFactory')) {
374
-                    $compiler = Compiler::compilerFactory();
375
-                } else {
376
-                    $compiler = call_user_func($compiler);
377
-                }
378
-            }
379
-
380
-            $this->compiler = $compiler;
381
-
382
-            $compiler->setCustomPlugins($core->getCustomPlugins());
383
-            $compiler->setSecurityPolicy($core->getSecurityPolicy());
384
-            $this->makeDirectory(dirname($compiledFile), $core->getCompileDir());
385
-            file_put_contents($compiledFile, $compiler->compile($core, $this));
386
-            if ($this->chmod !== null) {
387
-                chmod($compiledFile, $this->chmod);
388
-            }
389
-
390
-            if (extension_loaded('Zend OPcache')) {
391
-                opcache_invalidate($compiledFile);
392
-            } elseif (extension_loaded('apc') && ini_get('apc.enabled')) {
393
-                apc_delete_file($compiledFile);
394
-            }
395
-
396
-            self::$cache['compiled'][$this->compileId] = true;
397
-        }
398
-
399
-        return $compiledFile;
400
-    }
401
-
402
-    /**
403
-     * Checks if compiled file is valid (it exists).
404
-     *
405
-     * @param string $file
406
-     *
407
-     * @return bool True cache file existence
408
-     */
409
-    protected function isValidCompiledFile($file)
410
-    {
411
-        return file_exists($file);
412
-    }
413
-
414
-    /**
415
-     * Returns a new template string object with the resource id being the template source code.
416
-     *
417
-     * @param Core      $core           the dwoo instance requiring it
418
-     * @param mixed     $resourceId     the filename (relative to this template's dir) of the template to include
419
-     * @param int       $cacheTime      duration of the cache validity for this template, if null it defaults to the
420
-     *                                  Dwoo instance that will render this template if null it defaults to the Dwoo
421
-     *                                  instance that will render this template
422
-     * @param string    $cacheId        the unique cache identifier of this page or anything else that makes this
423
-     *                                  template's content unique, if null it defaults to the current url makes this
424
-     *                                  template's content unique, if null it defaults to the current url
425
-     * @param string    $compileId      the unique compiled identifier, which is used to distinguish this template from
426
-     *                                  others, if null it defaults to the filename+bits of the path template from
427
-     *                                  others, if null it defaults to the filename+bits of the path
428
-     * @param ITemplate $parentTemplate the template that is requesting a new template object (through an include,
429
-     *                                  extends or any other plugin) an include, extends or any other plugin)
430
-     *
431
-     * @return $this
432
-     */
433
-    public static function templateFactory(Core $core, $resourceId, $cacheTime = null, $cacheId = null,
434
-                                           $compileId = null, ITemplate $parentTemplate = null)
435
-    {
436
-        return new self($resourceId, $cacheTime, $cacheId, $compileId);
437
-    }
438
-
439
-    /**
440
-     * Returns the full compiled file name and assigns a default value to it if
441
-     * required.
442
-     *
443
-     * @param Core $core the Core instance that requests the file name
444
-     *
445
-     * @return string the full path to the compiled file
446
-     */
447
-    protected function getCompiledFilename(Core $core)
448
-    {
449
-        return $core->getCompileDir() . hash('md4', $this->compileId) . '.d' . Core::RELEASE_TAG . '.php';
450
-    }
451
-
452
-    /**
453
-     * Returns the full cached file name and assigns a default value to it if
454
-     * required.
455
-     *
456
-     * @param Core $core the dwoo instance that requests the file name
457
-     *
458
-     * @return string the full path to the cached file
459
-     */
460
-    protected function getCacheFilename(Core $core)
461
-    {
462
-        // no cache id provided, use request_uri as default
463
-        if ($this->cacheId === null) {
464
-            if (isset($_SERVER['REQUEST_URI']) === true) {
465
-                $cacheId = $_SERVER['REQUEST_URI'];
466
-            } elseif (isset($_SERVER['SCRIPT_FILENAME']) && isset($_SERVER['argv'])) {
467
-                $cacheId = $_SERVER['SCRIPT_FILENAME'] . '-' . implode('-', $_SERVER['argv']);
468
-            } else {
469
-                $cacheId = '';
470
-            }
471
-            // force compiled id generation
472
-            $this->getCompiledFilename($core);
473
-
474
-            $this->cacheId = str_replace('../', '__',
475
-                $this->compileId . strtr($cacheId, '\\%?=!:;' . PATH_SEPARATOR, '/-------'));
476
-        }
477
-
478
-        return $core->getCacheDir() . $this->cacheId . '.html';
479
-    }
480
-
481
-    /**
482
-     * Returns some php code that will check if this template has been modified or not.
483
-     * if the function returns null, the template will be instanciated and then the Uid checked
484
-     *
485
-     * @return string
486
-     */
487
-    public function getIsModifiedCode()
488
-    {
489
-        return null;
490
-    }
491
-
492
-    /**
493
-     * Ensures the given path exists.
494
-     *
495
-     * @param string $path    any path
496
-     * @param string $baseDir the base directory where the directory is created
497
-     *                        ($path must still contain the full path, $baseDir
498
-     *                        is only used for unix permissions)
499
-     *
500
-     * @throws Exception
501
-     */
502
-    protected function makeDirectory($path, $baseDir = null)
503
-    {
504
-        if (is_dir($path) === true) {
505
-            return;
506
-        }
507
-
508
-        if ($this->chmod === null) {
509
-            $chmod = 0777;
510
-        } else {
511
-            $chmod = $this->chmod;
512
-        }
513
-
514
-        $retries = 3;
515
-        while ($retries --) {
516
-            @mkdir($path, $chmod, true);
517
-            if (is_dir($path)) {
518
-                break;
519
-            }
520
-            usleep(20);
521
-        }
522
-
523
-        // enforce the correct mode for all directories created
524
-        if (strpos(PHP_OS, 'WIN') !== 0 && $baseDir !== null) {
525
-            $path    = strtr(str_replace($baseDir, '', $path), '\\', '/');
526
-            $folders = explode('/', trim($path, '/'));
527
-            foreach ($folders as $folder) {
528
-                $baseDir .= $folder . DIRECTORY_SEPARATOR;
529
-                if (!chmod($baseDir, $chmod)) {
530
-                    throw new Exception('Unable to chmod ' . "$baseDir to $chmod: " . print_r(error_get_last(), true));
531
-                }
532
-            }
533
-        }
534
-    }
32
+	/**
33
+	 * Template name.
34
+	 *
35
+	 * @var string
36
+	 */
37
+	protected $name;
38
+
39
+	/**
40
+	 * Template compilation id.
41
+	 *
42
+	 * @var string
43
+	 */
44
+	protected $compileId;
45
+
46
+	/**
47
+	 * Template cache id, if not provided in the constructor, it is set to
48
+	 * the md4 hash of the request_uri. it is however highly recommended to
49
+	 * provide one that will fit your needs.
50
+	 * in all cases, the compilation id is prepended to the cache id to separate
51
+	 * templates with similar cache ids from one another
52
+	 *
53
+	 * @var string
54
+	 */
55
+	protected $cacheId;
56
+
57
+	/**
58
+	 * Validity duration of the generated cache file (in seconds).
59
+	 * set to -1 for infinite cache, 0 to disable and null to inherit the Dwoo instance's cache time
60
+	 *
61
+	 * @var int
62
+	 */
63
+	protected $cacheTime;
64
+
65
+	/**
66
+	 * Boolean flag that defines whether the compilation should be enforced (once) or
67
+	 * not use this if you have issues with the compiled templates not being updated
68
+	 * but if you do need this it's most likely that you should file a bug report.
69
+	 *
70
+	 * @var bool
71
+	 */
72
+	protected $compilationEnforced;
73
+
74
+	/**
75
+	 * Caches the results of the file checks to save some time when the same
76
+	 * templates is rendered several times.
77
+	 *
78
+	 * @var array
79
+	 */
80
+	protected static $cache = array(
81
+		'cached'   => array(),
82
+		'compiled' => array()
83
+	);
84
+
85
+	/**
86
+	 * Holds the compiler that built this template.
87
+	 *
88
+	 * @var ICompiler
89
+	 */
90
+	protected $compiler;
91
+
92
+	/**
93
+	 * Chmod value for all files written (cached or compiled ones).
94
+	 * set to null if you don't want any chmod operation to happen
95
+	 *
96
+	 * @var int
97
+	 */
98
+	protected $chmod = 0777;
99
+
100
+	/**
101
+	 * Containing template string.
102
+	 *
103
+	 * @var string
104
+	 */
105
+	protected $template;
106
+
107
+	/**
108
+	 * Creates a template from a string.
109
+	 *
110
+	 * @param string $templateString the template to use
111
+	 * @param int    $cacheTime      duration of the cache validity for this template,
112
+	 *                               if null it defaults to the Dwoo instance that will
113
+	 *                               render this template, set to -1 for infinite cache or 0 to disable
114
+	 * @param string $cacheId        the unique cache identifier of this page or anything else that
115
+	 *                               makes this template's content unique, if null it defaults
116
+	 *                               to the current url
117
+	 * @param string $compileId      the unique compiled identifier, which is used to distinguish this
118
+	 *                               template from others, if null it defaults to the md4 hash of the template
119
+	 */
120
+	public function __construct($templateString, $cacheTime = null, $cacheId = null, $compileId = null)
121
+	{
122
+		$this->template  = $templateString;
123
+		$this->name      = hash('md4', $templateString);
124
+		$this->cacheTime = $cacheTime;
125
+
126
+		if ($compileId !== null) {
127
+			$this->compileId = str_replace('../', '__', strtr($compileId, '\\%?=!:;' . PATH_SEPARATOR, '/-------'));
128
+		} else {
129
+			$this->compileId = $templateString;
130
+		}
131
+
132
+		if ($cacheId !== null) {
133
+			$this->cacheId = str_replace('../', '__', strtr($cacheId, '\\%?=!:;' . PATH_SEPARATOR, '/-------'));
134
+		}
135
+	}
136
+
137
+	/**
138
+	 * Returns the cache duration for this template.
139
+	 * defaults to null if it was not provided
140
+	 *
141
+	 * @return int|null
142
+	 */
143
+	public function getCacheTime()
144
+	{
145
+		return $this->cacheTime;
146
+	}
147
+
148
+	/**
149
+	 * Sets the cache duration for this template.
150
+	 * can be used to set it after the object is created if you did not provide
151
+	 * it in the constructor
152
+	 *
153
+	 * @param int $seconds duration of the cache validity for this template, if
154
+	 *                     null it defaults to the Dwoo instance's cache time. 0 = disable and
155
+	 *                     -1 = infinite cache
156
+	 */
157
+	public function setCacheTime($seconds = null)
158
+	{
159
+		$this->cacheTime = $seconds;
160
+	}
161
+
162
+	/**
163
+	 * Returns the chmod value for all files written (cached or compiled ones).
164
+	 * defaults to 0777
165
+	 *
166
+	 * @return int|null
167
+	 */
168
+	public function getChmod()
169
+	{
170
+		return $this->chmod;
171
+	}
172
+
173
+	/**
174
+	 * Set the chmod value for all files written (cached or compiled ones).
175
+	 * set to null if you don't want to do any chmod() operation
176
+	 *
177
+	 * @param int $mask new bitmask to use for all files
178
+	 */
179
+	public function setChmod($mask = null)
180
+	{
181
+		$this->chmod = $mask;
182
+	}
183
+
184
+	/**
185
+	 * Returns the template name.
186
+	 *
187
+	 * @return string
188
+	 */
189
+	public function getName()
190
+	{
191
+		return $this->name;
192
+	}
193
+
194
+	/**
195
+	 * Returns the resource name for this template class.
196
+	 *
197
+	 * @return string
198
+	 */
199
+	public function getResourceName()
200
+	{
201
+		return 'string';
202
+	}
203
+
204
+	/**
205
+	 * Returns the resource identifier for this template, false here as strings don't have identifiers.
206
+	 *
207
+	 * @return false
208
+	 */
209
+	public function getResourceIdentifier()
210
+	{
211
+		return false;
212
+	}
213
+
214
+	/**
215
+	 * Returns the template source of this template.
216
+	 *
217
+	 * @return string
218
+	 */
219
+	public function getSource()
220
+	{
221
+		return $this->template;
222
+	}
223
+
224
+	/**
225
+	 * Returns an unique value identifying the current version of this template,
226
+	 * in this case it's the md4 hash of the content.
227
+	 *
228
+	 * @return string
229
+	 */
230
+	public function getUid()
231
+	{
232
+		return $this->name;
233
+	}
234
+
235
+	/**
236
+	 * Returns the compiler used by this template, if it was just compiled, or null.
237
+	 *
238
+	 * @return ICompiler
239
+	 */
240
+	public function getCompiler()
241
+	{
242
+		return $this->compiler;
243
+	}
244
+
245
+	/**
246
+	 * Marks this template as compile-forced, which means it will be recompiled even if it
247
+	 * was already saved and wasn't modified since the last compilation. do not use this in production,
248
+	 * it's only meant to be used in development (and the development of dwoo particularly).
249
+	 */
250
+	public function forceCompilation()
251
+	{
252
+		$this->compilationEnforced = true;
253
+	}
254
+
255
+	/**
256
+	 * Returns the cached template output file name, true if it's cache-able but not cached
257
+	 * or false if it's not cached.
258
+	 *
259
+	 * @param Core $core the dwoo instance that requests it
260
+	 *
261
+	 * @return string|bool
262
+	 */
263
+	public function getCachedTemplate(Core $core)
264
+	{
265
+		$cacheLength = $core->getCacheTime();
266
+		if ($this->cacheTime !== null) {
267
+			$cacheLength = $this->cacheTime;
268
+		}
269
+
270
+		// file is not cacheable
271
+		if ($cacheLength == 0) {
272
+			return false;
273
+		}
274
+
275
+		$cachedFile = $this->getCacheFilename($core);
276
+
277
+		if (isset(self::$cache['cached'][$this->cacheId]) === true && file_exists($cachedFile)) {
278
+			// already checked, return cache file
279
+			return $cachedFile;
280
+		} elseif ($this->compilationEnforced !== true && file_exists($cachedFile) && ($cacheLength === - 1 || filemtime($cachedFile) > ($_SERVER['REQUEST_TIME'] - $cacheLength)) && $this->isValidCompiledFile($this->getCompiledFilename($core))) {
281
+			// cache is still valid and can be loaded
282
+			self::$cache['cached'][$this->cacheId] = true;
283
+
284
+			return $cachedFile;
285
+		}
286
+
287
+		// file is cacheable
288
+		return true;
289
+	}
290
+
291
+	/**
292
+	 * Caches the provided output into the cache file.
293
+	 *
294
+	 * @param Core   $core   the dwoo instance that requests it
295
+	 * @param string $output the template output
296
+	 *
297
+	 * @return mixed full path of the cached file or false upon failure
298
+	 */
299
+	public function cache(Core $core, $output)
300
+	{
301
+		$cacheDir   = $core->getCacheDir();
302
+		$cachedFile = $this->getCacheFilename($core);
303
+
304
+		// the code below is courtesy of Rasmus Schultz,
305
+		// thanks for his help on avoiding concurency issues
306
+		$temp = tempnam($cacheDir, 'temp');
307
+		if (!($file = @fopen($temp, 'wb'))) {
308
+			$temp = $cacheDir . uniqid('temp');
309
+			if (!($file = @fopen($temp, 'wb'))) {
310
+				trigger_error('Error writing temporary file \'' . $temp . '\'', E_USER_WARNING);
311
+
312
+				return false;
313
+			}
314
+		}
315
+
316
+		fwrite($file, $output);
317
+		fclose($file);
318
+
319
+		$this->makeDirectory(dirname($cachedFile), $cacheDir);
320
+		if (!@rename($temp, $cachedFile)) {
321
+			@unlink($cachedFile);
322
+			@rename($temp, $cachedFile);
323
+		}
324
+
325
+		if ($this->chmod !== null) {
326
+			chmod($cachedFile, $this->chmod);
327
+		}
328
+
329
+		self::$cache['cached'][$this->cacheId] = true;
330
+
331
+		return $cachedFile;
332
+	}
333
+
334
+	/**
335
+	 * Clears the cached template if it's older than the given time.
336
+	 *
337
+	 * @param Core $core      the dwoo instance that was used to cache that template
338
+	 * @param int  $olderThan minimum time (in seconds) required for the cache to be cleared
339
+	 *
340
+	 * @return bool true if the cache was not present or if it was deleted, false if it remains there
341
+	 */
342
+	public function clearCache(Core $core, $olderThan = - 1)
343
+	{
344
+		$cachedFile = $this->getCacheFilename($core);
345
+
346
+		return !file_exists($cachedFile) || (filectime($cachedFile) < (time() - $olderThan) && unlink($cachedFile));
347
+	}
348
+
349
+	/**
350
+	 * Returns the compiled template file name.
351
+	 *
352
+	 * @param Core      $core     the dwoo instance that requests it
353
+	 * @param ICompiler $compiler the compiler that must be used
354
+	 *
355
+	 * @return string
356
+	 */
357
+	public function getCompiledTemplate(Core $core, ICompiler $compiler = null)
358
+	{
359
+		$compiledFile = $this->getCompiledFilename($core);
360
+
361
+		if ($this->compilationEnforced !== true && isset(self::$cache['compiled'][$this->compileId]) === true) {
362
+			// already checked, return compiled file
363
+		} elseif ($this->compilationEnforced !== true && $this->isValidCompiledFile($compiledFile)) {
364
+			// template is compiled
365
+			self::$cache['compiled'][$this->compileId] = true;
366
+		} else {
367
+			// compiles the template
368
+			$this->compilationEnforced = false;
369
+
370
+			if ($compiler === null) {
371
+				$compiler = $core->getDefaultCompilerFactory($this->getResourceName());
372
+
373
+				if ($compiler === null || $compiler === array('Dwoo\Compiler', 'compilerFactory')) {
374
+					$compiler = Compiler::compilerFactory();
375
+				} else {
376
+					$compiler = call_user_func($compiler);
377
+				}
378
+			}
379
+
380
+			$this->compiler = $compiler;
381
+
382
+			$compiler->setCustomPlugins($core->getCustomPlugins());
383
+			$compiler->setSecurityPolicy($core->getSecurityPolicy());
384
+			$this->makeDirectory(dirname($compiledFile), $core->getCompileDir());
385
+			file_put_contents($compiledFile, $compiler->compile($core, $this));
386
+			if ($this->chmod !== null) {
387
+				chmod($compiledFile, $this->chmod);
388
+			}
389
+
390
+			if (extension_loaded('Zend OPcache')) {
391
+				opcache_invalidate($compiledFile);
392
+			} elseif (extension_loaded('apc') && ini_get('apc.enabled')) {
393
+				apc_delete_file($compiledFile);
394
+			}
395
+
396
+			self::$cache['compiled'][$this->compileId] = true;
397
+		}
398
+
399
+		return $compiledFile;
400
+	}
401
+
402
+	/**
403
+	 * Checks if compiled file is valid (it exists).
404
+	 *
405
+	 * @param string $file
406
+	 *
407
+	 * @return bool True cache file existence
408
+	 */
409
+	protected function isValidCompiledFile($file)
410
+	{
411
+		return file_exists($file);
412
+	}
413
+
414
+	/**
415
+	 * Returns a new template string object with the resource id being the template source code.
416
+	 *
417
+	 * @param Core      $core           the dwoo instance requiring it
418
+	 * @param mixed     $resourceId     the filename (relative to this template's dir) of the template to include
419
+	 * @param int       $cacheTime      duration of the cache validity for this template, if null it defaults to the
420
+	 *                                  Dwoo instance that will render this template if null it defaults to the Dwoo
421
+	 *                                  instance that will render this template
422
+	 * @param string    $cacheId        the unique cache identifier of this page or anything else that makes this
423
+	 *                                  template's content unique, if null it defaults to the current url makes this
424
+	 *                                  template's content unique, if null it defaults to the current url
425
+	 * @param string    $compileId      the unique compiled identifier, which is used to distinguish this template from
426
+	 *                                  others, if null it defaults to the filename+bits of the path template from
427
+	 *                                  others, if null it defaults to the filename+bits of the path
428
+	 * @param ITemplate $parentTemplate the template that is requesting a new template object (through an include,
429
+	 *                                  extends or any other plugin) an include, extends or any other plugin)
430
+	 *
431
+	 * @return $this
432
+	 */
433
+	public static function templateFactory(Core $core, $resourceId, $cacheTime = null, $cacheId = null,
434
+										   $compileId = null, ITemplate $parentTemplate = null)
435
+	{
436
+		return new self($resourceId, $cacheTime, $cacheId, $compileId);
437
+	}
438
+
439
+	/**
440
+	 * Returns the full compiled file name and assigns a default value to it if
441
+	 * required.
442
+	 *
443
+	 * @param Core $core the Core instance that requests the file name
444
+	 *
445
+	 * @return string the full path to the compiled file
446
+	 */
447
+	protected function getCompiledFilename(Core $core)
448
+	{
449
+		return $core->getCompileDir() . hash('md4', $this->compileId) . '.d' . Core::RELEASE_TAG . '.php';
450
+	}
451
+
452
+	/**
453
+	 * Returns the full cached file name and assigns a default value to it if
454
+	 * required.
455
+	 *
456
+	 * @param Core $core the dwoo instance that requests the file name
457
+	 *
458
+	 * @return string the full path to the cached file
459
+	 */
460
+	protected function getCacheFilename(Core $core)
461
+	{
462
+		// no cache id provided, use request_uri as default
463
+		if ($this->cacheId === null) {
464
+			if (isset($_SERVER['REQUEST_URI']) === true) {
465
+				$cacheId = $_SERVER['REQUEST_URI'];
466
+			} elseif (isset($_SERVER['SCRIPT_FILENAME']) && isset($_SERVER['argv'])) {
467
+				$cacheId = $_SERVER['SCRIPT_FILENAME'] . '-' . implode('-', $_SERVER['argv']);
468
+			} else {
469
+				$cacheId = '';
470
+			}
471
+			// force compiled id generation
472
+			$this->getCompiledFilename($core);
473
+
474
+			$this->cacheId = str_replace('../', '__',
475
+				$this->compileId . strtr($cacheId, '\\%?=!:;' . PATH_SEPARATOR, '/-------'));
476
+		}
477
+
478
+		return $core->getCacheDir() . $this->cacheId . '.html';
479
+	}
480
+
481
+	/**
482
+	 * Returns some php code that will check if this template has been modified or not.
483
+	 * if the function returns null, the template will be instanciated and then the Uid checked
484
+	 *
485
+	 * @return string
486
+	 */
487
+	public function getIsModifiedCode()
488
+	{
489
+		return null;
490
+	}
491
+
492
+	/**
493
+	 * Ensures the given path exists.
494
+	 *
495
+	 * @param string $path    any path
496
+	 * @param string $baseDir the base directory where the directory is created
497
+	 *                        ($path must still contain the full path, $baseDir
498
+	 *                        is only used for unix permissions)
499
+	 *
500
+	 * @throws Exception
501
+	 */
502
+	protected function makeDirectory($path, $baseDir = null)
503
+	{
504
+		if (is_dir($path) === true) {
505
+			return;
506
+		}
507
+
508
+		if ($this->chmod === null) {
509
+			$chmod = 0777;
510
+		} else {
511
+			$chmod = $this->chmod;
512
+		}
513
+
514
+		$retries = 3;
515
+		while ($retries --) {
516
+			@mkdir($path, $chmod, true);
517
+			if (is_dir($path)) {
518
+				break;
519
+			}
520
+			usleep(20);
521
+		}
522
+
523
+		// enforce the correct mode for all directories created
524
+		if (strpos(PHP_OS, 'WIN') !== 0 && $baseDir !== null) {
525
+			$path    = strtr(str_replace($baseDir, '', $path), '\\', '/');
526
+			$folders = explode('/', trim($path, '/'));
527
+			foreach ($folders as $folder) {
528
+				$baseDir .= $folder . DIRECTORY_SEPARATOR;
529
+				if (!chmod($baseDir, $chmod)) {
530
+					throw new Exception('Unable to chmod ' . "$baseDir to $chmod: " . print_r(error_get_last(), true));
531
+				}
532
+			}
533
+		}
534
+	}
535 535
 }
Please login to merge, or discard this patch.