BxBaseStudioPage.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentView Trident Studio Representation classes
  7. * @ingroup TridentStudio
  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. }
  25. public function getPageJs()
  26. {
  27. return array('jquery.anim.js', 'jquery.jfeed.pack.js', 'jquery.dolRSSFeed.js', 'page.js');
  28. }
  29. public function getPageJsClass()
  30. {
  31. return '';
  32. }
  33. public function getPageJsObject()
  34. {
  35. return '';
  36. }
  37. public function getPageJsCode($aOptions = array(), $bWrap = true)
  38. {
  39. $sJsClass = $this->getPageJsClass();
  40. $sJsObject = $this->getPageJsObject();
  41. if(empty($sJsClass) || empty($sJsObject))
  42. return '';
  43. $sOptions = '{}';
  44. if(!empty($aOptions))
  45. $sOptions = json_encode($aOptions);
  46. $sContent = 'var ' . $sJsObject . ' = new ' . $sJsClass . '(' . $sOptions . ');';
  47. if($bWrap)
  48. $sContent = BxDolStudioTemplate::getInstance()->_wrapInTagJsCode($sContent);
  49. return $sContent;
  50. }
  51. public function getPageCss()
  52. {
  53. $aCss = array('page.css', 'menu_top.css');
  54. if((int)$this->aPage['index'] == 3)
  55. $aCss[] = 'page_columns.css';
  56. return $aCss;
  57. }
  58. public function getPageHeader()
  59. {
  60. if(empty($this->aPage) || !is_array($this->aPage))
  61. return '';
  62. return _t(!$this->bPageMultiple ? $this->aPage['caption'] : $this->aPage[$this->sPageSelected]['caption']);
  63. }
  64. public function getPageBreadcrumb()
  65. {
  66. return array();
  67. }
  68. public function getPageCaption()
  69. {
  70. if(empty($this->aPage) || !is_array($this->aPage))
  71. return '';
  72. $oTemplate = BxDolStudioTemplate::getInstance();
  73. $oFunctions = BxTemplStudioFunctions::getInstance();
  74. $sHelp = $this->getPageCaptionHelp();
  75. if(($bHelp = strlen($sHelp)) > 0)
  76. $sHelp = $oFunctions->transBox('bx-std-pcap-menu-popup-help', $sHelp, true);
  77. $sActions = $this->getPageCaptionActions();
  78. if(($bActions = strlen($sActions)) > 0)
  79. $sActions = $oFunctions->transBox('bx-std-pcap-menu-popup-actions', $sActions, true);
  80. $oTemplate->addInjection('injection_header', 'text', $sHelp . $sActions);
  81. //--- Menu Left ---//
  82. $aItems = array(
  83. 'back' => array(
  84. 'name' => 'back',
  85. 'icon' => 'th',
  86. 'link' => BX_DOL_URL_STUDIO . 'launcher.php',
  87. 'title' => '_adm_txt_back_to_launcher'
  88. )
  89. );
  90. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_top_toolbar.html', 'menu_items' => $aItems));
  91. $sMenuLeft = $oMenu->getCode();
  92. //--- Menu Right ---//
  93. $aItems = array();
  94. if($bHelp)
  95. $aItems['help'] = array(
  96. 'name' => 'help',
  97. 'icon' => 'question-circle',
  98. 'onclick' => BX_DOL_STUDIO_PAGE_JS_OBJECT . ".togglePopup('help', this)",
  99. 'title' => '_adm_txt_show_help'
  100. );
  101. if($bActions)
  102. $aItems['actions'] = array(
  103. 'name' => 'actions',
  104. 'icon' => 'cog',
  105. 'onclick' => BX_DOL_STUDIO_PAGE_JS_OBJECT . ".togglePopup('actions', this)",
  106. 'title' => '_adm_txt_show_help'
  107. );
  108. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_top_toolbar.html', 'menu_items' => $aItems));
  109. $sMenuRight = $oMenu->getCode();
  110. $aTmplVars = array(
  111. 'menu_left' => $sMenuLeft,
  112. 'caption' => _t($this->aPage['caption']),
  113. 'menu_right' => $sMenuRight
  114. );
  115. return $oTemplate->parseHtmlByName('page_caption.html', $aTmplVars);
  116. }
  117. public function getPageAttributes()
  118. {
  119. return '';
  120. }
  121. public function getPageMenu($aMenu, $aMarkers = array())
  122. {
  123. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aMenu));
  124. if(!empty($aMarkers))
  125. $oMenu->addMarkers($aMarkers);
  126. return $oMenu->getCode();
  127. }
  128. public function getPageCode($bHidden = false) {}
  129. protected function getPageCaptionHelp()
  130. {
  131. $sContent = BxDolRss::getObjectInstance($this->sPageRssHelpObject)->getHolder($this->sPageRssHelpId, $this->iPageRssHelpLength, 0, false);
  132. $oTemplate = BxDolStudioTemplate::getInstance();
  133. $oTemplate->addJsTranslation('_adm_txt_show_help_content_empty');
  134. return $oTemplate->parseHtmlByName('page_caption_help.html', array(
  135. 'content' => $sContent
  136. ));
  137. }
  138. protected function getPageCaptionActions()
  139. {
  140. if(empty($this->aActions))
  141. return "";
  142. $aForm = array(
  143. 'form_attrs' => array(
  144. 'id' => 'adm-page-actions',
  145. 'name' => 'adm-page-actions',
  146. 'action' => '',
  147. 'method' => 'post',
  148. ),
  149. 'params' => array(),
  150. 'inputs' => array()
  151. );
  152. foreach($this->aActions as $aAction) {
  153. $aInput = array(
  154. 'type' => $aAction['type'],
  155. 'name' => $aAction['name'],
  156. 'caption' => _t($aAction['caption'])
  157. );
  158. switch($aAction['type']) {
  159. case 'switcher':
  160. $aInput['checked'] = $aAction['checked'];
  161. $aInput['attrs']['onchange'] = $aAction['onchange'];
  162. break;
  163. }
  164. $aForm['inputs'][$aInput['name']] = $aInput;
  165. }
  166. $oForm = new BxTemplStudioFormView($aForm);
  167. return BxDolStudioTemplate::getInstance()->parseHtmlByName('page_caption_actions.html', array('content' => $oForm->getCode()));
  168. }
  169. /**
  170. *
  171. * Block Methods
  172. *
  173. */
  174. public function getBlockCaption($aBlock)
  175. {
  176. if(empty($aBlock) || !is_array($aBlock))
  177. return '';
  178. $oTemplate = BxDolStudioTemplate::getInstance();
  179. $aTmplActions = array();
  180. if(isset($aBlock['actions']) && is_array($aBlock['actions']))
  181. foreach($aBlock['actions'] as $aAction) {
  182. $sCaption = _t($aAction['caption']);
  183. $aTmplActions[] = array(
  184. 'name' => $aAction['name'],
  185. 'url' => $aAction['url'],
  186. 'title' => $sCaption,
  187. 'bx_if:show_onclick' => array(
  188. 'condition' => $aAction['onclick'] != '',
  189. 'content' => array(
  190. 'onclick' => $aAction['onclick']
  191. )
  192. ),
  193. 'caption' => $sCaption
  194. );
  195. }
  196. $aTmplVars = array(
  197. 'caption' => _t($aBlock['caption']),
  198. 'bx_if:show_actions' => array(
  199. 'condition' => count($aTmplActions) > 0,
  200. 'content' => array(
  201. 'bx_repeat:actions' => $aTmplActions
  202. )
  203. ),
  204. );
  205. return $oTemplate->parseHtmlByName('block_caption.html', $aTmplVars);
  206. }
  207. public function getBlockPanelTop($aBlock)
  208. {
  209. if(empty($aBlock) || !is_array($aBlock))
  210. return '';
  211. $oTemplate = BxDolStudioTemplate::getInstance();
  212. $aTmplVars = array(
  213. 'content' => isset($aBlock['panel_top']) ? $aBlock['panel_top'] : ''
  214. );
  215. return $oTemplate->parseHtmlByName('block_panel_top.html', $aTmplVars);
  216. }
  217. public function getBlockPanelBottom($aBlock)
  218. {
  219. if(empty($aBlock) || !is_array($aBlock))
  220. return '';
  221. $oTemplate = BxDolStudioTemplate::getInstance();
  222. $aTmplVars = array(
  223. 'content' => isset($aBlock['panel_bottom']) ? $aBlock['panel_bottom'] : ''
  224. );
  225. return $oTemplate->parseHtmlByName('block_panel_bottom.html', $aTmplVars);
  226. }
  227. protected function getJsResult($sMessage, $bTranslate = true, $bRedirect = false, $sRedirect = '', $sOnResult = '')
  228. {
  229. $aResult = array();
  230. $aResult['message'] = $bTranslate ? _t($sMessage) : $sMessage;
  231. if($bRedirect)
  232. $aResult['redirect'] = $sRedirect != '' ? $sRedirect : BX_DOL_URL_STUDIO;
  233. if(!empty($sOnResult))
  234. $aResult['on_result'] = $sOnResult;
  235. $sResult = "window.parent." . BX_DOL_STUDIO_PAGE_JS_OBJECT . ".showMessage(" . json_encode($aResult) . ");";
  236. return BxDolStudioTemplate::getInstance()->_wrapInTagJsCode($sResult);
  237. }
  238. }
  239. /** @} */