BxBaseModProfileAlertsResponse.php 11 KB

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