PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/components/bitrix/forum.subscribe.list/component.php

https://gitlab.com/alexprowars/bitrix
PHP | 195 lines | 157 code | 7 blank | 31 comment | 34 complexity | 68ffef75276976c3674c327e9a1a466b MD5 | raw file
  1. <?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
  2. if (!CModule::IncludeModule("forum")):
  3. ShowError(GetMessage("FSL_NO_MODULE"));
  4. return 0;
  5. elseif (!$USER->IsAuthorized()):
  6. $APPLICATION->AuthForm(GetMessage("FSL_AUTH"));
  7. return 0;
  8. endif;
  9. $strErrorMessage = "";
  10. $strOKMessage = "";
  11. $bVarsFromForm = false;
  12. /********************************************************************
  13. Input params
  14. ********************************************************************/
  15. /***************** BASE ********************************************/
  16. $arParams["UID"] = intval($_REQUEST["UID"]);
  17. $arParams["UID"] = intval((!CForumUser::IsAdmin() || $arParams["UID"] <= 0) ? $USER->GetID() : $arParams["UID"]);
  18. $arParams["ACTION"] = mb_strtoupper($_REQUEST["ACTION"]);
  19. /***************** URL *********************************************/
  20. if (empty($arParams["URL_TEMPLATES_MESSAGE"]) && !empty($arParams["URL_TEMPLATES_READ"]))
  21. $arParams["URL_TEMPLATES_MESSAGE"] = $arParams["URL_TEMPLATES_READ"];
  22. $URL_NAME_DEFAULT = array(
  23. "list" => "PAGE_NAME=list&FID=#FID#",
  24. "read" => "PAGE_NAME=read&FID=#FID#&TID=#TID#",
  25. "message" => "PAGE_NAME=message&FID=#FID#&TID=#TID#&MID=#MID#",
  26. "subscr_list" => "PAGE_NAME=subscr_list",
  27. "profile_view" => "PAGE_NAME=profile_view&UID=#UID#");
  28. if (empty($arParams["URL_TEMPLATES_MESSAGE"]) && !empty($arParams["URL_TEMPLATES_READ"]))
  29. {
  30. $arParams["URL_TEMPLATES_MESSAGE"] = $arParams["URL_TEMPLATES_READ"];
  31. }
  32. foreach ($URL_NAME_DEFAULT as $URL => $URL_VALUE)
  33. {
  34. if (trim($arParams["URL_TEMPLATES_".mb_strtoupper($URL)]) == '')
  35. $arParams["URL_TEMPLATES_".mb_strtoupper($URL)] = $APPLICATION->GetCurPage()."?".$URL_VALUE;
  36. $arParams["~URL_TEMPLATES_".mb_strtoupper($URL)] = $arParams["URL_TEMPLATES_".mb_strtoupper($URL)];
  37. $arParams["URL_TEMPLATES_".mb_strtoupper($URL)] = htmlspecialcharsbx($arParams["~URL_TEMPLATES_".mb_strtoupper($URL)]);
  38. }
  39. /***************** ADDITIONAL **************************************/
  40. // Data and data-time format
  41. $arParams["TOPICS_PER_PAGE"] = intval($arParams["TOPICS_PER_PAGE"] > 0 ? $arParams["TOPICS_PER_PAGE"] : COption::GetOptionString("forum", "TOPICS_PER_PAGE", "10"));
  42. $arParams["DATE_TIME_FORMAT"] = trim(empty($arParams["DATE_TIME_FORMAT"]) ? $DB->DateFormatToPHP(CSite::GetDateFormat("FULL")) : $arParams["DATE_TIME_FORMAT"]);
  43. $arParams["NAME_TEMPLATE"] = (!empty($arParams["NAME_TEMPLATE"]) ? $arParams["NAME_TEMPLATE"] : false);
  44. $arParams["PAGE_NAVIGATION_TEMPLATE"] = trim($arParams["PAGE_NAVIGATION_TEMPLATE"]);
  45. $arParams["PAGE_NAVIGATION_WINDOW"] = intval(intVal($arParams["PAGE_NAVIGATION_WINDOW"]) > 0 ? $arParams["PAGE_NAVIGATION_WINDOW"] : 11);
  46. /***************** STANDART ****************************************/
  47. $arParams["SET_NAVIGATION"] = ($arParams["SET_NAVIGATION"] == "N" ? "N" : "Y");
  48. $arParams["SET_TITLE"] = ($arParams["SET_TITLE"] == "N" ? "N" : "Y");
  49. /********************************************************************
  50. /Input params
  51. ********************************************************************/
  52. $arResult["USER"] = array();
  53. $db_res = CForumUser::GetList(
  54. array(),
  55. array("USER_ID" => $arParams["UID"], "SHOW_ABC" => ""),
  56. array("sNameTemplate" => $arParams["NAME_TEMPLATE"])
  57. );
  58. if ($db_res && $res = $db_res->GetNext())
  59. $arResult["USER"] = $res;
  60. if (empty($arResult["USER"])):
  61. ShowError(str_replace("#UID#", $arParams["UID"], GetMessage("FSL_NO_DUSER")));
  62. return false;
  63. endif;
  64. /********************************************************************
  65. Action
  66. ********************************************************************/
  67. $arError = array(); $arNote = array();
  68. if ($arParams["ACTION"] == "DEL")
  69. {
  70. $arParams["SID"] = (is_array($_REQUEST["SID"]) ? $_REQUEST["SID"] : array($_REQUEST["SID"]));
  71. if (!check_bitrix_sessid()):
  72. $arError[] = GetMessage("F_ERR_SESS_FINISH");
  73. elseif (empty($arParams["SID"])):
  74. $arError[] = GetMessage("F_EMPTY_SUBSCRIBES");
  75. else:
  76. foreach ($arParams["SID"] as $res):
  77. if (!CForumSubscribe::CanUserDeleteSubscribe($res, $USER->GetUserGroupArray(), $USER->GetID())):
  78. $arError[] = str_replace("#SID#", $res, GetMessage("FSL_NO_SPERMS"));
  79. elseif(!CForumSubscribe::Delete($res)):
  80. $arError[] = str_replace("#SID#", $res, GetMessage("FSL_NO_DELETE"));
  81. else:
  82. $arNote[] = str_replace("#SID#", $res, GetMessage("FSL_SUCC_DELETE"));
  83. endif;
  84. endforeach;
  85. endif;
  86. }
  87. /********************************************************************
  88. /Action
  89. ********************************************************************/
  90. /********************************************************************
  91. Default values
  92. ********************************************************************/
  93. $arResult["CURRENT_PAGE"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_SUBSCR_LIST"], array());
  94. $arResult["~FORUMS"] = $arResult["FORUMS"] = array();
  95. $arResult["~TOPICS"] = $arResult["TOPICS"] = array();
  96. $arResult["ERROR_MESSAGE"] = implode("\n", $arError);
  97. $arResult["OK_MESSAGE"] = implode("\n", $arNote);
  98. $arResult["sessid"] = bitrix_sessid_get();
  99. $arResult["SHOW_SUBSCRIBE_LIST"] = "N";
  100. $arResult["SUBSCRIBE_LIST"] = array();
  101. /********************************************************************
  102. /Default values
  103. ********************************************************************/
  104. /********************************************************************
  105. Data
  106. ********************************************************************/
  107. $db_res = CForumSubscribe::GetListEx(
  108. array("FORUM_ID" => "ASC", "TOPIC_ID" => "ASC", "START_DATE" => "ASC"),
  109. array("USER_ID" => $arParams["UID"]),
  110. array(
  111. "bDescPageNumbering" => false,
  112. "nPageSize" => $arParams["TOPICS_PER_PAGE"]
  113. )
  114. );
  115. $db_res->NavStart($arParams["TOPICS_PER_PAGE"]);
  116. $db_res->nPageWindow = $arParams["PAGE_NAVIGATION_WINDOW"];
  117. $db_res->bShowAll = false;
  118. $arResult["NAV_RESULT"] = $db_res;
  119. $arResult["NAV_STRING"] = $db_res->GetPageNavStringEx($navComponentObject, GetMessage("F_SUBSCRIBE"), $arParams["PAGE_NAVIGATION_TEMPLATE"]);
  120. if ($db_res && $res = $db_res->GetNext())
  121. {
  122. $arResult["SHOW_SUBSCRIBE_LIST"] = "Y";
  123. do
  124. {
  125. $arResult["~FORUMS"][] = $res["FORUM_ID"];
  126. $arResult["~TOPICS"][] = $res["TOPIC_ID"];
  127. $res["START_DATE"] = trim($res["START_DATE"]);
  128. if ($res["START_DATE"] <> '')
  129. $res["START_DATE"] = CForumFormat::DateFormat($arParams["DATE_TIME_FORMAT"], MakeTimeStamp($res["START_DATE"], CSite::GetDateFormat()));;
  130. $res["SUBSCRIBE_TYPE"] = (intval($res["TOPIC_ID"]) > 0 ? "TOPIC" : ($res["NEW_TOPIC_ONLY"] == "Y" ? "NEW_TOPIC_ONLY" : "ALL_MESSAGES"));
  131. $res["LAST_SEND"] = intval($res["LAST_SEND"]);
  132. $res["read"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_READ"],
  133. array("FID" => $res["FORUM_ID"], "TID" => $res["TOPIC_ID"], "TITLE_SEO" => $res["TITLE_SEO"], "MID" => "s"));
  134. $res["list"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_LIST"], array("FID" => $res["FORUM_ID"]));
  135. $res["read_last_send"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"],
  136. array("FID" => $res["FORUM_ID"], "TID" => $res["TOPIC_ID"], "TITLE_SEO" => $res["TITLE_SEO"], "MID" => intval($res["LAST_SEND"]))).
  137. "#message".intval($res["LAST_SEND"]);
  138. $res["subscr_delete"] = ForumAddPageParams($arResult["CURRENT_PAGE"],
  139. array("SID" => $res["ID"], "ACTION" => "DEL"))."&amp;".bitrix_sessid_get();
  140. $res["URL"] = array(
  141. "TOPIC" => $res["read"],
  142. "FORUM" => $res["list"],
  143. "LAST_MESSAGE" => $res["read_last_send"],
  144. "DELETE" => $res["subscr_delete"]);
  145. $arResult["SUBSCRIBE_LIST"][] = $res;
  146. }while ($res = $db_res->GetNext());
  147. }
  148. if (!empty($arResult["~FORUMS"]))
  149. {
  150. $arResult["~FORUMS"] = array_unique($arResult["~FORUMS"]);
  151. $db_res = CForumNew::GetListEx(array("SORT" => "ASC"), array("@ID" => $arResult["~FORUMS"]));
  152. if ($db_res && ($res = $db_res->GetNext()))
  153. {
  154. do {
  155. $arResult["FORUMS"][$res["ID"]] = $res;
  156. } while ($res = $db_res->GetNext());
  157. }
  158. }
  159. if (!empty($arResult["~TOPICS"]))
  160. {
  161. $arResult["~TOPICS"] = array_unique(array_diff($arResult["~TOPICS"], array(0, "")));
  162. $db_res = CForumTopic::GetListEx(array("SORT" => "ASC"), array("@ID" => $arResult["~TOPICS"]));
  163. if ($db_res && ($res = $db_res->GetNext()))
  164. {
  165. do {
  166. $arResult["TOPICS"][$res["ID"]] = $res;
  167. } while ($res = $db_res->GetNext());
  168. }
  169. }
  170. foreach($arResult["SUBSCRIBE_LIST"] as $key => $res)
  171. {
  172. $arResult["SUBSCRIBE_LIST"][$key]["FORUM_INFO"] = $arResult["FORUMS"][$res["FORUM_ID"]];
  173. $arResult["SUBSCRIBE_LIST"][$key]["TOPIC_INFO"] = $arResult["TOPICS"][$res["TOPIC_ID"]];
  174. }
  175. /********************************************************************
  176. /Data
  177. ********************************************************************/
  178. /*******************************************************************/
  179. $this->IncludeComponentTemplate();
  180. /*******************************************************************/
  181. if ($arParams["SET_NAVIGATION"] != "N"):
  182. $APPLICATION->AddChainItem($arResult["USER"]["SHOW_ABC"],
  183. CComponentEngine::MakePathFromTemplate($arParams["~URL_TEMPLATES_PROFILE_VIEW"], array("UID" => $arParams["UID"])));
  184. $APPLICATION->AddChainItem(GetMessage("FSL_TITLE"));
  185. endif;
  186. if ($arParams["SET_TITLE"] != "N")
  187. $APPLICATION->SetTitle(GetMessage("FSL_TITLE"));
  188. ?>