mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2026-05-05 19:57:04 +02:00
broke out notifications into ‘locations’ in data
This commit is contained in:
@@ -1345,22 +1345,21 @@ class Admin
|
||||
$notifications = $notifications_content['data'] ?? array();
|
||||
$timeout = $this->grav['config']->get('system.session.timeout', 1800);
|
||||
|
||||
if ($force || !$last_checked || empty($notifications) || ($last_checked && (time() - $last_checked > $timeout))) {
|
||||
$body = Response::get('https://getgrav.org/notifications.json?' . time());
|
||||
$notifications = Yaml::parse($body);
|
||||
if ($force || !$last_checked || empty($notifications) || (time() - $last_checked > $timeout)) {
|
||||
// $body = Response::get('https://getgrav.org/notifications.json?' . time());
|
||||
$body = Response::get('http://localhost/notifications.json?' . time());
|
||||
$notifications = json_decode($body, true);
|
||||
|
||||
// Sort by date
|
||||
usort($notifications, function ($a, $b) {
|
||||
return strcmp($a['date'], $b['date']);
|
||||
});
|
||||
|
||||
// Get top 10
|
||||
$notifications = array_slice($notifications, 0, 10);
|
||||
|
||||
// Reverse order and create a new array
|
||||
$cleaned_notifications = array_reverse($notifications);
|
||||
$notifications = array_reverse($notifications);
|
||||
$cleaned_notifications = [];
|
||||
|
||||
foreach ($cleaned_notifications as $key => $notification) {
|
||||
foreach ($notifications as $key => $notification) {
|
||||
|
||||
if (isset($notification['permissions']) && !$this->authorize($notification['permissions'])) {
|
||||
continue;
|
||||
@@ -1397,6 +1396,15 @@ class Admin
|
||||
// return $notification;
|
||||
// }, $cleaned_notifications);
|
||||
|
||||
// reset notifications
|
||||
$notifications = [];
|
||||
|
||||
foreach($cleaned_notifications as $notification) {
|
||||
foreach ($notification['location'] as $location) {
|
||||
$notifications = array_merge_recursive($notifications, [$location => [$notification]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$notifications_file->content(['last_checked' => time(), 'data' => $notifications]);
|
||||
$notifications_file->save();
|
||||
|
||||
@@ -831,11 +831,15 @@ class AdminController extends AdminBaseController
|
||||
}
|
||||
|
||||
// do we need to force a reload
|
||||
$refresh = (bool) ($this->data['refresh'] ?? false);
|
||||
$refresh = (bool) ($this->data['refresh'] ?? true);
|
||||
|
||||
try {
|
||||
$notifications = $this->admin->getNotifications($refresh);
|
||||
$notification_data = $this->grav['twig']->processTemplate('partials/notification-block.html.twig', ['notifications' => $notifications]);
|
||||
|
||||
|
||||
foreach ($notifications as $type => $type_notifications) {
|
||||
$notification_data[$type] = $this->grav['twig']->processTemplate('partials/notification-block.html.twig', ['notifications' => $type_notifications]);
|
||||
}
|
||||
|
||||
$json_response = [
|
||||
'status' => 'success',
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{% for entry in notifications if 'feed' in entry.location %}
|
||||
<li class="single-notification "><span class="badge alert {{ entry.type }}">{{ entry.type|capitalize }}</span><a target="_blank" href="{{ entry.link }}" title="{{ entry.message|striptags|e('html_attr') }}">{{ e.message|raw }}</a></li>
|
||||
{% for entry in notifications if 'feed' %}
|
||||
<li class="single-notification {{ entry.type }}-notification"><span class="badge alert {{ entry.type }}">{{ entry.type|capitalize }}</span><a target="_blank" href="{{ entry.link }}" title="{{ entry.message|striptags|e('html_attr') }}">{{ e.message|raw }}</a></li>
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user