]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
Take remote profiles into account when looking up canonical profile URIs
[quix0rs-gnu-social.git] / classes / Profile.php
index 664c45f6403d16e3dd18babd96c663ac47eb0b02..5a86619fd24ac7a6f92add9e9bcc52e7a8ce4f00 100644 (file)
@@ -755,6 +755,14 @@ class Profile extends Memcached_DataObject
         return !empty($notice);
     }
 
+    /**
+     * Returns an XML string fragment with limited profile information
+     * as an Atom <author> element.
+     *
+     * Assumes that Atom has been previously set up as the base namespace.
+     *
+     * @return string
+     */
     function asAtomAuthor()
     {
         $xs = new XMLStringer(true);
@@ -767,11 +775,33 @@ class Profile extends Memcached_DataObject
         return $xs->getString();
     }
 
+    /**
+     * Returns an XML string fragment with profile information as an
+     * Activity Streams <activity:actor> element.
+     *
+     * Assumes that 'activity' namespace has been previously defined.
+     *
+     * @return string
+     */
     function asActivityActor()
+    {
+        return $this->asActivityNoun('actor');
+    }
+
+    /**
+     * Returns an XML string fragment with profile information as an
+     * Activity Streams noun object with the given element type.
+     *
+     * Assumes that 'activity' namespace has been previously defined.
+     *
+     * @param string $element one of 'actor', 'subject', 'object', 'target'
+     * @return string
+     */
+    function asActivityNoun($element)
     {
         $xs = new XMLStringer(true);
 
-        $xs->elementStart('activity:actor');
+        $xs->elementStart('activity:' . $element);
         $xs->element(
             'activity:object-type',
             null,
@@ -780,10 +810,7 @@ class Profile extends Memcached_DataObject
         $xs->element(
             'id',
             null,
-            common_local_url(
-                'userbyid',
-                array('id' => $this->id)
-                )
+            $this->getUri()
             );
         $xs->element('title', null, $this->getBestName());
 
@@ -792,6 +819,7 @@ class Profile extends Memcached_DataObject
         $xs->element(
             'link', array(
                 'type' => empty($avatar) ? 'image/png' : $avatar->mediatype,
+                'rel'  => 'avatar',
                 'href' => empty($avatar)
                 ? Avatar::defaultImage(AVATAR_PROFILE_SIZE)
                 : $avatar->displayUrl()
@@ -799,8 +827,26 @@ class Profile extends Memcached_DataObject
             ''
         );
 
-        $xs->elementEnd('activity:actor');
+        $xs->elementEnd('activity:' . $element);
 
         return $xs->getString();
     }
+
+    function getUri()
+    {
+        if (Event::handle('GetProfileUri', array($this))) {
+
+            $remote = Remote_profile::staticGet('id', $this->id);
+
+            if (!empty($remote)) {
+                return $remote->uri;
+            } else {
+                return common_local_url(
+                    'userbyid',
+                    array('id' => $this->id)
+                );
+            }
+        }
+    }
+
 }