1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
authadapter.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Seo\Retargeting;
4
5
use Bitrix\Main\Loader;
6
use Bitrix\Main\SystemException;
7
use Bitrix\Main\Web\Uri;
8
use Bitrix\Seo\BusinessSuite\Utils\QueueRemoveEventHandler;
9
use Bitrix\Seo\Service;
10
use Bitrix\Seo\Service as SeoService;
11
12
class
AuthAdapter
13
{
15
protected
$service
;
16
18
protected
$type
;
19
20
/* @var \CSocServOAuthTransport|\CFacebookInterface */
21
protected
$transport
;
22
23
protected
$requestCodeParamName
;
24
protected
$data
;
25
27
protected
$parameters
= [
'URL_PARAMETERS'
=> []];
28
29
public
function
__construct
(
$type
)
30
{
31
$this->type =
$type
;
32
33
if
(
$type
=== \
Bitrix
\
Seo
\
Retargeting
\
Service::TYPE_YANDEX
)
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
{
91
if
(!
SeoService::isRegistered
())
92
{
93
try
94
{
95
SeoService::register
();
96
}
97
catch
(
SystemException
$e)
98
{
99
return
''
;
100
}
101
}
102
103
$authorizeData =
SeoService::getAuthorizeData
(
104
$this->
getEngineCode
(),
105
$this->
canUseMultipleClients
() ?
Service::CLIENT_TYPE_MULTIPLE
:
Service::CLIENT_TYPE_SINGLE
106
);
107
108
if
(!empty($this->parameters[
'URL_PARAMETERS'
]))
109
{
110
$authorizeData[
'urlParameters'
] = $this->parameters[
'URL_PARAMETERS'
];
111
}
112
113
$uri
=
new
Uri
(
SeoService::getAuthorizeLink
());
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
{
151
QueueRemoveEventHandler::handleEvent
(
152
$existedAuthData[
'proxy_client_id'
],
153
$existedAuthData[
'engine_code'
]
154
);
155
$this->
canUseMultipleClients
()
156
?
SeoService::clearAuthForClient
($existedAuthData)
157
:
SeoService::clearAuth
($this->
getEngineCode
());
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
{
205
return
Service::canUseMultipleClients
();
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
}
Bitrix\Main\SystemException
Определения
SystemException.php:9
Bitrix\Main\Web\Uri
Определения
uri.php:17
Bitrix\Seo\BusinessSuite\Utils\QueueRemoveEventHandler\handleEvent
static handleEvent($clientId, $engineCode)
Определения
queueremoveeventhandler.php:107
Bitrix\Seo\Retargeting\AuthAdapter
Определения
authadapter.php:13
Bitrix\Seo\Retargeting\AuthAdapter\create
static create($type, IService $service=null, bool $ignoreType=false)
Определения
authadapter.php:43
Bitrix\Seo\Retargeting\AuthAdapter\$transport
$transport
Определения
authadapter.php:21
Bitrix\Seo\Retargeting\AuthAdapter\getToken
getToken()
Определения
authadapter.php:183
Bitrix\Seo\Retargeting\AuthAdapter\getAuthData
getAuthData($isUseCache=true)
Определения
authadapter.php:118
Bitrix\Seo\Retargeting\AuthAdapter\setParameters
setParameters(array $parameters=[])
Определения
authadapter.php:82
Bitrix\Seo\Retargeting\AuthAdapter\getEngineCode
getEngineCode()
Определения
authadapter.php:165
Bitrix\Seo\Retargeting\AuthAdapter\removeAuth
removeAuth()
Определения
authadapter.php:145
Bitrix\Seo\Retargeting\AuthAdapter\getClientById
getClientById($clientId)
Определения
authadapter.php:225
Bitrix\Seo\Retargeting\AuthAdapter\$data
$data
Определения
authadapter.php:24
Bitrix\Seo\Retargeting\AuthAdapter\getType
getType()
Определения
authadapter.php:178
Bitrix\Seo\Retargeting\AuthAdapter\hasAuth
hasAuth()
Определения
authadapter.php:191
Bitrix\Seo\Retargeting\AuthAdapter\getAuthUrl
getAuthUrl()
Определения
authadapter.php:89
Bitrix\Seo\Retargeting\AuthAdapter\setService
setService(IService $service)
Определения
authadapter.php:71
Bitrix\Seo\Retargeting\AuthAdapter\$type
$type
Определения
authadapter.php:18
Bitrix\Seo\Retargeting\AuthAdapter\canUseMultipleClients
canUseMultipleClients()
Определения
authadapter.php:201
Bitrix\Seo\Retargeting\AuthAdapter\getClientId
getClientId()
Определения
authadapter.php:252
Bitrix\Seo\Retargeting\AuthAdapter\$parameters
$parameters
Определения
authadapter.php:27
Bitrix\Seo\Retargeting\AuthAdapter\$service
$service
Определения
authadapter.php:15
Bitrix\Seo\Retargeting\AuthAdapter\getClientList
getClientList()
Определения
authadapter.php:220
Bitrix\Seo\Retargeting\AuthAdapter\__construct
__construct($type)
Определения
authadapter.php:29
Bitrix\Seo\Retargeting\AuthAdapter\getAuthorizedClientsList
getAuthorizedClientsList()
Определения
authadapter.php:242
Bitrix\Seo\Retargeting\AuthAdapter\getAuthDataSingle
getAuthDataSingle($isUseCache=true)
Определения
authadapter.php:131
Bitrix\Seo\Retargeting\AuthAdapter\getAuthDataMultiple
getAuthDataMultiple()
Определения
authadapter.php:126
Bitrix\Seo\Retargeting\AuthAdapter\$requestCodeParamName
$requestCodeParamName
Определения
authadapter.php:23
Bitrix\Seo\Retargeting\Service\TYPE_YANDEX
const TYPE_YANDEX
Определения
service.php:15
Bitrix\Seo\Retargeting\Service\getEngineCode
static getEngineCode($type)
Определения
service.php:40
Bitrix\Seo\Retargeting\Service\canUseMultipleClients
static canUseMultipleClients()
Определения
service.php:69
Bitrix\Seo\Service\CLIENT_TYPE_COMPATIBLE
const CLIENT_TYPE_COMPATIBLE
Определения
service.php:55
Bitrix\Seo\Service\getAuthorizeLink
static getAuthorizeLink()
Определения
service.php:370
Bitrix\Seo\Service\getAuth
static getAuth(string $engineCode)
Определения
service.php:78
Bitrix\Seo\Service\clearAuthForClient
static clearAuthForClient($client, $localOnly=false)
Определения
service.php:242
Bitrix\Seo\Service\register
static register(string $serviceUrl='')
Определения
service.php:318
Bitrix\Seo\Service\isRegistered
static isRegistered()
Определения
service.php:65
Bitrix\Seo\Service\getClientList
static getClientList($engineCode=false, string $type=null)
Определения
service.php:116
Bitrix\Seo\Service\clearAuth
static clearAuth($engineCode, $localOnly=false)
Определения
service.php:225
Bitrix\Seo\Service\getAuthorizeData
static getAuthorizeData($engine, $clientType=false)
Определения
service.php:381
Bitrix\Seo\Service\CLIENT_TYPE_SINGLE
const CLIENT_TYPE_SINGLE
Определения
service.php:53
Bitrix\Seo\Service\CLIENT_TYPE_MULTIPLE
const CLIENT_TYPE_MULTIPLE
Определения
service.php:54
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
Bitrix\Seo\Retargeting\IMultiClientService
Определения
imulticlientservice.php:6
Bitrix\Seo\Retargeting\IService
Определения
iservice.php:6
$uri
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения
urlrewrite.php:61
Bitrix\Seo\Retargeting
Определения
account.php:3
Bitrix\Seo
Bitrix
$instance
$instance
Определения
ps_b24_final.php:14
count
</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
$clientId
Определения
seo_client.php:18
bitrix
modules
seo
lib
retargeting
authadapter.php
Создано системой
1.14.0