BxBaseModGroupsAlertsResponse.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. class BxBaseModGroupsAlertsResponse extends BxBaseModProfileAlertsResponse
  12. {
  13. /*
  14. * Use Internal Notifications.
  15. */
  16. protected $_bUseIn;
  17. public function __construct()
  18. {
  19. parent::__construct();
  20. $this->_bUseIn = $this->_oModule->_oConfig->isInternalNotifications();
  21. }
  22. public function response($oAlert)
  23. {
  24. parent::response($oAlert);
  25. $CNF = &$this->_oModule->_oConfig->CNF;
  26. // connection events
  27. if (isset($CNF['OBJECT_CONNECTIONS']) && $CNF['OBJECT_CONNECTIONS'] == $oAlert->sUnit && 'connection_added' == $oAlert->sAction) {
  28. $this->_oModule->serviceAddMutualConnection($oAlert->aExtras['content'], $oAlert->aExtras['initiator']);
  29. }
  30. elseif (isset($CNF['OBJECT_CONNECTIONS']) && $CNF['OBJECT_CONNECTIONS'] == $oAlert->sUnit && 'connection_removed' == $oAlert->sAction) {
  31. $this->_oModule->serviceOnRemoveConnection($oAlert->aExtras['content'], $oAlert->aExtras['initiator']);
  32. }
  33. // profile delete event
  34. if ('profile' == $oAlert->sUnit && 'delete' == $oAlert->sAction) {
  35. $this->_oModule->serviceDeleteProfileFromFansAndAdmins($oAlert->iObject);
  36. $this->_oModule->serviceReassignEntitiesByAuthor($oAlert->iObject);
  37. }
  38. if ($this->MODULE != $oAlert->sUnit)
  39. return;
  40. // join group events
  41. switch ($oAlert->sAction) {
  42. case 'join_invitation':
  43. $this->sendMailInvitation($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
  44. break;
  45. case 'join_request':
  46. if($this->_bUseIn)
  47. $this->sendMailJoinRequest($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
  48. break;
  49. case 'join_request_accepted':
  50. if($this->_bUseIn)
  51. $this->sendMailJoinRequestAccepted($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
  52. break;
  53. }
  54. }
  55. protected function sendMailInvitation ($oAlert, $iInvited, $iInviter = 0)
  56. {
  57. $CNF = &$this->_oModule->_oConfig->CNF;
  58. $bTrackInvites = isset($CNF["TABLE_INVITES"]) && isset($CNF['OBJECT_CONNECTIONS']);
  59. if(!$this->_bUseIn && !$bTrackInvites)
  60. return;
  61. $sEntryUrl = $oAlert->aExtras['entry_url'];
  62. if($bTrackInvites) {
  63. if(!($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  64. return;
  65. if($iInviter != $oAlert->iSender && !$oConnection->isConnected($iInviter, $oAlert->iSender))
  66. return;
  67. if($this->_oModule->_oDb->isInviteByInvited($iInvited, $oAlert->iSender))
  68. return;
  69. $sKey = BxDolKey::getInstance()->getNewKey(false, $CNF["INVITES_KEYS_LIFETIME"]);
  70. $this->_oModule->_oDb->insertInvite($sKey, $oAlert->iSender, $iInviter, $iInvited);
  71. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], [
  72. 'id' => $oAlert->iObject,
  73. 'key' => $sKey
  74. ]);
  75. }
  76. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_INVITATION'], 0, $iInvited, array(
  77. 'InviterUrl' => BxDolProfile::getInstance($iInviter)->getUrl(),
  78. 'InviterDisplayName' => BxDolProfile::getInstance($iInviter)->getDisplayName(),
  79. 'EntryUrl' => $sEntryUrl,
  80. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  81. ), BX_EMAIL_NOTIFY);
  82. }
  83. protected function sendMailJoinRequest ($oAlert, $iProfileId, $iSender = 0)
  84. {
  85. $aAdmins = $this->_oModule->_oDb->getAdmins($oAlert->aExtras['group_profile']);
  86. foreach ($aAdmins as $iAdminProfileId) {
  87. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_JOIN_REQUEST'], 0, $iAdminProfileId, array(
  88. 'NewMemberUrl' => BxDolProfile::getInstance($iProfileId)->getUrl(),
  89. 'NewMemberDisplayName' => BxDolProfile::getInstance($iProfileId)->getDisplayName(),
  90. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  91. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  92. ), BX_EMAIL_NOTIFY);
  93. }
  94. }
  95. protected function sendMailJoinRequestAccepted ($oAlert, $iProfileId, $iSender = 0)
  96. {
  97. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_JOIN_CONFIRM'], 0, $iProfileId, array(
  98. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  99. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  100. ), BX_EMAIL_NOTIFY);
  101. }
  102. protected function processTimelineShare ($oAlert, $iGroupProfileId)
  103. {
  104. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  105. return;
  106. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  107. if (!$oGroupProfile)
  108. return;
  109. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  110. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  111. if (BX_DOL_PG_ALL == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] || (BX_DOL_PG_MEMBERS == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] && isLogged()) || $oPrivacy->isPartiallyVisible($aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']])) {
  112. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  113. }
  114. else {
  115. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  116. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
  117. }
  118. }
  119. }
  120. /** @} */