BxBaseModProfileAlertsResponse.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. /**
  27. * @hooks
  28. * @hookdef hook-bx_base_profile-profile_picture_deleted '{module_name}', 'profile_picture_deleted' - hook after profile picture was deleted
  29. * - $unit_name - module name
  30. * - $action - equals `profile_picture_deleted`
  31. * - $object_id - context id
  32. * - $sender_id - not used
  33. * - $extra_params - not used
  34. * @hook @ref hook-bx_base_profile-profile_picture_deleted
  35. */
  36. bx_alert($sModule, 'profile_picture_deleted', $oAlert->iObject);
  37. }
  38. if ($CNF['OBJECT_STORAGE_COVER'] == $oAlert->sUnit && 'file_deleted' == $oAlert->sAction && isset($CNF['FIELD_COVER'])) {
  39. $bResult = (int)$this->_oModule->_oDb->resetContentPictureByFileId($oAlert->iObject, $CNF['FIELD_COVER']) > 0;
  40. if($bResult)
  41. /**
  42. * @hooks
  43. * @hookdef hook-bx_base_profile-profile_cover_deleted '{module_name}', 'profile_cover_deleted' - hook after profile cover was deleted
  44. * - $unit_name - module name
  45. * - $action - equals `profile_cover_deleted`
  46. * - $object_id - context id
  47. * - $sender_id - not used
  48. * - $extra_params - not used
  49. * @hook @ref hook-bx_base_profile-profile_cover_deleted
  50. */
  51. bx_alert($sModule, 'profile_cover_deleted', $oAlert->iObject);
  52. }
  53. // connection events
  54. if ($oAlert->sUnit == 'sys_profiles_friends' && $oAlert->sAction == 'connection_added') {
  55. if((int)$oAlert->aExtras['mutual'] == 0 && !BxDolModuleQuery::getInstance()->isEnabledByName('bx_notifications'))
  56. $this->sendMailFriendRequest($oAlert);
  57. }
  58. /*
  59. * Re-translate timeline alert for timeline posts made by other profiles.
  60. * It's used with Notifications module in the following circumstances:
  61. * 1. User1 follow User2.
  62. * 2. User1 doesn't follow User3.
  63. * 3. User3 posts something on User2's timeline.
  64. * Result: User1 would be notifiend when the timeline of following profile (User2) was update by 3d party user.
  65. */
  66. /*
  67. * The code was commented because it looks like the Retranslation of
  68. * Timeline Common Post is redundant. It's happened after system of Contexts was created.
  69. *
  70. * TODO: If nothing happened, remove the code in UNA v.10.
  71. * Don't forget to:
  72. * 1. Stop listening 'bx_timeline' - 'post_common' alert.
  73. * 2. Remove BxBaseModProfileModule::serviceGetNotificationsTimelinePostCommon method
  74. * 3. Remove language keys from $CNF['T']['txt_ntfs_timeline_post_common']
  75. *
  76. if($oAlert->sUnit == 'bx_timeline' && $oAlert->sAction == 'post_common' && !empty($oAlert->aExtras['owner_id'])) {
  77. $iTimelineOwner = (int)$oAlert->aExtras['owner_id'];
  78. $oTimelineOwner = BxDolProfile::getInstance($iTimelineOwner);
  79. if($oTimelineOwner && $oTimelineOwner->getModule() == $this->_oModule->getName() && $iTimelineOwner != $oAlert->iSender) {
  80. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oTimelineOwner->getContentId());
  81. //--- Note. Timeline owner profile ID is used as alert sender and also a content (group) owner (author).
  82. $iSenderId = $iObjectAuthorId = $iTimelineOwner;
  83. bx_alert($this->_oModule->getName(), 'timeline_post_common', $aContentInfo[$CNF['FIELD_ID']], $iSenderId, array(
  84. 'object_author_id' => $iObjectAuthorId,
  85. 'timeline_post_id' => $oAlert->iObject,
  86. 'timeline_post_author_id' => $oAlert->iSender,
  87. 'content' => $aContentInfo,
  88. 'group_profile' => $iTimelineOwner,
  89. 'profile' => $oAlert->iSender,
  90. ));
  91. }
  92. }
  93. */
  94. if ($this->MODULE != $oAlert->sUnit)
  95. return;
  96. // timeline events to override permissions
  97. switch ($oAlert->sAction) {
  98. case 'timeline_view':
  99. $this->processTimelineView($oAlert, $oAlert->iObject);
  100. break;
  101. case 'timeline_report':
  102. $this->processTimelineEventsBoolResult($oAlert, $oAlert->iObject,'checkAllowedView');
  103. break;
  104. case 'timeline_comment':
  105. case 'timeline_vote':
  106. case 'timeline_score':
  107. $this->processTimelineEventsBoolResult($oAlert, $oAlert->iObject);
  108. break;
  109. case 'timeline_post':
  110. $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject);
  111. break;
  112. case 'timeline_pin':
  113. case 'timeline_delete':
  114. $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject, 'checkAllowedEdit');
  115. break;
  116. case 'timeline_repost':
  117. $this->processTimelineRepost($oAlert, $oAlert->iObject);
  118. break;
  119. }
  120. }
  121. protected function sendMailFriendRequest ($oAlert)
  122. {
  123. $CNF = &$this->_oModule->_oConfig->CNF;
  124. if(empty($CNF['EMAIL_FRIEND_REQUEST']) || empty($CNF['URI_VIEW_FRIEND_REQUESTS']))
  125. return;
  126. $iRecipient = $oAlert->aExtras['content'];
  127. $oRecipient = BxDolProfile::getInstance($iRecipient);
  128. if($oRecipient->getModule() != $this->MODULE)
  129. return;
  130. $iSender = $oAlert->aExtras['initiator'];
  131. $oSender = BxDolProfile::getInstance($iSender);
  132. sendMailTemplate($CNF['EMAIL_FRIEND_REQUEST'], 0, $iRecipient, array(
  133. 'SenderUrl' => $oSender->getUrl(),
  134. 'SenderDisplayName' => $oSender->getDisplayName(),
  135. 'FriendsLink' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_FRIEND_REQUESTS'] . '&profile_id=' . $iRecipient)),
  136. ), BX_EMAIL_NOTIFY);
  137. }
  138. protected function processTimelineView ($oAlert, $iGroupProfileId, $bDisableOwnerActions = false)
  139. {
  140. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  141. if (!$oGroupProfile)
  142. return;
  143. $bDisableOwnerActions = !BxDolService::call($oGroupProfile->getModule(), 'act_as_profile');
  144. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  145. if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedView($aContentInfo)) {
  146. $oAlert->aExtras['override_content'] = MsgBox(_t('_sys_access_denied_to_private_content'));
  147. }
  148. if ($bDisableOwnerActions && isset($oAlert->aExtras['menu'])) {
  149. foreach ($oAlert->aExtras['menu'] as $i => $r) {
  150. if ('timeline-view-owner' == $r['id'] || 'timeline-view-other' == $r['id'])
  151. unset($oAlert->aExtras['menu'][$i]);
  152. }
  153. }
  154. }
  155. protected function processTimelineEventsCheckResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  156. {
  157. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  158. if (!$oGroupProfile)
  159. return;
  160. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  161. if (CHECK_ACTION_RESULT_ALLOWED === ($s = $this->_oModule->$sFunc($aContentInfo))) {
  162. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  163. }
  164. else {
  165. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  166. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = $s;
  167. }
  168. }
  169. protected function processTimelineEventsBoolResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  170. {
  171. if (isAdmin() || !$oAlert->aExtras['result'])
  172. return;
  173. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  174. if (!$oGroupProfile)
  175. return;
  176. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  177. $oAlert->aExtras['result'] = (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->$sFunc($aContentInfo)) ? true : false;
  178. }
  179. protected function processTimelineRepost ($oAlert, $iGroupProfileId)
  180. {
  181. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  182. return;
  183. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  184. if (!$oGroupProfile)
  185. return;
  186. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  187. if (BX_DOL_PG_ALL == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]) {
  188. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  189. }
  190. else {
  191. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  192. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
  193. }
  194. }
  195. }
  196. /** @} */