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/ImgRequired.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/ImgRequired.php')
-rw-r--r-- | inc/3rdparty/htmlpurifier/HTMLPurifier/AttrTransform/ImgRequired.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/inc/3rdparty/htmlpurifier/HTMLPurifier/AttrTransform/ImgRequired.php b/inc/3rdparty/htmlpurifier/HTMLPurifier/AttrTransform/ImgRequired.php new file mode 100644 index 00000000..561b4d9d --- /dev/null +++ b/inc/3rdparty/htmlpurifier/HTMLPurifier/AttrTransform/ImgRequired.php | |||
@@ -0,0 +1,48 @@ | |||
1 | <?php | ||
2 | |||
3 | // must be called POST validation | ||
4 | |||
5 | /** | ||
6 | * Transform that supplies default values for the src and alt attributes | ||
7 | * in img tags, as well as prevents the img tag from being removed | ||
8 | * because of a missing alt tag. This needs to be registered as both | ||
9 | * a pre and post attribute transform. | ||
10 | */ | ||
11 | class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform | ||
12 | { | ||
13 | |||
14 | /** | ||
15 | * @param array $attr | ||
16 | * @param HTMLPurifier_Config $config | ||
17 | * @param HTMLPurifier_Context $context | ||
18 | * @return array | ||
19 | */ | ||
20 | public function transform($attr, $config, $context) | ||
21 | { | ||
22 | $src = true; | ||
23 | if (!isset($attr['src'])) { | ||
24 | if ($config->get('Core.RemoveInvalidImg')) { | ||
25 | return $attr; | ||
26 | } | ||
27 | $attr['src'] = $config->get('Attr.DefaultInvalidImage'); | ||
28 | $src = false; | ||
29 | } | ||
30 | |||
31 | if (!isset($attr['alt'])) { | ||
32 | if ($src) { | ||
33 | $alt = $config->get('Attr.DefaultImageAlt'); | ||
34 | if ($alt === null) { | ||
35 | // truncate if the alt is too long | ||
36 | $attr['alt'] = substr(basename($attr['src']), 0, 40); | ||
37 | } else { | ||
38 | $attr['alt'] = $alt; | ||
39 | } | ||
40 | } else { | ||
41 | $attr['alt'] = $config->get('Attr.DefaultInvalidImageAlt'); | ||
42 | } | ||
43 | } | ||
44 | return $attr; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | // vim: et sw=4 sts=4 | ||