diff options
author | Arthur <arthur@hoa.ro> | 2016-07-09 07:36:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-09 07:36:23 +0200 |
commit | 0c4c7ae818336d5b0f94562e551ca1a3f34d3435 (patch) | |
tree | 5f0da042d12c10c8e09deb788c928e0644e9cdcb /application/Utils.php | |
parent | 649af5b501d2a90448242f53764ff693e9854039 (diff) | |
parent | 9ccca40189652e529732683abcdf54fcf775c9ec (diff) | |
download | Shaarli-0c4c7ae818336d5b0f94562e551ca1a3f34d3435.tar.gz Shaarli-0c4c7ae818336d5b0f94562e551ca1a3f34d3435.tar.zst Shaarli-0c4c7ae818336d5b0f94562e551ca1a3f34d3435.zip |
Merge pull request #558 from ArthurHoaro/hashtag4
Hashtag system
Diffstat (limited to 'application/Utils.php')
-rw-r--r-- | application/Utils.php | 53 |
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 | */ | ||
210 | function 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 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 | */ | ||
235 | function space2nbsp($text) | ||
236 | { | ||
237 | return preg_replace('/(^| ) /m', '$1 ', $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 | */ | ||
249 | function 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 | * |