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