BxBaseCover.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. if(!empty($this->_aOptions) && is_array($this->_aOptions))
  34. return $this->_oTemplate->parseHtmlByName($this->_sTemplateName, array_merge($this->_aOptiondDefault, $this->_aOptions));
  35. $oPage = BxDolPage::getObjectInstanceByURI();
  36. if(empty($oPage) || !is_a($oPage, 'BxDolPage'))
  37. return $this->displayEmpty();
  38. $mixedOptions = $oPage->getPageCoverParams();
  39. if(empty($mixedOptions) || !is_array($mixedOptions))
  40. return $this->displayEmpty();
  41. if(!$this->_sCoverImageUrl) {
  42. $iId = (int)getParam('sys_site_cover_common');
  43. if($iId != 0)
  44. $this->setCoverImageUrl(array('id' => $iId, 'transcoder' => BX_DOL_TRANSCODER_OBJ_COVER));
  45. }
  46. if($this->_sCoverImageUrl)
  47. $mixedOptions['bx_if:bg'] = array (
  48. 'condition' => true,
  49. 'content' => array('image_url' => $this->_sCoverImageUrl),
  50. );
  51. return $this->_oTemplate->parseHtmlByName($this->_sTemplateName, array_merge($this->_aOptiondDefault, $mixedOptions));
  52. }
  53. /**
  54. * Display Empty Cover.
  55. */
  56. public function displayEmpty ()
  57. {
  58. return $this->_oTemplate->parseHtmlByName($this->_sTemplateNameEmpty, array());
  59. }
  60. /**
  61. * Add css/js files which are needed for display and functionality.
  62. */
  63. protected function _addJsCss()
  64. {
  65. if ($this->_bJsCssAdded)
  66. return;
  67. $this->_oTemplate->addCss(array('cover.css'));
  68. $this->_bJsCssAdded = true;
  69. }
  70. }
  71. /** @} */