403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/seo/lib/retargeting/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/seo/lib/retargeting/authadapter.php
<?php

namespace Bitrix\Seo\Retargeting;

use Bitrix\Main\Loader;
use Bitrix\Main\SystemException;
use Bitrix\Main\Web\Uri;
use Bitrix\Seo\BusinessSuite\Utils\QueueRemoveEventHandler;
use Bitrix\Seo\Service;
use Bitrix\Seo\Service as SeoService;

class AuthAdapter
{
	/** @var  IService $service */
	protected $service;

	/**@var string $type*/
	protected $type;

	/* @var \CSocServOAuthTransport|\CFacebookInterface */
	protected $transport;

	protected $requestCodeParamName;
	protected $data;

	/** @var array $parameters Parameters. */
	protected $parameters = ['URL_PARAMETERS' => []];

	public function __construct($type)
	{
		$this->type = $type;

		if($type === \Bitrix\Seo\Retargeting\Service::TYPE_YANDEX)
		{
			$this->parameters['URL_PARAMETERS']['force_confirm'] = 'yes';
		}
	}

	/**
	 * @throws \Bitrix\Main\LoaderException
	 * @throws SystemException
	 */
	public static function create($type, IService $service = null, bool $ignoreType = false)
	{
		if (!Loader::includeModule('socialservices'))
		{
			throw new SystemException('Module "socialservices" not installed.');
		}

		if ($type === 'facebook' && !$ignoreType)
		{
			$instance = new \Bitrix\Seo\Retargeting\FacebookAuthAdapter($type);
		}
		else
		{
			$instance = new static($type);
		}

		if ($service)
		{
			$instance->setService($service);
		}

		return $instance;
	}

	/**
	 * @param IService $service
	 * @return $this
	 */
	public function setService(IService $service)
	{
		$this->service = $service;

		return $this;
	}

	/**
	 * @param array $parameters
	 * @return $this
	 */
	public function setParameters(array $parameters = [])
	{
		$this->parameters = $parameters + $this->parameters;

		return $this;
	}

	public function getAuthUrl()
	{
		if (!SeoService::isRegistered())
		{
			try
			{
				SeoService::register();
			}
			catch (SystemException $e)
			{
				return '';
			}
		}

		$authorizeData = SeoService::getAuthorizeData(
			$this->getEngineCode(),
			$this->canUseMultipleClients() ? Service::CLIENT_TYPE_MULTIPLE : Service::CLIENT_TYPE_SINGLE
		);

		if (!empty($this->parameters['URL_PARAMETERS']))
		{
			$authorizeData['urlParameters'] = $this->parameters['URL_PARAMETERS'];
		}

		$uri = new Uri(SeoService::getAuthorizeLink());

		return $uri->addParams($authorizeData)->getLocator();
	}

	protected function getAuthData($isUseCache = true)
	{
		return ($this->canUseMultipleClients()
			? $this->getAuthDataMultiple()
			: $this->getAuthDataSingle($isUseCache))
		;
	}

	protected function getAuthDataMultiple()
	{
		return $this->getClientById($this->getClientId());
	}

	protected function getAuthDataSingle($isUseCache = true)
	{
		if (!$isUseCache || !$this->data || count($this->data) == 0)
		{
			$this->data = SeoService::getAuth($this->getEngineCode());
		}

		return $this->data;
	}

	/**
	 * @throws SystemException
	 * @return void
	 */
	public function removeAuth()
	{
		$this->data = array();

		if ($existedAuthData = $this->getAuthData(false))
		{
			QueueRemoveEventHandler::handleEvent(
				$existedAuthData['proxy_client_id'],
				$existedAuthData['engine_code']
			);
			$this->canUseMultipleClients()
				? SeoService::clearAuthForClient($existedAuthData)
				: SeoService::clearAuth($this->getEngineCode());

		}
	}

	/**
	 * @return string
	 */
	protected function getEngineCode()
	{
		if ($this->service)
		{
			return $this->service::getEngineCode($this->type);
		}

		return Service::getEngineCode($this->type);
	}

	/**
	 * @return string
	 */
	public function getType()
	{
		return $this->type;
	}

	public function getToken()
	{
		return is_array($data = $this->getAuthData(false)) ? $data['access_token'] : null;
	}

	/**
	 * @return bool
	 */
	public function hasAuth()
	{
		return $this->canUseMultipleClients()
			? count($this->getAuthorizedClientsList()) > 0
			: $this->getToken() <> "";
	}

	/**
	 * @return bool
	 */
	public function canUseMultipleClients()
	{
		if (!$this->service)
		{
			return Service::canUseMultipleClients();
		}

		if ($this->service instanceof IMultiClientService)
		{
			return $this->service::canUseMultipleClients();
		}

		return false;
	}

	/**
	 * @return array|null
	 * @throws SystemException
	 */
	public function getClientList()
	{
		return $this->canUseMultipleClients() ? SeoService::getClientList($this->getEngineCode(), $this->type) : [];
	}

	public function getClientById($clientId)
	{
		$clients = $this->getClientList();
		foreach ($clients as $client)
		{
			if ($client['proxy_client_id'] == $clientId)
			{
				return $client;
			}
		}
		return null;
	}

	/**
	 * @return array|null
	 * @throws SystemException
	 */
	public function getAuthorizedClientsList()
	{
		return array_filter(
			$this->getClientList(),
			static function ($item) : bool {
				return $item['access_token'] <> '';
			}
		);
	}

	public function getClientId()
	{
		if (!$this->canUseMultipleClients())
		{
			return null;
		}
		$clientId = $this->service->getClientId();
		if ($clientId)
		{
			$client = $this->getClientById($clientId);
			if ($client['engine_code'] == $this->getEngineCode())
			{
				return $clientId;
			}
			return null;
		}

		// try to guess account id from accounts list:
		$clients = $this->getClientList();
		foreach ($clients as $client)
		{
			if ($client['proxy_client_type'] == SeoService::CLIENT_TYPE_COMPATIBLE)
			{
				return $client['proxy_client_id'];
			}
		}
		return null;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit