GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b130b6...8a2f54 )
by gyeong-won
07:36
created
htmlpurifier/library/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -7,37 +7,37 @@
 block discarded – undo
7 7
 class HTMLPurifier_ConfigSchema_Builder_ConfigSchema
8 8
 {
9 9
 
10
-    public function build($interchange) {
11
-        $schema = new HTMLPurifier_ConfigSchema();
12
-        foreach ($interchange->directives as $d) {
13
-            $schema->add(
14
-                $d->id->key,
15
-                $d->default,
16
-                $d->type,
17
-                $d->typeAllowsNull
18
-            );
19
-            if ($d->allowed !== null) {
20
-                $schema->addAllowedValues(
21
-                    $d->id->key,
22
-                    $d->allowed
23
-                );
24
-            }
25
-            foreach ($d->aliases as $alias) {
26
-                $schema->addAlias(
27
-                    $alias->key,
28
-                    $d->id->key
29
-                );
30
-            }
31
-            if ($d->valueAliases !== null) {
32
-                $schema->addValueAliases(
33
-                    $d->id->key,
34
-                    $d->valueAliases
35
-                );
36
-            }
37
-        }
38
-        $schema->postProcess();
39
-        return $schema;
40
-    }
10
+	public function build($interchange) {
11
+		$schema = new HTMLPurifier_ConfigSchema();
12
+		foreach ($interchange->directives as $d) {
13
+			$schema->add(
14
+				$d->id->key,
15
+				$d->default,
16
+				$d->type,
17
+				$d->typeAllowsNull
18
+			);
19
+			if ($d->allowed !== null) {
20
+				$schema->addAllowedValues(
21
+					$d->id->key,
22
+					$d->allowed
23
+				);
24
+			}
25
+			foreach ($d->aliases as $alias) {
26
+				$schema->addAlias(
27
+					$alias->key,
28
+					$d->id->key
29
+				);
30
+			}
31
+			if ($d->valueAliases !== null) {
32
+				$schema->addValueAliases(
33
+					$d->id->key,
34
+					$d->valueAliases
35
+				);
36
+			}
37
+		}
38
+		$schema->postProcess();
39
+		return $schema;
40
+	}
41 41
 
42 42
 }
43 43
 
Please login to merge, or discard this patch.
security/htmlpurifier/library/HTMLPurifier/ConfigSchema/Builder/Xml.php 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -7,99 +7,99 @@
 block discarded – undo
7 7
 class HTMLPurifier_ConfigSchema_Builder_Xml extends XMLWriter
8 8
 {
9 9
 
10
-    protected $interchange;
11
-    private $namespace;
12
-
13
-    protected function writeHTMLDiv($html) {
14
-        $this->startElement('div');
15
-
16
-        $purifier = HTMLPurifier::getInstance();
17
-        $html = $purifier->purify($html);
18
-        $this->writeAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
19
-        $this->writeRaw($html);
20
-
21
-        $this->endElement(); // div
22
-    }
23
-
24
-    protected function export($var) {
25
-        if ($var === array()) return 'array()';
26
-        return var_export($var, true);
27
-    }
28
-
29
-    public function build($interchange) {
30
-        // global access, only use as last resort
31
-        $this->interchange = $interchange;
32
-
33
-        $this->setIndent(true);
34
-        $this->startDocument('1.0', 'UTF-8');
35
-        $this->startElement('configdoc');
36
-        $this->writeElement('title', $interchange->name);
37
-
38
-        foreach ($interchange->directives as $directive) {
39
-            $this->buildDirective($directive);
40
-        }
41
-
42
-        if ($this->namespace) $this->endElement(); // namespace
43
-
44
-        $this->endElement(); // configdoc
45
-        $this->flush();
46
-    }
47
-
48
-    public function buildDirective($directive) {
49
-
50
-        // Kludge, although I suppose having a notion of a "root namespace"
51
-        // certainly makes things look nicer when documentation is built.
52
-        // Depends on things being sorted.
53
-        if (!$this->namespace || $this->namespace !== $directive->id->getRootNamespace()) {
54
-            if ($this->namespace) $this->endElement(); // namespace
55
-            $this->namespace = $directive->id->getRootNamespace();
56
-            $this->startElement('namespace');
57
-            $this->writeAttribute('id', $this->namespace);
58
-            $this->writeElement('name', $this->namespace);
59
-        }
60
-
61
-        $this->startElement('directive');
62
-        $this->writeAttribute('id', $directive->id->toString());
63
-
64
-        $this->writeElement('name', $directive->id->getDirective());
65
-
66
-        $this->startElement('aliases');
67
-            foreach ($directive->aliases as $alias) $this->writeElement('alias', $alias->toString());
68
-        $this->endElement(); // aliases
69
-
70
-        $this->startElement('constraints');
71
-            if ($directive->version) $this->writeElement('version', $directive->version);
72
-            $this->startElement('type');
73
-                if ($directive->typeAllowsNull) $this->writeAttribute('allow-null', 'yes');
74
-                $this->text($directive->type);
75
-            $this->endElement(); // type
76
-            if ($directive->allowed) {
77
-                $this->startElement('allowed');
78
-                    foreach ($directive->allowed as $value => $x) $this->writeElement('value', $value);
79
-                $this->endElement(); // allowed
80
-            }
81
-            $this->writeElement('default', $this->export($directive->default));
82
-            $this->writeAttribute('xml:space', 'preserve');
83
-            if ($directive->external) {
84
-                $this->startElement('external');
85
-                    foreach ($directive->external as $project) $this->writeElement('project', $project);
86
-                $this->endElement();
87
-            }
88
-        $this->endElement(); // constraints
89
-
90
-        if ($directive->deprecatedVersion) {
91
-            $this->startElement('deprecated');
92
-                $this->writeElement('version', $directive->deprecatedVersion);
93
-                $this->writeElement('use', $directive->deprecatedUse->toString());
94
-            $this->endElement(); // deprecated
95
-        }
96
-
97
-        $this->startElement('description');
98
-            $this->writeHTMLDiv($directive->description);
99
-        $this->endElement(); // description
100
-
101
-        $this->endElement(); // directive
102
-    }
10
+	protected $interchange;
11
+	private $namespace;
12
+
13
+	protected function writeHTMLDiv($html) {
14
+		$this->startElement('div');
15
+
16
+		$purifier = HTMLPurifier::getInstance();
17
+		$html = $purifier->purify($html);
18
+		$this->writeAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
19
+		$this->writeRaw($html);
20
+
21
+		$this->endElement(); // div
22
+	}
23
+
24
+	protected function export($var) {
25
+		if ($var === array()) return 'array()';
26
+		return var_export($var, true);
27
+	}
28
+
29
+	public function build($interchange) {
30
+		// global access, only use as last resort
31
+		$this->interchange = $interchange;
32
+
33
+		$this->setIndent(true);
34
+		$this->startDocument('1.0', 'UTF-8');
35
+		$this->startElement('configdoc');
36
+		$this->writeElement('title', $interchange->name);
37
+
38
+		foreach ($interchange->directives as $directive) {
39
+			$this->buildDirective($directive);
40
+		}
41
+
42
+		if ($this->namespace) $this->endElement(); // namespace
43
+
44
+		$this->endElement(); // configdoc
45
+		$this->flush();
46
+	}
47
+
48
+	public function buildDirective($directive) {
49
+
50
+		// Kludge, although I suppose having a notion of a "root namespace"
51
+		// certainly makes things look nicer when documentation is built.
52
+		// Depends on things being sorted.
53
+		if (!$this->namespace || $this->namespace !== $directive->id->getRootNamespace()) {
54
+			if ($this->namespace) $this->endElement(); // namespace
55
+			$this->namespace = $directive->id->getRootNamespace();
56
+			$this->startElement('namespace');
57
+			$this->writeAttribute('id', $this->namespace);
58
+			$this->writeElement('name', $this->namespace);
59
+		}
60
+
61
+		$this->startElement('directive');
62
+		$this->writeAttribute('id', $directive->id->toString());
63
+
64
+		$this->writeElement('name', $directive->id->getDirective());
65
+
66
+		$this->startElement('aliases');
67
+			foreach ($directive->aliases as $alias) $this->writeElement('alias', $alias->toString());
68
+		$this->endElement(); // aliases
69
+
70
+		$this->startElement('constraints');
71
+			if ($directive->version) $this->writeElement('version', $directive->version);
72
+			$this->startElement('type');
73
+				if ($directive->typeAllowsNull) $this->writeAttribute('allow-null', 'yes');
74
+				$this->text($directive->type);
75
+			$this->endElement(); // type
76
+			if ($directive->allowed) {
77
+				$this->startElement('allowed');
78
+					foreach ($directive->allowed as $value => $x) $this->writeElement('value', $value);
79
+				$this->endElement(); // allowed
80
+			}
81
+			$this->writeElement('default', $this->export($directive->default));
82
+			$this->writeAttribute('xml:space', 'preserve');
83
+			if ($directive->external) {
84
+				$this->startElement('external');
85
+					foreach ($directive->external as $project) $this->writeElement('project', $project);
86
+				$this->endElement();
87
+			}
88
+		$this->endElement(); // constraints
89
+
90
+		if ($directive->deprecatedVersion) {
91
+			$this->startElement('deprecated');
92
+				$this->writeElement('version', $directive->deprecatedVersion);
93
+				$this->writeElement('use', $directive->deprecatedUse->toString());
94
+			$this->endElement(); // deprecated
95
+		}
96
+
97
+		$this->startElement('description');
98
+			$this->writeHTMLDiv($directive->description);
99
+		$this->endElement(); // description
100
+
101
+		$this->endElement(); // directive
102
+	}
103 103
 
104 104
 }
105 105
 
Please login to merge, or discard this patch.
Braces   +26 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
     }
23 23
 
