root/afridex/plugins/Flutter/purifier_lib/HTMLPurifier/Injector/PurifierLinkify.php

Revision 21, 1.4 kB (checked in by admin, 18 years ago)
Line 
1<?php
2
3/**
4 * Injector that converts configuration directive syntax %Namespace.Directive
5 * to links
6 */
7class HTMLPurifier_Injector_PurifierLinkify extends HTMLPurifier_Injector
8{
9   
10    public $name = 'PurifierLinkify';
11    public $docURL;
12    public $needed = array('a' => array('href'));
13   
14    public function prepare($config, $context) {
15        $this->docURL = $config->get('AutoFormatParam', 'PurifierLinkifyDocURL');
16        return parent::prepare($config, $context);
17    }
18   
19    public function handleText(&$token) {
20        if (!$this->allowsElement('a')) return;
21        if (strpos($token->data, '%') === false) return;
22       
23        $bits = preg_split('#%([a-z0-9]+\.[a-z0-9]+)#Si', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
24        $token = array();
25       
26        // $i = index
27        // $c = count
28        // $l = is link
29        for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++, $l = !$l) {
30            if (!$l) {
31                if ($bits[$i] === '') continue;
32                $token[] = new HTMLPurifier_Token_Text($bits[$i]);
33            } else {
34                $token[] = new HTMLPurifier_Token_Start('a',
35                    array('href' => str_replace('%s', $bits[$i], $this->docURL)));
36                $token[] = new HTMLPurifier_Token_Text('%' . $bits[$i]);
37                $token[] = new HTMLPurifier_Token_End('a');
38            }
39        }
40       
41    }
42   
43}
44
Note: See TracBrowser for help on using the browser.