PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/Rad1calDreamer/honey
PHP | 324 lines | 263 code | 23 blank | 38 comment | 65 complexity | 1b8e21b8204a02f27eb1e35eea29b6de MD5 | raw file
  1. <?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
  2. /**
  3. * @global CMain $APPLICATION
  4. * @global CUser $USER
  5. * @var array $arParams
  6. * @var array $arResult
  7. * @var string $componentName
  8. * @var CBitrixComponent $this
  9. * @global CDataBase $DB
  10. */
  11. if (!CModule::IncludeModule("forum")):
  12. ShowError(GetMessage("F_NO_MODULE"));
  13. return 0;
  14. endif;
  15. CPageOption::SetOptionString("main", "nav_page_in_session", "N");
  16. $orderIndex = InitSortingEx();
  17. global $by, $order, $CACHE_MANAGER;
  18. /********************************************************************
  19. Input params
  20. ********************************************************************/
  21. /***************** BASE ********************************************/
  22. $arParams["FID"] = (is_array($arParams["FID"]) && !empty($arParams["FID"]) ? $arParams["FID"] : array());
  23. $arParams["SORT_BY"] = (empty($arParams["SORT_BY"]) ? false : $arParams["SORT_BY"]);
  24. $arParams["SORT_BY"] = ($by ? $by : $arParams["SORT_BY"]);
  25. $arParams["SORT_BY"] = ($arParams["SORT_BY"] ? $arParams["SORT_BY"] : "LAST_POST_DATE");
  26. $arParams["SORT_ORDER"] = strToUpper($arParams["SORT_ORDER"] == "ASC" ? "ASC" : "DESC");
  27. $arParams["SORT_ORDER"] = strToUpper($order ? $order : $arParams["SORT_ORDER"]);
  28. $by = $arParams["SORT_BY"];
  29. $order = $arParams["SORT_ORDER"];
  30. $arParams["SORT_BY_SORT_FIRST"] = ($arParams["SORT_BY_SORT_FIRST"] == "Y" ? "Y" : "N");
  31. /***************** URL *********************************************/
  32. $URL_NAME_DEFAULT = array(
  33. "index" => "",
  34. "list" => "PAGE_NAME=list&FID=#FID#",
  35. "read" => "PAGE_NAME=read&FID=#FID#&TID=#TID#",
  36. "message" => "PAGE_NAME=message&FID=#FID#&TID=#TID#&MID=#MID#",
  37. "profile_view" => "PAGE_NAME=profile_view&UID=#UID#");
  38. if (empty($arParams["URL_TEMPLATES_MESSAGE"]) && !empty($arParams["URL_TEMPLATES_READ"]))
  39. $arParams["URL_TEMPLATES_MESSAGE"] = $arParams["URL_TEMPLATES_READ"];
  40. foreach ($URL_NAME_DEFAULT as $URL => $URL_VALUE)
  41. {
  42. if (strLen(trim($arParams["URL_TEMPLATES_".strToUpper($URL)])) <= 0)
  43. $arParams["URL_TEMPLATES_".strToUpper($URL)] = $APPLICATION->GetCurPage()."?".$URL_VALUE;
  44. $arParams["~URL_TEMPLATES_".strToUpper($URL)] = $arParams["URL_TEMPLATES_".strToUpper($URL)];
  45. $arParams["URL_TEMPLATES_".strToUpper($URL)] = htmlspecialcharsbx($arParams["~URL_TEMPLATES_".strToUpper($URL)]);
  46. }
  47. /***************** ADDITIONAL **************************************/
  48. $arParams["TOPICS_PER_PAGE"] = intVal($arParams["TOPICS_PER_PAGE"] > 0 ? $arParams["TOPICS_PER_PAGE"] :
  49. COption::GetOptionString("forum", "TOPICS_PER_PAGE", "10"));
  50. $arParams["SHOW_FORUM_ANOTHER_SITE"] = ($arParams["SHOW_FORUM_ANOTHER_SITE"] == "Y" ? "Y" : "N");
  51. $arParams["DATE_TIME_FORMAT"] = trim(empty($arParams["DATE_TIME_FORMAT"]) ? $DB->DateFormatToPHP(CSite::GetDateFormat("FULL")) :
  52. $arParams["DATE_TIME_FORMAT"]);
  53. $arParams["SET_NAVIGATION"] = ($arParams["SET_NAVIGATION"] == "Y" ? "Y" : "N");
  54. $arParams["SHOW_TOPIC_POST_MESSAGE"] = ($arParams["SHOW_TOPIC_POST_MESSAGE"] == "FIRST_POST" || $arParams["SHOW_TOPIC_POST_MESSAGE"] == "LAST_POST" ? $arParams["SHOW_TOPIC_POST_MESSAGE"] : "NONE");
  55. $arParams["USER_FIELDS"] = (is_array($arParams["USER_FIELDS"]) ? $arParams["USER_FIELDS"] : (empty($arParams["USER_FIELDS"]) ? array() : array($arParams["USER_FIELDS"])));
  56. if (!in_array("UF_FORUM_MESSAGE_DOC", $arParams["USER_FIELDS"]) && IsModuleInstalled("disk"))
  57. $arParams["USER_FIELDS"][] = "UF_FORUM_MESSAGE_DOC";
  58. // $arParams["DISPLAY_PANEL"] = ($arParams["DISPLAY_PANEL"] == "Y" ? "Y" : "N");
  59. /***************** ANOTHER *****************************************/
  60. $arParams["PAGER_DESC_NUMBERING"] = ($arParams["PAGER_DESC_NUMBERING"] == "N" ? "N" : "Y");
  61. $arParams["PAGER_TITLE"] = (empty($arParams["PAGER_TITLE"]) ? GetMessage("FTP_TITLE_NAV") : $arParams["PAGER_TITLE"]);
  62. $arParams["PAGER_TEMPLATE"] = (empty($arParams["PAGER_TEMPLATE"]) ? false : $arParams["PAGER_TEMPLATE"]);
  63. $arParams["PAGER_SHOW_ALWAYS"] = ($arParams["PAGER_SHOW_ALWAYS"] == "Y" ? true : false);
  64. /***************** STANDART ****************************************/
  65. if ($arParams["CACHE_TYPE"] == "Y" || ($arParams["CACHE_TYPE"] == "A" && COption::GetOptionString("main", "component_cache_on", "Y") == "Y"))
  66. $arParams["CACHE_TIME"] = intval($arParams["CACHE_TIME"]);
  67. else
  68. $arParams["CACHE_TIME"] = 0;
  69. $arParams["CACHE_TAG"] = ($arParams["CACHE_TAG"] == "N" ? "N" : "Y");
  70. $arParams["SET_TITLE"] = ($arParams["SET_TITLE"] == "N" ? "N" : "Y");
  71. /********************************************************************
  72. /Input params
  73. ********************************************************************/
  74. $arNavParams = array("nPageSize"=>$arParams["TOPICS_PER_PAGE"], "bDescPageNumbering"=>($arParams["PAGER_DESC_NUMBERING"] == "Y"));
  75. if ($arParams['SET_NAVIGATION'] == 'N')
  76. $arNavParams['nTopCount'] = $arParams["TOPICS_PER_PAGE"];
  77. $arNavigation = CDBResult::GetNavParams($arNavParams);
  78. $arSort = ($arParams["SORT_BY_SORT_FIRST"] == "Y" ? array("SORT" => "ASC") : array());
  79. $arSort[$arParams["SORT_BY"]] = $arParams["SORT_ORDER"];
  80. $arFilter = array();
  81. if (!CForumUser::IsAdmin())
  82. $arFilter = array("LID" => SITE_ID, "PERMS" => array($USER->GetGroups(), 'A'), "ACTIVE" => "Y");
  83. elseif ($arParams["SHOW_FORUM_ANOTHER_SITE"] == "N")
  84. $arFilter["LID"] = SITE_ID;
  85. if (!empty($arParams["FID"]))
  86. $arFilter["@ID"] = $arParams["FID"];
  87. if($this->StartResultCache(false, array($arNavigation, $USER->GetGroups(), $arSort, $arFilter, $orderIndex)))
  88. {
  89. /********************************************************************
  90. Default values
  91. ********************************************************************/
  92. $arResult["TOPIC"] = array();
  93. $arResult["FORUM"] = array();
  94. $arResult["FORUMS"] = array();
  95. $arResult["TOPICS"] = array();
  96. $arForums = array();
  97. $arTopics = array();
  98. /********************************************************************
  99. /Default values
  100. ********************************************************************/
  101. /********************************************************************
  102. Data
  103. ********************************************************************/
  104. $db_res = CForumNew::GetListEx(array(), $arFilter);
  105. if ($db_res && ($res = $db_res->GetNext()))
  106. {
  107. do
  108. {
  109. $res["URL"] = array(
  110. "LIST" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_LIST"], array("FID" => $res["ID"])),
  111. "~LIST" => CComponentEngine::MakePathFromTemplate($arParams["~URL_TEMPLATES_LIST"], array("FID" => $res["ID"])));
  112. $res["list"] = $res["URL"]["list"]; // for custom
  113. $arForums[$res["ID"]] = $res;
  114. }while ($res = $db_res->GetNext());
  115. }
  116. if (!empty($arForums))
  117. {
  118. // it needs for custom components
  119. foreach (array("TITLE", "USER_START_NAME", "POSTS", "VIEWS", "LAST_POST_DATE", "START_DATE") as $res):
  120. $arResult["SortingEx"][$res] = SortingEx($res, false, "by".$orderIndex, "order".$orderIndex);
  121. endforeach;
  122. // /it needs for custom components
  123. $db_res = CForumTopic::GetListEx($arSort, array("@FORUM_ID" => array_keys($arForums), "APPROVED" => "Y", "!STATE" => "L"), false, false, $arNavParams);
  124. if ($db_res)
  125. {
  126. $db_res->NavStart($arParams["TOPICS_PER_PAGE"], false);
  127. $arResult["NAV_STRING"] = $db_res->GetPageNavStringEx($navComponentObject, $arParams["PAGER_TITLE"], $arParams["PAGER_TEMPLATE"], $arParams["PAGER_SHOW_ALWAYS"]);
  128. //$arResult["NAV_CACHED_DATA"] = $navComponentObject->GetTemplateCachedData();
  129. $arResult["NAV_RESULT"] = $db_res;
  130. $ids = array();
  131. while ($res = $db_res->GetNext())
  132. {
  133. if (strlen($res["LAST_POST_DATE"]) > 0)
  134. {
  135. $res["LAST_POST_DATE"] = CForumFormat::DateFormat($arParams["DATE_TIME_FORMAT"],
  136. MakeTimeStamp($res["LAST_POST_DATE"], CSite::GetDateFormat()));
  137. }
  138. $res["URL"] = array(
  139. "AUTHOR" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_PROFILE_VIEW"],
  140. array("UID" => $res["USER_START_ID"])),
  141. "~AUTHOR" => CComponentEngine::MakePathFromTemplate($arParams["~URL_TEMPLATES_PROFILE_VIEW"],
  142. array("UID" => $res["USER_START_ID"])),
  143. "READ" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"],
  144. array("FID" => $res["FORUM_ID"], "TID" => $res["ID"], "TITLE_SEO" => $res["TITLE_SEO"], "MID" => intVal($res["LAST_MESSAGE_ID"]))).
  145. "#message".intVal($res["LAST_MESSAGE_ID"]),
  146. "~READ" => CComponentEngine::MakePathFromTemplate($arParams["~URL_TEMPLATES_MESSAGE"],
  147. array("FID" => $res["FORUM_ID"], "TID" => $res["ID"], "TITLE_SEO" => $res["TITLE_SEO"], "MID" => intVal($res["LAST_MESSAGE_ID"]))).
  148. "#message".intVal($res["LAST_MESSAGE_ID"]));
  149. $res["user_start_id_profile"] = $res["URL"]["AUTHOR"]; // For custom
  150. $res["read"] = $res["URL"]["READ"]; // For custom
  151. $arTopics[$res["ID"]] = $res;
  152. $ids[$res['ID']] = $res['LAST_MESSAGE_ID'];
  153. }
  154. }
  155. if ($arParams['SHOW_TOPIC_POST_MESSAGE'] != 'NONE' && !empty($arTopics))
  156. {
  157. $db_res = CForumMessage::GetListEx(
  158. array("ID" => "ASC"),
  159. ($arParams['SHOW_TOPIC_POST_MESSAGE'] == 'FIRST_POST' ?
  160. array("@TOPIC_ID" => array_keys($ids), 'APPROVED' => 'Y', 'NEW_TOPIC' => 'Y') :
  161. array("@ID" => array_values($ids), 'APPROVED' => 'Y'))
  162. );
  163. $ids = array();
  164. while ($res = $db_res->GetNext())
  165. {
  166. $ids[] = $res["ID"];
  167. $res["~POST_MESSAGE_TEXT"] = (COption::GetOptionString("forum", "FILTER", "Y")=="Y" ? $res["~POST_MESSAGE_FILTER"] : $res["~POST_MESSAGE"]);
  168. if (!empty($arParams["NAME_TEMPLATE"]) && $res["SHOW_NAME"] != "Y")
  169. {
  170. $name = CUser::FormatName(
  171. $arParams["NAME_TEMPLATE"],
  172. array(
  173. "NAME" => $res["NAME"],
  174. "LAST_NAME" => $res["LAST_NAME"],
  175. "SECOND_NAME" => $res["SECOND_NAME"],
  176. "LOGIN" => $res["LOGIN"]
  177. ),
  178. true,
  179. false
  180. );
  181. if (!!$name)
  182. {
  183. $res["~AUTHOR_NAME"] = $name;
  184. $res["AUTHOR_NAME"] = htmlspecialcharsbx($name);
  185. }
  186. }
  187. $res["AUTHOR_ID"] = intval($res["AUTHOR_ID"]);
  188. $res["AUTHOR_URL"] = "";
  189. if (!empty($arParams["URL_TEMPLATES_PROFILE_VIEW"]))
  190. {
  191. $res["AUTHOR_URL"] = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_PROFILE_VIEW"], array("user_id" => $res["AUTHOR_ID"]));
  192. }
  193. $res["POST_TIMESTAMP"] = MakeTimeStamp($res["POST_DATE"], CSite::GetDateFormat());
  194. $arTopics[$res['TOPIC_ID']]['MESSAGE'] = array(
  195. 'ID' => $res["ID"],
  196. '~POST_MESSAGE_TEXT' => $res["~POST_MESSAGE_TEXT"],
  197. 'POST_MESSAGE_TEXT' => $res["~POST_MESSAGE_TEXT"],
  198. 'NEW_TOPIC' => $res["NEW_TOPIC"],
  199. 'POST_DATE' => CForumFormat::DateFormat($arParams["DATE_TIME_FORMAT"], $res["POST_TIMESTAMP"]),
  200. 'USE_SMILES' => $res["USE_SMILES"],
  201. 'POST_TIMESTAMP' => $res["POST_TIMESTAMP"],
  202. 'AUTHOR_NAME' => $res["AUTHOR_NAME"],
  203. 'AUTHOR_ID' => $res["AUTHOR_ID"],
  204. 'AUTHOR_URL' => str_replace('#UID#', $res["AUTHOR_ID"], $res["AUTHOR_URL"]),
  205. 'AUTHOR_AVATAR_ID' => $res["AVATAR"] > 0 ? $res["AVATAR"] : $res["PERSONAL_PHOTO"]
  206. );
  207. if ($arParams["CACHE_TAG"] == "Y" && $arParams["CACHE_TIME"] > 0 && defined("BX_COMP_MANAGED_CACHE"))
  208. {
  209. $CACHE_MANAGER->RegisterTag('forum_topic_'.$res['TOPIC_ID']);
  210. }
  211. }
  212. if (!empty($ids))
  213. {
  214. $parser = new forumTextParser(LANGUAGE_ID);
  215. $parser->imageWidth = $parser->imageHeight = (array_key_exists("IMAGE_SIZE", $arParams) ? $arParams["IMAGE_SIZE"] : 200);
  216. $parser->userPath = $arParams["URL_TEMPLATES_PROFILE_VIEW"];
  217. $parser->userNameTemplate = $arParams["NAME_TEMPLATE"];
  218. $files = array();
  219. $props = array();
  220. $db_files = CForumFiles::GetList(array("MESSAGE_ID" => "ASC"), array("@MESSAGE_ID" => $ids));
  221. while ($res = $db_files->Fetch())
  222. {
  223. $files[$res["MESSAGE_ID"]] = ($files[$res["MESSAGE_ID"]] ?: array());
  224. $files[$res["MESSAGE_ID"]][$res["FILE_ID"]] = $res;
  225. }
  226. if (!empty($arParams["USER_FIELDS"]))
  227. {
  228. $db_props = CForumMessage::GetList(array("ID" => "ASC"), array("@ID" => $ids), false, 0, array("SELECT" => $arParams["USER_FIELDS"]));
  229. while ($res = $db_props->Fetch())
  230. {
  231. $props[$res["ID"]] = array_intersect_key($res, array_flip($arParams["USER_FIELDS"]));
  232. }
  233. }
  234. $arAllow = array(
  235. "HTML" => $arParams["ALLOW_HTML"],
  236. "ANCHOR" => $arParams["ALLOW_ANCHOR"],
  237. "BIU" => $arParams["ALLOW_BIU"],
  238. "IMG" => $arParams["ALLOW_IMG"],
  239. "VIDEO" => $arParams["ALLOW_VIDEO"],
  240. "LIST" => $arParams["ALLOW_LIST"],
  241. "QUOTE" => $arParams["ALLOW_QUOTE"],
  242. "CODE" => $arParams["ALLOW_CODE"],
  243. "FONT" => $arParams["ALLOW_FONT"],
  244. "SMILES" => $arParams["ALLOW_SMILES"],
  245. "NL2BR" => $arParams["ALLOW_NL2BR"],
  246. "TABLE" => $arParams["ALLOW_TABLE"],
  247. "UPLOAD" => $arParams["ALLOW_UPLOAD"],
  248. "ALIGN" => $arParams["ALLOW_ALIGN"]
  249. );
  250. foreach ($arTopics as &$topic)
  251. {
  252. $topic['MESSAGE']["POST_MESSAGE_TEXT"] = $parser->convert(
  253. $topic['MESSAGE']["~POST_MESSAGE_TEXT"],
  254. array_merge($arAllow, array(
  255. "SMILES" => ($topic["MESSAGE"]["USE_SMILES"] == "Y" ? $arParams["ALLOW_SMILES"] : "N"),
  256. "USERFIELDS" => $props[$topic["MESSAGE"]["ID"]])),
  257. "html",
  258. $files[$topic["MESSAGE"]["ID"]]
  259. );
  260. if ($arParams['TOPIC_POST_MESSAGE_LENGTH'] > 0)
  261. {
  262. $symbols_len = strlen(strip_tags($topic['MESSAGE']["POST_MESSAGE_TEXT"]));
  263. if($symbols_len > $arParams['TOPIC_POST_MESSAGE_LENGTH'])
  264. {
  265. $strip_text = $parser->strip_words($topic['MESSAGE']["POST_MESSAGE_TEXT"], $arParams['TOPIC_POST_MESSAGE_LENGTH']);
  266. if($symbols_len > $arParams['TOPIC_POST_MESSAGE_LENGTH'])
  267. $strip_text = $strip_text."...";
  268. $topic['MESSAGE']["POST_MESSAGE_TEXT"] = $parser->closetags($strip_text);
  269. }
  270. }
  271. $topic['MESSAGE']["FILES"] = $files[$topic["MESSAGE"]["ID"]];
  272. $topic['MESSAGE']["FILES_PARSED"] = $parser->arFilesIDParsed;
  273. unset($topic["MESSAGE"]["USE_SMILES"]);
  274. }
  275. }
  276. }
  277. }
  278. $arResult['TOPICS'] = CForumCacheManager::Compress($arTopics);
  279. $arResult['FORUMS'] = CForumCacheManager::Compress($arForums);
  280. $this->EndResultCache();
  281. $arResult['TOPICS'] = $arTopics;
  282. $arResult['FORUMS'] = $arForums;
  283. }
  284. else
  285. {
  286. $arResult['TOPICS'] = CForumCacheManager::Expand($arResult['TOPICS']);
  287. $arResult['FORUMS'] = CForumCacheManager::Expand($arResult['FORUMS']);
  288. }
  289. $arResult["TOPIC"] = $arResult["TOPICS"]; // For custom
  290. $arResult["FORUM"] = $arResult["FORUMS"]; // For custom
  291. $this->IncludeComponentTemplate();
  292. /********************************************************************
  293. Data
  294. ********************************************************************/
  295. if ($arParams["SET_NAVIGATION"] != "N")
  296. $APPLICATION->AddChainItem(GetMessage("FTP_INDEX"), CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_INDEX"], array()));
  297. if ($arParams["SET_TITLE"] != "N")
  298. $APPLICATION->SetTitle(GetMessage("FTP_TITLE"));
  299. // if($arParams["DISPLAY_PANEL"] == "Y" && $USER->IsAuthorized())
  300. // CForumNew::ShowPanel(0, 0, false);
  301. ?>