24 24
     protected function export($var) {
25
-        if ($var === array()) return 'array()';
25
+        if ($var === array()) {
26
+        	return 'array()';
27
+        }
26 28
         return var_export($var, true);
27 29
     }
28 30
 
@@ -39,7 +41,10 @@  discard block
 block discarded – undo
39 41
             $this->buildDirective($directive);
40 42
         }
41 43
 
42
-        if ($this->namespace) $this->endElement(); // namespace
44
+        if ($this->namespace) {
45
+        	$this->endElement();
46
+        }
47
+        // namespace
43 48
 
44 49
         $this->endElement(); // configdoc
45 50
         $this->flush();
@@ -51,7 +56,10 @@  discard block
 block discarded – undo
51 56
         // certainly makes things look nicer when documentation is built.
52 57
         // Depends on things being sorted.
53 58
         if (!$this->namespace || $this->namespace !== $directive->id->getRootNamespace()) {
54
-            if ($this->namespace) $this->endElement(); // namespace
59
+            if ($this->namespace) {
60
+            	$this->endElement();
61
+            }
62
+            // namespace
55 63
             $this->namespace = $directive->id->getRootNamespace();
56 64
             $this->startElement('namespace');
57 65
             $this->writeAttribute('id', $this->namespace);
@@ -64,25 +72,35 @@  discard block
 block discarded – undo
64 72
         $this->writeElement('name', $directive->id->getDirective());
65 73
 
66 74
         $this->startElement('aliases');
67
-            foreach ($directive->aliases as $alias) $this->writeElement('alias', $alias->toString());
75
+            foreach ($directive->aliases as $alias) {
76
+            	$this->writeElement('alias', $alias->toString());
77
+            }
68 78
         $this->endElement(); // aliases
69 79
 
70 80
         $this->startElement('constraints');
71
-            if ($directive->version) $this->writeElement('version', $directive->version);
81
+            if ($directive->version) {
82
+            	$this->writeElement('version', $directive->version);
83
+            }
72 84
             $this->startElement('type');
73
-                if ($directive->typeAllowsNull) $this->writeAttribute('allow-null', 'yes');
85
+                if ($directive->typeAllowsNull) {
86
+                	$this->writeAttribute('allow-null', 'yes');
87
+                }
74 88
                 $this->text($directive->type);
75 89
             $this->endElement(); // type
76 90
             if ($directive->allowed) {
77 91
                 $this->startElement('allowed');
78
-                    foreach ($directive->allowed as $value => $x) $this->writeElement('value', $value);
92
+                    foreach ($directive->allowed as $value => $x) {
93
+                    	$this->writeElement('value', $value);
94
+                    }
79 95
                 $this->endElement(); // allowed
80 96
             }
81 97
             $this->writeElement('default', $this->export($directive->default));
82 98
             $this->writeAttribute('xml:space', 'preserve');
83 99
             if ($directive->external) {
84 100
                 $this->startElement('external');
85
-                    foreach ($directive->external as $project) $this->writeElement('project', $project);
101
+                    foreach ($directive->external as $project) {
102
+                    	$this->writeElement('project', $project);
103
+                    }
86 104
                 $this->endElement();
87 105
             }
88 106
         $this->endElement(); // constraints
Please login to merge, or discard this patch.
security/htmlpurifier/library/HTMLPurifier/ConfigSchema/Interchange.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -8,34 +8,34 @@
 block discarded – undo
8 8
 class HTMLPurifier_ConfigSchema_Interchange
9 9
 {
10 10
 
11
-    /**
12
-     * Name of the application this schema is describing.
13
-     */
14
-    public $name;
11
+	/**
12
+	 * Name of the application this schema is describing.
13
+	 */
14
+	public $name;
15 15
 
16
-    /**
17
-     * Array of Directive ID => array(directive info)
18
-     */
19
-    public $directives = array();
16
+	/**
17
+	 * Array of Directive ID => array(directive info)
18
+	 */
19
+	public $directives = array();
20 20
 
21
-    /**
22
-     * Adds a directive array to $directives
23
-     */
24
-    public function addDirective($directive) {
25
-        if (isset($this->directives[$i = $directive->id->toString()])) {
26
-            throw new HTMLPurifier_ConfigSchema_Exception("Cannot redefine directive '$i'");
27
-        }
28
-        $this->directives[$i] = $directive;
29
-    }
21
+	/**
22
+	 * Adds a directive array to $directives
23
+	 */
24
+	public function addDirective($directive) {
25
+		if (isset($this->directives[$i = $directive->id->toString()])) {
26
+			throw new HTMLPurifier_ConfigSchema_Exception("Cannot redefine directive '$i'");
27
+		}
28
+		$this->directives[$i] = $directive;
29
+	}
30 30
 
31
-    /**
32
-     * Convenience function to perform standard validation. Throws exception
33
-     * on failed validation.
34
-     */
35
-    public function validate() {
36
-        $validator = new HTMLPurifier_ConfigSchema_Validator();
37
-        return $validator->validate($this);
38
-    }
31
+	/**
32
+	 * Convenience function to perform standard validation. Throws exception
33
+	 * on failed validation.
34
+	 */
35
+	public function validate() {
36
+		$validator = new HTMLPurifier_ConfigSchema_Validator();
37
+		return $validator->validate($this);
38
+	}
39 39
 
40 40
 }
41 41
 
Please login to merge, or discard this patch.
htmlpurifier/library/HTMLPurifier/ConfigSchema/Interchange/Directive.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -6,71 +6,71 @@
 block discarded – undo
6 6
 class HTMLPurifier_ConfigSchema_Interchange_Directive
7 7
 {
8 8
 
9
-    /**
10
-     * ID of directive, instance of HTMLPurifier_ConfigSchema_Interchange_Id.
11
-     */
12
-    public $id;
9
+	/**
10
+	 * ID of directive, instance of HTMLPurifier_ConfigSchema_Interchange_Id.
11
+	 */
12
+	public $id;
13 13
 
14
-    /**
15
-     * String type, e.g. 'integer' or 'istring'.
16
-     */
17
-    public $type;
14
+	/**
15
+	 * String type, e.g. 'integer' or 'istring'.
16
+	 */
17
+	public $type;
18 18
 
19
-    /**
20
-     * Default value, e.g. 3 or 'DefaultVal'.
21
-     */
22
-    public $default;
19
+	/**
20
+	 * Default value, e.g. 3 or 'DefaultVal'.
21
+	 */
22
+	public $default;
23 23
 
24
-    /**
25
-     * HTML description.
26
-     */
27
-    public $description;
24
+	/**
25
+	 * HTML description.
26
+	 */
27
+	public $description;
28 28
 
29
-    /**
30
-     * Boolean whether or not null is allowed as a value.
31
-     */
32
-    public $typeAllowsNull = false;
29
+	/**
30
+	 * Boolean whether or not null is allowed as a value.
31
+	 */
32
+	public $typeAllowsNull = false;
33 33
 
34
-    /**
35
-     * Lookup table of allowed scalar values, e.g. array('allowed' => true).
36
-     * Null if all values are allowed.
37
-     */
38
-    public $allowed;
34
+	/**
35
+	 * Lookup table of allowed scalar values, e.g. array('allowed' => true).
36
+	 * Null if all values are allowed.
37
+	 */
38
+	public $allowed;
39 39
 
40
-    /**
41
-     * List of aliases for the directive,
42
-     * e.g. array(new HTMLPurifier_ConfigSchema_Interchange_Id('Ns', 'Dir'))).
43
-     */
44
-    public $aliases = array();
40
+	/**
41
+	 * List of aliases for the directive,
42
+	 * e.g. array(new HTMLPurifier_ConfigSchema_Interchange_Id('Ns', 'Dir'))).
43
+	 */
44
+	public $aliases = array();
45 45
 
46
-    /**
47
-     * Hash of value aliases, e.g. array('alt' => 'real'). Null if value
48
-     * aliasing is disabled (necessary for non-scalar types).
49
-     */
50
-    public $valueAliases;
46
+	/**
47
+	 * Hash of value aliases, e.g. array('alt' => 'real'). Null if value
48
+	 * aliasing is disabled (necessary for non-scalar types).
49
+	 */
50
+	public $valueAliases;
51 51
 
52
-    /**
53
-     * Version of HTML Purifier the directive was introduced, e.g. '1.3.1'.
54
-     * Null if the directive has always existed.
55
-     */
56
-    public $version;
52
+	/**
53
+	 * Version of HTML Purifier the directive was introduced, e.g. '1.3.1'.
54
+	 * Null if the directive has always existed.
55
+	 */
56
+	public $version;
57 57
 
58
-    /**
59
-     * ID of directive that supercedes this old directive, is an instance
60
-     * of HTMLPurifier_ConfigSchema_Interchange_Id. Null if not deprecated.
61
-     */
62
-    public $deprecatedUse;
58
+	/**
59
+	 * ID of directive that supercedes this old directive, is an instance
60
+	 * of HTMLPurifier_ConfigSchema_Interchange_Id. Null if not deprecated.
61
+	 */
62
+	public $deprecatedUse;
63 63
 
64
-    /**
65
-     * Version of HTML Purifier this directive was deprecated. Null if not
66
-     * deprecated.
67
-     */
68
-    public $deprecatedVersion;
64
+	/**
65
+	 * Version of HTML Purifier this directive was deprecated. Null if not
66
+	 * deprecated.
67
+	 */
68
+	public $deprecatedVersion;
69 69
 
70
-    /**
71
-     * List of external projects this directive depends on, e.g. array('CSSTidy').
72
-     */
73
-    public $external = array();
70
+	/**
71
+	 * List of external projects this directive depends on, e.g. array('CSSTidy').
72
+	 */
73
+	public $external = array();
74 74
 
75 75
 }
76 76
 
Please login to merge, or discard this patch.
security/htmlpurifier/library/HTMLPurifier/ConfigSchema/Interchange/Id.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -6,31 +6,31 @@
 block discarded – undo
6 6
 class HTMLPurifier_ConfigSchema_Interchange_Id
7 7
 {
8 8
 
9
-    public $key;
10
-
11
-    public function __construct($key) {
12
-        $this->key = $key;
13
-    }
14
-
15
-    /**
16
-     * @warning This is NOT magic, to ensure that people don't abuse SPL and
17
-     *          cause problems for PHP 5.0 support.
18
-     */
19
-    public function toString() {
20
-        return $this->key;
21
-    }
22
-
23
-    public function getRootNamespace() {
24
-        return substr($this->key, 0, strpos($this->key, "."));
25
-    }
26
-
27
-    public function getDirective() {
28
-        return substr($this->key, strpos($this->key, ".") + 1);
29
-    }
30
-
31
-    public static function make($id) {
32
-        return new HTMLPurifier_ConfigSchema_Interchange_Id($id);
33
-    }
9
+	public $key;
10
+
11
+	public function __construct($key) {
12
+		$this->key = $key;
13
+	}
14
+
15
+	/**
16
+	 * @warning This is NOT magic, to ensure that people don't abuse SPL and
17
+	 *          cause problems for PHP 5.0 support.
18
+	 */
19
+	public function toString() {
20
+		return $this->key;
21
+	}
22
+
23
+	public function getRootNamespace() {
24
+		return substr($this->key, 0, strpos($this->key, "."));
25
+	}
26
+
27
+	public function getDirective() {
28
+		return substr($this->key, strpos($this->key, ".") + 1);
29
+	}
30
+
31
+	public static function make($id) {
32
+		return new HTMLPurifier_ConfigSchema_Interchange_Id($id);
33
+	}
34 34
 
35 35
 }
36 36
 
Please login to merge, or discard this patch.
htmlpurifier/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php 3 patches
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -3,177 +3,177 @@
 block discarded – undo
3 3
 class HTMLPurifier_ConfigSchema_InterchangeBuilder
4 4
 {
5 5
 
6
-    /**
7
-     * Used for processing DEFAULT, nothing else.
8
-     */
9
-    protected $varParser;
10
-
11
-    public function __construct($varParser = null) {
12
-        $this->varParser = $varParser ? $varParser : new HTMLPurifier_VarParser_Native();
13
-    }
14
-
15
-    public static function buildFromDirectory($dir = null) {
16
-        $builder     = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
17
-        $interchange = new HTMLPurifier_ConfigSchema_Interchange();
18
-        return $builder->buildDir($interchange, $dir);
19
-    }
20
-
21
-    public function buildDir($interchange, $dir = null) {
22
-        if (!$dir) $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema';
23
-        if (file_exists($dir . '/info.ini')) {
24
-            $info = parse_ini_file($dir . '/info.ini');
25
-            $interchange->name = $info['name'];
26
-        }
27
-
28
-        $files = array();
29
-        $dh = opendir($dir);
30
-        while (false !== ($file = readdir($dh))) {
31
-            if (!$file || $file[0] == '.' || strrchr($file, '.') !== '.txt') {
32
-                continue;
33
-            }
34
-            $files[] = $file;
35
-        }
36
-        closedir($dh);
37
-
38
-        sort($files);
39
-        foreach ($files as $file) {
40
-            $this->buildFile($interchange, $dir . '/' . $file);
41
-        }
42
-
43
-        return $interchange;
44
-    }
45
-
46
-    public function buildFile($interchange, $file) {
47
-        $parser = new HTMLPurifier_StringHashParser();
48
-        $this->build(
49
-            $interchange,
50
-            new HTMLPurifier_StringHash( $parser->parseFile($file) )
51
-        );
52
-    }
53
-
54
-    /**
55
-     * Builds an interchange object based on a hash.
56
-     * @param $interchange HTMLPurifier_ConfigSchema_Interchange object to build
57
-     * @param $hash HTMLPurifier_ConfigSchema_StringHash source data
58
-     */
59
-    public function build($interchange, $hash) {
60
-        if (!$hash instanceof HTMLPurifier_StringHash) {
61
-            $hash = new HTMLPurifier_StringHash($hash);
62
-        }
63
-        if (!isset($hash['ID'])) {
64
-            throw new HTMLPurifier_ConfigSchema_Exception('Hash does not have any ID');
65
-        }
66
-        if (strpos($hash['ID'], '.') === false) {
67
-            if (count($hash) == 2 && isset($hash['DESCRIPTION'])) {
68
-                $hash->offsetGet('DESCRIPTION'); // prevent complaining
69
-            } else {
70
-                throw new HTMLPurifier_ConfigSchema_Exception('All directives must have a namespace');
71
-            }
72
-        } else {
73
-            $this->buildDirective($interchange, $hash);
74
-        }
75
-        $this->_findUnused($hash);
76
-    }
77
-
78
-    public function buildDirective($interchange, $hash) {
79
-        $directive = new HTMLPurifier_ConfigSchema_Interchange_Directive();
80
-
81
-        // These are required elements:
82
-        $directive->id = $this->id($hash->offsetGet('ID'));
83
-        $id = $directive->id->toString(); // convenience
84
-
85
-        if (isset($hash['TYPE'])) {
86
-            $type = explode('/', $hash->offsetGet('TYPE'));
87
-            if (isset($type[1])) $directive->typeAllowsNull = true;
88
-            $directive->type = $type[0];
89
-        } else {
90
-            throw new HTMLPurifier_ConfigSchema_Exception("TYPE in directive hash '$id' not defined");
91
-        }
92
-
93
-        if (isset($hash['DEFAULT'])) {
94
-            try {
95
-                $directive->default = $this->varParser->parse($hash->offsetGet('DEFAULT'), $directive->type, $directive->typeAllowsNull);
96
-            } catch (HTMLPurifier_VarParserException $e) {
97
-                throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in DEFAULT in directive hash '$id'");
98
-            }
99
-        }
100
-
101
-        if (isset($hash['DESCRIPTION'])) {
102
-            $directive->description = $hash->offsetGet('DESCRIPTION');
103
-        }
104
-
105
-        if (isset($hash['ALLOWED'])) {
106
-            $directive->allowed = $this->lookup($this->evalArray($hash->offsetGet('ALLOWED')));
107
-        }
108
-
109
-        if (isset($hash['VALUE-ALIASES'])) {
110
-            $directive->valueAliases = $this->evalArray($hash->offsetGet('VALUE-ALIASES'));
111
-        }
112
-
113
-        if (isset($hash['ALIASES'])) {
114
-            $raw_aliases = trim($hash->offsetGet('ALIASES'));
115
-            $aliases = preg_split('/\s*,\s*/', $raw_aliases);
116
-            foreach ($aliases as $alias) {
117
-                $directive->aliases[] = $this->id($alias);
118
-            }
119
-        }
120
-
121
-        if (isset($hash['VERSION'])) {
122
-            $directive->version = $hash->offsetGet('VERSION');
123
-        }
124
-
125
-        if (isset($hash['DEPRECATED-USE'])) {
126
-            $directive->deprecatedUse = $this->id($hash->offsetGet('DEPRECATED-USE'));
127
-        }
128
-
129
-        if (isset($hash['DEPRECATED-VERSION'])) {
130
-            $directive->deprecatedVersion = $hash->offsetGet('DEPRECATED-VERSION');
131
-        }
132
-
133
-        if (isset($hash['EXTERNAL'])) {
134
-            $directive->external = preg_split('/\s*,\s*/', trim($hash->offsetGet('EXTERNAL')));
135
-        }
136
-
137
-        $interchange->addDirective($directive);
138
-    }
139
-
140
-    /**
141
-     * Evaluates an array PHP code string without array() wrapper
142
-     */
143
-    protected function evalArray($contents) {
144
-        return eval('return array('. $contents .');');
145
-    }
146
-
147
-    /**
148
-     * Converts an array list into a lookup array.
149
-     */
150
-    protected function lookup($array) {
151
-        $ret = array();
152
-        foreach ($array as $val) $ret[$val] = true;
153
-        return $ret;
154
-    }
155
-
156
-    /**
157
-     * Convenience function that creates an HTMLPurifier_ConfigSchema_Interchange_Id
158
-     * object based on a string Id.
159
-     */
160
-    protected function id($id) {
161
-        return HTMLPurifier_ConfigSchema_Interchange_Id::make($id);
162
-    }
163
-
164
-    /**
165
-     * Triggers errors for any unused keys passed in the hash; such keys
166
-     * may indicate typos, missing values, etc.
167
-     * @param $hash Instance of ConfigSchema_StringHash to check.
168
-     */
169
-    protected function _findUnused($hash) {
170
-        $accessed = $hash->getAccessed();
171
-        foreach ($hash as $k => $v) {
172
-            if (!isset($accessed[$k])) {
173
-                trigger_error("String hash key '$k' not used by builder", E_USER_NOTICE);
174
-            }
175
-        }
176
-    }
6
+	/**
7
+	 * Used for processing DEFAULT, nothing else.
8
+	 */
9
+	protected $varParser;
10
+
11
+	public function __construct($varParser = null) {
12
+		$this->varParser = $varParser ? $varParser : new HTMLPurifier_VarParser_Native();
13
+	}
14
+
15
+	public static function buildFromDirectory($dir = null) {
16
+		$builder     = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
17
+		$interchange = new HTMLPurifier_ConfigSchema_Interchange();
18
+		return $builder->buildDir($interchange, $dir);
19
+	}
20
+
21
+	public function buildDir($interchange, $dir = null) {
22
+		if (!$dir) $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema';
23
+		if (file_exists($dir . '/info.ini')) {
24
+			$info = parse_ini_file($dir . '/info.ini');
25
+			$interchange->name = $info['name'];
26
+		}
27
+
28
+		$files = array();
29
+		$dh = opendir($dir);
30
+		while (false !== ($file = readdir($dh))) {
31
+			if (!$file || $file[0] == '.' || strrchr($file, '.') !== '.txt') {
32
+				continue;
33
+			}
34
+			$files[] = $file;
35
+		}
36
+		closedir($dh);
37
+
38
+		sort($files);
39
+		foreach ($files as $file) {
40
+			$this->buildFile($interchange, $dir . '/' . $file);
41
+		}
42
+
43
+		return $interchange;
44
+	}
45
+
46
+	public function buildFile($interchange, $file) {
47
+		$parser = new HTMLPurifier_StringHashParser();
48
+		$this->build(
49
+			$interchange,
50
+			new HTMLPurifier_StringHash( $parser->parseFile($file) )
51
+		);
52
+	}
53
+
54
+	/**
55
+	 * Builds an interchange object based on a hash.
56
+	 * @param $interchange HTMLPurifier_ConfigSchema_Interchange object to build
57
+	 * @param $hash HTMLPurifier_ConfigSchema_StringHash source data
58
+	 */
59
+	public function build($interchange, $hash) {
60
+		if (!$hash instanceof HTMLPurifier_StringHash) {
61
+			$hash = new HTMLPurifier_StringHash($hash);
62
+		}
63
+		if (!isset($hash['ID'])) {
64
+			throw new HTMLPurifier_ConfigSchema_Exception('Hash does not have any ID');
65
+		}
66
+		if (strpos($hash['ID'], '.') === false) {
67
+			if (count($hash) == 2 && isset($hash['DESCRIPTION'])) {
68
+				$hash->offsetGet('DESCRIPTION'); // prevent complaining
69
+			} else {
70
+				throw new HTMLPurifier_ConfigSchema_Exception('All directives must have a namespace');
71
+			}
72
+		} else {
73
+			$this->buildDirective($interchange, $hash);
74
+		}
75
+		$this->_findUnused($hash);
76
+	}
77
+
78
+	public function buildDirective($interchange, $hash) {
79
+		$directive = new HTMLPurifier_ConfigSchema_Interchange_Directive();
80
+
81
+		// These are required elements:
82
+		$directive->id = $this->id($hash->offsetGet('ID'));
83
+		$id = $directive->id->toString(); // convenience
84
+
85
+		if (isset($hash['TYPE'])) {
86
+			$type = explode('/', $hash->offsetGet('TYPE'));
87
+			if (isset($type[1])) $directive->typeAllowsNull = true;
88
+			$directive->type = $type[0];
89
+		} else {
90
+			throw new HTMLPurifier_ConfigSchema_Exception("TYPE in directive hash '$id' not defined");
91
+		}
92
+
93
+		if (isset($hash['DEFAULT'])) {
94
+			try {
95
+				$directive->default = $this->varParser->parse($hash->offsetGet('DEFAULT'), $directive->type, $directive->typeAllowsNull);
96
+			} catch (HTMLPurifier_VarParserException $e) {
97
+				throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in DEFAULT in directive hash '$id'");
98
+			}
99
+		}
100
+
101
+		if (isset($hash['DESCRIPTION'])) {
102
+			$directive->description = $hash->offsetGet('DESCRIPTION');
103
+		}
104
+
105
+		if (isset($hash['ALLOWED'])) {
106
+			$directive->allowed = $this->lookup($this->evalArray($hash->offsetGet('ALLOWED')));
107
+		}
108
+
109
+		if (isset($hash['VALUE-ALIASES'])) {
110
+			$directive->valueAliases = $this->evalArray($hash->offsetGet('VALUE-ALIASES'));
111
+		}
112
+
113
+		if (isset($hash['ALIASES'])) {
114
+			$raw_aliases = trim($hash->offsetGet('ALIASES'));
115
+			$aliases = preg_split('/\s*,\s*/', $raw_aliases);
116
+			foreach ($aliases as $alias) {
117
+				$directive->aliases[] = $this->id($alias);
118
+			}
119
+		}
120
+
121
+		if (isset($hash['VERSION'])) {
122
+			$directive->version = $hash->offsetGet('VERSION');
123
+		}
124
+
125
+		if (isset($hash['DEPRECATED-USE'])) {
126
+			$directive->deprecatedUse = $this->id($hash->offsetGet('DEPRECATED-USE'));
127
+		}
128
+
129
+		if (isset($hash['DEPRECATED-VERSION'])) {
130
+			$directive->deprecatedVersion = $hash->offsetGet('DEPRECATED-VERSION');
131
+		}
132
+
133
+		if (isset($hash['EXTERNAL'])) {
134
+			$directive->external = preg_split('/\s*,\s*/', trim($hash->offsetGet('EXTERNAL')));
135
+		}
136
+
137
+		$interchange->addDirective($directive);
138
+	}
139
+
140
+	/**
141
+	 * Evaluates an array PHP code string without array() wrapper
142
+	 */
143
+	protected function evalArray($contents) {
144
+		return eval('return array('. $contents .');');
145
+	}
146
+
147
+	/**
148
+	 * Converts an array list into a lookup array.
149
+	 */
150
+	protected function lookup($array) {
151
+		$ret = array();
152
+		foreach ($array as $val) $ret[$val] = true;
153
+		return $ret;
154
+	}
155
+
156
+	/**
157
+	 * Convenience function that creates an HTMLPurifier_ConfigSchema_Interchange_Id
158
+	 * object based on a string Id.
159
+	 */
160
+	protected function id($id) {
161
+		return HTMLPurifier_ConfigSchema_Interchange_Id::make($id);
162
+	}
163
+
164
+	/**
165
+	 * Triggers errors for any unused keys passed in the hash; such keys
166
+	 * may indicate typos, missing values, etc.
167
+	 * @param $hash Instance of ConfigSchema_StringHash to check.
168
+	 */
169
+	protected function _findUnused($hash) {
170
+		$accessed = $hash->getAccessed();
171
+		foreach ($hash as $k => $v) {
172
+			if (!isset($accessed[$k])) {
173
+				trigger_error("String hash key '$k' not used by builder", E_USER_NOTICE);
174
+			}
175
+		}
176
+	}
177 177
 
178 178
 }
179 179
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -19,7 +19,9 @@  discard block
 block discarded – undo
19 19
     }
