BxBaseModGroupsAlertsResponse.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 = true;
  36. if(isset($CNF['PARAM_USE_IN']))
  37. $bUseIn = getParam($CNF['PARAM_USE_IN']) == 'on';
  38. // join group events
  39. switch ($oAlert->sAction) {
  40. case 'join_invitation':
  41. if($bUseIn)
  42. $this->sendMailInvitation($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
  43. break;
  44. case 'join_request':
  45. if($bUseIn)
  46. $this->sendMailJoinRequest($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
  47. break;
  48. case 'join_request_accepted':
  49. if($bUseIn)
  50. $this->sendMailJoinRequestAccepted($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
  51. break;
  52. }
  53. }
  54. protected function sendMailInvitation ($oAlert, $iProfileId, $iSender = 0)
  55. {
  56. $CNF = $this->_oModule->_oConfig->CNF;
  57. if (isset($CNF["TABLE_INVITES"])){
  58. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  59. return '';
  60. if($oConnection && $oConnection->isConnected($iSender, $oAlert->iSender)){
  61. if ($this->_oModule->_oDb->getInviteByInvited($iProfileId, $oAlert->iSender) == 0){
  62. $oKeys = BxDolKey::getInstance();
  63. $iKeyLifetime = $CNF["INVITES_KEYS_LIFETIME"];
  64. $sKey = $oKeys->getNewKey(false, $iKeyLifetime);
  65. $this->_oModule->_oDb->insertInvite($sKey, $oAlert->iSender, $iSender, $iProfileId);
  66. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $oAlert->iObject . "&key=" . $sKey);
  67. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_INVITATION'], 0, $iProfileId, array(
  68. 'InviterUrl' => BxDolProfile::getInstance($iSender)->getUrl(),
  69. 'InviterDisplayName' => BxDolProfile::getInstance($iSender)->getDisplayName(),
  70. 'EntryUrl' => $sEntryUrl,
  71. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  72. ), BX_EMAIL_NOTIFY);
  73. }
  74. }
  75. }
  76. else{
  77. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_INVITATION'], 0, $iProfileId, array(
  78. 'InviterUrl' => BxDolProfile::getInstance($iSender)->getUrl(),
  79. 'InviterDisplayName' => BxDolProfile::getInstance($iSender)->getDisplayName(),
  80. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  81. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  82. ), BX_EMAIL_NOTIFY);
  83. }
  84. }
  85. protected function sendMailJoinRequest ($oAlert, $iProfileId, $iSender = 0)
  86. {
  87. $aAdmins = $this->_oModule->_oDb->getAdmins($oAlert->aExtras['group_profile']);
  88. foreach ($aAdmins as $iAdminProfileId) {
  89. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_JOIN_REQUEST'], 0, $iAdminProfileId, array(
  90. 'NewMemberUrl' => BxDolProfile::getInstance($iProfileId)->getUrl(),
  91. 'NewMemberDisplayName' => BxDolProfile::getInstance($iProfileId)->getDisplayName(),
  92. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  93. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  94. ), BX_EMAIL_NOTIFY);
  95. }
  96. }
  97. protected function sendMailJoinRequestAccepted ($oAlert, $iProfileId, $iSender = 0)
  98. {
  99. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_JOIN_CONFIRM'], 0, $iProfileId, array(
  100. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  101. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  102. ), BX_EMAIL_NOTIFY);
  103. }
  104. protected function processTimelineShare ($oAlert, $iGroupProfileId)
  105. {
  106. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  107. return;
  108. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  109. if (!$oGroupProfile)
  110. return;
  111. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  112. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  113. 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']])) {
  114. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  115. }
  116. else {
  117. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  118. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
  119. }
  120. }
  121. }
  122. /** @} */