]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/twitapistatuses.php
add design classes
[quix0rs-gnu-social.git] / actions / twitapistatuses.php
index 8d175ecab87574b18d270adce71cf5e408a1472b..3abeba36727d2f8ae4ee6708f8d3aab95d00a64d 100644 (file)
@@ -29,10 +29,12 @@ class TwitapistatusesAction extends TwitterapiAction
         parent::handle($args);
 
         $sitename = common_config('site', 'name');
-        $siteserver = common_config('site', 'server');
         $title = sprintf(_("%s public timeline"), $sitename);
-        $id = "tag:$siteserver:Statuses";
+
+        $taguribase = common_config('integration', 'taguri');
+        $id = "tag:$taguribase:PublicTimeline";
         $link = common_root_url();
+
         $subtitle = sprintf(_("%s updates from everyone!"), $sitename);
 
         // Number of public statuses to return by default -- Twitter sends 20
@@ -70,18 +72,19 @@ class TwitapistatusesAction extends TwitterapiAction
                     $this->show_rss_timeline($notice, $title, $link, $subtitle);
                     break;
                 case 'atom':
-                    $this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
+                    $selfuri = common_root_url() . 'api/statuses/public_timeline.atom';
+                    $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri);
                     break;
                 case 'json':
                     $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);
         }
 
     }
@@ -114,17 +117,19 @@ 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;
 
-        $profile = $user->getProfile();
+        if (empty($user)) {
+             $this->clientError(_('No such user!'), 404, $apidata['content-type']);
+            return;
+        }
 
+        $profile = $user->getProfile();
         $sitename = common_config('site', 'name');
-        $siteserver = common_config('site', 'server');
-
         $title = sprintf(_("%s and friends"), $user->nickname);
-        $id = "tag:$siteserver:friends:" . $user->id;
+        $taguribase = common_config('integration', 'taguri');
+        $id = "tag:$taguribase:FriendsTimeline:" . $user->id;
         $link = common_local_url('all', array('nickname' => $user->nickname));
         $subtitle = sprintf(_('Updates from %1$s and friends on %2$s!'), $user->nickname, $sitename);
 
@@ -138,13 +143,20 @@ class TwitapistatusesAction extends TwitterapiAction
             $this->show_rss_timeline($notice, $title, $link, $subtitle);
             break;
          case 'atom':
-            $this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
+            if (isset($apidata['api_arg'])) {
+                $selfuri = common_root_url() .
+                    'api/statuses/friends_timeline/' . $apidata['api_arg'] . '.atom';
+            } else {
+                $selfuri = common_root_url() .
+                    'api/statuses/friends_timeline.atom';
+            }
+            $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri);
             break;
          case 'json':
             $this->show_json_timeline($notice);
             break;
          default:
-            common_user_error(_('API method not found!'), $code = 404);
+            $this->clientError(_('API method not found!'), $code = 404);
         }
 
     }
@@ -157,14 +169,14 @@ class TwitapistatusesAction extends TwitterapiAction
         $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;
         }
 
@@ -194,17 +206,16 @@ class TwitapistatusesAction extends TwitterapiAction
         $since = strtotime($this->arg('since'));
 
         $sitename = common_config('site', 'name');
-        $siteserver = common_config('site', 'server');
-
         $title = sprintf(_("%s timeline"), $user->nickname);
-        $id = "tag:$siteserver:user:".$user->id;
+        $taguribase = common_config('integration', 'taguri');
+        $id = "tag:$taguribase:UserTimeline:".$user->id;
         $link = common_local_url('showstream', array('nickname' => $user->nickname));
         $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $user->nickname, $sitename);
 
         # 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
@@ -219,13 +230,20 @@ class TwitapistatusesAction extends TwitterapiAction
             $this->show_rss_timeline($notice, $title, $link, $subtitle, $suplink);
             break;
          case 'atom':
-            $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink);
+            if (isset($apidata['api_arg'])) {
+                $selfuri = common_root_url() .
+                    'api/statuses/user_timeline/' . $apidata['api_arg'] . '.atom';
+            } else {
+                $selfuri = common_root_url() .
+                 'api/statuses/user_timeline.atom';
+            }
+            $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink, $selfuri);
             break;
          case 'json':
             $this->show_json_timeline($notice);
             break;
          default:
