BxBaseModProfileAlertsResponse.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModProfileAlertsResponse extends BxBaseModGeneralAlertsResponse
  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. $sModule = $this->_oModule->getName();
  22. // update picture field id when file is deleted
  23. if ($CNF['OBJECT_STORAGE'] == $oAlert->sUnit && 'file_deleted' == $oAlert->sAction && isset($CNF['FIELD_PICTURE'])) {
  24. $bResult = (int)$this->_oModule->_oDb->resetContentPictureByFileId($oAlert->iObject, $CNF['FIELD_PICTURE']) > 0;
  25. if($bResult)
  26. bx_alert($sModule, 'profile_picture_deleted', $oAlert->iObject);
  27. }
  28. if ($CNF['OBJECT_STORAGE_COVER'] == $oAlert->sUnit && 'file_deleted' == $oAlert->sAction && isset($CNF['FIELD_COVER'])) {
  29. $bResult = (int)$this->_oModule->_oDb->resetContentPictureByFileId($oAlert->iObject, $CNF['FIELD_COVER']) > 0;
  30. if($bResult)
  31. bx_alert($sModule, 'profile_cover_deleted', $oAlert->iObject);
  32. }
  33. // connection events
  34. if ($oAlert->sUnit == 'sys_profiles_friends' && $oAlert->sAction == 'connection_added') {
  35. if((int)$oAlert->aExtras['mutual'] == 0)
  36. $this->sendMailFriendRequest($oAlert);
  37. }
  38. /*
  39. * Re-translate timeline alert for timeline posts made by other profiles.
  40. * It's used with Notifications module in the following circumstances:
  41. * 1. User1 follow User2.
  42. * 2. User1 doesn't follow User3.
  43. * 3. User3 posts something on User2's timeline.
  44. * Result: User1 would be notifiend when the timeline of following profile (User2) was update by 3d party user.
  45. */
  46. if($oAlert->sUnit == 'bx_timeline' && $oAlert->sAction == 'post_common' && !empty($oAlert->aExtras['object_author_id'])) {
  47. $oTimelineOwner = BxDolProfile::getInstance($oAlert->aExtras['object_author_id']);
  48. if($oTimelineOwner && $oTimelineOwner->getModule() == $this->_oModule->getName() && $oTimelineOwner->id() != $oAlert->iSender) {
  49. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oTimelineOwner->getContentId());
  50. /*
  51. * Note. Timeline owner profile ID is used as alert sender and also a content (group) owner (author).
  52. */
  53. $iSenderId = $iObjectAuthorId = $oTimelineOwner->id();
  54. bx_alert($this->_oModule->getName(), 'timeline_post_common', $aContentInfo[$CNF['FIELD_ID']], $iSenderId, array(
  55. 'object_author_id' => $iObjectAuthorId,
  56. 'timeline_post_id' => $oAlert->iObject,
  57. 'timeline_post_author_id' => $oAlert->iSender,
  58. 'content' => $aContentInfo,
  59. 'group_profile' => $oTimelineOwner->id(),
  60. 'profile' => $oAlert->iSender,
  61. ));
  62. }
  63. }
  64. if ($this->MODULE != $oAlert->sUnit)
  65. return;
  66. // timeline events to override permissions
  67. switch ($oAlert->sAction) {
  68. case 'timeline_view':
  69. $this->processTimelineView($oAlert, $oAlert->iObject);
  70. break;
  71. case 'timeline_comment':
  72. case 'timeline_report':
  73. case 'timeline_vote':
  74. $this->processTimelineEventsBoolResult($oAlert, $oAlert->iObject);
  75. break;
  76. case 'timeline_post':
  77. $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject);
  78. break;
  79. case 'timeline_delete':
  80. $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject, 'checkAllowedEdit');
  81. break;
  82. case 'timeline_repost':
  83. $this->processTimelineRepost($oAlert, $oAlert->iObject);
  84. break;
  85. }
  86. }
  87. protected function sendMailFriendRequest ($oAlert)
  88. {
  89. $CNF = &$this->_oModule->_oConfig->CNF;
  90. if(empty($CNF['EMAIL_FRIEND_REQUEST']) || empty($CNF['URI_VIEW_FRIEND_REQUESTS']))
  91. return;
  92. $iRecipient = $oAlert->aExtras['content'];
  93. $oRecipient = BxDolProfile::getInstance($iRecipient);
  94. if($oRecipient->getModule() != $this->MODULE)
  95. return;
  96. $iSender = $oAlert->aExtras['initiator'];
  97. $oSender = BxDolProfile::getInstance($iSender);
  98. sendMailTemplate($CNF['EMAIL_FRIEND_REQUEST'], 0, $iRecipient, array(
  99. 'SenderUrl' => $oSender->getUrl(),
  100. 'SenderDisplayName' => $oSender->getDisplayName(),
  101. 'FriendsLink' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_FRIEND_REQUESTS'] . '&profile_id=' . $iRecipient),
  102. ), BX_EMAIL_NOTIFY);
  103. }
  104. protected function processTimelineView ($oAlert, $iGroupProfileId, $bDisableOwnerActions = false)
  105. {
  106. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  107. if (!$oGroupProfile)
  108. return;
  109. $bDisableOwnerActions = !BxDolService::call($oGroupProfile->getModule(), 'act_as_profile');
  110. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  111. if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedView($aContentInfo)) {
  112. $oAlert->aExtras['override_content'] = MsgBox(_t('_sys_access_denied_to_private_content'));
  113. }
  114. if ($bDisableOwnerActions && isset($oAlert->aExtras['menu'])) {
  115. foreach ($oAlert->aExtras['menu'] as $i => $r) {
  116. if ('timeline-view-owner' == $r['id'] || 'timeline-view-other' == $r['id'])
  117. unset($oAlert->aExtras['menu'][$i]);
  118. }
  119. }
  120. }
  121. protected function processTimelineEventsCheckResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  122. {
  123. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  124. return;
  125. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  126. if (!$oGroupProfile)
  127. return;
  128. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  129. if (CHECK_ACTION_RESULT_ALLOWED === ($s = $this->_oModule->$sFunc($aContentInfo))) {
  130. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  131. }
  132. else {
  133. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  134. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = $s;
  135. }
  136. }
  137. protected function processTimelineEventsBoolResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  138. {
  139. if (isAdmin() || !$oAlert->aExtras['result'])
  140. return;
  141. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  142. if (!$oGroupProfile)
  143. return;
  144. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  145. $oAlert->aExtras['result'] = (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->$sFunc($aContentInfo)) ? true : false;
  146. }
  147. protected function processTimelineRepost ($oAlert, $iGroupProfileId)
  148. {
  149. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  150. return;
  151. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  152. if (!$oGroupProfile)
  153. return;
  154. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  155. if (BX_DOL_PG_ALL == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]) {
  156. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  157. }
  158. else {
  159. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  160. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
  161. }
  162. }
  163. }
  164. /** @} */