BxBaseModProfilePageEntry.php 6.2 KB

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