PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/landing/options.php

https://gitlab.com/alexprowars/bitrix
PHP | 479 lines | 427 code | 31 blank | 21 comment | 59 complexity | ed49657c2e65dd47189b193538e0f1cc MD5 | raw file
  1. <?php
  2. $module_id = 'landing';
  3. use \Bitrix\Landing\Manager;
  4. use \Bitrix\Main\Localization\Loc;
  5. use \Bitrix\Main\SiteTemplateTable;
  6. if (!\Bitrix\Main\Loader::includeModule('landing'))
  7. {
  8. return;
  9. }
  10. /** @var \CMain $APPLICATION */
  11. // vars
  12. $context = \Bitrix\Main\Application::getInstance()->getContext();
  13. $request = $context->getRequest();
  14. $mid = $request->get('mid');
  15. $backUrl = $request->get('back_url_settings');
  16. $docRoot = Manager::getDocRoot();
  17. $postRight = $APPLICATION->GetGroupRight($module_id);
  18. // lang
  19. IncludeModuleLangFile($docRoot . '/bitrix/modules/main/options.php');
  20. Loc::loadMessages(__FILE__);
  21. // local function for build iblocks tree
  22. $getIblocksTree = function()
  23. {
  24. static $iblocks = null;
  25. if ($iblocks !== null)
  26. {
  27. return $iblocks;
  28. }
  29. $iblocks = [];
  30. if (\Bitrix\Main\Loader::includeModule('iblock'))
  31. {
  32. // first gets types
  33. $iblockTypes = [];
  34. $res = \CIBlockType::getList();
  35. while($row = $res->fetch())
  36. {
  37. if ($typeLang = \CIBlockType::getByIDLang($row['ID'], LANG))
  38. {
  39. $iblockTypes[$typeLang['IBLOCK_TYPE_ID']] = [
  40. 'NAME' => $typeLang['NAME'],
  41. 'SORT' => $typeLang['SORT']
  42. ];
  43. }
  44. }
  45. // and iblocks then
  46. $res = \CIBlock::getList(['sort' => 'asc']);
  47. while ($row = $res->GetNext(true, false))
  48. {
  49. if (!isset($iblocks[$row['IBLOCK_TYPE_ID']]))
  50. {
  51. $iblocks[$row['IBLOCK_TYPE_ID']] = [
  52. 'ID' => $row['IBLOCK_TYPE_ID'],
  53. 'NAME' => $iblockTypes[$row['IBLOCK_TYPE_ID']]['NAME'],
  54. 'SORT' => $iblockTypes[$row['IBLOCK_TYPE_ID']]['SORT'],
  55. 'ITEMS' => []
  56. ];
  57. }
  58. $iblocks[$row['IBLOCK_TYPE_ID']]['ITEMS'][] = [
  59. 'ID' => $row['ID'],
  60. 'NAME' => $row['NAME']
  61. ];
  62. }
  63. // sorting by sort
  64. usort($iblocks,
  65. function($a, $b)
  66. {
  67. if ($a['SORT'] == $b['SORT'])
  68. {
  69. return 0;
  70. }
  71. return ($a['SORT'] < $b['SORT']) ? -1 : 1;
  72. }
  73. );
  74. return $iblocks;
  75. }
  76. };
  77. if ($postRight >= 'R'):
  78. // sites list
  79. $sites = [];
  80. $res = \Bitrix\Main\SiteTable::getList(array(
  81. 'select' => array(
  82. '*'
  83. ),
  84. 'filter' => array(
  85. 'ACTIVE' => 'Y'
  86. ),
  87. 'order' => array(
  88. 'SORT' => 'ASC'
  89. )
  90. ));
  91. while ($row = $res->fetch())
  92. {
  93. $row['NAME'] = \htmlspecialcharsbx($row['NAME']);
  94. $sites[] = $row;
  95. }
  96. // site templates
  97. $allOptions[] = array(
  98. 'site_template_id',
  99. Loc::getMessage('LANDING_OPT_SITE_TEMPLATE_ID') . ':',
  100. array('text', 32)
  101. );
  102. $allOptions[] = array(
  103. 'header',
  104. Loc::getMessage('LANDING_OPT_SITE_TEMPLATE_ID_SITES')
  105. );
  106. foreach ($sites as $row)
  107. {
  108. $allOptions[] = array(
  109. 'site_template_id_' . $row['LID'],
  110. $row['NAME'] . ' [' . $row['LID'] . ']:',
  111. array('text', 32)
  112. );
  113. }
  114. // paths for sites
  115. $allOptions[] = array(
  116. 'header',
  117. Loc::getMessage('LANDING_OPT_PUB_PATH_HEADER'),
  118. Loc::getMessage('LANDING_OPT_PUB_PATH_HELP')
  119. );
  120. foreach ($sites as $row)
  121. {
  122. $allOptions[] = array(
  123. 'pub_path_' . $row['LID'],
  124. $row['NAME'] . ' [' . $row['LID'] . ']:',
  125. array('text', 32),
  126. \Bitrix\Landing\Manager::getPublicationPathConst()
  127. );
  128. }
  129. // other options
  130. $allOptions[] = array(
  131. 'header',
  132. Loc::getMessage('LANDING_OPT_OTHER')
  133. );
  134. $allOptions[] = array(
  135. 'google_images_key',
  136. Loc::getMessage('LANDING_OPT_GOOGLE_IMAGES_KEY') . ':',
  137. array('text', 32)
  138. );
  139. if (Manager::isB24())
  140. {
  141. $allOptions[] = array(
  142. 'portal_url',
  143. Loc::getMessage('LANDING_OPT_PORTAL_URL') . ':',
  144. array('text', 32)
  145. );
  146. }
  147. $allOptions[] = array(
  148. 'deleted_lifetime_days',
  149. Loc::getMessage('LANDING_OPT_DELETED_LIFETIME_DAYS') . ':',
  150. array('text', 4)
  151. );
  152. if (Manager::isB24())
  153. {
  154. $allOptions[] = array(
  155. 'rights_extended_mode',
  156. Loc::getMessage('LANDING_OPT_RIGHTS_EXTENDED_MODE') . ':',
  157. array('checkbox')
  158. );
  159. }
  160. $allOptions[] = array(
  161. 'public_hook_on_save',
  162. Loc::getMessage('LANDING_OPT_PUBLIC_HOOK_ON_SAVE') . ':',
  163. array('checkbox')
  164. );
  165. /*$allOptions[] = array(
  166. 'strict_verification_update',
  167. Loc::getMessage('LANDING_OPT_STRICT_VERIFICATION_UPDATE') . ':',
  168. array('checkbox')
  169. );*/
  170. $allOptions[] = array(
  171. 'source_iblocks',
  172. Loc::getMessage('LANDING_OPT_SOURCE_IBLOCKS') . ':',
  173. array(
  174. 'selectboxtree',
  175. $getIblocksTree(),
  176. 'multiple="multiple" size="10"'
  177. )
  178. );
  179. // tabs
  180. $tabControl = new \CAdmintabControl('tabControl', array(
  181. array('DIV' => 'edit1', 'TAB' => Loc::getMessage('MAIN_TAB_SET'), 'ICON' => ''),
  182. array('DIV' => 'edit2', 'TAB' => Loc::getMessage('MAIN_TAB_RIGHTS'), 'ICON' => '')
  183. ));
  184. $Update = $Update ?? '';
  185. $Apply = $Apply ?? '';
  186. // post save
  187. if (
  188. $Update . $Apply <> '' &&
  189. ($postRight=='W' || $postRight=='X') &&
  190. \check_bitrix_sessid()
  191. )
  192. {
  193. $clearTmplCache = false;
  194. foreach ($allOptions as $arOption)
  195. {
  196. if ($arOption[0] == 'header')
  197. {
  198. continue;
  199. }
  200. $name = $arOption[0];
  201. if ($arOption[2][0] == 'text-list')
  202. {
  203. $val = '';
  204. for ($j = 0; $j < count($$name); $j++)
  205. {
  206. if (trim(${$name}[$j]) <> '')
  207. {
  208. $val .= ($val <> '' ? ',':'') . trim(${$name}[$j]);
  209. }
  210. }
  211. }
  212. elseif ($arOption[2][0] == 'doubletext')
  213. {
  214. $val = ${$name.'_1'} . 'x' . ${$name.'_2'};
  215. }
  216. elseif (
  217. $arOption[2][0] == 'selectbox' ||
  218. $arOption[2][0] == 'selectboxtree'
  219. )
  220. {
  221. $val = '';
  222. if (isset($$name))
  223. {
  224. for ($j=0; $j<count($$name); $j++)
  225. {
  226. if (trim(${$name}[$j]) <> '')
  227. {
  228. $val .= ($val <> '' ? ',':'') . trim(${$name}[$j]);
  229. }
  230. }
  231. }
  232. }
  233. else
  234. {
  235. $val = $$name;
  236. }
  237. if ($arOption[2][0] == 'checkbox' && $val<>'Y')
  238. {
  239. $val = 'N';
  240. }
  241. $val = trim($val);
  242. // set new references site <> templates
  243. $prefix = 'site_template_id_';
  244. if ($arOption[0] == 'site_template_id')// base template
  245. {
  246. $valOld = trim(\COption::getOptionString(
  247. $module_id,
  248. 'site_template_id'
  249. ));
  250. if (!$val)
  251. {
  252. $val = $valOld;
  253. }
  254. if ($valOld != $val)
  255. {
  256. $res = SiteTemplateTable::getList(array(
  257. 'filter' => array(
  258. '=TEMPLATE' => $valOld
  259. )
  260. ));
  261. while ($row = $res->fetch())
  262. {
  263. $clearTmplCache = true;
  264. SiteTemplateTable::update($row['ID'], [
  265. 'TEMPLATE' => $val
  266. ]
  267. );
  268. }
  269. }
  270. }
  271. elseif (strpos($arOption[0], $prefix) === 0)// individual templates
  272. {
  273. $valDefault = trim(\COption::getOptionString(
  274. $module_id,
  275. 'site_template_id'
  276. ));
  277. $valOld = \COption::getOptionString(
  278. $module_id,
  279. $arOption[0]
  280. );
  281. if ($valOld != $val)
  282. {
  283. $siteId = substr($arOption[0], strlen($prefix));
  284. $res = SiteTemplateTable::getList(array(
  285. 'filter' => array(
  286. '=SITE_ID' => $siteId,
  287. '=TEMPLATE' => $valOld ? $valOld : $valDefault
  288. )
  289. ));
  290. while ($row = $res->fetch())
  291. {
  292. $clearTmplCache = true;
  293. SiteTemplateTable::update($row['ID'], [
  294. 'TEMPLATE' => $val ? $val : $valDefault
  295. ]
  296. );
  297. }
  298. }
  299. }
  300. \COption::setOptionString($module_id, $name, $val);
  301. }
  302. $Update = $Update . $Apply;
  303. if ($clearTmplCache)
  304. {
  305. Manager::getCacheManager()->clean('b_site_template');
  306. }
  307. // access settings save
  308. ob_start();
  309. require_once($docRoot . '/bitrix/modules/main/admin/group_rights.php');
  310. ob_end_clean();
  311. if ($Update <> '' && $backUrl <> '')
  312. {
  313. \LocalRedirect($backUrl);
  314. }
  315. else
  316. {
  317. \LocalRedirect(
  318. $APPLICATION->GetCurPage() .
  319. '?mid=' . urlencode($mid) .
  320. '&lang=' . urlencode(LANGUAGE_ID) .
  321. '&back_url_settings=' . urlencode($backUrl) .
  322. '&' . $tabControl->ActiveTabParam());
  323. }
  324. }
  325. ?><form method="post" action="<?= $APPLICATION->GetCurPage()?>?mid=<?= urlencode($mid)?>&amp;lang=<?= LANGUAGE_ID?>"><?
  326. $tabControl->Begin();
  327. $tabControl->BeginNextTab();
  328. foreach($allOptions as $Option):
  329. if ($Option[0] == 'header')
  330. {
  331. ?>
  332. <tr class="heading">
  333. <td colspan="2">
  334. <?= $Option[1];?>
  335. </td>
  336. </tr>
  337. <?if (isset($Option[2])):?>
  338. <tr>
  339. <td></td>
  340. <td>
  341. <?
  342. echo BeginNote();
  343. echo $Option[2];
  344. echo EndNote();
  345. ?>
  346. </td>
  347. </tr>
  348. <?endif;?>
  349. <?
  350. continue;
  351. }
  352. $type = $Option[2];
  353. $val = \COption::getOptionString(
  354. $module_id,
  355. $Option[0],
  356. isset($Option[3]) ? $Option[3] : null
  357. );
  358. ?>
  359. <tr>
  360. <td valign="top" width="40%"><?
  361. if ($type[0]=='checkbox')
  362. {
  363. echo '<label for="' . \htmlspecialcharsbx($Option[0]) . '">'.$Option[1].'</label>';
  364. }
  365. else
  366. {
  367. echo $Option[1];
  368. }
  369. ?></td>
  370. <td valign="middle" width="60%"><?
  371. if ($type[0] == 'checkbox'):
  372. ?><input type="checkbox" name="<?echo \htmlspecialcharsbx($Option[0])?>" id="<?echo \htmlspecialcharsbx($Option[0])?>" value="Y"<?if($val == 'Y') echo ' checked="checked"';?> /><?
  373. elseif ($type[0] == 'text'):
  374. ?><input type="text" size="<?echo $type[1]?>" maxlength="255" value="<?echo \htmlspecialcharsbx($val)?>" name="<?echo \htmlspecialcharsbx($Option[0])?>" /><?
  375. elseif ($type[0] == 'doubletext'):
  376. list($val1, $val2) = explode('x', $val);
  377. ?><input type="text" size="<?echo $type[1]?>" maxlength="255" value="<?echo \htmlspecialcharsbx($val1)?>" name="<?echo \htmlspecialcharsbx($Option[0].'_1')?>" /><?
  378. ?><input type="text" size="<?echo $type[1]?>" maxlength="255" value="<?echo \htmlspecialcharsbx($val2)?>" name="<?echo \htmlspecialcharsbx($Option[0].'_2')?>" /><?
  379. elseif ($type[0] == 'textarea'):
  380. ?><textarea rows="<?echo $type[1]?>" cols="<?echo $type[2]?>" name="<?echo \htmlspecialcharsbx($Option[0])?>"><?echo \htmlspecialcharsbx($val)?></textarea><?
  381. elseif ($type[0] == 'text-list'):
  382. $aVal = explode(",", $val);
  383. for($j=0; $j<count($aVal); $j++):
  384. ?><input type="text" size="<?echo $type[2]?>" value="<?echo \htmlspecialcharsbx($aVal[$j])?>" name="<?echo \htmlspecialcharsbx($Option[0]).'[]'?>" /><br /><?
  385. endfor;
  386. for($j=0; $j<$type[1]; $j++):
  387. ?><input type="text" size="<?echo $type[2]?>" value="" name="<?echo \htmlspecialcharsbx($Option[0]).'[]'?>" /><br /><?
  388. endfor;
  389. elseif ($type[0] == 'selectbox'):
  390. $arr = $type[1];
  391. $arr_keys = array_keys($arr);
  392. $currValue = explode(',', $val);
  393. ?><select name="<?echo \htmlspecialcharsbx($Option[0])?>[]"<?= $type[2]?>><?
  394. for($j = 0; $j < count($arr_keys); $j++):
  395. ?><option value="<?echo $arr_keys[$j]?>"<?if(in_array($arr_keys[$j], $currValue))echo ' selected="selected"'?>><?echo \htmlspecialcharsbx($arr[$arr_keys[$j]])?></option><?
  396. endfor;
  397. ?></select><?
  398. elseif ($type[0] == 'selectboxtree'):
  399. $arr = $type[1];
  400. $currValue = explode(',', $val);
  401. $output = '<select name="'.\htmlspecialcharsbx($Option[0]).'[]"'.$type[2].'>';
  402. $output .= '<option></option>';
  403. foreach ($getIblocksTree() as $rowType)
  404. {
  405. $strIBlocksCpGr = '';
  406. foreach ($rowType['ITEMS'] as $rowIb)
  407. {
  408. if (in_array($rowIb['ID'], $currValue))
  409. {
  410. $sel = ' selected="selected"';
  411. }
  412. else
  413. {
  414. $sel = '';
  415. }
  416. $strIBlocksCpGr .= '<option value="' . $rowIb['ID'] . '"' . $sel . '>' .
  417. $rowIb['NAME'] .
  418. '</option>';
  419. }
  420. if ($strIBlocksCpGr != '')
  421. {
  422. $output .= '<optgroup label="'.$rowType['NAME'].'">';
  423. $output .= $strIBlocksCpGr;
  424. $output .= '</optgroup>';
  425. }
  426. }
  427. $output .= '</select>';
  428. echo $output;
  429. endif;
  430. echo $Option[4];?>
  431. </td>
  432. <?
  433. endforeach;
  434. // access tab
  435. $tabControl->BeginNextTab();
  436. require_once($docRoot . '/bitrix/modules/main/admin/group_rights.php');
  437. $tabControl->Buttons();
  438. ?>
  439. <input <?if ($postRight < 'W') echo 'disabled="disabled"' ?> type="submit" name="Update" value="<?= Loc::getMessage('MAIN_SAVE')?>" title="<?= Loc::getMessage('MAIN_OPT_SAVE_TITLE')?>" />
  440. <input <?if ($postRight < 'W') echo 'disabled="disabled"' ?> type="submit" name="Apply" value="<?= Loc::getMessage('MAIN_OPT_APPLY')?>" title="<?= Loc::getMessage('MAIN_OPT_APPLY_TITLE')?>" />
  441. <?if ($backUrl <> ''):?>
  442. <input <?if ($postRight < 'W') echo 'disabled="disabled"' ?> type="button" name="Cancel" value="<?= Loc::getMessage('MAIN_OPT_CANCEL')?>" title="<?= Loc::getMessage('MAIN_OPT_CANCEL_TITLE')?>" onclick="window.location='<?echo \htmlspecialcharsbx(CUtil::addslashes($backUrl))?>'" />
  443. <input type="hidden" name="back_url_settings" value="<?=\htmlspecialcharsbx($backUrl)?>" />
  444. <?endif?>
  445. <?=bitrix_sessid_post();?>
  446. <?$tabControl->End();?>
  447. </form>
  448. <?endif;?>