BxBaseCover.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /**
  60. * @hooks
  61. * @hookdef hook-system-display_cover 'system', 'display_cover' - hook to override page cover code to be output
  62. * - $unit_name - equals `system`
  63. * - $action - equals `display_cover`
  64. * - $object_id - not used
  65. * - $sender_id - not used
  66. * - $extra_params - array of additional params with the following array keys:
  67. * - `res` - [string] by ref, when null the default generation mechanism will be used, can be overridden in hook processing
  68. * - `template_name` - [string] by ref, template name, can be overridden in hook processing
  69. * - `params` - [array] by ref, additional params array as key&value pairs, can be overridden in hook processing
  70. * @hook @ref hook-system-display_cover
  71. */
  72. bx_alert('system', 'display_cover', 0, 0, [
  73. 'res' => &$sResult,
  74. 'template_name' => &$this->_sTemplateName,
  75. 'params' => &$aParams,
  76. ]);
  77. if ($sResult != null)
  78. return $sResult;
  79. return $this->_oTemplate->parseHtmlByName($this->_sTemplateName, $aParams);
  80. }
  81. /**
  82. * Display Empty Cover.
  83. */
  84. public function displayEmpty ()
  85. {
  86. return $this->_oTemplate->parseHtmlByName($this->_sTemplateNameEmpty, array());
  87. }
  88. /**
  89. * Add css/js files which are needed for display and functionality.
  90. */
  91. protected function _addJsCss()
  92. {
  93. if ($this->_bJsCssAdded)
  94. return;
  95. $this->_oTemplate->addCss(array('cover.css'));
  96. $this->_bJsCssAdded = true;
  97. }
  98. }
  99. /** @} */