20 20
 
21 21
     public function buildDir($interchange, $dir = null) {
22
-        if (!$dir) $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema';
22
+        if (!$dir) {
23
+        	$dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema';
24
+        }
23 25
         if (file_exists($dir . '/info.ini')) {
24 26
             $info = parse_ini_file($dir . '/info.ini');
25 27
             $interchange->name = $info['name'];
@@ -84,7 +86,9 @@  discard block
 block discarded – undo
84 86
 
85 87
         if (isset($hash['TYPE'])) {
86 88
             $type = explode('/', $hash->offsetGet('TYPE'));
87
-            if (isset($type[1])) $directive->typeAllowsNull = true;
89
+            if (isset($type[1])) {
90
+            	$directive->typeAllowsNull = true;
91
+            }
88 92
             $directive->type = $type[0];
89 93
         } else {
90 94
             throw new HTMLPurifier_ConfigSchema_Exception("TYPE in directive hash '$id' not defined");
@@ -149,7 +153,9 @@  discard block
 block discarded – undo
149 153
      */
150 154
     protected function lookup($array) {
151 155
         $ret = array();
152
-        foreach ($array as $val) $ret[$val] = true;
156
+        foreach ($array as $val) {
157
+        	$ret[$val] = true;
158
+        }
153 159
         return $ret;
154 160
     }
155 161
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -19,9 +19,9 @@  discard block
 block discarded – undo
19 19
     }
20 20
 
21 21
     public function buildDir($interchange, $dir = null) {
22
-        if (!$dir) $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema';
23
-        if (file_exists($dir . '/info.ini')) {
24
-            $info = parse_ini_file($dir . '/info.ini');
22
+        if (!$dir) $dir = HTMLPURIFIER_PREFIX.'/HTMLPurifier/ConfigSchema/schema';
23
+        if (file_exists($dir.'/info.ini')) {
24
+            $info = parse_ini_file($dir.'/info.ini');
25 25
             $interchange->name = $info['name'];
26 26
         }
27 27
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
         sort($files);
39 39
         foreach ($files as $file) {
40
-            $this->buildFile($interchange, $dir . '/' . $file);
40
+            $this->buildFile($interchange, $dir.'/'.$file);
41 41
         }
42 42
 
43 43
         return $interchange;
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
         $parser = new HTMLPurifier_StringHashParser();
48 48
         $this->build(
49 49
             $interchange,
50
-            new HTMLPurifier_StringHash( $parser->parseFile($file) )
50
+            new HTMLPurifier_StringHash($parser->parseFile($file))
51 51
         );
52 52
     }
53 53
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
             try {
95 95
                 $directive->default = $this->varParser->parse($hash->offsetGet('DEFAULT'), $directive->type, $directive->typeAllowsNull);
96 96
             } catch (HTMLPurifier_VarParserException $e) {
97
-                throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in DEFAULT in directive hash '$id'");
97
+                throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage()." in DEFAULT in directive hash '$id'");
98 98
             }
99 99
         }
100 100
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      * Evaluates an array PHP code string without array() wrapper
142 142
      */
143 143
     protected function evalArray($contents) {
144
-        return eval('return array('. $contents .');');
144
+        return eval('return array('.$contents.');');
145 145
     }
146 146
 
147 147
     /**
Please login to merge, or discard this patch.
security/htmlpurifier/library/HTMLPurifier/ConfigSchema/Validator.php 3 patches
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -11,195 +11,195 @@
 block discarded – undo
11 11
 class HTMLPurifier_ConfigSchema_Validator
12 12
 {
13 13
 
14
-    /**
15
-     * Easy to access global objects.
16
-     */
17
-    protected $interchange, $aliases;
18
-
19
-    /**
20
-     * Context-stack to provide easy to read error messages.
21
-     */
22
-    protected $context = array();
23
-
24
-    /**
25
-     * HTMLPurifier_VarParser to test default's type.
26
-     */
27
-    protected $parser;
28
-
29
-    public function __construct() {
30
-        $this->parser = new HTMLPurifier_VarParser();
31
-    }
32
-
33
-    /**
34
-     * Validates a fully-formed interchange object. Throws an
35
-     * HTMLPurifier_ConfigSchema_Exception if there's a problem.
36
-     */
37
-    public function validate($interchange) {
38
-        $this->interchange = $interchange;
39
-        $this->aliases = array();
40
-        // PHP is a bit lax with integer <=> string conversions in
41
-        // arrays, so we don't use the identical !== comparison
42
-        foreach ($interchange->directives as $i => $directive) {
43
-            $id = $directive->id->toString();
44
-            if ($i != $id) $this->error(false, "Integrity violation: key '$i' does not match internal id '$id'");
45
-            $this->validateDirective($directive);
46
-        }
47
-        return true;
48
-    }
49
-
50
-    /**
51
-     * Validates a HTMLPurifier_ConfigSchema_Interchange_Id object.
52
-     */
53
-    public function validateId($id) {
54
-        $id_string = $id->toString();
55
-        $this->context[] = "id '$id_string'";
56
-        if (!$id instanceof HTMLPurifier_ConfigSchema_Interchange_Id) {
57
-            // handled by InterchangeBuilder
58
-            $this->error(false, 'is not an instance of HTMLPurifier_ConfigSchema_Interchange_Id');
59
-        }
60
-        // keys are now unconstrained (we might want to narrow down to A-Za-z0-9.)
61
-        // we probably should check that it has at least one namespace
62
-        $this->with($id, 'key')
63
-            ->assertNotEmpty()
64
-            ->assertIsString(); // implicit assertIsString handled by InterchangeBuilder
65
-        array_pop($this->context);
66
-    }
67
-
68
-    /**
69
-     * Validates a HTMLPurifier_ConfigSchema_Interchange_Directive object.
70
-     */
71
-    public function validateDirective($d) {
72
-        $id = $d->id->toString();
73
-        $this->context[] = "directive '$id'";
74
-        $this->validateId($d->id);
75
-
76
-        $this->with($d, 'description')
77
-            ->assertNotEmpty();
78
-
79
-        // BEGIN - handled by InterchangeBuilder
80
-        $this->with($d, 'type')
81
-            ->assertNotEmpty();
82
-        $this->with($d, 'typeAllowsNull')
83
-            ->assertIsBool();
84
-        try {
85
-            // This also tests validity of $d->type
86
-            $this->parser->parse($d->default, $d->type, $d->typeAllowsNull);
87
-        } catch (HTMLPurifier_VarParserException $e) {
88
-            $this->error('default', 'had error: ' . $e->getMessage());
89
-        }
90
-        // END - handled by InterchangeBuilder
91
-
92
-        if (!is_null($d->allowed) || !empty($d->valueAliases)) {
93
-            // allowed and valueAliases require that we be dealing with
94
-            // strings, so check for that early.
95
-            $d_int = HTMLPurifier_VarParser::$types[$d->type];
96
-            if (!isset(HTMLPurifier_VarParser::$stringTypes[$d_int])) {
97
-                $this->error('type', 'must be a string type when used with allowed or value aliases');
98
-            }
99
-        }
100
-
101
-        $this->validateDirectiveAllowed($d);
102
-        $this->validateDirectiveValueAliases($d);
103
-        $this->validateDirectiveAliases($d);
104
-
105
-        array_pop($this->context);
106
-    }
107
-
108
-    /**
109
-     * Extra validation if $allowed member variable of
110
-     * HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
111
-     */
112
-    public function validateDirectiveAllowed($d) {
113
-        if (is_null($d->allowed)) return;
114
-        $this->with($d, 'allowed')
115
-            ->assertNotEmpty()
116
-            ->assertIsLookup(); // handled by InterchangeBuilder
117
-        if (is_string($d->default) && !isset($d->allowed[$d->default])) {
118
-            $this->error('default', 'must be an allowed value');
119
-        }
120
-        $this->context[] = 'allowed';
121
-        foreach ($d->allowed as $val => $x) {
122
-            if (!is_string($val)) $this->error("value $val", 'must be a string');
123
-        }
124
-        array_pop($this->context);
125
-    }
126
-
127
-    /**
128
-     * Extra validation if $valueAliases member variable of
129
-     * HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
130
-     */
131
-    public function validateDirectiveValueAliases($d) {
132
-        if (is_null($d->valueAliases)) return;
133
-        $this->with($d, 'valueAliases')
134
-            ->assertIsArray(); // handled by InterchangeBuilder
135
-        $this->context[] = 'valueAliases';
136
-        foreach ($d->valueAliases as $alias => $real) {
137
-            if (!is_string($alias)) $this->error("alias $alias", 'must be a string');
138
-            if (!is_string($real))  $this->error("alias target $real from alias '$alias'",  'must be a string');
139
-            if ($alias === $real) {
140
-                $this->error("alias '$alias'", "must not be an alias to itself");
141
-            }
142
-        }
143
-        if (!is_null($d->allowed)) {
144
-            foreach ($d->valueAliases as $alias => $real) {
145
-                if (isset($d->allowed[$alias])) {
146
-                    $this->error("alias '$alias'", 'must not be an allowed value');
147
-                } elseif (!isset($d->allowed[$real])) {
148
-                    $this->error("alias '$alias'", 'must be an alias to an allowed value');
149
-                }
150
-            }
151
-        }
152
-        array_pop($this->context);
153
-    }
154
-
155
-    /**
156
-     * Extra validation if $aliases member variable of
157
-     * HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
158
-     */
159
-    public function validateDirectiveAliases($d) {
160
-        $this->with($d, 'aliases')
161
-            ->assertIsArray(); // handled by InterchangeBuilder
162
-        $this->context[] = 'aliases';
163
-        foreach ($d->aliases as $alias) {
164
-            $this->validateId($alias);
165
-            $s = $alias->toString();
166
-            if (isset($this->interchange->directives[$s])) {
167
-                $this->error("alias '$s'", 'collides with another directive');
168
-            }
169
-            if (isset($this->aliases[$s])) {
170
-                $other_directive = $this->aliases[$s];
171
-                $this->error("alias '$s'", "collides with alias for directive '$other_directive'");
172
-            }
173
-            $this->aliases[$s] = $d->id->toString();
174
-        }
175
-        array_pop($this->context);
176
-    }
177
-
178
-    // protected helper functions
179
-
180
-    /**
181
-     * Convenience function for generating HTMLPurifier_ConfigSchema_ValidatorAtom
182
-     * for validating simple member variables of objects.
183
-     */
184
-    protected function with($obj, $member) {
185
-        return new HTMLPurifier_ConfigSchema_ValidatorAtom($this->getFormattedContext(), $obj, $member);
186
-    }
187
-
188
-    /**
189
-     * Emits an error, providing helpful context.
190
-     */
191
-    protected function error($target, $msg) {
192
-        if ($target !== false) $prefix = ucfirst($target) . ' in ' .  $this->getFormattedContext();
193
-        else $prefix = ucfirst($this->getFormattedContext());
194
-        throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix . ' ' . $msg));
195
-    }
196
-
197
-    /**
198
-     * Returns a formatted context string.
199
-     */
200
-    protected function getFormattedContext() {
201
-        return implode(' in ', array_reverse($this->context));
202
-    }
14
+	/**
15
+	 * Easy to access global objects.
16
+	 */
17
+	protected $interchange, $aliases;
18
+
19
+	/**
20
+	 * Context-stack to provide easy to read error messages.
21
+	 */
22
+	protected $context = array();
23
+
24
+	/**
25
+	 * HTMLPurifier_VarParser to test default's type.
26
+	 */
27
+	protected $parser;
28
+
29
+	public function __construct() {
30
+		$this->parser = new HTMLPurifier_VarParser();
31
+	}
32
+
33
+	/**
34
+	 * Validates a fully-formed interchange object. Throws an
35
+	 * HTMLPurifier_ConfigSchema_Exception if there's a problem.
36
+	 */
37
+	public function validate($interchange) {
38
+		$this->interchange = $interchange;
39
+		$this->aliases = array();
40
+		// PHP is a bit lax with integer <=> string conversions in
41
+		// arrays, so we don't use the identical !== comparison
42
+		foreach ($interchange->directives as $i => $directive) {
43
+			$id = $directive->id->toString();
44
+			if ($i != $id) $this->error(false, "Integrity violation: key '$i' does not match internal id '$id'");
45
+			$this->validateDirective($directive);
46
+		}
47
+		return true;
48
+	}
49
+
50
+	/**
51
+	 * Validates a HTMLPurifier_ConfigSchema_Interchange_Id object.
52
+	 */
53
+	public function validateId($id) {
54
+		$id_string = $id->toString();
55
+		$this->context[] = "id '$id_string'";
56
+		if (!$id instanceof HTMLPurifier_ConfigSchema_Interchange_Id) {
57
+			// handled by InterchangeBuilder
58
+			$this->error(false, 'is not an instance of HTMLPurifier_ConfigSchema_Interchange_Id');
59
+		}
60
+		// keys are now unconstrained (we might want to narrow down to A-Za-z0-9.)
61
+		// we probably should check that it has at least one namespace
62
+		$this->with($id, 'key')
63
+			->assertNotEmpty()
64
+			->assertIsString(); // implicit assertIsString handled by InterchangeBuilder
65
+		array_pop($this->context);
66
+	}
67
+
68
+	/**
69
+	 * Validates a HTMLPurifier_ConfigSchema_Interchange_Directive object.
70
+	 */
71
+	public function validateDirective($d) {
72
+		$id = $d->id->toString();
73
+		$this->context[] = "directive '$id'";
74
+		$this->validateId($d->id);
75
+
76
+		$this->with($d, 'description')
77
+			->assertNotEmpty();
78
+
79
+		// BEGIN - handled by InterchangeBuilder
80
+		$this->with($d, 'type')
81
+			->assertNotEmpty();
82
+		$this->with($d, 'typeAllowsNull')
83
+			->assertIsBool();
84
+		try {
85
+			// This also tests validity of $d->type
86
+			$this->parser->parse($d->default, $d->type, $d->typeAllowsNull);
87
+		} catch (HTMLPurifier_VarParserException $e) {
88
+			$this->error('default', 'had error: ' . $e->getMessage());
89
+		}
90
+		// END - handled by InterchangeBuilder
91
+
92
+		if (!is_null($d->allowed) || !empty($d->valueAliases)) {
93
+			// allowed and valueAliases require that we be dealing with
94
+			// strings, so check for that early.
95
+			$d_int = HTMLPurifier_VarParser::$types[$d->type];
96
+			if (!isset(HTMLPurifier_VarParser::$stringTypes[$d_int])) {
97
+				$this->error('type', 'must be a string type when used with allowed or value aliases');
98
+			}
99
+		}
100
+
101
+		$this->validateDirectiveAllowed($d);
102
+		$this->validateDirectiveValueAliases($d);
103
+		$this->validateDirectiveAliases($d);
104
+
105
+		array_pop($this->context);
106
+	}
107
+
108
+	/**
109
+	 * Extra validation if $allowed member variable of
110
+	 * HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
111
+	 */
112
+	public function validateDirectiveAllowed($d) {
113
+		if (is_null($d->allowed)) return;
114
+		$this->with($d, 'allowed')
115
+			->assertNotEmpty()
116
+			->assertIsLookup(); // handled by InterchangeBuilder
117
+		if (is_string($d->default) && !isset($d->allowed[$d->default])) {
118
+			$this->error('default', 'must be an allowed value');
119
+		}
120
+		$this->context[] = 'allowed';
121
+		foreach ($d->allowed as $val => $x) {
122
+			if (!is_string($val)) $this->error("value $val", 'must be a string');
123
+		}
124
+		array_pop($this->context);
125
+	}
126
+
127
+	/**
128
+	 * Extra validation if $valueAliases member variable of
129
+	 * HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
130
+	 */
131
+	public function validateDirectiveValueAliases($d) {
132
+		if (is_null($d->valueAliases)) return;
133
+		$this->with($d, 'valueAliases')
134
+			->assertIsArray(); // handled by InterchangeBuilder
135
+		$this->context[] = 'valueAliases';
136
+		foreach ($d->valueAliases as $alias => $real) {
137
+			if (!is_string($alias)) $this->error("alias $alias", 'must be a string');
138
+			if (!is_string($real))  $this->error("alias target $real from alias '$alias'",  'must be a string');
139
+			if ($alias === $real) {
140
+				$this->error("alias '$alias'", "must not be an alias to itself");
141
+			}
142
+		}
143
+		if (!is_null($d->allowed)) {
144
+			foreach ($d->valueAliases as $alias => $real) {
145
+				if (isset($d->allowed[$alias])) {
146
+					$this->error("alias '$alias'", 'must not be an allowed value');
147
+				} elseif (!isset($d->allowed[$real])) {
148
+					$this->error("alias '$alias'", 'must be an alias to an allowed value');
149
+				}
150
+			}
151
+		}
152
+		array_pop($this->context);
153
+	}
154
+
155
+	/**
156
+	 * Extra validation if $aliases member variable of
157
+	 * HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
158
+	 */
159
+	public function validateDirectiveAliases($d) {
160
+		$this->with($d, 'aliases')
161
+			->assertIsArray(); // handled by InterchangeBuilder
162
+		$this->context[] = 'aliases';
163
+		foreach ($d->aliases as $alias) {
164
+			$this->validateId($alias);
165
+			$s = $alias->toString();
166
+			if (isset($this->interchange->directives[$s])) {
167
+				$this->error("alias '$s'", 'collides with another directive');
168
+			}
169
+			if (isset($this->aliases[$s])) {
170
+				$other_directive = $this->aliases[$s];
171
+				$this->error("alias '$s'", "collides with alias for directive '$other_directive'");
172
+			}
173
+			$this->aliases[$s] = $d->id->toString();
174
+		}
175
+		array_pop($this->context);
176
+	}
177
+
178
+	// protected helper functions
179
+
180
+	/**
181
+	 * Convenience function for generating HTMLPurifier_ConfigSchema_ValidatorAtom
182
+	 * for validating simple member variables of objects.
183
+	 */
184
+	protected function with($obj, $member) {
185
+		return new HTMLPurifier_ConfigSchema_ValidatorAtom($this->getFormattedContext(), $obj, $member);
186
+	}
187
+
188
+	/**
189
+	 * Emits an error, providing helpful context.
190
+	 */
191
+	protected function error($target, $msg) {
192
+		if ($target !== false) $prefix = ucfirst($target) . ' in ' .  $this->getFormattedContext();
193
+		else $prefix = ucfirst($this->getFormattedContext());
194
+		throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix . ' ' . $msg));
195
+	}
196
+
197
+	/**
198
+	 * Returns a formatted context string.
199
+	 */
200
+	protected function getFormattedContext() {
201
+		return implode(' in ', array_reverse($this->context));
202
+	}
203 203
 
