diff --git a/main/inc/lib/AnnouncementEmail.php b/main/inc/lib/AnnouncementEmail.php index 0f745c7161..056d2823e3 100644 --- a/main/inc/lib/AnnouncementEmail.php +++ b/main/inc/lib/AnnouncementEmail.php @@ -212,7 +212,7 @@ class AnnouncementEmail * Email message. * * @param int $receiverUserId - * @param bool $checkUrls + * @param bool $checkUrls It checks access url of user when multiple_access_urls = true * * @return string */ @@ -323,7 +323,7 @@ class AnnouncementEmail * @param bool $sendToDrhUsers send a copy of the message to the DRH users * @param int $senderId related to the main user * @param bool $directMessage - * @param bool $checkUrls + * @param bool $checkUrls It checks access url of user when multiple_access_urls = true * * @return array */ @@ -360,7 +360,11 @@ class AnnouncementEmail $message, $senderId, $sendToDrhUsers, - true + true, + [], + true, + [], + $checkUrls ); } else { if (!empty($this->logger)) { @@ -397,7 +401,11 @@ class AnnouncementEmail $message, $senderId, false, - true + true, + [], + true, + [], + $checkUrls ); } } diff --git a/main/inc/lib/AnnouncementManager.php b/main/inc/lib/AnnouncementManager.php index 1df6baea2f..360e80cf0a 100755 --- a/main/inc/lib/AnnouncementManager.php +++ b/main/inc/lib/AnnouncementManager.php @@ -1536,7 +1536,7 @@ class AnnouncementManager * @param Monolog\Handler\HandlerInterface logger * @param int $senderId * @param bool $directMessage - * @param bool $checkUrls + * @param bool $checkUrls It checks access url of user when multiple_access_urls = true * * @return array */ diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index 2a136969f7..90538e7918 100755 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -514,6 +514,7 @@ class MessageManager * @param bool $checkCurrentAudioId * @param bool $forceTitleWhenSendingEmail force the use of $title as subject instead of "You have a new message" * @param int $status Message status + * @param bool $checkUrls It checks access url of user when multiple_access_urls = true * * @return bool */ @@ -534,7 +535,8 @@ class MessageManager $checkCurrentAudioId = false, $forceTitleWhenSendingEmail = false, $status = 0, - array $extraParams = [] + array $extraParams = [], + $checkUrls = false ) { $group_id = (int) $group_id; $receiverUserId = (int) $receiverUserId; @@ -802,7 +804,8 @@ class MessageManager $sender_info, $attachmentAddedByMail, $smsParameters, - $forceTitleWhenSendingEmail + $forceTitleWhenSendingEmail, + $checkUrls ); } else { $usergroup = new UserGroup(); @@ -836,7 +839,9 @@ class MessageManager $content, $group_info, $attachmentAddedByMail, - $smsParameters + $smsParameters, + false, + $checkUrls ); } } @@ -857,6 +862,7 @@ class MessageManager * @param array $smsParameters * @param bool $uploadFiles Do not upload files using the MessageManager class * @param array $attachmentList + * @param bool $checkUrls It checks access url of user when multiple_access_urls = true * * @return bool */ @@ -869,7 +875,8 @@ class MessageManager $directMessage = false, $smsParameters = [], $uploadFiles = true, - $attachmentList = [] + $attachmentList = [], + $checkUrls = false ) { $files = $_FILES ? $_FILES : []; if (false === $uploadFiles) { @@ -892,7 +899,11 @@ class MessageManager $sender_id, $directMessage, 0, - $smsParameters + $smsParameters, + false, + 0, + [], + $checkUrls ); if ($sendCopyToDrhUsers) { @@ -911,7 +922,11 @@ class MessageManager $message, $sender_id, false, - $directMessage + $directMessage, + [], + true, + [], + $checkUrls ); } } diff --git a/main/inc/lib/notification.lib.php b/main/inc/lib/notification.lib.php index 23a37421d2..554cbb3c18 100644 --- a/main/inc/lib/notification.lib.php +++ b/main/inc/lib/notification.lib.php @@ -239,6 +239,7 @@ class Notification extends Model * @param array $attachments * @param array $smsParameters * @param bool $forceTitleWhenSendingEmail force the use of $title as subject instead of "You have a new message" + * @param bool $checkUrls It checks access url of user when multiple_access_urls = true */ public function saveNotification( $messageId, @@ -249,11 +250,12 @@ class Notification extends Model $senderInfo = [], $attachments = [], $smsParameters = [], - $forceTitleWhenSendingEmail = false + $forceTitleWhenSendingEmail = false, + $checkUrls = false ) { $this->type = (int) $type; $messageId = (int) $messageId; - $content = $this->formatContent($messageId, $content, $senderInfo); + $content = $this->formatContent($messageId, $content, $senderInfo, $checkUrls); $titleToNotification = $this->formatTitle($title, $senderInfo, $forceTitleWhenSendingEmail); $settingToCheck = ''; $avoid_my_self = false; @@ -370,11 +372,16 @@ class Notification extends Model * @param string $content * @param array $senderInfo result of api_get_user_info() or * GroupPortalManager:get_group_data() + * @param bool $checkUrls It checks access url of user when multiple_access_urls = true * * @return string * */ - public function formatContent($messageId, $content, $senderInfo) - { + public function formatContent( + $messageId, + $content, + $senderInfo, + $checkUrls = false + ) { $hook = HookNotificationContent::create(); if (!empty($hook)) { $hook->setEventData(['content' => $content]); @@ -384,6 +391,18 @@ class Notification extends Model } } + $accessConfig = []; + $useMultipleUrl = api_get_configuration_value('multiple_access_urls'); + if ($useMultipleUrl && $checkUrls) { + $accessUrls = api_get_access_url_from_user($senderInfo['user_info']['user_id']); + if (!empty($accessUrls)) { + $accessConfig['multiple_access_urls'] = true; + $accessConfig['access_url'] = (int) $accessUrls[0]; + } + // To replace the current url by access url user + $content = str_replace(api_get_path(WEB_PATH), api_get_path(WEB_PATH, $accessConfig), $content); + } + $newMessageText = $linkToNewMessage = ''; $showEmail = api_get_configuration_value('show_user_email_in_notification'); $senderInfoName = ''; @@ -399,7 +418,7 @@ class Notification extends Model $newMessageText = ''; $linkToNewMessage = Display::url( get_lang('SeeMessage'), - api_get_path(WEB_CODE_PATH).'messages/view_message.php?id='.$messageId + api_get_path(WEB_CODE_PATH, $accessConfig).'messages/view_message.php?id='.$messageId ); break; case self::NOTIFICATION_TYPE_MESSAGE: @@ -415,7 +434,7 @@ class Notification extends Model } $linkToNewMessage = Display::url( get_lang('SeeMessage'), - api_get_path(WEB_CODE_PATH).'messages/view_message.php?id='.$messageId + api_get_path(WEB_CODE_PATH, $accessConfig).'messages/view_message.php?id='.$messageId ); break; case self::NOTIFICATION_TYPE_INVITATION: @@ -427,7 +446,7 @@ class Notification extends Model } $linkToNewMessage = Display::url( get_lang('SeeInvitation'), - api_get_path(WEB_CODE_PATH).'social/invitations.php' + api_get_path(WEB_CODE_PATH, $accessConfig).'social/invitations.php' ); break; case self::NOTIFICATION_TYPE_GROUP: @@ -437,15 +456,15 @@ class Notification extends Model $newMessageText = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $senderName); $senderName = Display::url( $senderInfoName, - api_get_path(WEB_CODE_PATH).'social/profile.php?'.$senderInfo['user_info']['user_id'] + api_get_path(WEB_CODE_PATH, $accessConfig).'social/profile.php?'.$senderInfo['user_info']['user_id'] ); $newMessageText .= '
'.get_lang('User').': '.$senderName; } - $groupUrl = api_get_path(WEB_CODE_PATH).'social/group_topics.php?id='.$senderInfo['group_info']['id'].'&topic_id='.$senderInfo['group_info']['topic_id'].'&msg_id='.$senderInfo['group_info']['msg_id'].'&topics_page_nr='.$topicPage; + $groupUrl = api_get_path(WEB_CODE_PATH, $accessConfig).'social/group_topics.php?id='.$senderInfo['group_info']['id'].'&topic_id='.$senderInfo['group_info']['topic_id'].'&msg_id='.$senderInfo['group_info']['msg_id'].'&topics_page_nr='.$topicPage; $linkToNewMessage = Display::url(get_lang('SeeMessage'), $groupUrl); break; } - $preferenceUrl = api_get_path(WEB_CODE_PATH).'auth/profile.php'; + $preferenceUrl = api_get_path(WEB_CODE_PATH, $accessConfig).'auth/profile.php'; // You have received a new message text if (!empty($newMessageText)) {