3require_once(
$_SERVER[
"DOCUMENT_ROOT"].
"/bitrix/modules/forum/classes/general/message.php");
11 $strUploadDir = ($strUploadDir ===
false ?
"forum/upload" : $strUploadDir);
19 $arParams[
"SKIP_INDEXING"] = (
$arParams[
"SKIP_INDEXING"] ==
"Y" || $arForum[
"INDEXATION"] !=
"Y" ?
"Y" :
"N");
21 $POST_MESSAGE =
$arFields[
"POST_MESSAGE"];
24 $allow[
'SMILES'] = ((
$arFields[
"USE_SMILES"] !=
"Y") ?
'N' : $allow[
'SMILES']);
25 if (COption::GetOptionString(
"forum",
"FILTER",
"Y") ==
"Y")
28 $arFields[
"POST_MESSAGE_FILTER"] = (empty($POST_MESSAGE) ?
"*" : $POST_MESSAGE);
49 if (COption::GetOptionString(
"forum",
"MESSAGE_HTML",
"N") ==
"Y")
50 $POST_MESSAGE = $parser->convert($POST_MESSAGE, $allow,
"html",
$arFiles);
51 $arFields[
"POST_MESSAGE_HTML"] = $POST_MESSAGE;
53 foreach(
GetModuleEvents(
"forum",
"onBeforeMessageAdd",
true) as $arEvent)
61 $arInsert =
$DB->PrepareInsert(
"b_forum_message",
$arFields, $strUploadDir);
63 $strDatePostField =
"";
64 $strDatePostValue =
"";
67 $strDatePostField =
", POST_DATE";
68 $strDatePostValue =
", ".$DB->GetNowFunction().
"";
71 $strSql =
"INSERT INTO b_forum_message(".$arInsert[0].$strDatePostField.
") VALUES(".$arInsert[1].$strDatePostValue.
")";
73 $ID = intval(
$DB->LastID());
77 "TOPIC_ID" =>
$arFields[
"TOPIC_ID"],
"MESSAGE_ID" =>
$ID));
84 foreach(
GetModuleEvents(
"forum",
"onAfterMessageAdd",
true) as $arEvent)
93 if (intval($arMessage[
"AUTHOR_ID"]) > 0)
100 if ($arMessage[
"APPROVED"] ==
"Y" &&
$arParams[
"SKIP_INDEXING"] !=
"Y" && CModule::IncludeModule(
"search"))
102 $arMessage[
"POST_MESSAGE"] = (COption::GetOptionString(
"forum",
"FILTER",
"Y") ==
"Y" ?
103 $arMessage[
"POST_MESSAGE_FILTER"] : $arMessage[
"POST_MESSAGE"]);
105 "PERMISSION" =>
array(),
107 "DEFAULT_URL" =>
"/");
112 if ($arGroup[1] >=
"E")
115 if ($arGroup[0] == 2)
120 $arSearchInd =
array(
122 "LAST_MODIFIED" => $arMessage[
"POST_DATE"],
123 "PARAM1" => $arMessage[
"FORUM_ID"],
124 "PARAM2" => $arMessage[
"TOPIC_ID"],
125 "ENTITY_TYPE_ID" => ($arMessage[
"NEW_TOPIC"] ==
"Y"?
"FORUM_TOPIC":
"FORUM_POST"),
126 "ENTITY_ID" => ($arMessage[
"NEW_TOPIC"] ==
"Y"? $arMessage[
"TOPIC_ID"]:
$ID),
127 "USER_ID" => $arMessage[
"AUTHOR_ID"],
128 "PERMISSIONS" =>
$arParams[
"PERMISSION"],
129 "TITLE" => $arMessage[
"TOPIC_INFO"][
"TITLE"].($arMessage[
"NEW_TOPIC"] ==
"Y" && !empty($arMessage[
"TOPIC_INFO"][
"DESCRIPTION"]) ?
130 ", ".$arMessage[
"TOPIC_INFO"][
"DESCRIPTION"] :
""),
131 "TAGS" => ($arMessage[
"NEW_TOPIC"] ==
"Y" ? $arMessage[
"TOPIC_INFO"][
"TAGS"] :
""),
134 "INDEX_TITLE" => $arMessage[
"NEW_TOPIC"] ==
"Y",
139 if (!empty($arMentionedUserID))
141 $arSearchInd[
"PARAMS"] =
array(
142 "mentioned_user_id" => $arMentionedUserID
146 $urlPatterns =
array(
147 "FORUM_ID" => $arMessage[
"FORUM_ID"],
148 "TOPIC_ID" => $arMessage[
"TOPIC_ID"],
149 "TITLE_SEO" => $arMessage[
"TOPIC_INFO"][
"TITLE_SEO"],
150 "MESSAGE_ID" => $arMessage[
"ID"],
151 "SOCNET_GROUP_ID" => $arMessage[
"TOPIC_INFO"][
"SOCNET_GROUP_ID"],
152 "OWNER_ID" => $arMessage[
"TOPIC_INFO"][
"OWNER_ID"],
153 "PARAM1" => $arMessage[
"PARAM1"],
154 "PARAM2" => $arMessage[
"PARAM2"]);
158 if (empty($arSearchInd[
"URL"]) && !empty($arSearchInd[
"LID"][
$key]))
159 $arSearchInd[
"URL"] = $arSearchInd[
"LID"][
$key];
162 if (empty($arSearchInd[
"URL"]))
165 $db_lang = CLang::GetByID(
$key);
166 if ($db_lang && $ar_lang = $db_lang->Fetch()):
167 $arParams[
"DEFAULT_URL"] = $ar_lang[
"DIR"];
171 $arParams[
"DEFAULT_URL"] .= COption::GetOptionString(
"forum",
"REL_FPATH",
"").
172 "forum/read.php?FID=#FID#&TID=#TID#&MID=#MID##message#MID#";
178 foreach(
GetModuleEvents(
"forum",
"onMessageIsIndexed",
true) as $arEvent)
193 public static function GetList($arOrder = Array(
"ID"=>
"ASC"),
$arFilter = Array(), $bCount =
false, $iNum = 0, $arAddParams =
array())
196 $arSqlSearch =
array();
197 $arSqlOrder =
array();
201 $arAddParams = (is_array($arAddParams) ? $arAddParams :
array());
202 $arAddParams[
'nTopCount'] = ($arAddParams[
'nTopCount'] ?? 0);
204 $obUserFieldsSql->
SetEntity(
"FORUM_MESSAGE",
"FM.ID");
205 $obUserFieldsSql->SetSelect($arAddParams[
"SELECT"] ??
null);
207 $obUserFieldsSql->SetOrder($arOrder);
212 $key = mb_strtoupper($key_res[
"FIELD"]);
213 $strNegative = $key_res[
"NEGATIVE"];
214 $strOperation = $key_res[
"OPERATION"];
220 case "POST_MESSAGE_CHECK":
224 $arSqlSearch[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.".
$key.
" IS NULL OR LENGTH(FM.".
$key.
")<=0)";
226 $arSqlSearch[] = ($strNegative==
"Y"?
" FM.".$key.
" IS NULL OR NOT ":
"").
"(FM.".
$key.
" ".$strOperation.
" '".
$DB->ForSql(
$val).
"' )";
234 if ( ($strOperation ==
"IN") && (!is_array(
$val)) && (mb_strpos(
$val,
",") > 0) )
236 if (($strOperation!=
"IN") && (intval(
$val) > 0))
237 $arSqlSearch[] = ($strNegative==
"Y"?
" FM.".$key.
" IS NULL OR NOT ":
"").
"(FM.".
$key.
" ".$strOperation.
" ".intval(
$val).
" )";
244 $val_int[] = intval($v);
245 $val = implode(
", ", $val_int);
251 $arSqlSearch[] = ($strNegative==
"Y"?
" NOT ":
"").
"(FM.".
$key.
" IN (".
$DB->ForSql(
$val).
") )";
254 $arSqlSearch[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.".
$key.
" IS NULL OR FM.".
$key.
"<=0)";
259 $arSqlSearch[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.".
$key.
" IS NULL OR LENGTH(FM.".
$key.
")<=0)";
261 $arSqlSearch[] = ($strNegative==
"Y"?
" FM.".$key.
" IS NULL OR NOT ":
"").
"(FM.".
$key.
" ".$strOperation.
" ".
$DB->CharToDateFunction(
$DB->ForSql(
$val),
"FULL").
" )";
267 foreach (
$val as $value)
270 foreach ($value as
$k => $v)
273 $k = mb_strtoupper($k_res[
"FIELD"]);
274 $strNegative = $k_res[
"NEGATIVE"];
275 $strOperation = $k_res[
"OPERATION"];
281 $str[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.".
$k.
" IS NULL OR FM.".
$k.
"<=0)";
283 $str[] = ($strNegative==
"Y"?
" FM.".$k.
" IS NULL OR NOT ":
"").
"(FM.".
$k.
" ".$strOperation.
" ".intval($v).
" )";
287 $str[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.APPROVED IS NULL OR LENGTH(FM.APPROVED)<=0)";
289 $str[] = ($strNegative==
"Y"?
" FM.APPROVED IS NULL OR NOT ":
"").
"FM.APPROVED ".$strOperation.
" '".
$DB->ForSql($v).
"' ";
293 $return[] = implode(
" AND ",
$str);
295 if (
count($return)>0)
296 $arSqlSearch[] =
"(".implode(
") OR (", $return).
")";
301 $r = $obUserFieldsSql->GetFilter();
304 if (!empty($arSqlSearch))
305 $strSqlSearch =
" AND (".implode(
") AND (", $arSqlSearch).
") ";
307 if ($bCount || (
is_set($arAddParams,
"bDescPageNumbering") && $arAddParams[
"nTopCount"] <= 0))
309 $strFrom =
"FROM b_forum_message FM\n".$obUserFieldsSql->GetJoin(
"FM.ID").
"\nWHERE 1 = 1 ".$strSqlSearch;
310 if($obUserFieldsSql->GetDistinct())
311 $strFrom =
"FROM b_forum_message FM\n\tINNER JOIN (SELECT DISTINCT FM.ID ".$strFrom.
") FM2 ON (FM2.ID=FM.ID)";
314 if ($bCount ===
"cnt_not_approved")
318 "SELECT COUNT(FM.ID) as CNT, MAX(FM.ID) AS ABS_LAST_MESSAGE_ID, MIN(FM.ID) AS ABS_FIRST_MESSAGE_ID, \n\t".
319 "MIN(CASE WHEN FM.NEW_TOPIC='Y' THEN FM.ID ELSE NULL END) AS FIRST_MESSAGE_ID, \n\t".
320 "SUM(CASE WHEN FM.APPROVED!='Y' THEN 1 ELSE 0 END) as CNT_NOT_APPROVED,\n\t".
321 "MAX(CASE WHEN FM.APPROVED='Y' THEN FM.ID ELSE 0 END) AS LAST_MESSAGE_ID \n".
326 $db_res =
$DB->Query($strSql .
"\nGROUP BY FM.FORUM_ID");
331 $db_res =
$DB->Query($strSql .
"\nGROUP BY FM.TOPIC_ID");
336 $strSql =
"SELECT COUNT(FM.ID) as CNT ".$strFrom;
341 "SELECT MAX(FM.ID) AS ABS_LAST_MESSAGE_ID, MIN(FM.ID) AS ABS_FIRST_MESSAGE_ID, \n\t".
342 "MIN(CASE WHEN FM.NEW_TOPIC='Y' THEN FM.ID ELSE NULL END) AS FIRST_MESSAGE_ID, \n\t".
343 "SUM(CASE WHEN FM.APPROVED!='Y' THEN 1 ELSE 0 END) as CNT_NOT_APPROVED,\n\t".
344 "MAX(CASE WHEN FM.APPROVED='Y' THEN FM.ID ELSE 0 END) AS LAST_MESSAGE_ID \n".
356 else if ($bCount ===
"cnt_and_last_mid")
361 $strSql =
"SELECT COUNT(FM.ID) as CNT, MAX(FM.ID) as LAST_MESSAGE_ID \n ".$strFrom.
" \nGROUP BY FM.AUTHOR_ID";
368 $strSql =
"SELECT COUNT(FM.ID) as CNT \n ".$strFrom;
372 $strSql =
"SELECT MAX(FM.ID) as LAST_MESSAGE_ID \n ".$strFrom;
376 $ar_res[
"LAST_MESSAGE_ID"] = $ar_res1[
"LAST_MESSAGE_ID"];
384 $strSql =
"SELECT COUNT(FM.ID) as CNT \n ".$strFrom;
388 $iCnt = intval(
$ar_res[
"CNT"]);
395 foreach ($arOrder as $by=>
$order)
397 $by = mb_strtoupper($by);
400 if ($by ==
"AUTHOR_NAME") $arSqlOrder[] =
" FM.AUTHOR_NAME ".$order.
" ";
401 elseif ($by ==
"EDIT_DATE") $arSqlOrder[] =
" FM.EDIT_DATE ".$order.
" ";
402 elseif ($by ==
"POST_DATE") $arSqlOrder[] =
" FM.POST_DATE ".$order.
" ";
403 elseif ($by ==
"FORUM_ID") $arSqlOrder[] =
" FM.FORUM_ID ".$order.
" ";
404 elseif ($by ==
"TOPIC_ID") $arSqlOrder[] =
" FM.TOPIC_ID ".$order.
" ";
405 elseif ($by ==
"NEW_TOPIC") $arSqlOrder[] =
" FM.NEW_TOPIC ".$order.
" ";
406 elseif ($by ==
"APPROVED") $arSqlOrder[] =
" FM.APPROVED ".$order.
" ";
409 $r = $obUserFieldsSql->GetOrder($by);
412 $arSqlOrder[] =
" ".$r.
" ".
$order.
" ";
416 $arSqlOrder[] =
" FM.ID ".$order.
" ";
421 $arSqlOrder = array_unique($arSqlOrder);
423 if(!empty($arSqlOrder))
424 $strSqlOrder =
" ORDER BY ".implode(
", ", $arSqlOrder);
426 $strSqlUserFieldJoin = $obUserFieldsSql->GetJoin(
"FM.ID");
427 if ($obUserFieldsSql->GetDistinct())
430 $obUserFieldsSqlSelect->
SetEntity(
"FORUM_MESSAGE",
"FM.ID");
431 $obUserFieldsSqlSelect->SetSelect($arAddParams[
"SELECT"]);
432 $obUserFieldsSqlSelect->SetOrder($arOrder);
434 $strSqlUserFieldJoin =
435 $obUserFieldsSqlSelect->GetJoin(
"FM.ID").
"
437 SELECT DISTINCT FM.ID
438 FROM b_forum_message FM\n".
439 $obUserFieldsSql->GetJoin(
"FM.ID").
"\n".
440 "WHERE 1 = 1 ".$strSqlSearch.
") FM2 ON (FM2.ID = FM.ID) ";
445 FM.AUTHOR_ID, FM.AUTHOR_NAME, FM.AUTHOR_EMAIL, FM.AUTHOR_IP,
446 FM.USE_SMILES, FM.POST_MESSAGE, FM.POST_MESSAGE_HTML, FM.POST_MESSAGE_FILTER,
447 FM.FORUM_ID, FM.TOPIC_ID, FM.NEW_TOPIC,
448 FM.APPROVED, FM.SOURCE_ID, FM.POST_MESSAGE_CHECK, FM.GUEST_ID, FM.AUTHOR_REAL_IP, FM.ATTACH_IMG, FM.XML_ID,
449 " .
$DB->DateToCharFunction(
"FM.POST_DATE",
"FULL") .
" as POST_DATE,
450 FM.EDITOR_ID, FM.EDITOR_NAME, FM.EDITOR_EMAIL, FM.EDIT_REASON,
451 FU.SHOW_NAME, U.LOGIN, U.NAME, U.SECOND_NAME, U.LAST_NAME, U.PERSONAL_PHOTO,
452 " .
$DB->DateToCharFunction(
"FM.EDIT_DATE",
"FULL") .
" as EDIT_DATE, FM.PARAM1, FM.PARAM2, FM.HTML, FM.MAIL_HEADER, FM.SERVICE_TYPE, FM.SERVICE_DATA " .
453 $obUserFieldsSql->GetSelect() .
454 (!empty($arAddParams[
"sNameTemplate"]) ?
455 ",\n\t".CForumUser::GetFormattedNameFieldsForSelect(array_merge(
457 "sUserTablePrefix" =>
"U.",
458 "sForumUserTablePrefix" =>
"FU.",
459 "sFieldName" =>
"AUTHOR_NAME_FRMT")),
false) :
"");
463 FROM b_forum_message FM
464 LEFT JOIN b_forum_user FU ON (FM.AUTHOR_ID = FU.USER_ID)
465 LEFT JOIN b_user U ON (FM.AUTHOR_ID = U.ID)" .
466 $strSqlUserFieldJoin .
"
467 WHERE 1 = 1 " . $strSqlSearch .
"
470 $limit = intval($iNum ?? $arAddParams[
"nTopCount"]);
473 $strSql .=
" LIMIT ".$limit;
475 if (!$iNum &&
is_set($arAddParams,
"bDescPageNumbering") && $arAddParams[
"nTopCount"] <= 0)
479 $db_res->NavQuery($strSql, $iCnt, $arAddParams);
489 public static function GetListEx($arOrder = Array(
"ID"=>
"ASC"),
$arFilter = Array(), $bCount =
false, $iNum = 0, $arAddParams =
array())
492 $arSqlSearch =
array();
493 $arSqlOrder =
array();
494 $arSqlFrom =
array();
495 $arSqlSelect =
array();
496 $arSqlGroup =
array();
504 $arAddParams = (is_array($arAddParams) ? $arAddParams :
array());
505 $arIndexFields =
array();
510 $key = mb_strtoupper($key_res[
"FIELD"]);
511 $strNegative = $key_res[
"NEGATIVE"];
512 $strOperation = $key_res[
"OPERATION"];
518 case "POST_MESSAGE_CHECK":
522 $arIndexFields[] =
$key;
523 if ($strOperation ==
"LIKE")
526 $arSqlSearch[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.".
$key.
" IS NULL OR LENGTH(FM.".
$key.
")<=0)";
528 $arSqlSearch[] = ($strNegative==
"Y"?
" FM.".$key.
" IS NULL OR NOT ":
"").
"(FM.".
$key.
" ".$strOperation.
" '".
$DB->ForSql(
$val).
"' )";
530 case "APPROVED_AND_MINE":
531 $arIndexFields[] =
"APPROVED";
534 $arSqlSearch[] =
"(FM.APPROVED='Y' OR FM.AUTHOR_ID=".intval(
$val).
")";
535 $arIndexFields[] =
"AUTHOR_ID";
539 $arSqlSearch[] =
"(FM.APPROVED='Y')";
548 $arIndexFields[] =
$key;
549 if ( ($strOperation ==
"IN") && (!is_array(
$val)) && (mb_strpos(
$val,
",") > 0) )
551 if (($strOperation!=
"IN") && (intval(
$val) > 0))
552 $arSqlSearch[] = ($strNegative==
"Y"?
" FM.".$key.
" IS NULL OR NOT ":
"").
"(FM.".
$key.
" ".$strOperation.
" ".intval(
$val).
" )";
559 $val_int[] = intval($v);
560 $val = implode(
", ", $val_int);
566 $arSqlSearch[] = ($strNegative==
"Y"?
" NOT ":
"").
"(FM.".
$key.
" IN (".
$DB->ForSql(
$val).
") )";
569 $arSqlSearch[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.".
$key.
" IS NULL OR FM.".
$key.
"<=0)";
571 case "POINTS_TO_AUTHOR_ID":
572 if (intval(
$val) > 0)
574 $arSqlSelect[
"FR.POINTS"] =
"FR.POINTS";
575 $arSqlSelect[
"FR.DATE_UPDATE"] =
"FR.DATE_UPDATE";
576 $arSqlFrom[
"FR"] =
"LEFT JOIN b_forum_user_points FR ON ((FM.AUTHOR_ID = FR.TO_USER_ID) AND (FR.FROM_USER_ID=".intval(
$val).
"))";
580 $arIndexFields[] =
$key;
582 $arSqlSearch[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.".
$key.
" IS NULL OR LENGTH(FM.".
$key.
")<=0)";
584 $arSqlSearch[] = ($strNegative==
"Y"?
" FM.".$key.
" IS NULL OR NOT ":
"").
"(FM.".
$key.
" ".$strOperation.
" ".
$DB->CharToDateFunction(
$DB->ForSql(
$val),
"FULL").
")";
590 $arSqlFrom[
"FUT"] =
"
591 LEFT JOIN b_forum_user_topic FUT ON (FM.TOPIC_ID = FUT.TOPIC_ID AND FUT.USER_ID=".intval(
$val).
")";
597 $arSqlFrom[
"FUT"] =
"
598 LEFT JOIN b_forum_user_topic FUT ON (FM.TOPIC_ID = FUT.TOPIC_ID AND FUT.USER_ID=".intval(
$arFilter[
"USER_ID"]).
")";
600 (FUT.LAST_VISIT IS NOT NULL AND FM.POST_DATE > FUT.LAST_VISIT)
602 (FUT.LAST_VISIT IS NULL AND FM.POST_DATE ".$strOperation.
" ".
$DB->CharToDateFunction(
$DB->ForSql(
$val),
"FULL").
")
611 if (!in_array(2,
$val))
613 $val = implode(
",", array_map(
"intval",
$val));
614 $arIndexFields[] =
"FP.GROUP_ID";
615 $arSqlFrom[
"FP"] =
"LEFT JOIN b_forum_perms FP ON (FP.FORUM_ID=FM.FORUM_ID)";
616 $arSqlSearch[] =
"FP.GROUP_ID IN (".$DB->ForSql(
$val).
") AND ((FP.PERMISSION IN ('E','I','M') AND FM.APPROVED='Y') OR (FP.PERMISSION IN ('Q','U','Y')))";
620 case "TOPIC_SOCNET_GROUP_ID":
621 $arIndexFields[] =
"FT.SOCNET_GROUP_ID";
623 LEFT JOIN b_forum_topic FT ON (FT.ID = FM.TOPIC_ID)";
624 $arSqlSearch[] =
"FT.SOCNET_GROUP_ID = ".intval(
$val);
625 $arSqlSelect[] =
"FT.SOCNET_GROUP_ID as TOPIC_SOCNET_GROUP_ID";
627 case "TOPIC_OWNER_ID":
628 $arIndexFields[] =
"FT.OWNER_ID";
630 LEFT JOIN b_forum_topic FT ON (FT.ID = FM.TOPIC_ID)";
631 $arSqlSearch[] =
"FT.OWNER_ID = ".intval(
$val);
632 $arSqlSelect[] =
"FT.OWNER_ID as TOPIC_OWNER_ID";
636 LEFT JOIN b_forum_topic FT ON (FT.ID = FM.TOPIC_ID)";
637 $arSqlSelect[] =
"FT.TITLE";
639 $arSqlSelect[] =
"FT.DESCRIPTION AS TOPIC_DESCRIPTION";
640 $arSqlSelect[] =
$DB->DateToCharFunction(
"FT.START_DATE",
"FULL").
" as START_DATE";
641 $arSqlSelect[] =
"FT.USER_START_NAME";
642 $arSqlSelect[] =
"FT.USER_START_ID";
643 $arSqlSelect[] =
"FT.XML_ID AS TOPIC_XML_ID";
644 $arSqlSelect[] =
"FT.SOCNET_GROUP_ID AS TOPIC_SOCNET_GROUP_ID";
645 $arSqlSelect[] =
"FT.OWNER_ID AS TOPIC_OWNER_ID";
647 case "TOPIC_MESSAGE_ID":
652 $val_int[] = intval($v);
653 $val = implode(
", ", $val_int);
662 LEFT JOIN b_forum_topic FT ON (FT.ID = FM.TOPIC_ID)";
663 $arIndexFields[] =
"ID";
664 $arSqlSearch[] =
"FT.ID IN (SELECT DISTINCT TOPIC_ID FROM b_forum_message WHERE ID IN (".$val.
"))";
670 LEFT JOIN b_forum_topic FT ON (FT.ID = FM.TOPIC_ID)";
672 $arIndexFields[] =
$key;
673 if ($strOperation ==
"LIKE")
676 $arSqlSearch[] = ($strNegative==
"Y"?
"NOT":
"").
"(FT.".
$key.
" IS NULL OR LENGTH(FT.".
$key.
")<=0)";
678 $arSqlSearch[] = ($strNegative==
"Y"?
" FT.".$key.
" IS NULL OR NOT ":
"").
"(FT.".
$key.
" ".$strOperation.
" '".
$DB->ForSql(
$val).
"' )";
682 foreach ($arOrder as $by=>
$order)
684 $by = mb_strtoupper($by);
687 if (in_array($by,
array(
"FORUM_ID",
"TOPIC_ID",
"USE_SMILES",
"NEW_TOPIC",
"APPROVED",
688 "POST_DATE",
"POST_MESSAGE",
"ATTACH_IMG",
"PARAM1",
"PARAM2",
689 "AUTHOR_ID",
"AUTHOR_NAME",
"AUTHOR_EMAIL",
"AUTHOR_IP",
"AUTHOR_REAL_IP",
"GUEST_ID",
690 "EDITOR_ID",
"EDITOR_NAME",
"EDITOR_EMAIL",
"EDIT_REASON",
"EDIT_DATE",
"HTML"))):
691 $arSqlOrder[] =
"FM.".$by.
" ".
$order;
692 elseif ($by ==
"SORT" || $by ==
"NAME"):
694 LEFT JOIN b_forum F ON (F.ID = FM.FORUM_ID)";
695 $arSqlSelect[
"F.".$by] =
"F.".$by;
696 $arSqlOrder[] =
"F_M.".$by.
" ".
$order;
698 $arSqlOrder[] =
"FM.ID ".$order;
702 $arSqlOrder = array_unique($arSqlOrder);
704 if(
count($arSqlOrder) > 0)
705 $strSqlOrder =
" ORDER BY ".implode(
", ", $arSqlOrder);
707 $IX_FORUM_MESSAGE_TOPIC =
false;
708 if (
count($arSqlSearch) > 0)
710 $strSqlSearch =
" AND (".implode(
") AND (", $arSqlSearch).
") ";
711 $arIndexFields = array_unique($arIndexFields);
712 $IX_FORUM_MESSAGE_TOPIC = ($arIndexFields ==
array(
"TOPIC_ID",
"APPROVED") || $arIndexFields ==
array(
"TOPIC_ID"));
714 if (
count($arSqlSelect) > 0)
715 $strSqlSelect =
",\n\t".implode(
", ", $arSqlSelect);
716 if (
count($arSqlFrom) > 0)
717 $strSqlFrom .=
"\n\t".implode(
"\n\t", $arSqlFrom);
720 foreach ($arSqlSelect as
$key =>
$val)
722 if (mb_substr(
$key, 0, 1) !=
"!")
725 if (!empty($arSqlGroup)):
726 $strSqlGroup =
", ".implode(
", ", $arSqlGroup);
730 if (!isset($arAddParams[
"nTopCount"]))
732 $arAddParams[
"nTopCount"] = 0;
734 if ($bCount || (
is_set($arAddParams,
"bDescPageNumbering") && intval($arAddParams[
"nTopCount"]) <= 0))
739 MAX(FM.ID) AS LAST_MESSAGE_ID
740 FROM b_forum_message FM
746 $strSql .=
"GROUP BY FM.TOPIC_ID";
747 return $DB->Query($strSql);
750 $iCnt = 0; $iLAST_MESSAGE_ID = 0;
754 $strSql .=
"GROUP BY FM.TOPIC_ID";
758 $iCnt = intval(
$ar_res[
"CNT"]);
759 $iLAST_MESSAGE_ID = intval(
$ar_res[
"LAST_MESSAGE_ID"]);
764 $strSql =
"SELECT COUNT(FM.ID) as CNT \nFROM b_forum_message FM ".$strSqlFrom.
"\nWHERE 1 = 1 ".$strSqlSearch;
768 $iCnt = intval(
$ar_res[
"CNT"]);
772 $strSql =
"SELECT MAX(FM.ID) AS LAST_MESSAGE_ID \nFROM b_forum_message FM ".$strSqlFrom.
"\nWHERE 1 = 1 ".$strSqlSearch;
776 $iLAST_MESSAGE_ID = intval(
$ar_res[
"LAST_MESSAGE_ID"]);
782 return array(
"CNT" => $iCnt,
"LAST_MESSAGE_ID" => $iLAST_MESSAGE_ID);
791 "SELECT F_M.*, FM.FORUM_ID, FM.TOPIC_ID, FM.USE_SMILES, FM.NEW_TOPIC, \n".
792 " FM.APPROVED, FM.SOURCE_ID, \n".
793 " ".$DB->DateToCharFunction(
"FM.POST_DATE",
"FULL").
" as POST_DATE, \n".
794 " FM.POST_MESSAGE, FM.POST_MESSAGE_HTML, FM.POST_MESSAGE_FILTER, \n".
795 " FM.ATTACH_IMG, FM.XML_ID, FM.PARAM1, FM.PARAM2, \n".
796 " FM.AUTHOR_ID, FM.AUTHOR_NAME, FM.AUTHOR_EMAIL, \n".
797 " FM.AUTHOR_IP, FM.AUTHOR_REAL_IP, FM.GUEST_ID, \n".
798 " FM.EDITOR_ID, FM.EDITOR_NAME, FM.EDITOR_EMAIL, FM.EDIT_REASON, \n".
799 " ".$DB->DateToCharFunction(
"FM.EDIT_DATE",
"FULL").
" as EDIT_DATE, \n".
800 " FM.HTML, FM.MAIL_HEADER, FM.SERVICE_TYPE, FM.SERVICE_DATA, \n".
801 " FU.SHOW_NAME, FU.DESCRIPTION, FU.NUM_POSTS, FU.POINTS as NUM_POINTS, FU.SIGNATURE, FU.AVATAR, \n".
802 " ".$DB->DateToCharFunction(
"FU.DATE_REG",
"SHORT").
" as DATE_REG, \n".
803 " U.LOGIN, U.NAME, U.SECOND_NAME, U.LAST_NAME, U.PERSONAL_PHOTO, FU.RANK_ID, U.PERSONAL_WWW, U.PERSONAL_GENDER, \n".
804 " U.EMAIL, U.PERSONAL_ICQ, U.PERSONAL_CITY, U.PERSONAL_COUNTRY, U.EXTERNAL_AUTH_ID".
805 (!empty($arAddParams[
"sNameTemplate"]) ?
806 ",\n\t".CForumUser::GetFormattedNameFieldsForSelect(array_merge(
808 "sUserTablePrefix" =>
"U.",
809 "sForumUserTablePrefix" =>
"FU.",
810 "sFieldName" =>
"AUTHOR_NAME_FRMT")),
false) :
"").
" \n".
812 " SELECT FM.ID".$strSqlSelect.
" \n".
813 " FROM b_forum_message FM \n".
814 " LEFT JOIN b_forum_user FU ON FM.AUTHOR_ID = FU.USER_ID \n".
815 " LEFT JOIN b_user U ON FM.AUTHOR_ID = U.ID \n".
816 " ".$strSqlFrom.
" \n".
817 " WHERE (1=1 ".$strSqlSearch.
") \n".
818 " GROUP BY FM.ID".$strSqlGroup.
" \n".
820 " INNER JOIN b_forum_message FM ON (F_M.ID = FM.ID) \n".
821 " LEFT JOIN b_forum_user FU ON (FM.AUTHOR_ID = FU.USER_ID) \n".
822 " LEFT JOIN b_user U ON (FM.AUTHOR_ID = U.ID) \n".
829 "SELECT FM.ID, FM.FORUM_ID, FM.TOPIC_ID, FM.USE_SMILES, FM.NEW_TOPIC, \n".
830 " FM.APPROVED, FM.SOURCE_ID, \n".
831 " ".$DB->DateToCharFunction(
"FM.POST_DATE",
"FULL").
" as POST_DATE, \n".
832 " FM.POST_MESSAGE, FM.POST_MESSAGE_HTML, FM.POST_MESSAGE_FILTER, \n".
833 " FM.ATTACH_IMG, FM.XML_ID, FM.PARAM1, FM.PARAM2, \n".
834 " FM.AUTHOR_ID, FM.AUTHOR_NAME, FM.AUTHOR_EMAIL, \n".
835 " FM.AUTHOR_IP, FM.AUTHOR_REAL_IP, FM.GUEST_ID, \n".
836 " FM.EDITOR_ID, FM.EDITOR_NAME, FM.EDITOR_EMAIL, FM.EDIT_REASON, \n".
837 " ".$DB->DateToCharFunction(
"FM.EDIT_DATE",
"FULL").
" as EDIT_DATE, \n".
838 " FM.HTML, FM.MAIL_HEADER, FM.SERVICE_TYPE, FM.SERVICE_DATA, \n".
839 " FU.SHOW_NAME, FU.DESCRIPTION, FU.NUM_POSTS, FU.POINTS as NUM_POINTS, FU.SIGNATURE, FU.AVATAR, \n".
840 " ".$DB->DateToCharFunction(
"FU.DATE_REG",
"SHORT").
" as DATE_REG, \n".
841 " U.LOGIN, U.NAME, U.SECOND_NAME, U.LAST_NAME, U.PERSONAL_PHOTO, FU.RANK_ID, U.PERSONAL_WWW, U.PERSONAL_GENDER, \n".
842 " U.EMAIL, U.PERSONAL_ICQ, U.PERSONAL_CITY, U.PERSONAL_COUNTRY, U.EXTERNAL_AUTH_ID".
843 (!empty($arAddParams[
"sNameTemplate"]) ?
844 ",\n\t".CForumUser::GetFormattedNameFieldsForSelect(array_merge(
846 "sUserTablePrefix" =>
"U.",
847 "sForumUserTablePrefix" =>
"FU.",
848 "sFieldName" =>
"AUTHOR_NAME_FRMT")),
false).
"\n" :
"").$strSqlSelect.
"\n".
849 "FROM b_forum_message FM ".(($IX_FORUM_MESSAGE_TOPIC && $isMysql) ?
"USE INDEX (IX_FORUM_MESSAGE_TOPIC)" :
"").
"\n".
850 " LEFT JOIN b_forum_user FU ON (FM.AUTHOR_ID = FU.USER_ID) \n".
851 " LEFT JOIN b_user U ON (FM.AUTHOR_ID = U.ID) \n".
852 " ".$strSqlFrom.
" \n".
853 "WHERE 1 = 1 ".$strSqlSearch.
" \n".
857 $iNum = intval($iNum);
858 if ($iNum > 0 || intval($arAddParams[
"nTopCount"]) > 0):
859 $iNum = ($iNum > 0) ? $iNum : intval($arAddParams[
"nTopCount"]);
860 $strSql .=
"\nLIMIT 0,".$iNum;
863 if (!$iNum && is_array($arAddParams) &&
is_set($arAddParams,
"bDescPageNumbering") && (intval($arAddParams[
"nTopCount"])<=0))
866 $db_res->NavQuery($strSql, $iCnt, $arAddParams);
884 public static function GetList($arOrder = Array(
"ID"=>
"ASC"),
$arFilter = Array(), $iNum = 0, $arAddParams =
array())
887 $arSqlSearch =
array();
888 $arSqlOrder =
array();
892 $iNum = intval($iNum);
894 $arAddParams = (is_array($arAddParams) ? $arAddParams :
array());
895 if (isset($arAddParams[
"nTopCount"]) && intval($arAddParams[
"nTopCount"]) > 0)
896 unset($arAddParams[
"bDescPageNumbering"]);
901 $key = mb_strtoupper($key_res[
"FIELD"]);
902 $strNegative = $key_res[
"NEGATIVE"];
903 $strOperation = $key_res[
"OPERATION"];
909 case "POST_MESSAGE_CHECK":
912 $arSqlSearch[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.".
$key.
" IS NULL OR LENGTH(FM.".
$key.
")<=0)";
914 $arSqlSearch[] = ($strNegative==
"Y"?
" FM.".$key.
" IS NULL OR NOT ":
"").
"(FM.".
$key.
" ".$strOperation.
" '".
$DB->ForSql(
$val).
"' )";
917 case "APPROVED_AND_MINE":
919 $arSqlSearch[] =
"(FM.APPROVED='Y' OR FM.AUTHOR_ID=".intval(
$val).
")";
921 $arSqlSearch[] =
"(FM.APPROVED='Y')";
927 if (($strOperation!=
"IN") && (intval(
$val) > 0))
928 $arSqlSearch[] = ($strNegative==
"Y"?
" FM.".$key.
" IS NULL OR NOT ":
"").
"(FM.".
$key.
" ".$strOperation.
" ".intval(
$val).
" )";
935 $val_int[] = intval($v);
936 $val = implode(
", ", $val_int);
938 $arSqlSearch[] = ($strNegative==
"Y"?
" NOT ":
"").
"(FM.".
$key.
" IN (".
$DB->ForSql(
$val).
") )";
941 $arSqlSearch[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.".
$key.
" IS NULL OR FM.".
$key.
"<=0)";
944 case "FILE_FORUM_ID":
945 case "FILE_TOPIC_ID":
946 case "FILE_MESSAGE_ID":
948 if ($strOperation !=
"IN" && intval(
$val) > 0)
950 $res = ($strNegative==
"Y"?
" FF.".$key.
" IS NULL OR NOT ":
"").
"(FF.".
$key.
" ".$strOperation.
" ".intval(
$val).
" ) OR ".
951 "".($strNegative==
"Y"?
"NOT":
"").
"(FF.".
$key.
" IS NULL OR FF.".
$key.
"<=0)";
952 $arSqlSearch[] =
$res;
959 foreach (
$val as
$k => $v):
960 $val_int[] = intval($v);
962 $val = implode(
",", $val_int);
965 $arSqlSearch[] = ($strNegative==
"Y"?
" NOT ":
"").
"(FF.".
$key.
" IN (".
$DB->ForSql(
$val).
") )";
969 $arSqlSearch[] = ($strNegative==
"Y"?
"NOT":
"").
"(FF.".
$key.
" IS NULL OR FF.".
$key.
"<=0)";
974 if (($strOperation!=
"IN") && (intval(
$val) > 0 ||
$val === 0))
976 $arSqlSearch[] = ($strNegative==
"Y"?
" FF.".$key.
" IS NULL OR NOT ":
"").
"(FF.".
$key.
" ".$strOperation.
" ".intval(
$val).
" )";
983 foreach (
$val as
$k => $v):
984 $val_int[] = intval($v);
986 $val = implode(
",", $val_int);
989 $arSqlSearch[] = ($strNegative==
"Y"?
" NOT ":
"").
"(FF.".
$key.
" IN (".
$DB->ForSql(
$val).
") )";
993 $arSqlSearch[] = ($strNegative==
"Y"?
"NOT":
"").
"(FF.".
$key.
" IS NULL OR FF.".
$key.
"<=0)";
998 $arSqlSearch[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.".
$key.
" IS NULL OR LENGTH(FM.".
$key.
")<=0)";
1000 $arSqlSearch[] = ($strNegative==
"Y"?
" FM.".$key.
" IS NULL OR NOT ":
"").
"(FM.".
$key.
" ".$strOperation.
" ".
$DB->CharToDateFunction(
$DB->ForSql(
$val),
"FULL").
" )";
1006 foreach (
$val as $value)
1009 foreach ($value as
$k => $v)
1012 $k = mb_strtoupper($k_res[
"FIELD"]);
1013 $strNegative = $k_res[
"NEGATIVE"];
1014 $strOperation = $k_res[
"OPERATION"];
1020 $str[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.".
$k.
" IS NULL OR FM.".
$k.
"<=0)";
1022 $str[] = ($strNegative==
"Y"?
" FM.".$k.
" IS NULL OR NOT ":
"").
"(FM.".
$k.
" ".$strOperation.
" ".intval($v).
" )";
1026 $str[] = ($strNegative==
"Y"?
"NOT":
"").
"(FM.APPROVED IS NULL OR LENGTH(FM.APPROVED)<=0)";
1028 $str[] = ($strNegative==
"Y"?
" FM.APPROVED IS NULL OR NOT ":
"").
"FM.APPROVED ".$strOperation.
" '".
$DB->ForSql($v).
"' ";
1032 $return[] = implode(
" AND ",
$str);
1034 if (
count($return)>0)
1035 $arSqlSearch[] =
"(".implode(
") OR (", $return).
")";
1040 if (
count($arSqlSearch) > 0)
1041 $strSqlSearch =
" AND (".implode(
") AND (", $arSqlSearch).
") ";
1043 foreach ($arOrder as $by=>
$order)
1045 $by = mb_strtoupper($by);
1048 if ($by ==
"FILE_ID") $arSqlOrder[] =
" FF.FILE_ID ".$order.
" ";
1049 elseif ($by ==
"FORUM_ID") $arSqlOrder[] =
" FF.FORUM_ID ".$order.
" ";
1050 elseif ($by ==
"TOPIC_ID") $arSqlOrder[] =
" FF.TOPIC_ID ".$order.
" ";
1051 elseif ($by ==
"MESSAGE_ID") $arSqlOrder[] =
" FF.MESSAGE_ID ".$order.
" ";
1054 $arSqlOrder[] =
" FF.FILE_ID ".$order.
" ";
1059 if(
count($arSqlOrder) > 0)
1060 $strSqlOrder =
" ORDER BY ".implode(
", ", $arSqlOrder);
1063 "SELECT BF.ID, BF.HEIGHT, BF.WIDTH, BF.FILE_SIZE, BF.CONTENT_TYPE, BF.SUBDIR, BF.FILE_NAME,
1064 BF.ORIGINAL_NAME, FF.FILE_ID, FF.FORUM_ID, FF.TOPIC_ID, FF.MESSAGE_ID, FF.USER_ID, FF.HITS,
1065 ".$DB->DateToCharFunction(
"FF.TIMESTAMP_X",
"FULL").
" as TIMESTAMP_X, BF.HANDLER_ID
1066 FROM b_forum_file FF
1067 INNER JOIN b_file BF ON (BF.ID = FF.FILE_ID)
1068 LEFT JOIN b_forum_message FM ON (FM.ID=FF.MESSAGE_ID)
1072 if ($iNum > 0 || (isset($arAddParams[
"nTopCount"]) && intval($arAddParams[
"nTopCount"]) > 0))
1074 $iNum = ($iNum > 0) ? $iNum : intval($arAddParams[
"nTopCount"]);
1075 $strSql =
"SELECT * FROM(".$strSql.
") WHERE ROWNUM<=".$iNum;
1080 $strSql1 =
"SELECT COUNT(FM.ID) as CNT FROM b_forum_message FM WHERE 1 = 1 ".$strSqlSearch;
1083 $iCnt = intval(
$ar_res[
"CNT"]);
1085 $db_res->NavQuery($strSql, $iCnt, $arAddParams);
1101 SELECT FF.ID, FF.FILE_ID
1102 FROM b_forum_file FF
1103 WHERE FF.TIMESTAMP_X < ' . $helper->addDaysToDateTime(-1) .
'
1104 AND (FF.TOPIC_ID IS NULL OR FF.TOPIC_ID <= 0)
1105 AND (FF.MESSAGE_ID IS NULL OR FF.MESSAGE_ID <= 0)
1112 CFile::Delete(
$res[
"FILE_ID"]);
1120 AND (TOPIC_ID IS NULL OR TOPIC_ID <= 0)
1121 AND (MESSAGE_ID IS NULL OR MESSAGE_ID <= 0)
1124 return "CForumFiles::CleanUp();";
static getConnection($name="")
static GetByIDEx($ID, $arAddParams=array())
static GetMentionedUserID($strMessage)
static CheckFields($ACTION, &$arFields, $ID=0, $arParams=array())
static GetFilterOperation($key)
static GetAccessPermissions($ID, $TYPE="ONE")
static PreparePath2Message($strPath, $arVals=array())
static SetStat($ID=0, $arParams=array())
static SetStat($ID=0, $params=[])
static SetStat($userId=0, $params=[])
static Index($MODULE_ID, $ITEM_ID, $arFields, $bOverWrite=false, $SEARCH_SESS_ID='')
static GetList($arOrder=Array("ID"=>"ASC"), $arFilter=Array(), $iNum=0, $arAddParams=array())
static QueryFirstUnread($arFilter)
static GetList($arOrder=Array("ID"=>"ASC"), $arFilter=Array(), $bCount=false, $iNum=0, $arAddParams=array())
static Add($arFields, $strUploadDir=false, $arParams=array())
static GetListEx($arOrder=Array("ID"=>"ASC"), $arFilter=Array(), $bCount=false, $iNum=0, $arAddParams=array())
static Concat($glue="", $pieces=array())
static clearAllTags($text)
SetEntity($entity_id, $ID)
static GetFeatures($arForum)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
global $USER_FIELD_MANAGER
$_SERVER["DOCUMENT_ROOT"]
ExecuteModuleEventEx($arEvent, $arParams=[])
DelDuplicateSort(&$arSort)
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
GetMessage($name, $aReplace=null)
global_menu_<?echo $menu["menu_id"]?> adm main menu item icon adm main menu item text text adm main menu hover adm submenu menucontainer menu_id menu_id items_id items_id desktop menu_id block none adm global submenu<?=($subMenuDisplay=="block" ? " adm-global-submenu-active" :"")?> global_submenu_<?echo $menu["menu_id"]?> text MAIN_PR_ADMIN_FAV items adm submenu items wrap adm submenu items stretch wrap BX adminMenu itemsStretchScroll()"> <table class if (!empty( $menu["items"])) elseif ( $menu[ 'menu_id']=='desktop') if ( $menu[ 'menu_id']=='desktop') endforeach
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</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."%"