Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
comment.php
1<?php
2
9namespace Bitrix\Blog\Item;
10
15
17{
18 private $fields;
19
20 public function __construct()
21 {
22 $this->fields = [];
23 }
24
25 public static function getById($commentId = 0)
26 {
27 static $cachedFields = array();
28
29 $commentItem = false;
30 $commentId = (int)$commentId;
31
32 if ($commentId > 0)
33 {
34 $commentItem = new Comment;
35 $commentFields = array();
36
37 if (isset($cachedFields[$commentId]))
38 {
39 $commentFields = $cachedFields[$commentId];
40 }
41 else
42 {
43 $select = array('*', 'UF_BLOG_COMM_URL_PRV');
44
45 if (
46 Option::get('disk', 'successfully_converted', false)
48 )
49 {
50 $select[] = 'UF_BLOG_COMMENT_FILE';
51 }
52
53 $res = CommentTable::getList(array(
54 'filter' => array('=ID' => $commentId),
55 'select' => $select
56 ));
57 if ($fields = $res->fetch())
58 {
59 $commentFields = $fields;
60
61 if ($commentFields['DATE_CREATE'] instanceof \Bitrix\Main\Type\DateTime)
62 {
63 $commentFields['DATE_CREATE'] = $commentFields['DATE_CREATE']->toString();
64 }
65 }
66
67 $cachedFields[$commentId] = $commentFields;
68 }
69
70 $commentItem->setFields($commentFields);
71 }
72
73 return $commentItem;
74 }
75
76 public function setFields($fields = []): void
77 {
78 $this->fields = $fields;
79 }
80
81 public function getFields(): array
82 {
83 return $this->fields;
84 }
85
86 public static function checkDuplicate(array $params = [], int &$duplicateCommentId = 0): bool
87 {
88 $message = (
89 isset($params['MESSAGE'])
90 && trim((string)$params['MESSAGE']) !== ''
91 ? trim((string)$params['MESSAGE'])
92 : ''
93 );
94
95 $blogId = (
96 isset($params['BLOG_ID'])
97 && (int)$params['BLOG_ID'] > 0
98 ? (int)$params['BLOG_ID']
99 : 0
100 );
101
102 $postId = (
103 isset($params['POST_ID'])
104 && (int)$params['POST_ID'] > 0
105 ? (int)$params['POST_ID']
106 : 0
107 );
108
109 $authorId = (
110 isset($params['AUTHOR_ID'])
111 && (int)$params['AUTHOR_ID'] > 0
112 ? (int)$params['AUTHOR_ID']
113 : 0
114 );
115
116 if (
117 $message === ''
118 || $blogId <= 0
119 || $postId <= 0
120 )
121 {
122 return false;
123 }
124
125 \CTimeZone::Disable();
126 $res = \CBlogComment::getList(
127 [ "ID" => "DESC" ],
128 [
129 "BLOG_ID" => $blogId,
130 "POST_ID" => $postId,
131 "AUTHOR_ID" => $authorId,
132 ">DATE_CREATE" => ConvertTimeStamp(time() - 60*30, "FULL")
133 ],
134 false,
135 [ "nTopCount" => 1 ],
136 [ 'ID', 'POST_TEXT' ]
137 );
138 \CTimeZone::Enable();
139
140 if (
141 ($duplicateComment = $res->fetch())
142 && mb_strlen($message) > 10
143 && md5((string)$duplicateComment['POST_TEXT']) === md5($message)
144 )
145 {
146 $duplicateCommentId = (int)$duplicateComment['ID'];
147 return false;
148 }
149
150 return true;
151 }
152
153 public static function actionsAfter(array $params): bool
154 {
155 static $blogPostEventIdList = null;
156
157 if (!Loader::includeModule('socialnetwork'))
158 {
159 return false;
160 }
161
162 $message = (
163 isset($params["MESSAGE"])
164 && trim($params["MESSAGE"])
165 ? trim($params["MESSAGE"])
166 : ''
167 );
168
169 $blogId = (
170 isset($params["BLOG_ID"])
171 && (int)$params["BLOG_ID"] > 0
172 ? (int)$params["BLOG_ID"]
173 : 0
174 );
175
176 $blogOwnerId = (
177 isset($params["BLOG_OWNER_ID"])
178 && (int)$params["BLOG_OWNER_ID"] > 0
179 ? (int)$params["BLOG_OWNER_ID"]
180 : 0
181 );
182
183 $postId = (
184 isset($params["POST_ID"])
185 && (int)$params["POST_ID"] > 0
186 ? (int)$params["POST_ID"]
187 : 0
188 );
189
190 $postTitle = (
191 isset($params["POST_TITLE"])
192 && trim($params["POST_TITLE"])
193 ? trim($params["POST_TITLE"])
194 : ''
195 );
196
197 $postAuthorId = (
198 isset($params["POST_AUTHOR_ID"])
199 && (int)$params["POST_AUTHOR_ID"] > 0
200 ? (int)$params["POST_AUTHOR_ID"]
201 : 0
202 );
203
204 $commentId = (
205 isset($params["COMMENT_ID"])
206 && (int)$params["COMMENT_ID"] > 0
207 ? (int)$params["COMMENT_ID"]
208 : 0
209 );
210
211 $commentAuthorId = (
212 isset($params["AUTHOR_ID"])
213 && (int)$params["AUTHOR_ID"] > 0
214 ? (int)$params["AUTHOR_ID"]
215 : 0
216 );
217
218 if (
219 $message === ''
220 || $blogId <= 0
221 || $blogOwnerId <= 0
222 || $postAuthorId <= 0
223 || $postId <= 0
224 || $commentId <= 0
225 || $commentAuthorId <= 0
226 )
227 {
228 return false;
229 }
230
231 \BXClearCache(true, "/blog/comment/" . (int)($postId / 100) ."/" . $postId . "/");
232 $connection = \Bitrix\Main\Application::getConnection();
233 $helper = $connection->getSqlHelper();
234
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);
236
237 if ($blogPostEventIdList === null)
238 {
239 $blogPostLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\BlogPost;
240 $blogPostEventIdList = $blogPostLivefeedProvider->getEventId();
241 }
242
243 $res = \CSocNetLog::getList(
244 array(),
245 array(
246 "EVENT_ID" => $blogPostEventIdList,
247 "SOURCE_ID" => $postId
248 ),
249 false,
250 false,
251 array("ID")
252 );
253
254 if ($log = $res->fetch())
255 {
256 $extranetSiteId = false;
257 if (Loader::includeModule('extranet'))
258 {
259 $extranetSiteId = \CExtranet::getExtranetSiteId();
260 }
261
262 $logSiteId = [];
263 $res = \CSocNetLog::getSite($log["ID"]);
264 while ($logSite = $res->fetch())
265 {
266 $logSiteId[] = $logSite["LID"];
267 }
268
269 $siteId = (
270 $extranetSiteId
271 && count($logSiteId) === 1
272 && $logSiteId[0] === $extranetSiteId
273 ? $extranetSiteId
274 : $logSiteId[0]
275 );
276
277 $postUrl = Option::get("socialnetwork", "userblogpost_page", '/company/personal/users/'.$blogOwnerId.'/blog/#post_id#/', $siteId);
278 $postUrl = \CComponentEngine::makePathFromTemplate(
279 $postUrl,
280 array(
281 "user_id" => $postAuthorId,
282 "post_id" => $postId
283 )
284 );
285
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,
294 "URL" => $postUrl,
295 "MODULE_ID" => false,
296 "SOURCE_ID" => $commentId,
297 "LOG_ID" => $log["ID"],
298 "RATING_TYPE_ID" => "BLOG_COMMENT",
299 "RATING_ENTITY_ID" => $commentId
300 );
301
302 $parser = new \CTextParser();
303 $tagInlineList = $parser->detectTags($message);
304
305 if (!empty($tagInlineList))
306 {
307 $fieldsSocnet["TAG"] = $tagInlineList;
308 }
309
310 $logCommentId = \CSocNetLogComments::add($fieldsSocnet, false, false);
311
312 if ($logCommentId > 0)
313 {
314 \CSocNetLog::counterIncrement(
315 $logCommentId,
316 false,
317 false,
318 "LC",
319 \CSocNetLogRights::checkForUserAll($log["ID"])
320 );
321 }
322
323 $postSonetRights = \CBlogPost::getSocnetPerms($postId);
324 $userCode = array();
325 $mailUserId = array();
326 if (!empty($postSonetRights["U"]))
327 {
328 $mailUserId = array_keys($postSonetRights["U"]);
329 foreach($postSonetRights["U"] as $k => $v)
330 {
331 $userCode[] = "U".$k;
332 }
333 }
334
335 $fieldsIM = Array(
336 "TYPE" => "COMMENT",
337 "TITLE" => $postTitle,
338 "URL" => $postUrl,
339 "ID" => $postId,
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(
345 "U" => array(),
346 "SG" => array()
347 ),
348 "AUTHOR_ID" => $postAuthorId,
349 "BODY" => $message,
350 );
351
352 $fieldsIM["EXCLUDE_USERS"] = array();
353
354 $res = \CSocNetLogFollow::getList(
355 array(
356 "CODE" => "L".$log["ID"],
357 "TYPE" => "N"
358 ),
359 array("USER_ID")
360 );
361
362 while ($unfollower = $res->fetch())
363 {
364 $fieldsIM["EXCLUDE_USERS"][$unfollower["USER_ID"]] = $unfollower["USER_ID"];
365 }
366
367 \CBlogPost::notifyIm($fieldsIM);
368
369 if (!empty($mailUserId))
370 {
371 \CBlogPost::notifyMail(array(
372 "type" => "COMMENT",
373 "userId" => $mailUserId,
374 "authorId" => $commentAuthorId,
375 "postId" => $postId,
376 "commentId" => $commentId,
377 "siteId" => $siteId,
378 "postUrl" => \CComponentEngine::makePathFromTemplate(
379 '/pub/post.php?post_id=#post_id#',
380 array(
381 "post_id"=> $postId
382 )
383 )
384 ));
385 }
386
387 $siteResult = \CSite::getByID($siteId);
388
389 if ($site = $siteResult->fetch())
390 {
391 \CBlogComment::addLiveComment($commentId, array(
392 "DATE_TIME_FORMAT" => $site["FORMAT_DATETIME"],
393 "NAME_TEMPLATE" => \CSite::getNameFormat(null, $siteId),
394 "SHOW_LOGIN" => "Y",
395 "MODE" => "PULL_MESSAGE"
396 ));
397 }
398 }
399
400 return true;
401 }
402
403 public static function processCommentShare($params = [])
404 {
405 if (!Loader::includeModule('socialnetwork'))
406 {
407 return false;
408 }
409
410 return \Bitrix\Socialnetwork\Integration\Blog\Mention::processCommentShare($params);
411 }
412}
static checkDuplicate(array $params=[], int &$duplicateCommentId=0)
Definition comment.php:86
static processCommentShare($params=[])
Definition comment.php:403
static getById($commentId=0)
Definition comment.php:25
static actionsAfter(array $params)
Definition comment.php:153
setFields($fields=[])
Definition comment.php:76
static isModuleInstalled($moduleName)