diff options
author | Simon Rettberg | 2022-05-03 17:36:29 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-05-03 17:36:29 +0200 |
commit | b155c8167ddd5562f30fcfadd9eeb60d80e2619e (patch) | |
tree | cfbb0fda2f4aeadc24a0cbb010f975e3c10ee779 /modules-available/news/api.inc.php | |
parent | [eventlog] Add de translations (diff) | |
download | slx-admin-b155c8167ddd5562f30fcfadd9eeb60d80e2619e.tar.gz slx-admin-b155c8167ddd5562f30fcfadd9eeb60d80e2619e.tar.xz slx-admin-b155c8167ddd5562f30fcfadd9eeb60d80e2619e.zip |
[locations/news] Add per-location news/help/loginscreentext
Diffstat (limited to 'modules-available/news/api.inc.php')
-rw-r--r-- | modules-available/news/api.inc.php | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/modules-available/news/api.inc.php b/modules-available/news/api.inc.php index 851f31a8..e8ef11d1 100644 --- a/modules-available/news/api.inc.php +++ b/modules-available/news/api.inc.php @@ -4,23 +4,54 @@ header('Content-Type: application/xml; charset=utf-8'); $type = Request::any('type', 'news', 'string'); +$locationId = Request::any('location', 0, 'int'); +if ($locationId === 0) { + $locationId = Location::getFromIp($_SERVER['REMOTE_ADDR']); +} +$locations = Location::getLocationRootChain($locationId); +$locations[] = 0; + // Fetch news from DB -$row = Database::queryFirst('SELECT title, content, dateline FROM vmchooser_pages' - . ' WHERE type = :type AND expires > UNIX_TIMESTAMP() ORDER BY dateline DESC LIMIT 1', compact('type')); -if ($row !== false ) { +$res = Database::simpleQuery('SELECT title, locationid, content, dateline FROM vmchooser_pages + WHERE type = :type AND (locationid IS NULL OR locationid IN (:lids)) + AND expires > UNIX_TIMESTAMP() ORDER BY dateline DESC', [ + 'type' => $type, + 'lids' => $locations, + ]); - echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; - echo "<news>" . "\n"; - echo "\t" . '<headline>' . "\n"; - echo "\t\t" . htmlspecialchars($row['title']) . "\n"; - echo "\t" . '</headline>' . "\n"; - echo "\t" . "<info>" . "\n"; - echo "\t\t" . htmlspecialchars($row['content']) . "\n"; - echo "\t" . '</info>' . "\n"; - echo "\t" . "<date>" . "\n"; - echo "\t\t" . $row['dateline'] . "\n"; - echo "\t" . "</date>" . "\n"; - echo "</news>"; +// Get one for each location. As we sort by dateline and check expiry in the query, we only +// need one per location and then pick the first one that is set, as the locations are ordered +// by closest to furthest +$locations = array_flip($locations); +foreach ($res as $row) { + $lid = $row['locationid']; + if (is_array($locations[$lid])) + continue; // Already have one + $locations[$lid] = $row; +} +// Pick first one +foreach ($locations as $row) { + if (is_array($row)) + break; +} + +if (is_array($row)) { + $title = htmlspecialchars($row['title']); + $content = htmlspecialchars($row['content']); + echo <<<EOF +<?xml version="1.0" encoding="UTF-8"?> +<news> + <headline> + $title + </headline> + <info> + $content + </info> + <date> + {$row['dateline']} + </date> +</news> +EOF; } else { // no news in DB, output a 'null' news xml |