aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Utils.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-05-10 23:18:04 +0200
committerArthurHoaro <arthur@hoa.ro>2016-06-06 21:04:43 +0200
commit9ccca40189652e529732683abcdf54fcf775c9ec (patch)
tree9deda85d287dcba664bbba2f0bf9228e6118fbad /application/Utils.php
parentbb9ca54838e2f877635197541e8439171c83d5dc (diff)
downloadShaarli-9ccca40189652e529732683abcdf54fcf775c9ec.tar.gz
Shaarli-9ccca40189652e529732683abcdf54fcf775c9ec.tar.zst
Shaarli-9ccca40189652e529732683abcdf54fcf775c9ec.zip
Hashtag system
* Hashtag are auto-linked with a filter search * Supports unicode * Compatible with markdown (excluded in code blocks)
Diffstat (limited to 'application/Utils.php')
-rw-r--r--application/Utils.php55
1 files changed, 1 insertions, 54 deletions
diff --git a/application/Utils.php b/application/Utils.php
index da521cce..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 *
@@ -273,4 +220,4 @@ function autoLocale($headerLocale)
273 } 220 }
274 } 221 }
275 setlocale(LC_ALL, $attempts); 222 setlocale(LC_ALL, $attempts);
276} \ No newline at end of file 223}