From f192b9128c5d48c5d9579c20002b9ec6f9bf54f1 Mon Sep 17 00:00:00 2001 From: lwhitelock Date: Fri, 22 May 2015 15:45:07 +0100 Subject: [PATCH 1/2] Fix issue with PDF attachments There is an issue where the mime type of attachments it was always being set to application/x-www-form-urlencoded instead of what it should have been. See https://github.com/XeroAPI/XeroOAuth-PHP/issues/43#issuecomment-104675923 --- lib/XeroOAuth.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/XeroOAuth.php b/lib/XeroOAuth.php index ab6955a..579d5ca 100644 --- a/lib/XeroOAuth.php +++ b/lib/XeroOAuth.php @@ -301,12 +301,23 @@ private function curlit() { break; case 'PUT' : $fh = tmpfile(); - if ($this->format == "file") { - $put_body = $this->xml; - } else { - $put_body = $this->safe_encode ( $this->xml ); - $this->headers ['Content-Type'] = 'application/x-www-form-urlencoded'; - } + switch ($this->format) { + case "file" : + $put_body = $this->xml; + break; + case "pdf" : + $put_body = $this->xml; + $this->headers ['Content-Type'] = 'application/pdf'; + break; + case "json" : + $put_body = $this->xml; + $this->headers ['Content-Type'] = 'application/json'; + break; + default : + $put_body = $this->safe_encode ( $this->xml ); + $this->headers ['Content-Type'] = 'application/x-www-form-urlencoded'; + break; + } fwrite ( $fh, $put_body ); rewind ( $fh ); curl_setopt ( $c, CURLOPT_PUT, true ); From 10f42fe63ac1fa187d4b710a79a35f7c893e2896 Mon Sep 17 00:00:00 2001 From: lwhitelock Date: Mon, 1 Jun 2015 10:31:49 +0100 Subject: [PATCH 2/2] Fixed bug when a ? is used in the URL When setting an attachment to be viewable on-line requires ?IncludeOnline=true added to the URL. This fixes the first part of the problem with the URL not being formatted correctly. There is another problem I haven't been able to find yet with the signature not being correctly generated. See here for more info: https://github.com/XeroAPI/XeroOAuth-PHP/issues/43 --- lib/OAuthSimple.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/OAuthSimple.php b/lib/OAuthSimple.php index 00dc4af..614e633 100644 --- a/lib/OAuthSimple.php +++ b/lib/OAuthSimple.php @@ -262,10 +262,15 @@ function sign($args=array()) { $this->setParameters($args['parameters']); $normParams = $this->_normalizedParameters(); $this->_parameters['oauth_signature'] = $this->_generateSignature($normParams); + if (strpos($this->_path,'?') !== false) { + $returnURL = $this->_path . '&' . $this->_normalizedParameters('true'); + } else { + $returnURL = $this->_path . '?' . $this->_normalizedParameters('true'); + } return Array( 'parameters' => $this->_parameters, 'signature' => $this->_oauthEscape($this->_parameters['oauth_signature']), - 'signed_url' => $this->_path . '?' . $this->_normalizedParameters('true'), + 'signed_url' => $returnURL, 'header' => $this->getHeaderString(), 'sbs'=> $this->sbs ); @@ -466,4 +471,4 @@ function _generateSignature () { } } } -?> \ No newline at end of file +?>