BxBaseModProfilePageEntry.php 7.1 KB

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