Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
common.php
1
<?php
2
namespace
Bitrix\Im
;
3
4
use
Bitrix\Im\V2\ActionUuid
;
5
6
class
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
;
51
if
(\
Bitrix
\Main\
Application::isUtfMode
())
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
Bitrix\Im\Common
Definition
common.php:7
Bitrix\Im\Common\getExternalAuthId
static getExternalAuthId($skipTypes=[])
Definition
common.php:123
Bitrix\Im\Common\toJson
static toJson($array, $camelCase=true)
Definition
common.php:90
Bitrix\Im\Common\objectEncode
static objectEncode($params, $pureJson=false)
Definition
common.php:28
Bitrix\Im\Common\isChatId
static isChatId($id)
Definition
common.php:64
Bitrix\Im\Common\getPullExtra
static getPullExtra()
Definition
common.php:128
Bitrix\Im\Common\jsonEncode
static jsonEncode($array=[])
Definition
common.php:48
Bitrix\Im\Common\getCacheUserPostfix
static getCacheUserPostfix($id)
Definition
common.php:59
Bitrix\Im\Common\getUserId
static getUserId($userId=null)
Definition
common.php:74
Bitrix\Im\Common\getPublicDomain
static getPublicDomain()
Definition
common.php:8
Bitrix\Im\Common\isDialogId
static isDialogId($id)
Definition
common.php:69
Bitrix\Im\Text
Definition
text.php:9
Bitrix\Im\V2\ActionUuid
Definition
ActionUuid.php:8
Bitrix\Im\V2\ActionUuid\getInstance
static getInstance()
Definition
ActionUuid.php:17
Bitrix\Main\Application\isUtfMode
static isUtfMode()
Definition
application.php:698
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Im
Bitrix\Main\Type
Definition
collection.php:2
Bitrix\Main\$GLOBALS
$GLOBALS['____1444769544']
Definition
license.php:1
Bitrix
modules
im
lib
common.php
Создано системой
1.10.0