ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_HTMLModule_Tidy Class Reference

Abstract class for a set of proprietary modules that clean up (tidy) poorly written HTML. More...

+ Inheritance diagram for HTMLPurifier_HTMLModule_Tidy:
+ Collaboration diagram for HTMLPurifier_HTMLModule_Tidy:

Public Member Functions

 setup ($config)
 Lazy load constructs the module by determining the necessary fixes to create and then delegating to the populate() function.
 getFixesForLevel ($level)
 Retrieves all fixes per a level, returning fixes for that specific level as well as all levels below it.
 makeFixesForLevel ($fixes)
 Dynamically populates the $fixesForLevel member variable using the fixes array.
 populate ($fixes)
 Populates the module with transforms and other special-case code based on a list of fixes passed to it.
 getFixType ($name)
 Parses a fix name and determines what kind of fix it is, as well as other information defined by the fix.
 makeFixes ()
 Defines all fixes the module will perform in a compact associative array of fix name to fix implementation.
- Public Member Functions inherited from HTMLPurifier_HTMLModule
 getChildDef ($def)
 Retrieves a proper HTMLPurifier_ChildDef subclass based on content_model and content_model_type member variables of the HTMLPurifier_ElementDef class.
 addElement ($element, $type, $contents, $attr_includes=array(), $attr=array())
 Convenience function that sets up a new element.
 addBlankElement ($element)
 Convenience function that creates a totally blank, non-standalone element.
 addElementToContentSet ($element, $type)
 Convenience function that registers an element to a content set.
 parseContents ($contents)
 Convenience function that transforms single-string contents into separate content model and content model type.
 mergeInAttrIncludes (&$attr, $attr_includes)
 Convenience function that merges a list of attribute includes into an attribute array.
 makeLookup ($list)
 Convenience function that generates a lookup table with boolean true as value.

Data Fields

 $levels = array(0 => 'none', 'light', 'medium', 'heavy')
 List of supported levels.
 $defaultLevel = null
 Default level to place all fixes in.
 $fixesForLevel
 Lists of fixes used by getFixesForLevel().
- Data Fields inherited from HTMLPurifier_HTMLModule
 $name
 Short unique string identifier of the module.
 $elements = array()
 Informally, a list of elements this module changes.
 $info = array()
 Associative array of element names to element definitions.
 $content_sets = array()
 Associative array of content set names to content set additions.
 $attr_collections = array()
 Associative array of attribute collection names to attribute collection additions.
 $info_tag_transform = array()
 Associative array of deprecated tag name to HTMLPurifier_TagTransform.
 $info_attr_transform_pre = array()
 List of HTMLPurifier_AttrTransform to be performed before validation.
 $info_attr_transform_post = array()
 List of HTMLPurifier_AttrTransform to be performed after validation.
 $info_injector = array()
 List of HTMLPurifier_Injector to be performed during well-formedness fixing.
 $defines_child_def = false
 Boolean flag that indicates whether or not getChildDef is implemented.
 $safe = true
 Boolean flag whether or not this module is safe.

Detailed Description

Abstract class for a set of proprietary modules that clean up (tidy) poorly written HTML.

Todo:
Figure out how to protect some of these methods/properties

Definition at line 8 of file Tidy.php.

Member Function Documentation

HTMLPurifier_HTMLModule_Tidy::getFixesForLevel (   $level)

Retrieves all fixes per a level, returning fixes for that specific level as well as all levels below it.

Parameters
$levelString level identifier, see $levels for valid values
Returns
Lookup up table of fixes

Definition at line 73 of file Tidy.php.

References $ret.

Referenced by setup().

{
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 ($i == $c) {
trigger_error(
'Tidy level ' . htmlspecialchars($level) . ' not recognized',
E_USER_WARNING
);
return array();
}
$ret = array();
foreach ($activated_levels as $level) {
foreach ($this->fixesForLevel[$level] as $fix) {
$ret[$fix] = true;
}
}
return $ret;
}

+ Here is the caller graph for this function:

HTMLPurifier_HTMLModule_Tidy::getFixType (   $name)

Parses a fix name and determines what kind of fix it is, as well as other information defined by the fix.

Parameters
$nameString name of fix
Returns
array(string $fix_type, array $fix_parameters)
Note
$fix_parameters is type dependant, see populate() for usage of these parameters

Definition at line 172 of file Tidy.php.

References HTMLPurifier_HTMLModule\$name.

Referenced by populate().

