• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/log_tools.php
  • Класс: CSocNetLogTools
  • Вызов: CSocNetLogTools::AddComment_Blog
static function AddComment_Blog($arFields)
{
	global $USER, $APPLICATION;

	if (!CModule::IncludeModule("blog"))
		return false;

	$dbResult = CSocNetLog::GetList(
		array(),
		array("ID" => $arFields["LOG_ID"]),
		false,
		false,
		array("ID", "SOURCE_ID", "SITE_ID")
	);

	if ($arLog = $dbResult->Fetch())
	{
		$arPost = CBlogPost::GetByID($arLog["SOURCE_ID"]);
		if ($arPost)
		{
			$arBlog = CBlog::GetByID($arPost["BLOG_ID"]);
			$userID = $USER->GetID();

			$arLogSites = array();
			$rsLogSite = CSocNetLog::GetSite($arLog["ID"]);
			while ($arLogSite = $rsLogSite->Fetch())
				$arLogSites[] = $arLogSite["LID"];

			$bCurrentUserIsAdmin = CSocNetUser::IsCurrentUserModuleAdmin($arLogSites);
			$strPermission = BLOG_PERMS_DENY;
			$strPostPermission = BLOG_PERMS_DENY;

			if ($arFields["ENTITY_TYPE"] === SONET_ENTITY_GROUP)
			{
				if (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "blog", "full_post", $bCurrentUserIsAdmin))
					$strPostPermission = BLOG_PERMS_FULL;
				elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "blog", "premoderate_post"))
					$strPostPermission = BLOG_PERMS_PREMODERATE;
				elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "blog", "write_post"))
					$strPostPermission = BLOG_PERMS_WRITE;
				elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "blog", "moderate_post"))
					$strPostPermission = BLOG_PERMS_MODERATE;
				elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "blog", "view_post"))
					$strPostPermission = BLOG_PERMS_READ;

				if($strPostPermission > BLOG_PERMS_DENY)
				{
					if (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "blog", "full_comment", $bCurrentUserIsAdmin))
						$strPermission = BLOG_PERMS_FULL;
					elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "blog", "moderate_comment"))
						$strPermission = BLOG_PERMS_MODERATE;
					elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "blog", "write_comment"))
						$strPermission = BLOG_PERMS_WRITE;
					elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "blog", "premoderate_comment"))
						$strPermission = BLOG_PERMS_PREMODERATE;
					elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "blog", "view_comment"))
						$strPermission = BLOG_PERMS_READ;
				}
			}
			else
			{
				if (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "blog", "full_post", $bCurrentUserIsAdmin) || CMain::GetGroupRight("blog") >= "W" || $arFields["USER_ID"] == $userID)
					$strPostPermission = BLOG_PERMS_FULL;
				elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "blog", "moderate_post"))
					$strPostPermission = BLOG_PERMS_MODERATE;
				elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "blog", "write_post"))
					$strPostPermission = BLOG_PERMS_WRITE;
				elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "blog", "premoderate_post"))
					$strPostPermission = BLOG_PERMS_PREMODERATE;
				elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "blog", "view_post"))
					$strPostPermission = BLOG_PERMS_READ;

				if($strPostPermission > BLOG_PERMS_DENY)
				{
					if (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "blog", "full_comment", $bCurrentUserIsAdmin) || CMain::GetGroupRight("blog") >= "W" || $arFields["USER_ID"] == $userID)
						$strPermission = BLOG_PERMS_FULL;
					elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "blog", "moderate_comment"))
						$strPermission = BLOG_PERMS_MODERATE;
					elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "blog", "write_comment"))
						$strPermission = BLOG_PERMS_WRITE;
					elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "blog", "premoderate_comment"))
						$strPermission = BLOG_PERMS_PREMODERATE;
					elseif (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "blog", "view_comment"))
						$strPermission = BLOG_PERMS_READ;
				}
			}

			$UserIP = CBlogUser::GetUserIP();
			$path_to_post = ($arFields["ENTITY_TYPE"] == SONET_ENTITY_GROUP ? $arFields["PATH_TO_GROUP_BLOG_POST"] : $arFields["PATH_TO_USER_BLOG_POST"]);

			$arFieldsComment = Array(
				"POST_ID" => $arPost["ID"],
				"BLOG_ID" => $arBlog["ID"],
				"POST_TEXT" => $arFields["TEXT_MESSAGE"],
				"DATE_CREATE" => ConvertTimeStamp(time()+CTimeZone::GetOffset(), "FULL"),
				"AUTHOR_IP" => $UserIP[0],
				"AUTHOR_IP1" => $UserIP[1],
				"AUTHOR_ID" => $userID,
				"PARENT_ID" => false
			);

			if($strPermission == BLOG_PERMS_PREMODERATE)
			{
				$arFieldsComment["PUBLISH_STATUS"] = BLOG_PUBLISH_STATUS_READY;
				$strNotes = GetMessage("SONET_GL_ADD_COMMENT_BLOG_PREMODERATE");
			}

			$commentUrl = CComponentEngine::MakePathFromTemplate(
				htmlspecialcharsBack($path_to_post),
				array(
					"blog" => $arBlog["URL"],
					"post_id" => CBlogPost::GetPostID($arPost["ID"], $arPost["CODE"], $arFields["BLOG_ALLOW_POST_CODE"]),
					"user_id" => $arBlog["OWNER_ID"],
					"group_id" => ($arFields["ENTITY_TYPE"] == SONET_ENTITY_GROUP ? $arFields["ENTITY_ID"] : false)
				)
			);

			$arFieldsComment["PATH"] = $commentUrl.(mb_strpos($arFieldsComment["PATH"], "?") !== false ? "&" : "?")."commentId=#comment_id##com#comment_id#";

			$commentId = CBlogComment::Add($arFieldsComment);
			if($strPermission == BLOG_PERMS_PREMODERATE)
				unset($commentId);

			BXClearCache(True, "/".SITE_ID."/blog/".$arBlog["URL"]."/comment/".$arPost["ID"]."/");
			BXClearCache(True, "/".SITE_ID."/blog/".$arBlog["URL"]."/post/".$arPost["ID"]."/");
			BXClearCache(True, "/".SITE_ID."/blog/".$arBlog["URL"]."/first_page/");
			BXClearCache(True, "/".SITE_ID."/blog/last_comments/");
			BXClearCache(True, "/".SITE_ID."/blog/".$arBlog["URL"]."/rss_out/".$arPost["POST_ID"]."/C/");
			BXClearCache(True, "/".SITE_ID."/blog/last_messages/");
			BXClearCache(True, "/".SITE_ID."/blog/commented_posts/");
			BXClearCache(True, ComponentHelper::getBlogPostCacheDir(array(
				'TYPE' => 'posts_popular',
				'SITE_ID' => SITE_ID
			)));
		}
		else
			$strError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR");
	}

	return array(
		"SOURCE_ID" => $commentId,
		"RATING_TYPE_ID" => "BLOG_COMMENT",
		"RATING_ENTITY_ID" => $commentId,
		"ERROR" => $strError,
		"NOTES"	=> $strNotes
	);
}