xref: /dokuwiki/inc/Parsing/ParserMode/Filelink.php (revision 71096e46fcbfaeaa808667aba794e77fe2780169)
1be906b56SAndreas Gohr<?php
2be906b56SAndreas Gohr
3be906b56SAndreas Gohrnamespace dokuwiki\Parsing\ParserMode;
4be906b56SAndreas Gohr
5*71096e46SAndreas Gohruse dokuwiki\Parsing\Handler;
6*71096e46SAndreas Gohr
7be906b56SAndreas Gohrclass Filelink extends AbstractMode
8be906b56SAndreas Gohr{
9be906b56SAndreas Gohr    protected $pattern;
10be906b56SAndreas Gohr
11be906b56SAndreas Gohr    /** @inheritdoc */
12*71096e46SAndreas Gohr    public function getSort()
13*71096e46SAndreas Gohr    {
14*71096e46SAndreas Gohr        return 360;
15*71096e46SAndreas Gohr    }
16*71096e46SAndreas Gohr
17*71096e46SAndreas Gohr    /** @inheritdoc */
18be906b56SAndreas Gohr    public function preConnect()
19be906b56SAndreas Gohr    {
20be906b56SAndreas Gohr
21be906b56SAndreas Gohr        $ltrs = '\w';
22be906b56SAndreas Gohr        $gunk = '/\#~:.?+=&%@!\-';
23be906b56SAndreas Gohr        $punc = '.:?\-;,';
24be906b56SAndreas Gohr        $any  = $ltrs . $gunk . $punc;
25be906b56SAndreas Gohr
26be906b56SAndreas Gohr        $this->pattern = '\b(?i)file(?-i)://[' . $any . ']+?[' .
27be906b56SAndreas Gohr            $punc . ']*[^' . $any . ']';
28be906b56SAndreas Gohr    }
29be906b56SAndreas Gohr
30be906b56SAndreas Gohr    /** @inheritdoc */
31be906b56SAndreas Gohr    public function connectTo($mode)
32be906b56SAndreas Gohr    {
33be906b56SAndreas Gohr        $this->Lexer->addSpecialPattern(
34be906b56SAndreas Gohr            $this->pattern,
35be906b56SAndreas Gohr            $mode,
36be906b56SAndreas Gohr            'filelink'
37be906b56SAndreas Gohr        );
38be906b56SAndreas Gohr    }
39be906b56SAndreas Gohr
40be906b56SAndreas Gohr    /** @inheritdoc */
41*71096e46SAndreas Gohr    public function handle($match, $state, $pos, Handler $handler)
42be906b56SAndreas Gohr    {
43*71096e46SAndreas Gohr        $handler->addCall('filelink', [$match, null], $pos);
44*71096e46SAndreas Gohr        return true;
45be906b56SAndreas Gohr    }
46be906b56SAndreas Gohr}
47