BxBaseModGroupsPageEntry.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 'approving' informer.
  36. if(!empty($sStatusAdmin) && $sStatusAdmin != BX_BASE_MOD_GENERAL_STATUS_ACTIVE) {
  37. if(!empty($CNF['INFORMERS']['approving']) && isset($CNF['INFORMERS']['approving']['map'][$sStatusAdmin])) {
  38. $aInformer = $CNF['INFORMERS']['approving'];
  39. $aInformers[] = ['name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatusAdmin]['msg']), 'type' => $aInformer['map'][$sStatusAdmin]['type']];
  40. }
  41. }
  42. //--- Display 'scheduled' informer if an item wasn't published yet.
  43. if(isset($CNF['FIELD_PUBLISHED'])) {
  44. if(!empty($CNF['INFORMERS']['scheduled']) && isset($CNF['INFORMERS']['scheduled']['map'][$sStatus])) {
  45. $this->addMarkers(array(
  46. 'date_publish_uf' => bx_time_js((int)$this->_aContentInfo[$CNF['FIELD_PUBLISHED']], BX_FORMAT_DATE, true)
  47. ));
  48. $aInformer = $CNF['INFORMERS']['scheduled'];
  49. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus]['msg']), 'type' => $aInformer['map'][$sStatus]['type']);
  50. }
  51. }
  52. if($aInformers)
  53. foreach($aInformers as $aInformer)
  54. $oInformer->add($aInformer['name'], $this->_replaceMarkers($aInformer['msg']), $aInformer['type']);
  55. }
  56. }
  57. protected function _getInvitationCode($aParams = [])
  58. {
  59. $CNF = &$this->_oModule->_oConfig->CNF;
  60. if(empty($CNF['TABLE_INVITES']) || !$this->_oProfile)
  61. return '';
  62. $iProfileId = bx_get_logged_profile_id();
  63. $iGroupProfileId = $this->_oProfile->id();
  64. if(!$this->_oModule->serviceIsInvited($iGroupProfileId, $iProfileId))
  65. return '';
  66. $sId = $this->_oModule->getName() . '_popup_invite';
  67. $sKey = $this->_oModule->serviceGetInvitedKey($iGroupProfileId, $iProfileId);
  68. $sCode = $this->_oModule->_oTemplate->getJsCode('invite_popup', array(
  69. 'sPopupId' => $sId,
  70. 'sKey' => $sKey,
  71. 'sAcceptUrl' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $this->_aProfileInfo['content_id'])),
  72. 'sDeclineUrl' => BX_DOL_URL_ROOT,
  73. 'iGroupProfileId' => $this->_oProfile->id(),
  74. ));
  75. if(!isset($aParams['use_invitation_popup']) || $aParams['use_invitation_popup'] === true)
  76. $sCode .= BxTemplFunctions::getInstance()->popupBox($sId, _t($CNF['T']['txt_invitation_popup_title']), $this->_oModule->_oTemplate->parseHtmlByName('popup_invite.html', array(
  77. 'popup_id' => $sId,
  78. 'text' => _t($CNF['T']['txt_invitation_popup_text']),
  79. 'button_accept' => _t($CNF['T']['txt_invitation_popup_accept_button']),
  80. 'button_decline' => _t($CNF['T']['txt_invitation_popup_decline_button']),
  81. )), true);
  82. $this->_oTemplate->addJs([
  83. 'modules/base/groups/js/|invite_popup.js',
  84. 'invite_popup.js'
  85. ]);
  86. return $sCode;
  87. }
  88. public function getCode ()
  89. {
  90. return $this->_getInvitationCode() . parent::getCode();
  91. }
  92. protected function _isAvailablePage($a)
  93. {
  94. if(!$this->_aContentInfo || !$this->_oModule->isEntryActive($this->_aContentInfo))
  95. return false;
  96. return parent::_isAvailablePage($a);
  97. }
  98. protected function _isVisiblePage ($a)
  99. {
  100. $CNF = &$this->_oModule->_oConfig->CNF;
  101. if(!$this->_aContentInfo)
  102. return false;
  103. if(($mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED) {
  104. $bPartiallyVisible = false;
  105. if(!empty($CNF['OBJECT_PRIVACY_VIEW']) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
  106. $bPartiallyVisible = $oPrivacy->isPartiallyVisible($this->_aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  107. /*
  108. * If partially visible, replace current page with different set of blocks.
  109. */
  110. if($bPartiallyVisible && $this->_sObject == $CNF['OBJECT_PAGE_VIEW_ENTRY']) {
  111. $aObject = BxDolPageQuery::getPageObject($CNF['OBJECT_PAGE_VIEW_ENTRY_CLOSED']);
  112. $this->_sObject = $aObject['object'];
  113. $this->_aObject = $aObject;
  114. $this->_oQuery = new BxDolPageQuery($this->_aObject);
  115. }
  116. else
  117. return $mixedAllowView;
  118. }
  119. if(!BxDolPage::_isVisiblePage($a))
  120. return false;
  121. $this->_oModule->checkAllowedView($this->_aContentInfo, true);
  122. return true;
  123. }
  124. }
  125. /** @} */