BxBaseModGroupsAlertsResponse.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. public function __construct()
  14. {
  15. parent::__construct();
  16. }
  17. public function response($oAlert)
  18. {
  19. parent::response($oAlert);
  20. $CNF = $this->_oModule->_oConfig->CNF;
  21. // connection events
  22. if (isset($CNF['OBJECT_CONNECTIONS']) && $CNF['OBJECT_CONNECTIONS'] == $oAlert->sUnit && 'connection_added' == $oAlert->sAction) {
  23. $this->_oModule->serviceAddMutualConnection($oAlert->aExtras['content'], $oAlert->aExtras['initiator']);
  24. }
  25. elseif (isset($CNF['OBJECT_CONNECTIONS']) && $CNF['OBJECT_CONNECTIONS'] == $oAlert->sUnit && 'connection_removed' == $oAlert->sAction) {
  26. $this->_oModule->serviceOnRemoveConnection($oAlert->aExtras['content'], $oAlert->aExtras['initiator']);
  27. }
  28. // profile delete event
  29. if ('profile' == $oAlert->sUnit && 'delete' == $oAlert->sAction) {
  30. $this->_oModule->serviceDeleteProfileFromFansAndAdmins($oAlert->iObject);
  31. $this->_oModule->serviceReassignEntitiesByAuthor($oAlert->iObject);
  32. }
  33. if ($this->MODULE != $oAlert->sUnit)
  34. return;
  35. $bUseIn = getParam($CNF['PARAM_USE_IN']) == 'on';
  36. // join group events
  37. switch ($oAlert->sAction) {
  38. case 'join_invitation':
  39. if($bUseIn)
  40. $this->sendMailInvitation($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
  41. break;
  42. case 'join_request':
  43. if($bUseIn)
  44. $this->sendMailJoinRequest($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
  45. break;
  46. case 'join_request_accepted':
  47. if($bUseIn)
  48. $this->sendMailJoinRequestAccepted($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
  49. break;
  50. }
  51. }
  52. protected function sendMailInvitation ($oAlert, $iProfileId, $iSender = 0)
  53. {
  54. $CNF = $this->_oModule->_oConfig->CNF;
  55. if (isset($CNF["TABLE_INVITES"])){
  56. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  57. return '';
  58. if($oConnection && $oConnection->isConnected($iSender, $oAlert->iSender)){
  59. if ($this->_oModule->_oDb->getInviteByInvited($iProfileId, $oAlert->iSender) == 0){
  60. $oKeys = BxDolKey::getInstance();
  61. $iKeyLifetime = $CNF["INVITES_KEYS_LIFETIME"];
  62. $sKey = $oKeys->getNewKey(false, $iKeyLifetime);
  63. $this->_oModule->_oDb->insertInvite($sKey, $oAlert->iSender, $iSender, $iProfileId);
  64. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $oAlert->iObject . "&key=" . $sKey);
  65. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_INVITATION'], 0, $iProfileId, array(
  66. 'InviterUrl' => BxDolProfile::getInstance($iSender)->getUrl(),
  67. 'InviterDisplayName' => BxDolProfile::getInstance($iSender)->getDisplayName(),
  68. 'EntryUrl' => $sEntryUrl,
  69. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  70. ), BX_EMAIL_NOTIFY);
  71. }
  72. }
  73. }
  74. else{
  75. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_INVITATION'], 0, $iProfileId, array(
  76. 'InviterUrl' => BxDolProfile::getInstance($iSender)->getUrl(),
  77. 'InviterDisplayName' => BxDolProfile::getInstance($iSender)->getDisplayName(),
  78. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  79. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  80. ), BX_EMAIL_NOTIFY);
  81. }
  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. /** @} */