function showATOM() { header('Content-Type: application/atom+xml; charset=utf-8'); // Cache system $query = $_SERVER["QUERY_STRING"]; $cache = new pageCache(pageUrl(), startsWith($query, 'do=atom') && !isLoggedIn()); $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } // If cached was not found (or not usable), then read the database and build the response: $LINKSDB = new linkdb(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in). // 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; } $pageaddr = htmlspecialchars(indexUrl()); $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]]; $guid = $pageaddr . '?' . smallHash($link['linkdate']); $iso8601date = linkdate2iso8601($link['linkdate']); $latestDate = max($latestDate, $iso8601date); $absurl = htmlspecialchars($link['url']); if (startsWith($absurl, '?')) { $absurl = $pageaddr . $absurl; } // make permalink URL absolute $entries .= '<entry><title>' . htmlspecialchars($link['title']) . '</title><link href="' . $absurl . '" /><id>' . $guid . '</id>'; if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) { $entries .= '<updated>' . htmlspecialchars($iso8601date) . '</updated>'; } $entries .= '<content type="html">' . htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))) . "</content>\n"; if ($link['tags'] != '') { foreach (explode(' ', $link['tags']) as $tag) { $entries .= '<category scheme="' . htmlspecialchars($pageaddr, ENT_QUOTES) . '" term="' . htmlspecialchars($tag, ENT_QUOTES) . '" />' . "\n"; } } $entries .= "</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 (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) { $feed .= '<updated>' . htmlspecialchars($latestDate) . '</updated>'; } $feed .= '<link rel="self" href="' . htmlspecialchars(serverUrl() . $_SERVER["REQUEST_URI"]) . '" />'; if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) { $feed .= '<!-- PubSubHubbub Discovery -->'; $feed .= '<link rel="hub" href="' . htmlspecialchars($GLOBALS['config']['PUBSUBHUB_URL']) . '" />'; $feed .= '<!-- End Of PubSubHubbub Discovery -->'; } $feed .= '<author><name>' . htmlspecialchars($pageaddr) . '</name><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; $cache->cache(ob_get_contents()); ob_end_flush(); exit; }
function showATOM() { header('Content-Type: application/atom+xml; charset=utf-8'); // $usepermalink : If true, use permalink instead of final link. // User just has to add 'permalink' in URL parameters. e.g. http://mysite.com/shaarli/?do=atom&permalinks $usepermalinks = isset($_GET['permalinks']) || !$GLOBALS['config']['ENABLE_RSS_PERMALINKS']; // Cache system $query = $_SERVER["QUERY_STRING"]; $cache = new CachedPage($GLOBALS['config']['PAGECACHE'], page_url($_SERVER), startsWith($query, 'do=atom') && !isLoggedIn()); $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } // If cached was not found (or not usable), then read the database and build the response: // Read links from database (and filter private links if used it not logged in). $LINKSDB = new LinkDB($GLOBALS['config']['DATASTORE'], isLoggedIn(), $GLOBALS['config']['HIDE_PUBLIC_LINKS'], $GLOBALS['redirector']); // Optionally filter the results: if (!empty($_GET['searchterm'])) { $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $_GET['searchterm']); } else { if (!empty($_GET['searchtags'])) { $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TAG, trim($_GET['searchtags'])); } else { $linksToDisplay = $LINKSDB; } } $nblinksToDisplay = 50; // Number of links to display. // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. if (!empty($_GET['nb'])) { $nblinksToDisplay = $_GET['nb'] == 'all' ? count($linksToDisplay) : max(intval($_GET['nb']), 1); } $pageaddr = escape(index_url($_SERVER)); $latestDate = ''; $entries = ''; $i = 0; $keys = array(); foreach ($linksToDisplay as $key => $value) { $keys[] = $key; } // No, I can't use array_keys(). while ($i < $nblinksToDisplay && $i < count($keys)) { $link = $linksToDisplay[$keys[$i]]; $guid = $pageaddr . '?' . smallHash($link['linkdate']); $iso8601date = linkdate2iso8601($link['linkdate']); $latestDate = max($latestDate, $iso8601date); $absurl = $link['url']; if (startsWith($absurl, '?')) { $absurl = $pageaddr . $absurl; } // make permalink URL absolute $entries .= '<entry><title>' . $link['title'] . '</title>'; if ($usepermalinks === true) { $entries .= '<link href="' . $guid . '" /><id>' . $guid . '</id>'; } else { $entries .= '<link href="' . $absurl . '" /><id>' . $guid . '</id>'; } if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) { $entries .= '<updated>' . escape($iso8601date) . '</updated>'; } // Add permalink in description $descriptionlink = '(<a href="' . $guid . '">Permalink</a>)'; // If user wants permalinks first, put the final link in description if ($usepermalinks === true) { $descriptionlink = '(<a href="' . $absurl . '">Link</a>)'; } if (strlen($link['description']) > 0) { $descriptionlink = '<br>' . $descriptionlink; } $entries .= '<content type="html"><![CDATA[' . format_description($link['description'], $GLOBALS['redirector']) . $descriptionlink . "]]></content>\n"; if ($link['tags'] != '') { foreach (explode(' ', $link['tags']) as $tag) { $entries .= '<category scheme="' . $pageaddr . '" term="' . $tag . '" />' . "\n"; } } $entries .= "</entry>\n"; $i++; } $feed = '<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">'; $feed .= '<title>' . $GLOBALS['title'] . '</title>'; if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) { $feed .= '<updated>' . escape($latestDate) . '</updated>'; } $feed .= '<link rel="self" href="' . escape(server_url($_SERVER) . $_SERVER["REQUEST_URI"]) . '" />'; if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) { $feed .= '<!-- PubSubHubbub Discovery -->'; $feed .= '<link rel="hub" href="' . escape($GLOBALS['config']['PUBSUBHUB_URL']) . '" />'; $feed .= '<!-- End Of PubSubHubbub Discovery -->'; } $feed .= '<author><name>' . $pageaddr . '</name><uri>' . $pageaddr . '</uri></author>'; $feed .= '<id>' . $pageaddr . '</id>' . "\n\n"; // Yes, I know I should use a real IRI (RFC3987), but the site URL will do. $feed .= $entries; $feed .= '</feed><!-- Cached version of ' . escape(page_url($_SERVER)) . ' -->'; echo $feed; $cache->cache(ob_get_contents()); ob_end_flush(); exit; }
function showATOM() { header('Content-Type: application/atom+xml; charset=utf-8'); // $usepermalink : If true, use permalink instead of final link. // User just has to add 'permalink' in URL parameters. eg. http://mysite.com/shaarli/?do=atom&permalinks $usepermalinks = isset($_GET['permalinks']); // Cache system $query = $_SERVER["QUERY_STRING"]; $cache = new pageCache(pageUrl(), startsWith($query, 'do=atom') && !isLoggedIn()); $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } // If cached was not found (or not usable), then read the database and build the response: $LINKSDB = new linkdb(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'] && !$GLOBALS['config']['OPEN_NEWS']); // Read links from database (and filter private links if used it not logged in). // 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; } $nblinksToDisplay = 50; // Number of links to display. if (!empty($_GET['nb'])) { $nblinksToDisplay = $_GET['nb'] == 'all' ? count($linksToDisplay) : max($_GET['nb'] + 0, 1); } $pageaddr = htmlspecialchars(indexUrl()); $latestDate = ''; $entries = ''; $i = 0; $keys = array(); foreach ($linksToDisplay as $key => $value) { $keys[] = $key; } // No, I can't use array_keys(). while ($i < $nblinksToDisplay && $i < count($keys)) { $link = $linksToDisplay[$keys[$i]]; // Si le lien est en attente de modération, il est ignoré if (hasModerationTag($link)) { $nblinksToDisplay++; $i++; continue; } $guid = $pageaddr . '?' . smallHash($link['linkdate']); $iso8601date = linkdate2iso8601($link['linkdate']); $latestDate = max($latestDate, $iso8601date); $absurl = htmlspecialchars($link['url']); if (startsWith($absurl, '?')) { $absurl = $pageaddr . $absurl; } // make permalink URL absolute $entries .= '<entry><title>' . htmlspecialchars($link['title']) . '</title>'; if ($usepermalinks === true) { $entries .= '<link href="' . $guid . '" /><id>' . $guid . '</id>'; } else { $entries .= '<link href="' . $absurl . '" /><id>' . $guid . '</id>'; } if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) { $entries .= '<updated>' . htmlspecialchars($iso8601date) . '</updated>'; } // Add permalink in description $descriptionlink = htmlspecialchars('(<a href="' . $guid . '">Permalink</a>)'); // If user wants permalinks first, put the final link in description if ($usepermalinks === true) { $descriptionlink = htmlspecialchars('(<a href="' . $absurl . '">Link</a>)'); } if (strlen($link['description']) > 0) { $descriptionlink = '<br>' . $descriptionlink; } $entries .= '<content type="html">' . htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))) . $descriptionlink . "</content>\n"; if ($link['tags'] != '') { foreach (explode(' ', $link['tags']) as $tag) { $entries .= '<category scheme="' . htmlspecialchars($pageaddr, ENT_QUOTES) . '" term="' . htmlspecialchars($tag, ENT_QUOTES) . '" />' . "\n"; } } $entries .= "</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 (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) { $feed .= '<updated>' . htmlspecialchars($latestDate) . '</updated>'; } $feed .= '<link rel="self" href="' . htmlspecialchars(serverUrl() . $_SERVER["REQUEST_URI"]) . '" />'; if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) { $feed .= '<!-- PubSubHubbub Discovery -->'; $feed .= '<link rel="hub" href="' . htmlspecialchars($GLOBALS['config']['PUBSUBHUB_URL']) . '" />'; $feed .= '<!-- End Of PubSubHubbub Discovery -->'; } $feed .= '<author><name>' . htmlspecialchars($pageaddr) . '</name><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><!-- Cached version of ' . htmlspecialchars(pageUrl()) . ' -->'; echo $feed; $cache->cache(ob_get_contents()); ob_end_flush(); exit; }