| 1: | <?php
|
| 2: |
|
| 3: | |
| 4: | |
| 5: | |
| 6: |
|
| 7: | class HTMLPurifier_Injector_PurifierLinkify extends HTMLPurifier_Injector
|
| 8: | {
|
| 9: | |
| 10: | |
| 11: |
|
| 12: | public $name = 'PurifierLinkify';
|
| 13: |
|
| 14: | |
| 15: | |
| 16: |
|
| 17: | public $docURL;
|
| 18: |
|
| 19: | |
| 20: | |
| 21: |
|
| 22: | public $needed = array('a' => array('href'));
|
| 23: |
|
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: |
|
| 29: | public function prepare($config, $context)
|
| 30: | {
|
| 31: | $this->docURL = $config->get('AutoFormat.PurifierLinkify.DocURL');
|
| 32: | return parent::prepare($config, $context);
|
| 33: | }
|
| 34: |
|
| 35: | |
| 36: | |
| 37: |
|
| 38: | public function handleText(&$token)
|
| 39: | {
|
| 40: | if (!$this->allowsElement('a')) {
|
| 41: | return;
|
| 42: | }
|
| 43: | if (strpos($token->data, '%') === false) {
|
| 44: | return;
|
| 45: | }
|
| 46: |
|
| 47: | $bits = preg_split('#%([a-z0-9]+\.[a-z0-9]+)#Si', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
|
| 48: | $token = array();
|
| 49: |
|
| 50: |
|
| 51: |
|
| 52: |
|
| 53: | for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++, $l = !$l) {
|
| 54: | if (!$l) {
|
| 55: | if ($bits[$i] === '') {
|
| 56: | continue;
|
| 57: | }
|
| 58: | $token[] = new HTMLPurifier_Token_Text($bits[$i]);
|
| 59: | } else {
|
| 60: | $token[] = new HTMLPurifier_Token_Start(
|
| 61: | 'a',
|
| 62: | array('href' => str_replace('%s', $bits[$i], $this->docURL))
|
| 63: | );
|
| 64: | $token[] = new HTMLPurifier_Token_Text('%' . $bits[$i]);
|
| 65: | $token[] = new HTMLPurifier_Token_End('a');
|
| 66: | }
|
| 67: | }
|
| 68: | }
|
| 69: | }
|
| 70: |
|
| 71: |
|
| 72: | |