BxBaseModProfilePageEntry.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 $_sCanonicalUrl;
  17. protected $_aProfileInfo;
  18. protected $_oProfile;
  19. public function __construct($aObject, $oTemplate = false)
  20. {
  21. parent::__construct($aObject, $oTemplate);
  22. $CNF = &$this->_oModule->_oConfig->CNF;
  23. // get profile info
  24. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  25. $iContentId = 0;
  26. if ('mine' == bx_get('id')) {
  27. $o = BxDolProfile::getInstance();
  28. if ($o && $iContentId = $o->getContentId())
  29. $_GET['id'] = $_REQUEST['id'] = $iContentId;
  30. } else {
  31. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  32. }
  33. if ($iProfileId) {
  34. $this->_sCanonicalUrl = 'page.php?i=' . $this->_aObject['uri'] . '&profile_id=' . $iProfileId;
  35. $this->_oProfile = BxDolProfile::getInstance($iProfileId);
  36. }
  37. if (!$this->_oProfile && $iContentId)
  38. $this->_oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
  39. if ($this->_oProfile) {
  40. $this->_aProfileInfo = $this->_oProfile->getInfo();
  41. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_aProfileInfo['content_id']);
  42. }
  43. if (!$this->_oProfile && isLogged() && !defined('BX_DOL_STUDIO_BUILDER_PAGE')) { // if no params are given, then redirect to own profile pages
  44. $a = [];
  45. if (isset($CNF['URI_VIEW_ENTRY']))
  46. $a[$CNF['URI_VIEW_ENTRY']] = ['id', 'getContentId'];
  47. if (isset($CNF['URI_VIEW_FRIENDS']))
  48. $a[$CNF['URI_VIEW_FRIENDS']] = ['profile_id', 'id'];
  49. if (isset($CNF['URI_VIEW_RELATIONS']))
  50. $a[$CNF['URI_VIEW_RELATIONS']] = ['profile_id', 'id'];
  51. foreach ($a as $sUri => $r) {
  52. if ($this->_aObject['uri'] == $sUri) {
  53. $oProfile = BxDolProfile::getInstance();
  54. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&' . $r[0] . '=' . $oProfile->{$r[1]}()));
  55. header("Location: " . $sUrl);
  56. exit;
  57. }
  58. }
  59. }
  60. if (!$this->_isAvailablePage($this->_aObject) || !$this->_oProfile) {
  61. $this->setPageCover(false);
  62. return;
  63. }
  64. $bLoggedOwner = $this->_oProfile->id() == bx_get_logged_profile_id();
  65. $bLoggedModerator = $this->_oModule->checkAllowedEditAnyEntry() === CHECK_ACTION_RESULT_ALLOWED;
  66. if(!$this->_oProfile->isActive() && !$bLoggedOwner && !$bLoggedModerator) {
  67. $this->setPageCover(false);
  68. return;
  69. }
  70. // select view profile submenu
  71. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  72. if($oMenuSubmenu)
  73. $oMenuSubmenu->setObjectSubmenu($CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'], array (
  74. 'title' => $this->_oProfile->getDisplayName(),
  75. 'link' => $this->_oProfile->getUrl(),
  76. 'icon' => $CNF['ICON'],
  77. ));
  78. // select view profile manage menu
  79. if(($oMenuManage = BxDolMenu::getObjectInstance('sys_site_manage')) !== false) {
  80. if(!empty($CNF['FIELD_ID']) && !empty($this->_aContentInfo) && is_array($this->_aContentInfo))
  81. $oMenuManage->setContentId($this->_aContentInfo[$CNF['FIELD_ID']]);
  82. $aObjectManage = [];
  83. if(!empty($CNF['OBJECT_MENU_MANAGE_VIEW_ENTRY']))
  84. $aObjectManage = [$CNF['OBJECT_MENU_MANAGE_VIEW_ENTRY']];
  85. else if(!empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  86. $aObjectManage = [$CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE'], true];
  87. call_user_func_array([$oMenuManage, 'setObjectManage'], $aObjectManage);
  88. }
  89. // add replaceable markers
  90. $this->addMarkers($this->_aContentInfo);
  91. $this->addMarkers($this->_aProfileInfo); // every content field can be used as marker
  92. $this->addMarkers(array('profile_id' => $this->_oProfile->id())); // profile id field
  93. $this->addMarkers(array('display_name' => $this->_oProfile->getDisplayName())); // profile display name
  94. $this->addMarkers(array('profile_link' => $this->_oProfile->getUrl())); // profile link
  95. if(($oInformer = BxDolInformer::getInstance($this->_oTemplate))) {
  96. $aInformers = [];
  97. // display message to profile author if profile isn't active
  98. if ($bLoggedOwner && !empty($CNF['INFORMERS']['status'])) {
  99. $sStatus = $this->_aContentInfo['profile_status'];
  100. $aInformer = $CNF['INFORMERS']['status'];
  101. if (isset($aInformer['map'][$sStatus]))
  102. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus]), 'type' => BX_INFORMER_ALERT);
  103. }
  104. // display message to moderator/administrator if profile isn't active
  105. if (!$bLoggedOwner && $bLoggedModerator && !empty($CNF['INFORMERS']['status_moderation'])) {
  106. $sStatus = $this->_aContentInfo['profile_status'];
  107. $sManageUrl = '#';
  108. if(!empty($CNF['FIELD_TITLE']) && !empty($CNF['URL_MANAGE_ADMINISTRATION']))
  109. $sManageUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_MANAGE_ADMINISTRATION'], array('filter' => urlencode($this->_aContentInfo[$CNF['FIELD_TITLE']]))));
  110. $aInformer = $CNF['INFORMERS']['status_moderation'];
  111. if (isset($aInformer['map'][$sStatus]))
  112. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus], $sManageUrl), 'type' => BX_INFORMER_ALERT);
  113. }
  114. // add informers
  115. if ($aInformers)
  116. foreach ($aInformers as $a)
  117. $oInformer->add($a['name'], $this->_replaceMarkers($a['msg']), $a['type']);
  118. if($bLoggedOwner || $bLoggedModerator)
  119. $this->_oProfile->getAccountObject()->addInformerDeletionScheduled($oInformer);
  120. }
  121. // display message if it is possible to switch to this profile
  122. if ($this->_oModule->serviceActAsProfile()) {
  123. $oProfile = $this->_aContentInfo ? BxDolProfile::getInstanceByContentAndType($this->_aContentInfo['id'], $this->MODULE) : false;
  124. if ($oProfile)
  125. $oProfile->checkSwitchToProfile($this->_oTemplate);
  126. }
  127. // set cover
  128. $this->_oModule->_oTemplate->setCover($this, $this->_aContentInfo);
  129. }
  130. public function getCode ()
  131. {
  132. // check if profile is active
  133. if (!$this->_oProfile || (!$this->_oProfile->isActive() && $this->_oProfile->id() != bx_get_logged_profile_id() && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)) {
  134. $this->_oTemplate->displayPageNotFound();
  135. exit;
  136. }
  137. $this->_oTemplate->addCss('main.css');
  138. $sResult = parent::getCode();
  139. if($this->_sCanonicalUrl)
  140. BxDolTemplate::getInstance()->setPageUrl($this->_sCanonicalUrl);
  141. return $sResult;
  142. }
  143. protected function _isVisiblePage ($a)
  144. {
  145. $CNF = &$this->_oModule->_oConfig->CNF;
  146. bx_import('BxDolPrivacy');
  147. if(($mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED) {
  148. /*
  149. * If visible by privacy, replace current page with different set of blocks.
  150. */
  151. if(!in_array($this->_aContentInfo['allow_view_to'], [BX_DOL_PG_HIDDEN, BX_DOL_PG_MEONLY])) {
  152. $aObject = BxDolPageQuery::getPageObject($CNF['OBJECT_PAGE_VIEW_ENTRY_CLOSED']);
  153. $this->_sObject = $aObject['object'];
  154. $this->_aObject = $aObject;
  155. $this->_oQuery = new BxDolPageQuery($this->_aObject);
  156. }
  157. else
  158. return $mixedAllowView;
  159. }
  160. if(!BxDolPage::_isVisiblePage($a))
  161. return false;
  162. $this->_oModule->checkAllowedView($this->_aContentInfo, true);
  163. return true;
  164. }
  165. }
  166. /** @} */