]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apitimelineuser.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / actions / apitimelineuser.php
index 9696ea3615902de8d4ee4f9bd80f3ef966704f61..1ec6b74de6ea74bf495f1369820134beefb2c43c 100644 (file)
@@ -59,6 +59,8 @@ class ApiTimelineUserAction extends ApiBareAuthAction
 {
     var $notices = null;
 
+    var $next_id = null;
+
     /**
      * Take arguments for running
      *
@@ -66,7 +68,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
      *
      * @return boolean success flag
      */
-    protected function prepare($args)
+    protected function prepare(array $args=array())
     {
         parent::prepare($args);
 
@@ -77,6 +79,10 @@ class ApiTimelineUserAction extends ApiBareAuthAction
             $this->clientError(_('No such user.'), 404);
         }
 
+        if (!$this->target->isLocal()) {
+            $this->serverError(_('Remote user timelines are not available here yet.'), 501);
+        }
+
         $this->notices = $this->getNotices();
 
         return true;
@@ -124,6 +130,29 @@ class ApiTimelineUserAction extends ApiBareAuthAction
         $suplink = common_local_url('sup', null, null, $this->target->id);
         header('X-SUP-ID: ' . $suplink);
 
+
+        // paging links
+        $nextUrl = !empty($this->next_id)
+                    ? common_local_url('ApiTimelineUser',
+                                    array('format' => $this->format,
+                                          'id' => $this->target->id),
+                                    array('max_id' => $this->next_id))
+                    : null;
+
+        $prevExtra = array();
+        if (!empty($this->notices)) {
+            assert($this->notices[0] instanceof Notice);
+            $prevExtra['since_id'] = $this->notices[0]->id;
+        }
+
+        $prevUrl = common_local_url('ApiTimelineUser',
+                                    array('format' => $this->format,
+                                          'id' => $this->target->id),
+                                    $prevExtra);
+        $firstUrl = common_local_url('ApiTimelineUser',
+                                    array('format' => $this->format,
+                                          'id' => $this->target->id));
+
         switch($this->format) {
         case 'xml':
             $this->showXmlTimeline($this->notices);
@@ -150,37 +179,18 @@ class ApiTimelineUserAction extends ApiBareAuthAction
             // change too quickly!
 
             if (!empty($this->next_id)) {
-                $nextUrl = common_local_url('ApiTimelineUser',
-                                            array('format' => 'atom',
-                                                  'id' => $this->target->id),
-                                            array('max_id' => $this->next_id));
-
                 $atom->addLink($nextUrl,
                                array('rel' => 'next',
                                      'type' => 'application/atom+xml'));
             }
 
             if (($this->page > 1 || !empty($this->max_id)) && !empty($this->notices)) {
-
-                $lastNotice = $this->notices[0];
-                $lastId     = $lastNotice->id;
-
-                $prevUrl = common_local_url('ApiTimelineUser',
-                                            array('format' => 'atom',
-                                                  'id' => $this->target->id),
-                                            array('since_id' => $lastId));
-
                 $atom->addLink($prevUrl,
                                array('rel' => 'prev',
                                      'type' => 'application/atom+xml'));
             }
 
             if ($this->page > 1 || !empty($this->since_id) || !empty($this->max_id)) {
-
-                $firstUrl = common_local_url('ApiTimelineUser',
-                                            array('format' => 'atom',
-                                                  'id' => $this->target->id));
-
                 $atom->addLink($firstUrl,
                                array('rel' => 'first',
                                      'type' => 'application/atom+xml'));
@@ -201,13 +211,29 @@ class ApiTimelineUserAction extends ApiBareAuthAction
             $doc->addLink($link, 'alternate', 'text/html');
             $doc->addItemsFromNotices($this->notices);
 
-            // XXX: Add paging extension?
+            if (!empty($this->next_id)) {
+                $doc->addLink($nextUrl,
+                               array('rel' => 'next',
+                                     'type' => ActivityStreamJSONDocument::CONTENT_TYPE));
+            }
+
+            if (($this->page > 1 || !empty($this->max_id)) && !empty($this->notices)) {
+                $doc->addLink($prevUrl,
+                               array('rel' => 'prev',
+                                     'type' => ActivityStreamJSONDocument::CONTENT_TYPE));
+            }
+
+            if ($this->page > 1 || !empty($this->since_id) || !empty($this->max_id)) {
+                $doc->addLink($firstUrl,
+                               array('rel' => 'first',
+                                     'type' => ActivityStreamJSONDocument::CONTENT_TYPE));
+            }
 
             $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);
+            $this->clientError(_('API method not found.'), 404);
         }
     }
 
@@ -246,7 +272,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
      * @return boolean true
      */
 
-    function isReadOnly($args)
+    function isReadOnly(array $args=array())
     {
         return ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD');
     }
@@ -383,8 +409,8 @@ class ApiTimelineUserAction extends ApiBareAuthAction
 
         // Get (safe!) HTML and text versions of the content
 
-        $rendered = $this->purify($sourceContent);
-        $content = html_entity_decode(strip_tags($rendered), ENT_QUOTES, 'UTF-8');
+        $rendered = common_purify($sourceContent);
+        $content = common_strip_html($rendered);
 
         $shortened = $this->auth_user->shortenLinks($content);
 
@@ -423,19 +449,15 @@ class ApiTimelineUserAction extends ApiBareAuthAction
         if ($activity->context instanceof ActivityContext) {
 
             foreach ($activity->context->attention as $uri=>$type) {
-
-                $profile = Profile::fromURI($uri);
-
-                if (!empty($profile)) {
-                    $options['replies'][] = $uri;
-                } else {
-                    $group = User_group::getKV('uri', $uri);
-                    if (!empty($group)) {
-                        $options['groups'][] = $group->id;
+                try {
+                    $profile = Profile::fromUri($uri);
+                    if ($profile->isGroup()) {
+                        $options['groups'][] = $profile->id;
                     } else {
-                        // @fixme: hook for discovery here
-                        common_log(LOG_WARNING, sprintf('AtomPub post with unknown attention URI %s', $uri));
+                        $options['replies'][] = $uri;
                     }
+                } catch (UnknownUriException $e) {
+                    common_log(LOG_WARNING, sprintf('AtomPub post with unknown attention URI %s', $uri));
                 }
             }
 
@@ -486,13 +508,4 @@ class ApiTimelineUserAction extends ApiBareAuthAction
 
         return $saved;
     }
-
-    function purify($content)
-    {
-        require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
-
-        $config = array('safe' => 1,
-                        'deny_attribute' => 'id,style,on*');
-        return htmLawed($content, $config);
-    }
 }