blob: c5c5b00440cf998eac965aa8ffc3bfe3110894e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
<?php
/**
* Display the URL of an anchor or image instead of linking to it.
*/
class HTMLPurifier_Injector_Unlinkify extends HTMLPurifier_Injector
{
public $name = 'Unlinkify';
public $needed = ['a' => 'href', 'img' => 'src'];
private $sanitizer;
private $config;
private $context;
public function prepare($config, $context)
{
$this->sanitizer = new HTMLPurifier_AttrDef_URI();
$this->config = $config;
$this->context = $context;
return parent::prepare($config, $context);
}
public function handleElement(&$token)
{
if (isset($this->needed[$token->name])) {
$attribute = $this->needed[$token->name];
$url = '';
if (isset($token->attr[$attribute])) {
$url = $this->sanitizer->validate(
$token->attr[$attribute],
$this->config,
$this->context
);
}
$token = $url ? new HTMLPurifier_Token_Text('[ ' . $url . ' ]') : false;
}
}
}
|