1
0

BxDolStudioWidgets.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 UnaStudio UNA Studio
  7. * @{
  8. */
  9. define('BX_DOL_STUDIO_WS_ENABLED', 1);
  10. define('BX_DOL_STUDIO_WS_DISABLED', 2);
  11. define('BX_DOL_STUDIO_WTYPE_DEFAULT', '');
  12. class BxDolStudioWidgets extends BxTemplStudioPage
  13. {
  14. protected $sCacheKeyNotices = 'std_widgets_notices';
  15. protected $sCookieKeyFeatured = 'bx_studio_featured';
  16. protected $_sType;
  17. protected $aWidgets;
  18. protected $aWidgetsNotices;
  19. public function __construct($mixedPageName)
  20. {
  21. parent::__construct($mixedPageName);
  22. $this->oDb = BxDolStudioWidgetsQuery::getInstance();
  23. $this->_sType = BX_DOL_STUDIO_WTYPE_DEFAULT;
  24. if(($sType = bx_get('type')) !== false)
  25. $this->_sType = bx_process_input($sType);
  26. $this->aWidgets = array();
  27. $this->aWidgetsNotices = array();
  28. $sWType = $this->_sType != BX_DOL_STUDIO_WTYPE_DEFAULT ? $this->_sType : '';
  29. if(!$this->bPageMultiple) {
  30. $this->aWidgets = $this->oDb->getWidgets(array('type' => 'by_page_id', 'value' => $this->aPage['id'], 'wtype' => $sWType));
  31. }
  32. else
  33. foreach($this->aPage as $sPage => $aPage)
  34. $this->aWidgets[$sPage] = $this->oDb->getWidgets(array('type' => 'by_page_id', 'value' => $aPage['id'], 'wtype' => $sWType));
  35. //--- Load Cache (Widgets' Notices)
  36. $oCache = $this->oDb->getDbCacheObject();
  37. $sCacheKey = $this->oDb->genDbCacheKey($this->sCacheKeyNotices);
  38. $this->aWidgetsNotices = $oCache->getData($sCacheKey);
  39. }
  40. /**
  41. * Checks whether 'Featured Only' mode is enabled or not.
  42. */
  43. public function isFeatured()
  44. {
  45. return isset($_COOKIE[$this->sCookieKeyFeatured]) && (int)$_COOKIE[$this->sCookieKeyFeatured] == 1;
  46. }
  47. public function updateCache()
  48. {
  49. $aWidgets = $this->oDb->getWidgets(array('type' => 'all_with_notices'));
  50. $aResult = array();
  51. foreach($aWidgets as $aWidget) {
  52. if(BxDolService::isSerializedService($aWidget['cnt_notices'])) {
  53. $aService = unserialize($aWidget['cnt_notices']);
  54. $sNotices = BxDolService::call($aService['module'], $aService['method'], array_merge(array($aWidget), $aService['params']), $aService['class']);
  55. }
  56. $aResult[$aWidget['id']] = $sNotices;
  57. }
  58. $oCache = $this->oDb->getDbCacheObject();
  59. $sCacheKey = $this->oDb->genDbCacheKey($this->sCacheKeyNotices);
  60. return $oCache->setData($sCacheKey, $aResult);
  61. }
  62. }
  63. /** @} */