403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/mail/lib/integration/im/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/mail/lib/integration/im/notification.php
<?php

namespace Bitrix\Mail\Integration\Im;

use Bitrix\Main;
use Bitrix\Main\Localization\Loc;
use \Bitrix\Main\Web\Uri;
use \Bitrix\Mail\Internals\MailboxAccessTable;
use \Bitrix\Mail\MailboxTable;

Loc::loadMessages(__FILE__);

class Notification
{
	const notifierSchemeTypeMail = 'new_message';
	const notifierSchemeTypeMailTariffRestrictions = 'tariff_restrictions';

	public static function getSchema()
	{
		Main\Loader::includeModule('im');

		return [
			'mail' => [
				'new_message' => [
					'NAME' => Loc::getMessage('MAIL_NOTIFY_NEW_MESSAGE'),
					'SITE' => 'Y',
					'SYSTEM' => 'Y',
					'MAIL' => 'N',
					'PUSH' => 'N',
					'DISABLED' => [
						IM_NOTIFY_FEATURE_PUSH,
						IM_NOTIFY_FEATURE_MAIL,
					],
				],
				'imposed_tariff_restrictions_on_the_mailbox' => [
					'NAME' => Loc::getMessage('MAIL_NOTIFY_IMPOSE_TARIFF_RESTRICTIONS_ON_THE_MAILBOX'),
					'SITE' => 'Y',
					'SYSTEM' => 'Y',
					'MAIL' => 'Y',
					'PUSH' => 'Y',
					'DISABLED' => [
						IM_NOTIFY_FEATURE_PUSH,
						IM_NOTIFY_FEATURE_MAIL,
						IM_NOTIFY_FEATURE_SITE,
					],
				],
			],
		];
	}

	private static function getNotifyMessageForNewMessageSetInMail($mailboxId, $messageCount, $absoluteUrl = false): string
	{
		$url = htmlspecialcharsbx(sprintf("/mail/list/%u", $mailboxId));

		if ($absoluteUrl)
		{
			$uri = new Uri($url);
			$url = $uri->toAbsolute()->getLocator();
		}

		return Loc::getMessage('MAIL_NOTIFY_NEW_MESSAGE_MULTI_1',
			[
				'#COUNT#' => $messageCount,
				'#VIEW_URL#' => $url,
			]
		);
	}

	private static function getNotifyMessageForNewMessageInMail($message, $absoluteUrl = false): string
	{
		$url = htmlspecialcharsbx($message['__href']);

		if ($absoluteUrl)
		{
			$uri = new Uri($url);
			$url = $uri->toAbsolute()->getLocator();
		}

		if ($message['SUBJECT'])
		{
			return Loc::getMessage('MAIL_NOTIFY_NEW_SINGLE_MESSAGE_IN_MAIL_CLIENT_1',
				[
					'#SUBJECT#' => $message['SUBJECT'],
					'#VIEW_URL#' => $url,
				]
			);
		}
		else
		{
			return Loc::getMessage('MAIL_NOTIFY_NEW_SINGLE_MESSAGE_IN_MAIL_CLIENT_EMPTY_SUBJECT',
				[
					'#VIEW_URL#' => $url,
				]
			);
		}
	}

	private static function getNotifyMessageForTariffRestrictionsMailbox($mailboxId, $email, $forEmailNotification = false): string
	{
		$url = htmlspecialcharsbx(sprintf("/mail/list/%u", $mailboxId));

		if ($forEmailNotification)
		{
			$uri = new Uri($url);
			$url = $uri->toAbsolute()->getLocator();

			$text = Loc::getMessage('MAIL_NOTIFY_FULL_MAILBOX_TARIFF_RESTRICTIONS_HAVE_BEEN_IMPOSED',
				[
					'#EMAIL#' => $email,
					'#VIEW_URL#' => $url,
				]
			);
		}
		else
		{
			$text = Loc::getMessage('MAIL_NOTIFY_MAILBOX_TARIFF_RESTRICTIONS_HAVE_BEEN_IMPOSED',
				[
					'#EMAIL#' => $email,
					'#VIEW_URL#' => $url,
				]
			);
		}

		return $text;
	}

	private static function notifyForNewMessagesInMail($userId, $fields): void
	{
		$message = $fields['message'];

		\CIMNotify::add([
			'MESSAGE_TYPE' => IM_MESSAGE_SYSTEM,
			'NOTIFY_TYPE' => IM_NOTIFY_SYSTEM,
			'NOTIFY_MODULE' => 'mail',
			'NOTIFY_EVENT' => self::notifierSchemeTypeMail,
			'NOTIFY_TITLE' => Loc::getMessage('MAIL_NOTIFY_NEW_MESSAGE_TITLE'),
			'NOTIFY_MESSAGE_OUT' => empty($message)
				? self::getNotifyMessageForNewMessageSetInMail($fields['mailboxId'], $fields['count'], true)
				: self::getNotifyMessageForNewMessageInMail($message, true),
			'NOTIFY_MESSAGE' => empty($message)
				? self::getNotifyMessageForNewMessageSetInMail($fields['mailboxId'], $fields['count'])
				: self::getNotifyMessageForNewMessageInMail($message),
			'TO_USER_ID' => $userId,
		]);
	}

	private static function notifyForTariffRestrictions($mailboxId): void
	{
		$mailbox = MailboxTable::getList([
			'select' => [
				'USER_ID',
				'EMAIL'
			],
			'filter' => [
				'=ID' => $mailboxId,
			],
			'limit' => 1,
		])->fetch();

		if (isset($mailbox['USER_ID']) && isset($mailbox['EMAIL']))
		{
			\CIMNotify::add([
				'MESSAGE_TYPE' => IM_MESSAGE_SYSTEM,
				'NOTIFY_TYPE' => IM_NOTIFY_SYSTEM,
				'NOTIFY_MODULE' => 'mail',
				'NOTIFY_EVENT' => self::notifierSchemeTypeMailTariffRestrictions,
				'NOTIFY_TITLE' => Loc::getMessage('MAIL_NOTIFY_NEW_MESSAGE_TITLE'),
				'NOTIFY_MESSAGE_OUT' => self::getNotifyMessageForTariffRestrictionsMailbox($mailboxId, $mailbox['EMAIL'], true),
				'NOTIFY_MESSAGE' => self::getNotifyMessageForTariffRestrictionsMailbox($mailboxId, $mailbox['EMAIL']),
				'TO_USER_ID' => $mailbox['USER_ID'],
			]);
		}
	}

	public static function add($userId, $type, $fields, $mailboxId = null)
	{
		if (Main\Loader::includeModule('im'))
		{
			if ($type == 'new_message')
			{
				$mailboxId = $fields['mailboxId'];

				$userIds = [];

				$mailboxOwnerId = (int)$fields['mailboxOwnerId'] ?? 0;

				if ($mailboxOwnerId)
				{
					$userIds = MailboxAccessTable::getUserIdsWithAccessToTheMailbox($mailboxId);
				}
				else
				{
					$userIds[] = $userId;
				}

				foreach ($userIds as $id)
				{
					self::notifyForNewMessagesInMail($id, $fields);
				}
			}
			else if ($type == 'imposed_tariff_restrictions_on_the_mailbox')
			{
				self::notifyForTariffRestrictions($mailboxId);
			}
		}
	}

}

Youez - 2016 - github.com/yon3zu
LinuXploit