BxBaseModProfileAlertsResponse.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 && !BxDolModuleQuery::getInstance()->isEnabledByName('bx_notifications'))
  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. /*
  47. * The code was commented because it looks like the Retranslation of
  48. * Timeline Common Post is redundant. It's happened after system of Contexts was created.
  49. *
  50. * TODO: If nothing happened, remove the code in UNA v.10.
  51. * Don't forget to:
  52. * 1. Stop listening 'bx_timeline' - 'post_common' alert.
  53. * 2. Remove BxBaseModProfileModule::serviceGetNotificationsTimelinePostCommon method
  54. * 3. Remove language keys from $CNF['T']['txt_ntfs_timeline_post_common']
  55. *
  56. if($oAlert->sUnit == 'bx_timeline' && $oAlert->sAction == 'post_common' && !empty($oAlert->aExtras['owner_id'])) {
  57. $iTimelineOwner = (int)$oAlert->aExtras['owner_id'];
  58. $oTimelineOwner = BxDolProfile::getInstance($iTimelineOwner);
  59. if($oTimelineOwner && $oTimelineOwner->getModule() == $this->_oModule->getName() && $iTimelineOwner != $oAlert->iSender) {
  60. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oTimelineOwner->getContentId());
  61. //--- Note. Timeline owner profile ID is used as alert sender and also a content (group) owner (author).
  62. $iSenderId = $iObjectAuthorId = $iTimelineOwner;
  63. bx_alert($this->_oModule->getName(), 'timeline_post_common', $aContentInfo[$CNF['FIELD_ID']], $iSenderId, array(
  64. 'object_author_id' => $iObjectAuthorId,
  65. 'timeline_post_id' => $oAlert->iObject,
  66. 'timeline_post_author_id' => $oAlert->iSender,
  67. 'content' => $aContentInfo,
  68. 'group_profile' => $iTimelineOwner,
  69. 'profile' => $oAlert->iSender,
  70. ));
  71. }
  72. }
  73. */
  74. if ($this->MODULE != $oAlert->sUnit)
  75. return;
  76. // timeline events to override permissions
  77. switch ($oAlert->sAction) {
  78. case 'timeline_view':
  79. $this->processTimelineView($oAlert, $oAlert->iObject);
  80. break;
  81. case 'timeline_comment':
  82. case 'timeline_report':
  83. case 'timeline_vote':
  84. case 'timeline_score':
  85. $this->processTimelineEventsBoolResult($oAlert, $oAlert->iObject);
  86. break;
  87. case 'timeline_post':
  88. $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject);
  89. break;
  90. case 'timeline_pin':
  91. case 'timeline_promote':
  92. case 'timeline_delete':
  93. $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject, 'checkAllowedEdit');
  94. break;
  95. case 'timeline_repost':
  96. $this->processTimelineRepost($oAlert, $oAlert->iObject);
  97. break;
  98. }
  99. }
  100. protected function sendMailFriendRequest ($oAlert)
  101. {
  102. $CNF = &$this->_oModule->_oConfig->CNF;
  103. if(empty($CNF['EMAIL_FRIEND_REQUEST']) || empty($CNF['URI_VIEW_FRIEND_REQUESTS']))
  104. return;
  105. $iRecipient = $oAlert->aExtras['content'];
  106. $oRecipient = BxDolProfile::getInstance($iRecipient);
  107. if($oRecipient->getModule() != $this->MODULE)
  108. return;
  109. $iSender = $oAlert->aExtras['initiator'];
  110. $oSender = BxDolProfile::getInstance($iSender);
  111. sendMailTemplate($CNF['EMAIL_FRIEND_REQUEST'], 0, $iRecipient, array(
  112. 'SenderUrl' => $oSender->getUrl(),
  113. 'SenderDisplayName' => $oSender->getDisplayName(),
  114. 'FriendsLink' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_FRIEND_REQUESTS'] . '&profile_id=' . $iRecipient),
  115. ), BX_EMAIL_NOTIFY);
  116. }
  117. protected function processTimelineView ($oAlert, $iGroupProfileId, $bDisableOwnerActions = false)
  118. {
  119. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  120. if (!$oGroupProfile)
  121. return;
  122. $bDisableOwnerActions = !BxDolService::call($oGroupProfile->getModule(), 'act_as_profile');
  123. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  124. if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedView($aContentInfo)) {
  125. $oAlert->aExtras['override_content'] = MsgBox(_t('_sys_access_denied_to_private_content'));
  126. }
  127. if ($bDisableOwnerActions && isset($oAlert->aExtras['menu'])) {
  128. foreach ($oAlert->aExtras['menu'] as $i => $r) {
  129. if ('timeline-view-owner' == $r['id'] || 'timeline-view-other' == $r['id'])
  130. unset($oAlert->aExtras['menu'][$i]);
  131. }
  132. }
  133. }
  134. protected function processTimelineEventsCheckResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  135. {
  136. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  137. if (!$oGroupProfile)
  138. return;
  139. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  140. if (CHECK_ACTION_RESULT_ALLOWED === ($s = $this->_oModule->$sFunc($aContentInfo))) {
  141. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  142. }
  143. else {
  144. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  145. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = $s;
  146. }
  147. }
  148. protected function processTimelineEventsBoolResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  149. {
  150. if (isAdmin() || !$oAlert->aExtras['result'])
  151. return;
  152. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  153. if (!$oGroupProfile)
  154. return;
  155. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  156. $oAlert->aExtras['result'] = (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->$sFunc($aContentInfo)) ? true : false;
  157. }
  158. protected function processTimelineRepost ($oAlert, $iGroupProfileId)
  159. {
  160. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  161. return;
  162. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  163. if (!$oGroupProfile)
  164. return;
  165. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  166. if (BX_DOL_PG_ALL == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]) {
  167. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  168. }
  169. else {
  170. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  171. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
  172. }
  173. }
  174. }
  175. /** @} */