BxBaseModProfileAlertsResponse.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. // re-translate timeline alert for timeline in this module for posts made by other profiles
  29. 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) {
  30. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  31. 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']]));
  32. }
  33. if ($this->MODULE != $oAlert->sUnit)
  34. return;
  35. // timeline events to override permissions
  36. switch ($oAlert->sAction) {
  37. case 'timeline_view':
  38. $this->processTimelineView($oAlert, $oAlert->iObject);
  39. break;
  40. case 'timeline_comment':
  41. case 'timeline_report':
  42. case 'timeline_vote':
  43. $this->processTimelineEventsBoolResult($oAlert, $oAlert->iObject);
  44. break;
  45. case 'timeline_post':
  46. $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject);
  47. break;
  48. case 'timeline_delete':
  49. $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject, 'checkAllowedEdit');
  50. break;
  51. case 'timeline_share':
  52. $this->processTimelineShare($oAlert, $oAlert->iObject);
  53. break;
  54. }
  55. }
  56. protected function processTimelineView ($oAlert, $iGroupProfileId, $bDisableOwnerActions = false)
  57. {
  58. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  59. if (!$oGroupProfile)
  60. return;
  61. $bDisableOwnerActions = !BxDolService::call($oGroupProfile->getModule(), 'act_as_profile');
  62. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  63. if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedView($aContentInfo)) {
  64. $oAlert->aExtras['override_content'] = MsgBox(_t('_sys_access_denied_to_private_content'));
  65. }
  66. if ($bDisableOwnerActions) {
  67. foreach ($oAlert->aExtras['menu'] as $i => $r) {
  68. if ('timeline-view-owner' == $r['id'] || 'timeline-view-other' == $r['id'])
  69. unset($oAlert->aExtras['menu'][$i]);
  70. }
  71. }
  72. }
  73. protected function processTimelineEventsCheckResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  74. {
  75. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  76. return;
  77. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  78. if (!$oGroupProfile)
  79. return;
  80. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  81. if (CHECK_ACTION_RESULT_ALLOWED === ($s = $this->_oModule->$sFunc($aContentInfo))) {
  82. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  83. }
  84. else {
  85. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  86. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = $s;
  87. }
  88. }
  89. protected function processTimelineEventsBoolResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  90. {
  91. if (isAdmin() || !$oAlert->aExtras['result'])
  92. return;
  93. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  94. if (!$oGroupProfile)
  95. return;
  96. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  97. $oAlert->aExtras['result'] = (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->$sFunc($aContentInfo)) ? true : false;
  98. }
  99. protected function processTimelineShare ($oAlert, $iGroupProfileId)
  100. {
  101. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  102. return;
  103. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  104. if (!$oGroupProfile)
  105. return;
  106. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  107. if (BX_DOL_PG_ALL == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]) {
  108. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  109. }
  110. else {
  111. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  112. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
  113. }
  114. }
  115. }
  116. /** @} */