5 <meta name=
"generator" content=
"pandoc">
6 <meta name=
"viewport" content=
"width=device-width, initial-scale=1.0, user-scalable=yes">
7 <title>Shaarli – Example patch add new via field for links
</title>
8 <style type=
"text/css">code{white-space: pre;}
</style>
9 <link rel=
"stylesheet" href=
"github-markdown.css">
11 <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
15 <div id=
"local-sidebar">
17 <li><a href=
"Home.html">Home
</a></li>
20 <li><a href=
"Download-and-Installation.html">Download and Installation
</a></li>
21 <li><a href=
"Upgrade-and-migration.html">Upgrade and migration
</a></li>
22 <li><a href=
"Server-requirements.html">Server requirements
</a></li>
23 <li><a href=
"Server-configuration.html">Server configuration
</a></li>
24 <li><a href=
"Server-security.html">Server security
</a></li>
25 <li><a href=
"Shaarli-configuration.html">Shaarli configuration
</a></li>
26 <li><a href=
"Plugins.html">Plugins
</a></li>
28 <li><a href=
"Docker.html">Docker
</a></li>
29 <li><a href=
"Usage.html">Usage
</a>
31 <li><a href=
"Sharing-button.html">Sharing button
</a> (bookmarklet)
</li>
32 <li><a href=
"Browsing-and-Searching.html">Browsing and Searching
</a></li>
33 <li><a href=
"Firefox-share.html">Firefox share
</a></li>
34 <li><a href=
"RSS-feeds.html">RSS feeds
</a></li>
38 <li><a href=
"Backup,-restore,-import-and-export.html">Backup, restore, import and export
</a></li>
39 <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>
40 <li><a href=
"Create-and-serve-multiple-Shaarlis-(farm).html">Create and serve multiple Shaarlis (farm)
</a></li>
41 <li><a href=
"Download-CSS-styles-from-an-OPML-list.html">Download CSS styles from an OPML list
</a></li>
42 <li><a href=
"Datastore-hacks.html">Datastore hacks
</a></li>
44 <li><a href=
"Troubleshooting.html">Troubleshooting
</a></li>
45 <li><a href=
"Development.html">Development
</a>
47 <li><a href=
"GnuPG-signature.html">GnuPG signature
</a></li>
48 <li><a href=
"Coding-guidelines.html">Coding guidelines
</a></li>
49 <li><a href=
"Directory-structure.html">Directory structure
</a></li>
50 <li><a href=
"3rd-party-libraries.html">3rd party libraries
</a></li>
51 <li><a href=
"Plugin-System.html">Plugin System
</a></li>
52 <li><a href=
"Release-Shaarli.html">Release Shaarli
</a></li>
53 <li><a href=
"Security.html">Security
</a></li>
54 <li><a href=
"Static-analysis.html">Static analysis
</a></li>
55 <li><a href=
"Theming.html">Theming
</a></li>
56 <li><a href=
"Unit-tests.html">Unit tests
</a></li>
60 <li><a href=
"FAQ.html">FAQ
</a></li>
61 <li><a href=
"Community-&-Related-software.html">Community
& Related software
</a></li>
65 <h1 id=
"example-patch-add-new-via-field-for-links">Example patch add new via field for links
</h1>
66 <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>
67 <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>
68 <pre><code>From e0f363c18e8fe67990ed2bb1a08652e24e70bbcb Mon Sep
17 00:
00:
00 2001
69 From: Knah Tsaeb
<knah-tsaeb@knah-tsaeb.org
>
70 Date: Fri,
11 Oct
2013 15:
18:
37 +
0200
71 Subject: [PATCH] Add a
"via
"/origin property for links, add new input in
"edit link
" dialog[](.html)
73 * https://github.com/Knah-Tsaeb/Shaarli/commit/
040eb18ec8cdabd5ea855e108f81f97fbf0478c4
74 * https://github.com/Knah-Tsaeb/Shaarli/commit/
4123658eae44d7564d1128ce52ddd5689efee813
75 * https://github.com/Knah-Tsaeb/Shaarli/commit/f1a8ca9cc8fe49b119d51b2d8382cc1a34542f96
78 index.php |
43 ++++++++++++++++++++++++++++++++-----------
79 tpl/editlink.html |
1 +
80 tpl/linklist.html |
1 +
81 3 files changed,
34 insertions(+),
11 deletions(-)
83 diff --git a/index.php b/index.php
84 index
6fae2f8.
.53f798e
100644
87 @@ -
436,
6 +
436,
12 @@ if (isset($_POST[
'login
']))[](.html)
88 // ------------------------------------------------------------------------------------------
89 // Misc utility functions:
91 +// Try to get just domain for @via
92 +function getJustDomain($url){
93 + $parts = parse_url($url);
94 + return trim($parts[
'host
']);[](.html)
97 // Returns the server URL (including port and http/https), without path.
98 // e.g.
"http://myserver.com:
8080"
99 // You can append $_SERVER[
'SCRIPT_NAME
'] to get the current script URL.[](.html)
100 @@ -
799,
7 +
805,
8 @@ class linkdb implements Iterator, Countable, ArrayAccess
101 $found= (strpos(strtolower($l[
'title
']),$s)!==false)[](.html)
102 || (strpos(strtolower($l[
'description
']),$s)!==false)[](.html)
103 || (strpos(strtolower($l[
'url
']),$s)!==false)[](.html)
104 - || (strpos(strtolower($l[
'tags
']),$s)!==false);[](.html)
105 + || (strpos(strtolower($l[
'tags
']),$s)!==false)[](.html)
106 + || (!empty($l[
'via
'])
&& (strpos(strtolower($l[
'via
']),$s)!==false));[](.html)
107 if ($found) $filtered[$l[
'linkdate
'[ = $l;](-=-$l;.html)
110 @@ -
814,
7 +
821,
7 @@ class linkdb implements Iterator, Countable, ArrayAccess
111 $t = str_replace(
',
',
' ',($casesensitive?$tags:strtolower($tags)));
112 $searchtags=explode(
' ',$t);
114 - foreach($this-
>links as $l)
115 + foreach($this-
> links as $l)
117 $linktags = explode(
' ',($casesensitive?$l[
'tags
']:strtolower($l[
'tags
'])));[](.html)
118 if (count(array_intersect($linktags,$searchtags)) == count($searchtags))
119 @@ -
905,
7 +
912,
7 @@ function showRSS()
120 else $linksToDisplay = $LINKSDB;
121 $nblinksToDisplay =
50; // Number of links to display.
122 if (!empty($_GET[
'nb
'])) // In URL, you can specificy the number of links. Example: nb=
200 or nb=all for all links.[](.html)
125 $nblinksToDisplay = $_GET[
'nb
']==
'all
' ? count($linksToDisplay) : max($_GET[
'nb
']+
0,
1) ;[](.html)
128 @@ -
944,
7 +
951,
12 @@ function showRSS()
129 // If user wants permalinks first, put the final link in description
130 if ($usepermalinks===true) $descriptionlink =
'(
<a href=
"'.$absurl.
'">Link
</a
>)
';
131 if (strlen($link[
'description
'])
>0) $descriptionlink =
'<br
>'.$descriptionlink;[](.html)
132 - echo
'<description
><![CDATA[
'.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link[
'description
'])))).$descriptionlink.
'[
></description
>'.
"\n
</item
>\n
";](
></description
>'.
"\n
</item
>\n
";.html)
133 + if(!empty($link[
'via
'])){[](.html)
134 + $via =
'<br
>Origine =
> <a href=
"'.htmlspecialchars($link[
'via
']).
'">'.htmlspecialchars(getJustDomain($link[
'via
'])).
'</a
>';[](.html)
138 + echo
'<description
><![CDATA[
'.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link[
'description
'])))).$via.$descriptionlink.
'[
></description
>'.
"\n
</item
>\n
";](
></description
>'.
"\n
</item
>\n
";.html)
141 echo
'</channel
></rss
><!-- Cached version of
'.htmlspecialchars(pageUrl()).
' --
>';
142 @@ -
980,
7 +
992,
7 @@ function showATOM()
143 else $linksToDisplay = $LINKSDB;
144 $nblinksToDisplay =
50; // Number of links to display.
145 if (!empty($_GET[
'nb
'])) // In URL, you can specificy the number of links. Example: nb=
200 or nb=all for all links.[](.html)
148 $nblinksToDisplay = $_GET[
'nb
']==
'all
' ? count($linksToDisplay) : max($_GET[
'nb
']+
0,
1) ;[](.html)
151 @@ -
1006,
11 +
1018,
16 @@ function showATOM()
153 // Add permalink in description
154 $descriptionlink = htmlspecialchars(
'(
<a href=
"'.$guid.
'">Permalink
</a
>)
');
155 + if(isset($link[
'via
'])
&& !empty($link[
'via
'])){[](.html)
156 + $via = htmlspecialchars(
'</br
> Origine =
> <a href=
"'.$link[
'via
'].
'">'.getJustDomain($link[
'via
']).
'</a
>');[](.html)
160 // If user wants permalinks first, put the final link in description
161 if ($usepermalinks===true) $descriptionlink = htmlspecialchars(
'(
<a href=
"'.$absurl.
'">Link
</a
>)
');
162 if (strlen($link[
'description
'])
>0) $descriptionlink =
'&lt;br
&gt;
'.$descriptionlink;[](.html)
164 - $entries.=
'<content type=
"html
">'.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link[
'description
']))))).$descriptionlink.
"</content
>\n
";[](.html)
165 + $entries.=
'<content type=
"html
">'.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link[
'description
']))))).$descriptionlink.$via.
"</content
>\n
";[](.html)
166 if ($link[
'tags
']!=
'') // Adding tags to each ATOM entry (as mentioned in ATOM specification)[](.html)
168 foreach(explode(
' ',$link[
'tags
']) as $tag)[](.html)
169 @@ -
1478,
7 +
1495,
7 @@ function renderPage()
170 if (!startsWith($url,
'http:
')
&& !startsWith($url,
'https:
')
&& !startsWith($url,
'ftp:
')
&& !startsWith($url,
'magnet:
')
&& !startsWith($url,
'?
'))
171 $url =
'http://
'.$url;
172 $link = array(
'title
'=
>trim($_POST[
'lf_title
']),
'url
'=
>$url,
'description
'=
>trim($_POST[
'lf_description
']),
'private
'=
>(isset($_POST[
'lf_private
']) ?
1 :
0),[](.html)
173 -
'linkdate
'=
>$linkdate,
'tags
'=
>str_replace(
',
',
' ',$tags));
174 +
'linkdate
'=
>$linkdate,
'tags
'=
>str_replace(
',
',
' ',$tags),
'via
'=
>trim($_POST[
'lf_via
']));[](.html)
175 if ($link[
'title
']==
'') $link[
'title
']=$link[
'url
']; // If title is empty, use the URL as title.[](.html)
176 $LINKSDB[$linkdate] = $link;[](.html)
177 $LINKSDB-
>savedb(); // Save to disk.
178 @@ -
1556,
7 +
1573,
8 @@ function renderPage()
179 $title = (empty($_GET[
'title
']) ?
'' : $_GET[
'title
'] ); // Get title if it was provided in URL (by the bookmarklet).[](.html)
180 $description = (empty($_GET[
'description
']) ?
'' : $_GET[
'description
']); // Get description if it was provided in URL (by the bookmarklet). [Bronco added that][](.html)
181 $tags = (empty($_GET[
'tags
']) ?
'' : $_GET[
'tags
'] ); // Get tags if it was provided in URL[](.html)
182 - $private = (!empty($_GET[
'private
'])
&& $_GET[
'private
'] ===
"1" ?
1 :
0); // Get private if it was provided in URL [](.html)
183 + $via = (empty($_GET[
'via
']) ?
'' : $_GET[
'via
'] );[](.html)
184 + $private = (!empty($_GET[
'private
'])
&& $_GET[
'private
'] ===
"1" ?
1 :
0); // Get private if it was provided in URL[](.html)
185 if (($url!=
'')
&& parse_url($url,PHP_URL_SCHEME)==
'') $url =
'http://
'.$url;
186 // 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.)
187 if (empty($title)
&& parse_url($url,PHP_URL_SCHEME)==
'http
')
188 @@ -
1567,
7 +
1585,
7 @@ function renderPage()
190 // Look for charset in html header.
191 preg_match(
'#
<meta .*charset=.*
>#Usi
', $data, $meta);
194 // If found, extract encoding.
195 if (!empty($meta[
0]))[](.html)
197 @@ -
1577,
7 +
1595,
7 @@ function renderPage()
198 $html_charset = (!empty($enc[
1])) ? strtolower($enc[
1]) :
'utf-
8';[](.html)
200 else { $html_charset =
'utf-
8'; }
204 $title = html_extract_title($data);
206 @@ -
1592,
7 +
1610,
7 @@ function renderPage()
207 $url=
'?
'.smallHash($linkdate);
208 $title=
'Note:
';
210 - $link = array(
'linkdate
'=
>$linkdate,
'title
'=
>$title,
'url
'=
>$url,
'description
'=
>$description,
'tags
'=
>$tags,
'private
'=
>$private);
211 + $link = array(
'linkdate
'=
>$linkdate,
'title
'=
>$title,
'url
'=
>$url,
'description
'=
>$description,
'tags
'=
>$tags,
'via
' =
> $via,
'private
'=
>$private);
214 $PAGE = new pageBuilder;
215 @@ -
1842,
6 +
1860,
9 @@ function buildLinkList($PAGE,$LINKSDB)
216 $taglist = explode(
' ',$link[
'tags
']);[](.html)
217 uasort($taglist,
'strcasecmp
');
218 $link[
'taglist
']=$taglist;[](.html)
219 + if(!empty($link[
'via
'])){[](.html)
220 + $link[
'via
']=htmlspecialchars($link[
'via
']);[](.html)
222 $linkDisp[$keys[$i[ = $link;](-=-$link;.html)
225 diff --git a/tpl/editlink.html b/tpl/editlink.html
226 index
4a2c30c.
.14d4f9c
100644
227 --- a/tpl/editlink.html
228 +++ b/tpl/editlink.html
230 <i
>Title
</i
><br
><input type=
"text
" name=
"lf_title
" value=
"{$link.title|htmlspecialchars}
" style=
"width:
100%
"><br
>
231 <i
>Description
</i
><br
><textarea name=
"lf_description
" rows=
"4" cols=
"25" style=
"width:
100%
">{$link.description|htmlspecialchars}
</textarea
><br
>
232 <i
>Tags
</i
><br
><input type=
"text
" id=
"lf_tags
" name=
"lf_tags
" value=
"{$link.tags|htmlspecialchars}
" style=
"width:
100%
"><br
>
233 +
<i
>Origine
</i
><br
><input type=
"text
" name=
"lf_via
" value=
"{$link.via|htmlspecialchars}
" style=
"width:
100%
"><br
>
234 {if condition=
"($link_is_new
&& $GLOBALS[
'privateLinkByDefault
']==true) || $link.private == true
"}[](.html)
235 <input type=
"checkbox
" checked=
"checked
" name=
"lf_private
" id=
"lf_private
">
236 &nbsp;
<label for=
"lf_private
"><i
>Private
</i
></label
><br
>
237 diff --git a/tpl/linklist.html b/tpl/linklist.html
238 index ddc38cb.
.0a8475f
100644
239 --- a/tpl/linklist.html
240 +++ b/tpl/linklist.html
242 <span class=
"linktitle
"><a href=
"{$redirector}{$value.url|htmlspecialchars}
">{$value.title|htmlspecialchars}
</a
></span
>
244 {if=
"$value.description
"}
<div class=
"linkdescription
"{if condition=
"$search_type==
'permalink
'"} style=
"max-height:none !important;
"{/if}
>{$value.description}
</div
>{/if}
245 + {if condition=
"isset($value.via)
&& !empty($value.via)
"}
<div
><a href=
"{$value.via}
">Origine =
> {$value.via|getJustDomain}
</a
></div
>{/if}
246 {if=
"!$GLOBALS[
'config
'[
'HIDE_TIMESTAMPS
'] || isLoggedIn()
"}](
'HIDE_TIMESTAMPS
']-||-isLoggedIn()
"}.html)
247 <span class=
"linkdate
" title=
"Permalink
"><a href=
"?{$value.linkdate|smallHash}
">{$value.localdate|htmlspecialchars} - permalink
</a
> -
</span
>