]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / lib / util.php
index add1b0ae67e4ec5512713244627e2d5a4deac2d2..a7f43b5d4f23f5a978b756bc2519023d52979260 100644 (file)
@@ -52,17 +52,43 @@ function common_init_language()
 {
     mb_internal_encoding('UTF-8');
 
-    // gettext seems very picky... We first need to setlocale()
-    // to a locale which _does_ exist on the system, and _then_
-    // we can set in another locale that may not be set up
-    // (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);
 
+    if (!$locale_set) {
+        // The requested locale doesn't exist on the system.
+        //
+        // gettext seems very picky... We first need to setlocale()
+        // to a locale which _does_ exist on the system, and _then_
+        // we can set in another locale that may not be set up
+        // (say, ga_ES for Galego/Galician) it seems to take it.
+        //
+        // For some reason C and POSIX which are guaranteed to work
+        // don't do the job. en_US.UTF-8 should be there most of the
+        // time, but not guaranteed.
+        $ok = common_init_locale("en_US");
+        if (!$ok) {
+            // Try to find a complete, working locale...
+            // @fixme shelling out feels awfully inefficient
+            // but I don't think there's a more standard way.
+            $all = `locale -a`;
+            foreach (explode("\n", $all) as $locale) {
+                if (preg_match('/\.utf[-_]?8$/i', $locale)) {
+                    $ok = setlocale(LC_ALL, $locale);
+                    if ($ok) {
+                        break;
+                    }
+                }
+            }
+            if (!$ok) {
+                common_log(LOG_ERR, "Unable to find a UTF-8 locale on this system; UI translations may not work.");
+            }
+        }
+        $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');
@@ -105,11 +131,13 @@ function common_language()
 
     // Otherwise, find the best match for the languages requested by the
     // user's browser...
-    $httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null;
-    if (!empty($httplang)) {
-        $language = client_prefered_language($httplang);
-        if ($language)
-          return $language;
+    if (common_config('site', 'langdetect')) {
+        $httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null;
+        if (!empty($httplang)) {
+            $language = client_prefered_language($httplang);
+            if ($language)
+              return $language;
+        }
     }
 
     // Finally, if none of the above worked, use the site's default...
@@ -131,6 +159,11 @@ function common_munge_password($password, $id)
 
 function common_check_user($nickname, $password)
 {
+    // empty nickname always unacceptable
+    if (empty($nickname)) {
+        return false;
+    }
+
     $authenticatedUser = false;
 
     if (Event::handle('StartCheckPassword', array($nickname, $password, &$authenticatedUser))) {
@@ -770,7 +803,7 @@ function common_linkify($url) {
     }
 
     if (!empty($f)) {
-        if ($f->getEnclosure()) {
+        if ($f->getEnclosure() || File_oembed::staticGet('file_id',$f->id)) {
             $is_attachment = true;
             $attachment_id = $f->id;
 
@@ -853,7 +886,7 @@ function common_valid_profile_tag($str)
 function common_group_link($sender_id, $nickname)
 {
     $sender = Profile::staticGet($sender_id);
-    $group = User_group::getForNickname($nickname);
+    $group = User_group::getForNickname($nickname, $sender);
     if ($sender && $group && $sender->isMember($group)) {
         $attrs = array('href' => $group->permalink(),
                        'class' => 'url');
@@ -1143,19 +1176,10 @@ function common_enqueue_notice($notice)
         $transports[] = 'plugin';
     }
 
-    $xmpp = common_config('xmpp', 'enabled');
-
-    if ($xmpp) {
-        $transports[] = 'jabber';
-    }
-
     // @fixme move these checks into QueueManager and/or individual handlers
     if ($notice->is_local == Notice::LOCAL_PUBLIC ||
         $notice->is_local == Notice::LOCAL_NONPUBLIC) {
         $transports = array_merge($transports, $localTransports);
-        if ($xmpp) {
-            $transports[] = 'public';
-        }
     }
 
     if (Event::handle('StartEnqueueNotice', array($notice, &$transports))) {
@@ -1460,7 +1484,15 @@ function common_copy_args($from)
     $to = array();
     $strip = get_magic_quotes_gpc();
     foreach ($from as $k => $v) {
-        $to[$k] = ($strip) ? stripslashes($v) : $v;
+        if($strip) {
+            if(is_array($v)) {
+                $to[$k] = common_copy_args($v);
+            } else {
+                $to[$k] = stripslashes($v);
+            }
+        } else {
+            $to[$k] = $v;
+        }
     }
     return $to;
 }
@@ -1488,7 +1520,8 @@ function common_user_uri(&$user)
 function common_notice_uri(&$notice)
 {
     return common_local_url('shownotice',
-                            array('notice' => $notice->id));
+                            array('notice' => $notice->id),
+                            null, null, false);
 }
 
 // 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits