Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
responsevkontakte.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 = 'vkontakte';
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 switch ((string) $parsed['error']['error_code'])
29 {
30 case '100':
31 $errorMessage = Loc::getMessage(
32 'SEO_RETARGETING_SERVICE_RESPONSE_VKONTAKTE_ERROR_100',
33 array(
34 '%code%' => htmlspecialcharsbx($parsed['error']['error_code']),
35 '%msg%' => htmlspecialcharsbx($parsed['error']['error_msg']),
36 )
37 );
38 break;
39 }
40
41 $errorMessage = Loc::getMessage('SEO_RETARGETING_SERVICE_RESPONSE_VKONTAKTE_ERROR')
42 . ': '
43 . $errorMessage;
44 $this->addError(new Error($errorMessage, $parsed['error']['error_code']));
45 }
46
47 $result = array();
48 if ($parsed['response'])
49 {
50 $result = $parsed['response'];
51 }
52 else if(!isset($parsed['error']))
53 {
54 $result = $parsed;
55 }
56
57 $this->setData(is_array($result) ? $result : array($result));
58 }
59}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29