1: <?php
2:
3: 4: 5:
6: class HTMLPurifier_Injector_Linkify extends HTMLPurifier_Injector
7: {
8:
9: public $name = 'Linkify';
10: public $needed = array('a' => array('href'));
11:
12: public function handleText(&$token) {
13: if (!$this->allowsElement('a')) return;
14:
15: if (strpos($token->data, '://') === false) {
16:
17:
18:
19: return;
20: }
21:
22:
23:
24: $bits = preg_split('#((?:https?|ftp)://[^\s\'"<>()]+)#S', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
25:
26: $token = array();
27:
28:
29:
30:
31: for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++, $l = !$l) {
32: if (!$l) {
33: if ($bits[$i] === '') continue;
34: $token[] = new HTMLPurifier_Token_Text($bits[$i]);
35: } else {
36: $token[] = new HTMLPurifier_Token_Start('a', array('href' => $bits[$i]));
37: $token[] = new HTMLPurifier_Token_Text($bits[$i]);
38: $token[] = new HTMLPurifier_Token_End('a');
39: }
40: }
41:
42: }
43:
44: }
45:
46:
47: