BxBaseStudioPage.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. $this->addMarkers(array(
  73. 'js_object_launcher' => BxTemplStudioLauncher::getInstance()->getPageJsObject()
  74. ));
  75. $aMenuItems = array(
  76. 'home' => array(
  77. 'name' => 'home',
  78. 'icon' => 'bc-home.svg',
  79. 'link' => 'javascript:void(0)',
  80. 'onclick' => bx_replace_markers('{js_object_launcher}.browser(this)', $this->aMarkers),
  81. 'title' => ''
  82. )
  83. );
  84. if(!empty($this->aPage['wid_type']))
  85. $aMenuItems['type'] = array(
  86. 'name' => 'type',
  87. 'icon' => $this->getPageTypeIcon(),
  88. 'link' => $this->getPageTypeUrl(),
  89. 'title' => ''
  90. );
  91. $aMenuItems['page'] = array(
  92. 'name' => 'page',
  93. 'icon' => $this->aPage['icon'],
  94. 'link' => $this->getPageUrl(),
  95. 'title' => _t($this->aPage['caption'])
  96. );
  97. $oMenu = new BxTemplStudioMenu(array(
  98. 'template' => 'page_breadcrumb.html',
  99. 'menu_items' => $aMenuItems
  100. ));
  101. return $oMenu->getCode();
  102. }
  103. public function getPageCaption()
  104. {
  105. return '';
  106. }
  107. public function getPageAttributes()
  108. {
  109. return '';
  110. }
  111. public function getPageMenu($aMenu = array(), $aMarkers = array())
  112. {
  113. $oMenu = $this->getPageMenuObject($aMenu, $aMarkers);
  114. return $oMenu->getCode();
  115. }
  116. public function getPageCode($sPage = '', $bWrap = true) {
  117. if(empty($this->aPage) || !is_array($this->aPage)) {
  118. $this->setError('_sys_txt_not_found');
  119. return false;
  120. }
  121. return '';
  122. }
  123. protected function getPageMenuObject($aMenu = array(), $aMarkers = array())
  124. {
  125. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aMenu));
  126. if(!empty($aMarkers))
  127. $oMenu->addMarkers($aMarkers);
  128. return $oMenu;
  129. }
  130. protected function getPageCaptionHelp()
  131. {
  132. $sContent = BxDolRss::getObjectInstance($this->sPageRssHelpObject)->getHolder($this->sPageRssHelpId, $this->iPageRssHelpLength, 0, false);
  133. $oTemplate = BxDolStudioTemplate::getInstance();
  134. $oTemplate->addJsTranslation('_adm_txt_show_help_content_empty');
  135. return $oTemplate->parseHtmlByName('page_caption_help.html', array(
  136. 'content' => $sContent
  137. ));
  138. }
  139. protected function getJsResult($sMessage, $bTranslate = true, $bRedirect = false, $sRedirect = '', $sOnResult = '')
  140. {
  141. return $this->getJsResultBy(array(
  142. 'message' => $sMessage,
  143. 'translate' => $bTranslate,
  144. 'redirect' => $bRedirect === true && !empty($sRedirect) ? $sRedirect : $bRedirect,
  145. 'eval' => $sOnResult
  146. ));
  147. }
  148. protected function getJsResultBy($aParams)
  149. {
  150. $aResult = array();
  151. if(!empty($aParams['message'])) {
  152. $aResult['message'] = $aParams['message'];
  153. if(!isset($aParams['translate']) || !empty($aParams['translate'])) {
  154. $aTrtParams = array($aResult['message']);
  155. if(!empty($aParams['translate']) && is_array($aParams['translate']))
  156. $aTrtParams = array_merge($aTrtParams, $aParams['translate']);
  157. $aResult['message'] = call_user_func_array ('_t', $aTrtParams);
  158. }
  159. }
  160. if(isset($aParams['redirect']) && $aParams['redirect'] !== false)
  161. $aResult['redirect'] = is_string($aParams['redirect']) ? $aParams['redirect'] : BX_DOL_URL_STUDIO;
  162. if(!empty($aParams['eval']))
  163. $aResult['eval'] = $aParams['eval'];
  164. $sResult = "window.parent.processJsonData(" . json_encode($aResult) . ");";
  165. if(isset($aParams['on_page_load']) && $aParams['on_page_load'] === true)
  166. $sResult = "$(document).ready(function() {" . $sResult . "});";
  167. return BxDolStudioTemplate::getInstance()->_wrapInTagJsCode($sResult);
  168. }
  169. }
  170. /** @} */