array (
'name' => t('CMIS Alfresco'),
'module' => 'cmis_alfresco',
'description' => t('Alfresco CMIS client'),
),
);
}
/**
* Implementation of hook_menu() for Alfresco CMIS module.
* Add Alfresco setting link to admin menu.
*/
function cmis_alfresco_menu() {
$items['admin/settings/cmis/alfresco'] = array (
'title' => 'Alfresco Settings',
'description' => 'Connection settings to Alfresco repository',
'page callback' => 'drupal_get_form',
'page arguments' => array ('cmis_alfresco_admin_settings'),
'access callback' => 'user_access',
'access arguments' => array ('administer alfresco'),
);
return $items;
}
/**
* Prepare and generate entry form for Alfresco settings.
*/
function cmis_alfresco_admin_settings() {
$form['cmis_alfresco_settings'] = array (
'#type' => 'fieldset',
'#title' => t('Alfresco CMIS Settings'),
'#description' => t('Settings for Alfreso Server including Server Endpoint, Username and password for connection.'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['cmis_alfresco_settings']['cmis_alfresco_endpoint'] = array (
'#type' => 'textfield',
'#title' => t('Repository endpoint'),
'#description' => t('Specify the Alfresco Endpoint to integrate with.'),
'#default_value' => variable_get('cmis_alfresco_endpoint', 'http://localhost:8080/alfresco'),
);
$form['cmis_alfresco_settings']['cmis_alfresco_user'] = array (
'#type' => 'textfield',
'#title' => t('Repository user'),
'#description' => t('Specify the user name to use to authenticate with the repository.'),
'#default_value' => variable_get('cmis_alfresco_user', 'admin'),
);
$form['cmis_alfresco_settings']['cmis_alfresco_password'] = array (
'#type' => 'password',
'#title' => t('Repository password'),
'#description' => t('Specify the password to use to authenticate with the repository.'),
'#default_value' => ''
);
return system_settings_form($form);
}
/**
* Validate Setting inputs for Alfresco
*/
function cmis_alfresco_admin_settings_validate($form, & $form_state) {
// endpoint is required
$endpoint = $form_state['values']['cmis_alfresco_endpoint'];
if ($endpoint == '') {
form_set_error('cmis_alfresco_endpoint', t('You must specify the Alfresco endpoint.'));
}
// see if the endpoint is okay
/*
$response = drupal_http_request($endpoint);
if ($response->code != 200) {
form_set_error('cmis_alfresco_endpoint', t('Error received from endpoint: ' . $response->code));
}
*/
// user and password are required
if (empty($form_state['values']['cmis_alfresco_user'])) {
form_set_error('cmis_alfresco_user', t('You must specify the repository user.'));
}
if (empty($form_state['values']['cmis_alfresco_password'])) {
form_set_error('cmis_alfresco_password', t('You must specify the repository password.'));
}else {
$form_state['values']['cmis_alfresco_password'] = base64_encode($form_state['values']['cmis_alfresco_password']);
}
/*
* DG: This can't be done with the current API because the values have not been persisted yet
*
// attempt to authenticate
if (cmis_alfresco_utils_get_ticket() == '') {
form_set_error('', t('Could not authenticate with endpoint.'));
} else {
drupal_set_message('Alfresco Repo Info:
' . cmis_alfresco_info());
}
*/
}
/**
* Return permissions for the Alfresco module.
*/
function cmis_alfresco_perm() {
$perms = array (
'administer alfresco',
'access alfresco',
);
return $perms;
}
/**
* Implementation of hook_form_alter for Alfresco CMIS search
* @param $formId
* @param $form
* @return unknown_type
*/
function cmis_alfresco_form_cmis_query_form_alter(& $form, $form_state) {
$opensearch = array (
'#type' => 'fieldset',
'#title' => t('OpenSearch'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$opensearch['cmis_alfresco_opensearch_keyword'] = array (
'#type' => 'textfield',
'#title' => t('Keyword'),
'#description' => t('Search the repository using opensearch support'),
'#attributes' => array (),
);
$opensearch['cmis_alfresco_opensearch_submit'] = array (
'#type' => 'submit',
'#value' => t('Search'),
'#submit' => array ('cmis_alfresco_opensearch'),
);
$form['opensearch'] = $opensearch;
// little hack to prevent form submit on "enter"
drupal_add_js('$(document).ready(function(){
$("#edit-cmis-alfresco-opensearch-keyword").bind("keypress", function(e) {
if(e.keyCode==13)$("#edit-cmis-alfresco-opensearch-submit").click();
});});', 'inline');
}
function cmis_alfresco_opensearch($form, & $form_state) {
$form_state['storage']['query_result'] = cmis_alfresco_open_search($form_state['values']['cmis_alfresco_opensearch_keyword']);
}
/**
* Executes open search and process search return.
* $query CMIS SQL query.
*/
function cmis_alfresco_open_search($keyword, $p = 1) {
module_load_include('utils.inc', 'cmis_alfresco');
module_load_include('utils.inc', 'cmis_alfresco', 'opensearch');
$xml = cmis_alfresco_utils_invoke_service('/api/search/keyword.atom?q=' . urlencode($keyword) . '&p=' . $p, 'ticket');
if (false != $xml) {
// Process the returned XML
$contents = "
Search Results
";
$header = array (t('name'), t('author'), t('last modified'), t('score'));
$file_img = theme('image', drupal_get_path('module', 'alfresco') . '/images/file.png');
$entries = opensearch_utils_process_opensearch_xml($xml, '//D:entry');
foreach ($entries as $entry) {
$summary = $entry->summary;
$score = opensearch_utils_opensearch_xml_get_value($entry, 'relevance:score');
$updated = date_create($entry->updated);
$updatedStr = date_format($updated, 'n/j/Y g:i A');
$alfIcon = $entry->icon;
$documentLink = l($entry->title, 'cmis/get', array ('query' => array ('id' => $entry->id)));
$rows[] = array ('' . $documentLink, $entry->author->name, $updatedStr, $score);
}
//$contents .= '';
$contents .= theme('table', $header, $rows);
$feed = opensearch_utils_process_opensearch_xml($xml, '/D:feed');
$feed = $feed[0];
$total_items = (int) opensearch_utils_opensearch_xml_get_value($feed, 'opensearch:totalResults');
$items_per_page = (int) opensearch_utils_opensearch_xml_get_value($feed, 'opensearch:itemsPerPage');
if (fmod($total_items, $items_per_page) == 0) {
$last_page_number = floor($total_items / $items_per_page);
}
else {
$last_page_number = floor($total_items / $items_per_page) + 1;
}
// Add pagination bar
/* Disabled pagination
$base_search_url = '/cmis/query/?keyword='.$keyword.'&c='.$items_per_page.'&p=';
$contents .= '