Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
responsevkads.php
1<?
2
4
5use \Bitrix\Main\Error;
6use \Bitrix\Main\Localization\Loc;
8use \Bitrix\Main\Web\Json;
9use \Bitrix\Seo\Retargeting\Response;
10
11Loc::loadMessages(__FILE__);
13{
14 const TYPE_CODE = 'vkads';
15
16 public function parse($data)
17 {
18 // Need for preserve double UTF-conversion, because VK return JSON answer in result
19 if (is_string($data))
20 {
21 $data = Encoding::convertEncoding($data, SITE_CHARSET, 'UTF-8');
22 }
23
24 $parsed = is_array($data) ? $data : Json::decode($data);
25 if ($parsed['error'])
26 {
27 $errorMessage = $parsed['error']['error_msg'];
28 if ((string)$parsed['error']['error_code'] === '100')
29 {
30 $errorMessage = Loc::getMessage(
31 'SEO_RETARGETING_SERVICE_RESPONSE_VKONTAKTE_ERROR_100',
32 [
33 '%code%' => htmlspecialcharsbx($parsed['error']['error_code']),
34 '%msg%' => htmlspecialcharsbx($parsed['error']['error_msg']),
35 ]
36 );
37 }
38
39 $errorMessage = Loc::getMessage('SEO_RETARGETING_SERVICE_RESPONSE_VKONTAKTE_ERROR')
40 . ': '
41 . $errorMessage;
42 $this->addError(new Error($errorMessage, $parsed['error']['error_code']));
43 }
44
45 $result = [];
46 if ($parsed['response'])
47 {
48 $result = $parsed['response'];
49 }
50 elseif(!isset($parsed['error']))
51 {
52 $result = $parsed;
53 }
54
55 $this->setData(is_array($result) ? $result : [$result]);
56 }
57}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29