/components/bitrix/ui.sidepanel.wrapper/class.php

https://gitlab.com/alexprowars/bitrix · PHP · 239 lines · 201 code · 28 blank · 10 comment · 39 complexity · 0c44a7e09c1f7e1ea57e86d6dd474e40 MD5 · raw file

  1. <?php
  2. if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true)
  3. {
  4. die();
  5. }
  6. use Bitrix\Main\Loader;
  7. /**
  8. * Class UIPageSliderWrapperComponent
  9. */
  10. class UIPageSliderWrapperComponent extends \CBitrixComponent
  11. {
  12. /** @var bool $isWrapperCalled */
  13. protected static $isWrapperCalled = false;
  14. /**
  15. * Is page slider context.
  16. */
  17. protected function isPageSliderContext(): bool
  18. {
  19. return
  20. $this->request->get('IFRAME') === 'Y' ||
  21. (isset($this->arParams['IFRAME_MODE']) && $this->arParams['IFRAME_MODE'] === true)
  22. ;
  23. }
  24. /**
  25. * Execute component.
  26. */
  27. public function executeComponent()
  28. {
  29. global $USER;
  30. if (!isset($this->arParams['POPUP_COMPONENT_PARAMS']) || !is_array($this->arParams['POPUP_COMPONENT_PARAMS']))
  31. {
  32. $this->arParams['POPUP_COMPONENT_PARAMS'] = [];
  33. }
  34. $this->processSliderComponents();
  35. if (empty($this->arParams['EDITABLE_TITLE_DEFAULT']))
  36. {
  37. $this->arParams['EDITABLE_TITLE_DEFAULT'] = 'Default name';
  38. }
  39. if (empty($this->arParams['EDITABLE_TITLE_SELECTOR']))
  40. {
  41. $this->arParams['EDITABLE_TITLE_SELECTOR'] = null;
  42. }
  43. if (!isset($this->arParams['POPUP_COMPONENT_PARENT']))
  44. {
  45. $this->arParams['POPUP_COMPONENT_PARENT'] = false;
  46. }
  47. if (!isset($this->arParams['PREVENT_LOADING_WITHOUT_IFRAME']))
  48. {
  49. $this->arParams['PREVENT_LOADING_WITHOUT_IFRAME'] = true;
  50. }
  51. if (!isset($this->arParams['POPUP_COMPONENT_USE_BITRIX24_THEME']))
  52. {
  53. $this->arParams['POPUP_COMPONENT_USE_BITRIX24_THEME'] = "N";
  54. }
  55. elseif (
  56. !isset($this->arParams["POPUP_COMPONENT_BITRIX24_THEME_FOR_USER_ID"])
  57. || (int)$this->arParams["POPUP_COMPONENT_BITRIX24_THEME_FOR_USER_ID"] < 0
  58. )
  59. {
  60. $this->arParams["POPUP_COMPONENT_BITRIX24_THEME_FOR_USER_ID"] = $USER->GetID();
  61. }
  62. $notification = [
  63. 'content' => null,
  64. 'autoHideDelay' => 5000,
  65. ];
  66. if (isset($this->arParams['NOTIFICATION']))
  67. {
  68. if (is_string($this->arParams['NOTIFICATION']) && !empty($this->arParams['~NOTIFICATION']))
  69. {
  70. $notification['content'] = $this->arParams['~NOTIFICATION'];
  71. }
  72. elseif(is_array($this->arParams['NOTIFICATION']))
  73. {
  74. $notifyOptions = $this->arParams['NOTIFICATION'];
  75. foreach ($notification as $key => $defaultValue)
  76. {
  77. $notification[$key] = ($notifyOptions[$key] ?? $defaultValue);
  78. }
  79. }
  80. }
  81. $this->arParams['NOTIFICATION'] = $notification;
  82. $this->arParams['USE_LINK_TARGETS_REPLACING'] = isset($this->arParams['USE_LINK_TARGETS_REPLACING']) && $this->arParams['USE_LINK_TARGETS_REPLACING'];
  83. $this->arParams['PLAIN_VIEW'] = isset($this->arParams['PLAIN_VIEW']) && $this->arParams['PLAIN_VIEW'];
  84. $this->arParams['USE_PADDING'] = !isset($this->arParams['USE_PADDING']) || $this->arParams['USE_PADDING'];
  85. $this->arParams['USE_BACKGROUND_CONTENT'] = !isset($this->arParams['USE_BACKGROUND_CONTENT']) || $this->arParams['USE_BACKGROUND_CONTENT'];
  86. $this->arParams['BUTTONS'] = $this->arParams['BUTTONS'] ?? [];
  87. $this->arParams['PAGE_MODE'] = !isset($this->arParams['PAGE_MODE']) || $this->arParams['PAGE_MODE'];
  88. $this->arParams['RETURN_CONTENT'] = isset($this->arParams['RETURN_CONTENT']) && $this->arParams['RETURN_CONTENT'];
  89. $this->arParams['PAGE_MODE_OFF_BACK_URL'] = $this->arParams['PAGE_MODE_OFF_BACK_URL'] ?? '/';
  90. $this->arParams['CLOSE_AFTER_SAVE'] = isset($this->arParams['CLOSE_AFTER_SAVE']) && $this->arParams['CLOSE_AFTER_SAVE'];
  91. $this->arParams['RELOAD_PAGE_AFTER_SAVE'] = isset($this->arParams['RELOAD_PAGE_AFTER_SAVE']) && $this->arParams['RELOAD_PAGE_AFTER_SAVE'];
  92. $this->arParams['RELOAD_GRID_AFTER_SAVE'] = isset($this->arParams['RELOAD_GRID_AFTER_SAVE'])
  93. ?
  94. is_string($this->arParams['RELOAD_GRID_AFTER_SAVE'])
  95. ?
  96. $this->arParams['RELOAD_GRID_AFTER_SAVE']
  97. :
  98. (bool) $this->arParams['RELOAD_GRID_AFTER_SAVE']
  99. :
  100. false;
  101. if ($this->request->isPost())
  102. {
  103. $this->arParams['CLOSE_AFTER_SAVE'] = false;
  104. $this->arParams['RELOAD_GRID_AFTER_SAVE'] = false;
  105. $this->arParams['RELOAD_PAGE_AFTER_SAVE'] = false;
  106. }
  107. $this->arResult["SKIP_NOTIFICATION"] = $this->request->get("notifyAfterSave") === "N";
  108. $this->arParams['USE_TOP_MENU'] =
  109. isset($this->arParams['USE_TOP_MENU']) && $this->arParams['USE_TOP_MENU'] === true
  110. ;
  111. if ($this->arParams['USE_TOP_MENU'])
  112. {
  113. $this->arParams['TOP_MENU_TEMPLATE'] = $this->arParams['TOP_MENU_TEMPLATE'] ?? 'top_horizontal';
  114. $this->arParams['TOP_MENU_PARAMS'] = array_merge(
  115. [
  116. "ROOT_MENU_TYPE" => "left",
  117. "CHILD_MENU_TYPE" => "sub",
  118. "MENU_CACHE_TYPE" => "N",
  119. "MENU_CACHE_TIME" => "604800",
  120. "MENU_CACHE_USE_GROUPS" => "N",
  121. "MENU_CACHE_USE_USERS" => "Y",
  122. "CACHE_SELECTED_ITEMS" => "Y",
  123. "MENU_CACHE_GET_VARS" => array(),
  124. "MAX_LEVEL" => "3",
  125. "USE_EXT" => "Y",
  126. "DELAY" => "N",
  127. "ALLOW_MULTI_SELECT" => "N"
  128. ],
  129. isset($this->arParams['TOP_MENU_PARAMS']) && is_array($this->arParams['TOP_MENU_PARAMS'])
  130. ? $this->arParams['TOP_MENU_PARAMS']
  131. : []
  132. );
  133. }
  134. if (
  135. Loader::includeModule("intranet")
  136. && $this->arParams["POPUP_COMPONENT_USE_BITRIX24_THEME"] === "Y"
  137. && SITE_TEMPLATE_ID === "bitrix24"
  138. )
  139. {
  140. $this->arResult["SHOW_BITRIX24_THEME"] = "Y";
  141. }
  142. else
  143. {
  144. $this->arResult["SHOW_BITRIX24_THEME"] = "N";
  145. }
  146. if ($this->isPageSliderContext() && !self::$isWrapperCalled)
  147. {
  148. self::$isWrapperCalled = true;
  149. global $APPLICATION;
  150. $APPLICATION->RestartBuffer();
  151. $this->includeComponentTemplate();
  152. if ($this->arParams['RETURN_CONTENT'])
  153. {
  154. foreach (GetModuleEvents("main", "OnEpilog", true) as $arEvent)
  155. {
  156. ExecuteModuleEventEx($arEvent);
  157. }
  158. return $APPLICATION->EndBufferContentMan();
  159. }
  160. require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_after.php');
  161. exit;
  162. }
  163. if ($this->arParams['PAGE_MODE'] || self::$isWrapperCalled)
  164. {
  165. $this->includeComponentTemplate('content');
  166. }
  167. elseif (!$this->arParams['PAGE_MODE'])
  168. {
  169. $this->includeComponentTemplate('loader');
  170. }
  171. }
  172. protected function processSliderComponents()
  173. {
  174. $this->arResult['SLIDER_COMPONENT_NAME_LIST'] = [];
  175. $this->arResult['SLIDER_COMPONENT_TEMPLATE_LIST'] = [];
  176. $this->arResult['SLIDER_COMPONENT_PARAMS_LIST'] = [];
  177. if (is_array($this->arParams['POPUP_COMPONENT_NAME']))
  178. {
  179. $this->arResult['SLIDER_COMPONENT_NAME_LIST'] = array_values($this->arParams['POPUP_COMPONENT_NAME']);
  180. if (is_array($this->arParams['POPUP_COMPONENT_TEMPLATE_NAME']))
  181. {
  182. $this->arParams['POPUP_COMPONENT_TEMPLATE_NAME'] = array_values($this->arParams['POPUP_COMPONENT_TEMPLATE_NAME']);
  183. }
  184. $defaultTemplateValue = (!is_array($this->arParams['POPUP_COMPONENT_TEMPLATE_NAME']) ? $this->arParams['POPUP_COMPONENT_TEMPLATE_NAME'] : '');
  185. foreach ($this->arResult['SLIDER_COMPONENT_NAME_LIST'] as $key => $value)
  186. {
  187. $this->arResult['SLIDER_COMPONENT_TEMPLATE_LIST'][$key] = (
  188. is_array($this->arParams['POPUP_COMPONENT_TEMPLATE_NAME'])
  189. && isset($this->arParams['POPUP_COMPONENT_TEMPLATE_NAME'][$key])
  190. ? $this->arParams['POPUP_COMPONENT_TEMPLATE_NAME'][$key]
  191. : $defaultTemplateValue
  192. );
  193. $this->arResult['SLIDER_COMPONENT_PARAMS_LIST'][$key] = (
  194. is_array($this->arParams['POPUP_COMPONENT_PARAMS'])
  195. && isset($this->arParams['POPUP_COMPONENT_PARAMS'][$key])
  196. && is_array($this->arParams['POPUP_COMPONENT_PARAMS'][$key])
  197. ? $this->arParams['POPUP_COMPONENT_PARAMS'][$key]
  198. : []
  199. );
  200. $this->arResult['SLIDER_COMPONENT_PARAMS_LIST'][$key]['IFRAME'] = true;
  201. }
  202. }
  203. else
  204. {
  205. $this->arResult['SLIDER_COMPONENT_NAME_LIST'][] = $this->arParams['POPUP_COMPONENT_NAME'];
  206. $this->arResult['SLIDER_COMPONENT_TEMPLATE_LIST'][] = $this->arParams['POPUP_COMPONENT_TEMPLATE_NAME'];
  207. $this->arParams['POPUP_COMPONENT_PARAMS']['IFRAME'] = true;
  208. $this->arResult['SLIDER_COMPONENT_PARAMS_LIST'][] = $this->arParams['POPUP_COMPONENT_PARAMS'];
  209. }
  210. }
  211. }