Test Failed
Pull Request — 1.2 (#90)
by
unknown
02:45
created
lib/plugins/builtin/blocks/dynamic.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -19,57 +19,57 @@
 block discarded – undo
19 19
  */
20 20
 class Dwoo_Plugin_dynamic extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
21 21
 {
22
-    public function init()
23
-    {
24
-    }
22
+	public function init()
23
+	{
24
+	}
25 25
 
26
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
27
-    {
28
-        return '';
29
-    }
26
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
27
+	{
28
+		return '';
29
+	}
30 30
 
31
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
32
-    {
33
-        try {
34
-            $compiler->findBlock('dynamic');
31
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
32
+	{
33
+		try {
34
+			$compiler->findBlock('dynamic');
35 35
 
36
-            return $content;
37
-        } catch (Dwoo_Compilation_Exception $e) {
38
-        }
39
-        $output = Dwoo_Compiler::PHP_OPEN.
40
-            'if($doCache) {'."\n\t".
41
-                'echo \'<dwoo:dynamic_\'.$dynamicId.\'>'.
42
-                str_replace('\'', '\\\'', $content).
43
-                '</dwoo:dynamic_\'.$dynamicId.\'>\';'.
44
-            "\n} else {\n\t";
45
-        if (substr($content, 0, strlen(Dwoo_Compiler::PHP_OPEN)) == Dwoo_Compiler::PHP_OPEN) {
46
-            $output .= substr($content, strlen(Dwoo_Compiler::PHP_OPEN));
47
-        } else {
48
-            $output .= Dwoo_Compiler::PHP_CLOSE.$content;
49
-        }
50
-        if (substr($output, -strlen(Dwoo_Compiler::PHP_CLOSE)) == Dwoo_Compiler::PHP_CLOSE) {
51
-            $output = substr($output, 0, -strlen(Dwoo_Compiler::PHP_CLOSE));
52
-        } else {
53
-            $output .= Dwoo_Compiler::PHP_OPEN;
54
-        }
55
-        $output .= "\n}".Dwoo_Compiler::PHP_CLOSE;
36
+			return $content;
37
+		} catch (Dwoo_Compilation_Exception $e) {
38
+		}
39
+		$output = Dwoo_Compiler::PHP_OPEN.
40
+			'if($doCache) {'."\n\t".
41
+				'echo \'<dwoo:dynamic_\'.$dynamicId.\'>'.
42
+				str_replace('\'', '\\\'', $content).
43
+				'</dwoo:dynamic_\'.$dynamicId.\'>\';'.
44
+			"\n} else {\n\t";
45
+		if (substr($content, 0, strlen(Dwoo_Compiler::PHP_OPEN)) == Dwoo_Compiler::PHP_OPEN) {
46
+			$output .= substr($content, strlen(Dwoo_Compiler::PHP_OPEN));
47
+		} else {
48
+			$output .= Dwoo_Compiler::PHP_CLOSE.$content;
49
+		}
50
+		if (substr($output, -strlen(Dwoo_Compiler::PHP_CLOSE)) == Dwoo_Compiler::PHP_CLOSE) {
51
+			$output = substr($output, 0, -strlen(Dwoo_Compiler::PHP_CLOSE));
52
+		} else {
53
+			$output .= Dwoo_Compiler::PHP_OPEN;
54
+		}
55
+		$output .= "\n}".Dwoo_Compiler::PHP_CLOSE;
56 56
 
57
-        return $output;
58
-    }
57
+		return $output;
58
+	}
59 59
 
60
-    public static function unescape($output, $dynamicId, $compiledFile)
61
-    {
62
-        $output = preg_replace_callback('/<dwoo:dynamic_('.$dynamicId.')>(.+?)<\/dwoo:dynamic_'.$dynamicId.'>/s', array('self', 'unescapePhp'), $output, -1, $count);
63
-        // re-add the includes on top of the file
64
-        if ($count && preg_match('#/\* template head \*/(.+?)/\* end template head \*/#s', file_get_contents($compiledFile), $m)) {
65
-            $output = '<?php '.$m[1].' ?>'.$output;
66
-        }
60
+	public static function unescape($output, $dynamicId, $compiledFile)
61
+	{
62
+		$output = preg_replace_callback('/<dwoo:dynamic_('.$dynamicId.')>(.+?)<\/dwoo:dynamic_'.$dynamicId.'>/s', array('self', 'unescapePhp'), $output, -1, $count);
63
+		// re-add the includes on top of the file
64
+		if ($count && preg_match('#/\* template head \*/(.+?)/\* end template head \*/#s', file_get_contents($compiledFile), $m)) {
65
+			$output = '<?php '.$m[1].' ?>'.$output;
66
+		}
67 67
 
68
-        return $output;
69
-    }
68
+		return $output;
69
+	}
70 70
 
71
-    public static function unescapePhp($match)
72
-    {
73
-        return preg_replace('{<\?php /\*'.$match[1].'\*/ echo \'(.+?)\'; \?>}s', '$1', $match[2]);
74
-    }
71
+	public static function unescapePhp($match)
72
+	{
73
+		return preg_replace('{<\?php /\*'.$match[1].'\*/ echo \'(.+?)\'; \?>}s', '$1', $match[2]);
74
+	}
75 75
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/forelse.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -19,29 +19,29 @@
 block discarded – undo
19 19
  */
20 20
 class Dwoo_Plugin_forelse extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
21 21
 {
22
-    public function init()
23
-    {
24
-    }
22
+	public function init()
23
+	{
24
+	}
25 25
 
26
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
27
-    {
28
-        $with = &$compiler->findBlock('for', true);
26
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
27
+	{
28
+		$with = &$compiler->findBlock('for', true);
29 29
 
30
-        $params['initialized'] = true;
31
-        $compiler->injectBlock($type, $params);
30
+		$params['initialized'] = true;
31
+		$compiler->injectBlock($type, $params);
32 32
 
33
-        return '';
34
-    }
33
+		return '';
34
+	}
35 35
 
36
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
37
-    {
38
-        if (!isset($params['initialized'])) {
39
-            return '';
40
-        }
36
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
37
+	{
38
+		if (!isset($params['initialized'])) {
39
+			return '';
40
+		}
41 41
 
42
-        $block = &$compiler->getCurrentBlock();
43
-        $block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE;
42
+		$block = &$compiler->getCurrentBlock();
43
+		$block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE;
44 44
 
45
-        return '';
46
-    }
45
+		return '';
46
+	}
47 47
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/topLevelBlock.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -19,17 +19,17 @@
 block discarded – undo
19 19
  */
20 20
 final class Dwoo_Plugin_topLevelBlock extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
21 21
 {
22
-    public function init()
23
-    {
24
-    }
22
+	public function init()
23
+	{
24
+	}
25 25
 
26
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
27
-    {
28
-        return '/* end template head */ ob_start(); /* template body */ '.Dwoo_Compiler::PHP_CLOSE;
29
-    }
26
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
27
+	{
28
+		return '/* end template head */ ob_start(); /* template body */ '.Dwoo_Compiler::PHP_CLOSE;
29
+	}
30 30
 
31
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
32
-    {
33
-        return $content.Dwoo_Compiler::PHP_OPEN.' /* end template body */'."\n".'return $this->buffer . ob_get_clean();';
34
-    }
31
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
32
+	{
33
+		return $content.Dwoo_Compiler::PHP_OPEN.' /* end template body */'."\n".'return $this->buffer . ob_get_clean();';
34
+	}
35 35
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/foreachelse.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -19,29 +19,29 @@
 block discarded – undo
19 19
  */
20 20
 class Dwoo_Plugin_foreachelse extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
21 21
 {
22
-    public function init()
23
-    {
24
-    }
22
+	public function init()
23
+	{
24
+	}
25 25
 
26
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
27
-    {
28
-        $with = &$compiler->findBlock('foreach', true);
26
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
27
+	{
28
+		$with = &$compiler->findBlock('foreach', true);
29 29
 
30
-        $params['initialized'] = true;
31
-        $compiler->injectBlock($type, $params);
30
+		$params['initialized'] = true;
31
+		$compiler->injectBlock($type, $params);
32 32
 
33
-        return '';
34
-    }
33
+		return '';
34
+	}
35 35
 
36
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
37
-    {
38
-        if (!isset($params['initialized'])) {
39
-            return '';
40
-        }
36
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
37
+	{
38
+		if (!isset($params['initialized'])) {
39
+			return '';
40
+		}
41 41
 
42
-        $block = &$compiler->getCurrentBlock();
43
-        $block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE;
42
+		$block = &$compiler->getCurrentBlock();
43
+		$block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE;
44 44
 
45
-        return '';
46
-    }
45
+		return '';
46
+	}
47 47
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/block.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -21,17 +21,17 @@
 block discarded – undo
21 21
  */
22 22
 class Dwoo_Plugin_block extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
23 23
 {
24
-    public function init($name = '')
25
-    {
26
-    }
24
+	public function init($name = '')
25
+	{
26
+	}
27 27
 
28
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
29
-    {
30
-        return '';
31
-    }
28
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
29
+	{
30
+		return '';
31
+	}
32 32
 
33
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
34
-    {
35
-        return $content;
36
-    }
33
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
34
+	{
35
+		return $content;
36
+	}
37 37
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/with.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -43,36 +43,36 @@
 block discarded – undo
43 43
  */
44 44
 class Dwoo_Plugin_with extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block, Dwoo_IElseable
45 45
 {
46
-    protected static $cnt = 0;
46
+	protected static $cnt = 0;
47 47
 
48
-    public function init($var)
49
-    {
50
-    }
48
+	public function init($var)
49
+	{
50
+	}
51 51
 
52
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
53
-    {
54
-        return '';
55
-    }
52
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
53
+	{
54
+		return '';
55
+	}
56 56
 
57
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
58
-    {
59
-        $rparams = $compiler->getRealParams($params);
60
-        $cparams = $compiler->getCompiledParams($params);
57
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
58
+	{
59
+		$rparams = $compiler->getRealParams($params);
60
+		$cparams = $compiler->getCompiledParams($params);
61 61
 
62
-        $compiler->setScope($rparams['var']);
62
+		$compiler->setScope($rparams['var']);
63 63
 
64
-        $pre = Dwoo_Compiler::PHP_OPEN.'if ('.$cparams['var'].')'."\n{\n".
65
-            '$_with'.(self::$cnt).' = $this->setScope("'.$rparams['var'].'");'.
66
-            "\n/* -- start with output */\n".Dwoo_Compiler::PHP_CLOSE;
64
+		$pre = Dwoo_Compiler::PHP_OPEN.'if ('.$cparams['var'].')'."\n{\n".
65
+			'$_with'.(self::$cnt).' = $this->setScope("'.$rparams['var'].'");'.
66
+			"\n/* -- start with output */\n".Dwoo_Compiler::PHP_CLOSE;
67 67
 
68
-        $post = Dwoo_Compiler::PHP_OPEN."\n/* -- end with output */\n".
69
-            '$this->setScope($_with'.(self::$cnt++).', true);'.
70
-            "\n}\n".Dwoo_Compiler::PHP_CLOSE;
68
+		$post = Dwoo_Compiler::PHP_OPEN."\n/* -- end with output */\n".
69
+			'$this->setScope($_with'.(self::$cnt++).', true);'.
70
+			"\n}\n".Dwoo_Compiler::PHP_CLOSE;
71 71
 
72
-        if (isset($params['hasElse'])) {
73
-            $post .= $params['hasElse'];
74
-        }
72
+		if (isset($params['hasElse'])) {
73
+			$post .= $params['hasElse'];
74
+		}
75 75
 
76
-        return $pre.$content.$post;
77
-    }
76
+		return $pre.$content.$post;
77
+	}
78 78
 }
Please login to merge, or discard this patch.
lib/plugins/builtin/blocks/withelse.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -19,29 +19,29 @@
 block discarded – undo
19 19
  */
20 20
 class Dwoo_Plugin_withelse extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
21 21
 {
22
-    public function init()
23
-    {
24
-    }
22
+	public function init()
23
+	{
24
+	}
25 25
 
26
-    public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
27
-    {
28
-        $with = &$compiler->findBlock('with', true);
26
+	public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
27
+	{
28
+		$with = &$compiler->findBlock('with', true);
29 29
 
30
-        $params['initialized'] = true;
31
-        $compiler->injectBlock($type, $params);
30
+		$params['initialized'] = true;
31
+		$compiler->injectBlock($type, $params);
32 32
 
33
-        return '';
34
-    }
33
+		return '';
34
+	}
35 35
 
36
-    public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
37
-    {
38
-        if (!isset($params['initialized'])) {
39
-            return '';
40
-        }
36
+	public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
37
+	{
38
+		if (!isset($params['initialized'])) {
39
+			return '';
40
+		}
41 41
 
42
-        $block = &$compiler->getCurrentBlock();
43
-        $block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE;
42
+		$block = &$compiler->getCurrentBlock();
43
+		$block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN."else {\n".Dwoo_Compiler::PHP_CLOSE.$content.Dwoo_Compiler::PHP_OPEN."\n}".Dwoo_Compiler::PHP_CLOSE;
44 44
 
45
-        return '';
46
-    }
45
+		return '';
46
+	}
47 47
 }
Please login to merge, or discard this patch.
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.