. */ //Permissions define('FEDORA_VIEW', 'view fedora repository'); define('FEDORA_METADATA_EDIT', 'edit fedora metadata'); define('FEDORA_ADD_DS', 'add fedora datastreams'); define('FEDORA_INGEST', 'ingest fedora objects'); define('FEDORA_PURGE', 'delete fedora objects and datastreams'); define('FEDORA_MODIFY_STATE', 'modify fedora state'); define('FEDORA_MANAGE', 'manage fedora items'); //hooks define('ISLANDORA_VIEW_HOOK', 'islandora_view_object'); define('ISLANDORA_EDIT_HOOK', 'islandora_edit_object'); /** * Implementation of hook_menu. * we need some standard entry points so we can have consistent urls for different Object actions */ function islandora_menu() { $items = array(); $items['admin/islandora'] = array( 'title' => 'Islandora Configuration', 'description' => "Configure Islandora's interaction with Fedora", 'access arguments' => array('administer site configuration'), 'type' => MENU_NORMAL_ITEM, ); $items['admin/islandora/configure'] = array( 'title' => 'Islandora Configuration', 'description' => 'Enter the Islandora collection information here.', 'page callback' => 'drupal_get_form', 'page arguments' => array('islandora_repository_admin'), 'file' => 'admin/islandora.admin.inc', 'access arguments' => array('administer site configuration'), 'type' => MENU_NORMAL_ITEM, 'weight' => 0, ); /* may not need this $items['admin/islandora/solution_packs'] = array( 'title' => 'Solution Packs', 'description' => 'Install content models and collections required by installed solution packs.', 'page callback' => 'islandora_solution_packs_page', 'access arguments' => array(FEDORA_ADD_DS), 'file' => 'admin/islandora.solutionpacks.inc', 'type' => MENU_NORMAL_ITEM, ); */ $items['islandoracm.xsd'] = array( 'title' => 'Islandora Content Model XML Schema Definition', 'page callback' => 'islandora_display_schema', 'page arguments' => array('islandoracm.xsd'), 'type' => MENU_CALLBACK, 'access arguments' => array(FEDORA_VIEW), ); $items['collection_policy.xsd'] = array( 'title' => 'Islandora Content Model XML Schema Definition', 'page callback' => 'islandora_display_schema', 'page arguments' => array('collection_policy.xsd'), 'type' => MENU_CALLBACK, 'access arguments' => array(FEDORA_VIEW), ); $items['islandora/ingest/%'] = array( 'title' => 'Ingest object', 'page callback' => 'islandora_ingest_callback', 'page arguments' => array(2), 'file' => 'includes/ingest-menu.inc', 'type' => MENU_CALLBACK, 'access arguments' => array(FEDORA_INGEST), ); $items['islandora'] = array( 'title' => 'Islandora Repository', 'page callback' => 'islandora_view_default_object', 'type' => MENU_NORMAL_ITEM, 'access arguments' => array(FEDORA_VIEW), ); $items['islandora/object/%'] = array( 'title' => 'Repository', 'page callback' => 'islandora_view_object', 'page arguments' => array(2), 'type' => MENU_NORMAL_ITEM, 'access arguments' => array(FEDORA_VIEW), ); $items['islandora/object/%/view'] = array( 'title' => 'View', //'page callback' => 'islandora_view_object', 'page arguments' => array(2), 'type' => MENU_DEFAULT_LOCAL_TASK, 'access arguments' => array(FEDORA_VIEW), 'weight' => -10 ); $items['islandora/object/%/view/default'] = array( 'title' => 'View', 'page callback' => 'islandora_view_object', 'page arguments' => array(2), 'type' => MENU_LOCAL_TASK, 'access arguments' => array(FEDORA_VIEW), 'weight' => -10, ); $items['islandora/object/%/manage'] = array( 'title' => 'Manage', 'page callback' => 'islandora_edit_object', 'page arguments' => array(2), 'type' => MENU_LOCAL_TASK, 'access arguments' => array(FEDORA_MODIFY_STATE), ); $items['islandora/object/%/manage/datastreams'] = array( 'title' => 'Datastreams', //'page callback' => 'islandora_edit_object', 'page arguments' => array(2), 'type' => MENU_DEFAULT_LOCAL_TASK, 'access arguments' => array(FEDORA_PURGE), 'weight' => -10, ); $items['islandora/object/%/manage/properties'] = array( 'title' => 'Properties', 'page callback' => 'drupal_get_form', 'file' => 'includes/object_properties.inc', 'page arguments' => array('islandora_edit_properties_form', 2), 'type' => MENU_LOCAL_TASK, 'access arguments' => array(FEDORA_MODIFY_STATE), 'weight' => -5, ); $items['islandora/object/%/delete'] = array( 'title' => 'Purge object', 'page callback' => 'islandora_purge_object', 'page arguments' => array(2), 'type' => MENU_CALLBACK, 'access arguments' => array(FEDORA_PURGE), ); $items['islandora/object/%/manage/datastreams/add'] = array( 'title' => 'Add a datastream', 'file' => 'includes/datastream.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('islandora_add_datastream_form', 2), 'type' => MENU_NORMAL_ITEM, 'access arguments' => array(FEDORA_ADD_DS) ); $items['islandora/object/%/manage/datastreams/add/autocomplete'] = array( 'file' => 'includes/datastream.inc', 'page callback' => 'islandora_datastream_autocomplete_callback', 'page arguments' => array(2), 'type' => MENU_CALLBACK, 'access arguments' => array(FEDORA_ADD_DS) ); $items['islandora/object/%/datastream/%'] = array( 'title' => 'View datastream', 'page callback' => 'islandora_datastream_as_attachment', 'page arguments' => array(2, 4), 'type' => MENU_CALLBACK, 'file' => 'includes/datastream.inc', 'access arguments' => array(FEDORA_VIEW), ); $items['islandora/object/%/datastream/%/view'] = array( 'title' => 'View datastream', 'page callback' => 'islandora_datastream_as_attachment', 'page arguments' => array(2, 4), 'type' => MENU_CALLBACK, 'file' => 'includes/datastream.inc', 'access arguments' => array(FEDORA_VIEW), ); $items['islandora/object/%/datastream/%/download'] = array( 'title' => 'Download datastream', 'page callback' => 'islandora_datastream_as_attachment', 'page arguments' => array(2, 4), 'type' => MENU_CALLBACK, 'file' => 'includes/datastream.inc', 'access arguments' => array(FEDORA_VIEW), ); $items['islandora/object/%/datastream/%/edit'] = array( 'title' => 'Edit datastream', 'page callback' => 'islandora_edit_datastream', 'page arguments' => array(2, 4), 'type' => MENU_CALLBACK, 'access arguments' => array(FEDORA_METADATA_EDIT), ); $items['islandora/object/%/datastream/%/delete'] = array( 'title' => 'Purge data stream', 'page callback' => 'islandora_purge_datastream', 'page arguments' => array(2, 4), 'type' => MENU_CALLBACK, 'access arguments' => array(FEDORA_PURGE), ); return $items; } function islandora_admin_paths_alter(&$paths) { $paths['*/manage*'] = TRUE; } /** * Implements hook_menu_local_tasks_alter(). */ function islandora_menu_local_tasks_alter(&$data, $router_item, $root_path) { // Add action link 'islandora/object/%/manage/datastreams'. if ($root_path == 'islandora/object/%/manage') { $object_id = $router_item['page_arguments'][0]; $item = menu_get_item("islandora/object/$object_id/manage/datastreams/add"); if ($item['access']) { $data['actions']['output'][] = array( '#theme' => 'menu_local_action', '#link' => $item, ); } } } /** * determines whether we can see the object or not * checks PID namespace permissions, and user permissions * @global object $user * @param string $op * @param string $pid * * @return boolean */ function islandora_node_access($op, $pid = NULL, $as_user = NULL) { //$returnValue = FALSE; if ($pid == NULL) { $pid = variable_get('fedora_repository_pid', 'islandora:root'); } $isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE); $namespace_access = NULL; if (!$isRestricted) { $namespace_access = TRUE; } else { $pid_namespace = substr($pid, 0, strpos($pid, ':') + 1); //Get the namespace (with colon) $allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); $namespace_access = in_array($pid_namespace, $allowed_namespaces); } return ($namespace_access && user_access($op, $as_user)); } /** * Gives the option of deleting or purging and object. * * The default behaviour is to purge the object to reduce maintenance. * If a solution pack wants to change this behaviour and have the object set to deleted then * it can respond to the 'islandora_pre_purge_object' hook with an array containing the pair * 'delete' => TRUE. * Once the object has been deleted/purged then a second call lets the solution packs know that * the object has been dealt with. In this call the object id and content models are sent out so * that the solution packs can act on this news. There is no guarantee that the object still exists * and so the object object isn't sent. * * @param string $object_id * ID of the object * @return type */ function islandora_purge_object($object_id) { module_load_include('inc', 'islandora', 'RestConnection'); global $user; if (!isset($object_id)) { drupal_set_message(t('Cannot remove object, object id not set')); return; } 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 %e', array('%s' => $object_id, '%e' => $e)), 'error'); return ""; } if (!isset($fedora_object)) { drupal_set_message(t('Could not remove object, object not found')); return; } $content_models = $fedora_object->models; $arr = module_invoke_all('islandora_pre_purge_object', $fedora_object); //notify modules of pending deletion if (isset($arr['delete']) && $arr['delete']) { try { $fedora_object->delete(); } catch (Exception $e) { drupal_set_message(t('Error deleting Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error'); return ""; } } else { try { $restConnection->repository->purgeObject($object_id); } catch (Exception $e) { drupal_set_message(t('Error purging Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error'); return ""; } } module_invoke_all('islandora_post_purge_object', $object_id, $content_models); //notify modules post deletion drupal_goto('islandora'); } /** * returns an array listing object types provided by sub modules * @return array */ function islandora_get_types() { return module_invoke_all('islandora_get_types'); } /** * a function to call other modules edit page. If there are not any modules * that handle this function this module will build a default page. * @global object $user * @param string $object_id * @return string */ function islandora_edit_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""; } drupal_alter('islandora_edit_object', $fedora_object); $arr = module_invoke_all('islandora_edit_object', $fedora_object); $output = ""; foreach ($arr as $key => $value) { $output .= $value; //if we have multiple modules handle one cmodel we need to iterate over multiple } //we could do another module invoke all here to build the edit tab with a default implemented in this module? return $output; } /** * edit properties form * @param type $object_id * @return string */ function islandora_edit_properties($object_id) { $object = islandora_get_object($object_id); if (isset($object)) { module_load_include('inc', 'islandora', 'includes/object_properties'); $form = drupal_get_form('islandora_edit_properties_form', $object); drupal_set_title($object->label); return drupal_render($form); } return ""; } /** * builds a default page for the edit tab * * @param object $fedora_object * A tuque Fedora Object */ function islandora_islandora_edit_object($fedora_object) { $supported_models = islandora_get_types(); $output = ""; foreach ($fedora_object->models as $model) { if (isset($supported_models[$model][ISLANDORA_EDIT_HOOK]) && $supported_models[$model][ISLANDORA_EDIT_HOOK] == TRUE) {//another module is handling the view return; } } $output = theme('islandora_default_edit', array('islandora_object' => $fedora_object)); return array('Default Edit output' => $output); } /** * Gives the option of purging or deleting a datastream. * * The default behaviour is to purge the datastream but this can be overridden using the * 'islandora_pre_purge_datastream' hook. The returned array can include a 'block' => TRUE * pair which will prevent the datastream from being deleted if it particularly needed for * a certain function. Returning 'delete' => TRUE will cause the datastream to be put into * a deleted state. * * @param string $object_id * ID of the object * @param string $datastream_id * ID of the datastream * */ function islandora_purge_datastream($object_id, $datastream_id) { module_load_include('inc', 'islandora', 'RestConnection'); global $user; if (!isset($datastream_id)) { drupal_set_message(t('Cannot remove datastream, datastream id not set')); return; } 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 %e', array('%s' => $object_id, '%e' => $e)), 'error'); return ""; } if (!isset($fedora_object)) { drupal_set_message(t('Could not remove object, object not found')); return; } if (!isset($fedora_object)) { drupal_set_message(t('Could not remove object, object not found')); return; } $arr = module_invoke_all('islandora_pre_purge_datastream', $fedora_object, $datastream_id); //notify modules of pending deletion so we can update rels etc if (isset($arr['block']) && $arr['block']) { drupal_set_message(t('Purging of the %d datastream was blocked', array('%d' => $datastream_id)), 'warning'); return; } if (isset($arr['delete']) && $arr['delete']) { try { $datastream = new FedoraDatastream($datastream_id, $fedora_object, $restConnection->repository); $datastream->state = 'D'; } catch (Exception $e) { drupal_set_message(t('Error deleting %s datastream from Islandora object %o %e', array('%s' => $datastream_id, '%o' => $object_id, '%e' => $e)), 'error'); return; } } else { try { $fedora_object->purgeDatastream($datastream_id); } catch (Exception $e) { drupal_set_message(t('Error purging %s datastream from Islandora object %o %e', array('%s' => $datastream_id, '%o' => $object_id, '%e' => $e)), 'error'); return; } } module_invoke_all('islandora_post_purge_datastream', $fedora_object, $datastream_id); //notify modules post deletion drupal_set_message(t('%d datastream sucessfully purged from Islandora object %o', array('%d' => $datastream_id, '%o' => $object_id))); drupal_goto('islandora/object/' . $object_id); } function islandora_view_default_object() { $pid = variable_get('islandora_repository_pid', 'islandora:root'); drupal_goto("islandora/object/$pid"); } /** * The view entry point. modules should implement hook_islandora_view_object for the Fedora Content models that * their modules want to provide a view for. * @global object $user * @param string $object_id * * @return string */ function islandora_view_object($object_id = NULL) { //return $object_id; if (!isset($object_id)) { $object_id = variable_get('islandora_repository_pid', 'islandora:root'); //return; } $page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; $page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize']; 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""; } drupal_alter('islandora_view_object', $fedora_object); //modify object if required before it is passed along $arr = module_invoke_all('islandora_view_object', $fedora_object, $user, $page_number, $page_size); //allow submodules to decide how to handle content base on object type if (empty($arr)) { //TODO: make sure we iterate over the array as they will be more then one cmodel per object drupal_set_message(t('there was an error loading the view for islandora object %s', array('%s' => $object_id)), 'error'); return ""; } //module_invoke_all(islandora_display($arr)), $output = ""; foreach ($arr as $key => $value) { $output .= $value; //if we have multiple modules handle one cmodel we need to iterate over multiple } return $output; } /** * the default view hook. If there are no modules registered to handle this objects cmodels or there are * not any cmodels specified this will create a default display. * @param string $object_id * @return string */ function islandora_islandora_view_object($object) { $supported_models = islandora_get_types(); $output = ""; 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 return; } } $output = theme('islandora_default', array('islandora_object' => $object)); return array('Default Output' => $output); } /** * Theme registry function * @return array */ function islandora_theme() { return array( 'islandora_default' => array( 'template' => 'islandora-object', 'variables' => array('islandora_object' => NULL), ), 'islandora_default_edit' => array( 'template' => 'islandora-object-edit', 'variables' => array('islandora_object' => NULL), ), ); } /** * drupal hook_permissions function * @return array */ function islandora_permission() { return array( FEDORA_VIEW => array( 'title' => t('View Fedora Repository objects and datastreams'), 'description' => t('Users with this permission will be allowed to view Fedora objects and datastreams. Unless Fedora XACML security policies limits this functionality to certain objects.') ), FEDORA_ADD_DS => array( 'title' => t('Add Fedora streams to Fedora objects'), 'description' => t('Users with this permission will be allowed to add datastreams to Fedora objects. Unless Fedora XACML security policies limits this functionality to certain objects.') ), FEDORA_METADATA_EDIT => array( 'title' => t('Edit Fedora Metadata'), 'description' => t('Users with this permission will be allowed to edit Fedora Metadata streams') ), FEDORA_INGEST => array( 'title' => t('Create new Fedora objects'), 'description' => t('Users with this permission will be allowed to create new objects in the Fedora repository') ), FEDORA_PURGE => array( 'title' => t('Permanently remove objects from the Fedora repository'), 'description' => t('Users with this permission will be allowed to Permantly remove objects from the Fedora repository.') ), FEDORA_MODIFY_STATE => array( 'title' => t('Change a Fedora objects state'), 'description' => t('Users with this permission will be allowed to change a Fedora objects state.') ), FEDORA_MANAGE => array( 'title' => t('View Fedora Manage tabs'), 'description' => t('Users with this permission will be allowed to view fedora manage manage tabs.') ) ); } /** * preprocess for the default view template * @global string $base_url * @param array $variables */ function islandora_preprocess_islandora_default(&$variables) { drupal_add_js('misc/form.js'); drupal_add_js('misc/collapse.js'); $islandora_object = $variables['islandora_object']; module_load_include('inc', 'islandora', 'includes/islandora_dublin_core'); module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/datastream'); $variables['parent_collections'] = islandora_get_datastream_parents($islandora_object); $datastreams = array(); foreach ($islandora_object as $ds) { $pid = $islandora_object->id; $id = $ds->id; $label = $ds->label; $download_path = islandora_datastream_get_url($ds, 'download'); $datastreams[$id]['id'] = $id; $datastreams[$id]['label'] = $label; $datastreams[$id]['label_link'] = l($label, $download_path); $datastreams[$id]['download_url'] = $download_path; $datastreams[$id]['mimetype'] = $ds->mimetype; $datastreams[$id]['size'] = islandora_datastream_get_human_readable_size($ds); $datastreams[$id]['created_date'] = $ds->createdDate->format("Y-m-d"); $datastreams[$id]['class'] = strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $id)); } $variables['datastreams'] = $datastreams; try { $dc = $islandora_object['DC']->content; //$dc_xml = simplexml_load_string($dc); $dc_object = Dublin_Core::import_from_xml_string($dc); } catch (Exception $e) { drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error'); } $variables['dc_array'] = $dc_object->as_formatted_array(); $variables['islandora_dublin_core'] = $dc_object; $variables['islandora_object_label'] = $islandora_object->label; global $base_url; if (isset($islandora_object['TN'])) { $variables['islandora_thumbnail_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/TN/view'; } } /** * a helper function to get a connection and return an object * @global object $user * @param string $object_id * @return FedoraObject */ 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; } /** * preprocess the edit template * @global string $base_url * @param array $variables * theme variables for the edit template */ function islandora_preprocess_islandora_default_edit(&$variables) { $islandora_object = $variables['islandora_object']; global $base_url; $datastreams = array(); $variables['islandora_editmetadata_url'] = $base_url . '/islandora/edit_form/' . $islandora_object->id; module_load_include('inc', 'islandora', 'includes/datastream'); module_load_include('inc', 'islandora', 'includes/utilities'); // $variables['add_datastream_form'] = drupal_get_form('islandora_add_datastream_form', $islandora_object->id); $header = array( array('data' => t('ID')), array('data' => t('Label')), array('data' => t('Type')), array('data' => t('Mime type')), array('data' => t('Size')), array('data' => t('Operations'), 'colspan' => '2'), //array('data' => t('Delete')), ); $table_attributes = array('class' => array('manage-datastreams')); $rows = array(); foreach ($islandora_object as $ds) { $rows[] = array( array('class' => 'datastream-id', 'data' => l($ds->id, islandora_datastream_get_url($ds, 'view'))), array('class' => 'datastream-label', 'data' => $ds->label), array('class' => 'datastream-control', 'data' => islandora_control_group_to_human_readable($ds->controlGroup)), array('class' => 'datastream-mime', 'data' => $ds->mimeType), array('class' => 'datastream-size', 'data' => islandora_datastream_get_human_readable_size($ds)), array('class' => 'datastream-download', 'data' => l(t('download'), islandora_datastream_get_url($ds, 'download'))), array('class' => 'datastream-delete', 'data' => l(t('delete'), $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/delete')), ); } $caption = $islandora_object->label . ' - ' . $islandora_object->id; $table = array('colgroups' => NULL, 'sticky' => TRUE, 'empty' => 'Error loading datastreams', 'caption' => $caption, 'header' => $header, 'rows' => $rows, 'attributes' => $table_attributes); $variables['datastream_table'] = theme_table($table); }