blob: 354254b64bebdbe75e9b2236f6db6b32b6dbeb8a (
plain) (
blame)
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
|
<?php
namespace dokuwiki\Parsing\ParserMode;
class Externallink extends AbstractMode
{
protected $schemes = [];
protected $patterns = [];
/** @inheritdoc */
public function preConnect()
{
if (count($this->patterns)) return;
$ltrs = '\w';
$gunk = '/\#~:.?+=&%@!\-\[\]';
$punc = '.:?\-;,';
$host = $ltrs . $punc;
$any = $ltrs . $gunk . $punc;
$this->schemes = getSchemes();
foreach ($this->schemes as $scheme) {
$this->patterns[] = '\b(?i)' . $scheme . '(?-i)://[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])';
}
$this->patterns[] = '(?<![/\\\\])\b(?i)www?(?-i)\.[' . $host . ']+?\.' .
'[' . $host . ']+?[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])';
$this->patterns[] = '(?<![/\\\\])\b(?i)ftp?(?-i)\.[' . $host . ']+?\.' .
'[' . $host . ']+?[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])';
}
/** @inheritdoc */
public function connectTo($mode)
{
foreach ($this->patterns as $pattern) {
$this->Lexer->addSpecialPattern($pattern, $mode, 'externallink');
}
}
/** @inheritdoc */
public function getSort()
{
return 330;
}
/**
* @return array
*/
public function getPatterns()
{
return $this->patterns;
}
}
|