PageRenderTime 135ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://gitlab.com/alexprowars/bitrix
PHP | 324 lines | 276 code | 11 blank | 37 comment | 69 complexity | 586c730dc378e5bf1ecdf65a858b0036 MD5 | raw file
  1. <?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
  2. if (!CModule::IncludeModule("forum")):
  3. ShowError(GetMessage("F_NO_MODULE"));
  4. return 0;
  5. elseif (!$USER->IsAuthorized()):
  6. $APPLICATION->AuthForm(GetMessage("PM_AUTH"));
  7. return 0;
  8. elseif (intval(COption::GetOptionString("forum", "UsePMVersion", "2")) <= 0):
  9. ShowError(GetMessage("F_NO_PM"));
  10. CHTTP::SetStatus("404 Not Found");
  11. return 0;
  12. endif;
  13. if(!function_exists("GetUserName"))
  14. {
  15. function GetUserName($USER_ID, $sNameTemplate = "")
  16. {
  17. $sNameTemplate = str_replace(array("#NOBR#","#/NOBR#"), "", (!empty($sNameTemplate) ? $sNameTemplate : CSite::GetDefaultNameFormat()));
  18. if (intval($USER_ID) <= 0)
  19. {
  20. $db_res = CUser::GetByLogin($USER_ID);
  21. $ar_res = $db_res->Fetch();
  22. $USER_ID = $ar_res["ID"];
  23. }
  24. return CForumUser::GetFormattedNameByUserID($USER_ID, $sNameTemplate);
  25. }
  26. }
  27. /********************************************************************
  28. Input params
  29. ********************************************************************/
  30. /***************** BASE ********************************************/
  31. $arParams["pm_version"] = intval(COption::GetOptionString("forum", "UsePMVersion", "2"));
  32. $arParams["FID"] = intval(intVal($arParams["FID"]) <= 0 ? $_REQUEST["FID"] : $arParams["FID"]);
  33. $arParams["FID"] = intval(intVal($arParams["FID"]) <= 0 ? 1 : $arParams["FID"]);
  34. if ($arParams["pm_version"] == 2 && ($arParams["FID"] > 1 && $arParams["FID"] < 4))
  35. $arParams["FID"] = 3;
  36. $arParams["UID"] = intval($USER->GetId());
  37. /***************** Sorting *****************************************/
  38. InitSorting($GLOBALS["APPLICATION"]->GetCurPage()."?PAGE_NAME=pm_list&FID=".$arParams["FID"]);
  39. global $by, $order;
  40. if (empty($by))
  41. {
  42. $by = "post_date";
  43. $order = "desc";
  44. }
  45. /***************** URL *********************************************/
  46. $URL_NAME_DEFAULT = array(
  47. "pm_list" => "PAGE_NAME=pm_list&FID=#FID#",
  48. "pm_read" => "PAGE_NAME=pm_read&FID=#FID#&MID=#MID#",
  49. "pm_edit" => "PAGE_NAME=pm_edit&FID=#FID#&MID=#MID#&mode=#mode#",
  50. "profile_view" => "PAGE_NAME=profile_view&UID=#UID#",
  51. "pm_folder" => "PAGE_NAME=pm_folder");
  52. foreach ($URL_NAME_DEFAULT as $URL => $URL_VALUE)
  53. {
  54. if (trim($arParams["URL_TEMPLATES_".mb_strtoupper($URL)]) == '')
  55. $arParams["URL_TEMPLATES_".mb_strtoupper($URL)] = $APPLICATION->GetCurPage()."?".$URL_VALUE;
  56. $arParams["~URL_TEMPLATES_".mb_strtoupper($URL)] = $arParams["URL_TEMPLATES_".mb_strtoupper($URL)];
  57. if (!empty($by) && !in_array($URL, array("profile_view", "pm_read", "pm_edit")))
  58. {
  59. $arParams["~URL_TEMPLATES_".mb_strtoupper($URL)] = ForumAddPageParams($arParams["URL_TEMPLATES_".mb_strtoupper($URL)],
  60. array("by" => $by, "order" => $order), false, false);
  61. }
  62. $arParams["URL_TEMPLATES_".mb_strtoupper($URL)] = htmlspecialcharsbx($arParams["~URL_TEMPLATES_".mb_strtoupper($URL)]);
  63. }
  64. /***************** ADDITIONAL **************************************/
  65. $arParams["PAGE_NAVIGATION_TEMPLATE"] = trim($arParams["PAGE_NAVIGATION_TEMPLATE"]);
  66. $arParams["PAGE_NAVIGATION_WINDOW"] = intval(intVal($arParams["PAGE_NAVIGATION_WINDOW"]) > 0 ? $arParams["PAGE_NAVIGATION_WINDOW"] : 11);
  67. $arParams["PM_PER_PAGE"] = intval($arParams["PM_PER_PAGE"] > 0 ? $arParams["PM_PER_PAGE"] : 20);
  68. $arParams["DATE_FORMAT"] = trim(empty($arParams["DATE_FORMAT"]) ? $DB->DateFormatToPHP(CSite::GetDateFormat("SHORT")) : $arParams["DATE_FORMAT"]);
  69. $arParams["DATE_TIME_FORMAT"] = trim(empty($arParams["DATE_TIME_FORMAT"]) ? $DB->DateFormatToPHP(CSite::GetDateFormat("FULL")) : $arParams["DATE_TIME_FORMAT"]);
  70. $arParams["NAME_TEMPLATE"] = str_replace(array("#NOBR#","#/NOBR#"), "",
  71. (!empty($arParams["NAME_TEMPLATE"]) ? $arParams["NAME_TEMPLATE"] : CSite::GetDefaultNameFormat()));
  72. /***************** STANDART ****************************************/
  73. $arParams["SET_NAVIGATION"] = ($arParams["SET_NAVIGATION"] == "N" ? "N" : "Y");
  74. if ($arParams["CACHE_TYPE"] == "Y" || ($arParams["CACHE_TYPE"] == "A" && COption::GetOptionString("main", "component_cache_on", "Y") == "Y"))
  75. $arParams["CACHE_TIME"] = intval($arParams["CACHE_TIME"]);
  76. else
  77. $arParams["CACHE_TIME"] = 0;
  78. $arParams["SET_TITLE"] = ($arParams["SET_TITLE"] == "N" ? "N" : "Y");
  79. /********************************************************************
  80. /Input params
  81. ********************************************************************/
  82. /********************************************************************
  83. Default values
  84. ********************************************************************/
  85. $arResult["ERROR_MESSAGE"] = "";
  86. $arResult["OK_MESSAGE"] = "";
  87. if (!empty($_REQUEST["result"])):
  88. switch(mb_strtolower($_REQUEST["result"]))
  89. {
  90. case "delete":
  91. $arResult["OK_MESSAGE"] = GetMessage("PM_OK_ALL_DELETE");
  92. break;
  93. case "move":
  94. $arResult["OK_MESSAGE"] = GetMessage("PM_OK_ALL_MOVE");
  95. break;
  96. case "copy":
  97. $arResult["OK_MESSAGE"] = GetMessage("PM_OK_ALL_COPY");
  98. break;
  99. case "no_mid":
  100. $arResult["ERROR_MESSAGE"] = GetMessage("PM_ERR_NO_MID");
  101. break;
  102. case "no_perm":
  103. $arResult["ERROR_MESSAGE"] = GetMessage("PM_ERR_NO_PERM");
  104. break;
  105. }
  106. endif;
  107. $arResult["count"] = CForumPrivateMessage::PMSize($USER->GetID(), COption::GetOptionInt("forum", "MaxPrivateMessages", 100));
  108. $arResult["count"] = round($arResult["count"]*100);
  109. $arResult["sessid"] = bitrix_sessid_post();
  110. $arResult["FID"] = $arParams["FID"];
  111. $arResult["CURRENT_PAGE"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_PM_LIST"], array("FID" => $arParams["FID"]));
  112. $arResult["version"] = $arParams["pm_version"];
  113. $arResult["MESSAGE"] = array();
  114. $arResult["SystemFolder"] = FORUM_SystemFolder;
  115. $arResult["UserFolder"] = array();
  116. $message = (is_array($_REQUEST["message"]) && !empty($_REQUEST["message"]) ? $_REQUEST["message"] : array());
  117. /********************************************************************
  118. /Default values
  119. ********************************************************************/
  120. /********************************************************************
  121. Action
  122. ********************************************************************/
  123. $arResult["action"] = mb_strtolower($_REQUEST["action"]);
  124. if (!empty($arResult["action"]))
  125. {
  126. $arError = array();
  127. $strOK = "";
  128. $APPLICATION->ResetException();
  129. $APPLICATION->ThrowException(" ");
  130. $folder_id = 0;
  131. if (!check_bitrix_sessid()):
  132. $arError[] = array("id" => "BAD_SESSID", "text" => GetMessage("F_ERR_SESS_FINISH"));
  133. elseif (empty($message)):
  134. $arError[] = array("id" => "BAD_DATA", "text" => GetMessage("PM_ERR_NO_DATA"));
  135. elseif ($arResult["action"] == "delete"):
  136. $folder_id = 4;
  137. foreach ($message as $MID):
  138. if (!CForumPrivateMessage::CheckPermissions($MID))
  139. $arError[] = array("id" => "BAD_PERMISSION_".$MID, "text" => str_replace("#MID#", $MID, GetMessage("PM_ERR_DELETE_NO_PERM")));
  140. elseif(!CForumPrivateMessage::Delete($MID, array("FOLDER_ID"=>4)))
  141. $arError[] = array("id" => "BAD_DELETE_".$MID, "text" => str_replace("#MID#", $MID, GetMessage("PM_ERR_DELETE")));
  142. else
  143. $strOK .= str_replace("#MID#", $MID, GetMessage("PM_OK_DELETE"));
  144. endforeach;
  145. elseif (($arResult["action"] == "copy" || $arResult["action"] == "move") && intval($_REQUEST["folder_id"]) <= 0):
  146. $arError[] = array("id" => "BAD_DATA", "text" => GetMessage("PM_ERR_MOVE_NO_FOLDER"));
  147. elseif ($arResult["action"] == "copy" || $arResult["action"] == "move"):
  148. $folder_id = intval($_REQUEST["folder_id"]);
  149. foreach ($message as $MID)
  150. {
  151. $arrVars = array(
  152. "FOLDER_ID" => intval($folder_id),
  153. "USER_ID" => $USER->GetId());
  154. if ($folder_id == 4 || $arResult["action"] != "move")
  155. $arrVars["IS_READ"] = "Y";
  156. if (!CForumPrivateMessage::CheckPermissions($MID)):
  157. $arError[] = array("id" => "BAD_PERMISSION_".$MID, "text" => str_replace("#MID#", $MID, GetMessage("PM_ERR_MOVE_NO_PERM")));
  158. elseif ($arResult["action"] == "move"):
  159. if (!CForumPrivateMessage::Update($MID, $arrVars)):
  160. $err = $APPLICATION->GetException();
  161. $arError[] = array("id" => "BAD_MOVE_".$MID, "text" => $err->GetString());
  162. else:
  163. $strOK .= str_replace("#MID#", $MID, GetMessage("PM_OK_MOVE"))."\n";
  164. endif;
  165. else:
  166. if (!CForumPrivateMessage::Copy($MID, $arrVars)):
  167. $err = $APPLICATION->GetException();
  168. $arError[] = array("id" => "BAD_MOVE_".$MID, "text" => $err->GetString());
  169. else:
  170. $strOK .= str_replace("#MID#", $MID, GetMessage("PM_OK_COPY"))."\n";
  171. endif;
  172. endif;
  173. }
  174. endif;
  175. BXClearCache(true, "/bitrix/forum/user/".intval($USER->GetID())."/");
  176. $arComponentPath = array("bitrix:forum");
  177. foreach ($arComponentPath as $path)
  178. {
  179. $componentRelativePath = CComponentEngine::MakeComponentPath($path);
  180. $arComponentDescription = CComponentUtil::GetComponentDescr($path);
  181. if ($componentRelativePath == '' || !is_array($arComponentDescription)):
  182. continue;
  183. elseif (!array_key_exists("CACHE_PATH", $arComponentDescription)):
  184. continue;
  185. endif;
  186. $path = str_replace("//", "/", $componentRelativePath."/user".$USER->GetID());
  187. if ($arComponentDescription["CACHE_PATH"] == "Y")
  188. $path = "/".SITE_ID.$path;
  189. if (!empty($path))
  190. BXClearCache(true, $path);
  191. }
  192. if (empty($arError))
  193. {
  194. LocalRedirect(ForumAddPageParams(CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_PM_LIST"],
  195. array("FID" => $arParams["FID"])), array("result" => $arResult["action"])));
  196. }
  197. else
  198. {
  199. $e = new CAdminException(array_reverse($arError));
  200. $GLOBALS["APPLICATION"]->ThrowException($e);
  201. $err = $GLOBALS['APPLICATION']->GetException();
  202. $arResult["ERROR_MESSAGE"] .= $err->GetString();
  203. $arResult["OK_MESSAGE"] .= $strOK;
  204. }
  205. }
  206. /********************************************************************
  207. /Action
  208. ********************************************************************/
  209. /********************************************************************
  210. Data
  211. ********************************************************************/
  212. $arResult["StatusUser"] = "AUTHOR";
  213. $arResult["InputOutput"] = "AUTHOR_ID";
  214. $SortingField = "AUTHOR_NAME";
  215. if ($arParams["FID"] <= 1)
  216. {
  217. $arResult["StatusUser"] = "SENDER";
  218. $arResult["InputOutput"] = "AUTHOR_ID";
  219. $SortingField = "AUTHOR_NAME";
  220. }
  221. elseif (1 < $arParams["FID"] && $arParams["FID"] <= 3)
  222. {
  223. $arResult["StatusUser"] = "RECIPIENT";
  224. $arResult["InputOutput"] = "RECIPIENT_ID";
  225. $SortingField = "RECIPIENT_NAME";
  226. }
  227. $arResult["SortingEx"]["POST_SUBJ"] = SortingEx("post_subj");
  228. $arResult["SortingEx"]["AUTHOR_NAME"] = SortingEx(mb_strtolower($SortingField));
  229. $arResult["SortingEx"]["POST_DATE"] = SortingEx("post_date");
  230. $arFilter = array("USER_ID"=>$arParams["UID"], "FOLDER_ID"=>$arParams["FID"]);
  231. if ($arParams["FID"] == 2) //If this is outbox folder
  232. $arFilter = array("OWNER_ID" => $arParams["UID"]);
  233. $dbrMessages = CForumPrivateMessage::GetListEx(array($by => $order), $arFilter,
  234. array(
  235. "bDescPageNumbering" => false,
  236. "nPageSize" => $arParams["PM_PER_PAGE"],
  237. "bShowAll" => false,
  238. "sNameTemplate" => $arParams["NAME_TEMPLATE"]));
  239. $dbrMessages->NavStart($arParams["PM_PER_PAGE"]);
  240. $dbrMessages->nPageWindow = $arParams["PAGE_NAVIGATION_WINDOW"];
  241. $arResult["NAV_RESULT"] = $dbrMessages;
  242. $arResult["NAV_STRING"] = $dbrMessages->GetPageNavStringEx($navComponentObject, GetMessage("PM_TITLE_PAGES"), $arParams["PAGE_NAVIGATION_TEMPLATE"]);
  243. if($dbrMessages && $arMsg = $dbrMessages->GetNext())
  244. {
  245. do
  246. {
  247. $arMsg["POST_SUBJ"] = wordwrap($arMsg["POST_SUBJ"], 100, " ", 1);
  248. $arMsg["~SHOW_NAME"] = $arMsg["~".$SortingField];
  249. $arMsg["SHOW_NAME"] = $arMsg[$SortingField];
  250. $arMsg["URL"] = array(
  251. "MESSAGE" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_PM_READ"],
  252. array("FID" => $arParams["FID"], "MID" => $arMsg["ID"])),
  253. "MESSAGE_EDIT" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_PM_EDIT"],
  254. array("FID" => $arParams["FID"], "mode" => "new", "MID" => 0, "UID" => $arMsg[$arResult["InputOutput"]])),
  255. "RECIPIENT" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_PROFILE_VIEW"],
  256. array("UID" => $arMsg["RECIPIENT_ID"])),
  257. "SENDER" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_PROFILE_VIEW"],
  258. array("UID" => $arMsg["AUTHOR_ID"])));
  259. $arMsg["pm_read"] = $arMsg["URL"]["MESSAGE"];
  260. $arMsg["pm_edit"] = $arMsg["URL"]["MESSAGE_EDIT"];
  261. $arMsg["profile_view"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_PROFILE_VIEW"],
  262. array("UID" => $arMsg[$arResult["InputOutput"]]));
  263. $arMsg["POST_DATE"] = CForumFormat::DateFormat($arParams["DATE_TIME_FORMAT"], MakeTimeStamp($arMsg["POST_DATE"], CSite::GetDateFormat()));
  264. $arMsg["checked"] = "";
  265. if (in_array($arMsg["ID"], $message))
  266. $arMsg["checked"] = " checked ";
  267. $arResult["MESSAGE"][$arMsg["ID"]] = $arMsg;
  268. }while($arMsg = $dbrMessages->GetNext());
  269. }
  270. /************** Folders ********************************************/
  271. $resFolder = CForumPMFolder::GetList(array(), array("USER_ID" => $USER->GetID()));
  272. if ($resFolder && $resF = $resFolder->GetNext())
  273. {
  274. do
  275. {
  276. $arResult["UserFolder"][intval($resF["ID"])] = $resF;
  277. }
  278. while ($resF = $resFolder->GetNext());
  279. }
  280. if ($arParams["FID"] > 4 && empty($arResult["UserFolder"][$arParams["FID"]]))
  281. {
  282. ShowError(GetMessage("PM_FOLDER_IS_NOT_EXISTS"));
  283. return false;
  284. }
  285. $arResult["FolderName"] = ($arParams["FID"] > 4) ? $arResult["UserFolder"][$arParams["FID"]]["TITLE"] : GetMessage("PM_FOLDER_ID_".$arParams["FID"]);
  286. /*******************************************************************/
  287. $arResult["pm_folder"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_PM_FOLDER"], array());
  288. if ($arParams["FID"] > 4)
  289. {
  290. $title = $arResult["UserFolder"][$arParams["FID"]]["TITLE"];
  291. }
  292. else
  293. {
  294. $title = GetMessage("PM_FOLDER_ID_".$arParams["FID"]);
  295. }
  296. // if($arParams["DISPLAY_PANEL"] == "Y" && $USER->IsAuthorized())
  297. // CForumNew::ShowPanel(0, 0, false);
  298. // GetMessage("PM_FOLDER_ID_1");
  299. // GetMessage("PM_FOLDER_ID_2");
  300. // GetMessage("PM_FOLDER_ID_3");
  301. // GetMessage("PM_FOLDER_ID_4");
  302. /*******************************************************************/
  303. $this->IncludeComponentTemplate();
  304. /*******************************************************************/
  305. if ($arParams["SET_NAVIGATION"] != "N")
  306. {
  307. $APPLICATION->AddChainItem(GetMessage("PM_TITLE_NAV"), CComponentEngine::MakePathFromTemplate($arParams["~URL_TEMPLATES_PM_FOLDER"], array()));
  308. $APPLICATION->AddChainItem($title);
  309. }
  310. /*******************************************************************/
  311. if ($arParams["SET_TITLE"] != "N")
  312. $APPLICATION->SetTitle(str_replace("#TITLE#", $title, GetMessage("PM_TITLE")));
  313. ?>