Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
smile.php
1
<?php
2
namespace
Bitrix\Main\Rest
;
3
4
class
Smile
extends
\IRestService
5
{
6
public
static
function
getList
($arParams, $n, \CRestServer $server)
7
{
8
$options = [];
9
if
(isset($arParams[
'FULL_TYPINGS'
]) && $arParams[
'FULL_TYPINGS'
] ===
'Y'
)
10
{
11
$options[
'FULL_TYPINGS'
] =
'Y'
;
12
}
13
14
$smiles = \CSmileGallery::getSmilesWithSets(\CSmileGallery::GALLERY_DEFAULT, $options);
15
16
return
self::objectEncode
([
17
'SETS'
=> $smiles[
'SMILE_SET'
],
18
'SMILES'
=> $smiles[
'SMILE'
],
19
], [
20
'IMAGE_FIELD'
=> [
'IMAGE'
]
21
]);
22
}
23
24
/* Utils */
25
public
static
function
objectEncode
($data, $options = [])
26
{
27
if
(!is_array($options[
'IMAGE_FIELD'
]))
28
{
29
$options[
'IMAGE_FIELD'
] = [
'AVATAR'
,
'AVATAR_HR'
];
30
}
31
32
if
(is_array($data))
33
{
34
$result = [];
35
foreach
($data as $key => $value)
36
{
37
if
(is_array($value))
38
{
39
$value =
self::objectEncode
($value, $options);
40
}
41
else
if
($value instanceof \
Bitrix
\Main\
Type
\
DateTime
)
42
{
43
$value = date(
'c'
, $value->getTimestamp());
44
}
45
else
if
(is_string($key) && in_array($key, $options[
'IMAGE_FIELD'
]) && is_string($value) && $value && mb_strpos($value,
'http'
) !== 0)
46
{
47
$value =
self::getServerAddress
().$value;
48
}
49
50
$key = str_replace(
'_'
,
''
, lcfirst(ucwords(mb_strtolower($key),
'_'
)));
51
52
$result[$key] = $value;
53
}
54
$data = $result;
55
}
56
57
return
$data;
58
}
59
60
public
static
function
getServerAddress
()
61
{
62
$publicUrl = \Bitrix\Main\Config\Option::get(
'main'
,
'last_site_url'
,
''
);
63
64
if
($publicUrl)
65
{
66
return
$publicUrl;
67
}
68
else
69
{
70
return
(\
Bitrix
\Main\
Context::getCurrent
()->getRequest()->isHttps() ?
"https"
:
"http"
).
"://"
.$_SERVER[
'SERVER_NAME'
].(in_array($_SERVER[
'SERVER_PORT'
], Array(80, 443))?
''
:
':'
.$_SERVER[
'SERVER_PORT'
]);
71
}
72
}
73
}
Bitrix\Main\Context\getCurrent
static getCurrent()
Definition
context.php:241
Bitrix\Main\Rest\Smile
Definition
smile.php:5
Bitrix\Main\Rest\Smile\getServerAddress
static getServerAddress()
Definition
smile.php:60
Bitrix\Main\Rest\Smile\getList
static getList($arParams, $n, \CRestServer $server)
Definition
smile.php:6
Bitrix\Main\Rest\Smile\objectEncode
static objectEncode($data, $options=[])
Definition
smile.php:25
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Main\Rest
Definition
handlers.php:8
Bitrix\Main\Type
Definition
collection.php:2
Bitrix
modules
main
lib
rest
smile.php
Создано системой
1.10.0