BxBaseModProfileAlertsResponse.php 5.2 KB

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