BxBaseCover.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  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. $mixedOptions = BxDolPage::getObjectInstanceByURI()->getPageCoverParams();
  34. if(empty($mixedOptions) || !is_array($mixedOptions))
  35. return $this->displayEmpty();
  36. if(!$this->_sCoverImageUrl) {
  37. $iId = (int)getParam('sys_site_cover_common');
  38. if($iId != 0)
  39. $this->setCoverImageUrl(array('id' => $iId, 'transcoder' => BX_DOL_TRANSCODER_OBJ_COVER));
  40. }
  41. if($this->_sCoverImageUrl)
  42. $mixedOptions['bx_if:bg'] = array (
  43. 'condition' => true,
  44. 'content' => array('image_url' => $this->_sCoverImageUrl),
  45. );
  46. return $this->_oTemplate->parseHtmlByName($this->_sTemplateName, array_merge($this->_aOptiondDefault, $mixedOptions));
  47. }
  48. /**
  49. * Display Empty Cover.
  50. */
  51. public function displayEmpty ()
  52. {
  53. return $this->_oTemplate->parseHtmlByName($this->_sTemplateNameEmpty, array());
  54. }
  55. /**
  56. * Add css/js files which are needed for display and functionality.
  57. */
  58. protected function _addJsCss()
  59. {
  60. if ($this->_bJsCssAdded)
  61. return;
  62. $this->_oTemplate->addCss(array('cover.css'));
  63. $this->_bJsCssAdded = true;
  64. }
  65. }
  66. /** @} */