<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
- <title></title>
+ <title>Shaarli – Example patch add new via field for links</title>
<style type="text/css">code{white-space: pre;}</style>
+ <link rel="stylesheet" href="github-markdown.css">
<!--[if lt IE 9]>
- <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+ <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
- <link rel="stylesheet" href="github-markdown.css">
</head>
<body>
+<div id="local-sidebar">
+<ul>
+<li><a href="Home.html">Home</a></li>
+<li>Installation
+<ul>
+<li><a href="Download.html">Download</a></li>
+<li><a href="Server-requirements.html">Server requirements</a></li>
+<li><a href="Server-configuration.html">Server configuration</a></li>
+<li><a href="Server-security.html">Server security</a></li>
+<li><a href="Shaarli-installation.html">Shaarli installation</a></li>
+<li><a href="Shaarli-configuration.html">Shaarli configuration</a></li>
+<li><a href="Plugins.html">Plugins</a></li>
+</ul></li>
+<li><a href="Docker.html">Docker</a></li>
+<li><a href="Usage.html">Usage</a>
+<ul>
+<li><a href="Sharing-button.html">Sharing button</a> (bookmarklet)</li>
+<li><a href="Browsing-and-Searching.html">Browsing and Searching</a></li>
+<li><a href="Firefox-share.html">Firefox share</a></li>
+<li><a href="RSS-feeds.html">RSS feeds</a></li>
+</ul></li>
+<li>How To
+<ul>
+<li><a href="Backup,-restore,-import-and-export.html">Backup, restore, import and export</a></li>
+<li><a href="Upgrade-from-original-sebsauvage/Shaarli.html">Upgrade from original sebsauvage/Shaarli</a></li>
+<li><a href="Copy-an-existing-installation-over-SSH-and-serve-it-locally.html">Copy an existing installation over SSH and serve it locally</a></li>
+<li><a href="Create-and-serve-multiple-Shaarlis-(farm).html">Create and serve multiple Shaarlis (farm)</a></li>
+<li><a href="Download-CSS-styles-from-an-OPML-list.html">Download CSS styles from an OPML list</a></li>
+<li><a href="Datastore-hacks.html">Datastore hacks</a></li>
+</ul></li>
+<li><a href="Troubleshooting.html">Troubleshooting</a></li>
+<li><a href="Development.html">Development</a>
+<ul>
+<li><a href="GnuPG-signature.html">GnuPG signature</a></li>
+<li><a href="Coding-guidelines.html">Coding guidelines</a></li>
+<li><a href="Directory-structure.html">Directory structure</a></li>
+<li><a href="3rd-party-libraries.html">3rd party libraries</a></li>
+<li><a href="Plugin-System.html">Plugin System</a></li>
+<li><a href="Release-Shaarli.html">Release Shaarli</a></li>
+<li><a href="Security.html">Security</a></li>
+<li><a href="Static-analysis.html">Static analysis</a></li>
+<li><a href="Theming.html">Theming</a></li>
+<li><a href="Unit-tests.html">Unit tests</a></li>
+</ul></li>
+<li>About
+<ul>
+<li><a href="FAQ.html">FAQ</a></li>
+<li><a href="Community-&-Related-software.html">Community & Related software</a></li>
+<li><a href="TODO.html">TODO</a></li>
+</ul></li>
+</ul>
+</div>
+<h1 id="example-patch-add-new-via-field-for-links">Example patch add new via field for links</h1>
<p>Example patch to add a new field ("via") for links, an input field to set the "via" property from the "edit link" dialog, and display the "via" field in the link list display. <strong>Untested, use at your own risk</strong></p>
-<p>Thanks to @Knah-Tsaeb in <a href="https://github.com/sebsauvage/Shaarli/pull/158">https://github.com/sebsauvage/Shaarli/pull/158</a></p>
+<p>Thanks to @Knah-Tsaeb in <a href="https://github.com/sebsauvage/Shaarli/pull/158" class="uri">https://github.com/sebsauvage/Shaarli/pull/158</a></p>
<pre><code>From e0f363c18e8fe67990ed2bb1a08652e24e70bbcb Mon Sep 17 00:00:00 2001
From: Knah Tsaeb <knah-tsaeb@knah-tsaeb.org>
Date: Fri, 11 Oct 2013 15:18:37 +0200
-Subject: [PATCH] Add a "via"/origin property for links, add new input in "edit link" dialog
+Subject: [PATCH] Add a "via"/origin property for links, add new input in "edit link" dialog[](.html)
Thanks to:
* https://github.com/Knah-Tsaeb/Shaarli/commit/040eb18ec8cdabd5ea855e108f81f97fbf0478c4
* https://github.com/Knah-Tsaeb/Shaarli/commit/4123658eae44d7564d1128ce52ddd5689efee813
index 6fae2f8..53f798e 100644
--- a/index.php
+++ b/index.php
-@@ -436,6 +436,12 @@ if (isset($_POST['login']))
+@@ -436,6 +436,12 @@ if (isset($_POST['login']))[](.html)
// ------------------------------------------------------------------------------------------
// Misc utility functions:
+// Try to get just domain for @via
+function getJustDomain($url){
+ $parts = parse_url($url);
-+ return trim($parts['host']);
++ return trim($parts['host']);[](.html)
+ }
+
// Returns the server URL (including port and http/https), without path.
// e.g. "http://myserver.com:8080"
- // You can append $_SERVER['SCRIPT_NAME'] to get the current script URL.
+ // You can append $_SERVER['SCRIPT_NAME'] to get the current script URL.[](.html)
@@ -799,7 +805,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)
-+ || (!empty($l['via']) && (strpos(strtolower($l['via']),$s)!==false));
- if ($found) $filtered[$l['linkdate']] = $l;
+ $found= (strpos(strtolower($l['title']),$s)!==false)[](.html)
+ || (strpos(strtolower($l['description']),$s)!==false)[](.html)
+ || (strpos(strtolower($l['url']),$s)!==false)[](.html)
+- || (strpos(strtolower($l['tags']),$s)!==false);[](.html)
++ || (strpos(strtolower($l['tags']),$s)!==false)[](.html)
++ || (!empty($l['via']) && (strpos(strtolower($l['via']),$s)!==false));[](.html)
+ if ($found) $filtered[$l['linkdate'[ = $l;](-=-$l;.html)
}
krsort($filtered);
@@ -814,7 +821,7 @@ class linkdb implements Iterator, Countable, ArrayAccess
- foreach($this->links as $l)
+ foreach($this-> links as $l)
{
- $linktags = explode(' ',($casesensitive?$l['tags']:strtolower($l['tags'])));
+ $linktags = explode(' ',($casesensitive?$l['tags']:strtolower($l['tags'])));[](.html)
if (count(array_intersect($linktags,$searchtags)) == count($searchtags))
@@ -905,7 +912,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.
+ if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links.[](.html)
- {
+ {
- $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ;
+ $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ;[](.html)
}
@@ -944,7 +951,12 @@ function showRSS()
// If user wants permalinks first, put the final link in description
if ($usepermalinks===true) $descriptionlink = '(<a href="'.$absurl.'">Link</a>)';
- if (strlen($link['description'])>0) $descriptionlink = '<br>'.$descriptionlink;
-- echo '<description><![CDATA['.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))).$descriptionlink.']]></description>'."\n</item>\n";
-+ if(!empty($link['via'])){
-+ $via = '<br>Origine => <a href="'.htmlspecialchars($link['via']).'">'.htmlspecialchars(getJustDomain($link['via'])).'</a>';
+ if (strlen($link['description'])>0) $descriptionlink = '<br>'.$descriptionlink;[](.html)
+- echo '<description><![CDATA['.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))).$descriptionlink.'[></description>'."\n</item>\n";](></description>'."\n</item>\n";.html)
++ if(!empty($link['via'])){[](.html)
++ $via = '<br>Origine => <a href="'.htmlspecialchars($link['via']).'">'.htmlspecialchars(getJustDomain($link['via'])).'</a>';[](.html)
+ } else {
+ $via = '';
+ }
-+ echo '<description><![CDATA['.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))).$via.$descriptionlink.']]></description>'."\n</item>\n";
++ echo '<description><![CDATA['.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))).$via.$descriptionlink.'[></description>'."\n</item>\n";](></description>'."\n</item>\n";.html)
$i++;
}
echo '</channel></rss><!-- Cached version of '.htmlspecialchars(pageUrl()).' -->';
@@ -980,7 +992,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.
+ if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links.[](.html)
- {
+ {
- $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ;
+ $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ;[](.html)
}
@@ -1006,11 +1018,16 @@ function showATOM()
// Add permalink in description
$descriptionlink = htmlspecialchars('(<a href="'.$guid.'">Permalink</a>)');
-+ if(isset($link['via']) && !empty($link['via'])){
-+ $via = htmlspecialchars('</br> Origine => <a href="'.$link['via'].'">'.getJustDomain($link['via']).'</a>');
++ if(isset($link['via']) && !empty($link['via'])){[](.html)
++ $via = htmlspecialchars('</br> Origine => <a href="'.$link['via'].'">'.getJustDomain($link['via']).'</a>');[](.html)
+ } else {
+ $via = '';
+ }
// If user wants permalinks first, put the final link in description
if ($usepermalinks===true) $descriptionlink = htmlspecialchars('(<a href="'.$absurl.'">Link</a>)');
- if (strlen($link['description'])>0) $descriptionlink = '&lt;br&gt;'.$descriptionlink;
+ if (strlen($link['description'])>0) $descriptionlink = '&lt;br&gt;'.$descriptionlink;[](.html)
-- $entries.='<content type="html">'.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink."</content>\n";
-+ $entries.='<content type="html">'.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink.$via."</content>\n";
- if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification)
+- $entries.='<content type="html">'.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink."</content>\n";[](.html)
++ $entries.='<content type="html">'.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink.$via."</content>\n";[](.html)
+ if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification)[](.html)
{
- foreach(explode(' ',$link['tags']) as $tag)
+ foreach(explode(' ',$link['tags']) as $tag)[](.html)
@@ -1478,7 +1495,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),
+ $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0),[](.html)
- '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;
++ 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags), 'via'=>trim($_POST['lf_via']));[](.html)
+ if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title.[](.html)
+ $LINKSDB[$linkdate] = $link;[](.html)
$LINKSDB->savedb(); // Save to disk.
@@ -1556,7 +1573,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
+ $title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet).[](.html)
+ $description = (empty($_GET['description']) ? '' : $_GET['description']); // Get description if it was provided in URL (by the bookmarklet). [Bronco added that][](.html)
+ $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); // Get tags if it was provided in URL[](.html)
+- $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL [](.html)
++ $via = (empty($_GET['via']) ? '' : $_GET['via'] );[](.html)
++ $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL[](.html)
if (($url!='') && parse_url($url,PHP_URL_SCHEME)=='') $url = 'http://'.$url;
// If this is an HTTP link, we try go get the page to extract the title (otherwise we will to straight to the edit form.)
if (empty($title) && parse_url($url,PHP_URL_SCHEME)=='http')
-
+
// If found, extract encoding.
- if (!empty($meta[0]))
+ if (!empty($meta[0]))[](.html)
{
@@ -1577,7 +1595,7 @@ function renderPage()
- $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8';
+ $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8';[](.html)
}
else { $html_charset = 'utf-8'; }
-
$PAGE = new pageBuilder;
@@ -1842,6 +1860,9 @@ function buildLinkList($PAGE,$LINKSDB)
- $taglist = explode(' ',$link['tags']);
+ $taglist = explode(' ',$link['tags']);[](.html)
uasort($taglist, 'strcasecmp');
- $link['taglist']=$taglist;
-+ if(!empty($link['via'])){
-+ $link['via']=htmlspecialchars($link['via']);
+ $link['taglist']=$taglist;[](.html)
++ if(!empty($link['via'])){[](.html)
++ $link['via']=htmlspecialchars($link['via']);[](.html)
+ }
- $linkDisp[$keys[$i]] = $link;
+ $linkDisp[$keys[$i[ = $link;](-=-$link;.html)
$i++;
}
diff --git a/tpl/editlink.html b/tpl/editlink.html
<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>Origine</i><br><input type="text" name="lf_via" value="{$link.via|htmlspecialchars}" style="width:100%"><br>
- {if condition="($link_is_new && $GLOBALS['privateLinkByDefault']==true) || $link.private == true"}
+ {if condition="($link_is_new && $GLOBALS['privateLinkByDefault']==true) || $link.private == true"}[](.html)
<input type="checkbox" checked="checked" name="lf_private" id="lf_private">
&nbsp;<label for="lf_private"><i>Private</i></label><br>
diff --git a/tpl/linklist.html b/tpl/linklist.html
<br>
{if="$value.description"}<div class="linkdescription"{if condition="$search_type=='permalink'"} style="max-height:none !important;"{/if}>{$value.description}</div>{/if}
+ {if condition="isset($value.via) && !empty($value.via)"}<div><a href="{$value.via}">Origine => {$value.via|getJustDomain}</a></div>{/if}
- {if="!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()"}
+ {if="!$GLOBALS['config'['HIDE_TIMESTAMPS'] || isLoggedIn()"}]('HIDE_TIMESTAMPS']-||-isLoggedIn()"}.html)
<span class="linkdate" title="Permalink"><a href="?{$value.linkdate|smallHash}">{$value.localdate|htmlspecialchars} - permalink</a> - </span>
{else}
--