Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
configurator.php
1<?php
2
4
7
13{
15 protected static $errors = array();
16
18 protected static $isQueueUsed = false;
19
25 public static function canUse()
26 {
27 return Loader::includeModule('seo') && Loader::includeModule('socialservices');
28 }
29
35 public static function useQueue()
36 {
37 self::$isQueueUsed = true;
38 }
39
45 public static function getService()
46 {
47 return Service::getInstance();
48 }
49
50 public static function getRegions($type)
51 {
52 $account = Service::getAccount($type);
53 if (!$account)
54 {
55 return [];
56 }
57
58 return $account->getRegionsList();
59 }
60
67 public static function getProviders(array $types = null)
68 {
69 return static::getServiceProviders($types);
70 }
71
77 public static function getErrors()
78 {
79 return self::$errors;
80 }
81
87 public static function resetErrors()
88 {
89 self::$errors = array();
90 }
91
97 public static function hasErrors()
98 {
99 return count(self::$errors) > 0;
100 }
101
108 public static function removeAuth($type)
109 {
110 static::getService()->getAuthAdapter($type)->removeAuth();
111 }
112
118 public static function getServiceTypes()
119 {
120 if (!static::canUse())
121 {
122 return array();
123 }
124
125 return static::getService()->getTypes();
126 }
127
134 protected static function getServiceProviders(array $types = null)
135 {
136 $typeList = static::getServiceTypes();
137
138 $providers = array();
139 foreach ($typeList as $type)
140 {
141 if ($types && !in_array($type, $types))
142 {
143 continue;
144 }
145
146 if($type === Service::TYPE_INSTAGRAM)
147 {
149 }
150 $service = static::getService();
151 $authAdapter = $service->getAuthAdapter($type);
152 $account = $service->getAccount($type);
153 $canUserMultiClients = $authAdapter->canUseMultipleClients();
154
155 $providers[$type] = array(
156 'TYPE' => $type,
157 'HAS_AUTH' => $authAdapter->hasAuth(),
158 'AUTH_URL' => $authAdapter->getAuthUrl(),
159 'PROFILE' => $authAdapter->getToken() ? $account->getProfileCached() : false,
160 'IS_SUPPORT_ACCOUNT' => true,
161 'ENGINE_CODE' => $service::getEngineCode($type)
162 );
163 if ($canUserMultiClients)
164 {
165 $providers[$type]['CLIENTS'] = static::getClientsProfiles($authAdapter);
166 if (empty($providers[$type]['CLIENTS']))
167 {
168 $providers[$type]['HAS_AUTH'] = false;
169 }
170 }
171
172 // check if no profile, then may be auth was removed in service
173 if ($providers[$type]['HAS_AUTH'] && empty($providers[$type]['PROFILE']))
174 {
175 static::removeAuth($type);
176 if (!$canUserMultiClients)
177 {
178 $providers[$type]['HAS_AUTH'] = false;
179 }
180 }
181 }
182
183 return $providers;
184 }
185
191 protected static function getClientsProfiles(AuthAdapter $authAdapter)
192 {
193 $type = $authAdapter->getType();
194 return array_values(array_filter(array_map(function ($item) use ($type) {
195 $service = new Service();
196 $service->setClientId($item['proxy_client_id']);
197
198 $authAdapter = Service::getAuthAdapter($type);
199 $authAdapter->setService($service);
200
201 $account = Service::getAccount($type);
202 $account->setService($service);
203 $account->getRequest()->setAuthAdapter($authAdapter);
204
205 $profile = $account->getProfileCached();
206 if ($profile)
207 {
208 return $profile;
209 }
210 else
211 {
212 // if no profile, then may be auth was removed in service
213 $authAdapter->removeAuth();
214 }
215 }, $authAdapter->getAuthorizedClientsList())));
216 }
217
224 public static function getAccounts($type)
225 {
226 if (!static::canUse())
227 {
228 return array();
229 }
230
231 $result = array();
232
233 $account = static::getService()->getAccount($type);
234 $accountsResult = $account->getList();
235 if ($accountsResult->isSuccess())
236 {
237 while ($accountData = $accountsResult->fetch())
238 {
239 if ($accountData['ID'])
240 {
241
242 $result[] = array(
243 'id' => $accountData['ID'],
244 'name' => $accountData['NAME'] ? $accountData['NAME'] : $accountData['ID'],
245 'currency' => $accountData['CURRENCY'],
246 );
247 }
248 }
249 }
250 else
251 {
252 self::$errors = $accountsResult->getErrorMessages();
253 }
254
255 return $result;
256 }
257
264 public static function getInstagramAccounts($type)
265 {
266 if (!static::canUse())
267 {
268 return array();
269 }
270
271 $result = array();
272
273 $account = static::getService()->getAccount($type);
274 $accountsResult = $account->getInstagramList();
275 if ($accountsResult->isSuccess())
276 {
277 while ($accountData = $accountsResult->fetch())
278 {
279 if ($accountData['ID'])
280 {
281 $result[] = array(
282 'id' => $accountData['ID'],
283 'name' => $accountData['NAME'] ? $accountData['NAME'] : $accountData['ID'],
284 'page_id' => $accountData['PAGE_ID'] ? $accountData['PAGE_ID'] : $accountData['ID'],
285 'actor_id' => $accountData['IG_ID']
286 );
287 }
288 }
289 }
290 else
291 {
292 self::$errors = $accountsResult->getErrorMessages();
293 }
294
295 return $result;
296 }
297
306 public static function getPostList($type, $params)
307 {
308 if (!static::canUse())
309 {
310 return array();
311 }
312
313 return static::getService()->getPostList($type, $params);
314 }
315
322 public static function getAudiences($type, $accountId)
323 {
324 if (!static::canUse())
325 {
326 return array();
327 }
328
329 return static::getService()->getAudienceList($type, $accountId);
330 }
331
338 public static function getCampaignList($type, $accountId)
339 {
340 if (!static::canUse())
341 {
342 return array();
343 }
344
345 return static::getService()->getCampaignList($type, $accountId);
346 }
347
354 public static function getAdSetList($type, $accountId)
355 {
356 if (!static::canUse())
357 {
358 return array();
359 }
360
361 return static::getService()->getAdSetList($type, $accountId);
362 }
363
373 public static function createCampaign($type, $data)
374 {
375 if (!static::canUse())
376 {
377 return array();
378 }
379 return static::getService()->createCampaign($type, $data);
380 }
381
391 public static function createAudience($type, $data)
392 {
393 if (!static::canUse())
394 {
395 return array();
396 }
397 return static::getService()->createAudience($type, $data);
398 }
399
407 public static function getAds($type, $adsId)
408 {
409 if (!static::canUse())
410 {
411 return array();
412 }
413 return static::getService()->getAds($type, $adsId);
414 }
415
423 public static function searchTargetingData($type, $params)
424 {
425 if (!static::canUse())
426 {
427 return array();
428 }
429 return static::getService()->searchTargetingData($type, $params);
430 }
431}
static getClientsProfiles(AuthAdapter $authAdapter)
static getProviders(array $types=null)
static getAdSetList($type, $accountId)
static createAudience($type, $data)
static getAudiences($type, $accountId)
static createCampaign($type, $data)
static getCampaignList($type, $accountId)
static getPostList($type, $params)
static getServiceProviders(array $types=null)
static searchTargetingData($type, $params)
static getAuthAdapter($type)
Definition service.php:205