BxBaseModProfileAlertsResponse.php 7.3 KB

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