summaryrefslogtreecommitdiff
path: root/platform/www/inc/Parsing/ParserMode/Smiley.php
blob: 084ccc9ed6c5910a5f5a286c6d9ff4f26992e5c6 (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
<?php

namespace dokuwiki\Parsing\ParserMode;

use dokuwiki\Parsing\Lexer\Lexer;

class Smiley extends AbstractMode
{
    protected $smileys = array();
    protected $pattern = '';

    /**
     * Smiley constructor.
     * @param string[] $smileys
     */
    public function __construct($smileys)
    {
        $this->smileys = $smileys;
    }

    /** @inheritdoc */
    public function preConnect()
    {
        if (!count($this->smileys) || $this->pattern != '') return;

        $sep = '';
        foreach ($this->smileys as $smiley) {
            $this->pattern .= $sep.'(?<=\W|^)'. Lexer::escape($smiley).'(?=\W|$)';
            $sep = '|';
        }
    }

    /** @inheritdoc */
    public function connectTo($mode)
    {
        if (!count($this->smileys)) return;

        if (strlen($this->pattern) > 0) {
            $this->Lexer->addSpecialPattern($this->pattern, $mode, 'smiley');
        }
    }

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