40 public static function addAttachment($connection, $list_id, $list_item_id, $file_name, $base64Binary)
42 $list_wsdl = self::getWSDLLocation(
'lists', $connection[
'url']);
44 $client =
new SoapClient($list_wsdl, $connection[
'authentication']);
45 $input_param = Array (
46 'listName' => $list_id,
47 'listItemID' => $list_item_id,
48 'fileName' => basename($file_name),
49 'attachment' => $base64Binary,
51 $response = $client->AddAttachment($input_param);
52 $upload_result = $response->AddAttachmentResult;
53 if (basename($upload_result) == basename($file_name)) {
56 }
catch (SoapFault $sf) {
58 if (isset($sf->detail)) $detail = $sf->detail;
59 trigger_error($sf->getMessage().
'.'.$detail, E_USER_WARNING);
76 $client =
new SoapClient(WSDL, $authen);
77 $input_param = Array (
78 'pageUrl' => $page_url,
79 'checkoutToLocal' => TRUE,
80 'lastmodified' => $last_modified,
82 $response = $client->CheckOutFile($input_param);
83 $response_xml = simplexml_load_string($response->GetPermissionCollectionResult->any);
85 }
catch (SoapFault $sf) {
87 if (isset($sf->detail)) $detail = $sf->detail;
88 trigger_error($sf->getMessage().
'.'.$detail, E_USER_WARNING);
102 $services_list = self::getServiceLocation();
103 $clean_service_name = str_replace(
' ',
'_', strtolower($service_name));
105 if (isset($services_list[$clean_service_name]))
106 return $url_root.$services_list[$clean_service_name].
'?WSDL';
119 private static function getServiceLocation()
121 $services_list = Array (
122 'administration' =>
'/_vti_adm/admin.asmx',
123 'alerts' =>
'/_vti_bin/alerts.asmx',
124 'document_workspace' =>
'/_vti_bin/dws.asmx',
125 'form' =>
'/_vti_bin/forms.asmx',
126 'imaging' =>
'/_vti_bin/imaging.asmx',
127 'list_data_retrieval' =>
'/_vti_bin/dspsts.asmx',
128 'lists' =>
'/_vti_bin/lists.asmx',
129 'meeting' =>
'/_vti_bin/meeting.asmx',
130 'permissions' =>
'/_vti_bin/permissions.asmx',
131 'site_data' =>
'/_vti_bin/sitedata.asmx',
132 'site' =>
'/_vti_bin/sites.asmx',
133 'usergroup' =>
'/_vti_bin/usergroup.asmx',
134 'versions' =>
'/_vti_bin/versions.asmx',
135 'web_part_pages' =>
'/_vti_bin/webpartpages.asmx',
136 'webs' =>
'/_vti_bin/webs.asmx',
139 return $services_list;
156 $client =
new SoapClient(WSDL_USRGRP, $authen);
157 $input_param = Array (
158 'userLoginName' => $user_name,
160 $response = $client->GetUserInfo($input_param);
161 $response_xml = simplexml_load_string($response->GetPermissionCollectionResult->any);
163 }
catch (SoapFault $sf) {
165 if (isset($sf->detail)) $detail = $sf->detail;
166 trigger_error($sf->getMessage().
'.'.$detail, E_USER_WARNING);
183 $client =
new SoapClient(WSDL_PERM, $authen);
184 $input_param = Array (
185 'objectName' => $list_name,
186 'objectType' =>
'List',
188 $response = $client->GetPermissionCollection($input_param);
189 $response_xml = simplexml_load_string($response->GetPermissionCollectionResult->any);
191 }
catch (SoapFault $sf) {
193 if (isset($sf->detail)) $detail = $sf->detail;
194 trigger_error($sf->getMessage().
'.'.$detail, E_USER_WARNING);
212 $client =
new SoapClient(WSDL, $authen);
213 $input_param = Array (
214 'listName' => $list_name,
216 $response = $client->DeleteList($input_param);
217 }
catch (SoapFault $sf) {
219 if (isset($sf->detail)) $detail = $sf->detail;
220 trigger_error($sf->getMessage().
'.'.$detail, E_USER_WARNING);
236 public static function addList($list_name, $description=
'', $templateID=
'100')
240 $client =
new SoapClient(WSDL, $authen);
241 $input_param = Array (
242 'listName' => $list_name,
243 'description' => $description,
244 'templateID' => $templateID,
246 $response = $client->AddList($input_param);
247 }
catch (SoapFault $sf) {
249 if (isset($sf->detail)) $detail = $sf->detail;
250 trigger_error($sf->getMessage().
'.'.$detail, E_USER_WARNING);
265 private static function getTemplateId($template_name=
'')
267 $template_ids = Array (
268 'announcements' =>
'104',
270 'custom_list' =>
'100',
271 'custom_list_in_datasheet_view' =>
'120',
272 'dataSources' =>
'110',
273 'discussion_board' =>
'108',
274 'document_library' =>
'101',
276 'form_library' =>
'115',
279 'picture_library' =>
'109',
284 if (!empty($template_name)) {
285 return $template_ids[$template_name];
287 return $template_ids;
304 public static function getList($connection, $list_id)
306 $list_wsdl = self::getWSDLLocation(
'lists', $connection[
'url']);
308 $client =
new SoapClient($list_wsdl, $connection[
'authentication']);
309 $input_param = Array (
310 'listName' => $list_id,
312 $response = $client->getList($input_param);
314 }
catch (SoapFault $sf) {
316 if (isset($sf->detail)) $detail = $sf->detail;
317 trigger_error($sf->getMessage().
'.'.$detail, E_USER_WARNING);
339 $response = self::getList($connection, $list_id);
341 $available_fields = Array();
342 $field_info = Array();
343 if (!empty($response)) {
344 $xml = simplexml_load_string($response->GetListResult->any);
346 foreach ($xml->Fields->children() as $field) {
347 $read_only = (string) $field[
'ReadOnly'];
348 if ($read_only ==
'TRUE' && $all == FALSE)
continue;
350 if (!$get_field_info) {
351 $field_xml = $field->asXML();
352 $pattern =
'/(<Field Type[^>]*>)/s';
354 preg_match($pattern, $field_xml, $matches);
355 if (isset($matches[0]) && !empty($matches[0])) {
356 $available_fields[(string) $field[
'Name']] = (
string) $field[
'DisplayName'];
358 $available_fields[(string) $field[
'Name']] = (
string) $field[
'DisplayName'];
361 foreach ($field->attributes() as $attr_name => $attr_val) {
362 $field_info[(string) $field[
'Name']][$attr_name] = (
string) $attr_val;
369 if ($get_field_info) {
372 asort($available_fields);
373 return $available_fields;
392 $client =
new SoapClient(WSDL, $authen);
394 <Batch OnError="Continue" PreCalc="TRUE"
396 <Method ID="1" Cmd="Delete">
397 <Field Name="ID">'.$list_item_id.
'</Field>
401 $input_param = Array (
402 'listName' => $list_id,
404 'any' => $update_xml,
407 $response = $client->UpdateListItems($input_param);
409 }
catch (SoapFault $sf) {
411 if (isset($sf->detail)) $detail = $sf->detail;
412 trigger_error($sf->getMessage().
'.'.$detail, E_USER_WARNING);
428 public static function addListItem($connection, $list_id, $sharepoint_fields)
431 $list_wsdl = self::getWSDLLocation(
'lists', $connection[
'url']);
433 $client =
new SoapClient($list_wsdl, $connection[
'authentication']);
434 $fs = $client->__getFunctions();
437 foreach ($sharepoint_fields as $field_id => $value) {
438 if (!empty($value)) {
439 $inner_xml .=
'<Field Name="'.$field_id.
'">'.$value.
'</Field>';
443 $request_xml =
'<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0" ><Method ID="1" Cmd="New">'.$inner_xml.
'</Method></Batch>';
445 $input_param = Array (
446 'listName' => $list_id,
448 'any' => $request_xml,
453 $response = $client->UpdateListItems($input_param);
455 }
catch (SoapFault $sf) {
457 if (isset($sf->detail)) $detail = $sf->detail;
458 trigger_error($sf->getMessage().
'.'.$detail, E_USER_WARNING);
462 $xml = simplexml_load_string($response->UpdateListItemsResult->any);
463 $error_code = (string) $xml->Result->ErrorCode;
465 if ($error_code ==
'0x00000000') {
466 $items_xml = $xml->Result;
468 $items_xml->registerXPathNamespace(
'zz',
'#RowsetSchema');
469 $zresults = $items_xml->xpath(
'//zz:row');
471 $ows_ID = (int) $zresults[0][
'ows_ID'];
474 $res_msg =
'Error Code '.$error_code .
' - '.(string) $xml->Result->ErrorText;
493 private static function constructXMLQuery($search_query, $search_logic, $field_info)
505 'Contains' =>
'Contains',
506 'BeginsWith' =>
'BeginsWith',
507 'IsNotNull' =>
'IsNotNull',
508 'IsNull' =>
'IsNull',
511 $search_query_temp = Array();
513 foreach ($search_query as $index => $field_crit_info) {
514 $field_name = key($field_crit_info);
515 $crit_info = $field_crit_info[$field_name];
516 $op = $operators[$crit_info[
'operator']];
517 $val = $crit_info[
'value'];
518 $type = $field_info[$field_name][
'Type'];
520 $query_str =
'<'.$op.
'><FieldRef Name="'.$field_name.
'" /><Value Type="'.$type.
'">'.$val.
'</Value></'.$op.
'>';
521 $search_query_temp[] = $query_str;
524 $query_strings = self::recursiveXMLConstruct($search_query_temp, $search_logic);
525 $built_query_string = array_pop($search_query_temp);
527 $final_query_str =
"<Query><Where>".$built_query_string.
"</Where></Query>";
529 return $final_query_str;
543 private static function recursiveXMLConstruct(&$search_query, $search_logic)
557 $temp_array = Array();
558 for (reset($search_query); NULL !== ($k = key($search_query)); next($search_query)) {
559 $current_element = $search_query[$k];
560 if (!empty($current_element)) {
561 $next_element = next($search_query);
562 if (!empty($next_element)) {
563 $search_clause =
'<'.$search_logic.
'>'.$current_element.$next_element.
'</'.$search_logic.
'>';
564 $temp_array[] = $search_clause;
566 $search_clause = $current_element;
567 $temp_array[] = $search_clause;
571 $search_query = $temp_array;
572 if (count($search_query) >= 2) {
573 self::recursiveXMLConstruct($search_query, $search_logic);
588 public static function getListItems($connection, $list_id, $search_query=Array(), $search_logic=
'And', $row_limit=
'', $download_file=FALSE, $bridge_info=
"")
591 $list_wsdl = self::getWSDLLocation(
'lists', $connection[
'url']);
593 $client =
new SoapClient($list_wsdl, $connection[
'authentication']);
595 $ndViewFields =
" <viewFields>
596 <FieldRef Name='Field1'/><FieldRef Name='Field2'/>
600 'listName' => $list_id,
602 'rowLimit' => $row_limit,
604 $ndQueryOptions =
' <QueryOptions>
605 <IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls>
608 $param[
'queryOptions'] = Array (
609 'any' => $ndQueryOptions,
612 if (!empty($search_query)) {
613 $field_info = self::getListAvailableFields($connection, $list_id, TRUE, TRUE);
614 $query = self::constructXMLQuery($search_query, $search_logic, $field_info);
615 $param[
'query'] = Array (
621 $items = $client->GetListItems($param);
622 $all_items = $items->GetListItemsResult->any;
624 $items_xml = simplexml_load_string($all_items);
625 $namespaces = $items_xml->getDocNamespaces();
626 $items_xml->registerXPathNamespace(
'zz',
'#RowsetSchema');
627 $zresults = $items_xml->xpath(
'//zz:row');
629 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
630 foreach ($zresults as $zresult) {
631 $ows_ID = (string) $zresult[
'ows_ID'];
632 foreach ($zresult->attributes() as $attr_name => $attr_val) {
633 $attr_val = str_replace($ows_ID.
';#',
'', $attr_val);
634 if ($attr_name ==
'ows_Attachments') {
635 $attr_val = str_replace(
';#',
'', $attr_val);
637 $result[$ows_ID][$attr_name] = (string) $attr_val;
641 if(isset($result[$ows_ID][
'ows_FileRef']))
642 $result[$ows_ID][
'ows_FileRef'] = str_replace(
' ',
'%20', $result[$ows_ID][
'ows_FileRef']);
643 if(isset($result[$ows_ID][
'ows_Attachments']))
644 $result[$ows_ID][
'ows_Attachments'] = str_replace(
' ',
'%20', $result[$ows_ID][
'ows_Attachments']);
647 $url_bits = parse_url($connection[
'url']);
648 $base_url = $url_bits[
'scheme'].
'://'.$url_bits[
'host'];
649 if (isset($url_bits[
'port']) && !empty($url_bits[
'port'])) $base_url = $base_url.
':'.$url_bits[
'port'];
650 $remote_download_url = $base_url.
'/'.$result[$ows_ID][
'ows_FileRef'];
653 if ($download_file) {
654 $data_path = $bridge_info[
'data_path'].
'/'.$list_id.
'/';
655 if (create_directory($data_path)) {
656 self::downloadFiles(Array($remote_download_url), $data_path, $connection[
'authentication']);
657 $result[$ows_ID][
'download_url'] = $bridge_info[
'url'].
'?file_uri='.$list_id.
'/'.basename($result[$ows_ID][
'ows_FileRef']);
659 trigger_error(
'Unable to download the file to directory: '.$data_path, E_USER_WARNING);
660 $result[$ows_ID][
'download_url'] =
'';
663 $result[$ows_ID][
'download_url'] = $remote_download_url;
667 if ($download_file && isset($result[$ows_ID][
'ows_Attachments']) && $result[$ows_ID][
'ows_Attachments']) {
668 $data_path = $bridge_info[
'data_path'].
'/'.$list_id.
'/';
669 if (create_directory($data_path)) {
670 self::downloadFiles(Array($result[$ows_ID][
'ows_Attachments']), $data_path, $connection[
'authentication']);
671 $result[$ows_ID][
'ows_Attachments'] = $bridge_info[
'url'].
'?file_uri='.$list_id.
'/'.basename($result[$ows_ID][
'ows_Attachments']);
673 trigger_error(
'Unable to download the file attachment to directory: '.$data_path, E_USER_WARNING);
674 $result[$ows_ID][
'ows_Attachments'] =
'';
680 }
catch (SoapFault $sf) {
682 if (isset($sf->detail)) $detail = $sf->detail;
683 trigger_error($sf->getMessage().
'.'.$detail, E_USER_WARNING);
700 $list_wsdl = self::getWSDLLocation(
'lists', $connection[
'url']);
702 $client =
new SoapClient($list_wsdl, $connection[
'authentication']);
703 $collections = $client->GetListCollection();
705 $all_lists = $collections->GetListCollectionResult->any;
706 $result = simplexml_load_string($all_lists);
708 foreach ($result->children() as $list) {
709 $list_id = (string) $list [
'ID'];
710 if ($custom_list_only && (
string) $list[
'ServerTemplate'] !=
'100') {
713 foreach ($list->attributes() as $name => $value) {
714 $lists[$list_id][$name] = (string) $value;
718 }
catch (SoapFault $sf) {
720 if (isset($sf->detail)) $detail = $sf->detail;
737 public static function getListNames($connection, $all_list_details=Array())
739 if (empty($all_list_details)) {
740 $all_list_details = self::getListCollections($connection);
742 $list_names = Array();
744 foreach ($all_list_details as $list_id => $list_info) {
745 $list_names[$list_id] = $list_info[
'Title'];
763 private static function downloadFiles($urls, $save_path, $auth)
765 $mh = curl_multi_init();
766 foreach ($urls as $i => $url) {
767 $final_path = $save_path.urldecode(basename($url));
768 $conn[$i] = curl_init($url);
769 $fp[$i] = fopen($final_path,
"w");
770 curl_setopt($conn[$i], CURLOPT_FILE, $fp[$i]);
771 curl_setopt($conn[$i], CURLOPT_HEADER ,0);
772 curl_setopt($conn[$i], CURLOPT_CONNECTTIMEOUT, 60);
773 curl_setopt($conn[$i], CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
774 if (isset($auth[
'login']) && isset($auth[
'password']))
775 curl_setopt($conn[$i], CURLOPT_USERPWD, $auth[
'login'].
':'.$auth[
'password']);
776 curl_multi_add_handle($mh,$conn[$i]);
780 $n = curl_multi_exec($mh, $active);
783 foreach ($urls as $i => $url) {
784 if (isset($conn[$i]) && isset($fp[$i])) {
785 curl_multi_remove_handle($mh, $conn[$i]);
786 curl_close($conn[$i]);
790 curl_multi_close($mh);
806 $client =
new SoapClient(self::getWSDLLocation(
'lists', $connection[
'url']), $connection[
'authentication']);
807 $fns = $client->__getFunctions();
811 if (empty($all_lists))
return FALSE;
817 }
catch (SoapFault $e) {
819 echo $e->getMessage().
'<br />';