-            common_user_error(_('API method not found!'), $code = 404);
+            $this->clientError(_('API method not found!'), $code = 404);
         }
 
     }
@@ -236,12 +254,12 @@ class TwitapistatusesAction extends TwitterapiAction
         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;
         }
 
@@ -273,7 +291,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;
 
             }
@@ -306,7 +324,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;
                 }
             }
@@ -315,7 +333,7 @@ class TwitapistatusesAction extends TwitterapiAction
                 $source, 1, $reply_to);
 
             if (is_string($notice)) {
-                $this->server_error($notice);
+                $this->serverError($notice);
                 return;
             }
 
@@ -326,7 +344,7 @@ class TwitapistatusesAction extends TwitterapiAction
         $this->show($args, $apidata);
     }
 
-    function replies($args, $apidata)
+    function mentions($args, $apidata)
     {
 
         parent::handle($args);
@@ -337,17 +355,18 @@ class TwitapistatusesAction extends TwitterapiAction
         $since_id = $this->arg('since_id');
         $before_id = $this->arg('before_id');
 
+        $user = $this->get_user($apidata['api_arg'], $apidata);
         $this->auth_user = $apidata['user'];
-        $user = $this->auth_user;
         $profile = $user->getProfile();
 
         $sitename = common_config('site', 'name');
-        $siteserver = common_config('site', 'server');
-
-        $title = sprintf(_('%1$s / Updates replying to %2$s'), $sitename, $user->nickname);
-        $id = "tag:$siteserver:replies:".$user->id;
+        $title = sprintf(_('%1$s / Updates mentioning %2$s'),
+            $sitename, $user->nickname);
+        $taguribase = common_config('integration', 'taguri');
+        $id = "tag:$taguribase:Mentions:".$user->id;
         $link = common_local_url('replies', array('nickname' => $user->nickname));
-        $subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'), $sitename, $user->nickname, $profile->getBestName());
+        $subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'),
+            $sitename, $user->nickname, $profile->getBestName());
 
         if (!$page) {
             $page = 1;
@@ -368,7 +387,8 @@ class TwitapistatusesAction extends TwitterapiAction
 
         $since = strtotime($this->arg('since'));
 
-        $notice = $user->getReplies((($page-1)*20), $count, $since_id, $before_id, $since);
+        $notice = $user->getReplies((($page-1)*20),
+            $count, $since_id, $before_id, $since);
         $notices = array();
 
         while ($notice->fetch()) {
@@ -383,23 +403,31 @@ class TwitapistatusesAction extends TwitterapiAction
             $this->show_rss_timeline($notices, $title, $link, $subtitle);
             break;
          case 'atom':
-            $this->show_atom_timeline($notices, $title, $id, $link, $subtitle);
+            $selfuri = common_root_url() .
+                ltrim($_SERVER['QUERY_STRING'], 'p=');
+            $this->show_atom_timeline($notices, $title, $id, $link, $subtitle,
+                null, $selfuri);
             break;
          case 'json':
             $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 replies($args, $apidata)
+    {
+        call_user_func(array($this, 'mentions'), $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;
         }
 
@@ -415,7 +443,7 @@ 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']);
         }
 
     }
@@ -426,14 +454,14 @@ class TwitapistatusesAction extends TwitterapiAction
         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;
         }
 
@@ -443,14 +471,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();
 
@@ -460,7 +487,7 @@ 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']);
         }
 
     }
@@ -471,23 +498,32 @@ class TwitapistatusesAction extends TwitterapiAction
         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;
         }
 
@@ -500,7 +536,7 @@ class TwitapistatusesAction extends TwitterapiAction
         $profile = $user->getProfile();
 
         if (!$profile) {
-            common_server_error(_('User has no profile.'));
+            $this->serverError(_('User has no profile.'));
             return;
         }
 
@@ -515,7 +551,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();
 
@@ -530,7 +569,13 @@ 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);
     }
 
@@ -552,14 +597,36 @@ 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)
     {
         parent::handle($args);
-        common_server_error(_('API method under construction.'), $code=501);
+        $this->serverError(_('API method under construction.'), $code=501);
     }
 
     function supported($cmd)