diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-02-21 15:57:10 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-02-21 15:57:10 +0100 |
commit | 99679d06884120c57f43b44e55e03595f1f87bed (patch) | |
tree | a3f2a1aa1afdaeca1386d0c6e8a75344fd2241fb /inc/3rdparty/htmlpurifier/HTMLPurifier/AttrTransform/ImgSpace.php | |
parent | 655214ab30ee84884dc408488b85586f36263fcb (diff) | |
parent | d3b47e94705e17b3ba3529cbb1dc6efe69c5d2b7 (diff) | |
download | wallabag-1.5.2.tar.gz wallabag-1.5.2.tar.zst wallabag-1.5.2.zip |
Merge pull request #481 from wallabag/dev1.5.2
1.5.2
Diffstat (limited to 'inc/3rdparty/htmlpurifier/HTMLPurifier/AttrTransform/ImgSpace.php')
-rw-r--r-- | inc/3rdparty/htmlpurifier/HTMLPurifier/AttrTransform/ImgSpace.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/inc/3rdparty/htmlpurifier/HTMLPurifier/AttrTransform/ImgSpace.php b/inc/3rdparty/htmlpurifier/HTMLPurifier/AttrTransform/ImgSpace.php new file mode 100644 index 00000000..aec42aea --- /dev/null +++ b/inc/3rdparty/htmlpurifier/HTMLPurifier/AttrTransform/ImgSpace.php | |||
@@ -0,0 +1,61 @@ | |||
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 | ||