Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
vk.php
1<?php
2
4
11
12class Vk
13{
14 public static function isAuthorized(): PublicActionResult
15 {
16 $result = new PublicActionResult();
17 if (!Loader::includeModule('seo'))
18 {
19 $error = new Error;
20 $error->addError('SEO_NOT_INCLUDED');
21 $result->setError($error);
22
23 return $result;
24 }
25
26 $service = Media\Service::getInstance();
27 $authAdapter = Retargeting\AuthAdapter::create('vkontakte', $service);
28
29 $result->setResult($authAdapter->hasAuth());
30
31 return $result;
32 }
33
34 public static function getAuthUrl(): PublicActionResult
35 {
36 $result = new PublicActionResult();
37 if (!Loader::includeModule('seo'))
38 {
39 $error = new Error;
40 $error->addError('SEO_NOT_INCLUDED');
41 $result->setError($error);
42
43 return $result;
44 }
45
46 $service = Media\Service::getInstance();
47 $authAdapter = Retargeting\AuthAdapter::create('vkontakte', $service);
48
49 $result->setResult($authAdapter->getAuthUrl());
50
51 return $result;
52 }
53
54 public static function getVideoInfo(string $videoId): PublicActionResult
55 {
56 $result = new PublicActionResult();
57 if (!Loader::includeModule('seo'))
58 {
59 $error = new Error;
60 $error->addError('SEO_NOT_INCLUDED');
61 $result->setError($error);
62 $result->setResult(false);
63
64 return $result;
65 }
66
67 $response = Media\Service::getVideo($videoId);
68 if ($response->isSuccess())
69 {
70 $responseData = $response->getData();
71 if ($responseData['count'])
72 {
73 $responseItem = $responseData['items'][0];
74 if ($responseItem['content_restricted'] && $responseItem['content_restricted_message'])
75 {
76 $error = new Error;
77 $error->addError(
78 'CONTENT_RESTRICTED',
79 Encoding::convertEncoding(
80 $responseItem['content_restricted_message'],
81 'utf8',
82 SITE_CHARSET
83 )
84 );
85 $result->setError($error);
86 }
87 else
88 {
89 $result->setResult([
90 'player' => $responseItem['player'],
91 'preview' => $responseItem['image'][min(count($responseItem['image']), 4) - 1],
92 ]);
93 }
94 }
95 else
96 {
97 $result->setResult([]);
98 }
99 }
100 else
101 {
102 $error = new Error;
103 foreach ($response->getErrors() as $err)
104 {
105 $error->addError($err->getCode(), $err->getMessage());
106 }
107 $result->setError($error);
108 }
109
110 return $result;
111 }
112}
addError($code, $message='')
Definition error.php:18
static getVideoInfo(string $videoId)
Definition vk.php:54