BxBaseModProfilePageEntry.php 7.4 KB

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