3 require_once 'HTMLPurifier/Injector.php';
5 HTMLPurifier_ConfigSchema
::define(
6 'AutoFormat', 'PurifierLinkify', false, 'bool', '
8 Internal auto-formatter that converts configuration directives in
9 syntax <a>%Namespace.Directive</a> to links. <code>a</code> tags
10 with the <code>href</code> attribute must be allowed.
11 This directive has been available since 2.0.1.
15 HTMLPurifier_ConfigSchema
::define(
16 'AutoFormatParam', 'PurifierLinkifyDocURL', '#%s', 'string', '
18 Location of configuration documentation to link to, let %s substitute
19 into the configuration\'s namespace and directive names sans the percent
20 sign. This directive has been available since 2.0.1.
25 * Injector that converts configuration directive syntax %Namespace.Directive
28 class HTMLPurifier_Injector_PurifierLinkify
extends HTMLPurifier_Injector
31 var $name = 'PurifierLinkify';
33 var $needed = array('a' => array('href'));
35 function prepare($config, &$context) {
36 $this->docURL
= $config->get('AutoFormatParam', 'PurifierLinkifyDocURL');
37 return parent
::prepare($config, $context);
40 function handleText(&$token) {
41 if (!$this->allowsElement('a')) return;
42 if (strpos($token->data
, '%') === false) return;
44 $bits = preg_split('#%([a-z0-9]+\.[a-z0-9]+)#Si', $token->data
, -1, PREG_SPLIT_DELIM_CAPTURE
);
50 for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++
, $l = !$l) {
52 if ($bits[$i] === '') continue;
53 $token[] = new HTMLPurifier_Token_Text($bits[$i]);
55 $token[] = new HTMLPurifier_Token_Start('a',
56 array('href' => str_replace('%s', $bits[$i], $this->docURL
)));
57 $token[] = new HTMLPurifier_Token_Text('%' . $bits[$i]);
58 $token[] = new HTMLPurifier_Token_End('a');