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