]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Put all required field setup into AtomUserNoticeFeed and AtomGroupNoticeFeed, consoli...
authorBrion Vibber <brion@pobox.com>
Wed, 3 Mar 2010 20:51:23 +0000 (12:51 -0800)
committerBrion Vibber <brion@pobox.com>
Thu, 4 Mar 2010 00:33:20 +0000 (16:33 -0800)
OStatus now calling the feed classes directly instead of faking a call into the API, should be less flakey.

actions/apitimelinegroup.php
actions/apitimelineuser.php
lib/atom10feed.php
lib/atomgroupnoticefeed.php
lib/atomusernoticefeed.php
plugins/OStatus/lib/ostatusqueuehandler.php

index e30a08fb5d0db7830c7928d8fa5d1d6b6e474947..8f971392bf7650adbb9e1e2dec5eb331b21d0fe4 100644 (file)
@@ -104,30 +104,21 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
 
     function showTimeline()
     {
-        $sitename   = common_config('site', 'name');
-        $avatar     = $this->group->homepage_logo;
-        $title      = sprintf(_("%s timeline"), $this->group->nickname);
-
-        $subtitle   = sprintf(
-            _('Updates from %1$s on %2$s!'),
-            $this->group->nickname,
-            $sitename
-        );
-
-        $logo = ($avatar) ? $avatar : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
+        // We'll pull common formatting out of this for other formats
+        $atom = new AtomGroupNoticeFeed($this->group);
 
         switch($this->format) {
         case 'xml':
             $this->showXmlTimeline($this->notices);
             break;
         case 'rss':
-                $this->showRssTimeline(
+            $this->showRssTimeline(
                 $this->notices,
-                $title,
+                $atom->title,
                 $this->group->homeUrl(),
-                $subtitle,
+                $atom->subtitle,
                 null,
-                $logo
+                $atom->logo
             );
             break;
         case 'atom':
@@ -136,38 +127,22 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
 
             try {
 
-                $atom = new AtomGroupNoticeFeed($this->group);
-
-                // @todo set all this Atom junk up inside the feed class
-
-                #$atom->setId($id);
-                $atom->setTitle($title);
-                $atom->setSubtitle($subtitle);
-                $atom->setLogo($logo);
-                $atom->setUpdated('now');
-
                 $atom->addAuthorRaw($this->group->asAtomAuthor());
                 $atom->setActivitySubject($this->group->asActivitySubject());
 
-                $atom->addLink($this->group->homeUrl());
-
                 $id = $this->arg('id');
                 $aargs = array('format' => 'atom');
                 if (!empty($id)) {
                     $aargs['id'] = $id;
                 }
+                $self = $this->getSelfUri('ApiTimelineGroup', $aargs);
 
-                $atom->setId($this->getSelfUri('ApiTimelineGroup', $aargs));
-
-                $atom->addLink(
-                    $this->getSelfUri('ApiTimelineGroup', $aargs),
-                    array('rel' => 'self', 'type' => 'application/atom+xml')
-                );
+                $atom->setId($self);
+                $atom->setSelfLink($self);
 
                 $atom->addEntryFromNotices($this->notices);
 
-                //$this->raw($atom->getString());
-                print $atom->getString(); // temp hack until PuSH feeds are redone cleanly
+                $this->raw($atom->getString());
 
             } catch (Atom10FeedException $e) {
                 $this->serverError(
index 94491946c21b5943f61a7c40bfafef2818c70cd8..2d0047c0464f8723d75d418a7c318fa11c880331 100644 (file)
@@ -112,19 +112,17 @@ class ApiTimelineUserAction extends ApiBareAuthAction
     function showTimeline()
     {
         $profile = $this->user->getProfile();
-        $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
 
-        $sitename   = common_config('site', 'name');
-        $title      = sprintf(_("%s timeline"), $this->user->nickname);
+        // We'll use the shared params from the Atom stub
+        // for other feed types.
+        $atom = new AtomUserNoticeFeed($this->user);
+        $title      = $atom->title;
         $link       = common_local_url(
             'showstream',
             array('nickname' => $this->user->nickname)
         );
-        $subtitle   = sprintf(
-            _('Updates from %1$s on %2$s!'),
-            $this->user->nickname, $sitename
-        );
-        $logo = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE);
+        $subtitle = $atom->subtitle;
+        $logo = $atom->logo;
 
         // FriendFeed's SUP protocol
         // Also added RSS and Atom feeds
@@ -146,47 +144,18 @@ class ApiTimelineUserAction extends ApiBareAuthAction
 
             header('Content-Type: application/atom+xml; charset=utf-8');
 
-            // @todo set all this Atom junk up inside the feed class
-
-            $atom = new AtomUserNoticeFeed($this->user);
-
-            $atom->setTitle($title);
-            $atom->setSubtitle($subtitle);
-            $atom->setLogo($logo);
-            $atom->setUpdated('now');
-
-            $atom->addLink(
-                common_local_url(
-                    'showstream',
-                    array('nickname' => $this->user->nickname)
-                )
-            );
-
             $id = $this->arg('id');
             $aargs = array('format' => 'atom');
             if (!empty($id)) {
                 $aargs['id'] = $id;
             }
-
-            $atom->setId($this->getSelfUri('ApiTimelineUser', $aargs));
-
-            $atom->addLink(
-                $this->getSelfUri('ApiTimelineUser', $aargs),
-                array('rel' => 'self', 'type' => 'application/atom+xml')
-            );
-
-            $atom->addLink(
-                $suplink,
-                array(
-                    'rel' => 'http://api.friendfeed.com/2008/03#sup',
-                    'type' => 'application/json'
-                )
-            );
+            $self = $this->getSelfUri('ApiTimelineUser', $aargs);
+            $atom->setId($self);
+            $atom->setSelfLink($self);
 
             $atom->addEntryFromNotices($this->notices);
 
-            #$this->raw($atom->getString());
-            print $atom->getString(); // temporary for output buffering
+            $this->raw($atom->getString());
 
             break;
         case 'json':
index 8842840d568ef862d387ecac72b9c8cfcbf2553b..c1fdeaae935719e15c0fe8d2ac33955664759e61 100644 (file)
@@ -49,6 +49,8 @@ class Atom10FeedException extends Exception
 class Atom10Feed extends XMLStringer
 {
     public  $xw;
+
+    // @fixme most of these should probably be read-only properties
     private $namespaces;
     private $authors;
     private $subject;
@@ -57,10 +59,12 @@ class Atom10Feed extends XMLStringer
     private $generator;
     private $icon;
     private $links;
-    private $logo;
+    private $selfLink;
+    private $selfLinkType;
+    public $logo;
     private $rights;
-    private $subtitle;
-    private $title;
+    public $subtitle;
+    public $title;
     private $published;
     private $updated;
     private $entries;
@@ -184,6 +188,10 @@ class Atom10Feed extends XMLStringer
 
         $this->renderAuthors();
 
+        if ($this->selfLink) {
+            $this->addLink($this->selfLink, array('rel' => 'self',
+                                                  'type' => $this->selfLinkType));
+        }
         $this->renderLinks();
     }
 
@@ -253,6 +261,12 @@ class Atom10Feed extends XMLStringer
         $this->id = $id;
     }
 
+    function setSelfLink($url, $type='application/atom+xml')
+    {
+        $this->selfLink = $url;
+        $this->selfLinkType = $type;
+    }
+
     function setTitle($title)
     {
         $this->title = $title;
index 52ee4c7d6e4d725d671e72772ef2797deb538370..08c1c707c578091a0d5eb7d67b0795d776b9f013 100644 (file)
@@ -49,14 +49,42 @@ class AtomGroupNoticeFeed extends AtomNoticeFeed
     /**
      * Constructor
      *
-     * @param Group   $group   the group for the feed (optional)
+     * @param Group   $group   the group for the feed
      * @param boolean $indent  flag to turn indenting on or off
      *
      * @return void
      */
-    function __construct($group = null, $indent = true) {
+    function __construct($group, $indent = true) {
         parent::__construct($indent);
         $this->group = $group;
+
+        $title      = sprintf(_("%s timeline"), $group->nickname);
+        $this->setTitle($title);
+
+        $sitename   = common_config('site', 'name');
+        $subtitle   = sprintf(
+            _('Updates from %1$s on %2$s!'),
+            $group->nickname,
+            $sitename
+        );
+        $this->setSubtitle($subtitle);
+
+        $avatar = $group->homepage_logo;
+        $logo = ($avatar) ? $avatar : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
+        $this->setLogo($logo);
+
+        $this->setUpdated('now');
+
+        $self = common_local_url('ApiTimelineGroup',
+                                 array('id' => $group->id,
+                                       'format' => 'atom'));
+        $this->setId($self);
+        $this->setSelfLink($self);
+
+        $this->addAuthorRaw($group->asAtomAuthor());
+        $this->setActivitySubject($group->asActivitySubject());
+
+        $this->addLink($group->homeUrl());
     }
 
     function getGroup()
index 2ad8de4550d1a3c3aac8b694f974a4ebf9e19c2d..55cebef6df9551a482edf0ca2522b7cf6f02cd52 100644 (file)
@@ -49,19 +49,56 @@ class AtomUserNoticeFeed extends AtomNoticeFeed
     /**
      * Constructor
      *
-     * @param User    $user    the user for the feed (optional)
+     * @param User    $user    the user for the feed
      * @param boolean $indent  flag to turn indenting on or off
      *
      * @return void
      */
 
-    function __construct($user = null, $indent = true) {
+    function __construct($user, $indent = true) {
         parent::__construct($indent);
         $this->user = $user;
         if (!empty($user)) {
             $profile = $user->getProfile();
             $this->addAuthor($profile->nickname, $user->uri);
         }
+
+        $title      = sprintf(_("%s timeline"), $user->nickname);
+        $this->setTitle($title);
+
+        $sitename   = common_config('site', 'name');
+        $subtitle   = sprintf(
+            _('Updates from %1$s on %2$s!'),
+            $user->nickname, $sitename
+        );
+        $this->setSubtitle($subtitle);
+
+        $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+        $logo = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE);
+        $this->setLogo($logo);
+
+        $this->setUpdated('now');
+
+        $this->addLink(
+            common_local_url(
+                'showstream',
+                array('nickname' => $user->nickname)
+            )
+        );
+        
+        $self = common_local_url('ApiTimelineUser',
+                                 array('id' => $user->id,
+                                       'format' => 'atom'));
+        $this->setId($self);
+        $this->setSelfLink($self);
+
+        $this->addLink(
+            common_local_url('sup', null, null, $user->id),
+            array(
+                'rel' => 'http://api.friendfeed.com/2008/03#sup',
+                'type' => 'application/json'
+            )
+        );
     }
 
     function getUser()
index 6ca31c485c3346919410f09fb768feeab3cc792f..d1e58f1d68ec2b83925b9faa98043b2da1fd5dff 100644 (file)
@@ -164,46 +164,21 @@ class OStatusQueueHandler extends QueueHandler
      */
     function userFeedForNotice()
     {
-        // @fixme this feels VERY hacky...
-        // should probably be a cleaner way to do it
-
-        ob_start();
-        $api = new ApiTimelineUserAction();
-        $api->prepare(array('id' => $this->notice->profile_id,
-                            'format' => 'atom',
-                            'max_id' => $this->notice->id,
-                            'since_id' => $this->notice->id - 1));
-        $api->showTimeline();
-        $feed = ob_get_clean();
-        
-        // ...and override the content-type back to something normal... eww!
-        // hope there's no other headers that got set while we weren't looking.
-        header('Content-Type: text/html; charset=utf-8');
-
-        common_log(LOG_DEBUG, $feed);
+        $atom = new AtomUserNoticeFeed($this->user);
+        $atom->addEntryFromNotice($this->notice);
+        $feed = $atom->getString();
+
         return $feed;
     }
 
     function groupFeedForNotice($group_id)
     {
-        // @fixme this feels VERY hacky...
-        // should probably be a cleaner way to do it
-
-        ob_start();
-        $api = new ApiTimelineGroupAction();
-        $args = array('id' => $group_id,
-                      'format' => 'atom',
-                      'max_id' => $this->notice->id,
-                      'since_id' => $this->notice->id - 1);
-        $api->prepare($args);
-        $api->handle($args);
-        $feed = ob_get_clean();
-        
-        // ...and override the content-type back to something normal... eww!
-        // hope there's no other headers that got set while we weren't looking.
-        header('Content-Type: text/html; charset=utf-8');
-
-        common_log(LOG_DEBUG, $feed);
+        $group = User_group::staticGet('id', $group_id);
+
+        $atom = new AtomGroupNoticeFeed($group);
+        $atom->addEntryFromNotice($this->notice);
+        $feed = $atom->getString();
+
         return $feed;
     }