BxBaseCover.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 (!$this->_aOptions) {
  32. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  33. $mixedOptions = $oMenuSubmenu->getParamsForCover();
  34. if (!$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(
  40. 'id' => $iId,
  41. 'transcoder' => BX_DOL_TRANSCODER_OBJ_COVER
  42. ));
  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. return $this->_oTemplate->parseHtmlByName($this->_sTemplateName, array_merge($this->_aOptiondDefault, $this->_aOptions));
  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. /** @} */