~ubuntu-branches/ubuntu/natty/moodle/natty

« back to all changes in this revision

Viewing changes to lib/htmlpurifier/HTMLPurifier/Injector/Linkify.php

  • Committer: Bazaar Package Importer
  • Author(s): Tomasz Muras
  • Date: 2010-10-30 12:19:28 UTC
  • mfrom: (1.1.12 upstream) (3.1.10 squeeze)
  • Revision ID: james.westby@ubuntu.com-20101030121928-qzobi6mctpnk4dif
Tags: 1.9.9.dfsg2-2
* Added Romanian translation
* Updated Japanese translation (closes: #596820)
* Backporting security fixes from Moodle 1.9.10 (closes: #601384)
   - Updated embedded CAS to 1.1.3
   - Added patch for MDL-24523:
     clean_text() not filtering text in markdown format
   - Added patch for MDL-24810 and upgraded customized HTML Purifier to 4.2.0 
   - Added patch for MDL-24258:
     students can delete their forum posts later than $CFG->maxeditingtime 
     under certain conditions
   - Added patch for MDL-23377:
     Can't delete quiz attempts in course without enrolled students

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
 
3
 
require_once 'HTMLPurifier/Injector.php';
4
 
 
5
 
HTMLPurifier_ConfigSchema::define(
6
 
    'AutoFormat', 'Linkify', false, 'bool', '
7
 
<p>
8
 
  This directive turns on linkification, auto-linking http, ftp and
9
 
  https URLs. <code>a</code> tags with the <code>href</code> attribute
10
 
  must be allowed. This directive has been available since 2.0.1.
11
 
</p>
12
 
');
13
 
 
14
3
/**
15
4
 * Injector that converts http, https and ftp text URLs to actual links.
16
5
 */
17
6
class HTMLPurifier_Injector_Linkify extends HTMLPurifier_Injector
18
7
{
19
 
    
20
 
    var $name = 'Linkify';
21
 
    var $needed = array('a' => array('href'));
22
 
    
23
 
    function handleText(&$token) {
 
8
 
 
9
    public $name = 'Linkify';
 
10
    public $needed = array('a' => array('href'));
 
11
 
 
12
    public function handleText(&$token) {
24
13
        if (!$this->allowsElement('a')) return;
25
 
        
 
14
 
26
15
        if (strpos($token->data, '://') === false) {
27
16
            // our really quick heuristic failed, abort
28
17
            // this may not work so well if we want to match things like
29
18
            // "google.com", but then again, most people don't
30
19
            return;
31
20
        }
32
 
        
 
21
 
33
22
        // there is/are URL(s). Let's split the string:
34
23
        // Note: this regex is extremely permissive
35
24
        $bits = preg_split('#((?:https?|ftp)://[^\s\'"<>()]+)#S', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
36
 
        
 
25
 
37
26
        $token = array();
38
 
        
 
27
 
39
28
        // $i = index
40
29
        // $c = count
41
30
        // $l = is link
49
38
                $token[] = new HTMLPurifier_Token_End('a');
50
39
            }
51
40
        }
52
 
        
 
41
 
53
42
    }
54
 
    
 
43
 
55
44
}
56
45
 
 
46
// vim: et sw=4 sts=4