You are here

cmis.module in CMIS API 6.2

File

cmis.module
View source
<?php

/**
 * Utility function that returns all known vendors
 * 
 * @return array
 */
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;
}

/**
 * Utility function used to call a CMIS method, 
 * using the CMIS vendor selected in config.  
 *
 * @return mixed
 */
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,
  )));
}

/**
 * Implementation of hook_menu() for CMIS module.
 * 
 */
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;
}

/**
 * Prepare and generate entry form for CMIS settings.
 * 
 */
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);
}

/**
 * Validate Setting inputs for CMIS.
 * 
 */
function cmis_admin_settings_validate($form, &$form_state) {

  // vendor is required
  $endpoint = $form_state['values']['cmis_vendor'];
  if ($endpoint == '') {
    form_set_error('cmis_vendor', t('You must specify the CMIS vendor.'));
  }
}

/**
 * Return permissions for the CMIS module.
 * 
 */
function cmis_perm() {
  $perms = array(
    'administer cmis',
    'access cmis',
  );
  return $perms;
}

/**
 * CMIS Exception class.
 *  
 */
class CMISException extends Exception {

}

/**
 * Utility for handling CMIS errors. 
 * 
 * @param $e Exception
 */
function cmis_error_handler($type, $e) {
  watchdog($type, $e
    ->getMessage(), NULL, WATCHDOG_ERROR);
  drupal_set_message($e
    ->getMessage(), 'error');
}

/**
 * Returns supported CMIS version
 * 
 * @return string
 */
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');
}

Functions

Namesort descending Description
cmis_admin_settings Prepare and generate entry form for CMIS settings.
cmis_admin_settings_validate Validate Setting inputs for CMIS.
cmis_error_handler Utility for handling CMIS errors.
cmis_get_vendors Utility function that returns all known vendors
cmis_menu Implementation of hook_menu() for CMIS module.
cmis_perm Return permissions for the CMIS module.
cmis_vendor_invoke Utility function used to call a CMIS method, using the CMIS vendor selected in config.
cmis_version_supported Returns supported CMIS version

Classes

Namesort descending Description
CMISException CMIS Exception class.