aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
authorpikzen <mr.pikzen@gmail.com>2015-03-31 20:14:49 +0200
committernodiscc <nodiscc@gmail.com>2015-03-31 20:16:06 +0200
commitd3b2b456e174a7a4de67bf39460749cc35a6e382 (patch)
treeb53e47011494f9d55ea245fff2a304aa343846f3 /index.php
parent3139a6cf8ddb9fd50e84e33d35739c9fb4a1914c (diff)
parent3ea318dad05954e2043d5bb2f8572b103d7c3930 (diff)
downloadShaarli-d3b2b456e174a7a4de67bf39460749cc35a6e382.tar.gz
Shaarli-d3b2b456e174a7a4de67bf39460749cc35a6e382.tar.zst
Shaarli-d3b2b456e174a7a4de67bf39460749cc35a6e382.zip
Display notes as absolute urls
Fixes https://github.com/shaarli/Shaarli/issues/177 Merge commit '3ea318dad05954e2043d5bb2f8572b103d7c3930' into notes-absolute-url Conflicts: index.php
Diffstat (limited to 'index.php')
-rw-r--r--index.php42
1 files changed, 27 insertions, 15 deletions
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)
302// (Note that is may not work on your server if the corresponding local is not installed.) 302// (Note that is may not work on your server if the corresponding local is not installed.)
303function autoLocale() 303function autoLocale()
304{ 304{
305 $attempts = array('en_US'); // Default if browser does not send HTTP_ACCEPT_LANGUAGE 305 $loc='en_US'; // Default if browser does not send HTTP_ACCEPT_LANGUAGE
306 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // e.g. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3" 306 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // e.g. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3"
307 { // (It's a bit crude, but it works very well. Preferred language is always presented first.) 307 { // (It's a bit crude, but it works very well. Preferred language is always presented first.)
308 if (preg_match('/([a-z]{2})-?([a-z]{2})?/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) { 308 if (preg_match('/([a-z]{2}(-[a-z]{2})?)/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) $loc=$matches[1];
309 $loc = $matches[1] . (!empty($matches[2]) ? '_' . strtoupper($matches[2]) : '');
310 $attempts = array($loc, str_replace('_', '-', $loc),
311 $loc . '_' . strtoupper($loc), $loc . '_' . $loc,
312 $loc . '-' . strtoupper($loc), $loc . '-' . $loc);
313 }
314 } 309 }
315 setlocale(LC_TIME, $attempts); // LC_TIME = Set local for date/time format only. 310 setlocale(LC_TIME,$loc); // LC_TIME = Set local for date/time format only.
316} 311}
317 312
318// ------------------------------------------------------------------------------------------ 313// ------------------------------------------------------------------------------------------
@@ -554,7 +549,7 @@ function endsWith($haystack,$needle,$case=true)
554function linkdate2timestamp($linkdate) 549function linkdate2timestamp($linkdate)
555{ 550{
556 $Y=$M=$D=$h=$m=$s=0; 551 $Y=$M=$D=$h=$m=$s=0;
557 sscanf($linkdate,'%4d%2d%2d_%2d%2d%2d',$Y,$M,$D,$h,$m,$s); 552 $r = sscanf($linkdate,'%4d%2d%2d_%2d%2d%2d',$Y,$M,$D,$h,$m,$s);
558 return mktime($h,$m,$s,$M,$D,$Y); 553 return mktime($h,$m,$s,$M,$D,$Y);
559} 554}
560 555
@@ -572,6 +567,16 @@ function linkdate2iso8601($linkdate)
572 return date('c',linkdate2timestamp($linkdate)); // 'c' is for ISO 8601 date format. 567 return date('c',linkdate2timestamp($linkdate)); // 'c' is for ISO 8601 date format.
573} 568}
574 569
570/* Converts a linkdate time (YYYYMMDD_HHMMSS) of an article to a localized date format.
571 (used to display link date on screen)
572 The date format is automatically chosen according to locale/languages sniffed from browser headers (see autoLocale()). */
573function linkdate2locale($linkdate)
574{
575 return utf8_encode(strftime('%c',linkdate2timestamp($linkdate))); // %c is for automatic date format according to locale.
576 // Note that if you use a locale which is not installed on your webserver,
577 // the date will not be displayed in the chosen locale, but probably in US notation.
578}
579
575// Parse HTTP response headers and return an associative array. 580// Parse HTTP response headers and return an associative array.
576function http_parse_headers_shaarli( $headers ) 581function http_parse_headers_shaarli( $headers )
577{ 582{
@@ -1137,7 +1142,7 @@ function showDailyRSS()
1137 $l = $LINKSDB[$linkdate]; 1142 $l = $LINKSDB[$linkdate];
1138 $l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($l['description'])))); 1143 $l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($l['description']))));
1139 $l['thumbnail'] = thumbnail($l['url']); 1144 $l['thumbnail'] = thumbnail($l['url']);
1140 $l['timestamp'] = linkdate2timestamp($l['linkdate']); 1145 $l['localdate']=linkdate2locale($l['linkdate']);
1141 if (startsWith($l['url'],'?')) $l['url']=indexUrl().$l['url']; // make permalink URL absolute 1146 if (startsWith($l['url'],'?')) $l['url']=indexUrl().$l['url']; // make permalink URL absolute
1142 $links[$linkdate]=$l; 1147 $links[$linkdate]=$l;
1143 } 1148 }
@@ -1185,7 +1190,7 @@ function showDaily()
1185 $linksToDisplay[$key]['taglist']=$taglist; 1190 $linksToDisplay[$key]['taglist']=$taglist;
1186 $linksToDisplay[$key]['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))); 1191 $linksToDisplay[$key]['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))));
1187 $linksToDisplay[$key]['thumbnail'] = thumbnail($link['url']); 1192 $linksToDisplay[$key]['thumbnail'] = thumbnail($link['url']);
1188 $linksToDisplay[$key]['timestamp'] = linkdate2timestamp($link['linkdate']); 1193 $linksToDisplay[$key]['localdate'] = linkdate2locale($link['linkdate']);
1189 } 1194 }
1190 1195
1191 /* We need to spread the articles on 3 columns. 1196 /* We need to spread the articles on 3 columns.
@@ -1935,14 +1940,21 @@ function buildLinkList($PAGE,$LINKSDB)
1935 while ($i<$end && $i<count($keys)) 1940 while ($i<$end && $i<count($keys))
1936 { 1941 {
1937 $link = $linksToDisplay[$keys[$i]]; 1942 $link = $linksToDisplay[$keys[$i]];
1943 $title = $link['title'];
1944 $taglist = explode(' ',$link['tags']);
1945 uasort($taglist, 'strcasecmp');
1946 $classLi = $i%2!=0 ? '' : 'publicLinkHightLight'; // This could really be done with just a css pseudoclass.
1938 $link['description']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))); 1947 $link['description']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))));
1939 $title=$link['title'];
1940 $classLi = $i%2!=0 ? '' : 'publicLinkHightLight';
1941 $link['class'] = ($link['private']==0 ? $classLi : 'private'); 1948 $link['class'] = ($link['private']==0 ? $classLi : 'private');
1942 $link['timestamp']=linkdate2timestamp($link['linkdate']); 1949 $link['timestamp']=linkdate2timestamp($link['linkdate']);
1943 $taglist = explode(' ',$link['tags']);
1944 uasort($taglist, 'strcasecmp');
1945 $link['taglist']=$taglist; 1950 $link['taglist']=$taglist;
1951
1952 // Convert notes to absolute URLs
1953 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.
1954 strlen($link["url"]) === 7) {
1955 $link["url"] = indexUrl() . $link["url"];
1956 }
1957
1946 $linkDisp[$keys[$i]] = $link; 1958 $linkDisp[$keys[$i]] = $link;
1947 $i++; 1959 $i++;
1948 } 1960 }