Server IP : 85.193.89.191 / Your IP : 18.188.181.248 Web Server : Apache System : Linux 956367-cx40159.tmweb.ru 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64 User : bitrix ( 600) PHP Version : 8.1.27 Disable Function : NONE MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/bitrix/www/bitrix/modules/main/lib/text/ |
Upload File : |
<?php namespace Bitrix\Main\Text; /** * Bitrix Framework * @package bitrix * @subpackage main * @copyright 2001-2019 Bitrix */ class Emoji { private static $emojiPattern = '%(?: \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 )%xs'; public static function encode($text) { return self::replace($text, function ($m) { return ":".bin2hex($m[0]).":"; }); } public static function decode($text) { if (!\Bitrix\Main\Application::isUtfMode()) { return $text; } return preg_replace_callback("/:([A-F0-9]{8}):/is".BX_UTF_PCRE_MODIFIER, function ($m) { $result = hex2bin($m[1]); if (preg_match(self::$emojiPattern, $result)) { return $result; } return $m[0]; }, $text); } /** * @param string $text * @param callable $callback * * @return string|string[]|null */ public static function replace($text, $callback) { if (!\Bitrix\Main\Application::isUtfMode()) { return $text; } return preg_replace_callback(self::$emojiPattern, $callback, $text); } public static function getSaveModificator() { return array( array(__CLASS__, 'encode') ); } public static function getFetchModificator() { return array( array(__CLASS__, 'decode') ); } }