From fa6c33d3ac7d3d8f8bd2cdfc341217cd88a6a557 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Wed, 22 Jan 2020 23:18:14 +0100 Subject: [PATCH 01/10] Move mod/notifications to Module\Notification --- mod/notifications.php | 375 --------------------- src/Module/BaseNotifications.php | 145 ++++++++ src/Module/Notifications/Introductions.php | 191 +++++++++++ src/Module/Notifications/Notifications.php | 111 ++++++ static/routes.config.php | 9 + 5 files changed, 456 insertions(+), 375 deletions(-) delete mode 100644 mod/notifications.php create mode 100644 src/Module/BaseNotifications.php create mode 100644 src/Module/Notifications/Introductions.php create mode 100644 src/Module/Notifications/Notifications.php diff --git a/mod/notifications.php b/mod/notifications.php deleted file mode 100644 index deee5f1b7a..0000000000 --- a/mod/notifications.php +++ /dev/null @@ -1,375 +0,0 @@ - 'network', - Notify::SYSTEM => 'system', - Notify::HOME => 'home', - Notify::PERSONAL => 'personal', - Notify::INTRO => 'intros', -]; - -/** @var array Array of the allowed notifies and their printable name */ -const PRINT_TYPES = [ - Notify::NETWORK => 'Network', - Notify::SYSTEM => 'System', - Notify::HOME => 'Home', - Notify::PERSONAL => 'Personal', - Notify::INTRO => 'Introductions', -]; - -/** @var array The array of access keys for notify pages */ -const ACCESS_KEYS = [ - Notify::NETWORK => 'w', - Notify::SYSTEM => 'y', - Notify::HOME => 'h', - Notify::PERSONAL => 'r', - Notify::INTRO => 'i', -]; - -function notifications_post(App $a) -{ - if (!local_user()) { - DI::baseUrl()->redirect(); - } - - $request_id = (($a->argc > 1) ? $a->argv[1] : 0); - - if ($request_id === 'all') { - return; - } - - if ($request_id) { - $intro = DI::intro()->selectFirst(['id' => $request_id, 'uid' => local_user()]); - - switch ($_POST['submit']) { - case DI::l10n()->t('Discard'): - $intro->discard(); - break; - case DI::l10n()->t('Ignore'): - $intro->ignore(); - break; - } - - DI::baseUrl()->redirect('notifications/intros'); - } -} - -function notifications_content(App $a) -{ - if (!local_user()) { - notice(DI::l10n()->t('Permission denied.') . EOL); - return Login::form(); - } - - $page = ($_REQUEST['page'] ?? 0) ?: 1; - $show = ($_REQUEST['show'] ?? '') === 'all'; - - Nav::setSelected('notifications'); - - $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false); - - $nm = DI::notify(); - - $o = ''; - // Get the nav tabs for the notification pages - $tabs = getTabs(DI::args()->get(1, '')); - $notif_content = []; - $notif_nocontent = ''; - - // Notification results per page - $perpage = 20; - $startrec = ($page * $perpage) - $perpage; - - $notif_header = DI::l10n()->t('Notifications'); - - $all = false; - - // Get introductions - if ((($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) { - Nav::setSelected('introductions'); - - $id = 0; - if (!empty($a->argv[2]) && intval($a->argv[2]) != 0) { - $id = (int)$a->argv[2]; - } - - $all = (($a->argc > 2) && ($a->argv[2] == 'all')); - - $notifs = $nm->getIntroList($all, $startrec, $perpage, $id); - - // Get the network notifications - } elseif (($a->argc > 1) && ($a->argv[1] == 'network')) { - $notif_header = DI::l10n()->t('Network Notifications'); - $notifs = $nm->getNetworkList($show, $startrec, $perpage); - - // Get the system notifications - } elseif (($a->argc > 1) && ($a->argv[1] == 'system')) { - $notif_header = DI::l10n()->t('System Notifications'); - $notifs = $nm->getSystemList($show, $startrec, $perpage); - - // Get the personal notifications - } elseif (($a->argc > 1) && ($a->argv[1] == 'personal')) { - $notif_header = DI::l10n()->t('Personal Notifications'); - $notifs = $nm->getPersonalList($show, $startrec, $perpage); - - // Get the home notifications - } elseif (($a->argc > 1) && ($a->argv[1] == 'home')) { - $notif_header = DI::l10n()->t('Home Notifications'); - $notifs = $nm->getHomeList($show, $startrec, $perpage); - // fallback - redirect to main page - } else { - DI::baseUrl()->redirect('notifications'); - } - - // Set the pager - $pager = new Pager(DI::args()->getQueryString(), $perpage); - - // Add additional informations (needed for json output) - $notifs['items_page'] = $pager->getItemsPerPage(); - $notifs['page'] = $pager->getPage(); - - // Json output - if (intval($json) === 1) { - System::jsonExit($notifs); - } - - $notif_tpl = Renderer::getMarkupTemplate('notifications.tpl'); - - $notif_show_lnk = [ - 'href' => ($show ? 'notifications/' . $notifs['ident'] : 'notifications/' . $notifs['ident'] . '?show=all' ), - 'text' => ($show ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')), - ]; - - // Process the data for template creation - if (($notifs['ident'] ?? '') == 'introductions') { - $sugg = Renderer::getMarkupTemplate('suggestions.tpl'); - $tpl = Renderer::getMarkupTemplate('intros.tpl'); - - // The link to switch between ignored and normal connection requests - $notif_show_lnk = [ - 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros' ), - 'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests')) - ]; - - // Loop through all introduction notifications.This creates an array with the output html for each - // introduction - foreach ($notifs['notifications'] as $notif) { - - // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests. - // We have to distinguish between these two because they use different data. - switch ($notif['label']) { - case 'friend_suggestion': - $notif_content[] = Renderer::replaceMacros($sugg, [ - '$type' => $notif['label'], - '$str_notifytype' => DI::l10n()->t('Notification type:'), - '$notify_type'=> $notif['notify_type'], - '$intro_id' => $notif['intro_id'], - '$lbl_madeby' => DI::l10n()->t('Suggested by:'), - '$madeby' => $notif['madeby'], - '$madeby_url' => $notif['madeby_url'], - '$madeby_zrl' => $notif['madeby_zrl'], - '$madeby_addr'=> $notif['madeby_addr'], - '$contact_id' => $notif['contact_id'], - '$photo' => $notif['photo'], - '$fullname' => $notif['name'], - '$url' => $notif['url'], - '$zrl' => $notif['zrl'], - '$lbl_url' => DI::l10n()->t('Profile URL'), - '$addr' => $notif['addr'], - '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''], - '$knowyou' => $notif['knowyou'], - '$approve' => DI::l10n()->t('Approve'), - '$note' => $notif['note'], - '$request' => $notif['request'], - '$ignore' => DI::l10n()->t('Ignore'), - '$discard' => DI::l10n()->t('Discard'), - ]); - break; - - // Normal connection requests - default: - $friend_selected = (($notif['network'] !== Protocol::OSTATUS) ? ' checked="checked" ' : ' disabled '); - $fan_selected = (($notif['network'] === Protocol::OSTATUS) ? ' checked="checked" disabled ' : ''); - - $lbl_knowyou = ''; - $knowyou = ''; - $helptext = ''; - $helptext2 = ''; - $helptext3 = ''; - - if ($notif['network'] === Protocol::DFRN) { - $lbl_knowyou = DI::l10n()->t('Claims to be known to you: '); - $knowyou = (($notif['knowyou']) ? DI::l10n()->t('yes') : DI::l10n()->t('no')); - $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?'); - $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notif['name'], $notif['name']); - $helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notif['name']); - } elseif ($notif['network'] === Protocol::DIASPORA) { - $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?'); - $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notif['name'], $notif['name']); - $helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notif['name']); - } - - $dfrn_tpl = Renderer::getMarkupTemplate('netfriend.tpl'); - $dfrn_text = Renderer::replaceMacros($dfrn_tpl, [ - '$intro_id' => $notif['intro_id'], - '$friend_selected' => $friend_selected, - '$fan_selected'=> $fan_selected, - '$approve_as1' => $helptext, - '$approve_as2' => $helptext2, - '$approve_as3' => $helptext3, - '$as_friend' => DI::l10n()->t('Friend'), - '$as_fan' => (($notif['network'] == Protocol::DIASPORA) ? DI::l10n()->t('Sharer') : DI::l10n()->t('Subscriber')) - ]); - - $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notif['contact_id']]); - - if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) { - $action = 'follow_confirm'; - } else { - $action = 'dfrn_confirm'; - } - - $header = $notif['name']; - - if ($notif['addr'] != '') { - $header .= ' <' . $notif['addr'] . '>'; - } - - $header .= ' (' . ContactSelector::networkToName($notif['network'], $notif['url']) . ')'; - - if ($notif['network'] != Protocol::DIASPORA) { - $discard = DI::l10n()->t('Discard'); - } else { - $discard = ''; - } - - $notif_content[] = Renderer::replaceMacros($tpl, [ - '$type' => $notif['label'], - '$header' => $header, - '$str_notifytype' => DI::l10n()->t('Notification type:'), - '$notify_type' => $notif['notify_type'], - '$dfrn_text' => $dfrn_text, - '$dfrn_id' => $notif['dfrn_id'], - '$uid' => $notif['uid'], - '$intro_id' => $notif['intro_id'], - '$contact_id' => $notif['contact_id'], - '$photo' => $notif['photo'], - '$fullname' => $notif['name'], - '$location' => $notif['location'], - '$lbl_location'=> DI::l10n()->t('Location:'), - '$about' => $notif['about'], - '$lbl_about' => DI::l10n()->t('About:'), - '$keywords' => $notif['keywords'], - '$lbl_keywords'=> DI::l10n()->t('Tags:'), - '$gender' => $notif['gender'], - '$lbl_gender' => DI::l10n()->t('Gender:'), - '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''], - '$url' => $notif['url'], - '$zrl' => $notif['zrl'], - '$lbl_url' => DI::l10n()->t('Profile URL'), - '$addr' => $notif['addr'], - '$lbl_knowyou' => $lbl_knowyou, - '$lbl_network' => DI::l10n()->t('Network:'), - '$network' => ContactSelector::networkToName($notif['network'], $notif['url']), - '$knowyou' => $knowyou, - '$approve' => DI::l10n()->t('Approve'), - '$note' => $notif['note'], - '$ignore' => DI::l10n()->t('Ignore'), - '$discard' => $discard, - '$action' => $action, - ]); - break; - } - } - - if (count($notifs['notifications']) == 0) { - info(DI::l10n()->t('No introductions.') . EOL); - } - - // Normal notifications (no introductions) - } elseif (!empty($notifs['notifications'])) { - // 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). - foreach ($notifs['notifications'] as $notif) { - $notification_templates = [ - 'like' => 'notifications_likes_item.tpl', - 'dislike' => 'notifications_dislikes_item.tpl', - 'attend' => 'notifications_attend_item.tpl', - 'attendno' => 'notifications_attend_item.tpl', - 'attendmaybe' => 'notifications_attend_item.tpl', - 'friend' => 'notifications_friends_item.tpl', - 'comment' => 'notifications_comments_item.tpl', - 'post' => 'notifications_posts_item.tpl', - 'notify' => 'notify.tpl', - ]; - - $tpl_notif = Renderer::getMarkupTemplate($notification_templates[$notif['label']]); - - $notif_content[] = Renderer::replaceMacros($tpl_notif, [ - '$item_label' => $notif['label'], - '$item_link' => $notif['link'], - '$item_image' => $notif['image'], - '$item_url' => $notif['url'], - '$item_text' => $notif['text'], - '$item_when' => $notif['when'], - '$item_ago' => $notif['ago'], - '$item_seen' => $notif['seen'], - ]); - } - } else { - $notif_nocontent = DI::l10n()->t('No more %s notifications.', $notifs['ident']); - } - - $o .= Renderer::replaceMacros($notif_tpl, [ - '$notif_header' => $notif_header, - '$tabs' => $tabs, - '$notif_content' => $notif_content, - '$notif_nocontent' => $notif_nocontent, - '$notif_show_lnk' => $notif_show_lnk, - '$notif_paginate' => $pager->renderMinimal(count($notif_content)) - ]); - - return $o; -} - -/** - * List of pages for the Notifications TabBar - * - * @param string $selected The selected notification tab - * - * @return array with with notifications TabBar data - * @throws Exception - */ -function getTabs(string $selected = '') -{ - $tabs = []; - - foreach (URL_TYPES as $type => $url) { - $tabs[] = [ - 'label' => DI::l10n()->t(PRINT_TYPES[$type]), - 'url' => 'notifications/' . $url, - 'sel' => (($selected == $url) ? 'active' : ''), - 'id' => $type . '-tab', - 'accesskey' => ACCESS_KEYS[$type], - ]; - } - - return $tabs; -} diff --git a/src/Module/BaseNotifications.php b/src/Module/BaseNotifications.php new file mode 100644 index 0000000000..be2ad16b2b --- /dev/null +++ b/src/Module/BaseNotifications.php @@ -0,0 +1,145 @@ + 'network', + Notify::SYSTEM => 'system', + Notify::HOME => 'home', + Notify::PERSONAL => 'personal', + Notify::INTRO => 'intros', + ]; + + /** @var array Array of the allowed notifies and their printable name */ + const PRINT_TYPES = [ + Notify::NETWORK => 'Network', + Notify::SYSTEM => 'System', + Notify::HOME => 'Home', + Notify::PERSONAL => 'Personal', + Notify::INTRO => 'Introductions', + ]; + + /** @var array The array of access keys for notify pages */ + const ACCESS_KEYS = [ + Notify::NETWORK => 'w', + Notify::SYSTEM => 'y', + Notify::HOME => 'h', + Notify::PERSONAL => 'r', + Notify::INTRO => 'i', + ]; + + const PER_PAGE = 20; + + protected static $show; + protected static $start; + + /** + * Collects all notifies from the backend + * + * @return array The determined notification array + * ['header', 'notifs'] + */ + abstract public static function getNotifies(); + + public static function init(array $parameters = []) + { + if (!local_user()) { + throw new ForbiddenException(DI::l10n()->t('Permission denied.')); + } + + $page = ($_REQUEST['page'] ?? 0) ?: 1; + + self::$start = ($page * self::PER_PAGE) - self::PER_PAGE; + self::$show = ($_REQUEST['show'] ?? '') === 'all'; + } + + public static function post(array $parameters = []) + { + $request_id = DI::args()->get(1); + + if ($request_id === 'all') { + return; + } + + if ($request_id) { + $intro = DI::intro()->selectFirst(['id' => $request_id, 'uid' => local_user()]); + + switch ($_POST['submit']) { + case DI::l10n()->t('Discard'): + $intro->discard(); + break; + case DI::l10n()->t('Ignore'): + $intro->ignore(); + break; + } + + DI::baseUrl()->redirect('notifications/intros'); + } + } + + public static function rawContent(array $parameters = []) + { + // If the last argument of the query is NOT json, return + if (DI::args()->get(DI::args()->getArgc() - 1) !== 'json') { + return; + } + + System::jsonExit(static::getNotifies()['notifs'] ?? []); + } + + public static function printContent(string $notif_header, array $notif_content, string $notif_nocontent, array $notif_show_lnk) + { + // Get the nav tabs for the notification pages + $tabs = self::getTabs(); + + // Set the pager + $pager = new Pager(DI::args()->getQueryString(), self::PER_PAGE); + + $notif_tpl = Renderer::getMarkupTemplate('notifications.tpl'); + return Renderer::replaceMacros($notif_tpl, [ + '$notif_header' => $notif_header ?? DI::l10n()->t('Notifications'), + '$tabs' => $tabs, + '$notif_content' => $notif_content, + '$notif_nocontent' => $notif_nocontent, + '$notif_show_lnk' => $notif_show_lnk, + '$notif_paginate' => $pager->renderMinimal(count($notif_content)) + ]); + } + + /** + * List of pages for the Notifications TabBar + * + * @return array with with notifications TabBar data + * @throws Exception + */ + private static function getTabs() + { + $selected = DI::args()->get(1, ''); + + $tabs = []; + + foreach (self::URL_TYPES as $type => $url) { + $tabs[] = [ + 'label' => DI::l10n()->t(self::PRINT_TYPES[$type]), + 'url' => 'notifications/' . $url, + 'sel' => (($selected == $url) ? 'active' : ''), + 'id' => $type . '-tab', + 'accesskey' => self::ACCESS_KEYS[$type], + ]; + } + + return $tabs; + } +} diff --git a/src/Module/Notifications/Introductions.php b/src/Module/Notifications/Introductions.php new file mode 100644 index 0000000000..7befb45ce0 --- /dev/null +++ b/src/Module/Notifications/Introductions.php @@ -0,0 +1,191 @@ +get(2, 0); + $all = DI::args()->get(2) == 'all'; + + $notifs = DI::notify()->getIntroList($all, self::$start, self::PER_PAGE, $id); + + return [ + 'header' => DI::l10n()->t('Notifications'), + 'notifs' => $notifs, + ]; + } + + public static function content(array $parameters = []) + { + Nav::setSelected('introductions'); + + $all = DI::args()->get(2) == 'all'; + + $notif_content = []; + $notif_nocontent = ''; + + $notif_result = self::getNotifies(); + $notifs = $notif_result['notifs'] ?? []; + $notif_header = $notif_result['header'] ?? ''; + + $sugg = Renderer::getMarkupTemplate('suggestions.tpl'); + $tpl = Renderer::getMarkupTemplate('intros.tpl'); + + // The link to switch between ignored and normal connection requests + $notif_show_lnk = [ + 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'), + 'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests')) + ]; + + // Loop through all introduction notifications.This creates an array with the output html for each + // introduction + foreach ($notifs['notifications'] as $notif) { + + // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests. + // We have to distinguish between these two because they use different data. + switch ($notif['label']) { + case 'friend_suggestion': + $notif_content[] = Renderer::replaceMacros($sugg, [ + '$type' => $notif['label'], + '$str_notifytype' => DI::l10n()->t('Notification type:'), + '$notify_type' => $notif['notify_type'], + '$intro_id' => $notif['intro_id'], + '$lbl_madeby' => DI::l10n()->t('Suggested by:'), + '$madeby' => $notif['madeby'], + '$madeby_url' => $notif['madeby_url'], + '$madeby_zrl' => $notif['madeby_zrl'], + '$madeby_addr' => $notif['madeby_addr'], + '$contact_id' => $notif['contact_id'], + '$photo' => $notif['photo'], + '$fullname' => $notif['name'], + '$url' => $notif['url'], + '$zrl' => $notif['zrl'], + '$lbl_url' => DI::l10n()->t('Profile URL'), + '$addr' => $notif['addr'], + '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''], + '$knowyou' => $notif['knowyou'], + '$approve' => DI::l10n()->t('Approve'), + '$note' => $notif['note'], + '$request' => $notif['request'], + '$ignore' => DI::l10n()->t('Ignore'), + '$discard' => DI::l10n()->t('Discard'), + ]); + break; + + // Normal connection requests + default: + $friend_selected = (($notif['network'] !== Protocol::OSTATUS) ? ' checked="checked" ' : ' disabled '); + $fan_selected = (($notif['network'] === Protocol::OSTATUS) ? ' checked="checked" disabled ' : ''); + + $lbl_knowyou = ''; + $knowyou = ''; + $helptext = ''; + $helptext2 = ''; + $helptext3 = ''; + + if ($notif['network'] === Protocol::DFRN) { + $lbl_knowyou = DI::l10n()->t('Claims to be known to you: '); + $knowyou = (($notif['knowyou']) ? DI::l10n()->t('yes') : DI::l10n()->t('no')); + $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?'); + $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notif['name'], $notif['name']); + $helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notif['name']); + } elseif ($notif['network'] === Protocol::DIASPORA) { + $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?'); + $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notif['name'], $notif['name']); + $helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notif['name']); + } + + $dfrn_tpl = Renderer::getMarkupTemplate('netfriend.tpl'); + $dfrn_text = Renderer::replaceMacros($dfrn_tpl, [ + '$intro_id' => $notif['intro_id'], + '$friend_selected' => $friend_selected, + '$fan_selected' => $fan_selected, + '$approve_as1' => $helptext, + '$approve_as2' => $helptext2, + '$approve_as3' => $helptext3, + '$as_friend' => DI::l10n()->t('Friend'), + '$as_fan' => (($notif['network'] == Protocol::DIASPORA) ? DI::l10n()->t('Sharer') : DI::l10n()->t('Subscriber')) + ]); + + $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notif['contact_id']]); + + if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) { + $action = 'follow_confirm'; + } else { + $action = 'dfrn_confirm'; + } + + $header = $notif['name']; + + if ($notif['addr'] != '') { + $header .= ' <' . $notif['addr'] . '>'; + } + + $header .= ' (' . ContactSelector::networkToName($notif['network'], $notif['url']) . ')'; + + if ($notif['network'] != Protocol::DIASPORA) { + $discard = DI::l10n()->t('Discard'); + } else { + $discard = ''; + } + + $notif_content[] = Renderer::replaceMacros($tpl, [ + '$type' => $notif['label'], + '$header' => $header, + '$str_notifytype' => DI::l10n()->t('Notification type:'), + '$notify_type' => $notif['notify_type'], + '$dfrn_text' => $dfrn_text, + '$dfrn_id' => $notif['dfrn_id'], + '$uid' => $notif['uid'], + '$intro_id' => $notif['intro_id'], + '$contact_id' => $notif['contact_id'], + '$photo' => $notif['photo'], + '$fullname' => $notif['name'], + '$location' => $notif['location'], + '$lbl_location' => DI::l10n()->t('Location:'), + '$about' => $notif['about'], + '$lbl_about' => DI::l10n()->t('About:'), + '$keywords' => $notif['keywords'], + '$lbl_keywords' => DI::l10n()->t('Tags:'), + '$gender' => $notif['gender'], + '$lbl_gender' => DI::l10n()->t('Gender:'), + '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''], + '$url' => $notif['url'], + '$zrl' => $notif['zrl'], + '$lbl_url' => DI::l10n()->t('Profile URL'), + '$addr' => $notif['addr'], + '$lbl_knowyou' => $lbl_knowyou, + '$lbl_network' => DI::l10n()->t('Network:'), + '$network' => ContactSelector::networkToName($notif['network'], $notif['url']), + '$knowyou' => $knowyou, + '$approve' => DI::l10n()->t('Approve'), + '$note' => $notif['note'], + '$ignore' => DI::l10n()->t('Ignore'), + '$discard' => $discard, + '$action' => $action, + ]); + break; + } + } + + if (count($notifs['notifications']) == 0) { + info(DI::l10n()->t('No introductions.') . EOL); + $notif_nocontent = DI::l10n()->t('No more %s notifications.', $notifs['ident']); + } + + return self::printContent($notif_header, $notif_content, $notif_nocontent, $notif_show_lnk); + } +} diff --git a/src/Module/Notifications/Notifications.php b/src/Module/Notifications/Notifications.php new file mode 100644 index 0000000000..b1172cadc3 --- /dev/null +++ b/src/Module/Notifications/Notifications.php @@ -0,0 +1,111 @@ +get(1) == 'network')) { + $notif_header = DI::l10n()->t('Network Notifications'); + $notifs = $nm->getNetworkList(self::$show, self::$start, self::PER_PAGE); + + // Get the system notifications + } elseif ((DI::args()->get(1) == 'system')) { + $notif_header = DI::l10n()->t('System Notifications'); + $notifs = $nm->getSystemList(self::$show, self::$start, self::PER_PAGE); + + // Get the personal notifications + } elseif ((DI::args()->get(1) == 'personal')) { + $notif_header = DI::l10n()->t('Personal Notifications'); + $notifs = $nm->getPersonalList(self::$show, self::$start, self::PER_PAGE); + + // Get the home notifications + } elseif ((DI::args()->get(1) == 'home')) { + $notif_header = DI::l10n()->t('Home Notifications'); + $notifs = $nm->getHomeList(self::$show, self::$start, self::PER_PAGE); + // fallback - redirect to main page + } else { + DI::baseUrl()->redirect('notifications'); + } + + // Set the pager + $pager = new Pager(DI::args()->getQueryString(), self::PER_PAGE); + + // Add additional informations (needed for json output) + $notifs['items_page'] = $pager->getItemsPerPage(); + $notifs['page'] = $pager->getPage(); + + return [ + 'header' => $notif_header, + 'notifs' => $notifs, + ]; + } + + public static function content(array $parameters = []) + { + Nav::setSelected('notifications'); + + $notif_content = []; + $notif_nocontent = ''; + + $notif_result = self::getNotifies(); + $notifs = $notif_result['notifs'] ?? []; + $notif_header = $notif_result['header'] ?? ''; + + + if (!empty($notifs['notifications'])) { + // 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). + foreach ($notifs['notifications'] as $notif) { + $notification_templates = [ + 'like' => 'notifications_likes_item.tpl', + 'dislike' => 'notifications_dislikes_item.tpl', + 'attend' => 'notifications_attend_item.tpl', + 'attendno' => 'notifications_attend_item.tpl', + 'attendmaybe' => 'notifications_attend_item.tpl', + 'friend' => 'notifications_friends_item.tpl', + 'comment' => 'notifications_comments_item.tpl', + 'post' => 'notifications_posts_item.tpl', + 'notify' => 'notify.tpl', + ]; + + $tpl_notif = Renderer::getMarkupTemplate($notification_templates[$notif['label']]); + + $notif_content[] = Renderer::replaceMacros($tpl_notif, [ + '$item_label' => $notif['label'], + '$item_link' => $notif['link'], + '$item_image' => $notif['image'], + '$item_url' => $notif['url'], + '$item_text' => $notif['text'], + '$item_when' => $notif['when'], + '$item_ago' => $notif['ago'], + '$item_seen' => $notif['seen'], + ]); + } + } else { + $notif_nocontent = DI::l10n()->t('No more %s notifications.', $notifs['ident']); + } + + $notif_show_lnk = [ + 'href' => (self::$show ? 'notifications/' . $notifs['ident'] : 'notifications/' . $notifs['ident'] . '?show=all'), + 'text' => (self::$show ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')), + ]; + + return self::printContent($notif_header, $notif_content, $notif_nocontent, $notif_show_lnk); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index 05f2599561..aa04d6e6f7 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -167,6 +167,15 @@ return [ '/nodeinfo/{version}' => [Module\NodeInfo::class, [R::GET]], '/nogroup' => [Module\Group::class, [R::GET]], + '/notifications' => [ + '/network[/json]' => [Module\Notifications\Notifications::class, [R::GET, R::POST]], + '/system[/json]' => [Module\Notifications\Notifications::class, [R::GET, R::POST]], + '/personal[/json]' => [Module\Notifications\Notifications::class, [R::GET, R::POST]], + '/home[/json]' => [Module\Notifications\Notifications::class, [R::GET, R::POST]], + '/intros[/json]' => [Module\Notifications\Introductions::class, [R::GET, R::POST]], + '/intros/all[/json]' => [Module\Notifications\Introductions::class, [R::GET, R::POST]], + ], + '/notify' => [ '[/]' => [Module\Notifications\Notify::class, [R::GET]], '/view/{id:\d+}' => [Module\Notifications\Notify::class, [R::GET]], From d0c153943ad53e6b868005a6bb8c75ca4b5379cc Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Wed, 22 Jan 2020 23:31:00 +0100 Subject: [PATCH 02/10] Add phpdoc --- src/Module/BaseNotifications.php | 24 ++++++++++++++++++++-- src/Module/Notifications/Introductions.php | 3 +++ src/Module/Notifications/Notifications.php | 7 +++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Module/BaseNotifications.php b/src/Module/BaseNotifications.php index be2ad16b2b..feec56aea3 100644 --- a/src/Module/BaseNotifications.php +++ b/src/Module/BaseNotifications.php @@ -11,6 +11,11 @@ use Friendica\DI; use Friendica\Model\Notify; use Friendica\Network\HTTPException\ForbiddenException; +/** + * Base Module for each tab of the notification display + * + * General possibility to print it as JSON as well + */ abstract class BaseNotifications extends BaseModule { /** @var array Array of URL parameters */ @@ -40,9 +45,12 @@ abstract class BaseNotifications extends BaseModule Notify::INTRO => 'i', ]; + /** @var int The default count of items per page */ const PER_PAGE = 20; + /** @var boolean True, if ALL entries should get shown */ protected static $show; + /** @var int The determined start item of the current page */ protected static $start; /** @@ -62,7 +70,7 @@ abstract class BaseNotifications extends BaseModule $page = ($_REQUEST['page'] ?? 0) ?: 1; self::$start = ($page * self::PER_PAGE) - self::PER_PAGE; - self::$show = ($_REQUEST['show'] ?? '') === 'all'; + self::$show = ($_REQUEST['show'] ?? '') === 'all'; } public static function post(array $parameters = []) @@ -99,7 +107,19 @@ abstract class BaseNotifications extends BaseModule System::jsonExit(static::getNotifies()['notifs'] ?? []); } - public static function printContent(string $notif_header, array $notif_content, string $notif_nocontent, array $notif_show_lnk) + /** + * Shows the printable result of notifications for a specific tab + * + * @param string $notif_header The notification header + * @param array $notif_content The array with the notifications + * @param string $notif_nocontent The string in case there are no notifications + * @param array $notif_show_lnk The possible links at the top + * + * @return string The rendered output + * + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + protected static function printContent(string $notif_header, array $notif_content, string $notif_nocontent, array $notif_show_lnk) { // Get the nav tabs for the notification pages $tabs = self::getTabs(); diff --git a/src/Module/Notifications/Introductions.php b/src/Module/Notifications/Introductions.php index 7befb45ce0..7de1820362 100644 --- a/src/Module/Notifications/Introductions.php +++ b/src/Module/Notifications/Introductions.php @@ -10,6 +10,9 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Module\BaseNotifications; +/** + * Prints notifications about introduction + */ class Introductions extends BaseNotifications { /** diff --git a/src/Module/Notifications/Notifications.php b/src/Module/Notifications/Notifications.php index b1172cadc3..b15c7feca0 100644 --- a/src/Module/Notifications/Notifications.php +++ b/src/Module/Notifications/Notifications.php @@ -8,6 +8,13 @@ use Friendica\Core\Renderer; use Friendica\DI; use Friendica\Module\BaseNotifications; +/** + * Prints all notification types except introduction: + * - Network + * - System + * - Personal + * - Home + */ class Notifications extends BaseNotifications { /** From 512b00550e65ec08ed863118503526ac873b3b12 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Wed, 22 Jan 2020 23:37:23 +0100 Subject: [PATCH 03/10] rename some variables --- src/Module/BaseNotifications.php | 12 ++++++------ src/Module/Notifications/Introductions.php | 2 +- src/Module/Notifications/Notifications.php | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Module/BaseNotifications.php b/src/Module/BaseNotifications.php index feec56aea3..f1321dfec3 100644 --- a/src/Module/BaseNotifications.php +++ b/src/Module/BaseNotifications.php @@ -46,12 +46,12 @@ abstract class BaseNotifications extends BaseModule ]; /** @var int The default count of items per page */ - const PER_PAGE = 20; + const ITEMS_PER_PAGE = 20; /** @var boolean True, if ALL entries should get shown */ - protected static $show; + protected static $showAll; /** @var int The determined start item of the current page */ - protected static $start; + protected static $firstItemNum; /** * Collects all notifies from the backend @@ -69,8 +69,8 @@ abstract class BaseNotifications extends BaseModule $page = ($_REQUEST['page'] ?? 0) ?: 1; - self::$start = ($page * self::PER_PAGE) - self::PER_PAGE; - self::$show = ($_REQUEST['show'] ?? '') === 'all'; + self::$firstItemNum = ($page * self::ITEMS_PER_PAGE) - self::ITEMS_PER_PAGE; + self::$showAll = ($_REQUEST['show'] ?? '') === 'all'; } public static function post(array $parameters = []) @@ -125,7 +125,7 @@ abstract class BaseNotifications extends BaseModule $tabs = self::getTabs(); // Set the pager - $pager = new Pager(DI::args()->getQueryString(), self::PER_PAGE); + $pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE); $notif_tpl = Renderer::getMarkupTemplate('notifications.tpl'); return Renderer::replaceMacros($notif_tpl, [ diff --git a/src/Module/Notifications/Introductions.php b/src/Module/Notifications/Introductions.php index 7de1820362..b22df920bc 100644 --- a/src/Module/Notifications/Introductions.php +++ b/src/Module/Notifications/Introductions.php @@ -23,7 +23,7 @@ class Introductions extends BaseNotifications $id = (int)DI::args()->get(2, 0); $all = DI::args()->get(2) == 'all'; - $notifs = DI::notify()->getIntroList($all, self::$start, self::PER_PAGE, $id); + $notifs = DI::notify()->getIntroList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id); return [ 'header' => DI::l10n()->t('Notifications'), diff --git a/src/Module/Notifications/Notifications.php b/src/Module/Notifications/Notifications.php index b15c7feca0..50995645c3 100644 --- a/src/Module/Notifications/Notifications.php +++ b/src/Module/Notifications/Notifications.php @@ -29,29 +29,29 @@ class Notifications extends BaseNotifications // Get the network notifications if ((DI::args()->get(1) == 'network')) { $notif_header = DI::l10n()->t('Network Notifications'); - $notifs = $nm->getNetworkList(self::$show, self::$start, self::PER_PAGE); + $notifs = $nm->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); // Get the system notifications } elseif ((DI::args()->get(1) == 'system')) { $notif_header = DI::l10n()->t('System Notifications'); - $notifs = $nm->getSystemList(self::$show, self::$start, self::PER_PAGE); + $notifs = $nm->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); // Get the personal notifications } elseif ((DI::args()->get(1) == 'personal')) { $notif_header = DI::l10n()->t('Personal Notifications'); - $notifs = $nm->getPersonalList(self::$show, self::$start, self::PER_PAGE); + $notifs = $nm->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); // Get the home notifications } elseif ((DI::args()->get(1) == 'home')) { $notif_header = DI::l10n()->t('Home Notifications'); - $notifs = $nm->getHomeList(self::$show, self::$start, self::PER_PAGE); + $notifs = $nm->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); // fallback - redirect to main page } else { DI::baseUrl()->redirect('notifications'); } // Set the pager - $pager = new Pager(DI::args()->getQueryString(), self::PER_PAGE); + $pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE); // Add additional informations (needed for json output) $notifs['items_page'] = $pager->getItemsPerPage(); @@ -109,8 +109,8 @@ class Notifications extends BaseNotifications } $notif_show_lnk = [ - 'href' => (self::$show ? 'notifications/' . $notifs['ident'] : 'notifications/' . $notifs['ident'] . '?show=all'), - 'text' => (self::$show ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')), + 'href' => (self::$showAll ? 'notifications/' . $notifs['ident'] : 'notifications/' . $notifs['ident'] . '?show=all'), + 'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')), ]; return self::printContent($notif_header, $notif_content, $notif_nocontent, $notif_show_lnk); From 5c4eb2b2c90a343081452870dd9cf9f8ab718f96 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Thu, 23 Jan 2020 00:16:34 +0100 Subject: [PATCH 04/10] Move templates into sub-dir "notifications" --- src/Module/BaseNotifications.php | 2 +- src/Module/Notifications/Introductions.php | 6 +++--- src/Module/Notifications/Notifications.php | 18 +++++++++--------- .../attend_item.tpl} | 0 .../comments_item.tpl} | 0 .../dislikes_item.tpl} | 0 .../friends_item.tpl} | 0 view/templates/{ => notifications}/intros.tpl | 0 .../likes_item.tpl} | 0 .../{ => notifications}/netfriend.tpl | 0 .../network_item.tpl} | 0 .../{ => notifications}/notifications.tpl | 0 view/templates/{ => notifications}/notify.tpl | 0 .../posts_item.tpl} | 0 .../{ => notifications}/suggestions.tpl | 0 .../templates/notifications/attend_item.tpl | 2 ++ .../templates/notifications/comments_item.tpl | 2 ++ .../templates/notifications/dislikes_item.tpl | 2 ++ .../templates/notifications/friends_item.tpl | 2 ++ .../templates/{ => notifications}/intros.tpl | 0 .../templates/notifications/likes_item.tpl | 2 ++ .../templates/notifications/network_item.tpl | 2 ++ .../{ => notifications}/notifications.tpl | 4 ++-- .../templates/{ => notifications}/notify.tpl | 0 .../templates/notifications/posts_item.tpl | 2 ++ .../templates/notifications/suggestions.tpl | 2 ++ .../templates/notifications_attend_item.tpl | 2 -- .../templates/notifications_comments_item.tpl | 2 -- .../templates/notifications_dislikes_item.tpl | 2 -- .../templates/notifications_friends_item.tpl | 2 -- .../templates/notifications_likes_item.tpl | 2 -- .../templates/notifications_network_item.tpl | 2 -- .../templates/notifications_posts_item.tpl | 2 -- view/theme/frio/templates/suggestions.tpl | 2 -- 34 files changed, 31 insertions(+), 31 deletions(-) rename view/templates/{notifications_attend_item.tpl => notifications/attend_item.tpl} (100%) rename view/templates/{notifications_comments_item.tpl => notifications/comments_item.tpl} (100%) rename view/templates/{notifications_dislikes_item.tpl => notifications/dislikes_item.tpl} (100%) rename view/templates/{notifications_friends_item.tpl => notifications/friends_item.tpl} (100%) rename view/templates/{ => notifications}/intros.tpl (100%) rename view/templates/{notifications_likes_item.tpl => notifications/likes_item.tpl} (100%) rename view/templates/{ => notifications}/netfriend.tpl (100%) rename view/templates/{notifications_network_item.tpl => notifications/network_item.tpl} (100%) rename view/templates/{ => notifications}/notifications.tpl (100%) rename view/templates/{ => notifications}/notify.tpl (100%) rename view/templates/{notifications_posts_item.tpl => notifications/posts_item.tpl} (100%) rename view/templates/{ => notifications}/suggestions.tpl (100%) create mode 100644 view/theme/frio/templates/notifications/attend_item.tpl create mode 100644 view/theme/frio/templates/notifications/comments_item.tpl create mode 100644 view/theme/frio/templates/notifications/dislikes_item.tpl create mode 100644 view/theme/frio/templates/notifications/friends_item.tpl rename view/theme/frio/templates/{ => notifications}/intros.tpl (100%) create mode 100644 view/theme/frio/templates/notifications/likes_item.tpl create mode 100644 view/theme/frio/templates/notifications/network_item.tpl rename view/theme/frio/templates/{ => notifications}/notifications.tpl (80%) rename view/theme/frio/templates/{ => notifications}/notify.tpl (100%) create mode 100644 view/theme/frio/templates/notifications/posts_item.tpl create mode 100644 view/theme/frio/templates/notifications/suggestions.tpl delete mode 100644 view/theme/frio/templates/notifications_attend_item.tpl delete mode 100644 view/theme/frio/templates/notifications_comments_item.tpl delete mode 100644 view/theme/frio/templates/notifications_dislikes_item.tpl delete mode 100644 view/theme/frio/templates/notifications_friends_item.tpl delete mode 100644 view/theme/frio/templates/notifications_likes_item.tpl delete mode 100644 view/theme/frio/templates/notifications_network_item.tpl delete mode 100644 view/theme/frio/templates/notifications_posts_item.tpl delete mode 100644 view/theme/frio/templates/suggestions.tpl diff --git a/src/Module/BaseNotifications.php b/src/Module/BaseNotifications.php index f1321dfec3..fde4828e27 100644 --- a/src/Module/BaseNotifications.php +++ b/src/Module/BaseNotifications.php @@ -127,7 +127,7 @@ abstract class BaseNotifications extends BaseModule // Set the pager $pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE); - $notif_tpl = Renderer::getMarkupTemplate('notifications.tpl'); + $notif_tpl = Renderer::getMarkupTemplate('notifications/notifications.tpl'); return Renderer::replaceMacros($notif_tpl, [ '$notif_header' => $notif_header ?? DI::l10n()->t('Notifications'), '$tabs' => $tabs, diff --git a/src/Module/Notifications/Introductions.php b/src/Module/Notifications/Introductions.php index b22df920bc..3a7499a1e5 100644 --- a/src/Module/Notifications/Introductions.php +++ b/src/Module/Notifications/Introductions.php @@ -44,8 +44,8 @@ class Introductions extends BaseNotifications $notifs = $notif_result['notifs'] ?? []; $notif_header = $notif_result['header'] ?? ''; - $sugg = Renderer::getMarkupTemplate('suggestions.tpl'); - $tpl = Renderer::getMarkupTemplate('intros.tpl'); + $sugg = Renderer::getMarkupTemplate('notifications/suggestions.tpl'); + $tpl = Renderer::getMarkupTemplate('notifications/intros.tpl'); // The link to switch between ignored and normal connection requests $notif_show_lnk = [ @@ -111,7 +111,7 @@ class Introductions extends BaseNotifications $helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notif['name']); } - $dfrn_tpl = Renderer::getMarkupTemplate('netfriend.tpl'); + $dfrn_tpl = Renderer::getMarkupTemplate('notifications/netfriend.tpl'); $dfrn_text = Renderer::replaceMacros($dfrn_tpl, [ '$intro_id' => $notif['intro_id'], '$friend_selected' => $friend_selected, diff --git a/src/Module/Notifications/Notifications.php b/src/Module/Notifications/Notifications.php index 50995645c3..bfccbd4e70 100644 --- a/src/Module/Notifications/Notifications.php +++ b/src/Module/Notifications/Notifications.php @@ -80,15 +80,15 @@ class Notifications extends BaseNotifications // notification and apply the correct template according to the notificationtype (label). foreach ($notifs['notifications'] as $notif) { $notification_templates = [ - 'like' => 'notifications_likes_item.tpl', - 'dislike' => 'notifications_dislikes_item.tpl', - 'attend' => 'notifications_attend_item.tpl', - 'attendno' => 'notifications_attend_item.tpl', - 'attendmaybe' => 'notifications_attend_item.tpl', - 'friend' => 'notifications_friends_item.tpl', - 'comment' => 'notifications_comments_item.tpl', - 'post' => 'notifications_posts_item.tpl', - 'notify' => 'notify.tpl', + 'like' => 'notifications/likes_item.tpl', + 'dislike' => 'notifications/dislikes_item.tpl', + 'attend' => 'notifications/attend_item.tpl', + 'attendno' => 'notifications/attend_item.tpl', + 'attendmaybe' => 'notifications/attend_item.tpl', + 'friend' => 'notifications/friends_item.tpl', + 'comment' => 'notifications/comments_item.tpl', + 'post' => 'notifications/posts_item.tpl', + 'notify' => 'notifications/notify.tpl', ]; $tpl_notif = Renderer::getMarkupTemplate($notification_templates[$notif['label']]); diff --git a/view/templates/notifications_attend_item.tpl b/view/templates/notifications/attend_item.tpl similarity index 100% rename from view/templates/notifications_attend_item.tpl rename to view/templates/notifications/attend_item.tpl diff --git a/view/templates/notifications_comments_item.tpl b/view/templates/notifications/comments_item.tpl similarity index 100% rename from view/templates/notifications_comments_item.tpl rename to view/templates/notifications/comments_item.tpl diff --git a/view/templates/notifications_dislikes_item.tpl b/view/templates/notifications/dislikes_item.tpl similarity index 100% rename from view/templates/notifications_dislikes_item.tpl rename to view/templates/notifications/dislikes_item.tpl diff --git a/view/templates/notifications_friends_item.tpl b/view/templates/notifications/friends_item.tpl similarity index 100% rename from view/templates/notifications_friends_item.tpl rename to view/templates/notifications/friends_item.tpl diff --git a/view/templates/intros.tpl b/view/templates/notifications/intros.tpl similarity index 100% rename from view/templates/intros.tpl rename to view/templates/notifications/intros.tpl diff --git a/view/templates/notifications_likes_item.tpl b/view/templates/notifications/likes_item.tpl similarity index 100% rename from view/templates/notifications_likes_item.tpl rename to view/templates/notifications/likes_item.tpl diff --git a/view/templates/netfriend.tpl b/view/templates/notifications/netfriend.tpl similarity index 100% rename from view/templates/netfriend.tpl rename to view/templates/notifications/netfriend.tpl diff --git a/view/templates/notifications_network_item.tpl b/view/templates/notifications/network_item.tpl similarity index 100% rename from view/templates/notifications_network_item.tpl rename to view/templates/notifications/network_item.tpl diff --git a/view/templates/notifications.tpl b/view/templates/notifications/notifications.tpl similarity index 100% rename from view/templates/notifications.tpl rename to view/templates/notifications/notifications.tpl diff --git a/view/templates/notify.tpl b/view/templates/notifications/notify.tpl similarity index 100% rename from view/templates/notify.tpl rename to view/templates/notifications/notify.tpl diff --git a/view/templates/notifications_posts_item.tpl b/view/templates/notifications/posts_item.tpl similarity index 100% rename from view/templates/notifications_posts_item.tpl rename to view/templates/notifications/posts_item.tpl diff --git a/view/templates/suggestions.tpl b/view/templates/notifications/suggestions.tpl similarity index 100% rename from view/templates/suggestions.tpl rename to view/templates/notifications/suggestions.tpl diff --git a/view/theme/frio/templates/notifications/attend_item.tpl b/view/theme/frio/templates/notifications/attend_item.tpl new file mode 100644 index 0000000000..252b61c776 --- /dev/null +++ b/view/theme/frio/templates/notifications/attend_item.tpl @@ -0,0 +1,2 @@ + +{{include file="notifications/notify.tpl"}} diff --git a/view/theme/frio/templates/notifications/comments_item.tpl b/view/theme/frio/templates/notifications/comments_item.tpl new file mode 100644 index 0000000000..252b61c776 --- /dev/null +++ b/view/theme/frio/templates/notifications/comments_item.tpl @@ -0,0 +1,2 @@ + +{{include file="notifications/notify.tpl"}} diff --git a/view/theme/frio/templates/notifications/dislikes_item.tpl b/view/theme/frio/templates/notifications/dislikes_item.tpl new file mode 100644 index 0000000000..252b61c776 --- /dev/null +++ b/view/theme/frio/templates/notifications/dislikes_item.tpl @@ -0,0 +1,2 @@ + +{{include file="notifications/notify.tpl"}} diff --git a/view/theme/frio/templates/notifications/friends_item.tpl b/view/theme/frio/templates/notifications/friends_item.tpl new file mode 100644 index 0000000000..252b61c776 --- /dev/null +++ b/view/theme/frio/templates/notifications/friends_item.tpl @@ -0,0 +1,2 @@ + +{{include file="notifications/notify.tpl"}} diff --git a/view/theme/frio/templates/intros.tpl b/view/theme/frio/templates/notifications/intros.tpl similarity index 100% rename from view/theme/frio/templates/intros.tpl rename to view/theme/frio/templates/notifications/intros.tpl diff --git a/view/theme/frio/templates/notifications/likes_item.tpl b/view/theme/frio/templates/notifications/likes_item.tpl new file mode 100644 index 0000000000..252b61c776 --- /dev/null +++ b/view/theme/frio/templates/notifications/likes_item.tpl @@ -0,0 +1,2 @@ + +{{include file="notifications/notify.tpl"}} diff --git a/view/theme/frio/templates/notifications/network_item.tpl b/view/theme/frio/templates/notifications/network_item.tpl new file mode 100644 index 0000000000..252b61c776 --- /dev/null +++ b/view/theme/frio/templates/notifications/network_item.tpl @@ -0,0 +1,2 @@ + +{{include file="notifications/notify.tpl"}} diff --git a/view/theme/frio/templates/notifications.tpl b/view/theme/frio/templates/notifications/notifications.tpl similarity index 80% rename from view/theme/frio/templates/notifications.tpl rename to view/theme/frio/templates/notifications/notifications.tpl index 1be92c4b24..591d0c3a83 100644 --- a/view/theme/frio/templates/notifications.tpl +++ b/view/theme/frio/templates/notifications/notifications.tpl @@ -1,5 +1,5 @@ - - + +
{{include file="section_title.tpl" title=$notif_header}} diff --git a/view/theme/frio/templates/notify.tpl b/view/theme/frio/templates/notifications/notify.tpl similarity index 100% rename from view/theme/frio/templates/notify.tpl rename to view/theme/frio/templates/notifications/notify.tpl diff --git a/view/theme/frio/templates/notifications/posts_item.tpl b/view/theme/frio/templates/notifications/posts_item.tpl new file mode 100644 index 0000000000..252b61c776 --- /dev/null +++ b/view/theme/frio/templates/notifications/posts_item.tpl @@ -0,0 +1,2 @@ + +{{include file="notifications/notify.tpl"}} diff --git a/view/theme/frio/templates/notifications/suggestions.tpl b/view/theme/frio/templates/notifications/suggestions.tpl new file mode 100644 index 0000000000..9595190e0b --- /dev/null +++ b/view/theme/frio/templates/notifications/suggestions.tpl @@ -0,0 +1,2 @@ + +{{include file="notifications/intros.tpl"}} \ No newline at end of file diff --git a/view/theme/frio/templates/notifications_attend_item.tpl b/view/theme/frio/templates/notifications_attend_item.tpl deleted file mode 100644 index 680b29a27c..0000000000 --- a/view/theme/frio/templates/notifications_attend_item.tpl +++ /dev/null @@ -1,2 +0,0 @@ - -{{include file="notify.tpl"}} diff --git a/view/theme/frio/templates/notifications_comments_item.tpl b/view/theme/frio/templates/notifications_comments_item.tpl deleted file mode 100644 index 680b29a27c..0000000000 --- a/view/theme/frio/templates/notifications_comments_item.tpl +++ /dev/null @@ -1,2 +0,0 @@ - -{{include file="notify.tpl"}} diff --git a/view/theme/frio/templates/notifications_dislikes_item.tpl b/view/theme/frio/templates/notifications_dislikes_item.tpl deleted file mode 100644 index 680b29a27c..0000000000 --- a/view/theme/frio/templates/notifications_dislikes_item.tpl +++ /dev/null @@ -1,2 +0,0 @@ - -{{include file="notify.tpl"}} diff --git a/view/theme/frio/templates/notifications_friends_item.tpl b/view/theme/frio/templates/notifications_friends_item.tpl deleted file mode 100644 index 680b29a27c..0000000000 --- a/view/theme/frio/templates/notifications_friends_item.tpl +++ /dev/null @@ -1,2 +0,0 @@ - -{{include file="notify.tpl"}} diff --git a/view/theme/frio/templates/notifications_likes_item.tpl b/view/theme/frio/templates/notifications_likes_item.tpl deleted file mode 100644 index 680b29a27c..0000000000 --- a/view/theme/frio/templates/notifications_likes_item.tpl +++ /dev/null @@ -1,2 +0,0 @@ - -{{include file="notify.tpl"}} diff --git a/view/theme/frio/templates/notifications_network_item.tpl b/view/theme/frio/templates/notifications_network_item.tpl deleted file mode 100644 index 680b29a27c..0000000000 --- a/view/theme/frio/templates/notifications_network_item.tpl +++ /dev/null @@ -1,2 +0,0 @@ - -{{include file="notify.tpl"}} diff --git a/view/theme/frio/templates/notifications_posts_item.tpl b/view/theme/frio/templates/notifications_posts_item.tpl deleted file mode 100644 index 680b29a27c..0000000000 --- a/view/theme/frio/templates/notifications_posts_item.tpl +++ /dev/null @@ -1,2 +0,0 @@ - -{{include file="notify.tpl"}} diff --git a/view/theme/frio/templates/suggestions.tpl b/view/theme/frio/templates/suggestions.tpl deleted file mode 100644 index e2399eb49e..0000000000 --- a/view/theme/frio/templates/suggestions.tpl +++ /dev/null @@ -1,2 +0,0 @@ - -{{include file="intros.tpl"}} \ No newline at end of file From e59a9fbef7b5ea97822f04d5f6aafcfb3f5f7796 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Thu, 23 Jan 2020 00:31:22 +0100 Subject: [PATCH 05/10] Add explicit contact route --- static/routes.config.php | 1 + 1 file changed, 1 insertion(+) diff --git a/static/routes.config.php b/static/routes.config.php index aa04d6e6f7..44502cdfb2 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -174,6 +174,7 @@ return [ '/home[/json]' => [Module\Notifications\Notifications::class, [R::GET, R::POST]], '/intros[/json]' => [Module\Notifications\Introductions::class, [R::GET, R::POST]], '/intros/all[/json]' => [Module\Notifications\Introductions::class, [R::GET, R::POST]], + '/intros/{contact:\d+}[/json]' => [Module\Notifications\Introductions::class, [R::GET, R::POST]], ], '/notify' => [ From 0f932ae723c8b97a1889b9d77a52da3fe7f8b2b3 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 24 Jan 2020 18:32:38 +0100 Subject: [PATCH 06/10] Notify => Notification Notifs => Notifications --- include/api.php | 4 +- include/enotify.php | 2 +- mod/ping.php | 2 +- src/DI.php | 6 +- src/Model/{Notify.php => Notification.php} | 166 +++++++++--------- src/Module/BaseNotifications.php | 62 +++---- src/Module/Notifications/Introductions.php | 142 +++++++-------- .../{Notify.php => Notification.php} | 22 +-- src/Module/Notifications/Notifications.php | 74 ++++---- static/routes.config.php | 8 +- view/js/main.js | 2 +- .../{notify.tpl => notification.tpl} | 0 .../templates/notifications/attend_item.tpl | 2 +- .../templates/notifications/comments_item.tpl | 2 +- .../templates/notifications/dislikes_item.tpl | 2 +- .../templates/notifications/friends_item.tpl | 2 +- .../templates/notifications/likes_item.tpl | 2 +- .../templates/notifications/network_item.tpl | 2 +- .../templates/notifications/posts_item.tpl | 2 +- 19 files changed, 250 insertions(+), 254 deletions(-) rename src/Model/{Notify.php => Notification.php} (78%) rename src/Module/Notifications/{Notify.php => Notification.php} (71%) rename view/templates/notifications/{notify.tpl => notification.tpl} (100%) diff --git a/include/api.php b/include/api.php index 92b4e4b218..3836caa19d 100644 --- a/include/api.php +++ b/include/api.php @@ -5905,7 +5905,7 @@ function api_friendica_notification($type) if ($a->argc!==3) { throw new BadRequestException("Invalid argument count"); } - $notes = DI::notify()->getAll([], ['seen' => 'ASC', 'date' => 'DESC'], 50); + $notes = DI::notification()->getAll([], ['seen' => 'ASC', 'date' => 'DESC'], 50); if ($type == "xml") { $xmlnotes = []; @@ -5947,7 +5947,7 @@ function api_friendica_notification_seen($type) $id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0); - $nm = DI::notify(); + $nm = DI::notification(); $note = $nm->getByID($id); if (is_null($note)) { throw new BadRequestException("Invalid argument"); diff --git a/include/enotify.php b/include/enotify.php index 4bd9eb6967..403688af6d 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -516,7 +516,7 @@ function notification($params) $notify_id = DBA::lastInsertId(); - $itemlink = DI::baseUrl().'/notify/view/'.$notify_id; + $itemlink = DI::baseUrl().'/notification/view/'.$notify_id; $msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $itemlink]); $msg_cache = format_notification_message($datarray['name_cache'], strip_tags(BBCode::convert($msg))); diff --git a/mod/ping.php b/mod/ping.php index 4890197074..f9dd7faf27 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -443,7 +443,7 @@ function ping_get_notifications($uid) ); } - $notification["href"] = DI::baseUrl() . "/notify/view/" . $notification["id"]; + $notification["href"] = DI::baseUrl() . "/notification/view/" . $notification["id"]; if ($notification["visible"] && !$notification["deleted"] diff --git a/src/DI.php b/src/DI.php index e6d9c341b7..67e0b17315 100644 --- a/src/DI.php +++ b/src/DI.php @@ -257,11 +257,11 @@ abstract class DI } /** - * @return Model\Notify + * @return Model\Notification */ - public static function notify() + public static function notification() { - return self::$dice->create(Model\Notify::class); + return self::$dice->create(Model\Notification::class); } /** diff --git a/src/Model/Notify.php b/src/Model/Notification.php similarity index 78% rename from src/Model/Notify.php rename to src/Model/Notification.php index 7e8a71c165..b31014a599 100644 --- a/src/Model/Notify.php +++ b/src/Model/Notification.php @@ -25,7 +25,7 @@ use Friendica\Network\HTTPException; * Methods for read and write notifications from/to database * or for formatting notifications */ -final class Notify +final class Notification { /** @var int The default limit of notifies per page */ const DEFAULT_PAGE_LIMIT = 80; @@ -172,8 +172,8 @@ final class Notify /** * Format the notification query in an usable array * - * @param array $notifies The array from the db query - * @param string $ident The notifications identifier (e.g. network) + * @param array $notifications The array from the db query + * @param string $ident The notifications identifier (e.g. network) * * @return array * string 'label' => The type of the notification @@ -186,126 +186,126 @@ final class Notify * bool 'seen' => Is the notification marked as "seen" * @throws Exception */ - private function formatList(array $notifies, string $ident = "") + private function formatList(array $notifications, string $ident = "") { $formattedNotifies = []; - foreach ($notifies as $notify) { + foreach ($notifications as $notification) { // Because we use different db tables for the notification query - // we have sometimes $notify['unseen'] and sometimes $notify['seen]. - // So we will have to transform $notify['unseen'] - if (array_key_exists('unseen', $notify)) { - $notify['seen'] = ($notify['unseen'] > 0 ? false : true); + // we have sometimes $notification['unseen'] and sometimes $notification['seen]. + // So we will have to transform $notification['unseen'] + if (array_key_exists('unseen', $notification)) { + $notification['seen'] = ($notification['unseen'] > 0 ? false : true); } // For feed items we use the user's contact, since the avatar is mostly self choosen. - if (!empty($notify['network']) && $notify['network'] == Protocol::FEED) { - $notify['author-avatar'] = $notify['contact-avatar']; + if (!empty($notification['network']) && $notification['network'] == Protocol::FEED) { + $notification['author-avatar'] = $notification['contact-avatar']; } // Depending on the identifier of the notification we need to use different defaults switch ($ident) { case self::SYSTEM: - $default_item_label = 'notify'; - $default_item_link = $this->baseUrl->get(true) . '/notify/view/' . $notify['id']; - $default_item_image = ProxyUtils::proxifyUrl($notify['photo'], false, ProxyUtils::SIZE_MICRO); - $default_item_url = $notify['url']; - $default_item_text = strip_tags(BBCode::convert($notify['msg'])); - $default_item_when = DateTimeFormat::local($notify['date'], 'r'); - $default_item_ago = Temporal::getRelativeDate($notify['date']); + $default_item_label = 'notification'; + $default_item_link = $this->baseUrl->get(true) . '/notification/view/' . $notification['id']; + $default_item_image = ProxyUtils::proxifyUrl($notification['photo'], false, ProxyUtils::SIZE_MICRO); + $default_item_url = $notification['url']; + $default_item_text = strip_tags(BBCode::convert($notification['msg'])); + $default_item_when = DateTimeFormat::local($notification['date'], 'r'); + $default_item_ago = Temporal::getRelativeDate($notification['date']); break; case self::HOME: $default_item_label = 'comment'; - $default_item_link = $this->baseUrl->get(true) . '/display/' . $notify['parent-guid']; - $default_item_image = ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO); - $default_item_url = $notify['author-link']; - $default_item_text = $this->l10n->t("%s commented on %s's post", $notify['author-name'], $notify['parent-author-name']); - $default_item_when = DateTimeFormat::local($notify['created'], 'r'); - $default_item_ago = Temporal::getRelativeDate($notify['created']); + $default_item_link = $this->baseUrl->get(true) . '/display/' . $notification['parent-guid']; + $default_item_image = ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO); + $default_item_url = $notification['author-link']; + $default_item_text = $this->l10n->t("%s commented on %s's post", $notification['author-name'], $notification['parent-author-name']); + $default_item_when = DateTimeFormat::local($notification['created'], 'r'); + $default_item_ago = Temporal::getRelativeDate($notification['created']); break; default: - $default_item_label = (($notify['id'] == $notify['parent']) ? 'post' : 'comment'); - $default_item_link = $this->baseUrl->get(true) . '/display/' . $notify['parent-guid']; - $default_item_image = ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO); - $default_item_url = $notify['author-link']; - $default_item_text = (($notify['id'] == $notify['parent']) - ? $this->l10n->t("%s created a new post", $notify['author-name']) - : $this->l10n->t("%s commented on %s's post", $notify['author-name'], $notify['parent-author-name'])); - $default_item_when = DateTimeFormat::local($notify['created'], 'r'); - $default_item_ago = Temporal::getRelativeDate($notify['created']); + $default_item_label = (($notification['id'] == $notification['parent']) ? 'post' : 'comment'); + $default_item_link = $this->baseUrl->get(true) . '/display/' . $notification['parent-guid']; + $default_item_image = ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO); + $default_item_url = $notification['author-link']; + $default_item_text = (($notification['id'] == $notification['parent']) + ? $this->l10n->t("%s created a new post", $notification['author-name']) + : $this->l10n->t("%s commented on %s's post", $notification['author-name'], $notification['parent-author-name'])); + $default_item_when = DateTimeFormat::local($notification['created'], 'r'); + $default_item_ago = Temporal::getRelativeDate($notification['created']); } // Transform the different types of notification in an usable array - switch ($notify['verb']) { + switch ($notification['verb']) { case Activity::LIKE: $formattedNotify = [ 'label' => 'like', - 'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], - 'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), - 'url' => $notify['author-link'], - 'text' => $this->l10n->t("%s liked %s's post", $notify['author-name'], $notify['parent-author-name']), + 'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'], + 'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO), + 'url' => $notification['author-link'], + 'text' => $this->l10n->t("%s liked %s's post", $notification['author-name'], $notification['parent-author-name']), 'when' => $default_item_when, 'ago' => $default_item_ago, - 'seen' => $notify['seen'] + 'seen' => $notification['seen'] ]; break; case Activity::DISLIKE: $formattedNotify = [ 'label' => 'dislike', - 'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], - 'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), - 'url' => $notify['author-link'], - 'text' => $this->l10n->t("%s disliked %s's post", $notify['author-name'], $notify['parent-author-name']), + 'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'], + 'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO), + 'url' => $notification['author-link'], + 'text' => $this->l10n->t("%s disliked %s's post", $notification['author-name'], $notification['parent-author-name']), 'when' => $default_item_when, 'ago' => $default_item_ago, - 'seen' => $notify['seen'] + 'seen' => $notification['seen'] ]; break; case Activity::ATTEND: $formattedNotify = [ 'label' => 'attend', - 'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], - 'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), - 'url' => $notify['author-link'], - 'text' => $this->l10n->t("%s is attending %s's event", $notify['author-name'], $notify['parent-author-name']), + 'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'], + 'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO), + 'url' => $notification['author-link'], + 'text' => $this->l10n->t("%s is attending %s's event", $notification['author-name'], $notification['parent-author-name']), 'when' => $default_item_when, 'ago' => $default_item_ago, - 'seen' => $notify['seen'] + 'seen' => $notification['seen'] ]; break; case Activity::ATTENDNO: $formattedNotify = [ 'label' => 'attendno', - 'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], - 'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), - 'url' => $notify['author-link'], - 'text' => $this->l10n->t("%s is not attending %s's event", $notify['author-name'], $notify['parent-author-name']), + 'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'], + 'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO), + 'url' => $notification['author-link'], + 'text' => $this->l10n->t("%s is not attending %s's event", $notification['author-name'], $notification['parent-author-name']), 'when' => $default_item_when, 'ago' => $default_item_ago, - 'seen' => $notify['seen'] + 'seen' => $notification['seen'] ]; break; case Activity::ATTENDMAYBE: $formattedNotify = [ 'label' => 'attendmaybe', - 'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], - 'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), - 'url' => $notify['author-link'], - 'text' => $this->l10n->t("%s may attend %s's event", $notify['author-name'], $notify['parent-author-name']), + 'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'], + 'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO), + 'url' => $notification['author-link'], + 'text' => $this->l10n->t("%s may attend %s's event", $notification['author-name'], $notification['parent-author-name']), 'when' => $default_item_when, 'ago' => $default_item_ago, - 'seen' => $notify['seen'] + 'seen' => $notification['seen'] ]; break; case Activity::FRIEND: - if (!isset($notify['object'])) { + if (!isset($notification['object'])) { $formattedNotify = [ 'label' => 'friend', 'link' => $default_item_link, @@ -314,26 +314,26 @@ final class Notify 'text' => $default_item_text, 'when' => $default_item_when, 'ago' => $default_item_ago, - 'seen' => $notify['seen'] + 'seen' => $notification['seen'] ]; break; } /// @todo Check if this part here is used at all - $this->logger->info('Complete data.', ['notify' => $notify, 'callStack' => System::callstack(20)]); + $this->logger->info('Complete data.', ['notification' => $notification, 'callStack' => System::callstack(20)]); - $xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; - $obj = XML::parseString($xmlHead . $notify['object']); - $notify['fname'] = $obj->title; + $xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; + $obj = XML::parseString($xmlHead . $notification['object']); + $notification['fname'] = $obj->title; $formattedNotify = [ 'label' => 'friend', - 'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], - 'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), - 'url' => $notify['author-link'], - 'text' => $this->l10n->t("%s is now friends with %s", $notify['author-name'], $notify['fname']), + 'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'], + 'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO), + 'url' => $notification['author-link'], + 'text' => $this->l10n->t("%s is now friends with %s", $notification['author-name'], $notification['fname']), 'when' => $default_item_when, 'ago' => $default_item_ago, - 'seen' => $notify['seen'] + 'seen' => $notification['seen'] ]; break; @@ -346,7 +346,7 @@ final class Notify 'text' => $default_item_text, 'when' => $default_item_when, 'ago' => $default_item_ago, - 'seen' => $notify['seen'] + 'seen' => $notification['seen'] ]; } @@ -359,10 +359,10 @@ final class Notify /** * Get network notifications * - * @param bool $seen False => only include notifications into the query + * @param bool $seen False => only include notifications into the query * which aren't marked as "seen" - * @param int $start Start the query at this point - * @param int $limit Maximum number of query results + * @param int $start Start the query at this point + * @param int $limit Maximum number of query results * * @return array [string, array] * string 'ident' => Notification identifier @@ -402,10 +402,10 @@ final class Notify /** * Get system notifications * - * @param bool $seen False => only include notifications into the query + * @param bool $seen False => only include notifications into the query * which aren't marked as "seen" - * @param int $start Start the query at this point - * @param int $limit Maximum number of query results + * @param int $start Start the query at this point + * @param int $limit Maximum number of query results * * @return array [string, array] * string 'ident' => Notification identifier @@ -447,10 +447,10 @@ final class Notify /** * Get personal notifications * - * @param bool $seen False => only include notifications into the query + * @param bool $seen False => only include notifications into the query * which aren't marked as "seen" - * @param int $start Start the query at this point - * @param int $limit Maximum number of query results + * @param int $start Start the query at this point + * @param int $limit Maximum number of query results * * @return array [string, array] * string 'ident' => Notification identifier @@ -494,10 +494,10 @@ final class Notify /** * Get home notifications * - * @param bool $seen False => only include notifications into the query + * @param bool $seen False => only include notifications into the query * which aren't marked as "seen" - * @param int $start Start the query at this point - * @param int $limit Maximum number of query results + * @param int $start Start the query at this point + * @param int $limit Maximum number of query results * * @return array [string, array] * string 'ident' => Notification identifier diff --git a/src/Module/BaseNotifications.php b/src/Module/BaseNotifications.php index fde4828e27..2133a3b880 100644 --- a/src/Module/BaseNotifications.php +++ b/src/Module/BaseNotifications.php @@ -8,7 +8,7 @@ use Friendica\Content\Pager; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\DI; -use Friendica\Model\Notify; +use Friendica\Model\Notification; use Friendica\Network\HTTPException\ForbiddenException; /** @@ -20,29 +20,29 @@ abstract class BaseNotifications extends BaseModule { /** @var array Array of URL parameters */ const URL_TYPES = [ - Notify::NETWORK => 'network', - Notify::SYSTEM => 'system', - Notify::HOME => 'home', - Notify::PERSONAL => 'personal', - Notify::INTRO => 'intros', + Notification::NETWORK => 'network', + Notification::SYSTEM => 'system', + Notification::HOME => 'home', + Notification::PERSONAL => 'personal', + Notification::INTRO => 'intros', ]; /** @var array Array of the allowed notifies and their printable name */ const PRINT_TYPES = [ - Notify::NETWORK => 'Network', - Notify::SYSTEM => 'System', - Notify::HOME => 'Home', - Notify::PERSONAL => 'Personal', - Notify::INTRO => 'Introductions', + Notification::NETWORK => 'Network', + Notification::SYSTEM => 'System', + Notification::HOME => 'Home', + Notification::PERSONAL => 'Personal', + Notification::INTRO => 'Introductions', ]; - /** @var array The array of access keys for notify pages */ + /** @var array The array of access keys for notification pages */ const ACCESS_KEYS = [ - Notify::NETWORK => 'w', - Notify::SYSTEM => 'y', - Notify::HOME => 'h', - Notify::PERSONAL => 'r', - Notify::INTRO => 'i', + Notification::NETWORK => 'w', + Notification::SYSTEM => 'y', + Notification::HOME => 'h', + Notification::PERSONAL => 'r', + Notification::INTRO => 'i', ]; /** @var int The default count of items per page */ @@ -54,12 +54,12 @@ abstract class BaseNotifications extends BaseModule protected static $firstItemNum; /** - * Collects all notifies from the backend + * Collects all notifications from the backend * * @return array The determined notification array - * ['header', 'notifs'] + * ['header', 'notifications'] */ - abstract public static function getNotifies(); + abstract public static function getNotifications(); public static function init(array $parameters = []) { @@ -104,22 +104,22 @@ abstract class BaseNotifications extends BaseModule return; } - System::jsonExit(static::getNotifies()['notifs'] ?? []); + System::jsonExit(static::getNotifications()['notifs'] ?? []); } /** * Shows the printable result of notifications for a specific tab * - * @param string $notif_header The notification header - * @param array $notif_content The array with the notifications - * @param string $notif_nocontent The string in case there are no notifications - * @param array $notif_show_lnk The possible links at the top + * @param string $header The notification header + * @param array $content The array with the notifications + * @param string $noContent The string in case there are no notifications + * @param array $showLink The possible links at the top * * @return string The rendered output * * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - protected static function printContent(string $notif_header, array $notif_content, string $notif_nocontent, array $notif_show_lnk) + protected static function printContent(string $header, array $content, string $noContent, array $showLink) { // Get the nav tabs for the notification pages $tabs = self::getTabs(); @@ -129,12 +129,12 @@ abstract class BaseNotifications extends BaseModule $notif_tpl = Renderer::getMarkupTemplate('notifications/notifications.tpl'); return Renderer::replaceMacros($notif_tpl, [ - '$notif_header' => $notif_header ?? DI::l10n()->t('Notifications'), + '$notif_header' => $header ?? DI::l10n()->t('Notifications'), '$tabs' => $tabs, - '$notif_content' => $notif_content, - '$notif_nocontent' => $notif_nocontent, - '$notif_show_lnk' => $notif_show_lnk, - '$notif_paginate' => $pager->renderMinimal(count($notif_content)) + '$notif_content' => $content, + '$notif_nocontent' => $noContent, + '$notif_show_lnk' => $showLink, + '$notif_paginate' => $pager->renderMinimal(count($content)) ]); } diff --git a/src/Module/Notifications/Introductions.php b/src/Module/Notifications/Introductions.php index 3a7499a1e5..9b64e76911 100644 --- a/src/Module/Notifications/Introductions.php +++ b/src/Module/Notifications/Introductions.php @@ -18,16 +18,16 @@ class Introductions extends BaseNotifications /** * @inheritDoc */ - public static function getNotifies() + public static function getNotifications() { $id = (int)DI::args()->get(2, 0); $all = DI::args()->get(2) == 'all'; - $notifs = DI::notify()->getIntroList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id); + $notifications = DI::notification()->getIntroList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id); return [ - 'header' => DI::l10n()->t('Notifications'), - 'notifs' => $notifs, + 'header' => DI::l10n()->t('Notifications'), + 'notifications' => $notifications, ]; } @@ -37,52 +37,52 @@ class Introductions extends BaseNotifications $all = DI::args()->get(2) == 'all'; - $notif_content = []; - $notif_nocontent = ''; + $notificationContent = []; + $notificationNoContent = ''; - $notif_result = self::getNotifies(); - $notifs = $notif_result['notifs'] ?? []; - $notif_header = $notif_result['header'] ?? ''; + $notificationResult = self::getNotifications(); + $notifications = $notificationResult['notifications'] ?? []; + $notificationHeader = $notificationResult['header'] ?? ''; - $sugg = Renderer::getMarkupTemplate('notifications/suggestions.tpl'); - $tpl = Renderer::getMarkupTemplate('notifications/intros.tpl'); + $notificationSuggestions = Renderer::getMarkupTemplate('notifications/suggestions.tpl'); + $notificationTemplate = Renderer::getMarkupTemplate('notifications/intros.tpl'); // The link to switch between ignored and normal connection requests - $notif_show_lnk = [ + $notificationShowLink = [ 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'), 'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests')) ]; // Loop through all introduction notifications.This creates an array with the output html for each // introduction - foreach ($notifs['notifications'] as $notif) { + foreach ($notifications['notifications'] as $notification) { // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests. // We have to distinguish between these two because they use different data. - switch ($notif['label']) { + switch ($notification['label']) { case 'friend_suggestion': - $notif_content[] = Renderer::replaceMacros($sugg, [ - '$type' => $notif['label'], + $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [ + '$type' => $notification['label'], '$str_notifytype' => DI::l10n()->t('Notification type:'), - '$notify_type' => $notif['notify_type'], - '$intro_id' => $notif['intro_id'], + '$notify_type' => $notification['notify_type'], + '$intro_id' => $notification['intro_id'], '$lbl_madeby' => DI::l10n()->t('Suggested by:'), - '$madeby' => $notif['madeby'], - '$madeby_url' => $notif['madeby_url'], - '$madeby_zrl' => $notif['madeby_zrl'], - '$madeby_addr' => $notif['madeby_addr'], - '$contact_id' => $notif['contact_id'], - '$photo' => $notif['photo'], - '$fullname' => $notif['name'], - '$url' => $notif['url'], - '$zrl' => $notif['zrl'], + '$madeby' => $notification['madeby'], + '$madeby_url' => $notification['madeby_url'], + '$madeby_zrl' => $notification['madeby_zrl'], + '$madeby_addr' => $notification['madeby_addr'], + '$contact_id' => $notification['contact_id'], + '$photo' => $notification['photo'], + '$fullname' => $notification['name'], + '$url' => $notification['url'], + '$zrl' => $notification['zrl'], '$lbl_url' => DI::l10n()->t('Profile URL'), - '$addr' => $notif['addr'], - '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''], - '$knowyou' => $notif['knowyou'], + '$addr' => $notification['addr'], + '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''], + '$knowyou' => $notification['knowyou'], '$approve' => DI::l10n()->t('Approve'), - '$note' => $notif['note'], - '$request' => $notif['request'], + '$note' => $notification['note'], + '$request' => $notification['request'], '$ignore' => DI::l10n()->t('Ignore'), '$discard' => DI::l10n()->t('Discard'), ]); @@ -90,8 +90,8 @@ class Introductions extends BaseNotifications // Normal connection requests default: - $friend_selected = (($notif['network'] !== Protocol::OSTATUS) ? ' checked="checked" ' : ' disabled '); - $fan_selected = (($notif['network'] === Protocol::OSTATUS) ? ' checked="checked" disabled ' : ''); + $friend_selected = (($notification['network'] !== Protocol::OSTATUS) ? ' checked="checked" ' : ' disabled '); + $fan_selected = (($notification['network'] === Protocol::OSTATUS) ? ' checked="checked" disabled ' : ''); $lbl_knowyou = ''; $knowyou = ''; @@ -99,31 +99,31 @@ class Introductions extends BaseNotifications $helptext2 = ''; $helptext3 = ''; - if ($notif['network'] === Protocol::DFRN) { + if ($notification['network'] === Protocol::DFRN) { $lbl_knowyou = DI::l10n()->t('Claims to be known to you: '); - $knowyou = (($notif['knowyou']) ? DI::l10n()->t('yes') : DI::l10n()->t('no')); + $knowyou = (($notification['knowyou']) ? DI::l10n()->t('yes') : DI::l10n()->t('no')); $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?'); - $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notif['name'], $notif['name']); - $helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notif['name']); - } elseif ($notif['network'] === Protocol::DIASPORA) { + $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification['name'], $notification['name']); + $helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification['name']); + } elseif ($notification['network'] === Protocol::DIASPORA) { $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?'); - $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notif['name'], $notif['name']); - $helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notif['name']); + $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification['name'], $notification['name']); + $helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification['name']); } $dfrn_tpl = Renderer::getMarkupTemplate('notifications/netfriend.tpl'); $dfrn_text = Renderer::replaceMacros($dfrn_tpl, [ - '$intro_id' => $notif['intro_id'], + '$intro_id' => $notification['intro_id'], '$friend_selected' => $friend_selected, '$fan_selected' => $fan_selected, '$approve_as1' => $helptext, '$approve_as2' => $helptext2, '$approve_as3' => $helptext3, '$as_friend' => DI::l10n()->t('Friend'), - '$as_fan' => (($notif['network'] == Protocol::DIASPORA) ? DI::l10n()->t('Sharer') : DI::l10n()->t('Subscriber')) + '$as_fan' => (($notification['network'] == Protocol::DIASPORA) ? DI::l10n()->t('Sharer') : DI::l10n()->t('Subscriber')) ]); - $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notif['contact_id']]); + $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notification['contact_id']]); if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) { $action = 'follow_confirm'; @@ -131,51 +131,51 @@ class Introductions extends BaseNotifications $action = 'dfrn_confirm'; } - $header = $notif['name']; + $header = $notification['name']; - if ($notif['addr'] != '') { - $header .= ' <' . $notif['addr'] . '>'; + if ($notification['addr'] != '') { + $header .= ' <' . $notification['addr'] . '>'; } - $header .= ' (' . ContactSelector::networkToName($notif['network'], $notif['url']) . ')'; + $header .= ' (' . ContactSelector::networkToName($notification['network'], $notification['url']) . ')'; - if ($notif['network'] != Protocol::DIASPORA) { + if ($notification['network'] != Protocol::DIASPORA) { $discard = DI::l10n()->t('Discard'); } else { $discard = ''; } - $notif_content[] = Renderer::replaceMacros($tpl, [ - '$type' => $notif['label'], + $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [ + '$type' => $notification['label'], '$header' => $header, '$str_notifytype' => DI::l10n()->t('Notification type:'), - '$notify_type' => $notif['notify_type'], + '$notify_type' => $notification['notify_type'], '$dfrn_text' => $dfrn_text, - '$dfrn_id' => $notif['dfrn_id'], - '$uid' => $notif['uid'], - '$intro_id' => $notif['intro_id'], - '$contact_id' => $notif['contact_id'], - '$photo' => $notif['photo'], - '$fullname' => $notif['name'], - '$location' => $notif['location'], + '$dfrn_id' => $notification['dfrn_id'], + '$uid' => $notification['uid'], + '$intro_id' => $notification['intro_id'], + '$contact_id' => $notification['contact_id'], + '$photo' => $notification['photo'], + '$fullname' => $notification['name'], + '$location' => $notification['location'], '$lbl_location' => DI::l10n()->t('Location:'), - '$about' => $notif['about'], + '$about' => $notification['about'], '$lbl_about' => DI::l10n()->t('About:'), - '$keywords' => $notif['keywords'], + '$keywords' => $notification['keywords'], '$lbl_keywords' => DI::l10n()->t('Tags:'), - '$gender' => $notif['gender'], + '$gender' => $notification['gender'], '$lbl_gender' => DI::l10n()->t('Gender:'), - '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''], - '$url' => $notif['url'], - '$zrl' => $notif['zrl'], + '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''], + '$url' => $notification['url'], + '$zrl' => $notification['zrl'], '$lbl_url' => DI::l10n()->t('Profile URL'), - '$addr' => $notif['addr'], + '$addr' => $notification['addr'], '$lbl_knowyou' => $lbl_knowyou, '$lbl_network' => DI::l10n()->t('Network:'), - '$network' => ContactSelector::networkToName($notif['network'], $notif['url']), + '$network' => ContactSelector::networkToName($notification['network'], $notification['url']), '$knowyou' => $knowyou, '$approve' => DI::l10n()->t('Approve'), - '$note' => $notif['note'], + '$note' => $notification['note'], '$ignore' => DI::l10n()->t('Ignore'), '$discard' => $discard, '$action' => $action, @@ -184,11 +184,11 @@ class Introductions extends BaseNotifications } } - if (count($notifs['notifications']) == 0) { + if (count($notifications['notifications']) == 0) { info(DI::l10n()->t('No introductions.') . EOL); - $notif_nocontent = DI::l10n()->t('No more %s notifications.', $notifs['ident']); + $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']); } - return self::printContent($notif_header, $notif_content, $notif_nocontent, $notif_show_lnk); + return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink); } } diff --git a/src/Module/Notifications/Notify.php b/src/Module/Notifications/Notification.php similarity index 71% rename from src/Module/Notifications/Notify.php rename to src/Module/Notifications/Notification.php index 3c1b6a03ee..2f3f927f9c 100644 --- a/src/Module/Notifications/Notify.php +++ b/src/Module/Notifications/Notification.php @@ -8,9 +8,9 @@ use Friendica\DI; use Friendica\Network\HTTPException; /** - * Interacting with the /notify command + * Interacting with the /notification command */ -class Notify extends BaseModule +class Notification extends BaseModule { public static function init(array $parameters = []) { @@ -21,11 +21,9 @@ class Notify extends BaseModule public static function rawContent(array $parameters = []) { - $a = DI::app(); - // @TODO: Replace with parameter from router - if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') { - $success = DI::notify()->setAllSeen(); + if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') { + $success = DI::notification()->setAllSeen(); header('Content-type: application/json; charset=utf-8'); echo json_encode([ @@ -36,22 +34,20 @@ class Notify extends BaseModule } /** - * Redirect to the notifications main page or to the url for the chosen notify + * Redirect to the notifications main page or to the url for the chosen notifications * * @return string|void * @throws HTTPException\InternalServerErrorException */ public static function content(array $parameters = []) { - $a = DI::app(); - // @TODO: Replace with parameter from router - if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) { - $notificationsManager = DI::notify(); + if (DI::args()->getArgc() > 2 && DI::args()->get(1) === 'view' && intval(DI::args()->get(2))) { + $notificationManager = DI::notification(); // @TODO: Replace with parameter from router - $note = $notificationsManager->getByID($a->argv[2]); + $note = $notificationManager->getByID(DI::args()->get(2)); if (!empty($note)) { - $notificationsManager->setSeen($note); + $notificationManager->setSeen($note); if (!empty($note['link'])) { System::externalRedirect($note['link']); } diff --git a/src/Module/Notifications/Notifications.php b/src/Module/Notifications/Notifications.php index bfccbd4e70..432ae93aea 100644 --- a/src/Module/Notifications/Notifications.php +++ b/src/Module/Notifications/Notifications.php @@ -20,31 +20,31 @@ class Notifications extends BaseNotifications /** * {@inheritDoc} */ - public static function getNotifies() + public static function getNotifications() { - $nm = DI::notify(); + $nm = DI::notification(); - $notif_header = ''; + $notificationHeader = ''; // Get the network notifications if ((DI::args()->get(1) == 'network')) { - $notif_header = DI::l10n()->t('Network Notifications'); - $notifs = $nm->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); + $notificationHeader = DI::l10n()->t('Network Notifications'); + $notifications = $nm->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); // Get the system notifications } elseif ((DI::args()->get(1) == 'system')) { - $notif_header = DI::l10n()->t('System Notifications'); - $notifs = $nm->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); + $notificationHeader = DI::l10n()->t('System Notifications'); + $notifications = $nm->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); // Get the personal notifications } elseif ((DI::args()->get(1) == 'personal')) { - $notif_header = DI::l10n()->t('Personal Notifications'); - $notifs = $nm->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); + $notificationHeader = DI::l10n()->t('Personal Notifications'); + $notifications = $nm->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); // Get the home notifications } elseif ((DI::args()->get(1) == 'home')) { - $notif_header = DI::l10n()->t('Home Notifications'); - $notifs = $nm->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); + $notificationHeader = DI::l10n()->t('Home Notifications'); + $notifications = $nm->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); // fallback - redirect to main page } else { DI::baseUrl()->redirect('notifications'); @@ -54,12 +54,12 @@ class Notifications extends BaseNotifications $pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE); // Add additional informations (needed for json output) - $notifs['items_page'] = $pager->getItemsPerPage(); - $notifs['page'] = $pager->getPage(); + $notifications['items_page'] = $pager->getItemsPerPage(); + $notifications['page'] = $pager->getPage(); return [ - 'header' => $notif_header, - 'notifs' => $notifs, + 'header' => $notificationHeader, + 'notifications' => $notifications, ]; } @@ -67,18 +67,18 @@ class Notifications extends BaseNotifications { Nav::setSelected('notifications'); - $notif_content = []; - $notif_nocontent = ''; + $notificationContent = []; + $notificationNoContent = ''; - $notif_result = self::getNotifies(); - $notifs = $notif_result['notifs'] ?? []; - $notif_header = $notif_result['header'] ?? ''; + $notificationResult = self::getNotifications(); + $notifications = $notificationResult['notifications'] ?? []; + $notificationHeader = $notificationResult['header'] ?? ''; - if (!empty($notifs['notifications'])) { + if (!empty($notifications['notifications'])) { // 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). - foreach ($notifs['notifications'] as $notif) { + foreach ($notifications['notifications'] as $notification) { $notification_templates = [ 'like' => 'notifications/likes_item.tpl', 'dislike' => 'notifications/dislikes_item.tpl', @@ -88,31 +88,31 @@ class Notifications extends BaseNotifications 'friend' => 'notifications/friends_item.tpl', 'comment' => 'notifications/comments_item.tpl', 'post' => 'notifications/posts_item.tpl', - 'notify' => 'notifications/notify.tpl', + 'notification' => 'notifications/notification.tpl', ]; - $tpl_notif = Renderer::getMarkupTemplate($notification_templates[$notif['label']]); + $notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notification['label']]); - $notif_content[] = Renderer::replaceMacros($tpl_notif, [ - '$item_label' => $notif['label'], - '$item_link' => $notif['link'], - '$item_image' => $notif['image'], - '$item_url' => $notif['url'], - '$item_text' => $notif['text'], - '$item_when' => $notif['when'], - '$item_ago' => $notif['ago'], - '$item_seen' => $notif['seen'], + $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [ + '$item_label' => $notification['label'], + '$item_link' => $notification['link'], + '$item_image' => $notification['image'], + '$item_url' => $notification['url'], + '$item_text' => $notification['text'], + '$item_when' => $notification['when'], + '$item_ago' => $notification['ago'], + '$item_seen' => $notification['seen'], ]); } } else { - $notif_nocontent = DI::l10n()->t('No more %s notifications.', $notifs['ident']); + $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']); } - $notif_show_lnk = [ - 'href' => (self::$showAll ? 'notifications/' . $notifs['ident'] : 'notifications/' . $notifs['ident'] . '?show=all'), + $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')), ]; - return self::printContent($notif_header, $notif_content, $notif_nocontent, $notif_show_lnk); + return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink); } } diff --git a/static/routes.config.php b/static/routes.config.php index 44502cdfb2..f453856581 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -177,10 +177,10 @@ return [ '/intros/{contact:\d+}[/json]' => [Module\Notifications\Introductions::class, [R::GET, R::POST]], ], - '/notify' => [ - '[/]' => [Module\Notifications\Notify::class, [R::GET]], - '/view/{id:\d+}' => [Module\Notifications\Notify::class, [R::GET]], - '/mark/all' => [Module\Notifications\Notify::class, [R::GET]], + '/notification' => [ + '[/]' => [Module\Notifications\Notification::class, [R::GET]], + '/view/{id:\d+}' => [Module\Notifications\Notification::class, [R::GET]], + '/mark/all' => [Module\Notifications\Notification::class, [R::GET]], ], '/objects/{guid}' => [Module\Objects::class, [R::GET]], diff --git a/view/js/main.js b/view/js/main.js index 81d26120e7..c12156e4f8 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -949,7 +949,7 @@ function checkboxhighlight(box) { } function notifyMarkAll() { - $.get('notify/mark/all', function(data) { + $.get('notification/mark/all', function(data) { if (timer) { clearTimeout(timer); } diff --git a/view/templates/notifications/notify.tpl b/view/templates/notifications/notification.tpl similarity index 100% rename from view/templates/notifications/notify.tpl rename to view/templates/notifications/notification.tpl diff --git a/view/theme/frio/templates/notifications/attend_item.tpl b/view/theme/frio/templates/notifications/attend_item.tpl index 252b61c776..bb88e87ada 100644 --- a/view/theme/frio/templates/notifications/attend_item.tpl +++ b/view/theme/frio/templates/notifications/attend_item.tpl @@ -1,2 +1,2 @@ -{{include file="notifications/notify.tpl"}} +{{include file="notifications/notification.tpl"}} diff --git a/view/theme/frio/templates/notifications/comments_item.tpl b/view/theme/frio/templates/notifications/comments_item.tpl index 252b61c776..bb88e87ada 100644 --- a/view/theme/frio/templates/notifications/comments_item.tpl +++ b/view/theme/frio/templates/notifications/comments_item.tpl @@ -1,2 +1,2 @@ -{{include file="notifications/notify.tpl"}} +{{include file="notifications/notification.tpl"}} diff --git a/view/theme/frio/templates/notifications/dislikes_item.tpl b/view/theme/frio/templates/notifications/dislikes_item.tpl index 252b61c776..bb88e87ada 100644 --- a/view/theme/frio/templates/notifications/dislikes_item.tpl +++ b/view/theme/frio/templates/notifications/dislikes_item.tpl @@ -1,2 +1,2 @@ -{{include file="notifications/notify.tpl"}} +{{include file="notifications/notification.tpl"}} diff --git a/view/theme/frio/templates/notifications/friends_item.tpl b/view/theme/frio/templates/notifications/friends_item.tpl index 252b61c776..bb88e87ada 100644 --- a/view/theme/frio/templates/notifications/friends_item.tpl +++ b/view/theme/frio/templates/notifications/friends_item.tpl @@ -1,2 +1,2 @@ -{{include file="notifications/notify.tpl"}} +{{include file="notifications/notification.tpl"}} diff --git a/view/theme/frio/templates/notifications/likes_item.tpl b/view/theme/frio/templates/notifications/likes_item.tpl index 252b61c776..bb88e87ada 100644 --- a/view/theme/frio/templates/notifications/likes_item.tpl +++ b/view/theme/frio/templates/notifications/likes_item.tpl @@ -1,2 +1,2 @@ -{{include file="notifications/notify.tpl"}} +{{include file="notifications/notification.tpl"}} diff --git a/view/theme/frio/templates/notifications/network_item.tpl b/view/theme/frio/templates/notifications/network_item.tpl index 252b61c776..bb88e87ada 100644 --- a/view/theme/frio/templates/notifications/network_item.tpl +++ b/view/theme/frio/templates/notifications/network_item.tpl @@ -1,2 +1,2 @@ -{{include file="notifications/notify.tpl"}} +{{include file="notifications/notification.tpl"}} diff --git a/view/theme/frio/templates/notifications/posts_item.tpl b/view/theme/frio/templates/notifications/posts_item.tpl index 252b61c776..bb88e87ada 100644 --- a/view/theme/frio/templates/notifications/posts_item.tpl +++ b/view/theme/frio/templates/notifications/posts_item.tpl @@ -1,2 +1,2 @@ -{{include file="notifications/notify.tpl"}} +{{include file="notifications/notification.tpl"}} From 16b1d3fc08dc393763e0de1438481c0d285d8e90 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 24 Jan 2020 18:34:29 +0100 Subject: [PATCH 07/10] Notifies => Notifications --- src/Model/Notification.php | 52 ++++++++++++++++---------------- src/Module/BaseNotifications.php | 2 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Model/Notification.php b/src/Model/Notification.php index b31014a599..b7e10a0f31 100644 --- a/src/Model/Notification.php +++ b/src/Model/Notification.php @@ -27,7 +27,7 @@ use Friendica\Network\HTTPException; */ final class Notification { - /** @var int The default limit of notifies per page */ + /** @var int The default limit of notifications per page */ const DEFAULT_PAGE_LIMIT = 80; const NETWORK = 'network'; @@ -110,10 +110,10 @@ final class Notification $dbFilter = array_merge($filter, ['uid' => local_user()]); - $stmtNotifies = $this->dba->select('notify', [], $dbFilter, $params); + $stmtNotifications = $this->dba->select('notify', [], $dbFilter, $params); - if ($this->dba->isResult($stmtNotifies)) { - return $this->setExtra($this->dba->toArray($stmtNotifies)); + if ($this->dba->isResult($stmtNotifications)) { + return $this->setExtra($this->dba->toArray($stmtNotifications)); } return false; @@ -188,7 +188,7 @@ final class Notification */ private function formatList(array $notifications, string $ident = "") { - $formattedNotifies = []; + $formattedNotifications = []; foreach ($notifications as $notification) { // Because we use different db tables for the notification query @@ -350,10 +350,10 @@ final class Notification ]; } - $formattedNotifies[] = $formattedNotify; + $formattedNotifications[] = $formattedNotify; } - return $formattedNotifies; + return $formattedNotifications; } /** @@ -373,7 +373,7 @@ final class Notification public function getNetworkList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT) { $ident = self::NETWORK; - $notifies = []; + $notifications = []; $condition = ['wall' => false, 'uid' => local_user()]; @@ -388,11 +388,11 @@ final class Notification $items = Item::selectForUser(local_user(), $fields, $condition, $params); if ($this->dba->isResult($items)) { - $notifies = $this->formatList(Item::inArray($items), $ident); + $notifications = $this->formatList(Item::inArray($items), $ident); } $arr = [ - 'notifications' => $notifies, + 'notifications' => $notifications, 'ident' => $ident, ]; @@ -416,7 +416,7 @@ final class Notification public function getSystemList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT) { $ident = self::SYSTEM; - $notifies = []; + $notifications = []; $filter = ['uid' => local_user()]; if (!$seen) { @@ -427,17 +427,17 @@ final class Notification $params['order'] = ['date' => 'DESC']; $params['limit'] = [$start, $limit]; - $stmtNotifies = $this->dba->select('notify', + $stmtNotifications = $this->dba->select('notify', ['id', 'url', 'photo', 'msg', 'date', 'seen', 'verb'], $filter, $params); - if ($this->dba->isResult($stmtNotifies)) { - $notifies = $this->formatList($this->dba->toArray($stmtNotifies), $ident); + if ($this->dba->isResult($stmtNotifications)) { + $notifications = $this->formatList($this->dba->toArray($stmtNotifications), $ident); } $arr = [ - 'notifications' => $notifies, + 'notifications' => $notifications, 'ident' => $ident, ]; @@ -461,7 +461,7 @@ final class Notification public function getPersonalList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT) { $ident = self::PERSONAL; - $notifies = []; + $notifications = []; $myurl = str_replace('http://', '', DI::app()->contact['nurl']); $diasp_url = str_replace('/profile/', '/u/', $myurl); @@ -480,11 +480,11 @@ final class Notification $items = Item::selectForUser(local_user(), $fields, $condition, $params); if ($this->dba->isResult($items)) { - $notifies = $this->formatList(Item::inArray($items), $ident); + $notifications = $this->formatList(Item::inArray($items), $ident); } $arr = [ - 'notifications' => $notifies, + 'notifications' => $notifications, 'ident' => $ident, ]; @@ -508,7 +508,7 @@ final class Notification public function getHomeList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT) { $ident = self::HOME; - $notifies = []; + $notifications = []; $condition = ['wall' => true, 'uid' => local_user()]; @@ -523,11 +523,11 @@ final class Notification $items = Item::selectForUser(local_user(), $fields, $condition, $params); if ($this->dba->isResult($items)) { - $notifies = $this->formatList(Item::inArray($items), $ident); + $notifications = $this->formatList(Item::inArray($items), $ident); } $arr = [ - 'notifications' => $notifies, + 'notifications' => $notifications, 'ident' => $ident, ]; @@ -554,7 +554,7 @@ final class Notification { /// @todo sanitize wording according to SELF::INTRO $ident = 'introductions'; - $notifies = []; + $notifications = []; $sql_extra = ""; if (empty($id)) { @@ -568,7 +568,7 @@ final class Notification } /// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact - $stmtNotifies = $this->dba->p( + $stmtNotifications = $this->dba->p( "SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*, `fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`, `fcontact`.`addr` AS `faddr`, `fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`, @@ -585,13 +585,13 @@ final class Notification $start, $limit ); - if ($this->dba->isResult($stmtNotifies)) { - $notifies = $this->formatIntroList($this->dba->toArray($stmtNotifies)); + if ($this->dba->isResult($stmtNotifications)) { + $notifications = $this->formatIntroList($this->dba->toArray($stmtNotifications)); } $arr = [ 'ident' => $ident, - 'notifications' => $notifies, + 'notifications' => $notifications, ]; return $arr; diff --git a/src/Module/BaseNotifications.php b/src/Module/BaseNotifications.php index 2133a3b880..a0c49a0646 100644 --- a/src/Module/BaseNotifications.php +++ b/src/Module/BaseNotifications.php @@ -27,7 +27,7 @@ abstract class BaseNotifications extends BaseModule Notification::INTRO => 'intros', ]; - /** @var array Array of the allowed notifies and their printable name */ + /** @var array Array of the allowed notifications and their printable name */ const PRINT_TYPES = [ Notification::NETWORK => 'Network', Notification::SYSTEM => 'System', From b016e420fea8f40e4e7f9279c5789bfcf68fbbe1 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 24 Jan 2020 18:39:50 +0100 Subject: [PATCH 08/10] notify_type => str_type str_notifytype => st_notification_type --- src/Model/Notification.php | 4 ++-- src/Module/Notifications/Introductions.php | 8 ++++---- view/templates/notifications/intros.tpl | 2 +- view/templates/notifications/suggestions.tpl | 2 +- view/theme/frio/templates/notifications/intros.tpl | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Model/Notification.php b/src/Model/Notification.php index b7e10a0f31..8b0e0f1a51 100644 --- a/src/Model/Notification.php +++ b/src/Model/Notification.php @@ -623,7 +623,7 @@ final class Notification $intro = [ 'label' => 'friend_suggestion', - 'notify_type' => $this->l10n->t('Friend Suggestion'), + 'str_type' => $this->l10n->t('Friend Suggestion'), 'intro_id' => $intro['intro_id'], 'madeby' => $intro['name'], 'madeby_url' => $intro['url'], @@ -657,7 +657,7 @@ final class Notification } $intro = [ 'label' => (($intro['network'] !== Protocol::OSTATUS) ? 'friend_request' : 'follower'), - 'notify_type' => (($intro['network'] !== Protocol::OSTATUS) ? $this->l10n->t('Friend/Connect Request') : $this->l10n->t('New Follower')), + 'str_type' => (($intro['network'] !== Protocol::OSTATUS) ? $this->l10n->t('Friend/Connect Request') : $this->l10n->t('New Follower')), 'dfrn_id' => $intro['issued-id'], 'uid' => $_SESSION['uid'], 'intro_id' => $intro['intro_id'], diff --git a/src/Module/Notifications/Introductions.php b/src/Module/Notifications/Introductions.php index 9b64e76911..dc62110e2b 100644 --- a/src/Module/Notifications/Introductions.php +++ b/src/Module/Notifications/Introductions.php @@ -63,8 +63,8 @@ class Introductions extends BaseNotifications case 'friend_suggestion': $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [ '$type' => $notification['label'], - '$str_notifytype' => DI::l10n()->t('Notification type:'), - '$notify_type' => $notification['notify_type'], + 'str_notification_type' => DI::l10n()->t('Notification type:'), + 'str_type' => $notification['str_type'], '$intro_id' => $notification['intro_id'], '$lbl_madeby' => DI::l10n()->t('Suggested by:'), '$madeby' => $notification['madeby'], @@ -148,8 +148,8 @@ class Introductions extends BaseNotifications $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [ '$type' => $notification['label'], '$header' => $header, - '$str_notifytype' => DI::l10n()->t('Notification type:'), - '$notify_type' => $notification['notify_type'], + 'str_notification_type' => DI::l10n()->t('Notification type:'), + 'str_type' => $notification['notifytype'], '$dfrn_text' => $dfrn_text, '$dfrn_id' => $notification['dfrn_id'], '$uid' => $notification['uid'], diff --git a/view/templates/notifications/intros.tpl b/view/templates/notifications/intros.tpl index 1f7f838bcf..808f155b9d 100644 --- a/view/templates/notifications/intros.tpl +++ b/view/templates/notifications/intros.tpl @@ -2,7 +2,7 @@
-

{{$str_notifytype}} {{$notify_type}}

+

{{$str_notification_type}} {{$str_type}}

{{$fullname}}
{{$lbl_url}}
{{$url}}
{{if $location}}
{{$lbl_location}}
{{$location}}
{{/if}} diff --git a/view/templates/notifications/suggestions.tpl b/view/templates/notifications/suggestions.tpl index 44fe865104..d7bb7b6019 100644 --- a/view/templates/notifications/suggestions.tpl +++ b/view/templates/notifications/suggestions.tpl @@ -2,7 +2,7 @@
-

{{$str_notifytype}} {{$notify_type}}

+

{{$str_notification_type}} {{$str_type}}

{{if $madeby}}
{{$lbl_madeby}} {{$madeby}}
{{/if}}
{{$fullname}}
{{$fullname}} diff --git a/view/theme/frio/templates/notifications/intros.tpl b/view/theme/frio/templates/notifications/intros.tpl index a8a033c9b5..4bab6fa964 100644 --- a/view/theme/frio/templates/notifications/intros.tpl +++ b/view/theme/frio/templates/notifications/intros.tpl @@ -19,7 +19,7 @@
-
{{$str_notifytype}} {{$notify_type}}
+
{{$str_notification_type}} {{$str_type}}
{{* if the contact was suggestested by another contact, the contact who made the suggestion is displayed*}} {{if $madeby}}
{{$lbl_madeby}} {{$madeby}}
{{/if}} From b229939c3d3649a0757c3f42452dccf5341ee13b Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 24 Jan 2020 18:56:34 +0100 Subject: [PATCH 09/10] rename CSS attributes notify => notification --- src/Model/Notification.php | 18 +-- src/Module/BaseNotifications.php | 22 ++-- src/Module/Notifications/Introductions.php | 108 +++++++++--------- src/Module/Notifications/Notifications.php | 18 +-- view/global.css | 2 +- view/js/main.js | 20 ++-- view/templates/nav.tpl | 4 +- .../templates/notifications/notifications.tpl | 14 +-- view/templates/settings/settings.tpl | 2 +- view/theme/duepuntozero/deriv/darkzero.css | 2 +- view/theme/duepuntozero/style.css | 10 +- view/theme/duepuntozero/templates/nav.tpl | 4 +- view/theme/frio/css/style.css | 6 +- view/theme/frio/scheme/plusminus.css | 2 +- view/theme/frio/templates/nav.tpl | 14 +-- .../templates/notifications/notifications.tpl | 14 +-- .../frio/templates/settings/settings.tpl | 2 +- view/theme/quattro/dark/style.css | 6 +- view/theme/quattro/green/style.css | 6 +- view/theme/quattro/lilac/style.css | 6 +- view/theme/quattro/quattro.less | 4 +- view/theme/quattro/templates/nav.tpl | 10 +- view/theme/smoothly/style.css | 12 +- view/theme/smoothly/templates/nav.tpl | 4 +- view/theme/vier/dark.css | 6 +- view/theme/vier/plus.css | 4 +- view/theme/vier/plusminus.css | 4 +- view/theme/vier/shadow.css | 4 +- view/theme/vier/style.css | 12 +- view/theme/vier/templates/nav.tpl | 14 +-- 30 files changed, 177 insertions(+), 177 deletions(-) diff --git a/src/Model/Notification.php b/src/Model/Notification.php index 8b0e0f1a51..408f794972 100644 --- a/src/Model/Notification.php +++ b/src/Model/Notification.php @@ -372,7 +372,7 @@ final class Notification */ public function getNetworkList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT) { - $ident = self::NETWORK; + $ident = self::NETWORK; $notifications = []; $condition = ['wall' => false, 'uid' => local_user()]; @@ -415,7 +415,7 @@ final class Notification */ public function getSystemList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT) { - $ident = self::SYSTEM; + $ident = self::SYSTEM; $notifications = []; $filter = ['uid' => local_user()]; @@ -460,7 +460,7 @@ final class Notification */ public function getPersonalList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT) { - $ident = self::PERSONAL; + $ident = self::PERSONAL; $notifications = []; $myurl = str_replace('http://', '', DI::app()->contact['nurl']); @@ -507,7 +507,7 @@ final class Notification */ public function getHomeList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT) { - $ident = self::HOME; + $ident = self::HOME; $notifications = []; $condition = ['wall' => true, 'uid' => local_user()]; @@ -553,9 +553,9 @@ final class Notification public function getIntroList(bool $all = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT, int $id = 0) { /// @todo sanitize wording according to SELF::INTRO - $ident = 'introductions'; - $notifications = []; - $sql_extra = ""; + $ident = 'introductions'; + $notifications = []; + $sql_extra = ""; if (empty($id)) { if (!$all) { @@ -623,7 +623,7 @@ final class Notification $intro = [ 'label' => 'friend_suggestion', - 'str_type' => $this->l10n->t('Friend Suggestion'), + 'str_type' => $this->l10n->t('Friend Suggestion'), 'intro_id' => $intro['intro_id'], 'madeby' => $intro['name'], 'madeby_url' => $intro['url'], @@ -657,7 +657,7 @@ final class Notification } $intro = [ 'label' => (($intro['network'] !== Protocol::OSTATUS) ? 'friend_request' : 'follower'), - 'str_type' => (($intro['network'] !== Protocol::OSTATUS) ? $this->l10n->t('Friend/Connect Request') : $this->l10n->t('New Follower')), + 'str_type' => (($intro['network'] !== Protocol::OSTATUS) ? $this->l10n->t('Friend/Connect Request') : $this->l10n->t('New Follower')), 'dfrn_id' => $intro['issued-id'], 'uid' => $_SESSION['uid'], 'intro_id' => $intro['intro_id'], diff --git a/src/Module/BaseNotifications.php b/src/Module/BaseNotifications.php index a0c49a0646..728a9d402d 100644 --- a/src/Module/BaseNotifications.php +++ b/src/Module/BaseNotifications.php @@ -110,16 +110,16 @@ abstract class BaseNotifications extends BaseModule /** * Shows the printable result of notifications for a specific tab * - * @param string $header The notification header - * @param array $content The array with the notifications - * @param string $noContent The string in case there are no notifications - * @param array $showLink The possible links at the top + * @param string $header The notification header + * @param array $notifications The array with the notifications + * @param string $noContent The string in case there are no notifications + * @param array $showLink The possible links at the top * * @return string The rendered output * * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - protected static function printContent(string $header, array $content, string $noContent, array $showLink) + protected static function printContent(string $header, array $notifications, string $noContent, array $showLink) { // Get the nav tabs for the notification pages $tabs = self::getTabs(); @@ -129,12 +129,12 @@ abstract class BaseNotifications extends BaseModule $notif_tpl = Renderer::getMarkupTemplate('notifications/notifications.tpl'); return Renderer::replaceMacros($notif_tpl, [ - '$notif_header' => $header ?? DI::l10n()->t('Notifications'), - '$tabs' => $tabs, - '$notif_content' => $content, - '$notif_nocontent' => $noContent, - '$notif_show_lnk' => $showLink, - '$notif_paginate' => $pager->renderMinimal(count($content)) + '$header' => $header ?? DI::l10n()->t('Notifications'), + '$tabs' => $tabs, + '$notifications' => $notifications, + '$noContent' => $noContent, + '$showLink' => $showLink, + '$paginate' => $pager->renderMinimal(count($notifications)) ]); } diff --git a/src/Module/Notifications/Introductions.php b/src/Module/Notifications/Introductions.php index dc62110e2b..99066bd3c9 100644 --- a/src/Module/Notifications/Introductions.php +++ b/src/Module/Notifications/Introductions.php @@ -62,29 +62,29 @@ class Introductions extends BaseNotifications switch ($notification['label']) { case 'friend_suggestion': $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [ - '$type' => $notification['label'], + '$type' => $notification['label'], 'str_notification_type' => DI::l10n()->t('Notification type:'), - 'str_type' => $notification['str_type'], - '$intro_id' => $notification['intro_id'], - '$lbl_madeby' => DI::l10n()->t('Suggested by:'), - '$madeby' => $notification['madeby'], - '$madeby_url' => $notification['madeby_url'], - '$madeby_zrl' => $notification['madeby_zrl'], - '$madeby_addr' => $notification['madeby_addr'], - '$contact_id' => $notification['contact_id'], - '$photo' => $notification['photo'], - '$fullname' => $notification['name'], - '$url' => $notification['url'], - '$zrl' => $notification['zrl'], - '$lbl_url' => DI::l10n()->t('Profile URL'), - '$addr' => $notification['addr'], - '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''], - '$knowyou' => $notification['knowyou'], - '$approve' => DI::l10n()->t('Approve'), - '$note' => $notification['note'], - '$request' => $notification['request'], - '$ignore' => DI::l10n()->t('Ignore'), - '$discard' => DI::l10n()->t('Discard'), + 'str_type' => $notification['str_type'], + '$intro_id' => $notification['intro_id'], + '$lbl_madeby' => DI::l10n()->t('Suggested by:'), + '$madeby' => $notification['madeby'], + '$madeby_url' => $notification['madeby_url'], + '$madeby_zrl' => $notification['madeby_zrl'], + '$madeby_addr' => $notification['madeby_addr'], + '$contact_id' => $notification['contact_id'], + '$photo' => $notification['photo'], + '$fullname' => $notification['name'], + '$url' => $notification['url'], + '$zrl' => $notification['zrl'], + '$lbl_url' => DI::l10n()->t('Profile URL'), + '$addr' => $notification['addr'], + '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''], + '$knowyou' => $notification['knowyou'], + '$approve' => DI::l10n()->t('Approve'), + '$note' => $notification['note'], + '$request' => $notification['request'], + '$ignore' => DI::l10n()->t('Ignore'), + '$discard' => DI::l10n()->t('Discard'), ]); break; @@ -146,39 +146,39 @@ class Introductions extends BaseNotifications } $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [ - '$type' => $notification['label'], - '$header' => $header, + '$type' => $notification['label'], + '$header' => $header, 'str_notification_type' => DI::l10n()->t('Notification type:'), - 'str_type' => $notification['notifytype'], - '$dfrn_text' => $dfrn_text, - '$dfrn_id' => $notification['dfrn_id'], - '$uid' => $notification['uid'], - '$intro_id' => $notification['intro_id'], - '$contact_id' => $notification['contact_id'], - '$photo' => $notification['photo'], - '$fullname' => $notification['name'], - '$location' => $notification['location'], - '$lbl_location' => DI::l10n()->t('Location:'), - '$about' => $notification['about'], - '$lbl_about' => DI::l10n()->t('About:'), - '$keywords' => $notification['keywords'], - '$lbl_keywords' => DI::l10n()->t('Tags:'), - '$gender' => $notification['gender'], - '$lbl_gender' => DI::l10n()->t('Gender:'), - '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''], - '$url' => $notification['url'], - '$zrl' => $notification['zrl'], - '$lbl_url' => DI::l10n()->t('Profile URL'), - '$addr' => $notification['addr'], - '$lbl_knowyou' => $lbl_knowyou, - '$lbl_network' => DI::l10n()->t('Network:'), - '$network' => ContactSelector::networkToName($notification['network'], $notification['url']), - '$knowyou' => $knowyou, - '$approve' => DI::l10n()->t('Approve'), - '$note' => $notification['note'], - '$ignore' => DI::l10n()->t('Ignore'), - '$discard' => $discard, - '$action' => $action, + 'str_type' => $notification['notifytype'], + '$dfrn_text' => $dfrn_text, + '$dfrn_id' => $notification['dfrn_id'], + '$uid' => $notification['uid'], + '$intro_id' => $notification['intro_id'], + '$contact_id' => $notification['contact_id'], + '$photo' => $notification['photo'], + '$fullname' => $notification['name'], + '$location' => $notification['location'], + '$lbl_location' => DI::l10n()->t('Location:'), + '$about' => $notification['about'], + '$lbl_about' => DI::l10n()->t('About:'), + '$keywords' => $notification['keywords'], + '$lbl_keywords' => DI::l10n()->t('Tags:'), + '$gender' => $notification['gender'], + '$lbl_gender' => DI::l10n()->t('Gender:'), + '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''], + '$url' => $notification['url'], + '$zrl' => $notification['zrl'], + '$lbl_url' => DI::l10n()->t('Profile URL'), + '$addr' => $notification['addr'], + '$lbl_knowyou' => $lbl_knowyou, + '$lbl_network' => DI::l10n()->t('Network:'), + '$network' => ContactSelector::networkToName($notification['network'], $notification['url']), + '$knowyou' => $knowyou, + '$approve' => DI::l10n()->t('Approve'), + '$note' => $notification['note'], + '$ignore' => DI::l10n()->t('Ignore'), + '$discard' => $discard, + '$action' => $action, ]); break; } diff --git a/src/Module/Notifications/Notifications.php b/src/Module/Notifications/Notifications.php index 432ae93aea..3dffe90b5b 100644 --- a/src/Module/Notifications/Notifications.php +++ b/src/Module/Notifications/Notifications.php @@ -80,15 +80,15 @@ class Notifications extends BaseNotifications // notification and apply the correct template according to the notificationtype (label). foreach ($notifications['notifications'] as $notification) { $notification_templates = [ - 'like' => 'notifications/likes_item.tpl', - 'dislike' => 'notifications/dislikes_item.tpl', - 'attend' => 'notifications/attend_item.tpl', - 'attendno' => 'notifications/attend_item.tpl', - 'attendmaybe' => 'notifications/attend_item.tpl', - 'friend' => 'notifications/friends_item.tpl', - 'comment' => 'notifications/comments_item.tpl', - 'post' => 'notifications/posts_item.tpl', - 'notification' => 'notifications/notification.tpl', + 'like' => 'notifications/likes_item.tpl', + 'dislike' => 'notifications/dislikes_item.tpl', + 'attend' => 'notifications/attend_item.tpl', + 'attendno' => 'notifications/attend_item.tpl', + 'attendmaybe' => 'notifications/attend_item.tpl', + 'friend' => 'notifications/friends_item.tpl', + 'comment' => 'notifications/comments_item.tpl', + 'post' => 'notifications/posts_item.tpl', + 'notification' => 'notifications/notification.tpl', ]; $notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notification['label']]); diff --git a/view/global.css b/view/global.css index 0eaf4482dc..b82ad6e030 100644 --- a/view/global.css +++ b/view/global.css @@ -274,7 +274,7 @@ code, key { } /* notifications unseen */ -.notify-unseen { background-color: #cceeFF; } +.notification-unseen { background-color: #cceeFF; } /* autocomplete popup */ ul.acpopup { diff --git a/view/js/main.js b/view/js/main.js index c12156e4f8..b702669003 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -299,19 +299,19 @@ $(function() { var notification_id = 0; // Insert notifs into the notifications-menu - $(data.notifications).each(function(key, notif) { - var text = notif.message.format('' + notif.name + ''); - var contact = ('' + notif.name + ''); - var seenclass = (notif.seen == 1) ? "notify-seen" : "notify-unseen"; + $(data.notifications).each(function(key, notification) { + var text = notification.message.format('' + notification.name + ''); + var contact = ('' + notification.name + ''); + var seenclass = (notification.seen == 1) ? "notification-seen" : "notification-unseen"; var html = notifications_tpl.format( - notif.href, // {0} // link to the source - notif.photo, // {1} // photo of the contact + notification.href, // {0} // link to the source + notification.photo, // {1} // photo of the contact text, // {2} // preformatted text (autor + text) - notif.date, // {3} // date of notification (time ago) + notification.date, // {3} // date of notification (time ago) seenclass, // {4} // visited status of the notification - new Date(notif.timestamp*1000), // {5} // date of notification - notif.url, // {6} // profile url of the contact - notif.message.format(contact), // {7} // preformatted html (text including author profile url) + new Date(notification.timestamp*1000), // {5} // date of notification + notification.url, // {6} // profile url of the contact + notification.message.format(contact), // {7} // preformatted html (text including author profile url) '' // {8} // Deprecated ); nnm.append(html); diff --git a/view/templates/nav.tpl b/view/templates/nav.tpl index b9c2cf1f12..f39e58705b 100644 --- a/view/templates/nav.tpl +++ b/view/templates/nav.tpl @@ -34,7 +34,7 @@ {{$nav.community.1}} {{/if}} {{if $nav.introductions}} - {{$nav.introductions.1}} + {{$nav.introductions.1}} {{/if}} {{if $nav.messages}} @@ -49,7 +49,7 @@ {{if $nav.notifications}} {{$nav.notifications.1}} - +