• Модуль: imopenlines
  • Путь к файлу: ~/bitrix/modules/imopenlines/lib/livechat.php
  • Класс: BitrixImOpenLinesLiveChat
  • Вызов: LiveChat::openSession
public function openSession()
{
	CUtil::decodeURIComponent($_GET);
	$context = MainApplication::getInstance()->getContext();
	$request = $context->getRequest();

	$sessionId = '';
	if ($request->get('userHash') && preg_match("/^[a-fA-F0-9]{32}$/i", $request->get('userHash')))
	{
		$sessionId = $request->get('userHash');
	}
	else
	{
		$sessionId = $request->getCookieRaw('LIVECHAT_HASH');
	}
	if (isset($_GET['userName']))
	{
		$this->temporary['USER_NAME'] = $_GET['userName'];
	}
	if (isset($_GET['userLastName']))
	{
		$this->temporary['USER_LAST_NAME'] = $_GET['userLastName'];
	}
	if (isset($_GET['userAvatar']))
	{
		$this->temporary['USER_AVATAR'] = $_GET['userAvatar'];
	}
	if (isset($_GET['userEmail']))
	{
		$this->temporary['USER_EMAIL'] = $_GET['userEmail'];
	}
	if (isset($_GET['currentUrl']) && !empty($_GET['currentUrl']))
	{
		$currentUrl = parse_url($_GET['currentUrl']);
		if ($currentUrl)
		{
			$this->temporary['USER_PERSONAL_WWW'] = $_GET['currentUrl'];
		}
	}

	if (isset($_GET['firstMessage']))
	{
		$this->temporary['FIRST_MESSAGE'] = $_GET['firstMessage'];
	}
	else if (isset($_GET['currentUrl']) && !empty($_GET['currentUrl']))
	{
		$currentUrl = parse_url($_GET['currentUrl']);
		if ($currentUrl)
		{
			$this->temporary['FIRST_MESSAGE'] = '[b]'.Loc::getMessage('IMOL_LC_GUEST_URL').'[/b]: [url='.$_GET['currentUrl'].']'.$currentUrl['scheme'].'://'.$currentUrl['host'].$currentUrl['path'].'[/url]';
		}
	}

	if (preg_match("/^[a-fA-F0-9]{32}$/i", $sessionId))
	{
		$this->sessionId = $sessionId;
	}
	else if ($_SESSION['LIVECHAT_HASH'])
	{
		$this->sessionId = $_SESSION['LIVECHAT_HASH'];
	}
	else
	{
		$licence = MainApplication::getInstance()->getLicense()->getPublicHashKey();

		$this->sessionId = md5(time().bitrix_sessid().$licence);
	}

	$_SESSION['LIVECHAT_HASH'] = $this->sessionId;
	setcookie('LIVECHAT_HASH', $this->sessionId, time() + 31536000, '/');

	$this->userId = $this->getGuestUser();

	global $USER;
	if (!$USER->IsAuthorized())
	{
		$USER->Authorize($this->userId, false, true, 'public');
	}
	$this->getChatForUser();

	return true;
}