~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
/**
4
 
 * Pre-transform that changes deprecated hspace and vspace attributes to CSS
5
 
 */
6
 
class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform {
7
 
 
8
 
    protected $attr;
9
 
    protected $css = array(
10
 
        'hspace' => array('left', 'right'),
11
 
        'vspace' => array('top', 'bottom')
12
 
    );
13
 
 
14
 
    public function __construct($attr) {
15
 
        $this->attr = $attr;
16
 
        if (!isset($this->css[$attr])) {
17
 
            trigger_error(htmlspecialchars($attr) . ' is not valid space attribute');
18
 
        }
19
 
    }
20
 
 
21
 
    public function transform($attr, $config, $context) {
22
 
 
23
 
        if (!isset($attr[$this->attr])) return $attr;
24
 
 
25
 
        $width = $this->confiscateAttr($attr, $this->attr);
26
 
        // some validation could happen here
27
 
 
28
 
        if (!isset($this->css[$this->attr])) return $attr;
29
 
 
30
 
        $style = '';
31
 
        foreach ($this->css[$this->attr] as $suffix) {
32
 
            $property = "margin-$suffix";
33
 
            $style .= "$property:{$width}px;";
34
 
        }
35
 
 
36
 
        $this->prependCSS($attr, $style);
37
 
 
38
 
        return $attr;
39
 
 
40
 
    }
41
 
 
42
 
}
43
 
 
44
 
// vim: et sw=4 sts=4
 
1
<?php
 
2
 
 
3
/**
 
4
 * Pre-transform that changes deprecated hspace and vspace attributes to CSS
 
5
 */
 
6
class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform
 
7
{
 
8
    /**
 
9
     * @type string
 
10
     */
 
11
    protected $attr;
 
12
 
 
13
    /**
 
14
     * @type array
 
15
     */
 
16
    protected $css = array(
 
17
        'hspace' => array('left', 'right'),
 
18
        'vspace' => array('top', 'bottom')
 
19
    );
 
20
 
 
21
    /**
 
22
     * @param string $attr
 
23
     */
 
24
    public function __construct($attr)
 
25
    {
 
26
        $this->attr = $attr;
 
27
        if (!isset($this->css[$attr])) {
 
28
            trigger_error(htmlspecialchars($attr) . ' is not valid space attribute');
 
29
        }
 
30
    }
 
31
 
 
32
    /**
 
33
     * @param array $attr
 
34
     * @param HTMLPurifier_Config $config
 
35
     * @param HTMLPurifier_Context $context
 
36
     * @return array
 
37
     */
 
38
    public function transform($attr, $config, $context)
 
39
    {
 
40
        if (!isset($attr[$this->attr])) {
 
41
            return $attr;
 
42
        }
 
43
 
 
44
        $width = $this->confiscateAttr($attr, $this->attr);
 
45
        // some validation could happen here
 
46
 
 
47
        if (!isset($this->css[$this->attr])) {
 
48
            return $attr;
 
49
        }
 
50
 
 
51
        $style = '';
 
52
        foreach ($this->css[$this->attr] as $suffix) {
 
53
            $property = "margin-$suffix";
 
54
            $style .= "$property:{$width}px;";
 
55
        }
 
56
        $this->prependCSS($attr, $style);
 
57
        return $attr;
 
58
    }
 
59
}
 
60
 
 
61
// vim: et sw=4 sts=4