diff options
Diffstat (limited to 'library/HTMLPurifier/HTMLModule/Tidy.php')
-rw-r--r-- | library/HTMLPurifier/HTMLModule/Tidy.php | 85 |
1 files changed, 54 insertions, 31 deletions
diff --git a/library/HTMLPurifier/HTMLModule/Tidy.php b/library/HTMLPurifier/HTMLModule/Tidy.php index 21783f18e..08aa23247 100644 --- a/library/HTMLPurifier/HTMLModule/Tidy.php +++ b/library/HTMLPurifier/HTMLModule/Tidy.php @@ -7,36 +7,41 @@ */ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule { - /** - * List of supported levels. Index zero is a special case "no fixes" - * level. + * List of supported levels. + * Index zero is a special case "no fixes" level. + * @type array */ public $levels = array(0 => 'none', 'light', 'medium', 'heavy'); /** - * Default level to place all fixes in. Disabled by default + * Default level to place all fixes in. + * Disabled by default. + * @type string */ public $defaultLevel = null; /** - * Lists of fixes used by getFixesForLevel(). Format is: + * Lists of fixes used by getFixesForLevel(). + * Format is: * HTMLModule_Tidy->fixesForLevel[$level] = array('fix-1', 'fix-2'); + * @type array */ public $fixesForLevel = array( - 'light' => array(), + 'light' => array(), 'medium' => array(), - 'heavy' => array() + 'heavy' => array() ); /** * Lazy load constructs the module by determining the necessary * fixes to create and then delegating to the populate() function. + * @param HTMLPurifier_Config $config * @todo Wildcard matching and error reporting when an added or * subtracted fix has no effect. */ - public function setup($config) { - + public function setup($config) + { // create fixes, initialize fixesForLevel $fixes = $this->makeFixes(); $this->makeFixesForLevel($fixes); @@ -46,38 +51,38 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule $fixes_lookup = $this->getFixesForLevel($level); // get custom fix declarations: these need namespace processing - $add_fixes = $config->get('HTML.TidyAdd'); + $add_fixes = $config->get('HTML.TidyAdd'); $remove_fixes = $config->get('HTML.TidyRemove'); foreach ($fixes as $name => $fix) { // needs to be refactored a little to implement globbing - if ( - isset($remove_fixes[$name]) || - (!isset($add_fixes[$name]) && !isset($fixes_lookup[$name])) - ) { + if (isset($remove_fixes[$name]) || + (!isset($add_fixes[$name]) && !isset($fixes_lookup[$name]))) { unset($fixes[$name]); } } // populate this module with necessary fixes $this->populate($fixes); - } /** * Retrieves all fixes per a level, returning fixes for that specific * level as well as all levels below it. - * @param $level String level identifier, see $levels for valid values - * @return Lookup up table of fixes + * @param string $level level identifier, see $levels for valid values + * @return array Lookup up table of fixes */ - public function getFixesForLevel($level) { + public function getFixesForLevel($level) + { if ($level == $this->levels[0]) { return array(); } $activated_levels = array(); for ($i = 1, $c = count($this->levels); $i < $c; $i++) { $activated_levels[] = $this->levels[$i]; - if ($this->levels[$i] == $level) break; + if ($this->levels[$i] == $level) { + break; + } } if ($i == $c) { trigger_error( @@ -99,9 +104,13 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule * Dynamically populates the $fixesForLevel member variable using * the fixes array. It may be custom overloaded, used in conjunction * with $defaultLevel, or not used at all. + * @param array $fixes */ - public function makeFixesForLevel($fixes) { - if (!isset($this->defaultLevel)) return; + public function makeFixesForLevel($fixes) + { + if (!isset($this->defaultLevel)) { + return; + } if (!isset($this->fixesForLevel[$this->defaultLevel])) { trigger_error( 'Default level ' . $this->defaultLevel . ' does not exist', @@ -115,9 +124,10 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule /** * Populates the module with transforms and other special-case code * based on a list of fixes passed to it - * @param $lookup Lookup table of fixes to activate + * @param array $fixes Lookup table of fixes to activate */ - public function populate($fixes) { + public function populate($fixes) + { foreach ($fixes as $name => $fix) { // determine what the fix is for list($type, $params) = $this->getFixType($name); @@ -169,20 +179,31 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule * @note $fix_parameters is type dependant, see populate() for usage * of these parameters */ - public function getFixType($name) { + public function getFixType($name) + { // parse it $property = $attr = null; - if (strpos($name, '#') !== false) list($name, $property) = explode('#', $name); - if (strpos($name, '@') !== false) list($name, $attr) = explode('@', $name); + if (strpos($name, '#') !== false) { + list($name, $property) = explode('#', $name); + } + if (strpos($name, '@') !== false) { + list($name, $attr) = explode('@', $name); + } // figure out the parameters $params = array(); - if ($name !== '') $params['element'] = $name; - if (!is_null($attr)) $params['attr'] = $attr; + if ($name !== '') { + $params['element'] = $name; + } + if (!is_null($attr)) { + $params['attr'] = $attr; + } // special case: attribute transform if (!is_null($attr)) { - if (is_null($property)) $property = 'pre'; + if (is_null($property)) { + $property = 'pre'; + } $type = 'attr_transform_' . $property; return array($type, $params); } @@ -199,9 +220,11 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule /** * Defines all fixes the module will perform in a compact * associative array of fix name to fix implementation. + * @return array */ - public function makeFixes() {} - + public function makeFixes() + { + } } // vim: et sw=4 sts=4 |