BxBaseModProfilePageEntry.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  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. $bLoggedOwner = $this->_oProfile->id() == bx_get_logged_profile_id();
  34. $bLoggedModerator = $this->_oModule->checkAllowedEditAnyEntry() === CHECK_ACTION_RESULT_ALLOWED;
  35. if (!$this->_aContentInfo || !$this->_oProfile || (!$this->_oProfile->isActive() && !$bLoggedOwner && !$bLoggedModerator)) {
  36. $this->setPageCover(false);
  37. return;
  38. }
  39. // select view profile submenu
  40. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  41. $oMenuSubmenu->setObjectSubmenu($CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'], array (
  42. 'title' => $this->_oProfile->getDisplayName(),
  43. 'link' => $this->_oProfile->getUrl(),
  44. 'icon' => $CNF['ICON'],
  45. ));
  46. // add replaceable markers
  47. $this->addMarkers($this->_aProfileInfo); // every content field can be used as marker
  48. $this->addMarkers(array('profile_id' => $this->_oProfile->id())); // profile id field
  49. $this->addMarkers(array('display_name' => $this->_oProfile->getDisplayName())); // profile display name
  50. $this->addMarkers(array('profile_link' => $this->_oProfile->getUrl())); // profile link
  51. $aInformers = array ();
  52. $oInformer = BxDolInformer::getInstance($this->_oTemplate);
  53. if($oInformer) {
  54. // display message to profile author if profile isn't active
  55. if ($bLoggedOwner && !empty($CNF['INFORMERS']['status'])) {
  56. $sStatus = $this->_aContentInfo['profile_status'];
  57. $aInformer = $CNF['INFORMERS']['status'];
  58. if (isset($aInformer['map'][$sStatus]))
  59. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus]), 'type' => BX_INFORMER_ALERT);
  60. }
  61. // display message to moderator/administrator if profile isn't active
  62. if (!$bLoggedOwner && $bLoggedModerator && !empty($CNF['INFORMERS']['status_moderation'])) {
  63. $sStatus = $this->_aContentInfo['profile_status'];
  64. $sManageUrl = '#';
  65. if(!empty($CNF['FIELD_TITLE']) && !empty($CNF['URL_MANAGE_ADMINISTRATION']))
  66. $sManageUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_MANAGE_ADMINISTRATION'], array('filter' => urlencode($this->_aContentInfo[$CNF['FIELD_TITLE']])));
  67. $aInformer = $CNF['INFORMERS']['status_moderation'];
  68. if (isset($aInformer['map'][$sStatus]))
  69. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus], $sManageUrl), 'type' => BX_INFORMER_ALERT);
  70. }
  71. // add informers
  72. if ($aInformers)
  73. foreach ($aInformers as $a)
  74. $oInformer->add($a['name'], $this->_replaceMarkers($a['msg']), $a['type']);
  75. }
  76. // display message if it is possible to switch to this profile
  77. if ($this->_oModule->serviceActAsProfile()) {
  78. $oProfile = $this->_aContentInfo ? BxDolProfile::getInstanceByContentTypeAccount($this->_aContentInfo['id'], $this->MODULE) : false;
  79. if ($oProfile)
  80. $oProfile->checkSwitchToProfile($this->_oTemplate);
  81. }
  82. // set cover
  83. $this->_oModule->_oTemplate->setCover($this, $this->_aContentInfo);
  84. }
  85. public function getCode ()
  86. {
  87. // check if profile is active
  88. if (!$this->_oProfile || (!$this->_oProfile->isActive() && $this->_oProfile->id() != bx_get_logged_profile_id() && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)) {
  89. $this->_oTemplate->displayPageNotFound();
  90. exit;
  91. }
  92. return parent::getCode();
  93. }
  94. protected function _processPermissionsCheck ()
  95. {
  96. $CNF = &$this->_oModule->_oConfig->CNF;
  97. bx_import('BxDolPrivacy');
  98. $mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo);
  99. if ($CNF['OBJECT_PAGE_VIEW_ENTRY'] == $this->_sObject) {
  100. if ((BX_DOL_PG_HIDDEN == $this->_aContentInfo['allow_view_to'] || BX_DOL_PG_MEONLY == $this->_aContentInfo['allow_view_to']) && CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
  101. $this->_oTemplate->displayAccessDenied($mixedAllowView);
  102. exit;
  103. }
  104. elseif (CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
  105. // replace current page with different set of blocks
  106. $aObject = BxDolPageQuery::getPageObject($CNF['OBJECT_PAGE_VIEW_ENTRY_CLOSED']);
  107. $this->_sObject = $aObject['object'];
  108. $this->_aObject = $aObject;
  109. $this->_oQuery = new BxDolPageQuery($this->_aObject);
  110. }
  111. }
  112. elseif (CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
  113. $this->_oTemplate->displayAccessDenied($mixedAllowView);
  114. exit;
  115. }
  116. $this->_oModule->checkAllowedView($this->_aContentInfo, true);
  117. }
  118. }
  119. /** @} */