• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/search.php
  • Класс: CSocNetSearch
  • Вызов: CSocNetSearch::SetFeaturePermissions
static function SetFeaturePermissions($entity_type, $entity_id, $feature, $operation, $new_perm)
{
	if(mb_substr($operation, 0, 4) === "view")//This kind of extremely dangerous optimization
	{
		global $arSonetFeaturesPermsCache;
		unset($arSonetFeaturesPermsCache[$entity_type."_".$entity_id]);

		if(CModule::IncludeModule('search'))
		{
			$arGroups = self::GetSearchGroups($entity_type, $entity_id, $feature, $operation);
			$arParams = self::GetSearchParams($entity_type, $entity_id, $feature, $operation);

			CSearch::ChangePermission(false, $arGroups, false, false, false, false, $arParams);
		}
	}
	if (
		$feature === "blog"
		&& in_array($operation, Array("view_post", "view_comment"))
		&& CModule::IncludeModule('blog')
	)
	{
		if($operation === "view_post")
		{
			CBlogPost::ChangeSocNetPermission($entity_type, $entity_id, $operation);
		}

		if(CModule::IncludeModule('search'))
		{
			if($operation === "view_post")
			{
				$arPost = CBlogPost::GetSocNetPostsPerms($entity_type, $entity_id);
				foreach($arPost as $id => $perms)
				{
					CSearch::ChangePermission("blog", $perms["PERMS"], "P".$id);
				}
			}
			else
			{
				$arTmpCache = Array();
				$arPost = CBlogPost::GetSocNetPostsPerms($entity_type, $entity_id);
				$dbComment = CBlogComment::GetSocNetPostsPerms($entity_type, $entity_id);
				while($arComment = $dbComment->Fetch())
				{
					if(!empty($arPost[$arComment["POST_ID"]]))
					{
						if(empty($arPost[$arComment["POST_ID"]]["PERMS_CALC"]))
						{
							$arPost[$arComment["POST_ID"]]["PERMS_CALC"] = array();
							if(is_array($arPost[$arComment["POST_ID"]]["PERMS_FULL"]) && !empty($arPost[$arComment["POST_ID"]]["PERMS_FULL"]))
							{
								foreach($arPost[$arComment["POST_ID"]]["PERMS_FULL"] as $e => $v)
								{
									if(in_array($v["TYPE"], Array("SG", "U")))
									{
										$type = $v["TYPE"] === "SG" ? "G" : "U";
										if(array_key_exists($type.$v["ID"], $arTmpCache))
										{
											$spt = $arTmpCache[$type.$v["ID"]];
										}
										else
										{
											$spt = CBlogPost::GetSocnetGroups($type, $v["ID"], "view_comment");
											$arTmpCache[$type.$v["ID"]] = $spt;
										}
										foreach($spt as $vv)
										{
											if(!in_array($vv, $arPost[$arComment["POST_ID"]]["PERMS_CALC"]))
												$arPost[$arComment["POST_ID"]]["PERMS_CALC"][] = $vv;
										}
									}
									else
									{
										$arPost[$arComment["POST_ID"]]["PERMS_CALC"][] = $e;
									}
								}
							}
						}

						CSearch::ChangePermission("blog", $arPost[$arComment["POST_ID"]]["PERMS_CALC"], "C".$arComment["ID"]);
					}
				}
			}
		}
	}
}