diff options
Diffstat (limited to 'application/LinkUtils.php')
-rw-r--r-- | application/LinkUtils.php | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/application/LinkUtils.php b/application/LinkUtils.php index c0dd32a6..3705f7e9 100644 --- a/application/LinkUtils.php +++ b/application/LinkUtils.php | |||
@@ -123,14 +123,15 @@ function count_private($links) | |||
123 | * | 123 | * |
124 | * @param string $text input string. | 124 | * @param string $text input string. |
125 | * @param string $redirector if a redirector is set, use it to gerenate links. | 125 | * @param string $redirector if a redirector is set, use it to gerenate links. |
126 | * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not. | ||
126 | * | 127 | * |
127 | * @return string returns $text with all links converted to HTML links. | 128 | * @return string returns $text with all links converted to HTML links. |
128 | * | 129 | * |
129 | * @see Function inspired from http://www.php.net/manual/en/function.preg-replace.php#85722 | 130 | * @see Function inspired from http://www.php.net/manual/en/function.preg-replace.php#85722 |
130 | */ | 131 | */ |
131 | function text2clickable($text, $redirector = '') | 132 | function text2clickable($text, $redirector = '', $urlEncode = true) |
132 | { | 133 | { |
133 | $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[[:alnum:]]/?)!si'; | 134 | $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[a-z0-9\(\)]/?)!si'; |
134 | 135 | ||
135 | if (empty($redirector)) { | 136 | if (empty($redirector)) { |
136 | return preg_replace($regex, '<a href="$1">$1</a>', $text); | 137 | return preg_replace($regex, '<a href="$1">$1</a>', $text); |
@@ -138,8 +139,9 @@ function text2clickable($text, $redirector = '') | |||
138 | // Redirector is set, urlencode the final URL. | 139 | // Redirector is set, urlencode the final URL. |
139 | return preg_replace_callback( | 140 | return preg_replace_callback( |
140 | $regex, | 141 | $regex, |
141 | function ($matches) use ($redirector) { | 142 | function ($matches) use ($redirector, $urlEncode) { |
142 | return '<a href="' . $redirector . urlencode($matches[1]) .'">'. $matches[1] .'</a>'; | 143 | $url = $urlEncode ? urlencode($matches[1]) : $matches[1]; |
144 | return '<a href="' . $redirector . $url .'">'. $matches[1] .'</a>'; | ||
143 | }, | 145 | }, |
144 | $text | 146 | $text |
145 | ); | 147 | ); |
@@ -185,12 +187,13 @@ function space2nbsp($text) | |||
185 | * | 187 | * |
186 | * @param string $description shaare's description. | 188 | * @param string $description shaare's description. |
187 | * @param string $redirector if a redirector is set, use it to gerenate links. | 189 | * @param string $redirector if a redirector is set, use it to gerenate links. |
190 | * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not. | ||
188 | * @param string $indexUrl URL to Shaarli's index. | 191 | * @param string $indexUrl URL to Shaarli's index. |
189 | * | 192 | |
190 | * @return string formatted description. | 193 | * @return string formatted description. |
191 | */ | 194 | */ |
192 | function format_description($description, $redirector = '', $indexUrl = '') { | 195 | function format_description($description, $redirector = '', $urlEncode = true, $indexUrl = '') { |
193 | return nl2br(space2nbsp(hashtag_autolink(text2clickable($description, $redirector), $indexUrl))); | 196 | return nl2br(space2nbsp(hashtag_autolink(text2clickable($description, $redirector, $urlEncode), $indexUrl))); |
194 | } | 197 | } |
195 | 198 | ||
196 | /** | 199 | /** |