1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
common.php
См. документацию.
1<?php
2namespace Bitrix\Im;
3
4use Bitrix\Im\V2\ActionUuid;
5
6class Common
7{
8 public static function getPublicDomain()
9 {
10 $schema = \Bitrix\Main\Context::getCurrent()->getRequest()->isHttps()? "https" : "http";
11
12 if (defined("SITE_SERVER_NAME") && SITE_SERVER_NAME <> '')
13 {
14 $domain = SITE_SERVER_NAME;
15 }
16 else
17 {
18 $domain = \Bitrix\Main\Config\Option::get("main", "server_name", '');
19 if (!$domain)
20 {
21 $domain = $_SERVER['SERVER_NAME'].(in_array($_SERVER['SERVER_PORT'], Array(80, 443))?'':':'.$_SERVER['SERVER_PORT']);
22 }
23 }
24
25 return $schema."://".$domain;
26 }
27
28 public static function objectEncode($params, $pureJson = false)
29 {
30 if (is_array($params))
31 {
32 array_walk_recursive($params, function(&$value, $key)
33 {
34 if ($value instanceof \Bitrix\Main\Type\DateTime)
35 {
36 $value = date('c', $value->getTimestamp());
37 }
38 else if (is_string($key) && in_array($key, ['AVATAR', 'AVATAR_HR']) && is_string($value) && $value && mb_strpos($value, 'http') !== 0)
39 {
40 $value = \Bitrix\Im\Common::getPublicDomain().$value;
41 }
42 });
43 }
44
45 return $pureJson? self::jsonEncode($params): \CUtil::PhpToJSObject($params);
46 }
47
48 public static function jsonEncode($array = [])
49 {
50 return \Bitrix\Main\Web\Json::encode($array, JSON_UNESCAPED_UNICODE);
51 }
52
53 public static function getCacheUserPostfix($id)
54 {
55 return '/'.mb_substr(md5($id), 2, 2).'/'.intval($id);
56 }
57
58 public static function isChatId($id)
59 {
60 return $id && preg_match('/^(chat|sg|crm)[0-9]{1,}$/i', $id);
61 }
62
63 public static function isDialogId($id)
64 {
65 if (is_string($id) || is_int($id))
66 {
67 return $id && preg_match('/^([0-9]{1,}|(chat|sg|crm)[0-9]{1,})$/i', $id);
68 }
69
70 return false;
71 }
72
73 public static function getUserId($userId = null)
74 {
75 if (is_null($userId) && is_object($GLOBALS['USER']))
76 {
77 $userId = $GLOBALS['USER']->getId();
78 }
79
80 $userId = intval($userId);
81 if (!$userId)
82 {
83 return false;
84 }
85
86 return $userId;
87 }
88
89 public static function toJson($array, $camelCase = true)
90 {
91 $result = [];
92 foreach ($array as $field => $value)
93 {
94 if (is_array($value))
95 {
96 $value = self::toJson($value, $camelCase);
97 }
98 else if ($value instanceof \Bitrix\Main\Type\DateTime)
99 {
100 $value = date('c', $value->getTimestamp());
101 }
102 else if (is_string($value) && $value && is_string($field) && in_array($field, Array('AVATAR')) && mb_strpos($value, 'http') !== 0)
103 {
104 $value = \Bitrix\Im\Common::getPublicDomain().$value;
105 }
106
107 if ($camelCase)
108 {
109 $field = lcfirst(\Bitrix\Main\Text\StringHelper::snake2camel($field));
110 }
111 else
112 {
113 $field = mb_strtolower($field);
114 }
115
116 $result[$field] = $value;
117 }
118
119 return $result;
120 }
121
122 public static function getExternalAuthId($skipTypes = [])
123 {
124 return \Bitrix\Im\Model\UserTable::filterExternalUserTypes($skipTypes);
125 }
126
127 public static function getPullExtra()
128 {
129 $extra = [
130 'revision_im_web' => \Bitrix\Im\Revision::getWeb(),
131 'revision_im_mobile' => \Bitrix\Im\Revision::getMobile(),
132 'revision_im_rest' => \Bitrix\Im\Revision::getRest(),
133 // deprecated
134 'im_revision' => \Bitrix\Im\Revision::getWeb(),
135 'im_revision_mobile' => \Bitrix\Im\Revision::getMobile(),
136 'is_shared_event' => false,
137 ];
138
139 if (ActionUuid::getInstance()->getValue() !== null)
140 {
141 $extra['action_uuid'] = ActionUuid::getInstance()->getValue();
142 }
143
144 return $extra;
145 }
146}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения common.php:7
static getExternalAuthId($skipTypes=[])
Определения common.php:122
static toJson($array, $camelCase=true)
Определения common.php:89
static objectEncode($params, $pureJson=false)
Определения common.php:28
static isChatId($id)
Определения common.php:58
static getPullExtra()
Определения common.php:127
static jsonEncode($array=[])
Определения common.php:48
static getCacheUserPostfix($id)
Определения common.php:53
static getUserId($userId=null)
Определения common.php:73
static getPublicDomain()
Определения common.php:8
static isDialogId($id)
Определения common.php:63
static getRest()
Определения revision.php:63
static getMobile()
Определения revision.php:47
static getWeb()
Определения revision.php:42
static getInstance()
Определения ActionUuid.php:17
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
$result
Определения get_property_values.php:14
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
Определения base32.php:2
Определения collection.php:2
$GLOBALS['____1690880296']
Определения license.php:1
if(empty($signedUserToken)) $key
Определения quickway.php:257
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799