aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/LinkUtils.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-11-07 20:23:58 +0100
committerArthurHoaro <arthur@hoa.ro>2017-11-07 20:23:58 +0100
commitfd08b50a80c3aed25f9e2a19cbfe9fb3ad35cf1f (patch)
treeac75653241dec9fbdc0c66dfa14181b13d4a0dba /application/LinkUtils.php
parentd12b2a08c886a652d1edbacb287788814a8ef7f1 (diff)
downloadShaarli-fd08b50a80c3aed25f9e2a19cbfe9fb3ad35cf1f.tar.gz
Shaarli-fd08b50a80c3aed25f9e2a19cbfe9fb3ad35cf1f.tar.zst
Shaarli-fd08b50a80c3aed25f9e2a19cbfe9fb3ad35cf1f.zip
Don't URL encode description links if parameter 'redirector.encode_url' is set to false
Diffstat (limited to 'application/LinkUtils.php')
-rw-r--r--application/LinkUtils.php15
1 files changed, 9 insertions, 6 deletions
diff --git a/application/LinkUtils.php b/application/LinkUtils.php
index 267e62cd..e3d95d08 100644
--- a/application/LinkUtils.php
+++ b/application/LinkUtils.php
@@ -102,12 +102,13 @@ function count_private($links)
102 * 102 *
103 * @param string $text input string. 103 * @param string $text input string.
104 * @param string $redirector if a redirector is set, use it to gerenate links. 104 * @param string $redirector if a redirector is set, use it to gerenate links.
105 * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not.
105 * 106 *
106 * @return string returns $text with all links converted to HTML links. 107 * @return string returns $text with all links converted to HTML links.
107 * 108 *
108 * @see Function inspired from http://www.php.net/manual/en/function.preg-replace.php#85722 109 * @see Function inspired from http://www.php.net/manual/en/function.preg-replace.php#85722
109 */ 110 */
110function text2clickable($text, $redirector = '') 111function text2clickable($text, $redirector = '', $urlEncode = true)
111{ 112{
112 $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[a-z0-9\(\)]/?)!si'; 113 $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[a-z0-9\(\)]/?)!si';
113 114
@@ -117,8 +118,9 @@ function text2clickable($text, $redirector = '')
117 // Redirector is set, urlencode the final URL. 118 // Redirector is set, urlencode the final URL.
118 return preg_replace_callback( 119 return preg_replace_callback(
119 $regex, 120 $regex,
120 function ($matches) use ($redirector) { 121 function ($matches) use ($redirector, $urlEncode) {
121 return '<a href="' . $redirector . urlencode($matches[1]) .'">'. $matches[1] .'</a>'; 122 $url = $urlEncode ? urlencode($matches[1]) : $matches[1];
123 return '<a href="' . $redirector . $url .'">'. $matches[1] .'</a>';
122 }, 124 },
123 $text 125 $text
124 ); 126 );
@@ -164,12 +166,13 @@ function space2nbsp($text)
164 * 166 *
165 * @param string $description shaare's description. 167 * @param string $description shaare's description.
166 * @param string $redirector if a redirector is set, use it to gerenate links. 168 * @param string $redirector if a redirector is set, use it to gerenate links.
169 * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not.
167 * @param string $indexUrl URL to Shaarli's index. 170 * @param string $indexUrl URL to Shaarli's index.
168 * 171
169 * @return string formatted description. 172 * @return string formatted description.
170 */ 173 */
171function format_description($description, $redirector = '', $indexUrl = '') { 174function format_description($description, $redirector = '', $urlEncode = true, $indexUrl = '') {
172 return nl2br(space2nbsp(hashtag_autolink(text2clickable($description, $redirector), $indexUrl))); 175 return nl2br(space2nbsp(hashtag_autolink(text2clickable($description, $redirector, $urlEncode), $indexUrl)));
173} 176}
174 177
175/** 178/**