~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to lib/htmlpurifier/HTMLPurifier/AttrTransform/ImgRequired.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
require_once 'HTMLPurifier/AttrTransform.php';
 
4
 
 
5
// must be called POST validation
 
6
 
 
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
/**
 
23
 * Transform that supplies default values for the src and alt attributes
 
24
 * in img tags, as well as prevents the img tag from being removed
 
25
 * because of a missing alt tag. This needs to be registered as both
 
26
 * a pre and post attribute transform.
 
27
 */
 
28
class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform
 
29
{
 
30
    
 
31
    function transform($attr, $config, &$context) {
 
32
        
 
33
        $src = true;
 
34
        if (!isset($attr['src'])) {
 
35
            if ($config->get('Core', 'RemoveInvalidImg')) return $attr;
 
36
            $attr['src'] = $config->get('Attr', 'DefaultInvalidImage');
 
37
            $src = false;
 
38
        }
 
39
        
 
40
        if (!isset($attr['alt'])) {
 
41
            if ($src) {
 
42
                $attr['alt'] = basename($attr['src']);
 
43
            } else {
 
44
                $attr['alt'] = $config->get('Attr', 'DefaultInvalidImageAlt');
 
45
            }
 
46
        }
 
47
        
 
48
        return $attr;
 
49
        
 
50
    }
 
51
    
 
52
}
 
53