BxBaseModGeneralPageEntry.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup TridentModules
  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. public function __construct($aObject, $oTemplate = false)
  21. {
  22. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  23. parent::__construct($aObject, $oTemplate ? $oTemplate : $this->_oModule->_oTemplate);
  24. }
  25. public function getCode ()
  26. {
  27. // check if content exists
  28. if (!$this->_aContentInfo) { // if entry is not found - display standard "404 page not found" page
  29. $this->_oTemplate->displayPageNotFound();
  30. exit;
  31. }
  32. // permissions check
  33. $this->_processPermissionsCheck ();
  34. // count views
  35. $CNF = &$this->_oModule->_oConfig->CNF;
  36. if (!empty($CNF['OBJECT_VIEWS'])) {
  37. BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $this->_aContentInfo[$CNF['FIELD_ID']])->doView();
  38. }
  39. $oCover = BxDolCover::getInstance($this->_oModule->_oTemplate);
  40. $oCover->setCoverClass($this->_oModule->getName() . '_cover');
  41. // set cover image
  42. if ($aThumb = $this->_getThumbForMetaObject()) {
  43. $oCover->setCoverImageUrl($aThumb);
  44. }
  45. // add content metatags
  46. if (!empty($CNF['OBJECT_METATAGS']) && $aThumb) {
  47. $o = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  48. if ($o)
  49. $o->metaAdd($this->_aContentInfo[$CNF['FIELD_ID']], $aThumb);
  50. }
  51. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  52. // add actions menu to submenu
  53. if (isset($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']))
  54. $oMenuSubmenu->setObjectActionsMenu($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  55. // add social sharing menu to submenu
  56. $oMenuSubmenu->setServiceSocialSharing(array(
  57. 'module' => $this->MODULE,
  58. 'method' => 'entity_social_sharing',
  59. ));
  60. return parent::getCode ();
  61. }
  62. protected function _processPermissionsCheck ()
  63. {
  64. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($this->_aContentInfo))) {
  65. $this->_oTemplate->displayAccessDenied($sMsg);
  66. exit;
  67. }
  68. $this->_oModule->checkAllowedView($this->_aContentInfo, true);
  69. }
  70. protected function _getThumbForMetaObject ()
  71. {
  72. $CNF = &$this->_oModule->_oConfig->CNF;
  73. if (empty($CNF['FIELD_THUMB']) || empty($this->_aContentInfo[$CNF['FIELD_THUMB']]) || empty($CNF['OBJECT_STORAGE']))
  74. return false;
  75. return array('id' => $this->_aContentInfo[$CNF['FIELD_THUMB']], 'object' => $CNF['OBJECT_STORAGE']);
  76. }
  77. protected function _getPageCacheParams ()
  78. {
  79. if (!$this->_aContentInfo)
  80. return '';
  81. return $this->_aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ID']]; // cache is different for every entry
  82. }
  83. }
  84. /** @} */