function Set($user_id, $code = "**", $type = "Y", $follow_date = false, $site_id = SITE_ID) { static $LOG_CACHE; if (strlen($code) <= 0) { $code = "**"; } if ($type != "Y") { $type = "N"; } if (intval($user_id) <= 0) { $user_id = $GLOBALS["USER"]->GetID(); } $arFollows = array(); $rsFollow = CSocNetLogFollow::GetList(array("USER_ID" => $user_id, "CODE" => array_unique(array("**", $code)))); while ($arFollow = $rsFollow->Fetch()) { $arFollows[$arFollow["CODE"]] = array("TYPE" => $arFollow["TYPE"], "FOLLOW_DATE" => $arFollow["FOLLOW_DATE"]); } if (array_key_exists("**", $arFollows)) { $default_type = $arFollows["**"]["TYPE"]; } else { $default_type = COption::GetOptionString("socialnetwork", "follow_default_type", "Y"); } if (preg_match('/^L(\\d+)$/', $code, $matches)) { $log_id = intval($matches[1]); if ($log_id > 0) { if (isset($LOG_CACHE[$log_id])) { $arLog = $LOG_CACHE[$log_id]; } else { $rsLog = CSocNetLog::GetList(array("ID" => "DESC"), array("ID" => $log_id), false, false, array("ID", "LOG_UPDATE", "LOG_DATE"), array("CHECK_RIGHTS" => "N", "USE_SUBSCRIBE" => "N", "USE_FOLLOW" => "N")); if ($arLog = $rsLog->Fetch()) { $LOG_CACHE[$log_id] = $arLog; } } if ($arLog) { $log_date = strlen($arLog["LOG_DATE"]) > 0 ? $arLog["LOG_DATE"] : false; $log_update = strlen($arLog["LOG_UPDATE"]) > 0 ? $arLog["LOG_UPDATE"] : false; if (array_key_exists($code, $arFollows)) { // already in the follows table $res = CSocNetLogFollow::Update($user_id, $code, $type, strlen($arFollows[$code]["FOLLOW_DATE"]) > 0 ? $arFollows[$code]["FOLLOW_DATE"] : ($type == "N" ? $log_update : $log_date)); } elseif ($type != $default_type) { // new record in the follow table only if not equal to default type $res = CSocNetLogFollow::Add($user_id, $code, $type, $follow_date ? $follow_date : ($type == "N" ? $log_update : $log_date)); } } } } else { if (array_key_exists($code, $arFollows)) { $res = CSocNetLogFollow::Update($user_id, $code, $type, false); } else { $res = CSocNetLogFollow::Add($user_id, $code, $type, false); } } return $res; }