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

« back to all changes in this revision

Viewing changes to lib/htmlpurifier/HTMLPurifier/AttrTransform/ImgRequired.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/AttrTransform.php';
4
 
 
5
3
// must be called POST validation
6
4
 
7
 
HTMLPurifier_ConfigSchema::define(
8
 
    'Attr', 'DefaultInvalidImage', '', 'string',
9
 
    'This is the default image an img tag will be pointed to if it does '.
10
 
    'not have a valid src attribute.  In future versions, we may allow the '.
11
 
    'image tag to be removed completely, but due to design issues, this is '.
12
 
    'not possible right now.'
13
 
);
14
 
 
15
 
HTMLPurifier_ConfigSchema::define(
16
 
    'Attr', 'DefaultInvalidImageAlt', 'Invalid image', 'string',
17
 
    'This is the content of the alt tag of an invalid image if the user '.
18
 
    'had not previously specified an alt attribute.  It has no effect when the '.
19
 
    'image is valid but there was no alt attribute present.'
20
 
);
21
 
 
22
5
/**
23
6
 * Transform that supplies default values for the src and alt attributes
24
7
 * in img tags, as well as prevents the img tag from being removed
27
10
 */
28
11
class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform
29
12
{
30
 
    
31
 
    function transform($attr, $config, &$context) {
32
 
        
 
13
 
 
14
    public function transform($attr, $config, $context) {
 
15
 
33
16
        $src = true;
34
17
        if (!isset($attr['src'])) {
35
 
            if ($config->get('Core', 'RemoveInvalidImg')) return $attr;
36
 
            $attr['src'] = $config->get('Attr', 'DefaultInvalidImage');
 
18
            if ($config->get('Core.RemoveInvalidImg')) return $attr;
 
19
            $attr['src'] = $config->get('Attr.DefaultInvalidImage');
37
20
            $src = false;
38
21
        }
39
 
        
 
22
 
40
23
        if (!isset($attr['alt'])) {
41
24
            if ($src) {
42
 
                $attr['alt'] = basename($attr['src']);
 
25
                $alt = $config->get('Attr.DefaultImageAlt');
 
26
                if ($alt === null) {
 
27
                    // truncate if the alt is too long
 
28
                    $attr['alt'] = substr(basename($attr['src']),0,40);
 
29
                } else {
 
30
                    $attr['alt'] = $alt;
 
31
                }
43
32
            } else {
44
 
                $attr['alt'] = $config->get('Attr', 'DefaultInvalidImageAlt');
 
33
                $attr['alt'] = $config->get('Attr.DefaultInvalidImageAlt');
45
34
            }
46
35
        }
47
 
        
 
36
 
48
37
        return $attr;
49
 
        
 
38
 
50
39
    }
51
 
    
 
40
 
52
41
}
53
42
 
 
43
// vim: et sw=4 sts=4