aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSeb Sauvage <sebsauvage@sebsauvage.net>2011-09-27 13:35:00 +0200
committerEmilien Klein <emilien@klein.st>2011-09-27 13:35:00 +0200
commit8e92abac218a7419b4a4f0826b32daba46cfa926 (patch)
treef4955d83cd60779a85d64ea1d2dcaf94a5109b1b
parentba0718dcd43ecb44e80d65307ed4d2dfda24c0b9 (diff)
downloadShaarli-8e92abac218a7419b4a4f0826b32daba46cfa926.tar.gz
Shaarli-8e92abac218a7419b4a4f0826b32daba46cfa926.tar.zst
Shaarli-8e92abac218a7419b4a4f0826b32daba46cfa926.zip
Version 0.0.19 beta:
- Corrected: Patch by Emilien to remove the update notification after the update. - New: ATOM fee
-rw-r--r--index.php58
1 files changed, 53 insertions, 5 deletions
diff --git a/index.php b/index.php
index 15582051..276deb84 100644
--- a/index.php
+++ b/index.php
@@ -1,5 +1,5 @@
1<?php 1<?php
2// Shaarli 0.0.18 beta - Shaare your links... 2// Shaarli 0.0.19 beta - Shaare your links...
3// The personal, minimalist, super-fast, no-database delicious clone. By sebsauvage.net 3// The personal, minimalist, super-fast, no-database delicious clone. By sebsauvage.net
4// http://sebsauvage.net/wiki/doku.php?id=php:shaarli 4// http://sebsauvage.net/wiki/doku.php?id=php:shaarli
5// Licence: http://www.opensource.org/licenses/zlib-license.php 5// Licence: http://www.opensource.org/licenses/zlib-license.php
@@ -47,7 +47,7 @@ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
47header("Cache-Control: no-store, no-cache, must-revalidate"); 47header("Cache-Control: no-store, no-cache, must-revalidate");
48header("Cache-Control: post-check=0, pre-check=0", false); 48header("Cache-Control: post-check=0, pre-check=0", false);
49header("Pragma: no-cache"); 49header("Pragma: no-cache");
50define('shaarli_version','0.0.18 beta'); 50define('shaarli_version','0.0.19 beta');
51if (!is_dir(DATADIR)) { mkdir(DATADIR,0705); chmod(DATADIR,0705); } 51if (!is_dir(DATADIR)) { mkdir(DATADIR,0705); chmod(DATADIR,0705); }
52if (!is_file(DATADIR.'/.htaccess')) { file_put_contents(DATADIR.'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. 52if (!is_file(DATADIR.'/.htaccess')) { file_put_contents(DATADIR.'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files.
53if (!is_file(CONFIG_FILE)) install(); 53if (!is_file(CONFIG_FILE)) install();
@@ -89,7 +89,7 @@ function checkUpdate()
89 } 89 }
90 // Compare versions: 90 // Compare versions:
91 $newestversion=file_get_contents(UPDATECHECK_FILENAME); 91 $newestversion=file_get_contents(UPDATECHECK_FILENAME);
92 if ($newestversion!=shaarli_version) return $newestversion; 92 if (version_compare($newestversion,shaarli_version)==1) return $newestversion;
93 return ''; 93 return '';
94} 94}
95 95
@@ -310,6 +310,13 @@ function linkdate2rfc822($linkdate)
310 return date('r',linkdate2timestamp($linkdate)); // 'r' is for RFC822 date format. 310 return date('r',linkdate2timestamp($linkdate)); // 'r' is for RFC822 date format.
311} 311}
312 312
313/* Converts a linkdate time (YYYYMMDD_HHMMSS) of an article to a ISO 8601 date.
314 (used to build the updated tags in ATOM feed.) */
315function linkdate2iso8601($linkdate)
316{
317 return date('c',linkdate2timestamp($linkdate)); // 'c' is for ISO 8601 date format.
318}
319
313/* Converts a linkdate time (YYYYMMDD_HHMMSS) of an article to a localized date format. 320/* Converts a linkdate time (YYYYMMDD_HHMMSS) of an article to a localized date format.
314 (used to display link date on screen) 321 (used to display link date on screen)
315 The date format is automatically chosen according to locale/languages sniffed from browser headers (see autoLocale()). */ 322 The date format is automatically chosen according to locale/languages sniffed from browser headers (see autoLocale()). */
@@ -588,6 +595,46 @@ function showRSS()
588} 595}
589 596
590// ------------------------------------------------------------------------------------------ 597// ------------------------------------------------------------------------------------------
598// Ouput the last 50 links in ATOM format.
599function showATOM()
600{
601 global $LINKSDB;
602
603 // Optionnaly filter the results:
604 $linksToDisplay=array();
605 if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']);
606 elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags']));
607 else $linksToDisplay = $LINKSDB;
608
609 header('Content-Type: application/xhtml+xml; charset=utf-8');
610 $pageaddr=htmlspecialchars(serverUrl().$_SERVER["SCRIPT_NAME"]);
611 $latestDate = '';
612 $entries='';
613 $i=0;
614 $keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys().
615 while ($i<50 && $i<count($keys))
616 {
617 $link = $linksToDisplay[$keys[$i]];
618 $iso8601date = linkdate2iso8601($link['linkdate']);
619 $latestDate = max($latestDate,$iso8601date);
620 $entries.='<entry><title>'.htmlspecialchars($link['title']).'</title><link href="'.htmlspecialchars($link['url']).'"/><id>'.htmlspecialchars($link['url']).'</id>';
621 if (!HIDE_TIMESTAMPS || isLoggedIn()) $entries.='<updated>'.htmlspecialchars($iso8601date).'</updated>';
622 $entries.='<summary>'.nl2br(htmlspecialchars($link['description'])).'</summary></entry>'."\n";
623 $i++;
624 }
625 $feed='<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">';
626 $feed.='<title>'.htmlspecialchars($GLOBALS['title']).'</title>';
627 if (!HIDE_TIMESTAMPS || isLoggedIn()) $feed.='<updated>'.htmlspecialchars($latestDate).'</updated>';
628 $feed.='<link href="'.htmlspecialchars($pageaddr).'" />';
629 $feed.='<author><uri>'.htmlspecialchars($pageaddr).'</uri></author>';
630 $feed.='<id>'.htmlspecialchars($pageaddr).'</id>'."\n\n"; // Yes, I know I should use a real IRI (RFC3987), but the site URL will do.
631 $feed.=$entries;
632 $feed.='</feed>';
633 echo $feed;
634 exit;
635}
636
637// ------------------------------------------------------------------------------------------
591// Render HTML page: 638// Render HTML page:
592function renderPage() 639function renderPage()
593{ 640{
@@ -1284,7 +1331,7 @@ $(document).ready(function()
1284</script> 1331</script>
1285JS; 1332JS;
1286 } 1333 }
1287 $feedurl=htmlspecialchars(serverUrl().$_SERVER['SCRIPT_NAME'].'?do=rss'); 1334 $feedurl=htmlspecialchars(serverUrl().$_SERVER['SCRIPT_NAME']);
1288 if (!empty($_GET['searchtags'])) $feedurl.='&searchtags='.$_GET['searchtags']; 1335 if (!empty($_GET['searchtags'])) $feedurl.='&searchtags='.$_GET['searchtags'];
1289 elseif (!empty($_GET['searchterm'])) $feedurl.='&searchterm='.$_GET['searchterm']; 1336 elseif (!empty($_GET['searchterm'])) $feedurl.='&searchterm='.$_GET['searchterm'];
1290 1337
@@ -1299,7 +1346,7 @@ JS;
1299</head> 1346</head>
1300<body {$data['onload']}>{$newversion} 1347<body {$data['onload']}>{$newversion}
1301<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> 1348<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>
1302 <b><i>{$title}</i></b> - <a href="?">Home</a>&nbsp;{$menu}&nbsp;<a href="{$feedurl}" style="padding-left:30px;">RSS Feed</a> 1349 <b><i>{$title}</i></b> - <a href="?">Home</a>&nbsp;{$menu}&nbsp;<a href="{$feedurl}?do=rss" style="padding-left:30px;">RSS Feed</a> <a href="{$feedurl}?do=atom" style="padding-left:10px;">ATOM Feed</a>
1303&nbsp;&nbsp; <a href="?do=tagcloud">Tag cloud</a> 1350&nbsp;&nbsp; <a href="?do=tagcloud">Tag cloud</a>
1304{$data['pageheader']} 1351{$data['pageheader']}
1305</div> 1352</div>
@@ -1486,5 +1533,6 @@ $LINKSDB=new linkdb(isLoggedIn() || OPEN_SHAARLI); // Read links from database
1486if (startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI) 1533if (startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI)
1487if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=LINKS_PER_PAGE; 1534if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=LINKS_PER_PAGE;
1488if (startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; } 1535if (startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; }
1536if (startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; }
1489renderPage(); 1537renderPage();
1490?> \ No newline at end of file 1538?> \ No newline at end of file