From 6364a05bdc8c32b7a61a36ca2aeb2f027cb3773e Mon Sep 17 00:00:00 2001 From: m Date: Tue, 14 Jul 2015 17:46:52 +0200 Subject: [PATCH 1/4] Set SSL to TLS v1.0 (4). PHP 5.3 --- src/Thybag/Auth/SharePointOnlineAuth.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Thybag/Auth/SharePointOnlineAuth.php b/src/Thybag/Auth/SharePointOnlineAuth.php index 9dc04fd..68aa3b4 100644 --- a/src/Thybag/Auth/SharePointOnlineAuth.php +++ b/src/Thybag/Auth/SharePointOnlineAuth.php @@ -32,7 +32,8 @@ public function __doRequest($request, $location, $action, $version, $one_way = f curl_setopt($curl, CURLOPT_POSTFIELDS, $request); curl_setopt($curl, CURLOPT_COOKIE, $this->authCookies); - curl_setopt($curl, CURLOPT_TIMEOUT, 10); + curl_setopt($curl, CURLOPT_SSLVERSION, 4); + curl_setopt($curl, CURLOPT_TIMEOUT, 100); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // Useful for debugging @@ -89,7 +90,7 @@ protected function configureAuthCookies($location) { // Send request and grab returned xml $result = $this->authCurl("https://login.microsoftonline.com/extSTS.srf", $xml); - + // Extract security token from XML $xml = new \DOMDocument(); $xml->loadXML($result); @@ -180,9 +181,9 @@ protected function authCurl($url, $payload, $header = false){ curl_setopt($ch,CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); + curl_setopt($ch, CURLOPT_SSLVERSION, 4); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_TIMEOUT, 100); if($header) curl_setopt($ch, CURLOPT_HEADER, true); From edca460a360e7463c936bca3d4f7703ed9d58632 Mon Sep 17 00:00:00 2001 From: m Date: Wed, 15 Jul 2015 18:01:03 +0200 Subject: [PATCH 2/4] Added CopyIntoItems --- src/Thybag/Auth/SharePointOnlineAuth.php | 3 + src/Thybag/SharePointAPI.php | 120 +++++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/src/Thybag/Auth/SharePointOnlineAuth.php b/src/Thybag/Auth/SharePointOnlineAuth.php index 68aa3b4..6fee459 100644 --- a/src/Thybag/Auth/SharePointOnlineAuth.php +++ b/src/Thybag/Auth/SharePointOnlineAuth.php @@ -46,6 +46,9 @@ public function __doRequest($request, $location, $action, $version, $one_way = f if( strpos($request, 'UpdateListItems') !== FALSE ) { $headers[] = 'SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"'; } + if( strpos($request, 'CopyIntoItems') !== FALSE ) { + $headers[] = 'SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems"'; + } // Add headers curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); diff --git a/src/Thybag/SharePointAPI.php b/src/Thybag/SharePointAPI.php index 6d22999..9c209dd 100644 --- a/src/Thybag/SharePointAPI.php +++ b/src/Thybag/SharePointAPI.php @@ -1127,4 +1127,124 @@ public function getColumnVersions ($list, $id, $field) { return $this->getFieldV public function getVersions ($list, $id, $field = null) { return $this->getFieldVersions($list, $id, $field); } + + + // params + public function copyIntoItems ($destinationUrl, $file_path, array $fields = null) { + // base64 encode file + + + $partes_ruta = pathinfo($file_path); + + $file_name = $partes_ruta['basename']; + $destinationUrl = $destinationUrl . $file_name; + + $attachment = base64_encode(file_get_contents($file_path)); + + // Wrap in CAML + $CAML = ' + '.$file_name.' + + '.$destinationUrl.' + '; + if($fields!=null && count($fields)>0) + { + $CAML .= ' '; + for ($i = 0; $i < count($fields); ++$i) { + $CAML .= ' $value) { + $CAML .= " ".$key."=\"".$value."\""; + + } + $CAML .= ' />'; + } + + + + $CAML .= ' '; + } + $CAML .= ' + ' . $attachment . ' + '; + + $xmlvar = new \SoapVar($CAML, XSD_ANYXML); + + /* + $xmlvar = ' + POST /_vti_bin/copy.asmx HTTP/1.1 + Host: madrilenaredgas.sharepoint.com + Content-Type: text/xml; charset=utf-8 + Content-Length: length + SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems" + + + + + + string + + string + string + + + + + + base64Binary + + + + '; + */ + + // Attempt to run operation + try { + return $this->soapClient->CopyIntoItems($xmlvar); + } catch (\SoapFault $fault) { + $this->onError($fault); + } + + // Return true on success + return null; + } + + public function getItem ($sourceUrl) { + + // Wrap in CAML + $CAML = ' + '.$sourceUrl.' + '; + + $xmlvar = new \SoapVar($CAML, XSD_ANYXML); + + + /* + $xmlvar = ' + POST /_vti_bin/copy.asmx HTTP/1.1 + Host: madrilena.sharepoint.com + Content-Type: text/xml; charset=utf-8 + Content-Length: length + SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/GetItem" + + + + + + string + + + + '; + */ + + // Attempt to run operation + try { + return $this->soapClient->GetItem($xmlvar); + } catch (\SoapFault $fault) { + $this->onError($fault); + } + + // Return true on success + return null; + } } \ No newline at end of file From 8d01a3b8d636db3199fe474f4d710b35716cfaa7 Mon Sep 17 00:00:00 2001 From: m Date: Thu, 16 Jul 2015 15:21:11 +0200 Subject: [PATCH 3/4] =?UTF-8?q?A=C3=B1adido=20Copy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Thybag/Auth/SharePointOnlineAuth.php | 3 ++ src/Thybag/SharePointAPI.php | 67 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/src/Thybag/Auth/SharePointOnlineAuth.php b/src/Thybag/Auth/SharePointOnlineAuth.php index 68aa3b4..6fee459 100644 --- a/src/Thybag/Auth/SharePointOnlineAuth.php +++ b/src/Thybag/Auth/SharePointOnlineAuth.php @@ -46,6 +46,9 @@ public function __doRequest($request, $location, $action, $version, $one_way = f if( strpos($request, 'UpdateListItems') !== FALSE ) { $headers[] = 'SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"'; } + if( strpos($request, 'CopyIntoItems') !== FALSE ) { + $headers[] = 'SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems"'; + } // Add headers curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); diff --git a/src/Thybag/SharePointAPI.php b/src/Thybag/SharePointAPI.php index 6d22999..ae7eade 100644 --- a/src/Thybag/SharePointAPI.php +++ b/src/Thybag/SharePointAPI.php @@ -1127,4 +1127,71 @@ public function getColumnVersions ($list, $id, $field) { return $this->getFieldV public function getVersions ($list, $id, $field = null) { return $this->getFieldVersions($list, $id, $field); } + + + public function copyIntoItems ($destinationUrl, $file_path, array $fields = null) { + // base64 encode file + $file_info = pathinfo($file_path); + + $file_name = $file_info['basename']; + $destinationUrl = $destinationUrl . $file_name; + + $attachment = base64_encode(file_get_contents($file_path)); + + // Wrap in CAML + $CAML = ' + '.$file_name.' + + '.$destinationUrl.' + '; + if($fields!=null && count($fields)>0) + { + $CAML .= ' '; + for ($i = 0; $i < count($fields); ++$i) { + $CAML .= ' $value) { + $CAML .= " ".$key."=\"".$value."\""; + + } + $CAML .= ' />'; + } + + $CAML .= ' '; + } + $CAML .= ' + ' . $attachment . ' + '; + + $xmlvar = new \SoapVar($CAML, XSD_ANYXML); + + // Attempt to run operation + try { + return $this->soapClient->CopyIntoItems($xmlvar); + } catch (\SoapFault $fault) { + $this->onError($fault); + } + + // Return true on success + return null; + } + + public function getItem ($sourceUrl) { + + // Wrap in CAML + $CAML = ' + '.$sourceUrl.' + '; + + $xmlvar = new \SoapVar($CAML, XSD_ANYXML); + + // Attempt to run operation + try { + return $this->soapClient->GetItem($xmlvar); + } catch (\SoapFault $fault) { + $this->onError($fault); + } + + // Return true on success + return null; + } } \ No newline at end of file From 060232795a7ababf08ba08b8ff8f5ddbbfb726d5 Mon Sep 17 00:00:00 2001 From: Jose Juan Calvo Date: Thu, 5 Nov 2015 13:31:40 +0100 Subject: [PATCH 4/4] Ver bug https://github.com/thybag/PHP-SharePoint-Lists-API/issues/83 --- src/Thybag/Auth/SharePointOnlineAuth.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Thybag/Auth/SharePointOnlineAuth.php b/src/Thybag/Auth/SharePointOnlineAuth.php index 6fee459..3c6f457 100644 --- a/src/Thybag/Auth/SharePointOnlineAuth.php +++ b/src/Thybag/Auth/SharePointOnlineAuth.php @@ -147,7 +147,7 @@ protected function extractAuthCookies($result){ $authCookies[] = $loop[1]; } } - unset($authCookies[0]); // No need for first cookie + //unset($authCookies[0]); // No need for first cookie // Extract cookie name & payload and format in to cURL compatible string foreach($authCookies as $payload){ @@ -244,4 +244,4 @@ protected function generateSecurityToken($username, $password, $endpoint) { TOKEN; } -} \ No newline at end of file +}