]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Twitter-compatible API - JSONP callbacks for all methods emitting JSON
authorZach Copley <zach@controlyourself.ca>
Wed, 10 Sep 2008 02:50:13 +0000 (22:50 -0400)
committerZach Copley <zach@controlyourself.ca>
Wed, 10 Sep 2008 02:50:13 +0000 (22:50 -0400)
darcs-hash:20080910025013-7b5ce-95c8dd7eaf83e98e5ee0da5dee8ef07fe4ae5041.gz

lib/twitterapi.php

index 096dee2696060d1f25b7e32e2697a4065cecc233..184078299acc30aa2b510e7f63ea92ed1a3bcecf 100644 (file)
@@ -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();