BxBaseModGeneralPageEntry.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. /**
  13. * Entry create/edit pages
  14. */
  15. class BxBaseModGeneralPageEntry extends BxTemplPage
  16. {
  17. protected $MODULE;
  18. protected $_oModule;
  19. protected $_aContentInfo = false;
  20. protected $_sCoverClass;
  21. public function __construct($aObject, $oTemplate = false)
  22. {
  23. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  24. parent::__construct($aObject, $oTemplate ? $oTemplate : $this->_oModule->_oTemplate);
  25. $this->_sCoverClass = $this->_oModule->getName() . '_cover';
  26. }
  27. public function isActive()
  28. {
  29. return true;
  30. }
  31. public function getCode ()
  32. {
  33. // check if content exists
  34. if (!$this->_aContentInfo || !$this->isActive()) { // if entry is not found - display standard "404 page not found" page
  35. $this->_oTemplate->displayPageNotFound();
  36. exit;
  37. }
  38. // permissions check
  39. $this->_processPermissionsCheck ();
  40. // count views
  41. $CNF = &$this->_oModule->_oConfig->CNF;
  42. if (!empty($CNF['OBJECT_VIEWS'])) {
  43. BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $this->_aContentInfo[$CNF['FIELD_ID']])->doView();
  44. }
  45. $oCover = BxDolCover::getInstance($this->_oModule->_oTemplate);
  46. $oCover->setCoverClass($this->_sCoverClass);
  47. // set cover image
  48. $mixedThumb = $this->_getThumbForMetaObject();
  49. if($mixedThumb !== false) {
  50. $aCover = array(
  51. 'id' => $mixedThumb['id']
  52. );
  53. if(!empty($mixedThumb['transcoder']))
  54. $aCover['transcoder'] = $mixedThumb['transcoder'];
  55. else if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_COVER']))
  56. $aCover['transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_COVER'];
  57. else if(!empty($mixedThumb['object']))
  58. $aCover['object'] = $mixedThumb['object'];
  59. $oCover->setCoverImageUrl($aCover);
  60. }
  61. // add content metatags
  62. if (!empty($CNF['OBJECT_METATAGS']) && $mixedThumb) {
  63. $o = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  64. if ($o)
  65. $o->addPageMetaInfo($this->_aContentInfo[$CNF['FIELD_ID']], $mixedThumb);
  66. }
  67. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  68. // add actions menu to submenu
  69. if (isset($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']))
  70. $oMenuSubmenu->setObjectActionsMenu($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  71. // add social sharing menu to submenu
  72. $oMenuSubmenu->setServiceSocialSharing(array(
  73. 'module' => $this->MODULE,
  74. 'method' => 'entity_social_sharing',
  75. ));
  76. return parent::getCode ();
  77. }
  78. protected function _processPermissionsCheck ()
  79. {
  80. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($this->_aContentInfo))) {
  81. $this->_oTemplate->displayAccessDenied($sMsg);
  82. exit;
  83. }
  84. $this->_oModule->checkAllowedView($this->_aContentInfo, true);
  85. }
  86. protected function _getThumbForMetaObject ()
  87. {
  88. $CNF = &$this->_oModule->_oConfig->CNF;
  89. if (empty($CNF['FIELD_THUMB']) || empty($this->_aContentInfo[$CNF['FIELD_THUMB']]) || empty($CNF['OBJECT_STORAGE']))
  90. return false;
  91. return array('id' => $this->_aContentInfo[$CNF['FIELD_THUMB']], 'object' => $CNF['OBJECT_STORAGE']);
  92. }
  93. protected function _getPageCacheParams ()
  94. {
  95. if (!$this->_aContentInfo)
  96. return '';
  97. return $this->_aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ID']]; // cache is different for every entry
  98. }
  99. }
  100. /** @} */