PageRenderTime 3696ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 1ms

/components/bitrix/blog.blog.moderation/component.php

https://gitlab.com/alexprowars/bitrix
PHP | 304 lines | 269 code | 35 blank | 0 comment | 66 complexity | 6eebe179ec332430992be1547b166cc3 MD5 | raw file
  1. <?
  2. if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
  3. if (!CModule::IncludeModule("blog"))
  4. {
  5. ShowError(GetMessage("BLOG_MODULE_NOT_INSTALL"));
  6. return;
  7. }
  8. $arParams["BLOG_URL"] = preg_replace("/[^a-zA-Z0-9_-]/is", "", Trim($arParams["BLOG_URL"]));
  9. if($arParams["SET_TITLE"]=="Y")
  10. $APPLICATION->SetTitle(GetMessage('B_B_HIDE_TITLE'));
  11. if(!is_array($arParams["GROUP_ID"]))
  12. $arParams["GROUP_ID"] = array($arParams["GROUP_ID"]);
  13. foreach($arParams["GROUP_ID"] as $k=>$v)
  14. if(intval($v) <= 0)
  15. unset($arParams["GROUP_ID"][$k]);
  16. if($arParams["BLOG_VAR"] == '')
  17. $arParams["BLOG_VAR"] = "blog";
  18. if($arParams["PAGE_VAR"] == '')
  19. $arParams["PAGE_VAR"] = "page";
  20. if($arParams["POST_VAR"] == '')
  21. $arParams["POST_VAR"] = "id";
  22. $arParams["PATH_TO_BLOG_CATEGORY"] = trim($arParams["PATH_TO_BLOG_CATEGORY"]);
  23. if($arParams["PATH_TO_BLOG_CATEGORY"] == '')
  24. $arParams["PATH_TO_BLOG_CATEGORY"] = htmlspecialcharsbx($APPLICATION->GetCurPage()."?".$arParams["PAGE_VAR"]."=blog&".$arParams["BLOG_VAR"]."=#blog#"."&category=#category_id#");
  25. $arParams["PATH_TO_POST_EDIT"] = trim($arParams["PATH_TO_POST_EDIT"]);
  26. if($arParams["PATH_TO_POST_EDIT"] == '')
  27. $arParams["PATH_TO_POST_EDIT"] = htmlspecialcharsbx($APPLICATION->GetCurPage()."?".$arParams["PAGE_VAR"]."=post_edit&".$arParams["BLOG_VAR"]."=#blog#&".$arParams["POST_VAR"]."=#post_id#");
  28. $arParams["DATE_TIME_FORMAT"] = trim(empty($arParams["DATE_TIME_FORMAT"]) ? $DB->DateFormatToPHP(CSite::GetDateFormat("FULL")) : $arParams["DATE_TIME_FORMAT"]);
  29. $arParams["PATH_TO_SMILE"] = trim($arParams["PATH_TO_SMILE"]) == '' ? false : trim($arParams["PATH_TO_SMILE"]);
  30. $arParams["IMAGE_MAX_WIDTH"] = intval($arParams["IMAGE_MAX_WIDTH"]);
  31. $arParams["IMAGE_MAX_HEIGHT"] = intval($arParams["IMAGE_MAX_HEIGHT"]);
  32. if(!is_array($arParams["POST_PROPERTY_LIST"]))
  33. $arParams["POST_PROPERTY_LIST"] = Array("UF_BLOG_POST_DOC");
  34. else
  35. $arParams["POST_PROPERTY_LIST"][] = "UF_BLOG_POST_DOC";
  36. $arResult["OK_MESSAGE"] = Array();
  37. $arResult["ERROR_MESSAGE"] = Array();
  38. $user_id = intval($USER->GetID());
  39. $arBlog = CBlog::GetByUrl($arParams["BLOG_URL"], $arParams["GROUP_ID"]);
  40. $arResult["PostPerm"] = CBlog::GetBlogUserPostPerms($arBlog["ID"], $user_id);
  41. if(!empty($arBlog) && $arBlog["ACTIVE"] == "Y")
  42. {
  43. $arGroup = CBlogGroup::GetByID($arBlog["GROUP_ID"]);
  44. if($arGroup["SITE_ID"] == SITE_ID)
  45. {
  46. $arResult["BLOG"] = $arBlog;
  47. if($arParams["SET_TITLE"]=="Y")
  48. $APPLICATION->SetTitle(str_replace("#NAME#", $arBlog["NAME"], GetMessage("B_B_HIDE_TITLE_BLOG")));
  49. if($arParams["SET_NAV_CHAIN"]=="Y")
  50. $APPLICATION->AddChainItem($arBlog["NAME"], CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_BLOG"], array("blog" => $arBlog["URL"])));
  51. if($arResult["PostPerm"]>=BLOG_PERMS_MODERATE)
  52. {
  53. $errorMessage = "";
  54. $okMessage = "";
  55. if (intval($_GET["del_id"]) > 0)
  56. {
  57. if($_GET["success"] == "Y")
  58. {
  59. $okMessage = GetMessage("B_B_HIDE_M_DEL");
  60. }
  61. else
  62. {
  63. $DEL_ID = intval($_GET["del_id"]);
  64. if (check_bitrix_sessid() && CBlogPost::CanUserDeletePost($DEL_ID, $user_id))
  65. {
  66. if (CBlogPost::Delete($DEL_ID))
  67. {
  68. LocalRedirect($APPLICATION->GetCurPageParam("del_id=".$DEL_ID."&success=Y", Array("del_id", "sessid", "success", "show_id")));
  69. }
  70. else
  71. $errorMessage = GetMessage("B_B_HIDE_M_DEL_ERR");
  72. }
  73. else
  74. $errorMessage = GetMessage("B_B_HIDE_M_DEL_RIGHTS");
  75. }
  76. }
  77. elseif (intval($_GET["show_id"]) > 0)
  78. {
  79. if($_GET["success"] == "Y")
  80. {
  81. $okMessage = GetMessage("BLOG_BLOG_BLOG_MES_SHOWED");
  82. }
  83. else
  84. {
  85. if (check_bitrix_sessid())
  86. {
  87. $show_id = intval($_GET["show_id"]);
  88. if($arResult["PostPerm"]>=BLOG_PERMS_MODERATE)
  89. {
  90. if($arPost = CBlogPost::GetByID($show_id))
  91. {
  92. if(CBlogPost::Update($show_id, Array("PUBLISH_STATUS" => BLOG_PUBLISH_STATUS_PUBLISH)))
  93. {
  94. BXClearCache(True, "/".SITE_ID."/blog/".$arBlog["URL"]."/first_page/");
  95. BXClearCache(True, "/".SITE_ID."/blog/".$arBlog["URL"]."/pages/");
  96. BXClearCache(True, "/".SITE_ID."/blog/".$arBlog["URL"]."/calendar/");
  97. BXClearCache(True, "/".SITE_ID."/blog/".$arBlog["URL"]."/post/".$show_id."/");
  98. BXClearCache(True, "/".SITE_ID."/blog/last_messages/");
  99. BXClearCache(True, "/".SITE_ID."/blog/commented_posts/");
  100. BXClearCache(True, "/".SITE_ID."/blog/popular_posts/");
  101. BXClearCache(True, "/".SITE_ID."/blog/last_comments/");
  102. BXClearCache(True, "/".SITE_ID."/blog/groups/".$arBlog["GROUP_ID"]."/");
  103. BXClearCache(True, "/".SITE_ID."/blog/".$arBlog["URL"]."/trackback/".$show_id."/");
  104. BXClearCache(True, "/".SITE_ID."/blog/".$arBlog["URL"]."/rss_out/");
  105. BXClearCache(True, "/".SITE_ID."/blog/".$arBlog["URL"]."/rss_all/");
  106. BXClearCache(True, "/".SITE_ID."/blog/rss_sonet/");
  107. BXClearCache(True, "/".SITE_ID."/blog/rss_all/");
  108. BXClearCache(True, "/".SITE_ID."/blog/last_messages_list_extranet/");
  109. LocalRedirect($APPLICATION->GetCurPageParam("show_id=".$show_id."&success=Y", Array("del_id", "sessid", "success", "show_id")));
  110. }
  111. else
  112. $errorMessage = GetMessage("BLOG_BLOG_BLOG_MES_SHOW_ERROR");
  113. }
  114. }
  115. else
  116. $errorMessage = GetMessage("BLOG_BLOG_BLOG_MES_SHOW_NO_RIGHTS");
  117. }
  118. }
  119. }
  120. if ($errorMessage <> '')
  121. $arResult["ERROR_MESSAGE"][] = $errorMessage;
  122. if ($okMessage <> '')
  123. $arResult["OK_MESSAGE"][] = $okMessage;
  124. $arResult["POST"] = Array();
  125. $p = new blogTextParser(false, $arParams["PATH_TO_SMILE"]);
  126. $arParserParams = Array(
  127. "imageWidth" => $arParams["IMAGE_MAX_WIDTH"],
  128. "imageHeight" => $arParams["IMAGE_MAX_HEIGHT"],
  129. );
  130. $arPostColl1 = Array();
  131. $arPostColl2 = Array();
  132. $dbPost = CBlogPost::GetList(
  133. array("DATE_PUBLISH" => "DESC"),
  134. Array(
  135. "BLOG_ID" => $arBlog["ID"],
  136. "PUBLISH_STATUS" => BLOG_PUBLISH_STATUS_READY
  137. ),
  138. false,
  139. false,
  140. Array("ID", "BLOG_ID", "TITLE", "DATE_PUBLISH", "AUTHOR_ID", "DETAIL_TEXT", "BLOG_ACTIVE", "BLOG_URL", "BLOG_GROUP_ID", "BLOG_GROUP_SITE_ID", "AUTHOR_ID", "BLOG_OWNER_ID", "VIEWS", "NUM_COMMENTS", "ATTACH_IMG", "BLOG_SOCNET_GROUP_ID", "DETAIL_TEXT_TYPE", "CATEGORY_ID")
  141. );
  142. while($arPost = $dbPost->Fetch())
  143. {
  144. $arPost = CBlogTools::htmlspecialcharsExArray($arPost);
  145. $arPost["urlToAuthor"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER"], array("user_id" => $arPost["AUTHOR_ID"]));
  146. if($arPost["AUTHOR_ID"] == $arBlog["OWNER_ID"])
  147. {
  148. $arPost["urlToBlog"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_BLOG"], array("blog" => $arBlog["URL"], "user_id" => $arPost["AUTHOR_ID"]));
  149. }
  150. else
  151. {
  152. if($arOwnerBlog = CBlog::GetByOwnerID($arPost["AUTHOR_ID"], $arParams["GROUP_ID"]))
  153. $arPost["urlToBlog"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_BLOG"], array("blog" => $arOwnerBlog["URL"], "user_id" => $arPost["AUTHOR_ID"]));
  154. }
  155. $arPost["BlogUser"] = CBlogUser::GetByID($arPost["AUTHOR_ID"], BLOG_BY_USER_ID);
  156. $arPost["BlogUser"] = CBlogTools::htmlspecialcharsExArray($arPost["BlogUser"]);
  157. $arPost["BlogUser"]["AVATAR_file"] = CFile::GetFileArray($arPost["BlogUser"]["AVATAR"]);
  158. if ($arPost["BlogUser"]["AVATAR_file"] !== false)
  159. {
  160. $arPost["BlogUser"]["Avatar_resized"] = CFile::ResizeImageGet(
  161. $arPost["BlogUser"]["AVATAR_file"],
  162. array("width" => 100, "height" => 100),
  163. BX_RESIZE_IMAGE_EXACT,
  164. false
  165. );
  166. $arPost["BlogUser"]["AVATAR_img"] = CFile::ShowImage($arPost["BlogUser"]["Avatar_resized"]["src"], 100, 100, "border=0 align='right'");
  167. }
  168. $dbUser = CUser::GetByID($arPost["AUTHOR_ID"]);
  169. $arPost["arUser"] = $dbUser->GetNext();
  170. $arPost["AuthorName"] = CBlogUser::GetUserName($arPost["BlogUser"]["ALIAS"], $arPost["arUser"]["NAME"], $arPost["arUser"]["LAST_NAME"], $arPost["arUser"]["LOGIN"]);
  171. $arImages = array();
  172. $res = CBlogImage::GetList(array("ID"=>"ASC"),array("POST_ID"=>$arPost["ID"], "BLOG_ID"=>$arBlog["ID"], "IS_COMMENT" => "N"));
  173. while ($arImage = $res->Fetch())
  174. {
  175. $arImages[$arImage['ID']] = $arImage['FILE_ID'];
  176. $arPost["arImages"][$arImage['ID']] = Array(
  177. "small" => "/bitrix/components/bitrix/blog/show_file.php?fid=".$arImage['ID']."&width=70&height=70&type=square",
  178. "full" => "/bitrix/components/bitrix/blog/show_file.php?fid=".$arImage['ID']."&width=1000&height=1000"
  179. );
  180. }
  181. if($arPost["DETAIL_TEXT_TYPE"] == "html" && COption::GetOptionString("blog","allow_html", "N") == "Y")
  182. {
  183. $arAllow = array("HTML" => "Y", "ANCHOR" => "Y", "IMG" => "Y", "SMILES" => "Y", "NL2BR" => "N", "VIDEO" => "Y", "QUOTE" => "Y", "CODE" => "Y");
  184. if(COption::GetOptionString("blog","allow_video", "Y") != "Y")
  185. $arAllow["VIDEO"] = "N";
  186. $arPost["TEXT_FORMATED"] = $p->convert($arPost["~DETAIL_TEXT"], true, $arImages, $arAllow, $arParserParams);
  187. }
  188. else
  189. {
  190. $arAllow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "Y", "QUOTE" => "Y", "CODE" => "Y", "FONT" => "Y", "LIST" => "Y", "SMILES" => "Y", "NL2BR" => "N", "VIDEO" => "Y");
  191. if(COption::GetOptionString("blog","allow_video", "Y") != "Y")
  192. $arAllow["VIDEO"] = "N";
  193. $arPost["TEXT_FORMATED"] = $p->convert($arPost["~DETAIL_TEXT"], true, $arImages, $arAllow, $arParserParams);
  194. }
  195. $arPost["IMAGES"] = $arImages;
  196. if(!empty($p->showedImages))
  197. {
  198. foreach($p->showedImages as $val)
  199. {
  200. if(!empty($arPost["arImages"][$val]))
  201. unset($arPost["arImages"][$val]);
  202. }
  203. }
  204. $arPost["POST_PROPERTIES"] = array("SHOW" => "N");
  205. if (!empty($arParams["POST_PROPERTY_LIST"]))
  206. {
  207. $arPostFields = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields("BLOG_POST", $arPost["ID"], LANGUAGE_ID);
  208. if (count($arParams["POST_PROPERTY_LIST"]) > 0)
  209. {
  210. foreach ($arPostFields as $FIELD_NAME => $arPostField)
  211. {
  212. if (!in_array($FIELD_NAME, $arParams["POST_PROPERTY_LIST"]))
  213. continue;
  214. $arPostField["EDIT_FORM_LABEL"] = $arPostField["EDIT_FORM_LABEL"] <> '' ? $arPostField["EDIT_FORM_LABEL"] : $arPostField["FIELD_NAME"];
  215. $arPostField["EDIT_FORM_LABEL"] = htmlspecialcharsEx($arPostField["EDIT_FORM_LABEL"]);
  216. $arPostField["~EDIT_FORM_LABEL"] = $arPostField["EDIT_FORM_LABEL"];
  217. $arPost["POST_PROPERTIES"]["DATA"][$FIELD_NAME] = $arPostField;
  218. }
  219. }
  220. if (!empty($arPost["POST_PROPERTIES"]["DATA"]))
  221. $arPost["POST_PROPERTIES"]["SHOW"] = "Y";
  222. }
  223. if($arResult["PostPerm"]>=BLOG_PERMS_MODERATE)
  224. {
  225. $arPost["urlToShow"] = urlencode($APPLICATION->GetCurPageParam("show_id=".$arPost["ID"].'&'.bitrix_sessid_get(), Array("del_id", "sessid", "show_id", "success")));
  226. $arPost["urlToShow"] = htmlspecialcharsbx($arPost["urlToShow"]);
  227. }
  228. if($arResult["PostPerm"]>=BLOG_PERMS_FULL || $arPost["AUTHOR_ID"] == $user_id)
  229. $arPost["urlToEdit"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_POST_EDIT"], array("blog" => $arBlog["URL"], "post_id"=>$arPost["ID"], "user_id" => $arBlog["OWNER_ID"]));
  230. if($arResult["PostPerm"]>=BLOG_PERMS_FULL)
  231. {
  232. $arPost["urlToDelete"] = urlencode($APPLICATION->GetCurPageParam("del_id=".$arPost["ID"].'&'.bitrix_sessid_get(), Array("del_id", "sessid", "show_id", "success")));
  233. $arPost["urlToDelete"] = htmlspecialcharsbx($arPost["urlToDelete"]);
  234. }
  235. if($arPost["CATEGORY_ID"] <> '')
  236. {
  237. $arCategory = explode(",",$arPost["CATEGORY_ID"]);
  238. foreach($arCategory as $v)
  239. {
  240. if(intval($v)>0)
  241. {
  242. $arCatTmp = CBlogTools::htmlspecialcharsExArray(CBlogCategory::GetByID($v));
  243. $arCatTmp["urlToCategory"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_BLOG_CATEGORY"], array("blog" => $arBlog["URL"], "category_id" => $v, "user_id" => $arParams["USER_ID"]));
  244. $arPost["CATEGORY"][] = $arCatTmp;
  245. }
  246. }
  247. }
  248. $arPost["DATE_PUBLISH_FORMATED"] = FormatDate($arParams["DATE_TIME_FORMAT"], MakeTimeStamp($arPost["DATE_PUBLISH"], CSite::GetDateFormat("FULL")));
  249. $arPost["DATE_PUBLISH_DATE"] = ConvertDateTime($arPost["DATE_PUBLISH"], FORMAT_DATE);
  250. $arPost["DATE_PUBLISH_TIME"] = ConvertDateTime($arPost["DATE_PUBLISH"], "HH:MI");
  251. $arPost["DATE_PUBLISH_D"] = ConvertDateTime($arPost["DATE_PUBLISH"], "DD");
  252. $arPost["DATE_PUBLISH_M"] = ConvertDateTime($arPost["DATE_PUBLISH"], "MM");
  253. $arPost["DATE_PUBLISH_Y"] = ConvertDateTime($arPost["DATE_PUBLISH"], "YYYY");
  254. $arResult["POST"][] = $arPost;
  255. }
  256. }
  257. else
  258. $arResult["FATAL_ERROR"] = GetMessage("B_B_HIDE_NO_R_CR");
  259. }
  260. else
  261. $arResult["FATAL_ERROR"] = GetMessage("BLOG_BLOG_BLOG_NO_BLOG");
  262. }
  263. else
  264. {
  265. $arResult["FATAL_ERROR"] = GetMessage("BLOG_BLOG_BLOG_NO_BLOG");
  266. CHTTP::SetStatus("404 Not Found");
  267. }
  268. $this->IncludeComponentTemplate();
  269. ?>