function OnAfterPhotoCommentAddBlog($ID, $arFields)
{
global $USER, $DB;
if (!CModule::IncludeModule('iblock'))
return;
if (!$this->IsSocnet)
return;
if (intval($this->PhotoElementID) > 0)
{
$dbRes = CSocNetLog::GetList(
array("ID" => "DESC"),
array(
"EVENT_ID" => "photo_photo",
"SOURCE_ID" => $this->PhotoElementID
),
false,
false,
array("ID", "ENTITY_TYPE", "ENTITY_ID", "TMP_ID", "TITLE", "URL", "USER_ID", "PARAMS")
);
$bSocNetLogRecordExists = false;
if ($arRes = $dbRes->Fetch())
{
$log_id = $arRes["ID"];
$entity_type = $arRes["ENTITY_TYPE"];
$entity_id = $arRes["ENTITY_ID"];
$log_title = $arRes["TITLE"];
$log_url = $arRes["URL"];
$log_user_id = $arRes["USER_ID"];
$bSocNetLogRecordExists = true;
if ($arRes["PARAMS"] <> '')
{
$arTmp = unserialize($arRes["PARAMS"], [ 'allowed_classes' => false ]);
if ($arTmp)
{
if (
array_key_exists("SECTION_NAME", $arTmp)
&& $arTmp["SECTION_NAME"] <> ''
)
$log_section_name = $arTmp["SECTION_NAME"];
if (
array_key_exists("SECTION_URL", $arTmp)
&& $arTmp["SECTION_URL"] <> ''
)
$log_section_url = $arTmp["SECTION_URL"];
}
}
}
else
{
$rsElement = CIBlockElement::GetByID($this->PhotoElementID);
if ($arElement = $rsElement->Fetch())
{
$url = $this->arPath["DETAIL_URL"];
$sAuthorName = GetMessage("SONET_PHOTO_LOG_GUEST");
if (intval($arElement["CREATED_BY"]) > 0)
{
$rsUser = CUser::GetByID($arElement["CREATED_BY"]);
if ($arUser = $rsUser->Fetch())
$sAuthorName = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);
}
if (
in_array($this->entity_type, array(SONET_ENTITY_USER, SONET_ENTITY_GROUP))
&& intval($this->entity_id) > 0
)
{
$entity_type = $this->entity_type;
$entity_id = $this->entity_id;
$alias = ($this->entity_type == SONET_ENTITY_GROUP ? "group" : "user")."_".$this->entity_id;
}
$arLogParams = array(
"BLOG_ID" => intval($this->BlogID)
);
$rsIBlock = CIBlock::GetByID($arElement["IBLOCK_ID"]);
if($arIBlock = $rsIBlock->Fetch())
{
$arLogParams["IBLOCK_ID"] = $arIBlock["ID"];
$arLogParams["IBLOCK_TYPE"] = $arIBlock["IBLOCK_TYPE_ID"];
}
$rsSection = CIBlockSection::GetByID($arElement["IBLOCK_SECTION_ID"]);
if ($arSection = $rsSection->Fetch())
{
$arLogParams["SECTION_ID"] = $arSection["ID"];
$arLogParams["SECTION_NAME"] = $arSection["NAME"];
$arLogParams["SECTION_URL"] = str_replace("#SECTION_ID#", $arSection["ID"], $this->arPath["SECTION_URL"]);
$arSectionPath = array();
$bPassword = false;
$dbSectionPath = CIBlockSection::GetList(
array("LEFT_MARGIN" => "ASC"),
array(
"IBLOCK_ID" => intval($arLogParams["IBLOCK_ID"]),
"<=LEFT_BORDER" => intval($arSection["LEFT_MARGIN"]),
">=RIGHT_BORDER" => intval($arSection["RIGHT_MARGIN"]),
"<=DEPTH_LEVEL" => intval($arSection["DEPTH_LEVEL"]),
),
false,
array("ID", "IBLOCK_ID", "NAME", "CREATED_BY", "DEPTH_LEVEL", "LEFT_MARGIN", "RIGHT_MARGIN", "UF_PASSWORD")
);
while ($arPath = $dbSectionPath->Fetch())
{
$arSectionPath[] = $arPath;
if (trim($arPath["UF_PASSWORD"]) <> '')
{
$bPassword = true;
break;
}
}
if (!$alias)
{
$entity_type = SONET_ENTITY_USER;
$entity_id = $arSectionPath[0]["CREATED_BY"];
$alias = $arSectionPath[0]["CODE"];
}
}
$arLogParams["ALIAS"] = $alias;
$arSonetFields = array(
"ENTITY_TYPE" => $entity_type,
"ENTITY_ID" => $entity_id,
"EVENT_ID" => "photo_photo",
"LOG_DATE" => $arElement["TIMESTAMP_X"],
"TITLE_TEMPLATE" => str_replace("#AUTHOR_NAME#", $sAuthorName, GetMessage("SONET_PHOTOPHOTO_LOG_1")),
"TITLE" => $arElement["NAME"],
"MESSAGE" => "",
"TEXT_MESSAGE" => "",
"URL" => CComponentEngine::MakePathFromTemplate($url, array(
"ELEMENT_ID" => $arElement["ID"],
"element_id" => $arElement["ID"],
"SECTION_ID" => $arElement["IBLOCK_SECTION_ID"],
"section_id" => $arElement["IBLOCK_SECTION_ID"]
)),
"MODULE_ID" => false,
"CALLBACK_FUNC" => false,
"SOURCE_ID" => $arElement["ID"],
"PARAMS" => serialize($arLogParams),
"RATING_TYPE_ID" => "IBLOCK_ELEMENT",
"RATING_ENTITY_ID"=> $arElement["ID"],
);
if (intval($arElement["CREATED_BY"]) > 0)
$arSonetFields["USER_ID"] = $arElement["CREATED_BY"];
$log_id = CSocNetLog::Add($arSonetFields, false);
if (intval($log_id) > 0)
{
$log_title = $arSonetFields["TITLE"];
$log_url = $arSonetFields["URL"];
$log_section_name = $arLogParams["SECTION_NAME"];
$log_section_url = $arLogParams["SECTION_URL"];
$log_user_id = $arSonetFields["USER_ID"];
CSocNetLog::Update($log_id, array("TMP_ID" => $log_id));
if ($bPassword)
{
CSocNetLogRights::DeleteByLogID($log_id);
CSocNetLogRights::Add($log_id, array("U".$USER->GetID(), "SA"));
}
else
{
CSocNetLogRights::SetForSonet($log_id, $entity_type, $entity_id, "photo", "view", true);
}
}
}
}
if (intval($log_id) > 0)
{
$parserBlog = new blogTextParser(false, $this->arPath["PATH_TO_SMILE"]);
$arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "N");
if ($bSocNetLogRecordExists)
{
$text4message = $parserBlog->convert($arFields["POST_TEXT"], true, array(), $arAllow);
$text4mail = $parserBlog->convert4mail($arFields["POST_TEXT"]);
$arFieldsForSocnet = array(
"ENTITY_TYPE" => $entity_type,
"ENTITY_ID" => $entity_id,
"EVENT_ID" => "photo_comment",
"=LOG_DATE" => $DB->CurrentTimeFunction(),
"MESSAGE" => $text4message,
"TEXT_MESSAGE" => $text4mail,
"MODULE_ID" => false,
"SOURCE_ID" => $ID,
"LOG_ID" => $log_id,
"RATING_TYPE_ID" => "BLOG_COMMENT",
"RATING_ENTITY_ID" => $ID,
);
if (intval($arFields["AUTHOR_ID"]) > 0)
$arFieldsForSocnet["USER_ID"] = $arFields["AUTHOR_ID"];
$comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
if ($comment_id)
{
CSocNetLog::CounterIncrement($comment_id, false, false, "LC");
$arFieldsIM = Array(
"TYPE" => "COMMENT",
"TITLE" => $log_title,
"MESSAGE" => $arFieldsForSocnet["MESSAGE"],
"URL" => $log_url,
"SECTION_NAME" => $log_section_name,
"SECTION_URL" => $log_section_url,
"ID" => $this->PhotoElementID,
"PHOTO_AUTHOR_ID" => $log_user_id,
"COMMENT_AUTHOR_ID" => $arFields["AUTHOR_ID"],
);
CSocNetPhotoCommentEvent::NotifyIm($arFieldsIM);
}
}
else //socnetlog record didn't exist - adding all comments
{
$dbComments = CBlogComment::GetList(array(),
array(
"BLOG_ID" => intval($this->BlogID),
"POST_ID" => intval($this->PostID)
),
false,
false,
array("ID", "BLOG_ID", "POST_ID", "AUTHOR_ID", "POST_TEXT", "DATE_CREATE")
);
while ($arComment = $dbComments->GetNext())
{
$text4message = $parserBlog->convert($arComment["POST_TEXT"], true, array(), $arAllow);
$text4mail = $parserBlog->convert4mail($arComment["POST_TEXT"]);
$arFieldsForSocnet = array(
"ENTITY_TYPE" => $entity_type,
"ENTITY_ID" => $entity_id,
"EVENT_ID" => "photo_comment",
"=LOG_DATE" => $DB->CharToDateFunction($arComment["DATE_CREATE"], "FULL", SITE_ID),
"MESSAGE" => $text4message,
"TEXT_MESSAGE" => $text4mail,
"MODULE_ID" => false,
"SOURCE_ID" => intval($arComment["ID"]),
"LOG_ID" => $log_id,
"RATING_TYPE_ID" => "BLOG_COMMENT",
"RATING_ENTITY_ID" => intval($arComment["ID"]),
);
if (intval($arFields["AUTHOR_ID"]) > 0)
$arFieldsForSocnet["USER_ID"] = $arFields["AUTHOR_ID"];
$comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
if ($comment_id)
{
CSocNetLog::CounterIncrement($comment_id, false, false, "LC");
$arFieldsIM = Array(
"TYPE" => "COMMENT",
"TITLE" => $log_title,
"MESSAGE" => $arFieldsForSocnet["MESSAGE"],
"URL" => $log_url,
"SECTION_NAME" => $log_section_name,
"SECTION_URL" => $log_section_url,
"ID" => $this->PhotoElementID,
"PHOTO_AUTHOR_ID" => $log_user_id,
"COMMENT_AUTHOR_ID" => $arFields["AUTHOR_ID"],
);
CSocNetPhotoCommentEvent::NotifyIm($arFieldsIM);
}
}
if ($arElement)
{
self::InheriteAlbumFollow($arElement["IBLOCK_SECTION_ID"], $log_id, (intval($arElement["CREATED_BY"]) > 0 ? $arElement["CREATED_BY"] : false));
}
}
}
}
}