You are here

cmis_browser.module in CMIS API 7.2

File

cmis_browser/cmis_browser.module
View source
<?php

/**
 * Implementation of hook_menu().
 * 
 */
function cmis_browser_menu() {
  $items = array();
  $items['cmis/browser'] = array(
    'type' => MENU_NORMAL_ITEM,
    'title' => t('CMIS Repository'),
    'page callback' => 'cmis_browser_content_get',
    'access callback' => 'user_access',
    'access arguments' => array(
      'access cmis',
    ),
    'file' => 'cmis_browser.content_get.inc',
  );
  $items['cmis/delete'] = array(
    'type' => MENU_CALLBACK,
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'cmis_browser_content_delete_confirm',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'delete cmis',
    ),
    'file' => 'cmis_browser.content_delete.inc',
  );
  $items['cmis/properties'] = array(
    'type' => MENU_CALLBACK,
    'page callback' => 'cmis_browser_content_properties',
    'access callback' => 'user_access',
    'access arguments' => array(
      'access cmis',
    ),
    'file' => 'cmis_browser.content_properties.inc',
  );
  $items['cmis/autocomplete'] = array(
    'title' => t('cmis path autocomplete'),
    'page callback' => 'cmis_browser_autocomplete',
    'access callback' => 'user_access',
    'access arguments' => array(
      'access cmis',
    ),
    'type' => MENU_CALLBACK,
    'file' => 'cmis_browser.content_autocomplete.inc',
  );
  $items['cmis/tree'] = array(
    'title' => t('cmis tree nav'),
    'page callback' => 'cmis_browser_tree',
    'access callback' => 'user_access',
    'access arguments' => array(
      'access cmis',
    ),
    'type' => MENU_CALLBACK,
    'file' => 'cmis_browser.content_autocomplete.inc',
  );
  $items['admin/settings/cmis/browser'] = array(
    'title' => t('Set Root location for CMIS Broswer'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'cmis_browser_admin_settings',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer cmis',
    ),
    'type' => MENU_CALLBACK,
  );
  return $items;
}
function cmis_browser_admin_settings() {
  $form = array();
  $form['cmis_browser_root'] = array(
    '#title' => t('Root Directory'),
    '#description' => t('Root folder for CMIS nodes'),
    '#type' => 'textfield',
    '#default_value' => variable_get('cmis_browser_root'),
  );
  return system_settings_form($form);
}

/**
 * Implements hook_admin_paths
 */
function cmis_browser_admin_paths() {
  $paths = array(
    'cmis/properties' => TRUE,
  );
  return $paths;
}

/**
 * Register custom themes for cmis_browser module.
 * 
 */
function cmis_browser_theme() {
  return array(
    'cmis_browser_popup' => array(
      'arguments' => array(
        'context' => NULL,
      ),
      'file' => 'cmis_browser.theme.inc',
      'render element' => 'page',
      'template' => 'cmis-browser-popup',
    ),
    'cmis_browser' => array(
      'arguments' => array(
        'context' => NULL,
      ),
      'file' => 'cmis_browser.theme.inc',
    ),
    'cmis_browser_browse_form' => array(
      'arguments' => array(
        'form' => NULL,
      ),
      'file' => 'cmis_browser.theme.inc',
      'render element' => 'form',
    ),
    'cmis_browser_browse_children' => array(
      'arguments' => array(
        'context' => NULL,
      ),
      'file' => 'cmis_browser.theme.inc',
    ),
    'cmis_browser_browse_breadcrumb' => array(
      'arguments' => array(
        'bcarray' => NULL,
      ),
      'file' => 'cmis_browser.theme.inc',
    ),
    'cmis_browser_content_properties' => array(
      'arguments' => array(
        'cmis_object' => NULL,
      ),
      'file' => 'cmis_browser.theme.inc',
    ),
    'cmis_browser_folder_picker' => array(
      'arguments' => array(
        'text_element' => NULL,
      ),
      'file' => 'cmis_browser.theme.inc',
    ),
  );
}

