~gt/sahana-agasti/relief-experiments

« back to all changes in this revision

Viewing changes to 3rd/htmlpurifier/library/HTMLPurifier/AttrDef.php

  • Committer: turtle
  • Date: 2009-11-10 23:51:44 UTC
  • Revision ID: turtle@turtle-laptop-20091110235144-lvhvgwfm053jvq5q
first relief codebase

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
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.
 
11
 */
 
12
 
 
13
class HTMLPurifier_AttrDef
 
14
{
 
15
    
 
16
    /**
 
17
     * Tells us whether or not an HTML attribute is minimized. Has no
 
18
     * meaning in other contexts.
 
19
     */
 
20
    var $minimized = false;
 
21
    
 
22
    /**
 
23
     * Tells us whether or not an HTML attribute is required. Has no
 
24
     * meaning in other contexts
 
25
     */
 
26
    var $required = false;
 
27
    
 
28
    /**
 
29
     * Validates and cleans passed string according to a definition.
 
30
     * 
 
31
     * @public
 
32
     * @param $string String to be validated and cleaned.
 
33
     * @param $config Mandatory HTMLPurifier_Config object.
 
34
     * @param $context Mandatory HTMLPurifier_AttrContext object.
 
35
     */
 
36
    function validate($string, $config, &$context) {
 
37
        trigger_error('Cannot call abstract function', E_USER_ERROR);
 
38
    }
 
39
    
 
40
    /**
 
41
     * Convenience method that parses a string as if it were CDATA.
 
42
     * 
 
43
     * This method process a string in the manner specified at
 
44
     * <http://www.w3.org/TR/html4/types.html#h-6.2> by removing
 
45
     * leading and trailing whitespace, ignoring line feeds, and replacing
 
46
     * carriage returns and tabs with spaces.  While most useful for HTML
 
47
     * attributes specified as CDATA, it can also be applied to most CSS
 
48
     * values.
 
49
     * 
 
50
     * @note This method is not entirely standards compliant, as trim() removes
 
51
     *       more types of whitespace than specified in the spec. In practice,
 
52
     *       this is rarely a problem, as those extra characters usually have
 
53
     *       already been removed by HTMLPurifier_Encoder.
 
54
     * 
 
55
     * @warning This processing is inconsistent with XML's whitespace handling
 
56
     *          as specified by section 3.3.3 and referenced XHTML 1.0 section
 
57
     *          4.7.  Compliant processing requires all line breaks normalized
 
58
     *          to "\n", so the fix is not as simple as fixing it in this
 
59
     *          function.  Trim and whitespace collapsing are supposed to only
 
60
     *          occur in NMTOKENs.  However, note that we are NOT necessarily
 
61
     *          parsing XML, thus, this behavior may still be correct.
 
62
     * 
 
63
     * @public
 
64
     */
 
65
    function parseCDATA($string) {
 
66
        $string = trim($string);
 
67
        $string = str_replace("\n", '', $string);
 
68
        $string = str_replace(array("\r", "\t"), ' ', $string);
 
69
        return $string;
 
70
    }
 
71
    
 
72
    /**
 
73
     * Factory method for creating this class from a string.
 
74
     * @param $string String construction info
 
75
     * @return Created AttrDef object corresponding to $string
 
76
     * @public
 
77
     */
 
78
    function make($string) {
 
79
        // default implementation, return flyweight of this object
 
80
        // if overloaded, it is *necessary* for you to clone the
 
81
        // object (usually by instantiating a new copy) and return that
 
82
        return $this;
 
83
    }
 
84
    
 
85
}
 
86