]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
More sensical profile::getUri()
authorZach Copley <zach@status.net>
Wed, 17 Feb 2010 04:13:39 +0000 (20:13 -0800)
committerZach Copley <zach@status.net>
Wed, 17 Feb 2010 04:13:39 +0000 (20:13 -0800)
EVENTS.txt
classes/Profile.php

index f333c5442f3c2475dc8b691875d298930f0693b1..90242fa133ca203f2e11da19742b0db28e2e3e4d 100644 (file)
@@ -722,6 +722,10 @@ StartRobotsTxt: Before outputting the robots.txt page
 EndRobotsTxt: After the default robots.txt page (good place for customization)
 - &$action: RobotstxtAction being shown
 
-GetProfileUri: When determining the canonical URI for a given profile
-- &$profile: the current profile
+StartGetProfileUri: When determining the canonical URI for a given profile
+- $profile: the current profile
+- &$uri: the URI
 
+EndGetProfileUri: After determining the canonical URI for a given profile
+- $profile: the current profile
+- &$uri: the URI
index 5a86619fd24ac7a6f92add9e9bcc52e7a8ce4f00..494c697e425fab0fa9726cba9bf0aac41635e2ff 100644 (file)
@@ -769,7 +769,7 @@ class Profile extends Memcached_DataObject
 
         $xs->elementStart('author');
         $xs->element('name', null, $this->nickname);
-        $xs->element('uri', null, $this->profileurl);
+        $xs->element('uri', null, $this->getUri());
         $xs->elementEnd('author');
 
         return $xs->getString();
@@ -832,21 +832,40 @@ class Profile extends Memcached_DataObject
         return $xs->getString();
     }
 
+    /**
+     * Returns the best URI for a profile. Plugins may override.
+     *
+     * @return string $uri
+     */
     function getUri()
     {
-        if (Event::handle('GetProfileUri', array($this))) {
+        $uri = null;
 
-            $remote = Remote_profile::staticGet('id', $this->id);
+        // check for a local user first
+        $user = User::staticGet('id', $this->id);
 
-            if (!empty($remote)) {
-                return $remote->uri;
-            } else {
-                return common_local_url(
-                    'userbyid',
-                    array('id' => $this->id)
-                );
+        if (!empty($user)) {
+            $uri = common_local_url(
+                'userbyid',
+                array('id' => $user->id)
+            );
+        } else {
+
+            // give plugins a chance to set the URI
+            if (Event::handle('StartGetProfileUri', array($this, &$uri))) {
+
+                // return OMB profile if any
+                $remote = Remote_profile::staticGet('id', $this->id);
+
+                if (!empty($remote)) {
+                    $uri = $remote->uri;
+                }
+
+                Event::handle('EndGetProfileUri', array($this, &$uri));
             }
         }
+
+        return $uri;
     }
 
 }