+// ------------------------------------------------------------------------------------------
+// Ouput the last 50 links in ATOM format.
+function showATOM()
+{
+ global $LINKSDB;
+
+ // Optionnaly filter the results:
+ $linksToDisplay=array();
+ if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']);
+ elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags']));
+ else $linksToDisplay = $LINKSDB;
+
+ header('Content-Type: application/xhtml+xml; charset=utf-8');
+ $pageaddr=htmlspecialchars(serverUrl().$_SERVER["SCRIPT_NAME"]);
+ $latestDate = '';
+ $entries='';
+ $i=0;
+ $keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys().
+ while ($i<50 && $i<count($keys))
+ {
+ $link = $linksToDisplay[$keys[$i]];
+ $iso8601date = linkdate2iso8601($link['linkdate']);
+ $latestDate = max($latestDate,$iso8601date);
+ $entries.='<entry><title>'.htmlspecialchars($link['title']).'</title><link href="'.htmlspecialchars($link['url']).'"/><id>'.htmlspecialchars($link['url']).'</id>';
+ if (!HIDE_TIMESTAMPS || isLoggedIn()) $entries.='<updated>'.htmlspecialchars($iso8601date).'</updated>';
+ $entries.='<summary>'.nl2br(htmlspecialchars($link['description'])).'</summary></entry>'."\n";
+ $i++;
+ }
+ $feed='<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">';
+ $feed.='<title>'.htmlspecialchars($GLOBALS['title']).'</title>';
+ if (!HIDE_TIMESTAMPS || isLoggedIn()) $feed.='<updated>'.htmlspecialchars($latestDate).'</updated>';
+ $feed.='<link href="'.htmlspecialchars($pageaddr).'" />';
+ $feed.='<author><uri>'.htmlspecialchars($pageaddr).'</uri></author>';
+ $feed.='<id>'.htmlspecialchars($pageaddr).'</id>'."\n\n"; // Yes, I know I should use a real IRI (RFC3987), but the site URL will do.
+ $feed.=$entries;
+ $feed.='</feed>';
+ echo $feed;
+ exit;
+}
+