summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/twitapiaccount.php2
-rw-r--r--actions/twitapifriendships.php21
-rw-r--r--actions/twitapihelp.php6
-rw-r--r--actions/twitapistatuses.php23
-rw-r--r--lib/twitterapi.php24
5 files changed, 39 insertions, 37 deletions
diff --git a/actions/twitapiaccount.php b/actions/twitapiaccount.php
index 3a0fd8544..3a66e8885 100644
--- a/actions/twitapiaccount.php
+++ b/actions/twitapiaccount.php
@@ -51,7 +51,7 @@ class TwitapiaccountAction extends TwitterapiAction {
if (!is_null($location) && strlen($location) > 255) {
- // XXX: Twitter just truncates and runs with it.
+ // XXX: But Twitter just truncates and runs with it. -- Zach
header('HTTP/1.1 406 Not Acceptable');
print "That's too long. Max notice size is 255 chars.\n";
exit();
diff --git a/actions/twitapifriendships.php b/actions/twitapifriendships.php
index 90e890e35..19617a071 100644
--- a/actions/twitapifriendships.php
+++ b/actions/twitapifriendships.php
@@ -33,7 +33,6 @@ class TwitapifriendshipsAction extends TwitterapiAction {
if (!$other) {
$this->client_error(_('Could not follow user: User not found.'), 403, $apidata['content-type']);
exit();
- return;
}
$user = $apidata['user'];
@@ -41,7 +40,6 @@ class TwitapifriendshipsAction extends TwitterapiAction {
if ($user->isSubscribed($other)) {
$this->client_error("Could not follow user: $other->nickname is already on your list.", 403, $apidata['content-type']);
exit();
- return;
}
$sub = new Subscription();
@@ -57,7 +55,6 @@ class TwitapifriendshipsAction extends TwitterapiAction {
if (!$result) {
$this->client_error("Could not follow user: $other->nickname.", 400, $apidata['content-type']);
exit();
- return;
}
$sub->query('COMMIT');
@@ -66,7 +63,7 @@ class TwitapifriendshipsAction extends TwitterapiAction {
$type = $apidata['content-type'];
$this->init_document($type);
- $this->show_profile($other);
+ $this->show_profile($other, $type);
$this->end_document($type);
exit();
}
@@ -106,8 +103,8 @@ class TwitapifriendshipsAction extends TwitterapiAction {
}
$type = $apidata['content-type'];
- $this->init_document($type);
- $this->show_profile($other);
+ $this->init_document($type);
+ $this->show_profile($other, $type);
$this->end_document($type);
exit();
}
@@ -135,10 +132,6 @@ class TwitapifriendshipsAction extends TwitterapiAction {
$user_a = $this->get_profile($user_a_id);
$user_b = $this->get_profile($user_b_id);
- if($user_a) { print "got user a profile";}
- if($user_b) { print "got user b profile";}
-
-
if (!$user_a || !$user_b) {
$this->client_error(_('Two user ids or screen_names must be supplied.'), 400, $apidata['content-type']);
exit();
@@ -152,15 +145,17 @@ class TwitapifriendshipsAction extends TwitterapiAction {
switch ($apidata['content-type']) {
case 'xml':
- common_start_xml();
+ $this->init_document('xml');
common_element('friends', NULL, $result);
- common_end_xml();
+ $this->end_document('xml');
break;
case 'json':
+ $this->init_document('json');
print json_encode($result);
+ $this->end_document('json');
break;
default:
- print $result;
+ print $result; // Really? --Zach
break;
}
diff --git a/actions/twitapihelp.php b/actions/twitapihelp.php
index 5a35d8442..9701913f1 100644
--- a/actions/twitapihelp.php
+++ b/actions/twitapihelp.php
@@ -30,13 +30,15 @@ class TwitapihelpAction extends TwitterapiAction {
function test($args, $apidata) {
global $xw;
if ($apidata['content-type'] == 'xml') {
- header('Content-Type: application/xml; charset=utf-8');
+ $this->init_document('xml');
common_start_xml();
common_element('ok', NULL, 'true');
common_end_xml();
+ $this->end_document('xml');
} elseif ($apidata['content-type'] == 'json') {
- header('Content-Type: application/json; charset=utf-8');
+ $this->init_document('json');
print '"ok"';
+ $this->end_document('json');
} else {
common_user_error("API method not found!", $code=404);
}
diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php
index d770d6ff3..670aaebf0 100644
--- a/actions/twitapistatuses.php
+++ b/actions/twitapistatuses.php
@@ -80,8 +80,7 @@ class TwitapistatusesAction extends TwitterapiAction {
function show_xml_timeline($notice) {
- header('Content-Type: application/xml; charset=utf-8');
- common_start_xml();
+ $this->init_document('xml');
common_element_start('statuses', array('type' => 'array'));
if (is_array($notice)) {
@@ -97,14 +96,12 @@ class TwitapistatusesAction extends TwitterapiAction {
}
common_element_end('statuses');
- common_end_xml();
+ $this->end_document('xml');
}
function show_rss_timeline($notice, $title, $id, $link, $subtitle) {
- header("Content-Type: application/rss+xml; charset=utf-8");
-
- $this->init_twitter_rss();
+ $this->init_document('rss');
common_element_start('channel');
common_element('title', NULL, $title);
@@ -127,14 +124,12 @@ class TwitapistatusesAction extends TwitterapiAction {
}
common_element_end('channel');
- $this->end_twitter_rss();
+ $this->end_twitter_rss();
}
function show_atom_timeline($notice, $title, $id, $link, $subtitle=NULL) {
- header('Content-Type: application/atom+xml; charset=utf-8');
-
- $this->init_twitter_atom();
+ $this->init_document('atom');
common_element('title', NULL, $title);
common_element('id', NULL, $id);
@@ -153,12 +148,13 @@ class TwitapistatusesAction extends TwitterapiAction {
}
}
- $this->end_twitter_atom();
+ $this->end_document('atom');
+
}
function show_json_timeline($notice) {
- header('Content-Type: application/json; charset=utf-8');
+ $this->init_document('json');
$statuses = array();
@@ -175,6 +171,8 @@ class TwitapistatusesAction extends TwitterapiAction {
}
$this->show_twitter_json_statuses($statuses);
+
+ $this->end_document('json');
}
/*
@@ -449,6 +447,7 @@ class TwitapistatusesAction extends TwitterapiAction {
ID. Ex: http://server/api/statuses/replies.xml?since_id=12345
*/
function replies($args, $apidata) {
+
parent::handle($args);
$since = $this->arg('since');
diff --git a/lib/twitterapi.php b/lib/twitterapi.php
index 12416bc36..d27152cbc 100644
--- a/lib/twitterapi.php
+++ b/lib/twitterapi.php
@@ -98,7 +98,7 @@ class TwitterapiAction extends Action {
return $entry;
}
- function show_twitter_xml_status($twitter_status) {
+ function show_twitter_xml_status($twitter_status) {
common_element_start('status');
common_element('created_at', NULL, $twitter_status['created_at']);
common_element('id', NULL, $twitter_status['id']);
@@ -183,18 +183,18 @@ class TwitterapiAction extends Action {
}
function show_single_xml_status($notice) {
- header('Content-Type: application/xml; charset=utf-8');
- common_start_xml();
+ $this->init_document('xml');
$twitter_status = $this->twitter_status_array($notice);
$this->show_twitter_xml_status($twitter_status);
- common_end_xml();
+ $this->end_document('xml');
exit();
}
function show_single_json_status($notice) {
- header('Content-Type: application/json; charset=utf-8');
+ $this->init_document('json');
$status = $this->twitter_status_array($notice);
$this->show_twitter_json_statuses($status);
+ $this->end_document('json');
exit();
}
@@ -260,6 +260,8 @@ class TwitterapiAction extends Action {
$this->client_error(_('Unsupported type'));
break;
}
+
+ return;
}
function end_document($type='xml') {
@@ -279,6 +281,7 @@ class TwitterapiAction extends Action {
$this->client_error(_('Unsupported type'));
break;
}
+ return;
}
function client_error($msg, $code = 400, $content_type = 'json') {
@@ -314,15 +317,17 @@ class TwitterapiAction extends Action {
header('HTTP/1.1 '.$code.' '.$status_string);
if ($content_type == 'xml') {
- common_start_xml();
+ $this->init_document('xml');
common_element_start('hash');
common_element('error', NULL, $msg);
common_element('request', NULL, $_SERVER['REQUEST_URI']);
common_element_end('hash');
- common_end_xml();
+ $this->end_document('xml');
} else {
+ $this->init_document('json');
$error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
- print(json_encode($error_array));
+ print(json_encode($error_array));
+ $this->end_document('json');
}
exit();
@@ -348,7 +353,7 @@ class TwitterapiAction extends Action {
common_element_end('feed');
}
- function show_profile($profile, $content_type='xml', $notice=NULL) {
+ function show_profile($profile, $content_type='xml', $notice=NULL) {
$profile_array = $this->twitter_user_array($profile, true);
switch ($content_type) {
case 'xml':
@@ -361,5 +366,6 @@ class TwitterapiAction extends Action {
$this->client_error(_('not a supported data format'));
return;
}
+ return;
}
} \ No newline at end of file