Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / AttrDef.php
blob334a7aceddf29741c0e870cd05ecad13b062742a
1 <?php
3 /**
4 * Base class for all validating attribute definitions.
5 *
6 * This family of classes forms the core for not only HTML attribute validation,
7 * but also any sort of string that needs to be validated or cleaned (which
8 * means CSS properties and composite definitions are defined here too).
9 * Besides defining (through code) what precisely makes the string valid,
10 * subclasses are also responsible for cleaning the code if possible.
13 class HTMLPurifier_AttrDef
16 /**
17 * Tells us whether or not an HTML attribute is minimized. Only the
18 * boolean attribute vapourware would use this.
20 var $minimized = false;
22 /**
23 * Validates and cleans passed string according to a definition.
25 * @public
26 * @param $string String to be validated and cleaned.
27 * @param $config Mandatory HTMLPurifier_Config object.
28 * @param $context Mandatory HTMLPurifier_AttrContext object.
30 function validate($string, $config, &$context) {
31 trigger_error('Cannot call abstract function', E_USER_ERROR);
34 /**
35 * Convenience method that parses a string as if it were CDATA.
37 * This method process a string in the manner specified at
38 * <http://www.w3.org/TR/html4/types.html#h-6.2> by removing
39 * leading and trailing whitespace, ignoring line feeds, and replacing
40 * carriage returns and tabs with spaces. While most useful for HTML
41 * attributes specified as CDATA, it can also be applied to most CSS
42 * values.
44 * @note This method is not entirely standards compliant, as trim() removes
45 * more types of whitespace than specified in the spec. In practice,
46 * this is rarely a problem, as those extra characters usually have
47 * already been removed by HTMLPurifier_Encoder.
49 * @warning This processing is inconsistent with XML's whitespace handling
50 * as specified by section 3.3.3 and referenced XHTML 1.0 section
51 * 4.7. Compliant processing requires all line breaks normalized
52 * to "\n", so the fix is not as simple as fixing it in this
53 * function. Trim and whitespace collapsing are supposed to only
54 * occur in NMTOKENs. However, note that we are NOT necessarily
55 * parsing XML, thus, this behavior may still be correct.
57 * @public
59 function parseCDATA($string) {
60 $string = trim($string);
61 $string = str_replace("\n", '', $string);
62 $string = str_replace(array("\r", "\t"), ' ', $string);
63 return $string;