aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Minz/Request.php56
1 files changed, 46 insertions, 10 deletions
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index 39d172c7e..fc333244f 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -261,6 +261,49 @@ class Minz_Request {
return (bool)$is_public;
}
+ private static function requestId() {
+ if (empty($_GET['rid']) || !ctype_xdigit($_GET['rid'])) {
+ $_GET['rid'] = uniqid();
+ }
+ return $_GET['rid'];
+ }
+
+ private static function setNotification($type, $content) {
+ //TODO: Will need to ensure non-concurrency when landing https://github.com/FreshRSS/FreshRSS/pull/3096
+ $requests = Minz_Session::param('requests', []);
+ $requests[self::requestId()] = [
+ 'time' => time(),
+ 'notification' => [ 'type' => $type, 'content' => $content ],
+ ];
+ Minz_Session::_param('requests', $requests);
+ }
+
+ public static function setGoodNotification($content) {
+ self::setNotification('good', $content);
+ }
+
+ public static function setBadNotification($content) {
+ self::setNotification('bad', $content);
+ }
+
+ public static function getNotification() {
+ $notif = null;
+ //TODO: Will need to ensure non-concurrency when landing https://github.com/FreshRSS/FreshRSS/pull/3096
+ $requests = Minz_Session::param('requests');
+ if ($requests) {
+ //Delete abandonned notifications
+ $requests = array_filter($requests, function ($r) { return isset($r['time']) && $r['time'] > time() - 3600; });
+
+ $requestId = self::requestId();
+ if (!empty($requests[$requestId]['notification'])) {
+ $notif = $requests[$requestId]['notification'];
+ unset($requests[$requestId]);
+ }
+ Minz_Session::_param('requests', $requests);
+ }
+ return $notif;
+ }
+
/**
* Relance une requête
* @param $url l'url vers laquelle est relancée la requête
@@ -274,6 +317,7 @@ class Minz_Request {
}
$url = Minz_Url::checkUrl($url);
+ $url['params']['rid'] = self::requestId();
if ($redirect) {
header('Location: ' . Minz_Url::display($url, 'php'));
@@ -296,20 +340,12 @@ class Minz_Request {
* @param $url url array to where we should be forwarded
*/
public static function good($msg, $url = array()) {
- Minz_Session::_param('notification', array(
- 'type' => 'good',
- 'content' => $msg
- ));
-
+ Minz_Request::setGoodNotification($msg);
Minz_Request::forward($url, true);
}
public static function bad($msg, $url = array()) {
- Minz_Session::_param('notification', array(
- 'type' => 'bad',
- 'content' => $msg
- ));
-
+ Minz_Request::setBadNotification($msg);
Minz_Request::forward($url, true);
}