5 use Friendica\Core\System;
8 * A Twitter library in PHP.
12 * @author J.M. <me@mynetx.net>
13 * @copyright 2010-2013 J.M. <me@mynetx.net>
15 * Modified for statusnet by Michael Vogel <heluecht@pirati.ca>
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 $constants = explode(' ', 'OBJECT ARRAY JSON');
35 foreach ($constants as $i => $id) {
36 $id = 'CODEBIRD_RETURNFORMAT_' . $id;
37 defined($id) or define($id, $i);
40 'CURLE_SSL_CERTPROBLEM' => 58,
41 'CURLE_SSL_CACERT' => 60,
42 'CURLE_SSL_CACERT_BADFILE' => 77,
43 'CURLE_SSL_CRL_BADFILE' => 82,
44 'CURLE_SSL_ISSUER_ERROR' => 83
46 foreach ($constants as $id => $i) {
47 defined($id) or define($id, $i);
54 * A Twitter library in PHP.
57 * @subpackage codebird-php
62 * The current singleton instance
64 private static $_instance = null;
67 * The OAuth consumer key of your registered app
69 protected static $_oauth_consumer_key = null;
72 * The corresponding consumer secret
74 protected static $_oauth_consumer_secret = null;
77 * The app-only bearer token. Used to authorize app-only requests
79 protected static $_oauth_bearer_token = null;
82 * The API endpoint to use
84 protected static $_endpoint = 'https://api.twitter.com/1.1/';
87 * The API endpoint to use for OAuth requests
89 protected static $_endpoint_oauth = 'https://api.twitter.com/';
92 * The Request or access token. Used to sign requests
94 protected $_oauth_token = null;
97 * The corresponding request or access token secret
99 protected $_oauth_token_secret = null;
102 * The format of data to return from API calls
104 protected $_return_format = CODEBIRD_RETURNFORMAT_OBJECT;
107 * The file formats that Twitter accepts as image uploads
109 protected $_supported_media_files = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG);
112 * The current Codebird version
114 protected $_version = '2.4.1';
117 * Returns singleton class instance
118 * Always use this method unless you're working with multiple authenticated users at once
120 * @return Codebird The instance
122 public static function getInstance()
124 if (self::$_instance == null) {
125 self::$_instance = new self;
127 return self::$_instance;
131 * Sets the API endpoint
133 * @param string $api API endpoint
137 public static function setAPIEndpoint($api)
139 self::$_endpoint_oauth = $api;
140 self::$_endpoint = $api;
144 * Sets the OAuth consumer key and secret (App key)
146 * @param string $key OAuth consumer key
147 * @param string $secret OAuth consumer secret
151 public static function setConsumerKey($key, $secret)
153 self::$_oauth_consumer_key = $key;
154 self::$_oauth_consumer_secret = $secret;
158 * Sets the OAuth2 app-only auth bearer token
160 * @param string $token OAuth2 bearer token
164 public static function setBearerToken($token)
166 self::$_oauth_bearer_token = $token;
170 * Gets the current Codebird version
172 * @return string The version number
174 public function getVersion()
176 return $this->_version;
180 * Sets the OAuth request or access token and secret (User key)
182 * @param string $token OAuth request or access token
183 * @param string $secret OAuth request or access token secret
187 public function setToken($token, $secret)
189 $this->_oauth_token = $token;
190 $this->_oauth_token_secret = $secret;
194 * Sets the format for API replies
196 * @param int $return_format One of these:
197 * CODEBIRD_RETURNFORMAT_OBJECT (default)
198 * CODEBIRD_RETURNFORMAT_ARRAY
202 public function setReturnFormat($return_format)
204 $this->_return_format = $return_format;
208 * Main API handler working on any requests you issue
210 * @param string $fn The member function you called
211 * @param array $params The parameters you sent along
213 * @return mixed The API reply encoded in the set return_format
216 public function __call($fn, $params)
219 $apiparams = array();
220 if (count($params) > 0) {
221 if (is_array($params[0])) {
222 $apiparams = $params[0];
224 parse_str($params[0], $apiparams);
225 // remove auto-added slashes if on magic quotes steroids
226 if (get_magic_quotes_gpc()) {
227 foreach($apiparams as $key => $value) {
228 if (is_array($value)) {
229 $apiparams[$key] = array_map('stripslashes', $value);
231 $apiparams[$key] = stripslashes($value);
238 // stringify null and boolean parameters
239 foreach ($apiparams as $key => $value) {
240 if (! is_scalar($value)) {
243 if (is_null($value)) {
244 $apiparams[$key] = 'null';
245 } elseif (is_bool($value)) {
246 $apiparams[$key] = $value ? 'true' : 'false';
250 $app_only_auth = false;
251 if (count($params) > 1) {
252 $app_only_auth = !! $params[1];
255 // map function name to API method
259 $path = explode('_', $fn);
260 for ($i = 0; $i < count($path); $i++) {
264 $method .= $path[$i];
266 // undo replacement for URL parameters
267 $url_parameters_with_underscore = array('screen_name');
268 foreach ($url_parameters_with_underscore as $param) {
269 $param = strtoupper($param);
270 $replacement_was = str_replace('_', '/', $param);
271 $method = str_replace($replacement_was, $param, $method);
274 // replace AA by URL parameters
275 $method_template = $method;
277 if (preg_match('/[A-Z_]{2,}/', $method, $match)) {
278 foreach ($match as $param) {
279 $param_l = strtolower($param);
280 $method_template = str_replace($param, ':' . $param_l, $method_template);
281 if (!isset($apiparams[$param_l])) {
282 for ($i = 0; $i < 26; $i++) {
283 $method_template = str_replace(chr(65 + $i), '_' . chr(97 + $i), $method_template);
285 throw new \Exception(
286 'To call the templated method "' . $method_template
287 . '", specify the parameter value for "' . $param_l . '".'
290 $method = str_replace($param, $apiparams[$param_l], $method);
291 unset($apiparams[$param_l]);
295 // replace A-Z by _a-z
296 for ($i = 0; $i < 26; $i++) {
297 $method = str_replace(chr(65 + $i), '_' . chr(97 + $i), $method);
298 $method_template = str_replace(chr(65 + $i), '_' . chr(97 + $i), $method_template);
301 $httpmethod = $this->_detectMethod($method_template, $apiparams);
302 $multipart = $this->_detectMultipart($method_template);
303 return $this->_callApi(
314 * Uncommon API methods
318 * Gets the OAuth authenticate URL for the current request token
320 * @return string The OAuth authenticate URL
322 public function oauth_authenticate($force_login = NULL, $screen_name = NULL)
324 if ($this->_oauth_token == null) {
325 throw new \Exception('To get the authenticate URL, the OAuth token must be set.');
327 $url = self::$_endpoint_oauth . 'oauth/authenticate?oauth_token=' . $this->_url($this->_oauth_token);
329 $url .= "&force_login=1";
332 $url .= "&screen_name=" . $screen_name;
338 * Gets the OAuth authorize URL for the current request token
340 * @return string The OAuth authorize URL
342 public function oauth_authorize($force_login = NULL, $screen_name = NULL)
344 if ($this->_oauth_token == null) {
345 throw new \Exception('To get the authorize URL, the OAuth token must be set.');
347 $url = self::$_endpoint_oauth . 'oauth/authorize?oauth_token=' . $this->_url($this->_oauth_token);
349 $url .= "&force_login=1";
352 $url .= "&screen_name=" . $screen_name;
358 * Gets the OAuth bearer token
360 * @return string The OAuth bearer token
363 public function oauth2_token()
365 if (! function_exists('curl_init')) {
366 throw new \Exception('To make API requests, the PHP curl extension must be available.');
368 if (self::$_oauth_consumer_key == null) {
369 throw new \Exception('To obtain a bearer token, the consumer key must be set.');
372 $post_fields = array(
373 'grant_type' => 'client_credentials'
375 $url = self::$_endpoint_oauth . 'oauth2/token';
376 $ch = curl_init($url);
377 curl_setopt($ch, CURLOPT_POST, 1);
378 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
379 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
380 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
381 curl_setopt($ch, CURLOPT_HEADER, 1);
382 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
383 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
384 //curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/cacert.pem');
386 curl_setopt($ch, CURLOPT_USERPWD, self::$_oauth_consumer_key . ':' . self::$_oauth_consumer_secret);
387 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
390 $reply = curl_exec($ch);
392 // certificate validation results
393 //$validation_result = curl_errno($ch);
395 // $validation_result,
397 // CURLE_SSL_CERTPROBLEM,
399 // CURLE_SSL_CACERT_BADFILE,
400 // CURLE_SSL_CRL_BADFILE,
401 // CURLE_SSL_ISSUER_ERROR
405 // throw new \Exception('Error ' . $validation_result . ' while validating the Twitter API certificate.');
408 $httpstatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
409 $reply = $this->_parseApiReply('oauth2/token', $reply);
410 switch ($this->_return_format) {
411 case CODEBIRD_RETURNFORMAT_ARRAY:
412 $reply['httpstatus'] = $httpstatus;
413 if ($httpstatus == 200) {
414 self::setBearerToken($reply['access_token']);
417 case CODEBIRD_RETURNFORMAT_JSON:
418 if ($httpstatus == 200) {
419 $parsed = json_decode($reply);
420 self::setBearerToken($parsed->access_token);
423 case CODEBIRD_RETURNFORMAT_OBJECT:
424 $reply->httpstatus = $httpstatus;
425 if ($httpstatus == 200) {
426 self::setBearerToken($reply->access_token);
438 * URL-encodes the given data
442 * @return mixed The encoded data
444 private function _url($data)
446 if (is_array($data)) {
447 return array_map(array(
451 } elseif (is_scalar($data)) {
452 return str_replace(array(
466 ), rawurlencode($data));
473 * Gets the base64-encoded SHA1 hash for the given data
475 * @param string $data The data to calculate the hash from
477 * @return string The hash
479 private function _sha1($data)
481 if (self::$_oauth_consumer_secret == null) {
482 throw new \Exception('To generate a hash, the consumer secret must be set.');
484 if (!function_exists('hash_hmac')) {
485 throw new \Exception('To generate a hash, the PHP hash extension must be available.');
487 return base64_encode(hash_hmac('sha1', $data, self::$_oauth_consumer_secret . '&'
488 . ($this->_oauth_token_secret != null ? $this->_oauth_token_secret : ''), true));
492 * Generates a (hopefully) unique random string
494 * @param int optional $length The length of the string to generate
496 * @return string The random string
498 protected function _nonce($length = 8)
501 throw new \Exception('Invalid nonce length.');
503 return substr(md5(microtime(true)), 0, $length);
507 * Generates an OAuth signature
509 * @param string $httpmethod Usually either 'GET' or 'POST' or 'DELETE'
510 * @param string $method The API method to call
511 * @param array optional $params The API call parameters, associative
513 * @return string Authorization HTTP header
515 protected function _sign($httpmethod, $method, $params = array())
517 if (self::$_oauth_consumer_key == null) {
518 throw new \Exception('To generate a signature, the consumer key must be set.');
520 $sign_params = array(
521 'consumer_key' => self::$_oauth_consumer_key,
523 'timestamp' => time(),
524 'nonce' => $this->_nonce(),
525 'signature_method' => 'HMAC-SHA1'
527 $sign_base_params = array();
528 foreach ($sign_params as $key => $value) {
529 $sign_base_params['oauth_' . $key] = $this->_url($value);
531 if ($this->_oauth_token != null) {
532 $sign_base_params['oauth_token'] = $this->_url($this->_oauth_token);
534 $oauth_params = $sign_base_params;
535 foreach ($params as $key => $value) {
536 $sign_base_params[$key] = $this->_url($value);
538 ksort($sign_base_params);
539 $sign_base_string = '';
540 foreach ($sign_base_params as $key => $value) {
541 $sign_base_string .= $key . '=' . $value . '&';
543 $sign_base_string = substr($sign_base_string, 0, -1);
544 $signature = $this->_sha1($httpmethod . '&' . $this->_url($method) . '&' . $this->_url($sign_base_string));
546 $params = array_merge($oauth_params, array(
547 'oauth_signature' => $signature
550 $authorization = 'Authorization: OAuth ';
551 foreach ($params as $key => $value) {
552 $authorization .= $key . '="' . $this->_url($value) . '", ';
554 return substr($authorization, 0, -2);
558 * Detects HTTP method to use for API call
560 * @param string $method The API method to call
561 * @param array $params The parameters to send along
563 * @return string The HTTP method that should be used
565 protected function _detectMethod($method, $params)
567 // multi-HTTP method endpoints
569 case 'account/settings':
570 $method = count($params) > 0 ? $method . '__post' : $method;
574 $httpmethods = array();
575 $httpmethods['GET'] = array(
577 'statuses/mentions_timeline',
578 'statuses/user_timeline',
579 'statuses/home_timeline',
580 'statuses/retweets_of_me',
583 'statuses/retweets/:id',
592 'direct_messages/sent',
593 'direct_messages/show',
595 // Friends & Followers
596 'friendships/no_retweets/ids',
599 'friendships/lookup',
600 'friendships/incoming',
601 'friendships/outgoing',
608 'account/verify_credentials',
614 'users/contributees',
615 'users/contributors',
616 'users/profile_banner',
619 'users/suggestions/:slug',
621 'users/suggestions/:slug/members',
631 'lists/subscribers/show',
632 'lists/members/show',
635 'lists/subscriptions',
638 'saved_searches/list',
639 'saved_searches/show/:id',
643 'geo/reverse_geocode',
645 'geo/similar_places',
653 'oauth/authenticate',
657 'help/configuration',
661 'application/rate_limit_status'
663 $httpmethods['POST'] = array(
665 'statuses/destroy/:id',
667 'statuses/retweet/:id',
668 'statuses/update_with_media',
671 'statusnet/media/upload',
674 'direct_messages/destroy',
675 'direct_messages/new',
677 // Friends & Followers
678 'friendships/create',
679 'friendships/destroy',
680 'friendships/update',
683 'account/settings__post',
684 'account/update_delivery_device',
685 'account/update_profile',
686 'account/update_profile_background_image',
687 'account/update_profile_colors',
688 'account/update_profile_image',
691 'account/update_profile_banner',
692 'account/remove_profile_banner',
699 'lists/members/destroy',
700 'lists/subscribers/create',
701 'lists/subscribers/destroy',
702 'lists/members/create_all',
703 'lists/members/create',
707 'lists/members/destroy_all',
710 'saved_searches/create',
711 'saved_searches/destroy/:id',
720 'oauth/access_token',
721 'oauth/request_token',
723 'oauth2/invalidate_token'
725 foreach ($httpmethods as $httpmethod => $methods) {
726 if (in_array($method, $methods)) {
730 throw new \Exception('Can\'t find HTTP method to use for "' . $method . '".');
734 * Detects if API call should use multipart/form-data
736 * @param string $method The API method to call
738 * @return bool Whether the method should be sent as multipart
740 protected function _detectMultipart($method)
745 'statuses/update_with_media',
748 'statusnet/media/upload',
751 'account/update_profile_background_image',
752 'account/update_profile_image',
753 'account/update_profile_banner'
755 return in_array($method, $multiparts);
759 * Detect filenames in upload parameters,
760 * build multipart request from upload params
762 * @param string $method The API method to call
763 * @param array $params The parameters to send along
767 protected function _buildMultipart($method, $params)
769 // well, files will only work in multipart methods
770 if (! $this->_detectMultipart($method)) {
774 // only check specific parameters
775 $possible_files = array(
777 'statuses/update' => 'media[]',
778 'statuses/update_with_media' => 'media[]',
780 'account/update_profile_background_image' => 'image',
781 'account/update_profile_image' => 'image',
782 'account/update_profile_banner' => 'banner'
784 // method might have files?
785 if (! in_array($method, array_keys($possible_files))) {
789 $possible_files = explode(' ', $possible_files[$method]);
791 $multipart_border = '--------------------' . $this->_nonce();
792 $multipart_request = '';
793 foreach ($params as $key => $value) {
795 if (is_array($value)) {
796 throw new \Exception('Using URL-encoded parameters is not supported for uploading media.');
800 // check for filenames
801 if (in_array($key, $possible_files)) {
802 if (// is it a file, a readable one?
804 && @is_readable($value)
806 // is it a valid image?
807 && $data = @getimagesize($value)
809 if (// is it a supported image format?
810 in_array($data[2], $this->_supported_media_files)
812 // try to read the file
815 $data = ob_get_contents();
817 if (strlen($data) == 0) {
825 $tempfile = tempnam(System::getTempPath(), "mimecheck");
826 file_put_contents($tempfile, $data);
827 $mime = image_type_to_mime_type(exif_imagetype($tempfile));
829 $filename = "upload";
830 $parametername = str_replace("[]", "", $key);
832 $multipart_request .= "--".$multipart_border."\n";
833 $multipart_request .= "Content-Disposition: form-data; name=\"{$parametername}\"; filename=\"{$filename}\"\n";
834 $multipart_request .= "Content-Type: ".$mime."\n";
835 $multipart_request .= "Content-Transfer-Encoding: binary\n\n";
836 $multipart_request .= $data."\n";
839 $multipart_request .=
840 '--' . $multipart_border . "\r\n"
841 . 'Content-Disposition: form-data; name="' . $key . '"';
843 $multipart_request .=
844 "\r\n\r\n" . $value . "\r\n";
847 $multipart_request .= '--' . $multipart_border . '--';
849 return $multipart_request;
854 * Builds the complete API endpoint url
856 * @param string $method The API method to call
857 * @param string $method_template The API method template to call
859 * @return string The URL to send the request to
861 protected function _getEndpoint($method, $method_template)
863 if (substr($method, 0, 5) == 'oauth') {
864 $url = self::$_endpoint_oauth . $method;
866 $url = self::$_endpoint . $method . '.json';
872 * Calls the API using cURL
874 * @param string $httpmethod The HTTP method to use for making the request
875 * @param string $method The API method to call
876 * @param string $method_template The templated API method to call
877 * @param array optional $params The parameters to send along
878 * @param bool optional $multipart Whether to use multipart/form-data
879 * @param bool optional $app_only_auth Whether to use app-only bearer authentication
881 * @return mixed The API reply, encoded in the set return_format
884 protected function _callApi($httpmethod, $method, $method_template, $params = array(), $multipart = false, $app_only_auth = false)
886 if (! function_exists('curl_init')) {
887 throw new \Exception('To make API requests, the PHP curl extension must be available.');
889 $url = $this->_getEndpoint($method, $method_template);
891 if ($httpmethod == 'GET') {
892 $url_with_params = $url;
893 if (count($params) > 0) {
894 $url_with_params .= '?' . http_build_query($params);
896 $authorization = $this->_sign($httpmethod, $url, $params);
897 $ch = curl_init($url_with_params);
900 $authorization = $this->_sign($httpmethod, $url, array());
901 $params = $this->_buildMultipart($method_template, $params);
903 $authorization = $this->_sign($httpmethod, $url, $params);
904 $params = http_build_query($params);
906 $ch = curl_init($url);
907 curl_setopt($ch, CURLOPT_POST, 1);
908 curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
910 if ($app_only_auth) {
911 if (self::$_oauth_consumer_key == null) {
912 throw new \Exception('To make an app-only auth API request, the consumer key must be set.');
914 // automatically fetch bearer token, if necessary
915 if (self::$_oauth_bearer_token == null) {
916 $this->oauth2_token();
918 $authorization = 'Authorization: Bearer ' . self::$_oauth_bearer_token;
920 $request_headers = array();
921 if (isset($authorization)) {
922 $request_headers[] = $authorization;
923 $request_headers[] = 'Expect:';
926 $first_newline = strpos($params, "\r\n");
927 $multipart_boundary = substr($params, 2, $first_newline - 2);
928 $request_headers[] = 'Content-Length: ' . strlen($params);
929 $request_headers[] = 'Content-Type: multipart/form-data; boundary='
930 . $multipart_boundary;
933 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
934 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
935 curl_setopt($ch, CURLOPT_HEADER, 1);
936 curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
937 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
938 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
939 //curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/cacert.pem');
941 $reply = curl_exec($ch);
943 // certificate validation results
944 //$validation_result = curl_errno($ch);
946 // $validation_result,
948 // CURLE_SSL_CERTPROBLEM,
950 // CURLE_SSL_CACERT_BADFILE,
951 // CURLE_SSL_CRL_BADFILE,
952 // CURLE_SSL_ISSUER_ERROR
956 // throw new \Exception('Error ' . $validation_result . ' while validating the Twitter API certificate.');
959 $httpstatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
960 $reply = $this->_parseApiReply($method_template, $reply);
961 if ($this->_return_format == CODEBIRD_RETURNFORMAT_OBJECT) {
962 $reply->httpstatus = $httpstatus;
963 } elseif ($this->_return_format == CODEBIRD_RETURNFORMAT_ARRAY) {
964 $reply['httpstatus'] = $httpstatus;
970 * Parses the API reply to encode it in the set return_format
972 * @param string $method The method that has been called
973 * @param string $reply The actual reply, JSON-encoded or URL-encoded
975 * @return array|object The parsed reply
977 protected function _parseApiReply($method, $reply)
979 // split headers and body
981 $reply = explode("\r\n\r\n", $reply, 4);
983 // check if using proxy
984 if (substr($reply[0], 0, 35) === 'HTTP/1.1 200 Connection Established') {
986 } elseif (count($reply) > 2) {
987 $headers = array_shift($reply);
990 implode("\r\n", $reply)
994 $headers_array = explode("\r\n", $reply[0]);
995 foreach ($headers_array as $header) {
996 $header_array = explode(': ', $header, 2);
997 $key = $header_array[0];
999 if (count($header_array) > 1) {
1000 $value = $header_array[1];
1002 $headers[$key] = $value;
1004 if (count($reply) > 1) {
1010 $need_array = $this->_return_format == CODEBIRD_RETURNFORMAT_ARRAY;
1011 if ($reply == '[]') {
1012 switch ($this->_return_format) {
1013 case CODEBIRD_RETURNFORMAT_ARRAY:
1015 case CODEBIRD_RETURNFORMAT_JSON:
1017 case CODEBIRD_RETURNFORMAT_OBJECT:
1018 return new \stdClass;
1022 if (! $parsed = json_decode($reply, $need_array)) {
1024 if (stripos($reply, '<' . '?xml version="1.0" encoding="UTF-8"?' . '>') === 0) {
1025 // we received XML...
1026 // since this only happens for errors,
1027 // don't perform a full decoding
1028 preg_match('/<request>(.*)<\/request>/', $reply, $request);
1029 preg_match('/<error>(.*)<\/error>/', $reply, $error);
1030 $parsed['request'] = htmlspecialchars_decode($request[1]);
1031 $parsed['error'] = htmlspecialchars_decode($error[1]);
1033 // assume query format
1034 $reply = explode('&', $reply);
1035 foreach ($reply as $element) {
1036 if (stristr($element, '=')) {
1037 list($key, $value) = explode('=', $element);
1038 $parsed[$key] = $value;
1040 $parsed['message'] = $element;
1045 $reply = json_encode($parsed);
1047 switch ($this->_return_format) {
1048 case CODEBIRD_RETURNFORMAT_ARRAY:
1050 case CODEBIRD_RETURNFORMAT_JSON:
1052 case CODEBIRD_RETURNFORMAT_OBJECT:
1053 return (object) $parsed;