aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc/Parsing/ParserMode/Wordblock.php
blob: 64d377fe01fe5b17a71702b7b560336f9f9d1728 (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
<?php

namespace dokuwiki\Parsing\ParserMode;

use dokuwiki\Parsing\Lexer\Lexer;

/**
 * @fixme is this actually used?
 */
class Wordblock extends AbstractMode
{
    protected $badwords = [];
    protected $pattern = '';

    /**
     * Wordblock constructor.
     * @param $badwords
     */
    public function __construct($badwords)
    {
        $this->badwords = $badwords;
    }

    /** @inheritdoc */
    public function preConnect()
    {

        if (count($this->badwords) == 0 || $this->pattern != '') {
            return;
        }

        $sep = '';
        foreach ($this->badwords as $badword) {
            $this->pattern .= $sep . '(?<=\b)(?i)' . Lexer::escape($badword) . '(?-i)(?=\b)';
            $sep = '|';
        }
    }

    /** @inheritdoc */
    public function connectTo($mode)
    {
        if (strlen($this->pattern) > 0) {
            $this->Lexer->addSpecialPattern($this->pattern, $mode, 'wordblock');
        }
    }

    /** @inheritdoc */
    public function getSort()
    {
        return 250;
    }
}