BxBaseStudioWidgets.php 6.7 KB

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