BxBaseModProfilePageEntry.php 6.6 KB

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