BxBaseModGeneralPageEntry.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. $this->addMarkers([
  27. 'module' => $this->MODULE,
  28. ]);
  29. }
  30. public function isActive()
  31. {
  32. return true;
  33. }
  34. public function getContentInfo()
  35. {
  36. return $this->_aContentInfo;
  37. }
  38. public function getCode ()
  39. {
  40. // check if content exists
  41. if (!$this->_aContentInfo || !$this->isActive()) { // if entry is not found - display standard "404 page not found" page
  42. $this->_oTemplate->displayPageNotFound();
  43. exit;
  44. }
  45. $oCover = BxDolCover::getInstance($this->_oModule->_oTemplate);
  46. if ($oCover)
  47. $oCover->setCoverClass($this->_sCoverClass);
  48. // permissions check
  49. $this->_processPermissionsCheck ();
  50. // count views
  51. $CNF = &$this->_oModule->_oConfig->CNF;
  52. if(!empty($CNF['OBJECT_VIEWS'])) {
  53. $oView = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  54. if($oView && $oView->isEnabled())
  55. $oView->doView();
  56. }
  57. // set cover image
  58. $mixedCover = method_exists($this, '_getImageForPageCover') ? $this->_getImageForPageCover() : $this->_getThumbForMetaObject();
  59. if($mixedCover !== false) {
  60. $aCover = array(
  61. 'id' => $mixedCover['id']
  62. );
  63. if(!empty($mixedCover['transcoder']))
  64. $aCover['transcoder'] = $mixedCover['transcoder'];
  65. else if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_COVER']))
  66. $aCover['transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_COVER'];
  67. else if(!empty($mixedCover['object']))
  68. $aCover['object'] = $mixedCover['object'];
  69. $oCover->setCoverImageUrl($aCover);
  70. }
  71. // add content metatags
  72. if(!empty($CNF['OBJECT_METATAGS']) && ($o = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) !== false)
  73. $o->addPageMetaInfo($this->_aContentInfo[$CNF['FIELD_ID']], $this->_getThumbForMetaObject());
  74. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  75. if($oMenuSubmenu) {
  76. // add actions menu to submenu
  77. if(isset($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']))
  78. $oMenuSubmenu->setObjectActionsMenu($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  79. // add social sharing menu to submenu
  80. $oMenuSubmenu->setServiceSocialSharing(array(
  81. 'module' => $this->MODULE,
  82. 'method' => 'entity_social_sharing',
  83. ));
  84. }
  85. return parent::getCode ();
  86. }
  87. protected function _processPermissionsCheck ()
  88. {
  89. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($this->_aContentInfo))) {
  90. $this->_oTemplate->displayAccessDenied($sMsg);
  91. exit;
  92. }
  93. $this->_oModule->checkAllowedView($this->_aContentInfo, true);
  94. }
  95. protected function _getPageMetaDesc()
  96. {
  97. $CNF = &$this->_oModule->_oConfig->CNF;
  98. $sResult = '';
  99. if(isset($CNF['FIELD_TEXT'])) {
  100. $sResult = strip_tags($this->_oModule->_oTemplate->getText($this->_aContentInfo, false));
  101. $iLength = 0;
  102. if(!empty($CNF['PARAM_CHARS_SUMMARY']))
  103. $iLength = (int)getParam($CNF['PARAM_CHARS_SUMMARY']);
  104. if(empty($iLength))
  105. $iLength = 240;
  106. if(mb_strlen($sResult) > $iLength)
  107. $sResult = mb_substr($sResult, 0, $iLength);
  108. }
  109. if(empty($sResult))
  110. $sResult = $this->_replaceMarkers(_t($this->_aObject['meta_description']));
  111. return $sResult;
  112. }
  113. protected function _getThumbForMetaObject ()
  114. {
  115. return $this->_oModule->getEntryImageData($this->_aContentInfo);
  116. }
  117. protected function _getPageCacheParams ()
  118. {
  119. $s = parent::_getPageCacheParams ();
  120. if (!$this->_aContentInfo)
  121. return $s;
  122. return $s . $this->_aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ID']]; // cache is different for every entry
  123. }
  124. }
  125. /** @} */