ILIAS
release_5-2 Revision v5.2.25-18-g3f80b828510
◀ ilDoc Overview
Linkify.php
Go to the documentation of this file.
1
<?
php
2
6
class
HTMLPurifier_Injector_Linkify
extends
HTMLPurifier_Injector
7
{
11
public
$name
=
'Linkify'
;
12
16
public
$needed
=
array
(
'a'
=>
array
(
'href'
));
17
21
public
function
handleText
(&$token)
22
{
23
if
(!$this->
allowsElement
(
'a'
)) {
24
return
;
25
}
26
27
if
(strpos($token->data,
'://'
) ===
false
) {
28
// our really quick heuristic failed, abort
29
// this may not work so well if we want to match things like
30
// "google.com", but then again, most people don't
31
return
;
32
}
33
34
// there is/are URL(s). Let's split the string.
35
// We use this regex:
36
// https://gist.github.com/gruber/249502
37
// but with @cscott's backtracking fix and also
38
// the Unicode characters un-Unicodified.
39
$bits = preg_split(
40
'/\\b((?:[a-z][\\w\\-]+:(?:\\/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}\\/)(?:[^\\s()<>]|\\((?:[^\\s()<>]|(?:\\([^\\s()<>]+\\)))*\\))+(?:\\((?:[^\\s()<>]|(?:\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:\'".,<>?\x{00ab}\x{00bb}\x{201c}\x{201d}\x{2018}\x{2019}]))/iu'
,
41
$token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
42
43
44
$token =
array
();
45
46
// $i = index
47
// $c = count
48
// $l = is link
49
for
($i = 0, $c = count($bits),
$l
=
false
; $i < $c; $i++,
$l
= !
$l
) {
50
if
(!$l) {
51
if
($bits[$i] ===
''
) {
52
continue
;
53
}
54
$token[] =
new
HTMLPurifier_Token_Text
($bits[$i]);
55
}
else
{
56
$token[] =
new
HTMLPurifier_Token_Start
(
'a'
,
array
(
'href'
=> $bits[$i]));
57
$token[] =
new
HTMLPurifier_Token_Text
($bits[$i]);
58
$token[] =
new
HTMLPurifier_Token_End
(
'a'
);
59
}
60
}
61
}
62
}
63
64
// vim: et sw=4 sts=4
HTMLPurifier_Injector\allowsElement
allowsElement($name)
Tests if the context node allows a certain element.
Definition:
Injector.php:147
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
string
Definition:
Linkify.php:11
HTMLPurifier_Injector_Linkify\$needed
$needed
array
Definition:
Linkify.php:16
HTMLPurifier_Injector_Linkify\handleText
handleText(&$token)
Definition:
Linkify.php:21
array
Create styles array
The data for the language used.
Definition:
40duplicateStyle.php:19
HTMLPurifier_Injector
Injects tokens into the document while parsing for well-formedness.
Definition:
Injector.php:16
$l
global $l
Definition:
afr.php:30
php
HTMLPurifier_Token_Text
Concrete text token class.
Definition:
Text.php:12
libs
composer
vendor
ezyang
htmlpurifier
library
HTMLPurifier
Injector
Linkify.php
Generated on Fri Jan 24 2025 19:00:47 for ILIAS by
1.8.13 (using
Doxyfile
)