]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
Ignore user language settings that aren't listed in language config; we'll then fall...
[quix0rs-gnu-social.git] / lib / util.php
index 5bf4f6091bcf823182f050f57935a818de2ae179..5d20ed82df8ba0395d418305368edabb61f8b005 100644 (file)
@@ -58,18 +58,17 @@ function common_init_language()
     // (say, ga_ES for Galego/Galician) it seems to take it.
     common_init_locale("en_US");
 
+    // Note that this setlocale() call may "fail" but this is harmless;
+    // gettext will still select the right language.
     $language = common_language();
     $locale_set = common_init_locale($language);
+    
     setlocale(LC_CTYPE, 'C');
     // So we do not have to make people install the gettext locales
     $path = common_config('site','locale_path');
     bindtextdomain("statusnet", $path);
     bind_textdomain_codeset("statusnet", "UTF-8");
     textdomain("statusnet");
-
-    if(!$locale_set) {
-        common_log(LOG_INFO, 'Language requested:' . $language . ' - locale could not be set. Perhaps that system locale is not installed.', __FILE__);
-    }
 }
 
 function common_timezone()
@@ -92,8 +91,16 @@ function common_language()
     if (_have_config() && common_logged_in()) {
         $user = common_current_user();
         $user_language = $user->language;
-        if ($user_language)
-          return $user_language;
+
+        if ($user->language) {
+            // Validate -- we don't want to end up with a bogus code
+            // left over from some old junk.
+            foreach (common_config('site', 'languages') as $code => $info) {
+                if ($info['lang'] == $user_language) {
+                    return $user_language;
+                }
+            }
+        }
     }
 
     // Otherwise, find the best match for the languages requested by the
@@ -1051,8 +1058,27 @@ function common_log_line($priority, $msg)
     return date('Y-m-d H:i:s') . ' ' . $syslog_priorities[$priority] . ': ' . $msg . "\n";
 }
 
+function common_request_id()
+{
+    $pid = getmypid();
+    if (php_sapi_name() == 'cli') {
+        return $pid;
+    } else {
+        static $req_id = null;
+        if (!isset($req_id)) {
+            $req_id = substr(md5(mt_rand()), 0, 8);
+        }
+        if (isset($_SERVER['REQUEST_URI'])) {
+            $url = $_SERVER['REQUEST_URI'];
+        }
+        $method = $_SERVER['REQUEST_METHOD'];
+        return "$pid.$req_id $method $url";
+    }
+}
+
 function common_log($priority, $msg, $filename=null)
 {
+    $msg = '[' . common_request_id() . '] ' . $msg;
     $logfile = common_config('site', 'logfile');
     if ($logfile) {
         $log = fopen($logfile, "a");