PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/components/bitrix/forum.topic.move/component.php

https://gitlab.com/alexprowars/bitrix
PHP | 281 lines | 238 code | 7 blank | 36 comment | 62 complexity | 83cb93094fd6baff8e1cdc429f14b66b 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("FM_AUTH"));
  7. endif;
  8. if (!function_exists("__array_merge"))
  9. {
  10. function __array_merge($arr1, $arr2)
  11. {
  12. $arResult = $arr1;
  13. foreach ($arr2 as $key2 => $val2)
  14. {
  15. if (!array_key_exists($key2, $arResult))
  16. {
  17. $arResult[$key2] = $val2;
  18. continue;
  19. }
  20. elseif ($val2 == $arResult[$key2])
  21. continue;
  22. elseif (!is_array($arResult[$key2]))
  23. $arResult[$key2] = array($arResult[$key2]);
  24. $arResult[$key2] = __array_merge($arResult[$key2], $val2);
  25. }
  26. return $arResult;
  27. }
  28. }
  29. /********************************************************************
  30. Input params
  31. ********************************************************************/
  32. /***************** BASE ********************************************/
  33. $arParams["FID"] = intval(empty($arParams["FID"]) ? $_REQUEST["FID"] : $arParams["FID"]);
  34. if ($_SERVER['REQUEST_METHOD'] == "POST")
  35. $arParams["TID"] = $_POST["TID"];
  36. else
  37. $arParams["TID"] = (empty($arParams["TID"]) ? $_REQUEST["TID"] : $arParams["TID"]);
  38. $arParams["newFID"] = intval($_REQUEST["newFID"]);
  39. /***************** URL *********************************************/
  40. $URL_NAME_DEFAULT = array(
  41. "index" => "",
  42. "forums" => "PAGE_NAME=forums&GID=#GID#",
  43. "topic_move" => "PAGE_NAME=MOVE&FID=#FID#&TID=#TID#",
  44. "list" => "PAGE_NAME=list&FID=#FID#",
  45. "read" => "PAGE_NAME=read&FID=#FID#&TID=#TID#",
  46. "message" => "PAGE_NAME=message&FID=#FID#&TID=#TID#&MID=#MID#",
  47. "profile_view" => "PAGE_NAME=profile_view&UID=#UID#");
  48. if (empty($arParams["URL_TEMPLATES_MESSAGE"]) && !empty($arParams["URL_TEMPLATES_READ"]))
  49. {
  50. $arParams["URL_TEMPLATES_MESSAGE"] = $arParams["URL_TEMPLATES_READ"];
  51. }
  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. $arParams["URL_TEMPLATES_".mb_strtoupper($URL)] = htmlspecialcharsbx($arParams["~URL_TEMPLATES_".mb_strtoupper($URL)]);
  58. }
  59. /***************** ADDITIONAL **************************************/
  60. $arParams["NAME_TEMPLATE"] = (!empty($arParams["NAME_TEMPLATE"]) ? $arParams["NAME_TEMPLATE"] : false);
  61. /***************** STANDART ****************************************/
  62. if ($arParams["CACHE_TYPE"] == "Y" || ($arParams["CACHE_TYPE"] == "A" && COption::GetOptionString("main", "component_cache_on", "Y") == "Y"))
  63. $arParams["CACHE_TIME"] = intval($arParams["CACHE_TIME"]);
  64. else
  65. $arParams["CACHE_TIME"] = 0;
  66. $arParams["SET_TITLE"] = ($arParams["SET_TITLE"] == "N" ? "N" : "Y");
  67. $arParams["SET_NAVIGATION"] = ($arParams["SET_NAVIGATION"] == "N" ? "N" : "Y");
  68. // $arParams["DISPLAY_PANEL"] = ($arParams["DISPLAY_PANEL"] == "Y" ? "Y" : "N");
  69. /********************************************************************
  70. /Input params
  71. ********************************************************************/
  72. $arResult["FORUM"] = CForumNew::GetByID($arParams["FID"]);
  73. $topics = ForumMessageExistInArray($arParams["TID"]);
  74. if (!$arResult["FORUM"]):
  75. ShowError(GetMessage("F_ERROR_FORUM_IS_LOST"));
  76. return false;
  77. elseif (ForumCurrUserPermissions($arResult["FORUM"]["ID"]) < "Q"):
  78. $APPLICATION->AuthForm(GetMessage("FM_NO_FPERMS"));
  79. elseif (empty($topics)):
  80. ShowError(GetMessage("F_ERROR_TOPICS_IS_EMPTY"));
  81. return false;
  82. endif;
  83. /********************************************************************
  84. Default values
  85. ********************************************************************/
  86. $GLOBALS['APPLICATION']->ResetException();
  87. $arResult["TOPICS"] = array();
  88. $arResult["GROUPS"] = CForumGroup::GetByLang(LANGUAGE_ID);
  89. $arResult["GROUP_NAVIGATION"] = array();
  90. $arResult["ERROR_MESSAGE"] = "";
  91. $arResult["OK_MESSAGE"] = "";
  92. $arResult["sessid"] = bitrix_sessid_post();
  93. $arResult["arForum"] = array("data" => array(), "active" => $arParams["newFID"]);
  94. $bVarsFromForm = false;
  95. $arResult["CURRENT_PAGE"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_TOPIC_MOVE"],
  96. array("FID" => $arParams["FID"], "TID" => $arParams["TID"]));
  97. $arResult["URL"] = array(
  98. "LIST" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_LIST"],
  99. array("FID" => $arParams["FID"])),
  100. "~LIST" => CComponentEngine::MakePathFromTemplate($arParams["~URL_TEMPLATES_LIST"],
  101. array("FID" => $arParams["FID"])));
  102. $cache = new CPHPCache();
  103. $cache_path_main = str_replace(array(":", "//"), "/", "/".SITE_ID."/".$componentName."/");
  104. /********************************************************************
  105. /Default values
  106. ********************************************************************/
  107. /********************************************************************
  108. Action
  109. ********************************************************************/
  110. if (mb_strtoupper($_REQUEST["action"]) == "MOVE" && check_bitrix_sessid())
  111. {
  112. $strErrorMessage = "";
  113. $strOKMessage = "";
  114. $result = false;
  115. if (intval($arParams["newFID"])<=0)
  116. $strErrorMessage = GetMessage("FM_EMPTY_DEST_FORUM").". \n";
  117. else
  118. {
  119. $arResult["FORUM_NEW"] = CForumNew::GetByID($arParams["newFID"]);
  120. if (ForumCurrUserPermissions($arParams["newFID"]) < "Q" && ($arResult["FORUM_NEW"]["ALLOW_MOVE_TOPIC"]!="Y"))
  121. $strErrorMessage = GetMessage("FM_NO_DEST_FPERMS").". \n";
  122. else
  123. $result = CForumTopic::MoveTopic2Forum($topics, $arParams["newFID"], $_REQUEST["leaveLink"]);
  124. }
  125. if (!$result)
  126. {
  127. if ($GLOBALS['APPLICATION']->GetException())
  128. {
  129. $arErr = $GLOBALS['APPLICATION']->ERROR_STACK;
  130. if (is_array($arErr) && count($arErr) > 0)
  131. {
  132. foreach ($arErr as $res)
  133. $strErrorMessage .= $res["msg"]."\n";
  134. }
  135. $err = $GLOBALS['APPLICATION']->GetException();
  136. $strErrorMessage .= $err->GetString();
  137. }
  138. $bVarsFromForm = true;
  139. }
  140. else
  141. {
  142. LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_LIST"], array("FID" => $arResult["FORUM_NEW"]["ID"])));
  143. }
  144. $arResult["ERROR_MESSAGE"] = $strErrorMessage;
  145. $arResult["OK_MESSAGE"] = $strOKMessage;
  146. }
  147. /********************************************************************
  148. /Action
  149. ********************************************************************/
  150. /********************************************************************
  151. Data
  152. ********************************************************************/
  153. /************** Topic for move *************************************/
  154. $arFilter = array("@ID" => implode(",", $topics), "FORUM_ID" => $arParams["FID"]);
  155. if (!CForumUser::IsAdmin())
  156. $arFilter["PERMISSION_STRONG"] = true;
  157. $db_res = CForumTopic::GetListEx(array(), $arFilter);
  158. if ($db_res && ($res = $db_res->GetNext()))
  159. {
  160. do
  161. {
  162. $res["read"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_READ"],
  163. array("FID" => $res["FORUM_ID"], "TID" => $res["ID"], "TITLE_SEO" => $res["TITLE_SEO"], "MID" => "s"));
  164. $res["read_last_message"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"],
  165. array("FID" => $res["FORUM_ID"], "TID" => $res["ID"], "TITLE_SEO" => $res["TITLE_SEO"], "MID" => intval($res["LAST_MESSAGE_ID"])))."#message".$res["LAST_MESSAGE_ID"];
  166. $res["USER_START_HREF"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_PROFILE_VIEW"], array("UID" => intval($res["USER_START_ID"])));
  167. $res["LAST_POSTER_HREF"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_PROFILE_VIEW"], array("UID" => intval($res["LAST_POSTER_ID"])));
  168. $arResult["TOPICS"][$res["ID"]] = $res;
  169. }while ($res = $db_res->GetNext());
  170. }
  171. $arParams["TID"] = implode(",", array_keys($arResult["TOPICS"]));
  172. /************** Forums *********************************************/
  173. $arFilter = array();
  174. if ($arParams["SHOW_FORUM_ANOTHER_SITE"] == "N" || !CForumUser::IsAdmin())
  175. $arFilter["LID"] = SITE_ID;
  176. if (!empty($arParams["FID_RANGE"]))
  177. $arFilter["@ID"] = $arParams["FID_RANGE"];
  178. if (!CForumUser::IsAdmin()):
  179. $arFilter["PERMS"] = array($USER->GetGroups(), 'A');
  180. $arFilter["ACTIVE"] = "Y";
  181. endif;
  182. $cache_id = "forum_forums_".serialize($arFilter);
  183. $cache_path = $cache_path_main."forums";
  184. $arForums = false;
  185. if ($arParams["CACHE_TIME"] > 0 && $cache->InitCache($arParams["CACHE_TIME"], $cache_id, $cache_path))
  186. {
  187. $res = $cache->GetVars();
  188. $arForums = CForumCacheManager::Expand($res["arForums"]);
  189. }
  190. $arForums = (is_array($arForums) ? $arForums : array());
  191. if (empty($arForums))
  192. {
  193. $db_res = CForumNew::GetListEx(array("FORUM_GROUP_SORT"=>"ASC", "FORUM_GROUP_ID"=>"ASC", "SORT"=>"ASC", "NAME"=>"ASC"), $arFilter);
  194. if ($db_res && ($res = $db_res->GetNext()))
  195. {
  196. do
  197. {
  198. $arForums[$res["ID"]] = $res;
  199. } while ($res = $db_res->GetNext());
  200. }
  201. if ($arParams["CACHE_TIME"] > 0):
  202. $cache->StartDataCache($arParams["CACHE_TIME"], $cache_id, $cache_path);
  203. $cache->EndDataCache(array("arForums" => CForumCacheManager::Compress($arForums)));
  204. endif;
  205. }
  206. $arResult["FORUMS"] = $arForums;
  207. /*******************************************************************/
  208. $arGroupForum = array();
  209. foreach ($arForums as $res):
  210. if ($res["ID"] == $arParams["FID"])
  211. continue;
  212. $arGroupForum[intval($res["FORUM_GROUP_ID"])]["FORUMS"][] = $res;
  213. endforeach;
  214. /*******************************************************************/
  215. $arGroups = array();
  216. foreach ($arGroupForum as $PARENT_ID => $res)
  217. {
  218. $bResult = true;
  219. $res = array("FORUMS" => $res["FORUMS"]);
  220. while ($PARENT_ID > 0)
  221. {
  222. if (!array_key_exists($PARENT_ID, $arResult["GROUPS"]))
  223. {
  224. $bResult = false;
  225. $PARENT_ID = false;
  226. break;
  227. }
  228. $res = array($PARENT_ID => __array_merge($arResult["GROUPS"][$PARENT_ID], $res));
  229. $PARENT_ID = $arResult["GROUPS"][$PARENT_ID]["PARENT_ID"];
  230. $res = array("GROUPS" => $res);
  231. if ($PARENT_ID > 0)
  232. $res = __array_merge($arResult["GROUPS"][$PARENT_ID], $res);
  233. }
  234. if ($bResult == true)
  235. $arGroups = __array_merge($arGroups, $res);
  236. }
  237. $arResult["GROUPS_FORUMS"] = $arGroups;
  238. /************** Group Navigation ***********************************/
  239. if ($arResult["FORUM"]["FORUM_GROUP_ID"] > 0):
  240. $PARENT_ID = intval($arResult["FORUM"]["FORUM_GROUP_ID"]);
  241. while ($PARENT_ID > 0)
  242. {
  243. $arResult["GROUP_NAVIGATION"][] = $arResult["GROUPS"][$PARENT_ID];
  244. if (!array_key_exists("GROUP_".$PARENT_ID, $arResult["URL"]))
  245. {
  246. $arResult["URL"]["GROUP_".$PARENT_ID] = CComponentEngine::MakePathFromTemplate(
  247. $arParams["URL_TEMPLATES_FORUMS"], array("GID" => $PARENT_ID));
  248. $arResult["URL"]["~GROUP_".$PARENT_ID] = CComponentEngine::MakePathFromTemplate(
  249. $arParams["~URL_TEMPLATES_FORUMS"], array("GID" => $PARENT_ID));
  250. }
  251. $PARENT_ID = intval($arResult["GROUPS"][$PARENT_ID]["PARENT_ID"]);
  252. }
  253. $arResult["GROUP_NAVIGATION"] = array_reverse($arResult["GROUP_NAVIGATION"]);
  254. endif;
  255. /************** Custom components **********************************/
  256. $arResult["arForum"]["data"] = $arResult["FORUMS"];
  257. $arResult["list"] = $arResult["URL"]["LIST"];
  258. $arResult["TOPIC"] = $arResult["TOPICS"];
  259. /********************************************************************
  260. /Data
  261. ********************************************************************/
  262. if ($arParams["SET_NAVIGATION"] != "N")
  263. {
  264. foreach ($arResult["GROUP_NAVIGATION"] as $key => $res):
  265. $APPLICATION->AddChainItem($res["~NAME"], $arResult["URL"]["~GROUP_".$res["ID"]]);
  266. endforeach;
  267. $APPLICATION->AddChainItem($arResult["FORUM"]["NAME"], $arResult["URL"]["~LIST"]);
  268. $APPLICATION->AddChainItem(GetMessage("FM_TITLE"));
  269. }
  270. if ($arParams["SET_TITLE"] != "N")
  271. $APPLICATION->SetTitle(GetMessage("FM_TITLE"));
  272. /*******************************************************************/
  273. $this->IncludeComponentTemplate();
  274. ?>