BxBaseStudioWidgets.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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('BxDolStudioWidgets');
  11. class BxBaseStudioWidgets extends BxDolStudioWidgets
  12. {
  13. public function __construct($mixedPageName)
  14. {
  15. parent::__construct($mixedPageName);
  16. }
  17. public function getPageCode($bHidden = false)
  18. {
  19. if(empty($this->aPage) || !is_array($this->aPage))
  20. return BxDolStudioTemplate::getInstance()->displayPageNotFound();
  21. if(!$this->bPageMultiple)
  22. return $this->wrapWidgets($this->aPage['name'], $this->getWidgets($this->aPage['name'], $this->aWidgets), $bHidden);
  23. $sContent = "";
  24. foreach($this->aWidgets as $sPage => $aWidgets)
  25. $sContent .= $this->wrapWidgets($sPage, $this->getWidgets($sPage, $aWidgets), $bHidden || $sPage != $this->sPageSelected);
  26. return $sContent;
  27. }
  28. public function getPageWidgets()
  29. {
  30. if(empty($this->aPage) || !is_array($this->aPage))
  31. return BxDolStudioTemplate::getInstance()->displayPageNotFound();
  32. if(!$this->bPageMultiple)
  33. return $this->getWidgets($this->aPage['name'], $this->aWidgets);
  34. $sContent = "";
  35. foreach($this->aWidgets as $sPage => $aWidgets)
  36. $sContent .= $this->getWidgets($sPage, $aWidgets);
  37. return $sContent;
  38. }
  39. protected function wrapWidgets($sName, $sContent, $bHidden = false)
  40. {
  41. return BxDolStudioTemplate::getInstance()->parseHtmlByName('widgets_page.html', array(
  42. 'page' => $sName,
  43. 'bx_if:page_hidden' => array(
  44. 'condition' => $bHidden,
  45. 'content' => array()
  46. ),
  47. 'content' => $sContent
  48. ));
  49. }
  50. protected function getWidgets($sPage, $aWidgets)
  51. {
  52. $oTemplate = BxDolStudioTemplate::getInstance();
  53. $aParseVars = array(
  54. 'url_root' => BX_DOL_URL_ROOT,
  55. 'url_studio' => BX_DOL_URL_STUDIO,
  56. 'url_studio_icons' => BX_DOL_URL_STUDIO_BASE . 'images/icons/'
  57. );
  58. $aTmplVars = array();
  59. foreach($aWidgets as $aWidget) {
  60. $aTmplVarsActions = array();
  61. if(!$this->isEnabled($aWidget) && !empty($aWidget['cnt_actions'])) {
  62. $aService = unserialize($aWidget['cnt_actions']);
  63. $aActions = BxDolService::call($aService['module'], $aService['method'], array_merge(array($aWidget), $aService['params']), $aService['class']);
  64. foreach($aActions as $aAction) {
  65. $sActionIcon = $aAction['icon'];
  66. $bActionIcon = strpos($sActionIcon, '.') === false;
  67. if(!$bActionIcon)
  68. $sActionIcon = $oTemplate->getIconUrl($sActionIcon);
  69. $sCaption = _t($aAction['caption']);
  70. $aTmplVarsActions[] = array(
  71. 'caption' => $sCaption,
  72. 'url' => !empty($aAction['url']) ? $oTemplate->parseHtmlByContent($aAction['url'], $aParseVars, array('{', '}')) : 'javascript:void(0)',
  73. 'bx_if:show_click' => array(
  74. 'condition' => !empty($aAction['click']),
  75. 'content' => array(
  76. 'content' => 'javascript:' . $aAction['click'],
  77. )
  78. ),
  79. 'bx_if:action_icon' => array (
  80. 'condition' => $bActionIcon,
  81. 'content' => array('icon' => $sActionIcon, 'caption' => $sCaption),
  82. ),
  83. 'bx_if:action_image' => array (
  84. 'condition' => !$bActionIcon,
  85. 'content' => array('icon_url' => $sActionIcon, 'caption' => $sCaption),
  86. ),
  87. );
  88. }
  89. }
  90. $sIcon = $this->getIcon($aWidget);
  91. $bIcon = strpos($sIcon, '.') === false;
  92. $sNotices = !empty($this->aWidgetsNotices[$aWidget['id']]) ? $this->aWidgetsNotices[$aWidget['id']] : '';
  93. $aTmplVars[] = array(
  94. 'id' => $aWidget['id'],
  95. 'url' => !empty($aWidget['url']) ? $oTemplate->parseHtmlByContent($aWidget['url'], $aParseVars, array('{', '}')) : 'javascript:void(0)',
  96. 'bx_if:show_click_icon' => array(
  97. 'condition' => !empty($aWidget['click']),
  98. 'content' => array(
  99. 'content' => 'javascript:' . $aWidget['click'],
  100. )
  101. ),
  102. 'bx_if:show_click_link' => array(
  103. 'condition' => !empty($aWidget['click']),
  104. 'content' => array(
  105. 'content' => 'javascript:' . $aWidget['click'],
  106. )
  107. ),
  108. 'bx_if:show_notice' => array(
  109. 'condition' => !empty($sNotices),
  110. 'content' => array(
  111. 'content' => $sNotices
  112. )
  113. ),
  114. 'bx_if:show_actions' => array(
  115. 'condition' => !empty($aTmplVarsActions),
  116. 'content' => array(
  117. 'bx_repeat:actions' => $aTmplVarsActions,
  118. )
  119. ),
  120. 'bx_if:icon' => array (
  121. 'condition' => $bIcon,
  122. 'content' => array('icon' => $sIcon),
  123. ),
  124. 'bx_if:image' => array (
  125. 'condition' => !$bIcon,
  126. 'content' => array('icon_url' => $sIcon),
  127. ),
  128. 'caption' => _t($aWidget['caption']),
  129. 'widget_disabled_class' => !$this->isEnabled($aWidget) ? 'bx-std-widget-icon-disabled' : '',
  130. 'widget_bookmarked_class' => (int)$aWidget['bookmark'] == 1 ? 'bx-std-widget-icon-bookmarked' : '',
  131. 'widget_styles' => isset($_COOKIE['bx_studio_bookmark']) && (int)$_COOKIE['bx_studio_bookmark'] == 1 && (int)$aWidget['bookmark'] != 1 ? 'display:none;' : ''
  132. );
  133. }
  134. return $oTemplate->parseHtmlByName('widgets.html', array(
  135. 'bx_repeat:widgets' => $aTmplVars
  136. ));
  137. }
  138. protected function getIcon(&$aWidget)
  139. {
  140. $oTemplate = BxDolStudioTemplate::getInstance();
  141. $sUrl = $oTemplate->getIconUrl($aWidget['icon']);
  142. if(empty($sUrl)) {
  143. bx_import('BxDolModuleQuery');
  144. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($aWidget['module']);
  145. bx_import('BxDolStudioUtils');
  146. $sUrl = BxDolStudioUtils::getIconDefault($aModule['type']);
  147. }
  148. return $sUrl;
  149. }
  150. }
  151. /** @} */