/**
 * Implementation of hook_form().
 * 
 */
function cmis_browser_browse_form($form, &$form_state) {
  $parts = explode('/', $_GET['q']);
  $path = implode('/', array_slice($parts, 2));

  //TODO: Removing autocomplete as a buggy (and not-so-useful) feature. Need to replace with search.

  /*
  $form['path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path'),
    '#default_value' => '/'.  $path,
    '#autocomplete_path' => 'cmis/autocomplete',
    '#size' => 50,
    //'#theme' => 'cmis_browser_folder_picker',
    );

  $form['submit'] = array(
    '#type' => 'submit',
    '#name' => 'browse',
    '#default_value' => 'Browse',
  );

  return $form;
  */
}

/**
 * Implementation of hook_form_submit
 * 
 */
function cmis_browser_browse_form_submit($form, &$form_state) {
  unset($form_state['storage']);
  $form_state['redirect'] = 'cmis/browser' . $form_state['values']['path'];
}

/**
 * Implementation of hook_form()
 * 
 */
function cmis_browser_actions_form($form_state) {
  $form['#attributes']['enctype'] = 'multipart/form-data';
  $form['actions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Actions'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['actions']['folder_create'] = array(
    '#type' => 'fieldset',
    '#title' => t('Create folder'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['actions']['folder_create']['folder_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Folder name'),
  );
  $form['actions']['folder_create']['folder_create_button'] = array(
    '#type' => 'submit',
    '#name' => 'folder_create_action',
    '#value' => t('Create new folder'),
  );
  $form['actions']['content_create'] = array(
    '#type' => 'fieldset',
    '#title' => t('Create content'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['actions']['content_create']['content_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#size' => 70,
  );
  $form['actions']['content_create']['content_body'] = array(
    '#type' => 'textarea',
    '#title' => t('Content'),
  );
  $form['actions']['content_create']['content_create_button'] = array(
    '#type' => 'submit',
    '#name' => 'content_create_action',
    '#default_value' => 'Create',
  );
  $form['actions']['content_upload'] = array(
    '#type' => 'fieldset',
    '#title' => t('Upload content'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['actions']['content_upload']['file'] = array(
    '#type' => 'file',
    '#title' => t('Local file'),
  );
  $form['actions']['content_upload']['content_upload_button'] = array(
    '#type' => 'submit',
    '#name' => 'content_upload_action',
    '#value' => t('Upload'),
  );
  return $form;
}

/**
 * Implementation of hook_form_submit().
 * 
 */
function cmis_browser_actions_form_submit($form, &$form_state) {
  module_load_include('content_create.inc', 'cmis_browser');
  $path = rawurlencode('/' . implode('/', array_slice(explode('/', $_GET['q']), 2)));
  switch ($form_state['clicked_button']['#name']) {
    case 'folder_create_action':
      _cmis_browser_actions_folder_create($path, $form_state['values']['folder_name']);
      break;
    case 'content_create_action':
      _cmis_browser_actions_content_create($path, $form_state['values']['content_name'], $form_state['values']['content_body'], 'text/html');
      break;
    case 'content_upload_action':

      // @todo cleanup uploaded file
      $file = file_save_upload('file');
      if ($file) {
        _cmis_browser_actions_content_create($path, $file->filename, file_get_contents(drupal_realpath($file->uri)), $file->filemime);
      }
      else {
        form_set_error('content_upload', t('Unable to handle uploaded file.'));
      }
      break;
  }
}

Functions

Namesort descending Description
cmis_browser_actions_form Implementation of hook_form()
cmis_browser_actions_form_submit Implementation of hook_form_submit().
cmis_browser_admin_paths Implements hook_admin_paths
cmis_browser_admin_settings
cmis_browser_browse_form Implementation of hook_form().
cmis_browser_browse_form_submit Implementation of hook_form_submit
cmis_browser_menu Implementation of hook_menu().
cmis_browser_theme Register custom themes for cmis_browser module.