blob: 5b52df8e08be32b433fb93627526c46d6061bf2c (
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
49
50
51
52
53
54
55
56
57
|
<?php
/**
* SmileyFormat.php
*
* Provides a formatting object for smileys.
*
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @category Stud.IP
* @package smiley
* @since 2.3
* @uses Smiley
*/
class SmileyFormat extends TextFormat
{
const REGEXP = '(\>|^|\s):([_a-zA-Z][_a-z0-9A-Z-]*):(?=$|\<|\s)';
function __construct()
{
$rules = [];
// Smiley rule
$rules['smileys'] = [
'start' => self::REGEXP,
'callback' => 'SmileyFormat::smiley'
];
// Smiley short notation rule
$needles = array_keys(Smiley::getShort());
$needles = array_map('preg_quote', $needles);
$rules['smileys_short'] = [
'start' => '(>|^|\s)(' . implode('|', $needles) . ')(?=$|<|\s)',
'callback' => 'SmileyFormat::short'
];
parent::__construct($rules);
}
/**
* Smiley notation defined by name (:name:)
*/
static function smiley($markup, $matches)
{
return $matches[1] . Smiley::getByName($matches[2])->getImageTag() . $matches[3];
}
/**
* Smiley short notation as defined in database
*/
static function short($markup, $matches)
{
$smileys = Smiley::getShort();
$name = $smileys[$matches[2]] ?? '';
return $name
? $matches[1] . Smiley::getByName($name)->getImageTag() . $matches[3]
: $matches[0];
}
}
|