aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/Example-patch---add-new-via-field-for-links.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/Example-patch---add-new-via-field-for-links.md')
-rw-r--r--doc/Example-patch---add-new-via-field-for-links.md190
1 files changed, 0 insertions, 190 deletions
diff --git a/doc/Example-patch---add-new-via-field-for-links.md b/doc/Example-patch---add-new-via-field-for-links.md
deleted file mode 100644
index 883adf40..00000000
--- a/doc/Example-patch---add-new-via-field-for-links.md
+++ /dev/null
@@ -1,190 +0,0 @@
1#Example patch add new via field for links
2Example 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. **Untested, use at your own risk**
3
4Thanks to @Knah-Tsaeb in https://github.com/sebsauvage/Shaarli/pull/158
5
6```
7From e0f363c18e8fe67990ed2bb1a08652e24e70bbcb Mon Sep 17 00:00:00 2001
8From: Knah Tsaeb <knah-tsaeb@knah-tsaeb.org>
9Date: Fri, 11 Oct 2013 15:18:37 +0200
10Subject: [PATCH] Add a "via"/origin property for links, add new input in "edit link" dialog[](.html)
11Thanks to:
12* https://github.com/Knah-Tsaeb/Shaarli/commit/040eb18ec8cdabd5ea855e108f81f97fbf0478c4
13* https://github.com/Knah-Tsaeb/Shaarli/commit/4123658eae44d7564d1128ce52ddd5689efee813
14* https://github.com/Knah-Tsaeb/Shaarli/commit/f1a8ca9cc8fe49b119d51b2d8382cc1a34542f96
15
16---
17 index.php | 43 ++++++++++++++++++++++++++++++++-----------
18 tpl/editlink.html | 1 +
19 tpl/linklist.html | 1 +
20 3 files changed, 34 insertions(+), 11 deletions(-)
21
22diff --git a/index.php b/index.php
23index 6fae2f8..53f798e 100644
24--- a/index.php
25+++ b/index.php
26@@ -436,6 +436,12 @@ if (isset($_POST['login']))[](.html)
27 // ------------------------------------------------------------------------------------------
28 // Misc utility functions:
29
30+// Try to get just domain for @via
31+function getJustDomain($url){
32+ $parts = parse_url($url);
33+ return trim($parts['host']);[](.html)
34+ }
35+
36 // Returns the server URL (including port and http/https), without path.
37 // e.g. "http://myserver.com:8080"
38 // You can append $_SERVER['SCRIPT_NAME'] to get the current script URL.[](.html)
39@@ -799,7 +805,8 @@ class linkdb implements Iterator, Countable, ArrayAccess
40 $found= (strpos(strtolower($l['title']),$s)!==false)[](.html)
41 || (strpos(strtolower($l['description']),$s)!==false)[](.html)
42 || (strpos(strtolower($l['url']),$s)!==false)[](.html)
43- || (strpos(strtolower($l['tags']),$s)!==false);[](.html)
44+ || (strpos(strtolower($l['tags']),$s)!==false)[](.html)
45+ || (!empty($l['via']) && (strpos(strtolower($l['via']),$s)!==false));[](.html)
46 if ($found) $filtered[$l['linkdate'[ = $l;](-=-$l;.html)
47 }
48 krsort($filtered);
49@@ -814,7 +821,7 @@ class linkdb implements Iterator, Countable, ArrayAccess
50 $t = str_replace(',',' ',($casesensitive?$tags:strtolower($tags)));
51 $searchtags=explode(' ',$t);
52 $filtered=array();
53- foreach($this->links as $l)
54+ foreach($this-> links as $l)
55 {
56 $linktags = explode(' ',($casesensitive?$l['tags']:strtolower($l['tags'])));[](.html)
57 if (count(array_intersect($linktags,$searchtags)) == count($searchtags))
58@@ -905,7 +912,7 @@ function showRSS()
59 else $linksToDisplay = $LINKSDB;
60 $nblinksToDisplay = 50; // Number of links to display.
61 if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links.[](.html)
62- {
63+ {
64 $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ;[](.html)
65 }
66
67@@ -944,7 +951,12 @@ function showRSS()
68 // If user wants permalinks first, put the final link in description
69 if ($usepermalinks===true) $descriptionlink = '(<a href="'.$absurl.'">Link</a>)';
70 if (strlen($link['description'])>0) $descriptionlink = '<br>'.$descriptionlink;[](.html)
71- echo '<description><![CDATA['.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))).$descriptionlink.'[></description>'."\n</item>\n";](></description>'."\n</item>\n";.html)
72+ if(!empty($link['via'])){[](.html)
73+ $via = '<br>Origine => <a href="'.htmlspecialchars($link['via']).'">'.htmlspecialchars(getJustDomain($link['via'])).'</a>';[](.html)
74+ } else {
75+ $via = '';
76+ }
77+ echo '<description><![CDATA['.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))).$via.$descriptionlink.'[></description>'."\n</item>\n";](></description>'."\n</item>\n";.html)
78 $i++;
79 }
80 echo '</channel></rss><!-- Cached version of '.htmlspecialchars(pageUrl()).' -->';
81@@ -980,7 +992,7 @@ function showATOM()
82 else $linksToDisplay = $LINKSDB;
83 $nblinksToDisplay = 50; // Number of links to display.
84 if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links.[](.html)
85- {
86+ {
87 $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ;[](.html)
88 }
89
90@@ -1006,11 +1018,16 @@ function showATOM()
91
92 // Add permalink in description
93 $descriptionlink = htmlspecialchars('(<a href="'.$guid.'">Permalink</a>)');
94+ if(isset($link['via']) && !empty($link['via'])){[](.html)
95+ $via = htmlspecialchars('</br> Origine => <a href="'.$link['via'].'">'.getJustDomain($link['via']).'</a>');[](.html)
96+ } else {
97+ $via = '';
98+ }
99 // If user wants permalinks first, put the final link in description
100 if ($usepermalinks===true) $descriptionlink = htmlspecialchars('(<a href="'.$absurl.'">Link</a>)');
101 if (strlen($link['description'])>0) $descriptionlink = '&lt;br&gt;'.$descriptionlink;[](.html)
102
103- $entries.='<content type="html">'.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink."</content>\n";[](.html)
104+ $entries.='<content type="html">'.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink.$via."</content>\n";[](.html)
105 if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification)[](.html)
106 {
107 foreach(explode(' ',$link['tags']) as $tag)[](.html)
108@@ -1478,7 +1495,7 @@ function renderPage()
109 if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?'))
110 $url = 'http://'.$url;
111 $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0),[](.html)
112- 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags));
113+ 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags), 'via'=>trim($_POST['lf_via']));[](.html)
114 if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title.[](.html)
115 $LINKSDB[$linkdate] = $link;[](.html)
116 $LINKSDB->savedb(); // Save to disk.
117@@ -1556,7 +1573,8 @@ function renderPage()
118 $title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet).[](.html)
119 $description = (empty($_GET['description']) ? '' : $_GET['description']); // Get description if it was provided in URL (by the bookmarklet). [Bronco added that][](.html)
120 $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); // Get tags if it was provided in URL[](.html)
121- $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL [](.html)
122+ $via = (empty($_GET['via']) ? '' : $_GET['via'] );[](.html)
123+ $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL[](.html)
124 if (($url!='') && parse_url($url,PHP_URL_SCHEME)=='') $url = 'http://'.$url;
125 // 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.)
126 if (empty($title) && parse_url($url,PHP_URL_SCHEME)=='http')
127@@ -1567,7 +1585,7 @@ function renderPage()
128 {
129 // Look for charset in html header.
130 preg_match('#<meta .*charset=.*>#Usi', $data, $meta);
131-
132+
133 // If found, extract encoding.
134 if (!empty($meta[0]))[](.html)
135 {
136@@ -1577,7 +1595,7 @@ function renderPage()
137 $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8';[](.html)
138 }
139 else { $html_charset = 'utf-8'; }
140-
141+
142 // Extract title
143 $title = html_extract_title($data);
144 if (!empty($title))
145@@ -1592,7 +1610,7 @@ function renderPage()
146 $url='?'.smallHash($linkdate);
147 $title='Note: ';
148 }
149- $link = array('linkdate'=>$linkdate,'title'=>$title,'url'=>$url,'description'=>$description,'tags'=>$tags,'private'=>$private);
150+ $link = array('linkdate'=>$linkdate,'title'=>$title,'url'=>$url,'description'=>$description,'tags'=>$tags,'via' => $via,'private'=>$private);
151 }
152
153 $PAGE = new pageBuilder;
154@@ -1842,6 +1860,9 @@ function buildLinkList($PAGE,$LINKSDB)
155 $taglist = explode(' ',$link['tags']);[](.html)
156 uasort($taglist, 'strcasecmp');
157 $link['taglist']=$taglist;[](.html)
158+ if(!empty($link['via'])){[](.html)
159+ $link['via']=htmlspecialchars($link['via']);[](.html)
160+ }
161 $linkDisp[$keys[$i[ = $link;](-=-$link;.html)
162 $i++;
163 }
164diff --git a/tpl/editlink.html b/tpl/editlink.html
165index 4a2c30c..14d4f9c 100644
166--- a/tpl/editlink.html
167+++ b/tpl/editlink.html
168@@ -16,6 +16,7 @@
169 <i>Title</i><br><input type="text" name="lf_title" value="{$link.title|htmlspecialchars}" style="width:100%"><br>
170 <i>Description</i><br><textarea name="lf_description" rows="4" cols="25" style="width:100%">{$link.description|htmlspecialchars}</textarea><br>
171 <i>Tags</i><br><input type="text" id="lf_tags" name="lf_tags" value="{$link.tags|htmlspecialchars}" style="width:100%"><br>
172+ <i>Origine</i><br><input type="text" name="lf_via" value="{$link.via|htmlspecialchars}" style="width:100%"><br>
173 {if condition="($link_is_new && $GLOBALS['privateLinkByDefault']==true) || $link.private == true"}[](.html)
174 <input type="checkbox" checked="checked" name="lf_private" id="lf_private">
175 &nbsp;<label for="lf_private"><i>Private</i></label><br>
176diff --git a/tpl/linklist.html b/tpl/linklist.html
177index ddc38cb..0a8475f 100644
178--- a/tpl/linklist.html
179+++ b/tpl/linklist.html
180@@ -43,6 +43,7 @@
181 <span class="linktitle"><a href="{$redirector}{$value.url|htmlspecialchars}">{$value.title|htmlspecialchars}</a></span>
182 <br>
183 {if="$value.description"}<div class="linkdescription"{if condition="$search_type=='permalink'"} style="max-height:none !important;"{/if}>{$value.description}</div>{/if}
184+ {if condition="isset($value.via) && !empty($value.via)"}<div><a href="{$value.via}">Origine => {$value.via|getJustDomain}</a></div>{/if}
185 {if="!$GLOBALS['config'['HIDE_TIMESTAMPS'] || isLoggedIn()"}]('HIDE_TIMESTAMPS']-||-isLoggedIn()"}.html)
186 <span class="linkdate" title="Permalink"><a href="?{$value.linkdate|smallHash}">{$value.localdate|htmlspecialchars} - permalink</a> - </span>
187 {else}
188--
1892.1.1
190```