Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
emoji.php
1<?php
2namespace Bitrix\Main\Text;
9class Emoji
10{
11 private static $emojiPattern = '%(?:
12 \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
13 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
14 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
15 )%xs';
16
17 public static function encode($text)
18 {
19 return self::replace($text, function ($m) {
20 return ":".bin2hex($m[0]).":";
21 });
22 }
23
24 public static function decode($text)
25 {
26 if (!\Bitrix\Main\Application::isUtfMode())
27 {
28 return $text;
29 }
30
31 return preg_replace_callback("/:([A-F0-9]{8}):/is".BX_UTF_PCRE_MODIFIER, function ($m)
32 {
33 $result = hex2bin($m[1]);
34
35 if (preg_match(self::$emojiPattern, $result))
36 {
37 return $result;
38 }
39
40 return $m[0];
41 }, $text);
42 }
43
50 public static function replace($text, $callback)
51 {
52 if (!\Bitrix\Main\Application::isUtfMode())
53 {
54 return $text;
55 }
56
57 return preg_replace_callback(self::$emojiPattern, $callback, $text);
58 }
59
60 public static function getSaveModificator()
61 {
62 return array(
63 array(__CLASS__, 'encode')
64 );
65 }
66
67 public static function getFetchModificator()
68 {
69 return array(
70 array(__CLASS__, 'decode')
71 );
72 }
73}
static getFetchModificator()
Definition emoji.php:67
static replace($text, $callback)
Definition emoji.php:50
static getSaveModificator()
Definition emoji.php:60
static encode($text)
Definition emoji.php:17
static decode($text)
Definition emoji.php:24