]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apitimelinegroup.php
Initial upgraded Atom output for group timelines
[quix0rs-gnu-social.git] / actions / apitimelinegroup.php
index f25f6ba513d76b6ad85aa129be18dc3f4ffaabfb..45962fa76fefa3a08f0c3e22dbee1154e96326a9 100644 (file)
@@ -69,7 +69,6 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
         parent::prepare($args);
 
         $this->group   = $this->getTargetGroup($this->arg('id'));
-        $this->notices = $this->getNotices();
 
         return true;
     }
@@ -87,6 +86,13 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
     function handle($args)
     {
         parent::handle($args);
+
+        if (empty($this->group)) {
+            $this->clientError(_('Group not found!'), 404, $this->format);
+            return false;
+        }
+
+        $this->notices = $this->getNotices();
         $this->showTimeline();
     }
 
@@ -99,46 +105,81 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
     function showTimeline()
     {
         $sitename   = common_config('site', 'name');
+        $avatar     = $this->group->homepage_logo;
         $title      = sprintf(_("%s timeline"), $this->group->nickname);
         $taguribase = common_config('integration', 'taguri');
         $id         = "tag:$taguribase:GroupTimeline:" . $this->group->id;
-        $link       = common_local_url(
-            'showgroup',
-            array('nickname' => $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);
+
         switch($this->format) {
         case 'xml':
             $this->showXmlTimeline($this->notices);
             break;
         case 'rss':
-            $this->showRssTimeline($this->notices, $title, $link, $subtitle);
-            break;
-        case 'atom':
-            $selfuri = common_root_url() .
-                'api/statusnet/groups/timeline/' .
-                    $this->group->nickname . '.atom';
-            $this->showAtomTimeline(
+                $this->showRssTimeline(
                 $this->notices,
                 $title,
-                $id,
-                $link,
+                $this->group->homeUrl(),
                 $subtitle,
                 null,
-                $selfuri
+                $logo
             );
+            break;
+        case 'atom':
+
+            header('Content-Type: application/atom+xml; charset=utf-8');
+
+            try {
+
+                $atom = new AtomNoticeFeed();
+
+                $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;
+                }
+
+                $atom->addLink(
+                    $this->getSelfUri('ApiTimelineGroup', $aargs),
+                    array('rel' => 'self', 'type' => 'application/atom+xml')
+                );
+
+                $atom->addEntryFromNotices($this->notices);
+
+                $this->raw($atom->getString());
+
+            } catch (Atom10FeedException $e) {
+                $this->serverError(
+                    'Could not generate feed for group - ' . $e->getMessage()
+                );
+                return;
+            }
+
             break;
         case 'json':
             $this->showJsonTimeline($this->notices);
             break;
         default:
             $this->clientError(
-                _('API method not found!'),
+                _('API method not found.'),
                 404,
                 $this->format
             );