204 204
 }
205 205
 
Please login to merge, or discard this patch.
Braces   +23 added lines, -8 removed lines patch added patch discarded remove patch
@@ -41,7 +41,9 @@  discard block
 block discarded – undo
41 41
         // arrays, so we don't use the identical !== comparison
42 42
         foreach ($interchange->directives as $i => $directive) {
43 43
             $id = $directive->id->toString();
44
-            if ($i != $id) $this->error(false, "Integrity violation: key '$i' does not match internal id '$id'");
44
+            if ($i != $id) {
45
+            	$this->error(false, "Integrity violation: key '$i' does not match internal id '$id'");
46
+            }
45 47
             $this->validateDirective($directive);
46 48
         }
47 49
         return true;
@@ -110,7 +112,9 @@  discard block
 block discarded – undo
110 112
      * HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
111 113
      */
112 114
     public function validateDirectiveAllowed($d) {
113
-        if (is_null($d->allowed)) return;
115
+        if (is_null($d->allowed)) {
116
+        	return;
117
+        }
114 118
         $this->with($d, 'allowed')
115 119
             ->assertNotEmpty()
116 120
             ->assertIsLookup(); // handled by InterchangeBuilder
@@ -119,7 +123,9 @@  discard block
 block discarded – undo
119 123
         }
