1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
blog_post.php
См. документацию.
1<?php
2
5use Bitrix\Blog\Integration;
6use Bitrix\Extranet;
7
9
11{
12 public static $arSocNetPostPermsCache = array();
13 public static $arUACCache = array();
14 public static $arBlogPostCache = array();
15 public static $arBlogPostIdCache = array();
16 public static $arBlogPCCache = array();
17 public static $arBlogUCache = array();
18
19 const UF_NAME = 'UF_BLOG_POST_DOC';
20
21 public static function CanUserEditPost($id, $userId): bool
22 {
23 $id = (int)$id;
24 $userId = (int)$userId;
25
26 $blogModulePermissions = CMain::getGroupRight("blog");
27 if ($blogModulePermissions >= "W")
28 {
29 return true;
30 }
31
32 $arPost = CBlogPost::GetByID($id);
33 if (!$arPost)
34 {
35 return false;
36 }
37
38 if (CBlog::IsBlogOwner($arPost["BLOG_ID"], $userId))
39 {
40 return true;
41 }
42
44 if ($arBlogUser && $arBlogUser["ALLOW_POST"] != "Y")
45 {
46 return false;
47 }
48
50 {
51 return false;
52 }
53
54 if ((int)$arPost['AUTHOR_ID'] === $userId)
55 {
56 return true;
57 }
58
59 return false;
60 }
61
62 public static function CanUserDeletePost($id, $userId): bool
63 {
64 $id = (int)$id;
65 $userId = (int)$userId;
66
67 $blogModulePermissions = CMain::getGroupRight("blog");
68 if ($blogModulePermissions >= "W")
69 {
70 return true;
71 }
72
73 $arPost = CBlogPost::GetByID($id);
74 if (!$arPost)
75 {
76 return false;
77 }
78
79 if (CBlog::IsBlogOwner($arPost["BLOG_ID"], $userId))
80 {
81 return true;
82 }
83
85 if ($arBlogUser && $arBlogUser["ALLOW_POST"] != "Y")
86 {
87 return false;
88 }
89
91 if ($perms <= BLOG_PERMS_WRITE && $userId != $arPost["AUTHOR_ID"])
92 {
93 return false;
94 }
95
96 if ($perms > BLOG_PERMS_WRITE)
97 {
98 return true;
99 }
100
101 if ((int)$arPost['AUTHOR_ID'] === $userId)
102 {
103 return true;
104 }
105
106 return false;
107 }
108
109 public static function GetBlogUserPostPerms($id, $userId)
110 {
111 $id = (int)$id;
112 $userId = (int)$userId;
113
114 $arAvailPerms = array_keys($GLOBALS["AR_BLOG_PERMS"]);
115 $blogModulePermissions = CMain::getGroupRight('blog');
116 if ($blogModulePermissions >= "W")
117 {
118 return $arAvailPerms[count($arAvailPerms) - 1];
119 }
120
121 $arPost = CBlogPost::GetByID($id);
122 if (!$arPost)
123 {
124 return $arAvailPerms[0];
125 }
126
127 if (CBlog::IsBlogOwner($arPost["BLOG_ID"], $userId))
128 {
129 return $arAvailPerms[count($arAvailPerms) - 1];
130 }
131
132 $arUserGroups = CBlogUser::GetUserGroups($userId, $arPost["BLOG_ID"], "Y", BLOG_BY_USER_ID);
133 $permGroups = CBlogUser::GetUserPerms($arUserGroups, $arPost["BLOG_ID"], $id, BLOG_PERMS_POST, BLOG_BY_USER_ID);
134
135// if for user unset option "WRITE TO BLOG", they can only read (even if all user can write), or smaller rights, if group have smaller
137 if ($arBlogUser && $arBlogUser["ALLOW_POST"] != "Y")
138 {
139 if ($permGroups && in_array(BLOG_PERMS_READ, $arAvailPerms))
140 {
141 return min(BLOG_PERMS_READ, $permGroups);
142 }
143 else
144 {
145 return $arAvailPerms[0];
146 }
147 }
148
149 if ($permGroups)
150 {
151 return $permGroups;
152 }
153
154 return $arAvailPerms[0];
155 }
156
157 public static function GetBlogUserCommentPerms($id, $userId)
158 {
159 $id = (int)$id;
160 $userId = (int)$userId;
161
162 $arAvailPerms = array_keys($GLOBALS["AR_BLOG_PERMS"]);
163
164 $blogModulePermissions = CMain::getGroupRight("blog");
165 if ($blogModulePermissions >= "W")
166 {
167 return $arAvailPerms[count($arAvailPerms) - 1];
168 }
169
170 if ($id > 0)
171 {
172 if (!($arPost = CBlogPost::GetByID($id)))
173 {
174 return $arAvailPerms[0];
175 }
176 else
177 {
178 $arBlog = CBlog::GetByID($arPost["BLOG_ID"]);
179 if ($arBlog["ENABLE_COMMENTS"] != "Y")
180 {
181 return $arAvailPerms[0];
182 }
183
184 if (CBlog::IsBlogOwner($arPost["BLOG_ID"], $userId))
185 {
186 return $arAvailPerms[count($arAvailPerms) - 1];
187 }
188
189 $arUserGroups = CBlogUser::GetUserGroups($userId, $arPost["BLOG_ID"], "Y", BLOG_BY_USER_ID);
190 $permGroups = CBlogUser::GetUserPerms($arUserGroups, $arPost["BLOG_ID"], $id, BLOG_PERMS_COMMENT, BLOG_BY_USER_ID);
191
192// if for user unset option "WRITE TO BLOG", they can only read (even if all user can write), or smaller rights, if group have smaller
194 if ($arBlogUser && $arBlogUser["ALLOW_POST"] != "Y")
195 {
196 if ($permGroups && in_array(BLOG_PERMS_READ, $arAvailPerms))
197 {
198 return min(BLOG_PERMS_READ, $permGroups);
199 }
200 else
201 {
202 return $arAvailPerms[0];
203 }
204 }
205
206 if ($permGroups)
207 {
208 return $permGroups;
209 }
210 }
211 }
212 else
213 {
214 return $arAvailPerms[0];
215 }
216
217 return $arAvailPerms[0];
218 }
219
220 /*************** ADD, UPDATE, DELETE *****************/
221 public static function CheckFields($ACTION, &$arFields, $ID = 0)
222 {
223 global $DB, $APPLICATION;
224
225 if ((is_set($arFields, "DETAIL_TEXT") || $ACTION=="ADD") && trim(str_replace("\xc2\xa0", ' ', $arFields["DETAIL_TEXT"]), " \t\n\r\0\x0B\xA0") == '')
226 {
227 $APPLICATION->ThrowException(GetMessage("BLG_GP_EMPTY_DETAIL_TEXT"), "EMPTY_DETAIL_TEXT");
228 return false;
229 }
230
231 if ((is_set($arFields, "TITLE") || $ACTION=="ADD") && $arFields["TITLE"] == '')
232 {
233 $APPLICATION->ThrowException(GetMessage("BLG_GP_EMPTY_TITLE"), "EMPTY_TITLE");
234 return false;
235 }
236
237 if ((is_set($arFields, "BLOG_ID") || $ACTION=="ADD") && intval($arFields["BLOG_ID"]) <= 0)
238 {
239 $APPLICATION->ThrowException(GetMessage("BLG_GP_EMPTY_BLOG_ID"), "EMPTY_BLOG_ID");
240 return false;
241 }
242 elseif (is_set($arFields, "BLOG_ID"))
243 {
244 $arResult = CBlog::GetByID($arFields["BLOG_ID"]);
245 if (!$arResult)
246 {
247 $APPLICATION->ThrowException(str_replace("#ID#", $arFields["BLOG_ID"], GetMessage("BLG_GP_ERROR_NO_BLOG")), "ERROR_NO_BLOG");
248 return false;
249 }
250 }
251
252 if ((is_set($arFields, "AUTHOR_ID") || $ACTION=="ADD") && intval($arFields["AUTHOR_ID"]) <= 0)
253 {
254 $APPLICATION->ThrowException(GetMessage("BLG_GP_EMPTY_AUTHOR_ID"), "EMPTY_AUTHOR_ID");
255 return false;
256 }
257 elseif (is_set($arFields, "AUTHOR_ID"))
258 {
259 $dbResult = CUser::GetByID($arFields["AUTHOR_ID"]);
260 if (!$dbResult->Fetch())
261 {
262 $APPLICATION->ThrowException(GetMessage("BLG_GP_ERROR_NO_AUTHOR"), "ERROR_NO_AUTHOR");
263 return false;
264 }
265 }
266
267 if (is_set($arFields, "DATE_CREATE") && (!$DB->IsDate($arFields["DATE_CREATE"], false, LANG, "FULL")))
268 {
269 $APPLICATION->ThrowException(GetMessage("BLG_GP_ERROR_DATE_CREATE"), "ERROR_DATE_CREATE");
270 return false;
271 }
272
273 if (is_set($arFields, "DATE_PUBLISH") && (!$DB->IsDate($arFields["DATE_PUBLISH"], false, LANG, "FULL")))
274 {
275 $APPLICATION->ThrowException(GetMessage("BLG_GP_ERROR_DATE_PUBLISH"), "ERROR_DATE_PUBLISH");
276 return false;
277 }
278
279
280 $arFields["PREVIEW_TEXT_TYPE"] = mb_strtolower($arFields["PREVIEW_TEXT_TYPE"] ?? '');
281 if ((is_set($arFields, "PREVIEW_TEXT_TYPE") || $ACTION=="ADD") && $arFields["PREVIEW_TEXT_TYPE"] != "text" && $arFields["PREVIEW_TEXT_TYPE"] != "html")
282 $arFields["PREVIEW_TEXT_TYPE"] = "text";
283
284 if ((is_set($arFields, "DETAIL_TEXT_TYPE") || $ACTION=="ADD") && mb_strtolower($arFields["DETAIL_TEXT_TYPE"]) != "text" && mb_strtolower($arFields["DETAIL_TEXT_TYPE"]) != "html")
285 $arFields["DETAIL_TEXT_TYPE"] = "text";
286 if (($arFields["DETAIL_TEXT_TYPE"] ?? '') <> '')
287 {
288 $arFields["DETAIL_TEXT_TYPE"] = mb_strtolower($arFields["DETAIL_TEXT_TYPE"]);
289 }
290
291 $arStatus = array_keys($GLOBALS["AR_BLOG_PUBLISH_STATUS"]);
292 if ((is_set($arFields, "PUBLISH_STATUS") || $ACTION=="ADD") && !in_array($arFields["PUBLISH_STATUS"], $arStatus))
293 $arFields["PUBLISH_STATUS"] = $arStatus[0];
294
295 if (
296 (
297 is_set($arFields, "ENABLE_TRACKBACK")
298 || $ACTION == "ADD"
299 )
300 && ($arFields["ENABLE_TRACKBACK"] ?? '') != "Y"
301 && ($arFields["ENABLE_TRACKBACK"] ?? '') != "N"
302 )
303 {
304 $arFields["ENABLE_TRACKBACK"] = "Y";
305 }
306
307 if (
308 (
309 is_set($arFields, "ENABLE_COMMENTS")
310 || $ACTION == "ADD"
311 )
312 && ($arFields["ENABLE_COMMENTS"] ?? '') != "Y"
313 && ($arFields["ENABLE_COMMENTS"] ?? '') != "N"
314 )
315 {
316 $arFields["ENABLE_COMMENTS"] = "Y";
317 }
318
319 if (!empty($arFields["ATTACH_IMG"]))
320 {
321 $res = CFile::CheckImageFile($arFields["ATTACH_IMG"], 0, 0, 0);
322 if ($res <> '')
323 {
324 $APPLICATION->ThrowException(GetMessage("BLG_GP_ERROR_ATTACH_IMG").": ".$res, "ERROR_ATTACH_IMG");
325 return false;
326 }
327 }
328 else
329 $arFields["ATTACH_IMG"] = false;
330
331 if (is_set($arFields, "NUM_COMMENTS"))
332 $arFields["NUM_COMMENTS"] = intval($arFields["NUM_COMMENTS"]);
333 if (is_set($arFields, "NUM_COMMENTS_ALL"))
334 $arFields["NUM_COMMENTS_ALL"] = intval($arFields["NUM_COMMENTS_ALL"]);
335 if (is_set($arFields, "NUM_TRACKBACKS"))
336 $arFields["NUM_TRACKBACKS"] = intval($arFields["NUM_TRACKBACKS"]);
337 if (is_set($arFields, "FAVORITE_SORT"))
338 {
339 $arFields["FAVORITE_SORT"] = intval($arFields["FAVORITE_SORT"]);
340 if($arFields["FAVORITE_SORT"] <= 0)
341 $arFields["FAVORITE_SORT"] = false;
342 }
343
344 if (is_set($arFields, "CODE") && $arFields["CODE"] <> '')
345 {
346 $arFields["CODE"] = preg_replace("/[^a-zA-Z0-9_-]/is", "", Trim($arFields["CODE"]));
347// preserve collision between numeric code and post ID.
348 $arFields["CODE"] = is_numeric($arFields["CODE"]) ? "_".$arFields["CODE"] : $arFields["CODE"];
349
350 if (in_array(mb_strtolower($arFields["CODE"]), $GLOBALS["AR_BLOG_POST_RESERVED_CODES"]))
351 {
352 $APPLICATION->ThrowException(str_replace("#CODE#", $arFields["CODE"], GetMessage("BLG_GP_RESERVED_CODE")), "CODE_RESERVED");
353 return false;
354 }
355
356 $arFilter = Array(
357 "CODE" => $arFields["CODE"],
358 );
359 if(intval($ID) > 0)
360 {
361 $arPost = CBlogPost::GetByID($ID);
362 $arFilter["!ID"] = $arPost["ID"];
363 $arFilter["BLOG_ID"] = $arPost["BLOG_ID"];
364 }
365 else
366 {
367 if(intval($arFields["BLOG_ID"]) > 0)
368 $arFilter["BLOG_ID"] = $arFields["BLOG_ID"];
369 }
370
371 $dbItem = CBlogPost::GetList(Array(), $arFilter, false, Array("nTopCount" => 1), Array("ID", "CODE", "BLOG_ID"));
372 if($dbItem->Fetch())
373 {
374 $APPLICATION->ThrowException(GetMessage("BLG_GP_CODE_EXIST", Array("#CODE#" => $arFields["CODE"])), "CODE_EXIST");
375 return false;
376 }
377 }
378
379 if (!empty($arFields["TITLE"]))
380 {
382 }
383
384 if (!empty($arFields["DETAIL_TEXT"]))
385 {
386 $arFields["DETAIL_TEXT"] = \Bitrix\Main\Text\Emoji::encode($arFields["DETAIL_TEXT"]);
387 }
388
389 return True;
390 }
391
392 public static function SetPostPerms($ID, $arPerms = array(), $permsType = BLOG_PERMS_POST)
393 {
394 global $DB;
395
396 $ID = intval($ID);
397 $permsType = (($permsType == BLOG_PERMS_COMMENT) ? BLOG_PERMS_COMMENT : BLOG_PERMS_POST);
398 if(!is_array($arPerms))
399 $arPerms = array();
400
401 $arPost = CBlogPost::GetByID($ID);
402 if ($arPost)
403 {
404 $arInsertedGroups = array();
405 foreach ($arPerms as $key => $value)
406 {
407 $dbGroupPerms = CBlogUserGroupPerms::GetList(
408 array(),
409 array(
410 "BLOG_ID" => $arPost["BLOG_ID"],
411 "USER_GROUP_ID" => $key,
412 "PERMS_TYPE" => $permsType,
413 "POST_ID" => $arPost["ID"],
414 ),
415 false,
416 false,
417 array("ID")
418 );
419 if ($arGroupPerms = $dbGroupPerms->Fetch())
420 {
422 $arGroupPerms["ID"],
423 array(
424 "PERMS" => $value,
425 "AUTOSET" => "N",
426 )
427 );
428 }
429 else
430 {
432 array(
433 "BLOG_ID" => $arPost["BLOG_ID"],
434 "USER_GROUP_ID" => $key,
435 "PERMS_TYPE" => $permsType,
436 "POST_ID" => $arPost["ID"],
437 "AUTOSET" => "N",
438 "PERMS" => $value,
439 )
440 );
441 }
442
443 $arInsertedGroups[] = $key;
444 }
445
447 array(),
448 array(
449 "BLOG_ID" => $arPost["BLOG_ID"],
450 "PERMS_TYPE" => $permsType,
451 "POST_ID" => 0,
452 "!USER_GROUP_ID" => $arInsertedGroups,
453 ),
454 false,
455 false,
456 array("ID", "USER_GROUP_ID", "PERMS")
457 );
458 while ($arResult = $dbResult->Fetch())
459 {
460 $dbGroupPerms = CBlogUserGroupPerms::GetList(
461 array(),
462 array(
463 "BLOG_ID" => $arPost["BLOG_ID"],
464 "USER_GROUP_ID" => $arResult["USER_GROUP_ID"],
465 "PERMS_TYPE" => $permsType,
466 "POST_ID" => $arPost["ID"],
467 ),
468 false,
469 false,
470 array("ID")
471 );
472 if ($arGroupPerms = $dbGroupPerms->Fetch())
473 {
475 $arGroupPerms["ID"],
476 array(
477 "PERMS" => $arResult["PERMS"],
478 "AUTOSET" => "Y",
479 )
480 );
481 }
482 else
483 {
485 array(
486 "BLOG_ID" => $arPost["BLOG_ID"],
487 "USER_GROUP_ID" => $arResult["USER_GROUP_ID"],
488 "PERMS_TYPE" => $permsType,
489 "POST_ID" => $arPost["ID"],
490 "AUTOSET" => "Y",
491 "PERMS" => $arResult["PERMS"],
492 )
493 );
494 }
495 }
496 }
497 }
498
499 public static function Delete($ID)
500 {
502
503 $ID = intval($ID);
504
505 $arPost = CBlogPost::GetByID($ID);
506 if ($arPost)
507 {
508 foreach(GetModuleEvents("blog", "OnBeforePostDelete", true) as $arEvent)
509 {
510 if (ExecuteModuleEventEx($arEvent, Array($ID))===false)
511 return false;
512 }
513
515 array(),
516 array("POST_ID" => $ID),
517 false,
518 false,
519 array("ID")
520 );
521 while ($arResult = $dbResult->Fetch())
522 {
524 return False;
525 }
526
528 array(),
529 array("POST_ID" => $ID, "BLOG_ID" => $arPost["BLOG_ID"]),
530 false,
531 false,
532 array("ID")
533 );
534 while ($arResult = $dbResult->Fetch())
535 {
537 return False;
538 }
539
541 array(),
542 array("POST_ID" => $ID, "BLOG_ID" => $arPost["BLOG_ID"]),
543 false,
544 false,
545 array("ID")
546 );
547 while ($arResult = $dbResult->Fetch())
548 {
550 return False;
551 }
552
554 array(),
555 array("POST_ID" => $ID, "BLOG_ID" => $arPost["BLOG_ID"]),
556 false,
557 false,
558 array("ID")
559 );
560 while ($arResult = $dbResult->Fetch())
561 {
563 return False;
564 }
565
566 $strSql =
567 "SELECT F.ID ".
568 "FROM b_blog_post P, b_file F ".
569 "WHERE P.ID = ".$ID." ".
570 " AND P.ATTACH_IMG = F.ID ";
571 $z = $DB->Query($strSql);
572 while ($zr = $z->Fetch())
573 CFile::Delete($zr["ID"]);
574
576
577 unset(static::$arBlogPostCache[$ID]);
578
579 $arBlog = CBlog::GetByID($arPost["BLOG_ID"]);
580
581 $result = $DB->Query("DELETE FROM b_blog_post WHERE ID = ".$ID, true);
582
583 if (intval($arBlog["LAST_POST_ID"]) == $ID)
584 CBlog::SetStat($arPost["BLOG_ID"]);
585
586 if ($result)
587 {
588 $res = CBlogImage::GetList(array(), array("POST_ID"=>$ID, "IS_COMMENT" => "N"));
589 while($aImg = $res->Fetch())
590 CBlogImage::Delete($aImg['ID']);
591 }
592 if ($result)
593 $USER_FIELD_MANAGER->Delete("BLOG_POST", $ID);
594
595 foreach(GetModuleEvents("blog", "OnPostDelete", true) as $arEvent)
596 ExecuteModuleEventEx($arEvent, Array($ID, &$result));
597
598 if (CModule::IncludeModule("search"))
599 {
600 CSearch::Index("blog", "P".$ID,
601 array(
602 "TITLE" => "",
603 "BODY" => "",
604 )
605 );
606 //CSearch::DeleteIndex("blog", false, "COMMENT", $arPost["BLOG_ID"]."|".$ID);
607 }
608 if(defined("BX_COMP_MANAGED_CACHE"))
609 {
610 $CACHE_MANAGER->ClearByTag("blog_post_".$ID);
611 }
612
613 return $result;
614 }
615 else
616 return false;
617 }
618
619 //*************** SELECT *********************/
620 public static function PreparePath($blogUrl, $postID = 0, $siteID = False, $is404 = True, $userID = 0, $groupID = 0)
621 {
622 $blogUrl = Trim($blogUrl);
623 $postID = intval($postID);
624 $groupID = intval($groupID);
625 $userID = intval($userID);
626
627 if (!$siteID)
628 {
630 }
631
632 $dbPath = CBlogSitePath::GetList(array(), array("SITE_ID"=>$siteID));
633 while ($arPath = $dbPath->Fetch())
634 {
635 if ($arPath["TYPE"] <> '')
636 {
637 $arPaths[$arPath["TYPE"]] = $arPath["PATH"];
638 }
639 else
640 {
641 $arPaths["OLD"] = $arPath["PATH"];
642 }
643 }
644
645 if($postID > 0)
646 {
647 if($groupID > 0)
648 {
649 if($arPaths["H"] <> '')
650 {
651 $result = str_replace("#blog#", $blogUrl, $arPaths["H"]);
652 $result = str_replace("#post_id#", $postID, $result);
653 $result = str_replace("#user_id#", $userID, $result);
654 $result = str_replace("#group_id#", $groupID, $result);
655 }
656 elseif($arPaths["G"] <> '')
657 {
658 $result = str_replace("#blog#", $blogUrl, $arPaths["G"]);
659 $result = str_replace("#user_id#", $userID, $result);
660 $result = str_replace("#group_id#", $groupID, $result);
661 }
662 }
663 elseif($arPaths["P"] <> '')
664 {
665 $result = str_replace("#blog#", $blogUrl, $arPaths["P"]);
666 $result = str_replace("#post_id#", $postID, $result);
667 $result = str_replace("#user_id#", $userID, $result);
668 }
669 elseif($arPaths["B"] <> '')
670 {
671 $result = str_replace("#blog#", $blogUrl, $arPaths["B"]);
672 $result = str_replace("#user_id#", $userID, $result);
673 }
674 else
675 {
676 if($is404)
677 $result = htmlspecialcharsbx($arPaths["OLD"])."/".htmlspecialcharsbx($blogUrl)."/".$postID.".php";
678 else
679 $result = htmlspecialcharsbx($arPaths["OLD"])."/post.php?blog=".$blogUrl."&post_id=".$postID;
680 }
681 }
682 else
683 {
684 if($arPaths["B"] <> '')
685 {
686 $result = str_replace("#blog#", $blogUrl, $arPaths["B"]);
687 $result = str_replace("#user_id#", $userID, $result);
688 }
689 else
690 {
691 if($is404)
692 $result = htmlspecialcharsbx($arPaths["OLD"])."/".htmlspecialcharsbx($blogUrl)."/";
693 else
694 $result = htmlspecialcharsbx($arPaths["OLD"])."/post.php?blog=".$blogUrl;
695 }
696 }
697
698 return $result;
699 }
700
701 function PreparePath2Post($realUrl, $url, $arParams = array())
702 {
704 $url,
705 isset($arParams["POST_ID"]) ? $arParams["POST_ID"] : 0,
706 isset($arParams["SITE_ID"]) ? $arParams["SITE_ID"] : False
707 );
708 }
709
710 public static function CounterInc($ID)
711 {
712 global $DB;
713 $ID = intval($ID);
714 if(!is_array($_SESSION["BLOG_COUNTER"]))
715 $_SESSION["BLOG_COUNTER"] = Array();
716 if(in_array($ID, $_SESSION["BLOG_COUNTER"]))
717 return;
718 $_SESSION["BLOG_COUNTER"][] = $ID;
719 $strSql =
720 "UPDATE b_blog_post SET ".
721 " VIEWS = ".$DB->IsNull("VIEWS", 0)." + 1 ".
722 "WHERE ID=".$ID;
723 $DB->Query($strSql);
724 }
725
726 public static function Notify($arPost, $arBlog, $arParams)
727 {
728 global $DB;
729 if(empty($arBlog))
730 {
731 $arBlog = CBlog::GetByID($arPost["BLOG_ID"]);
732 }
733
734 $siteId = (!empty($arParams['SITE_ID']) ? $arParams['SITE_ID'] : SITE_ID);
735
736 $arImages = $arOwner = Array();
737 $parserBlog = false;
738 $text4mail = $serverName = $AuthorName = "";
739
740 if (
741 $arParams["bSoNet"]
742 || (
743 $arBlog["EMAIL_NOTIFY"] == "Y"
744 && $arParams["user_id"] != $arBlog["OWNER_ID"]
745 )
746 )
747 {
748 $BlogUser = CBlogUser::GetByID($arParams["user_id"], BLOG_BY_USER_ID);
749 $BlogUser = CBlogTools::htmlspecialcharsExArray($BlogUser);
750 $res = CUser::GetByID($arBlog["OWNER_ID"]);
751 $arOwner = $res->GetNext();
752 $dbUser = CUser::GetByID($arParams["user_id"]);
753 $arUser = $dbUser->Fetch();
754 $AuthorName = CBlogUser::GetUserNameEx($arUser, $BlogUser, $arParams);
755 $parserBlog = new blogTextParser(false, $arParams["PATH_TO_SMILE"] ?? false);
756 $text4mail = $arPost["DETAIL_TEXT"];
757 if($arPost["DETAIL_TEXT_TYPE"] == "html")
758 {
759 $text4mail = HTMLToTxt($text4mail);
760 }
761
762 $res = CBlogImage::GetList(array("ID"=>"ASC"),array("POST_ID"=>$arPost["ID"], "BLOG_ID"=>$arBlog["ID"], "IS_COMMENT" => "N"));
763 while ($arImage = $res->Fetch())
764 {
765 $arImages[$arImage['ID']] = $arImage['FILE_ID'];
766 }
767
768 $text4mail = $parserBlog->convert4mail($text4mail, $arImages);
769 $serverName = ((defined("SITE_SERVER_NAME") && SITE_SERVER_NAME <> '') ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", ""));
770 }
771
772 if (
773 !$arParams["bSoNet"]
774 && $arBlog["EMAIL_NOTIFY"] == "Y"
775 && $arParams["user_id"] != $arBlog["OWNER_ID"]
776 && intval($arBlog["OWNER_ID"]) > 0
777 ) // Send notification to email
778 {
779 CEvent::Send(
780 "NEW_BLOG_MESSAGE",
781 $siteId,
782 array(
783 "BLOG_ID" => $arBlog["ID"],
784 "BLOG_NAME" => htmlspecialcharsBack($arBlog["NAME"]),
785 "BLOG_URL" => $arBlog["URL"],
786 "MESSAGE_TITLE" => $arPost["TITLE"],
787 "MESSAGE_TEXT" => $text4mail,
788 "MESSAGE_DATE" => GetTime(MakeTimeStamp($arPost["DATE_PUBLISH"])-CTimeZone::GetOffset(), "FULL"),
789 "MESSAGE_PATH" => "http://".$serverName.CComponentEngine::MakePathFromTemplate(htmlspecialcharsBack($arParams["PATH_TO_POST"]), array("blog" => $arBlog["URL"], "post_id" => $arPost["ID"], "user_id" => $arBlog["OWNER_ID"], "group_id" => $arParams["SOCNET_GROUP_ID"])),
790 "AUTHOR" => $AuthorName,
791 "EMAIL_FROM" => COption::GetOptionString("main","email_from", "nobody@nobody.com"),
792 "EMAIL_TO" => $arOwner["EMAIL"],
793 )
794 );
795 }
796
797 if(
798 $arParams["bSoNet"]
799 && $arPost["ID"]
800 && CModule::IncludeModule("socialnetwork")
801 && $parserBlog
802 )
803 {
804 if($arPost["DETAIL_TEXT_TYPE"] == "html" && $arParams["allowHTML"] == "Y" && $arBlog["ALLOW_HTML"] == "Y")
805 {
806 $arAllow = array("HTML" => "Y", "ANCHOR" => "Y", "IMG" => "Y", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "Y", "QUOTE" => "Y", "CODE" => "Y");
807 if($arParams["allowVideo"] != "Y")
808 {
809 $arAllow["VIDEO"] = "N";
810 }
811 $text4message = $parserBlog->convert($arPost["DETAIL_TEXT"], false, $arImages, $arAllow);
812 }
813 else
814 {
815 $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "TABLE" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "N");
816 $text4message = $parserBlog->convert($arPost["DETAIL_TEXT"], false, $arImages, $arAllow, array("isSonetLog"=>true));
817 }
818
819 $arSoFields = Array(
820 "EVENT_ID" => (
821 isset($arPost["UF_BLOG_POST_IMPRTNT"])
822 && intval($arPost["UF_BLOG_POST_IMPRTNT"]) > 0
823 ? Integration\Socialnetwork\Log::EVENT_ID_POST_IMPORTANT
824 : Integration\Socialnetwork\Log::EVENT_ID_POST
825 ),
826 "=LOG_DATE" => (
827 ($arPost["DATE_PUBLISH"] ?? '') <> ''
828 ? (
829 MakeTimeStamp($arPost["DATE_PUBLISH"], CSite::GetDateFormat("FULL", SITE_ID)) > time()+CTimeZone::GetOffset()
830 ? $DB->CharToDateFunction($arPost["DATE_PUBLISH"], "FULL", SITE_ID)
831 : $DB->CurrentTimeFunction()
832 )
833 :
834 $DB->CurrentTimeFunction()
835 ),
836 "TITLE_TEMPLATE" => "#USER_NAME# ".GetMessage("BLG_SONET_TITLE"),
837 "TITLE" => $arPost["TITLE"],
838 "MESSAGE" => $text4message,
839 "TEXT_MESSAGE" => $text4mail,
840 "MODULE_ID" => "blog",
841 "CALLBACK_FUNC" => false,
842 "SOURCE_ID" => $arPost["ID"],
843 "ENABLE_COMMENTS" => (array_key_exists("ENABLE_COMMENTS", $arPost) && $arPost["ENABLE_COMMENTS"] == "N" ? "N" : "Y"),
844 );
845
846 $arSoFields["RATING_TYPE_ID"] = "BLOG_POST";
847 $arSoFields["RATING_ENTITY_ID"] = intval($arPost["ID"]);
848
849 if ($arParams["bGroupMode"] ?? false)
850 {
851 $arSoFields["ENTITY_TYPE"] = SONET_ENTITY_GROUP;
852 $arSoFields["ENTITY_ID"] = $arParams["SOCNET_GROUP_ID"];
853 $arSoFields["URL"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_POST"], array("blog" => $arBlog["URL"], "user_id" => $arBlog["OWNER_ID"], "group_id" => $arParams["SOCNET_GROUP_ID"], "post_id" => $arPost["ID"]));
854 }
855 else
856 {
857 $arSoFields["ENTITY_TYPE"] = SONET_ENTITY_USER;
858 $arSoFields["ENTITY_ID"] = $arBlog["OWNER_ID"];
859 $arSoFields["URL"] = CComponentEngine::MakePathFromTemplate(
860 $arParams["PATH_TO_POST"],
861 [
862 "blog" => $arBlog["URL"],
863 "user_id" => $arBlog["OWNER_ID"],
864 "group_id" => $arParams["SOCNET_GROUP_ID"] ?? null,
865 "post_id" => $arPost["ID"],
866 ]
867 );
868 }
869
870 if (intval($arParams["user_id"]) > 0)
871 {
872 $arSoFields["USER_ID"] = $arParams["user_id"];
873 }
874
875 $post = \Bitrix\Blog\Item\Post::getById($arPost["ID"]);
876 $arSoFields["TAG"] = $post->getTags();
877
878 $logID = CSocNetLog::Add($arSoFields, false);
879
880 if (intval($logID) > 0)
881 {
883 'postId' => $arPost["ID"],
884 'authorId' => $arPost["AUTHOR_ID"],
885 ));
886
887 $postFields = $post->getFields();
888 $inlineAttachedObjectsIdList = array();
889
890 if (preg_match_all('/\[DISK\s+FILE\s+ID\s*=\s*([n]*\d+)\s*\]/isu', $postFields['DETAIL_TEXT'], $matches))
891 {
892 if (!empty($matches[1]))
893 {
894 $inlineFileList = $matches[1];
895
896 foreach($inlineFileList as $key => $value)
897 {
898 if (
899 preg_match('/^n(\d+)/isu', $value, $matches)
900 && !empty($matches[1])
901 && intval($matches[1]) > 0
902 )
903 {
904 $res = \Bitrix\Disk\AttachedObject::getList(array(
905 'filter' => array(
906 '=ENTITY_TYPE' => \Bitrix\Disk\Uf\BlogPostConnector::className(),
907 'ENTITY_ID' => $postFields['ID'],
908 'OBJECT_ID' => (int)$matches[1],
909 ),
910 'select' => array('ID'),
911 ));
912 foreach ($res as $attachedObjectFields)
913 {
914 $inlineAttachedObjectsIdList[] = $attachedObjectFields['ID'];
915 }
916 }
917 }
918 }
919 }
920
921 CSocNetLog::Update($logID, array("TMP_ID" => $logID));
922
923 $hasVideoTransforming = (
924 !empty($inlineAttachedObjectsIdList)
926 'attachedIdList' => $inlineAttachedObjectsIdList,
927 ))
928 );
929
930 if ($hasVideoTransforming)
931 {
932 $socnetPerms = array("SA", "U".$arPost["AUTHOR_ID"]);
933 }
934
935 CSocNetLogRights::deleteByLogID($logID);
936 CSocNetLogRights::add($logID, $socnetPerms);
937
938 $updateFields = array(
939 "TRANSFORM" => ($hasVideoTransforming ? 'Y' : 'N'),
940 );
941
942 if (Loader::includeModule("extranet"))
943 {
944 $updateFields["SITE_ID"] = CExtranet::getSitesByLogDestinations($socnetPerms, $arPost["AUTHOR_ID"], $siteId);
945 }
946
947 CSocNetLog::update($logID, $updateFields);
948
949 if (Loader::includeModule('crm'))
950 {
951 CCrmLiveFeedComponent::processCrmBlogPostRights($logID, $arSoFields, $arPost, 'new');
952 }
953
955 'socnetPerms' => $socnetPerms,
956 'logId' => $logID,
957 'logEventId' => $arSoFields["EVENT_ID"],
958 'sendToAuthor' => (
959 !empty($arParams["SEND_COUNTER_TO_AUTHOR"])
960 && $arParams["SEND_COUNTER_TO_AUTHOR"] == "Y"
961 ),
962 ));
963
964 if ($hasVideoTransforming)
965 {
966 CUserOptions::setOption("socialnetwork", "~log_videotransform_popup_show", "Y");
967 CUserOptions::setOption("socialnetwork", "~log_videotransform_post_url", $arSoFields["URL"]);
968 CUserOptions::setOption("socialnetwork", "~log_videotransform_post_id", $arPost["ID"]);
969 }
970
971 return $logID;
972 }
973 }
974
975 return false;
976 }
977
978 public static function UpdateLog($postID, $arPost, $arBlog, $arParams)
979 {
980 static $blogPostEventIdList = null;
981
982 if (!CModule::IncludeModule('socialnetwork'))
983 {
984 return;
985 }
986
987 $parserBlog = new blogTextParser(false, $arParams["PATH_TO_SMILE"]);
988
989 preg_match("#^(.*?)<cut[\s]*(/>|>).*?$#is", $arPost["DETAIL_TEXT"], $arMatches);
990 if (count($arMatches) <= 0)
991 {
992 preg_match("#^(.*?)\[cut[\s]*(/\]|\]).*?$#is", $arPost["DETAIL_TEXT"], $arMatches);
993 }
994
995 $cut_suffix = (count($arMatches) > 0 ? "#CUT#" : "");
996
997 $arImages = Array();
998 $res = CBlogImage::GetList(array("ID"=>"ASC"),array("POST_ID"=>$postID, "BLOG_ID"=>$arBlog["ID"], "IS_COMMENT" => "N"));
999 while ($arImage = $res->Fetch())
1000 {
1001 $arImages[$arImage['ID']] = $arImage['FILE_ID'];
1002 }
1003
1004 if (
1005 ($arPost["DETAIL_TEXT_TYPE"] ?? null) === "html"
1006 && $arParams["allowHTML"] === "Y"
1007 && $arBlog["ALLOW_HTML"] === "Y"
1008 )
1009 {
1010 $arAllow = array("HTML" => "Y", "ANCHOR" => "Y", "IMG" => "Y", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "Y", "QUOTE" => "Y", "CODE" => "Y");
1011 if($arParams["allowVideo"] != "Y")
1012 {
1013 $arAllow["VIDEO"] = "N";
1014 }
1015 $text4message = $parserBlog->convert($arPost["DETAIL_TEXT"], true, $arImages, $arAllow);
1016 }
1017 else
1018 {
1019 $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "TABLE" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "N");
1020 $text4message = $parserBlog->convert($arPost["DETAIL_TEXT"], true, $arImages, $arAllow, array("isSonetLog"=>true));
1021 }
1022
1023 $text4message .= $cut_suffix;
1024
1026 if (
1027 isset($arPost['UF_BLOG_POST_IMPRTNT'])
1028 && (int)$arPost['UF_BLOG_POST_IMPRTNT'] > 0
1029 )
1030 {
1032 }
1033 elseif (
1034 isset($arPost['UF_GRATITUDE'])
1035 && (int)$arPost['UF_GRATITUDE'] > 0
1036 )
1037 {
1039 }
1040 elseif (
1041 isset($arPost['UF_BLOG_POST_VOTE'])
1042 && (int)$arPost['UF_BLOG_POST_VOTE'] > 0
1043 )
1044 {
1046 }
1047
1048 $arSoFields = array(
1049 "TITLE_TEMPLATE" => "#USER_NAME# ".GetMessage("BLG_SONET_TITLE"),
1050 "TITLE" => $arPost["TITLE"],
1051 "MESSAGE" => $text4message,
1052 "TEXT_MESSAGE" => $text4message,
1053 "ENABLE_COMMENTS" => (
1054 array_key_exists("ENABLE_COMMENTS", $arPost)
1055 && $arPost["ENABLE_COMMENTS"] === "N"
1056 ? "N"
1057 : "Y"
1058 ),
1059 "EVENT_ID" => $eventId,
1060 );
1061
1062 if ($blogPostEventIdList === null)
1063 {
1064 $blogPostLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\BlogPost;
1065 $blogPostEventIdList = $blogPostLivefeedProvider->getEventId();
1066 }
1067
1069 array("ID" => "DESC"),
1070 array(
1071 "EVENT_ID" => $blogPostEventIdList,
1072 "SOURCE_ID" => $postID,
1073 ),
1074 false,
1075 false,
1076 array("ID", "ENTITY_TYPE", "ENTITY_ID", "EVENT_ID", "USER_ID")
1077 );
1078 if ($arLog = $dbRes->Fetch())
1079 {
1080 CSocNetLog::Update($arLog["ID"], $arSoFields);
1081 $socnetPerms = CBlogPost::GetSocNetPermsCode($postID);
1082
1083 $profileBlogPost = false;
1084 foreach($socnetPerms as $perm)
1085 {
1086 if (preg_match('/^UP(\d+)$/', $perm, $matches))
1087 {
1088 $profileBlogPost = true;
1089 break;
1090 }
1091 }
1092
1093 if(
1094 !$profileBlogPost
1095 && !in_array("U".$arPost["AUTHOR_ID"], $socnetPerms)
1096 )
1097 {
1098 $socnetPerms[] = "U".$arPost["AUTHOR_ID"];
1099 if (CModule::IncludeModule("extranet"))
1100 {
1101 CSocNetLog::Update($arLog["ID"], array(
1102 "SITE_ID" => CExtranet::GetSitesByLogDestinations($socnetPerms, $arPost["AUTHOR_ID"], ($arParams['SITE_ID'] ?? false)),
1103 ));
1104 }
1105 $socnetPerms[] = "SA"; // socnet admin
1106 }
1107
1108 \CSocNetLogRights::deleteByLogID($arLog["ID"]);
1109 \CSocNetLogRights::add($arLog["ID"], $socnetPerms);
1110
1111 if (Loader::includeModule('crm'))
1112 {
1113 CCrmLiveFeedComponent::processCrmBlogPostRights($arLog["ID"], $arLog, $arPost, 'edit');
1114 }
1115 }
1116 }
1117
1118 public static function DeleteLog($postID, $bMicroblog = false)
1119 {
1120 global $USER_FIELD_MANAGER;
1121
1122 static $blogPostEventIdList = null;
1123
1124 if (!CModule::IncludeModule('socialnetwork'))
1125 {
1126 return;
1127 }
1128
1129 $dbComment = CBlogComment::GetList(
1130 array(),
1131 array(
1132 "POST_ID" => $postID,
1133 ),
1134 false,
1135 false,
1136 array("ID")
1137 );
1138
1139 while ($arComment = $dbComment->Fetch())
1140 {
1142 array("ID" => "DESC"),
1143 array(
1144 "EVENT_ID" => Array("blog_comment", "blog_comment_micro"),
1145 "SOURCE_ID" => $arComment["ID"],
1146 ),
1147 false,
1148 false,
1149 array("ID")
1150 );
1151 while ($arRes = $dbRes->Fetch())
1153 }
1154
1155 if ($blogPostEventIdList === null)
1156 {
1157 $blogPostLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\BlogPost;
1158 $blogPostEventIdList = $blogPostLivefeedProvider->getEventId();
1159 }
1160
1162 array("ID" => "DESC"),
1163 array(
1164 "EVENT_ID" => $blogPostEventIdList,
1165 "SOURCE_ID" => $postID,
1166 ),
1167 false,
1168 false,
1169 array("ID")
1170 );
1171 while ($arRes = $dbRes->Fetch())
1172 {
1174 }
1175
1176 $arPostFields = $USER_FIELD_MANAGER->getUserFields('BLOG_POST', $postID, LANGUAGE_ID);
1177 if (
1178 !empty($arPostFields['UF_GRATITUDE'])
1179 && !empty($arPostFields['UF_GRATITUDE']['VALUE'])
1180 && intval($arPostFields['UF_GRATITUDE']['VALUE']) > 0
1181 && Loader::includeModule('iblock')
1182 )
1183 {
1184 \CIBlockElement::delete(intval($arPostFields['UF_GRATITUDE']['VALUE']));
1185 }
1186 }
1187
1188 public static function GetID($code, $blogID)
1189 {
1190 $postID = false;
1191 $blogID = intval($blogID);
1192
1193 $code = preg_replace("/[^a-zA-Z0-9_-]/is", "", Trim($code));
1194 if($code == '' || intval($blogID) <= 0)
1195 return false;
1196
1197 if (
1198 !empty(static::$arBlogPostIdCache[$blogID."_".$code])
1199 && intval(static::$arBlogPostIdCache[$blogID."_".$code]) > 0)
1200 {
1201 return static::$arBlogPostIdCache[$blogID."_".$code];
1202 }
1203 else
1204 {
1205 $arFilter = Array("CODE" => $code);
1206 if(intval($blogID) > 0)
1207 $arFilter["BLOG_ID"] = $blogID;
1208 $dbPost = CBlogPost::GetList(Array(), $arFilter, false, Array("nTopCount" => 1), Array("ID"));
1209 if($arPost = $dbPost->Fetch())
1210 {
1211 static::$arBlogPostIdCache[$blogID."_".$code] = $arPost["ID"];
1212 $postID = $arPost["ID"];
1213 }
1214 }
1215
1216 return $postID;
1217 }
1218
1219 public static function GetPostID($postID, $code, $allowCode = false)
1220 {
1221 $postID = intval($postID);
1222 $code = preg_replace("/[^a-zA-Z0-9_-]/is", "", trim($code ?? ''));
1223 if($code == '' && intval($postID) <= 0)
1224 return false;
1225
1226 if($allowCode && $code <> '')
1227 return $code;
1228
1229 return $postID;
1230 }
1231
1232 public static function AddSocNetPerms($ID, $perms = array(), $arPost = array())
1233 {
1234 global $CACHE_MANAGER;
1235
1236 if(intval($ID) <= 0)
1237 return false;
1238
1239 $arResult = Array();
1240
1241 // D - department
1242 // U - user
1243 // SG - socnet group
1244 // DR - department and hier
1245 // G - user group
1246 // AU - authorized user
1247 // CRMCONTACT - CRM contact
1248 //$bAU = false;
1249
1250 if(
1251 empty($perms)
1252 || in_array('UA', $perms, true)
1253 || in_array('G2', $perms, true)
1254 ) //if default rights or for everyone
1255 {
1256 CBlogPost::__AddSocNetPerms($ID, "U", $arPost["AUTHOR_ID"], "US".$arPost["AUTHOR_ID"]); // for myself
1257 $perms1 = CBlogPost::GetSocnetGroups("U", $arPost["AUTHOR_ID"]);
1258 foreach($perms1 as $val)
1259 {
1260 if($val <> '')
1261 {
1262 CBlogPost::__AddSocNetPerms($ID, "U", $arPost["AUTHOR_ID"], $val);
1263
1264 if(!in_array($val, $arResult))
1265 {
1266 $arResult[] = $val;
1267 }
1268 }
1269 }
1270 }
1271 if(!empty($perms))
1272 {
1273 $perms = array_unique($perms);
1274
1275 foreach($perms as $val)
1276 {
1277 if($val == "UA")
1278 {
1279 continue;
1280 }
1281
1282 if($val <> '')
1283 {
1284 if (
1285 preg_match('/^(CRMCONTACT)(\d+)$/i', $val, $matches)
1286 || preg_match('/^(DR)(\d+)$/i', $val, $matches)
1287 || preg_match('/^(SG)(\d+)$/i', $val, $matches)
1288 || preg_match('/^(AU)(\d+)$/i', $val, $matches)
1289 || preg_match('/^(U)(\d+)$/i', $val, $matches)
1290 || preg_match('/^(UP)(\d+)$/i', $val, $matches)
1291 || preg_match('/^(D)(\d+)$/i', $val, $matches)
1292 || preg_match('/^(G)(\d+)$/i', $val, $matches)
1293 )
1294 {
1295 $scT = $matches[1];
1296 $scID = $matches[2];
1297 }
1298 else
1299 {
1300 continue;
1301 }
1302
1303 if($scT == "SG")
1304 {
1305 $permsNew = CBlogPost::GetSocnetGroups("G", $scID);
1306 foreach($permsNew as $val1)
1307 {
1308 CBlogPost::__AddSocNetPerms($ID, $scT, $scID, $val1);
1309 if(!in_array($val1, $arResult))
1310 {
1311 $arResult[] = $val1;
1312 }
1313 }
1314 }
1315
1316 CBlogPost::__AddSocNetPerms($ID, $scT, $scID, $val);
1317 if(!in_array($val, $arResult))
1318 {
1319 $arResult[] = $val;
1320 }
1321 }
1322 }
1323 }
1324
1325 BXClearCache(true, "/blog/getsocnetperms/".$ID);
1326 if(defined("BX_COMP_MANAGED_CACHE"))
1327 {
1328 $CACHE_MANAGER->ClearByTag("blog_post_getsocnetperms_".$ID);
1329 }
1330
1331 return $arResult;
1332 }
1333
1334 public static function UpdateSocNetPerms($ID, $perms = array(), $arPost = array())
1335 {
1336 global $DB;
1337 $ID = intval($ID);
1338 if($ID <= 0)
1339 {
1340 return false;
1341 }
1342
1343 $strSql = "DELETE FROM b_blog_socnet_rights WHERE POST_ID=".$ID;
1344 $DB->Query($strSql);
1345
1346 return CBlogPost::AddSocNetPerms($ID, $perms, $arPost);
1347 }
1348
1349 public static function __AddSocNetPerms($ID, $entityType = "", $entityID = 0, $entity = null)
1350 {
1351 global $DB;
1352
1353 static $allowedTypes = false;
1354
1355 if ($allowedTypes === false)
1356 {
1357 $allowedTypes = Array("D", "U", "UP", "SG", "DR", "G", "AU");
1358 if (IsModuleInstalled('crm'))
1359 {
1360 $allowedTypes[] = "CRMCONTACT";
1361 }
1362 }
1363
1364 if(intval($ID) > 0 && $entityType <> '' && $entity <> '' && in_array($entityType, $allowedTypes))
1365 {
1366 $arSCFields = Array("POST_ID" => $ID, "ENTITY_TYPE" => $entityType, "ENTITY_ID" => intval($entityID), "ENTITY" => $entity);
1367 $arSCInsert = $DB->PrepareInsert("b_blog_socnet_rights", $arSCFields);
1368
1369 if ($arSCInsert[0] <> '')
1370 {
1371 $strSql =
1372 "INSERT INTO b_blog_socnet_rights(".$arSCInsert[0].") ".
1373 "VALUES(".$arSCInsert[1].")";
1374 $DB->Query($strSql);
1375 return true;
1376 }
1377 }
1378 return false;
1379 }
1380
1381 public static function GetSocNetGroups($entity_type, $entity_id, $operation = "view_post")
1382 {
1383 $entity_id = intval($entity_id);
1384 if($entity_id <= 0)
1385 return false;
1386 if(!CModule::IncludeModule("socialnetwork"))
1387 return false;
1388 $feature = "blog";
1389
1390 $arResult = array();
1391
1392 if($entity_type == "G")
1393 {
1394 $prefix = "SG".$entity_id."_";
1395 $letter = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_GROUP, $entity_id, $feature, $operation);
1396 $arResult = array_merge($arResult, self::getFullGroupRoleSet($letter, $prefix));
1397 }
1398 else
1399 {
1400 $prefix = "SU".$entity_id."_";
1401 $letter = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_USER, $entity_id, $feature, $operation);
1402 switch($letter)
1403 {
1404 case "A"://All
1405 $arResult[] = 'G2';
1406 break;
1407 case "C"://Authorized
1408 $arResult[] = 'AU';
1409 break;
1410 case "E"://Friends of friends (has no rights yet) so it counts as
1411 case "M"://Friends
1412 $arResult[] = $prefix.'M';
1413 break;
1414 case "Z"://Personal
1415 $arResult[] = $prefix.'Z';
1416 break;
1417 }
1418 }
1419
1420 return $arResult;
1421 }
1422
1423 public static function getFullGroupRoleSet($role = "", $prefix = "")
1424 {
1425 $result = array();
1426
1427 switch($role)
1428 {
1429 case SONET_ROLES_ALL:
1430 $result[] = 'O'.$prefix.SONET_ROLES_ALL;
1431 $result[] = 'O'.$prefix.SONET_ROLES_AUTHORIZED;
1432 $result[] = $prefix.SONET_ROLES_USER;
1433 $result[] = $prefix.SONET_ROLES_MODERATOR;
1434 $result[] = $prefix.SONET_ROLES_OWNER;
1435 break;
1437 $result[] = 'O'.$prefix.SONET_ROLES_AUTHORIZED;
1438 $result[] = $prefix.SONET_ROLES_USER;
1439 $result[] = $prefix.SONET_ROLES_MODERATOR;
1440 $result[] = $prefix.SONET_ROLES_OWNER;
1441 break;
1442 case SONET_ROLES_USER:
1443 $result[] = 'O'.$prefix.SONET_ROLES_AUTHORIZED;
1444 $result[] = $prefix.SONET_ROLES_USER;
1445 $result[] = $prefix.SONET_ROLES_MODERATOR;
1446 $result[] = $prefix.SONET_ROLES_OWNER;
1447 break;
1449 $result[] = $prefix.SONET_ROLES_MODERATOR;
1450 $result[] = $prefix.SONET_ROLES_OWNER;
1451 break;
1452 case SONET_ROLES_OWNER:
1453 $result[] = $prefix.SONET_ROLES_OWNER;
1454 break;
1455 }
1456
1457 return $result;
1458 }
1459
1460 public static function getSocNetPerms($ID, $useCache = true)
1461 {
1462 global $DB, $CACHE_MANAGER;
1463 $ID = intval($ID);
1464 if($ID <= 0)
1465 return false;
1466
1467 $arResult = array();
1468
1469 $cacheTtl = defined("BX_COMP_MANAGED_CACHE") ? 3153600 : 3600*4;
1470 $cacheId = 'blog_post_getsocnetperms_'.$ID;
1471 $cacheDir = '/blog/getsocnetperms/'.$ID;
1472
1473 $obCache = new CPHPCache;
1474 if(
1475 $obCache->InitCache($cacheTtl, $cacheId, $cacheDir)
1476 && $useCache
1477 )
1478 {
1479 $arResult = $obCache->GetVars();
1480 }
1481 else
1482 {
1483 $obCache->StartDataCache();
1484
1485 $strSql = "SELECT SR.ENTITY_ID, SR.ENTITY_TYPE, SR.ENTITY FROM b_blog_socnet_rights SR
1486 INNER JOIN b_blog_post P ON (P.ID = SR.POST_ID)
1487 WHERE SR.POST_ID=".$ID." ORDER BY SR.ENTITY ASC";
1488 $dbRes = $DB->Query($strSql);
1489 while($arRes = $dbRes->Fetch())
1490 {
1491 $arResult[$arRes["ENTITY_TYPE"]][$arRes["ENTITY_ID"]][] = $arRes["ENTITY"];
1492 }
1493
1494 if(defined("BX_COMP_MANAGED_CACHE"))
1495 {
1496 $CACHE_MANAGER->StartTagCache($cacheDir);
1497 $CACHE_MANAGER->RegisterTag("blog_post_getsocnetperms_".$ID);
1498 $CACHE_MANAGER->EndTagCache();
1499 }
1500 $obCache->EndDataCache($arResult);
1501 }
1502
1503 return $arResult;
1504 }
1505
1506 public static function GetSocNetPermsName($ID)
1507 {
1508 global $DB;
1509 $ID = intval($ID);
1510 if($ID <= 0)
1511 return false;
1512
1513 $arResult = Array();
1514 $strSql = "SELECT SR.ENTITY_TYPE, SR.ENTITY_ID, SR.ENTITY,
1515 U.NAME as U_NAME, U.LAST_NAME as U_LAST_NAME, U.SECOND_NAME as U_SECOND_NAME, U.LOGIN as U_LOGIN, U.PERSONAL_PHOTO as U_PERSONAL_PHOTO, U.EXTERNAL_AUTH_ID as U_EXTERNAL_AUTH_ID,
1516 EL.NAME as EL_NAME
1517 FROM b_blog_socnet_rights SR
1518 INNER JOIN b_blog_post P
1519 ON (P.ID = SR.POST_ID)
1520 LEFT JOIN b_user U
1521 ON (U.ID = SR.ENTITY_ID AND SR.ENTITY_TYPE = 'U')
1522 LEFT JOIN b_iblock_section EL
1523 ON (EL.ID = SR.ENTITY_ID AND SR.ENTITY_TYPE = 'DR' AND EL.ACTIVE = 'Y')
1524 WHERE
1525 SR.POST_ID = " . $ID . "
1526 ORDER BY SR.ID ASC
1527 LIMIT 300
1528 ";
1529
1530 $dbRes = $DB->Query($strSql);
1531 while($arRes = $dbRes->GetNext())
1532 {
1533 if (
1534 !isset($arResult[$arRes["ENTITY_TYPE"]][$arRes["ENTITY_ID"]])
1535 || !is_array($arResult[$arRes["ENTITY_TYPE"]][$arRes["ENTITY_ID"]]))
1536 {
1537 $arResult[$arRes["ENTITY_TYPE"]][$arRes["ENTITY_ID"]] = $arRes;
1538 }
1539 if (
1540 !isset($arResult[$arRes["ENTITY_TYPE"]][$arRes["ENTITY_ID"]]["ENTITY"])
1541 || !is_array($arResult[$arRes["ENTITY_TYPE"]][$arRes["ENTITY_ID"]]["ENTITY"])
1542 )
1543 {
1544 $arResult[$arRes["ENTITY_TYPE"]][$arRes["ENTITY_ID"]]["ENTITY"] = [];
1545 }
1546 $arResult[$arRes["ENTITY_TYPE"]][$arRes["ENTITY_ID"]]["ENTITY"][] = $arRes["ENTITY"];
1547 }
1548 return $arResult;
1549 }
1550
1551 public static function GetSocNetPermsCode($ID)
1552 {
1553 global $DB;
1554 $ID = intval($ID);
1555 if($ID <= 0)
1556 return false;
1557
1558 $arResult = Array();
1559 $strSql = "SELECT SR.ENTITY FROM b_blog_socnet_rights SR
1560 INNER JOIN b_blog_post P ON (P.ID = SR.POST_ID)
1561 WHERE SR.POST_ID=".$ID."
1562 ORDER BY SR.ENTITY ASC";
1563 $dbRes = $DB->Query($strSql);
1564 while($arRes = $dbRes->Fetch())
1565 {
1566 if(!in_array($arRes["ENTITY"], $arResult))
1567 $arResult[] = $arRes["ENTITY"];
1568 }
1569 return $arResult;
1570 }
1571
1572 public static function ChangeSocNetPermission($entity_type, $entity_id, $operation)
1573 {
1574 global $DB;
1575 $entity_id = intval($entity_id);
1576 $perms = CBlogPost::GetSocnetGroups($entity_type, $entity_id, $operation);
1577 $type = "U";
1578 $type2 = "US";
1579 if($entity_type == "G")
1580 $type = $type2 = "SG";
1581 $DB->Query("DELETE FROM b_blog_socnet_rights
1582 WHERE
1583 ENTITY_TYPE = '".$type."'
1584 AND ENTITY_ID = ".$entity_id."
1585 AND ENTITY <> '".$type2.$entity_id."'
1586 AND ENTITY <> '".$type.$entity_id."'
1587 ");
1588 foreach($perms as $val)
1589 {
1590 $DB->Query("INSERT INTO b_blog_socnet_rights (POST_ID, ENTITY_TYPE, ENTITY_ID, ENTITY)
1591 SELECT SR.POST_ID, SR.ENTITY_TYPE, SR.ENTITY_ID, '".$DB->ForSql($val)."' FROM b_blog_socnet_rights SR
1592 WHERE SR.ENTITY = '".$type2.$entity_id."'");
1593 }
1594 }
1595
1596 public static function GetSocNetPostsPerms($entity_type, $entity_id)
1597 {
1598 global $DB;
1599 $entity_id = intval($entity_id);
1600 if($entity_id <= 0)
1601 return false;
1602
1603 $type = "U";
1604 $type2 = "US";
1605 if($entity_type == "G")
1606 $type = $type2 = "SG";
1607
1608 $arResult = Array();
1609 $dbRes = $DB->Query("
1610 SELECT SR.POST_ID, SR.ENTITY, SR.ENTITY_ID, SR.ENTITY_TYPE FROM b_blog_socnet_rights SR
1611 WHERE
1612 SR.POST_ID IN (SELECT POST_ID FROM b_blog_socnet_rights WHERE ENTITY_TYPE='".$type."' AND ENTITY_ID=".$entity_id." AND ENTITY = '".$type.$entity_id."')
1613 AND SR.ENTITY <> '".$type2.$entity_id."'
1614 ");
1615 while($arRes = $dbRes->Fetch())
1616 {
1617 $arResult[$arRes["POST_ID"]]["PERMS"][] = $arRes["ENTITY"];
1618 $arResult[$arRes["POST_ID"]]["PERMS_FULL"][$arRes["ENTITY_TYPE"].$arRes["ENTITY_ID"]] = Array("TYPE" => $arRes["ENTITY_TYPE"], "ID" => $arRes["ENTITY_ID"]);
1619 }
1620 return $arResult;
1621 }
1622
1623 public static function GetSocNetPostPerms(
1624 $postId = 0,
1625 $bNeedFull = false,
1626 $userId = false,
1627 $postAuthor = 0
1628 )
1629 {
1630 global $USER;
1631
1632 $cId = md5(serialize(func_get_args()));
1633
1634 if (
1635 is_array($postId)
1636 && isset($postId["POST_ID"])
1637 )
1638 {
1639 $arParams = $postId;
1640 $postId = intval($arParams["POST_ID"]);
1641 $bNeedFull = (isset($arParams["NEED_FULL"]) ? $arParams["NEED_FULL"] : false);
1642 $userId = (isset($arParams["USER_ID"]) ? $arParams["USER_ID"] : false);
1643 $postAuthor = (isset($arParams["POST_AUTHOR_ID"]) ? $arParams["POST_AUTHOR_ID"] : 0);
1644 $bPublic = (isset($arParams["PUBLIC"]) ? $arParams["PUBLIC"] : false);
1645 $logId = (isset($arParams["LOG_ID"]) ? intval($arParams["LOG_ID"]) : false);
1646 $bIgnoreAdmin = (isset($arParams["IGNORE_ADMIN"]) ? $arParams["IGNORE_ADMIN"] : false);
1647 }
1648 else
1649 {
1650 $bPublic = $logId = $bIgnoreAdmin = false;
1651 }
1652
1653 if(!$userId)
1654 {
1655 $userId = intval($USER->GetID());
1656 $bByUserId = false;
1657 }
1658 else
1659 {
1660 $userId = intval($userId);
1661 $bByUserId = true;
1662 }
1663 $postId = intval($postId);
1664 if($postId <= 0)
1665 {
1666 return false;
1667 }
1668
1669 if (!empty(static::$arSocNetPostPermsCache[$cId]))
1670 {
1671 return static::$arSocNetPostPermsCache[$cId];
1672 }
1673
1674 if (!CModule::IncludeModule("socialnetwork"))
1675 {
1676 return false;
1677 }
1678
1679 $perms = BLOG_PERMS_DENY;
1680 $arAvailPerms = array_keys($GLOBALS["AR_BLOG_PERMS"]);
1681
1682 if(!$bByUserId)
1683 {
1684 if (CSocNetUser::IsCurrentUserModuleAdmin())
1685 {
1686 $perms = $arAvailPerms[count($arAvailPerms) - 1]; // max
1687 }
1688 }
1689 elseif(
1690 !$bIgnoreAdmin
1691 && CSocNetUser::IsUserModuleAdmin($userId)
1692 )
1693 {
1694 $perms = $arAvailPerms[count($arAvailPerms) - 1]; // max
1695 }
1696
1697 if(intval($postAuthor) <= 0)
1698 {
1699 $dbPost = CBlogPost::GetList(
1700 [],
1701 ["ID" => $postId],
1702 false,
1703 false,
1704 [
1705 "ID",
1706 "AUTHOR_ID",
1707 ]
1708 );
1709 $arPost = $dbPost->Fetch();
1710 }
1711 else
1712 {
1713 $arPost["AUTHOR_ID"] = $postAuthor;
1714 }
1715
1716 if (($arPost["AUTHOR_ID"] ?? null) == $userId)
1717 {
1718 $perms = BLOG_PERMS_FULL;
1719 }
1720
1721 if($perms <= BLOG_PERMS_DENY)
1722 {
1723 $arPerms = CBlogPost::GetSocNetPerms($postId);
1724
1725 if (
1726 intval($userId) > 0
1727 && IsModuleInstalled('mail')
1728 ) // check for email authorization users
1729 {
1730 $rsUsers = CUser::GetList(
1731 "ID",
1732 "asc",
1733 array(
1734 "ID" => $userId,
1735 ),
1736 array(
1737 "FIELDS" => array("ID", "EXTERNAL_AUTH_ID"),
1738 "SELECT" => array("UF_DEPARTMENT"),
1739 )
1740 );
1741
1742 if($arUser = $rsUsers->Fetch())
1743 {
1744 if ($arUser["EXTERNAL_AUTH_ID"] == 'email')
1745 {
1746 return (
1747 isset($arPerms["U"])
1748 && isset($arPerms["U"][$userId])
1751 );
1752 }
1753 elseif (
1754 $bPublic
1755 && (
1756 !is_array($arUser["UF_DEPARTMENT"])
1757 || empty($arUser["UF_DEPARTMENT"])
1758 || intval($arUser["UF_DEPARTMENT"][0]) <= 0
1759 )
1760 && CModule::IncludeModule('extranet')
1761 && ($extranet_site_id = CExtranet::GetExtranetSiteID()) // for extranet users in public section
1762 )
1763 {
1764 if ($logId)
1765 {
1766 $arPostSite = array();
1767 $rsLogSite = CSocNetLog::GetSite($logId);
1768 while ($arLogSite = $rsLogSite->Fetch())
1769 {
1770 $arPostSite[] = $arLogSite["LID"];
1771 }
1772
1773 if (!in_array($extranet_site_id, $arPostSite))
1774 {
1775 return BLOG_PERMS_DENY;
1776 }
1777 }
1778 else
1779 {
1780 return BLOG_PERMS_DENY;
1781 }
1782 }
1783 }
1784 else
1785 {
1786 return BLOG_PERMS_DENY;
1787 }
1788 }
1789
1790 $arEntities = Array();
1791 if (!empty(static::$arUACCache[$userId]))
1792 {
1793 $arEntities = static::$arUACCache[$userId];
1794 }
1795 else
1796 {
1797 $arCodes = CAccess::GetUserCodesArray($userId);
1798 foreach($arCodes as $code)
1799 {
1800 if (
1801 preg_match('/^DR([0-9]+)/', $code, $match)
1802 || preg_match('/^D([0-9]+)/', $code, $match)
1803 || preg_match('/^IU([0-9]+)/', $code, $match)
1804 )
1805 {
1806 $arEntities["DR"][$code] = $code;
1807 }
1808 elseif (preg_match('/^SG([0-9]+)_([A-Z])/', $code, $match))
1809 {
1810 $arEntities["SG"][$match[1]][$match[2]] = $match[2];
1811 }
1812 }
1813 static::$arUACCache[$userId] = $arEntities;
1814 }
1815
1816 foreach($arPerms as $t => $val)
1817 {
1818 foreach($val as $id => $p)
1819 {
1820 if(!is_array($p))
1821 {
1822 $p = array();
1823 }
1824 if($userId > 0 && $t == "U" && $userId == $id)
1825 {
1826 $perms = BLOG_PERMS_WRITE;
1827 if(in_array("US".$userId, $p)) // if author
1828 $perms = BLOG_PERMS_FULL;
1829 break;
1830 }
1831 if(
1832 in_array("G2", $p)
1833 || ($userId > 0 && in_array("AU", $p))
1834 )
1835 {
1836 if (!\Bitrix\Main\ModuleManager::isModuleInstalled('intranet'))
1837 {
1838 $perms = BLOG_PERMS_WRITE;
1839 }
1840 else
1841 {
1842 $currentUserType = self::getCurrentUserType($userId);
1843
1844 if ($currentUserType === 'employee')
1845 {
1846 $perms = BLOG_PERMS_WRITE;
1847 }
1848 elseif (
1849 $currentUserType === 'extranet'
1850 && Loader::includeModule('extranet')
1851 && ($extranetSiteId = CExtranet::getExtranetSiteId())
1852 )
1853 {
1855 'filter' => [
1856 '=SOURCE_ID' => $postId,
1857 '@EVENT_ID' => (new \Bitrix\Socialnetwork\Livefeed\BlogPost)->getEventId(),
1858 ],
1859 'select' => [ 'ID' ],
1860 ]);
1861 if ($logFields = $res->fetch())
1862 {
1864 'filter' => [
1865 '=LOG_ID' => $logFields['ID'],
1866 '=SITE_ID' => $extranetSiteId,
1867 ],
1868 'select' => [ 'LOG_ID' ],
1869 ]);
1870 if ($res->fetch())
1871 {
1872 $perms = BLOG_PERMS_WRITE;
1873 }
1874 }
1875 }
1876 }
1877
1878 if ($perms === BLOG_PERMS_WRITE)
1879 {
1880 break;
1881 }
1882 }
1883 if($t == "SG")
1884 {
1885 if(!empty($arEntities["SG"][$id]))
1886 {
1887 foreach($arEntities["SG"][$id] as $gr)
1888 {
1889 if(in_array("SG".$id."_".$gr, $p))
1890 {
1891 $perms = BLOG_PERMS_READ;
1892 break;
1893 }
1894 }
1895 }
1896 }
1897
1898 if($t == "DR" && !empty($arEntities["DR"]))
1899 {
1900 if(in_array("DR".$id, $arEntities["DR"]))
1901 {
1902 $perms = BLOG_PERMS_WRITE;
1903 break;
1904 }
1905 }
1906 }
1907
1908 if($perms > BLOG_PERMS_DENY)
1909 {
1910 break;
1911 }
1912 }
1913
1914 if(
1915 $perms <= BLOG_PERMS_READ
1916 && !empty($arPerms['SG'])
1917 ) // check OSG
1918 {
1919 $openedWorkgroupsList = [];
1920 foreach ($arPerms['SG'] as $arSGPerm)
1921 {
1922 if (empty($arSGPerm))
1923 {
1924 continue;
1925 }
1926
1927 foreach($arSGPerm as $sgPerm)
1928 {
1929 if (!preg_match('/^OSG(\d+)_'.(!$userId ? SONET_ROLES_ALL : SONET_ROLES_AUTHORIZED).'$/', $sgPerm, $matches))
1930 {
1931 continue;
1932 }
1933
1934 $openedWorkgroupsList[] = (int)$matches[1];
1935 }
1936 }
1937
1938
1939
1940 if (
1941 !empty($openedWorkgroupsList)
1942 && Loader::includeModule('socialnetwork')
1943 && \Bitrix\Socialnetwork\Helper\Workgroup::checkAnyOpened($openedWorkgroupsList)
1944 && (
1945 !\Bitrix\Main\ModuleManager::isModuleInstalled('intranet')
1946 || self::getCurrentUserType($userId) === 'employee'
1947 )
1948 )
1949 {
1950 $perms = BLOG_PERMS_READ;
1951 }
1952 }
1953
1954 if(
1955 $bNeedFull
1956 && $perms < BLOG_PERMS_FULL
1957 )
1958 {
1959 $arGroupsId = Array();
1960 if(!empty($arPerms["SG"]))
1961 {
1962 foreach($arPerms["SG"] as $gid => $val)
1963 {
1964 if(!empty($arEntities["SG"][$gid]))
1965 $arGroupsId[] = $gid;
1966 }
1967 }
1968
1969 $operation = Array("full_post", "moderate_post", "write_post", "premoderate_post");
1970 if(!empty($arGroupsId))
1971 {
1972 foreach($operation as $v)
1973 {
1974 if($perms <= BLOG_PERMS_READ)
1975 {
1976 $f = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_GROUP, $arGroupsId, "blog", $v);
1977 if(is_array($f))
1978 {
1979 foreach($f as $gid => $val)
1980 {
1981 if(in_array($val, $arEntities["SG"][$gid]))
1982 {
1983 switch($v)
1984 {
1985 case "full_post":
1986 $perms = BLOG_PERMS_FULL;
1987 break;
1988 case "moderate_post":
1989 $perms = BLOG_PERMS_MODERATE;
1990 break;
1991 case "write_post":
1992 $perms = BLOG_PERMS_WRITE;
1993 break;
1994 case "premoderate_post":
1995 $perms = BLOG_PERMS_PREMODERATE;
1996 break;
1997 }
1998 }
1999 }
2000 }
2001 }
2002 }
2003
2004 // check if landing
2005 if ($perms < BLOG_PERMS_READ)
2006 {
2007 $res = \Bitrix\Socialnetwork\WorkgroupTable::getList([
2008 'filter' => [
2009 '@ID' => $arGroupsId,
2010 'ACTIVE' => 'Y',
2011 'LANDING' => 'Y',
2012 ],
2013 'select' => ['ID'],
2014 ]);
2015 if ($res->fetch())
2016 {
2017 $perms = BLOG_PERMS_READ;
2018 }
2019 }
2020 }
2021 }
2022 }
2023
2024 static::$arSocNetPostPermsCache[$cId] = $perms;
2025
2026 return $perms;
2027 }
2028
2029 private static function getCurrentUserType($userId)
2030 {
2031 static $currentUserType = null;
2032
2033 if ($userId <= 0)
2034 {
2035 return null;
2036 }
2037
2038 if (
2039 $currentUserType === null
2040 && Loader::includeModule('intranet')
2041 )
2042 {
2043 $res = \Bitrix\Intranet\UserTable::getList([
2044 'filter' => [
2045 'ID' => $userId,
2046 ],
2047 'select' => [ 'ID', 'USER_TYPE' ],
2048 ]);
2049 if ($userFields = $res->fetch())
2050 {
2051 $currentUserType = $userFields['USER_TYPE'];
2052 }
2053 }
2054
2055 return $currentUserType;
2056 }
2057
2058 public static function NotifyIm($arParams)
2059 {
2060 static $blogPostEventIdList = null;
2061
2062 $arUserIDSent = array();
2063
2064 if (!CModule::IncludeModule("im"))
2065 {
2066 return $arUserIDSent;
2067 }
2068
2069 $arUsers = array();
2070
2071 if(!empty($arParams["TO_USER_ID"]))
2072 {
2073 foreach($arParams["TO_USER_ID"] as $val)
2074 {
2075 $val = intval($val);
2076 if (
2077 $val > 0
2078 && $val != $arParams["FROM_USER_ID"]
2079 )
2080 {
2081 $arUsers[] = $val;
2082 }
2083 }
2084 }
2085 if(!empty($arParams["TO_SOCNET_RIGHTS"]))
2086 {
2087 foreach($arParams["TO_SOCNET_RIGHTS"] as $v)
2088 {
2089 if(mb_substr($v, 0, 1) == "U")
2090 {
2091 $u = intval(mb_substr($v, 1));
2092 if (
2093 $u > 0
2094 && !in_array($u, $arUsers)
2095 && (
2096 !array_key_exists("U", $arParams["TO_SOCNET_RIGHTS_OLD"])
2097 || empty($arParams["TO_SOCNET_RIGHTS_OLD"]["U"][$u])
2098 )
2099 && $u != $arParams["FROM_USER_ID"]
2100 )
2101 {
2102 $arUsers[] = $u;
2103 }
2104 }
2105 }
2106 }
2107
2108 if (!empty($arUsers))
2109 {
2111 'order' => array(),
2112 'filter' => array(
2113 "ID" => $arUsers,
2114 "=ACTIVE" => "Y",
2115 "!=EXTERNAL_AUTH_ID" => 'email',
2116 ),
2117 'select' => array("ID"),
2118 ));
2119
2120 $arUsers = array();
2121
2122 while ($arUser = $rsUser->fetch())
2123 {
2124 $arUsers[] = $arUser["ID"];
2125 }
2126 }
2127
2128 $arMessageFields = array(
2129 "MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
2130 "TO_USER_ID" => "",
2131 "FROM_USER_ID" => $arParams["FROM_USER_ID"],
2132 "NOTIFY_TYPE" => IM_NOTIFY_FROM,
2133 "NOTIFY_ANSWER" => "Y",
2134 "NOTIFY_MODULE" => "blog",
2135 "PARSE_LINK" => "N",
2136 );
2137
2138 $aditGM = $authorName = $authorAvatarUrl = "";
2139 if(intval($arParams["FROM_USER_ID"]) > 0)
2140 {
2141 $dbUser = CUser::GetByID($arParams["FROM_USER_ID"]);
2142 if($arUser = $dbUser->Fetch())
2143 {
2144 if($arUser["PERSONAL_GENDER"] == "F")
2145 {
2146 $aditGM = "_FEMALE";
2147 }
2148
2149 if (!empty($arUser["PERSONAL_PHOTO"]))
2150 {
2151 $avatarSize = (isset($arParams["PUSH_AVATAR_SIZE"]) && intval($arParams["PUSH_AVATAR_SIZE"]) > 0 ? intval($arParams["PUSH_AVATAR_SIZE"]) : 100);
2152 $imageResized = CFile::resizeImageGet(
2153 $arUser["PERSONAL_PHOTO"],
2154 array(
2155 "width" => $avatarSize,
2156 "height" => $avatarSize,
2157 ),
2159 );
2160 if ($imageResized)
2161 {
2162 $authorAvatarUrl = \Bitrix\Im\Common::getPublicDomain().$imageResized["src"];
2163 }
2164 }
2165
2166 $authorName = (
2167 $arUser
2168 ? CUser::FormatName(CSite::GetNameFormat(), $arUser, true)
2169 : GetMessage("BLG_GP_PUSH_USER")
2170 );
2171 }
2172 }
2173
2174 if (CModule::IncludeModule("socialnetwork"))
2175 {
2176 if ($blogPostEventIdList === null)
2177 {
2178 $blogPostLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\BlogPost;
2179 $blogPostEventIdList = $blogPostLivefeedProvider->getEventId();
2180 }
2181
2182 $rsLog = CSocNetLog::GetList(
2183 array(),
2184 array(
2185 "EVENT_ID" => $blogPostEventIdList,
2186 "SOURCE_ID" => $arParams["ID"],
2187 ),
2188 false,
2189 false,
2190 array("ID")
2191 );
2192 if ($arLog = $rsLog->Fetch())
2193 {
2194 $arMessageFields["LOG_ID"] = $arLog["ID"];
2195 }
2196 }
2197
2198 $arTitle = self::processNotifyTitle($arParams["TITLE"]);
2199 $arParams["TITLE"] = $arTitle['TITLE'];
2200 $arParams["TITLE_OUT"] = $arTitle['TITLE_OUT'];
2201 $bTitleEmpty = $arTitle['IS_TITLE_EMPTY'];
2202
2203 $serverName = (CMain::IsHTTPS() ? "https" : "http")."://".((defined("SITE_SERVER_NAME") && SITE_SERVER_NAME <> '') ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", ""));
2204 $urlOriginal = $arParams["URL"];
2205
2206 if (IsModuleInstalled("extranet"))
2207 {
2208 $user_path = COption::GetOptionString("socialnetwork", "user_page", false, SITE_ID);
2209 if (
2210 $user_path <> ''
2211 && mb_strpos($arParams["URL"], $user_path) === 0
2212 )
2213 {
2214 $arParams["URL"] = str_replace($user_path, "#USER_PATH#", $arParams["URL"]);
2215 }
2216 }
2217
2218 // notify mentioned users
2219 if(!empty($arParams["MENTION_ID"]))
2220 {
2221 if(!is_array($arParams["MENTION_ID_OLD"] ?? null))
2222 {
2223 $arParams["MENTION_ID_OLD"] = Array();
2224 }
2225
2226 $userIdsToMentions = $arNewRights = [];
2227
2228 foreach($arParams["MENTION_ID"] as $val)
2229 {
2230 $val = intval($val);
2231 if (
2232 intval($val) > 0
2233 && !in_array($val, $arParams["MENTION_ID_OLD"] ?? [])
2234 && $val != $arParams["FROM_USER_ID"]
2235 )
2236 {
2237 $postPerm = CBlogPost::GetSocNetPostPerms([
2238 "POST_ID" => $arParams["ID"],
2239 "NEED_FULL" => true,
2240 "USER_ID" => $val,
2241 "IGNORE_ADMIN" => true,
2242 ]);
2243
2244 if (
2245 $postPerm >= BLOG_PERMS_READ
2246 || $arParams["TYPE"] === "COMMENT"
2247 )
2248 {
2249 $userIdsToMentions[] = $val;
2250 }
2251 }
2252 }
2253
2254 $userIdsToMentions = array_unique($userIdsToMentions);
2255 $userIdsToMentions = self::filterUsersToNotify($userIdsToMentions);
2256
2257 foreach($userIdsToMentions as $userIdToMention)
2258 {
2259 $userIdToMention = (int)$userIdToMention;
2260 $arMessageFields["TO_USER_ID"] = $userIdToMention;
2261
2262 if (IsModuleInstalled("extranet"))
2263 {
2265 array(
2266 "URL" => $arParams["URL"],
2267 ),
2268 $userIdToMention,
2269 SITE_ID
2270 );
2271 $url = $arTmp["URLS"]["URL"];
2272
2273 $serverName = (
2274 mb_strpos($url, "http://") === 0
2275 || mb_strpos($url, "https://") === 0
2276 ? ""
2277 : $arTmp["SERVER_NAME"]
2278 );
2279 }
2280 else
2281 {
2282 $url = $arParams["URL"];
2283 }
2284
2285 $arMessageFields["PUSH_PARAMS"] = array(
2286 "ACTION" => "mention",
2287 );
2288
2289 if (!empty($authorAvatarUrl))
2290 {
2291 $arMessageFields["PUSH_PARAMS"]["ADVANCED_PARAMS"] = array(
2292 'avatarUrl' => $authorAvatarUrl,
2293 'senderName' => $authorName,
2294 );
2295 }
2296
2297 if ($arParams["TYPE"] === "POST")
2298 {
2299 $arMessageFields["NOTIFY_EVENT"] = "mention";
2300 $arMessageFields["NOTIFY_TAG"] = "BLOG|POST_MENTION|".$arParams["ID"];
2301 $arMessageFields["NOTIFY_SUB_TAG"] = "BLOG|POST_MENTION|" . $arParams["ID"] . '|' . $userIdToMention;
2302
2303 if (!$bTitleEmpty)
2304 {
2305 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2306 "BLG_GP_IM_6".$aditGM,
2307 array(
2308 "#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
2309 ),
2310 $languageId
2311 );
2312 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2313 "BLG_GP_IM_6".$aditGM,
2314 array(
2315 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
2316 ),
2317 $languageId
2318 )." ".$serverName.$url."";
2319 $arMessageFields["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2320 "BLG_GP_PUSH_6".$aditGM,
2321 array(
2322 "#name#" => $authorName,
2323 "#title#" => $arParams["TITLE"],
2324 ),
2325 $languageId
2326 );
2327 }
2328 else
2329 {
2330 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2331 "BLG_GP_IM_6A".$aditGM,
2332 array(
2333 "#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">". Loc::getMessage("BLG_GP_IM_6B", null, $languageId) ."</a>",
2334 ),
2335 $languageId
2336 );
2337 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2338 "BLG_GP_IM_6A".$aditGM,
2339 array(
2340 "#post#" => Loc::getMessage("BLG_GP_IM_6B", null, $languageId),
2341 ),
2342 $languageId
2343 )." ".$serverName.$url."";
2344 $arMessageFields["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2345 "BLG_GP_PUSH_6A".$aditGM,
2346 array(
2347 "#name#" => $authorName,
2348 "#post#" => Loc::getMessage("BLG_GP_IM_6B", null, $languageId),
2349 ),
2350 $languageId
2351 );
2352 }
2353 }
2354 elseif ($arParams["TYPE"] === "COMMENT")
2355 {
2356 $arMessageFields["NOTIFY_EVENT"] = "mention_comment";
2357 $arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT_MENTION|".$arParams["ID"].'|'.$arParams["COMMENT_ID"];
2358 $arMessageFields["NOTIFY_SUB_TAG"] = "BLOG|COMMENT_MENTION|".$arParams["COMMENT_ID"].'|'.$userIdToMention;
2359
2360 $commentCropped = truncateText($arParams["BODY"], 100);
2361
2362 if (!$bTitleEmpty)
2363 {
2364 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2365 "BLG_GP_IM_71".$aditGM,
2366 array(
2367 "#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
2368 "#comment#" => $commentCropped,
2369 ),
2370 $languageId
2371 );
2372 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2373 "BLG_GP_IM_71".$aditGM,
2374 array(
2375 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
2376 "#comment#" => $arParams["BODY"],
2377 ),
2378 $languageId
2379 )." ".$serverName.$url."";
2380 $arMessageFields["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2381 "BLG_GP_PUSH_71".$aditGM,
2382 array(
2383 "#name#" => $authorName,
2384 "#title#" => $arParams["TITLE"],
2385 "#comment#" => $commentCropped,
2386 ),
2387 $languageId
2388 );
2389 }
2390 else
2391 {
2392 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2393 "BLG_GP_IM_71A".$aditGM,
2394 array(
2395 "#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".Loc::getMessage("BLG_GP_IM_7B", null, $languageId)."</a>",
2396 "#comment#" => $commentCropped,
2397 ),
2398 $languageId
2399 );
2400 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2401 "BLG_GP_IM_71A".$aditGM,
2402 array(
2403 "#post#" => Loc::getMessage("BLG_GP_IM_7B", null, $languageId),
2404 "#comment#" => $arParams["BODY"],
2405 )
2406 )." ".$serverName.$url."";
2407 $arMessageFields["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2408 "BLG_GP_PUSH_71A".$aditGM,
2409 array(
2410 "#name#" => $authorName,
2411 "#post#" => Loc::getMessage("BLG_GP_IM_7B", null, $languageId),
2412 "#comment#" => $commentCropped,
2413 ),
2414 $languageId
2415 );
2416 }
2417 }
2418
2419 $arMessageFields["PUSH_PARAMS"]["TAG"] = $arMessageFields["NOTIFY_TAG"];
2420
2421 $ID = CIMNotify::Add($arMessageFields);
2422 $arUserIDSent[] = $userIdToMention;
2423
2424 if (
2425 (int)$ID > 0
2426 && (int)$arMessageFields["LOG_ID"] > 0
2427 )
2428 {
2429 foreach(GetModuleEvents("blog", "OnBlogPostMentionNotifyIm", true) as $arEvent)
2430 {
2431 ExecuteModuleEventEx($arEvent, Array($ID, $arMessageFields));
2432 }
2433 }
2434 }
2435 }
2436
2437 $notifySubTag = false;
2438 // notify 'to' users and an author
2439 if (!empty($arUsers))
2440 {
2441 if ($arParams["TYPE"] === "POST")
2442 {
2443 $arMessageFields["PUSH_PARAMS"] = array(
2444 "ACTION" => "post",
2445 );
2446
2447 if (!empty($authorAvatarUrl))
2448 {
2449 $arMessageFields["PUSH_PARAMS"]["ADVANCED_PARAMS"] = array(
2450 'avatarUrl' => $authorAvatarUrl,
2451 'senderName' => $authorName,
2452 );
2453 }
2454
2455 $arMessageFields["NOTIFY_EVENT"] = "post";
2456
2457 $notifySubTag = $arMessageFields["NOTIFY_TAG"] = "BLOG|POST|".$arParams["ID"];
2458
2459 if (!$bTitleEmpty)
2460 {
2461 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2462 "BLG_GP_IM_1_MSGVER_1".$aditGM,
2463 array(
2464 "#title#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
2465 ),
2466 $languageId
2467 );
2468 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2469 "BLG_GP_IM_1_MSGVER_1".$aditGM,
2470 array(
2471 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
2472 ),
2473 $languageId
2474 )." ".$serverName.$arParams["URL"]."";
2475 $arMessageFields["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2476 "BLG_GP_PUSH_1".$aditGM,
2477 array(
2478 "#name#" => $authorName,
2479 "#title#" => $arParams["TITLE"],
2480 ),
2481 $languageId
2482 );
2483 }
2484 else
2485 {
2486 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2487 "BLG_GP_IM_1A".$aditGM,
2488 array(
2489 "#post#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".Loc::getMessage("BLG_GP_IM_1B", null, $languageId)."</a>",
2490 ),
2491 $languageId
2492 );
2493 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2494 "BLG_GP_IM_1A".$aditGM,
2495 array(
2496 "#post#" => Loc::getMessage("BLG_GP_IM_1B", null, $languageId),
2497 )
2498 )." ".$serverName.$arParams["URL"]."";
2499 $arMessageFields["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2500 "BLG_GP_PUSH_1A".$aditGM,
2501 array(
2502 "#name#" => $authorName,
2503 "#post#" => Loc::getMessage("BLG_GP_IM_1B", null, $languageId),
2504 ),
2505 $languageId
2506 );
2507 }
2508 }
2509 elseif($arParams["TYPE"] === "COMMENT")
2510 {
2511 $arMessageFields["PUSH_PARAMS"] = array(
2512 "ACTION" => "comment",
2513 );
2514
2515 if (!empty($authorAvatarUrl))
2516 {
2517 $arMessageFields["PUSH_PARAMS"]["ADVANCED_PARAMS"] = array(
2518 'avatarUrl' => $authorAvatarUrl,
2519 'senderName' => $authorName,
2520 );
2521 }
2522
2523 $arMessageFields["NOTIFY_EVENT"] = "comment";
2524
2525 $arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT|".$arParams["ID"].'|'.$arParams["COMMENT_ID"];
2526 $notifySubTag = "BLOG|COMMENT|".$arParams["COMMENT_ID"];
2527
2528 $commentCropped = truncateText($arParams["BODY"], 100);
2529
2530 if (!$bTitleEmpty)
2531 {
2532 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2533 "BLG_GP_IM_41".$aditGM,
2534 array(
2535 "#title#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
2536 "#comment#" => $commentCropped,
2537 ),
2538 $languageId
2539 );
2540 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2541 "BLG_GP_IM_41".$aditGM,
2542 array(
2543 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
2544 "#comment#" => $arParams["BODY"],
2545 ),
2546 $languageId
2547 )." ".$serverName.$arParams["URL"]."\n\n".$arParams["BODY"];
2548 $arMessageFields["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2549 "BLG_GP_PUSH_41".$aditGM,
2550 array(
2551 "#name#" => $authorName,
2552 "#title#" => $arParams["TITLE"],
2553 "#comment#" => $commentCropped,
2554 ),
2555 $languageId
2556 );
2557
2558 $arMessageFields["NOTIFY_MESSAGE_AUTHOR"] = fn (?string $languageId = null) => Loc::getMessage(
2559 "BLG_GP_IM_51".$aditGM,
2560 array(
2561 "#title#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
2562 "#comment#" => $commentCropped,
2563 ),
2564 $languageId
2565 );
2566 $arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2567 "BLG_GP_IM_51".$aditGM,
2568 array(
2569 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
2570 "#comment#" => $arParams["BODY"],
2571 ),
2572 $languageId
2573 )." ".$serverName.$arParams["URL"]."\n\n".$arParams["BODY"];
2574 $arMessageFields["PUSH_MESSAGE_AUTHOR"] = fn (?string $languageId = null) => Loc::getMessage(
2575 "BLG_GP_PUSH_51".$aditGM,
2576 array(
2577 "#name#" => $authorName,
2578 "#title#" => $arParams["TITLE"],
2579 "#comment#" => $commentCropped,
2580 ),
2581 $languageId
2582 );
2583 }
2584 else
2585 {
2586 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2587 "BLG_GP_IM_41A".$aditGM,
2588 array(
2589 "#post#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".Loc::getMessage("BLG_GP_IM_4B", null, $languageId)."</a>",
2590 "#comment#" => $commentCropped,
2591 ),
2592 $languageId
2593 );
2594 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2595 "BLG_GP_IM_41A".$aditGM,
2596 array(
2597 "#post#" => Loc::getMessage("BLG_GP_IM_4B", null, $languageId),
2598 "#comment#" => $arParams["BODY"],
2599 ),
2600 $languageId
2601 )." ".$serverName.$arParams["URL"]."\n\n".$arParams["BODY"];
2602 $arMessageFields["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2603 "BLG_GP_PUSH_41A".$aditGM,
2604 array(
2605 "#name#" => $authorName,
2606 "#post#" => Loc::getMessage("BLG_GP_IM_4B", null, $languageId),
2607 "#comment#" => $commentCropped,
2608 ),
2609 $languageId
2610 );
2611
2612 $arMessageFields["NOTIFY_MESSAGE_AUTHOR"] = fn (?string $languageId = null) => Loc::getMessage(
2613 "BLG_GP_IM_51A".$aditGM,
2614 array(
2615 "#post#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".Loc::getMessage("BLG_GP_IM_5B", null, $languageId)."</a>",
2616 "#comment#" => $commentCropped,
2617 ),
2618 $languageId
2619 );
2620 $arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2621 "BLG_GP_IM_51A".$aditGM,
2622 Array(
2623 "#post#" => Loc::getMessage("BLG_GP_IM_5B", null, $languageId),
2624 "#comment#" => $arParams["BODY"],
2625 ),
2626 $languageId
2627 )." ".$serverName.$arParams["URL"]."\n\n".$arParams["BODY"];
2628 $arMessageFields["PUSH_MESSAGE_AUTHOR"] = fn (?string $languageId = null) => Loc::getMessage(
2629 "BLG_GP_PUSH_51A".$aditGM,
2630 array(
2631 "#name#" => $authorName,
2632 "#post#" => Loc::getMessage("BLG_GP_IM_5B", null, $languageId),
2633 "#comment#" => $commentCropped,
2634 ),
2635 $languageId
2636 );
2637 }
2638 }
2639 elseif($arParams["TYPE"] === "SHARE")
2640 {
2641 $arMessageFields["PUSH_PARAMS"] = array(
2642 "ACTION" => "share",
2643 );
2644
2645 if (!empty($authorAvatarUrl))
2646 {
2647 $arMessageFields["PUSH_PARAMS"]["ADVANCED_PARAMS"] = array(
2648 'avatarUrl' => $authorAvatarUrl,
2649 'senderName' => $authorName,
2650 );
2651 }
2652
2653 $arMessageFields["NOTIFY_EVENT"] = "share";
2654 $arMessageFields["NOTIFY_TAG"] = "BLOG|SHARE|".$arParams["ID"];
2655 $notifySubTag = "BLOG|POST|".$arParams["ID"];
2656
2657 if (!$bTitleEmpty)
2658 {
2659 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2660 "BLG_GP_IM_8".$aditGM,
2661 array(
2662 "#title#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
2663 ),
2664 $languageId
2665 );
2666 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2667 "BLG_GP_IM_8".$aditGM,
2668 Array(
2669 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
2670 ),
2671 $languageId
2672 )." ".$serverName.$arParams["URL"]."";
2673 $arMessageFields["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2674 "BLG_GP_PUSH_8".$aditGM,
2675 array(
2676 "#name#" => $authorName,
2677 "#title#" => $arParams["TITLE"],
2678 ),
2679 $languageId
2680 );
2681 }
2682 else
2683 {
2684 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2685 "BLG_GP_IM_8A".$aditGM,
2686 array(
2687 "#post#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".Loc::getMessage("BLG_GP_IM_8B", null, $languageId)."</a>",
2688 ),
2689 $languageId
2690 );
2691 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2692 "BLG_GP_IM_8A".$aditGM,
2693 array(
2694 "#post#" => Loc::getMessage("BLG_GP_IM_8B", null, $languageId),
2695 ),
2696 $languageId
2697 )." ".$serverName.$arParams["URL"]."";
2698 $arMessageFields["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2699 "BLG_GP_PUSH_8A".$aditGM,
2700 array(
2701 "#name#" => $authorName,
2702 "#post#" => Loc::getMessage("BLG_GP_IM_8B", null, $languageId),
2703 ),
2704 $languageId
2705 );
2706 }
2707 }
2708 elseif($arParams["TYPE"] === "SHARE2USERS")
2709 {
2710 $arMessageFields["PUSH_PARAMS"] = array(
2711 "ACTION" => "share2users",
2712 );
2713
2714 if (!empty($authorAvatarUrl))
2715 {
2716 $arMessageFields["PUSH_PARAMS"]["ADVANCED_PARAMS"] = array(
2717 'avatarUrl' => $authorAvatarUrl,
2718 'senderName' => $authorName,
2719 );
2720 }
2721
2722 $arMessageFields["NOTIFY_EVENT"] = "share2users";
2723 $arMessageFields["NOTIFY_TAG"] = "BLOG|SHARE2USERS|".$arParams["ID"];
2724 $notifySubTag = "BLOG|POST|".$arParams["ID"];
2725
2726 if (!$bTitleEmpty)
2727 {
2728 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2729 "BLG_GP_IM_9".$aditGM,
2730 array(
2731 "#title#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
2732 ),
2733 $languageId
2734 );
2735 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2736 "BLG_GP_IM_9".$aditGM,
2737 array(
2738 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
2739 ),
2740 $languageId
2741 )." ".$serverName.$arParams["URL"]."";
2742 $arMessageFields["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2743 "BLG_GP_PUSH_9".$aditGM,
2744 array(
2745 "#name#" => $authorName,
2746 "#title#" => $arParams["TITLE"],
2747 ),
2748 $languageId
2749 );
2750 }
2751 else
2752 {
2753 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2754 "BLG_GP_IM_9A".$aditGM,
2755 array(
2756 "#post#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".Loc::getMessage("BLG_GP_IM_9B", null, $languageId)."</a>",
2757 ),
2758 $languageId
2759 );
2760 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2761 "BLG_GP_IM_9A".$aditGM,
2762 array(
2763 "#post#" => Loc::getMessage("BLG_GP_IM_9B", null, $languageId),
2764 ),
2765 $languageId
2766 )." ".$serverName.$arParams["URL"]."";
2767 $arMessageFields["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2768 "BLG_GP_PUSH_9A".$aditGM,
2769 array(
2770 "#name#" => $authorName,
2771 "#post#" => Loc::getMessage("BLG_GP_IM_9B", null, $languageId),
2772 ),
2773 $languageId
2774 );
2775 }
2776 }
2777
2778 $arMessageFields["PUSH_PARAMS"]["TAG"] = $arMessageFields["NOTIFY_TAG"];
2779 }
2780
2781 $arUsers = self::filterUsersToNotify($arUsers);
2782 foreach($arUsers as $userId)
2783 {
2784 if(
2785 in_array($userId, $arUserIDSent)
2786 || (
2787 !empty($arParams["EXCLUDE_USERS"])
2788 && (int)$arParams["EXCLUDE_USERS"][$userId] > 0
2789 )
2790 )
2791 {
2792 continue;
2793 }
2794
2795 if (IsModuleInstalled("extranet"))
2796 {
2798 array(
2799 "URL" => $arParams["URL"],
2800 ),
2801 $userId,
2802 SITE_ID
2803 );
2804 $url = $arTmp["URLS"]["URL"];
2805
2806 $serverName = (
2807 mb_strpos($url, "http://") === 0
2808 || mb_strpos($url, "https://") === 0
2809 ? ""
2810 : $arTmp["SERVER_NAME"]
2811 );
2812
2813 if($arParams["TYPE"] === "POST")
2814 {
2815 if (!$bTitleEmpty)
2816 {
2817 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2818 "BLG_GP_IM_1_MSGVER_1".$aditGM,
2819 Array("#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>"),
2820 $languageId
2821 );
2822 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2823 "BLG_GP_IM_1_MSGVER_1".$aditGM,
2824 Array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])),
2825 $languageId
2826 )." (".$serverName.$url.")";
2827 }
2828 else
2829 {
2830 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2831 "BLG_GP_IM_1A".$aditGM,
2832 Array("#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".Loc::getMessage("BLG_GP_IM_1B", null, $languageId)."</a>"),
2833 $languageId
2834 );
2835 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2836 "BLG_GP_IM_1A".$aditGM,
2837 Array("#post#" => Loc::getMessage("BLG_GP_IM_1B", null, $languageId)),
2838 $languageId
2839 )." (".$serverName.$url.")";
2840 }
2841 }
2842 elseif($arParams["TYPE"] === "COMMENT")
2843 {
2844 $commentCropped = truncateText($arParams["BODY"], 100);
2845
2846 if (!$bTitleEmpty)
2847 {
2848 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage("BLG_GP_IM_41".$aditGM, array(
2849 "#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
2850 "#comment#" => $commentCropped,
2851 ), $languageId);
2852 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage("BLG_GP_IM_41".$aditGM, array(
2853 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
2854 "#comment#" => $arParams["BODY"],
2855 ), $languageId)." ".$serverName.$url;
2856 $arMessageFields["NOTIFY_MESSAGE_AUTHOR"] = fn (?string $languageId = null) => Loc::getMessage("BLG_GP_IM_51".$aditGM, array(
2857 "#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
2858 "#comment#" => $commentCropped,
2859 ), $languageId);
2860 $arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"] = fn (?string $languageId = null) => Loc::getMessage("BLG_GP_IM_51".$aditGM, array(
2861 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
2862 "#comment#" => $arParams["BODY"],
2863 ), $languageId)." ".$serverName.$url;
2864 }
2865 else
2866 {
2867 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage("BLG_GP_IM_41A".$aditGM, array(
2868 "#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".Loc::getMessage("BLG_GP_IM_4B", null, $languageId)."</a>",
2869 "#comment#" => $commentCropped,
2870 ), $languageId);
2871 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage("BLG_GP_IM_41A".$aditGM, array(
2872 "#post#" => Loc::getMessage("BLG_GP_IM_4B", null, $languageId),
2873 "#comment#" => $arParams["BODY"],
2874 ), $languageId)." ".$serverName.$url;
2875 $arMessageFields["NOTIFY_MESSAGE_AUTHOR"] = fn (?string $languageId = null) => Loc::getMessage("BLG_GP_IM_51A".$aditGM, array(
2876 "#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".Loc::getMessage("BLG_GP_IM_5B", null, $languageId)."</a>",
2877 "#comment#" => $commentCropped,
2878 ), $languageId);
2879 $arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"] = fn (?string $languageId = null) => Loc::getMessage("BLG_GP_IM_51A".$aditGM, array(
2880 "#post#" => Loc::getMessage("BLG_GP_IM_5B", null, $languageId),
2881 "#comment#" => $arParams["BODY"],
2882 ), $languageId)." ".$serverName.$url;
2883 }
2884 }
2885 elseif($arParams["TYPE"] === "SHARE")
2886 {
2887 if (!$bTitleEmpty)
2888 {
2889 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2890 "BLG_GP_IM_8".$aditGM,
2891 Array("#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>"),
2892 $languageId
2893 );
2894 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2895 "BLG_GP_IM_8".$aditGM,
2896 Array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])),
2897 $languageId
2898 )." ".$serverName.$url."";
2899 }
2900 else
2901 {
2902 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2903 "BLG_GP_IM_8A".$aditGM,
2904 Array("#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".Loc::getMessage("BLG_GP_IM_8B", null, $languageId)."</a>"),
2905 $languageId
2906 );
2907 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2908 "BLG_GP_IM_8A".$aditGM,
2909 Array("#post#" => Loc::getMessage("BLG_GP_IM_8B", null, $languageId)),
2910 $languageId
2911 )." ".$serverName.$url."";
2912 }
2913 }
2914 elseif($arParams["TYPE"] === "SHARE2USERS")
2915 {
2916 if (!$bTitleEmpty)
2917 {
2918 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2919 "BLG_GP_IM_9".$aditGM,
2920 Array("#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>"),
2921 $languageId
2922 );
2923 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2924 "BLG_GP_IM_9".$aditGM,
2925 Array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])),
2926 $languageId
2927 )." ".$serverName.$url."";
2928 }
2929 else
2930 {
2931 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
2932 "BLG_GP_IM_9A".$aditGM,
2933 Array("#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">"
2934 .Loc::getMessage(
2935 "BLG_GP_IM_9B",
2936 null,
2937 $languageId
2938 )
2939 ."</a>",
2940 ),
2941 $languageId
2942 );
2943 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
2944 "BLG_GP_IM_9A".$aditGM,
2945 Array("#post#" => Loc::getMessage("BLG_GP_IM_9B", null, $languageId)),
2946 $languageId
2947 )." ".$serverName.$url."";
2948 }
2949 }
2950 }
2951
2952 $arMessageFieldsTmp = $arMessageFields;
2953 if($arParams["TYPE"] === "COMMENT")
2954 {
2955 if($arParams["AUTHOR_ID"] == $userId)
2956 {
2957 $arMessageFieldsTmp["NOTIFY_MESSAGE"] = $arMessageFields["NOTIFY_MESSAGE_AUTHOR"];
2958 $arMessageFieldsTmp["NOTIFY_MESSAGE_OUT"] = $arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"];
2959 $arMessageFieldsTmp["PUSH_MESSAGE"] = $arMessageFields["PUSH_MESSAGE_AUTHOR"];
2960 }
2961 }
2962
2963 $arMessageFieldsTmp["TO_USER_ID"] = $userId;
2964 if ($notifySubTag)
2965 {
2966 $arMessageFieldsTmp["NOTIFY_SUB_TAG"] = $notifySubTag."|".$userId;
2967 }
2968
2969 CIMNotify::Add($arMessageFieldsTmp);
2970
2971 $arUserIDSent[] = $userId;
2972 }
2973
2974 // notify sonet groups subscribers
2975 if (
2976 $arParams["TYPE"] === "POST"
2977 && !empty($arParams["TO_SOCNET_RIGHTS"])
2978 )
2979 {
2980 $arGroupsId = array();
2981 foreach($arParams["TO_SOCNET_RIGHTS"] as $perm_tmp)
2982 {
2983 if (
2984 preg_match('/^SG(\d+)_'.SONET_ROLES_USER.'$/', $perm_tmp, $matches)
2985 || preg_match('/^SG(\d+)$/', $perm_tmp, $matches)
2986 )
2987 {
2988 $group_id_tmp = $matches[1];
2989 if (
2990 $group_id_tmp > 0
2991 && (
2992 !array_key_exists("SG", $arParams["TO_SOCNET_RIGHTS_OLD"])
2993 || empty($arParams["TO_SOCNET_RIGHTS_OLD"]["SG"][$group_id_tmp])
2994 )
2995 )
2996 {
2997 $arGroupsId[] = $group_id_tmp;
2998 }
2999 }
3000 }
3001
3002 if (!empty($arGroupsId))
3003 {
3004 $arTitle = self::processNotifyTitle($arParams["TITLE"]);
3005 $title = $arTitle['TITLE'];
3006 $title_out = $arTitle['TITLE_OUT'];
3007
3008 $arNotifyParams = array(
3009 "LOG_ID" => $arMessageFields["LOG_ID"],
3010 "GROUP_ID" => $arGroupsId,
3011 "NOTIFY_MESSAGE" => "",
3012 "FROM_USER_ID" => $arParams["FROM_USER_ID"],
3013 "URL" => $arParams["URL"],
3014 "MESSAGE" => fn (?string $languageId = null) => Loc::getMessage(
3015 "SONET_IM_NEW_POST",
3016 Array("#title#" => "[URL=#URL#]".$title."[/URL]"),
3017 $languageId
3018 ),
3019 "MESSAGE_OUT" => fn (?string $languageId = null) => Loc::getMessage(
3020 "SONET_IM_NEW_POST",
3021 Array("#title#" => $title_out),
3022 $languageId
3023 )." #URL#",
3024 "MESSAGE_CHAT" => GetMessage("SONET_IM_NEW_POST_CHAT".$aditGM, Array(
3025 "#title#" => "[URL=#URL#]".$title_out."[/URL]",
3026 )),
3027 "EXCLUDE_USERS" => array_merge([$arParams["FROM_USER_ID"]], $arUserIDSent),
3028 "PERMISSION" => array(
3029 "FEATURE" => "blog",
3030 "OPERATION" => "view_post",
3031 ),
3032 );
3033
3034 $arUserIDSentBySubscription = CSocNetSubscription::NotifyGroup($arNotifyParams);
3035 if (!$arUserIDSentBySubscription)
3036 {
3037 $arUserIDSentBySubscription = array();
3038 }
3039 $arUserIDSent = array_merge($arUserIDSent, $arUserIDSentBySubscription);
3040 }
3041 }
3042
3043 if (
3044 !empty($arParams['GRAT_DATA'])
3045 && is_array($arParams['GRAT_DATA'])
3046 && !empty($arParams['GRAT_DATA']['USERS'])
3047 && is_array($arParams['GRAT_DATA']['USERS'])
3048 )
3049 {
3050 $arMessageFieldsGrat = $arMessageFields;
3051 $arMessageFieldsGrat["NOTIFY_EVENT"] = 'grat';
3052 $arMessageFieldsGrat["NOTIFY_TAG"] = "BLOG|POST|".$arParams["ID"];
3053 $arMessageFieldsGrat["PUSH_PARAMS"] = [
3054 "ACTION" => "post",
3055 "TAG" => $arMessageFieldsGrat["NOTIFY_TAG"],
3056 ];
3057 if (!empty($authorAvatarUrl))
3058 {
3059 $arMessageFieldsGrat["PUSH_PARAMS"]["ADVANCED_PARAMS"] = array(
3060 'avatarUrl' => $authorAvatarUrl,
3061 'senderName' => $authorName,
3062 );
3063 }
3064
3065 $arMessageFieldsGrat["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage('SONET_IM_POST_GRAT_NEW', [
3066 "#link_post_start#" => "<a href=\"".$urlOriginal."\" class=\"bx-notifier-item-action\">",
3067 "#link_post_end#" => "</a>",
3068 "#title#" => htmlspecialcharsbx($arParams["TITLE"]),
3069 ], $languageId);
3070
3071 $arMessageFieldsGrat["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage('SONET_IM_POST_GRAT_NEW', [
3072 "#link_post_start#" => "",
3073 "#link_post_end#" => "",
3074 "#title#" => htmlspecialcharsbx($arParams["TITLE"]),
3075 ], $languageId)." ".$serverName.$urlOriginal."";
3076 $arMessageFieldsGrat["PUSH_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage('SONET_PUSH_POST_GRAT_NEW', [
3077 "#name#" => $authorName,
3078 "#title#" => $arParams["TITLE"],
3079 ], $languageId);
3080
3081 $gratUsers = self::filterUsersToNotify($arParams['GRAT_DATA']['USERS']);
3082 foreach($gratUsers as $gratUserId)
3083 {
3084 if (
3085 in_array($gratUserId, $arUserIDSent)
3086 || $arParams["FROM_USER_ID"] == $gratUserId
3087 )
3088 {
3089 continue;
3090 }
3091
3093 "POST_ID" => $arParams["ID"],
3094 "NEED_FULL" => true,
3095 "USER_ID" => $gratUserId,
3096 "IGNORE_ADMIN" => true,
3097 ));
3098
3099 if ($postPerm < BLOG_PERMS_READ)
3100 {
3101 continue;
3102 }
3103
3104 $arMessageFieldsTmp = $arMessageFieldsGrat;
3105 $arMessageFieldsTmp['TO_USER_ID'] = $gratUserId;
3106 $arMessageFieldsTmp['NOTIFY_SUB_TAG'] = "BLOG|POST|".$arParams["ID"]."|".$gratUserId;
3107
3108 CIMNotify::Add($arMessageFieldsTmp);
3109 $arUserIDSent[] = $gratUserId;
3110 }
3111 }
3112
3113 return $arUserIDSent;
3114 }
3115
3116 protected static function filterUsersToNotify(array $users): array
3117 {
3118 if (
3119 Loader::includeModule('extranet')
3120 // todo: remove and add version_control after release extranet_24.300.0
3121 && class_exists('Bitrix\Extranet\Service\ServiceContainer')
3122 )
3123 {
3124 try
3125 {
3126 $collaberService = Extranet\Service\ServiceContainer::getInstance()->getCollaberService();
3127 }
3128 catch (Exception $exception)
3129 {
3130 return $users;
3131 }
3132
3133 $users = array_filter(
3134 $users,
3135 fn ($userId) => !$collaberService->isCollaberById((int)$userId)
3136 );
3137 }
3138
3139 return $users;
3140 }
3141
3142 public static function NotifyImReady($arParams = array())
3143 {
3144 $arUserIDSent = array();
3145 $moderatorList = array();
3146
3147 if (
3148 !Loader::includeModule("im")
3149 || !Loader::includeModule("socialnetwork")
3150 )
3151 {
3152 return $arUserIDSent;
3153 }
3154
3155 if (!in_array($arParams['TYPE'], array('POST', 'COMMENT')))
3156 {
3157 return $arUserIDSent;
3158 }
3159
3160 if (
3161 isset($arParams["TO_SOCNET_RIGHTS"])
3162 && is_array($arParams["TO_SOCNET_RIGHTS"])
3163 && !empty($arParams["TO_SOCNET_RIGHTS"])
3164 )
3165 {
3166 $arGroupChecked = array();
3167 foreach($arParams["TO_SOCNET_RIGHTS"] as $code)
3168 {
3169
3170 if (preg_match('/^SG(\d+)/', $code, $matches))
3171 {
3172 $sonetGroupId = intval($matches[1]);
3173
3174 if (in_array($sonetGroupId, $arGroupChecked))
3175 {
3176 break;
3177 }
3178
3179 $arGroupChecked[] = $sonetGroupId;
3180
3181 if ($sonetGroupId > 0)
3182 {
3183 $featureOperationPerms = CSocNetFeaturesPerms::GetOperationPerm(
3185 $sonetGroupId,
3186 'blog',
3187 ($arParams['TYPE'] === 'POST' ? 'moderate_post' : 'moderate_comment')
3188 );
3189
3190 if ($featureOperationPerms)
3191 {
3192 $res = \Bitrix\Socialnetwork\UserToGroupTable::getList(array(
3193 'filter' => array(
3194 '<=ROLE' => $featureOperationPerms,
3195 'GROUP_ID' => $sonetGroupId,
3196 '=GROUP.ACTIVE' => 'Y',
3197 ),
3198 'select' => array('USER_ID'),
3199 ));
3200 while ($relation = $res->fetch())
3201 {
3202 if (!isset($moderatorList[$relation['USER_ID']]))
3203 {
3204 $moderatorList[$relation['USER_ID']] = array(
3205 'USER_ID' => $relation['USER_ID'],
3206 'GROUP_ID' => $sonetGroupId,
3207 );
3208 }
3209 }
3210 }
3211 }
3212 }
3213 }
3214 }
3215
3216 if (!empty($moderatorList))
3217 {
3218 $arMessageFields = array(
3219 "MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
3220 "NOTIFY_TYPE" => IM_NOTIFY_SYSTEM,
3221 "NOTIFY_MODULE" => "blog",
3222 );
3223
3224 $arTitle = self::processNotifyTitle($arParams["TITLE"]);
3225 $arParams["TITLE"] = $arTitle['TITLE'];
3226 $arParams["TITLE_OUT"] = $arTitle['TITLE_OUT'];
3227 $bTitleEmpty = $arTitle['IS_TITLE_EMPTY'];
3228 $serverName = (CMain::IsHTTPS() ? "https" : "http")."://".((defined("SITE_SERVER_NAME") && SITE_SERVER_NAME <> '') ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", ""));
3229 $moderationUrl = \Bitrix\Main\Config\Option::get('socialnetwork', 'workgroups_page', SITE_DIR.'workgroups/').'group/#group_id#/blog/moderation/';
3230
3231 if ($arParams["TYPE"] === "POST")
3232 {
3233 $arMessageFields["NOTIFY_EVENT"] = "moderate_post";
3234 $arMessageFields["NOTIFY_TAG"] = "BLOG|MODERATE_POST|".$arParams["POST_ID"];
3235
3236 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
3237 (!$bTitleEmpty ? "SONET_IM_NEW_POST_TO_MODERATE_W_TITLE" : "SONET_IM_NEW_POST_TO_MODERATE_WO_TITLE"),
3238 array(
3239 "#link_mod_start#" => "<a href=\"#MODERATION_URL#\" class=\"bx-notifier-item-action\">",
3240 "#link_mod_end#" => "</a>",
3241 "#title#" => htmlspecialcharsbx($arParams["TITLE"]),
3242 ),
3243 $languageId
3244 );
3245
3246 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
3247 (!$bTitleEmpty ? "SONET_IM_NEW_POST_TO_MODERATE_W_TITLE" : "SONET_IM_NEW_POST_TO_MODERATE_WO_TITLE"),
3248 array(
3249 "#link_mod_start#" => "",
3250 "#link_mod_end#" => "",
3251 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
3252 ),
3253 $languageId
3254 )." #SERVER_NAME##MODERATION_URL#";
3255 }
3256 else
3257 {
3258 $arMessageFields["NOTIFY_EVENT"] = "moderate_comment";
3259 $arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT|".$arParams["POST_ID"].'|'.$arParams["COMMENT_ID"];
3260
3261 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
3262 (!$bTitleEmpty ? "SONET_IM_NEW_COMMENT_TO_MODERATE_W_TITLE" : "SONET_IM_NEW_COMMENT_TO_MODERATE_WO_TITLE"),
3263 array(
3264 "#link_com_start#" => "<a href=\"#COMMENT_URL#\" class=\"bx-notifier-item-action\">",
3265 "#link_com_end#" => "</a>",
3266 "#title#" => htmlspecialcharsbx($arParams["TITLE"]),
3267 ),
3268 $languageId
3269 );
3270
3271 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
3272 (!$bTitleEmpty ? "SONET_IM_NEW_COMMENT_TO_MODERATE_W_TITLE" : "SONET_IM_NEW_COMMENT_TO_MODERATE_WO_TITLE"),
3273 array(
3274 "#link_com_start#" => "",
3275 "#link_com_end#" => "",
3276 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
3277 ),
3278 $languageId
3279 )." #SERVER_NAME##COMMENT_URL#";
3280 }
3281
3282 foreach($moderatorList as $moderator)
3283 {
3284 $moderatorId = $moderator['USER_ID'];
3285 $groupId = $moderator['GROUP_ID'];
3286
3287 if ($moderatorId != $arParams["FROM_USER_ID"])
3288 {
3289 $arMessageFieldsCurrent = $arMessageFields;
3290 $arMessageFieldsCurrent["TO_USER_ID"] = $moderatorId;
3291
3292 $userModerationUrl = str_replace('#group_id#', $groupId, $moderationUrl);
3293 $userCommentUrl = $arParams['COMMENT_URL'] ?? null;
3294
3295 if (IsModuleInstalled("extranet"))
3296 {
3298 array(
3299 "MODERATION_URL" => $userModerationUrl,
3300 "COMMENT_URL" => (isset($arParams['COMMENT_URL']) ? $arParams['COMMENT_URL'] : ''),
3301 ),
3302 $moderatorId,
3303 SITE_ID
3304 );
3305
3306 $userModerationUrl = $arTmp["URLS"]["MODERATION_URL"];
3307 $userCommentUrl = $arTmp["URLS"]["COMMENT_URL"];
3308
3309 $serverName = (
3310 mb_strpos($userModerationUrl, "http://") === 0
3311 || mb_strpos($userModerationUrl, "https://") === 0
3312 ? ""
3313 : $arTmp["SERVER_NAME"]
3314 );
3315 }
3316
3317 $notifyMessage = clone $arMessageFields["NOTIFY_MESSAGE"];
3318 $notifyMessageOut = clone $arMessageFields["NOTIFY_MESSAGE_OUT"];
3319
3320 $arMessageFieldsCurrent["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => str_replace(
3321 array('#MODERATION_URL#', '#COMMENT_URL#'),
3322 array($userModerationUrl, $userCommentUrl),
3323 $notifyMessage($languageId)
3324 );
3325 $arMessageFieldsCurrent["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => str_replace(
3326 array('#MODERATION_URL#', '#SERVER_NAME#', '#COMMENT_URL#'),
3327 array($userModerationUrl, $serverName, $userCommentUrl),
3328 $notifyMessageOut($languageId)
3329 );
3330
3331 CIMNotify::Add($arMessageFieldsCurrent);
3332
3333 $arUserIDSent[] = $moderatorId;
3334 }
3335 }
3336 }
3337
3338 return $arUserIDSent;
3339 }
3340
3341 public static function NotifyImPublish($arParams = array())
3342 {
3343 if (
3344 !Loader::includeModule("im")
3345 || !Loader::includeModule("socialnetwork")
3346 )
3347 {
3348 return false;
3349 }
3350
3351 if (!in_array($arParams['TYPE'], array('POST', 'COMMENT')))
3352 {
3353 return false;
3354 }
3355
3356 $arTitle = self::processNotifyTitle($arParams["TITLE"]);
3357 $arParams["TITLE"] = $arTitle['TITLE'];
3358 $arParams["TITLE_OUT"] = $arTitle['TITLE_OUT'];
3359 $bTitleEmpty = $arTitle['IS_TITLE_EMPTY'];
3360 $serverName = (CMain::IsHTTPS() ? "https" : "http")."://".((defined("SITE_SERVER_NAME") && SITE_SERVER_NAME <> '') ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", ""));
3361
3362 $arMessageFields = array(
3363 "MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
3364 "NOTIFY_TYPE" => IM_NOTIFY_SYSTEM,
3365 "NOTIFY_MODULE" => "blog",
3366 "TO_USER_ID" => $arParams["TO_USER_ID"],
3367 );
3368
3369 if ($arParams["TYPE"] === "POST")
3370 {
3371 $arMessageFields["NOTIFY_EVENT"] = "published_post";
3372 $arMessageFields["NOTIFY_TAG"] = "BLOG|POST|".$arParams["POST_ID"];
3373
3374 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
3375 (!$bTitleEmpty ? "SONET_IM_NEW_POST_PUBLISHED_W_TITLE" : "SONET_IM_NEW_POST_PUBLISHED_WO_TITLE"),
3376 array(
3377 "#link_post_start#" => "<a href=\"#POST_URL#\" class=\"bx-notifier-item-action\">",
3378 "#link_post_end#" => "</a>",
3379 "#title#" => htmlspecialcharsbx($arParams["TITLE"]),
3380 ),
3381 $languageId
3382 );
3383
3384 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
3385 (!$bTitleEmpty ? "SONET_IM_NEW_POST_PUBLISHED_W_TITLE" : "SONET_IM_NEW_POST_PUBLISHED_WO_TITLE"),
3386 array(
3387 "#link_post_start#" => "",
3388 "#link_post_end#" => "",
3389 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
3390 ),
3391 $languageId
3392 )." #SERVER_NAME##POST_URL#";
3393 }
3394 else
3395 {
3396 $arMessageFields["NOTIFY_EVENT"] = "published_comment";
3397 $arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT|".$arParams["POST_ID"]."|".$arParams["COMMENT_ID"];
3398
3399 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => Loc::getMessage(
3400 (!$bTitleEmpty ? "SONET_IM_NEW_COMMENT_PUBLISHED_W_TITLE" : "SONET_IM_NEW_COMMENT_PUBLISHED_WO_TITLE"),
3401 array(
3402 "#link_com_start#" => "<a href=\"#COMMENT_URL#\" class=\"bx-notifier-item-action\">",
3403 "#link_com_end#" => "</a>",
3404 "#title#" => htmlspecialcharsbx($arParams["TITLE"]),
3405 ),
3406 $languageId
3407 );
3408
3409 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => Loc::getMessage(
3410 (!$bTitleEmpty ? "SONET_IM_NEW_COMMENT_PUBLISHED_W_TITLE" : "SONET_IM_NEW_COMMENT_PUBLISHED_WO_TITLE"),
3411 array(
3412 "#link_com_start#" => "",
3413 "#link_com_end#" => "",
3414 "#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
3415 ),
3416 $languageId
3417 )." #SERVER_NAME##COMMENT_URL#";
3418 }
3419
3420 $userPostUrl = (isset($arParams['POST_URL']) ? $arParams['POST_URL'] : '');
3421 $userCommentUrl = (isset($arParams['COMMENT_URL']) ? $arParams['COMMENT_URL'] : '');
3422
3423 if (IsModuleInstalled("extranet"))
3424 {
3426 array(
3427 "POST_URL" => $userPostUrl,
3428 "COMMENT_URL" => $userCommentUrl,
3429 ),
3430 $arParams["TO_USER_ID"],
3431 SITE_ID
3432 );
3433
3434 $userPostUrl = $arTmp["URLS"]["POST_URL"];
3435 $userCommentUrl = $arTmp["URLS"]["COMMENT_URL"];
3436
3437 $serverName = (
3438 mb_strpos($userPostUrl, "http://") === 0
3439 || mb_strpos($userPostUrl, "https://") === 0
3440 ? ""
3441 : $arTmp["SERVER_NAME"]
3442 );
3443 }
3444
3445 $notifyMessage = clone $arMessageFields["NOTIFY_MESSAGE"];
3446 $notifyMessageOut = clone $arMessageFields["NOTIFY_MESSAGE_OUT"];
3447
3448 $arMessageFields["NOTIFY_MESSAGE"] = fn (?string $languageId = null) => str_replace(
3449 array('#POST_URL#', '#COMMENT_URL#'),
3450 array($userPostUrl, $userCommentUrl),
3451 $notifyMessage($languageId)
3452 );
3453 $arMessageFields["NOTIFY_MESSAGE_OUT"] = fn (?string $languageId = null) => str_replace(
3454 array('#POST_URL#', '#SERVER_NAME#', '#COMMENT_URL#'),
3455 array($userPostUrl, $serverName, $userCommentUrl),
3456 $notifyMessageOut($languageId)
3457 );
3458
3459 CIMNotify::Add($arMessageFields);
3460
3461 return true;
3462 }
3463
3464
3465 private static function processNotifyTitle($title)
3466 {
3467 $title = htmlspecialcharsback(str_replace(array("\r\n", "\n"), " ", $title));
3468
3469 return array(
3470 'TITLE' => htmlspecialcharsEx(truncateText($title, 100)),
3471 'TITLE_OUT' => htmlspecialcharsEx(truncateText($title, 255)),
3472 'IS_TITLE_EMPTY' => (trim($title, " \t\n\r\0\x0B\xA0" ) == ''),
3473 );
3474 }
3475
3476 public static function NotifyMail($arFields)
3477 {
3478 if (!CModule::IncludeModule('mail'))
3479 {
3480 return false;
3481 }
3482
3483 if (
3484 !isset($arFields["postId"])
3485 || intval($arFields["postId"]) <= 0
3486 || !isset($arFields["userId"])
3487 || !isset($arFields["postUrl"])
3488 || $arFields["postUrl"] == ''
3489 )
3490 {
3491 return false;
3492 }
3493
3494 if (!is_array($arFields["userId"]))
3495 {
3496 $arFields["userId"] = array($arFields["userId"]);
3497 }
3498
3499 if (!isset($arFields["siteId"]))
3500 {
3501 $arFields["siteId"] = SITE_ID;
3502 }
3503
3504 $nameTemplate = CSite::GetNameFormat("", $arFields["siteId"]);
3505 $authorName = "";
3506
3507 if (!empty($arFields["authorId"]))
3508 {
3509 $rsAuthor = CUser::GetById($arFields["authorId"]);
3510 $arAuthor = $rsAuthor->Fetch();
3511 $authorName = CUser::FormatName(
3512 $nameTemplate,
3513 $arAuthor,
3514 true,
3515 false
3516 );
3517
3518 if (check_email($authorName))
3519 {
3520 $authorName = '"'.$authorName.'"';
3521 }
3522
3523 foreach($arFields["userId"] as $key => $val)
3524 {
3525 if (intval($val) == intval($arFields["authorId"]))
3526 {
3527 unset($arFields["userId"][$key]);
3528 }
3529 }
3530 }
3531
3532 if (empty($arFields["userId"]))
3533 {
3534 return false;
3535 }
3536
3537 if (
3538 !isset($arFields["type"])
3539 || !in_array(mb_strtoupper($arFields["type"]), array("POST", "POST_SHARE", "COMMENT"))
3540 )
3541 {
3542 $arFields["type"] = "COMMENT";
3543 }
3544
3545 $arEmail = \Bitrix\Mail\User::getUserData($arFields["userId"], $nameTemplate);
3546 if (empty($arEmail))
3547 {
3548 return false;
3549 }
3550
3551 $arBlogPost = CBlogPost::GetByID(intval($arFields["postId"]));
3552 if (!$arBlogPost)
3553 {
3554 return false;
3555 }
3556
3557 $arTitle = self::processNotifyTitle($arBlogPost["TITLE"]);
3558 $postTitle = $arTitle['TITLE'];
3559
3560 switch(mb_strtoupper($arFields["type"]))
3561 {
3562 case "COMMENT":
3563 $mailMessageId = "<BLOG_COMMENT_".$arFields["commentId"]."@".$GLOBALS["SERVER_NAME"].">";
3564 $mailTemplateType = "BLOG_SONET_NEW_COMMENT";
3565 break;
3566 case "POST_SHARE":
3567 $mailMessageId = "<BLOG_POST_".$arFields["postId"]."@".$GLOBALS["SERVER_NAME"].">";
3568 $mailTemplateType = "BLOG_SONET_POST_SHARE";
3569 break;
3570 default:
3571 $mailMessageId = "<BLOG_POST_".$arFields["postId"]."@".$GLOBALS["SERVER_NAME"].">";
3572 $mailTemplateType = "BLOG_SONET_NEW_POST";
3573 }
3574
3575 $mailMessageInReplyTo = "<BLOG_POST_".$arFields["postId"]."@".$GLOBALS["SERVER_NAME"].">";
3576 $defaultEmailFrom = \Bitrix\Mail\User::getDefaultEmailFrom();
3577
3578 foreach ($arEmail as $userId => $arUser)
3579 {
3580 $email = $arUser["EMAIL"];
3581 $nameFormatted = str_replace(array('<', '>', '"'), '', $arUser["NAME_FORMATTED"]);
3582
3583 if (
3584 intval($userId) <= 0
3585 && $email == ''
3586 )
3587 {
3588 continue;
3589 }
3590
3591 $res = \Bitrix\Mail\User::getReplyTo(
3592 $arFields["siteId"],
3593 $userId,
3594 'BLOG_POST',
3595 $arFields["postId"],
3596 $arFields["postUrl"]
3597 );
3598 if (is_array($res))
3599 {
3600 list($replyTo, $backUrl) = $res;
3601
3602 if (
3603 $replyTo
3604 && $backUrl
3605 )
3606 {
3607 $authorName = str_replace(array('<', '>', '"'), '', $authorName);
3608 CEvent::Send(
3609 $mailTemplateType,
3610 $arFields["siteId"],
3611 array(
3612 "=Reply-To" => $authorName.' <'.$replyTo.'>',
3613 "=Message-Id" => $mailMessageId,
3614 "=In-Reply-To" => $mailMessageInReplyTo == $mailMessageId ? '' : $mailMessageInReplyTo,
3615 "EMAIL_FROM" => $authorName.' <'.$defaultEmailFrom.'>',
3616 "EMAIL_TO" => (!empty($nameFormatted) ? ''.$nameFormatted.' <'.$email.'>' : $email),
3617 "RECIPIENT_ID" => $userId,
3618 "COMMENT_ID" => (isset($arFields["commentId"]) ? intval($arFields["commentId"]) : false),
3619 "POST_ID" => intval($arFields["postId"]),
3620 "POST_TITLE" => $postTitle,
3621 "URL" => $arFields["postUrl"],
3622 )
3623 );
3624 }
3625 }
3626 }
3627
3628 if (
3629 mb_strtoupper($arFields["type"]) == 'COMMENT'
3630 && Loader::includeModule('crm')
3631 )
3632 {
3633 CCrmLiveFeedComponent::processCrmBlogComment(array(
3634 "AUTHOR" => isset($arAuthor) ? $arAuthor : false,
3635 "POST_ID" => intval($arFields["postId"]),
3636 "COMMENT_ID" => intval($arFields["commentId"]),
3637 "USER_ID" => array_keys($arEmail),
3638 ));
3639 }
3640
3641 return true;
3642 }
3643
3644 public static function DeleteSocNetPostPerms($postId)
3645 {
3646 global $DB;
3647 $postId = intval($postId);
3648 if($postId <= 0)
3649 return;
3650
3651 $DB->Query("DELETE FROM b_blog_socnet_rights WHERE POST_ID = ".$postId);
3652 }
3653
3654 public static function GetMentionedUserID($arFields)
3655 {
3656 global $USER_FIELD_MANAGER;
3657 $arMentionedUserID = array();
3658
3659 if (isset($arFields["DETAIL_TEXT"]))
3660 {
3661 preg_match_all("/\[user\s*=\s*([^\]]*)\](.+?)\[\/user\]/isu", $arFields["DETAIL_TEXT"], $arMention);
3662 if (!empty($arMention))
3663 {
3664 $arMentionedUserID = array_merge($arMentionedUserID, $arMention[1]);
3665 }
3666 }
3667
3668 $arPostUF = $USER_FIELD_MANAGER->GetUserFields("BLOG_POST", $arFields["ID"], LANGUAGE_ID);
3669
3670 if (
3671 is_array($arPostUF)
3672 && isset($arPostUF["UF_GRATITUDE"])
3673 && is_array($arPostUF["UF_GRATITUDE"])
3674 && isset($arPostUF["UF_GRATITUDE"]["VALUE"])
3675 && intval($arPostUF["UF_GRATITUDE"]["VALUE"]) > 0
3676 && CModule::IncludeModule("iblock")
3677 )
3678 {
3679 if (
3680 !is_array($GLOBALS["CACHE_HONOUR"])
3681 || !array_key_exists("honour_iblock_id", $GLOBALS["CACHE_HONOUR"])
3682 || intval($GLOBALS["CACHE_HONOUR"]["honour_iblock_id"]) <= 0
3683 )
3684 {
3685 $rsIBlock = CIBlock::GetList(array(), array("=CODE" => "honour", "=TYPE" => "structure"));
3686 if ($arIBlock = $rsIBlock->Fetch())
3687 {
3688 $GLOBALS["CACHE_HONOUR"]["honour_iblock_id"] = $arIBlock["ID"];
3689 }
3690 }
3691
3692 if (intval($GLOBALS["CACHE_HONOUR"]["honour_iblock_id"]) > 0)
3693 {
3694 $rsElementProperty = CIBlockElement::GetProperty(
3695 $GLOBALS["CACHE_HONOUR"]["honour_iblock_id"],
3696 $arPostUF["UF_GRATITUDE"]["VALUE"]
3697 );
3698 while ($arElementProperty = $rsElementProperty->GetNext())
3699 {
3700 if (
3701 $arElementProperty["CODE"] == "USERS"
3702 && intval($arElementProperty["VALUE"]) > 0
3703 )
3704 {
3705 $arMentionedUserID[] = $arElementProperty["VALUE"];
3706 }
3707 }
3708 }
3709 }
3710
3711 return $arMentionedUserID;
3712 }
3713
3714}
$arParams
Определения access_dialog.php:21
$type
Определения options.php:106
const BLOG_PERMS_COMMENT
Определения include.php:43
const BLOG_PERMS_MODERATE
Определения include.php:9
const BLOG_BY_USER_ID
Определения include.php:55
const BLOG_PERMS_POST
Определения include.php:42
const BLOG_PERMS_DENY
Определения include.php:5
const BLOG_PERMS_WRITE
Определения include.php:8
const BLOG_PERMS_READ
Определения include.php:6
const BLOG_PERMS_FULL
Определения include.php:10
const BLOG_PERMS_PREMODERATE
Определения include.php:7
global $APPLICATION
Определения include.php:80
$arResult
Определения generate_coupon.php:16
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getStatus($params=array())
Определения transformation.php:10
static increment($params=array())
Определения counterpost.php:7
const EVENT_ID_POST_IMPORTANT
Определения log.php:20
const EVENT_ID_POST_GRAT
Определения log.php:22
static getById($postId=0, $params=array())
Определения post.php:35
static getPublicDomain()
Определения common.php:8
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
Определения loader.php:13
static getList(array $parameters=array())
Определения datamanager.php:431
static encode($text)
Определения emoji.php:17
static getBlogPostSocNetPerms($params=array())
Определения componenthelper.php:3840
static Delete($ID)
Определения blog_comment.php:110
static GetByID($ID)
Определения blog.php:931
static IsBlogOwner($ID, $userID)
Определения blog.php:11
static SetStat($ID)
Определения blog.php:389
static Delete($ID)
Определения blog_image.php:143
static Delete($ID)
Определения blog_post_category.php:60
Определения blog_post.php:11
static $arSocNetPostPermsCache
Определения blog_post.php:12
static CanUserDeletePost($id, $userId)
Определения blog_post.php:62
PreparePath2Post($realUrl, $url, $arParams=array())
Определения blog_post.php:701
static UpdateLog($postID, $arPost, $arBlog, $arParams)
Определения blog_post.php:978
static Delete($ID)
Определения blog_post.php:499
static GetSocNetPermsName($ID)
Определения blog_post.php:1506
static ChangeSocNetPermission($entity_type, $entity_id, $operation)
Определения blog_post.php:1572
static DeleteSocNetPostPerms($postId)
Определения blog_post.php:3644
static Notify($arPost, $arBlog, $arParams)
Определения blog_post.php:726
static GetBlogUserCommentPerms($id, $userId)
Определения blog_post.php:157
static NotifyImPublish($arParams=array())
Определения blog_post.php:3341
static SetPostPerms($ID, $arPerms=array(), $permsType=BLOG_PERMS_POST)
Определения blog_post.php:392
static AddSocNetPerms($ID, $perms=array(), $arPost=array())
Определения blog_post.php:1232
static GetPostID($postID, $code, $allowCode=false)
Определения blog_post.php:1219
static CanUserEditPost($id, $userId)
Определения blog_post.php:21
static DeleteLog($postID, $bMicroblog=false)
Определения blog_post.php:1118
static getSocNetPerms($ID, $useCache=true)
Определения blog_post.php:1460
static GetID($code, $blogID)
Определения blog_post.php:1188
static $arBlogPCCache
Определения blog_post.php:16
static $arBlogPostIdCache
Определения blog_post.php:15
static getFullGroupRoleSet($role="", $prefix="")
Определения blog_post.php:1423
static CheckFields($ACTION, &$arFields, $ID=0)
Определения blog_post.php:221
const UF_NAME
Определения blog_post.php:19
static $arBlogPostCache
Определения blog_post.php:14
static UpdateSocNetPerms($ID, $perms=array(), $arPost=array())
Определения blog_post.php:1334
static filterUsersToNotify(array $users)
Определения blog_post.php:3116
static $arUACCache
Определения blog_post.php:13
static GetMentionedUserID($arFields)
Определения blog_post.php:3654
static __AddSocNetPerms($ID, $entityType="", $entityID=0, $entity=null)
Определения blog_post.php:1349
static GetBlogUserPostPerms($id, $userId)
Определения blog_post.php:109
static PreparePath($blogUrl, $postID=0, $siteID=False, $is404=True, $userID=0, $groupID=0)
Определения blog_post.php:620
static NotifyImReady($arParams=array())
Определения blog_post.php:3142
static CounterInc($ID)
Определения blog_post.php:710
static NotifyMail($arFields)
Определения blog_post.php:3476
static GetSocNetGroups($entity_type, $entity_id, $operation="view_post")
Определения blog_post.php:1381
static GetSocNetPostPerms( $postId=0, $bNeedFull=false, $userId=false, $postAuthor=0)
Определения blog_post.php:1623
static NotifyIm($arParams)
Определения blog_post.php:2058
static $arBlogUCache
Определения blog_post.php:17
static GetSocNetPostsPerms($entity_type, $entity_id)
Определения blog_post.php:1596
static GetSocNetPermsCode($ID)
Определения blog_post.php:1551
static Delete($ID)
Определения blog_trackback.php:67
static Delete($ID)
Определения blog_user_group_perms.php:125
static GetUserPerms($arGroups, $blogID, $postID=0, $permsType=BLOG_PERMS_POST, $selectType=BLOG_BY_BLOG_USER_ID)
Определения blog_user.php:501
static GetUserNameEx($arUser, $arBlogUser, $arParams)
Определения blog_user.php:574
static GetUserGroups($ID, $blogID, $joinStatus="", $selectType=BLOG_BY_BLOG_USER_ID, $bUrl=false)
Определения blog_user.php:436
static GetByID($ID, $selectType=BLOG_BY_BLOG_USER_ID)
Определения blog_user.php:354
static Index($MODULE_ID, $ITEM_ID, $arFields, $bOverWrite=false, $SEARCH_SESS_ID='')
Определения search.php:1302
static GetSite($log_id)
Определения log.php:1025
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения blog_comment.php:334
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения blog_image.php:122
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения blog_post_category.php:97
static GetByID($ID)
Определения blog_post.php:511
static GetList( $arOrder=["ID"=> "DESC"], $arFilter=[], $arGroupBy=false, $arNavStartParams=false, $arSelectFields=[])
Определения blog_post.php:554
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения blog_site_path.php:97
static htmlspecialcharsExArray($array)
Определения functions.php:617
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения blog_trackback.php:102
static Add($arFields)
Определения blog_user_group_perms.php:8
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения blog_user_group_perms.php:104
static Update($ID, $arFields)
Определения blog_user_group_perms.php:54
Определения cache.php:11
static Delete($ID)
Определения log.php:1294
static Add($arFields, $bSendEvent=true)
Определения log.php:20
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array(), $arParams=array())
Определения log.php:338
static Update($ID, $arFields)
Определения log.php:151
static ProcessPath($arUrl, $user_id, $explicit_site_id=false)
Определения log_tools.php:5283
Определения functions.php:6
global $CACHE_MANAGER
Определения clear_component_cache.php:7
$f
Определения component_props.php:52
$arFields
Определения dblapprove.php:5
$arPath
Определения file_edit.php:72
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$gr
Определения file_new.php:147
$res
Определения filter_act.php:7
$perm
Определения options.php:169
$zr
Определения options.php:5
global $USER_FIELD_MANAGER
Определения attempt.php:6
$result
Определения get_property_values.php:14
if($ajaxMode) $ID
Определения get_user.php:27
$entity
$p
Определения group_list_element_edit.php:23
if($request->getPost('Update') !==null) elseif( $request->getPost( 'Apply') !==null) elseif($request->getPost('RestoreDefaults') !==null) $backUrl
Определения options.php:66
const IM_MESSAGE_SYSTEM
Определения include.php:21
const IM_NOTIFY_SYSTEM
Определения include.php:38
const IM_NOTIFY_FROM
Определения include.php:37
$arPaths
Определения options.php:169
global $DB
Определения cron_frame.php:29
$siteID
Определения cron_frame.php:12
global $USER
Определения csv_new_run.php:40
$ACTION
Определения csv_new_setup.php:27
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
const BX_RESIZE_IMAGE_EXACT
Определения constants.php:12
const SITE_DIR(!defined('LANG'))
Определения include.php:72
$z
Определения options.php:31
$arCodes
Определения options.php:154
$siteId
Определения ajax.php:8
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
htmlspecialcharsback($str)
Определения tools.php:2693
IsModuleInstalled($module_id)
Определения tools.php:5301
htmlspecialcharsEx($str)
Определения tools.php:2685
HTMLToTxt($str, $strSiteUrl="", $aDelete=[], $maxlen=70)
Определения tools.php:2587
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
GetTime($timestamp, $type="SHORT", $site=false, $bSearchInSitesOnly=false)
Определения tools.php:1890
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
BXClearCache($full=false, $initdir='')
Определения tools.php:5150
check_email($email, $strict=false, $domainCheck=false)
Определения tools.php:4571
MakeTimeStamp($datetime, $format=false)
Определения tools.php:538
$email
Определения payment.php:49
if(intval($iTestTransaction) > 0) $arTmp
Определения payment.php:22
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$post
Определения template.php:8
$title
Определения pdf.php:123
$val
Определения options.php:1793
$matches
Определения index.php:22
const SONET_ROLES_USER
Определения include.php:31
const SONET_ENTITY_GROUP
Определения include.php:117
const SONET_ROLES_AUTHORIZED
Определения include.php:36
const SONET_ENTITY_USER
Определения include.php:118
const SONET_ROLES_MODERATOR
Определения include.php:30
const SONET_ROLES_OWNER
Определения include.php:29
const SONET_ROLES_ALL
Определения include.php:35
$arRes
Определения options.php:104
const SITE_ID
Определения sonet_set_content_view.php:12
$GLOBALS['_____370096793']
Определения update_client.php:1
$dbResult
Определения updtr957.php:3
$arFilter
Определения user_search.php:106
$url
Определения iframe.php:7
$dbRes
Определения yandex_detail.php:168
$arIBlock['PROPERTY']
Определения yandex_detail.php:172