| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup BaseProfile Base classes for profile modules
- * @ingroup UnaModules
- *
- * @{
- */
- class BxBaseModProfileAlertsResponse extends BxBaseModGeneralAlertsResponse
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function response($oAlert)
- {
- parent::response($oAlert);
- $CNF = $this->_oModule->_oConfig->CNF;
- $sModule = $this->_oModule->getName();
- // update picture field id when file is deleted
- if ($CNF['OBJECT_STORAGE'] == $oAlert->sUnit && 'file_deleted' == $oAlert->sAction && isset($CNF['FIELD_PICTURE'])) {
- $bResult = (int)$this->_oModule->_oDb->resetContentPictureByFileId($oAlert->iObject, $CNF['FIELD_PICTURE']) > 0;
- if($bResult)
- bx_alert($sModule, 'profile_picture_deleted', $oAlert->iObject);
- }
- if ($CNF['OBJECT_STORAGE_COVER'] == $oAlert->sUnit && 'file_deleted' == $oAlert->sAction && isset($CNF['FIELD_COVER'])) {
- $bResult = (int)$this->_oModule->_oDb->resetContentPictureByFileId($oAlert->iObject, $CNF['FIELD_COVER']) > 0;
- if($bResult)
- bx_alert($sModule, 'profile_cover_deleted', $oAlert->iObject);
- }
- // connection events
- if ($oAlert->sUnit == 'sys_profiles_friends' && $oAlert->sAction == 'connection_added') {
- if((int)$oAlert->aExtras['mutual'] == 0)
- $this->sendMailFriendRequest($oAlert);
- }
- /*
- * Re-translate timeline alert for timeline posts made by other profiles.
- * It's used with Notifications module in the following circumstances:
- * 1. User1 follow User2.
- * 2. User1 doesn't follow User3.
- * 3. User3 posts something on User2's timeline.
- * Result: User1 would be notifiend when the timeline of following profile (User2) was update by 3d party user.
- */
- if($oAlert->sUnit == 'bx_timeline' && $oAlert->sAction == 'post_common') {
- $oTimelineOwner = BxDolProfile::getInstance($oAlert->aExtras['object_author_id']);
- if($oTimelineOwner && $oTimelineOwner->getModule() == $this->_oModule->getName() && $oTimelineOwner->id() != $oAlert->iSender) {
- $aContentInfo = $this->_oModule->serviceGetContentInfoById($oTimelineOwner->getContentId());
- /*
- * Note. Timeline owner profile ID is used as alert sender and also a content (group) owner (author).
- */
- $iSenderId = $iObjectAuthorId = $oTimelineOwner->id();
- bx_alert($this->_oModule->getName(), 'timeline_post_common', $aContentInfo[$CNF['FIELD_ID']], $iSenderId, array(
- 'object_author_id' => $iObjectAuthorId,
- 'timeline_post_id' => $oAlert->iObject,
- 'timeline_post_author_id' => $oAlert->iSender,
- 'content' => $aContentInfo,
- 'group_profile' => $oTimelineOwner->id(),
- 'profile' => $oAlert->iSender,
- ));
- }
- }
- if ($this->MODULE != $oAlert->sUnit)
- return;
- // timeline events to override permissions
- switch ($oAlert->sAction) {
- case 'timeline_view':
- $this->processTimelineView($oAlert, $oAlert->iObject);
- break;
- case 'timeline_comment':
- case 'timeline_report':
- case 'timeline_vote':
- $this->processTimelineEventsBoolResult($oAlert, $oAlert->iObject);
- break;
- case 'timeline_post':
- $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject);
- break;
- case 'timeline_delete':
- $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject, 'checkAllowedEdit');
- break;
- case 'timeline_repost':
- $this->processTimelineRepost($oAlert, $oAlert->iObject);
- break;
- }
- }
- protected function sendMailFriendRequest ($oAlert)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if(empty($CNF['EMAIL_FRIEND_REQUEST']) || empty($CNF['URI_VIEW_FRIEND_REQUESTS']))
- return;
- $iRecipient = $oAlert->aExtras['content'];
- $oRecipient = BxDolProfile::getInstance($iRecipient);
- if($oRecipient->getModule() != $this->MODULE)
- return;
- $iSender = $oAlert->aExtras['initiator'];
- $oSender = BxDolProfile::getInstance($iSender);
- sendMailTemplate($CNF['EMAIL_FRIEND_REQUEST'], 0, $iRecipient, array(
- 'SenderUrl' => $oSender->getUrl(),
- 'SenderDisplayName' => $oSender->getDisplayName(),
- 'FriendsLink' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_FRIEND_REQUESTS'] . '&profile_id=' . $iRecipient),
- ), BX_EMAIL_NOTIFY);
- }
- protected function processTimelineView ($oAlert, $iGroupProfileId, $bDisableOwnerActions = false)
- {
- $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
- if (!$oGroupProfile)
- return;
- $bDisableOwnerActions = !BxDolService::call($oGroupProfile->getModule(), 'act_as_profile');
- $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
- if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedView($aContentInfo)) {
- $oAlert->aExtras['override_content'] = MsgBox(_t('_sys_access_denied_to_private_content'));
- }
- if ($bDisableOwnerActions && isset($oAlert->aExtras['menu'])) {
- foreach ($oAlert->aExtras['menu'] as $i => $r) {
- if ('timeline-view-owner' == $r['id'] || 'timeline-view-other' == $r['id'])
- unset($oAlert->aExtras['menu'][$i]);
- }
- }
- }
- protected function processTimelineEventsCheckResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
- {
- if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
- return;
- $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
- if (!$oGroupProfile)
- return;
- $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
- if (CHECK_ACTION_RESULT_ALLOWED === ($s = $this->_oModule->$sFunc($aContentInfo))) {
- $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
- }
- else {
- $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
- $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = $s;
- }
- }
- protected function processTimelineEventsBoolResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
- {
- if (isAdmin() || !$oAlert->aExtras['result'])
- return;
- $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
- if (!$oGroupProfile)
- return;
- $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
- $oAlert->aExtras['result'] = (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->$sFunc($aContentInfo)) ? true : false;
- }
- protected function processTimelineRepost ($oAlert, $iGroupProfileId)
- {
- if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
- return;
- $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
- if (!$oGroupProfile)
- return;
- $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
- if (BX_DOL_PG_ALL == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]) {
- $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
- }
- else {
- $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
- $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
- }
- }
- }
- /** @} */
|