Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
smile.php
1<?php
2namespace Bitrix\Main\Rest;
3
4class 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}
static getCurrent()
Definition context.php:241
static getServerAddress()
Definition smile.php:60
static getList($arParams, $n, \CRestServer $server)
Definition smile.php:6
static objectEncode($data, $options=[])
Definition smile.php:25