@@ -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 |
@@ -11,172 +11,172 @@ |
||
| 11 | 11 | class HTMLPurifier_ElementDef |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Does the definition work by itself, or is it created solely |
|
| 16 | - * for the purpose of merging into another definition? |
|
| 17 | - */ |
|
| 18 | - public $standalone = true; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Associative array of attribute name to HTMLPurifier_AttrDef |
|
| 22 | - * @note Before being processed by HTMLPurifier_AttrCollections |
|
| 23 | - * when modules are finalized during |
|
| 24 | - * HTMLPurifier_HTMLDefinition->setup(), this array may also |
|
| 25 | - * contain an array at index 0 that indicates which attribute |
|
| 26 | - * collections to load into the full array. It may also |
|
| 27 | - * contain string indentifiers in lieu of HTMLPurifier_AttrDef, |
|
| 28 | - * see HTMLPurifier_AttrTypes on how they are expanded during |
|
| 29 | - * HTMLPurifier_HTMLDefinition->setup() processing. |
|
| 30 | - */ |
|
| 31 | - public $attr = array(); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Indexed list of tag's HTMLPurifier_AttrTransform to be done before validation |
|
| 35 | - */ |
|
| 36 | - public $attr_transform_pre = array(); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Indexed list of tag's HTMLPurifier_AttrTransform to be done after validation |
|
| 40 | - */ |
|
| 41 | - public $attr_transform_post = array(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * HTMLPurifier_ChildDef of this tag. |
|
| 45 | - */ |
|
| 46 | - public $child; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Abstract string representation of internal ChildDef rules. See |
|
| 50 | - * HTMLPurifier_ContentSets for how this is parsed and then transformed |
|
| 51 | - * into an HTMLPurifier_ChildDef. |
|
| 52 | - * @warning This is a temporary variable that is not available after |
|
| 53 | - * being processed by HTMLDefinition |
|
| 54 | - */ |
|
| 55 | - public $content_model; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Value of $child->type, used to determine which ChildDef to use, |
|
| 59 | - * used in combination with $content_model. |
|
| 60 | - * @warning This must be lowercase |
|
| 61 | - * @warning This is a temporary variable that is not available after |
|
| 62 | - * being processed by HTMLDefinition |
|
| 63 | - */ |
|
| 64 | - public $content_model_type; |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Does the element have a content model (#PCDATA | Inline)*? This |
|
| 70 | - * is important for chameleon ins and del processing in |
|
| 71 | - * HTMLPurifier_ChildDef_Chameleon. Dynamically set: modules don't |
|
| 72 | - * have to worry about this one. |
|
| 73 | - */ |
|
| 74 | - public $descendants_are_inline = false; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * List of the names of required attributes this element has. Dynamically |
|
| 78 | - * populated by HTMLPurifier_HTMLDefinition::getElement |
|
| 79 | - */ |
|
| 80 | - public $required_attr = array(); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Lookup table of tags excluded from all descendants of this tag. |
|
| 84 | - * @note SGML permits exclusions for all descendants, but this is |
|
| 85 | - * not possible with DTDs or XML Schemas. W3C has elected to |
|
| 86 | - * use complicated compositions of content_models to simulate |
|
| 87 | - * exclusion for children, but we go the simpler, SGML-style |
|
| 88 | - * route of flat-out exclusions, which correctly apply to |
|
| 89 | - * all descendants and not just children. Note that the XHTML |
|
| 90 | - * Modularization Abstract Modules are blithely unaware of such |
|
| 91 | - * distinctions. |
|
| 92 | - */ |
|
| 93 | - public $excludes = array(); |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * This tag is explicitly auto-closed by the following tags. |
|
| 97 | - */ |
|
| 98 | - public $autoclose = array(); |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * If a foreign element is found in this element, test if it is |
|
| 102 | - * allowed by this sub-element; if it is, instead of closing the |
|
| 103 | - * current element, place it inside this element. |
|
| 104 | - */ |
|
| 105 | - public $wrap; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Whether or not this is a formatting element affected by the |
|
| 109 | - * "Active Formatting Elements" algorithm. |
|
| 110 | - */ |
|
| 111 | - public $formatting; |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Low-level factory constructor for creating new standalone element defs |
|
| 115 | - */ |
|
| 116 | - public static function create($content_model, $content_model_type, $attr) { |
|
| 117 | - $def = new HTMLPurifier_ElementDef(); |
|
| 118 | - $def->content_model = $content_model; |
|
| 119 | - $def->content_model_type = $content_model_type; |
|
| 120 | - $def->attr = $attr; |
|
| 121 | - return $def; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Merges the values of another element definition into this one. |
|
| 126 | - * Values from the new element def take precedence if a value is |
|
| 127 | - * not mergeable. |
|
| 128 | - */ |
|
| 129 | - public function mergeIn($def) { |
|
| 130 | - |
|
| 131 | - // later keys takes precedence |
|
| 132 | - foreach($def->attr as $k => $v) { |
|
| 133 | - if ($k === 0) { |
|
| 134 | - // merge in the includes |
|
| 135 | - // sorry, no way to override an include |
|
| 136 | - foreach ($v as $v2) { |
|
| 137 | - $this->attr[0][] = $v2; |
|
| 138 | - } |
|
| 139 | - continue; |
|
| 140 | - } |
|
| 141 | - if ($v === false) { |
|
| 142 | - if (isset($this->attr[$k])) unset($this->attr[$k]); |
|
| 143 | - continue; |
|
| 144 | - } |
|
| 145 | - $this->attr[$k] = $v; |
|
| 146 | - } |
|
| 147 | - $this->_mergeAssocArray($this->attr_transform_pre, $def->attr_transform_pre); |
|
| 148 | - $this->_mergeAssocArray($this->attr_transform_post, $def->attr_transform_post); |
|
| 149 | - $this->_mergeAssocArray($this->excludes, $def->excludes); |
|
| 150 | - |
|
| 151 | - if(!empty($def->content_model)) { |
|
| 152 | - $this->content_model = |
|
| 153 | - str_replace("#SUPER", $this->content_model, $def->content_model); |
|
| 154 | - $this->child = false; |
|
| 155 | - } |
|
| 156 | - if(!empty($def->content_model_type)) { |
|
| 157 | - $this->content_model_type = $def->content_model_type; |
|
| 158 | - $this->child = false; |
|
| 159 | - } |
|
| 160 | - if(!is_null($def->child)) $this->child = $def->child; |
|
| 161 | - if(!is_null($def->formatting)) $this->formatting = $def->formatting; |
|
| 162 | - if($def->descendants_are_inline) $this->descendants_are_inline = $def->descendants_are_inline; |
|
| 163 | - |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Merges one array into another, removes values which equal false |
|
| 168 | - * @param $a1 Array by reference that is merged into |
|
| 169 | - * @param $a2 Array that merges into $a1 |
|
| 170 | - */ |
|
| 171 | - private function _mergeAssocArray(&$a1, $a2) { |
|
| 172 | - foreach ($a2 as $k => $v) { |
|
| 173 | - if ($v === false) { |
|
| 174 | - if (isset($a1[$k])) unset($a1[$k]); |
|
| 175 | - continue; |
|
| 176 | - } |
|
| 177 | - $a1[$k] = $v; |
|
| 178 | - } |
|
| 179 | - } |
|
| 14 | + /** |
|
| 15 | + * Does the definition work by itself, or is it created solely |
|
| 16 | + * for the purpose of merging into another definition? |
|
| 17 | + */ |
|
| 18 | + public $standalone = true; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Associative array of attribute name to HTMLPurifier_AttrDef |
|
| 22 | + * @note Before being processed by HTMLPurifier_AttrCollections |
|
| 23 | + * when modules are finalized during |
|
| 24 | + * HTMLPurifier_HTMLDefinition->setup(), this array may also |
|
| 25 | + * contain an array at index 0 that indicates which attribute |
|
| 26 | + * collections to load into the full array. It may also |
|
| 27 | + * contain string indentifiers in lieu of HTMLPurifier_AttrDef, |
|
| 28 | + * see HTMLPurifier_AttrTypes on how they are expanded during |
|
| 29 | + * HTMLPurifier_HTMLDefinition->setup() processing. |
|
| 30 | + */ |
|
| 31 | + public $attr = array(); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Indexed list of tag's HTMLPurifier_AttrTransform to be done before validation |
|
| 35 | + */ |
|
| 36 | + public $attr_transform_pre = array(); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Indexed list of tag's HTMLPurifier_AttrTransform to be done after validation |
|
| 40 | + */ |
|
| 41 | + public $attr_transform_post = array(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * HTMLPurifier_ChildDef of this tag. |
|
| 45 | + */ |
|
| 46 | + public $child; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Abstract string representation of internal ChildDef rules. See |
|
| 50 | + * HTMLPurifier_ContentSets for how this is parsed and then transformed |
|
| 51 | + * into an HTMLPurifier_ChildDef. |
|
| 52 | + * @warning This is a temporary variable that is not available after |
|
| 53 | + * being processed by HTMLDefinition |
|
| 54 | + */ |
|
| 55 | + public $content_model; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Value of $child->type, used to determine which ChildDef to use, |
|
| 59 | + * used in combination with $content_model. |
|
| 60 | + * @warning This must be lowercase |
|
| 61 | + * @warning This is a temporary variable that is not available after |
|
| 62 | + * being processed by HTMLDefinition |
|
| 63 | + */ |
|
| 64 | + public $content_model_type; |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Does the element have a content model (#PCDATA | Inline)*? This |
|
| 70 | + * is important for chameleon ins and del processing in |
|
| 71 | + * HTMLPurifier_ChildDef_Chameleon. Dynamically set: modules don't |
|
| 72 | + * have to worry about this one. |
|
| 73 | + */ |
|
| 74 | + public $descendants_are_inline = false; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * List of the names of required attributes this element has. Dynamically |
|
| 78 | + * populated by HTMLPurifier_HTMLDefinition::getElement |
|
| 79 | + */ |
|
| 80 | + public $required_attr = array(); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Lookup table of tags excluded from all descendants of this tag. |
|
| 84 | + * @note SGML permits exclusions for all descendants, but this is |
|
| 85 | + * not possible with DTDs or XML Schemas. W3C has elected to |
|
| 86 | + * use complicated compositions of content_models to simulate |
|
| 87 | + * exclusion for children, but we go the simpler, SGML-style |
|
| 88 | + * route of flat-out exclusions, which correctly apply to |
|
| 89 | + * all descendants and not just children. Note that the XHTML |
|
| 90 | + * Modularization Abstract Modules are blithely unaware of such |
|
| 91 | + * distinctions. |
|
| 92 | + */ |
|
| 93 | + public $excludes = array(); |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * This tag is explicitly auto-closed by the following tags. |
|
| 97 | + */ |
|
| 98 | + public $autoclose = array(); |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * If a foreign element is found in this element, test if it is |
|
| 102 | + * allowed by this sub-element; if it is, instead of closing the |
|
| 103 | + * current element, place it inside this element. |
|
| 104 | + */ |
|
| 105 | + public $wrap; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Whether or not this is a formatting element affected by the |
|
| 109 | + * "Active Formatting Elements" algorithm. |
|
| 110 | + */ |
|
| 111 | + public $formatting; |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Low-level factory constructor for creating new standalone element defs |
|
| 115 | + */ |
|
| 116 | + public static function create($content_model, $content_model_type, $attr) { |
|
| 117 | + $def = new HTMLPurifier_ElementDef(); |
|
| 118 | + $def->content_model = $content_model; |
|
| 119 | + $def->content_model_type = $content_model_type; |
|
| 120 | + $def->attr = $attr; |
|
| 121 | + return $def; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Merges the values of another element definition into this one. |
|
| 126 | + * Values from the new element def take precedence if a value is |
|
| 127 | + * not mergeable. |
|
| 128 | + */ |
|
| 129 | + public function mergeIn($def) { |
|
| 130 | + |
|
| 131 | + // later keys takes precedence |
|
| 132 | + foreach($def->attr as $k => $v) { |
|
| 133 | + if ($k === 0) { |
|
| 134 | + // merge in the includes |
|
| 135 | + // sorry, no way to override an include |
|
| 136 | + foreach ($v as $v2) { |
|
| 137 | + $this->attr[0][] = $v2; |
|
| 138 | + } |
|
| 139 | + continue; |
|
| 140 | + } |
|
| 141 | + if ($v === false) { |
|
| 142 | + if (isset($this->attr[$k])) unset($this->attr[$k]); |
|
| 143 | + continue; |
|
| 144 | + } |
|
| 145 | + $this->attr[$k] = $v; |
|
| 146 | + } |
|
| 147 | + $this->_mergeAssocArray($this->attr_transform_pre, $def->attr_transform_pre); |
|
| 148 | + $this->_mergeAssocArray($this->attr_transform_post, $def->attr_transform_post); |
|
| 149 | + $this->_mergeAssocArray($this->excludes, $def->excludes); |
|
| 150 | + |
|
| 151 | + if(!empty($def->content_model)) { |
|
| 152 | + $this->content_model = |
|
| 153 | + str_replace("#SUPER", $this->content_model, $def->content_model); |
|
| 154 | + $this->child = false; |
|
| 155 | + } |
|
| 156 | + if(!empty($def->content_model_type)) { |
|
| 157 | + $this->content_model_type = $def->content_model_type; |
|
| 158 | + $this->child = false; |
|
| 159 | + } |
|
| 160 | + if(!is_null($def->child)) $this->child = $def->child; |
|
| 161 | + if(!is_null($def->formatting)) $this->formatting = $def->formatting; |
|
| 162 | + if($def->descendants_are_inline) $this->descendants_are_inline = $def->descendants_are_inline; |
|
| 163 | + |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Merges one array into another, removes values which equal false |
|
| 168 | + * @param $a1 Array by reference that is merged into |
|
| 169 | + * @param $a2 Array that merges into $a1 |
|
| 170 | + */ |
|
| 171 | + private function _mergeAssocArray(&$a1, $a2) { |
|
| 172 | + foreach ($a2 as $k => $v) { |
|
| 173 | + if ($v === false) { |
|
| 174 | + if (isset($a1[$k])) unset($a1[$k]); |
|
| 175 | + continue; |
|
| 176 | + } |
|
| 177 | + $a1[$k] = $v; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | 181 | } |
| 182 | 182 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | public function mergeIn($def) { |
| 130 | 130 | |
| 131 | 131 | // later keys takes precedence |
| 132 | - foreach($def->attr as $k => $v) { |
|
| 132 | + foreach ($def->attr as $k => $v) { |
|
| 133 | 133 | if ($k === 0) { |
| 134 | 134 | // merge in the includes |
| 135 | 135 | // sorry, no way to override an include |
@@ -148,18 +148,18 @@ discard block |
||
| 148 | 148 | $this->_mergeAssocArray($this->attr_transform_post, $def->attr_transform_post); |
| 149 | 149 | $this->_mergeAssocArray($this->excludes, $def->excludes); |
| 150 | 150 | |
| 151 | - if(!empty($def->content_model)) { |
|
| 151 | + if (!empty($def->content_model)) { |
|
| 152 | 152 | $this->content_model = |
| 153 | 153 | str_replace("#SUPER", $this->content_model, $def->content_model); |
| 154 | 154 | $this->child = false; |
| 155 | 155 | } |
| 156 | - if(!empty($def->content_model_type)) { |
|
| 156 | + if (!empty($def->content_model_type)) { |
|
| 157 | 157 | $this->content_model_type = $def->content_model_type; |
| 158 | 158 | $this->child = false; |
| 159 | 159 | } |
| 160 | - if(!is_null($def->child)) $this->child = $def->child; |
|
| 161 | - if(!is_null($def->formatting)) $this->formatting = $def->formatting; |
|
| 162 | - if($def->descendants_are_inline) $this->descendants_are_inline = $def->descendants_are_inline; |
|
| 160 | + if (!is_null($def->child)) $this->child = $def->child; |
|
| 161 | + if (!is_null($def->formatting)) $this->formatting = $def->formatting; |
|
| 162 | + if ($def->descendants_are_inline) $this->descendants_are_inline = $def->descendants_are_inline; |
|
| 163 | 163 | |
| 164 | 164 | } |
| 165 | 165 | |
@@ -139,7 +139,9 @@ discard block |
||
| 139 | 139 | continue; |
| 140 | 140 | } |
| 141 | 141 | if ($v === false) { |
| 142 | - if (isset($this->attr[$k])) unset($this->attr[$k]); |
|
| 142 | + if (isset($this->attr[$k])) { |
|
| 143 | + unset($this->attr[$k]); |
|
| 144 | + } |
|
| 143 | 145 | continue; |
| 144 | 146 | } |
| 145 | 147 | $this->attr[$k] = $v; |
@@ -157,9 +159,15 @@ discard block |
||
| 157 | 159 | $this->content_model_type = $def->content_model_type; |
| 158 | 160 | $this->child = false; |
| 159 | 161 | } |
| 160 | - if(!is_null($def->child)) $this->child = $def->child; |
|
| 161 | - if(!is_null($def->formatting)) $this->formatting = $def->formatting; |
|
| 162 | - if($def->descendants_are_inline) $this->descendants_are_inline = $def->descendants_are_inline; |
|
| 162 | + if(!is_null($def->child)) { |
|
| 163 | + $this->child = $def->child; |
|
| 164 | + } |
|
| 165 | + if(!is_null($def->formatting)) { |
|
| 166 | + $this->formatting = $def->formatting; |
|
| 167 | + } |
|
| 168 | + if($def->descendants_are_inline) { |
|
| 169 | + $this->descendants_are_inline = $def->descendants_are_inline; |
|
| 170 | + } |
|
| 163 | 171 | |
| 164 | 172 | } |
| 165 | 173 | |
@@ -171,7 +179,9 @@ discard block |
||
| 171 | 179 | private function _mergeAssocArray(&$a1, $a2) { |
| 172 | 180 | foreach ($a2 as $k => $v) { |
| 173 | 181 | if ($v === false) { |
| 174 | - if (isset($a1[$k])) unset($a1[$k]); |
|
| 182 | + if (isset($a1[$k])) { |
|
| 183 | + unset($a1[$k]); |
|
| 184 | + } |
|
| 175 | 185 | continue; |
| 176 | 186 | } |
| 177 | 187 | $a1[$k] = $v; |