11use Bitrix\Main\Application;
12use Bitrix\Main\Context;
13use Bitrix\Main\Loader;
14use Bitrix\Main\LoaderException;
15use Bitrix\Main\Localization\Loc;
16use Bitrix\Main\SystemException;
17use Bitrix\Main\Web\HttpClient;
18use Bitrix\Main\Web\Json;
19use Bitrix\Seo\Engine\Bitrix;
20use Bitrix\Seo\Retargeting\AdsAudience;
21use Bitrix\Seo\Retargeting\Request;
23Loc::loadMessages(__FILE__);
25if (!defined(
"BITRIX_CLOUD_ADV_URL"))
27 $domain = (new \Bitrix\Main\License\UrlProvider())->getTechDomain();
28 $cloudAdvUrl =
'https://cloud-adv.' . $domain;
30 define(
"BITRIX_CLOUD_ADV_URL", $cloudAdvUrl);
33if (!defined(
"SEO_SERVICE_URL"))
35 define(
'SEO_SERVICE_URL', BITRIX_CLOUD_ADV_URL);
67 return static::getEngine() && static::getEngine()->isRegistered();
78 public static function getAuth(
string $engineCode)
81 if (static::$auth ===
null)
83 if (
$CACHE_MANAGER->Read(static::SERVICE_AUTH_CACHE_TLL, static::SERVICE_AUTH_CACHE_ID))
85 static::$auth =
$CACHE_MANAGER->Get(static::SERVICE_AUTH_CACHE_ID);
87 elseif (!
$CACHE_MANAGER->Read(static::SERVICE_AUTH_CACHE_TLL_ERROR, static::SERVICE_AUTH_CACHE_ID_ERROR))
89 static::$auth = static::getEngine()?->getInterface()?->getClientInfo();
92 static::$auth =
false;
93 $CACHE_MANAGER->Read(static::SERVICE_AUTH_CACHE_TLL_ERROR, static::SERVICE_AUTH_CACHE_ID_ERROR);
94 $CACHE_MANAGER->Set(static::SERVICE_AUTH_CACHE_ID_ERROR, static::$auth);
103 static::$auth =
false;
107 return static::$auth[
"engine"][$engineCode] ??
false;
118 if (static::$clientList ==
null)
121 if ($cache->read(static::CLIENT_LIST_CACHE_TLL, static::CLIENT_LIST_CACHE_ID))
123 static::$clientList = $cache->get(static::CLIENT_LIST_CACHE_ID);
124 static::$clientList = is_array(static::$clientList) ? static::$clientList : [];
129 $clientDataProvider = static::getEngine(
$request)?->getInterface();
130 if (!$clientDataProvider)
135 $result = $clientDataProvider->getClientList();
139 $data = $clientDataProvider->getClientInfo();
144 $data[
'proxy_client_type'] = static::CLIENT_TYPE_COMPATIBLE;
146 $data[
'proxy_client_id'] =
null;
155 $cache->set(static::CLIENT_LIST_CACHE_ID,
$result);
161 return array_filter(static::$clientList,
function ($item) use ($engineCode)
163 return $item[
'engine_code'] == $engineCode;
167 return static::$clientList;
181 static::$auth =
null;
194 $cache->Clean(static::CLIENT_LIST_CACHE_ID);
195 $cache->Clean(static::SERVICE_AUTH_CACHE_ID);
196 $cache->Clean(static::SERVICE_AUTH_CACHE_ID_ERROR);
203 $service = AdsAudience::getService();
208 $account->clearCache();
213 static::$clientList =
null;
214 static::$auth =
null;
225 public static function clearAuth($engineCode, $localOnly =
false)
227 static::clearClientsCache($engineCode);
231 static::getEngine()?->getInterface()?->clearClientAuth($engineCode);
246 static::getEngine()?->getInterface()?->clearClientAuth($client[
'engine_code'], $client[
'proxy_client_id']);
248 static::clearClientsCache($client[
'engine_code'], $client[
'proxy_client_id']);
259 if (static::isRegistered())
261 $id = static::getEngine()->getId();
263 $result = SearchEngineTable::update($id, [
264 "CLIENT_ID" => $accessParams[
"client_id"],
265 "CLIENT_SECRET" => $accessParams[
"client_secret"],
271 $result = SearchEngineTable::add([
275 "CLIENT_ID" => $accessParams[
"client_id"],
276 "CLIENT_SECRET" => $accessParams[
"client_secret"],
277 "REDIRECT_URI" => static::getRedirectUri(),
284 static::$engine =
null;
299 if (!static::$engine)
301 static::$engine =
new Bitrix();
305 static::$engine->setAuthSettings([
'PROXY_URL' =>
$request->getProxyUrl()]);
309 return static::$engine;
318 public static function register(
string $serviceUrl =
''): void
320 static::clearClientsCache();
325 "key" => static::getLicense(),
326 "scope" => static::getEngine()?->getInterface()?->getScopeEncode(),
327 "redirect_uri" => static::getRedirectUri(),
330 $serviceUrl = $serviceUrl ?: static::SERVICE_URL;
332 $result = $httpClient->post($serviceUrl . static::REGISTER, $queryParams);
338 catch (\Exception $e)
341 'error' => $e->getCode() .
': ' . $e->getMessage(),
350 static::setAccessSettings(
$result);
359 if (static::isRegistered())
361 $id = static::getEngine()->getId();
362 SearchEngineTable::delete($id);
363 static::clearClientsCache();
372 return static::SERVICE_URL . static::AUTHORIZE;
396 "action" =>
"authorize",
397 "type" => $clientType,
399 "client_id" => static::getEngine()?->getClientId(),
400 "client_secret" => static::getEngine()?->getClientSecret(),
401 "key" => static::getLicense(),
402 "check_key" => urlencode($checkKey),
403 "redirect_uri" => static::getRedirectUri(),
412 $request = Context::getCurrent()->getRequest();
415 $port = (int)
$request->getServerPort();
416 $host .= ($port && $port !== 80 && $port !== 443) ?
":{$port}" :
'';
420 return ($isHttps ?
'https' :
'http') .
'://' .
$host . static::REDIRECT_URI;
438 if (!self::isRegistered())
442 if (!
$engine = static::getEngine())
447 $newRedirectUri = static::getRedirectUri();
448 if (!empty($domains))
450 $newRedirectUri = str_replace($domains[
'old_domain'], $domains[
'new_domain'], $newRedirectUri);
453 SearchEngineTable::update(
$engine->getId(), [
454 'REDIRECT_URI' => $newRedirectUri,
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
static includeModule($moduleName)
const CLIENT_TYPE_COMPATIBLE
static getAuthorizeLink()
static getAuth(string $engineCode)
static clearAuthForClient($client, $localOnly=false)
const CLIENT_LIST_CACHE_ID
static getClientList($engineCode=false, string $type=null)
const CLIENT_LIST_CACHE_TLL
const SERVICE_AUTH_CACHE_ID
const SERVICE_AUTH_CACHE_TLL_ERROR
const SERVICE_AUTH_CACHE_TLL
static changeRegisteredDomain(array $domains=[])
static clearAuth($engineCode, $localOnly=false)
const SERVICE_AUTH_CACHE_ID_ERROR
static clearClientsCache($engine=null, $clientId=null)
static getAuthorizeData($engine, $clientType=false)
static setAccessSettings(array $accessParams)
const CLIENT_TYPE_MULTIPLE
static getEngine(?Request $request=null)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
const LICENSE_KEY($show_sql_stat=='Y')
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)