|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00007 class HTMLPurifier_Injector_PurifierLinkify extends HTMLPurifier_Injector 00008 { 00009 00010 public $name = 'PurifierLinkify'; 00011 public $docURL; 00012 public $needed = array('a' => array('href')); 00013 00014 public function prepare($config, $context) { 00015 $this->docURL = $config->get('AutoFormat.PurifierLinkify.DocURL'); 00016 return parent::prepare($config, $context); 00017 } 00018 00019 public function handleText(&$token) { 00020 if (!$this->allowsElement('a')) return; 00021 if (strpos($token->data, '%') === false) return; 00022 00023 $bits = preg_split('#%([a-z0-9]+\.[a-z0-9]+)#Si', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE); 00024 $token = array(); 00025 00026 // $i = index 00027 // $c = count 00028 // $l = is link 00029 for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++, $l = !$l) { 00030 if (!$l) { 00031 if ($bits[$i] === '') continue; 00032 $token[] = new HTMLPurifier_Token_Text($bits[$i]); 00033 } else { 00034 $token[] = new HTMLPurifier_Token_Start('a', 00035 array('href' => str_replace('%s', $bits[$i], $this->docURL))); 00036 $token[] = new HTMLPurifier_Token_Text('%' . $bits[$i]); 00037 $token[] = new HTMLPurifier_Token_End('a'); 00038 } 00039 } 00040 00041 } 00042 00043 } 00044 00045 // vim: et sw=4 sts=4