• Модуль: statistic
  • Путь к файлу: ~/bitrix/modules/statistic/classes/general/statistic.php
  • Класс: CAllStatistics
  • Вызов: CAllStatistics::OnSearch
static function OnSearch($search_phrase)
{
	$DB = CDatabase::GetModuleConnection('statistic');
	if(intval($_SESSION["SESS_SEARCHER_ID"]) > 0)
		return "";

	if(COption::GetOptionString("statistic", "SAVE_REFERERS") != "N")
	{
		if(!array_key_exists("SESS_PHRASE_ID", $_SESSION))
			$_SESSION["SESS_PHRASE_ID"] = array();
		$search_phrase = mb_substr(trim($search_phrase), 0, 255);
		if($search_phrase <> '')
		{
			// check if search of this phrase already occured in this session
			if(array_key_exists($search_phrase, $_SESSION["SESS_PHRASE_ID"]))
			{
				// return it's ID
				return "phrase_id=".$_SESSION["SESS_PHRASE_ID"][$search_phrase];
			}
			else
			{
				if(defined("ADMIN_SECTION") && ADMIN_SECTION === true)
				{
					$sql_site = "'ad'";
				}
				elseif(defined("SITE_ID"))
				{
					$sql_site = "'".$DB->ForSql(SITE_ID, 2)."'";
				}
				else
				{
					$sql_site = "null";
				}

				// otherwise add it
				$arFields = Array(
					"DATE_HIT" => $DB->GetNowFunction(),
					"SEARCHER_ID" => '1',
					"PHRASE" => "'".$DB->ForSql($search_phrase)."'",
					"SESSION_ID" => intval($_SESSION["SESS_SESSION_ID"]),
					"SITE_ID" => $sql_site,
				);
				$_SESSION["SESS_PHRASE_ID"][$search_phrase] = $phrase_id = $DB->Insert("b_stat_phrase_list", $arFields, "File: ".__FILE__."
Line: ".__LINE__); // let's use lru to control session data volume while(count($_SESSION["SESS_PHRASE_ID"]) > 10) { array_shift($_SESSION["SESS_PHRASE_ID"]); } stat_session_register("SESS_FROM_SEARCHERS"); // update search engine statistic $arFields = Array( "PHRASES" => "PHRASES + 1", ); $DB->Update("b_stat_searcher", $arFields, "WHERE ID=1", "File: ".__FILE__."
Line: ".__LINE__); $_SESSION["SESS_FROM_SEARCHERS"][] = 1; return "phrase_id=".$phrase_id; } } } return ""; }