BxBaseModProfileAlertsResponse.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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_report':
  82. $this->processTimelineEventsBoolResult($oAlert, $oAlert->iObject,'checkAllowedView');
  83. break;
  84. case 'timeline_comment':
  85. case 'timeline_vote':
  86. case 'timeline_score':
  87. $this->processTimelineEventsBoolResult($oAlert, $oAlert->iObject);
  88. break;
  89. case 'timeline_post':
  90. $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject);
  91. break;
  92. case 'timeline_pin':
  93. case 'timeline_delete':
  94. $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject, 'checkAllowedEdit');
  95. break;
  96. case 'timeline_repost':
  97. $this->processTimelineRepost($oAlert, $oAlert->iObject);
  98. break;
  99. }
  100. }
  101. protected function sendMailFriendRequest ($oAlert)
  102. {
  103. $CNF = &$this->_oModule->_oConfig->CNF;
  104. if(empty($CNF['EMAIL_FRIEND_REQUEST']) || empty($CNF['URI_VIEW_FRIEND_REQUESTS']))
  105. return;
  106. $iRecipient = $oAlert->aExtras['content'];
  107. $oRecipient = BxDolProfile::getInstance($iRecipient);
  108. if($oRecipient->getModule() != $this->MODULE)
  109. return;
  110. $iSender = $oAlert->aExtras['initiator'];
  111. $oSender = BxDolProfile::getInstance($iSender);
  112. sendMailTemplate($CNF['EMAIL_FRIEND_REQUEST'], 0, $iRecipient, array(
  113. 'SenderUrl' => $oSender->getUrl(),
  114. 'SenderDisplayName' => $oSender->getDisplayName(),
  115. 'FriendsLink' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_FRIEND_REQUESTS'] . '&profile_id=' . $iRecipient),
  116. ), BX_EMAIL_NOTIFY);
  117. }
  118. protected function processTimelineView ($oAlert, $iGroupProfileId, $bDisableOwnerActions = false)
  119. {
  120. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  121. if (!$oGroupProfile)
  122. return;
  123. $bDisableOwnerActions = !BxDolService::call($oGroupProfile->getModule(), 'act_as_profile');
  124. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  125. if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedView($aContentInfo)) {
  126. $oAlert->aExtras['override_content'] = MsgBox(_t('_sys_access_denied_to_private_content'));
  127. }
  128. if ($bDisableOwnerActions && isset($oAlert->aExtras['menu'])) {
  129. foreach ($oAlert->aExtras['menu'] as $i => $r) {
  130. if ('timeline-view-owner' == $r['id'] || 'timeline-view-other' == $r['id'])
  131. unset($oAlert->aExtras['menu'][$i]);
  132. }
  133. }
  134. }
  135. protected function processTimelineEventsCheckResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  136. {
  137. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  138. if (!$oGroupProfile)
  139. return;
  140. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  141. if (CHECK_ACTION_RESULT_ALLOWED === ($s = $this->_oModule->$sFunc($aContentInfo))) {
  142. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  143. }
  144. else {
  145. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  146. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = $s;
  147. }
  148. }
  149. protected function processTimelineEventsBoolResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  150. {
  151. if (isAdmin() || !$oAlert->aExtras['result'])
  152. return;
  153. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  154. if (!$oGroupProfile)
  155. return;
  156. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  157. $oAlert->aExtras['result'] = (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->$sFunc($aContentInfo)) ? true : false;
  158. }
  159. protected function processTimelineRepost ($oAlert, $iGroupProfileId)
  160. {
  161. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  162. return;
  163. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  164. if (!$oGroupProfile)
  165. return;
  166. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  167. if (BX_DOL_PG_ALL == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]) {
  168. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  169. }
  170. else {
  171. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  172. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
  173. }
  174. }
  175. }
  176. /** @} */