summaryrefslogtreecommitdiff
path: root/inc/parser/spamcheck.php
blob: 1c2958e6f07b677e834504553305550d88d5055e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');

require_once DOKU_INC . 'inc/parser/renderer.php';

class Doku_Renderer_SpamCheck extends Doku_Renderer {
    
    // This should be populated by the code executing the instructions
    var $currentCall;
    
    // An array of instructions that contain spam
    var $spamFound = array();
    
    // pcre pattern for finding spam
    var $spamPattern = '#^$#';
    
    function internallink($link, $title = NULL) {
        $this->__checkTitle($title);
    }
    
    function externallink($link, $title = NULL) {
        $this->__checkLinkForSpam($link);
        $this->__checkTitle($title);
    }
    
    function interwikilink($link, $title = NULL) {
        $this->__checkTitle($title);
    }
    
    function filelink($link, $title = NULL) {
        $this->__checkLinkForSpam($link);
        $this->__checkTitle($title);
    }
    
    function windowssharelink($link, $title = NULL) {
        $this->__checkLinkForSpam($link);
        $this->__checkTitle($title);
    }
    
    function email($address, $title = NULL) {
        $this->__checkLinkForSpam($address);
        $this->__checkTitle($title);
    }
    
    function internalmedialink ($src) {
        $this->__checkLinkForSpam($src);
    }

    function externalmedialink($src) {
        $this->__checkLinkForSpam($src);
    }

    function __checkTitle($title) {
        if ( is_array($title) && isset($title['src'])) {
            $this->__checkLinkForSpam($title['src']);
        }
    }
    
    // Pattern matching happens here
    /**
    * @TODO What about links like www.google.com - no http://
    */
    function __checkLinkForSpam($link) {
        if( preg_match($this->spamPattern,$link) ) {
            $spam = $this->currentCall;
            $spam[3] = $link;
            $this->spamFound[] = $spam;
        }
    }
}

?>