4 * Injector that converts configuration directive syntax %Namespace.Directive
7 class HTMLPurifier_Injector_PurifierLinkify
extends HTMLPurifier_Injector
12 public $name = 'PurifierLinkify';
22 public $needed = array('a' => array('href'));
25 * @param HTMLPurifier_Config $config
26 * @param HTMLPurifier_Context $context
29 public function prepare($config, $context)
31 $this->docURL
= $config->get('AutoFormat.PurifierLinkify.DocURL');
32 return parent
::prepare($config, $context);
36 * @param HTMLPurifier_Token $token
38 public function handleText(&$token)
40 if (!$this->allowsElement('a')) {
43 if (strpos($token->data
, '%') === false) {
47 $bits = preg_split('#%([a-z0-9]+\.[a-z0-9]+)#Si', $token->data
, -1, PREG_SPLIT_DELIM_CAPTURE
);
53 for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++
, $l = !$l) {
55 if ($bits[$i] === '') {
58 $token[] = new HTMLPurifier_Token_Text($bits[$i]);
60 $token[] = new HTMLPurifier_Token_Start(
62 array('href' => str_replace('%s', $bits[$i], $this->docURL
))
64 $token[] = new HTMLPurifier_Token_Text('%' . $bits[$i]);
65 $token[] = new HTMLPurifier_Token_End('a');