ILIAS
release_4-4 Revision
◀ ilDoc Overview
Linkify.php
Go to the documentation of this file.
1
<?php
2
6
class
HTMLPurifier_Injector_Linkify
extends
HTMLPurifier_Injector
7
{
8
9
public
$name
=
'Linkify'
;
10
public
$needed
= array(
'a'
=> array(
'href'
));
11
12
public
function
handleText
(&$token) {
13
if
(!$this->
allowsElement
(
'a'
))
return
;
14
15
if
(strpos($token->data,
'://'
) ===
false
) {
16
// our really quick heuristic failed, abort
17
// this may not work so well if we want to match things like
18
// "google.com", but then again, most people don't
19
return
;
20
}
21
22
// there is/are URL(s). Let's split the string:
23
// Note: this regex is extremely permissive
24
$bits = preg_split(
'#((?:https?|ftp)://[^\s\'"<>()]+)#S'
, $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
25
26
$token = array();
27
28
// $i = index
29
// $c = count
30
// $l = is link
31
for
($i = 0, $c = count($bits), $l =
false
; $i < $c; $i++, $l = !$l) {
32
if
(!$l) {
33
if
($bits[$i] ===
''
)
continue
;
34
$token[] =
new
HTMLPurifier_Token_Text
($bits[$i]);
35
}
else
{
36
$token[] =
new
HTMLPurifier_Token_Start
(
'a'
, array(
'href'
=> $bits[$i]));
37
$token[] =
new
HTMLPurifier_Token_Text
($bits[$i]);
38
$token[] =
new
HTMLPurifier_Token_End
(
'a'
);
39
}
40
}
41
42
}
43
44
}
45
46
// vim: et sw=4 sts=4
HTMLPurifier_Injector\allowsElement
allowsElement($name)
Tests if the context node allows a certain element.
Definition:
Injector.php:129
HTMLPurifier_Token_End
Concrete end token class.
Definition:
End.php:10
HTMLPurifier_Injector_Linkify
Injector that converts http, https and ftp text URLs to actual links.
Definition:
Linkify.php:6
HTMLPurifier_Token_Start
Concrete start token class.
Definition:
Start.php:6
HTMLPurifier_Injector_Linkify\$name
$name
Definition:
Linkify.php:9
HTMLPurifier_Injector_Linkify\$needed
$needed
Definition:
Linkify.php:10
HTMLPurifier_Injector_Linkify\handleText
handleText(&$token)
Definition:
Linkify.php:12
HTMLPurifier_Injector
Injects tokens into the document while parsing for well-formedness.
Definition:
Injector.php:16
HTMLPurifier_Token_Text
Concrete text token class.
Definition:
Text.php:12
Services
Html
HtmlPurifier
library
HTMLPurifier
Injector
Linkify.php
Generated on Mon Dec 21 2020 19:01:16 for ILIAS by
1.8.13 (using
Doxyfile
)