]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apitimelinetag.php
Add AtomPub, Twitter-compat. API documentation to doc-src/
[quix0rs-gnu-social.git] / actions / apitimelinetag.php
index a29061fccfcbc50d35eef9c27ee3e79ad94ea3c1..1184440c7ddd9742f8388ad84130e61b8e53d9e5 100644 (file)
@@ -25,7 +25,8 @@
  * @author    Evan Prodromou <evan@status.net>
  * @author    Jeffery To <jeffery.to@gmail.com>
  * @author    Zach Copley <zach@status.net>
- * @copyright 2009 StatusNet, Inc.
+ * @copyright 2009-2010 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/
  */
@@ -34,8 +35,6 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 
-require_once INSTALLDIR . '/lib/apiprivateauth.php';
-
 /**
  * Returns the 20 most recent notices tagged by a given tag
  *
@@ -48,22 +47,11 @@ require_once INSTALLDIR . '/lib/apiprivateauth.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 ApiTimelineTagAction extends ApiPrivateAuthAction
 {
-
     var $notices = null;
 
-    /**
-     * Take arguments for running
-     *
-     * @param array $args $_REQUEST args
-     *
-     * @return boolean success flag
-     *
-     */
-
-    function prepare($args)
+    protected function prepare(array $args=array())
     {
         parent::prepare($args);
 
@@ -82,10 +70,9 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
      *
      * @return void
      */
-
-    function handle($args)
+    protected function handle()
     {
-        parent::handle($args);
+        parent::handle();
         $this->showTimeline();
     }
 
@@ -94,66 +81,58 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
      *
      * @return void
      */
-
     function showTimeline()
     {
         $sitename   = common_config('site', 'name');
         $sitelogo   = (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png');
+        // TRANS: Title for timeline with lastest notices with a given tag.
+        // TRANS: %s is the tag.
         $title      = sprintf(_("Notices tagged with %s"), $this->tag);
         $subtitle   = sprintf(
+            // TRANS: Subtitle for timeline with lastest notices with a given tag.
+            // TRANS: %1$s is the tag, $2$s is the StatusNet sitename.
             _('Updates tagged with %1$s on %2$s!'),
             $this->tag,
             $sitename
         );
         $taguribase = TagURI::base();
-        $id         = "tag:$taguribase:TagTimeline:".$tag;
+        $id         = "tag:$taguribase:TagTimeline:".$this->tag;
+
+        $link = common_local_url(
+            'tag',
+            array('tag' => $this->tag)
+        );
+
+        $self = $this->getSelfUri();
 
         switch($this->format) {
         case 'xml':
             $this->showXmlTimeline($this->notices);
             break;
         case 'rss':
-            $link = common_local_url(
-                'tag',
-                array('tag' => $this->tag)
-            );
             $this->showRssTimeline(
                 $this->notices,
                 $title,
                 $link,
                 $subtitle,
                 null,
-                $sitelogo
+                $sitelogo,
+                $self
             );
             break;
         case 'atom':
-
             header('Content-Type: application/atom+xml; charset=utf-8');
 
-            $atom = new AtomNoticeFeed();
+            $atom = new AtomNoticeFeed($this->auth_user);
 
             $atom->setId($id);
             $atom->setTitle($title);
             $atom->setSubtitle($subtitle);
-            $atom->setLogo($logo);
+            $atom->setLogo($sitelogo);
             $atom->setUpdated('now');
 
-            $atom->addLink(
-                common_local_url(
-                    'tag',
-                    array('tag' => $this->tag)
-                )
-            );
-
-            $aargs = array('format' => 'atom');
-            if (!empty($this->tag)) {
-                $aargs['tag'] = $this->tag;
-            }
-
-            $atom->addLink(
-                $this->getSelfUri('ApiTimelineTag', $aargs),
-                array('rel' => 'self', 'type' => 'application/atom+xml')
-            );
+            $atom->addLink($link);
+            $atom->setSelfLink($self);
 
             $atom->addEntryFromNotices($this->notices);
             $this->raw($atom->getString());
@@ -162,7 +141,16 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
         case 'json':
             $this->showJsonTimeline($this->notices);
             break;
+        case 'as':
+            header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
+            $doc = new ActivityStreamJSONDocument($this->auth_user);
+            $doc->setTitle($title);
+            $doc->addLink($link, 'alternate', 'text/html');
+            $doc->addItemsFromNotices($this->notices);
+            $this->raw($doc->asString());
+            break;
         default:
+            // TRANS: Client error displayed when coming across a non-supported API method.
             $this->clientError(_('API method not found.'), $code = 404);
             break;
         }
@@ -173,22 +161,14 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
      *
      * @return array notices
      */
-
     function getNotices()
     {
-        $notices = array();
+        $notice = Notice_tag::getStream($this->tag)->getNotices(($this->page - 1) * $this->count,
+                                                                 $this->count + 1,
+                                                                 $this->since_id,
+                                                                 $this->max_id);
 
-        $notice = Notice_tag::getStream(
-            $this->tag,
-            ($this->page - 1) * $this->count,
-            $this->count + 1
-        );
-
-        while ($notice->fetch()) {
-            $notices[] = clone($notice);
-        }
-
-        return $notices;
+        return $notice->fetchAll();
     }
 
     /**
@@ -198,7 +178,6 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
      *
      * @return boolean true
      */
-
     function isReadOnly($args)
     {
         return true;
@@ -209,7 +188,6 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
      *
      * @return string datestamp of the latest notice in the stream
      */
-
     function lastModified()
     {
         if (!empty($this->notices) && (count($this->notices) > 0)) {
@@ -227,7 +205,6 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
      *
      * @return string etag
      */
-
     function etag()
     {
         if (!empty($this->notices) && (count($this->notices) > 0)) {
@@ -237,6 +214,7 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
             return '"' . implode(
                 ':',
                 array($this->arg('action'),
+                      common_user_cache_hash($this->auth_user),
                       common_language(),
                       $this->tag,
                       strtotime($this->notices[0]->created),
@@ -247,5 +225,4 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
 
         return null;
     }
-
 }