Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 10 additions & 6 deletions src/Thybag/Auth/SharePointOnlineAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,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);
Expand Down Expand Up @@ -89,7 +93,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);
Expand Down Expand Up @@ -143,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){
Expand Down Expand Up @@ -180,9 +184,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);

Expand Down Expand Up @@ -240,4 +244,4 @@ protected function generateSecurityToken($username, $password, $endpoint) {
</s:Envelope>
TOKEN;
}
}
}
67 changes: 67 additions & 0 deletions src/Thybag/SharePointAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<CopyIntoItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<SourceUrl>'.$file_name.'</SourceUrl>
<DestinationUrls>
<string>'.$destinationUrl.'</string>
</DestinationUrls>';
if($fields!=null && count($fields)>0)
{
$CAML .= ' <Fields>';
for ($i = 0; $i < count($fields); ++$i) {
$CAML .= ' <FieldInformation';
foreach ($fields[$i] as $key => $value) {
$CAML .= " ".$key."=\"".$value."\"";

}
$CAML .= ' />';
}

$CAML .= ' </Fields>';
}
$CAML .= '
<Stream>' . $attachment . '</Stream>
</CopyIntoItems>';

$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 = '<GetItem xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<Url>'.$sourceUrl.'</Url>
</GetItem>';

$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;
}
}