'Alfresco Settings', 'description' => 'Connection settings to Alfresco repository', 'page callback' => 'drupal_get_form', 'page arguments' => array('cmis_alfresco_headerswing_admin_settings'), 'access callback' => 'user_access', 'access arguments' => array('administer alfresco'), 'file' => 'cmis_alfresco_headerswing.pages.inc' ); return $items; } /** * Invoke Alfresco Webscript based Service. In order to use this implementation of hook_cmis_alfresco_service() please add * * $conf['cmis_alfresco_service_invoker']='cmis_alfresco_headerswing'; * * in your settings.php file. * * @param $serviceurl * @param $headers * @param $method * @param $data * @param $retry * @return string xml response */ function cmis_alfresco_headerswing_cmis_alfresco_service($serviceurl, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) { $response = cmis_alfresco_headerswing_http_request($serviceurl, $headers, $method, $data, $retry); if ($response->code == 200 || $response->code == 201) { return $response->data; } else { throw new CMISException(t('Failed to invoke service '. $serviceurl .' Code:'. $response->code)); } } /** * Invoke Webscript based Service using curl apis. * It is intended to be a utility function that handles authentication (basic, ticket), * http headers (if necessary) and custom post ( cmisquery+xml, atom+xml etc.). * * @param $serviceurl Alfreco webscript service url without /service or /wcservice prefix. * @param $headers Additional http headers for making the http call. 'ticket' is for ticket based, 'basic' for http basic authentication, 'refresh' for ticket based but with ticket refresh. * @param $method * @param $data * @param $retry * @return response stdClass object */ function cmis_alfresco_headerswing_http_request($service_url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) { $wc_endpoint = variable_get('cmis_alfresco_headerswing_endpoint', '') .'/service'; $url = $service_url; if ($url[0] == '/') { $url = $wc_endpoint . $service_url; } // propagate headers $headers = _cmis_alfresco_headerswing_propagate_headers($headers); // Prepare curl session $session = curl_init($url); curl_setopt($session, CURLOPT_VERBOSE, 1); // Add additonal headers curl_setopt($session, CURLOPT_HTTPHEADER, $headers); // Don't return HTTP headers. Do return the contents of the call curl_setopt($session, CURLOPT_HEADER, FALSE); curl_setopt($session, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($session, CURLOPT_CONNECTTIMEOUT, 4); if ($method == 'CUSTOM-POST') { curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($session, CURLOPT_POSTFIELDS, $data); curl_setopt($session, CURLOPT_ERRORBUFFER, 1); } if ($method == 'CUSTOM-PUT') { curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($session, CURLOPT_POSTFIELDS, $data); curl_setopt($session, CURLOPT_ERRORBUFFER, 1); } // Make the call $return_data = curl_exec($session); // Get return http status code $httpcode = curl_getinfo($session, CURLINFO_HTTP_CODE); // Close HTTP session curl_close($session); // Prepare return $result = new stdClass(); $result->code = $httpcode; $result->data = $return_data; return $result; } /** * Decorates wc request headers with * headers defined in drupal request. * * @param $headers * @return array */ function _cmis_alfresco_headerswing_propagate_headers($headers) { $header_names = variable_get('cmis_alfresco_headerswing_headers', array()); foreach($header_names as $header_name) { if(array_key_exists($header_name, $_SERVER)) { $headers[$header_name] = $_SERVER[$header]; } } return $headers; }