PageRenderTime 70ms CodeModel.GetById 40ms RepoModel.GetById 0ms app.codeStats 1ms

/bitrix/modules/seo/include.php

https://bitbucket.org/bohdan1217/norka
PHP | 393 lines | 358 code | 35 blank | 0 comment | 45 complexity | 7de253ea098e63a20eae5843b585cf85 MD5 | raw file
  1. <?
  2. global $DB, $APPLICATION, $MESS, $DBType;
  3. \Bitrix\Main\Loader::registerAutoLoadClasses(
  4. "seo",
  5. array(
  6. 'CSeoUtils' => 'classes/general/seo_utils.php',
  7. 'CSeoKeywords' => 'classes/general/seo_keywords.php',
  8. 'CSeoPageChecker' => 'classes/general/seo_page_checker.php'
  9. )
  10. );
  11. if (!defined('SEO_COUNTERS_DEFAULT'))
  12. {
  13. if (COption::GetOptionString('main', 'vendor', '') == '1c_bitrix')
  14. {
  15. define(
  16. 'SEO_COUNTERS_DEFAULT',
  17. "<img src=\"http://yandex.ru/cycounter?#DOMAIN#\" width=\"88\" height=\"31\" border=\"0\" />"
  18. );
  19. }
  20. else
  21. {
  22. define(
  23. 'SEO_COUNTERS_DEFAULT',
  24. '<a href="http://www.whats-my-pagerank.com" target="_blank"><img src = "http://www.whats-my-pagerank.com/pagerank2.php" alt="PR Checker" border="0" /></a>'
  25. );
  26. }
  27. }
  28. IncludeModuleLangFile(__FILE__);
  29. class CSeoEventHandlers
  30. {
  31. function SeoOnPanelCreate()
  32. {
  33. global $APPLICATION, $USER;
  34. if (!$USER->CanDoOperation('seo_tools'))
  35. return false;
  36. if (isset($_SERVER["REAL_FILE_PATH"]) && $_SERVER["REAL_FILE_PATH"] != "")
  37. {
  38. $currentDirPath = dirname($_SERVER["REAL_FILE_PATH"]);
  39. $currentFilePath = $_SERVER["REAL_FILE_PATH"];
  40. }
  41. else
  42. {
  43. $currentDirPath = $APPLICATION->GetCurDir();
  44. $currentFilePath = $APPLICATION->GetCurPage(true);
  45. }
  46. $encCurrentDirPath = urlencode($currentDirPath);
  47. $encCurrentFilePath = urlencode($currentFilePath);
  48. $encRequestUri = urlencode($_SERVER["REQUEST_URI"]);
  49. $encTitleChangerLink = '';
  50. $encWinTitleChangerLink = '';
  51. $encTitleChangerName = '';
  52. $encWinTitleChangerName = '';
  53. if (is_array($APPLICATION->sDocTitleChanger))
  54. {
  55. if (isset($APPLICATION->sDocTitleChanger['PUBLIC_EDIT_LINK']))
  56. $encTitleChangerLink = urlencode(base64_encode($APPLICATION->sDocTitleChanger['PUBLIC_EDIT_LINK']));
  57. if (isset($APPLICATION->sDocTitleChanger['COMPONENT_NAME']))
  58. $encTitleChangerName = urlencode($APPLICATION->sDocTitleChanger['COMPONENT_NAME']);
  59. }
  60. $prop_code = ToUpper(COption::GetOptionString('seo', 'property_window_title', 'title'));
  61. if (is_array($APPLICATION->arPagePropertiesChanger[$prop_code]))
  62. {
  63. if (isset($APPLICATION->arPagePropertiesChanger[$prop_code]['PUBLIC_EDIT_LINK']))
  64. $encWinTitleChangerLink = urlencode(base64_encode($APPLICATION->arPagePropertiesChanger[$prop_code]['PUBLIC_EDIT_LINK']));
  65. if (isset($APPLICATION->arPagePropertiesChanger[$prop_code]['COMPONENT_NAME']))
  66. $encWinTitleChangerName = urlencode($APPLICATION->arPagePropertiesChanger[$prop_code]['COMPONENT_NAME']);
  67. }
  68. $encTitle = urlencode(base64_encode($APPLICATION->sDocTitle));
  69. $encWinTitle = urlencode(base64_encode($APPLICATION->arPageProperties[$prop_code]));
  70. $APPLICATION->AddPanelButton(array(
  71. "HREF"=> 'javascript:'.$APPLICATION->GetPopupLink(
  72. array(
  73. "URL"=>"/bitrix/admin/public_seo_tools.php?lang=".LANGUAGE_ID."&bxpublic=Y&from_module=seo&site=".SITE_ID
  74. ."&path=".$encCurrentFilePath
  75. ."&title_final=".$encTitle."&title_changer_name=".$encTitleChangerName.'&title_changer_link='.$encTitleChangerLink
  76. ."&title_win_final=".$encWinTitle."&title_win_changer_name=".$encWinTitleChangerName.'&title_win_changer_link='.$encWinTitleChangerLink
  77. ."&".bitrix_sessid_get()
  78. ."&back_url=".$encRequestUri,
  79. "PARAMS"=> Array("width"=>920, "height" => 400, 'resize' => false)
  80. )),
  81. "ID"=>"seo",
  82. "ICON" => "bx-panel-seo-icon",
  83. "ALT"=>GetMessage('SEO_ICON_ALT'),
  84. "TEXT"=>GetMessage('SEO_ICON_TEXT'),
  85. "MAIN_SORT"=>"300",
  86. "SORT"=> 50,
  87. "HINT" => array(
  88. "TITLE" => GetMessage('SEO_ICON_TEXT'),
  89. "TEXT" => GetMessage('SEO_ICON_HINT')
  90. ),
  91. ));
  92. }
  93. public static function OnIncludeHTMLEditorScript()
  94. {
  95. if (COption::GetOptionString('main', 'vendor', '') == '1c_bitrix' && defined('ADMIN_SECTION'))
  96. {
  97. ?>
  98. <script>
  99. ;(function(){
  100. var originalTextWnd = null;
  101. var originalTextBtn = new BX.CWindowButton({
  102. title: '<?=GetMessageJS('SEO_UNIQUE_TEXT_YANDEX_SUBMIT')?>',
  103. className: 'adm-btn-save',
  104. action: function()
  105. {
  106. var content = document.forms.seo_original_text_form.original_text.value;
  107. var domain = document.forms.seo_original_text_form.domain.options[document.forms.seo_original_text_form.domain.selectedIndex].value;
  108. if(content.length < <?=\Bitrix\Seo\Engine\Yandex::ORIGINAL_TEXT_MIN_LENGTH?>)
  109. {
  110. alert('<?=GetMessageJS('SEO_YANDEX_ORIGINAL_TEXT_TOO_SHORT', array('#NUM#' => \Bitrix\Seo\Engine\Yandex::ORIGINAL_TEXT_MIN_LENGTH))?>');
  111. }
  112. else if(content.length > <?=\Bitrix\Seo\Engine\Yandex::ORIGINAL_TEXT_MAX_LENGTH?>)
  113. {
  114. alert('<?=GetMessageJS('SEO_YANDEX_ORIGINAL_TEXT_TOO_LONG', array('#NUM#' => \Bitrix\Seo\Engine\Yandex::ORIGINAL_TEXT_MAX_LENGTH))?>');
  115. }
  116. else
  117. {
  118. originalTextBtn.disable();
  119. BX.ajax({
  120. method: 'POST',
  121. dataType: 'json',
  122. url: '/bitrix/tools/seo_yandex.php',
  123. data: {
  124. action: 'original_text',
  125. domain: domain,
  126. dir: '/',
  127. original_text: content,
  128. sessid: BX.bitrix_sessid()
  129. },
  130. onsuccess: function(res)
  131. {
  132. originalTextBtn.enable();
  133. if(!!res.error)
  134. {
  135. alert(BX.util.strip_tags(res.error));
  136. }
  137. else
  138. {
  139. BX('seo_original_text_form_form').style.display = 'none';
  140. BX('seo_original_text_form_ok').style.display = 'block';
  141. originalTextBtn.btn.disabled = true;
  142. originalTextWnd.adjustSizeEx();
  143. BX.defer(originalTextWnd.adjustPos, originalTextWnd)();
  144. }
  145. }
  146. });
  147. }
  148. }
  149. });
  150. var originalTextLoader = function(res)
  151. {
  152. BX.closeWait();
  153. originalTextWnd = new BX.CDialog({
  154. content: res,
  155. resizable: false,
  156. width: 750,
  157. height: 550,
  158. title: '<?=GetMessageJS('SEO_UNIQUE_TEXT_YANDEX')?>',
  159. buttons: [
  160. originalTextBtn
  161. ]
  162. });
  163. originalTextHandler.apply(this, arguments);
  164. };
  165. var originalTextHandler = function()
  166. {
  167. if(!originalTextWnd)
  168. {
  169. BX.showWait();
  170. BX.ajax.get('/bitrix/tools/seo_yandex.php?get=original_text_form&sessid=' + BX.bitrix_sessid(), BX.proxy(originalTextLoader, this));
  171. }
  172. else if(!!document.forms.seo_original_text_form)
  173. {
  174. this.pMainObj.SaveContent();
  175. var content = BX.util.strip_tags(
  176. this.pMainObj.GetContent()
  177. .replace(/<\?(.|[\r\n])*?\?>/g, '')
  178. .replace(/#PHP[^#]*#/ig, '')
  179. );
  180. originalTextWnd.Show();
  181. document.forms.seo_original_text_form.original_text.value = content;
  182. BX('seo_original_text_form_form').style.display = 'block';
  183. BX('seo_original_text_form_ok').style.display = 'none';
  184. originalTextWnd.adjustSizeEx();
  185. originalTextBtn.enable();
  186. originalTextBtn.btn.disabled = false;
  187. BX.defer(originalTextWnd.adjustPos, originalTextWnd)();
  188. }
  189. else
  190. {
  191. originalTextWnd.Show();
  192. originalTextBtn.btn.disabled = true;
  193. }
  194. };
  195. var seoEditorButton = ['BXButton',
  196. {
  197. id : 'SeoUniqText',
  198. src : '/bitrix/panel/seo/images/icon_editor_toolbar.png',
  199. name : '<?=CUtil::JSEscape(GetMessage('SEO_UNIQUE_TEXT_YANDEX'))?>',
  200. codeEditorMode : true,
  201. handler : originalTextHandler
  202. }];
  203. if(typeof window.arToolbars != 'undefined' && !window.bSeoToolbarButtonAdded)
  204. {
  205. if(typeof window.arToolbars['manage'] != 'undefined')
  206. {
  207. window.arToolbars['manage'][1].push(seoEditorButton);
  208. }
  209. else
  210. {
  211. window.arToolbars['standart'][1].push(seoEditorButton);
  212. }
  213. window.bSeoToolbarButtonAdded = true;
  214. }
  215. if(typeof window.arGlobalToolbar != 'undefined' && !window.bSeoGlobalToolbarButtonAdded)
  216. {
  217. window.arGlobalToolbar.push(seoEditorButton);
  218. window.bSeoGlobalToolbarButtonAdded = true;
  219. }
  220. })();
  221. </script>
  222. <?
  223. }
  224. }
  225. public static function OnBeforeHTMLEditorScriptRuns()
  226. {
  227. if (COption::GetOptionString('main', 'vendor', '') == '1c_bitrix' && defined('ADMIN_SECTION'))
  228. {
  229. ?>
  230. <script>
  231. ;(function(){
  232. var originalTextWnd = null;
  233. var originalTextBtn = new BX.CWindowButton({
  234. title: '<?=GetMessageJS('SEO_UNIQUE_TEXT_YANDEX_SUBMIT')?>',
  235. className: 'adm-btn-save',
  236. action: function()
  237. {
  238. var content = document.forms.seo_original_text_form.original_text.value;
  239. var domain = document.forms.seo_original_text_form.domain.options[document.forms.seo_original_text_form.domain.selectedIndex].value;
  240. if(content.length < <?=\Bitrix\Seo\Engine\Yandex::ORIGINAL_TEXT_MIN_LENGTH?>)
  241. {
  242. alert('<?=GetMessageJS('SEO_YANDEX_ORIGINAL_TEXT_TOO_SHORT', array('#NUM#' => \Bitrix\Seo\Engine\Yandex::ORIGINAL_TEXT_MIN_LENGTH))?>');
  243. }
  244. else if(content.length > <?=\Bitrix\Seo\Engine\Yandex::ORIGINAL_TEXT_MAX_LENGTH?>)
  245. {
  246. alert('<?=GetMessageJS('SEO_YANDEX_ORIGINAL_TEXT_TOO_LONG', array('#NUM#' => \Bitrix\Seo\Engine\Yandex::ORIGINAL_TEXT_MAX_LENGTH))?>');
  247. }
  248. else
  249. {
  250. originalTextBtn.disable();
  251. BX.ajax({
  252. method: 'POST',
  253. dataType: 'json',
  254. url: '/bitrix/tools/seo_yandex.php',
  255. data: {
  256. action: 'original_text',
  257. domain: domain,
  258. dir: '/',
  259. original_text: content,
  260. sessid: BX.bitrix_sessid()
  261. },
  262. onsuccess: function(res)
  263. {
  264. originalTextBtn.enable();
  265. if(!!res.error)
  266. {
  267. alert(BX.util.strip_tags(res.error));
  268. }
  269. else
  270. {
  271. BX('seo_original_text_form_form').style.display = 'none';
  272. BX('seo_original_text_form_ok').style.display = 'block';
  273. originalTextBtn.btn.disabled = true;
  274. originalTextWnd.adjustSizeEx();
  275. BX.defer(originalTextWnd.adjustPos, originalTextWnd)();
  276. }
  277. }
  278. });
  279. }
  280. }
  281. });
  282. var originalTextHandler = function(editor)
  283. {
  284. if(!originalTextWnd)
  285. {
  286. BX.showWait();
  287. BX.ajax.get(
  288. '/bitrix/tools/seo_yandex.php?get=original_text_form&sessid=' + BX.bitrix_sessid(),
  289. BX.delegate(function(res)
  290. {
  291. BX.closeWait();
  292. originalTextWnd = new BX.CDialog({
  293. content: res,
  294. resizable: false,
  295. width: 750,
  296. height: 550,
  297. title: '<?=GetMessageJS('SEO_UNIQUE_TEXT_YANDEX')?>',
  298. buttons: [
  299. originalTextBtn
  300. ]
  301. });
  302. originalTextHandler.apply(this, [editor]);
  303. }, this)
  304. );
  305. }
  306. else if(!!document.forms.seo_original_text_form)
  307. {
  308. var content = BX.util.strip_tags(
  309. editor.GetContent()
  310. .replace(/<\?(.|[\r\n])*?\?>/g, '')
  311. .replace(/#PHP[^#]*#/ig, '')
  312. );
  313. originalTextWnd.Show();
  314. document.forms.seo_original_text_form.original_text.value = content;
  315. BX('seo_original_text_form_form').style.display = 'block';
  316. BX('seo_original_text_form_ok').style.display = 'none';
  317. originalTextWnd.adjustSizeEx();
  318. originalTextBtn.enable();
  319. originalTextBtn.btn.disabled = false;
  320. BX.defer(originalTextWnd.adjustPos, originalTextWnd)();
  321. }
  322. else
  323. {
  324. originalTextWnd.Show();
  325. originalTextBtn.btn.disabled = true;
  326. }
  327. };
  328. function applyForEditor(editor)
  329. {
  330. editor.AddButton(
  331. {
  332. id : 'SeoUniqText',
  333. src : '/bitrix/panel/seo/images/icon_editor_toolbar_2.png',
  334. name : '<?=CUtil::JSEscape(GetMessage('SEO_UNIQUE_TEXT_YANDEX'))?>',
  335. codeEditorMode : true,
  336. handler : function(){originalTextHandler(editor);},
  337. toolbarSort: 305
  338. }
  339. );
  340. }
  341. if (window.BXHtmlEditor && window.BXHtmlEditor.editors)
  342. {
  343. for (var id in window.BXHtmlEditor.editors)
  344. {
  345. if (window.BXHtmlEditor.editors.hasOwnProperty(id))
  346. {
  347. applyForEditor(window.BXHtmlEditor.Get(id))
  348. }
  349. }
  350. }
  351. BX.addCustomEvent("OnEditorInitedBefore", applyForEditor);
  352. })();
  353. </script>
  354. <?
  355. }
  356. }
  357. }
  358. ?>