BxBaseCover.php 2.8 KB

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