Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
common.php
1<?php
2namespace Bitrix\Im;
3
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 $option = null;
52 {
53 $option = JSON_UNESCAPED_UNICODE;
54 }
55
56 return \Bitrix\Main\Web\Json::encode($array, $option);
57 }
58
59 public static function getCacheUserPostfix($id)
60 {
61 return '/'.mb_substr(md5($id), 2, 2).'/'.intval($id);
62 }
63
64 public static function isChatId($id)
65 {
66 return $id && preg_match('/^(chat|sg|crm)[0-9]{1,}$/i', $id);
67 }
68
69 public static function isDialogId($id)
70 {
71 return $id && preg_match('/^([0-9]{1,}|(chat|sg|crm)[0-9]{1,})$/i', $id);
72 }
73
74 public static function getUserId($userId = null)
75 {
76 if (is_null($userId) && is_object($GLOBALS['USER']))
77 {
78 $userId = $GLOBALS['USER']->getId();
79 }
80
81 $userId = intval($userId);
82 if (!$userId)
83 {
84 return false;
85 }
86
87 return $userId;
88 }
89
90 public static function toJson($array, $camelCase = true)
91 {
92 $result = [];
93 foreach ($array as $field => $value)
94 {
95 if (is_array($value))
96 {
97 $value = self::toJson($value, $camelCase);
98 }
99 else if ($value instanceof \Bitrix\Main\Type\DateTime)
100 {
101 $value = date('c', $value->getTimestamp());
102 }
103 else if (is_string($value) && $value && is_string($field) && in_array($field, Array('AVATAR')) && mb_strpos($value, 'http') !== 0)
104 {
105 $value = \Bitrix\Im\Common::getPublicDomain().$value;
106 }
107
108 if ($camelCase)
109 {
110 $field = lcfirst(\Bitrix\Main\Text\StringHelper::snake2camel($field));
111 }
112 else
113 {
114 $field = mb_strtolower($field);
115 }
116
117 $result[$field] = $value;
118 }
119
120 return $result;
121 }
122
123 public static function getExternalAuthId($skipTypes = [])
124 {
125 return \Bitrix\Im\Model\UserTable::filterExternalUserTypes($skipTypes);
126 }
127
128 public static function getPullExtra()
129 {
130 $extra = [
131 'revision_im_web' => \Bitrix\Im\Revision::getWeb(),
132 'revision_im_mobile' => \Bitrix\Im\Revision::getMobile(),
133 'revision_im_rest' => \Bitrix\Im\Revision::getRest(),
134 // deprecated
135 'im_revision' => \Bitrix\Im\Revision::getWeb(),
136 'im_revision_mobile' => \Bitrix\Im\Revision::getMobile(),
137 ];
138
139 if (ActionUuid::getInstance()->getValue() !== null)
140 {
141 $extra['action_uuid'] = ActionUuid::getInstance()->getValue();
142 }
143
144 return $extra;
145 }
146}
147
static getExternalAuthId($skipTypes=[])
Definition common.php:123
static toJson($array, $camelCase=true)
Definition common.php:90
static objectEncode($params, $pureJson=false)
Definition common.php:28
static isChatId($id)
Definition common.php:64
static getPullExtra()
Definition common.php:128
static jsonEncode($array=[])
Definition common.php:48
static getCacheUserPostfix($id)
Definition common.php:59
static getUserId($userId=null)
Definition common.php:74
static getPublicDomain()
Definition common.php:8
static isDialogId($id)
Definition common.php:69
$GLOBALS['____1444769544']
Definition license.php:1