3
require_once 'HTMLPurifier/Injector.php';
5
HTMLPurifier_ConfigSchema::define(
6
'AutoFormat', 'Linkify', false, 'bool', '
8
This directive turns on linkification, auto-linking http, ftp and
9
https URLs. <code>a</code> tags with the <code>href</code> attribute
10
must be allowed. This directive has been available since 2.0.1.
15
4
* Injector that converts http, https and ftp text URLs to actual links.
17
6
class HTMLPurifier_Injector_Linkify extends HTMLPurifier_Injector
20
var $name = 'Linkify';
21
var $needed = array('a' => array('href'));
23
function handleText(&$token) {
9
public $name = 'Linkify';
10
public $needed = array('a' => array('href'));
12
public function handleText(&$token) {
24
13
if (!$this->allowsElement('a')) return;
26
15
if (strpos($token->data, '://') === false) {
27
16
// our really quick heuristic failed, abort
28
17
// this may not work so well if we want to match things like
29
18
// "google.com", but then again, most people don't
33
22
// there is/are URL(s). Let's split the string:
34
23
// Note: this regex is extremely permissive
35
24
$bits = preg_split('#((?:https?|ftp)://[^\s\'"<>()]+)#S', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);