]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Notifications/Notifications.php
Allow the search for contacts on blocked servers via web
[friendica.git] / src / Module / Notifications / Notifications.php
index eef4af9bc42d57d980ea8ef47aea7ae831aa8e98..7852f81c2430e613ebb9cba837cf1e5ddd04ff59 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 namespace Friendica\Module\Notifications;
 
+use Friendica\App;
+use Friendica\App\Arguments;
 use Friendica\Content\Nav;
+use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
-use Friendica\DI;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
 use Friendica\Module\BaseNotifications;
-use Friendica\Navigation\Notifications\Collection\FormattedNotifications;
-use Friendica\Navigation\Notifications\ValueObject\FormattedNotification;
-use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Module\Response;
+use Friendica\Navigation\Notifications\ValueObject\FormattedNotify;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 /**
  * Prints all notification types except introduction:
@@ -38,42 +42,52 @@ use Friendica\Network\HTTPException\InternalServerErrorException;
  */
 class Notifications extends BaseNotifications
 {
+       /** @var \Friendica\Navigation\Notifications\Factory\FormattedNotify */
+       protected $formattedNotifyFactory;
+
+       public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, \Friendica\Navigation\Notifications\Factory\FormattedNotify $formattedNotifyFactory, IHandleUserSessions $userSession, array $server, array $parameters = [])
+       {
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $userSession, $server, $parameters);
+
+               $this->formattedNotifyFactory = $formattedNotifyFactory;
+       }
+
        /**
         * {@inheritDoc}
         */
-       public static function getNotifications()
+       public function getNotifications()
        {
                $notificationHeader = '';
                $notifications = [];
 
-               $factory = DI::formattedNotificationFactory();
+               $factory = $this->formattedNotifyFactory;
 
-               if ((DI::args()->get(1) == 'network')) {
-                       $notificationHeader = DI::l10n()->t('Network Notifications');
+               if (($this->args->get(1) == 'network')) {
+                       $notificationHeader = $this->t('Network Notifications');
                        $notifications      = [
-                               'ident'        => FormattedNotification::NETWORK,
-                               'notifications' => $factory->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
+                               'ident'        => FormattedNotify::NETWORK,
+                               'notifications' => $factory->getNetworkList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
                        ];
-               } elseif ((DI::args()->get(1) == 'system')) {
-                       $notificationHeader = DI::l10n()->t('System Notifications');
+               } elseif (($this->args->get(1) == 'system')) {
+                       $notificationHeader = $this->t('System Notifications');
                        $notifications      = [
-                               'ident'        => FormattedNotification::SYSTEM,
-                               'notifications' => $factory->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
+                               'ident'        => FormattedNotify::SYSTEM,
+                               'notifications' => $factory->getSystemList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
                        ];
-               } elseif ((DI::args()->get(1) == 'personal')) {
-                       $notificationHeader = DI::l10n()->t('Personal Notifications');
+               } elseif (($this->args->get(1) == 'personal')) {
+                       $notificationHeader = $this->t('Personal Notifications');
                        $notifications      = [
-                               'ident'        => FormattedNotification::PERSONAL,
-                               'notifications' => $factory->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
+                               'ident'        => FormattedNotify::PERSONAL,
+                               'notifications' => $factory->getPersonalList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
                        ];
-               } elseif ((DI::args()->get(1) == 'home')) {
-                       $notificationHeader = DI::l10n()->t('Home Notifications');
+               } elseif (($this->args->get(1) == 'home')) {
+                       $notificationHeader = $this->t('Home Notifications');
                        $notifications      = [
-                               'ident'        => FormattedNotification::HOME,
-                               'notifications' => $factory->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
+                               'ident'        => FormattedNotify::HOME,
+                               'notifications' => $factory->getHomeList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
                        ];
                } else {
-                       DI::baseUrl()->redirect('notifications');
+                       $this->baseUrl->redirect('notifications');
                }
 
                return [
@@ -82,14 +96,14 @@ class Notifications extends BaseNotifications
                ];
        }
 
-       public function content(): string
+       protected function content(array $request = []): string
        {
                Nav::setSelected('notifications');
 
                $notificationContent   = [];
                $notificationNoContent = '';
 
-               $notificationResult = self::getNotifications();
+               $notificationResult = $this->getNotifications();
                $notifications      = $notificationResult['notifications'] ?? [];
                $notificationHeader = $notificationResult['header'] ?? '';
 
@@ -107,7 +121,7 @@ class Notifications extends BaseNotifications
                        ];
                        // Loop trough ever notification This creates an array with the output html for each
                        // notification and apply the correct template according to the notificationtype (label).
-                       /** @var FormattedNotification $Notification */
+                       /** @var FormattedNotify $Notification */
                        foreach ($notifications['notifications'] as $Notification) {
                                $notificationArray = $Notification->toArray();
 
@@ -118,14 +132,14 @@ class Notifications extends BaseNotifications
                                ]);
                        }
                } else {
-                       $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notificationResult['ident']);
+                       $notificationNoContent = $this->t('No more %s notifications.', $notificationResult['ident']);
                }
 
                $notificationShowLink = [
-                       'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
-                       'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
+                       'href' => ($this->showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
+                       'text' => ($this->showAll ? $this->t('Show unread') : $this->t('Show all')),
                ];
 
-               return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
+               return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
        }
 }