1
0

BxBaseModProfileAlertsResponse.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. // re-translate timeline alert for timeline in this module for posts made by other profiles
  39. if ('bx_timeline' == $oAlert->sUnit && 'post_common' == $oAlert->sAction && ($oGroupProfile = BxDolProfile::getInstance($oAlert->aExtras['object_author_id'])) && $oGroupProfile->getModule() == $this->_oModule->getName() && $oGroupProfile->id() != $oAlert->iSender) {
  40. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  41. /*
  42. * Note. Group Profile ID is used as alert sender and also a content (group) owner (author).
  43. */
  44. $iSenderId = $iObjectAuthorId = $oGroupProfile->id();
  45. bx_alert($this->_oModule->getName(), 'timeline_post_common', $aContentInfo[$CNF['FIELD_ID']], $iSenderId, array(
  46. 'object_author_id' => $iObjectAuthorId,
  47. 'timeline_post_id' => $oAlert->iObject,
  48. 'timeline_post_author_id' => $oAlert->iSender,
  49. 'content' => $aContentInfo,
  50. 'group_profile' => $oGroupProfile->id(),
  51. 'profile' => $oAlert->iSender,
  52. ));
  53. }
  54. if ($this->MODULE != $oAlert->sUnit)
  55. return;
  56. // timeline events to override permissions
  57. switch ($oAlert->sAction) {
  58. case 'timeline_view':
  59. $this->processTimelineView($oAlert, $oAlert->iObject);
  60. break;
  61. case 'timeline_comment':
  62. case 'timeline_report':
  63. case 'timeline_vote':
  64. $this->processTimelineEventsBoolResult($oAlert, $oAlert->iObject);
  65. break;
  66. case 'timeline_post':
  67. $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject);
  68. break;
  69. case 'timeline_delete':
  70. $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject, 'checkAllowedEdit');
  71. break;
  72. case 'timeline_share':
  73. $this->processTimelineShare($oAlert, $oAlert->iObject);
  74. break;
  75. }
  76. }
  77. protected function sendMailFriendRequest ($oAlert)
  78. {
  79. $CNF = &$this->_oModule->_oConfig->CNF;
  80. if(empty($CNF['EMAIL_FRIEND_REQUEST']) || empty($CNF['URI_VIEW_FRIEND_REQUESTS']))
  81. return;
  82. $iRecipient = $oAlert->aExtras['content'];
  83. $oRecipient = BxDolProfile::getInstance($iRecipient);
  84. if($oRecipient->getModule() != $this->MODULE)
  85. return;
  86. $iSender = $oAlert->aExtras['initiator'];
  87. $oSender = BxDolProfile::getInstance($iSender);
  88. sendMailTemplate($CNF['EMAIL_FRIEND_REQUEST'], 0, $iRecipient, array(
  89. 'SenderUrl' => $oSender->getUrl(),
  90. 'SenderDisplayName' => $oSender->getDisplayName(),
  91. 'FriendsLink' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_FRIEND_REQUESTS'] . '&profile_id=' . $iRecipient),
  92. ), BX_EMAIL_NOTIFY);
  93. }
  94. protected function processTimelineView ($oAlert, $iGroupProfileId, $bDisableOwnerActions = false)
  95. {
  96. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  97. if (!$oGroupProfile)
  98. return;
  99. $bDisableOwnerActions = !BxDolService::call($oGroupProfile->getModule(), 'act_as_profile');
  100. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  101. if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedView($aContentInfo)) {
  102. $oAlert->aExtras['override_content'] = MsgBox(_t('_sys_access_denied_to_private_content'));
  103. }
  104. if ($bDisableOwnerActions && isset($oAlert->aExtras['menu'])) {
  105. foreach ($oAlert->aExtras['menu'] as $i => $r) {
  106. if ('timeline-view-owner' == $r['id'] || 'timeline-view-other' == $r['id'])
  107. unset($oAlert->aExtras['menu'][$i]);
  108. }
  109. }
  110. }
  111. protected function processTimelineEventsCheckResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  112. {
  113. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  114. return;
  115. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  116. if (!$oGroupProfile)
  117. return;
  118. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  119. if (CHECK_ACTION_RESULT_ALLOWED === ($s = $this->_oModule->$sFunc($aContentInfo))) {
  120. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  121. }
  122. else {
  123. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  124. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = $s;
  125. }
  126. }
  127. protected function processTimelineEventsBoolResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  128. {
  129. if (isAdmin() || !$oAlert->aExtras['result'])
  130. return;
  131. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  132. if (!$oGroupProfile)
  133. return;
  134. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  135. $oAlert->aExtras['result'] = (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->$sFunc($aContentInfo)) ? true : false;
  136. }
  137. protected function processTimelineShare ($oAlert, $iGroupProfileId)
  138. {
  139. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  140. return;
  141. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  142. if (!$oGroupProfile)
  143. return;
  144. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  145. if (BX_DOL_PG_ALL == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]) {
  146. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  147. }
  148. else {
  149. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  150. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
  151. }
  152. }
  153. }
  154. /** @} */