aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/bookmark/LinkUtils.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/bookmark/LinkUtils.php')
-rw-r--r--application/bookmark/LinkUtils.php24
1 files changed, 4 insertions, 20 deletions
diff --git a/application/bookmark/LinkUtils.php b/application/bookmark/LinkUtils.php
index de5b61cb..988970bd 100644
--- a/application/bookmark/LinkUtils.php
+++ b/application/bookmark/LinkUtils.php
@@ -133,29 +133,15 @@ function count_private($links)
133 * In a string, converts URLs to clickable links. 133 * In a string, converts URLs to clickable links.
134 * 134 *
135 * @param string $text input string. 135 * @param string $text input string.
136 * @param string $redirector if a redirector is set, use it to gerenate links.
137 * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not.
138 * 136 *
139 * @return string returns $text with all links converted to HTML links. 137 * @return string returns $text with all links converted to HTML links.
140 * 138 *
141 * @see Function inspired from http://www.php.net/manual/en/function.preg-replace.php#85722 139 * @see Function inspired from http://www.php.net/manual/en/function.preg-replace.php#85722
142 */ 140 */
143function text2clickable($text, $redirector = '', $urlEncode = true) 141function text2clickable($text)
144{ 142{
145 $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[a-z0-9\(\)]/?)!si'; 143 $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[a-z0-9\(\)]/?)!si';
146 144 return preg_replace($regex, '<a href="$1">$1</a>', $text);
147 if (empty($redirector)) {
148 return preg_replace($regex, '<a href="$1">$1</a>', $text);
149 }
150 // Redirector is set, urlencode the final URL.
151 return preg_replace_callback(
152 $regex,
153 function ($matches) use ($redirector, $urlEncode) {
154 $url = $urlEncode ? urlencode($matches[1]) : $matches[1];
155 return '<a href="' . $redirector . $url .'">'. $matches[1] .'</a>';
156 },
157 $text
158 );
159} 145}
160 146
161/** 147/**
@@ -197,15 +183,13 @@ function space2nbsp($text)
197 * Format Shaarli's description 183 * Format Shaarli's description
198 * 184 *
199 * @param string $description shaare's description. 185 * @param string $description shaare's description.
200 * @param string $redirector if a redirector is set, use it to gerenate links.
201 * @param bool $urlEncode Use `urlencode()` on the URL after the redirector or not.
202 * @param string $indexUrl URL to Shaarli's index. 186 * @param string $indexUrl URL to Shaarli's index.
203 187
204 * @return string formatted description. 188 * @return string formatted description.
205 */ 189 */
206function format_description($description, $redirector = '', $urlEncode = true, $indexUrl = '') 190function format_description($description, $indexUrl = '')
207{ 191{
208 return nl2br(space2nbsp(hashtag_autolink(text2clickable($description, $redirector, $urlEncode), $indexUrl))); 192 return nl2br(space2nbsp(hashtag_autolink(text2clickable($description), $indexUrl)));
209} 193}
210 194
211/** 195/**