Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions application/libraries/Twitteroauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ function get($url, $parameters = array()) {
/**
* POST wrapper for oAuthRequest.
*/
function post($url, $parameters = array()) {
$response = $this->oAuthRequest($url, 'POST', $parameters);
function post($url, $parameters = array(), $multipart = false) {
$response = $this->oAuthRequest($url, 'POST', $parameters, $multipart);
if ($this->format === 'json' && $this->decode_json) {
return json_decode($response);
}
Expand All @@ -174,17 +174,32 @@ function delete($url, $parameters = array()) {
/**
* Format and sign an OAuth / API request
*/
function oAuthRequest($url, $method, $parameters) {
if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
function oAuthRequest($url, $method, $parameters, $multipart = false) {
if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
$url = "{$this->host}{$url}.{$this->format}";
}
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);

$signature_parameters = array();
if ($multipart) {
// When making a multipart request, use only oauth_* -keys for signature
foreach ($parameters AS $key => $value) {
if (strpos($key, 'oauth_') !== 0) {
continue;
}
$signature_parameters[$key] = $value;
}
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $signature_parameters);
}
else {
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
}

$request->sign_request($this->sha1_method, $this->consumer, $this->token);
switch ($method) {
case 'GET':
return $this->http($request->to_url(), 'GET');
default:
return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
return $this->http($request->get_normalized_http_url(), $method, ($multipart ? $parameters : $request->to_postdata()), $request, $multipart);
}
}

Expand All @@ -193,15 +208,19 @@ function oAuthRequest($url, $method, $parameters) {
*
* @return API results
*/
function http($url, $method, $postfields = NULL) {
function http($url, $method, $postfields = NULL, OAuthRequest $request = NULL, $multipart = false) {
$this->http_info = array();
$ci = curl_init();
/* Curl settings */
curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
$headers = array('Expect:');
if ($multipart) {
$headers[] = $request->to_header();
}
curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
curl_setopt($ci, CURLOPT_HEADER, FALSE);
Expand Down