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