Skip to content

Commit

Permalink
Merge pull request thybag#146 from thybag/develop
Browse files Browse the repository at this point in the history
Dev->Master
  • Loading branch information
thybag authored Jul 6, 2018
2 parents 5732be7 + 0dd10cc commit cf5cae5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "thybag/php-sharepoint-lists-api",
"version": "0.6.4",
"type": "library",
"description": "A simple PHP API to make working with SharePoint lists easy.",
"homepage": "https://github.com/thybag/PHP-SharePoint-Lists-API",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The **PHP SharePoint Lists API** is designed to make working with SharePoint Lis

Using the PHP SharePoint Lists API, you can easily create, read, edit and delete from SharePoint list. The API also has support for querying list metadata and the list of lists.

Known to work with: SharePoint 2007 and SharePoint online (experimental).
Known to work with: SharePoint 2007, SharePoint 2013 and SharePoint online (experimental).

### Usage Instructions

Expand Down
8 changes: 1 addition & 7 deletions src/Thybag/Auth/SharePointOnlineAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __doRequest($request, $location, $action, $version, $one_way = f
// Set base headers
$headers = array();
$headers[] = "Content-Type: text/xml;";
$headers[] = "SOAPAction: \"{$action}\"";

$curl = curl_init($location);

Expand All @@ -39,13 +40,6 @@ public function __doRequest($request, $location, $action, $version, $one_way = f
curl_setopt($curl, CURLOPT_VERBOSE,FALSE);
curl_setopt($curl, CURLOPT_HEADER, FALSE);

// SharePoint Online requires the SOAPAction header set for ADD/EDIT and DELETE Operations.
// Failure to have this will result in a "Security Validation exception"
// @see http://weblogs.asp.net/jan/archive/2009/05/25/quot-the-security-validation-for-this-page-is-invalid-quot-when-calling-the-sharepoint-web-services.aspx
if( strpos($request, 'UpdateListItems') !== FALSE ) {
$headers[] = 'SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"';
}

// Add headers
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

Expand Down
14 changes: 12 additions & 2 deletions src/Thybag/Auth/SoapClientAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public function __doRequest($request, $location, $action, $version, $one_way = 0
);

$this->__last_request_headers = $headers;
$location = $this->sanitizeUrl($location);

$ch = curl_init($location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

Expand All @@ -109,8 +111,6 @@ public function __doRequest($request, $location, $action, $version, $one_way = 0
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_CERTINFO, TRUE);

$response = curl_exec($ch);

Expand All @@ -131,4 +131,14 @@ public function __doRequest($request, $location, $action, $version, $one_way = 0
}
}
}

/**
* Sanitize URL to request to Sharepoint
*
* @param string $url
* @return type string
*/
protected function sanitizeUrl($url) {
return str_replace(" ", "%20", $url);
}
}
10 changes: 5 additions & 5 deletions src/Thybag/Service/QueryObjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,21 @@ public function get ($options = NULL) {
*
* @param $rel Relation AND/OR etc
* @param $col column to test
* @param $test comparison type (=,!+,<,>)
* @param $test comparison type (=,!+,<,>,like)
* @param $value value to test with
* @return Ref to self
* @throws \Exception Thrown if $test is unrecognized
*/
private function addQueryLine ($rel, $col, $test, $value) {
// Check tests are usable
if (!in_array($test, array('!=', '>=', '<=', '<', '>', '='))) {
throw new \Exception('Unrecognized query parameter. Please use <,>,=,>=,<= or !=');
if (!in_array($test, array('!=', '>=', '<=', '<', '>', '=', 'like'))) {
throw new \Exception('Unrecognized query parameter. Please use <,>,=,>=,<=, != or like');
}

// Make sure $rel is lower-case
$rel = strtolower($rel);

$test = str_replace(array('!=', '>=', '<=', '<', '>', '='), array('Neq', 'Geq', 'Leq', 'Lt', 'Gt', 'Eq'), $test);
$test = str_replace(array('!=', '>=', '<=', '<', '>', '=', 'like'), array('Neq', 'Geq', 'Leq', 'Lt', 'Gt', 'Eq', 'Contains'), $test);

// Create caml
$caml = $this->where_caml;
Expand Down Expand Up @@ -291,4 +291,4 @@ public function getOptionCAML () {

return $xml;
}
}
}
5 changes: 3 additions & 2 deletions src/Thybag/SharePointAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,8 @@ public function CRUD ($list_name) {
private function getArrayFromElementsByTagName ($rawXml, $tag, $namespace = NULL) {
// Get DOM instance and load XML
$dom = new \DOMDocument();
$dom->loadXML($rawXml);

$dom->loadXML($rawXml, (LIBXML_VERSION >= 20900) ? LIBXML_PARSEHUGE : null);

// Is namespace set?
if (!is_null($namespace)) {
Expand Down Expand Up @@ -1096,7 +1097,7 @@ public function getFieldVersions ($list, $id, $field) {

// Load XML in to DOM document and grab all Fields
$dom = new \DOMDocument();
$dom->loadXML($rawxml);
$dom->loadXML($rawxml, (LIBXML_VERSION >= 20900) ? LIBXML_PARSEHUGE : null);
$nodes = $dom->getElementsByTagName("Version");

// Parse results
Expand Down

0 comments on commit cf5cae5

Please sign in to comment.