ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
HTMLPurifier_Injector_Linkify Class Reference

Injector that converts http, https and ftp text URLs to actual links. More...

+ Inheritance diagram for HTMLPurifier_Injector_Linkify:
+ Collaboration diagram for HTMLPurifier_Injector_Linkify:

Public Member Functions

 handleText (&$token)
 
- Public Member Functions inherited from HTMLPurifier_Injector
 rewindOffset ($offset)
 Rewind to a spot to re-perform processing. More...
 
 getRewindOffset ()
 Retrieves rewind offset, and then unsets it. More...
 
 prepare ($config, $context)
 Prepares the injector by giving it the config and context objects: this allows references to important variables to be made within the injector. More...
 
 checkNeeded ($config)
 This function checks if the HTML environment will work with the Injector: if p tags are not allowed, the Auto-Paragraphing injector should not be enabled. More...
 
 allowsElement ($name)
 Tests if the context node allows a certain element. More...
 
 handleText (&$token)
 Handler that is called when a text token is processed. More...
 
 handleElement (&$token)
 Handler that is called when a start or empty token is processed. More...
 
 handleEnd (&$token)
 Handler that is called when an end token is processed. More...
 
 notifyEnd ($token)
 Notifier that is called when an end token is processed. More...
 

Data Fields

 $name = 'Linkify'
 string More...
 
 $needed = array('a' => array('href'))
 array More...
 
- Data Fields inherited from HTMLPurifier_Injector
 $name
 Advisory name of injector, this is for friendly error messages. More...
 
 $needed = array()
 Array of elements and attributes this injector creates and therefore need to be allowed by the definition. More...
 

Additional Inherited Members

- Protected Member Functions inherited from HTMLPurifier_Injector
 forward (&$i, &$current)
 Iterator function, which starts with the next token and continues until you reach the end of the input tokens. More...
 
 forwardUntilEndToken (&$i, &$current, &$nesting)
 Similar to _forward, but accepts a third parameter $nesting (which should be initialized at 0) and stops when we hit the end tag for the node $this->inputIndex starts in. More...
 
 backward (&$i, &$current)
 Iterator function, starts with the previous token and continues until you reach the beginning of input tokens. More...
 
- Protected Attributes inherited from HTMLPurifier_Injector
 $htmlDefinition
 HTMLPurifier_HTMLDefinition More...
 
 $currentNesting
 Reference to CurrentNesting variable in Context. More...
 
 $currentToken
 Reference to current token. More...
 
 $inputZipper
 Reference to InputZipper variable in Context. More...
 
 $rewindOffset = false
 Number of elements to rewind backwards (relative). More...
 

Detailed Description

Injector that converts http, https and ftp text URLs to actual links.

Definition at line 6 of file Linkify.php.

Member Function Documentation

◆ handleText()

HTMLPurifier_Injector_Linkify::handleText ( $token)
Parameters
HTMLPurifier_Token$token

Definition at line 21 of file Linkify.php.

References $i, $l, HTMLPurifier_Injector\allowsElement(), and array.

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  }
allowsElement($name)
Tests if the context node allows a certain element.
Definition: Injector.php:147
Concrete end token class.
Definition: End.php:10
Concrete start token class.
Definition: Start.php:6
Create styles array
The data for the language used.
global $l
Definition: afr.php:30
$i
Definition: disco.tpl.php:19
Concrete text token class.
Definition: Text.php:12
+ Here is the call graph for this function:

Field Documentation

◆ $name

HTMLPurifier_Injector_Linkify::$name = 'Linkify'

string

Definition at line 11 of file Linkify.php.

◆ $needed

HTMLPurifier_Injector_Linkify::$needed = array('a' => array('href'))

array

Definition at line 16 of file Linkify.php.


The documentation for this class was generated from the following file: