Esempio n. 1
0
    public static function onProlog()
    {
        static $done = false;
        if (!$done) {
            $done = true;
            DayContext::getInstance();
            // For composite site this script must not be changing often!!!
            Asset::getInstance()->addString('<script type="text/javascript">
					(function () {
						"use strict";

						var counter = function ()
						{
							var cookie = (function (name) {
								var parts = ("; " + document.cookie).split("; " + name + "=");
								if (parts.length == 2) {
									try {return JSON.parse(decodeURIComponent(parts.pop().split(";").shift()));}
									catch (e) {}
								}
							})("' . DayContext::getVarName() . '");

							if (! cookie || cookie.EXPIRE < BX.message("SERVER_TIME"))
							{
								var request = new XMLHttpRequest();
								request.open("POST", "/bitrix/tools/conversion/ajax_counter.php", true);
								request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
								request.send(
									"SITE_ID="      + encodeURIComponent(BX.message("SITE_ID")) + "&" +
									"sessid="       + encodeURIComponent(BX.bitrix_sessid())    + "&" +
									"HTTP_REFERER=" + encodeURIComponent(document.referrer)
								);
							}
						};

						if (window.frameRequestStart === true)
							BX.addCustomEvent("onFrameDataReceived", counter);
						else
							BX.ready(counter);
					})();
				</script>', false, AssetLocation::AFTER_JS_KERNEL);
        }
    }