120 124
         $this->context[] = 'allowed';
121 125
         foreach ($d->allowed as $val => $x) {
122
-            if (!is_string($val)) $this->error("value $val", 'must be a string');
126
+            if (!is_string($val)) {
127
+            	$this->error("value $val", 'must be a string');
128
+            }
123 129
         }
124 130
         array_pop($this->context);
125 131
     }
@@ -129,13 +135,19 @@  discard block
 block discarded – undo
129 135
      * HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
130 136
      */
131 137
     public function validateDirectiveValueAliases($d) {
132
-        if (is_null($d->valueAliases)) return;
138
+        if (is_null($d->valueAliases)) {
139
+        	return;
140
+        }
133 141
         $this->with($d, 'valueAliases')
134 142
             ->assertIsArray(); // handled by InterchangeBuilder
135 143
         $this->context[] = 'valueAliases';
136 144
         foreach ($d->valueAliases as $alias => $real) {
137
-            if (!is_string($alias)) $this->error("alias $alias", 'must be a string');
138
-            if (!is_string($real))  $this->error("alias target $real from alias '$alias'",  'must be a string');
145
+            if (!is_string($alias)) {
146
+            	$this->error("alias $alias", 'must be a string');
147
+            }
148
+            if (!is_string($real)) {
149
+            	$this->error("alias target $real from alias '$alias'",  'must be a string');
150
+            }
139 151
             if ($alias === $real) {
140 152
                 $this->error("alias '$alias'", "must not be an alias to itself");
141 153
             }
@@ -189,8 +201,11 @@  discard block
 block discarded – undo
189 201
      * Emits an error, providing helpful context.
190 202
      */
191 203
     protected function error($target, $msg) {
192
-        if ($target !== false) $prefix = ucfirst($target) . ' in ' .  $this->getFormattedContext();
193
-        else $prefix = ucfirst($this->getFormattedContext());
204
+        if ($target !== false) {
205
+        	$prefix = ucfirst($target) . ' in ' .  $this->getFormattedContext();
206
+        } else {
207
+        	$prefix = ucfirst($this->getFormattedContext());
208
+        }
194 209
         throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix . ' ' . $msg));
195 210
     }
