public function SocnetLogMessageAdd($ID, $arFields, $bUpdate = false) // add log comment
{
$arForum = CForumNew::GetByID($this->forumID);
$arMessage = CForumMessage::GetByIDEx($ID);
if ($arMessage["TOPIC_ID"])
$arTopic = CForumTopic::GetByID($arMessage["TOPIC_ID"]);
$arRes = $this->_getSocnetLogEntityByComment($arMessage);
if ($arRes && (intval($arRes["TMP_ID"]) > 0))
{
$parser = new textParser(LANGUAGE_ID, $this->arPath["PATH_TO_SMILE"]);
$parser->image_params["width"] = false;
$parser->image_params["height"] = false;
$arAllow = array(
"HTML" => "N",
"ANCHOR" => "N",
"BIU" => "N",
"IMG" => "N",
"LIST" => "N",
"QUOTE" => "N",
"CODE" => "N",
"FONT" => "N",
"UPLOAD" => $arForum["ALLOW_UPLOAD"],
"NL2BR" => "N",
"SMILES" => "N"
);
if (intval($arRes["COMMENTS_COUNT"]) == intval($arTopic["POSTS"]))
{
$url = CComponentEngine::MakePathFromTemplate($arParams["~URL_TEMPLATES_MESSAGE"],
array("FID" => $arMessage["FORUM_ID"], "TID" => $arMessage["TOPIC_ID"], "MID"=> $ID));
$arFieldsForSocnet = array(
"ENTITY_TYPE" => $arRes["ENTITY_TYPE"],
"ENTITY_ID" => $arRes["ENTITY_ID"],
"EVENT_ID" => $this->event_comments_id,
"=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(),
"MESSAGE" => $parser->convert($arMessage["POST_MESSAGE"], $arAllow),
"TEXT_MESSAGE" => $parser->convert4mail($arMessage["POST_MESSAGE"]),
"URL" => $url,
"MODULE_ID" => false,
"SOURCE_ID" => $ID,
"LOG_ID" => $arRes["TMP_ID"],
"RATING_TYPE_ID" => "FORUM_POST",
"RATING_ENTITY_ID" => intval($ID)
);
if (intval($arMessage["AUTHOR_ID"]) > 0)
$arFieldsForSocnet["USER_ID"] = $arMessage["AUTHOR_ID"];
if ($bUpdate)
{
$commentID = $this->_getSocnetLogCommentByForumComment($ID, $arRes);
if ($arMessage['APPROVED'] == 'Y')
{
if ($commentID)
{
CSocNetLogComments::Update($commentID, $arFieldsForSocnet);
}
else
{
$log_comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false); //, true
CSocNetLog::CounterIncrement($log_comment_id, false, false, "LC");
}
}
else
{
if ($commentID)
{
CSocNetLogComments::Delete($commentID);
}
}
}
else
{
$log_comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false); //, true
CSocNetLog::CounterIncrement($log_comment_id, false, false, "LC");
}
}
else // new socnetlog record created- we need to add all comments
{
$dbComments = CForumMessage::GetListEx(
array(),
array('TOPIC_ID' => $arMessage["TOPIC_ID"], "NEW_TOPIC" => "N")
);
while ($arComment = $dbComments->GetNext())
{
$url = CComponentEngine::MakePathFromTemplate($arParams["~URL_TEMPLATES_MESSAGE"],
array("FID" => $arComment["FORUM_ID"], "TID" => $arComment["TOPIC_ID"], "MID"=> $arComment["ID"]));
$arFieldsForSocnet = array(
"ENTITY_TYPE" => $arRes["ENTITY_TYPE"],
"ENTITY_ID" => $arRes["ENTITY_ID"],
"EVENT_ID" => $this->event_comments_id,
"=LOG_DATE" => $GLOBALS["DB"]->CharToDateFunction($arComment['POST_DATE'], "FULL", SITE_ID),
"MESSAGE" => $parser->convert($arComment["POST_MESSAGE"], $arAllow),
"TEXT_MESSAGE" => $parser->convert4mail($arComment["POST_MESSAGE"]),
"URL" => $url,
"MODULE_ID" => false,
"SOURCE_ID" => $arComment["ID"],
"LOG_ID" => $arRes["TMP_ID"],
"RATING_TYPE_ID" => "FORUM_POST",
"RATING_ENTITY_ID" => intval($arComment["ID"])
);
if (intval($arComment["AUTHOR_ID"]) > 0)
$arFieldsForSocnet["USER_ID"] = $arComment["AUTHOR_ID"];
$log_comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false); //, true
CSocNetLog::CounterIncrement($log_comment_id, false, false, "LC");
}
}
}
}