BxBaseModGeneralPageEntry.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // set cover image
  40. if ($aThumb = $this->_getThumbForMetaObject()) {
  41. $oCover = BxDolCover::getInstance($this->_oModule->_oTemplate);
  42. $oCover->setCoverImageUrl($aThumb);
  43. }
  44. // add content metatags
  45. if (!empty($CNF['OBJECT_METATAGS']) && $aThumb) {
  46. $o = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  47. if ($o)
  48. $o->metaAdd($this->_aContentInfo[$CNF['FIELD_ID']], $aThumb);
  49. }
  50. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  51. // add actions menu to submenu
  52. if (isset($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']))
  53. $oMenuSubmenu->setObjectActionsMenu($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  54. // add social sharing menu to submenu
  55. $oMenuSubmenu->setServiceSocialSharing(array(
  56. 'module' => $this->MODULE,
  57. 'method' => 'entity_social_sharing',
  58. ));
  59. return parent::getCode ();
  60. }
  61. protected function _processPermissionsCheck ()
  62. {
  63. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($this->_aContentInfo))) {
  64. $this->_oTemplate->displayAccessDenied($sMsg);
  65. exit;
  66. }
  67. $this->_oModule->checkAllowedView($this->_aContentInfo, true);
  68. }
  69. protected function _getThumbForMetaObject ()
  70. {
  71. $CNF = &$this->_oModule->_oConfig->CNF;
  72. if (empty($CNF['FIELD_THUMB']) || empty($this->_aContentInfo[$CNF['FIELD_THUMB']]) || empty($CNF['OBJECT_STORAGE']))
  73. return false;
  74. return array('id' => $this->_aContentInfo[$CNF['FIELD_THUMB']], 'object' => $CNF['OBJECT_STORAGE']);
  75. }
  76. protected function _getPageCacheParams ()
  77. {
  78. if (!$this->_aContentInfo)
  79. return '';
  80. return $this->_aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ID']]; // cache is different for every entry
  81. }
  82. }
  83. /** @} */