196 211
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
             // This also tests validity of $d->type
86 86
             $this->parser->parse($d->default, $d->type, $d->typeAllowsNull);
87 87
         } catch (HTMLPurifier_VarParserException $e) {
88
-            $this->error('default', 'had error: ' . $e->getMessage());
88
+            $this->error('default', 'had error: '.$e->getMessage());
89 89
         }
90 90
         // END - handled by InterchangeBuilder
91 91
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         $this->context[] = 'valueAliases';
136 136
         foreach ($d->valueAliases as $alias => $real) {
137 137
             if (!is_string($alias)) $this->error("alias $alias", 'must be a string');
138
-            if (!is_string($real))  $this->error("alias target $real from alias '$alias'",  'must be a string');
138
+            if (!is_string($real))  $this->error("alias target $real from alias '$alias'", 'must be a string');
139 139
             if ($alias === $real) {
140 140
                 $this->error("alias '$alias'", "must not be an alias to itself");
141 141
             }
@@ -189,9 +189,9 @@  discard block
 block discarded – undo
189 189
      * Emits an error, providing helpful context.
190 190
      */
191 191
     protected function error($target, $msg) {
192
-        if ($target !== false) $prefix = ucfirst($target) . ' in ' .  $this->getFormattedContext();
192
+        if ($target !== false) $prefix = ucfirst($target).' in '.$this->getFormattedContext();
193 193
         else $prefix = ucfirst($this->getFormattedContext());
194
-        throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix . ' ' . $msg));
194
+        throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix.' '.$msg));
195 195
     }
