aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/Utils.php43
1 files changed, 42 insertions, 1 deletions
diff --git a/application/Utils.php b/application/Utils.php
index 10d60698..3d819716 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -62,7 +62,11 @@ function endsWith($haystack, $needle, $case=true)
62} 62}
63 63
64/** 64/**
65 * htmlspecialchars wrapper 65 * Htmlspecialchars wrapper
66 *
67 * @param string $str the string to escape.
68 *
69 * @return string escaped.
66 */ 70 */
67function escape($str) 71function escape($str)
68{ 72{
@@ -70,6 +74,18 @@ function escape($str)
70} 74}
71 75
72/** 76/**
77 * Reverse the escape function.
78 *
79 * @param string $str the string to unescape.
80 *
81 * @return string unescaped string.
82 */
83function unescape($str)
84{
85 return htmlspecialchars_decode($str);
86}
87
88/**
73 * Link sanitization before templating 89 * Link sanitization before templating
74 */ 90 */
75function sanitizeLink(&$link) 91function sanitizeLink(&$link)
@@ -213,3 +229,28 @@ function space2nbsp($text)
213function format_description($description, $redirector) { 229function format_description($description, $redirector) {
214 return nl2br(space2nbsp(text2clickable($description, $redirector))); 230 return nl2br(space2nbsp(text2clickable($description, $redirector)));
215} 231}
232
233/**
234 * Sniff browser language to set the locale automatically.
235 * Note that is may not work on your server if the corresponding locale is not installed.
236 *
237 * @param string $headerLocale Locale send in HTTP headers (e.g. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3").
238 **/
239function autoLocale($headerLocale)
240{
241 // Default if browser does not send HTTP_ACCEPT_LANGUAGE
242 $attempts = array('en_US');
243 if (isset($headerLocale)) {
244 // (It's a bit crude, but it works very well. Preferred language is always presented first.)
245 if (preg_match('/([a-z]{2})-?([a-z]{2})?/i', $headerLocale, $matches)) {
246 $loc = $matches[1] . (!empty($matches[2]) ? '_' . strtoupper($matches[2]) : '');
247 $attempts = array(
248 $loc.'.UTF-8', $loc, str_replace('_', '-', $loc).'.UTF-8', str_replace('_', '-', $loc),
249 $loc . '_' . strtoupper($loc).'.UTF-8', $loc . '_' . strtoupper($loc),
250 $loc . '_' . $loc.'.UTF-8', $loc . '_' . $loc, $loc . '-' . strtoupper($loc).'.UTF-8',
251 $loc . '-' . strtoupper($loc), $loc . '-' . $loc.'.UTF-8', $loc . '-' . $loc
252 );
253 }
254 }
255 setlocale(LC_ALL, $attempts);
256} \ No newline at end of file