aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Utils.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/Utils.php')
-rw-r--r--application/Utils.php53
1 files changed, 0 insertions, 53 deletions
diff --git a/application/Utils.php b/application/Utils.php
index 9a8ca6d1..7d7eaffd 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -198,59 +198,6 @@ function is_session_id_valid($sessionId)
198} 198}
199 199
200/** 200/**
201 * In a string, converts URLs to clickable links.
202 *
203 * @param string $text input string.
204 * @param string $redirector if a redirector is set, use it to gerenate links.
205 *
206 * @return string returns $text with all links converted to HTML links.
207 *
208 * @see Function inspired from http://www.php.net/manual/en/function.preg-replace.php#85722
209 */
210function text2clickable($text, $redirector)
211{
212 $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[[:alnum:]]/?)!si';
213
214 if (empty($redirector)) {
215 return preg_replace($regex, '<a href="$1">$1</a>', $text);
216 }
217 // Redirector is set, urlencode the final URL.
218 return preg_replace_callback(
219 $regex,
220 function ($matches) use ($redirector) {
221 return '<a href="' . $redirector . urlencode($matches[1]) .'">'. $matches[1] .'</a>';
222 },
223 $text
224 );
225}
226
227/**
228 * This function inserts &nbsp; where relevant so that multiple spaces are properly displayed in HTML
229 * even in the absence of <pre> (This is used in description to keep text formatting).
230 *
231 * @param string $text input text.
232 *
233 * @return string formatted text.
234 */
235function space2nbsp($text)
236{
237 return preg_replace('/(^| ) /m', '$1&nbsp;', $text);
238}
239
240/**
241 * Format Shaarli's description
242 * TODO: Move me to ApplicationUtils when it's ready.
243 *
244 * @param string $description shaare's description.
245 * @param string $redirector if a redirector is set, use it to gerenate links.
246 *
247 * @return string formatted description.
248 */
249function format_description($description, $redirector = false) {
250 return nl2br(space2nbsp(text2clickable($description, $redirector)));
251}
252
253/**
254 * Sniff browser language to set the locale automatically. 201 * Sniff browser language to set the locale automatically.
255 * Note that is may not work on your server if the corresponding locale is not installed. 202 * Note that is may not work on your server if the corresponding locale is not installed.
256 * 203 *