]> git.immae.eu Git - github/wallabag/wallabag.git/blame - inc/3rdparty/htmlpurifier/HTMLPurifier/Injector/PurifierLinkify.php
remove autoload section in composer.json
[github/wallabag/wallabag.git] / inc / 3rdparty / htmlpurifier / HTMLPurifier / Injector / PurifierLinkify.php
CommitLineData
d4949327
NL
1<?php\r
2\r
3/**\r
4 * Injector that converts configuration directive syntax %Namespace.Directive\r
5 * to links\r
6 */\r
7class HTMLPurifier_Injector_PurifierLinkify extends HTMLPurifier_Injector\r
8{\r
9 /**\r
10 * @type string\r
11 */\r
12 public $name = 'PurifierLinkify';\r
13\r
14 /**\r
15 * @type string\r
16 */\r
17 public $docURL;\r
18\r
19 /**\r
20 * @type array\r
21 */\r
22 public $needed = array('a' => array('href'));\r
23\r
24 /**\r
25 * @param HTMLPurifier_Config $config\r
26 * @param HTMLPurifier_Context $context\r
27 * @return string\r
28 */\r
29 public function prepare($config, $context)\r
30 {\r
31 $this->docURL = $config->get('AutoFormat.PurifierLinkify.DocURL');\r
32 return parent::prepare($config, $context);\r
33 }\r
34\r
35 /**\r
36 * @param HTMLPurifier_Token $token\r
37 */\r
38 public function handleText(&$token)\r
39 {\r
40 if (!$this->allowsElement('a')) {\r
41 return;\r
42 }\r
43 if (strpos($token->data, '%') === false) {\r
44 return;\r
45 }\r
46\r
47 $bits = preg_split('#%([a-z0-9]+\.[a-z0-9]+)#Si', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);\r
48 $token = array();\r
49\r
50 // $i = index\r
51 // $c = count\r
52 // $l = is link\r
53 for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++, $l = !$l) {\r
54 if (!$l) {\r
55 if ($bits[$i] === '') {\r
56 continue;\r
57 }\r
58 $token[] = new HTMLPurifier_Token_Text($bits[$i]);\r
59 } else {\r
60 $token[] = new HTMLPurifier_Token_Start(\r
61 'a',\r
62 array('href' => str_replace('%s', $bits[$i], $this->docURL))\r
63 );\r
64 $token[] = new HTMLPurifier_Token_Text('%' . $bits[$i]);\r
65 $token[] = new HTMLPurifier_Token_End('a');\r
66 }\r
67 }\r
68 }\r
69}\r
70\r
71// vim: et sw=4 sts=4\r