BxBaseStudioPage.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioPage extends BxDolStudioPage
  11. {
  12. protected $aPageCss;
  13. protected $aPageJs;
  14. protected $sPageJsClass;
  15. protected $sPageJsObject;
  16. function __construct($mixedPageName)
  17. {
  18. parent::__construct($mixedPageName);
  19. $this->aPageCss = [
  20. 'page.css',
  21. 'page-media-tablet.css',
  22. 'page-media-desktop.css',
  23. 'page_columns.css',
  24. 'menu_top.css'
  25. ];
  26. $this->aPageJs = [
  27. 'jquery.anim.js',
  28. 'jquery.jfeed.pack.js',
  29. 'jquery.dolRSSFeed.js',
  30. 'page.js'
  31. ];
  32. $this->sPageJsClass = 'BxDolStudioPage';
  33. $this->sPageJsObject = 'oBxDolStudioPage';
  34. }
  35. public function getPageIndex()
  36. {
  37. if(!is_array($this->aPage) || empty($this->aPage))
  38. return BX_PAGE_DEFAULT;
  39. if(!$this->bPageMultiple)
  40. return !empty($this->aPage['index']) ? (int)$this->aPage['index'] : BX_PAGE_DEFAULT;
  41. else
  42. return !empty($this->aPage[$this->sPageSelected]['index']) ? (int)$this->aPage[$this->sPageSelected]['index'] : BX_PAGE_DEFAULT;
  43. $this->aMarkers = array_merge($this->aMarkers, array(
  44. 'js_object' => $this->getPageJsObject(),
  45. ));
  46. }
  47. public function getPageJs()
  48. {
  49. return $this->aPageJs;
  50. }
  51. public function getPageJsClass()
  52. {
  53. return $this->sPageJsClass;
  54. }
  55. public function getPageJsObject()
  56. {
  57. return $this->sPageJsObject;
  58. }
  59. public function getPageJsCode($aOptions = array(), $bWrap = true)
  60. {
  61. $sJsClass = $this->getPageJsClass();
  62. $sJsObject = $this->getPageJsObject();
  63. if(empty($sJsClass) || empty($sJsObject))
  64. return '';
  65. $sOptions = '{}';
  66. if(!empty($aOptions))
  67. $sOptions = json_encode($aOptions);
  68. $sContent = 'var ' . $sJsObject . ' = new ' . $sJsClass . '(' . $sOptions . ');';
  69. if($bWrap)
  70. $sContent = BxDolStudioTemplate::getInstance()->_wrapInTagJsCode($sContent);
  71. return $sContent;
  72. }
  73. public function getPageCss()
  74. {
  75. return $this->aPageCss;
  76. }
  77. public function getPageHeader()
  78. {
  79. if(empty($this->aPage) || !is_array($this->aPage))
  80. return '';
  81. return _t(!$this->bPageMultiple ? $this->aPage['caption'] : $this->aPage[$this->sPageSelected]['caption']);
  82. }
  83. /**
  84. * The page's meta description: the page's own text (_adm_page_dsc_<name>, {0} = site title) when it has one, the generic
  85. * Studio wording with the page caption otherwise (app pages). Read by search engines and offered by screen readers.
  86. */
  87. public function getPageDescription()
  88. {
  89. if(empty($this->aPage) || !is_array($this->aPage))
  90. return '';
  91. $aPage = !$this->bPageMultiple ? $this->aPage : $this->aPage[$this->sPageSelected];
  92. $sSiteTitle = getParam('site_title');
  93. $sKey = '_adm_page_dsc_' . $aPage['name'];
  94. $sDescription = _t($sKey, $sSiteTitle);
  95. if($sDescription == $sKey)
  96. $sDescription = _t('_adm_page_dsc_default', _t($aPage['caption']), $sSiteTitle);
  97. return strip_tags($sDescription);
  98. }
  99. /*
  100. * Left area in in page header. Contains 'home' button, page caption and search.
  101. */
  102. public function getPageBreadcrumb()
  103. {
  104. $bPageHome = $this->aPage['name'] == 'home';
  105. $bWidgetType = !empty($this->aPage['wid_type']);
  106. $aMarkers = array('js_object_launcher' => BxTemplStudioLauncher::getInstance()->getPageJsObject());
  107. if($bWidgetType)
  108. $aMarkers['widget_type'] = $this->aPage['wid_type'];
  109. $this->addMarkers($aMarkers);
  110. $aMenuItems = [];
  111. $aMenuItems['home'] = [
  112. 'name' => 'home',
  113. 'icon' => 'tmi-launcher.svg',
  114. 'link' => BX_DOL_URL_STUDIO,
  115. //'onclick' => bx_replace_markers('return {js_object_launcher}.browser(this)', $this->aMarkers),
  116. 'title' => '',
  117. 'area_label' => '_adm_page_cpt_home'
  118. ];
  119. /**
  120. * Hidden for now.
  121. */
  122. if(false && $bWidgetType)
  123. $aMenuItems['type'] = [
  124. 'name' => 'type',
  125. 'icon' => $this->getPageTypeIcon(),
  126. 'link' => $this->getPageTypeUrl(),
  127. 'onclick' => bx_replace_markers("return {js_object_launcher}.browser(this, '{widget_type}')", $this->aMarkers),
  128. 'title' => ''
  129. ];
  130. $bShowSearch = $bPageHome && getParam('sys_std_show_header_left_search') == 'on';
  131. // On the launcher the launcher button stays, and the search field takes the page item's place after the separator, its
  132. // glyph exactly where an app's icon sits on app pages (the page heading moves into the search block for assistive tech).
  133. // The app item is also the trigger of the page's context menu (right-click, Menu key, long press), when it has actions.
  134. if(!$bShowSearch)
  135. // the app's own launcher icon next to its title, as an image (not inlined: the tile art carries gradients)
  136. $aMenuItems['page'] = [
  137. 'name' => 'page',
  138. 'icon' => !empty($this->aPage['wid_icon']) ? $this->aPage['wid_icon'] : '',
  139. 'icon_inline' => false,
  140. 'link' => $this->getPageUrl(),
  141. 'title' => _t($this->aPage['caption']),
  142. 'attrs_add' => getParam('sys_std_show_header_left') == 'on' ? $this->getPageCaptionActions() : ''
  143. ];
  144. $oMenu = new BxTemplStudioMenu([
  145. 'template' => 'page_breadcrumb.html',
  146. 'menu_items' => $aMenuItems
  147. ]);
  148. $sMenu = $oMenu->getCode();
  149. return BxDolStudioTemplate::getInstance()->parseHtmlByContent($sMenu, [
  150. 'bx_if:show_search' => [
  151. 'condition' => $bShowSearch,
  152. 'content' => [
  153. 'title' => _t($this->aPage['caption'])
  154. ]
  155. ]
  156. ]);
  157. }
  158. public function getPageCaption()
  159. {
  160. if(($sAssistant = $this->getPageCaptionAssistant()) != '') {
  161. $sAssistant = BxTemplStudioFunctions::getInstance()->popupBox('bx-std-pcap-menu-popup-assistant', _t('_adm_txt_assistant_popup_title'), $sAssistant, true);
  162. BxDolStudioTemplate::getInstance()->addInjection('injection_header', 'text', $sAssistant);
  163. }
  164. return '';
  165. }
  166. public function getPageAttributes()
  167. {
  168. return '';
  169. }
  170. public function getPageMenu($aMenu = [], $aMarkers = [])
  171. {
  172. if($aMenu === false)
  173. return '';
  174. foreach($aMenu as $aItem)
  175. if(($aItem['selected'] ?? false))
  176. $this->aPage['subcaption'] = $aItem['title'] ?? '';
  177. return $this->getPageMenuObject($aMenu, $aMarkers)->getCode();
  178. }
  179. public function getPageCode($sPage = '', $bWrap = true) {
  180. if(empty($this->aPage) || !is_array($this->aPage)) {
  181. $this->setError([404, '_sys_request_page_not_found_cpt']);
  182. return false;
  183. }
  184. return '';
  185. }
  186. protected function getPageMenuObject($aMenu = array(), $aMarkers = array())
  187. {
  188. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aMenu));
  189. if(!empty($aMarkers))
  190. $oMenu->addMarkers($aMarkers);
  191. return $oMenu;
  192. }
  193. /**
  194. * The page's actions live in a context menu (studio/js/context_menu.js): this puts the menu popup into the header and
  195. * returns the attributes that make an element its trigger, or '' when the page has no actions.
  196. */
  197. protected function getPageCaptionActions()
  198. {
  199. $sMenu = $this->getPageContextMenu();
  200. if(empty($sMenu))
  201. return '';
  202. $sId = 'bx-std-pmenu-popup-actions';
  203. BxDolStudioTemplate::getInstance()->addInjection('injection_header', 'text', BxTemplStudioFunctions::getInstance()->transBox($sId, [
  204. 'wrapper_class' => 'bx-std-context-wrapper',
  205. 'wrapper_role' => 'presentation', // the [role="menu"] inside is the thing
  206. 'content' => $sMenu
  207. ], true));
  208. return 'data-bx-context-menu="#' . $sId . '"';
  209. }
  210. protected function getPageContextMenu($iWidgetId = 0)
  211. {
  212. return '';
  213. }
  214. protected function getPageCaptionHelp()
  215. {
  216. $sContent = BxDolRss::getObjectInstance($this->sPageRssHelpObject)->getHolder($this->sPageRssHelpId, $this->iPageRssHelpLength, 0, false);
  217. $oTemplate = BxDolStudioTemplate::getInstance();
  218. $oTemplate->addJsTranslation('_adm_txt_show_help_content_empty');
  219. return $oTemplate->parseHtmlByName('page_caption_help.html', array(
  220. 'content' => $sContent
  221. ));
  222. }
  223. protected function getPageCaptionAssistant()
  224. {
  225. if(!$this->_bShowHeaderRightAssistant)
  226. return '';
  227. $oAssistant = BxDolAIAssistant::getObjectInstance($this->iPageAssistantId);
  228. if(!$oAssistant)
  229. return '';
  230. $oTemplate = BxDolStudioTemplate::getInstance();
  231. $sContent = $oAssistant->getAskChat($this->sPageAssistantChatName, $this->sPageAssistantChatDescription, '', $oTemplate);
  232. if(!$sContent)
  233. return '';
  234. return $oTemplate->parseHtmlByName('page_caption_assistant.html', [
  235. 'content' => $sContent
  236. ]);
  237. }
  238. protected function getPageActions($iWidgetId = 0)
  239. {
  240. return '';
  241. }
  242. protected function getJsResult($sMessage, $bTranslate = true, $bRedirect = false, $sRedirect = '', $sOnResult = '')
  243. {
  244. return bx_get_js_result(array(
  245. 'message' => $sMessage,
  246. 'translate' => $bTranslate,
  247. 'redirect' => $bRedirect === true && !empty($sRedirect) ? $sRedirect : $bRedirect,
  248. 'eval' => $sOnResult
  249. ));
  250. }
  251. protected function getJsResultBy($aParams)
  252. {
  253. return bx_get_js_result($aParams);
  254. }
  255. }
  256. /** @} */