]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
User user_group.uri to look up local groups for OStatus addressing checks when availa...
authorBrion Vibber <brion@pobox.com>
Mon, 27 Sep 2010 18:29:54 +0000 (11:29 -0700)
committerBrion Vibber <brion@pobox.com>
Mon, 27 Sep 2010 18:29:54 +0000 (11:29 -0700)
Should help with keeping remote groups working when renaming sites -- as long as user_group.uri has been filled out on the site changing its domain and other issues with POST handling are resolved.

plugins/OStatus/OStatusPlugin.php

index 6cd935c9e52ebbb63a12ae329b0f2147f583774d..dcf1b36078d8f490d83d11b5e4c429df1b0a5d5d 100644 (file)
@@ -956,7 +956,7 @@ class OStatusPlugin extends Plugin
     }
 
     /**
-     * Utility function to check if the given URL is a canonical group profile
+     * Utility function to check if the given URI is a canonical group profile
      * page, and if so return the ID number.
      *
      * @param string $url
@@ -964,11 +964,22 @@ class OStatusPlugin extends Plugin
      */
     public static function localGroupFromUrl($url)
     {
-        $template = common_local_url('groupbyid', array('id' => '31337'));
-        $template = preg_quote($template, '/');
-        $template = str_replace('31337', '(\d+)', $template);
-        if (preg_match("/$template/", $url, $matches)) {
-            return intval($matches[1]);
+        $group = User_group::staticGet('uri', $url);
+        if ($group) {
+            $local = Local_group::staticGet('id', $group->id);
+            if ($local) {
+                return $group->id;
+            }
+        } else {
+            // To find local groups which haven't had their uri fields filled out...
+            // If the domain has changed since a subscriber got the URI, it'll
+            // be broken.
+            $template = common_local_url('groupbyid', array('id' => '31337'));
+            $template = preg_quote($template, '/');
+            $template = str_replace('31337', '(\d+)', $template);
+            if (preg_match("/$template/", $url, $matches)) {
+                return intval($matches[1]);
+            }
         }
         return false;
     }