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)) {
watchdog('cmis_vendor_invoke', "cmis module not configured", null, WATCHDOG_ERROR);
return;
}
$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);
}
watchdog('cmis_vendor_invoke', "{$function} not implemented", null, WATCHDOG_ERROR);
return;
}
watchdog('cmis_vendor_invoke', "Unknown vendor: {$vendor}", null, WATCHDOG_ERROR);
return;
}
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',
),
);
$items['cmis/autocomplete'] = array(
'title' => t('cmis path autocomplete'),
'page callback' => 'cmis_path_autocomplete',
'access callback' => 'user_access',
'access arguments' => array(
'access cmis',
),
'type' => MENU_CALLBACK,
);
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;
}
function cmis_path_autocomplete() {
module_load_include('api.inc', 'cmis');
$args = func_get_args();
$path = '/' . implode('/', array_slice($args, 0, sizeof($args) - 1));
$key = end($args);
$matches = array();
$repository = cmisapi_getRepositoryInfo();
if ($path == '/') {
$folderId_parts = explode('/', $repository->rootFolderId);
$path = '/' . end($folderId_parts);
$matches[$path] = $path;
print drupal_to_js($matches);
return;
}
$folderObject = cmisapi_getProperties($repository->repositoryId, drupal_urlencode($path));
foreach (array(
'folder',
'document',
) as $cmis_base_type) {
$cmis_objects = cmisapi_query($repository->repositoryId, "SELECT * FROM {$cmis_base_type} WHERE " . ($key != '*' ? "Name like '%{$key}%' AND" : "") . " IN_FOLDER('{$folderObject->id}')");
foreach ($cmis_objects as $cmis_object) {
$matches[$path . '/' . $cmis_object->title . ($cmis_base_type == 'folder' ? '/' : '')] = $cmis_object->title;
}
}
print drupal_to_js($matches);
}