streams/Code/Module/Fastping.php

67 lines
1.8 KiB
PHP
Raw Normal View History

<?php
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
/**
* @brief Fastping Controller.
* Called from the client at regular intervals to check for updates from the server
*
*/
2021-12-02 23:02:31 +00:00
class Fastping extends Controller
{
/**
* @brief do several updates when pinged.
*
* This function does several tasks. Whenever called it checks for new messages,
* introductions, notifications, etc. and returns a json with the results.
*
* @result JSON
*/
public function init()
{
$result['notice'] = [];
$result['info'] = [];
$vnotify = (-1);
$result['invalid'] = ((isset($_GET['uid']) && intval($_GET['uid'])) && (intval($_GET['uid']) != local_channel()) ? 1 : 0);
if (local_channel()) {
$vnotify = get_pconfig(local_channel(), 'system', 'vnotify', (-1));
}
/**
* Send all system messages (alerts) to the browser.
* Some are marked as informational and some represent
* errors or serious notifications. These typically
2022-09-04 22:39:58 +00:00
* will provide a popup on the current page (no matter
* what page it is).
2021-12-02 23:02:31 +00:00
*/
if (x($_SESSION, 'sysmsg')) {
foreach ($_SESSION['sysmsg'] as $m) {
2022-09-04 01:35:50 +00:00
$result['notice'][] = ['message' => $m];
2021-12-02 23:02:31 +00:00
}
unset($_SESSION['sysmsg']);
}
if (x($_SESSION, 'sysmsg_info')) {
foreach ($_SESSION['sysmsg_info'] as $m) {
2022-09-04 01:35:50 +00:00
$result['info'][] = ['message' => $m];
2021-12-02 23:02:31 +00:00
}
unset($_SESSION['sysmsg_info']);
}
if (!($vnotify & VNOTIFY_INFO)) {
$result['info'] = [];
}
if (!($vnotify & VNOTIFY_ALERT)) {
$result['notice'] = [];
}
json_return_and_die($result);
}
}