Skip to content

Commit

Permalink
Support for for multipart requests to prevent deprecated warnings in …
Browse files Browse the repository at this point in the history
…PHP 5.5. (Issue #168). Props: shiki
  • Loading branch information
themattharris committed May 18, 2014
1 parent 00ed300 commit cdc1db2
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tmhOAuth.php
Expand Up @@ -303,9 +303,7 @@ private function prepare_url() {
* @return string the original or modified string, depending on the request and the input parameter
*/
private function multipart_escape($value) {
if (class_exists('CurlFile', false) && is_object($value) && $value instanceof CurlFile)
return $value;
if (! $this->request_settings['multipart'] || strpos($value, '@') !== 0)
if (!$this->request_settings['multipart'] || strpos($value, '@') !== 0)
return $value;

// see if the parameter is a file.
Expand Down Expand Up @@ -353,14 +351,24 @@ private function prepare_params() {
// Ref: Spec: 9.1.1 (1)
uksort($params, 'strcmp');

// set this now so we're not doing it on every parameter
$supports_curl_file = class_exists('CurlFile', false);

// encode params unless we're doing multipart
foreach ($params as $k => $v) {
$k = $this->request_settings['multipart'] ? $k : $this->safe_encode($k);

if (is_array($v))
$v = implode(',', $v);

$v = $this->request_settings['multipart'] ? $this->multipart_escape($v) : $this->safe_encode($v);
// we don't need to do the multipart escaping if we support curlfile
if ($supports_curl_file && ($v instanceof CurlFile)) {
// leave $v alone
} elseif ($this->request_settings['multipart']) {
$v = $this->multipart_escape($v);
} else {
$v = $this->safe_encode($v);
}

// split parameters for the basestring and authorization header, and recreate the oauth1 array
if ($doing_oauth1) {
Expand All @@ -375,7 +383,7 @@ private function prepare_params() {
}
$prepared[$k] = $v;

if (!is_object($v) || !class_exists('CurlFile', false) || !($v instanceof CurlFile))
if (!$this->request_settings['multipart'])
$prepared_pairs[] = "{$k}={$v}";
}

Expand All @@ -384,7 +392,7 @@ private function prepare_params() {
}

// setup params for GET/POST/PUT method handling
if (!empty($prepared_pairs)) {
if (!empty($prepared)) {
$content = implode('&', $prepared_pairs);

switch ($this->request_settings['method']) {
Expand Down

0 comments on commit cdc1db2

Please sign in to comment.