BxBaseModGeneralPageEntry.php 5.7 KB

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