1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
blog_search.php
См. документацию.
1<?php
2
4
6{
7 public static function fillSearchPermsWithSonetGroupData($sonetPerms, $authorId, &$arSearchIndex = array(), $arParams = array()): void
8 {
9 if (is_array($sonetPerms))
10 {
11 if (
12 is_array($arParams)
13 && isset($arParams['INIT_PERMISSIONS'])
14 && $arParams['INIT_PERMISSIONS'] === 'Y'
15 )
16 {
17 $arSearchIndex['PERMISSIONS'] = $sonetPerms;
18 }
19
20 if (!in_array('U'.$authorId, $arSearchIndex['PERMISSIONS'], true))
21 {
22 $arSearchIndex['PERMISSIONS'][] = 'U' . $authorId;
23 }
24
25 $sgId = [];
26
27 foreach ($sonetPerms as $perm)
28 {
29 if (mb_strpos($perm, 'SG') === 0)
30 {
31 $sgIdTmp = (int)str_replace('SG', '', mb_substr($perm, 0, mb_strpos($perm, '_')));
32 if (
33 $sgIdTmp > 0
34 && !in_array($sgIdTmp, $sgId, true)
35 )
36 {
37 $sgId[] = $sgIdTmp;
38 }
39 }
40 elseif(preg_match('/^OSG(\d+)_([' . SONET_ROLES_AUTHORIZED . SONET_ROLES_ALL . '])$/', $perm, $matches))
41 {
42 if (
43 !Loader::includeModule('socialnetwork')
44 || !\Bitrix\Socialnetwork\Helper\Workgroup::checkAnyOpened([ (int)$matches[1] ])
45 )
46 {
47 continue;
48 }
49
50 if (
52 && !in_array('G2', $arSearchIndex['PERMISSIONS'], true)
53 )
54 {
55 $arSearchIndex['PERMISSIONS'][] = 'G2';
56 }
57 if (
59 && !in_array('AU', $arSearchIndex['PERMISSIONS'], true)
60 )
61 {
62 $arSearchIndex['PERMISSIONS'][] = 'AU';
63 }
64 }
65 }
66
67 if (!empty($sgId))
68 {
69 $arSearchIndex['PARAMS'] = [
70 'socnet_group' => $sgId,
71 'entity' => 'socnet_group',
72 ];
73 }
74 }
75 }
76
77 public static function fillSearchParamsWithMentionData($arMentionedUserID = array(), &$arSearchIndex = array())
78 {
79 if (!empty($arMentionedUserID))
80 {
81 if (!isset($arSearchIndex["PARAMS"]))
82 {
83 $arSearchIndex["PARAMS"] = array();
84 }
85 $arSearchIndex["PARAMS"]["mentioned_user_id"] = $arMentionedUserID;
86 }
87 }
88
89 public static function OnSearchReindex($NS=Array(), $oCallback=NULL, $callback_method="")
90 {
92 static $blogPostEventIdList = null;
93
94 $arResult = array();
95 //CBlogSearch::Trace('OnSearchReindex', 'NS', $NS);
96 if($NS["MODULE"]=="blog" && $NS["ID"] <> '')
97 {
98 $category = mb_substr($NS["ID"], 0, 1);
99 $id = intval(mb_substr($NS["ID"], 1));
100 }
101 else
102 {
103 $category = 'B';//start with blogs
104 $id = 0;//very first id
105 }
106
107 //CBlogSearch::Trace('OnSearchReindex', 'category+id', array("CATEGORY"=>$category,"ID"=>$id));
108
109 //Reindex blogs
110 if($category == 'B')
111 {
112 $strSql = "
113 SELECT
114 b.ID
115 ,bg.SITE_ID
116 ,b.REAL_URL
117 ,b.URL
118 ,".$DB->DateToCharFunction("b.DATE_UPDATE")." as DATE_UPDATE
119 ,b.NAME
120 ,b.DESCRIPTION
121 ,b.OWNER_ID
122 ,b.SOCNET_GROUP_ID
123 ,b.USE_SOCNET
124 ,b.SEARCH_INDEX
125 FROM
126 b_blog b
127 INNER JOIN b_blog_group bg ON (b.GROUP_ID = bg.ID)
128 WHERE
129 b.ACTIVE = 'Y'
130 AND b.SEARCH_INDEX = 'Y'
131 ".($NS["SITE_ID"]!=""?"AND bg.SITE_ID='".$DB->ForSQL($NS["SITE_ID"])."'":"")."
132 AND b.ID > ".$id."
133 ORDER BY
134 b.ID
135 ";
136 //CBlogSearch::Trace('OnSearchReindex', 'strSql', $strSql);
137 $rs = $DB->Query($strSql);
138 while($ar = $rs->Fetch())
139 {
140 if($ar["USE_SOCNET"] == "Y")
141 {
142 $Result = Array(
143 "ID" =>"B".$ar["ID"],
144 "BODY" => "",
145 "TITLE" => ""
146 );
147
148 }
149 else
150 {
151 //CBlogSearch::Trace('OnSearchReindex', 'ar', $ar);
152 $arSite = array(
153 $ar["SITE_ID"] => CBlog::PreparePath($ar["URL"], $ar["SITE_ID"], false, $ar["OWNER_ID"], $ar["SOCNET_GROUP_ID"]),
154 );
155 //CBlogSearch::Trace('OnSearchReindex', 'arSite', $arSite);
156 $Result = Array(
157 "ID" =>"B".$ar["ID"],
158 "LAST_MODIFIED" =>$ar["DATE_UPDATE"],
159 "TITLE" =>$ar["NAME"],
160 "BODY" =>blogTextParser::killAllTags($ar["DESCRIPTION"]),
161 "SITE_ID" =>$arSite,
162 "PARAM1" =>"BLOG",
163 "PARAM2" =>$ar["OWNER_ID"],
164 "PERMISSIONS" =>array(2),
165 );
166 //CBlogSearch::Trace('OnSearchReindex', 'Result', $Result);
167 }
168 if($oCallback)
169 {
170 $res = call_user_func(array($oCallback, $callback_method), $Result);
171 if(!$res)
172 return $Result["ID"];
173 }
174 else
175 {
176 $arResult[] = $Result;
177 }
178 }
179 //all blogs indexed so let's start index posts
180 $category='P';
181 $id=0;
182 }
183 if($category == 'P')
184 {
185 $arUser2Blog = Array();
186 if(COption::GetOptionString("blog", "socNetNewPerms", "N") == "N")
187 {
188 $dbB = CBlog::GetList(array(), Array("USE_SOCNET" => "Y", "!OWNER_ID" => false), false, false, Array("ID", "OWNER_ID", "USE_SOCNET", "GROUP_ID"));
189 while($arB = $dbB->Fetch())
190 {
191 $arUser2Blog[$arB["OWNER_ID"]][$arB["GROUP_ID"]] = $arB["ID"];
192 }
193 }
194
195 $bSonet = false;
196 if(IsModuleInstalled("socialnetwork"))
197 {
198 $bSonet = true;
199 if (
200 $blogPostEventIdList === null
201 && Loader::includeModule("socialnetwork")
202 )
203 {
204 $blogPostLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\BlogPost;
205 $blogPostEventIdList = $blogPostLivefeedProvider->getEventId();
206 }
207 }
208
209 $parserBlog = new blogTextParser(false, "/bitrix/images/blog/smile/");
210
211 $strSql = "
212 SELECT
213 bp.ID
214 ,bg.SITE_ID
215 ,b.REAL_URL
216 ,b.URL
217 ,".$DB->DateToCharFunction("bp.DATE_PUBLISH")." as DATE_PUBLISH
218 ,bp.TITLE
219 ,bp.DETAIL_TEXT
220 ,bp.BLOG_ID
221 ,b.OWNER_ID
222 ,bp.CATEGORY_ID
223 ,b.SOCNET_GROUP_ID
224 ,b.USE_SOCNET
225 ,b.SEARCH_INDEX
226 ,b.GROUP_ID
227 ,bp.PATH
228 ,bp.MICRO
229 ,bp.PUBLISH_STATUS
230 ,bp.AUTHOR_ID ".
231 ($bSonet ? ", BSL.ID as SLID" : "").
232 " FROM
233 b_blog_post bp
234 INNER JOIN b_blog b ON (bp.BLOG_ID = b.ID)
235 INNER JOIN b_blog_group bg ON (b.GROUP_ID = bg.ID) ".
236 ($bSonet ? "LEFT JOIN b_sonet_log BSL ON (BSL.EVENT_ID in ('".implode("', '", $blogPostEventIdList)."') AND BSL.SOURCE_ID = bp.ID) " : "").
237 " WHERE
238 bp.DATE_PUBLISH <= ".$DB->CurrentTimeFunction()."
239 AND b.ACTIVE = 'Y'
240 ".($NS["SITE_ID"]!=""?"AND bg.SITE_ID='".$DB->ForSQL($NS["SITE_ID"])."'":"")."
241 AND bp.ID > ".$id."
242
243 ORDER BY
244 bp.ID
245 ";
246
247 $limit = 1000;
248 $strSql = \Bitrix\Main\Application::getConnection()->getSqlHelper()->getTopSql($strSql, $limit);
249
250 /* AND bp.PUBLISH_STATUS = '".$DB->ForSQL(BLOG_PUBLISH_STATUS_PUBLISH)."'*/
251 //AND b.SEARCH_INDEX = 'Y'
252 //CBlogSearch::Trace('OnSearchReindex', 'strSql', $strSql);
253 $rs = $DB->Query($strSql);
254 while($ar = $rs->Fetch())
255 {
256 //Check permissions
257 $tag = "";
258 if($ar["USE_SOCNET"] != "Y")
259 {
260 $PostPerms = CBlogUserGroup::GetGroupPerms(1, $ar["BLOG_ID"], $ar["ID"], BLOG_PERMS_POST);
261 if($PostPerms < BLOG_PERMS_READ)
262 continue;
263 }
264 //CBlogSearch::Trace('OnSearchReindex', 'ar', $ar);
265 if($ar["PATH"] <> '')
266 {
267 $arSite = array(
268 $ar["SITE_ID"] => str_replace("#post_id#", $ar["ID"], $ar["PATH"])
269 );
270 }
271 else
272 {
273 $arSite = array(
274 $ar["SITE_ID"] => CBlogPost::PreparePath($ar["URL"], $ar["ID"], $ar["SITE_ID"], false, $ar["OWNER_ID"], $ar["SOCNET_GROUP_ID"]),
275 );
276 }
277
278 if($ar["CATEGORY_ID"] <> '')
279 {
280 $arC = explode(",", $ar["CATEGORY_ID"]);
281 $tag = "";
282 $arTag = Array();
283 foreach($arC as $v)
284 {
285 $arCategory = CBlogCategory::GetByID($v);
286 $arTag[] = $arCategory["NAME"];
287 }
288 $tag = implode(",", $arTag);
289 }
290
291 $searchContent = blogTextParser::killAllTags($ar["DETAIL_TEXT"]);
292 $searchContent .= "\r\n" . $USER_FIELD_MANAGER->OnSearchIndex("BLOG_POST", $ar["ID"]);
293
294 //CBlogSearch::Trace('OnSearchReindex', 'arSite', $arSite);
295 $Result = Array(
296 "ID" => "P".$ar["ID"],
297 "LAST_MODIFIED" => $ar["DATE_PUBLISH"],
298 "TITLE" => CSearch::KillTags(blogTextParser::killAllTags($ar["MICRO"] == "Y" ? $ar["TITLE"] : htmlspecialcharsEx($ar["TITLE"]))),
299 "BODY" => CSearch::KillTags($searchContent),
300 "SITE_ID" => $arSite,
301 "PARAM1" => "POST",
302 "PARAM2" => $ar["BLOG_ID"],
303 "PERMISSIONS" =>array(2),//public
304 "TAGS" => $tag,
305 "USER_ID" => $ar["AUTHOR_ID"],
306 "ENTITY_TYPE_ID" => "BLOG_POST",
307 "ENTITY_ID" => $ar["ID"],
308 );
309
310 if($ar["USE_SOCNET"] == "Y" && CModule::IncludeModule("socialnetwork"))
311 {
312 $arF = Array();
313 if(COption::GetOptionString("blog", "socNetNewPerms", "N") == "N")
314 {
315 if(intval($ar["SOCNET_GROUP_ID"]) > 0)
316 {
317 $newBlogId = 0;
318 if(intval($arUser2Blog[$ar["AUTHOR_ID"]][$ar["GROUP_ID"]]) > 0)
319 {
320 $newBlogId = intval($arUser2Blog[$ar["AUTHOR_ID"]][$ar["GROUP_ID"]]);
321 }
322 else
323 {
325 "=DATE_UPDATE" => $DB->CurrentTimeFunction(),
326 "GROUP_ID" => $ar["GROUP_ID"],
327 "ACTIVE" => "Y",
328 "ENABLE_COMMENTS" => "Y",
329 "ENABLE_IMG_VERIF" => "Y",
330 "EMAIL_NOTIFY" => "Y",
331 "ENABLE_RSS" => "Y",
332 "ALLOW_HTML" => "N",
333 "ENABLE_TRACKBACK" => "N",
334 "SEARCH_INDEX" => "Y",
335 "USE_SOCNET" => "Y",
336 "=DATE_CREATE" => $DB->CurrentTimeFunction(),
337 "PERMS_POST" => Array(
338 1 => "I",
339 2 => "I" ),
340 "PERMS_COMMENT" => Array(
341 1 => "P",
342 2 => "P" ),
343 );
344
345 $bRights = false;
346 $rsUser = CUser::GetByID($ar["AUTHOR_ID"]);
347 $arUser = $rsUser->Fetch();
348 if($arUser["NAME"]."".$arUser["LAST_NAME"] == '')
349 $arFields["NAME"] = GetMessage("BLG_NAME")." ".$arUser["LOGIN"];
350 else
351 $arFields["NAME"] = GetMessage("BLG_NAME")." ".$arUser["NAME"]." ".$arUser["LAST_NAME"];
352
353 $arFields["URL"] = str_replace(" ", "_", $arUser["LOGIN"])."-blog-".$ar["SITE_ID"];
354 $arFields["OWNER_ID"] = $ar["AUTHOR_ID"];
355
356 $urlCheck = preg_replace("/[^a-zA-Z0-9_-]/is", "", $arFields["URL"]);
357 if ($urlCheck != $arFields["URL"])
358 {
359 $arFields["URL"] = "u".$arUser["ID"]."-blog-".$ar["SITE_ID"];
360 }
361
362 if(CBlog::GetByUrl($arFields["URL"]))
363 {
364 $uind = 0;
365 do
366 {
367 $uind++;
368 $arFields["URL"] = $arFields["URL"].$uind;
369 }
370 while (CBlog::GetByUrl($arFields["URL"]));
371 }
372
373 $featureOperationPerms = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_USER, $ar["AUTHOR_ID"], "blog", "view_post");
374 if ($featureOperationPerms == SONET_RELATIONS_TYPE_ALL)
375 $bRights = true;
376
377 $blogID = CBlog::Add($arFields);
378
379 if($bRights)
380 CBlog::AddSocnetRead($blogID);
381
382 $newBlogId = $blogID;
383 $arUser2Blog[$arFields["OWNER_ID"]][$arFields["GROUP_ID"]] = $newBlogId;
384 }
385
386 if(intval($newBlogId) > 0)
387 {
388 $arF = Array(
389 "BLOG_ID" => $newBlogId,
390 "SOCNET_RIGHTS" => Array("SG".$ar["SOCNET_GROUP_ID"]),
391 );
392 }
393
394 if(intval($ar["SLID"]) > 0)
395 {
396 CSocNetLog::Delete($ar["SLID"]);
397 $ar["SLID"] = 0;
398 }
399
400 $arSites = array();
401 $rsGroupSite = CSocNetGroup::GetSite($ar["SOCNET_GROUP_ID"]);
402 while($arGroupSite = $rsGroupSite->Fetch())
403 $arSites[] = $arGroupSite["LID"];
404 }
405 else
406 {
407 $newBlogId = 0;
408 if($ar["OWNER_ID"] != $ar["AUTHOR_ID"])
409 {
410 if(intval($arUser2Blog[$ar["AUTHOR_ID"]][$ar["GROUP_ID"]]) > 0)
411 {
412 $newBlogId = intval($arUser2Blog[$ar["AUTHOR_ID"]][$ar["GROUP_ID"]]);
413 }
414 else
415 {
417 "=DATE_UPDATE" => $DB->CurrentTimeFunction(),
418 "GROUP_ID" => $ar["GROUP_ID"],
419 "ACTIVE" => "Y",
420 "ENABLE_COMMENTS" => "Y",
421 "ENABLE_IMG_VERIF" => "Y",
422 "EMAIL_NOTIFY" => "Y",
423 "ENABLE_RSS" => "Y",
424 "ALLOW_HTML" => "N",
425 "ENABLE_TRACKBACK" => "N",
426 "SEARCH_INDEX" => "Y",
427 "USE_SOCNET" => "Y",
428 "=DATE_CREATE" => $DB->CurrentTimeFunction(),
429 "PERMS_POST" => Array(
430 1 => "I",
431 2 => "I" ),
432 "PERMS_COMMENT" => Array(
433 1 => "P",
434 2 => "P" ),
435 );
436
437 $bRights = false;
438 $rsUser = CUser::GetByID($ar["AUTHOR_ID"]);
439 $arUser = $rsUser->Fetch();
440 if($arUser["NAME"]."".$arUser["LAST_NAME"] == '')
441 $arFields["NAME"] = GetMessage("BLG_NAME")." ".$arUser["LOGIN"];
442 else
443 $arFields["NAME"] = GetMessage("BLG_NAME")." ".$arUser["NAME"]." ".$arUser["LAST_NAME"];
444
445 $arFields["URL"] = str_replace(" ", "_", $arUser["LOGIN"])."-blog-".$ar["SITE_ID"];
446 $arFields["OWNER_ID"] = $ar["AUTHOR_ID"];
447
448 $urlCheck = preg_replace("/[^a-zA-Z0-9_-]/is", "", $arFields["URL"]);
449 if ($urlCheck != $arFields["URL"])
450 {
451 $arFields["URL"] = "u".$arUser["ID"]."-blog-".$ar["SITE_ID"];
452 }
453
454 if(CBlog::GetByUrl($arFields["URL"]))
455 {
456 $uind = 0;
457 do
458 {
459 $uind++;
460 $arFields["URL"] = $arFields["URL"].$uind;
461 }
462 while (CBlog::GetByUrl($arFields["URL"]));
463 }
464
465 $featureOperationPerms = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_USER, $ar["AUTHOR_ID"], "blog", "view_post");
466 if ($featureOperationPerms == SONET_RELATIONS_TYPE_ALL)
467 $bRights = true;
468
469 $blogID = CBlog::Add($arFields);
470 if($bRights)
471 CBlog::AddSocnetRead($blogID);
472 $newBlogId = $blogID;
473
474 $arUser2Blog[$arFields["OWNER_ID"]][$arFields["GROUP_ID"]] = $newBlogId;
475 }
476 if(intval($ar["SLID"]) > 0)
477 {
478 CSocNetLog::Delete($ar["SLID"]);
479 $ar["SLID"] = 0;
480 }
481 }
482 $arF = Array("SOCNET_RIGHTS" => Array());
483 if(intval($newBlogId) > 0)
484 $arF["BLOG_ID"] = $newBlogId;
485
486 $arSites = array($ar["SITE_ID"]);
487 }
488
489 if(!empty($arF))
490 {
491 if(intval($arF["BLOG_ID"]) > 0)
492 {
493 $Result["PARAM2"] = $ar["BLOG_ID"];
494 $sqlR = "UPDATE b_blog_post SET BLOG_ID=".intval($arF["BLOG_ID"])." WHERE ID=".intval($ar["ID"]);
495 $DB->Query($sqlR);
496 $sqlR = "UPDATE b_blog_post_category SET BLOG_ID=".intval($arF["BLOG_ID"])." WHERE POST_ID=".intval($ar["ID"]);
497 $DB->Query($sqlR);
498 $sqlR = "UPDATE b_blog_image SET BLOG_ID=".intval($arF["BLOG_ID"])." WHERE POST_ID=".intval($ar["ID"]);
499 $DB->Query($sqlR);
500 $sqlR = "UPDATE b_blog_comment SET BLOG_ID=".intval($arF["BLOG_ID"])." WHERE POST_ID=".intval($ar["ID"]);
501 $DB->Query($sqlR);
502 }
503 $sqlR = "SELECT * FROM b_blog_socnet_rights where POST_ID=".intval($ar["ID"]);
504 $dbBB = $DB->Query($sqlR);
505 if(!$dbBB->Fetch())
506 {
507 $arF["SC_PERM"] = CBlogPost::UpdateSocNetPerms($ar["ID"], $arF["SOCNET_RIGHTS"], Array("AUTHOR_ID" => $ar["AUTHOR_ID"]));
508 }
509 if(intval($arF["BLOG_ID"]) > 0 && $ar["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH)
510 {
511 $dbComment = CBlogComment::GetList(Array(), Array("POST_ID" => $ar["ID"]), false, false, Array("ID", "POST_ID", "BLOG_ID", "PATH"));
512 if($arComment = $dbComment->Fetch())
513 {
514 $arParamsComment = Array(
515 "BLOG_ID" => $arF["BLOG_ID"],
516 "POST_ID" => $ar["ID"],
517 "SITE_ID" => $ar["SITE_ID"],
518 "PATH" => $arPostSite[$arGroup["SITE_ID"]]."?commentId=#comment_id##com#comment_id#",
519 "USE_SOCNET" => "Y",
520 );
521 CBlogComment::_IndexPostComments($arParamsComment);
522 }
523 }
524 }
525 }
526
527 if($ar["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH)
528 {
529 if(empty($arF["SC_PERM"]))
530 {
531 $arF["SC_PERM"] = CBlogPost::GetSocNetPermsCode($ar["ID"]);
532 }
533
534 CBlogSearch::fillSearchPermsWithSonetGroupData($arF["SC_PERM"], $ar["AUTHOR_ID"], $Result, array("INIT_PERMISSIONS" => "Y"));
535
536 // get mentions and grats
538
539 $socnetPerms = false;
540
541 if(intval($ar["SLID"]) <= 0)
542 {
543 $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");
544 $text4message = $parserBlog->convert($ar["DETAIL_TEXT"], false, array(), $arAllow, array("isSonetLog"=>true));
545
546 $arSoFields = Array(
547 "EVENT_ID" => "blog_post",
548 "=LOG_DATE" => $DB->CharToDateFunction($ar["DATE_PUBLISH"], "FULL", SITE_ID),
549 "LOG_UPDATE" => $DB->CharToDateFunction($ar["DATE_PUBLISH"], "FULL", SITE_ID),
550 "TITLE_TEMPLATE" => "#USER_NAME# add post",
551 "TITLE" => $ar["TITLE"],
552 "MESSAGE" => $text4message,
553 "MODULE_ID" => "blog",
554 "CALLBACK_FUNC" => false,
555 "SOURCE_ID" => $ar["ID"],
556 "ENABLE_COMMENTS" => "Y",
557 "ENTITY_TYPE" => SONET_ENTITY_USER,
558 "ENTITY_ID" => $ar["AUTHOR_ID"],
559 "USER_ID" => $ar["AUTHOR_ID"],
560 "URL" => $arSite[$ar["SITE_ID"]],
561 "SITE_ID" => $arSites
562 );
563 $logID = CSocNetLog::Add($arSoFields, false);
564 if (intval($logID) > 0)
565 {
566 $socnetPerms = $arF["SC_PERM"];
567
568 if(!in_array("U".$ar["AUTHOR_ID"], $socnetPerms))
569 $socnetPerms[] = "U".$ar["AUTHOR_ID"];
570 $socnetPerms[] = "SA"; // socnet admin
571 CSocNetLog::Update($logID, array("TMP_ID" => $logID, "=LOG_UPDATE" => $arSoFields["LOG_UPDATE"]));
572 }
573 }
574 else
575 {
576 $socnetPerms = $arF["SC_PERM"];
577
578 if(!in_array("U".$ar["AUTHOR_ID"], $socnetPerms))
579 $socnetPerms[] = "U".$ar["AUTHOR_ID"];
580 $socnetPerms[] = "SA"; // socnet admin
581 $logID = $ar["SLID"];
582 }
583
584 if (
585 intval($logID) > 0
586 && is_array($socnetPerms)
587 )
588 {
589 if (
590 in_array("AU", $socnetPerms)
591 || in_array("G2", $socnetPerms)
592 )
593 {
594 $socnetPermsAdd = array();
595
596 foreach($socnetPerms as $perm_tmp)
597 {
598 if (preg_match('/^SG(\d+)$/', $perm_tmp, $matches))
599 {
600 if (
601 !in_array("SG".$matches[1]."_".SONET_ROLES_USER, $socnetPerms)
602 && !in_array("SG".$matches[1]."_".SONET_ROLES_MODERATOR, $socnetPerms)
603 && !in_array("SG".$matches[1]."_".SONET_ROLES_OWNER, $socnetPerms)
604 )
605 $socnetPermsAdd[] = "SG".$matches[1]."_".SONET_ROLES_USER;
606
607 }
608 }
609 if (count($socnetPermsAdd) > 0)
610 $socnetPerms = array_merge($socnetPerms, $socnetPermsAdd);
611 }
612
614 CSocNetLogRights::Add($logID, $socnetPerms, false, false);
615 }
616 }
617 }
618
619 if($ar["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH && $ar["SEARCH_INDEX"] == "Y")
620 {
621 //CBlogSearch::Trace('OnSearchReindex', 'Result', $Result);
622 if($oCallback)
623 {
624 $res = call_user_func(array($oCallback, $callback_method), $Result);
625 if(!$res)
626 return $Result["ID"];
627 }
628 else
629 {
630 $arResult[] = $Result;
631 }
632
633 $limit--;
634 if ($limit <= 0)
635 {
636 return $Result["ID"];
637 }
638 }
639 }
640
641 //all blog posts indexed so let's start index users
642 $category='C';
643 $id=0;
644 COption::SetOptionString("blog", "socNetNewPerms", "Y");
645 }
646 if($category == 'C')
647 {
648 $bSonet = CModule::IncludeModule("socialnetwork");
649
650 $strSql = "
651 SELECT
652 bc.ID
653 ,bg.SITE_ID
654 ,bp.ID as POST_ID
655 ,b.URL
656 ,bp.TITLE as POST_TITLE
657 ,b.OWNER_ID
658 ,b.SOCNET_GROUP_ID
659 ,bc.TITLE
660 ,bc.POST_TEXT
661 ,bc.POST_ID
662 ,bc.BLOG_ID
663 ,b.USE_SOCNET
664 ,b.SEARCH_INDEX
665 ,bc.PATH
666 ,".$DB->DateToCharFunction("bc.DATE_CREATE")." as DATE_CREATE
667 ,bc.AUTHOR_ID
668 FROM
669 b_blog_comment bc
670 INNER JOIN b_blog_post bp ON (bp.ID = bc.POST_ID)
671 INNER JOIN b_blog b ON (bc.BLOG_ID = b.ID)
672 INNER JOIN b_blog_group bg ON (b.GROUP_ID = bg.ID)
673 WHERE
674 bc.ID > ".$id."
675 ".($NS["SITE_ID"]!=""?" AND bg.SITE_ID='".$DB->ForSQL($NS["SITE_ID"])."'":"")."
676 AND b.SEARCH_INDEX = 'Y'
677 ORDER BY
678 bc.ID
679 ";
680
681 $limit = 1000;
682 $strSql = \Bitrix\Main\Application::getConnection()->getSqlHelper()->getTopSql($strSql, $limit);
683
684 //CBlogSearch::Trace('OnSearchReindex', 'strSql', $strSql);
685 $rs = $DB->Query($strSql);
686 while($ar = $rs->Fetch())
687 {
688 //Check permissions
689 $tag = "";
690 $PostPerms = CBlogUserGroup::GetGroupPerms(1, $ar["BLOG_ID"], $ar["POST_ID"], BLOG_PERMS_POST);
691 if($PostPerms < BLOG_PERMS_READ)
692 {
693 continue;
694 }
695
696 if ($bSonet)
697 {
699 if($handlerManager->getHandlerByPostText($ar["POST_TEXT"]))
700 {
701 continue;
702 }
703 }
704
705 //CBlogSearch::Trace('OnSearchReindex', 'ar', $ar);
706 if($ar["PATH"] <> '')
707 {
708 $arSite = array(
709 $ar["SITE_ID"] => str_replace("#comment_id#", $ar["ID"], $ar["PATH"])
710 );
711 }
712 else
713 {
714 $arSite = array(
715 $ar["SITE_ID"] => CBlogPost::PreparePath($ar["URL"], $ar["POST_ID"], $ar["SITE_ID"], false, $ar["OWNER_ID"], $ar["SOCNET_GROUP_ID"]),
716 );
717 }
718
719 $searchContent = blogTextParser::killAllTags($ar["POST_TEXT"]);
720 $searchContent .= "\r\n" . $USER_FIELD_MANAGER->OnSearchIndex("BLOG_COMMENT", $ar["ID"]);
721
722 $Result = array(
723 "ID" => "C".$ar["ID"],
724 "SITE_ID" => $arSite,
725 "LAST_MODIFIED" => $ar["DATE_CREATE"],
726 "PARAM1" => "COMMENT",
727 "PARAM2" => $ar["BLOG_ID"]."|".$ar["POST_ID"],
728 "PERMISSIONS" => array(2),
729 "TITLE" => CSearch::KillTags($ar["TITLE"]),
730 "BODY" => CSearch::KillTags($searchContent),
731 "INDEX_TITLE" => false,
732 "USER_ID" => (intval($ar["AUTHOR_ID"]) > 0) ? $ar["AUTHOR_ID"] : false,
733 "ENTITY_TYPE_ID" => "BLOG_COMMENT",
734 "ENTITY_ID" => $ar["ID"],
735 );
736
737 if($ar["USE_SOCNET"] == "Y")
738 {
739 $arSp = CBlogComment::GetSocNetCommentPerms($ar["POST_ID"]);
740 CBlogSearch::fillSearchPermsWithSonetGroupData($arSp, $ar["AUTHOR_ID"], $Result, array("INIT_PERMISSIONS" => "Y"));
741
742 // get mentions
744 }
745
746 if($ar["TITLE"] == '')
747 {
748 $Result["TITLE"] = mb_substr(CSearch::KillTags($searchContent), 0, 100);
749 }
750
751 if($oCallback)
752 {
753 $res = call_user_func(array($oCallback, $callback_method), $Result);
754 if(!$res)
755 return $Result["ID"];
756 }
757 else
758 {
759 $arResult[] = $Result;
760 }
761
762 $limit--;
763 if ($limit <= 0)
764 {
765 return $Result["ID"];
766 }
767 }
768
769 //all blog posts indexed so let's start index users
770 $category='U';
771 $id=0;
772 }
773
774 if($category == 'U')
775 {
776 $strSql = "
777 SELECT
778 bu.ID
779 ,bg.SITE_ID
780 ,".$DB->DateToCharFunction("bu.LAST_VISIT")." as LAST_VISIT
781 ,".$DB->DateToCharFunction("u.DATE_REGISTER")." as DATE_REGISTER
782 ,bu.ALIAS
783 ,bu.DESCRIPTION
784 ,bu.INTERESTS
785 ,u.NAME
786 ,u.LAST_NAME
787 ,u.LOGIN
788 ,bu.USER_ID
789 ,b.OWNER_ID
790 ,b.USE_SOCNET
791 ,b.SEARCH_INDEX
792 FROM
793 b_blog_user bu
794 INNER JOIN b_user u ON (u.ID = bu.USER_ID)
795 INNER JOIN b_blog b ON (u.ID = b.OWNER_ID)
796 INNER JOIN b_blog_group bg ON (b.GROUP_ID = bg.ID)
797 WHERE
798 b.ACTIVE = 'Y'
799 ".($NS["SITE_ID"]!=""?"AND bg.SITE_ID='".$DB->ForSQL($NS["SITE_ID"])."'":"")."
800 AND bu.ID > ".$id."
801 AND b.SEARCH_INDEX = 'Y'
802 ORDER BY
803 bu.ID
804 ";
805 //CBlogSearch::Trace('OnSearchReindex', 'strSql', $strSql);
806 $rs = $DB->Query($strSql);
807 while($ar = $rs->Fetch())
808 {
809 if($ar["USE_SOCNET"] == "Y")
810 {
811 $Result = Array(
812 "ID" =>"U".$ar["ID"],
813 "BODY" => "",
814 "TITLE" => ""
815 );
816 }
817 else
818 {
819 //CBlogSearch::Trace('OnSearchReindex', 'ar', $ar);
820 $arSite = array(
821 $ar["SITE_ID"] => CBlogUser::PreparePath($ar["USER_ID"], $ar["SITE_ID"]),
822 );
823 //CBlogSearch::Trace('OnSearchReindex', 'arSite', $arSite);
824 $Result = Array(
825 "ID" =>"U".$ar["ID"],
826 "LAST_MODIFIED" =>$ar["LAST_VISIT"],
827 "TITLE" =>CBlogUser::GetUserName($ar["ALIAS"], $ar["NAME"], $ar["LAST_NAME"], $ar["LOGIN"]),
828 "BODY" =>blogTextParser::killAllTags($ar["DESCRIPTION"]." ".$ar["INTERESTS"]),
829 "SITE_ID" =>$arSite,
830 "PARAM1" =>"USER",
831 "PARAM2" =>$ar["ID"],
832 "PERMISSIONS" =>array(2),//public
833 //TODO????"URL" =>$DETAIL_URL,
834 );
835 if($Result["LAST_MODIFIED"] == '')
836 $Result["LAST_MODIFIED"] = $ar["DATE_REGISTER"];
837 }
838
839 //CBlogSearch::Trace('OnSearchReindex', 'Result', $Result);
840 if($oCallback)
841 {
842 $res = call_user_func(array($oCallback, $callback_method), $Result);
843 if(!$res)
844 return $Result["ID"];
845 }
846 else
847 {
848 $arResult[] = $Result;
849 }
850 }
851 }
852
853 if($oCallback)
854 return false;
855
856 return $arResult;
857 }
858
859 public static function Trace($method, $varname, $var)
860 {
861 //return;
862 ob_start();print_r($var);$m=ob_get_contents();ob_end_clean();
863 $m=" CBlogSearch::$method:$varname:$m\n";$f=fopen($_SERVER["DOCUMENT_ROOT"]."/debug.log", "a");
864 fwrite($f, time().$m);fclose($f);
865 }
866
867 public static function SetSoNetFeatureIndexSearch($ID, $arFields)
868 {
869 if(CModule::IncludeModule("socialnetwork"))
870 {
871 $feature = CSocNetFeatures::GetByID($ID);
872 if($feature["FEATURE"] == "blog")
873 {
874 if(intval($feature["ENTITY_ID"]) > 0)
875 {
876 $bRights = false;
877 $arFilter = Array("USE_SOCNET" => "Y");
878
879 if($feature["ENTITY_TYPE"] == "U")
880 {
881 $arFilter["OWNER_ID"] = $feature["ENTITY_ID"];
882 $featureOperationPerms = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_USER, $feature["ENTITY_ID"], "blog", "view_post");
883 if ($featureOperationPerms == SONET_RELATIONS_TYPE_ALL)
884 {
885 $bRights = true;
886 }
887 }
888 else
889 {
890 $arFilter["SOCNET_GROUP_ID"] = $feature["ENTITY_ID"];
891 $featureOperationPerms = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_GROUP, $feature["ENTITY_ID"], "blog", "view_post");
892 if ($featureOperationPerms == SONET_ROLES_ALL)
893 {
894 $bRights = true;
895 }
896 }
897
898 $dbBlog = CBlog::GetList(Array(), $arFilter, false, Array("nTopCount" => 1), Array("ID", "SOCNET_GROUP_ID"));
899 if($arBlog = $dbBlog->Fetch())
900 {
901 if (intval($arBlog["SOCNET_GROUP_ID"]) > 0 && CModule::IncludeModule("socialnetwork") && method_exists("CSocNetGroup", "GetSite"))
902 {
903 $arSites = array();
904 $rsGroupSite = CSocNetGroup::GetSite($arBlog["SOCNET_GROUP_ID"]);
905 while($arGroupSite = $rsGroupSite->Fetch())
906 {
907 $arSites[] = $arGroupSite["LID"];
908 }
909 }
910 else
911 {
913 }
914
915 foreach ($arSites as $site_id_tmp)
916 {
917 BXClearCache(True, "/".$site_id_tmp."/blog/sonet/");
918 }
919
920 if($arFields["ACTIVE"] == "N")
921 {
922 CBlog::DeleteSocnetRead($arBlog["ID"]);
923 }
924 else
925 {
926 if($bRights)
927 {
928 CBlog::AddSocnetRead($arBlog["ID"]);
929 }
930 else
931 {
932 CBlog::DeleteSocnetRead($arBlog["ID"]);
933 }
934 }
935 }
936 }
937 }
938 }
939 }
940
942 {
944 return true;
945 }
946
948 {
949 $permFields = \CSocNetFeaturesPerms::getByID($ID);
951 return true;
952 }
953
955 {
956 if (
957 $fields["OPERATION_ID"] == "view_post"
958 && Loader::includeModule("socialnetwork")
959 )
960 {
961 $feature = CSocNetFeatures::GetByID($fields["FEATURE_ID"]);
962 if (
963 $feature["FEATURE"] == "blog"
964 && $feature["ENTITY_TYPE"] == "G"
965 )
966 {
967 $perm = \CSocNetFeaturesPerms::GetOperationPerm('G', $feature["ENTITY_ID"], 'blog', 'view_post');
968 \Bitrix\Blog\Item\PostSocnetRights::set($feature['ENTITY_ID'], $perm);
969 }
970 }
971 }
972
974 {
975 global $DB;
976
977 $featurePerm = CSocNetFeaturesPerms::GetByID($ID);
978 if($featurePerm["OPERATION_ID"] == "view_post")
979 {
980 if(CModule::IncludeModule("socialnetwork"))
981 {
982 $feature = CSocNetFeatures::GetByID($featurePerm["FEATURE_ID"]);
983 if(
984 $feature["FEATURE"] == "blog"
985 && intval($feature["ENTITY_ID"]) > 0
986 )
987 {
988 if(
989 $feature["ACTIVE"] == "Y"
990 && (
991 ($feature["ENTITY_TYPE"] == "U" && $arFields["ROLE"] == "A")
992 || ($feature["ENTITY_TYPE"] == "G" && $arFields["ROLE"] == "N")
993 )
994 )
995 {
996 $arFilter = Array("USE_SOCNET" => "Y");
997 if($feature["ENTITY_TYPE"] == "U")
998 {
999 $arFilter["OWNER_ID"] = $feature["ENTITY_ID"];
1000 }
1001 else
1002 {
1003 $arFilter["SOCNET_GROUP_ID"] = $feature["ENTITY_ID"];
1004 }
1005 $dbBlog = CBlog::GetList(Array(), $arFilter, false, Array("nTopCount" => 1), Array("ID", "SOCNET_GROUP_ID"));
1006 if($arBlog = $dbBlog->Fetch())
1007 {
1008 CBlog::AddSocnetRead($arBlog["ID"]);
1009 }
1010 }
1011 else
1012 {
1013 $arFilter = Array("USE_SOCNET" => "Y");
1014 if($feature["ENTITY_TYPE"] == "U")
1015 {
1016 $arFilter["OWNER_ID"] = $feature["ENTITY_ID"];
1017 }
1018 else
1019 {
1020 $arFilter["SOCNET_GROUP_ID"] = $feature["ENTITY_ID"];
1021 }
1022 $dbBlog = CBlog::GetList(Array(), $arFilter, false, Array("nTopCount" => 1), Array("ID", "SOCNET_GROUP_ID"));
1023 if($arBlog = $dbBlog->Fetch())
1024 {
1025 CBlog::DeleteSocnetRead($arBlog["ID"]);
1026 }
1027 }
1028
1029 if (
1030 $arBlog
1031 && intval($arBlog["SOCNET_GROUP_ID"]) > 0
1032 )
1033 {
1034 $arSites = array();
1035 $rsGroupSite = CSocNetGroup::GetSite($arBlog["SOCNET_GROUP_ID"]);
1036 while($arGroupSite = $rsGroupSite->Fetch())
1037 {
1038 $arSites[] = $arGroupSite["LID"];
1039 }
1040 }
1041 else
1042 {
1044 }
1045
1046 foreach ($arSites as $site_id_tmp)
1047 {
1048 BXClearCache(True, "/".$site_id_tmp."/blog/sonet/");
1049 }
1050
1051 if ($feature["ENTITY_TYPE"] == "G")
1052 {
1054 'groupId' => $feature["ENTITY_ID"],
1055 'role' => $arFields["ROLE"]
1056 ));
1057 }
1058 }
1059 }
1060 }
1061 }
1062}
$arParams
Определения access_dialog.php:21
$arSites
Определения options.php:15
const BLOG_PERMS_POST
Определения include.php:42
const BLOG_PERMS_READ
Определения include.php:6
const BLOG_PUBLISH_STATUS_PUBLISH
Определения include.php:47
$arResult
Определения generate_coupon.php:16
static set($groupId, $value)
Определения postsocnetrights.php:14
static recalcGroupPostRights($params=array())
Определения postsocnetrights.php:72
static getConnection($name="")
Определения application.php:638
Определения loader.php:13
static GetByID($ID)
Определения blog_category.php:82
static GetSocNetCommentPerms($postID=0)
Определения blog_comment.php:629
static GetMentionedUserID($arFields)
Определения blog_comment.php:888
static _IndexPostComments($arParams=Array())
Определения blog_comment.php:475
static DeleteSocnetRead($ID)
Определения blog.php:1773
static GetByUrl($BLOG_URL, $arGroup=Array())
Определения blog.php:1026
static PreparePath($blogUrl, $siteID=False, $is404=True, $userID=0, $groupID=0)
Определения blog.php:1453
static UpdateSocNetPerms($ID, $perms=array(), $arPost=array())
Определения blog_post.php:1334
static GetMentionedUserID($arFields)
Определения blog_post.php:3654
static PreparePath($blogUrl, $postID=0, $siteID=False, $is404=True, $userID=0, $groupID=0)
Определения blog_post.php:620
static GetSocNetPermsCode($ID)
Определения blog_post.php:1551
static GetGroupPerms($ID, $blogID, $postID=0, $permsType=BLOG_PERMS_POST)
Определения blog_user_group.php:209
static GetUserName($alias, $name, $lastName, $login, $secondName="")
Определения blog_user.php:569
static PreparePath($userID=0, $siteID=False, $is404=True)
Определения blog_user.php:579
static KillTags($str)
Определения search.php:2092
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения blog_comment.php:334
static Add($arFields)
Определения blog.php:8
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения blog.php:249
static AddSocnetRead($ID)
Определения blog.php:452
Определения blog_search.php:6
static OnBeforeSocNetFeaturesPermsAdd($arFields)
Определения blog_search.php:941
static Trace($method, $varname, $var)
Определения blog_search.php:859
static OnSearchReindex($NS=Array(), $oCallback=NULL, $callback_method="")
Определения blog_search.php:89
static fillSearchParamsWithMentionData($arMentionedUserID=array(), &$arSearchIndex=array())
Определения blog_search.php:77
static SetSoNetFeaturePermIndexSearch($ID, $arFields)
Определения blog_search.php:973
static SetSoNetFeatureIndexSearch($ID, $arFields)
Определения blog_search.php:867
static fillSearchPermsWithSonetGroupData($sonetPerms, $authorId, &$arSearchIndex=array(), $arParams=array())
Определения blog_search.php:7
static OnBeforeSocNetFeaturesPermsUpdate($ID, $arFields)
Определения blog_search.php:947
static setSoNetFeaturePermIndexSearchBefore($fields)
Определения blog_search.php:954
static Delete($ID)
Определения log.php:1294
static Add($arFields, $bSendEvent=true)
Определения log.php:20
static Update($ID, $arFields)
Определения log.php:151
static DeleteByLogID($LOG_ID)
Определения log_rights.php:232
static Add($LOG_ID, $GROUP_CODE, $bShare=false, $followSet=true)
Определения log_rights.php:8
Определения functions.php:6
static killAllTags($text)
Определения functions.php:473
$f
Определения component_props.php:52
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$perm
Определения options.php:169
global $USER_FIELD_MANAGER
Определения attempt.php:6
if($ajaxMode) $ID
Определения get_user.php:27
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
if(!defined('NOT_CHECK_PERMISSIONS')) $NS
Определения backup.php:24
IsModuleInstalled($module_id)
Определения tools.php:5301
htmlspecialcharsEx($str)
Определения tools.php:2685
GetMessage($name, $aReplace=null)
Определения tools.php:3397
BXClearCache($full=false, $initdir='')
Определения tools.php:5150
$var
Определения payment.php:63
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
</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
$method
Определения index.php:27
$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
const SONET_RELATIONS_TYPE_ALL
Определения include.php:38
const SITE_ID
Определения sonet_set_content_view.php:12
$rs
Определения action.php:82
$arFilter
Определения user_search.php:106
$fields
Определения yandex_run.php:501