@ -59,14 +59,14 @@ function islandora_menu() {
'weight' => 0,
'weight' => 0,
);
);
/* may not need this
/* may not need this
$items['admin/islandora/solution_packs'] = array(
$items['admin/islandora/solution_packs'] = array(
'title' => 'Solution Packs',
'title' => 'Solution Packs',
'description' => 'Install content models and collections required by installed solution packs.',
'description' => 'Install content models and collections required by installed solution packs.',
'page callback' => 'islandora_solution_packs_page',
'page callback' => 'islandora_solution_packs_page',
'access arguments' => array(FEDORA_ADD_DS),
'access arguments' => array(FEDORA_ADD_DS),
'file' => 'admin/islandora.solutionpacks.inc',
'file' => 'admin/islandora.solutionpacks.inc',
'type' => MENU_NORMAL_ITEM,
'type' => MENU_NORMAL_ITEM,
);*/
); */
$items['islandoracm.xsd'] = array(
$items['islandoracm.xsd'] = array(
'title' => 'Islandora Content Model XML Schema Definition',
'title' => 'Islandora Content Model XML Schema Definition',
@ -99,7 +99,7 @@ function islandora_menu() {
'type' => MENU_NORMAL_ITEM,
'type' => MENU_NORMAL_ITEM,
'access arguments' => array(FEDORA_VIEW),
'access arguments' => array(FEDORA_VIEW),
);
);
$items['islandora/object/%'] = array(
$items['islandora/object/%'] = array(
'title' => 'Repository',
'title' => 'Repository',
'page callback' => 'islandora_view_object',
'page callback' => 'islandora_view_object',
@ -111,8 +111,8 @@ function islandora_menu() {
$items['islandora/object/%/add'] = array(
$items['islandora/object/%/add'] = array(
'title' => 'Add to an object',
'title' => 'Add to an object',
'file' => 'includes/add-menu.inc',
// 'file' => 'includes/add-menu.inc',
'page callback' => 'islandora_add_callback ',
'page callback' => 'islandora_add_datastream ',
'page arguments' => array(2),
'page arguments' => array(2),
'type' => MENU_NORMAL_ITEM,
'type' => MENU_NORMAL_ITEM,
'access arguments' => array(FEDORA_ADD_DS)
'access arguments' => array(FEDORA_ADD_DS)
@ -142,7 +142,7 @@ function islandora_menu() {
'type' => MENU_LOCAL_TASK,
'type' => MENU_LOCAL_TASK,
'access arguments' => array(FEDORA_MODIFY_STATE),
'access arguments' => array(FEDORA_MODIFY_STATE),
);
);
$items['islandora/object/%/manage/datastreams'] = array(
$items['islandora/object/%/manage/datastreams'] = array(
'title' => 'Datastreams',
'title' => 'Datastreams',
'page callback' => 'islandora_edit_object',
'page callback' => 'islandora_edit_object',
@ -150,17 +150,17 @@ function islandora_menu() {
'type' => MENU_LOCAL_TASK,
'type' => MENU_LOCAL_TASK,
'access arguments' => array(FEDORA_PURGE),
'access arguments' => array(FEDORA_PURGE),
'weight' => -10,
'weight' => -10,
);
);
$items['islandora/object/%/manage/properties'] = array(
$items['islandora/object/%/manage/properties'] = array(
'title' => 'Properties',
'title' => 'Properties',
'page callback' => 'islandora_edit_properties',
'page callback' => 'islandora_edit_properties',
'page arguments' => array(2),
'page arguments' => array(2),
'type' => MENU_LOCAL_TASK,
'type' => MENU_LOCAL_TASK,
'access arguments' => array(FEDORA_MODIFY_STATE),
'access arguments' => array(FEDORA_MODIFY_STATE),
'weight' => -5,
'weight' => -5,
);
);
$items['islandora/object/%/delete'] = array(
$items['islandora/object/%/delete'] = array(
'title' => 'Purge object',
'title' => 'Purge object',
@ -216,12 +216,9 @@ function islandora_menu() {
return $items;
return $items;
}
}
function islandora_admin_paths_alter(&$paths) {
function islandora_admin_paths_alter(&$paths) {
$paths['*/manage*'] = TRUE;
$paths['*/manage*'] = TRUE;
}
}
/**
/**
@ -346,8 +343,8 @@ function islandora_edit_object($object_id) {
return $output;
return $output;
}
}
function islandora_edit_properties($object_id){
function islandora_edit_properties($object_id) {
return 'edit properties '.$object_id;
return 'edit properties ' . $object_id;
}
}
/**
/**
@ -444,11 +441,11 @@ function islandora_view_default_object() {
*
*
* @return string
* @return string
*/
*/
function islandora_view_object($object_id) {
function islandora_view_object($object_id = NULL ) {
//return $object_id;
//return $object_id;
if (!isset($object_id)) {
if (!isset($object_id)) {
drupal_set_message(t('Cannot view object, object id not set') );
$object_id = variable_get('islandora_repository_pid', 'islandora:root' );
return;
// return;
}
}
$page_number = (empty($_GET['page'])) ? '1' : $_GET['page'];
$page_number = (empty($_GET['page'])) ? '1' : $_GET['page'];
@ -474,7 +471,7 @@ function islandora_view_object($object_id) {
foreach ($arr as $key => $value) {
foreach ($arr as $key => $value) {
$output .= $value; //if we have multiple modules handle one cmodel we need to iterate over multiple
$output .= $value; //if we have multiple modules handle one cmodel we need to iterate over multiple
}
}
return $output;
return $output;
}
}
/**
/**
@ -487,7 +484,7 @@ function islandora_islandora_view_object($object) {
$supported_models = islandora_get_types();
$supported_models = islandora_get_types();
$output = "";
$output = "";
foreach ($object->models as $model) {
foreach ($object->models as $model) {
if (isset($supported_models[$model][ISLANDORA_VIEW_HOOK]) && (boolean)$supported_models[$model][ISLANDORA_VIEW_HOOK] === TRUE) {//another module is handling the view
if (isset($supported_models[$model][ISLANDORA_VIEW_HOOK]) && (boolean) $supported_models[$model][ISLANDORA_VIEW_HOOK] === TRUE) {//another module is handling the view
return;
return;
}
}
}
}
@ -550,7 +547,7 @@ function islandora_permission() {
}
}
/**
/**
*
* Not implemented
* @param string $object_id
* @param string $object_id
* @return type
* @return type
*/
*/
@ -559,14 +556,14 @@ function islandora_add_datastream($object_id) {
drupal_set_message(t('Cannot add datastream to object, object id not set'));
drupal_set_message(t('Cannot add datastream to object, object id not set'));
return;
return;
}
}
//send message to synapse
$object = islandora_get_object($object_id);
$object = new IslandoraObject($object_id);
if (isset($object)) {
$form = drupal_get_form('islandora_add_datastream_form', $object);
if (!isset($object)) {
drupal_set_title($object->label);
drupal_set_message(t('Could not remove object, object not found'));
return drupal_render($form);
return;
}
}
module_invoke_all('islandora_add_datastream', $object); //allow submodules to handle add datastream based on object type
return "";
// hook form alter might be enough heremodule_invoke_all('islandora_add_datastream', $object); //allow submodules to handle add datastream based on object type
}
}
function islandora_preprocess_islandora_default(&$variables) {
function islandora_preprocess_islandora_default(&$variables) {
@ -587,14 +584,131 @@ function islandora_preprocess_islandora_default(&$variables) {
}
}
}
}
function islandora_get_object($object_id) {
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
try {
$restConnection = new RestConnection($user);
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
} catch (Exception $e) {
drupal_set_message(t('Error getting Islandora object %s', array('%s' => $object_id)), 'error');
return NULL;
}
return $fedora_object;
}
/**
* Builds the default add a datastream form.
* @param array $form
* @param array $form_state
* @param Object $islandora_object
* @return type
*/
function islandora_add_datastream_form($form, &$form_state, $islandora_object) {
module_load_include('inc', 'islandora', 'includes/datastream');
$form = islandora_get_add_datastream_form($islandora_object->id, $form_state);
return $form;
}
/**
* Default implmentation currently only does M (managed datastreams)
* other modules can hook form alter to add other functionality
* @global string $base_url
* @global object $user
* Drupal user
* @param array $form
* @param array $form_state
* @return type
*/
function islandora_add_datastream_form_submit($form, &$form_state) {
global $base_url;
if (!empty($form_state['submit']) && $form_state['submit'] == 'OK') {
$form_state['rebuild'] = TRUE;
return;
}
$file = $form_state['values']['add-stream-file-location'];
$file = drupal_realpath($file);
$object_id = $form_state['values']['pid'];
$dsid = $form_state['values']['stream_id'];
$ds_label = $form_state['values']['stream_label']; // Add the file extention to the end of the label.;
//$dformat = $mimetype->getType($file);
$controlGroup = "M";
//if ($dformat == 'text/xml') {
// $controlGroup = 'X';
//}
global $user;
try {
$restConnection = new RestConnection($user);
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
$ds = $fedora_object->constructDatastream($dsid, $controlGroup);
$ds->label = $ds_label;
$ds->setContentFromFile($file);
$fedora_object->ingestDatastream($ds);
$d_file = file_load($form_state['values']['fid']);
file_delete($d_file);
} catch (exception $e) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
return;
}
$form_state['rebuild'] = TRUE;
}
/**
* validates this datastream id against its allowed mimetypes in the dscomposite
* of its content models.
* @param array $form
* @param array $form_state
* @return boolean
*/
function islandora_add_datastream_form_validate($form, &$form_state) {
module_load_include('inc', 'islandora', 'includes/MimeClass');
$mimetype = new MimeClass();
if ($form_state['clicked_button']['#value'] == 'OK') {
$form_state['rebuild'] = TRUE;
return;
}
$dsid = $form_state['values']['stream_id'];
$dsLabel = $form_state['values']['stream_label'];
if (strlen($dsid) > 64) {
form_set_error('', t('Data stream ID cannot be more than 64 characters.'));
return FALSE;
}
if (!(preg_match("/^[a-zA-Z]/", $dsid))) {
form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid))));
return FALSE;
}
if (strlen($dsLabel) > 64) {
form_set_error('', t('Data stream Label cannot be more than 64 characters.'));
return FALSE;
}
if (strpos($dsLabel, '/')) {
form_set_error('', t('Data stream Label cannot contain a "/".'));
return FALSE;
}
$mimetype = new MimeClass();
$unused_dsids = islandora_get_unused_dsids($form_state['values']['pid']);
$types_allowed = $unused_dsids[$dsid];
$arr = array();
foreach ($types_allowed as $type) {
$arr[] = $mimetype->getExtension($type);
}
$file = file_save_upload('add-stream-file-location', array('file_validate_extensions' => $arr));
if ($file) {
$form_state['values']['add-stream-file-location'] = $file->uri;
$form_state['values']['fid'] = $file->fid; //so we can load it to delete later
}
else {
form_set_error('add-stream-file-location', t('There was no file uploaded'));
}
}
function islandora_preprocess_islandora_default_edit(&$variables) {
function islandora_preprocess_islandora_default_edit(&$variables) {
$islandora_object = $variables['islandora_object'];
$islandora_object = $variables['islandora_object'];
//module_load_include('inc', 'islandora', 'includes/datastream');
//$test = '';
//$dsids = islandora_add_datastream_form($islandora_object->id, $test);
global $base_url;
global $base_url;
$datastreams = array();
$datastreams = array();
$variables['islandora_editmetadata_url'] = $base_url . '/islandora/edit_form/' . $islandora_object->id;
$variables['islandora_editmetadata_url'] = $base_url . '/islandora/edit_form/' . $islandora_object->id;
$variables['add_datastream_form'] = drupal_get_form('islandora_add_datastream_form', $islandora_object);
foreach ($islandora_object as $ds) {
foreach ($islandora_object as $ds) {
$datastreams['download_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/download';
$datastreams['download_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/download';
$datastreams['view_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/view';
$datastreams['view_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/view';