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