- $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;
- }
-
- $this->auth_user = $apidata['user'];
- $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']);
- }
-
- }
-
- 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;
- }
-
- $this->auth_user = $apidata['user'];
- $user = $this->auth_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']);
- }
-
- }
-
- function friends($args, $apidata) {
- parent::handle($args);
- return $this->subscriptions($apidata, 'subscribed', 'subscriber');
- }
-
- function followers($args, $apidata) {
- parent::handle($args);
-
- return $this->subscriptions($apidata, 'subscriber', 'subscribed');
- }
-
- function subscriptions($apidata, $other_attr, $user_attr) {
-
- # XXX: lite
-
- $this->auth_user = $apidate['user'];
- $user = $this->get_user($apidata['api_arg'], $apidata);
-
- if (!$user) {
- $this->client_error('Not Found', 404, $apidata['content-type']);
- return;
- }
-
- $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 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'));
- }
- }
-
- function featured($args, $apidata) {
- parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
- }
-
- function supported($cmd) {
-
- $cmdlist = array('MessageCommand', 'SubCommand', 'UnsubCommand', 'FavCommand', 'OnCommand', 'OffCommand');
-
- if (in_array(get_class($cmd), $cmdlist)) {
- return true;
- }
-
- return false;
- }