BxBaseCover.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Cover representation.
  11. * @see BxDolCover
  12. */
  13. class BxBaseCover extends BxDolCover
  14. {
  15. protected $_bJsCssAdded = false;
  16. protected $_oTemplate;
  17. public function __construct ($oTemplate)
  18. {
  19. parent::__construct ();
  20. if ($oTemplate)
  21. $this->_oTemplate = $oTemplate;
  22. else
  23. $this->_oTemplate = BxDolTemplate::getInstance();
  24. }
  25. /**
  26. * Display Cover.
  27. */
  28. public function display ()
  29. {
  30. if (getParam('sys_site_cover_disabled') == 'on')
  31. return '';
  32. $this->_addJsCss();
  33. $sResult = null;
  34. $aParams = [];
  35. if(!empty($this->_aOptions) && is_array($this->_aOptions)){
  36. $aParams = array_merge($this->_aOptiondDefault, $this->_aOptions);
  37. }
  38. else{
  39. $oPage = BxDolPage::getObjectInstanceByURI();
  40. if(empty($oPage) || !is_a($oPage, 'BxDolPage'))
  41. return $this->displayEmpty();
  42. $mixedOptions = $oPage->getPageCoverParams();
  43. if(empty($mixedOptions) || !is_array($mixedOptions))
  44. return $this->displayEmpty();
  45. if(!$this->_sCoverImageUrl) {
  46. $iId = (int)getParam('sys_site_cover_common');
  47. if($iId != 0)
  48. $this->setCoverImageUrl(array('id' => $iId, 'transcoder' => BX_DOL_TRANSCODER_OBJ_COVER));
  49. }
  50. if($this->_sCoverImageUrl)
  51. $mixedOptions['bx_if:bg'] = array (
  52. 'condition' => true,
  53. 'content' => array('image_url' => $this->_sCoverImageUrl),
  54. );
  55. $mixedOptions['bx_if:empty_cover_class'] = array (
  56. 'condition' => empty($this->_sCoverImageUrl),
  57. 'content' => array(),
  58. );
  59. $aParams = array_merge($this->_aOptiondDefault, $mixedOptions);
  60. }
  61. bx_alert('system', 'display_cover', 0, 0, array(
  62. 'res' => &$sResult,
  63. 'template_name' => &$this->_sTemplateName,
  64. 'params' => &$aParams,
  65. ));
  66. if ($sResult != null)
  67. return $sResult;
  68. return $this->_oTemplate->parseHtmlByName($this->_sTemplateName, $aParams);
  69. }
  70. /**
  71. * Display Empty Cover.
  72. */
  73. public function displayEmpty ()
  74. {
  75. return $this->_oTemplate->parseHtmlByName($this->_sTemplateNameEmpty, array());
  76. }
  77. /**
  78. * Add css/js files which are needed for display and functionality.
  79. */
  80. protected function _addJsCss()
  81. {
  82. if ($this->_bJsCssAdded)
  83. return;
  84. $this->_oTemplate->addCss(array('cover.css'));
  85. $this->_bJsCssAdded = true;
  86. }
  87. }
  88. /** @} */