Completed
Push — 1.2 ( 261ddf...fd7ca1 )
by David
15:45 queued 09:58
created
lib/plugins/builtin/blocks/auto_escape.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -21,46 +21,46 @@
 block discarded – undo
21 21
  */
22 22
 class Dwoo_Plugin_auto_escape extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
23 23
 {
24
-    protected static $stack = array();
24
+	protected static $stack = array();
25 25
 
26
-    public function init($enabled)
27
-    {
28
-    }
26
+	public function init($enabled)
27
+	{
28
+	}
29 29
 
30
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
31
-    {
32
-        $params = $compiler->getCompiledParams($params);
33
-        switch (strtolower(trim((string) $params['enabled'], '"\''))) {
30
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
31
+	{
32
+		$params = $compiler->getCompiledParams($params);
33
+		switch (strtolower(trim((string) $params['enabled'], '"\''))) {
34 34
 
35
-        case 'on':
36
-        case 'true':
37
-        case 'enabled':
38
-        case 'enable':
39
-        case '1':
40
-            $enable = true;
41
-            break;
42
-        case 'off':
43
-        case 'false':
44
-        case 'disabled':
45
-        case 'disable':
46
-        case '0':
47
-            $enable = false;
48
-            break;
49
-        default:
50
-            throw new Dwoo_Compilation_Exception($compiler, 'Auto_Escape : Invalid parameter ('.$params['enabled'].'), valid parameters are "enable"/true or "disable"/false');
35
+		case 'on':
36
+		case 'true':
37
+		case 'enabled':
38
+		case 'enable':
39
+		case '1':
40
+			$enable = true;
41
+			break;
42
+		case 'off':
43
+		case 'false':
44
+		case 'disabled':
45
+		case 'disable':
46
+		case '0':
47
+			$enable = false;
48
+			break;
49
+		default:
50
+			throw new Dwoo_Compilation_Exception($compiler, 'Auto_Escape : Invalid parameter ('.$params['enabled'].'), valid parameters are "enable"/true or "disable"/false');
51 51
 
52
-        }
52
+		}
53 53
 
54
-        self::$stack[] = $compiler->getAutoEscape();
55
-        $compiler->setAutoEscape($enable);
54
+		self::$stack[] = $compiler->getAutoEscape();
55
+		$compiler->setAutoEscape($enable);
56 56
 
57
-        return '';
58
-    }
57
+		return '';
58
+	}
59 59
 
60
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
61
-    {
62
-        $compiler->setAutoEscape(array_pop(self::$stack));
60
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
61
+	{
62
+		$compiler->setAutoEscape(array_pop(self::$stack));
63 63
 
64
-        return $content;
65
-    }
64
+		return $content;
65
+	}
66 66
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/filters/html_format.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -25,158 +25,158 @@
 block discarded – undo
25 25
  */
26 26
 class Dwoo_Filter_html_format extends Dwoo_Filter
27 27
 {
28
-    /**
29
-     * tab count to auto-indent the source.
30
-     *
31
-     * @var int
32
-     */
33
-    protected static $tabCount = -1;
34
-
35
-    /**
36
-     * stores the additional data (following a tag) of the last call to open/close/singleTag.
37
-     *
38
-     * @var string
39
-     */
40
-    protected static $lastCallAdd = '';
41
-
42
-    /**
43
-     * formats the input using the singleTag/closeTag/openTag functions.
44
-     *
45
-     * It is auto indenting the whole code, excluding <textarea>, <code> and <pre> tags that must be kept intact.
46
-     * Those tags must however contain only htmlentities-escaped text for everything to work properly.
47
-     * Inline tags are presented on a single line with their content
48
-     *
49
-     * @param string $input the xhtml to format
50
-     *
51
-     * @return string formatted xhtml
52
-     */
53
-    public function process($input)
54
-    {
55
-        self::$tabCount = -1;
56
-
57
-        // auto indent all but textareas & pre (or we have weird tabs inside)
58
-        $input = preg_replace_callback("#(<[^>]+>)(\s*)([^<]*)#", array('self', 'tagDispatcher'), $input);
59
-
60
-        return $input;
61
-    }
62
-
63
-    /**
64
-     * helper function for format()'s preg_replace call.
65
-     *
66
-     * @param array $input array of matches (1=>tag, 2=>whitespace(optional), 3=>additional non-html content)
67
-     *
68
-     * @return string the indented tag
69
-     */
70
-    protected static function tagDispatcher($input)
71
-    {
72
-        // 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
73
-        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[') {
74
-            return $input[1].$input[3];
75
-        }
76
-        // 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
77
-        if (substr($input[1], 0, 10) == '</textarea' || substr($input[1], 0, 5) == '</pre' || substr($input[1], 0, 6) == '</code' || substr($input[1], -2) == '/>') {
78
-            return self::singleTag($input[1], $input[3], $input[2]);
79
-        }
80
-        // it's the closing tag
81
-        if ($input[0][1] == '/') {
82
-            return self::closeTag($input[1], $input[3], $input[2]);
83
-        }
84
-        // opening tag
85
-        return self::openTag($input[1], $input[3], $input[2]);
86
-    }
87
-
88
-    /**
89
-     * returns an open tag and adds a tab into the auto indenting.
90
-     *
91
-     * @param string $tag        content of the tag
92
-     * @param string $add        additional data (anything before the following tag)
93
-     * @param string $whitespace white space between the tag and the additional data
94
-     *
95
-     * @return string
96
-     */
97
-    protected static function openTag($tag, $add, $whitespace)
98
-    {
99
-        $tabs = str_pad('', self::$tabCount++, "\t");
100
-
101
-        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)) {
102
-            // if it's one of those tag it's inline so it does not require a leading line break
103
-            $result = $tag.$whitespace.str_replace("\n", "\n".$tabs, $add);
104
-        } elseif (substr($tag, 0, 9) == '<!DOCTYPE') {
105
-            // it's the doctype declaration so no line break here either
106
-            $result = $tabs.$tag;
107
-        } else {
108
-            // normal block tag
109
-            $result = "\n".$tabs.$tag;
110
-
111
-            if (!empty($add)) {
112
-                $result .= "\n".$tabs."\t".str_replace("\n", "\n\t".$tabs, $add);
113
-            }
114
-        }
115
-
116
-        self::$lastCallAdd = $add;
117
-
118
-        return $result;
119
-    }
120
-
121
-    /**
122
-     * returns a closing tag and removes a tab from the auto indenting.
123
-     *
124
-     * @param string $tag        content of the tag
125
-     * @param string $add        additional data (anything before the following tag)
126
-     * @param string $whitespace white space between the tag and the additional data
127
-     *
128
-     * @return string
129
-     */
130
-    protected static function closeTag($tag, $add, $whitespace)
131
-    {
132
-        $tabs = str_pad('', --self::$tabCount, "\t");
133
-
134
-        // if it's one of those tag it's inline so it does not require a leading line break
135
-        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)) {
136
-            $result = $tag.$whitespace.str_replace("\n", "\n".$tabs, $add);
137
-        } else {
138
-            $result = "\n".$tabs.$tag;
139
-
140
-            if (!empty($add)) {
141
-                $result .= "\n".$tabs."\t".str_replace("\n", "\n\t".$tabs, $add);
142
-            }
143
-        }
144
-
145
-        self::$lastCallAdd = $add;
146
-
147
-        return $result;
148
-    }
149
-
150
-    /**
151
-     * returns a single tag with auto indenting.
152
-     *
153
-     * @param string $tag content of the tag
154
-     * @param string $add additional data (anything before the following tag)
155
-     *
156
-     * @return string
157
-     */
158
-    protected static function singleTag($tag, $add, $whitespace)
159
-    {
160
-        $tabs = str_pad('', self::$tabCount, "\t");
161
-
162
-        // if it's img, br it's inline so it does not require a leading line break
163
-        // 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
164
-        if (preg_match('#^<(img|br|/textarea|/pre|/code)(?: [^>]*|)>#', $tag)) {
165
-            $result = $tag.$whitespace;
166
-
167
-            if (!empty($add)) {
168
-                $result .= str_replace("\n", "\n".$tabs, $add);
169
-            }
170
-        } else {
171
-            $result = "\n".$tabs.$tag;
172
-
173
-            if (!empty($add)) {
174
-                $result .= "\n".$tabs.str_replace("\n", "\n".$tabs, $add);
175
-            }
176
-        }
177
-
178
-        self::$lastCallAdd = $add;
179
-
180
-        return $result;
181
-    }
28
+	/**
29
+	 * tab count to auto-indent the source.
30
+	 *
31
+	 * @var int
32
+	 */
33
+	protected static $tabCount = -1;
34
+
35
+	/**
36
+	 * stores the additional data (following a tag) of the last call to open/close/singleTag.
37
+	 *
38
+	 * @var string
39
+	 */
40
+	protected static $lastCallAdd = '';
41
+
42
+	/**
43
+	 * formats the input using the singleTag/closeTag/openTag functions.
44
+	 *
45
+	 * It is auto indenting the whole code, excluding <textarea>, <code> and <pre> tags that must be kept intact.
46
+	 * Those tags must however contain only htmlentities-escaped text for everything to work properly.
47
+	 * Inline tags are presented on a single line with their content
48
+	 *
49
+	 * @param string $input the xhtml to format
50
+	 *
51
+	 * @return string formatted xhtml
52
+	 */
53
+	public function process($input)
54
+	{
55
+		self::$tabCount = -1;
56
+
57
+		// auto indent all but textareas & pre (or we have weird tabs inside)
58
+		$input = preg_replace_callback("#(<[^>]+>)(\s*)([^<]*)#", array('self', 'tagDispatcher'), $input);
59
+
60
+		return $input;
61
+	}
62
+
63
+	/**
64
+	 * helper function for format()'s preg_replace call.
65
+	 *
66
+	 * @param array $input array of matches (1=>tag, 2=>whitespace(optional), 3=>additional non-html content)
67
+	 *
68
+	 * @return string the indented tag
69
+	 */
70
+	protected static function tagDispatcher($input)
71
+	{
72
+		// 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
73
+		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[') {
74
+			return $input[1].$input[3];
75
+		}
76
+		// 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
77
+		if (substr($input[1], 0, 10) == '</textarea' || substr($input[1], 0, 5) == '</pre' || substr($input[1], 0, 6) == '</code' || substr($input[1], -2) == '/>') {
78
+			return self::singleTag($input[1], $input[3], $input[2]);
79
+		}
80
+		// it's the closing tag
81
+		if ($input[0][1] == '/') {
82
+			return self::closeTag($input[1], $input[3], $input[2]);
83
+		}
84
+		// opening tag
85
+		return self::openTag($input[1], $input[3], $input[2]);
86
+	}
87
+
88
+	/**
89
+	 * returns an open tag and adds a tab into the auto indenting.
90
+	 *
91
+	 * @param string $tag        content of the tag
92
+	 * @param string $add        additional data (anything before the following tag)
93
+	 * @param string $whitespace white space between the tag and the additional data
94
+	 *
95
+	 * @return string
96
+	 */
97
+	protected static function openTag($tag, $add, $whitespace)
98
+	{
99
+		$tabs = str_pad('', self::$tabCount++, "\t");
100
+
101
+		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)) {
102
+			// if it's one of those tag it's inline so it does not require a leading line break
103
+			$result = $tag.$whitespace.str_replace("\n", "\n".$tabs, $add);
104
+		} elseif (substr($tag, 0, 9) == '<!DOCTYPE') {
105
+			// it's the doctype declaration so no line break here either
106
+			$result = $tabs.$tag;
107
+		} else {
108
+			// normal block tag
109
+			$result = "\n".$tabs.$tag;
110
+
111
+			if (!empty($add)) {
112
+				$result .= "\n".$tabs."\t".str_replace("\n", "\n\t".$tabs, $add);
113
+			}
114
+		}
115
+
116
+		self::$lastCallAdd = $add;
117
+
118
+		return $result;
119
+	}
120
+
121
+	/**
122
+	 * returns a closing tag and removes a tab from the auto indenting.
123
+	 *
124
+	 * @param string $tag        content of the tag
125
+	 * @param string $add        additional data (anything before the following tag)
126
+	 * @param string $whitespace white space between the tag and the additional data
127
+	 *
128
+	 * @return string
129
+	 */
130
+	protected static function closeTag($tag, $add, $whitespace)
131
+	{
132
+		$tabs = str_pad('', --self::$tabCount, "\t");
133
+
134
+		// if it's one of those tag it's inline so it does not require a leading line break
135
+		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)) {
136
+			$result = $tag.$whitespace.str_replace("\n", "\n".$tabs, $add);
137
+		} else {
138
+			$result = "\n".$tabs.$tag;
139
+
140
+			if (!empty($add)) {
141
+				$result .= "\n".$tabs."\t".str_replace("\n", "\n\t".$tabs, $add);
142
+			}
143
+		}
144
+
145
+		self::$lastCallAdd = $add;
146
+
147
+		return $result;
148
+	}
149
+
150
+	/**
151
+	 * returns a single tag with auto indenting.
152
+	 *
153
+	 * @param string $tag content of the tag
154
+	 * @param string $add additional data (anything before the following tag)
155
+	 *
156
+	 * @return string
157
+	 */
158
+	protected static function singleTag($tag, $add, $whitespace)
159
+	{
160
+		$tabs = str_pad('', self::$tabCount, "\t");
161
+
162
+		// if it's img, br it's inline so it does not require a leading line break
163
+		// 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
164
+		if (preg_match('#^<(img|br|/textarea|/pre|/code)(?: [^>]*|)>#', $tag)) {
165
+			$result = $tag.$whitespace;
166
+
167
+			if (!empty($add)) {
168
+				$result .= str_replace("\n", "\n".$tabs, $add);
169
+			}
170
+		} else {
171
+			$result = "\n".$tabs.$tag;
172
+
173
+			if (!empty($add)) {
174
+				$result .= "\n".$tabs.str_replace("\n", "\n".$tabs, $add);
175
+			}
176
+		}
177
+
178
+		self::$lastCallAdd = $add;
179
+
180
+		return $result;
181
+	}
182 182
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/functions/whitespace.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,5 +32,5 @@
 block discarded – undo
