ILIAS
Release_5_0_x_branch Revision 61816
◀ ilDoc Overview
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
Examples
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Groups
Pages
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
// Note: this regex is extremely permissive
36
$bits = preg_split(
'#((?:https?|ftp)://[^\s\'",<>()]+)#Su'
, $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
37
38
39
$token = array();
40
41
// $i = index
42
// $c = count
43
// $l = is link
44
for
($i = 0, $c = count($bits), $l =
false
; $i < $c; $i++, $l = !$l) {
45
if
(!$l) {
46
if
($bits[$i] ===
''
) {
47
continue
;
48
}
49
$token[] =
new
HTMLPurifier_Token_Text
($bits[$i]);
50
}
else
{
51
$token[] =
new
HTMLPurifier_Token_Start
(
'a'
, array(
'href'
=> $bits[$i]));
52
$token[] =
new
HTMLPurifier_Token_Text
($bits[$i]);
53
$token[] =
new
HTMLPurifier_Token_End
(
'a'
);
54
}
55
}
56
}
57
}
58
59
// vim: et sw=4 sts=4
Services
Html
HtmlPurifier
library
HTMLPurifier
Injector
Linkify.php
Generated on Wed Apr 27 2016 21:01:41 for ILIAS by
1.8.1.2 (using
Doxyfile
)