From: pikzen Date: Tue, 31 Mar 2015 18:14:49 +0000 (+0200) Subject: Display notes as absolute urls X-Git-Tag: v0.5.0~55 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=d3b2b456e174a7a4de67bf39460749cc35a6e382;hp=3139a6cf8ddb9fd50e84e33d35739c9fb4a1914c;p=github%2Fshaarli%2FShaarli.git Display notes as absolute urls Fixes https://github.com/shaarli/Shaarli/issues/177 Merge commit '3ea318dad05954e2043d5bb2f8572b103d7c3930' into notes-absolute-url Conflicts: index.php --- diff --git "a/doc/Mentions-of-Shaarli-in-\"the-press\".md" "b/doc/Mentions-of-Shaarli-in-\"the-press\".md" deleted file mode 100644 index 60c22cf0..00000000 --- "a/doc/Mentions-of-Shaarli-in-\"the-press\".md" +++ /dev/null @@ -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 \ No newline at end of file diff --git a/index.php b/index.php index 7795a597..83c507bb 100644 --- a/index.php +++ b/index.php @@ -302,17 +302,12 @@ function keepMultipleSpaces($text) // (Note that is may not work on your server if the corresponding local is not installed.) 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" { // (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)) { - $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); - } + if (preg_match('/([a-z]{2}(-[a-z]{2})?)/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) $loc=$matches[1]; } - 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) { $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); } @@ -572,6 +567,16 @@ 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()). */ +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. function http_parse_headers_shaarli( $headers ) { @@ -1137,7 +1142,7 @@ function showDailyRSS() $l = $LINKSDB[$linkdate]; $l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($l['description'])))); $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 $links[$linkdate]=$l; } @@ -1185,7 +1190,7 @@ function showDaily() $linksToDisplay[$key]['taglist']=$taglist; $linksToDisplay[$key]['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))); $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. @@ -1935,14 +1940,21 @@ function buildLinkList($PAGE,$LINKSDB) while ($i<$end && $i