<?php
-// Shaarli 0.0.18 beta - Shaare your links...
+// Shaarli 0.0.19 beta - Shaare your links...
// The personal, minimalist, super-fast, no-database delicious clone. By sebsauvage.net
// http://sebsauvage.net/wiki/doku.php?id=php:shaarli
// Licence: http://www.opensource.org/licenses/zlib-license.php
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
-define('shaarli_version','0.0.18 beta');
+define('shaarli_version','0.0.19 beta');
if (!is_dir(DATADIR)) { mkdir(DATADIR,0705); chmod(DATADIR,0705); }
if (!is_file(DATADIR.'/.htaccess')) { file_put_contents(DATADIR.'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files.
if (!is_file(CONFIG_FILE)) install();
}
// Compare versions:
$newestversion=file_get_contents(UPDATECHECK_FILENAME);
- if ($newestversion!=shaarli_version) return $newestversion;
+ if (version_compare($newestversion,shaarli_version)==1) return $newestversion;
return '';
}
return date('r',linkdate2timestamp($linkdate)); // 'r' is for RFC822 date format.
}
+/* Converts a linkdate time (YYYYMMDD_HHMMSS) of an article to a ISO 8601 date.
+ (used to build the updated tags in ATOM feed.) */
+function linkdate2iso8601($linkdate)
+{
+ return date('c',linkdate2timestamp($linkdate)); // 'c' is for ISO 8601 date format.
+}
+
/* Converts a linkdate time (YYYYMMDD_HHMMSS) of an article to a localized date format.
(used to display link date on screen)
The date format is automatically chosen according to locale/languages sniffed from browser headers (see autoLocale()). */
exit;
}
+// ------------------------------------------------------------------------------------------
+// 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;
+}
+
// ------------------------------------------------------------------------------------------
// Render HTML page:
function renderPage()
</script>
JS;
}
- $feedurl=htmlspecialchars(serverUrl().$_SERVER['SCRIPT_NAME'].'?do=rss');
+ $feedurl=htmlspecialchars(serverUrl().$_SERVER['SCRIPT_NAME']);
if (!empty($_GET['searchtags'])) $feedurl.='&searchtags='.$_GET['searchtags'];
elseif (!empty($_GET['searchterm'])) $feedurl.='&searchterm='.$_GET['searchterm'];
</head>
<body {$data['onload']}>{$newversion}
<div id="pageheader"><div style="float:right; font-style:italic; color:#bbb; text-align:right; padding:0 5 0 0;">Shaare your links...<br>{$linkcount} links</div>
- <b><i>{$title}</i></b> - <a href="?">Home</a> {$menu} <a href="{$feedurl}" style="padding-left:30px;">RSS Feed</a>
+ <b><i>{$title}</i></b> - <a href="?">Home</a> {$menu} <a href="{$feedurl}?do=rss" style="padding-left:30px;">RSS Feed</a> <a href="{$feedurl}?do=atom" style="padding-left:10px;">ATOM Feed</a>
<a href="?do=tagcloud">Tag cloud</a>
{$data['pageheader']}
</div>
if (startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI)
if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=LINKS_PER_PAGE;
if (startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; }
+if (startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; }
renderPage();
?>
\ No newline at end of file