View source
<?php
function cmis_common_cmis_info() {
return array(
'cmis_common' => array(
'name' => t('CMIS Common'),
'module' => 'cmis_common',
'description' => t('CMIS common client'),
),
);
}
function cmis_common_menu() {
$items = array();
$items['admin/settings/cmis/common'] = array(
'type' => MENU_CALLBACK,
'title' => t('CMIS Library checker'),
'page callback' => 'cmis_common_lib_check',
'access callback' => 'user_access',
'access arguments' => array(
'access cmis',
),
);
return $items;
}
function cmis_common_lib_check() {
$library = libraries_detect('cmis-phplib');
if ($library['installed']) {
$string = t('PHP CMIS Library detected - everything is good!');
$string .= "<p>" . t("Found at: root/libraries/cmis-phplib/cmis-lib.php") . "</p>";
return $string;
}
else {
$string = '<h1 class="error">' . t('PHP CMIS Library not detected') . '</h1>';
$string .= '<p>' . t('Please download the PHP CMIS Library from apache chemistry (https://svn.apache.org/repos/asf/chemistry/phpclient/trunk)') . '</p>';
$string .= "<p>" . t('Please check you libraries directory, the CMIS lib should be located at') . "<site>/libraries/cmis-phplib/cmis-lib.php" . t(' or equivalent') . "</p>";
return $string;
}
}
function short_circuit_version() {
return TRUE;
}
function cmis_common_libraries_info() {
$libraries = array();
$libraries['cmis-phplib'] = array(
'name' => 'CMIS Library',
'vendor url' => 'http://chemistry.apache.org/php/phpclient.html',
'download url' => 'https://svn.apache.org/repos/asf/chemistry/phpclient/trunk',
'version callback' => 'short_circuit_version',
'files' => array(
'php' => array(
'cmis-lib.php',
),
),
);
return $libraries;
}
function cmis_common_cmisapi_invoke() {
$args = func_get_args();
$cmis_method = $args[0];
$repository_id = count($args) > 1 ? $args[1] : 'default';
unset($args[0]);
unset($args[1]);
$cmis_repository = cmis_get_repository($repository_id);
if ($cmis_method == 'getRepositoryInfo' && isset($cmis_repository->info)) {
return $cmis_repository->info;
}
if (!isset($cmis_repository->service)) {
module_load_include('utils.inc', 'cmis_common');
$cmis_repository->service = new CommonCMISService($cmis_repository->settings['url'], isset($cmis_repository->settings['user']), isset($cmis_repository->settings['password']));
}
return call_user_func_array(array(
$cmis_repository->service,
$cmis_method,
), $args);
}
function cmis_common_cmis_invoke($url, $properties, $settings, $dry_run = FALSE) {
$session = curl_init($url);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
if ($settings['user']) {
curl_setopt($session, CURLOPT_USERPWD, $settings['user'] . ":" . $settings['password']);
}
curl_setopt($session, CURLOPT_CUSTOMREQUEST, $properties['method']);
if ($properties['headers']) {
$headers = array();
foreach ($properties['headers'] as $header_name => $header_value) {
$headers[] = $header_name . ': ' . $header_value;
}
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
}
if ($properties['data']) {
curl_setopt($session, CURLOPT_POSTFIELDS, $properties['data']);
}
if ($properties['method'] == "POST") {
curl_setopt($session, CURLOPT_POST, true);
}
$retval = new stdClass();
$retval->url = $url;
$retval->method = $properties['method'];
$retval->content_sent = $properties['data'];
$retval->content_type_sent = $properties['headers']['Content-Type'];
if (!$dry_run) {
$retval->body = curl_exec($session);
$retval->code = curl_getinfo($session, CURLINFO_HTTP_CODE);
$retval->content_type = curl_getinfo($session, CURLINFO_CONTENT_TYPE);
$retval->content_length = curl_getinfo($session, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($session);
if (!in_array($retval->code, array(
200,
201,
204,
))) {
throw new CMISException(t("HTTP call to [@url] returned [@code]. Response: @response", array(
'@code' => $retval->code,
'@response' => strip_tags($retval->body),
'@url' => $url,
)));
}
}
else {
$retval->body = NULL;
$retval->curl_session = $session;
$retval->code = 0;
$retval->content_type = NULL;
$retval->content_length = NULL;
}
return $retval;
}