BxBaseModGeneralPageEntry.php 4.7 KB

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