1
0

BxBaseModGroupsPageEntry.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Profile create/edit/delete pages.
  13. */
  14. class BxBaseModGroupsPageEntry extends BxBaseModProfilePageEntry
  15. {
  16. public function __construct($aObject, $oTemplate = false)
  17. {
  18. parent::__construct($aObject, $oTemplate);
  19. $CNF = &$this->_oModule->_oConfig->CNF;
  20. $this->_sCoverClass = 'bx-base-group-cover-wrapper ' . $this->_oModule->getName() . '_cover';
  21. $bLoggedOwner = isset($this->_aContentInfo[$CNF['FIELD_AUTHOR']]) && $this->_aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id();
  22. $bLoggedModerator = $this->_oModule->checkAllowedEditAnyEntry() === CHECK_ACTION_RESULT_ALLOWED;
  23. if(!empty($CNF['FIELD_CF']) && isset($this->_aContentInfo[$CNF['FIELD_CF']])) {
  24. $oCf = BxDolContentFilter::getInstance();
  25. if($oCf->isEnabled() && !$oCf->isAllowed($this->_aContentInfo[$CNF['FIELD_CF']])) {
  26. $this->setPageCover(false);
  27. return;
  28. }
  29. }
  30. $aInformers = array ();
  31. $oInformer = BxDolInformer::getInstance($this->_oTemplate);
  32. if($oInformer && ($bLoggedOwner || $bLoggedModerator)) {
  33. $sStatus = isset($CNF['FIELD_STATUS']) && isset($this->_aContentInfo[$CNF['FIELD_STATUS']]) ? $this->_aContentInfo[$CNF['FIELD_STATUS']] : '';
  34. $sStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']) && isset($this->_aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) ? $this->_aContentInfo[$CNF['FIELD_STATUS_ADMIN']] : '';
  35. //--- Display message to context author if context isn't active
  36. if ($bLoggedOwner && !empty($CNF['INFORMERS']['status'])) {
  37. $aInformer = $CNF['INFORMERS']['status'];
  38. if (isset($aInformer['map'][$sStatus]))
  39. $aInformers[] = ['name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus]), 'type' => BX_INFORMER_ALERT];
  40. }
  41. //--- Display 'approving' informer.
  42. if(!empty($sStatusAdmin) && $sStatusAdmin != BX_BASE_MOD_GENERAL_STATUS_ACTIVE) {
  43. if(!empty($CNF['INFORMERS']['approving']) && isset($CNF['INFORMERS']['approving']['map'][$sStatusAdmin])) {
  44. $aInformer = $CNF['INFORMERS']['approving'];
  45. $aInformers[] = ['name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatusAdmin]['msg']), 'type' => $aInformer['map'][$sStatusAdmin]['type']];
  46. }
  47. }
  48. //--- Display 'scheduled' informer if an item wasn't published yet.
  49. if(isset($CNF['FIELD_PUBLISHED'])) {
  50. if(!empty($CNF['INFORMERS']['scheduled']) && isset($CNF['INFORMERS']['scheduled']['map'][$sStatus])) {
  51. $this->addMarkers(array(
  52. 'date_publish_uf' => bx_time_js((int)$this->_aContentInfo[$CNF['FIELD_PUBLISHED']], BX_FORMAT_DATE, true)
  53. ));
  54. $aInformer = $CNF['INFORMERS']['scheduled'];
  55. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus]['msg']), 'type' => $aInformer['map'][$sStatus]['type']);
  56. }
  57. }
  58. if($aInformers)
  59. foreach($aInformers as $aInformer)
  60. $oInformer->add($aInformer['name'], $this->_replaceMarkers($aInformer['msg']), $aInformer['type']);
  61. }
  62. }
  63. protected function _getInvitationCode($aParams = [])
  64. {
  65. $CNF = &$this->_oModule->_oConfig->CNF;
  66. if(empty($CNF['TABLE_INVITES']) || !$this->_oProfile)
  67. return '';
  68. $iProfileId = bx_get_logged_profile_id();
  69. $iGroupProfileId = $this->_oProfile->id();
  70. if(!$this->_oModule->serviceIsInvited($iGroupProfileId, $iProfileId))
  71. return '';
  72. $sId = $this->_oModule->getName() . '_popup_invite';
  73. $sKey = $this->_oModule->serviceGetInvitedKey($iGroupProfileId, $iProfileId);
  74. $sCode = $this->_oModule->_oTemplate->getJsCode('invite_popup', array(
  75. 'sPopupId' => $sId,
  76. 'sKey' => $sKey,
  77. 'sAcceptUrl' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $this->_aProfileInfo['content_id'])),
  78. 'sDeclineUrl' => BX_DOL_URL_ROOT,
  79. 'iGroupProfileId' => $this->_oProfile->id(),
  80. ));
  81. if(!isset($aParams['use_invitation_popup']) || $aParams['use_invitation_popup'] === true)
  82. $sCode .= BxTemplFunctions::getInstance()->popupBox($sId, _t($CNF['T']['txt_invitation_popup_title']), $this->_oModule->_oTemplate->parseHtmlByName('popup_invite.html', array(
  83. 'popup_id' => $sId,
  84. 'text' => _t($CNF['T']['txt_invitation_popup_text']),
  85. 'button_accept' => _t($CNF['T']['txt_invitation_popup_accept_button']),
  86. 'button_decline' => _t($CNF['T']['txt_invitation_popup_decline_button']),
  87. )), true);
  88. $this->_oTemplate->addJs([
  89. 'modules/base/groups/js/|invite_popup.js',
  90. 'invite_popup.js'
  91. ]);
  92. return $sCode;
  93. }
  94. public function getCode ()
  95. {
  96. return $this->_getInvitationCode() . parent::getCode();
  97. }
  98. protected function _isAvailablePage($a)
  99. {
  100. if(!$this->_aContentInfo || !$this->_oModule->isEntryActive($this->_aContentInfo))
  101. return false;
  102. return parent::_isAvailablePage($a);
  103. }
  104. protected function _isVisiblePage ($a)
  105. {
  106. $CNF = &$this->_oModule->_oConfig->CNF;
  107. if(!$this->_aContentInfo)
  108. return false;
  109. if(($mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED) {
  110. $bPartiallyVisible = false;
  111. if(!empty($CNF['OBJECT_PRIVACY_VIEW']) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  112. $bPartiallyVisible = $oPrivacy->isPartiallyVisible($this->_aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  113. /*
  114. * If partially visible, replace current page with different set of blocks.
  115. */
  116. $bJoinPage = isset($CNF['OBJECT_PAGE_JOINED_ENTRY']) && $this->_sObject === $CNF['OBJECT_PAGE_JOINED_ENTRY'];
  117. if($bPartiallyVisible && ($this->_sObject === $CNF['OBJECT_PAGE_VIEW_ENTRY'] || $bJoinPage)) {
  118. $sPage = $bJoinPage ? $CNF['OBJECT_PAGE_JOINED_ENTRY'] : $CNF['OBJECT_PAGE_VIEW_ENTRY_CLOSED'];
  119. $aObject = BxDolPageQuery::getPageObject($sPage);
  120. $this->_sObject = $aObject['object'];
  121. $this->_aObject = $aObject;
  122. $this->_oQuery = new BxDolPageQuery($this->_aObject);
  123. }
  124. else
  125. return $mixedAllowView;
  126. }
  127. if(!BxDolPage::_isVisiblePage($a))
  128. return false;
  129. $this->_oModule->checkAllowedView($this->_aContentInfo, true);
  130. return true;
  131. }
  132. }
  133. /** @} */