1
0

BxBaseStudioWidget.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 BxBaseStudioWidget extends BxDolStudioWidget
  11. {
  12. public function __construct($mixedPageName)
  13. {
  14. parent::__construct($mixedPageName);
  15. }
  16. public function getPageCss()
  17. {
  18. return array_merge(parent::getPageCss(), array(
  19. 'launcher.css'
  20. ));
  21. }
  22. public function getPageJs()
  23. {
  24. return array_merge(parent::getPageJs(), array(
  25. 'launcher.js'
  26. ));
  27. }
  28. public function getPageCaption()
  29. {
  30. if(empty($this->aPage) || !is_array($this->aPage))
  31. return '';
  32. $this->updateHistory();
  33. $oTemplate = BxDolStudioTemplate::getInstance();
  34. $oFunctions = BxTemplStudioFunctions::getInstance();
  35. $bActions = false;
  36. $sActions = $this->getPageCaptionActions();
  37. if(($bActions = strlen($sActions)) > 0)
  38. $sActions = $oFunctions->transBox('bx-std-pcap-menu-popup-actions', $sActions, true);
  39. $bHelp = false;
  40. $sHelp = $this->getPageCaptionHelp();
  41. if(($bHelp = strlen($sHelp)) > 0)
  42. $sHelp = $oFunctions->transBox('bx-std-pcap-menu-popup-help', $sHelp, true);
  43. $oTemplate->addInjection('injection_header', 'text', $sActions . $sHelp);
  44. //--- Menu Right ---//
  45. $aItemsRight = array(
  46. 'site' => array(
  47. 'name' => 'site',
  48. 'icon' => 'tmi-site.svg',
  49. 'link' => '{url_root}',
  50. 'title' => '_adm_tmi_cpt_site'
  51. ),
  52. );
  53. if($bHelp)
  54. $aItemsRight['help'] = array(
  55. 'name' => 'help',
  56. 'icon' => 'tmi-help.svg',
  57. 'onclick' => BX_DOL_STUDIO_PAGE_JS_OBJECT . ".togglePopup('help', this)",
  58. 'title' => '_adm_txt_show_help'
  59. );
  60. if($bActions)
  61. $aItemsRight['actions'] = array(
  62. 'name' => 'actions',
  63. 'icon' => 'tmi-actions.svg',
  64. 'onclick' => BX_DOL_STUDIO_PAGE_JS_OBJECT . ".togglePopup('actions', this)",
  65. 'title' => '_adm_txt_show_actions'
  66. );
  67. $aItemsRight['account'] = array(
  68. 'name' => 'account',
  69. 'icon' => 'tmi-account.svg',
  70. 'link' => 'javascript:void(0);',
  71. 'onclick' => 'bx_menu_popup(\'sys_studio_account_popup\', this);',
  72. 'title' => '_adm_tmi_cpt_account'
  73. );
  74. $oTopMenu = BxTemplStudioMenuTop::getInstance();
  75. $oTopMenu->setContent(BX_DOL_STUDIO_MT_LEFT, $this->getPageBreadcrumb());
  76. $oTopMenu->setSelected(BX_DOL_STUDIO_MT_CENTER, $this->aPage['name']);
  77. $oTopMenu->setContent(BX_DOL_STUDIO_MT_RIGHT, array(
  78. 'template' => 'menu_top_toolbar.html',
  79. 'menu_items' => $aItemsRight
  80. ));
  81. return '';
  82. }
  83. public function getPageCode()
  84. {
  85. $sResult = parent::getPageCode();
  86. if($sResult === false)
  87. return false;
  88. if(!empty($this->aPage['wid_type']) && !BxDolStudioRolesUtils::getInstance()->isActionAllowed('use ' . $this->aPage['wid_type'])) {
  89. $this->setError('_Access denied');
  90. return false;
  91. }
  92. return $sResult . BxTemplStudioLauncher::getInstance()->getPageJsCode(array(
  93. 'bInit' => false
  94. ));
  95. }
  96. /**
  97. * Block related methods
  98. */
  99. public function getBlocksLine($aBlocks)
  100. {
  101. $aTmplVarsBlocks = array();
  102. foreach ($aBlocks as $aBlock) {
  103. $aTmplVarsBlocks[] = array(
  104. 'content' => $this->getBlockCode($aBlock)
  105. );
  106. }
  107. return BxDolStudioTemplate::getInstance()->parseHtmlByName('page_blocks_line.html', array(
  108. 'count' => count($aTmplVarsBlocks),
  109. 'bx_repeat:blocks' => $aTmplVarsBlocks
  110. ));
  111. }
  112. public function getBlockCode($aBlock)
  113. {
  114. return BxDolStudioTemplate::getInstance()->parseHtmlByName('page_block.html', array(
  115. 'caption' => $this->getBlockCaption($aBlock),
  116. 'panel_top' => $this->getBlockPanelTop($aBlock),
  117. 'items' => !empty($aBlock['items']) ? $aBlock['items'] : '',
  118. 'panel_bottom' => $this->getBlockPanelBottom($aBlock)
  119. ));
  120. }
  121. public function getBlockCaption($aBlock)
  122. {
  123. if(empty($aBlock) || !is_array($aBlock) || (empty($aBlock['caption']) && empty($aBlock['actions'])))
  124. return '';
  125. $aTmplActions = array();
  126. if(!empty($aBlock['actions']) && is_array($aBlock['actions']))
  127. foreach($aBlock['actions'] as $aAction) {
  128. $sCaption = is_array($aAction['caption']) ? call_user_func_array('_t', $aAction['caption']) : _t($aAction['caption']);
  129. $bOnClick = !empty($aAction['onclick']);
  130. $aOnClick = $bOnClick ? array('onclick' => $aAction['onclick']) : array();
  131. $aTmplActions[] = array(
  132. 'name' => $aAction['name'],
  133. 'url' => $aAction['url'],
  134. 'title' => $sCaption,
  135. 'bx_if:show_onclick' => array(
  136. 'condition' => $bOnClick,
  137. 'content' => $aOnClick
  138. ),
  139. 'caption' => $sCaption
  140. );
  141. }
  142. return BxDolStudioTemplate::getInstance()->parseHtmlByName('block_caption.html', array(
  143. 'caption' => is_array($aBlock['caption']) ? call_user_func_array('_t', $aBlock['caption']) : _t($aBlock['caption']),
  144. 'bx_if:show_actions' => array(
  145. 'condition' => !empty($aTmplActions),
  146. 'content' => array(
  147. 'bx_repeat:actions' => $aTmplActions
  148. )
  149. ),
  150. ));
  151. }
  152. public function getBlockPanelTop($aBlock)
  153. {
  154. if(empty($aBlock) || !is_array($aBlock) || empty($aBlock['panel_top']))
  155. return '';
  156. return BxDolStudioTemplate::getInstance()->parseHtmlByName('block_panel_top.html', array(
  157. 'content' => $aBlock['panel_top']
  158. ));
  159. }
  160. public function getBlockPanelBottom($aBlock)
  161. {
  162. if(empty($aBlock) || !is_array($aBlock) || empty($aBlock['panel_bottom']))
  163. return '';
  164. return BxDolStudioTemplate::getInstance()->parseHtmlByName('block_panel_bottom.html', array(
  165. 'content' => $aBlock['panel_bottom']
  166. ));
  167. }
  168. /**
  169. * Internal methods.
  170. */
  171. protected function getPageCaptionActions()
  172. {
  173. $sActions = $this->getPageActions();
  174. if(empty($sActions))
  175. return "";
  176. return BxDolStudioTemplate::getInstance()->parseHtmlByName('page_caption_actions.html', array(
  177. 'content' => $sActions
  178. ));
  179. }
  180. protected function getPageActions($iWidgetId = 0)
  181. {
  182. if(empty($this->aActions))
  183. return "";
  184. $aMarkers = array(
  185. 'widget_id' => $iWidgetId,
  186. );
  187. if(!empty($iWidgetId)) {
  188. $aWidget = BxDolStudioWidgetsQuery::getInstance()->getWidgets(array('type' => 'by_id', 'value' => $iWidgetId));
  189. if(!empty($aWidget) && is_array($aWidget))
  190. $aMarkers['widget_type'] = $aWidget['type'];
  191. }
  192. $aForm = array(
  193. 'form_attrs' => array(
  194. 'id' => 'adm-page-actions',
  195. 'name' => 'adm-page-actions',
  196. 'action' => '',
  197. 'method' => 'post',
  198. ),
  199. 'params' => array(),
  200. 'inputs' => array()
  201. );
  202. foreach($this->aActions as $aAction) {
  203. if($aAction['name'] == 'rearrange' && empty($iWidgetId))
  204. continue;
  205. $aInput = array(
  206. 'type' => $aAction['type'],
  207. 'name' => $aAction['name'],
  208. 'caption' => _t($aAction['caption'])
  209. );
  210. switch($aAction['type']) {
  211. case 'switcher':
  212. $aInput['checked'] = $aAction['checked'];
  213. $aInput['attrs']['onchange'] = bx_replace_markers($aAction['onchange'], $aMarkers);
  214. break;
  215. case 'select':
  216. $aInput['value'] = bx_replace_markers($aAction['value'], $aMarkers);
  217. $aInput['values'] = $aAction['values'];
  218. $aInput['attrs']['onchange'] = bx_replace_markers($aAction['onchange'], $aMarkers);
  219. break;
  220. }
  221. $aForm['inputs'][$aInput['name']] = $aInput;
  222. }
  223. $oForm = new BxTemplStudioFormView($aForm);
  224. return $oForm->getCode();
  225. }
  226. }
  227. /** @} */