]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apitimelineuser.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / actions / apitimelineuser.php
index 3e849cc786c56b69c77b67c5ae6eee3685cdbd8b..0046c462d71cc7ef5970bdd01147378aa767eb26 100644 (file)
@@ -29,6 +29,7 @@
  * @author    Robin Millette <robin@millette.info>
  * @author    Zach Copley <zach@status.net>
  * @copyright 2009 StatusNet, Inc.
+ * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -56,10 +57,8 @@ require_once INSTALLDIR . '/lib/apibareauth.php';
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link     http://status.net/
  */
-
 class ApiTimelineUserAction extends ApiBareAuthAction
 {
-
     var $notices = null;
 
     /**
@@ -68,9 +67,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
      * @param array $args $_REQUEST args
      *
      * @return boolean success flag
-     *
      */
-
     function prepare($args)
     {
         parent::prepare($args);
@@ -78,6 +75,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
         $this->user = $this->getTargetUser($this->arg('id'));
 
         if (empty($this->user)) {
+            // TRANS: Client error displayed requesting most recent notices for a non-existing user.
             $this->clientError(_('No such user.'), 404, $this->format);
             return;
         }
@@ -96,7 +94,6 @@ class ApiTimelineUserAction extends ApiBareAuthAction
      *
      * @return void
      */
-
     function handle($args)
     {
         parent::handle($args);
@@ -108,25 +105,20 @@ class ApiTimelineUserAction extends ApiBareAuthAction
      *
      * @return void
      */
-
     function showTimeline()
     {
         $profile = $this->user->getProfile();
-        $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
 
-        $sitename   = common_config('site', 'name');
-        $title      = sprintf(_("%s timeline"), $this->user->nickname);
-        $taguribase = TagURI::base();
-        $id         = "tag:$taguribase:UserTimeline:" . $this->user->id;
-        $link       = common_local_url(
+        // We'll use the shared params from the Atom stub
+        // for other feed types.
+        $atom = new AtomUserNoticeFeed($this->user, $this->auth_user);
+
+        $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);
+
+        $self = $this->getSelfUri();
 
         // FriendFeed's SUP protocol
         // Also added RSS and Atom feeds
@@ -140,74 +132,32 @@ class ApiTimelineUserAction extends ApiBareAuthAction
             break;
         case 'rss':
             $this->showRssTimeline(
-                $this->notices, $title, $link,
-                $subtitle, $suplink, $logo
+                $this->notices,
+                $atom->title,
+                $link,
+                $atom->subtitle,
+                $suplink,
+                $atom->logo,
+                $self
             );
             break;
         case 'atom':
-
             header('Content-Type: application/atom+xml; charset=utf-8');
 
-            // If this was called using an integer ID, i.e.: using the canonical
-            // URL for this user's feed, then pass the User object into the feed,
-            // so the OStatus plugin, and possibly other plugins, can access it.
-            // Feels sorta hacky. -- Z
-
-            $atom = null;
-            $id = $this->arg('id');
-
-            if (strval(intval($id)) === strval($id)) {
-                $atom = new AtomUserNoticeFeed($this->user);
-            } else {
-                $atom = new AtomUserNoticeFeed();
-            }
-
-            $atom->setId($id);
-            $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->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'
-                )
-            );
-
+            $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':
             $this->showJsonTimeline($this->notices);
             break;
         default:
+            // TRANS: Client error displayed when trying to handle an unknown API method.
             $this->clientError(_('API method not found.'), $code = 404);
             break;
         }
-
     }
 
     /**
@@ -215,14 +165,13 @@ class ApiTimelineUserAction extends ApiBareAuthAction
      *
      * @return array notices
      */
-
     function getNotices()
     {
         $notices = array();
 
         $notice = $this->user->getNotices(
             ($this->page-1) * $this->count, $this->count,
-            $this->since_id, $this->max_id, $this->since
+            $this->since_id, $this->max_id
         );
 
         while ($notice->fetch()) {
@@ -239,7 +188,6 @@ class ApiTimelineUserAction extends ApiBareAuthAction
      *
      * @return boolean true
      */
-
     function isReadOnly($args)
     {
         return true;
@@ -250,7 +198,6 @@ class ApiTimelineUserAction extends ApiBareAuthAction
      *
      * @return string datestamp of the latest notice in the stream
      */
-
     function lastModified()
     {
         if (!empty($this->notices) && (count($this->notices) > 0)) {
@@ -268,16 +215,15 @@ class ApiTimelineUserAction extends ApiBareAuthAction
      *
      * @return string etag
      */
-
     function etag()
     {
         if (!empty($this->notices) && (count($this->notices) > 0)) {
-
             $last = count($this->notices) - 1;
 
             return '"' . implode(
                 ':',
                 array($this->arg('action'),
+                      common_user_cache_hash($this->auth_user),
                       common_language(),
                       $this->user->id,
                       strtotime($this->notices[0]->created),
@@ -288,5 +234,4 @@ class ApiTimelineUserAction extends ApiBareAuthAction
 
         return null;
     }
-
 }