]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Some upgrades to Atom output for OStatus
authorZach Copley <zach@status.net>
Thu, 11 Feb 2010 02:55:14 +0000 (18:55 -0800)
committerZach Copley <zach@status.net>
Thu, 11 Feb 2010 21:56:05 +0000 (13:56 -0800)
actions/apitimelineuser.php
classes/Notice.php
classes/Profile.php
lib/atom10feed.php
lib/atomnoticefeed.php

index bcc48f59c1e4b2665bccc3ff1238fb3f60ec9424..cb82136195d008ca29b5ed6ed6ae52a52b27bc70 100644 (file)
@@ -189,7 +189,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
 
             $atom->addEntryFromNotices($this->notices);
 
-            print $atom->getString();
+            $this->raw($atom->getString());
 
             break;
         case 'json':
index 247440f29cbcf3eae2874658e4a3f823db623cdd..091f2dc7b406279a5714a3c060fb7daca88f06a0 100644 (file)
@@ -957,7 +957,10 @@ class Notice extends Memcached_DataObject
 
         if ($namespace) {
             $attrs = array('xmlns' => 'http://www.w3.org/2005/Atom',
-                           'xmlns:thr' => 'http://purl.org/syndication/thread/1.0');
+                           'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
+                           'xmlns:georss' => 'http://www.georss.org/georss',
+                           'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/',
+                           'xmlns:ostatus' => 'http://ostatus.org/schema/1.0');
         } else {
             $attrs = array();
         }
@@ -983,11 +986,6 @@ class Notice extends Memcached_DataObject
             $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE));
         }
 
-        $xs->elementStart('author');
-        $xs->element('name', null, $profile->nickname);
-        $xs->element('uri', null, $profile->profileurl);
-        $xs->elementEnd('author');
-
         if ($source) {
             $xs->elementEnd('source');
         }
@@ -995,6 +993,9 @@ class Notice extends Memcached_DataObject
         $xs->element('title', null, $this->content);
         $xs->element('summary', null, $this->content);
 
+        $xs->raw($profile->asAtomAuthor());
+        $xs->raw($profile->asActivityActor($namespace));
+
         $xs->element('link', array('rel' => 'alternate',
                                    'href' => $this->bestUrl()));
 
@@ -1014,6 +1015,29 @@ class Notice extends Memcached_DataObject
             }
         }
 
+        if (!empty($this->conversation)
+            && $this->conversation != $this->notice->id) {
+            $xs->element(
+                'link', array(
+                    'rel' => 'osatus:conversation',
+                    'href' => common_local_url(
+                        'conversation',
+                        array('id' => $this->conversation)
+                        )
+                    )
+                );
+        }
+
+        if (!empty($this->repeat_of)) {
+            $repeat = Notice::staticGet('id', $this->repeat_of);
+            if (!empty($repeat)) {
+                $xs->element(
+                    'ostatus:forward',
+                     array('ref' => $repeat->uri, 'href' => $repeat->bestUrl())
+                );
+            }
+        }
+
         $xs->element('content', array('type' => 'html'), $this->rendered);
 
         $tag = new Notice_tag();
@@ -1041,9 +1065,7 @@ class Notice extends Memcached_DataObject
         }
 
         if (!empty($this->lat) && !empty($this->lon)) {
-            $xs->elementStart('geo', array('xmlns:georss' => 'http://www.georss.org/georss'));
             $xs->element('georss:point', null, $this->lat . ' ' . $this->lon);
-            $xs->elementEnd('geo');
         }
 
         $xs->elementEnd('entry');
index feabc250870c2effcff82b065b3b65eb021c8764..664c45f6403d16e3dd18babd96c663ac47eb0b02 100644 (file)
@@ -754,4 +754,53 @@ class Profile extends Memcached_DataObject
 
         return !empty($notice);
     }
+
+    function asAtomAuthor()
+    {
+        $xs = new XMLStringer(true);
+
+        $xs->elementStart('author');
+        $xs->element('name', null, $this->nickname);
+        $xs->element('uri', null, $this->profileurl);
+        $xs->elementEnd('author');
+
+        return $xs->getString();
+    }
+
+    function asActivityActor()
+    {
+        $xs = new XMLStringer(true);
+
+        $xs->elementStart('activity:actor');
+        $xs->element(
+            'activity:object-type',
+            null,
+            'http://activitystrea.ms/schema/1.0/person'
+        );
+        $xs->element(
+            'id',
+            null,
+            common_local_url(
+                'userbyid',
+                array('id' => $this->id)
+                )
+            );
+        $xs->element('title', null, $this->getBestName());
+
+        $avatar = $this->getAvatar(AVATAR_PROFILE_SIZE);
+
+        $xs->element(
+            'link', array(
+                'type' => empty($avatar) ? 'image/png' : $avatar->mediatype,
+                'href' => empty($avatar)
+                ? Avatar::defaultImage(AVATAR_PROFILE_SIZE)
+                : $avatar->displayUrl()
+            ),
+            ''
+        );
+
+        $xs->elementEnd('activity:actor');
+
+        return $xs->getString();
+    }
 }
index 9dd8ebc9bc98247e6fef10ef65ab29aa0a898ff5..01fc69072c6ae9ba383f22ca33cc206819943d4f 100644 (file)
@@ -153,7 +153,7 @@ class Atom10Feed extends XMLStringer
      * Assumes you want rel="alternate" and type="text/html" unless
      * you send in $otherAttrs.
      *
-     * @param string $uri            the uri the href need to point to
+     * @param string $uri            the uri the href needs to point to
      * @param array  $otherAttrs     other attributes to stick in
      *
      * @return void
index a28c9cda7b678795be3e78695ccd093c5be9babf..ce87ec9e64bc03e30dbe96a5a9795070ed39301b 100644 (file)
@@ -5,12 +5,28 @@ class AtomNoticeFeed extends Atom10Feed
     function __construct($indent = true) {
         parent::__construct($indent);
 
-        // Feeds containing notice info use the Atom Threading Extensions
+        // Feeds containing notice info use these namespaces
 
         $this->addNamespace(
             'xmlns:thr',
             'http://purl.org/syndication/thread/1.0'
         );
+
+        $this->addNamespace(
+            'xmlns:georss',
+            'http://www.georss.org/georss'
+        );
+
+        $this->addNamespace(
+            'xmlns:activity',
+            'http://activitystrea.ms/spec/1.0/'
+        );
+
+        // XXX: What should the uri be?
+        $this->addNamespace(
+            'xmlns:ostatus',
+            'http://ostatus.org/schema/1.0'
+        );
     }
 
     function addEntryFromNotices($notices)