@@ -7,43 +7,43 @@ |
||
7 | 7 | abstract class HTMLPurifier_Definition |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * Has setup() been called yet? |
|
12 | - */ |
|
13 | - public $setup = false; |
|
14 | - |
|
15 | - /** |
|
16 | - * If true, write out the final definition object to the cache after |
|
17 | - * setup. This will be true only if all invocations to get a raw |
|
18 | - * definition object are also optimized. This does not cause file |
|
19 | - * system thrashing because on subsequent calls the cached object |
|
20 | - * is used and any writes to the raw definition object are short |
|
21 | - * circuited. See enduser-customize.html for the high-level |
|
22 | - * picture. |
|
23 | - */ |
|
24 | - public $optimized = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * What type of definition is it? |
|
28 | - */ |
|
29 | - public $type; |
|
30 | - |
|
31 | - /** |
|
32 | - * Sets up the definition object into the final form, something |
|
33 | - * not done by the constructor |
|
34 | - * @param $config HTMLPurifier_Config instance |
|
35 | - */ |
|
36 | - abstract protected function doSetup($config); |
|
37 | - |
|
38 | - /** |
|
39 | - * Setup function that aborts if already setup |
|
40 | - * @param $config HTMLPurifier_Config instance |
|
41 | - */ |
|
42 | - public function setup($config) { |
|
43 | - if ($this->setup) return; |
|
44 | - $this->setup = true; |
|
45 | - $this->doSetup($config); |
|
46 | - } |
|
10 | + /** |
|
11 | + * Has setup() been called yet? |
|
12 | + */ |
|
13 | + public $setup = false; |
|
14 | + |
|
15 | + /** |
|
16 | + * If true, write out the final definition object to the cache after |
|
17 | + * setup. This will be true only if all invocations to get a raw |
|
18 | + * definition object are also optimized. This does not cause file |
|
19 | + * system thrashing because on subsequent calls the cached object |
|
20 | + * is used and any writes to the raw definition object are short |
|
21 | + * circuited. See enduser-customize.html for the high-level |
|
22 | + * picture. |
|
23 | + */ |
|
24 | + public $optimized = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * What type of definition is it? |
|
28 | + */ |
|
29 | + public $type; |
|
30 | + |
|
31 | + /** |
|
32 | + * Sets up the definition object into the final form, something |
|
33 | + * not done by the constructor |
|
34 | + * @param $config HTMLPurifier_Config instance |
|
35 | + */ |
|
36 | + abstract protected function doSetup($config); |
|
37 | + |
|
38 | + /** |
|
39 | + * Setup function that aborts if already setup |
|
40 | + * @param $config HTMLPurifier_Config instance |
|
41 | + */ |
|
42 | + public function setup($config) { |
|
43 | + if ($this->setup) return; |
|
44 | + $this->setup = true; |
|
45 | + $this->doSetup($config); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | } |
49 | 49 |
@@ -40,7 +40,9 @@ |
||
40 | 40 | * @param $config HTMLPurifier_Config instance |
41 | 41 | */ |
42 | 42 | public function setup($config) { |
43 | - if ($this->setup) return; |
|
43 | + if ($this->setup) { |
|
44 | + return; |
|
45 | + } |
|
44 | 46 | $this->setup = true; |
45 | 47 | $this->doSetup($config); |
46 | 48 | } |
@@ -11,97 +11,97 @@ |
||
11 | 11 | abstract class HTMLPurifier_DefinitionCache |
12 | 12 | { |
13 | 13 | |
14 | - public $type; |
|
14 | + public $type; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @param $name Type of definition objects this instance of the |
|
18 | - * cache will handle. |
|
19 | - */ |
|
20 | - public function __construct($type) { |
|
21 | - $this->type = $type; |
|
22 | - } |
|
16 | + /** |
|
17 | + * @param $name Type of definition objects this instance of the |
|
18 | + * cache will handle. |
|
19 | + */ |
|
20 | + public function __construct($type) { |
|
21 | + $this->type = $type; |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * Generates a unique identifier for a particular configuration |
|
26 | - * @param Instance of HTMLPurifier_Config |
|
27 | - */ |
|
28 | - public function generateKey($config) { |
|
29 | - return $config->version . ',' . // possibly replace with function calls |
|
30 | - $config->getBatchSerial($this->type) . ',' . |
|
31 | - $config->get($this->type . '.DefinitionRev'); |
|
32 | - } |
|
24 | + /** |
|
25 | + * Generates a unique identifier for a particular configuration |
|
26 | + * @param Instance of HTMLPurifier_Config |
|
27 | + */ |
|
28 | + public function generateKey($config) { |
|
29 | + return $config->version . ',' . // possibly replace with function calls |
|
30 | + $config->getBatchSerial($this->type) . ',' . |
|
31 | + $config->get($this->type . '.DefinitionRev'); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Tests whether or not a key is old with respect to the configuration's |
|
36 | - * version and revision number. |
|
37 | - * @param $key Key to test |
|
38 | - * @param $config Instance of HTMLPurifier_Config to test against |
|
39 | - */ |
|
40 | - public function isOld($key, $config) { |
|
41 | - if (substr_count($key, ',') < 2) return true; |
|
42 | - list($version, $hash, $revision) = explode(',', $key, 3); |
|
43 | - $compare = version_compare($version, $config->version); |
|
44 | - // version mismatch, is always old |
|
45 | - if ($compare != 0) return true; |
|
46 | - // versions match, ids match, check revision number |
|
47 | - if ( |
|
48 | - $hash == $config->getBatchSerial($this->type) && |
|
49 | - $revision < $config->get($this->type . '.DefinitionRev') |
|
50 | - ) return true; |
|
51 | - return false; |
|
52 | - } |
|
34 | + /** |
|
35 | + * Tests whether or not a key is old with respect to the configuration's |
|
36 | + * version and revision number. |
|
37 | + * @param $key Key to test |
|
38 | + * @param $config Instance of HTMLPurifier_Config to test against |
|
39 | + */ |
|
40 | + public function isOld($key, $config) { |
|
41 | + if (substr_count($key, ',') < 2) return true; |
|
42 | + list($version, $hash, $revision) = explode(',', $key, 3); |
|
43 | + $compare = version_compare($version, $config->version); |
|
44 | + // version mismatch, is always old |
|
45 | + if ($compare != 0) return true; |
|
46 | + // versions match, ids match, check revision number |
|
47 | + if ( |
|
48 | + $hash == $config->getBatchSerial($this->type) && |
|
49 | + $revision < $config->get($this->type . '.DefinitionRev') |
|
50 | + ) return true; |
|
51 | + return false; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Checks if a definition's type jives with the cache's type |
|
56 | - * @note Throws an error on failure |
|
57 | - * @param $def Definition object to check |
|
58 | - * @return Boolean true if good, false if not |
|
59 | - */ |
|
60 | - public function checkDefType($def) { |
|
61 | - if ($def->type !== $this->type) { |
|
62 | - trigger_error("Cannot use definition of type {$def->type} in cache for {$this->type}"); |
|
63 | - return false; |
|
64 | - } |
|
65 | - return true; |
|
66 | - } |
|
54 | + /** |
|
55 | + * Checks if a definition's type jives with the cache's type |
|
56 | + * @note Throws an error on failure |
|
57 | + * @param $def Definition object to check |
|
58 | + * @return Boolean true if good, false if not |
|
59 | + */ |
|
60 | + public function checkDefType($def) { |
|
61 | + if ($def->type !== $this->type) { |
|
62 | + trigger_error("Cannot use definition of type {$def->type} in cache for {$this->type}"); |
|
63 | + return false; |
|
64 | + } |
|
65 | + return true; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Adds a definition object to the cache |
|
70 | - */ |
|
71 | - abstract public function add($def, $config); |
|
68 | + /** |
|
69 | + * Adds a definition object to the cache |
|
70 | + */ |
|
71 | + abstract public function add($def, $config); |
|
72 | 72 | |
73 | - /** |
|
74 | - * Unconditionally saves a definition object to the cache |
|
75 | - */ |
|
76 | - abstract public function set($def, $config); |
|
73 | + /** |
|
74 | + * Unconditionally saves a definition object to the cache |
|
75 | + */ |
|
76 | + abstract public function set($def, $config); |
|
77 | 77 | |
78 | - /** |
|
79 | - * Replace an object in the cache |
|
80 | - */ |
|
81 | - abstract public function replace($def, $config); |
|
78 | + /** |
|
79 | + * Replace an object in the cache |
|
80 | + */ |
|
81 | + abstract public function replace($def, $config); |
|
82 | 82 | |
83 | - /** |
|
84 | - * Retrieves a definition object from the cache |
|
85 | - */ |
|
86 | - abstract public function get($config); |
|
83 | + /** |
|
84 | + * Retrieves a definition object from the cache |
|
85 | + */ |
|
86 | + abstract public function get($config); |
|
87 | 87 | |
88 | - /** |
|
89 | - * Removes a definition object to the cache |
|
90 | - */ |
|
91 | - abstract public function remove($config); |
|
88 | + /** |
|
89 | + * Removes a definition object to the cache |
|
90 | + */ |
|
91 | + abstract public function remove($config); |
|
92 | 92 | |
93 | - /** |
|
94 | - * Clears all objects from cache |
|
95 | - */ |
|
96 | - abstract public function flush($config); |
|
93 | + /** |
|
94 | + * Clears all objects from cache |
|
95 | + */ |
|
96 | + abstract public function flush($config); |
|
97 | 97 | |
98 | - /** |
|
99 | - * Clears all expired (older version or revision) objects from cache |
|
100 | - * @note Be carefuly implementing this method as flush. Flush must |
|
101 | - * not interfere with other Definition types, and cleanup() |
|
102 | - * should not be repeatedly called by userland code. |
|
103 | - */ |
|
104 | - abstract public function cleanup($config); |
|
98 | + /** |
|
99 | + * Clears all expired (older version or revision) objects from cache |
|
100 | + * @note Be carefuly implementing this method as flush. Flush must |
|
101 | + * not interfere with other Definition types, and cleanup() |
|
102 | + * should not be repeatedly called by userland code. |
|
103 | + */ |
|
104 | + abstract public function cleanup($config); |
|
105 | 105 | |
106 | 106 | } |
107 | 107 |
@@ -38,16 +38,22 @@ |
||
38 | 38 | * @param $config Instance of HTMLPurifier_Config to test against |
39 | 39 | */ |
40 | 40 | public function isOld($key, $config) { |
41 | - if (substr_count($key, ',') < 2) return true; |
|
41 | + if (substr_count($key, ',') < 2) { |
|
42 | + return true; |
|
43 | + } |
|
42 | 44 | list($version, $hash, $revision) = explode(',', $key, 3); |
43 | 45 | $compare = version_compare($version, $config->version); |
44 | 46 | // version mismatch, is always old |
45 | - if ($compare != 0) return true; |
|
47 | + if ($compare != 0) { |
|
48 | + return true; |
|
49 | + } |
|
46 | 50 | // versions match, ids match, check revision number |
47 | 51 | if ( |
48 | 52 | $hash == $config->getBatchSerial($this->type) && |
49 | 53 | $revision < $config->get($this->type . '.DefinitionRev') |
50 | - ) return true; |
|
54 | + ) { |
|
55 | + return true; |
|
56 | + } |
|
51 | 57 | return false; |
52 | 58 | } |
53 | 59 |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | * @param Instance of HTMLPurifier_Config |
27 | 27 | */ |
28 | 28 | public function generateKey($config) { |
29 | - return $config->version . ',' . // possibly replace with function calls |
|
30 | - $config->getBatchSerial($this->type) . ',' . |
|
31 | - $config->get($this->type . '.DefinitionRev'); |
|
29 | + return $config->version.','.// possibly replace with function calls |
|
30 | + $config->getBatchSerial($this->type).','. |
|
31 | + $config->get($this->type.'.DefinitionRev'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | // versions match, ids match, check revision number |
47 | 47 | if ( |
48 | 48 | $hash == $config->getBatchSerial($this->type) && |
49 | - $revision < $config->get($this->type . '.DefinitionRev') |
|
49 | + $revision < $config->get($this->type.'.DefinitionRev') |
|
50 | 50 | ) return true; |
51 | 51 | return false; |
52 | 52 | } |
@@ -3,59 +3,59 @@ |
||
3 | 3 | class HTMLPurifier_DefinitionCache_Decorator extends HTMLPurifier_DefinitionCache |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * Cache object we are decorating |
|
8 | - */ |
|
9 | - public $cache; |
|
10 | - |
|
11 | - public function __construct() {} |
|
12 | - |
|
13 | - /** |
|
14 | - * Lazy decorator function |
|
15 | - * @param $cache Reference to cache object to decorate |
|
16 | - */ |
|
17 | - public function decorate(&$cache) { |
|
18 | - $decorator = $this->copy(); |
|
19 | - // reference is necessary for mocks in PHP 4 |
|
20 | - $decorator->cache =& $cache; |
|
21 | - $decorator->type = $cache->type; |
|
22 | - return $decorator; |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Cross-compatible clone substitute |
|
27 | - */ |
|
28 | - public function copy() { |
|
29 | - return new HTMLPurifier_DefinitionCache_Decorator(); |
|
30 | - } |
|
31 | - |
|
32 | - public function add($def, $config) { |
|
33 | - return $this->cache->add($def, $config); |
|
34 | - } |
|
35 | - |
|
36 | - public function set($def, $config) { |
|
37 | - return $this->cache->set($def, $config); |
|
38 | - } |
|
39 | - |
|
40 | - public function replace($def, $config) { |
|
41 | - return $this->cache->replace($def, $config); |
|
42 | - } |
|
43 | - |
|
44 | - public function get($config) { |
|
45 | - return $this->cache->get($config); |
|
46 | - } |
|
47 | - |
|
48 | - public function remove($config) { |
|
49 | - return $this->cache->remove($config); |
|
50 | - } |
|
51 | - |
|
52 | - public function flush($config) { |
|
53 | - return $this->cache->flush($config); |
|
54 | - } |
|
55 | - |
|
56 | - public function cleanup($config) { |
|
57 | - return $this->cache->cleanup($config); |
|
58 | - } |
|
6 | + /** |
|
7 | + * Cache object we are decorating |
|
8 | + */ |
|
9 | + public $cache; |
|
10 | + |
|
11 | + public function __construct() {} |
|
12 | + |
|
13 | + /** |
|
14 | + * Lazy decorator function |
|
15 | + * @param $cache Reference to cache object to decorate |
|
16 | + */ |
|
17 | + public function decorate(&$cache) { |
|
18 | + $decorator = $this->copy(); |
|
19 | + // reference is necessary for mocks in PHP 4 |
|
20 | + $decorator->cache =& $cache; |
|
21 | + $decorator->type = $cache->type; |
|
22 | + return $decorator; |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Cross-compatible clone substitute |
|
27 | + */ |
|
28 | + public function copy() { |
|
29 | + return new HTMLPurifier_DefinitionCache_Decorator(); |
|
30 | + } |
|
31 | + |
|
32 | + public function add($def, $config) { |
|
33 | + return $this->cache->add($def, $config); |
|
34 | + } |
|
35 | + |
|
36 | + public function set($def, $config) { |
|
37 | + return $this->cache->set($def, $config); |
|
38 | + } |
|
39 | + |
|
40 | + public function replace($def, $config) { |
|
41 | + return $this->cache->replace($def, $config); |
|
42 | + } |
|
43 | + |
|
44 | + public function get($config) { |
|
45 | + return $this->cache->get($config); |
|
46 | + } |
|
47 | + |
|
48 | + public function remove($config) { |
|
49 | + return $this->cache->remove($config); |
|
50 | + } |
|
51 | + |
|
52 | + public function flush($config) { |
|
53 | + return $this->cache->flush($config); |
|
54 | + } |
|
55 | + |
|
56 | + public function cleanup($config) { |
|
57 | + return $this->cache->cleanup($config); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | } |
61 | 61 |
@@ -17,7 +17,7 @@ |
||
17 | 17 | public function decorate(&$cache) { |
18 | 18 | $decorator = $this->copy(); |
19 | 19 | // reference is necessary for mocks in PHP 4 |
20 | - $decorator->cache =& $cache; |
|
20 | + $decorator->cache = & $cache; |
|
21 | 21 | $decorator->type = $cache->type; |
22 | 22 | return $decorator; |
23 | 23 | } |
@@ -5,38 +5,38 @@ |
||
5 | 5 | * whenever there is a cache miss. |
6 | 6 | */ |
7 | 7 | class HTMLPurifier_DefinitionCache_Decorator_Cleanup extends |
8 | - HTMLPurifier_DefinitionCache_Decorator |
|
8 | + HTMLPurifier_DefinitionCache_Decorator |
|
9 | 9 | { |
10 | 10 | |
11 | - public $name = 'Cleanup'; |
|
12 | - |
|
13 | - public function copy() { |
|
14 | - return new HTMLPurifier_DefinitionCache_Decorator_Cleanup(); |
|
15 | - } |
|
16 | - |
|
17 | - public function add($def, $config) { |
|
18 | - $status = parent::add($def, $config); |
|
19 | - if (!$status) parent::cleanup($config); |
|
20 | - return $status; |
|
21 | - } |
|
22 | - |
|
23 | - public function set($def, $config) { |
|
24 | - $status = parent::set($def, $config); |
|
25 | - if (!$status) parent::cleanup($config); |
|
26 | - return $status; |
|
27 | - } |
|
28 | - |
|
29 | - public function replace($def, $config) { |
|
30 | - $status = parent::replace($def, $config); |
|
31 | - if (!$status) parent::cleanup($config); |
|
32 | - return $status; |
|
33 | - } |
|
34 | - |
|
35 | - public function get($config) { |
|
36 | - $ret = parent::get($config); |
|
37 | - if (!$ret) parent::cleanup($config); |
|
38 | - return $ret; |
|
39 | - } |
|
11 | + public $name = 'Cleanup'; |
|
12 | + |
|
13 | + public function copy() { |
|
14 | + return new HTMLPurifier_DefinitionCache_Decorator_Cleanup(); |
|
15 | + } |
|
16 | + |
|
17 | + public function add($def, $config) { |
|
18 | + $status = parent::add($def, $config); |
|
19 | + if (!$status) parent::cleanup($config); |
|
20 | + return $status; |
|
21 | + } |
|
22 | + |
|
23 | + public function set($def, $config) { |
|
24 | + $status = parent::set($def, $config); |
|
25 | + if (!$status) parent::cleanup($config); |
|
26 | + return $status; |
|
27 | + } |
|
28 | + |
|
29 | + public function replace($def, $config) { |
|
30 | + $status = parent::replace($def, $config); |
|
31 | + if (!$status) parent::cleanup($config); |
|
32 | + return $status; |
|
33 | + } |
|
34 | + |
|
35 | + public function get($config) { |
|
36 | + $ret = parent::get($config); |
|
37 | + if (!$ret) parent::cleanup($config); |
|
38 | + return $ret; |
|
39 | + } |
|
40 | 40 | |
41 | 41 | } |
42 | 42 |
@@ -16,25 +16,33 @@ |
||
16 | 16 | |
17 | 17 | public function add($def, $config) { |
18 | 18 | $status = parent::add($def, $config); |
19 | - if (!$status) parent::cleanup($config); |
|
19 | + if (!$status) { |
|
20 | + parent::cleanup($config); |
|
21 | + } |
|
20 | 22 | return $status; |
21 | 23 | } |
22 | 24 | |
23 | 25 | public function set($def, $config) { |
24 | 26 | $status = parent::set($def, $config); |
25 | - if (!$status) parent::cleanup($config); |
|
27 | + if (!$status) { |
|
28 | + parent::cleanup($config); |
|
29 | + } |
|
26 | 30 | return $status; |
27 | 31 | } |
28 | 32 | |
29 | 33 | public function replace($def, $config) { |
30 | 34 | $status = parent::replace($def, $config); |
31 | - if (!$status) parent::cleanup($config); |
|
35 | + if (!$status) { |
|
36 | + parent::cleanup($config); |
|
37 | + } |
|
32 | 38 | return $status; |
33 | 39 | } |
34 | 40 | |
35 | 41 | public function get($config) { |
36 | 42 | $ret = parent::get($config); |
37 | - if (!$ret) parent::cleanup($config); |
|
43 | + if (!$ret) { |
|
44 | + parent::cleanup($config); |
|
45 | + } |
|
38 | 46 | return $ret; |
39 | 47 | } |
40 | 48 |
@@ -6,40 +6,40 @@ |
||
6 | 6 | * there are lots of configuration objects floating around. |
7 | 7 | */ |
8 | 8 | class HTMLPurifier_DefinitionCache_Decorator_Memory extends |
9 | - HTMLPurifier_DefinitionCache_Decorator |
|
9 | + HTMLPurifier_DefinitionCache_Decorator |
|
10 | 10 | { |
11 | 11 | |
12 | - protected $definitions; |
|
13 | - public $name = 'Memory'; |
|
14 | - |
|
15 | - public function copy() { |
|
16 | - return new HTMLPurifier_DefinitionCache_Decorator_Memory(); |
|
17 | - } |
|
18 | - |
|
19 | - public function add($def, $config) { |
|
20 | - $status = parent::add($def, $config); |
|
21 | - if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
22 | - return $status; |
|
23 | - } |
|
24 | - |
|
25 | - public function set($def, $config) { |
|
26 | - $status = parent::set($def, $config); |
|
27 | - if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
28 | - return $status; |
|
29 | - } |
|
30 | - |
|
31 | - public function replace($def, $config) { |
|
32 | - $status = parent::replace($def, $config); |
|
33 | - if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
34 | - return $status; |
|
35 | - } |
|
36 | - |
|
37 | - public function get($config) { |
|
38 | - $key = $this->generateKey($config); |
|
39 | - if (isset($this->definitions[$key])) return $this->definitions[$key]; |
|
40 | - $this->definitions[$key] = parent::get($config); |
|
41 | - return $this->definitions[$key]; |
|
42 | - } |
|
12 | + protected $definitions; |
|
13 | + public $name = 'Memory'; |
|
14 | + |
|
15 | + public function copy() { |
|
16 | + return new HTMLPurifier_DefinitionCache_Decorator_Memory(); |
|
17 | + } |
|
18 | + |
|
19 | + public function add($def, $config) { |
|
20 | + $status = parent::add($def, $config); |
|
21 | + if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
22 | + return $status; |
|
23 | + } |
|
24 | + |
|
25 | + public function set($def, $config) { |
|
26 | + $status = parent::set($def, $config); |
|
27 | + if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
28 | + return $status; |
|
29 | + } |
|
30 | + |
|
31 | + public function replace($def, $config) { |
|
32 | + $status = parent::replace($def, $config); |
|
33 | + if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
34 | + return $status; |
|
35 | + } |
|
36 | + |
|
37 | + public function get($config) { |
|
38 | + $key = $this->generateKey($config); |
|
39 | + if (isset($this->definitions[$key])) return $this->definitions[$key]; |
|
40 | + $this->definitions[$key] = parent::get($config); |
|
41 | + return $this->definitions[$key]; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | } |
45 | 45 |
@@ -18,25 +18,33 @@ |
||
18 | 18 | |
19 | 19 | public function add($def, $config) { |
20 | 20 | $status = parent::add($def, $config); |
21 | - if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
21 | + if ($status) { |
|
22 | + $this->definitions[$this->generateKey($config)] = $def; |
|
23 | + } |
|
22 | 24 | return $status; |
23 | 25 | } |
24 | 26 | |
25 | 27 | public function set($def, $config) { |
26 | 28 | $status = parent::set($def, $config); |
27 | - if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
29 | + if ($status) { |
|
30 | + $this->definitions[$this->generateKey($config)] = $def; |
|
31 | + } |
|
28 | 32 | return $status; |
29 | 33 | } |
30 | 34 | |
31 | 35 | public function replace($def, $config) { |
32 | 36 | $status = parent::replace($def, $config); |
33 | - if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
37 | + if ($status) { |
|
38 | + $this->definitions[$this->generateKey($config)] = $def; |
|
39 | + } |
|
34 | 40 | return $status; |
35 | 41 | } |
36 | 42 | |
37 | 43 | public function get($config) { |
38 | 44 | $key = $this->generateKey($config); |
39 | - if (isset($this->definitions[$key])) return $this->definitions[$key]; |
|
45 | + if (isset($this->definitions[$key])) { |
|
46 | + return $this->definitions[$key]; |
|
47 | + } |
|
40 | 48 | $this->definitions[$key] = parent::get($config); |
41 | 49 | return $this->definitions[$key]; |
42 | 50 | } |
@@ -6,33 +6,33 @@ |
||
6 | 6 | class HTMLPurifier_DefinitionCache_Null extends HTMLPurifier_DefinitionCache |
7 | 7 | { |
8 | 8 | |
9 | - public function add($def, $config) { |
|
10 | - return false; |
|
11 | - } |
|
9 | + public function add($def, $config) { |
|
10 | + return false; |
|
11 | + } |
|
12 | 12 | |
13 | - public function set($def, $config) { |
|
14 | - return false; |
|
15 | - } |
|
13 | + public function set($def, $config) { |
|
14 | + return false; |
|
15 | + } |
|
16 | 16 | |
17 | - public function replace($def, $config) { |
|
18 | - return false; |
|
19 | - } |
|
17 | + public function replace($def, $config) { |
|
18 | + return false; |
|
19 | + } |
|
20 | 20 | |
21 | - public function remove($config) { |
|
22 | - return false; |
|
23 | - } |
|
21 | + public function remove($config) { |
|
22 | + return false; |
|
23 | + } |
|
24 | 24 | |
25 | - public function get($config) { |
|
26 | - return false; |
|
27 | - } |
|
25 | + public function get($config) { |
|
26 | + return false; |
|
27 | + } |
|
28 | 28 | |
29 | - public function flush($config) { |
|
30 | - return false; |
|
31 | - } |
|
29 | + public function flush($config) { |
|
30 | + return false; |
|
31 | + } |
|
32 | 32 | |
33 | - public function cleanup($config) { |
|
34 | - return false; |
|
35 | - } |
|
33 | + public function cleanup($config) { |
|
34 | + return false; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | } |
38 | 38 |
@@ -1,190 +1,190 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class HTMLPurifier_DefinitionCache_Serializer extends |
4 | - HTMLPurifier_DefinitionCache |
|
4 | + HTMLPurifier_DefinitionCache |
|
5 | 5 | { |
6 | 6 | |
7 | - public function add($def, $config) { |
|
8 | - if (!$this->checkDefType($def)) return; |
|
9 | - $file = $this->generateFilePath($config); |
|
10 | - if (file_exists($file)) return false; |
|
11 | - if (!$this->_prepareDir($config)) return false; |
|
12 | - return $this->_write($file, serialize($def), $config); |
|
13 | - } |
|
14 | - |
|
15 | - public function set($def, $config) { |
|
16 | - if (!$this->checkDefType($def)) return; |
|
17 | - $file = $this->generateFilePath($config); |
|
18 | - if (!$this->_prepareDir($config)) return false; |
|
19 | - return $this->_write($file, serialize($def), $config); |
|
20 | - } |
|
21 | - |
|
22 | - public function replace($def, $config) { |
|
23 | - if (!$this->checkDefType($def)) return; |
|
24 | - $file = $this->generateFilePath($config); |
|
25 | - if (!file_exists($file)) return false; |
|
26 | - if (!$this->_prepareDir($config)) return false; |
|
27 | - return $this->_write($file, serialize($def), $config); |
|
28 | - } |
|
29 | - |
|
30 | - public function get($config) { |
|
31 | - $file = $this->generateFilePath($config); |
|
32 | - if (!file_exists($file)) return false; |
|
33 | - return unserialize(file_get_contents($file)); |
|
34 | - } |
|
35 | - |
|
36 | - public function remove($config) { |
|
37 | - $file = $this->generateFilePath($config); |
|
38 | - if (!file_exists($file)) return false; |
|
39 | - return unlink($file); |
|
40 | - } |
|
41 | - |
|
42 | - public function flush($config) { |
|
43 | - if (!$this->_prepareDir($config)) return false; |
|
44 | - $dir = $this->generateDirectoryPath($config); |
|
45 | - $dh = opendir($dir); |
|
46 | - while (false !== ($filename = readdir($dh))) { |
|
47 | - if (empty($filename)) continue; |
|
48 | - if ($filename[0] === '.') continue; |
|
49 | - unlink($dir . '/' . $filename); |
|
50 | - } |
|
51 | - } |
|
52 | - |
|
53 | - public function cleanup($config) { |
|
54 | - if (!$this->_prepareDir($config)) return false; |
|
55 | - $dir = $this->generateDirectoryPath($config); |
|
56 | - $dh = opendir($dir); |
|
57 | - while (false !== ($filename = readdir($dh))) { |
|
58 | - if (empty($filename)) continue; |
|
59 | - if ($filename[0] === '.') continue; |
|
60 | - $key = substr($filename, 0, strlen($filename) - 4); |
|
61 | - if ($this->isOld($key, $config)) unlink($dir . '/' . $filename); |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Generates the file path to the serial file corresponding to |
|
67 | - * the configuration and definition name |
|
68 | - * @todo Make protected |
|
69 | - */ |
|
70 | - public function generateFilePath($config) { |
|
71 | - $key = $this->generateKey($config); |
|
72 | - return $this->generateDirectoryPath($config) . '/' . $key . '.ser'; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Generates the path to the directory contain this cache's serial files |
|
77 | - * @note No trailing slash |
|
78 | - * @todo Make protected |
|
79 | - */ |
|
80 | - public function generateDirectoryPath($config) { |
|
81 | - $base = $this->generateBaseDirectoryPath($config); |
|
82 | - return $base . '/' . $this->type; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Generates path to base directory that contains all definition type |
|
87 | - * serials |
|
88 | - * @todo Make protected |
|
89 | - */ |
|
90 | - public function generateBaseDirectoryPath($config) { |
|
91 | - $base = $config->get('Cache.SerializerPath'); |
|
92 | - $base = is_null($base) ? HTMLPURIFIER_PREFIX . '/HTMLPurifier/DefinitionCache/Serializer' : $base; |
|
93 | - return $base; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Convenience wrapper function for file_put_contents |
|
98 | - * @param $file File name to write to |
|
99 | - * @param $data Data to write into file |
|
100 | - * @param $config Config object |
|
101 | - * @return Number of bytes written if success, or false if failure. |
|
102 | - */ |
|
103 | - private function _write($file, $data, $config) { |
|
104 | - $result = file_put_contents($file, $data, LOCK_EX); |
|
105 | - if ($result !== false) { |
|
106 | - // set permissions of the new file (no execute) |
|
107 | - $chmod = $config->get('Cache.SerializerPermissions'); |
|
108 | - if (!$chmod) { |
|
109 | - $chmod = 0644; // invalid config or simpletest |
|
110 | - } |
|
111 | - $chmod = $chmod & 0666; |
|
112 | - chmod($file, $chmod); |
|
113 | - } |
|
114 | - return $result; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Prepares the directory that this type stores the serials in |
|
119 | - * @param $config Config object |
|
120 | - * @return True if successful |
|
121 | - */ |
|
122 | - private function _prepareDir($config) { |
|
123 | - $directory = $this->generateDirectoryPath($config); |
|
124 | - $chmod = $config->get('Cache.SerializerPermissions'); |
|
125 | - if (!$chmod) { |
|
126 | - $chmod = 0755; // invalid config or simpletest |
|
127 | - } |
|
128 | - if (!is_dir($directory)) { |
|
129 | - $base = $this->generateBaseDirectoryPath($config); |
|
130 | - if (!is_dir($base)) { |
|
131 | - trigger_error('Base directory '.$base.' does not exist, |
|
7 | + public function add($def, $config) { |
|
8 | + if (!$this->checkDefType($def)) return; |
|
9 | + $file = $this->generateFilePath($config); |
|
10 | + if (file_exists($file)) return false; |
|
11 | + if (!$this->_prepareDir($config)) return false; |
|
12 | + return $this->_write($file, serialize($def), $config); |
|
13 | + } |
|
14 | + |
|
15 | + public function set($def, $config) { |
|
16 | + if (!$this->checkDefType($def)) return; |
|
17 | + $file = $this->generateFilePath($config); |
|
18 | + if (!$this->_prepareDir($config)) return false; |
|
19 | + return $this->_write($file, serialize($def), $config); |
|
20 | + } |
|
21 | + |
|
22 | + public function replace($def, $config) { |
|
23 | + if (!$this->checkDefType($def)) return; |
|
24 | + $file = $this->generateFilePath($config); |
|
25 | + if (!file_exists($file)) return false; |
|
26 | + if (!$this->_prepareDir($config)) return false; |
|
27 | + return $this->_write($file, serialize($def), $config); |
|
28 | + } |
|
29 | + |
|
30 | + public function get($config) { |
|
31 | + $file = $this->generateFilePath($config); |
|
32 | + if (!file_exists($file)) return false; |
|
33 | + return unserialize(file_get_contents($file)); |
|
34 | + } |
|
35 | + |
|
36 | + public function remove($config) { |
|
37 | + $file = $this->generateFilePath($config); |
|
38 | + if (!file_exists($file)) return false; |
|
39 | + return unlink($file); |
|
40 | + } |
|
41 | + |
|
42 | + public function flush($config) { |
|
43 | + if (!$this->_prepareDir($config)) return false; |
|
44 | + $dir = $this->generateDirectoryPath($config); |
|
45 | + $dh = opendir($dir); |
|
46 | + while (false !== ($filename = readdir($dh))) { |
|
47 | + if (empty($filename)) continue; |
|
48 | + if ($filename[0] === '.') continue; |
|
49 | + unlink($dir . '/' . $filename); |
|
50 | + } |
|
51 | + } |
|
52 | + |
|
53 | + public function cleanup($config) { |
|
54 | + if (!$this->_prepareDir($config)) return false; |
|
55 | + $dir = $this->generateDirectoryPath($config); |
|
56 | + $dh = opendir($dir); |
|
57 | + while (false !== ($filename = readdir($dh))) { |
|
58 | + if (empty($filename)) continue; |
|
59 | + if ($filename[0] === '.') continue; |
|
60 | + $key = substr($filename, 0, strlen($filename) - 4); |
|
61 | + if ($this->isOld($key, $config)) unlink($dir . '/' . $filename); |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Generates the file path to the serial file corresponding to |
|
67 | + * the configuration and definition name |
|
68 | + * @todo Make protected |
|
69 | + */ |
|
70 | + public function generateFilePath($config) { |
|
71 | + $key = $this->generateKey($config); |
|
72 | + return $this->generateDirectoryPath($config) . '/' . $key . '.ser'; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Generates the path to the directory contain this cache's serial files |
|
77 | + * @note No trailing slash |
|
78 | + * @todo Make protected |
|
79 | + */ |
|
80 | + public function generateDirectoryPath($config) { |
|
81 | + $base = $this->generateBaseDirectoryPath($config); |
|
82 | + return $base . '/' . $this->type; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Generates path to base directory that contains all definition type |
|
87 | + * serials |
|
88 | + * @todo Make protected |
|
89 | + */ |
|
90 | + public function generateBaseDirectoryPath($config) { |
|
91 | + $base = $config->get('Cache.SerializerPath'); |
|
92 | + $base = is_null($base) ? HTMLPURIFIER_PREFIX . '/HTMLPurifier/DefinitionCache/Serializer' : $base; |
|
93 | + return $base; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Convenience wrapper function for file_put_contents |
|
98 | + * @param $file File name to write to |
|
99 | + * @param $data Data to write into file |
|
100 | + * @param $config Config object |
|
101 | + * @return Number of bytes written if success, or false if failure. |
|
102 | + */ |
|
103 | + private function _write($file, $data, $config) { |
|
104 | + $result = file_put_contents($file, $data, LOCK_EX); |
|
105 | + if ($result !== false) { |
|
106 | + // set permissions of the new file (no execute) |
|
107 | + $chmod = $config->get('Cache.SerializerPermissions'); |
|
108 | + if (!$chmod) { |
|
109 | + $chmod = 0644; // invalid config or simpletest |
|
110 | + } |
|
111 | + $chmod = $chmod & 0666; |
|
112 | + chmod($file, $chmod); |
|
113 | + } |
|
114 | + return $result; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Prepares the directory that this type stores the serials in |
|
119 | + * @param $config Config object |
|
120 | + * @return True if successful |
|
121 | + */ |
|
122 | + private function _prepareDir($config) { |
|
123 | + $directory = $this->generateDirectoryPath($config); |
|
124 | + $chmod = $config->get('Cache.SerializerPermissions'); |
|
125 | + if (!$chmod) { |
|
126 | + $chmod = 0755; // invalid config or simpletest |
|
127 | + } |
|
128 | + if (!is_dir($directory)) { |
|
129 | + $base = $this->generateBaseDirectoryPath($config); |
|
130 | + if (!is_dir($base)) { |
|
131 | + trigger_error('Base directory '.$base.' does not exist, |
|
132 | 132 | please create or change using %Cache.SerializerPath', |
133 | - E_USER_WARNING); |
|
134 | - return false; |
|
135 | - } elseif (!$this->_testPermissions($base, $chmod)) { |
|
136 | - return false; |
|
137 | - } |
|
138 | - $old = umask(0000); |
|
139 | - mkdir($directory, $chmod); |
|
140 | - umask($old); |
|
141 | - } elseif (!$this->_testPermissions($directory, $chmod)) { |
|
142 | - return false; |
|
143 | - } |
|
144 | - return true; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Tests permissions on a directory and throws out friendly |
|
149 | - * error messages and attempts to chmod it itself if possible |
|
150 | - * @param $dir Directory path |
|
151 | - * @param $chmod Permissions |
|
152 | - * @return True if directory writable |
|
153 | - */ |
|
154 | - private function _testPermissions($dir, $chmod) { |
|
155 | - // early abort, if it is writable, everything is hunky-dory |
|
156 | - if (is_writable($dir)) return true; |
|
157 | - if (!is_dir($dir)) { |
|
158 | - // generally, you'll want to handle this beforehand |
|
159 | - // so a more specific error message can be given |
|
160 | - trigger_error('Directory '.$dir.' does not exist', |
|
161 | - E_USER_WARNING); |
|
162 | - return false; |
|
163 | - } |
|
164 | - if (function_exists('posix_getuid')) { |
|
165 | - // POSIX system, we can give more specific advice |
|
166 | - if (fileowner($dir) === posix_getuid()) { |
|
167 | - // we can chmod it ourselves |
|
168 | - $chmod = $chmod | 0700; |
|
169 | - if (chmod($dir, $chmod)) return true; |
|
170 | - } elseif (filegroup($dir) === posix_getgid()) { |
|
171 | - $chmod = $chmod | 0070; |
|
172 | - } else { |
|
173 | - // PHP's probably running as nobody, so we'll |
|
174 | - // need to give global permissions |
|
175 | - $chmod = $chmod | 0777; |
|
176 | - } |
|
177 | - trigger_error('Directory '.$dir.' not writable, '. |
|
178 | - 'please chmod to ' . decoct($chmod), |
|
179 | - E_USER_WARNING); |
|
180 | - } else { |
|
181 | - // generic error message |
|
182 | - trigger_error('Directory '.$dir.' not writable, '. |
|
183 | - 'please alter file permissions', |
|
184 | - E_USER_WARNING); |
|
185 | - } |
|
186 | - return false; |
|
187 | - } |
|
133 | + E_USER_WARNING); |
|
134 | + return false; |
|
135 | + } elseif (!$this->_testPermissions($base, $chmod)) { |
|
136 | + return false; |
|
137 | + } |
|
138 | + $old = umask(0000); |
|
139 | + mkdir($directory, $chmod); |
|
140 | + umask($old); |
|
141 | + } elseif (!$this->_testPermissions($directory, $chmod)) { |
|
142 | + return false; |
|
143 | + } |
|
144 | + return true; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Tests permissions on a directory and throws out friendly |
|
149 | + * error messages and attempts to chmod it itself if possible |
|
150 | + * @param $dir Directory path |
|
151 | + * @param $chmod Permissions |
|
152 | + * @return True if directory writable |
|
153 | + */ |
|
154 | + private function _testPermissions($dir, $chmod) { |
|
155 | + // early abort, if it is writable, everything is hunky-dory |
|
156 | + if (is_writable($dir)) return true; |
|
157 | + if (!is_dir($dir)) { |
|
158 | + // generally, you'll want to handle this beforehand |
|
159 | + // so a more specific error message can be given |
|
160 | + trigger_error('Directory '.$dir.' does not exist', |
|
161 | + E_USER_WARNING); |
|
162 | + return false; |
|
163 | + } |
|
164 | + if (function_exists('posix_getuid')) { |
|
165 | + // POSIX system, we can give more specific advice |
|
166 | + if (fileowner($dir) === posix_getuid()) { |
|
167 | + // we can chmod it ourselves |
|
168 | + $chmod = $chmod | 0700; |
|
169 | + if (chmod($dir, $chmod)) return true; |
|
170 | + } elseif (filegroup($dir) === posix_getgid()) { |
|
171 | + $chmod = $chmod | 0070; |
|
172 | + } else { |
|
173 | + // PHP's probably running as nobody, so we'll |
|
174 | + // need to give global permissions |
|
175 | + $chmod = $chmod | 0777; |
|
176 | + } |
|
177 | + trigger_error('Directory '.$dir.' not writable, '. |
|
178 | + 'please chmod to ' . decoct($chmod), |
|
179 | + E_USER_WARNING); |
|
180 | + } else { |
|
181 | + // generic error message |
|
182 | + trigger_error('Directory '.$dir.' not writable, '. |
|
183 | + 'please alter file permissions', |
|
184 | + E_USER_WARNING); |
|
185 | + } |
|
186 | + return false; |
|
187 | + } |
|
188 | 188 | |
189 | 189 | } |
190 | 190 |
@@ -5,60 +5,94 @@ discard block |
||
5 | 5 | { |
6 | 6 | |
7 | 7 | public function add($def, $config) { |
8 | - if (!$this->checkDefType($def)) return; |
|
8 | + if (!$this->checkDefType($def)) { |
|
9 | + return; |
|
10 | + } |
|
9 | 11 | $file = $this->generateFilePath($config); |
10 | - if (file_exists($file)) return false; |
|
11 | - if (!$this->_prepareDir($config)) return false; |
|
12 | + if (file_exists($file)) { |
|
13 | + return false; |
|
14 | + } |
|
15 | + if (!$this->_prepareDir($config)) { |
|
16 | + return false; |
|
17 | + } |
|
12 | 18 | return $this->_write($file, serialize($def), $config); |
13 | 19 | } |
14 | 20 | |
15 | 21 | public function set($def, $config) { |
16 | - if (!$this->checkDefType($def)) return; |
|
22 | + if (!$this->checkDefType($def)) { |
|
23 | + return; |
|
24 | + } |
|
17 | 25 | $file = $this->generateFilePath($config); |
18 | - if (!$this->_prepareDir($config)) return false; |
|
26 | + if (!$this->_prepareDir($config)) { |
|
27 | + return false; |
|
28 | + } |
|
19 | 29 | return $this->_write($file, serialize($def), $config); |
20 | 30 | } |
21 | 31 | |
22 | 32 | public function replace($def, $config) { |
23 | - if (!$this->checkDefType($def)) return; |
|
33 | + if (!$this->checkDefType($def)) { |
|
34 | + return; |
|
35 | + } |
|
24 | 36 | $file = $this->generateFilePath($config); |
25 | - if (!file_exists($file)) return false; |
|
26 | - if (!$this->_prepareDir($config)) return false; |
|
37 | + if (!file_exists($file)) { |
|
38 | + return false; |
|
39 | + } |
|
40 | + if (!$this->_prepareDir($config)) { |
|
41 | + return false; |
|
42 | + } |
|
27 | 43 | return $this->_write($file, serialize($def), $config); |
28 | 44 | } |
29 | 45 | |
30 | 46 | public function get($config) { |
31 | 47 | $file = $this->generateFilePath($config); |
32 | - if (!file_exists($file)) return false; |
|
48 | + if (!file_exists($file)) { |
|
49 | + return false; |
|
50 | + } |
|
33 | 51 | return unserialize(file_get_contents($file)); |
34 | 52 | } |
35 | 53 | |
36 | 54 | public function remove($config) { |
37 | 55 | $file = $this->generateFilePath($config); |
38 | - if (!file_exists($file)) return false; |
|
56 | + if (!file_exists($file)) { |
|
57 | + return false; |
|
58 | + } |
|
39 | 59 | return unlink($file); |
40 | 60 | } |
41 | 61 | |
42 | 62 | public function flush($config) { |
43 | - if (!$this->_prepareDir($config)) return false; |
|
63 | + if (!$this->_prepareDir($config)) { |
|
64 | + return false; |
|
65 | + } |
|
44 | 66 | $dir = $this->generateDirectoryPath($config); |
45 | 67 | $dh = opendir($dir); |
46 | 68 | while (false !== ($filename = readdir($dh))) { |
47 | - if (empty($filename)) continue; |
|
48 | - if ($filename[0] === '.') continue; |
|
69 | + if (empty($filename)) { |
|
70 | + continue; |
|
71 | + } |
|
72 | + if ($filename[0] === '.') { |
|
73 | + continue; |
|
74 | + } |
|
49 | 75 | unlink($dir . '/' . $filename); |
50 | 76 | } |
51 | 77 | } |
52 | 78 | |
53 | 79 | public function cleanup($config) { |
54 | - if (!$this->_prepareDir($config)) return false; |
|
80 | + if (!$this->_prepareDir($config)) { |
|
81 | + return false; |
|
82 | + } |
|
55 | 83 | $dir = $this->generateDirectoryPath($config); |
56 | 84 | $dh = opendir($dir); |
57 | 85 | while (false !== ($filename = readdir($dh))) { |
58 | - if (empty($filename)) continue; |
|
59 | - if ($filename[0] === '.') continue; |
|
86 | + if (empty($filename)) { |
|
87 | + continue; |
|
88 | + } |
|
89 | + if ($filename[0] === '.') { |
|
90 | + continue; |
|
91 | + } |
|
60 | 92 | $key = substr($filename, 0, strlen($filename) - 4); |
61 | - if ($this->isOld($key, $config)) unlink($dir . '/' . $filename); |
|
93 | + if ($this->isOld($key, $config)) { |
|
94 | + unlink($dir . '/' . $filename); |
|
95 | + } |
|
62 | 96 | } |
63 | 97 | } |
64 | 98 | |
@@ -153,7 +187,9 @@ discard block |
||
153 | 187 | */ |
154 | 188 | private function _testPermissions($dir, $chmod) { |
155 | 189 | // early abort, if it is writable, everything is hunky-dory |
156 | - if (is_writable($dir)) return true; |
|
190 | + if (is_writable($dir)) { |
|
191 | + return true; |
|
192 | + } |
|
157 | 193 | if (!is_dir($dir)) { |
158 | 194 | // generally, you'll want to handle this beforehand |
159 | 195 | // so a more specific error message can be given |
@@ -166,7 +202,9 @@ discard block |
||
166 | 202 | if (fileowner($dir) === posix_getuid()) { |
167 | 203 | // we can chmod it ourselves |
168 | 204 | $chmod = $chmod | 0700; |
169 | - if (chmod($dir, $chmod)) return true; |
|
205 | + if (chmod($dir, $chmod)) { |
|
206 | + return true; |
|
207 | + } |
|
170 | 208 | } elseif (filegroup($dir) === posix_getgid()) { |
171 | 209 | $chmod = $chmod | 0070; |
172 | 210 | } else { |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | while (false !== ($filename = readdir($dh))) { |
47 | 47 | if (empty($filename)) continue; |
48 | 48 | if ($filename[0] === '.') continue; |
49 | - unlink($dir . '/' . $filename); |
|
49 | + unlink($dir.'/'.$filename); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | if (empty($filename)) continue; |
59 | 59 | if ($filename[0] === '.') continue; |
60 | 60 | $key = substr($filename, 0, strlen($filename) - 4); |
61 | - if ($this->isOld($key, $config)) unlink($dir . '/' . $filename); |
|
61 | + if ($this->isOld($key, $config)) unlink($dir.'/'.$filename); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function generateFilePath($config) { |
71 | 71 | $key = $this->generateKey($config); |
72 | - return $this->generateDirectoryPath($config) . '/' . $key . '.ser'; |
|
72 | + return $this->generateDirectoryPath($config).'/'.$key.'.ser'; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function generateDirectoryPath($config) { |
81 | 81 | $base = $this->generateBaseDirectoryPath($config); |
82 | - return $base . '/' . $this->type; |
|
82 | + return $base.'/'.$this->type; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | $chmod = $chmod | 0777; |
176 | 176 | } |
177 | 177 | trigger_error('Directory '.$dir.' not writable, '. |
178 | - 'please chmod to ' . decoct($chmod), |
|
178 | + 'please chmod to '.decoct($chmod), |
|
179 | 179 | E_USER_WARNING); |
180 | 180 | } else { |
181 | 181 | // generic error message |
@@ -6,85 +6,85 @@ |
||
6 | 6 | class HTMLPurifier_DefinitionCacheFactory |
7 | 7 | { |
8 | 8 | |
9 | - protected $caches = array('Serializer' => array()); |
|
10 | - protected $implementations = array(); |
|
11 | - protected $decorators = array(); |
|
9 | + protected $caches = array('Serializer' => array()); |
|
10 | + protected $implementations = array(); |
|
11 | + protected $decorators = array(); |
|
12 | 12 | |
13 | - /** |
|
14 | - * Initialize default decorators |
|
15 | - */ |
|
16 | - public function setup() { |
|
17 | - $this->addDecorator('Cleanup'); |
|
18 | - } |
|
13 | + /** |
|
14 | + * Initialize default decorators |
|
15 | + */ |
|
16 | + public function setup() { |
|
17 | + $this->addDecorator('Cleanup'); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * Retrieves an instance of global definition cache factory. |
|
22 | - */ |
|
23 | - public static function instance($prototype = null) { |
|
24 | - static $instance; |
|
25 | - if ($prototype !== null) { |
|
26 | - $instance = $prototype; |
|
27 | - } elseif ($instance === null || $prototype === true) { |
|
28 | - $instance = new HTMLPurifier_DefinitionCacheFactory(); |
|
29 | - $instance->setup(); |
|
30 | - } |
|
31 | - return $instance; |
|
32 | - } |
|
20 | + /** |
|
21 | + * Retrieves an instance of global definition cache factory. |
|
22 | + */ |
|
23 | + public static function instance($prototype = null) { |
|
24 | + static $instance; |
|
25 | + if ($prototype !== null) { |
|
26 | + $instance = $prototype; |
|
27 | + } elseif ($instance === null || $prototype === true) { |
|
28 | + $instance = new HTMLPurifier_DefinitionCacheFactory(); |
|
29 | + $instance->setup(); |
|
30 | + } |
|
31 | + return $instance; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Registers a new definition cache object |
|
36 | - * @param $short Short name of cache object, for reference |
|
37 | - * @param $long Full class name of cache object, for construction |
|
38 | - */ |
|
39 | - public function register($short, $long) { |
|
40 | - $this->implementations[$short] = $long; |
|
41 | - } |
|
34 | + /** |
|
35 | + * Registers a new definition cache object |
|
36 | + * @param $short Short name of cache object, for reference |
|
37 | + * @param $long Full class name of cache object, for construction |
|
38 | + */ |
|
39 | + public function register($short, $long) { |
|
40 | + $this->implementations[$short] = $long; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Factory method that creates a cache object based on configuration |
|
45 | - * @param $name Name of definitions handled by cache |
|
46 | - * @param $config Instance of HTMLPurifier_Config |
|
47 | - */ |
|
48 | - public function create($type, $config) { |
|
49 | - $method = $config->get('Cache.DefinitionImpl'); |
|
50 | - if ($method === null) { |
|
51 | - return new HTMLPurifier_DefinitionCache_Null($type); |
|
52 | - } |
|
53 | - if (!empty($this->caches[$method][$type])) { |
|
54 | - return $this->caches[$method][$type]; |
|
55 | - } |
|
56 | - if ( |
|
57 | - isset($this->implementations[$method]) && |
|
58 | - class_exists($class = $this->implementations[$method], false) |
|
59 | - ) { |
|
60 | - $cache = new $class($type); |
|
61 | - } else { |
|
62 | - if ($method != 'Serializer') { |
|
63 | - trigger_error("Unrecognized DefinitionCache $method, using Serializer instead", E_USER_WARNING); |
|
64 | - } |
|
65 | - $cache = new HTMLPurifier_DefinitionCache_Serializer($type); |
|
66 | - } |
|
67 | - foreach ($this->decorators as $decorator) { |
|
68 | - $new_cache = $decorator->decorate($cache); |
|
69 | - // prevent infinite recursion in PHP 4 |
|
70 | - unset($cache); |
|
71 | - $cache = $new_cache; |
|
72 | - } |
|
73 | - $this->caches[$method][$type] = $cache; |
|
74 | - return $this->caches[$method][$type]; |
|
75 | - } |
|
43 | + /** |
|
44 | + * Factory method that creates a cache object based on configuration |
|
45 | + * @param $name Name of definitions handled by cache |
|
46 | + * @param $config Instance of HTMLPurifier_Config |
|
47 | + */ |
|
48 | + public function create($type, $config) { |
|
49 | + $method = $config->get('Cache.DefinitionImpl'); |
|
50 | + if ($method === null) { |
|
51 | + return new HTMLPurifier_DefinitionCache_Null($type); |
|
52 | + } |
|
53 | + if (!empty($this->caches[$method][$type])) { |
|
54 | + return $this->caches[$method][$type]; |
|
55 | + } |
|
56 | + if ( |
|
57 | + isset($this->implementations[$method]) && |
|
58 | + class_exists($class = $this->implementations[$method], false) |
|
59 | + ) { |
|
60 | + $cache = new $class($type); |
|
61 | + } else { |
|
62 | + if ($method != 'Serializer') { |
|
63 | + trigger_error("Unrecognized DefinitionCache $method, using Serializer instead", E_USER_WARNING); |
|
64 | + } |
|
65 | + $cache = new HTMLPurifier_DefinitionCache_Serializer($type); |
|
66 | + } |
|
67 | + foreach ($this->decorators as $decorator) { |
|
68 | + $new_cache = $decorator->decorate($cache); |
|
69 | + // prevent infinite recursion in PHP 4 |
|
70 | + unset($cache); |
|
71 | + $cache = $new_cache; |
|
72 | + } |
|
73 | + $this->caches[$method][$type] = $cache; |
|
74 | + return $this->caches[$method][$type]; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Registers a decorator to add to all new cache objects |
|
79 | - * @param |
|
80 | - */ |
|
81 | - public function addDecorator($decorator) { |
|
82 | - if (is_string($decorator)) { |
|
83 | - $class = "HTMLPurifier_DefinitionCache_Decorator_$decorator"; |
|
84 | - $decorator = new $class; |
|
85 | - } |
|
86 | - $this->decorators[$decorator->name] = $decorator; |
|
87 | - } |
|
77 | + /** |
|
78 | + * Registers a decorator to add to all new cache objects |
|
79 | + * @param |
|
80 | + */ |
|
81 | + public function addDecorator($decorator) { |
|
82 | + if (is_string($decorator)) { |
|
83 | + $class = "HTMLPurifier_DefinitionCache_Decorator_$decorator"; |
|
84 | + $decorator = new $class; |
|
85 | + } |
|
86 | + $this->decorators[$decorator->name] = $decorator; |
|
87 | + } |
|
88 | 88 | |
89 | 89 | } |
90 | 90 |
@@ -8,53 +8,53 @@ |
||
8 | 8 | */ |
9 | 9 | class HTMLPurifier_Doctype |
10 | 10 | { |
11 | - /** |
|
12 | - * Full name of doctype |
|
13 | - */ |
|
14 | - public $name; |
|
15 | - |
|
16 | - /** |
|
17 | - * List of standard modules (string identifiers or literal objects) |
|
18 | - * that this doctype uses |
|
19 | - */ |
|
20 | - public $modules = array(); |
|
21 | - |
|
22 | - /** |
|
23 | - * List of modules to use for tidying up code |
|
24 | - */ |
|
25 | - public $tidyModules = array(); |
|
26 | - |
|
27 | - /** |
|
28 | - * Is the language derived from XML (i.e. XHTML)? |
|
29 | - */ |
|
30 | - public $xml = true; |
|
31 | - |
|
32 | - /** |
|
33 | - * List of aliases for this doctype |
|
34 | - */ |
|
35 | - public $aliases = array(); |
|
36 | - |
|
37 | - /** |
|
38 | - * Public DTD identifier |
|
39 | - */ |
|
40 | - public $dtdPublic; |
|
41 | - |
|
42 | - /** |
|
43 | - * System DTD identifier |
|
44 | - */ |
|
45 | - public $dtdSystem; |
|
46 | - |
|
47 | - public function __construct($name = null, $xml = true, $modules = array(), |
|
48 | - $tidyModules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null |
|
49 | - ) { |
|
50 | - $this->name = $name; |
|
51 | - $this->xml = $xml; |
|
52 | - $this->modules = $modules; |
|
53 | - $this->tidyModules = $tidyModules; |
|
54 | - $this->aliases = $aliases; |
|
55 | - $this->dtdPublic = $dtd_public; |
|
56 | - $this->dtdSystem = $dtd_system; |
|
57 | - } |
|
11 | + /** |
|
12 | + * Full name of doctype |
|
13 | + */ |
|
14 | + public $name; |
|
15 | + |
|
16 | + /** |
|
17 | + * List of standard modules (string identifiers or literal objects) |
|
18 | + * that this doctype uses |
|
19 | + */ |
|
20 | + public $modules = array(); |
|
21 | + |
|
22 | + /** |
|
23 | + * List of modules to use for tidying up code |
|
24 | + */ |
|
25 | + public $tidyModules = array(); |
|
26 | + |
|
27 | + /** |
|
28 | + * Is the language derived from XML (i.e. XHTML)? |
|
29 | + */ |
|
30 | + public $xml = true; |
|
31 | + |
|
32 | + /** |
|
33 | + * List of aliases for this doctype |
|
34 | + */ |
|
35 | + public $aliases = array(); |
|
36 | + |
|
37 | + /** |
|
38 | + * Public DTD identifier |
|
39 | + */ |
|
40 | + public $dtdPublic; |
|
41 | + |
|
42 | + /** |
|
43 | + * System DTD identifier |
|
44 | + */ |
|
45 | + public $dtdSystem; |
|
46 | + |
|
47 | + public function __construct($name = null, $xml = true, $modules = array(), |
|
48 | + $tidyModules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null |
|
49 | + ) { |
|
50 | + $this->name = $name; |
|
51 | + $this->xml = $xml; |
|
52 | + $this->modules = $modules; |
|
53 | + $this->tidyModules = $tidyModules; |
|
54 | + $this->aliases = $aliases; |
|
55 | + $this->dtdPublic = $dtd_public; |
|
56 | + $this->dtdSystem = $dtd_system; |
|
57 | + } |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // vim: et sw=4 sts=4 |