32 32
  */
33 33
 function Dwoo_Plugin_whitespace_compile(Dwoo_Compiler $compiler, $value, $with = ' ')
34 34
 {
35
-    return "preg_replace('#\s+#'.(strcasecmp(\$this->charset, 'utf-8')===0?'u':''), $with, $value)";
35
+	return "preg_replace('#\s+#'.(strcasecmp(\$this->charset, 'utf-8')===0?'u':''), $with, $value)";
36 36
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/functions/strip_tags.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@
 block discarded – undo
22 22
  */
23 23
 function Dwoo_Plugin_strip_tags_compile(Dwoo_Compiler $compiler, $value, $addspace = true)
24 24
 {
25
-    if ($addspace === 'true') {
26
-        return "preg_replace('#<[^>]*>#', ' ', $value)";
27
-    } else {
28
-        return "strip_tags($value)";
29
-    }
25
+	if ($addspace === 'true') {
26
+		return "preg_replace('#<[^>]*>#', ' ', $value)";
27
+	} else {
28
+		return "strip_tags($value)";
29
+	}
30 30
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/functions/extends.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -21,18 +21,18 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Dwoo_Plugin_extends extends Dwoo_Plugin implements Dwoo_ICompilable
23 23
 {
24
-    protected static $childSource;
25
-    protected static $regex;
26
-    protected static $l;
27
-    protected static $r;
28
-    protected static $lastReplacement;
29
-
30
-    public static function compile(Dwoo_Compiler $compiler, $file)
31
-    {
32
-        list($l, $r) = $compiler->getDelimiters();
33
-        self::$l = preg_quote($l, '/');
34
-        self::$r = preg_quote($r, '/');
35
-        self::$regex = '/
24
+	protected static $childSource;
25
+	protected static $regex;
26
+	protected static $l;
27
+	protected static $r;
28
+	protected static $lastReplacement;
29
+
30
+	public static function compile(Dwoo_Compiler $compiler, $file)
31
+	{
32
+		list($l, $r) = $compiler->getDelimiters();
33
+		self::$l = preg_quote($l, '/');
34
+		self::$r = preg_quote($r, '/');
35
+		self::$regex = '/
36 36
 			'.self::$l.'block\s(["\']?)(.+?)\1'.self::$r.'(?:\r?\n?)
37 37
 			((?:
38 38
 				(?R)
@@ -47,118 +47,118 @@  discard block
 block discarded – undo
47 47
 			'.self::$l.'\/block'.self::$r.'
48 48
 			/six';
49 49
 
50
-        if ($compiler->getLooseOpeningHandling()) {
51
-            self::$l .= '\s*';
52
-            self::$r = '\s*'.self::$r;
53
-        }
54
-        $inheritanceTree = array(array('source' => $compiler->getTemplateSource()));
55
-        $curPath = dirname($compiler->getDwoo()->getTemplate()->getResourceIdentifier()).DIRECTORY_SEPARATOR;
56
-        $curTpl = $compiler->getDwoo()->getTemplate();
57
-
58
-        while (!empty($file)) {
59
-            if ($file === '""' || $file === "''" || (substr($file, 0, 1) !== '"' && substr($file, 0, 1) !== '\'')) {
60
-                throw new Dwoo_Compilation_Exception($compiler, 'Extends : The file name must be a non-empty string');
61
-            }
62
-
63
-            if (preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m)) {
64
-                // resource:identifier given, extract them
65
-                $resource = $m[1];
66
-                $identifier = $m[2];
67
-            } else {
68
-                // get the current template's resource
69
-                $resource = $curTpl->getResourceName();
70
-                $identifier = substr($file, 1, -1);
71
-            }
72
-
73
-            try {
74
-                $parent = $compiler->getDwoo()->templateFactory($resource, $identifier, null, null, null, $curTpl);
75
-            } catch (Dwoo_Security_Exception $e) {
76
-                throw new Dwoo_Compilation_Exception($compiler, 'Extends : Security restriction : '.$e->getMessage());
77
-            } catch (Dwoo_Exception $e) {
78
-                throw new Dwoo_Compilation_Exception($compiler, 'Extends : '.$e->getMessage());
79
-            }
80
-
81
-            if ($parent === null) {
82
-                throw new Dwoo_Compilation_Exception($compiler, 'Extends : Resource "'.$resource.':'.$identifier.'" not found.');
83
-            } elseif ($parent === false) {
84
-                throw new Dwoo_Compilation_Exception($compiler, 'Extends : Resource "'.$resource.'" does not support extends.');
85
-            }
86
-
87
-            $curTpl = $parent;
88
-            $newParent = array('source' => $parent->getSource(), 'resource' => $resource, 'identifier' => $parent->getResourceIdentifier(), 'uid' => $parent->getUid());
89
-            if (array_search($newParent, $inheritanceTree, true) !== false) {
90
-                throw new Dwoo_Compilation_Exception($compiler, 'Extends : Recursive template inheritance detected');
91
-            }
92
-            $inheritanceTree[] = $newParent;
93
-
94
-            if (preg_match('/^'.self::$l.'extends(?:\(?\s*|\s+)(?:file=)?\s*((["\']).+?\2|\S+?)\s*\)?\s*?'.self::$r.'/i', $parent->getSource(), $match)) {
95
-                $curPath = dirname($identifier).DIRECTORY_SEPARATOR;
96
-                if (isset($match[2]) && $match[2] == '"') {
97
-                    $file = '"'.str_replace('"', '\\"', substr($match[1], 1, -1)).'"';
98
-                } elseif (isset($match[2]) && $match[2] == "'") {
99
-                    $file = '"'.substr($match[1], 1, -1).'"';
100
-                } else {
101
-                    $file = '"'.$match[1].'"';
102
-                }
103
-            } else {
104
-                $file = false;
105
-            }
106
-        }
107
-
108
-        while (true) {
109
-            $parent = array_pop($inheritanceTree);
110
-            $child = end($inheritanceTree);
111
-            self::$childSource = $child['source'];
112
-            self::$lastReplacement = count($inheritanceTree) === 1;
113
-            if (!isset($newSource)) {
114
-                $newSource = $parent['source'];
115
-            }
116
-            $newSource = preg_replace_callback(self::$regex, array('Dwoo_Plugin_extends', 'replaceBlock'), $newSource);
117
-            $newSource = $l.'do extendsCheck('.var_export($parent['resource'].':'.$parent['identifier'], true).')'.$r.$newSource;
118
-
119
-            if (self::$lastReplacement) {
120
-                break;
121
-            }
122
-        }
123
-        $compiler->setTemplateSource($newSource);
124
-        $compiler->recompile();
125
-    }
126
-
127
-    protected static function replaceBlock(array $matches)
128
-    {
129
-        $matches[3] = self::removeTrailingNewline($matches[3]);
130
-
131
-        if (preg_match_all(self::$regex, self::$childSource, $override) && in_array($matches[2], $override[2])) {
132
-            $key = array_search($matches[2], $override[2]);
133
-            $override = self::removeTrailingNewline($override[3][$key]);
134
-
135
-            $l = stripslashes(self::$l);
136
-            $r = stripslashes(self::$r);
137
-
138
-            if (self::$lastReplacement) {
139
-                return preg_replace('/'.self::$l.'\$dwoo\.parent'.self::$r.'/is', $matches[3], $override);
140
-            }
141
-
142
-            return $l.'block '.$matches[1].$matches[2].$matches[1].$r.preg_replace('/'.self::$l.'\$dwoo\.parent'.self::$r.'/is', $matches[3], $override).$l.'/block'.$r;
143
-        }
144
-
145
-        if (preg_match(self::$regex, $matches[3])) {
146
-            return preg_replace_callback(self::$regex, array('Dwoo_Plugin_extends', 'replaceBlock'), $matches[3]);
147
-        }
148
-
149
-        if (self::$lastReplacement) {
150
-            return $matches[3];
151
-        }
152
-
153
-        return  $matches[0];
154
-    }
155
-
156
-    protected static function removeTrailingNewline($text)
157
-    {
158
-        return substr($text, -1) === "\n"
159
-                ? substr($text, -2, 1) === "\r"
160
-                    ? substr($text, 0, -2)
161
-                    : substr($text, 0, -1)
162
-                : $text;
163
-    }
50
+		if ($compiler->getLooseOpeningHandling()) {
51
+			self::$l .= '\s*';
52
+			self::$r = '\s*'.self::$r;
53
+		}
54
+		$inheritanceTree = array(array('source' => $compiler->getTemplateSource()));
55
+		$curPath = dirname($compiler->getDwoo()->getTemplate()->getResourceIdentifier()).DIRECTORY_SEPARATOR;
56
+		$curTpl = $compiler->getDwoo()->getTemplate();
57
+
58
+		while (!empty($file)) {
59
+			if ($file === '""' || $file === "''" || (substr($file, 0, 1) !== '"' && substr($file, 0, 1) !== '\'')) {
60
+				throw new Dwoo_Compilation_Exception($compiler, 'Extends : The file name must be a non-empty string');
61
+			}
62
+
63
+			if (preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m)) {
64
+				// resource:identifier given, extract them
65
+				$resource = $m[1];
66
+				$identifier = $m[2];
67
+			} else {
68
+				// get the current template's resource
69
+				$resource = $curTpl->getResourceName();
70
+				$identifier = substr($file, 1, -1);
71
+			}
72
+
73
+			try {
74
+				$parent = $compiler->getDwoo()->templateFactory($resource, $identifier, null, null, null, $curTpl);
75
+			} catch (Dwoo_Security_Exception $e) {
76
+				throw new Dwoo_Compilation_Exception($compiler, 'Extends : Security restriction : '.$e->getMessage());
77
+			} catch (Dwoo_Exception $e) {
78
+				throw new Dwoo_Compilation_Exception($compiler, 'Extends : '.$e->getMessage());
79
+			}
80
+
81
+			if ($parent === null) {
82
+				throw new Dwoo_Compilation_Exception($compiler, 'Extends : Resource "'.$resource.':'.$identifier.'" not found.');
83
+			} elseif ($parent === false) {
84
+				throw new Dwoo_Compilation_Exception($compiler, 'Extends : Resource "'.$resource.'" does not support extends.');
85
+			}
86
+
87
+			$curTpl = $parent;
88
+			$newParent = array('source' => $parent->getSource(), 'resource' => $resource, 'identifier' => $parent->getResourceIdentifier(), 'uid' => $parent->getUid());
89
+			if (array_search($newParent, $inheritanceTree, true) !== false) {
90
+				throw new Dwoo_Compilation_Exception($compiler, 'Extends : Recursive template inheritance detected');
91
+			}
92
+			$inheritanceTree[] = $newParent;
93
+
94
+			if (preg_match('/^'.self::$l.'extends(?:\(?\s*|\s+)(?:file=)?\s*((["\']).+?\2|\S+?)\s*\)?\s*?'.self::$r.'/i', $parent->getSource(), $match)) {
95
+				$curPath = dirname($identifier).DIRECTORY_SEPARATOR;
96
+				if (isset($match[2]) && $match[2] == '"') {
97
+					$file = '"'.str_replace('"', '\\"', substr($match[1], 1, -1)).'"';
98
+				} elseif (isset($match[2]) && $match[2] == "'") {
99
+					$file = '"'.substr($match[1], 1, -1).'"';
100
+				} else {
101
+					$file = '"'.$match[1].'"';
102
+				}
103
+			} else {
104
+				$file = false;
105
+			}
106
+		}
107
+
108
+		while (true) {
109
+			$parent = array_pop($inheritanceTree);
110
+			$child = end($inheritanceTree);
111
+			self::$childSource = $child['source'];
112
+			self::$lastReplacement = count($inheritanceTree) === 1;
113
+			if (!isset($newSource)) {
114
+				$newSource = $parent['source'];
115
+			}
116
+			$newSource = preg_replace_callback(self::$regex, array('Dwoo_Plugin_extends', 'replaceBlock'), $newSource);
117
+			$newSource = $l.'do extendsCheck('.var_export($parent['resource'].':'.$parent['identifier'], true).')'.$r.$newSource;
118
+
119
+			if (self::$lastReplacement) {
120
+				break;
121
+			}
122
+		}
123
+		$compiler->setTemplateSource($newSource);
124
+		$compiler->recompile();
125
+	}
126
+
127
+	protected static function replaceBlock(array $matches)
128
+	{
129
+		$matches[3] = self::removeTrailingNewline($matches[3]);
130
+
131
+		if (preg_match_all(self::$regex, self::$childSource, $override) && in_array($matches[2], $override[2])) {
132
+			$key = array_search($matches[2], $override[2]);
133
+			$override = self::removeTrailingNewline($override[3][$key]);
134
+
135
+			$l = stripslashes(self::$l);
136
+			$r = stripslashes(self::$r);
137
+
138
+			if (self::$lastReplacement) {
139
+				return preg_replace('/'.self::$l.'\$dwoo\.parent'.self::$r.'/is', $matches[3], $override);
140
+			}
141
+
142
+			return $l.'block '.$matches[1].$matches[2].$matches[1].$r.preg_replace('/'.self::$l.'\$dwoo\.parent'.self::$r.'/is', $matches[3], $override).$l.'/block'.$r;
143
+		}
144
+
145
+		if (preg_match(self::$regex, $matches[3])) {
146
+			return preg_replace_callback(self::$regex, array('Dwoo_Plugin_extends', 'replaceBlock'), $matches[3]);
147
+		}
148
+
149
+		if (self::$lastReplacement) {
150
+			return $matches[3];
151
+		}
152
+
153
+		return  $matches[0];
154
+	}
155
+
156
+	protected static function removeTrailingNewline($text)
157
+	{
158
+		return substr($text, -1) === "\n"
159
+				? substr($text, -2, 1) === "\r"
160
+					? substr($text, 0, -2)
161
+					: substr($text, 0, -1)
162
+				: $text;
163
+	}
164 164
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/functions/count_characters.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@
 block discarded – undo
22 22
  */
23 23
 function Dwoo_Plugin_count_characters_compile(Dwoo_Compiler $compiler, $value, $count_spaces = false)
24 24
 {
25
-    if ($count_spaces === 'false') {
26
-        return 'preg_match_all(\'#[^\s\pZ]#u\', '.$value.', $tmp)';
27
-    } else {
28
-        return 'mb_strlen('.$value.', $this->charset)';
29
-    }
25
+	if ($count_spaces === 'false') {
26
+		return 'preg_match_all(\'#[^\s\pZ]#u\', '.$value.', $tmp)';
27
+	} else {
28
+		return 'mb_strlen('.$value.', $this->charset)';
29
+	}
30 30
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/functions/nl2br.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,5 +21,5 @@
 block discarded – undo
21 21
  */
22 22
 function Dwoo_Plugin_nl2br_compile(Dwoo_Compiler $compiler, $value)
23 23
 {
24
-    return 'nl2br((string) '.$value.')';
24
+	return 'nl2br((string) '.$value.')';
25 25
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/functions/indent.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,5 +23,5 @@
 block discarded – undo
23 23
  */
24 24
 function Dwoo_Plugin_indent_compile(Dwoo_Compiler $compiler, $value, $by = 4, $char = ' ')
25 25
 {
26
-    return "preg_replace('#^#m', '".str_repeat(substr($char, 1, -1), trim($by, '"\''))."', $value)";
26
+	return "preg_replace('#^#m', '".str_repeat(substr($char, 1, -1), trim($by, '"\''))."', $value)";
27 27
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/functions/cycle.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -27,45 +27,45 @@
 block discarded – undo
27 27
  */
28 28
 class Dwoo_Plugin_cycle extends Dwoo_Plugin
29 29
 {
30
-    protected $cycles = array();
30
+	protected $cycles = array();
31 31
 
32
-    public function process($name = 'default', $values = null, $print = true, $advance = true, $delimiter = ',', $assign = null, $reset = false)
33
-    {
34
-        if ($values !== null) {
35
-            if (is_string($values)) {
36
-                $values = explode($delimiter, $values);
37
-            }
32
+	public function process($name = 'default', $values = null, $print = true, $advance = true, $delimiter = ',', $assign = null, $reset = false)
33
+	{
34
+		if ($values !== null) {
35
+			if (is_string($values)) {
36
+				$values = explode($delimiter, $values);
37
+			}
38 38
 
39
-            if (!isset($this->cycles[$name]) || $this->cycles[$name]['values'] !== $values) {
40
-                $this->cycles[$name]['index'] = 0;
41
-            }
39
+			if (!isset($this->cycles[$name]) || $this->cycles[$name]['values'] !== $values) {
40
+				$this->cycles[$name]['index'] = 0;
41
+			}
42 42
 
43
-            $this->cycles[$name]['values'] = array_values($values);
44
-        } elseif (isset($this->cycles[$name])) {
45
-            $values = $this->cycles[$name]['values'];
46
-        }
43
+			$this->cycles[$name]['values'] = array_values($values);
44
+		} elseif (isset($this->cycles[$name])) {
45
+			$values = $this->cycles[$name]['values'];
46
+		}
47 47
 
48
-        if ($reset) {
49
-            $this->cycles[$name]['index'] = 0;
50
-        }
48
+		if ($reset) {
49
+			$this->cycles[$name]['index'] = 0;
50
+		}
51 51
 
52
-        if ($print) {
53
-            $out = $values[$this->cycles[$name]['index']];
54
-        } else {
55
-            $out = null;
56
-        }
52
+		if ($print) {
53
+			$out = $values[$this->cycles[$name]['index']];
54
+		} else {
55
+			$out = null;
56
+		}
57 57
 
58
-        if ($advance) {
59
-            if ($this->cycles[$name]['index'] >= count($values) - 1) {
60
-                $this->cycles[$name]['index'] = 0;
61
-            } else {
62
-                ++$this->cycles[$name]['index'];
63
-            }
64
-        }
58
+		if ($advance) {
59
+			if ($this->cycles[$name]['index'] >= count($values) - 1) {
60
+				$this->cycles[$name]['index'] = 0;
61
+			} else {
62
+				++$this->cycles[$name]['index'];
63
+			}
64
+		}
65 65
 
66
-        if ($assign === null) {
67
-            return $out;
68
-        }
69
-        $this->dwoo->assignInScope($out, $assign);
70
-    }
66
+		if ($assign === null) {
67
+			return $out;
68
+		}
69
+		$this->dwoo->assignInScope($out, $assign);
70
+	}
71 71
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
         }
57 57
 
58 58
         if ($advance) {
59
-            if ($this->cycles[$name]['index'] >= count($values) - 1) {
59
+            if ($this->cycles[$name]['index'] >= count($values)-1) {
60 60
                 $this->cycles[$name]['index'] = 0;
61 61
             } else {
62 62
                 ++$this->cycles[$name]['index'];
Please login to merge, or discard this patch.