BxBaseStudioPage.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. function __construct($mixedPageName)
  13. {
  14. parent::__construct($mixedPageName);
  15. }
  16. public function getPageIndex()
  17. {
  18. if(!is_array($this->aPage) || empty($this->aPage))
  19. return BX_PAGE_DEFAULT;
  20. if(!$this->bPageMultiple)
  21. return !empty($this->aPage['index']) ? (int)$this->aPage['index'] : BX_PAGE_DEFAULT;
  22. else
  23. return !empty($this->aPage[$this->sPageSelected]['index']) ? (int)$this->aPage[$this->sPageSelected]['index'] : BX_PAGE_DEFAULT;
  24. $this->aMarkers = array_merge($this->aMarkers, array(
  25. 'js_object' => $this->getPageJsObject(),
  26. ));
  27. }
  28. public function getPageJs()
  29. {
  30. return array('jquery.anim.js', 'jquery.jfeed.pack.js', 'jquery.dolRSSFeed.js', 'page.js');
  31. }
  32. public function getPageJsClass()
  33. {
  34. return 'BxDolStudioPage';
  35. }
  36. public function getPageJsObject()
  37. {
  38. return 'oBxDolStudioPage';
  39. }
  40. public function getPageJsCode($aOptions = array(), $bWrap = true)
  41. {
  42. $sJsClass = $this->getPageJsClass();
  43. $sJsObject = $this->getPageJsObject();
  44. if(empty($sJsClass) || empty($sJsObject))
  45. return '';
  46. $sOptions = '{}';
  47. if(!empty($aOptions))
  48. $sOptions = json_encode($aOptions);
  49. $sContent = 'var ' . $sJsObject . ' = new ' . $sJsClass . '(' . $sOptions . ');';
  50. if($bWrap)
  51. $sContent = BxDolStudioTemplate::getInstance()->_wrapInTagJsCode($sContent);
  52. return $sContent;
  53. }
  54. public function getPageCss()
  55. {
  56. return array(
  57. 'page.css',
  58. 'page-media-tablet.css',
  59. 'page-media-desktop.css',
  60. 'page_columns.css',
  61. 'menu_top.css'
  62. );
  63. }
  64. public function getPageHeader()
  65. {
  66. if(empty($this->aPage) || !is_array($this->aPage))
  67. return '';
  68. return _t(!$this->bPageMultiple ? $this->aPage['caption'] : $this->aPage[$this->sPageSelected]['caption']);
  69. }
  70. public function getPageBreadcrumb()
  71. {
  72. $bWidgetType = !empty($this->aPage['wid_type']);
  73. $aMarkers = array('js_object_launcher' => BxTemplStudioLauncher::getInstance()->getPageJsObject());
  74. if($bWidgetType)
  75. $aMarkers['widget_type'] = $this->aPage['wid_type'];
  76. $this->addMarkers($aMarkers);
  77. $aMenuItems = array(
  78. 'home' => array(
  79. 'name' => 'home',
  80. 'icon' => 'bc-home.svg',
  81. 'link' => 'javascript:void(0)',
  82. 'onclick' => bx_replace_markers('return {js_object_launcher}.browser(this)', $this->aMarkers),
  83. 'title' => ''
  84. )
  85. );
  86. if($bWidgetType)
  87. $aMenuItems['type'] = array(
  88. 'name' => 'type',
  89. 'icon' => $this->getPageTypeIcon(),
  90. 'link' => $this->getPageTypeUrl(),
  91. 'onclick' => bx_replace_markers("return {js_object_launcher}.browser(this, '{widget_type}')", $this->aMarkers),
  92. 'title' => ''
  93. );
  94. $aMenuItems['page'] = array(
  95. 'name' => 'page',
  96. 'icon' => $this->aPage['icon'],
  97. 'link' => $this->getPageUrl(),
  98. 'title' => _t($this->aPage['caption'])
  99. );
  100. $oMenu = new BxTemplStudioMenu(array(
  101. 'template' => 'page_breadcrumb.html',
  102. 'menu_items' => $aMenuItems
  103. ));
  104. return $oMenu->getCode();
  105. }
  106. public function getPageCaption()
  107. {
  108. return '';
  109. }
  110. public function getPageAttributes()
  111. {
  112. return '';
  113. }
  114. public function getPageMenu($aMenu = array(), $aMarkers = array())
  115. {
  116. $oMenu = $this->getPageMenuObject($aMenu, $aMarkers);
  117. return $oMenu->getCode();
  118. }
  119. public function getPageCode($sPage = '', $bWrap = true) {
  120. if(empty($this->aPage) || !is_array($this->aPage)) {
  121. $this->setError('_sys_txt_not_found');
  122. return false;
  123. }
  124. return '';
  125. }
  126. protected function getPageMenuObject($aMenu = array(), $aMarkers = array())
  127. {
  128. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aMenu));
  129. if(!empty($aMarkers))
  130. $oMenu->addMarkers($aMarkers);
  131. return $oMenu;
  132. }
  133. protected function getPageCaptionHelp()
  134. {
  135. $sContent = BxDolRss::getObjectInstance($this->sPageRssHelpObject)->getHolder($this->sPageRssHelpId, $this->iPageRssHelpLength, 0, false);
  136. $oTemplate = BxDolStudioTemplate::getInstance();
  137. $oTemplate->addJsTranslation('_adm_txt_show_help_content_empty');
  138. return $oTemplate->parseHtmlByName('page_caption_help.html', array(
  139. 'content' => $sContent
  140. ));
  141. }
  142. protected function getJsResult($sMessage, $bTranslate = true, $bRedirect = false, $sRedirect = '', $sOnResult = '')
  143. {
  144. return $this->getJsResultBy(array(
  145. 'message' => $sMessage,
  146. 'translate' => $bTranslate,
  147. 'redirect' => $bRedirect === true && !empty($sRedirect) ? $sRedirect : $bRedirect,
  148. 'eval' => $sOnResult
  149. ));
  150. }
  151. protected function getJsResultBy($aParams)
  152. {
  153. $aResult = array();
  154. if(!empty($aParams['message'])) {
  155. $aResult['message'] = $aParams['message'];
  156. if(!isset($aParams['translate']) || !empty($aParams['translate'])) {
  157. $aTrtParams = array($aResult['message']);
  158. if(!empty($aParams['translate']) && is_array($aParams['translate']))
  159. $aTrtParams = array_merge($aTrtParams, $aParams['translate']);
  160. $aResult['message'] = call_user_func_array ('_t', $aTrtParams);
  161. }
  162. }
  163. if(isset($aParams['redirect']) && $aParams['redirect'] !== false)
  164. $aResult['redirect'] = is_string($aParams['redirect']) ? $aParams['redirect'] : BX_DOL_URL_STUDIO;
  165. if(!empty($aParams['eval']))
  166. $aResult['eval'] = $aParams['eval'];
  167. $sResult = "window.parent.processJsonData(" . json_encode($aResult) . ");";
  168. if(isset($aParams['on_page_load']) && $aParams['on_page_load'] === true)
  169. $sResult = "$(document).ready(function() {" . $sResult . "});";
  170. return BxDolStudioTemplate::getInstance()->_wrapInTagJsCode($sResult);
  171. }
  172. }
  173. /** @} */