BxBaseStudioPage.php 9.3 KB

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