• Модуль: imopenlines
  • Путь к файлу: ~/bitrix/modules/imopenlines/lib/livechatmanager.php
  • Класс: BitrixImOpenLinesLiveChatManager
  • Вызов: LiveChatManager::getWidgetSource
private function getWidgetSource($params = array())
{
	if (!BitrixMainLoader::includeModule('crm'))
	{
		return '';
	}

	$config = $this->get();

	$params['LANG'] = isset($params['LANG'])? $params['LANG']: BitrixMainLocalizationLoc::getCurrentLang();
	$params['CONFIG'] = is_array($params['CONFIG'])? $params['CONFIG']: Array();

	$charset = SITE_CHARSET;

	$lang = $params['LANG'];
	$host = BitrixCrmSiteButtonResourceManager::getServerAddress();
	$code = $config['URL_CODE'];
	$copyrightEnable = isset($params['CONFIG']["copyright"])? (bool)$params['CONFIG']["copyright"]: true;
	$copyrightEnable = $copyrightEnable? 'true': 'false';
	$copyrightUrl = BitrixImOpenLinesCommon::getBitrixUrlByLang($lang);

	BitrixImOpenLinesLiveChatManager::compileWidgetAssets();

	$localize = CUtil::PhpToJSObject(self::getWidgetLocalize($lang));

$initWidget = <<getModificationTime() <= $minFile->getModificationTime())
		{
			$scriptName = 'script.min.js';
		}
	}

	$stylesName = 'styles.css';
	$stylesPath = Application::getDocumentRoot().self::WIDGET_PATH_STYLE;
	$stylesPathMin = mb_substr(Application::getDocumentRoot().self::WIDGET_PATH_STYLE, 0, -4).'.min.css';
	if (MainIOFile::isFileExists($stylesPathMin))
	{
		$file = new BitrixMainIOFile($stylesPath);
		$minFile = new BitrixMainIOFile($stylesPathMin);
		if ($file->getModificationTime() <= $minFile->getModificationTime())
		{
			$stylesName = 'styles.min.css';
		}
	}

	$codeWidget =
		'window.addEventListener('onBitrixLiveChatSourceLoaded',function() {'
			.str_replace(["n","t"], " ", $initWidget).
		'});'.
		'(function () {'.
			'var f = function () {'.
				'var week = function () {var d = new Date();d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay()||7));var yearStart = new Date(Date.UTC(d.getUTCFullYear(),0,1)); return Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7);};'.
				'var head = (document.getElementsByTagName("head")[0] || document.documentElement);'.
				'var style = document.createElement("link"); style.type = "text/css"; style.rel = "stylesheet";  style.href = "'.$host.'/bitrix/js/imopenlines/widget/'.$stylesName.'?r='.time().'-"+week();'.
				'var script = document.createElement("script"); script.type = "text/javascript"; script.async = "true"; script.charset = "'.$charset.'"; script.src = "'.$host.'/bitrix/js/imopenlines/widget/'.$scriptName.'?r='.time().'-"+week();'.
				'head.appendChild(style); head.appendChild(script);'.
			'};'.
			'if (typeof(BX)!="undefined" && typeof(BX.ready)!="undefined") {BX.ready(f)}'.
			'else if (typeof(jQuery)!="undefined") {jQuery(f)}'.
			'else {f();}'.
		'})();'
	;

	return $codeWidget;
}