196 196
 
197 197
     /**
Please login to merge, or discard this patch.
security/htmlpurifier/library/HTMLPurifier/ConfigSchema/ValidatorAtom.php 3 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -9,57 +9,57 @@
 block discarded – undo
9 9
 class HTMLPurifier_ConfigSchema_ValidatorAtom
10 10
 {
11 11
 
12
-    protected $context, $obj, $member, $contents;
12
+	protected $context, $obj, $member, $contents;
13 13
 
14
-    public function __construct($context, $obj, $member) {
15
-        $this->context     = $context;
16
-        $this->obj         = $obj;
17
-        $this->member      = $member;
18
-        $this->contents    =& $obj->$member;
19
-    }
14
+	public function __construct($context, $obj, $member) {
15
+		$this->context     = $context;
16
+		$this->obj         = $obj;
17
+		$this->member      = $member;
18
+		$this->contents    =& $obj->$member;
19
+	}
20 20
 
21
-    public function assertIsString() {
22
-        if (!is_string($this->contents)) $this->error('must be a string');
23
-        return $this;
24
-    }
21
+	public function assertIsString() {
22
+		if (!is_string($this->contents)) $this->error('must be a string');
23
+		return $this;
24
+	}
25 25
 
26
-    public function assertIsBool() {
27
-        if (!is_bool($this->contents)) $this->error('must be a boolean');
28
-        return $this;
29
-    }
26
+	public function assertIsBool() {
27
+		if (!is_bool($this->contents)) $this->error('must be a boolean');
28
+		return $this;
29
+	}
30 30
 
31
-    public function assertIsArray() {
32
-        if (!is_array($this->contents)) $this->error('must be an array');
33
-        return $this;
34
-    }
31
+	public function assertIsArray() {
32
+		if (!is_array($this->contents)) $this->error('must be an array');
33
+		return $this;
34
+	}
35 35
 
36
-    public function assertNotNull() {
37
-        if ($this->contents === null) $this->error('must not be null');
38
-        return $this;
39
-    }
36
+	public function assertNotNull() {
37
+		if ($this->contents === null) $this->error('must not be null');
38
+		return $this;
39
+	}
40 40
 
41
-    public function assertAlnum() {
42
-        $this->assertIsString();
43
-        if (!ctype_alnum($this->contents)) $this->error('must be alphanumeric');
44
-        return $this;
45
-    }
41
+	public function assertAlnum() {
42
+		$this->assertIsString();
43
+		if (!ctype_alnum($this->contents)) $this->error('must be alphanumeric');
44
+		return $this;
45
+	}
46 46
 
47
-    public function assertNotEmpty() {
48
-        if (empty($this->contents)) $this->error('must not be empty');
49
-        return $this;
50
-    }
47
+	public function assertNotEmpty() {
48
+		if (empty($this->contents)) $this->error('must not be empty');
49
+		return $this;
50
+	}
51 51
 
52
-    public function assertIsLookup() {
53
-        $this->assertIsArray();
54
-        foreach ($this->contents as $v) {
55
-            if ($v !== true) $this->error('must be a lookup array');
56
-        }
57
-        return $this;
58
-    }
52
+	public function assertIsLookup() {
53
+		$this->assertIsArray();
54
+		foreach ($this->contents as $v) {
55
+			if ($v !== true) $this->error('must be a lookup array');
56
+		}
57
+		return $this;
58
+	}
59 59
 
60
-    protected function error($msg) {
61
-        throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member) . ' in ' . $this->context . ' ' . $msg);
62
-    }
60
+	protected function error($msg) {
61
+		throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member) . ' in ' . $this->context . ' ' . $msg);
62
+	}
63 63
 
64 64
 }
65 65
 
Please login to merge, or discard this patch.
Braces   +21 added lines, -7 removed lines patch added patch discarded remove patch
@@ -19,40 +19,54 @@
 block discarded – undo
19 19
     }
20 20
 
21 21
     public function assertIsString() {
22
-        if (!is_string($this->contents)) $this->error('must be a string');
22
+        if (!is_string($this->contents)) {
23
+        	$this->error('must be a string');
24
+        }
23 25
         return $this;
24 26
     }
25 27
 
26 28
     public function assertIsBool() {
27
-        if (!is_bool($this->contents)) $this->error('must be a boolean');
29
+        if (!is_bool($this->contents)) {
30
+        	$this->error('must be a boolean');
31
+        }
28 32
         return $this;
29 33
     }
30 34
 
31 35
     public function assertIsArray() {
32
-        if (!is_array($this->contents)) $this->error('must be an array');
36
+        if (!is_array($this->contents)) {
37
+        	$this->error('must be an array');
38
+        }
33 39
         return $this;
34 40
     }
35 41
 
36 42
     public function assertNotNull() {
37
-        if ($this->contents === null) $this->error('must not be null');
43
+        if ($this->contents === null) {
44
+        	$this->error('must not be null');
45
+        }
38 46
         return $this;
39 47
     }
40 48
 
41 49
     public function assertAlnum() {
42 50
         $this->assertIsString();
43
-        if (!ctype_alnum($this->contents)) $this->error('must be alphanumeric');
51
+        if (!ctype_alnum($this->contents)) {
52
+        	$this->error('must be alphanumeric');
53
+        }
44 54
         return $this;
45 55
     }
46 56
 
47 57
     public function assertNotEmpty() {
48
-        if (empty($this->contents)) $this->error('must not be empty');
58
+        if (empty($this->contents)) {
59
+        	$this->error('must not be empty');
60
+        }
49 61
         return $this;
50 62
     }
51 63
 
52 64
     public function assertIsLookup() {
53 65
         $this->assertIsArray();
54 66
         foreach ($this->contents as $v) {
55
-            if ($v !== true) $this->error('must be a lookup array');
67
+            if ($v !== true) {
68
+            	$this->error('must be a lookup array');
69
+            }
56 70
         }
57 71
         return $this;
58 72
     }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
         $this->context     = $context;
16 16
         $this->obj         = $obj;
17 17
         $this->member      = $member;
18
-        $this->contents    =& $obj->$member;
18
+        $this->contents    = & $obj->$member;
19 19
     }
20 20
 
21 21
     public function assertIsString() {
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     }
59 59
 
60 60
     protected function error($msg) {
61
-        throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member) . ' in ' . $this->context . ' ' . $msg);
61
+        throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member).' in '.$this->context.' '.$msg);
62 62
     }
63 63
 
64 64
 }
Please login to merge, or discard this patch.
classes/security/htmlpurifier/library/HTMLPurifier/ContentSets.php 3 patches
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -6,149 +6,149 @@
 block discarded – undo
6 6
 class HTMLPurifier_ContentSets
7 7
 {
8 8
 
9
-    /**
10
-     * List of content set strings (pipe seperators) indexed by name.
11
-     */
12
-    public $info = array();
9
+	/**
10
+	 * List of content set strings (pipe seperators) indexed by name.
11
+	 */
12
+	public $info = array();
13 13
 
14
-    /**
15
-     * List of content set lookups (element => true) indexed by name.
16
-     * @note This is in HTMLPurifier_HTMLDefinition->info_content_sets
17
-     */
18
-    public $lookup = array();
14
+	/**
15
+	 * List of content set lookups (element => true) indexed by name.
16
+	 * @note This is in HTMLPurifier_HTMLDefinition->info_content_sets
17
+	 */
18
+	public $lookup = array();
19 19
 
20
-    /**
21
-     * Synchronized list of defined content sets (keys of info)
22
-     */
23
-    protected $keys = array();
24
-    /**
25
-     * Synchronized list of defined content values (values of info)
26
-     */
27
-    protected $values = array();
20
+	/**
21
+	 * Synchronized list of defined content sets (keys of info)
22
+	 */
23
+	protected $keys = array();
24
+	/**
25
+	 * Synchronized list of defined content values (values of info)
26
+	 */
27
+	protected $values = array();
28 28
 
29
-    /**
30
-     * Merges in module's content sets, expands identifiers in the content
31
-     * sets and populates the keys, values and lookup member variables.
32
-     * @param $modules List of HTMLPurifier_HTMLModule
33
-     */
34
-    public function __construct($modules) {
35
-        if (!is_array($modules)) $modules = array($modules);
36
-        // populate content_sets based on module hints
37
-        // sorry, no way of overloading
38
-        foreach ($modules as $module_i => $module) {
39
-            foreach ($module->content_sets as $key => $value) {
40
-                $temp = $this->convertToLookup($value);
41
-                if (isset($this->lookup[$key])) {
42
-                    // add it into the existing content set
43
-                    $this->lookup[$key] = array_merge($this->lookup[$key], $temp);
44
-                } else {
45
-                    $this->lookup[$key] = $temp;
46
-                }
47
-            }
48
-        }
49
-        $old_lookup = false;
50
-        while ($old_lookup !== $this->lookup) {
51
-            $old_lookup = $this->lookup;
52
-            foreach ($this->lookup as $i => $set) {
53
-                $add = array();
54
-                foreach ($set as $element => $x) {
55
-                    if (isset($this->lookup[$element])) {
56
-                        $add += $this->lookup[$element];
57
-                        unset($this->lookup[$i][$element]);
58
-                    }
59
-                }
60
-                $this->lookup[$i] += $add;
61
-            }
62
-        }
29
+	/**
30
+	 * Merges in module's content sets, expands identifiers in the content
31
+	 * sets and populates the keys, values and lookup member variables.
32
+	 * @param $modules List of HTMLPurifier_HTMLModule
33
+	 */
34
+	public function __construct($modules) {
35
+		if (!is_array($modules)) $modules = array($modules);
36
+		// populate content_sets based on module hints
37
+		// sorry, no way of overloading
38
+		foreach ($modules as $module_i => $module) {
39
+			foreach ($module->content_sets as $key => $value) {
40
+				$temp = $this->convertToLookup($value);
41
+				if (isset($this->lookup[$key])) {
42
+					// add it into the existing content set
43
+					$this->lookup[$key] = array_merge($this->lookup[$key], $temp);
44
+				} else {
45
+					$this->lookup[$key] = $temp;
46
+				}
47
+			}
48
+		}
49
+		$old_lookup = false;
50
+		while ($old_lookup !== $this->lookup) {
51
+			$old_lookup = $this->lookup;
52
+			foreach ($this->lookup as $i => $set) {
53
+				$add = array();
54
+				foreach ($set as $element => $x) {
55
+					if (isset($this->lookup[$element])) {
56
+						$add += $this->lookup[$element];
57
+						unset($this->lookup[$i][$element]);
58
+					}
59
+				}
60
+				$this->lookup[$i] += $add;
61
+			}
62
+		}
63 63
 
64
-        foreach ($this->lookup as $key => $lookup) {
65
-            $this->info[$key] = implode(' | ', array_keys($lookup));
66
-        }
67
-        $this->keys   = array_keys($this->info);
68
-        $this->values = array_values($this->info);
69
-    }
64
+		foreach ($this->lookup as $key => $lookup) {
65
+			$this->info[$key] = implode(' | ', array_keys($lookup));
66
+		}
67
+		$this->keys   = array_keys($this->info);
68
+		$this->values = array_values($this->info);
69
+	}
70 70
 
