BxBaseModProfileAlertsResponse.php 7.0 KB

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