MENU_NORMAL_ITEM, 'title' => t('Create CMIS Content'), 'page callback' => 'cmis_content_create', 'access callback' => 'user_access', 'access arguments' => array('access cmis'), ); $items['cmis/get'] = array( 'type' => MENU_CALLBACK, 'page callback' => 'cmis_content_get', 'access callback' => 'user_access', 'access arguments' => array('access cmis'), ); $items['cmis/block_settings_more_items_js'] = array( 'page callback' => 'cmis_block_settings_more_items_js', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } /** * Register custom themes for CMIS module. */ function cmis_content_theme() { return array( 'cmis_content_create_form' => array( 'arguments' => array('form' => null), ), 'cmis_content_block_settings' => array( 'arguments' => array('form' => NULL), ) ); } /** * Custom theme for CMIS content creation form. */ function theme_cmis_content_create_form($form) { $rows = array( array( drupal_render($form['create']['path']), ), array( drupal_render($form['create']['name']), ), array( drupal_render($form['create']['content']), ), array( drupal_render($form['create']['submit']), ) ); $header = array(''); $output = theme('table', $header, $rows); $output .= drupal_render($form); return $output; } /** * Custom theme for CMIS document view block settings form * TODO: Implement Add/Delete/Order here (hint: use drupal_add_tabledrag for order) */ function theme_cmis_content_block_settings($form){ return drupal_render($form); } /** * Implementation of CMIS content creation page. * Allows user to create a text or html file and upload it to CMIS repository. * Required input from user is the space path where the content will be stored. * Optional inputs include content description, author etc. */ function cmis_content_create() { drupal_add_css(drupal_get_path('module', 'cmis_content').'/cmis_content.css'); $contents = ''; $contents .= drupal_get_form('cmis_content_create_form'); return $contents; } /** * CMIS content creation form builder. */ function cmis_content_create_form($form_state) { $parts = explode('/', $_GET['q']); $path = implode('/', array_slice($parts, 2)); $form['#theme'] = 'cmis_content_create_form'; $form['create']['path'] = array( '#type' => 'textfield', '#title' => t('Path'), '#default_value' => '/' . $path, '#autocomplete_path' => 'cmis/autocomplete', '#size' => 70 ); $form['create']['name'] = array( '#type' => 'textfield', '#title' => t('Name'), '#size' => 70 ); $form['create']['content'] = array( '#type' => 'textarea', '#title' => t('Content') ); $form['create']['submit'] = array( '#type' => 'submit', '#name' => 'browse', '#default_value' => 'Create', ); return $form; } /** * Handle content create form submission. */ function cmis_content_create_form_submit($form, &$form_state) { module_load_include('api.inc', 'cmis'); $path = $form_state['values']['path']; $name = $form_state['values']['name']; $content = $form_state['values']['content']; // Process the form // Invoke Utility Service to get content id $repository = cmisapi_getRepositoryInfo(); if (!$path) { $folderId_parts = explode('/', $repository->rootFolderId); $path = '/'.end($folderId_parts); } $cmis_object = cmisapi_getProperties($repository->repositoryId, drupal_urlencode($path)); if (false === $cmis_object) { drupal_set_message(t('Failed to locate the target space with path '.$path)); $form_state['redirect'] = 'cmis/create'; } else { if ($cmis_object->type == 'folder') { $objectId = cmisapi_createDocument($repository->repositoryId, 'document', array('content-type' => 'text/html', 'title' => $name), $cmis_object->id, $content); if ($objectId) { drupal_set_message('CMIS content '.$name.' has been created.'); $form_state['redirect'] = 'cmis/browser'.$path; } else { drupal_set_message('Unable to create '.$name.' content.', 'error'); $form_state['redirect'] = 'cmis/create'; return false; } } else { drupal_set_message(t('Error when locating the target space '.$path, 'error')); $form_state['redirect'] = 'cmis/create'; } } } /** * Handle content download * @todo: input validation */ function cmis_content_get() { module_load_include('api.inc', 'cmis'); $objectId = urldecode($_GET['id']); $repository = cmisapi_getRepositoryInfo(); $object = cmisapi_getProperties($repository->repositoryId, $objectId); $content = cmisapi_getContentStream($repository->repositoryId, $objectId); if (ob_get_level()) { ob_end_clean(); } drupal_set_header('Cache-Control: no-cache, must-revalidate'); drupal_set_header('Content-type: '.$object->contentMimeType); drupal_set_header('Content-Disposition: attachment; filename="'.$object->title.'"'); print($content); exit(); } /** * Implementation of hook_block() for CMIS content module. */ function cmis_content_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': // If $op is "list", we just need to return a list of block descriptions. // This is used to provide a list of possible blocks to the administrator, // end users will not see these descriptions. $blocks[0] = array( 'info' => t('CMIS Repository Document View'), ); // A block can provide default settings. In this case we'll enable the // block and make it visible only on the 'node/*' pages. //$blocks[1] = array( // 'info' => t('Example: empty block'), // 'status' => TRUE, // 'weight' => 0, // 'visibility' => 1, // 'pages' => 'node/*', //); return $blocks; case 'configure': // If $op is "configure", we need to provide the administrator with a // configuration form. The $delta parameter tells us which block is being // configured. In this example, we'll allow the administrator to customize // the text of the first block. $form = array( '#cache' => TRUE, ); if ($delta == 0) { // All we need to provide is a text field, Drupal will take care of // the other block configuration options and the save button. $form['cmis_target_document_items'] = array( '#tree' => TRUE, '#prefix' => '