BxBaseModProfileAlertsResponse.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup TridentModules
  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, true);
  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. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  62. if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedView($aContentInfo)) {
  63. $oAlert->aExtras['override_content'] = MsgBox(_t('_sys_access_denied_to_private_content'));
  64. }
  65. if ($bDisableOwnerActions) {
  66. foreach ($oAlert->aExtras['menu'] as $i => $r) {
  67. if ('timeline-view-owner' == $r['id'] || 'timeline-view-other' == $r['id'])
  68. unset($oAlert->aExtras['menu'][$i]);
  69. }
  70. }
  71. }
  72. protected function processTimelineEventsCheckResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  73. {
  74. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  75. return;
  76. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  77. if (!$oGroupProfile)
  78. return;
  79. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  80. if (CHECK_ACTION_RESULT_ALLOWED === ($s = $this->_oModule->$sFunc($aContentInfo))) {
  81. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  82. }
  83. else {
  84. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  85. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = $s;
  86. }
  87. }
  88. protected function processTimelineEventsBoolResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
  89. {
  90. if (isAdmin() || !$oAlert->aExtras['result'])
  91. return;
  92. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  93. if (!$oGroupProfile)
  94. return;
  95. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  96. $oAlert->aExtras['result'] = (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->$sFunc($aContentInfo)) ? true : false;
  97. }
  98. protected function processTimelineShare ($oAlert, $iGroupProfileId)
  99. {
  100. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  101. return;
  102. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  103. if (!$oGroupProfile)
  104. return;
  105. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  106. if (BX_DOL_PG_ALL == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]) {
  107. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  108. }
  109. else {
  110. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  111. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
  112. }
  113. }
  114. }
  115. /** @} */