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

« back to all changes in this revision

Viewing changes to lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Percentage.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
 
require_once 'HTMLPurifier/AttrDef/CSS/Number.php';
5
 
 
6
3
/**
7
4
 * Validates a Percentage as defined by the CSS spec.
8
5
 */
9
6
class HTMLPurifier_AttrDef_CSS_Percentage extends HTMLPurifier_AttrDef
10
7
{
11
 
    
 
8
 
12
9
    /**
13
10
     * Instance of HTMLPurifier_AttrDef_CSS_Number to defer number validation
14
11
     */
15
 
    var $number_def;
16
 
    
 
12
    protected $number_def;
 
13
 
17
14
    /**
18
15
     * @param Bool indicating whether to forbid negative values
19
16
     */
20
 
    function HTMLPurifier_AttrDef_CSS_Percentage($non_negative = false) {
 
17
    public function __construct($non_negative = false) {
21
18
        $this->number_def = new HTMLPurifier_AttrDef_CSS_Number($non_negative);
22
19
    }
23
 
    
24
 
    function validate($string, $config, &$context) {
25
 
        
 
20
 
 
21
    public function validate($string, $config, $context) {
 
22
 
26
23
        $string = $this->parseCDATA($string);
27
 
        
 
24
 
28
25
        if ($string === '') return false;
29
26
        $length = strlen($string);
30
27
        if ($length === 1) return false;
31
28
        if ($string[$length - 1] !== '%') return false;
32
 
        
 
29
 
33
30
        $number = substr($string, 0, $length - 1);
34
31
        $number = $this->number_def->validate($number, $config, $context);
35
 
        
 
32
 
36
33
        if ($number === false) return false;
37
34
        return "$number%";
38
 
        
 
35
 
39
36
    }
40
 
    
 
37
 
41
38
}
42
39
 
 
40
// vim: et sw=4 sts=4