X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=index.php;h=d9692927ca292f41a43323ab6713b732b633a7df;hb=05f41b062a76238545ace056fc1cab9acd1deb1a;hp=f182ad2905f1851dae7b30a90dadd639f4e28751;hpb=03cd3750fd26d2667ccdadb55fd4807be34e1d1c;p=github%2Fshaarli%2FShaarli.git
diff --git a/index.php b/index.php
index f182ad29..d9692927 100644
--- a/index.php
+++ b/index.php
@@ -1,5 +1,5 @@
publish_update($topic_url);
+ }
+}
+
// ------------------------------------------------------------------------------------------
// Session management
define('INACTIVITY_TIMEOUT',3600); // (in seconds). If the user does not access any page within this time, his/her session is considered expired.
@@ -378,13 +396,13 @@ function linkdate2locale($linkdate)
}
// Parse HTTP response headers and return an associative array.
-function http_parse_headers( $headers )
+function http_parse_headers_shaarli( $headers )
{
$res=array();
foreach($headers as $header)
{
$i = strpos($header,': ');
- if ($i)
+ if ($i!==false)
{
$key=substr($header,0,$i);
$value=substr($header,$i+2,strlen($header)-$i-2);
@@ -401,7 +419,7 @@ function http_parse_headers( $headers )
[1] = associative array containing HTTP response headers (eg. echo getHTTP($url)[1]['Content-Type'])
[2] = data
Example: list($httpstatus,$headers,$data) = getHTTP('http://sebauvage.net/');
- if (strpos($httpstatus,'200 OK'))
+ if (strpos($httpstatus,'200 OK')!==false)
echo 'Data type: '.htmlspecialchars($headers['Content-Type']);
else
echo 'There was an error: '.htmlspecialchars($httpstatus)
@@ -415,7 +433,7 @@ function getHTTP($url,$timeout=30)
$data=file_get_contents($url,false,$context,-1, 4000000); // We download at most 4 Mb from source.
if (!$data) { $lasterror=error_get_last(); return array($lasterror['message'],array(),''); }
$httpStatus=$http_response_header[0]; // eg. "HTTP/1.1 200 OK"
- $responseHeaders=http_parse_headers($http_response_header);
+ $responseHeaders=http_parse_headers_shaarli($http_response_header);
return array($httpStatus,$responseHeaders,$data);
}
catch (Exception $e) // getHTTP *can* fail silentely (we don't care if the title cannot be fetched)
@@ -428,7 +446,7 @@ function getHTTP($url,$timeout=30)
// (Returns an empty string if not found.)
function html_extract_title($html)
{
- return preg_match('!
(.*) !is', $html, $matches) ? trim(str_replace("\n",' ', $matches[1])) : '' ;
+ return preg_match('!(.*?) !is', $html, $matches) ? trim(str_replace("\n",' ', $matches[1])) : '' ;
}
// ------------------------------------------------------------------------------------------
@@ -574,7 +592,10 @@ class linkdb implements Iterator, Countable, ArrayAccess
$s = strtolower($searchterms);
foreach($this->links as $l)
{
- $found=strpos(strtolower($l['title']),$s) || strpos(strtolower($l['description']),$s) || strpos(strtolower($l['url']),$s) || strpos(strtolower($l['tags']),$s);
+ $found= (strpos(strtolower($l['title']),$s)!==false)
+ || (strpos(strtolower($l['description']),$s)!==false)
+ || (strpos(strtolower($l['url']),$s)!==false)
+ || (strpos(strtolower($l['tags']),$s)!==false);
if ($found) $filtered[$l['linkdate']] = $l;
}
krsort($filtered);
@@ -644,16 +665,29 @@ function showRSS()
$pageaddr=htmlspecialchars(serverUrl().$_SERVER["SCRIPT_NAME"]);
echo '';
echo ''.htmlspecialchars($GLOBALS['title']).' '.$pageaddr.'';
- echo 'Shared links '.$pageaddr.' '."\n\n";
+ echo 'Shared links en-en '.$pageaddr.' '."\n\n";
+ if (!empty($GLOBALS['config']['PUBSUBHUB_URL']))
+ {
+ echo '';
+ echo ' ';
+ echo ' ';
+ echo '';
+ }
$i=0;
$keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys().
while ($i<50 && $i'.htmlspecialchars($link['title']).' '.htmlspecialchars($link['url']).' '.htmlspecialchars($link['url']).'';
- if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) echo ''.htmlspecialchars($rfc822date).' ';
- echo ' '."\n";
+ $absurl = htmlspecialchars($link['url']);
+ if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute
+ echo ''.htmlspecialchars($link['title']).' '.$absurl.' '.$absurl.'';
+ if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) echo ''.htmlspecialchars($rfc822date)." \n";
+ if ($link['tags']!='') // Adding tags to each RSS entry (as mentioned in RSS specification)
+ {
+ foreach(explode(' ',$link['tags']) as $tag) { echo ''.htmlspecialchars($tag).' '."\n"; }
+ }
+ echo ' '."\n \n";
$i++;
}
echo ' ';
@@ -683,15 +717,29 @@ function showATOM()
$link = $linksToDisplay[$keys[$i]];
$iso8601date = linkdate2iso8601($link['linkdate']);
$latestDate = max($latestDate,$iso8601date);
- $entries.=''.htmlspecialchars($link['title']).' '.htmlspecialchars($link['url']).' ';
+ $absurl = htmlspecialchars($link['url']);
+ if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute
+ $entries.=''.htmlspecialchars($link['title']).' '.$absurl.' ';
if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) $entries.=''.htmlspecialchars($iso8601date).' ';
- $entries.=''.nl2br(htmlspecialchars($link['description'])).' '."\n";
+ $entries.=''.nl2br(text2clickable(htmlspecialchars($link['description'])))." \n";
+ if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification)
+ {
+ foreach(explode(' ',$link['tags']) as $tag)
+ { $entries.=' '."\n"; }
+ }
+ $entries.=" \n";
$i++;
}
$feed='';
$feed.=''.htmlspecialchars($GLOBALS['title']).' ';
if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) $feed.=''.htmlspecialchars($latestDate).' ';
- $feed.=' ';
+ $feed.=' ';
+ if (!empty($GLOBALS['config']['PUBSUBHUB_URL']))
+ {
+ $feed.='';
+ $feed.=' ';
+ $feed.='';
+ }
$feed.=''.htmlspecialchars($pageaddr).' ';
$feed.=''.htmlspecialchars($pageaddr).' '."\n\n"; // Yes, I know I should use a real IRI (RFC3987), but the site URL will do.
$feed.=$entries;
@@ -738,6 +786,33 @@ function renderPage()
exit;
}
+ // -------- Picture wall
+ if (startswith($_SERVER["QUERY_STRING"],'do=picwall'))
+ {
+ // 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;
+ $body='';
+
+ foreach($linksToDisplay as $link)
+ {
+ $href='?'.htmlspecialchars(smallhash($link['linkdate']),ENT_QUOTES);
+ $thumb=thumbnail($link['url'],$href);
+ if ($thumb!='')
+ {
+ $body.='';
+
+ }
+ }
+ $body = ''.$body.'
';
+ $data = array('pageheader'=>' ','body'=>$body,'onload'=>'');
+ templatePage($data);
+ exit;
+
+ }
+
// -------- Tag cloud
if (startswith($_SERVER["QUERY_STRING"],'do=tagcloud'))
{
@@ -805,15 +880,15 @@ function renderPage()
// Show login screen, then redirect to ?post=...
if (isset($_GET['post']))
{
- header('Location: ?do=login&post='.urlencode($_GET['post']).(isset($_GET['title'])?'&title='.urlencode($_GET['title']):'').(isset($_GET['source'])?'&source='.urlencode($_GET['source']):'')); // Redirect to login page, then back to post link.
+ header('Location: ?do=login&post='.urlencode($_GET['post']).(!empty($_GET['title'])?'&title='.urlencode($_GET['title']):'').(!empty($_GET['source'])?'&source='.urlencode($_GET['source']):'')); // Redirect to login page, then back to post link.
exit;
}
// Show search form and display list of links.
$searchform=<<
-
-
+
+
HTML;
$data = array('pageheader'=>$searchform,'body'=>templateLinkList(),'onload'=>'');
@@ -830,13 +905,13 @@ HTML;
// The javascript code for the bookmarklet:
$changepwd = ($GLOBALS['config']['OPEN_SHAARLI'] ? '' : 'Change password - Change your password. ' );
$toolbar= <<
+
HTML;
$data = array('pageheader'=>$toolbar,'body'=>'','onload'=>'');
@@ -866,7 +941,7 @@ HTML;
{
$token = getToken();
$changepwdform= <<
+