403Webshell
Server IP : 85.214.143.32  /  Your IP : 216.73.216.33
Web Server : nginx/1.24.0
System : Linux datensicherung.webdress.site 6.8.0-142-generic #142-Ubuntu SMP PREEMPT_DYNAMIC Wed Sep 2 14:24:27 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/nextcloud/apps/activity/lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/nextcloud/apps/activity/lib/NotificationGenerator.php
<?php

declare(strict_types=1);
/**
 * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace OCA\Activity;

use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IManager as ActivityManager;
use OCP\IL10N;
use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\IManager as NotificationManager;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
use OCP\Notification\UnknownNotificationException;
use Psr\Log\LoggerInterface;

class NotificationGenerator implements INotifier {

	public function __construct(
		protected Data $data,
		protected ActivityManager $activityManager,
		protected NotificationManager $notificationManager,
		protected UserSettings $userSettings,
		protected IL10N $l10n,
		protected LoggerInterface $logger,
	) {
	}

	private function sanitizeUrl(string $url): string {
		if (str_starts_with($url, 'http://') || str_starts_with($url, 'https://')) {
			return $url;
		}

		return '';
	}

	public function deferNotifications(): bool {
		return $this->notificationManager->defer();
	}

	public function flushNotifications() {
		$this->notificationManager->flush();
	}

	public function sendNotificationForEvent(IEvent $event, int $activityId, ?bool $notificationSetting = null) {
		$selfAction = $event->getAffectedUser() === $event->getAuthor();
		$notifySetting = $notificationSetting ?? $this->userSettings->getUserSetting($event->getAffectedUser(), 'notification', $event->getType());

		if ($notifySetting && !$selfAction && $event->getGenerateNotification()) {
			$this->notificationManager->notify($this->getNotificationForEvent($event, $activityId));
		}
	}

	private function getNotificationForEvent(IEvent $event, int $activityId): INotification {
		$notification = $this->notificationManager->createNotification();
		$notification->setApp($event->getApp());
		$notification->setUser($event->getAffectedUser());
		$notification->setDateTime(\DateTime::createFromFormat('U', (string)$event->getTimestamp()));
		$notification->setObject('activity_notification', (string)$activityId);
		$notification->setSubject($event->getSubject(), $event->getSubjectParameters());

		if ($event->getRichSubject()) {
			$notification->setRichSubject($event->getRichSubject(), $event->getRichSubjectParameters());
		}

		if ($event->getRichMessage()) {
			$notification->setRichMessage($event->getRichMessage(), $event->getRichMessageParameters());
		}

		if ($event->getMessage()) {
			$notification->setMessage($event->getMessage(), $event->getMessageParameters());
		}

		$link = $event->getLink() ? $this->sanitizeUrl($event->getLink()) : '';
		if ($link !== '') {
			$notification->setLink($link);
		}

		return $notification;
	}

	private function populateEvent(IEvent $event, string $language) {
		$this->activityManager->setFormattingObject($event->getObjectType(), $event->getObjectId());
		foreach ($this->activityManager->getProviders() as $provider) {
			try {
				$event = $provider->parse($language, $event);
			} catch (UnknownActivityException) {
			} catch (\InvalidArgumentException $e) {
				// todo 39.0.0 Log as error
				$this->logger->warning(get_class($provider) . '::parse() threw \InvalidArgumentException which is deprecated. Throw \OCP\Activity\Exceptions\UnknownActivityException when the event is not known to your provider and otherwise handle all \InvalidArgumentException yourself.');
			}
		}
		$this->activityManager->setFormattingObject('', 0);

		return $event;
	}

	#[\Override]
	public function getID(): string {
		return 'activity';
	}

	#[\Override]
	public function getName(): string {
		return 'Activity';
	}

	#[\Override]
	public function prepare(INotification $notification, string $languageCode): INotification {
		if ($notification->getObjectType() !== 'activity_notification') {
			throw new UnknownNotificationException();
		}

		$event = $this->data->getById((int)$notification->getObjectId());
		if (!$event) {
			throw new AlreadyProcessedException();
		}
		if ($event->getAffectedUser() !== $notification->getUser()) {
			throw new AlreadyProcessedException();
		}
		$this->activityManager->setCurrentUserId($notification->getUser());
		$event = $this->populateEvent($event, $languageCode);
		$this->activityManager->setCurrentUserId(null);

		try {
			return $this->getDisplayNotificationForEvent($event, $event->getObjectId());
		} catch (\InvalidArgumentException $e) {
			$this->logger->error('Failed to format activity notification', ['exception' => $e]);
			throw new AlreadyProcessedException();
		}
	}

	private function getDisplayNotificationForEvent(IEvent $event, int $activityId): INotification {
		$notification = $this->getNotificationForEvent($event, $activityId);

		$notification->setRichSubject($event->getRichSubject(), $event->getRichSubjectParameters());
		$notification->setParsedSubject($event->getParsedSubject());

		$icon = $event->getIcon() ? $this->sanitizeUrl($event->getIcon()) : '';
		if ($icon !== '') {
			$notification->setIcon($icon);
		}

		if ($event->getRichMessage()) {
			$notification->setRichMessage($event->getRichMessage(), $event->getRichMessageParameters());
		}

		if ($event->getParsedMessage()) {
			$notification->setParsedMessage($event->getParsedMessage());
		}

		return $notification;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit