ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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. More...
 
 getFixesForLevel ($level)
 Retrieves all fixes per a level, returning fixes for that specific level as well as all levels below it. More...
 
 makeFixesForLevel ($fixes)
 Dynamically populates the $fixesForLevel member variable using the fixes array. More...
 
 populate ($fixes)
 Populates the module with transforms and other special-case code based on a list of fixes passed to it. More...
 
 getFixType ($name)
 Parses a fix name and determines what kind of fix it is, as well as other information defined by the fix. More...
 
 makeFixes ()
 Defines all fixes the module will perform in a compact associative array of fix name to fix implementation. More...
 
- 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. More...
 
 addElement ($element, $type, $contents, $attr_includes=array(), $attr=array())
 Convenience function that sets up a new element. More...
 
 addBlankElement ($element)
 Convenience function that creates a totally blank, non-standalone element. More...
 
 addElementToContentSet ($element, $type)
 Convenience function that registers an element to a content set. More...
 
 parseContents ($contents)
 Convenience function that transforms single-string contents into separate content model and content model type. More...
 
 mergeInAttrIncludes (&$attr, $attr_includes)
 Convenience function that merges a list of attribute includes into an attribute array. More...
 
 makeLookup ($list)
 Convenience function that generates a lookup table with boolean true as value. More...
 
 setup ($config)
 Lazy load construction of the module after determining whether or not it's needed, and also when a finalized configuration object is available. More...
 

Data Fields

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

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

◆ getFixesForLevel()

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
string$levellevel identifier, see $levels for valid values
Returns
array Lookup up table of fixes

Definition at line 75 of file Tidy.php.

76 {
77 if ($level == $this->levels[0]) {
78 return array();
79 }
80 $activated_levels = array();
81 for ($i = 1, $c = count($this->levels); $i < $c; $i++) {
82 $activated_levels[] = $this->levels[$i];
83 if ($this->levels[$i] == $level) {
84 break;
85 }
86 }
87 if ($i == $c) {
88 trigger_error(
89 'Tidy level ' . htmlspecialchars($level) . ' not recognized',
90 E_USER_WARNING
91 );
92 return array();
93 }
94 $ret = array();
95 foreach ($activated_levels as $level) {
96 foreach ($this->fixesForLevel[$level] as $fix) {
97 $ret[$fix] = true;
98 }
99 }
100 return $ret;
101 }

References $ret.

Referenced by setup().

+ Here is the caller graph for this function:

◆ getFixType()

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 182 of file Tidy.php.

183 {
184 // parse it
185 $property = $attr = null;
186 if (strpos($name, '#') !== false) {
187 list($name, $property) = explode('#', $name);
188 }
189 if (strpos($name, '@') !== false) {
190 list($name, $attr) = explode('@', $name);
191 }
192
193 // figure out the parameters
194 $params = array();
195 if ($name !== '') {
196 $params['element'] = $name;
197 }
198 if (!is_null($attr)) {
199 $params['attr'] = $attr;
200 }
201
202 // special case: attribute transform
203 if (!is_null($attr)) {
204 if (is_null($property)) {
205 $property = 'pre';
206 }
207 $type = 'attr_transform_' . $property;
208 return array($type, $params);
209 }
210
211 // special case: tag transform
212 if (is_null($property)) {
213 return array('tag_transform', $params);
214 }
215
216 return array($property, $params);
217
218 }
$name
Short unique string identifier of the module.
Definition: HTMLModule.php:27
$params
Definition: example_049.php:96

References HTMLPurifier_HTMLModule\$name, and $params.

Referenced by populate().

+ Here is the caller graph for this function:

◆ makeFixes()

HTMLPurifier_HTMLModule_Tidy::makeFixes ( )

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

Returns
array

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

Definition at line 225 of file Tidy.php.

226 {
227 }

Referenced by setup().

+ Here is the caller graph for this function:

◆ makeFixesForLevel()

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.

Parameters
array$fixes

Definition at line 109 of file Tidy.php.

