1
0

BxBaseModProfileAlertsResponse.php 5.8 KB

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