]> 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 6946f60feefc32c78bc5a92c3fe6ef792cddd7c7..5d20ed82df8ba0395d418305368edabb61f8b005 100644 (file)
@@ -91,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
@@ -1050,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");