110 {
111 if (!isset($this->defaultLevel)) {
112 return;
113 }
114 if (!isset($this->fixesForLevel[$this->defaultLevel])) {
115 trigger_error(
116 'Default level ' . $this->defaultLevel . ' does not exist',
117 E_USER_ERROR
118 );
119 return;
120 }
121 $this->fixesForLevel[$this->defaultLevel] = array_keys($fixes);
122 }
$defaultLevel
Default level to place all fixes in.
Definition: Tidy.php:22

References $defaultLevel.

Referenced by setup().

+ Here is the caller graph for this function:

◆ populate()

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
array$fixesLookup table of fixes to activate

Definition at line 129 of file Tidy.php.

130 {
131 foreach ($fixes as $name => $fix) {
132 // determine what the fix is for
133 list($type, $params) = $this->getFixType($name);
134 switch ($type) {
135 case 'attr_transform_pre':
136 case 'attr_transform_post':
137 $attr = $params['attr'];
138 if (isset($params['element'])) {
139 $element = $params['element'];
140 if (empty($this->info[$element])) {
141 $e = $this->addBlankElement($element);
142 } else {
143 $e = $this->info[$element];
144 }
145 } else {
146 $type = "info_$type";
147 $e = $this;
148 }
149 // PHP does some weird parsing when I do
150 // $e->$type[$attr], so I have to assign a ref.
151 $f =& $e->$type;
152 $f[$attr] = $fix;
153 break;
154 case 'tag_transform':
155 $this->info_tag_transform[$params['element']] = $fix;
156 break;
157 case 'child':
158 case 'content_model_type':
159 $element = $params['element'];
160 if (empty($this->info[$element])) {
161 $e = $this->addBlankElement($element);
162 } else {
163 $e = $this->info[$element];
164 }
165 $e->$type = $fix;
166 break;
167 default:
168 trigger_error("Fix type $type not supported", E_USER_ERROR);
169 break;
170 }
171 }
172 }
getFixType($name)
Parses a fix name and determines what kind of fix it is, as well as other information defined by the ...
Definition: Tidy.php:182
addBlankElement($element)
Convenience function that creates a totally blank, non-standalone element.
Definition: HTMLModule.php:174

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

Referenced by setup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setup()

HTMLPurifier_HTMLModule_Tidy::setup (   $config)

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

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

Reimplemented from HTMLPurifier_HTMLModule.

Definition at line 43 of file Tidy.php.

44 {
45 // create fixes, initialize fixesForLevel
46 $fixes = $this->makeFixes();
47 $this->makeFixesForLevel($fixes);
48
49 // figure out which fixes to use
50 $level = $config->get('HTML.TidyLevel');
51 $fixes_lookup = $this->getFixesForLevel($level);
52
53 // get custom fix declarations: these need namespace processing
54 $add_fixes = $config->get('HTML.TidyAdd');
55 $remove_fixes = $config->get('HTML.TidyRemove');
56
57 foreach ($fixes as $name => $fix) {
58 // needs to be refactored a little to implement globbing
59 if (isset($remove_fixes[$name]) ||
60 (!isset($add_fixes[$name]) && !isset($fixes_lookup[$name]))) {
61 unset($fixes[$name]);
62 }
63 }
64
65 // populate this module with necessary fixes
66 $this->populate($fixes);
67 }
getFixesForLevel($level)
Retrieves all fixes per a level, returning fixes for that specific level as well as all levels below ...
Definition: Tidy.php:75
populate($fixes)
Populates the module with transforms and other special-case code based on a list of fixes passed to i...
Definition: Tidy.php:129
makeFixesForLevel($fixes)
Dynamically populates the $fixesForLevel member variable using the fixes array.
Definition: Tidy.php:109
makeFixes()
Defines all fixes the module will perform in a compact associative array of fix name to fix implement...
Definition: Tidy.php:225

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

+ Here is the call graph for this function:

Field Documentation

◆ $defaultLevel

HTMLPurifier_HTMLModule_Tidy::$defaultLevel = null

Default level to place all fixes in.

Disabled by default. @type string

Definition at line 22 of file Tidy.php.

Referenced by makeFixesForLevel().

◆ $fixesForLevel

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'); @type array

Definition at line 30 of file Tidy.php.

◆ $levels

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

List of supported levels.

Index zero is a special case "no fixes" level. @type array

Definition at line 15 of file Tidy.php.


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