# XXX: sub-optimal performance
- $notice->is_local = 1;
+ if (common_config('public', 'localonly')) {
+ $notice->is_local = 1;
+ }
+
$notice->orderBy('created DESC, notice.id DESC');
$notice->limit($MAX_PUBSTATUSES);
$cnt = $notice->find();
$this->show_json_timeline($notice);
break;
default:
- common_user_error("API method not found!", $code = 404);
+ common_user_error(_('API method not found!'), $code = 404);
break;
}
} else {
- common_server_error('Couldn\'t find any statuses.', $code = 503);
+ common_server_error(_('Couldn\'t find any statuses.'), $code = 503);
}
exit();
$this->show_json_timeline($notice);
break;
default:
- common_user_error("API method not found!", $code = 404);
+ common_user_error(_('API method not found!'), $code = 404);
}
exit();
$this->show_json_timeline($notice);
break;
default:
- common_user_error("API method not found!", $code = 404);
+ common_user_error(_('API method not found!'), $code = 404);
}
exit();
parent::handle($args);
- $user = $apidata['user'];
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
+ exit();
+ }
- $status = htmlspecialchars_decode($this->trimmed('status'));
+ $user = $apidata['user'];
+ $status = $this->trimmed('status');
$source = $this->trimmed('source');
+ $in_reply_to_status_id = intval($this->trimmed('in_reply_to_status_id'));
if (!$source) {
$source = 'api';
// errror? -- Zach
exit();
- } else if (strlen($status) > 140) {
+ } else if (mb_strlen($status) > 140) {
// XXX: Twitter truncates anything over 140, flags the status
// as "truncated." Sending this error may screw up some clients
// that assume Twitter will truncate for them. Should we just
// truncate too? -- Zach
- header('HTTP/1.1 406 Not Acceptable');
- print "That's too long. Max notice size is 140 chars.\n";
+ $this->client_error(_('That\'s too long. Max notice size is 140 chars.'), $code = 406, $apidata['content-type']);
exit();
}
- $notice = Notice::saveNew($user->id, $status, $source);
+ $reply_to = NULL;
+
+ if ($in_reply_to_status_id) {
+
+ // check whether notice actually exists
+ $reply = Notice::staticGet($in_reply_to_status_id);
+
+ if ($reply) {
+ $reply_to = $in_reply_to_status_id;
+ } else {
+ $this->client_error(_('Not found'), $code = 404, $apidata['content-type']);
+ exit();
+ }
+ }
+
+ $notice = Notice::saveNew($user->id, $status, $source, 1, $reply_to);
if (is_string($notice)) {
$this->server_error($notice);
- return;
+ exit();
}
common_broadcast_notice($notice);
$this->show_json_timeline($notices);
break;
default:
- common_user_error("API method not found!", $code = 404);
+ common_user_error(_('API method not found!'), $code = 404);
}
}
+ function show($args, $apidata) {
+ parent::handle($args);
+
+ $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']);
+ }
+
+ exit();
+ }
/*
*/
function destroy($args, $apidata) {
+
parent::handle($args);
- common_server_error("API method under construction.", $code=501);
+
+ common_debug($_SERVER['REQUEST_METHOD']);
+
+ // 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']);
+ exit();
+ }
+
+ $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']);
+ exit();
+ }
+
+ 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']);
+ }
+
+ exit();
}
# User Methods
*/
function featured($args, $apidata) {
parent::handle($args);
- common_server_error("API method under construction.", $code=501);
+ common_server_error(_('API method under construction.'), $code=501);
}
function get_user($id, $apidata) {
}
}
-