BxBaseModProfilePageEntry.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 BaseProfile Base classes for profile modules
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Profile create/edit/delete pages.
  13. */
  14. class BxBaseModProfilePageEntry extends BxBaseModGeneralPageEntry
  15. {
  16. protected $_aProfileInfo;
  17. protected $_oProfile;
  18. public function __construct($aObject, $oTemplate = false)
  19. {
  20. parent::__construct($aObject, $oTemplate);
  21. $CNF = &$this->_oModule->_oConfig->CNF;
  22. // get profile info
  23. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  24. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  25. if ($iProfileId)
  26. $this->_oProfile = BxDolProfile::getInstance($iProfileId);
  27. if (!$this->_oProfile && $iContentId)
  28. $this->_oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
  29. if ($this->_oProfile) {
  30. $this->_aProfileInfo = $this->_oProfile->getInfo();
  31. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_aProfileInfo['content_id']);
  32. }
  33. if (!$this->_aContentInfo || !$this->_oProfile)
  34. return;
  35. // select view profile submenu
  36. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  37. $oMenuSubmenu->setObjectSubmenu($CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'], array (
  38. 'title' => $this->_oProfile->getDisplayName(),
  39. 'link' => $this->_oProfile->getUrl(),
  40. 'icon' => $CNF['ICON'],
  41. ));
  42. // add replaceable markers
  43. $this->addMarkers($this->_aProfileInfo); // every content field can be used as marker
  44. $this->addMarkers(array('profile_id' => $this->_oProfile->id())); // profile id field
  45. $this->addMarkers(array('display_name' => $this->_oProfile->getDisplayName())); // profile display name
  46. $this->addMarkers(array('profile_link' => $this->_oProfile->getUrl())); // profile link
  47. // display message if profile isn't active
  48. $aInformers = array ();
  49. $oInformer = BxDolInformer::getInstance($this->_oTemplate);
  50. if (bx_get_logged_profile_id() == $this->_oProfile->id() && !empty($CNF['INFORMERS']['status']) && $oInformer) {
  51. $sStatus = $this->_aContentInfo['profile_status'];
  52. if (isset($CNF['INFORMERS']['status']['map'][$sStatus]))
  53. $aInformers[] = array ('name' => $CNF['INFORMERS']['status']['name'], 'msg' => _t($CNF['INFORMERS']['status']['map'][$sStatus]), 'type' => BX_INFORMER_ALERT);
  54. }
  55. // display message if it is possible to switch to this profile
  56. if ($this->_oModule->serviceActAsProfile()) {
  57. $oProfile = $this->_aContentInfo ? BxDolProfile::getInstanceByContentTypeAccount($this->_aContentInfo['id'], $this->MODULE) : false;
  58. if ($oProfile)
  59. $oProfile->checkSwitchToProfile($this->_oTemplate);
  60. }
  61. // add informers
  62. if ($aInformers && $oInformer) {
  63. foreach ($aInformers as $a)
  64. $oInformer->add($a['name'], $this->_replaceMarkers($a['msg']), $a['type']);
  65. }
  66. // set cover
  67. $this->_oModule->_oTemplate->setCover($this->_aContentInfo);
  68. }
  69. protected function _processPermissionsCheck ()
  70. {
  71. $CNF = &$this->_oModule->_oConfig->CNF;
  72. bx_import('BxDolPrivacy');
  73. $mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo);
  74. if ($CNF['OBJECT_PAGE_VIEW_ENTRY'] == $this->_sObject) {
  75. if ((BX_DOL_PG_HIDDEN == $this->_aContentInfo['allow_view_to'] || BX_DOL_PG_MEONLY == $this->_aContentInfo['allow_view_to']) && CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
  76. $this->_oTemplate->displayAccessDenied($mixedAllowView);
  77. exit;
  78. }
  79. elseif (CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
  80. // replace current page with different set of blocks
  81. $aObject = BxDolPageQuery::getPageObject($CNF['OBJECT_PAGE_VIEW_ENTRY_CLOSED']);
  82. $this->_sObject = $aObject['object'];
  83. $this->_aObject = $aObject;
  84. $this->_oQuery = new BxDolPageQuery($this->_aObject);
  85. }
  86. }
  87. elseif (CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
  88. $this->_oTemplate->displayAccessDenied($mixedAllowView);
  89. exit;
  90. }
  91. $this->_oModule->checkAllowedView($this->_aContentInfo, true);
  92. }
  93. }
  94. /** @} */