BxBaseStudioPage.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. $this->sPageRssHelpUrl = bx_replace_markers($this->sPageRssHelpUrl, $this->aMarkers);
  137. $GLOBALS['gbBxSysIsRssInitialized'] = true;
  138. bx_import('BxTemplFunctions');
  139. $sContent = BxTemplFunctions::getInstance()->getRssHolder($this->sPageRssHelpUrl, $this->iPageRssHelpLength);
  140. $oTemplate = BxDolStudioTemplate::getInstance();
  141. $oTemplate->addJsTranslation('_adm_txt_show_help_content_empty');
  142. return $oTemplate->parseHtmlByName('page_caption_help.html', array(
  143. 'content' => $sContent
  144. ));
  145. }
  146. protected function getPageCaptionActions()
  147. {
  148. if(empty($this->aActions))
  149. return "";
  150. $aForm = array(
  151. 'form_attrs' => array(
  152. 'id' => 'adm-page-actions',
  153. 'name' => 'adm-page-actions',
  154. 'action' => '',
  155. 'method' => 'post',
  156. ),
  157. 'params' => array(),
  158. 'inputs' => array()
  159. );
  160. foreach($this->aActions as $aAction) {
  161. $aInput = array(
  162. 'type' => $aAction['type'],
  163. 'name' => $aAction['name'],
  164. 'caption' => _t($aAction['caption'])
  165. );
  166. switch($aAction['type']) {
  167. case 'switcher':
  168. $aInput['checked'] = $aAction['checked'];
  169. $aInput['attrs']['onchange'] = $aAction['onchange'];
  170. break;
  171. }
  172. $aForm['inputs'][$aInput['name']] = $aInput;
  173. }
  174. bx_import('BxTemplStudioFormView');
  175. $oForm = new BxTemplStudioFormView($aForm);
  176. return BxDolStudioTemplate::getInstance()->parseHtmlByName('page_caption_actions.html', array('content' => $oForm->getCode()));
  177. }
  178. /**
  179. *
  180. * Block Methods
  181. *
  182. */
  183. public function getBlockCaption($aBlock)
  184. {
  185. if(empty($aBlock) || !is_array($aBlock))
  186. return '';
  187. $oTemplate = BxDolStudioTemplate::getInstance();
  188. $aTmplActions = array();
  189. if(isset($aBlock['actions']) && is_array($aBlock['actions']))
  190. foreach($aBlock['actions'] as $aAction) {
  191. $sCaption = _t($aAction['caption']);
  192. $aTmplActions[] = array(
  193. 'name' => $aAction['name'],
  194. 'url' => $aAction['url'],
  195. 'title' => $sCaption,
  196. 'bx_if:show_onclick' => array(
  197. 'condition' => $aAction['onclick'] != '',
  198. 'content' => array(
  199. 'onclick' => $aAction['onclick']
  200. )
  201. ),
  202. 'caption' => $sCaption
  203. );
  204. }
  205. $aTmplVars = array(
  206. 'caption' => _t($aBlock['caption']),
  207. 'bx_if:show_actions' => array(
  208. 'condition' => count($aTmplActions) > 0,
  209. 'content' => array(
  210. 'bx_repeat:actions' => $aTmplActions
  211. )
  212. ),
  213. );
  214. return $oTemplate->parseHtmlByName('block_caption.html', $aTmplVars);
  215. }
  216. public function getBlockPanelTop($aBlock)
  217. {
  218. if(empty($aBlock) || !is_array($aBlock))
  219. return '';
  220. $oTemplate = BxDolStudioTemplate::getInstance();
  221. $aTmplVars = array(
  222. 'content' => isset($aBlock['panel_top']) ? $aBlock['panel_top'] : ''
  223. );
  224. return $oTemplate->parseHtmlByName('block_panel_top.html', $aTmplVars);
  225. }
  226. public function getBlockPanelBottom($aBlock)
  227. {
  228. if(empty($aBlock) || !is_array($aBlock))
  229. return '';
  230. $oTemplate = BxDolStudioTemplate::getInstance();
  231. $aTmplVars = array(
  232. 'content' => isset($aBlock['panel_bottom']) ? $aBlock['panel_bottom'] : ''
  233. );
  234. return $oTemplate->parseHtmlByName('block_panel_bottom.html', $aTmplVars);
  235. }
  236. protected function getJsResult($sMessage, $bTranslate = true, $bRedirect = false, $sRedirect = '', $sOnResult = '')
  237. {
  238. $aResult = array();
  239. $aResult['message'] = $bTranslate ? _t($sMessage) : $sMessage;
  240. if($bRedirect)
  241. $aResult['redirect'] = $sRedirect != '' ? $sRedirect : BX_DOL_URL_STUDIO;
  242. if(!empty($sOnResult))
  243. $aResult['on_result'] = $sOnResult;
  244. $sResult = "window.parent." . BX_DOL_STUDIO_PAGE_JS_OBJECT . ".showMessage(" . json_encode($aResult) . ");";
  245. return BxDolStudioTemplate::getInstance()->_wrapInTagJsCode($sResult);
  246. }
  247. }
  248. /** @} */