]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
correctly show <source> for atom feeds
authorEvan Prodromou <evan@status.net>
Tue, 3 Aug 2010 22:50:21 +0000 (15:50 -0700)
committerEvan Prodromou <evan@status.net>
Tue, 3 Aug 2010 22:50:21 +0000 (15:50 -0700)
classes/Notice.php
classes/Profile.php
plugins/OStatus/OStatusPlugin.php

index f6e9eb585daa71226ce5a4e0f1e99e1a8e8ddad2..61844d487e8e577476b368633767ba714136e56e 100644 (file)
@@ -1215,29 +1215,45 @@ class Notice extends Memcached_DataObject
 
             if ($source) {
 
-                $xs->elementStart('source');
+                $atom_feed = $profile->getAtomFeed();
 
-                $xs->element('id', null, $profile->profileurl);
-                $xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name'));
-                $xs->element('link', array('href' => $profile->profileurl));
+                if (!empty($atom_feed)) {
 
-                $user = User::staticGet('id', $profile->id);
+                    $xs->elementStart('source');
+
+                    // XXX: we should store the actual feed ID
+
+                    $xs->element('id', null, $atom_feed);
+
+                    // XXX: we should store the actual feed title
+
+                    $xs->element('title', null, $profile->getBestName());
+
+                    $xs->element('link', array('rel' => 'alternate',
+                                               'type' => 'text/html',
+                                               'href' => $profile->profileurl));
 
-                if (!empty($user)) {
-                    $atom_feed = common_local_url('ApiTimelineUser',
-                                                  array('format' => 'atom',
-                                                        'id' => $profile->nickname));
                     $xs->element('link', array('rel' => 'self',
                                                'type' => 'application/atom+xml',
-                                               'href' => $profile->profileurl));
-                    $xs->element('link', array('rel' => 'license',
-                                               'href' => common_config('license', 'url')));
-                }
+                                               'href' => $atom_feed));
 
-                $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE));
-                $xs->element('updated', null, common_date_w3dtf($this->created)); // FIXME: not true!
+                    $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE));
 
-                $xs->elementEnd('source');
+                    $notice = $profile->getCurrentNotice();
+
+                    if (!empty($notice)) {
+                        $xs->element('updated', null, common_date_w3dtf($notice->created));
+                    }
+
+                    $user = User::staticGet('id', $profile->id);
+
+                    if (!empty($user)) {
+                        $xs->element('link', array('rel' => 'license',
+                                                   'href' => common_config('license', 'url')));
+                    }
+
+                    $xs->elementEnd('source');
+                }
             }
             Event::handle('EndActivitySource', array(&$this, &$xs));
         }
index a303469e96851652b18b49009f7aeda5a7fc063c..abd6eb0315aa67df7e0a201928e17132c9b84537 100644 (file)
@@ -152,17 +152,16 @@ class Profile extends Memcached_DataObject
      *
      * @return mixed Notice or null
      */
+
     function getCurrentNotice()
     {
-        $notice = new Notice();
-        $notice->profile_id = $this->id;
-        // @fixme change this to sort on notice.id only when indexes are updated
-        $notice->orderBy('created DESC, notice.id DESC');
-        $notice->limit(1);
-        if ($notice->find(true)) {
+        $notice = $this->getNotices(0, 1);
+
+        if ($notice->fetch()) {
             return $notice;
+        } else {
+            return null;
         }
-        return null;
     }
 
     function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
@@ -943,4 +942,20 @@ class Profile extends Memcached_DataObject
 
         return $result;
     }
+
+    function getAtomFeed()
+    {
+        $feed = null;
+
+        if (Event::handle('StartProfileGetAtomFeed', array($this, &$feed))) {
+            $user = User::staticGet('id', $this->id);
+            if (!empty($user)) {
+                $feed = common_local_url('ApiTimelineUser', array('id' => $user->id,
+                                                                  'format' => 'atom'));
+            }
+            Event::handle('EndProfileGetAtomFeed', array($this, $feed));
+        }
+
+        return $feed;
+    }
 }
index c61e2cc5f3984234940b694ea74132ece1d6b9db..4fc9d4108820f4807915c6f5b60690252a45a8b5 100644 (file)
@@ -953,4 +953,16 @@ class OStatusPlugin extends Plugin
         }
         return false;
     }
+
+    public function onStartProfileGetAtomFeed($profile, &$feed)
+    {
+        $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
+
+        if (empty($oprofile)) {
+            return true;
+        }
+
+        $feed = $oprofile->feeduri;
+        return false;
+    }
 }