From 040eb18ec8cdabd5ea855e108f81f97fbf0478c4 Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Fri, 11 Oct 2013 15:18:37 +0200 Subject: [PATCH 1/3] Add source of link (via imput) --- index.php | 26 +++++++++++++++++++++----- tpl/editlink.html | 1 + tpl/linklist.html | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 23a6294c..0643a4d8 100644 --- a/index.php +++ b/index.php @@ -432,6 +432,12 @@ if (isset($_POST['login'])) // ------------------------------------------------------------------------------------------ // Misc utility functions: +// Try to get just domain for @via +function getJustDomain($url){ + $parts = parse_url($url); + return trim($parts['host']); + } + // Returns the server URL (including port and http/https), without path. // eg. "http://myserver.com:8080" // You can append $_SERVER['SCRIPT_NAME'] to get the current script URL. @@ -794,7 +800,8 @@ class linkdb implements Iterator, Countable, ArrayAccess $found= (strpos(strtolower($l['title']),$s)!==false) || (strpos(strtolower($l['description']),$s)!==false) || (strpos(strtolower($l['url']),$s)!==false) - || (strpos(strtolower($l['tags']),$s)!==false); + || (strpos(strtolower($l['tags']),$s)!==false) + || (strpos(strtolower($l['via']),$s)!==false); if ($found) $filtered[$l['linkdate']] = $l; } krsort($filtered); @@ -939,7 +946,12 @@ function showRSS() // If user wants permalinks first, put the final link in description if ($usepermalinks===true) $descriptionlink = '(Link)'; if (strlen($link['description'])>0) $descriptionlink = '
'.$descriptionlink; - echo ''."\n\n"; + if(!empty($link['via'])){ + $via = '
via '.text2clickable(htmlspecialchars($link['via'])); + } else { + $via = ''; + } + echo ''."\n\n"; $i++; } echo ''; @@ -1001,11 +1013,12 @@ function showATOM() // Add permalink in description $descriptionlink = htmlspecialchars('(Permalink)'); + $via = htmlspecialchars('
via '.(text2clickable(htmlspecialchars($link['via'])))); // If user wants permalinks first, put the final link in description if ($usepermalinks===true) $descriptionlink = htmlspecialchars('(Link)'); if (strlen($link['description'])>0) $descriptionlink = '<br>'.$descriptionlink; - $entries.=''.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink."\n"; + $entries.=''.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink.$via."\n"; if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification) { foreach(explode(' ',$link['tags']) as $tag) @@ -1472,7 +1485,7 @@ function renderPage() if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?')) $url = 'http://'.$url; $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0), - 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags)); + 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags), 'via'=>trim($_POST['lf_via'])); if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title. $LINKSDB[$linkdate] = $link; $LINKSDB->savedb(); // save to disk @@ -1582,7 +1595,7 @@ function renderPage() } } if ($url=='') $url='?'.smallHash($linkdate); // In case of empty URL, this is just a text (with a link that point to itself) - $link = array('linkdate'=>$linkdate,'title'=>$title,'url'=>$url,'description'=>$description,'tags'=>$tags,'private'=>$private); + $link = array('linkdate'=>$linkdate,'title'=>$title,'url'=>$url,'description'=>$description,'tags'=>$tags,'via' => $via,'private'=>$private); } $PAGE = new pageBuilder; @@ -1832,6 +1845,9 @@ function buildLinkList($PAGE,$LINKSDB) $taglist = explode(' ',$link['tags']); uasort($taglist, 'strcasecmp'); $link['taglist']=$taglist; + if(!empty($link['via'])){ + $link['via']=htmlspecialchars($link['via']); + } $linkDisp[$keys[$i]] = $link; $i++; } diff --git a/tpl/editlink.html b/tpl/editlink.html index 4a2c30cc..0da1405e 100644 --- a/tpl/editlink.html +++ b/tpl/editlink.html @@ -16,6 +16,7 @@ Title

Description

Tags

+ Via