71
-    /**
72
-     * Accepts a definition; generates and assigns a ChildDef for it
73
-     * @param $def HTMLPurifier_ElementDef reference
74
-     * @param $module Module that defined the ElementDef
75
-     */
76
-    public function generateChildDef(&$def, $module) {
77
-        if (!empty($def->child)) return; // already done!
78
-        $content_model = $def->content_model;
79
-        if (is_string($content_model)) {
80
-            // Assume that $this->keys is alphanumeric
81
-            $def->content_model = preg_replace_callback(
82
-                '/\b(' . implode('|', $this->keys) . ')\b/',
83
-                array($this, 'generateChildDefCallback'),
84
-                $content_model
85
-            );
86
-            //$def->content_model = str_replace(
87
-            //    $this->keys, $this->values, $content_model);
88
-        }
89
-        $def->child = $this->getChildDef($def, $module);
90
-    }
71
+	/**
72
+	 * Accepts a definition; generates and assigns a ChildDef for it
73
+	 * @param $def HTMLPurifier_ElementDef reference
74
+	 * @param $module Module that defined the ElementDef
75
+	 */
76
+	public function generateChildDef(&$def, $module) {
77
+		if (!empty($def->child)) return; // already done!
78
+		$content_model = $def->content_model;
79
+		if (is_string($content_model)) {
80
+			// Assume that $this->keys is alphanumeric
81
+			$def->content_model = preg_replace_callback(
82
+				'/\b(' . implode('|', $this->keys) . ')\b/',
83
+				array($this, 'generateChildDefCallback'),
84
+				$content_model
85
+			);
86
+			//$def->content_model = str_replace(
87
+			//    $this->keys, $this->values, $content_model);
88
+		}
89
+		$def->child = $this->getChildDef($def, $module);
90
+	}
91 91
 
92
-    public function generateChildDefCallback($matches) {
93
-        return $this->info[$matches[0]];
94
-    }
92
+	public function generateChildDefCallback($matches) {
93
+		return $this->info[$matches[0]];
94
+	}
95 95
 
96
-    /**
97
-     * Instantiates a ChildDef based on content_model and content_model_type
98
-     * member variables in HTMLPurifier_ElementDef
99
-     * @note This will also defer to modules for custom HTMLPurifier_ChildDef
100
-     *       subclasses that need content set expansion
101
-     * @param $def HTMLPurifier_ElementDef to have ChildDef extracted
102
-     * @return HTMLPurifier_ChildDef corresponding to ElementDef
103
-     */
104
-    public function getChildDef($def, $module) {
105
-        $value = $def->content_model;
106
-        if (is_object($value)) {
107
-            trigger_error(
108
-                'Literal object child definitions should be stored in '.
109
-                'ElementDef->child not ElementDef->content_model',
110
-                E_USER_NOTICE
111
-            );
112
-            return $value;
113
-        }
114
-        switch ($def->content_model_type) {
115
-            case 'required':
116
-                return new HTMLPurifier_ChildDef_Required($value);
117
-            case 'optional':
118
-                return new HTMLPurifier_ChildDef_Optional($value);
119
-            case 'empty':
120
-                return new HTMLPurifier_ChildDef_Empty();
121
-            case 'custom':
122
-                return new HTMLPurifier_ChildDef_Custom($value);
123
-        }
124
-        // defer to its module
125
-        $return = false;
126
-        if ($module->defines_child_def) { // save a func call
127
-            $return = $module->getChildDef($def);
128
-        }
129
-        if ($return !== false) return $return;
130
-        // error-out
131
-        trigger_error(
132
-            'Could not determine which ChildDef class to instantiate',
133
-            E_USER_ERROR
134
-        );
135
-        return false;
136
-    }
96
+	/**
97
+	 * Instantiates a ChildDef based on content_model and content_model_type
98
+	 * member variables in HTMLPurifier_ElementDef
99
+	 * @note This will also defer to modules for custom HTMLPurifier_ChildDef
100
+	 *       subclasses that need content set expansion
101
+	 * @param $def HTMLPurifier_ElementDef to have ChildDef extracted
102
+	 * @return HTMLPurifier_ChildDef corresponding to ElementDef
103
+	 */
104
+	public function getChildDef($def, $module) {
105
+		$value = $def->content_model;
106
+		if (is_object($value)) {
107
+			trigger_error(
108
+				'Literal object child definitions should be stored in '.
109
+				'ElementDef->child not ElementDef->content_model',
110
+				E_USER_NOTICE
111
+			);
112
+			return $value;
113
+		}
114
+		switch ($def->content_model_type) {
115
+			case 'required':
116
+				return new HTMLPurifier_ChildDef_Required($value);
117
+			case 'optional':
118
+				return new HTMLPurifier_ChildDef_Optional($value);
119
+			case 'empty':
120
+				return new HTMLPurifier_ChildDef_Empty();
121
+			case 'custom':
122
+				return new HTMLPurifier_ChildDef_Custom($value);
123
+		}
124
+		// defer to its module
125
+		$return = false;
126
+		if ($module->defines_child_def) { // save a func call
127
+			$return = $module->getChildDef($def);
128
+		}
129
+		if ($return !== false) return $return;
130
+		// error-out
131
+		trigger_error(
132
+			'Could not determine which ChildDef class to instantiate',
133
+			E_USER_ERROR
134
+		);
135
+		return false;
136
+	}
137 137
 
138
-    /**
139
-     * Converts a string list of elements separated by pipes into
140
-     * a lookup array.
141
-     * @param $string List of elements
142
-     * @return Lookup array of elements
143
-     */
144
-    protected function convertToLookup($string) {
145
-        $array = explode('|', str_replace(' ', '', $string));
146
-        $ret = array();
147
-        foreach ($array as $i => $k) {
148
-            $ret[$k] = true;
149
-        }
150
-        return $ret;
151
-    }
138
+	/**
139
+	 * Converts a string list of elements separated by pipes into
140
+	 * a lookup array.
141
+	 * @param $string List of elements
142
+	 * @return Lookup array of elements
143
+	 */
144
+	protected function convertToLookup($string) {
145
+		$array = explode('|', str_replace(' ', '', $string));
146
+		$ret = array();
147
+		foreach ($array as $i => $k) {
148
+			$ret[$k] = true;
149
+		}
150
+		return $ret;
151
+	}
152 152
 
153 153
 }
154 154
 
Please login to merge, or discard this patch.
Braces   +10 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,9 @@  discard block
 block discarded – undo
32 32
      * @param $modules List of HTMLPurifier_HTMLModule
33 33
      */
34 34
     public function __construct($modules) {
35
-        if (!is_array($modules)) $modules = array($modules);
35
+        if (!is_array($modules)) {
36
+        	$modules = array($modules);
37
+        }
36 38
         // populate content_sets based on module hints
37 39
         // sorry, no way of overloading
38 40
         foreach ($modules as $module_i => $module) {
@@ -74,7 +76,10 @@  discard block
 block discarded – undo
74 76
      * @param $module Module that defined the ElementDef
75 77
      */
76 78
     public function generateChildDef(&$def, $module) {
77
-        if (!empty($def->child)) return; // already done!
79
+        if (!empty($def->child)) {
80
+        	return;
81
+        }
82
+        // already done!
78 83
         $content_model = $def->content_model;
79 84
         if (is_string($content_model)) {
80 85
             // Assume that $this->keys is alphanumeric
@@ -126,7 +131,9 @@  discard block
 block discarded – undo
126 131
         if ($module->defines_child_def) { // save a func call
127 132
             $return = $module->getChildDef($def);
128 133
         }
129
-        if ($return !== false) return $return;
134
+        if ($return !== false) {
135
+        	return $return;
136
+        }
130 137
         // error-out
131 138
         trigger_error(
132 139
             'Could not determine which ChildDef class to instantiate',
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@
 block discarded – undo
79 79
         if (is_string($content_model)) {
80 80
             // Assume that $this->keys is alphanumeric
81 81
             $def->content_model = preg_replace_callback(
82
-                '/\b(' . implode('|', $this->keys) . ')\b/',
82
+                '/\b('.implode('|', $this->keys).')\b/',
83 83
                 array($this, 'generateChildDefCallback'),
84 84
                 $content_model
85 85
             );
Please login to merge, or discard this patch.