CAdvBanner :: SetCookie: Bitrix method

      
<?php 
//  CAdvBanner :: SetCookie()
//  /dist/bitrix/modules/advertising/classes/general/advertising.php:4442

    
public static function SetCookie($arBanner, &$inc_banner_counter, &$inc_contract_counter)
    {
        global 
$arrADV_VIEWED_BANNERS$APPLICATION;
        if (
intval($arBanner["ID"])>0)
        {
            
$inc_contract_counter "N";
            
$inc_banner_counter "N";

            
$days COption::GetOptionString("advertising""COOKIE_DAYS");
            
$cookie_name "BANNERS";
            
$arrCookie = array();
            
$arrContracts = array();

            
// если мы уже получили на странице значение cookie то
            
if (is_array($arrADV_VIEWED_BANNERS))
            {
                
// берем массив arrCookie который уже определен на странице
                
$arrCookie $arrADV_VIEWED_BANNERS;

                
// соберем массив контрактов
                
reset($arrCookie);
                while (list(, 
$arr)=each($arrCookie))
                {
                    
$arrContracts[] = $arr["CONTRACT_ID"];
                }

                if (
in_array($arBanner["ID"],array_keys($arrCookie)))
                {
                    
$arrCookie[$arBanner["ID"]]["COUNTER"] = $arrCookie[$arBanner["ID"]]["COUNTER"]+1;
                    
$arrCookie[$arBanner["ID"]]["EXPIRATION_DATE"] = date("dmY",time()+(intval($days)*86400));
                }
            }
            else 
// если мы первый раз обращаемся к значению хранимому в cookie
            
{
                
// то инициализируем массив arrCookie
                
$arr explode(","$APPLICATION->get_cookie($cookie_name));
                if (
is_array($arr) && count($arr)>0)
                {
                    
$now time();

                    foreach(
$arr as $str)
                    {
                        
$ar explode("_",$str);
                        
$contract_id intval($ar[0]);
                        
$arrContracts[] = $contract_id;
                        
$banner_id intval($ar[1]);
                        
$counter intval($ar[2]);
                        if (
$arBanner["ID"]==$banner_id)
                        {
                            
$counter++;
                            
$arrCookie[$arBanner["ID"]] = array(
                                
"CONTRACT_ID"        => $arBanner["CONTRACT_ID"],
                                
"COUNTER"            => $counter,
                                
"EXPIRATION_DATE"    => date("dmY",time()+(intval($days)*86400))
                                );
                        }
                        else
                        {
                            
$strDate trim($ar[3]);
                            
$month intval(substr($strDate,2,2));
                            
$day intval(substr($strDate,0,2));
                            
$year intval(substr($strDate,4,4));
                            
$stmp false;

                            if (
$month && $day && $year)
                            {
                                
$stmp mktime(000$month$day$year);
                            }

                            if (
                                
$stmp
                                
&& $stmp $now
                            
)
                            {
                                
$arrCookie[$banner_id] = array(
                                    
"CONTRACT_ID" => $contract_id,
                                    
"COUNTER" => $counter,
                                    
"EXPIRATION_DATE" => ($stmp date("dmY"$stmp) : $strDate)
                                );
                            }
                        }
                    }
                }
            }

            
// если данный посетитель по контракту еще не фиксировался то
            
if (!in_array($arBanner["CONTRACT_ID"], $arrContracts))
                
$inc_contract_counter "Y";

            
// если посетитель еще не фиксировался по текущему баннеру то
            
if (!in_array($arBanner["ID"], array_keys($arrCookie)))
            {
                
// взводим флаг о необходимости увеличить счетчик посетителей
                
$inc_banner_counter="Y";

                
// добавляем текущий баннер в массив arrCookie
                
$arrCookie[$arBanner["ID"]] = array(
                    
"CONTRACT_ID"        => $arBanner["CONTRACT_ID"],
                    
"COUNTER"            => 1,
                    
"EXPIRATION_DATE"    => date("dmY",time()+(intval($days)*86400))
                );
            }
            
$arrADV_VIEWED_BANNERS $arrCookie;
        }
    }