aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
authorKnah Tsaeb <knah-tsaeb@knah-tsaeb.org>2013-03-04 10:18:39 +0100
committerKnah Tsaeb <knah-tsaeb@knah-tsaeb.org>2013-03-04 10:18:39 +0100
commitbb8f712db66f8e572eba4b14f636aeeace7cd9e7 (patch)
tree1850c60d4758ae2d865ff23b83466ef3e465e489 /index.php
parentdd064cc315374a419a29391c6ee0d1675d11ef4d (diff)
downloadShaarli-bb8f712db66f8e572eba4b14f636aeeace7cd9e7.tar.gz
Shaarli-bb8f712db66f8e572eba4b14f636aeeace7cd9e7.tar.zst
Shaarli-bb8f712db66f8e572eba4b14f636aeeace7cd9e7.zip
[add] https://github.com/sebsauvage/Shaarli/issues/20 New links created as private by default.
Diffstat (limited to 'index.php')
-rw-r--r--index.php117
1 files changed, 60 insertions, 57 deletions
diff --git a/index.php b/index.php
index 222f3295..0b4d454d 100644
--- a/index.php
+++ b/index.php
@@ -97,6 +97,7 @@ if (empty($GLOBALS['title'])) $GLOBALS['title']='Shared links on '.htmlspecialch
97if (empty($GLOBALS['timezone'])) $GLOBALS['timezone']=date_default_timezone_get(); 97if (empty($GLOBALS['timezone'])) $GLOBALS['timezone']=date_default_timezone_get();
98if (empty($GLOBALS['disablesessionprotection'])) $GLOBALS['disablesessionprotection']=false; 98if (empty($GLOBALS['disablesessionprotection'])) $GLOBALS['disablesessionprotection']=false;
99if (empty($GLOBALS['disablejquery'])) $GLOBALS['disablejquery']=false; 99if (empty($GLOBALS['disablejquery'])) $GLOBALS['disablejquery']=false;
100if (empty($GLOBALS['privateLinkByDefault'])) $GLOBALS['privateLinkByDefault']=false;
100// I really need to rewrite Shaarli with a proper configuation manager. 101// I really need to rewrite Shaarli with a proper configuation manager.
101 102
102autoLocale(); // Sniff browser language and set date format accordingly. 103autoLocale(); // Sniff browser language and set date format accordingly.
@@ -146,7 +147,7 @@ class pageCache
146 private $shouldBeCached; // boolean: Should this url be cached ? 147 private $shouldBeCached; // boolean: Should this url be cached ?
147 private $filename; // Name of the cache file for this url 148 private $filename; // Name of the cache file for this url
148 149
149 /* 150 /*
150 $url = url (typically the value returned by pageUrl()) 151 $url = url (typically the value returned by pageUrl())
151 $shouldBeCached = boolean. If false, the cache will be disabled. 152 $shouldBeCached = boolean. If false, the cache will be disabled.
152 */ 153 */
@@ -155,7 +156,7 @@ class pageCache
155 $this->url = $url; 156 $this->url = $url;
156 $this->filename = $GLOBALS['config']['PAGECACHE'].'/'.sha1($url).'.cache'; 157 $this->filename = $GLOBALS['config']['PAGECACHE'].'/'.sha1($url).'.cache';
157 $this->shouldBeCached = $shouldBeCached; 158 $this->shouldBeCached = $shouldBeCached;
158 } 159 }
159 160
160 // If the page should be cached and a cached version exists, 161 // If the page should be cached and a cached version exists,
161 // returns the cached version (otherwise, return null). 162 // returns the cached version (otherwise, return null).
@@ -183,7 +184,7 @@ class pageCache
183 $handler = opendir($GLOBALS['config']['PAGECACHE']); 184 $handler = opendir($GLOBALS['config']['PAGECACHE']);
184 if ($handler!==false) 185 if ($handler!==false)
185 { 186 {
186 while (($filename = readdir($handler))!==false) 187 while (($filename = readdir($handler))!==false)
187 { 188 {
188 if (endsWith($filename,'.cache')) { unlink($GLOBALS['config']['PAGECACHE'].'/'.$filename); } 189 if (endsWith($filename,'.cache')) { unlink($GLOBALS['config']['PAGECACHE'].'/'.$filename); }
189 } 190 }
@@ -240,7 +241,7 @@ function text2clickable($url)
240function keepMultipleSpaces($text) 241function keepMultipleSpaces($text)
241{ 242{
242 return str_replace(' ',' &nbsp;',$text); 243 return str_replace(' ',' &nbsp;',$text);
243 244
244} 245}
245// ------------------------------------------------------------------------------------------ 246// ------------------------------------------------------------------------------------------
246// Sniff browser language to display dates in the right format automatically. 247// Sniff browser language to display dates in the right format automatically.
@@ -306,7 +307,7 @@ function check_auth($login,$password)
306function isLoggedIn() 307function isLoggedIn()
307{ 308{
308 if ($GLOBALS['config']['OPEN_SHAARLI']) return true; 309 if ($GLOBALS['config']['OPEN_SHAARLI']) return true;
309 310
310 if (!isset($GLOBALS['login'])) return false; // Shaarli is not configured yet. 311 if (!isset($GLOBALS['login'])) return false; // Shaarli is not configured yet.
311 312
312 // If session does not exist on server side, or IP address has changed, or session has expired, logout. 313 // If session does not exist on server side, or IP address has changed, or session has expired, logout.
@@ -606,7 +607,7 @@ function tokenOk($token)
606 p = new pageBuilder; 607 p = new pageBuilder;
607 p.assign('myfield','myvalue'); 608 p.assign('myfield','myvalue');
608 p.renderPage('mytemplate'); 609 p.renderPage('mytemplate');
609 610
610*/ 611*/
611class pageBuilder 612class pageBuilder
612{ 613{
@@ -615,11 +616,11 @@ class pageBuilder
615 function __construct() 616 function __construct()
616 { 617 {
617 $this->tpl=false; 618 $this->tpl=false;
618 } 619 }
619 620
620 private function initialize() 621 private function initialize()
621 { 622 {
622 $this->tpl = new RainTPL; 623 $this->tpl = new RainTPL;
623 $this->tpl->assign('newversion',checkUpdate()); 624 $this->tpl->assign('newversion',checkUpdate());
624 $this->tpl->assign('feedurl',htmlspecialchars(indexUrl())); 625 $this->tpl->assign('feedurl',htmlspecialchars(indexUrl()));
625 $searchcrits=''; // Search criteria 626 $searchcrits=''; // Search criteria
@@ -634,16 +635,16 @@ class pageBuilder
634 if (!empty($GLOBALS['title'])) $this->tpl->assign('pagetitle',$GLOBALS['title']); 635 if (!empty($GLOBALS['title'])) $this->tpl->assign('pagetitle',$GLOBALS['title']);
635 if (!empty($GLOBALS['pagetitle'])) $this->tpl->assign('pagetitle',$GLOBALS['pagetitle']); 636 if (!empty($GLOBALS['pagetitle'])) $this->tpl->assign('pagetitle',$GLOBALS['pagetitle']);
636 $this->tpl->assign('shaarlititle',empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title'] ); 637 $this->tpl->assign('shaarlititle',empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title'] );
637 return; 638 return;
638 } 639 }
639 640
640 // The following assign() method is basically the same as RainTPL (except that it's lazy) 641 // The following assign() method is basically the same as RainTPL (except that it's lazy)
641 public function assign($what,$where) 642 public function assign($what,$where)
642 { 643 {
643 if ($this->tpl===false) $this->initialize(); // Lazy initialization 644 if ($this->tpl===false) $this->initialize(); // Lazy initialization
644 $this->tpl->assign($what,$where); 645 $this->tpl->assign($what,$where);
645 } 646 }
646 647
647 // Render a specific page (using a template). 648 // Render a specific page (using a template).
648 // eg. pb.renderPage('picwall') 649 // eg. pb.renderPage('picwall')
649 public function renderPage($page) 650 public function renderPage($page)
@@ -661,14 +662,14 @@ class pageBuilder
661 echo $mylinks['20110826_161819']['title']; 662 echo $mylinks['20110826_161819']['title'];
662 foreach($mylinks as $link) 663 foreach($mylinks as $link)
663 echo $link['title'].' at url '.$link['url'].' ; description:'.$link['description']; 664 echo $link['title'].' at url '.$link['url'].' ; description:'.$link['description'];
664 665
665 Available keys: 666 Available keys:
666 title : Title of the link 667 title : Title of the link
667 url : URL of the link. Can be absolute or relative. Relative URLs are permalinks (eg.'?m-ukcw') 668 url : URL of the link. Can be absolute or relative. Relative URLs are permalinks (eg.'?m-ukcw')
668 description : description of the entry 669 description : description of the entry
669 private : Is this link private ? 0=no, other value=yes 670 private : Is this link private ? 0=no, other value=yes
670 linkdate : date of the creation of this entry, in the form YYYYMMDD_HHMMSS (eg.'20110914_192317') 671 linkdate : date of the creation of this entry, in the form YYYYMMDD_HHMMSS (eg.'20110914_192317')
671 tags : tags attached to this entry (separated by spaces) 672 tags : tags attached to this entry (separated by spaces)
672 673
673 We implement 3 interfaces: 674 We implement 3 interfaces:
674 - ArrayAccess so that this object behaves like an associative array. 675 - ArrayAccess so that this object behaves like an associative array.
@@ -847,7 +848,7 @@ class linkdb implements Iterator, Countable, ArrayAccess
847 arsort($tags); // Sort tags by usage (most used tag first) 848 arsort($tags); // Sort tags by usage (most used tag first)
848 return $tags; 849 return $tags;
849 } 850 }
850 851
851 // Returns the list of days containing articles (oldest first) 852 // Returns the list of days containing articles (oldest first)
852 // Output: An array containing days (in format YYYYMMDD). 853 // Output: An array containing days (in format YYYYMMDD).
853 public function days() 854 public function days()
@@ -1007,7 +1008,7 @@ function showATOM()
1007 $feed.=$entries; 1008 $feed.=$entries;
1008 $feed.='</feed><!-- Cached version of '.pageUrl().' -->'; 1009 $feed.='</feed><!-- Cached version of '.pageUrl().' -->';
1009 echo $feed; 1010 echo $feed;
1010 1011
1011 $cache->cache(ob_get_contents()); 1012 $cache->cache(ob_get_contents());
1012 ob_end_flush(); 1013 ob_end_flush();
1013 exit; 1014 exit;
@@ -1025,11 +1026,11 @@ function showDailyRSS()
1025 $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } 1026 $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; }
1026 // If cached was not found (or not usable), then read the database and build the response: 1027 // If cached was not found (or not usable), then read the database and build the response:
1027 $LINKSDB=new linkdb(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in). 1028 $LINKSDB=new linkdb(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in).
1028 1029
1029 /* Some Shaarlies may have very few links, so we need to look 1030 /* Some Shaarlies may have very few links, so we need to look
1030 back in time (rsort()) until we have enough days ($nb_of_days). 1031 back in time (rsort()) until we have enough days ($nb_of_days).
1031 */ 1032 */
1032 $linkdates=array(); foreach($LINKSDB as $linkdate=>$value) { $linkdates[]=$linkdate; } 1033 $linkdates=array(); foreach($LINKSDB as $linkdate=>$value) { $linkdates[]=$linkdate; }
1033 rsort($linkdates); 1034 rsort($linkdates);
1034 $nb_of_days=7; // We take 7 days. 1035 $nb_of_days=7; // We take 7 days.
1035 $today=Date('Ymd'); 1036 $today=Date('Ymd');
@@ -1044,14 +1045,14 @@ function showDailyRSS()
1044 } 1045 }
1045 if (count($days)>$nb_of_days) break; // Have we collected enough days ? 1046 if (count($days)>$nb_of_days) break; // Have we collected enough days ?
1046 } 1047 }
1047 1048
1048 // Build the RSS feed. 1049 // Build the RSS feed.
1049 header('Content-Type: application/rss+xml; charset=utf-8'); 1050 header('Content-Type: application/rss+xml; charset=utf-8');
1050 $pageaddr=htmlspecialchars(indexUrl()); 1051 $pageaddr=htmlspecialchars(indexUrl());
1051 echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">'; 1052 echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">';
1052 echo '<channel><title>Daily - '.htmlspecialchars($GLOBALS['title']).'</title><link>'.$pageaddr.'</link>'; 1053 echo '<channel><title>Daily - '.htmlspecialchars($GLOBALS['title']).'</title><link>'.$pageaddr.'</link>';
1053 echo '<description>Daily shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n"; 1054 echo '<description>Daily shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n";
1054 1055
1055 foreach($days as $day=>$linkdates) // For each day. 1056 foreach($days as $day=>$linkdates) // For each day.
1056 { 1057 {
1057 $daydate = utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000'))); // Full text date 1058 $daydate = utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000'))); // Full text date
@@ -1059,7 +1060,7 @@ function showDailyRSS()
1059 $absurl=htmlspecialchars(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page. 1060 $absurl=htmlspecialchars(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
1060 echo '<item><title>'.htmlspecialchars($GLOBALS['title'].' - '.$daydate).'</title><guid>'.$absurl.'</guid><link>'.$absurl.'</link>'; 1061 echo '<item><title>'.htmlspecialchars($GLOBALS['title'].' - '.$daydate).'</title><guid>'.$absurl.'</guid><link>'.$absurl.'</link>';
1061 echo '<pubDate>'.htmlspecialchars($rfc822date)."</pubDate>"; 1062 echo '<pubDate>'.htmlspecialchars($rfc822date)."</pubDate>";
1062 1063
1063 // Build the HTML body of this RSS entry. 1064 // Build the HTML body of this RSS entry.
1064 $html=''; 1065 $html='';
1065 $href=''; 1066 $href='';
@@ -1069,21 +1070,21 @@ function showDailyRSS()
1069 { 1070 {
1070 $l = $LINKSDB[$linkdate]; 1071 $l = $LINKSDB[$linkdate];
1071 $l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($l['description'])))); 1072 $l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($l['description']))));
1072 $l['thumbnail'] = thumbnail($l['url']); 1073 $l['thumbnail'] = thumbnail($l['url']);
1073 $l['localdate']=linkdate2locale($l['linkdate']); 1074 $l['localdate']=linkdate2locale($l['linkdate']);
1074 if (startsWith($l['url'],'?')) $l['url']=indexUrl().$l['url']; // make permalink URL absolute 1075 if (startsWith($l['url'],'?')) $l['url']=indexUrl().$l['url']; // make permalink URL absolute
1075 $links[$linkdate]=$l; 1076 $links[$linkdate]=$l;
1076 } 1077 }
1077 // Then build the HTML for this day: 1078 // Then build the HTML for this day:
1078 $tpl = new RainTPL; 1079 $tpl = new RainTPL;
1079 $tpl->assign('links',$links); 1080 $tpl->assign('links',$links);
1080 $html = $tpl->draw('dailyrss',$return_string=true); 1081 $html = $tpl->draw('dailyrss',$return_string=true);
1081 echo "\n"; 1082 echo "\n";
1082 echo '<description><![CDATA['.$html.']]></description>'."\n</item>\n\n"; 1083 echo '<description><![CDATA['.$html.']]></description>'."\n</item>\n\n";
1083 1084
1084 } 1085 }
1085 echo '</channel></rss><!-- Cached version of '.pageUrl().' -->'; 1086 echo '</channel></rss><!-- Cached version of '.pageUrl().' -->';
1086 1087
1087 $cache->cache(ob_get_contents()); 1088 $cache->cache(ob_get_contents());
1088 ob_end_flush(); 1089 ob_end_flush();
1089 exit; 1090 exit;
@@ -1097,12 +1098,12 @@ function showDaily()
1097 1098
1098 $day=Date('Ymd',strtotime('-1 day')); // Yesterday, in format YYYYMMDD. 1099 $day=Date('Ymd',strtotime('-1 day')); // Yesterday, in format YYYYMMDD.
1099 if (isset($_GET['day'])) $day=$_GET['day']; 1100 if (isset($_GET['day'])) $day=$_GET['day'];
1100 1101
1101 $days = $LINKSDB->days(); 1102 $days = $LINKSDB->days();
1102 $i = array_search($day,$days); 1103 $i = array_search($day,$days);
1103 if ($i==false) { $i=count($days)-1; $day=$days[$i]; } 1104 if ($i==false) { $i=count($days)-1; $day=$days[$i]; }
1104 $previousday=''; 1105 $previousday='';
1105 $nextday=''; 1106 $nextday='';
1106 if ($i!==false) 1107 if ($i!==false)
1107 { 1108 {
1108 if ($i>1) $previousday=$days[$i-1]; 1109 if ($i>1) $previousday=$days[$i-1];
@@ -1117,12 +1118,12 @@ function showDaily()
1117 uasort($taglist, 'strcasecmp'); 1118 uasort($taglist, 'strcasecmp');
1118 $linksToDisplay[$key]['taglist']=$taglist; 1119 $linksToDisplay[$key]['taglist']=$taglist;
1119 $linksToDisplay[$key]['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))); 1120 $linksToDisplay[$key]['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))));
1120 $linksToDisplay[$key]['thumbnail'] = thumbnail($link['url']); 1121 $linksToDisplay[$key]['thumbnail'] = thumbnail($link['url']);
1121 } 1122 }
1122 1123
1123 /* We need to spread the articles on 3 columns. 1124 /* We need to spread the articles on 3 columns.
1124 I did not want to use a javascript lib like http://masonry.desandro.com/ 1125 I did not want to use a javascript lib like http://masonry.desandro.com/
1125 so I manually spread entries with a simple method: I roughly evaluate the 1126 so I manually spread entries with a simple method: I roughly evaluate the
1126 height of a div according to title and description length. 1127 height of a div according to title and description length.
1127 */ 1128 */
1128 $columns=array(array(),array(),array()); // Entries to display, for each column. 1129 $columns=array(array(),array(),array()); // Entries to display, for each column.
@@ -1150,7 +1151,7 @@ function showDaily()
1150 $PAGE->assign('col3',$columns[2]); 1151 $PAGE->assign('col3',$columns[2]);
1151 $PAGE->assign('day',utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000')))); 1152 $PAGE->assign('day',utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000'))));
1152 $PAGE->assign('previousday',$previousday); 1153 $PAGE->assign('previousday',$previousday);
1153 $PAGE->assign('nextday',$nextday); 1154 $PAGE->assign('nextday',$nextday);
1154 $PAGE->renderPage('daily'); 1155 $PAGE->renderPage('daily');
1155 exit; 1156 exit;
1156} 1157}
@@ -1229,7 +1230,7 @@ function renderPage()
1229 $PAGE->assign('linkcount',count($LINKSDB)); 1230 $PAGE->assign('linkcount',count($LINKSDB));
1230 $PAGE->assign('tags',$tagList); 1231 $PAGE->assign('tags',$tagList);
1231 $PAGE->renderPage('tagcloud'); 1232 $PAGE->renderPage('tagcloud');
1232 exit; 1233 exit;
1233 } 1234 }
1234 1235
1235 // -------- User clicks on a tag in a link: The tag is added to the list of searched tags (searchtags=...) 1236 // -------- User clicks on a tag in a link: The tag is added to the list of searched tags (searchtags=...)
@@ -1272,7 +1273,7 @@ function renderPage()
1272 header('Location: '.$referer); 1273 header('Location: '.$referer);
1273 exit; 1274 exit;
1274 } 1275 }
1275 1276
1276 // -------- User wants to see only private links (toggle) 1277 // -------- User wants to see only private links (toggle)
1277 if (isset($_GET['privateonly'])) 1278 if (isset($_GET['privateonly']))
1278 { 1279 {
@@ -1363,6 +1364,7 @@ function renderPage()
1363 $GLOBALS['redirector']=$_POST['redirector']; 1364 $GLOBALS['redirector']=$_POST['redirector'];
1364 $GLOBALS['disablesessionprotection']=!empty($_POST['disablesessionprotection']); 1365 $GLOBALS['disablesessionprotection']=!empty($_POST['disablesessionprotection']);
1365 $GLOBALS['disablejquery']=!empty($_POST['disablejquery']); 1366 $GLOBALS['disablejquery']=!empty($_POST['disablejquery']);
1367 $GLOBALS['privateLinkByDefault']=!empty($_POST['privateLinkByDefault']);
1366 writeConfig(); 1368 writeConfig();
1367 echo '<script language="JavaScript">alert("Configuration was saved.");document.location=\'?do=tools\';</script>'; 1369 echo '<script language="JavaScript">alert("Configuration was saved.");document.location=\'?do=tools\';</script>';
1368 exit; 1370 exit;
@@ -1740,7 +1742,7 @@ function buildLinkList($PAGE,$LINKSDB)
1740 } 1742 }
1741 else 1743 else
1742 $linksToDisplay = $LINKSDB; // otherwise, display without filtering. 1744 $linksToDisplay = $LINKSDB; // otherwise, display without filtering.
1743 1745
1744 // Option: Show only private links 1746 // Option: Show only private links
1745 if (!empty($_SESSION['privateonly'])) 1747 if (!empty($_SESSION['privateonly']))
1746 { 1748 {
@@ -1785,7 +1787,7 @@ function buildLinkList($PAGE,$LINKSDB)
1785 $linkDisp[$keys[$i]] = $link; 1787 $linkDisp[$keys[$i]] = $link;
1786 $i++; 1788 $i++;
1787 } 1789 }
1788 1790
1789 // Compute paging navigation 1791 // Compute paging navigation
1790 $searchterm= ( empty($_GET['searchterm']) ? '' : '&searchterm='.$_GET['searchterm'] ); 1792 $searchterm= ( empty($_GET['searchterm']) ? '' : '&searchterm='.$_GET['searchterm'] );
1791 $searchtags= ( empty($_GET['searchtags']) ? '' : '&searchtags='.$_GET['searchtags'] ); 1793 $searchtags= ( empty($_GET['searchtags']) ? '' : '&searchtags='.$_GET['searchtags'] );
@@ -1793,8 +1795,8 @@ function buildLinkList($PAGE,$LINKSDB)
1793 $previous_page_url=''; if ($i!=count($keys)) $previous_page_url='?page='.($page+1).$searchterm.$searchtags; 1795 $previous_page_url=''; if ($i!=count($keys)) $previous_page_url='?page='.($page+1).$searchterm.$searchtags;
1794 $next_page_url='';if ($page>1) $next_page_url='?page='.($page-1).$searchterm.$searchtags; 1796 $next_page_url='';if ($page>1) $next_page_url='?page='.($page-1).$searchterm.$searchtags;
1795 1797
1796 $token = ''; if (isLoggedIn()) $token=getToken(); 1798 $token = ''; if (isLoggedIn()) $token=getToken();
1797 1799
1798 // Fill all template fields. 1800 // Fill all template fields.
1799 $PAGE->assign('linkcount',count($LINKSDB)); 1801 $PAGE->assign('linkcount',count($LINKSDB));
1800 $PAGE->assign('previous_page_url',$previous_page_url); 1802 $PAGE->assign('previous_page_url',$previous_page_url);
@@ -1803,7 +1805,7 @@ function buildLinkList($PAGE,$LINKSDB)
1803 $PAGE->assign('page_max',$pagecount); 1805 $PAGE->assign('page_max',$pagecount);
1804 $PAGE->assign('result_count',count($linksToDisplay)); 1806 $PAGE->assign('result_count',count($linksToDisplay));
1805 $PAGE->assign('search_type',$search_type); 1807 $PAGE->assign('search_type',$search_type);
1806 $PAGE->assign('search_crits',$search_crits); 1808 $PAGE->assign('search_crits',$search_crits);
1807 $PAGE->assign('redirector',empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector']); // optional redirector URL 1809 $PAGE->assign('redirector',empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector']); // optional redirector URL
1808 $PAGE->assign('token',$token); 1810 $PAGE->assign('token',$token);
1809 $PAGE->assign('links',$linkDisp); 1811 $PAGE->assign('links',$linkDisp);
@@ -1811,7 +1813,7 @@ function buildLinkList($PAGE,$LINKSDB)
1811} 1813}
1812 1814
1813// Compute the thumbnail for a link. 1815// Compute the thumbnail for a link.
1814// 1816//
1815// with a link to the original URL. 1817// with a link to the original URL.
1816// Understands various services (youtube.com...) 1818// Understands various services (youtube.com...)
1817// Input: $url = url for which the thumbnail must be found. 1819// Input: $url = url for which the thumbnail must be found.
@@ -1838,15 +1840,15 @@ function computeThumbnail($url,$href=false)
1838 { 1840 {
1839 $path = parse_url($url,PHP_URL_PATH); 1841 $path = parse_url($url,PHP_URL_PATH);
1840 return array('src'=>'http://img.youtube.com/vi'.$path.'/default.jpg', 1842 return array('src'=>'http://img.youtube.com/vi'.$path.'/default.jpg',
1841 'href'=>$href,'width'=>'120','height'=>'90','alt'=>'YouTube thumbnail'); 1843 'href'=>$href,'width'=>'120','height'=>'90','alt'=>'YouTube thumbnail');
1842 } 1844 }
1843 if ($domain=='pix.toile-libre.org') // pix.toile-libre.org image hosting 1845 if ($domain=='pix.toile-libre.org') // pix.toile-libre.org image hosting
1844 { 1846 {
1845 parse_str(parse_url($url,PHP_URL_QUERY), $params); // Extract image filename. 1847 parse_str(parse_url($url,PHP_URL_QUERY), $params); // Extract image filename.
1846 if (!empty($params) && !empty($params['img'])) return array('src'=>'http://pix.toile-libre.org/upload/thumb/'.urlencode($params['img']), 1848 if (!empty($params) && !empty($params['img'])) return array('src'=>'http://pix.toile-libre.org/upload/thumb/'.urlencode($params['img']),
1847 'href'=>$href,'style'=>'max-width:120px; max-height:150px','alt'=>'pix.toile-libre.org thumbnail'); 1849 'href'=>$href,'style'=>'max-width:120px; max-height:150px','alt'=>'pix.toile-libre.org thumbnail');
1848 } 1850 }
1849 1851
1850 if ($domain=='imgur.com') 1852 if ($domain=='imgur.com')
1851 { 1853 {
1852 $path = parse_url($url,PHP_URL_PATH); 1854 $path = parse_url($url,PHP_URL_PATH);
@@ -1925,7 +1927,7 @@ function computeThumbnail($url,$href=false)
1925 { 1927 {
1926 $sign = hash_hmac('sha256', $url, $GLOBALS['salt']); // We use the salt to sign data (it's random, secret, and specific to each installation) 1928 $sign = hash_hmac('sha256', $url, $GLOBALS['salt']); // We use the salt to sign data (it's random, secret, and specific to each installation)
1927 return array('src'=>indexUrl().'?do=genthumbnail&hmac='.htmlspecialchars($sign).'&url='.urlencode($url), 1929 return array('src'=>indexUrl().'?do=genthumbnail&hmac='.htmlspecialchars($sign).'&url='.urlencode($url),
1928 'href'=>$href,'width'=>'120','style'=>'height:auto;','alt'=>'thumbnail'); 1930 'href'=>$href,'width'=>'120','style'=>'height:auto;','alt'=>'thumbnail');
1929 } 1931 }
1930 return array(); // No thumbnail. 1932 return array(); // No thumbnail.
1931 1933
@@ -1942,7 +1944,7 @@ function thumbnail($url,$href=false)
1942{ 1944{
1943 $t = computeThumbnail($url,$href); 1945 $t = computeThumbnail($url,$href);
1944 if (count($t)==0) return ''; // Empty array = no thumbnail for this URL. 1946 if (count($t)==0) return ''; // Empty array = no thumbnail for this URL.
1945 1947
1946 $html='<a href="'.htmlspecialchars($t['href']).'"><img src="'.htmlspecialchars($t['src']).'"'; 1948 $html='<a href="'.htmlspecialchars($t['href']).'"><img src="'.htmlspecialchars($t['src']).'"';
1947 if (!empty($t['width'])) $html.=' width="'.htmlspecialchars($t['width']).'"'; 1949 if (!empty($t['width'])) $html.=' width="'.htmlspecialchars($t['width']).'"';
1948 if (!empty($t['height'])) $html.=' height="'.htmlspecialchars($t['height']).'"'; 1950 if (!empty($t['height'])) $html.=' height="'.htmlspecialchars($t['height']).'"';
@@ -1961,11 +1963,11 @@ function thumbnail($url,$href=false)
1961// Returns '' if no thumbnail available. 1963// Returns '' if no thumbnail available.
1962function lazyThumbnail($url,$href=false) 1964function lazyThumbnail($url,$href=false)
1963{ 1965{
1964 $t = computeThumbnail($url,$href); 1966 $t = computeThumbnail($url,$href);
1965 if (count($t)==0) return ''; // Empty array = no thumbnail for this URL. 1967 if (count($t)==0) return ''; // Empty array = no thumbnail for this URL.
1966 1968
1967 $html='<a href="'.htmlspecialchars($t['href']).'">'; 1969 $html='<a href="'.htmlspecialchars($t['href']).'">';
1968 1970
1969 // Lazy image (only loaded by javascript when in the viewport). 1971 // Lazy image (only loaded by javascript when in the viewport).
1970 if (!empty($GLOBALS['disablejquery'])) // (except if jQuery is disabled) 1972 if (!empty($GLOBALS['disablejquery'])) // (except if jQuery is disabled)
1971 $html.='<img class="lazyimage" src="'.htmlspecialchars($t['src']).'"'; 1973 $html.='<img class="lazyimage" src="'.htmlspecialchars($t['src']).'"';
@@ -1978,7 +1980,7 @@ function lazyThumbnail($url,$href=false)
1978 if (!empty($t['style'])) $html.=' style="'.htmlspecialchars($t['style']).'"'; 1980 if (!empty($t['style'])) $html.=' style="'.htmlspecialchars($t['style']).'"';
1979 if (!empty($t['alt'])) $html.=' alt="'.htmlspecialchars($t['alt']).'"'; 1981 if (!empty($t['alt'])) $html.=' alt="'.htmlspecialchars($t['alt']).'"';
1980 $html.='>'; 1982 $html.='>';
1981 1983
1982 // No-javascript fallback. 1984 // No-javascript fallback.
1983 $html.='<noscript><img src="'.htmlspecialchars($t['src']).'"'; 1985 $html.='<noscript><img src="'.htmlspecialchars($t['src']).'"';
1984 if (!empty($t['width'])) $html.=' width="'.htmlspecialchars($t['width']).'"'; 1986 if (!empty($t['width'])) $html.=' width="'.htmlspecialchars($t['width']).'"';
@@ -1986,7 +1988,7 @@ function lazyThumbnail($url,$href=false)
1986 if (!empty($t['style'])) $html.=' style="'.htmlspecialchars($t['style']).'"'; 1988 if (!empty($t['style'])) $html.=' style="'.htmlspecialchars($t['style']).'"';
1987 if (!empty($t['alt'])) $html.=' alt="'.htmlspecialchars($t['alt']).'"'; 1989 if (!empty($t['alt'])) $html.=' alt="'.htmlspecialchars($t['alt']).'"';
1988 $html.='></noscript></a>'; 1990 $html.='></noscript></a>';
1989 1991
1990 return $html; 1992 return $html;
1991} 1993}
1992 1994
@@ -2041,7 +2043,7 @@ function install()
2041 // Display config form: 2043 // Display config form:
2042 list($timezone_form,$timezone_js) = templateTZform(); 2044 list($timezone_form,$timezone_js) = templateTZform();
2043 $timezone_html=''; if ($timezone_form!='') $timezone_html='<tr><td valign="top"><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>'; 2045 $timezone_html=''; if ($timezone_form!='') $timezone_html='<tr><td valign="top"><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>';
2044 2046
2045 $PAGE = new pageBuilder; 2047 $PAGE = new pageBuilder;
2046 $PAGE->assign('timezone_html',$timezone_html); 2048 $PAGE->assign('timezone_html',$timezone_html);
2047 $PAGE->assign('timezone_js',$timezone_js); 2049 $PAGE->assign('timezone_js',$timezone_js);
@@ -2163,6 +2165,7 @@ function writeConfig()
2163 $config .= '$GLOBALS[\'redirector\']='.var_export($GLOBALS['redirector'],true).'; '; 2165 $config .= '$GLOBALS[\'redirector\']='.var_export($GLOBALS['redirector'],true).'; ';
2164 $config .= '$GLOBALS[\'disablesessionprotection\']='.var_export($GLOBALS['disablesessionprotection'],true).'; '; 2166 $config .= '$GLOBALS[\'disablesessionprotection\']='.var_export($GLOBALS['disablesessionprotection'],true).'; ';
2165 $config .= '$GLOBALS[\'disablejquery\']='.var_export($GLOBALS['disablejquery'],true).'; '; 2167 $config .= '$GLOBALS[\'disablejquery\']='.var_export($GLOBALS['disablejquery'],true).'; ';
2168 $config .= '$GLOBALS[\'privateLinkByDefault\']='.var_export($GLOBALS['privateLinkByDefault'],true).'; ';
2166 $config .= ' ?>'; 2169 $config .= ' ?>';
2167 if (!file_put_contents($GLOBALS['config']['CONFIG_FILE'],$config) || strcmp(file_get_contents($GLOBALS['config']['CONFIG_FILE']),$config)!=0) 2170 if (!file_put_contents($GLOBALS['config']['CONFIG_FILE'],$config) || strcmp(file_get_contents($GLOBALS['config']['CONFIG_FILE']),$config)!=0)
2168 { 2171 {
@@ -2279,7 +2282,7 @@ function genThumbnail()
2279 // The thumbnail for TED talks is located in the <link rel="image_src" [...]> tag on that page 2282 // The thumbnail for TED talks is located in the <link rel="image_src" [...]> tag on that page
2280 // http://www.ted.com/talks/mikko_hypponen_fighting_viruses_defending_the_net.html 2283 // http://www.ted.com/talks/mikko_hypponen_fighting_viruses_defending_the_net.html
2281 // <link rel="image_src" href="http://images.ted.com/images/ted/28bced335898ba54d4441809c5b1112ffaf36781_389x292.jpg" /> 2284 // <link rel="image_src" href="http://images.ted.com/images/ted/28bced335898ba54d4441809c5b1112ffaf36781_389x292.jpg" />
2282 list($httpstatus,$headers,$data) = getHTTP($url,5); 2285 list($httpstatus,$headers,$data) = getHTTP($url,5);
2283 if (strpos($httpstatus,'200 OK')!==false) 2286 if (strpos($httpstatus,'200 OK')!==false)
2284 { 2287 {
2285 // Extract the link to the thumbnail 2288 // Extract the link to the thumbnail
@@ -2302,7 +2305,7 @@ function genThumbnail()
2302 } 2305 }
2303 } 2306 }
2304 } 2307 }
2305 2308
2306 elseif ($domain=='xkcd.com' || endsWith($domain,'.xkcd.com')) 2309 elseif ($domain=='xkcd.com' || endsWith($domain,'.xkcd.com'))
2307 { 2310 {
2308 // There is no thumbnail available for xkcd comics, so download the whole image and resize it. 2311 // There is no thumbnail available for xkcd comics, so download the whole image and resize it.
@@ -2330,7 +2333,7 @@ function genThumbnail()
2330 } 2333 }
2331 } 2334 }
2332 } 2335 }
2333 } 2336 }
2334 2337
2335 else 2338 else
2336 { 2339 {
@@ -2402,7 +2405,7 @@ if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=g
2402if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; } 2405if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; }
2403if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; } 2406if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; }
2404if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=dailyrss')) { showDailyRSS(); exit; } 2407if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=dailyrss')) { showDailyRSS(); exit; }
2405if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=daily')) { showDaily(); exit; } 2408if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=daily')) { showDaily(); exit; }
2406if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI) 2409if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI)
2407if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE']; 2410if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE'];
2408renderPage(); 2411renderPage();