diff options
author | Zach Copley <zach@controlyourself.ca> | 2008-09-09 22:50:13 -0400 |
---|---|---|
committer | Zach Copley <zach@controlyourself.ca> | 2008-09-09 22:50:13 -0400 |
commit | 219927cb7924a33a4e73aabe78218c0dc22bfc0c (patch) | |
tree | ae90c2fe63c5be116935e6ff5fc4ec903f716456 /lib/twitterapi.php | |
parent | 6eb84f0f0362e0b804c4c39b429e3dc8ce27acc3 (diff) |
Twitter-compatible API - JSONP callbacks for all methods emitting JSON
darcs-hash:20080910025013-7b5ce-95c8dd7eaf83e98e5ee0da5dee8ef07fe4ae5041.gz
Diffstat (limited to 'lib/twitterapi.php')
-rw-r--r-- | lib/twitterapi.php | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 096dee269..184078299 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -208,11 +208,17 @@ class TwitterapiAction extends Action { function init_document($type='xml') { switch ($type) { case 'xml': - header('Content-Type: application/xml; charset=utf-8'); + header('Content-Type: application/xml; charset=utf-8'); common_start_xml(); break; case 'json': header('Content-Type: application/json; charset=utf-8'); + + // Check for JSON-P callback + $callback = $this->arg('callback'); + if ($callback) { + print $callback . '('; + } break; case 'rss': header("Content-Type: application/rss+xml; charset=utf-8"); @@ -226,16 +232,22 @@ class TwitterapiAction extends Action { $this->client_error(_('Not a supported data format.')); break; } - + return; } - + function end_document($type='xml') { switch ($type) { case 'xml': common_end_xml(); break; case 'json': + + // Check for JSON-P callback + $callback = $this->arg('callback'); + if ($callback) { + print ')'; + } break; case 'rss': $this->end_twitter_rss(); |