BxBaseCover.php 2.1 KB

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