BxBaseStudioWidgets.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. function __construct($mixedPageName) {
  13. parent::__construct($mixedPageName);
  14. }
  15. function getPageCode($bHidden = false) {
  16. if(empty($this->aPage) || !is_array($this->aPage))
  17. return BxDolStudioTemplate::getInstance()->displayPageNotFound();
  18. if(!$this->bPageMultiple)
  19. return $this->wrapWidgets($this->aPage['name'], $this->getWidgets($this->aPage['name'], $this->aWidgets), $bHidden);
  20. $sContent = "";
  21. foreach($this->aWidgets as $sPage => $aWidgets)
  22. $sContent .= $this->wrapWidgets($sPage, $this->getWidgets($sPage, $aWidgets), $bHidden || $sPage != $this->sPageSelected);
  23. return $sContent;
  24. }
  25. function getPageWidgets() {
  26. if(empty($this->aPage) || !is_array($this->aPage))
  27. return BxDolStudioTemplate::getInstance()->displayPageNotFound();
  28. if(!$this->bPageMultiple)
  29. return $this->getWidgets($this->aPage['name'], $this->aWidgets);
  30. $sContent = "";
  31. foreach($this->aWidgets as $sPage => $aWidgets)
  32. $sContent .= $this->getWidgets($sPage, $aWidgets);
  33. return $sContent;
  34. }
  35. protected function wrapWidgets($sName, $sContent, $bHidden = false) {
  36. return BxDolStudioTemplate::getInstance()->parseHtmlByName('widgets_page.html', array(
  37. 'page' => $sName,
  38. 'bx_if:page_hidden' => array(
  39. 'condition' => $bHidden,
  40. 'content' => array()
  41. ),
  42. 'content' => $sContent
  43. ));
  44. }
  45. protected function getWidgets($sPage, $aWidgets) {
  46. $oTemplate = BxDolStudioTemplate::getInstance();
  47. $aParseVars = array(
  48. 'url_root' => BX_DOL_URL_ROOT,
  49. 'url_studio' => BX_DOL_URL_STUDIO,
  50. 'url_studio_icons' => BX_DOL_URL_STUDIO_BASE . 'images/icons/'
  51. );
  52. $aTmplVars = array();
  53. foreach($aWidgets as $aWidget) {
  54. $aTmplVarsActions = array();
  55. if(!$this->isEnabled($aWidget) && !empty($aWidget['cnt_actions'])) {
  56. $aService = unserialize($aWidget['cnt_actions']);
  57. $aActions = BxDolService::call($aService['module'], $aService['method'], array_merge(array($aWidget), $aService['params']), $aService['class']);
  58. foreach($aActions as $aAction)
  59. $aTmplVarsActions[] = array(
  60. 'caption' => _t($aAction['caption']),
  61. 'url' => !empty($aAction['url']) ? $oTemplate->parseHtmlByContent($aAction['url'], $aParseVars, array('{', '}')) : 'javascript:void(0)',
  62. 'bx_if:show_click' => array(
  63. 'condition' => !empty($aAction['click']),
  64. 'content' => array(
  65. 'content' => 'javascript:' . $aAction['click'],
  66. )
  67. ),
  68. 'icon' => $oTemplate->getIconUrl($aAction['icon'])
  69. );
  70. }
  71. $aTmplVars[] = array(
  72. 'id' => $aWidget['id'],
  73. 'url' => !empty($aWidget['url']) ? $oTemplate->parseHtmlByContent($aWidget['url'], $aParseVars, array('{', '}')) : 'javascript:void(0)',
  74. 'bx_if:show_click_icon' => array(
  75. 'condition' => !empty($aWidget['click']),
  76. 'content' => array(
  77. 'content' => 'javascript:' . $aWidget['click'],
  78. )
  79. ),
  80. 'bx_if:show_click_link' => array(
  81. 'condition' => !empty($aWidget['click']),
  82. 'content' => array(
  83. 'content' => 'javascript:' . $aWidget['click'],
  84. )
  85. ),
  86. 'bx_if:show_notice' => array(
  87. 'condition' => !empty($aWidget['cnt_notices']),
  88. 'content' => array(
  89. 'content' => $aWidget['cnt_notices']
  90. )
  91. ),
  92. 'bx_if:show_actions' => array(
  93. 'condition' => !empty($aTmplVarsActions),
  94. 'content' => array(
  95. 'bx_repeat:actions' => $aTmplVarsActions,
  96. )
  97. ),
  98. 'icon' => $this->getIcon($aWidget),
  99. 'caption' => _t($aWidget['caption']),
  100. 'widget_disabled_class' => !$this->isEnabled($aWidget) ? 'bx-std-widget-icon-disabled' : '',
  101. 'widget_bookmarked_class' => (int)$aWidget['bookmark'] == 1 ? 'bx-std-widget-icon-bookmarked' : '',
  102. 'widget_styles' => isset($_COOKIE['bx_studio_bookmark']) && (int)$_COOKIE['bx_studio_bookmark'] == 1 && (int)$aWidget['bookmark'] != 1 ? 'display:none;' : ''
  103. );
  104. }
  105. return $oTemplate->parseHtmlByName('widgets.html', array(
  106. 'bx_repeat:widgets' => $aTmplVars
  107. ));
  108. }
  109. protected function getIcon(&$aWidget) {
  110. $oTemplate = BxDolStudioTemplate::getInstance();
  111. $sUrl = $oTemplate->getIconUrl($aWidget['icon']);
  112. if(empty($sUrl))
  113. $sUrl = $oTemplate->getIconUrl('wi-empty.png');
  114. return $sUrl;
  115. }
  116. }
  117. /** @} */