BxBaseModProfileAlertsResponse.php 5.4 KB

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