BxBaseModProfilePageEntry.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 && ($oProfile = BxDolProfile::getInstance()) !== false) {
  53. $this->setForceRedirect(bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&' . $r[0] . '=' . $oProfile->{$r[1]}())));
  54. return;
  55. }
  56. }
  57. }
  58. if (!$this->_isAvailablePage($this->_aObject) || !$this->_oProfile) {
  59. $this->setPageCover(false);
  60. return;
  61. }
  62. $bLoggedOwner = $this->_oProfile->id() == bx_get_logged_profile_id();
  63. $bLoggedModerator = $this->_oModule->checkAllowedEditAnyEntry() === CHECK_ACTION_RESULT_ALLOWED;
  64. if(!$this->_oProfile->isActive() && !$bLoggedOwner && !$bLoggedModerator) {
  65. $this->setPageCover(false);
  66. return;
  67. }
  68. // select view profile submenu
  69. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  70. if($oMenuSubmenu)
  71. $oMenuSubmenu->setObjectSubmenu($CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'], array (
  72. 'title' => $this->_oProfile->getDisplayName(),
  73. 'link' => $this->_oProfile->getUrl(),
  74. 'icon' => $CNF['ICON'],
  75. ));
  76. // select view profile manage menu
  77. if(($oMenuManage = BxDolMenu::getObjectInstance('sys_site_manage')) !== false) {
  78. if(!empty($CNF['FIELD_ID']) && !empty($this->_aContentInfo) && is_array($this->_aContentInfo))
  79. $oMenuManage->setContentId($this->_aContentInfo[$CNF['FIELD_ID']]);
  80. $aObjectManage = [];
  81. if(!empty($CNF['OBJECT_MENU_MANAGE_VIEW_ENTRY']))
  82. $aObjectManage = [$CNF['OBJECT_MENU_MANAGE_VIEW_ENTRY']];
  83. else if(!empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  84. $aObjectManage = [$CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE'], true];
  85. call_user_func_array([$oMenuManage, 'setObjectManage'], $aObjectManage);
  86. }
  87. // add replaceable markers
  88. $this->addMarkers($this->_aContentInfo);
  89. $this->addMarkers($this->_aProfileInfo); // every content field can be used as marker
  90. $this->addMarkers(array('profile_id' => $this->_oProfile->id())); // profile id field
  91. $this->addMarkers(array('display_name' => $this->_oProfile->getDisplayName())); // profile display name
  92. $this->addMarkers(array('profile_link' => $this->_oProfile->getUrl())); // profile link
  93. if(($oInformer = BxDolInformer::getInstance($this->_oTemplate))) {
  94. $aInformers = [];
  95. // display message to profile author if profile isn't active
  96. if ($bLoggedOwner && !empty($CNF['INFORMERS']['status'])) {
  97. $sStatus = $this->_aContentInfo['profile_status'];
  98. $aInformer = $CNF['INFORMERS']['status'];
  99. if (isset($aInformer['map'][$sStatus]))
  100. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus]), 'type' => BX_INFORMER_ALERT);
  101. }
  102. // display message to moderator/administrator if profile isn't active
  103. if (!$bLoggedOwner && $bLoggedModerator && !empty($CNF['INFORMERS']['status_moderation'])) {
  104. $sStatus = $this->_aContentInfo['profile_status'];
  105. $sManageUrl = '#';
  106. if(!empty($CNF['FIELD_TITLE']) && !empty($CNF['URL_MANAGE_ADMINISTRATION']))
  107. $sManageUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_MANAGE_ADMINISTRATION'], array('filter' => urlencode($this->_aContentInfo[$CNF['FIELD_TITLE']]))));
  108. $aInformer = $CNF['INFORMERS']['status_moderation'];
  109. if (isset($aInformer['map'][$sStatus]))
  110. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus], $sManageUrl), 'type' => BX_INFORMER_ALERT);
  111. }
  112. // add informers
  113. if ($aInformers)
  114. foreach ($aInformers as $a)
  115. $oInformer->add($a['name'], $this->_replaceMarkers($a['msg']), $a['type']);
  116. if($bLoggedOwner || $bLoggedModerator)
  117. $this->_oProfile->getAccountObject()->addInformerDeletionScheduled($oInformer);
  118. }
  119. // display message if it is possible to switch to this profile
  120. if ($this->_oModule->serviceActAsProfile()) {
  121. $oProfile = $this->_aContentInfo ? BxDolProfile::getInstanceByContentAndType($this->_aContentInfo['id'], $this->MODULE) : false;
  122. if ($oProfile)
  123. $oProfile->checkSwitchToProfile($this->_oTemplate);
  124. }
  125. // set cover
  126. $this->_oModule->_oTemplate->setCover($this, $this->_aContentInfo);
  127. }
  128. public function getCode ()
  129. {
  130. // check if profile is active
  131. if (!$this->_oProfile || (!$this->_oProfile->isActive() && $this->_oProfile->id() != bx_get_logged_profile_id() && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)) {
  132. $this->_oTemplate->displayPageNotFound();
  133. exit;
  134. }
  135. $this->_oTemplate->addCss('main.css');
  136. $sResult = parent::getCode();
  137. if($this->_sCanonicalUrl)
  138. BxDolTemplate::getInstance()->setPageUrl($this->_sCanonicalUrl);
  139. return $sResult;
  140. }
  141. protected function _isVisiblePage ($a)
  142. {
  143. $CNF = &$this->_oModule->_oConfig->CNF;
  144. bx_import('BxDolPrivacy');
  145. if(($mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED) {
  146. /*
  147. * If visible by privacy, replace current page with different set of blocks.
  148. */
  149. if(!in_array($this->_aContentInfo['allow_view_to'], [BX_DOL_PG_HIDDEN, BX_DOL_PG_MEONLY])) {
  150. $aObject = BxDolPageQuery::getPageObject($CNF['OBJECT_PAGE_VIEW_ENTRY_CLOSED']);
  151. $this->_sObject = $aObject['object'];
  152. $this->_aObject = $aObject;
  153. $this->_oQuery = new BxDolPageQuery($this->_aObject);
  154. }
  155. else
  156. return $mixedAllowView;
  157. }
  158. if(!BxDolPage::_isVisiblePage($a))
  159. return false;
  160. $this->_oModule->checkAllowedView($this->_aContentInfo, true);
  161. return true;
  162. }
  163. }
  164. /** @} */