{
// parse it
$property = $attr = null;
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;
// special case: attribute transform
if (!is_null($attr)) {
if (is_null($property)) $property = 'pre';
$type = 'attr_transform_' . $property;
return array($type, $params);
}
// special case: tag transform
if (is_null($property)) {
return array('tag_transform', $params);
}
return array($property, $params);
}

+ Here is the caller graph for this function:

HTMLPurifier_HTMLModule_Tidy::makeFixes ( )

Defines all fixes the module will perform in a compact associative array of fix name to fix implementation.

Reimplemented in HTMLPurifier_HTMLModule_Tidy_Name, HTMLPurifier_HTMLModule_Tidy_Proprietary, HTMLPurifier_HTMLModule_Tidy_XHTML, HTMLPurifier_HTMLModule_Tidy_Strict, and HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4.

Definition at line 203 of file Tidy.php.

Referenced by setup().

{}

+ Here is the caller graph for this function:

HTMLPurifier_HTMLModule_Tidy::makeFixesForLevel (   $fixes)

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.

Definition at line 103 of file Tidy.php.

References $defaultLevel.

Referenced by setup().

{
if (!isset($this->defaultLevel)) return;
if (!isset($this->fixesForLevel[$this->defaultLevel])) {
trigger_error(
'Default level ' . $this->defaultLevel . ' does not exist',
E_USER_ERROR
);
return;
}
$this->fixesForLevel[$this->defaultLevel] = array_keys($fixes);
}

+ Here is the caller graph for this function:

HTMLPurifier_HTMLModule_Tidy::populate (   $fixes)

Populates the module with transforms and other special-case code based on a list of fixes passed to it.

Parameters
$lookupLookup table of fixes to activate

Definition at line 120 of file Tidy.php.

References HTMLPurifier_HTMLModule\$name, HTMLPurifier_HTMLModule\addBlankElement(), and getFixType().

Referenced by setup().

{
foreach ($fixes as $name => $fix) {
// determine what the fix is for
list($type, $params) = $this->getFixType($name);
switch ($type) {
case 'attr_transform_pre':
case 'attr_transform_post':
$attr = $params['attr'];
if (isset($params['element'])) {
$element = $params['element'];
if (empty($this->info[$element])) {
$e = $this->addBlankElement($element);
} else {
$e = $this->info[$element];
}
} else {
$type = "info_$type";
$e = $this;
}
// PHP does some weird parsing when I do
// $e->$type[$attr], so I have to assign a ref.
$f =& $e->$type;
$f[$attr] = $fix;
break;
case 'tag_transform':
$this->info_tag_transform[$params['element']] = $fix;
break;
case 'child':
case 'content_model_type':
$element = $params['element'];
if (empty($this->info[$element])) {
$e = $this->addBlankElement($element);
} else {
$e = $this->info[$element];
}
$e->$type = $fix;
break;
default:
trigger_error("Fix type $type not supported", E_USER_ERROR);
break;
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_HTMLModule_Tidy::setup (   $config)

Lazy load constructs the module by determining the necessary fixes to create and then delegating to the populate() function.

Todo:
Wildcard matching and error reporting when an added or subtracted fix has no effect.

Reimplemented from HTMLPurifier_HTMLModule.

Definition at line 38 of file Tidy.php.

References HTMLPurifier_HTMLModule\$name, getFixesForLevel(), makeFixes(), makeFixesForLevel(), and populate().

{
// create fixes, initialize fixesForLevel
$fixes = $this->makeFixes();
$this->makeFixesForLevel($fixes);
// figure out which fixes to use
$level = $config->get('HTML.TidyLevel');
$fixes_lookup = $this->getFixesForLevel($level);
// get custom fix declarations: these need namespace processing
$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]))
) {
unset($fixes[$name]);
}
}
// populate this module with necessary fixes
$this->populate($fixes);
}

+ Here is the call graph for this function:

Field Documentation

HTMLPurifier_HTMLModule_Tidy::$defaultLevel = null

Default level to place all fixes in.

Disabled by default

Definition at line 20 of file Tidy.php.

Referenced by makeFixesForLevel().

HTMLPurifier_HTMLModule_Tidy::$fixesForLevel
Initial value:
array(
'light' => array(),
'medium' => array(),
'heavy' => array()
)

Lists of fixes used by getFixesForLevel().

Format is: HTMLModule_Tidy->fixesForLevel[$level] = array('fix-1', 'fix-2');

Definition at line 26 of file Tidy.php.

HTMLPurifier_HTMLModule_Tidy::$levels = array(0 => 'none', 'light', 'medium', 'heavy')

List of supported levels.

Index zero is a special case "no fixes" level.

Definition at line 15 of file Tidy.php.


The documentation for this class was generated from the following file: