PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/search/admin/search_sitemap.php

https://gitlab.com/alexprowars/bitrix
PHP | 279 lines | 250 code | 27 blank | 2 comment | 27 complexity | 2637f177b48cd4a0b991bf920b251f66 MD5 | raw file
  1. <?
  2. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  3. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/search/prolog.php");
  4. IncludeModuleLangFile(__FILE__);
  5. /** @global CMain $APPLICATION */
  6. global $APPLICATION;
  7. /** @var CAdminMessage $message */
  8. $searchDB = CDatabase::GetModuleConnection('search');
  9. $POST_RIGHT = $APPLICATION->GetGroupRight("search");
  10. if($POST_RIGHT=="D")
  11. $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
  12. $arSiteMap=false;
  13. if($_SERVER["REQUEST_METHOD"] == "POST" && $_REQUEST["Generate"]=="Y")
  14. {
  15. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_js.php");
  16. if(check_bitrix_sessid())
  17. {
  18. if(array_key_exists("NS", $_POST) && is_array($_POST["NS"]))
  19. {
  20. $NS = $_POST["NS"];
  21. }
  22. else
  23. {
  24. $NS = array();
  25. $sm_max_execution_time = intval($_REQUEST["sm_max_execution_time"]);
  26. if($sm_max_execution_time < 1)
  27. $sm_max_execution_time = 30;
  28. COption::SetOptionString("search", "sm_max_execution_time", $sm_max_execution_time);
  29. $sm_record_limit = intval($_REQUEST["sm_record_limit"]);
  30. if($sm_record_limit < 1)
  31. $sm_record_limit = 5000;
  32. COption::SetOptionString("search", "sm_record_limit", $sm_record_limit);
  33. COption::SetOptionString("search", "sm_forum_topics_only", ($_REQUEST["sm_forum_topics_only"] == "Y"? "Y": "N"));
  34. COption::SetOptionString("search", "sm_blog_no_comments", ($_REQUEST["sm_blog_no_comments"] == "Y"? "Y": "N"));
  35. COption::SetOptionString("search", "sm_use_https", ($_REQUEST["sm_use_https"] == "Y"? "Y": "N"));
  36. }
  37. $cSiteMap = new CSiteMap;
  38. $arOptions = array(
  39. "FORUM_TOPICS_ONLY" => COption::GetOptionString("search", "sm_forum_topics_only"),
  40. "BLOG_NO_COMMENTS" => COption::GetOptionString("search", "sm_blog_no_comments"),
  41. "USE_HTTPS" => COption::GetOptionString("search", "sm_use_https"),
  42. );
  43. $sm_max_execution_time = COption::GetOptionString("search", "sm_max_execution_time");
  44. $sm_record_limit = COption::GetOptionString("search", "sm_record_limit");
  45. $arSiteMap=$cSiteMap->Create($SM_SITE_ID, array($sm_max_execution_time, $sm_record_limit), $NS, $arOptions);
  46. if(is_array($arSiteMap)):
  47. CAdminMessage::ShowMessage(array(
  48. "TYPE" => "PROGRESS",
  49. "HTML" => true,
  50. "DETAILS" => GetMessage("SEARCH_SITEMAP_DOC_COUNT").": <b>".intval($arSiteMap["CNT"])."</b>.<br>"
  51. .GetMessage("SEARCH_SITEMAP_ERR_COUNT").": <b>".intval($arSiteMap["ERROR_CNT"])."</b>.<br>",
  52. ));
  53. ?>
  54. <script>
  55. CloseWaitWindow();
  56. DoNext(<?echo CUtil::PhpToJSObject(array("NS"=>$arSiteMap))?>);
  57. </script>
  58. <?elseif($arSiteMap===true):?>
  59. <?echo BeginNote()?>
  60. <p><?echo GetMessage("SEARCH_SITEMAP_CREATED")?>: <b><a href="<?=htmlspecialcharsbx($cSiteMap->m_href)?>"><?=$cSiteMap->m_href?></a></b></p>
  61. <p><?echo GetMessage("SEARCH_SITEMAP_INSTR1")?>:</p>
  62. <ol>
  63. <li>
  64. <?echo GetMessage("SEARCH_SITEMAP_INSTR2")?> <a href="https://www.google.com/webmasters/tools/home">Google Sitemaps</a>
  65. <?echo GetMessage("SEARCH_SITEMAP_INSTR3")?> <a href="https://www.google.com/accounts/ManageAccount"><?echo GetMessage("SEARCH_SITEMAP_INSTR7")?></a>
  66. </li>
  67. <li>
  68. <?echo GetMessage("SEARCH_SITEMAP_INSTR4")?> <strong>"<? echo GetMessage("SEARCH_SITEMAP_INSTR8")?>"</strong>.
  69. </li>
  70. <li>
  71. <?echo GetMessage("SEARCH_SITEMAP_INSTR5")?>.
  72. </li>
  73. </ol>
  74. <p><?echo GetMessage("SEARCH_SITEMAP_INSTR6")?></p>
  75. <?if($cSiteMap->m_errors_count>0):?>
  76. <p>
  77. <?echo GetMessage("SEARCH_SITEMAP_WARN")?> <a href="<?=htmlspecialcharsbx($cSiteMap->m_errors_href)?>"><?=$cSiteMap->m_errors_href?></a>.
  78. <br><?echo GetMessage("SEARCH_SITEMAP_WARN1")?>.
  79. </p>
  80. <?endif;?>
  81. <?echo EndNote()?>
  82. <script>
  83. CloseWaitWindow();
  84. EndReindex();
  85. </script>
  86. <?elseif($arSiteMap===false):?>
  87. <?CAdminMessage::ShowMessage(array(
  88. "MESSAGE" => GetMessage("SEARCH_SITEMAP_ERR"),
  89. "DETAILS" => $cSiteMap->m_error,
  90. "TYPE" => "ERROR",
  91. "HTML" => "Y",
  92. ));?>
  93. <script>
  94. CloseWaitWindow();
  95. EndReindex();
  96. </script>
  97. <?endif;
  98. }
  99. else
  100. {
  101. CAdminMessage::ShowMessage(GetMessage("SEARCH_SITEMAP_SESSION_ERR"));
  102. ?>
  103. <script>
  104. CloseWaitWindow();
  105. EndReindex();
  106. </script>
  107. <?
  108. }
  109. require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/epilog_admin_js.php");
  110. }
  111. else
  112. {
  113. $APPLICATION->SetTitle(GetMessage("SEARCH_SITEMAP_TITLE"));
  114. $aTabs = array(
  115. array("DIV" => "edit1", "TAB" => "Google Sitemap", "ICON"=>"main_user_edit", "TITLE"=>GetMessage("SEARCH_SITEMAP_TAB_TITLE")),
  116. );
  117. $tabControl = new CAdminTabControl("tabControl", $aTabs, true, true);
  118. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
  119. if(is_object($message))
  120. echo $message->Show();
  121. ?>
  122. <script language="JavaScript">
  123. var savedNS;
  124. var stop;
  125. var interval = 0;
  126. function StartReindex()
  127. {
  128. stop=false;
  129. document.getElementById('reindex_result_div').innerHTML='';
  130. document.getElementById('stop_button').disabled=false;
  131. document.getElementById('start_button').disabled=true;
  132. document.getElementById('continue_button').disabled=true;
  133. DoNext();
  134. }
  135. function DoNext(NS)
  136. {
  137. var queryString = 'Generate=Y'
  138. + '&lang=<?echo urlencode(LANGUAGE_ID)?>'
  139. + '&<?echo bitrix_sessid_get()?>';
  140. var ck = document.getElementById('sm_forum_topics_only');
  141. if(ck && ck.checked)
  142. queryString += '&sm_forum_topics_only=Y';
  143. ck = document.getElementById('sm_blog_no_comments');
  144. if(ck && ck.checked)
  145. queryString += '&sm_blog_no_comments=Y';
  146. ck = document.getElementById('sm_use_https');
  147. if(ck && ck.checked)
  148. queryString += '&sm_use_https=Y';
  149. queryString+='&SM_SITE_ID='+document.fs2.SM_SITE_ID.value;
  150. if(!NS)
  151. {
  152. interval = parseInt(document.getElementById('sm_max_execution_time').value);
  153. queryString += '&sm_max_execution_time='+interval;
  154. queryString += '&sm_record_limit='+document.getElementById('sm_record_limit').value;
  155. }
  156. savedNS = NS;
  157. if(!stop)
  158. {
  159. ShowWaitWindow();
  160. BX.ajax.post(
  161. 'search_sitemap.php?'+queryString,
  162. NS,
  163. function(result){
  164. document.getElementById('reindex_result_div').innerHTML = result;
  165. }
  166. );
  167. }
  168. }
  169. function StopReindex()
  170. {
  171. stop=true;
  172. document.getElementById('stop_button').disabled=true;
  173. document.getElementById('start_button').disabled=false;
  174. document.getElementById('continue_button').disabled=false;
  175. }
  176. function ContinueReindex()
  177. {
  178. stop=false;
  179. document.getElementById('stop_button').disabled=false;
  180. document.getElementById('start_button').disabled=true;
  181. document.getElementById('continue_button').disabled=true;
  182. DoNext(savedNS);
  183. }
  184. function EndReindex()
  185. {
  186. stop=true;
  187. document.getElementById('stop_button').disabled=true;
  188. document.getElementById('start_button').disabled=false;
  189. document.getElementById('continue_button').disabled=true;
  190. }
  191. </script>
  192. <div id="reindex_result_div">
  193. </div>
  194. <form method="POST" action="<?echo $APPLICATION->GetCurPage()?>?lang=<?echo htmlspecialcharsbx(LANG)?>" name="fs2">
  195. <?
  196. $sm_max_execution_time = intval(COption::GetOptionInt("search", "sm_max_execution_time"));
  197. if($sm_max_execution_time < 1)
  198. $sm_max_execution_time = 30;
  199. $sm_record_limit = intval(COption::GetOptionInt("search", "sm_record_limit"));
  200. if($sm_record_limit < 1)
  201. $sm_record_limit = 5000;
  202. $tabControl->Begin();
  203. $tabControl->BeginNextTab();
  204. ?>
  205. <tr>
  206. <td width="40%"><?echo GetMessage("SEARCH_SITEMAP_SITE")?></td>
  207. <td width="60%"><?echo CLang::SelectBox("SM_SITE_ID", SITE_ID);?></td>
  208. </tr>
  209. <tr>
  210. <td><?echo GetMessage("SEARCH_SITEMAP_STEP")?></td>
  211. <td><input type="text" name="sm_max_execution_time" id="sm_max_execution_time" size="5" value="<?echo $sm_max_execution_time?>"> <?echo GetMessage("SEARCH_SITEMAP_STEP_sec")?></td>
  212. </tr>
  213. <tr>
  214. <td><?echo GetMessage("SEARCH_SITEMAP_RECORD_LIMIT")?></td>
  215. <td><input type="text" name="sm_record_limit" id="sm_record_limit" size="5" value="<?echo $sm_record_limit?>"></td>
  216. </tr>
  217. <?if(IsModuleInstalled("forum")):?>
  218. <tr>
  219. <td><label for="sm_forum_topics_only"><?echo GetMessage("SEARCH_SITEMAP_FORUM_TOPICS_ONLY")?>:</label></td>
  220. <td><input type="checkbox" id="sm_forum_topics_only" name="sm_forum_topics_only" value="Y"<?
  221. if(COption::GetOptionString("search", "sm_forum_topics_only")=="Y") echo ' checked="checked"'?>></td>
  222. </tr>
  223. <?endif?>
  224. <?if(IsModuleInstalled("blog")):?>
  225. <tr>
  226. <td><label for="sm_blog_no_comments"><?echo GetMessage("SEARCH_SITEMAP_BLOG_NO_COMMENTS")?>:</label></td>
  227. <td><input type="checkbox" id="sm_blog_no_comments" name="sm_blog_no_comments" value="Y"<?
  228. if(COption::GetOptionString("search", "sm_blog_no_comments")=="Y") echo ' checked="checked"'?>></td>
  229. </tr>
  230. <?endif?>
  231. <tr>
  232. <td><label for="sm_use_https"><?echo GetMessage("SEARCH_SITEMAP_USE_HTTPS")?>:</label></td>
  233. <td><input type="checkbox" id="sm_use_https" name="sm_use_https" value="Y"<?
  234. if(COption::GetOptionString("search", "sm_use_https")=="Y") echo ' checked="checked"'?>></td>
  235. </tr>
  236. <?
  237. $tabControl->Buttons();
  238. ?>
  239. <input type="button" id="start_button" value="<?=GetMessage("SEARCH_SITEMAP_CREATE")?>" OnClick="StartReindex();" class="adm-btn-save">
  240. <input type="button" id="stop_button" value="<?=GetMessage("SEARCH_SITEMAP_STOP")?>" OnClick="StopReindex();" disabled>
  241. <input type="button" id="continue_button" value="<?=GetMessage("SEARCH_SITEMAP_CONTINUE")?>" OnClick="ContinueReindex();" disabled>
  242. <?
  243. $tabControl->End();
  244. ?>
  245. </form>
  246. <?echo BeginNote();?>
  247. <?echo GetMessage("SEARCH_SITEMAP_NOTE")?>
  248. <?echo EndNote();?>
  249. <?
  250. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");
  251. }
  252. ?>