Completed
Push — globalErrorHandling ( 41422f...51c1fb )
by Andreas
13:14 queued 10:21
created

Externallink::getPatterns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\Parsing\ParserMode;
4
5
class Externallink extends AbstractMode
6
{
7
    protected $schemes = array();
8
    protected $patterns = array();
9
10
    /** @inheritdoc */
11
    public function preConnect()
12
    {
13
        if (count($this->patterns)) return;
14
15
        $ltrs = '\w';
16
        $gunk = '/\#~:.?+=&%@!\-\[\]';
17
        $punc = '.:?\-;,';
18
        $host = $ltrs.$punc;
19
        $any  = $ltrs.$gunk.$punc;
20
21
        $this->schemes = getSchemes();
22
        foreach ($this->schemes as $scheme) {
23
            $this->patterns[] = '\b(?i)'.$scheme.'(?-i)://['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
24
        }
25
26
        $this->patterns[] = '(?<=\s)(?i)www?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
27
        $this->patterns[] = '(?<=\s)(?i)ftp?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
28
    }
29
30
    /** @inheritdoc */
31
    public function connectTo($mode)
32
    {
33
34
        foreach ($this->patterns as $pattern) {
35
            $this->Lexer->addSpecialPattern($pattern, $mode, 'externallink');
36
        }
37
    }
38
39
    /** @inheritdoc */
40
    public function getSort()
41
    {
42
        return 330;
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getPatterns()
49
    {
50
        return $this->patterns;
51
    }
52
}
53