]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/twitapistatuses.php
Fixes #1277: Typo in variable name in actions/twitapidirect_messages.php.
[quix0rs-gnu-social.git] / actions / twitapistatuses.php
index c33643a3ce23123b7c7a7e1186094a5385869825..63e29068b140897da4e8d0eb5ffd72b4766b4516 100644 (file)
@@ -21,9 +21,11 @@ if (!defined('LACONICA')) { exit(1); }
 
 require_once(INSTALLDIR.'/lib/twitterapi.php');
 
-class TwitapistatusesAction extends TwitterapiAction {
+class TwitapistatusesAction extends TwitterapiAction
+{
 
-    function public_timeline($args, $apidata) {
+    function public_timeline($args, $apidata)
+    {
         parent::handle($args);
 
         $sitename = common_config('site', 'name');
@@ -74,17 +76,18 @@ class TwitapistatusesAction extends TwitterapiAction {
                     $this->show_json_timeline($notice);
                     break;
                 default:
-                    common_user_error(_('API method not found!'), $code = 404);
+                    $this->clientError(_('API method not found!'), $code = 404);
                     break;
             }
 
         } else {
-            common_server_error(_('Couldn\'t find any statuses.'), $code = 503);
+            $this->serverError(_('Couldn\'t find any statuses.'), $code = 503);
         }
 
     }
 
-    function friends_timeline($args, $apidata) {
+    function friends_timeline($args, $apidata)
+    {
         parent::handle($args);
 
         $since = $this->arg('since');
@@ -112,9 +115,14 @@ class TwitapistatusesAction extends TwitterapiAction {
 
         $since = strtotime($this->arg('since'));
 
-        $user = $this->get_user(NULL, $apidata);
+        $user = $this->get_user($apidata['api_arg'], $apidata);
         $this->auth_user = $user;
 
+        if (empty($user)) {
+             $this->clientError(_('No such user!'), 404, $apidata['content-type']);
+            return;
+        }
+
         $profile = $user->getProfile();
 
         $sitename = common_config('site', 'name');
@@ -141,26 +149,27 @@ class TwitapistatusesAction extends TwitterapiAction {
             $this->show_json_timeline($notice);
             break;
          default:
-            common_user_error(_('API method not found!'), $code = 404);
+            $this->clientError(_('API method not found!'), $code = 404);
         }
 
     }
 
-    function user_timeline($args, $apidata) {
+    function user_timeline($args, $apidata)
+    {
         parent::handle($args);
 
         $this->auth_user = $apidata['user'];
         $user = $this->get_user($apidata['api_arg'], $apidata);
 
         if (!$user) {
-            $this->client_error('Not Found', 404, $apidata['content-type']);
+            $this->clientError('Not Found', 404, $apidata['content-type']);
             return;
         }
 
         $profile = $user->getProfile();
 
         if (!$profile) {
-            common_server_error(_('User has no profile.'));
+            $this->serverError(_('User has no profile.'));
             return;
         }
 
@@ -200,7 +209,7 @@ class TwitapistatusesAction extends TwitterapiAction {
         # FriendFeed's SUP protocol
         # Also added RSS and Atom feeds
 
-        $suplink = common_local_url('sup', NULL, $user->id);
+        $suplink = common_local_url('sup', null, null, $user->id);
         header('X-SUP-ID: '.$suplink);
 
         # XXX: since
@@ -221,22 +230,23 @@ class TwitapistatusesAction extends TwitterapiAction {
             $this->show_json_timeline($notice);
             break;
          default:
-            common_user_error(_('API method not found!'), $code = 404);
+            $this->clientError(_('API method not found!'), $code = 404);
         }
 
     }
 
-    function update($args, $apidata) {
+    function update($args, $apidata)
+    {
 
         parent::handle($args);
 
         if (!in_array($apidata['content-type'], array('xml', 'json'))) {
-            common_user_error(_('API method not found!'), $code = 404);
+            $this->clientError(_('API method not found!'), $code = 404);
             return;
         }
 
         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
-            $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
+            $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']);
             return;
         }
 
@@ -268,7 +278,7 @@ class TwitapistatusesAction extends TwitterapiAction {
                 // as "truncated." Sending this error may screw up some clients
                 // that assume Twitter will truncate for them.    Should we just
                 // truncate too? -- Zach
-                $this->client_error(_('That\'s too long. Max notice size is 140 chars.'), $code = 406, $apidata['content-type']);
+                $this->clientError(_('That\'s too long. Max notice size is 140 chars.'), $code = 406, $apidata['content-type']);
                 return;
 
             }
@@ -291,7 +301,7 @@ class TwitapistatusesAction extends TwitterapiAction {
             $apidata['api_arg'] = $n->id;
         } else {
 
-            $reply_to = NULL;
+            $reply_to = null;
 
             if ($in_reply_to_status_id) {
 
@@ -301,7 +311,7 @@ class TwitapistatusesAction extends TwitterapiAction {
                 if ($reply) {
                     $reply_to = $in_reply_to_status_id;
                 } else {
-                    $this->client_error(_('Not found'), $code = 404, $apidata['content-type']);
+                    $this->clientError(_('Not found'), $code = 404, $apidata['content-type']);
                     return;
                 }
             }
@@ -310,7 +320,7 @@ class TwitapistatusesAction extends TwitterapiAction {
                 $source, 1, $reply_to);
 
             if (is_string($notice)) {
-                $this->server_error($notice);
+                $this->serverError($notice);
                 return;
             }
 
@@ -321,7 +331,8 @@ class TwitapistatusesAction extends TwitterapiAction {
         $this->show($args, $apidata);
     }
 
-    function replies($args, $apidata) {
+    function replies($args, $apidata)
+    {
 
         parent::handle($args);
 
@@ -383,16 +394,17 @@ class TwitapistatusesAction extends TwitterapiAction {
             $this->show_json_timeline($notices);
             break;
          default:
-            common_user_error(_('API method not found!'), $code = 404);
+            $this->clientError(_('API method not found!'), $code = 404);
         }
 
     }
 
-    function show($args, $apidata) {
+    function show($args, $apidata)
+    {
         parent::handle($args);
 
         if (!in_array($apidata['content-type'], array('xml', 'json'))) {
-            common_user_error(_('API method not found!'), $code = 404);
+            $this->clientError(_('API method not found!'), $code = 404);
             return;
         }
 
@@ -408,24 +420,25 @@ class TwitapistatusesAction extends TwitterapiAction {
             }
         } else {
             // XXX: Twitter just sets a 404 header and doens't bother to return an err msg
-            $this->client_error(_('No status with that ID found.'), 404, $apidata['content-type']);
+            $this->clientError(_('No status with that ID found.'), 404, $apidata['content-type']);
         }
 
     }
 
-    function destroy($args, $apidata) {
+    function destroy($args, $apidata)
+    {
 
         parent::handle($args);
 
         if (!in_array($apidata['content-type'], array('xml', 'json'))) {
-            common_user_error(_('API method not found!'), $code = 404);
+            $this->clientError(_('API method not found!'), $code = 404);
             return;
         }
 
         // Check for RESTfulness
         if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
             // XXX: Twitter just prints the err msg, no XML / JSON.
-            $this->client_error(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']);
+            $this->clientError(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']);
             return;
         }
 
@@ -435,14 +448,13 @@ class TwitapistatusesAction extends TwitterapiAction {
         $notice = Notice::staticGet($notice_id);
 
         if (!$notice) {
-            $this->client_error(_('No status found with that ID.'), 404, $apidata['content-type']);
+            $this->clientError(_('No status found with that ID.'), 404, $apidata['content-type']);
             return;
         }
 
         if ($user->id == $notice->profile_id) {
             $replies = new Reply;
             $replies->get('notice_id', $notice_id);
-            common_dequeue_notice($notice);
             $replies->delete();
             $notice->delete();
 
@@ -452,31 +464,43 @@ class TwitapistatusesAction extends TwitterapiAction {
                 $this->show_single_json_status($notice);
             }
         } else {
-            $this->client_error(_('You may not delete another user\'s status.'), 403, $apidata['content-type']);
+            $this->clientError(_('You may not delete another user\'s status.'), 403, $apidata['content-type']);
         }
 
     }
 
-    function friends($args, $apidata) {
+    function friends($args, $apidata)
+    {
         parent::handle($args);
         return $this->subscriptions($apidata, 'subscribed', 'subscriber');
     }
 
-    function followers($args, $apidata) {
+    function friendsIDs($args, $apidata)
+    {
         parent::handle($args);
+        return $this->subscriptions($apidata, 'subscribed', 'subscriber', true);
+    }
 
+    function followers($args, $apidata)
+    {
+        parent::handle($args);
         return $this->subscriptions($apidata, 'subscriber', 'subscribed');
     }
 
-    function subscriptions($apidata, $other_attr, $user_attr) {
+    function followersIDs($args, $apidata)
+    {
+        parent::handle($args);
+        return $this->subscriptions($apidata, 'subscriber', 'subscribed', true);
+    }
 
-        # XXX: lite
+    function subscriptions($apidata, $other_attr, $user_attr, $onlyIDs=false)
+    {
 
-        $this->auth_user = $apidate['user'];
+        $this->auth_user = $apidata['user'];
         $user = $this->get_user($apidata['api_arg'], $apidata);
 
         if (!$user) {
-            $this->client_error('Not Found', 404, $apidata['content-type']);
+            $this->clientError('Not Found', 404, $apidata['content-type']);
             return;
         }
 
@@ -489,7 +513,7 @@ class TwitapistatusesAction extends TwitterapiAction {
         $profile = $user->getProfile();
 
         if (!$profile) {
-            common_server_error(_('User has no profile.'));
+            $this->serverError(_('User has no profile.'));
             return;
         }
 
@@ -504,7 +528,10 @@ class TwitapistatusesAction extends TwitterapiAction {
         }
 
         $sub->orderBy('created DESC');
-        $sub->limit(($page-1)*100, 100);
+
+        if (!$onlyIDs) {
+            $sub->limit(($page-1)*100, 100);
+        }
 
         $others = array();
 
@@ -519,18 +546,25 @@ class TwitapistatusesAction extends TwitterapiAction {
         $type = $apidata['content-type'];
 
         $this->init_document($type);
-        $this->show_profiles($others, $type);
+
+        if ($onlyIDs) {
+            $this->showIDs($others, $type);
+        } else {
+            $this->show_profiles($others, $type);
+        }
+
         $this->end_document($type);
     }
 
-    function show_profiles($profiles, $type) {
+    function show_profiles($profiles, $type)
+    {
         switch ($type) {
          case 'xml':
-            common_element_start('users', array('type' => 'array'));
+            $this->elementStart('users', array('type' => 'array'));
             foreach ($profiles as $profile) {
                 $this->show_profile($profile);
             }
-            common_element_end('users');
+            $this->elementEnd('users');
             break;
          case 'json':
             $arrays = array();
@@ -540,16 +574,40 @@ class TwitapistatusesAction extends TwitterapiAction {
             print json_encode($arrays);
             break;
          default:
-            $this->client_error(_('unsupported file type'));
+            $this->clientError(_('unsupported file type'));
+        }
+    }
+
+    function showIDs($profiles, $type)
+    {
+        switch ($type) {
+         case 'xml':
+            $this->elementStart('ids');
+            foreach ($profiles as $profile) {
+                $this->element('id', null, $profile->id);
+            }
+            $this->elementEnd('ids');
+            break;
+         case 'json':
+            $ids = array();
+            foreach ($profiles as $profile) {
+                $ids[] = (int)$profile->id;
+            }
+            print json_encode($ids);
+            break;
+         default:
+            $this->clientError(_('unsupported file type'));
         }
     }
 
-    function featured($args, $apidata) {
+    function featured($args, $apidata)
+    {
         parent::handle($args);
-        common_server_error(_('API method under construction.'), $code=501);
+        $this->serverError(_('API method under construction.'), $code=501);
     }
 
-    function supported($cmd) {
+    function supported($cmd)
+    {
 
         $cmdlist = array('MessageCommand', 'SubCommand', 'UnsubCommand', 'FavCommand', 'OnCommand', 'OffCommand');