~ubuntu-branches/ubuntu/natty/moodle/natty

« back to all changes in this revision

Viewing changes to lib/htmlpurifier/HTMLPurifier/AttrDef/Enum.php

  • Committer: Bazaar Package Importer
  • Author(s): Tomasz Muras
  • Date: 2010-10-30 12:19:28 UTC
  • mfrom: (1.1.12 upstream) (3.1.10 squeeze)
  • Revision ID: james.westby@ubuntu.com-20101030121928-qzobi6mctpnk4dif
Tags: 1.9.9.dfsg2-2
* Added Romanian translation
* Updated Japanese translation (closes: #596820)
* Backporting security fixes from Moodle 1.9.10 (closes: #601384)
   - Updated embedded CAS to 1.1.3
   - Added patch for MDL-24523:
     clean_text() not filtering text in markdown format
   - Added patch for MDL-24810 and upgraded customized HTML Purifier to 4.2.0 
   - Added patch for MDL-24258:
     students can delete their forum posts later than $CFG->maxeditingtime 
     under certain conditions
   - Added patch for MDL-23377:
     Can't delete quiz attempts in course without enrolled students

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
 
3
 
require_once 'HTMLPurifier/AttrDef.php';
4
 
 
5
3
// Enum = Enumerated
6
4
/**
7
5
 * Validates a keyword against a list of valid values.
11
9
 */
12
10
class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
13
11
{
14
 
    
 
12
 
15
13
    /**
16
14
     * Lookup table of valid values.
 
15
     * @todo Make protected
17
16
     */
18
 
    var $valid_values   = array();
19
 
    
 
17
    public $valid_values   = array();
 
18
 
20
19
    /**
21
20
     * Bool indicating whether or not enumeration is case sensitive.
22
21
     * @note In general this is always case insensitive.
23
22
     */
24
 
    var $case_sensitive = false; // values according to W3C spec
25
 
    
 
23
    protected $case_sensitive = false; // values according to W3C spec
 
24
 
26
25
    /**
27
26
     * @param $valid_values List of valid values
28
27
     * @param $case_sensitive Bool indicating whether or not case sensitive
29
28
     */
30
 
    function HTMLPurifier_AttrDef_Enum(
 
29
    public function __construct(
31
30
        $valid_values = array(), $case_sensitive = false
32
31
    ) {
33
32
        $this->valid_values = array_flip($valid_values);
34
33
        $this->case_sensitive = $case_sensitive;
35
34
    }
36
 
    
37
 
    function validate($string, $config, &$context) {
 
35
 
 
36
    public function validate($string, $config, $context) {
38
37
        $string = trim($string);
39
38
        if (!$this->case_sensitive) {
40
39
            // we may want to do full case-insensitive libraries
41
40
            $string = ctype_lower($string) ? $string : strtolower($string);
42
41
        }
43
42
        $result = isset($this->valid_values[$string]);
44
 
        
 
43
 
45
44
        return $result ? $string : false;
46
45
    }
47
 
    
 
46
 
48
47
    /**
49
48
     * @param $string In form of comma-delimited list of case-insensitive
50
49
     *      valid values. Example: "foo,bar,baz". Prepend "s:" to make
51
50
     *      case sensitive
52
51
     */
53
 
    function make($string) {
 
52
    public function make($string) {
54
53
        if (strlen($string) > 2 && $string[0] == 's' && $string[1] == ':') {
55
54
            $string = substr($string, 2);
56
55
            $sensitive = true;
60
59
        $values = explode(',', $string);
61
60
        return new HTMLPurifier_AttrDef_Enum($values, $sensitive);
62
61
    }
63
 
    
 
62
 
64
63
}
65
64
 
 
65
// vim: et sw=4 sts=4