- Модуль: statistic
- Путь к файлу: ~/bitrix/modules/statistic/classes/mysql/stoplist.php
- Класс: CStoplist
- Вызов: CStoplist::Check
static function Check($test="N", $arParams = false)
{
$DB = CDatabase::GetModuleConnection('statistic');
$test = ($test=="Y") ? "Y" : "N";
$arStopRecord = false;
$zr = false;
//We did not use cache or it was cache miss
if(!$arStopRecord)
{
$user_agent = "";
$url_from = "";
$url_to = "";
$site_id = "";
$site_where = "";
$ip = array(0, 0, 0, 0);
if ($arParams===false)
{
$ip = explode(".", $_SERVER["REMOTE_ADDR"]);
$user_agent = trim($_SERVER["HTTP_USER_AGENT"]);
$url_from = isset($_SERVER["HTTP_REFERER"])? $_SERVER["HTTP_REFERER"]: "";
$url_to = __GetFullRequestUri();
if (defined("SITE_ID"))
$site_id = SITE_ID;
}
elseif(is_array($arParams))
{
$ip = explode(".", $arParams["IP"]);
$user_agent = trim($arParams["USER_AGENT"]);
$url_from = $arParams["URL_FROM"];
$url_to = $arParams["URL_TO"];
$site_id = $arParams["SITE_ID"];
}
$user_agent_len = mb_strlen($user_agent);
$user_agent = $DB->ForSql($user_agent, 500);
$url_from = $DB->ForSql($url_from, 2000);
$url_to = $DB->ForSql($url_to, 2000);
if ($site_id <> '')
{
$site_where = "and (SITE_ID = '".$DB->ForSql($site_id, 2)."' or SITE_ID is null or length(SITE_ID)<=0)";
}
$strSql = "
SELECT
ID,
MESSAGE,
MESSAGE_LID,
SAVE_STATISTIC,
URL_REDIRECT,
TEST
FROM
b_stop_list
WHERE
ACTIVE='Y'
and TEST='$test'
$site_where
and (DATE_START<=now() or DATE_START is null)
and (DATE_END>=now() or DATE_END is null)
and ((((MASK_1 & ".intval($ip[0]).")=IP_1 and
(MASK_2 & ".intval($ip[1]).")=IP_2 and
(MASK_3 & ".intval($ip[2]).")=IP_3 and
(MASK_4 & ".intval($ip[3]).")=IP_4)
or (IP_1 is null and IP_2 is null and IP_3 is null and IP_4 is null))
and (upper('".$DB->ForSql($user_agent)."') like concat('%',upper(USER_AGENT),'%')
or length(USER_AGENT)<=0 or USER_AGENT is null)
and ($user_agent_len=0 or USER_AGENT_IS_NULL<>'Y')
and (upper('$url_from') like concat('%',upper(URL_FROM),'%')
or length(URL_FROM)<=0 or URL_FROM is null)
and (upper('$url_to') like concat('%',upper(URL_TO),'%')
or length(URL_TO)<=0 or URL_TO is null)
)
";
$z = $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__);
if($zr = $z->Fetch())
{
$arStopRecord = array(
"STOP" => "Y",
"STOP_SAVE_STATISTIC" => $zr["SAVE_STATISTIC"],
"STOP_MESSAGE" => $zr["MESSAGE"],
"STOP_REDIRECT_URL" => $zr["URL_REDIRECT"],
"STOP_MESSAGE_LID" => $zr["MESSAGE_LID"],
"STOP_LIST_ID" => $zr["ID"],
);
}
else
{
$arStopRecord = array(
"STOP" => "N",
"STOP_SAVE_STATISTIC" => "Y",
"STOP_MESSAGE" => "",
"STOP_REDIRECT_URL" => "",
"STOP_MESSAGE_LID" => "",
"STOP_LIST_ID" => 0,
);
}
}
/*
//Save session cache
if($test == "N" && CACHED_b_stop_list !== false)
{
$_SESSION["STAT_STOP_LIST"] = array(
"TIMESTAMP_X" => $TIMESTAMP_X,
"DATA" => $arStopRecord,
);
}
*/
if($test == "N")
{
foreach($arStopRecord as $key => $value)
{
$GLOBALS[$key] = $value;
}
return false;
}
else
{
if($zr)
return intval($zr["ID"]);
else
return false;
}
}