17 require_once
'Mail/mimeDecode.php';
38 var $security_header = NULL;
78 if (empty($wsdl) || empty($conn_info[
'username']) || empty($conn_info[
'password']))
return FALSE;
80 if ($conn_info[
'ws_security']) {
81 $created = date(
'Y-m-d\TH:i:s\Z', time());
83 '<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1">
84 <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
85 <wsu:Created>'.$created.
'</wsu:Created>
88 <wsse:Username>'.$conn_info[
'username'].
'</wsse:Username>
89 <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.$conn_info[
'password'].
'</wsse:Password>
93 $soap_header_var = @
new SoapVar($soap_header_data, XSD_ANYXML);
94 $namespace =
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
95 $this->security_header = @
new SoapHeader($namespace,
"wsse:Security", $soap_header_var, TRUE);
100 $params[
'exceptions'] = TRUE;
101 $params[
'trace'] = TRUE;
102 $params[
'soap_version'] = SOAP_1_1;
103 $params[
'login'] = $conn_info[
'username'];
104 $params[
'password'] = $conn_info[
'password'];
106 if (!$conn_info[
'ws_security']) $params[
'location'] = substr($wsdl, 0, strpos($wsdl,
'?')).
'/basic';
109 if ($this->ptr) $this->ptr=NULL;
111 if ($conn_info[
'verify']){
113 'FOLLOWLOCATION' => 1,
114 'RETURNTRANSFER' => 1,
115 'HTTPAUTH' => CURLAUTH_BASIC,
117 'USERPWD' => $conn_info[
'username'].
":".$conn_info[
'password'],
119 $details = fetch_url($wsdl, $options, array(), FALSE);
120 $contents = $details[
'response'];
122 if (strpos($contents,
'?xml') === FALSE)
return FALSE;
125 $this->ptr =
new SoapClient($wsdl, $params);
126 $fns = $this->ptr->__getFunctions();
127 if (empty($fns))
return FALSE;
129 if ($conn_info[
'service_name'] ==
'RepositoryService') {
130 $response = $this->ptr->__soapCall(
'getRepositories', Array(), Array(
'uri'=>
''), $this->security_header);
131 }
else if ($conn_info[
'service_name'] ==
'NavigationService'){
132 $response = $this->ptr->__soapCall(
'getChildren', Array(
'paramaters' => Array (
'repositoryId' =>
'',
'folderId' =>
'')), Array(
'uri'=>
''), $this->security_header);
133 }
else if ($conn_info[
'service_name'] ==
'ObjectService'){
134 $response = $this->ptr->__soapCall(
'getContentStream', Array(
'paramaters' => Array (
'repositoryId' =>
'',
'objectId' =>
'')), Array(
'uri'=>
''), $this->security_header);
136 }
catch (SoapFault $e) {
137 if (strpos($e->getMessage(),
'looks like we got no XML document') === FALSE) {
138 trigger_error(
"Failed to connect to CMIS ".$conn_info[
'service_name'].
": ".$e->getMessage().
"\n", E_USER_WARNING);
144 $this->ptr =
new SoapClient($wsdl, $params);
160 $repositories = NULL;
161 if (!$this->ptr)
return $repositories;
164 $response = $this->ptr->__soapCall(
'getRepositories', Array(), Array(
'uri'=>
''), $this->security_header);
165 }
catch (SoapFault $e) {
166 if (strpos($e->getMessage(),
'looks like we got no XML document') === FALSE) {
167 trigger_error(
"Failed to getRepositories: ".$e->getMessage().
"\n", E_USER_WARNING);
168 return $repositories;
174 if (isset($data[
'xml']->getRepositoriesResponse)){
175 $repositories = $data[
'xml']->getRepositoriesResponse;
178 return $repositories;
192 $repositoryInfo = NULL;
193 if (!$this->ptr)
return $repositoryInfo;
196 $response = $this->ptr->__soapCall(
'getRepositoryInfo', Array(
'paramaters' => Array (
'repositoryId' => $repositoryId)), Array(
'uri'=>
''), $this->security_header);
197 }
catch (SoapFault $e) {
198 if (strpos($e->getMessage(),
'looks like we got no XML document') === FALSE) {
199 trigger_error(
"Failed to getRepositoryInfo: ".$e->getMessage().
"\n", E_USER_WARNING);
200 return $repositoryInfo;
205 if (isset($data[
'xml']->getRepositoryInfoResponse)) {
206 $repositoryInfo = $data[
'xml']->getRepositoryInfoResponse;
209 return $repositoryInfo;
225 if (!$this->ptr)
return $type_def;
228 $response = $this->ptr->__soapCall(
'getTypeDefinition', Array(
'paramaters' => Array (
'repositoryId' => $repositoryId,
'typeId' => $typeId)), Array(
'uri'=>
''), $this->security_header);
229 }
catch (SoapFault $e) {
230 if (strpos($e->getMessage(),
'looks like we got no XML document') === FALSE) {
231 trigger_error(
"Failed to getTypeDefinition: ".$e->getMessage().
"\n", E_USER_WARNING);
237 if (isset($data[
'xml']->getTypeDefinitionResponse)){
238 $type_def = $data[
'xml']->getTypeDefinitionResponse;
257 if (!$this->ptr)
return $children;
260 $response = $this->ptr->__soapCall(
'getChildren', Array(
'paramaters' => Array (
'repositoryId' => $repositoryId,
'folderId' => $folderId,
'includePathSegment' => TRUE)), Array(
'uri'=>
''), $this->security_header);
261 }
catch (SoapFault $e) {
262 if (strpos($e->getMessage(),
'looks like we got no XML document') === FALSE) {
263 trigger_error(
"Failed to getChildren: ".$e->getMessage().
"\n", E_USER_WARNING);
269 if (isset($data[
'xml']->getChildrenResponse)){
270 $children = $data[
'xml']->getChildrenResponse;
289 if (!$this->ptr)
return $contentStream;
292 $response = $this->ptr->__soapCall(
'getContentStream', Array(
'paramaters' => Array (
'repositoryId' => $repositoryId,
'objectId' => $objectId)), Array(
'uri'=>
''), $this->security_header);
293 }
catch (SoapFault $e) {
294 if (strpos($e->getMessage(),
'looks like we got no XML document') === FALSE) {
295 trigger_error(
"Failed to getContentStream: ".$e->getMessage().
"\n", E_USER_WARNING);
296 return $contentStream;
301 if (isset($data[
'binary'])) {
302 $contentStream = $data[
'binary'];
303 }
else if (isset($data[
'xml']->getContentStreamResponse->contentStream->stream)){
304 $contentStream = (string)$data[
'xml']->getContentStreamResponse->contentStream->stream;
305 $contentStream = base64_decode($contentStream);
308 return $contentStream;
323 $decode_params[
'include_bodies'] = TRUE;
324 $decode_params[
'decode_bodies'] = TRUE;
325 $decode_params[
'decode_headers'] = TRUE;
327 $soap_header = $this->ptr->__getLastResponseHeaders();
328 $soap_response = $this->ptr->__getLastResponse();
330 $decoder =
new Mail_mimeDecode($soap_header.
"\r\n".$soap_response);
331 $structure = $decoder->decode($decode_params);
333 if (isset($structure->parts[1]->body)) {
334 $data[
'binary'] = $structure->parts[1]->body;
335 $data[
'binary'] = preg_replace(
'|\r\n$|',
'', $data[
'binary']);
338 $soap_env = (isset($structure->parts[0]->body)) ? $structure->parts[0]->body :
'';
340 if (preg_match(
'|<([^:]+:)?Body[^>]*>(.*)</([^:]+:)?Body>|msi', $soap_env, $match)) {
342 $match[0] = preg_replace(
"/(<\/?)(\w+):([^>]*>)/",
"$1$2$3", $match[0]);
344 $xml =
new SimpleXMLElement($match[0]);
346 }
catch(Exception $e){
347 trigger_error(
"Failed to parse XML".$e->getMessage().
"\n", E_USER_WARNING);