ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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
 rewind ($index)
 Rewind to a spot to re-perform processing. More...
 
 getRewind ()
 Retrieves rewind, 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'
 
 $needed = array('a' => array('href'))
 
- 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...
 
 current (&$i, &$current)
 Initializes the iterator at the current position. More...
 
- Protected Attributes inherited from HTMLPurifier_Injector
 $htmlDefinition
 Instance of HTMLPurifier_HTMLDefinition. More...
 
 $currentNesting
 Reference to CurrentNesting variable in Context. More...
 
 $inputTokens
 Reference to InputTokens variable in Context. More...
 
 $inputIndex
 Reference to InputIndex variable in Context. More...
 
 $rewind = false
 Index of inputTokens to rewind to. 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)

Definition at line 12 of file Linkify.php.

References HTMLPurifier_Injector\allowsElement().

12  {
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  }
allowsElement($name)
Tests if the context node allows a certain element.
Definition: Injector.php:129
Concrete end token class.
Definition: End.php:10
Concrete start token class.
Definition: Start.php:6
Concrete text token class.
Definition: Text.php:12
+ Here is the call graph for this function:

Field Documentation

◆ $name

HTMLPurifier_Injector_Linkify::$name = 'Linkify'

Definition at line 9 of file Linkify.php.

◆ $needed

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

Definition at line 10 of file Linkify.php.


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