Merge pull request #30 from Knah-Tsaeb/master
Merged "Private by default" feature (when creating a new link).
This commit is contained in:
commit
22701e2d0b
3 changed files with 71 additions and 60 deletions
117
index.php
117
index.php
|
@ -97,6 +97,7 @@ function stripslashes_deep($value) { $value = is_array($value) ? array_map('stri
|
||||||
if (empty($GLOBALS['timezone'])) $GLOBALS['timezone']=date_default_timezone_get();
|
if (empty($GLOBALS['timezone'])) $GLOBALS['timezone']=date_default_timezone_get();
|
||||||
if (empty($GLOBALS['disablesessionprotection'])) $GLOBALS['disablesessionprotection']=false;
|
if (empty($GLOBALS['disablesessionprotection'])) $GLOBALS['disablesessionprotection']=false;
|
||||||
if (empty($GLOBALS['disablejquery'])) $GLOBALS['disablejquery']=false;
|
if (empty($GLOBALS['disablejquery'])) $GLOBALS['disablejquery']=false;
|
||||||
|
if (empty($GLOBALS['privateLinkByDefault'])) $GLOBALS['privateLinkByDefault']=false;
|
||||||
// I really need to rewrite Shaarli with a proper configuation manager.
|
// I really need to rewrite Shaarli with a proper configuation manager.
|
||||||
|
|
||||||
autoLocale(); // Sniff browser language and set date format accordingly.
|
autoLocale(); // Sniff browser language and set date format accordingly.
|
||||||
|
@ -146,7 +147,7 @@ class pageCache
|
||||||
private $shouldBeCached; // boolean: Should this url be cached ?
|
private $shouldBeCached; // boolean: Should this url be cached ?
|
||||||
private $filename; // Name of the cache file for this url
|
private $filename; // Name of the cache file for this url
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$url = url (typically the value returned by pageUrl())
|
$url = url (typically the value returned by pageUrl())
|
||||||
$shouldBeCached = boolean. If false, the cache will be disabled.
|
$shouldBeCached = boolean. If false, the cache will be disabled.
|
||||||
*/
|
*/
|
||||||
|
@ -155,7 +156,7 @@ public function __construct($url,$shouldBeCached)
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->filename = $GLOBALS['config']['PAGECACHE'].'/'.sha1($url).'.cache';
|
$this->filename = $GLOBALS['config']['PAGECACHE'].'/'.sha1($url).'.cache';
|
||||||
$this->shouldBeCached = $shouldBeCached;
|
$this->shouldBeCached = $shouldBeCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the page should be cached and a cached version exists,
|
// If the page should be cached and a cached version exists,
|
||||||
// returns the cached version (otherwise, return null).
|
// returns the cached version (otherwise, return null).
|
||||||
|
@ -183,7 +184,7 @@ public static function purgeCache()
|
||||||
$handler = opendir($GLOBALS['config']['PAGECACHE']);
|
$handler = opendir($GLOBALS['config']['PAGECACHE']);
|
||||||
if ($handler!==false)
|
if ($handler!==false)
|
||||||
{
|
{
|
||||||
while (($filename = readdir($handler))!==false)
|
while (($filename = readdir($handler))!==false)
|
||||||
{
|
{
|
||||||
if (endsWith($filename,'.cache')) { unlink($GLOBALS['config']['PAGECACHE'].'/'.$filename); }
|
if (endsWith($filename,'.cache')) { unlink($GLOBALS['config']['PAGECACHE'].'/'.$filename); }
|
||||||
}
|
}
|
||||||
|
@ -240,7 +241,7 @@ function text2clickable($url)
|
||||||
function keepMultipleSpaces($text)
|
function keepMultipleSpaces($text)
|
||||||
{
|
{
|
||||||
return str_replace(' ',' ',$text);
|
return str_replace(' ',' ',$text);
|
||||||
|
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------
|
||||||
// Sniff browser language to display dates in the right format automatically.
|
// Sniff browser language to display dates in the right format automatically.
|
||||||
|
@ -306,7 +307,7 @@ function check_auth($login,$password)
|
||||||
function isLoggedIn()
|
function isLoggedIn()
|
||||||
{
|
{
|
||||||
if ($GLOBALS['config']['OPEN_SHAARLI']) return true;
|
if ($GLOBALS['config']['OPEN_SHAARLI']) return true;
|
||||||
|
|
||||||
if (!isset($GLOBALS['login'])) return false; // Shaarli is not configured yet.
|
if (!isset($GLOBALS['login'])) return false; // Shaarli is not configured yet.
|
||||||
|
|
||||||
// If session does not exist on server side, or IP address has changed, or session has expired, logout.
|
// 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)
|
||||||
p = new pageBuilder;
|
p = new pageBuilder;
|
||||||
p.assign('myfield','myvalue');
|
p.assign('myfield','myvalue');
|
||||||
p.renderPage('mytemplate');
|
p.renderPage('mytemplate');
|
||||||
|
|
||||||
*/
|
*/
|
||||||
class pageBuilder
|
class pageBuilder
|
||||||
{
|
{
|
||||||
|
@ -615,11 +616,11 @@ class pageBuilder
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
$this->tpl=false;
|
$this->tpl=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function initialize()
|
private function initialize()
|
||||||
{
|
{
|
||||||
$this->tpl = new RainTPL;
|
$this->tpl = new RainTPL;
|
||||||
$this->tpl->assign('newversion',checkUpdate());
|
$this->tpl->assign('newversion',checkUpdate());
|
||||||
$this->tpl->assign('feedurl',htmlspecialchars(indexUrl()));
|
$this->tpl->assign('feedurl',htmlspecialchars(indexUrl()));
|
||||||
$searchcrits=''; // Search criteria
|
$searchcrits=''; // Search criteria
|
||||||
|
@ -634,16 +635,16 @@ private function initialize()
|
||||||
if (!empty($GLOBALS['title'])) $this->tpl->assign('pagetitle',$GLOBALS['title']);
|
if (!empty($GLOBALS['title'])) $this->tpl->assign('pagetitle',$GLOBALS['title']);
|
||||||
if (!empty($GLOBALS['pagetitle'])) $this->tpl->assign('pagetitle',$GLOBALS['pagetitle']);
|
if (!empty($GLOBALS['pagetitle'])) $this->tpl->assign('pagetitle',$GLOBALS['pagetitle']);
|
||||||
$this->tpl->assign('shaarlititle',empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title'] );
|
$this->tpl->assign('shaarlititle',empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title'] );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following assign() method is basically the same as RainTPL (except that it's lazy)
|
// The following assign() method is basically the same as RainTPL (except that it's lazy)
|
||||||
public function assign($what,$where)
|
public function assign($what,$where)
|
||||||
{
|
{
|
||||||
if ($this->tpl===false) $this->initialize(); // Lazy initialization
|
if ($this->tpl===false) $this->initialize(); // Lazy initialization
|
||||||
$this->tpl->assign($what,$where);
|
$this->tpl->assign($what,$where);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render a specific page (using a template).
|
// Render a specific page (using a template).
|
||||||
// eg. pb.renderPage('picwall')
|
// eg. pb.renderPage('picwall')
|
||||||
public function renderPage($page)
|
public function renderPage($page)
|
||||||
|
@ -661,14 +662,14 @@ public function renderPage($page)
|
||||||
echo $mylinks['20110826_161819']['title'];
|
echo $mylinks['20110826_161819']['title'];
|
||||||
foreach($mylinks as $link)
|
foreach($mylinks as $link)
|
||||||
echo $link['title'].' at url '.$link['url'].' ; description:'.$link['description'];
|
echo $link['title'].' at url '.$link['url'].' ; description:'.$link['description'];
|
||||||
|
|
||||||
Available keys:
|
Available keys:
|
||||||
title : Title of the link
|
title : Title of the link
|
||||||
url : URL of the link. Can be absolute or relative. Relative URLs are permalinks (eg.'?m-ukcw')
|
url : URL of the link. Can be absolute or relative. Relative URLs are permalinks (eg.'?m-ukcw')
|
||||||
description : description of the entry
|
description : description of the entry
|
||||||
private : Is this link private ? 0=no, other value=yes
|
private : Is this link private ? 0=no, other value=yes
|
||||||
linkdate : date of the creation of this entry, in the form YYYYMMDD_HHMMSS (eg.'20110914_192317')
|
linkdate : date of the creation of this entry, in the form YYYYMMDD_HHMMSS (eg.'20110914_192317')
|
||||||
tags : tags attached to this entry (separated by spaces)
|
tags : tags attached to this entry (separated by spaces)
|
||||||
|
|
||||||
We implement 3 interfaces:
|
We implement 3 interfaces:
|
||||||
- ArrayAccess so that this object behaves like an associative array.
|
- ArrayAccess so that this object behaves like an associative array.
|
||||||
|
@ -847,7 +848,7 @@ public function allTags()
|
||||||
arsort($tags); // Sort tags by usage (most used tag first)
|
arsort($tags); // Sort tags by usage (most used tag first)
|
||||||
return $tags;
|
return $tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the list of days containing articles (oldest first)
|
// Returns the list of days containing articles (oldest first)
|
||||||
// Output: An array containing days (in format YYYYMMDD).
|
// Output: An array containing days (in format YYYYMMDD).
|
||||||
public function days()
|
public function days()
|
||||||
|
@ -1007,7 +1008,7 @@ function showATOM()
|
||||||
$feed.=$entries;
|
$feed.=$entries;
|
||||||
$feed.='</feed><!-- Cached version of '.pageUrl().' -->';
|
$feed.='</feed><!-- Cached version of '.pageUrl().' -->';
|
||||||
echo $feed;
|
echo $feed;
|
||||||
|
|
||||||
$cache->cache(ob_get_contents());
|
$cache->cache(ob_get_contents());
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
exit;
|
exit;
|
||||||
|
@ -1025,11 +1026,11 @@ function showDailyRSS()
|
||||||
$cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; }
|
$cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; }
|
||||||
// If cached was not found (or not usable), then read the database and build the response:
|
// If cached was not found (or not usable), then read the database and build the response:
|
||||||
$LINKSDB=new linkdb(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in).
|
$LINKSDB=new linkdb(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in).
|
||||||
|
|
||||||
/* Some Shaarlies may have very few links, so we need to look
|
/* Some Shaarlies may have very few links, so we need to look
|
||||||
back in time (rsort()) until we have enough days ($nb_of_days).
|
back in time (rsort()) until we have enough days ($nb_of_days).
|
||||||
*/
|
*/
|
||||||
$linkdates=array(); foreach($LINKSDB as $linkdate=>$value) { $linkdates[]=$linkdate; }
|
$linkdates=array(); foreach($LINKSDB as $linkdate=>$value) { $linkdates[]=$linkdate; }
|
||||||
rsort($linkdates);
|
rsort($linkdates);
|
||||||
$nb_of_days=7; // We take 7 days.
|
$nb_of_days=7; // We take 7 days.
|
||||||
$today=Date('Ymd');
|
$today=Date('Ymd');
|
||||||
|
@ -1044,14 +1045,14 @@ function showDailyRSS()
|
||||||
}
|
}
|
||||||
if (count($days)>$nb_of_days) break; // Have we collected enough days ?
|
if (count($days)>$nb_of_days) break; // Have we collected enough days ?
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the RSS feed.
|
// Build the RSS feed.
|
||||||
header('Content-Type: application/rss+xml; charset=utf-8');
|
header('Content-Type: application/rss+xml; charset=utf-8');
|
||||||
$pageaddr=htmlspecialchars(indexUrl());
|
$pageaddr=htmlspecialchars(indexUrl());
|
||||||
echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">';
|
echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">';
|
||||||
echo '<channel><title>Daily - '.htmlspecialchars($GLOBALS['title']).'</title><link>'.$pageaddr.'</link>';
|
echo '<channel><title>Daily - '.htmlspecialchars($GLOBALS['title']).'</title><link>'.$pageaddr.'</link>';
|
||||||
echo '<description>Daily shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n";
|
echo '<description>Daily shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n";
|
||||||
|
|
||||||
foreach($days as $day=>$linkdates) // For each day.
|
foreach($days as $day=>$linkdates) // For each day.
|
||||||
{
|
{
|
||||||
$daydate = utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000'))); // Full text date
|
$daydate = utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000'))); // Full text date
|
||||||
|
@ -1059,7 +1060,7 @@ function showDailyRSS()
|
||||||
$absurl=htmlspecialchars(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
|
$absurl=htmlspecialchars(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
|
||||||
echo '<item><title>'.htmlspecialchars($GLOBALS['title'].' - '.$daydate).'</title><guid>'.$absurl.'</guid><link>'.$absurl.'</link>';
|
echo '<item><title>'.htmlspecialchars($GLOBALS['title'].' - '.$daydate).'</title><guid>'.$absurl.'</guid><link>'.$absurl.'</link>';
|
||||||
echo '<pubDate>'.htmlspecialchars($rfc822date)."</pubDate>";
|
echo '<pubDate>'.htmlspecialchars($rfc822date)."</pubDate>";
|
||||||
|
|
||||||
// Build the HTML body of this RSS entry.
|
// Build the HTML body of this RSS entry.
|
||||||
$html='';
|
$html='';
|
||||||
$href='';
|
$href='';
|
||||||
|
@ -1069,21 +1070,21 @@ 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['localdate']=linkdate2locale($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;
|
||||||
}
|
}
|
||||||
// Then build the HTML for this day:
|
// Then build the HTML for this day:
|
||||||
$tpl = new RainTPL;
|
$tpl = new RainTPL;
|
||||||
$tpl->assign('links',$links);
|
$tpl->assign('links',$links);
|
||||||
$html = $tpl->draw('dailyrss',$return_string=true);
|
$html = $tpl->draw('dailyrss',$return_string=true);
|
||||||
echo "\n";
|
echo "\n";
|
||||||
echo '<description><![CDATA['.$html.']]></description>'."\n</item>\n\n";
|
echo '<description><![CDATA['.$html.']]></description>'."\n</item>\n\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
echo '</channel></rss><!-- Cached version of '.pageUrl().' -->';
|
echo '</channel></rss><!-- Cached version of '.pageUrl().' -->';
|
||||||
|
|
||||||
$cache->cache(ob_get_contents());
|
$cache->cache(ob_get_contents());
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
exit;
|
exit;
|
||||||
|
@ -1097,12 +1098,12 @@ function showDaily()
|
||||||
|
|
||||||
$day=Date('Ymd',strtotime('-1 day')); // Yesterday, in format YYYYMMDD.
|
$day=Date('Ymd',strtotime('-1 day')); // Yesterday, in format YYYYMMDD.
|
||||||
if (isset($_GET['day'])) $day=$_GET['day'];
|
if (isset($_GET['day'])) $day=$_GET['day'];
|
||||||
|
|
||||||
$days = $LINKSDB->days();
|
$days = $LINKSDB->days();
|
||||||
$i = array_search($day,$days);
|
$i = array_search($day,$days);
|
||||||
if ($i==false) { $i=count($days)-1; $day=$days[$i]; }
|
if ($i==false) { $i=count($days)-1; $day=$days[$i]; }
|
||||||
$previousday='';
|
$previousday='';
|
||||||
$nextday='';
|
$nextday='';
|
||||||
if ($i!==false)
|
if ($i!==false)
|
||||||
{
|
{
|
||||||
if ($i>1) $previousday=$days[$i-1];
|
if ($i>1) $previousday=$days[$i-1];
|
||||||
|
@ -1117,12 +1118,12 @@ function showDaily()
|
||||||
uasort($taglist, 'strcasecmp');
|
uasort($taglist, 'strcasecmp');
|
||||||
$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']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We need to spread the articles on 3 columns.
|
/* We need to spread the articles on 3 columns.
|
||||||
I did not want to use a javascript lib like http://masonry.desandro.com/
|
I did not want to use a javascript lib like http://masonry.desandro.com/
|
||||||
so I manually spread entries with a simple method: I roughly evaluate the
|
so I manually spread entries with a simple method: I roughly evaluate the
|
||||||
height of a div according to title and description length.
|
height of a div according to title and description length.
|
||||||
*/
|
*/
|
||||||
$columns=array(array(),array(),array()); // Entries to display, for each column.
|
$columns=array(array(),array(),array()); // Entries to display, for each column.
|
||||||
|
@ -1150,7 +1151,7 @@ function showDaily()
|
||||||
$PAGE->assign('col3',$columns[2]);
|
$PAGE->assign('col3',$columns[2]);
|
||||||
$PAGE->assign('day',utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000'))));
|
$PAGE->assign('day',utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000'))));
|
||||||
$PAGE->assign('previousday',$previousday);
|
$PAGE->assign('previousday',$previousday);
|
||||||
$PAGE->assign('nextday',$nextday);
|
$PAGE->assign('nextday',$nextday);
|
||||||
$PAGE->renderPage('daily');
|
$PAGE->renderPage('daily');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -1229,7 +1230,7 @@ function renderPage()
|
||||||
$PAGE->assign('linkcount',count($LINKSDB));
|
$PAGE->assign('linkcount',count($LINKSDB));
|
||||||
$PAGE->assign('tags',$tagList);
|
$PAGE->assign('tags',$tagList);
|
||||||
$PAGE->renderPage('tagcloud');
|
$PAGE->renderPage('tagcloud');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------- User clicks on a tag in a link: The tag is added to the list of searched tags (searchtags=...)
|
// -------- 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()
|
||||||
header('Location: '.$referer);
|
header('Location: '.$referer);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------- User wants to see only private links (toggle)
|
// -------- User wants to see only private links (toggle)
|
||||||
if (isset($_GET['privateonly']))
|
if (isset($_GET['privateonly']))
|
||||||
{
|
{
|
||||||
|
@ -1363,6 +1364,7 @@ function renderPage()
|
||||||
$GLOBALS['redirector']=$_POST['redirector'];
|
$GLOBALS['redirector']=$_POST['redirector'];
|
||||||
$GLOBALS['disablesessionprotection']=!empty($_POST['disablesessionprotection']);
|
$GLOBALS['disablesessionprotection']=!empty($_POST['disablesessionprotection']);
|
||||||
$GLOBALS['disablejquery']=!empty($_POST['disablejquery']);
|
$GLOBALS['disablejquery']=!empty($_POST['disablejquery']);
|
||||||
|
$GLOBALS['privateLinkByDefault']=!empty($_POST['privateLinkByDefault']);
|
||||||
writeConfig();
|
writeConfig();
|
||||||
echo '<script language="JavaScript">alert("Configuration was saved.");document.location=\'?do=tools\';</script>';
|
echo '<script language="JavaScript">alert("Configuration was saved.");document.location=\'?do=tools\';</script>';
|
||||||
exit;
|
exit;
|
||||||
|
@ -1740,7 +1742,7 @@ function buildLinkList($PAGE,$LINKSDB)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$linksToDisplay = $LINKSDB; // otherwise, display without filtering.
|
$linksToDisplay = $LINKSDB; // otherwise, display without filtering.
|
||||||
|
|
||||||
// Option: Show only private links
|
// Option: Show only private links
|
||||||
if (!empty($_SESSION['privateonly']))
|
if (!empty($_SESSION['privateonly']))
|
||||||
{
|
{
|
||||||
|
@ -1785,7 +1787,7 @@ function buildLinkList($PAGE,$LINKSDB)
|
||||||
$linkDisp[$keys[$i]] = $link;
|
$linkDisp[$keys[$i]] = $link;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute paging navigation
|
// Compute paging navigation
|
||||||
$searchterm= ( empty($_GET['searchterm']) ? '' : '&searchterm='.$_GET['searchterm'] );
|
$searchterm= ( empty($_GET['searchterm']) ? '' : '&searchterm='.$_GET['searchterm'] );
|
||||||
$searchtags= ( empty($_GET['searchtags']) ? '' : '&searchtags='.$_GET['searchtags'] );
|
$searchtags= ( empty($_GET['searchtags']) ? '' : '&searchtags='.$_GET['searchtags'] );
|
||||||
|
@ -1793,8 +1795,8 @@ function buildLinkList($PAGE,$LINKSDB)
|
||||||
$previous_page_url=''; if ($i!=count($keys)) $previous_page_url='?page='.($page+1).$searchterm.$searchtags;
|
$previous_page_url=''; if ($i!=count($keys)) $previous_page_url='?page='.($page+1).$searchterm.$searchtags;
|
||||||
$next_page_url='';if ($page>1) $next_page_url='?page='.($page-1).$searchterm.$searchtags;
|
$next_page_url='';if ($page>1) $next_page_url='?page='.($page-1).$searchterm.$searchtags;
|
||||||
|
|
||||||
$token = ''; if (isLoggedIn()) $token=getToken();
|
$token = ''; if (isLoggedIn()) $token=getToken();
|
||||||
|
|
||||||
// Fill all template fields.
|
// Fill all template fields.
|
||||||
$PAGE->assign('linkcount',count($LINKSDB));
|
$PAGE->assign('linkcount',count($LINKSDB));
|
||||||
$PAGE->assign('previous_page_url',$previous_page_url);
|
$PAGE->assign('previous_page_url',$previous_page_url);
|
||||||
|
@ -1803,7 +1805,7 @@ function buildLinkList($PAGE,$LINKSDB)
|
||||||
$PAGE->assign('page_max',$pagecount);
|
$PAGE->assign('page_max',$pagecount);
|
||||||
$PAGE->assign('result_count',count($linksToDisplay));
|
$PAGE->assign('result_count',count($linksToDisplay));
|
||||||
$PAGE->assign('search_type',$search_type);
|
$PAGE->assign('search_type',$search_type);
|
||||||
$PAGE->assign('search_crits',$search_crits);
|
$PAGE->assign('search_crits',$search_crits);
|
||||||
$PAGE->assign('redirector',empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector']); // optional redirector URL
|
$PAGE->assign('redirector',empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector']); // optional redirector URL
|
||||||
$PAGE->assign('token',$token);
|
$PAGE->assign('token',$token);
|
||||||
$PAGE->assign('links',$linkDisp);
|
$PAGE->assign('links',$linkDisp);
|
||||||
|
@ -1811,7 +1813,7 @@ function buildLinkList($PAGE,$LINKSDB)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the thumbnail for a link.
|
// Compute the thumbnail for a link.
|
||||||
//
|
//
|
||||||
// with a link to the original URL.
|
// with a link to the original URL.
|
||||||
// Understands various services (youtube.com...)
|
// Understands various services (youtube.com...)
|
||||||
// Input: $url = url for which the thumbnail must be found.
|
// Input: $url = url for which the thumbnail must be found.
|
||||||
|
@ -1838,15 +1840,15 @@ function computeThumbnail($url,$href=false)
|
||||||
{
|
{
|
||||||
$path = parse_url($url,PHP_URL_PATH);
|
$path = parse_url($url,PHP_URL_PATH);
|
||||||
return array('src'=>'http://img.youtube.com/vi'.$path.'/default.jpg',
|
return array('src'=>'http://img.youtube.com/vi'.$path.'/default.jpg',
|
||||||
'href'=>$href,'width'=>'120','height'=>'90','alt'=>'YouTube thumbnail');
|
'href'=>$href,'width'=>'120','height'=>'90','alt'=>'YouTube thumbnail');
|
||||||
}
|
}
|
||||||
if ($domain=='pix.toile-libre.org') // pix.toile-libre.org image hosting
|
if ($domain=='pix.toile-libre.org') // pix.toile-libre.org image hosting
|
||||||
{
|
{
|
||||||
parse_str(parse_url($url,PHP_URL_QUERY), $params); // Extract image filename.
|
parse_str(parse_url($url,PHP_URL_QUERY), $params); // Extract image filename.
|
||||||
if (!empty($params) && !empty($params['img'])) return array('src'=>'http://pix.toile-libre.org/upload/thumb/'.urlencode($params['img']),
|
if (!empty($params) && !empty($params['img'])) return array('src'=>'http://pix.toile-libre.org/upload/thumb/'.urlencode($params['img']),
|
||||||
'href'=>$href,'style'=>'max-width:120px; max-height:150px','alt'=>'pix.toile-libre.org thumbnail');
|
'href'=>$href,'style'=>'max-width:120px; max-height:150px','alt'=>'pix.toile-libre.org thumbnail');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($domain=='imgur.com')
|
if ($domain=='imgur.com')
|
||||||
{
|
{
|
||||||
$path = parse_url($url,PHP_URL_PATH);
|
$path = parse_url($url,PHP_URL_PATH);
|
||||||
|
@ -1925,7 +1927,7 @@ function computeThumbnail($url,$href=false)
|
||||||
{
|
{
|
||||||
$sign = hash_hmac('sha256', $url, $GLOBALS['salt']); // We use the salt to sign data (it's random, secret, and specific to each installation)
|
$sign = hash_hmac('sha256', $url, $GLOBALS['salt']); // We use the salt to sign data (it's random, secret, and specific to each installation)
|
||||||
return array('src'=>indexUrl().'?do=genthumbnail&hmac='.htmlspecialchars($sign).'&url='.urlencode($url),
|
return array('src'=>indexUrl().'?do=genthumbnail&hmac='.htmlspecialchars($sign).'&url='.urlencode($url),
|
||||||
'href'=>$href,'width'=>'120','style'=>'height:auto;','alt'=>'thumbnail');
|
'href'=>$href,'width'=>'120','style'=>'height:auto;','alt'=>'thumbnail');
|
||||||
}
|
}
|
||||||
return array(); // No thumbnail.
|
return array(); // No thumbnail.
|
||||||
|
|
||||||
|
@ -1942,7 +1944,7 @@ function thumbnail($url,$href=false)
|
||||||
{
|
{
|
||||||
$t = computeThumbnail($url,$href);
|
$t = computeThumbnail($url,$href);
|
||||||
if (count($t)==0) return ''; // Empty array = no thumbnail for this URL.
|
if (count($t)==0) return ''; // Empty array = no thumbnail for this URL.
|
||||||
|
|
||||||
$html='<a href="'.htmlspecialchars($t['href']).'"><img src="'.htmlspecialchars($t['src']).'"';
|
$html='<a href="'.htmlspecialchars($t['href']).'"><img src="'.htmlspecialchars($t['src']).'"';
|
||||||
if (!empty($t['width'])) $html.=' width="'.htmlspecialchars($t['width']).'"';
|
if (!empty($t['width'])) $html.=' width="'.htmlspecialchars($t['width']).'"';
|
||||||
if (!empty($t['height'])) $html.=' height="'.htmlspecialchars($t['height']).'"';
|
if (!empty($t['height'])) $html.=' height="'.htmlspecialchars($t['height']).'"';
|
||||||
|
@ -1961,11 +1963,11 @@ function thumbnail($url,$href=false)
|
||||||
// Returns '' if no thumbnail available.
|
// Returns '' if no thumbnail available.
|
||||||
function lazyThumbnail($url,$href=false)
|
function lazyThumbnail($url,$href=false)
|
||||||
{
|
{
|
||||||
$t = computeThumbnail($url,$href);
|
$t = computeThumbnail($url,$href);
|
||||||
if (count($t)==0) return ''; // Empty array = no thumbnail for this URL.
|
if (count($t)==0) return ''; // Empty array = no thumbnail for this URL.
|
||||||
|
|
||||||
$html='<a href="'.htmlspecialchars($t['href']).'">';
|
$html='<a href="'.htmlspecialchars($t['href']).'">';
|
||||||
|
|
||||||
// Lazy image (only loaded by javascript when in the viewport).
|
// Lazy image (only loaded by javascript when in the viewport).
|
||||||
if (!empty($GLOBALS['disablejquery'])) // (except if jQuery is disabled)
|
if (!empty($GLOBALS['disablejquery'])) // (except if jQuery is disabled)
|
||||||
$html.='<img class="lazyimage" src="'.htmlspecialchars($t['src']).'"';
|
$html.='<img class="lazyimage" src="'.htmlspecialchars($t['src']).'"';
|
||||||
|
@ -1978,7 +1980,7 @@ function lazyThumbnail($url,$href=false)
|
||||||
if (!empty($t['style'])) $html.=' style="'.htmlspecialchars($t['style']).'"';
|
if (!empty($t['style'])) $html.=' style="'.htmlspecialchars($t['style']).'"';
|
||||||
if (!empty($t['alt'])) $html.=' alt="'.htmlspecialchars($t['alt']).'"';
|
if (!empty($t['alt'])) $html.=' alt="'.htmlspecialchars($t['alt']).'"';
|
||||||
$html.='>';
|
$html.='>';
|
||||||
|
|
||||||
// No-javascript fallback.
|
// No-javascript fallback.
|
||||||
$html.='<noscript><img src="'.htmlspecialchars($t['src']).'"';
|
$html.='<noscript><img src="'.htmlspecialchars($t['src']).'"';
|
||||||
if (!empty($t['width'])) $html.=' width="'.htmlspecialchars($t['width']).'"';
|
if (!empty($t['width'])) $html.=' width="'.htmlspecialchars($t['width']).'"';
|
||||||
|
@ -1986,7 +1988,7 @@ function lazyThumbnail($url,$href=false)
|
||||||
if (!empty($t['style'])) $html.=' style="'.htmlspecialchars($t['style']).'"';
|
if (!empty($t['style'])) $html.=' style="'.htmlspecialchars($t['style']).'"';
|
||||||
if (!empty($t['alt'])) $html.=' alt="'.htmlspecialchars($t['alt']).'"';
|
if (!empty($t['alt'])) $html.=' alt="'.htmlspecialchars($t['alt']).'"';
|
||||||
$html.='></noscript></a>';
|
$html.='></noscript></a>';
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2041,7 +2043,7 @@ function install()
|
||||||
// Display config form:
|
// Display config form:
|
||||||
list($timezone_form,$timezone_js) = templateTZform();
|
list($timezone_form,$timezone_js) = templateTZform();
|
||||||
$timezone_html=''; if ($timezone_form!='') $timezone_html='<tr><td valign="top"><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>';
|
$timezone_html=''; if ($timezone_form!='') $timezone_html='<tr><td valign="top"><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>';
|
||||||
|
|
||||||
$PAGE = new pageBuilder;
|
$PAGE = new pageBuilder;
|
||||||
$PAGE->assign('timezone_html',$timezone_html);
|
$PAGE->assign('timezone_html',$timezone_html);
|
||||||
$PAGE->assign('timezone_js',$timezone_js);
|
$PAGE->assign('timezone_js',$timezone_js);
|
||||||
|
@ -2163,6 +2165,7 @@ function writeConfig()
|
||||||
$config .= '$GLOBALS[\'redirector\']='.var_export($GLOBALS['redirector'],true).'; ';
|
$config .= '$GLOBALS[\'redirector\']='.var_export($GLOBALS['redirector'],true).'; ';
|
||||||
$config .= '$GLOBALS[\'disablesessionprotection\']='.var_export($GLOBALS['disablesessionprotection'],true).'; ';
|
$config .= '$GLOBALS[\'disablesessionprotection\']='.var_export($GLOBALS['disablesessionprotection'],true).'; ';
|
||||||
$config .= '$GLOBALS[\'disablejquery\']='.var_export($GLOBALS['disablejquery'],true).'; ';
|
$config .= '$GLOBALS[\'disablejquery\']='.var_export($GLOBALS['disablejquery'],true).'; ';
|
||||||
|
$config .= '$GLOBALS[\'privateLinkByDefault\']='.var_export($GLOBALS['privateLinkByDefault'],true).'; ';
|
||||||
$config .= ' ?>';
|
$config .= ' ?>';
|
||||||
if (!file_put_contents($GLOBALS['config']['CONFIG_FILE'],$config) || strcmp(file_get_contents($GLOBALS['config']['CONFIG_FILE']),$config)!=0)
|
if (!file_put_contents($GLOBALS['config']['CONFIG_FILE'],$config) || strcmp(file_get_contents($GLOBALS['config']['CONFIG_FILE']),$config)!=0)
|
||||||
{
|
{
|
||||||
|
@ -2279,7 +2282,7 @@ function genThumbnail()
|
||||||
// The thumbnail for TED talks is located in the <link rel="image_src" [...]> tag on that page
|
// The thumbnail for TED talks is located in the <link rel="image_src" [...]> tag on that page
|
||||||
// http://www.ted.com/talks/mikko_hypponen_fighting_viruses_defending_the_net.html
|
// http://www.ted.com/talks/mikko_hypponen_fighting_viruses_defending_the_net.html
|
||||||
// <link rel="image_src" href="http://images.ted.com/images/ted/28bced335898ba54d4441809c5b1112ffaf36781_389x292.jpg" />
|
// <link rel="image_src" href="http://images.ted.com/images/ted/28bced335898ba54d4441809c5b1112ffaf36781_389x292.jpg" />
|
||||||
list($httpstatus,$headers,$data) = getHTTP($url,5);
|
list($httpstatus,$headers,$data) = getHTTP($url,5);
|
||||||
if (strpos($httpstatus,'200 OK')!==false)
|
if (strpos($httpstatus,'200 OK')!==false)
|
||||||
{
|
{
|
||||||
// Extract the link to the thumbnail
|
// Extract the link to the thumbnail
|
||||||
|
@ -2302,7 +2305,7 @@ function genThumbnail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
elseif ($domain=='xkcd.com' || endsWith($domain,'.xkcd.com'))
|
elseif ($domain=='xkcd.com' || endsWith($domain,'.xkcd.com'))
|
||||||
{
|
{
|
||||||
// There is no thumbnail available for xkcd comics, so download the whole image and resize it.
|
// There is no thumbnail available for xkcd comics, so download the whole image and resize it.
|
||||||
|
@ -2330,7 +2333,7 @@ function genThumbnail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2402,7 +2405,7 @@ function invalidateCaches()
|
||||||
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; }
|
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; }
|
||||||
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; }
|
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; }
|
||||||
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=dailyrss')) { showDailyRSS(); exit; }
|
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=dailyrss')) { showDailyRSS(); exit; }
|
||||||
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=daily')) { showDaily(); exit; }
|
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=daily')) { showDaily(); exit; }
|
||||||
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI)
|
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI)
|
||||||
if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE'];
|
if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE'];
|
||||||
renderPage();
|
renderPage();
|
||||||
|
|
|
@ -19,8 +19,10 @@
|
||||||
|
|
||||||
<tr><td valign="top"><b>Features:</b></td><td>
|
<tr><td valign="top"><b>Features:</b></td><td>
|
||||||
<input type="checkbox" name="disablejquery" id="disablejquery" {if="!empty($GLOBALS['disablejquery'])"}checked{/if}><label for="disablejquery"> Disable jQuery and all heavy javascript (for example: Autocomplete in tags. Useful for slow computers.)</label>
|
<input type="checkbox" name="disablejquery" id="disablejquery" {if="!empty($GLOBALS['disablejquery'])"}checked{/if}><label for="disablejquery"> Disable jQuery and all heavy javascript (for example: Autocomplete in tags. Useful for slow computers.)</label>
|
||||||
|
</td></tr>
|
||||||
|
<tr><td valign="top"><b>New link:</b></td><td>
|
||||||
|
<input type="checkbox" name="privateLinkByDefault" id="privateLinkByDefault" {if="!empty($GLOBALS['privateLinkByDefault'])"}checked{/if}/><label for="privateLinkByDefault"> All new link are private by default</label></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr><td></td><td align="right"><input type="submit" name="Save" value="Save config" class="bigbutton"></td></tr>
|
<tr><td></td><td align="right"><input type="submit" name="Save" value="Save config" class="bigbutton"></td></tr>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>{include="includes"}</head>
|
<head>{include="includes"}</head>
|
||||||
<body
|
<body
|
||||||
{if condition="$link.title==''"}onload="document.linkform.lf_title.focus();"
|
{if condition="$link.title==''"}onload="document.linkform.lf_title.focus();"
|
||||||
{elseif condition="$link.description==''"}onload="document.linkform.lf_description.focus();"
|
{elseif condition="$link.description==''"}onload="document.linkform.lf_description.focus();"
|
||||||
{else}onload="document.linkform.lf_tags.focus();"{/if} >
|
{else}onload="document.linkform.lf_tags.focus();"{/if} >
|
||||||
|
@ -14,7 +14,13 @@
|
||||||
<i>Title</i><br><input type="text" name="lf_title" value="{$link.title|htmlspecialchars}" style="width:100%"><br>
|
<i>Title</i><br><input type="text" name="lf_title" value="{$link.title|htmlspecialchars}" style="width:100%"><br>
|
||||||
<i>Description</i><br><textarea name="lf_description" rows="4" cols="25" style="width:100%">{$link.description|htmlspecialchars}</textarea><br>
|
<i>Description</i><br><textarea name="lf_description" rows="4" cols="25" style="width:100%">{$link.description|htmlspecialchars}</textarea><br>
|
||||||
<i>Tags</i><br><input type="text" id="lf_tags" name="lf_tags" value="{$link.tags|htmlspecialchars}" style="width:100%"><br>
|
<i>Tags</i><br><input type="text" id="lf_tags" name="lf_tags" value="{$link.tags|htmlspecialchars}" style="width:100%"><br>
|
||||||
<input type="checkbox" {if condition="$link.private!=0"}checked="yes"{/if} style="margin:7 0 10 0;" name="lf_private" id="lf_private"> <label for="lf_private"><i>Private</i></label><br>
|
{if condition="($link_is_new && $GLOBALS['privateLinkByDefault']==true) || $link.private == true"}
|
||||||
|
<input type="checkbox" checked="checked" name="lf_private" id="lf_private">
|
||||||
|
<label for="lf_private"><i>Private</i></label><br>
|
||||||
|
{else}
|
||||||
|
<input type="checkbox" name="lf_private" id="lf_private">
|
||||||
|
<label for="lf_private"><i>Private</i></label><br>
|
||||||
|
{/if}
|
||||||
<input type="submit" value="Save" name="save_edit" class="bigbutton" style="margin-left:40px;">
|
<input type="submit" value="Save" name="save_edit" class="bigbutton" style="margin-left:40px;">
|
||||||
<input type="submit" value="Cancel" name="cancel_edit" class="bigbutton" style="margin-left:40px;">
|
<input type="submit" value="Cancel" name="cancel_edit" class="bigbutton" style="margin-left:40px;">
|
||||||
{if condition="!$link_is_new"}<input type="submit" value="Delete" name="delete_link" class="bigbutton" style="margin-left:180px;" onClick="return confirmDeleteLink();">{/if}
|
{if condition="!$link_is_new"}<input type="submit" value="Delete" name="delete_link" class="bigbutton" style="margin-left:180px;" onClick="return confirmDeleteLink();">{/if}
|
||||||
|
|
Loading…
Reference in a new issue