summaryrefslogtreecommitdiffstats
path: root/modules-available/news
diff options
context:
space:
mode:
authorSimon Rettberg2016-06-24 17:23:35 +0200
committerSimon Rettberg2016-06-24 17:23:35 +0200
commitd78c234a7244e93ac53fc7bcba8cdb152fa00130 (patch)
tree3c8c070f9c317f7c9afd9bc03b3c13f61b016620 /modules-available/news
parent[news] Fix install script (SQL syntax), add error messages/handling (diff)
downloadslx-admin-d78c234a7244e93ac53fc7bcba8cdb152fa00130.tar.gz
slx-admin-d78c234a7244e93ac53fc7bcba8cdb152fa00130.tar.xz
slx-admin-d78c234a7244e93ac53fc7bcba8cdb152fa00130.zip
[news] Move over global news API, add support for type param
Diffstat (limited to 'modules-available/news')
-rw-r--r--modules-available/news/api.inc.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/modules-available/news/api.inc.php b/modules-available/news/api.inc.php
new file mode 100644
index 00000000..cbfaa82b
--- /dev/null
+++ b/modules-available/news/api.inc.php
@@ -0,0 +1,29 @@
+<?php
+
+header('Content-Type: application/xml; charset=utf-8');
+
+$type = Request::any('type', 'news', 'string');
+
+// Fetch news from DB
+$row = Database::queryFirst('SELECT title, content, dateline FROM vmchooser_pages'
+ . ' WHERE type = :type ORDER BY dateline DESC LIMIT 1', compact('type'));
+if ($row !== false ) {
+
+ 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(nl2br($row['content'])) . "\n";
+ echo "\t" . '</info>' . "\n";
+ echo "\t" . "<date>" . "\n";
+ echo "\t\t" . $row['dateline'] . "\n";
+ echo "\t" . "</date>" . "\n";
+ echo "</news>";
+
+} else {
+ // no news in DB, output a 'null' news xml
+ echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
+ echo "<news>null</news>";
+}