25 public static function getById($commentId = 0)
27 static $cachedFields = array();
30 $commentId = (int)$commentId;
35 $commentFields = array();
37 if (isset($cachedFields[$commentId]))
39 $commentFields = $cachedFields[$commentId];
43 $select = array(
'*',
'UF_BLOG_COMM_URL_PRV');
46 Option::get(
'disk',
'successfully_converted',
false)
50 $select[] =
'UF_BLOG_COMMENT_FILE';
53 $res = CommentTable::getList(array(
54 'filter' => array(
'=ID' => $commentId),
57 if ($fields = $res->fetch())
59 $commentFields = $fields;
63 $commentFields[
'DATE_CREATE'] = $commentFields[
'DATE_CREATE']->toString();
67 $cachedFields[$commentId] = $commentFields;
70 $commentItem->setFields($commentFields);
86 public static function checkDuplicate(array $params = [],
int &$duplicateCommentId = 0): bool
89 isset($params[
'MESSAGE'])
90 && trim((
string)$params[
'MESSAGE']) !==
''
91 ? trim((
string)$params[
'MESSAGE'])
96 isset($params[
'BLOG_ID'])
97 && (int)$params[
'BLOG_ID'] > 0
98 ? (
int)$params[
'BLOG_ID']
103 isset($params[
'POST_ID'])
104 && (int)$params[
'POST_ID'] > 0
105 ? (
int)$params[
'POST_ID']
110 isset($params[
'AUTHOR_ID'])
111 && (int)$params[
'AUTHOR_ID'] > 0
112 ? (
int)$params[
'AUTHOR_ID']
125 \CTimeZone::Disable();
126 $res = \CBlogComment::getList(
129 "BLOG_ID" => $blogId,
130 "POST_ID" => $postId,
131 "AUTHOR_ID" => $authorId,
132 ">DATE_CREATE" => ConvertTimeStamp(time() - 60*30,
"FULL")
135 [
"nTopCount" => 1 ],
136 [
'ID',
'POST_TEXT' ]
138 \CTimeZone::Enable();
141 ($duplicateComment = $res->fetch())
142 && mb_strlen($message) > 10
143 && md5((
string)$duplicateComment[
'POST_TEXT']) === md5($message)
146 $duplicateCommentId = (int)$duplicateComment[
'ID'];
155 static $blogPostEventIdList =
null;
157 if (!Loader::includeModule(
'socialnetwork'))
163 isset($params[
"MESSAGE"])
164 && trim($params[
"MESSAGE"])
165 ? trim($params[
"MESSAGE"])
170 isset($params[
"BLOG_ID"])
171 && (int)$params[
"BLOG_ID"] > 0
172 ? (
int)$params[
"BLOG_ID"]
177 isset($params[
"BLOG_OWNER_ID"])
178 && (int)$params[
"BLOG_OWNER_ID"] > 0
179 ? (
int)$params[
"BLOG_OWNER_ID"]
184 isset($params[
"POST_ID"])
185 && (int)$params[
"POST_ID"] > 0
186 ? (
int)$params[
"POST_ID"]
191 isset($params[
"POST_TITLE"])
192 && trim($params[
"POST_TITLE"])
193 ? trim($params[
"POST_TITLE"])
198 isset($params[
"POST_AUTHOR_ID"])
199 && (int)$params[
"POST_AUTHOR_ID"] > 0
200 ? (
int)$params[
"POST_AUTHOR_ID"]
205 isset($params[
"COMMENT_ID"])
206 && (int)$params[
"COMMENT_ID"] > 0
207 ? (
int)$params[
"COMMENT_ID"]
212 isset($params[
"AUTHOR_ID"])
213 && (int)$params[
"AUTHOR_ID"] > 0
214 ? (
int)$params[
"AUTHOR_ID"]
222 || $postAuthorId <= 0
225 || $commentAuthorId <= 0
231 \BXClearCache(
true,
"/blog/comment/" . (
int)($postId / 100) .
"/" . $postId .
"/");
232 $connection = \Bitrix\Main\Application::getConnection();
233 $helper = $connection->getSqlHelper();
235 $connection->query(
"UPDATE b_blog_image SET COMMENT_ID=" . $commentId .
" WHERE BLOG_ID=".$blogId .
" AND POST_ID=" . $postId .
" AND IS_COMMENT = 'Y' AND (COMMENT_ID = 0 OR COMMENT_ID is null) AND USER_ID=" . $commentAuthorId);
237 if ($blogPostEventIdList ===
null)
239 $blogPostLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\BlogPost;
240 $blogPostEventIdList = $blogPostLivefeedProvider->getEventId();
243 $res = \CSocNetLog::getList(
246 "EVENT_ID" => $blogPostEventIdList,
247 "SOURCE_ID" => $postId
254 if ($log = $res->fetch())
256 $extranetSiteId =
false;
257 if (Loader::includeModule(
'extranet'))
259 $extranetSiteId = \CExtranet::getExtranetSiteId();
263 $res = \CSocNetLog::getSite($log[
"ID"]);
264 while ($logSite = $res->fetch())
266 $logSiteId[] = $logSite[
"LID"];
271 && count($logSiteId) === 1
272 && $logSiteId[0] === $extranetSiteId
277 $postUrl = Option::get(
"socialnetwork",
"userblogpost_page",
'/company/personal/users/'.$blogOwnerId.
'/blog/#post_id#/', $siteId);
278 $postUrl = \CComponentEngine::makePathFromTemplate(
281 "user_id" => $postAuthorId,
286 $fieldsSocnet = array(
287 "ENTITY_TYPE" => SONET_ENTITY_USER,
288 "ENTITY_ID" => $blogOwnerId,
289 "EVENT_ID" =>
"blog_comment",
290 "USER_ID" => $commentAuthorId,
291 "=LOG_DATE" => $helper->getCurrentDateTimeFunction(),
292 "MESSAGE" => $message,
293 "TEXT_MESSAGE" => $message,
295 "MODULE_ID" =>
false,
296 "SOURCE_ID" => $commentId,
297 "LOG_ID" => $log[
"ID"],
298 "RATING_TYPE_ID" =>
"BLOG_COMMENT",
299 "RATING_ENTITY_ID" => $commentId
302 $parser = new \CTextParser();
303 $tagInlineList = $parser->detectTags($message);
305 if (!empty($tagInlineList))
307 $fieldsSocnet[
"TAG"] = $tagInlineList;
310 $logCommentId = \CSocNetLogComments::add($fieldsSocnet,
false,
false);
312 if ($logCommentId > 0)
314 \CSocNetLog::counterIncrement(
319 \CSocNetLogRights::checkForUserAll($log[
"ID"])
323 $postSonetRights = \CBlogPost::getSocnetPerms($postId);
325 $mailUserId = array();
326 if (!empty($postSonetRights[
"U"]))
328 $mailUserId = array_keys($postSonetRights[
"U"]);
329 foreach($postSonetRights[
"U"] as $k => $v)
331 $userCode[] =
"U".$k;
337 "TITLE" => $postTitle,
340 "COMMENT_ID" => $commentId,
341 "FROM_USER_ID" => $commentAuthorId,
342 "TO_USER_ID" => array($postAuthorId),
343 "TO_SOCNET_RIGHTS" => $userCode,
344 "TO_SOCNET_RIGHTS_OLD" => array(
348 "AUTHOR_ID" => $postAuthorId,
352 $fieldsIM[
"EXCLUDE_USERS"] = array();
354 $res = \CSocNetLogFollow::getList(
356 "CODE" =>
"L".$log[
"ID"],
362 while ($unfollower = $res->fetch())
364 $fieldsIM[
"EXCLUDE_USERS"][$unfollower[
"USER_ID"]] = $unfollower[
"USER_ID"];
367 \CBlogPost::notifyIm($fieldsIM);
369 if (!empty($mailUserId))
371 \CBlogPost::notifyMail(array(
373 "userId" => $mailUserId,
374 "authorId" => $commentAuthorId,
376 "commentId" => $commentId,
378 "postUrl" => \CComponentEngine::makePathFromTemplate(
379 '/pub/post.php?post_id=#post_id#',
387 $siteResult = \CSite::getByID($siteId);
389 if ($site = $siteResult->fetch())
391 \CBlogComment::addLiveComment($commentId, array(
392 "DATE_TIME_FORMAT" => $site[
"FORMAT_DATETIME"],
393 "NAME_TEMPLATE" => \CSite::getNameFormat(
null, $siteId),
395 "MODE" =>
"PULL_MESSAGE"