]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - doc/md/Example-patch---add-new-via-field-for-links.md
Generate HTML documentation using MkDocs (WIP)
[github/shaarli/Shaarli.git] / doc / md / Example-patch---add-new-via-field-for-links.md
CommitLineData
1acc87ee 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
53ed6d7d 9Subject: [PATCH] Add a "via"/origin property for links, add new input in "edit link" dialog
1acc87ee 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
53ed6d7d 25@@ -436,6 +436,12 @@ if (isset($_POST['login']))
1acc87ee 26 // ------------------------------------------------------------------------------------------
27 // Misc utility functions:
28
29+// Try to get just domain for @via
30+function getJustDomain($url){
31+ $parts = parse_url($url);
53ed6d7d 32+ return trim($parts['host']);
1acc87ee 33+ }
34+
35 // Returns the server URL (including port and http/https), without path.
36 // e.g. "http://myserver.com:8080"
53ed6d7d 37 // You can append $_SERVER['SCRIPT_NAME'] to get the current script URL.
1acc87ee 38@@ -799,7 +805,8 @@ class linkdb implements Iterator, Countable, ArrayAccess
53ed6d7d 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;
1acc87ee 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 {
53ed6d7d 55 $linktags = explode(' ',($casesensitive?$l['tags']:strtolower($l['tags'])));
1acc87ee 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.
53ed6d7d 60 if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links.
1acc87ee 61- {
62+ {
53ed6d7d 63 $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ;
1acc87ee 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>)';
53ed6d7d 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>';
1acc87ee 73+ } else {
74+ $via = '';
75+ }
53ed6d7d 76+ echo '<description><![CDATA['.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))).$via.$descriptionlink.']]></description>'."\n</item>\n";
1acc87ee 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.
53ed6d7d 83 if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links.
1acc87ee 84- {
85+ {
53ed6d7d 86 $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ;
1acc87ee 87 }
88
89@@ -1006,11 +1018,16 @@ function showATOM()
90
91 // Add permalink in description
92 $descriptionlink = htmlspecialchars('(<a href="'.$guid.'">Permalink</a>)');
53ed6d7d 93+ if(isset($link['via']) && !empty($link['via'])){
94+ $via = htmlspecialchars('</br> Origine => <a href="'.$link['via'].'">'.getJustDomain($link['via']).'</a>');
1acc87ee 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>)');
53ed6d7d 100 if (strlen($link['description'])>0) $descriptionlink = '&lt;br&gt;'.$descriptionlink;
1acc87ee 101
53ed6d7d 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)
1acc87ee 105 {
53ed6d7d 106 foreach(explode(' ',$link['tags']) as $tag)
1acc87ee 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;
53ed6d7d 110 $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0),
1acc87ee 111- 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags));
53ed6d7d 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;
1acc87ee 115 $LINKSDB->savedb(); // Save to disk.
116@@ -1556,7 +1573,8 @@ function renderPage()
53ed6d7d 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
1acc87ee 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.
53ed6d7d 133 if (!empty($meta[0]))
1acc87ee 134 {
135@@ -1577,7 +1595,7 @@ function renderPage()
53ed6d7d 136 $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8';
1acc87ee 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)
53ed6d7d 154 $taglist = explode(' ',$link['tags']);
1acc87ee 155 uasort($taglist, 'strcasecmp');
53ed6d7d 156 $link['taglist']=$taglist;
157+ if(!empty($link['via'])){
158+ $link['via']=htmlspecialchars($link['via']);
1acc87ee 159+ }
53ed6d7d 160 $linkDisp[$keys[$i]] = $link;
1acc87ee 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>
53ed6d7d 172 {if condition="($link_is_new && $GLOBALS['privateLinkByDefault']==true) || $link.private == true"}
1acc87ee 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}
53ed6d7d 184 {if="!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()"}
1acc87ee 185 <span class="linkdate" title="Permalink"><a href="?{$value.linkdate|smallHash}">{$value.localdate|htmlspecialchars} - permalink</a> - </span>
186 {else}
187--
1882.1.1
53ed6d7d 189```