Display notes as absolute urls

Fixes https://github.com/shaarli/Shaarli/issues/177
Merge commit '3ea318dad05954e2043d5bb2f8572b103d7c3930' into notes-absolute-url
Conflicts:
	index.php
This commit is contained in:
pikzen 2015-03-31 20:14:49 +02:00 committed by nodiscc
commit d3b2b456e1
2 changed files with 27 additions and 18 deletions

View file

@ -1,3 +0,0 @@
This page lists the publications (physical or on the Internet) that mention Shaarli. It is by no means a complete list, and you are invited to add to it, should you spot a Shaarli mentioned in the wild.
* http://www.linuxjournal.com/content/youre-boss-ubos

View file

@ -302,17 +302,12 @@ function keepMultipleSpaces($text)
// (Note that is may not work on your server if the corresponding local is not installed.) // (Note that is may not work on your server if the corresponding local is not installed.)
function autoLocale() function autoLocale()
{ {
$attempts = array('en_US'); // Default if browser does not send HTTP_ACCEPT_LANGUAGE $loc='en_US'; // Default if browser does not send HTTP_ACCEPT_LANGUAGE
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // e.g. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3" if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // e.g. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3"
{ // (It's a bit crude, but it works very well. Preferred language is always presented first.) { // (It's a bit crude, but it works very well. Preferred language is always presented first.)
if (preg_match('/([a-z]{2})-?([a-z]{2})?/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) { if (preg_match('/([a-z]{2}(-[a-z]{2})?)/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) $loc=$matches[1];
$loc = $matches[1] . (!empty($matches[2]) ? '_' . strtoupper($matches[2]) : '');
$attempts = array($loc, str_replace('_', '-', $loc),
$loc . '_' . strtoupper($loc), $loc . '_' . $loc,
$loc . '-' . strtoupper($loc), $loc . '-' . $loc);
}
} }
setlocale(LC_TIME, $attempts); // LC_TIME = Set local for date/time format only. setlocale(LC_TIME,$loc); // LC_TIME = Set local for date/time format only.
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
@ -554,7 +549,7 @@ function endsWith($haystack,$needle,$case=true)
function linkdate2timestamp($linkdate) function linkdate2timestamp($linkdate)
{ {
$Y=$M=$D=$h=$m=$s=0; $Y=$M=$D=$h=$m=$s=0;
sscanf($linkdate,'%4d%2d%2d_%2d%2d%2d',$Y,$M,$D,$h,$m,$s); $r = sscanf($linkdate,'%4d%2d%2d_%2d%2d%2d',$Y,$M,$D,$h,$m,$s);
return mktime($h,$m,$s,$M,$D,$Y); return mktime($h,$m,$s,$M,$D,$Y);
} }
@ -572,6 +567,16 @@ function linkdate2iso8601($linkdate)
return date('c',linkdate2timestamp($linkdate)); // 'c' is for ISO 8601 date format. 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()). */
function linkdate2locale($linkdate)
{
return utf8_encode(strftime('%c',linkdate2timestamp($linkdate))); // %c is for automatic date format according to locale.
// Note that if you use a locale which is not installed on your webserver,
// the date will not be displayed in the chosen locale, but probably in US notation.
}
// Parse HTTP response headers and return an associative array. // Parse HTTP response headers and return an associative array.
function http_parse_headers_shaarli( $headers ) function http_parse_headers_shaarli( $headers )
{ {
@ -1137,7 +1142,7 @@ function showDailyRSS()
$l = $LINKSDB[$linkdate]; $l = $LINKSDB[$linkdate];
$l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($l['description'])))); $l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($l['description']))));
$l['thumbnail'] = thumbnail($l['url']); $l['thumbnail'] = thumbnail($l['url']);
$l['timestamp'] = linkdate2timestamp($l['linkdate']); $l['localdate']=linkdate2locale($l['linkdate']);
if (startsWith($l['url'],'?')) $l['url']=indexUrl().$l['url']; // make permalink URL absolute if (startsWith($l['url'],'?')) $l['url']=indexUrl().$l['url']; // make permalink URL absolute
$links[$linkdate]=$l; $links[$linkdate]=$l;
} }
@ -1185,7 +1190,7 @@ function showDaily()
$linksToDisplay[$key]['taglist']=$taglist; $linksToDisplay[$key]['taglist']=$taglist;
$linksToDisplay[$key]['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))); $linksToDisplay[$key]['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))));
$linksToDisplay[$key]['thumbnail'] = thumbnail($link['url']); $linksToDisplay[$key]['thumbnail'] = thumbnail($link['url']);
$linksToDisplay[$key]['timestamp'] = linkdate2timestamp($link['linkdate']); $linksToDisplay[$key]['localdate'] = linkdate2locale($link['linkdate']);
} }
/* We need to spread the articles on 3 columns. /* We need to spread the articles on 3 columns.
@ -1935,14 +1940,21 @@ function buildLinkList($PAGE,$LINKSDB)
while ($i<$end && $i<count($keys)) while ($i<$end && $i<count($keys))
{ {
$link = $linksToDisplay[$keys[$i]]; $link = $linksToDisplay[$keys[$i]];
$title = $link['title'];
$taglist = explode(' ',$link['tags']);
uasort($taglist, 'strcasecmp');
$classLi = $i%2!=0 ? '' : 'publicLinkHightLight'; // This could really be done with just a css pseudoclass.
$link['description']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))); $link['description']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))));
$title=$link['title'];
$classLi = $i%2!=0 ? '' : 'publicLinkHightLight';
$link['class'] = ($link['private']==0 ? $classLi : 'private'); $link['class'] = ($link['private']==0 ? $classLi : 'private');
$link['timestamp']=linkdate2timestamp($link['linkdate']); $link['timestamp']=linkdate2timestamp($link['linkdate']);
$taglist = explode(' ',$link['tags']);
uasort($taglist, 'strcasecmp');
$link['taglist']=$taglist; $link['taglist']=$taglist;
// Convert notes to absolute URLs
if ($link["url"][0] === '?' && // Check for both signs of a note: starting with ? and 7 chars long. I doubt that you'll post any links that look like this.
strlen($link["url"]) === 7) {
$link["url"] = indexUrl() . $link["url"];
}
$linkDisp[$keys[$i]] = $link; $linkDisp[$keys[$i]] = $link;
$i++; $i++;
} }