BxBaseStudioWidgets.php 5.6 KB

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