1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
authadapter.php
См. документацию.
1<?php
2
3namespace Bitrix\Seo\Retargeting;
4
5use Bitrix\Main\Loader;
6use Bitrix\Main\SystemException;
7use Bitrix\Main\Web\Uri;
8use Bitrix\Seo\BusinessSuite\Utils\QueueRemoveEventHandler;
9use Bitrix\Seo\Service;
10use Bitrix\Seo\Service as SeoService;
11
13{
15 protected $service;
16
18 protected $type;
19
20 /* @var \CSocServOAuthTransport|\CFacebookInterface */
21 protected $transport;
22
24 protected $data;
25
27 protected $parameters = ['URL_PARAMETERS' => []];
28
29 public function __construct($type)
30 {
31 $this->type = $type;
32
34 {
35 $this->parameters['URL_PARAMETERS']['force_confirm'] = 'yes';
36 }
37 }
38
43 public static function create($type, IService $service = null, bool $ignoreType = false)
44 {
45 if (!Loader::includeModule('socialservices'))
46 {
47 throw new SystemException('Module "socialservices" not installed.');
48 }
49
50 if ($type === 'facebook' && !$ignoreType)
51 {
52 $instance = new \Bitrix\Seo\Retargeting\FacebookAuthAdapter($type);
53 }
54 else
55 {
56 $instance = new static($type);
57 }
58
59 if ($service)
60 {
61 $instance->setService($service);
62 }
63
64 return $instance;
65 }
66
71 public function setService(IService $service)
72 {
73 $this->service = $service;
74
75 return $this;
76 }
77
82 public function setParameters(array $parameters = [])
83 {
84 $this->parameters = $parameters + $this->parameters;
85
86 return $this;
87 }
88
89 public function getAuthUrl()
90 {
92 {
93 try
94 {
96 }
97 catch (SystemException $e)
98 {
99 return '';
100 }
101 }
102
103 $authorizeData = SeoService::getAuthorizeData(
104 $this->getEngineCode(),
106 );
107
108 if (!empty($this->parameters['URL_PARAMETERS']))
109 {
110 $authorizeData['urlParameters'] = $this->parameters['URL_PARAMETERS'];
111 }
112
114
115 return $uri->addParams($authorizeData)->getLocator();
116 }
117
118 protected function getAuthData($isUseCache = true)
119 {
120 return ($this->canUseMultipleClients()
121 ? $this->getAuthDataMultiple()
122 : $this->getAuthDataSingle($isUseCache))
123 ;
124 }
125
126 protected function getAuthDataMultiple()
127 {
128 return $this->getClientById($this->getClientId());
129 }
130
131 protected function getAuthDataSingle($isUseCache = true)
132 {
133 if (!$isUseCache || !$this->data || count($this->data) == 0)
134 {
135 $this->data = SeoService::getAuth($this->getEngineCode());
136 }
137
138 return $this->data;
139 }
140
145 public function removeAuth()
146 {
147 $this->data = array();
148
149 if ($existedAuthData = $this->getAuthData(false))
150 {
152 $existedAuthData['proxy_client_id'],
153 $existedAuthData['engine_code']
154 );
155 $this->canUseMultipleClients()
156 ? SeoService::clearAuthForClient($existedAuthData)
158
159 }
160 }
161
165 protected function getEngineCode()
166 {
167 if ($this->service)
168 {
169 return $this->service::getEngineCode($this->type);
170 }
171
172 return Service::getEngineCode($this->type);
173 }
174
178 public function getType()
179 {
180 return $this->type;
181 }
182
183 public function getToken()
184 {
185 return is_array($data = $this->getAuthData(false)) ? $data['access_token'] : null;
186 }
187
191 public function hasAuth()
192 {
193 return $this->canUseMultipleClients()
194 ? count($this->getAuthorizedClientsList()) > 0
195 : $this->getToken() <> "";
196 }
197
201 public function canUseMultipleClients()
202 {
203 if (!$this->service)
204 {
206 }
207
208 if ($this->service instanceof IMultiClientService)
209 {
210 return $this->service::canUseMultipleClients();
211 }
212
213 return false;
214 }
215
220 public function getClientList()
221 {
222 return $this->canUseMultipleClients() ? SeoService::getClientList($this->getEngineCode(), $this->type) : [];
223 }
224
225 public function getClientById($clientId)
226 {
227 $clients = $this->getClientList();
228 foreach ($clients as $client)
229 {
230 if ($client['proxy_client_id'] == $clientId)
231 {
232 return $client;
233 }
234 }
235 return null;
236 }
237
242 public function getAuthorizedClientsList()
243 {
244 return array_filter(
245 $this->getClientList(),
246 static function ($item) : bool {
247 return $item['access_token'] <> '';
248 }
249 );
250 }
251
252 public function getClientId()
253 {
254 if (!$this->canUseMultipleClients())
255 {
256 return null;
257 }
258 $clientId = $this->service->getClientId();
259 if ($clientId)
260 {
261 $client = $this->getClientById($clientId);
262 if ($client['engine_code'] == $this->getEngineCode())
263 {
264 return $clientId;
265 }
266 return null;
267 }
268
269 // try to guess account id from accounts list:
270 $clients = $this->getClientList();
271 foreach ($clients as $client)
272 {
273 if ($client['proxy_client_type'] == SeoService::CLIENT_TYPE_COMPATIBLE)
274 {
275 return $client['proxy_client_id'];
276 }
277 }
278 return null;
279 }
280}
Определения uri.php:17
static handleEvent($clientId, $engineCode)
Определения queueremoveeventhandler.php:107
static create($type, IService $service=null, bool $ignoreType=false)
Определения authadapter.php:43
getAuthData($isUseCache=true)
Определения authadapter.php:118
setParameters(array $parameters=[])
Определения authadapter.php:82
getClientById($clientId)
Определения authadapter.php:225
setService(IService $service)
Определения authadapter.php:71
getAuthDataSingle($isUseCache=true)
Определения authadapter.php:131
const TYPE_YANDEX
Определения service.php:15
static getEngineCode($type)
Определения service.php:40
static canUseMultipleClients()
Определения service.php:69
const CLIENT_TYPE_COMPATIBLE
Определения service.php:55
static getAuthorizeLink()
Определения service.php:370
static getAuth(string $engineCode)
Определения service.php:78
static clearAuthForClient($client, $localOnly=false)
Определения service.php:242
static register(string $serviceUrl='')
Определения service.php:318
static isRegistered()
Определения service.php:65
static getClientList($engineCode=false, string $type=null)
Определения service.php:116
static clearAuth($engineCode, $localOnly=false)
Определения service.php:225
static getAuthorizeData($engine, $clientType=false)
Определения service.php:381
const CLIENT_TYPE_SINGLE
Определения service.php:53
const CLIENT_TYPE_MULTIPLE
Определения service.php:54
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
$instance
Определения ps_b24_final.php:14
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$clientId
Определения seo_client.php:18