added Atom feed for news and meetings

This commit is contained in:
Jan-Philipp Litza 2012-12-26 20:39:54 +01:00
parent fe6fab67be
commit e0e44fc8c3
4 changed files with 49 additions and 0 deletions

4
db/update.d/21_Atom.php Normal file
View File

@ -0,0 +1,4 @@
<?php
mysql_query("INSERT IGNORE INTO `Privileges` (`name`, `desc`) VALUES ('atom', ' Atom news export')");
$applied = mysql_affected_rows() > 0;
?>

View File

@ -0,0 +1,39 @@
<?php
// publically available page to feed the news to feedreaders
function user_atom() {
global $ical_shifts, $user, $DISPLAY_NEWS;
if (isset ($_REQUEST['key']) && preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key']))
$key = $_REQUEST['key'];
else
die("Missing key.");
$user = sql_select("SELECT * FROM `User` WHERE `ical_key`='" . sql_escape($key) . "' LIMIT 1");
if (count($user) == 0)
die("Key invalid.");
$user = $user[0];
$news = sql_select("SELECT * FROM `News` " . (empty($_REQUEST['meetings'])? '' : 'WHERE `Treffen` = 1 ') . "ORDER BY `ID` DESC LIMIT " . sql_escape($DISPLAY_NEWS));
header('Content-Type: application/atom+xml; charset=utf-8');
$html = '<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Engelsystem</title>
<id>' . $_SERVER['HTTP_HOST'] . htmlspecialchars(preg_replace('#[&?]key=[a-f0-9]{32}#', '', $_SERVER['REQUEST_URI'])) . '</id>
<updated>' . date('Y-m-d\TH:i:sP', $news[0]['Datum']) . "</updated>\n";
foreach ($news as $news_entry) {
$html .= " <entry>
<title>" . htmlspecialchars($news_entry['Betreff']) . "</title>
<link href=\"" . page_link_to_absolute("news_comments&amp;nid=") . "${news_entry['ID']}\"/>
<id>" . preg_replace('#^https?://#', '', page_link_to_absolute("news")) . "-${news_entry['ID']}</id>
<updated>" . date('Y-m-d\TH:i:sP', $news_entry['Datum']) . "</updated>
<summary type=\"html\">" . htmlspecialchars($news_entry['Text']) . "</summary>
</entry>\n";
}
$html .= "</feed>";
header("Content-Length: " . strlen($html));
echo $html;
die();
}
?>

View File

@ -40,6 +40,10 @@ if ($p == "ical") {
require_once ('includes/pages/user_ical.php'); require_once ('includes/pages/user_ical.php');
user_ical(); user_ical();
} }
elseif ($p == "atom") {
require_once ('includes/pages/user_atom.php');
user_atom();
}
// Recht dafür vorhanden? // Recht dafür vorhanden?
elseif (in_array($p, $privileges)) { elseif (in_array($p, $privileges)) {
if ($p == "news") { if ($p == "news") {
@ -185,6 +189,7 @@ if (isset ($user) && $p != "admin_user_angeltypes")
echo template_render('../templates/layout.html', array ( echo template_render('../templates/layout.html', array (
'theme' => isset ($user) ? $user['color'] : $default_theme, 'theme' => isset ($user) ? $user['color'] : $default_theme,
'title' => $title, 'title' => $title,
'atom_link' => ($p == 'news' || $p == 'user_meetings')? '<link href="' . page_link_to('atom') . (($p == 'user_meetings')? '&amp;meetings=1' : '') . '&amp;key=' . $user['ical_key'] . '" type="application/atom+xml" rel="alternate" title="Atom Feed">' : '',
'menu' => make_menu(), 'menu' => make_menu(),
'content' => $content 'content' => $content
)); ));

View File

@ -14,6 +14,7 @@
<script type="text/javascript" src="css/forms.js"></script> <script type="text/javascript" src="css/forms.js"></script>
<link rel="stylesheet" type="text/css" href="css/base.css" /> <link rel="stylesheet" type="text/css" href="css/base.css" />
<link rel="stylesheet" type="text/css" href="css/style%theme%.css" /> <link rel="stylesheet" type="text/css" href="css/style%theme%.css" />
%atom_link%
</head> </head>
<body class="background"> <body class="background">
<header> <header>