• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/log_tools.php
  • Класс: CSocNetLogTools
  • Вызов: CSocNetLogTools::AddComment_Files
static function AddComment_Files($arFields)
{
	if (!CModule::IncludeModule("forum"))
		return false;

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

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

	$bFound = false;
	if ($arLog = $dbResult->Fetch())
	{
		if ($arLog["PARAMS"] <> '')
		{
			$arFieldsParams = explode("&", $arLog["PARAMS"]);
			if (is_array($arFieldsParams) && count($arFieldsParams) > 0)
			{
				foreach ($arFieldsParams as $tmp)
				{
					list($key, $value) = explode("=", $tmp);
					if ($key == "forum_id")
					{
						$FORUM_ID = intval($value);
						break;
					}
				}
			}
		}
		if ($FORUM_ID > 0 && intval($arLog["SOURCE_ID"]) > 0)
			$bFound = true;
	}

	if ($bFound)
	{
		$arElement = false;

		$arFilter = array("ID" => $arLog["SOURCE_ID"]);
		$arSelectedFields = array("IBLOCK_ID", "ID", "NAME", "TAGS", "CODE", "IBLOCK_SECTION_ID", "DETAIL_PAGE_URL",
				"CREATED_BY", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PROPERTY_FORUM_TOPIC_ID", "PROPERTY_FORUM_MESSAGE_CNT");
		$db_res = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelectedFields);
		if ($db_res && $res = $db_res->GetNext())
			$arElement = $res;

		if ($arElement)
		{
			// check iblock properties
			CSocNetLogTools::AddComment_Review_CheckIBlock_Forum($arElement);

			$dbMessage = CForumMessage::GetList(
				array(),
				array(
					"PARAM1" => "IB",
					"PARAM2" => $arElement["ID"]
				)
			);

			if (!$arMessage = $dbMessage->Fetch())
			{
				// Add Topic and Root Message
				$arForum = CForumNew::GetByID($FORUM_ID);
				$sImage = "";
				if (intval($arElement["PREVIEW_PICTURE"]) > 0):
					$arImage = CFile::GetFileArray($arElement["PREVIEW_PICTURE"]);
					if (!empty($arImage))
						$sImage = ($arForum["ALLOW_IMG"] == "Y" ? "[IMG]".$arImage["SRC"]."[/IMG]" : '');
				endif;
				$sElementPreview = $arElement["~PREVIEW_TEXT"];
				if ($arForum["ALLOW_HTML"] != "Y")
					$sElementPreview = strip_tags($sElementPreview);

				$strFirstMessage = str_replace(array("#IMAGE#", "#TITLE#", "#BODY#"),
					array($sImage, $arElement["~NAME"], $sElementPreview),
					GetMessage("WD_TEMPLATE_MESSAGE"));

				$TOPIC_ID = CSocNetLogTools::AddComment_Review_CreateRoot_Forum($arElement, $FORUM_ID, true, $strFirstMessage);
				$bNewTopic = true;
			}
			else
				$TOPIC_ID = $arMessage["TOPIC_ID"];

			if(intval($TOPIC_ID) > 0)
			{
				// Add comment
				$messageID = false;
				$arFieldsMessage = array(
					"POST_MESSAGE" => $arFields["TEXT_MESSAGE"],
					"USE_SMILES" => "Y",
					"PARAM2" => $arElement["ID"],
					"APPROVED" => "Y"
				);
				$messageID = ForumAddMessage("REPLY", $FORUM_ID, $TOPIC_ID, 0, $arFieldsMessage, $sError, $sNote);

				if (!$messageID)
					$strError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR");
				else
					CSocNetLogTools::AddComment_Review_UpdateElement_Forum($arElement, $TOPIC_ID, $bNewTopic);
			}
			else
				$strError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR");
		}
		else
			$strError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR");
	}
	else
		$strError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR");

	return array(
		"SOURCE_ID" => $messageID,
		"RATING_TYPE_ID" => "FORUM_POST",
		"RATING_ENTITY_ID" => $messageID,
		"ERROR" => $strError,
		"NOTES" => ""
	);
}