aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/LinkUtils.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-11-08 18:54:32 +0100
committerGitHub <noreply@github.com>2017-11-08 18:54:32 +0100
commitb14d34d2c7b7a7360adcc823472a43f64b579e1c (patch)
tree3e9cf5757246945a499fdc45d45820021c04e2ce /application/LinkUtils.php
parente813f97b1af314e9391e6d4e734dc7cca5b0bc2c (diff)
parentfd08b50a80c3aed25f9e2a19cbfe9fb3ad35cf1f (diff)
downloadShaarli-b14d34d2c7b7a7360adcc823472a43f64b579e1c.tar.gz
Shaarli-b14d34d2c7b7a7360adcc823472a43f64b579e1c.tar.zst
Shaarli-b14d34d2c7b7a7360adcc823472a43f64b579e1c.zip
Merge pull request #1012 from ArthurHoaro/hotfix/urlencode
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/**