- $notice = $user->getReplies((($page-1)*20), $count, $since_id, $before_id);
- $notices = array();
-
- while ($notice->fetch()) {
- $notices[] = clone($notice);
- }
-
- switch($apidata['content-type']) {
- case 'xml':
- $this->show_xml_timeline($notices);
- break;
- case 'rss':
- $this->show_rss_timeline($notices, $title, $id, $link, $subtitle);
- break;
- case 'atom':
- $this->show_atom_timeline($notices, $title, $id, $link, $subtitle);
- break;
- case 'json':
- $this->show_json_timeline($notices);
- break;
- default:
- common_user_error(_('API method not found!'), $code = 404);
- }
-
- }
-
- 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);
- return;
- }
-
- $notice_id = $apidata['api_arg'];
- $notice = Notice::staticGet($notice_id);
-
- if ($notice) {
- if ($apidata['content-type'] == 'xml') {
- $this->show_single_xml_status($notice);
- } elseif ($apidata['content-type'] == 'json') {
- $this->show_single_json_status($notice);
- }
- } 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']);
- }
-
- }
-
-
- /*
- Destroys the status specified by the required ID parameter. The authenticating user must be
- the author of the specified status.
-
- URL: http://server/api/statuses/destroy/id.format
-
- Formats: xml, json
-
- Parameters:
-
- * id. Required. The ID of the status to destroy. Ex:
- http://server/api/statuses/destroy/12345.json or
- http://server/api/statuses/destroy/23456.xml
-
- */
- 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);
- 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']);
- return;
- }
-
- $user = $apidata['user'];
- $notice_id = $apidata['api_arg'];
- $notice = Notice::staticGet($notice_id);
-
- if (!$notice) {
- $this->client_error(_('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();
-
- if ($apidata['content-type'] == 'xml') {
- $this->show_single_xml_status($notice);
- } elseif ($apidata['content-type'] == 'json') {
- $this->show_single_json_status($notice);
- }
- } else {
- $this->client_error(_('You may not delete another user\'s status.'), 403, $apidata['content-type']);
- }
-
- }
-
- # User Methods
-
- /*
- Returns up to 100 of the authenticating user's friends who have most recently updated, each with current status inline.
- It's also possible to request another user's recent friends list via the id parameter below.
-
- URL: http://server/api/statuses/friends.format
-
- Formats: xml, json
-
- Parameters:
-
- * id. Optional. The ID or screen name of the user for whom to request a list of friends. Ex:
- http://server/api/statuses/friends/12345.json
- or
- http://server/api/statuses/friends/bob.xml
- * page. Optional. Retrieves the next 100 friends. Ex: http://server/api/statuses/friends.xml?page=2
- * lite. Optional. Prevents the inline inclusion of current status. Must be set to a value of true. Ex:
- http://server/api/statuses/friends.xml?lite=true
- * since. Optional. Narrows the returned results to just those friendships created after the specified
- HTTP-formatted date. The same behavior is available by setting an If-Modified-Since header in your HTTP
- request. Ex: http://server/api/statuses/friends.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
- */
- function friends($args, $apidata) {
- parent::handle($args);
- return $this->subscriptions($apidata, 'subscribed', 'subscriber');
- }
-
- /*
- Returns the authenticating user's followers, each with current status inline. They are ordered by the
- order in which they joined Twitter (this is going to be changed).
-
- URL: http://server/api/statuses/followers.format
- Formats: xml, json
-
- Parameters:
-
- * id. Optional. The ID or screen name of the user for whom to request a list of followers. Ex:
- http://server/api/statuses/followers/12345.json
- or
- http://server/api/statuses/followers/bob.xml
- * page. Optional. Retrieves the next 100 followers. Ex: http://server/api/statuses/followers.xml?page=2
- * lite. Optional. Prevents the inline inclusion of current status. Must be set to a value of true.
- Ex: http://server/api/statuses/followers.xml?lite=true
- */
- function followers($args, $apidata) {
- parent::handle($args);
-
- return $this->subscriptions($apidata, 'subscriber', 'subscribed');
- }
-
- function subscriptions($apidata, $other_attr, $user_attr) {
-
- $user = $this->get_subs_user($apidata);
-
- # XXX: id
- # XXX: lite
-
- $page = $this->trimmed('page');
-
- if (!$page || !is_numeric($page)) {
- $page = 1;
- }
-
- $profile = $user->getProfile();
-
- if (!$profile) {
- common_server_error(_('User has no profile.'));
- return;
- }
-
- $sub = new Subscription();
- $sub->$user_attr = $profile->id;
- $sub->orderBy('created DESC');
- $sub->limit(($page-1)*100, 100);
-
- $others = array();
-
- if ($sub->find()) {
- while ($sub->fetch()) {
- $others[] = Profile::staticGet($sub->$other_attr);
- }
- } else {
- // user has no followers
- }
-
- $type = $apidata['content-type'];
-
- $this->init_document($type);
- $this->show_profiles($others, $type);
- $this->end_document($type);
- }
-
- function get_subs_user($apidata) {
-
- // function was called with an argument /statuses/user_timeline/api_arg.format
- if (isset($apidata['api_arg'])) {
-
- if (is_numeric($apidata['api_arg'])) {
- $user = User::staticGet($apidata['api_arg']);
- } else {
- $nickname = common_canonical_nickname($apidata['api_arg']);
- $user = User::staticGet('nickname', $nickname);
- }
- } else {
-
- // if no user was specified, then we'll use the authenticated user
- $user = $apidata['user'];
- }
-
- if (!$user) {
- // Set the user to be the auth user if asked-for can't be found
- // honestly! This is what Twitter does, I swear --Zach
- $user = $apidata['user'];
- }
-
- return $user;
- }
-
- function show_profiles($profiles, $type) {
- switch ($type) {
- case 'xml':
- common_element_start('users', array('type' => 'array'));
- foreach ($profiles as $profile) {
- $this->show_profile($profile);
- }
- common_element_end('users');
- break;
- case 'json':
- $arrays = array();
- foreach ($profiles as $profile) {
- $arrays[] = $this->twitter_user_array($profile, true);
- }
- print json_encode($arrays);
- break;
- default:
- $this->client_error(_('unsupported file type'));
- }
- }
-
- /*
- Returns a list of the users currently featured on the site with their current statuses inline.
- URL: http://server/api/statuses/featured.format
-
- Formats: xml, json
- */
- function featured($args, $apidata) {
- parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
- }
-
- function get_user($id, $apidata) {
- if (!$id) {
- return $apidata['user'];
- } else if (is_numeric($id)) {
- return User::staticGet($id);
- } else {
- return User::staticGet('nickname', $id);
- }
- }
-
- function supported($cmd) {
-
- $cmdlist = array('MessageCommand', 'SubCommand', 'UnsubCommand', 'FavCommand');
-
- if (in_array(get_class($cmd), $cmdlist)) {
- return true;
- }
-
- return false;
- }