• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/lib/componenthelper.php
  • Класс: BitrixSocialnetworkComponentHelper
  • Вызов: ComponentHelper::getBlogPostSocNetPerms
static function getBlogPostSocNetPerms($params = array())
{
	$result = array();

	$postId = (
		is_array($params)
		&& !empty($params['postId'])
		&& (int)$params['postId'] > 0
			? (int)$params['postId']
			: 0
	);

	$authorId = (
		is_array($params)
		&& !empty($params['authorId'])
		&& (int)$params['authorId'] > 0
			? (int)$params['authorId']
			: 0
	);

	if ($postId <= 0)
	{
		return $result;
	}

	if ($authorId <= 0)
	{
		$blogPostFields = CBlogPost::getByID($postId);
		$authorId = (int)$blogPostFields["AUTHOR_ID"];
	}

	if ($authorId <= 0)
	{
		return $result;
	}

	$result = CBlogPost::getSocNetPermsCode($postId);

	$profileBlogPost = false;
	foreach($result as $perm)
	{
		if (preg_match('/^UP(d+)$/', $perm, $matches))
		{
			$profileBlogPost = true;
			break;
		}
	}
	if (!$profileBlogPost)
	{
		if (!in_array("U".$authorId, $result, true))
		{
			$result[] = "U".$authorId;
		}
		$result[] = "SA"; // socnet admin

		if (
			in_array("AU", $result, true)
			|| in_array("G2", $result, true)
		)
		{
			$socnetPermsAdd = array();

			foreach ($result as $perm)
			{
				if (preg_match('/^SG(d+)$/', $perm, $matches))
				{
					if (
						!in_array("SG".$matches[1]."_".UserToGroupTable::ROLE_USER, $result, true)
						&& !in_array("SG".$matches[1]."_".UserToGroupTable::ROLE_MODERATOR, $result, true)
						&& !in_array("SG".$matches[1]."_".UserToGroupTable::ROLE_OWNER, $result, true)
					)
					{
						$socnetPermsAdd[] = "SG".$matches[1]."_".$result;
					}
				}
			}
			if (count($socnetPermsAdd) > 0)
			{
				$result = array_merge($result, $socnetPermsAdd);
			}
		}
	}

	return $result;
}