View source
<?php
function cmis_get_vendors() {
$vendors = array();
$info_array = module_invoke_all('cmis_info');
foreach ($info_array as $type => $info) {
$info['type'] = $type;
$vendors[$type] = $info;
}
return $vendors;
}
function cmis_vendor_invoke() {
$vendor = variable_get('cmis_vendor', NULL);
if (is_null($vendor)) {
throw new CMISException(t('CMIS module not configured'));
}
$args = func_get_args();
$cmis_method = $args[0];
$vendors = cmis_get_vendors();
if (array_key_exists($vendor, $vendors)) {
unset($args[0]);
$function = $vendor . '_cmisapi_' . $cmis_method;
if (function_exists($function)) {
return call_user_func_array($function, $args);
}
throw new CMISException(t('@function not implemented by @vendor CMIS vendor', array(
'@function' => $function,
'@vendor' => $vendor,
)));
}
throw new CMISException(t('Unknown CMIS vendor: @vendor', array(
'@vendor' => $vendor,
)));
}
function cmis_menu() {
$items = array();
$items['admin/settings/cmis'] = array(
'title' => 'CMIS Settings',
'description' => 'Connection settings to CMIS repositories',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'cmis_admin_settings',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer cmis',
),
);
return $items;
}
function cmis_admin_settings() {
$vendors = array(
'None',
);
foreach (cmis_get_vendors() as $key => $vendor) {
$vendors[$key] = $vendor['name'];
}
$form['cmis_settings'] = array(
'#type' => 'fieldset',
'#title' => t('CMIS Settings'),
'#description' => t('Settings for cmis repositories'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['cmis_settings']['cmis_vendor'] = array(
'#type' => 'select',
'#title' => t('Vendors'),
'#default_value' => variable_get('cmis_vendor', NULL),
'#options' => $vendors,
'#description' => t('Select the CMIS vendor'),
);
return system_settings_form($form);
}
function cmis_admin_settings_validate($form, &$form_state) {
$endpoint = $form_state['values']['cmis_vendor'];
if ($endpoint == '') {
form_set_error('cmis_vendor', t('You must specify the CMIS vendor.'));
}
}
function cmis_perm() {
$perms = array(
'administer cmis',
'access cmis',
);
return $perms;
}
class CMISException extends Exception {
}
function cmis_error_handler($type, $e) {
watchdog($type, $e
->getMessage(), NULL, WATCHDOG_ERROR);
drupal_set_message($e
->getMessage(), 'error');
}
function cmis_version_supported() {
$repository = cmisapi_getRepositoryInfo();
foreach (array(
'cmisVersionSupported',
'cmisVersionsSupported',
) as $property_name) {
if (isset($repository->{$property_name})) {
return (string) $repository->{$property_name};
}
}
throw new CMISException('Unable to determine CMIS supported version');
}