BxBaseStudioPage.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 DolphinView Dolphin Studio Representation classes
  7. * @ingroup DolphinStudio
  8. * @{
  9. */
  10. bx_import('BxDolStudioPage');
  11. bx_import('BxDolStudioTemplate');
  12. bx_import('BxTemplStudioFunctions');
  13. class BxBaseStudioPage extends BxDolStudioPage
  14. {
  15. function __construct($mixedPageName)
  16. {
  17. parent::__construct($mixedPageName);
  18. }
  19. public function getPageIndex()
  20. {
  21. if(!is_array($this->aPage) || empty($this->aPage))
  22. return BX_PAGE_DEFAULT;
  23. if(!$this->bPageMultiple)
  24. return !empty($this->aPage['index']) ? (int)$this->aPage['index'] : BX_PAGE_DEFAULT;
  25. else
  26. return !empty($this->aPage[$this->sPageSelected]['index']) ? (int)$this->aPage[$this->sPageSelected]['index'] : BX_PAGE_DEFAULT;
  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 '';
  35. }
  36. public function getPageJsObject()
  37. {
  38. return '';
  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. $aCss = array('page.css', 'menu_top.css');
  57. if((int)$this->aPage['index'] == 3)
  58. $aCss[] = 'page_columns.css';
  59. return $aCss;
  60. }
  61. public function getPageHeader()
  62. {
  63. if(empty($this->aPage) || !is_array($this->aPage))
  64. return '';
  65. return _t(!$this->bPageMultiple ? $this->aPage['caption'] : $this->aPage[$this->sPageSelected]['caption']);
  66. }
  67. public function getPageBreadcrumb()
  68. {
  69. return array();
  70. }
  71. public function getPageCaption()
  72. {
  73. if(empty($this->aPage) || !is_array($this->aPage))
  74. return '';
  75. $oTemplate = BxDolStudioTemplate::getInstance();
  76. $oFunctions = BxTemplStudioFunctions::getInstance();
  77. $sHelp = $this->getPageCaptionHelp();
  78. if(($bHelp = strlen($sHelp)) > 0)
  79. $sHelp = $oFunctions->transBox('bx-std-pcap-menu-popup-help', $sHelp, true);
  80. $sActions = $this->getPageCaptionActions();
  81. if(($bActions = strlen($sActions)) > 0)
  82. $sActions = $oFunctions->transBox('bx-std-pcap-menu-popup-actions', $sActions, true);
  83. $oTemplate->addInjection('injection_header', 'text', $sHelp . $sActions);
  84. //--- Menu Left ---//
  85. $aItems = array(
  86. 'back' => array(
  87. 'name' => 'back',
  88. 'icon' => 'th',
  89. 'link' => BX_DOL_URL_STUDIO . 'launcher.php',
  90. 'title' => '_adm_txt_back_to_launcher'
  91. )
  92. );
  93. bx_import('BxTemplStudioMenu');
  94. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_top_toolbar.html', 'menu_items' => $aItems));
  95. $sMenuLeft = $oMenu->getCode();
  96. //--- Menu Right ---//
  97. $aItems = array();
  98. if($bHelp)
  99. $aItems['help'] = array(
  100. 'name' => 'help',
  101. 'icon' => 'question-circle',
  102. 'onclick' => BX_DOL_STUDIO_PAGE_JS_OBJECT . ".togglePopup('help', this)",
  103. 'title' => '_adm_txt_show_help'
  104. );
  105. if($bActions)
  106. $aItems['actions'] = array(
  107. 'name' => 'actions',
  108. 'icon' => 'cog',
  109. 'onclick' => BX_DOL_STUDIO_PAGE_JS_OBJECT . ".togglePopup('actions', this)",
  110. 'title' => '_adm_txt_show_help'
  111. );
  112. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_top_toolbar.html', 'menu_items' => $aItems));
  113. $sMenuRight = $oMenu->getCode();
  114. $aTmplVars = array(
  115. 'menu_left' => $sMenuLeft,
  116. 'caption' => _t($this->aPage['caption']),
  117. 'menu_right' => $sMenuRight
  118. );
  119. return $oTemplate->parseHtmlByName('page_caption.html', $aTmplVars);
  120. }
  121. public function getPageAttributes()
  122. {
  123. return '';
  124. }
  125. public function getPageMenu($aMenu, $aMarkers = array())
  126. {
  127. bx_import('BxTemplStudioMenu');
  128. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aMenu));
  129. if(!empty($aMarkers))
  130. $oMenu->addMarkers($aMarkers);
  131. return $oMenu->getCode();
  132. }
  133. public function getPageCode($bHidden = false) {}
  134. protected function getPageCaptionHelp()
  135. {
  136. bx_import('BxDolRss');
  137. $sContent = BxDolRss::getObjectInstance($this->sPageRssHelpObject)->getHolder($this->sPageRssHelpId, $this->iPageRssHelpLength, 0, false);
  138. $oTemplate = BxDolStudioTemplate::getInstance();
  139. $oTemplate->addJsTranslation('_adm_txt_show_help_content_empty');
  140. return $oTemplate->parseHtmlByName('page_caption_help.html', array(
  141. 'content' => $sContent
  142. ));
  143. }
  144. protected function getPageCaptionActions()
  145. {
  146. if(empty($this->aActions))
  147. return "";
  148. $aForm = array(
  149. 'form_attrs' => array(
  150. 'id' => 'adm-page-actions',
  151. 'name' => 'adm-page-actions',
  152. 'action' => '',
  153. 'method' => 'post',
  154. ),
  155. 'params' => array(),
  156. 'inputs' => array()
  157. );
  158. foreach($this->aActions as $aAction) {
  159. $aInput = array(
  160. 'type' => $aAction['type'],
  161. 'name' => $aAction['name'],
  162. 'caption' => _t($aAction['caption'])
  163. );
  164. switch($aAction['type']) {
  165. case 'switcher':
  166. $aInput['checked'] = $aAction['checked'];
  167. $aInput['attrs']['onchange'] = $aAction['onchange'];
  168. break;
  169. }
  170. $aForm['inputs'][$aInput['name']] = $aInput;
  171. }
  172. bx_import('BxTemplStudioFormView');
  173. $oForm = new BxTemplStudioFormView($aForm);
  174. return BxDolStudioTemplate::getInstance()->parseHtmlByName('page_caption_actions.html', array('content' => $oForm->getCode()));
  175. }
  176. /**
  177. *
  178. * Block Methods
  179. *
  180. */
  181. public function getBlockCaption($aBlock)
  182. {
  183. if(empty($aBlock) || !is_array($aBlock))
  184. return '';
  185. $oTemplate = BxDolStudioTemplate::getInstance();
  186. $aTmplActions = array();
  187. if(isset($aBlock['actions']) && is_array($aBlock['actions']))
  188. foreach($aBlock['actions'] as $aAction) {
  189. $sCaption = _t($aAction['caption']);
  190. $aTmplActions[] = array(
  191. 'name' => $aAction['name'],
  192. 'url' => $aAction['url'],
  193. 'title' => $sCaption,
  194. 'bx_if:show_onclick' => array(
  195. 'condition' => $aAction['onclick'] != '',
  196. 'content' => array(
  197. 'onclick' => $aAction['onclick']
  198. )
  199. ),
  200. 'caption' => $sCaption
  201. );
  202. }
  203. $aTmplVars = array(
  204. 'caption' => _t($aBlock['caption']),
  205. 'bx_if:show_actions' => array(
  206. 'condition' => count($aTmplActions) > 0,
  207. 'content' => array(
  208. 'bx_repeat:actions' => $aTmplActions
  209. )
  210. ),
  211. );
  212. return $oTemplate->parseHtmlByName('block_caption.html', $aTmplVars);
  213. }
  214. public function getBlockPanelTop($aBlock)
  215. {
  216. if(empty($aBlock) || !is_array($aBlock))
  217. return '';
  218. $oTemplate = BxDolStudioTemplate::getInstance();
  219. $aTmplVars = array(
  220. 'content' => isset($aBlock['panel_top']) ? $aBlock['panel_top'] : ''
  221. );
  222. return $oTemplate->parseHtmlByName('block_panel_top.html', $aTmplVars);
  223. }
  224. public function getBlockPanelBottom($aBlock)
  225. {
  226. if(empty($aBlock) || !is_array($aBlock))
  227. return '';
  228. $oTemplate = BxDolStudioTemplate::getInstance();
  229. $aTmplVars = array(
  230. 'content' => isset($aBlock['panel_bottom']) ? $aBlock['panel_bottom'] : ''
  231. );
  232. return $oTemplate->parseHtmlByName('block_panel_bottom.html', $aTmplVars);
  233. }
  234. protected function getJsResult($sMessage, $bTranslate = true, $bRedirect = false, $sRedirect = '', $sOnResult = '')
  235. {
  236. $aResult = array();
  237. $aResult['message'] = $bTranslate ? _t($sMessage) : $sMessage;
  238. if($bRedirect)
  239. $aResult['redirect'] = $sRedirect != '' ? $sRedirect : BX_DOL_URL_STUDIO;
  240. if(!empty($sOnResult))
  241. $aResult['on_result'] = $sOnResult;
  242. $sResult = "window.parent." . BX_DOL_STUDIO_PAGE_JS_OBJECT . ".showMessage(" . json_encode($aResult) . ");";
  243. return BxDolStudioTemplate::getInstance()->_wrapInTagJsCode($sResult);
  244. }
  245. }
  246. /** @} */