{if condition="($link_is_new && $GLOBALS['privateLinkByDefault']==true) || $link.private == true"}  
diff --git a/tpl/linklist.html b/tpl/linklist.html index ddc38cb0..78941308 100644 --- a/tpl/linklist.html +++ b/tpl/linklist.html @@ -43,6 +43,7 @@ {$value.title|htmlspecialchars}
{if="$value.description"}
{$value.description}
{/if} + {if condition="isset($value.via) && !empty($value.via)"}
@ via {$value.via|getJustDomain}
{/if} {if="!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()"} {$value.localdate|htmlspecialchars} - permalink - {else} From 4123658eae44d7564d1128ce52ddd5689efee813 Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Thu, 19 Dec 2013 09:53:12 +0100 Subject: [PATCH 2/3] =?UTF-8?q?[upd]=20change=20via=20message=20(@via=20to?= =?UTF-8?q?=20Origine=20=E2=87=92)=20[fix]=20via=20field=20for=20atom=20[f?= =?UTF-8?q?ix]=20warning=20when=20add=20new=20link?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 11 ++++++++--- tpl/editlink.html | 2 +- tpl/linklist.html | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index f17da34b..1de9f9a3 100644 --- a/index.php +++ b/index.php @@ -944,7 +944,7 @@ function showRSS() if ($usepermalinks===true) $descriptionlink = '(Link)'; if (strlen($link['description'])>0) $descriptionlink = '
'.$descriptionlink; if(!empty($link['via'])){ - $via = '
via '.text2clickable(htmlspecialchars($link['via'])); + $via = '
Origine => '.htmlspecialchars(getJustDomain($link['via'])).''; } else { $via = ''; } @@ -1010,7 +1010,11 @@ function showATOM() // Add permalink in description $descriptionlink = htmlspecialchars('(Permalink)'); - $via = htmlspecialchars('
via '.(text2clickable(htmlspecialchars($link['via'])))); + if(isset($link['via']) && !empty($link['via'])){ + $via = htmlspecialchars('
Origine => '.getJustDomain($link['via']).''); + } else { + $via = ''; + } // If user wants permalinks first, put the final link in description if ($usepermalinks===true) $descriptionlink = htmlspecialchars('(Link)'); if (strlen($link['description'])>0) $descriptionlink = '<br>'.$descriptionlink; @@ -1560,7 +1564,8 @@ function renderPage() $title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet). $description = (empty($_GET['description']) ? '' : $_GET['description']); // Get description if it was provided in URL (by the bookmarklet). [Bronco added that] $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); // Get tags if it was provided in URL - $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL + $via = (empty($_GET['via']) ? '' : $_GET['via'] ); + $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL if (($url!='') && parse_url($url,PHP_URL_SCHEME)=='') $url = 'http://'.$url; // If this is an HTTP link, we try go get the page to extact the title (otherwise we will to straight to the edit form.) if (empty($title) && parse_url($url,PHP_URL_SCHEME)=='http') diff --git a/tpl/editlink.html b/tpl/editlink.html index 0da1405e..14d4f9cc 100644 --- a/tpl/editlink.html +++ b/tpl/editlink.html @@ -16,7 +16,7 @@ Title

Description

Tags

- Via

+ Origine

{if condition="($link_is_new && $GLOBALS['privateLinkByDefault']==true) || $link.private == true"}  
diff --git a/tpl/linklist.html b/tpl/linklist.html index 78941308..0a8475f7 100644 --- a/tpl/linklist.html +++ b/tpl/linklist.html @@ -43,7 +43,7 @@ {$value.title|htmlspecialchars}
{if="$value.description"}
{$value.description}
{/if} - {if condition="isset($value.via) && !empty($value.via)"}
@ via {$value.via|getJustDomain}
{/if} + {if condition="isset($value.via) && !empty($value.via)"}
Origine => {$value.via|getJustDomain}
{/if} {if="!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()"} {$value.localdate|htmlspecialchars} - permalink - {else} From f1a8ca9cc8fe49b119d51b2d8382cc1a34542f96 Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Fri, 3 Jan 2014 09:39:02 +0100 Subject: [PATCH 3/3] [fix] warning in search form when empty via field --- index.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 1de9f9a3..2f60c287 100644 --- a/index.php +++ b/index.php @@ -798,7 +798,7 @@ class linkdb implements Iterator, Countable, ArrayAccess || (strpos(strtolower($l['description']),$s)!==false) || (strpos(strtolower($l['url']),$s)!==false) || (strpos(strtolower($l['tags']),$s)!==false) - || (strpos(strtolower($l['via']),$s)!==false); + || (!empty($l['via']) && (strpos(strtolower($l['via']),$s)!==false)); if ($found) $filtered[$l['linkdate']] = $l; } krsort($filtered); @@ -904,7 +904,7 @@ function showRSS() else $linksToDisplay = $LINKSDB; $nblinksToDisplay = 50; // Number of links to display. if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. - { + { $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ; } @@ -984,7 +984,7 @@ function showATOM() else $linksToDisplay = $LINKSDB; $nblinksToDisplay = 50; // Number of links to display. if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. - { + { $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ; } @@ -1576,7 +1576,7 @@ function renderPage() { // Look for charset in html header. preg_match('##Usi', $data, $meta); - + // If found, extract encoding. if (!empty($meta[0])) { @@ -1586,7 +1586,7 @@ function renderPage() $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8'; } else { $html_charset = 'utf-8'; } - + // Extract title $title = html_extract_title($data); if (!empty($title))