BxBaseModGeneralPageEntry.php 5.4 KB

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