3 namespace Friendica\Module;
6 use Friendica\BaseModule;
7 use Friendica\Content\Pager;
8 use Friendica\Core\Renderer;
9 use Friendica\Core\System;
11 use Friendica\Model\Notify;
12 use Friendica\Network\HTTPException\ForbiddenException;
14 abstract class BaseNotifications extends BaseModule
16 /** @var array Array of URL parameters */
18 Notify::NETWORK => 'network',
19 Notify::SYSTEM => 'system',
20 Notify::HOME => 'home',
21 Notify::PERSONAL => 'personal',
22 Notify::INTRO => 'intros',
25 /** @var array Array of the allowed notifies and their printable name */
27 Notify::NETWORK => 'Network',
28 Notify::SYSTEM => 'System',
29 Notify::HOME => 'Home',
30 Notify::PERSONAL => 'Personal',
31 Notify::INTRO => 'Introductions',
34 /** @var array The array of access keys for notify pages */
36 Notify::NETWORK => 'w',
37 Notify::SYSTEM => 'y',
39 Notify::PERSONAL => 'r',
45 protected static $show;
46 protected static $start;
49 * Collects all notifies from the backend
51 * @return array The determined notification array
52 * ['header', 'notifs']
54 abstract public static function getNotifies();
56 public static function init(array $parameters = [])
59 throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
62 $page = ($_REQUEST['page'] ?? 0) ?: 1;
64 self::$start = ($page * self::PER_PAGE) - self::PER_PAGE;
65 self::$show = ($_REQUEST['show'] ?? '') === 'all';
68 public static function post(array $parameters = [])
70 $request_id = DI::args()->get(1);
72 if ($request_id === 'all') {
77 $intro = DI::intro()->selectFirst(['id' => $request_id, 'uid' => local_user()]);
79 switch ($_POST['submit']) {
80 case DI::l10n()->t('Discard'):
83 case DI::l10n()->t('Ignore'):
88 DI::baseUrl()->redirect('notifications/intros');
92 public static function rawContent(array $parameters = [])
94 // If the last argument of the query is NOT json, return
95 if (DI::args()->get(DI::args()->getArgc() - 1) !== 'json') {
99 System::jsonExit(static::getNotifies()['notifs'] ?? []);
102 public static function printContent(string $notif_header, array $notif_content, string $notif_nocontent, array $notif_show_lnk)
104 // Get the nav tabs for the notification pages
105 $tabs = self::getTabs();
108 $pager = new Pager(DI::args()->getQueryString(), self::PER_PAGE);
110 $notif_tpl = Renderer::getMarkupTemplate('notifications.tpl');
111 return Renderer::replaceMacros($notif_tpl, [
112 '$notif_header' => $notif_header ?? DI::l10n()->t('Notifications'),
114 '$notif_content' => $notif_content,
115 '$notif_nocontent' => $notif_nocontent,
116 '$notif_show_lnk' => $notif_show_lnk,
117 '$notif_paginate' => $pager->renderMinimal(count($notif_content))
122 * List of pages for the Notifications TabBar
124 * @return array with with notifications TabBar data
127 private static function getTabs()
129 $selected = DI::args()->get(1, '');
133 foreach (self::URL_TYPES as $type => $url) {
135 'label' => DI::l10n()->t(self::PRINT_TYPES[$type]),
136 'url' => 'notifications/' . $url,
137 'sel' => (($selected == $url) ? 'active' : ''),
138 'id' => $type . '-tab',
139 'accesskey' => self::ACCESS_KEYS[$type],