Drupal modules for browsing and managing Fedora-based digital repositories.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

636 lines
19 KiB

<?php
/*
* @file
*
* islandora.module: defines paths (drupal menu items) as entry points and acts as a hub for dispatching tasks to other modules.
*
* This file is part of Islandora.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program. If not, see <http ://www.gnu.org/licenses/>.
*/
// 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');
define('ISLANDORA_POST_INGEST_HOOK', 'islandora_ingest_post_ingest');
define('ISLANDORA_PRE_PURGE_OBJECT_HOOK', 'islandora_pre_purge_object');
/**
* Implements 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',
'description' => "Configure settings associated with Islandora.",
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/islandora/configure'] = array(
'title' => 'Configuration',
'description' => 'Configure settings for Islandora.',
'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' => -1,
);
$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_admin',
'access arguments' => array(FEDORA_ADD_DS),
'file' => 'includes/solution_packs.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['islandora/object/%islandora_object/manage/ingest'] = array(
'title' => 'Add an object',
'page callback' => 'islandora_ingest_callback',
'page arguments' => array(2),
'file' => 'includes/ingest-menu.inc',
'type' => MENU_LOCAL_ACTION,
'access callback' => 'islandora_ingest_access_callback',
'access arguments' => array(2, 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/%islandora_object'] = array(
'title' => 'Repository',
'page callback' => 'islandora_view_object',
'page arguments' => array(2),
'type' => MENU_NORMAL_ITEM,
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_VIEW),
);
$items['islandora/object/%islandora_object/view'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
$items['islandora/object/%islandora_object/view/default'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
$items['islandora/object/%islandora_object/manage'] = array(
'title' => 'Manage',
'page callback' => 'islandora_edit_object',
'page arguments' => array(2),
'type' => MENU_LOCAL_TASK,
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_MODIFY_STATE),
);
$items['islandora/object/%islandora_object/manage/datastreams'] = array(
'title' => 'Datastreams',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['islandora/object/%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 callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_MODIFY_STATE),
'weight' => -5,
);
$items['islandora/object/%islandora_object/delete'] = array(
'title' => 'Delete object',
'file' => 'includes/purge.form.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_purge_object', 2),
'type' => MENU_CALLBACK,
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_PURGE),
);
$items['islandora/object/%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_LOCAL_ACTION,
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_ADD_DS)
);
$items['islandora/object/%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 callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_ADD_DS)
);
$items['islandora/object/%islandora_object/datastream/%'] = array(
'title' => 'View datastream',
'page callback' => 'islandora_view_datastream',
'page arguments' => array(2, 4),
'type' => MENU_CALLBACK,
'file' => 'includes/datastream.inc',
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_VIEW),
);
$items['islandora/object/%islandora_object/datastream/%/view'] = array(
'title' => 'View datastream',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['islandora/object/%islandora_object/datastream/%/download'] = array(
'title' => 'Download datastream',
'page callback' => 'islandora_view_datastream',
'page arguments' => array(2, 4, 5),
'type' => MENU_CALLBACK,
'file' => 'includes/datastream.inc',
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_VIEW),
);
$items['islandora/object/%islandora_object/datastream/%/edit'] = array(
'title' => 'Edit datastream',
'page callback' => 'islandora_edit_datastream',
'page arguments' => array(2, 4),
'type' => MENU_CALLBACK,
'file' => 'includes/datastream.inc',
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_METADATA_EDIT),
);
$items['islandora/object/%islandora_object/datastream/%/delete'] = array(
'title' => 'Purge data stream',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_purge_datastream', 2, 4),
'file' => 'includes/purge.form.inc',
'type' => MENU_CALLBACK,
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_PURGE),
);
return $items;
}
/**
* Implements hook_admin_paths().
*/
function islandora_admin_paths() {
$paths = array();
$paths['islandora/object/*/manage*'] = TRUE;
$paths['islandora/object/*/delete'] = TRUE;
$paths['islandora/object/*/datastream/*/edit'] = TRUE;
return $paths;
}
/**
* 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_access_callback($object = NULL, $perm = NULL) {
if (!$object || !$perm) {
return FALSE;
}
$isRestricted = variable_get('islandora_namespace_restriction_enforced', FALSE);
if (!$isRestricted) {
$namespace_access = TRUE;
}
else {
$pid_namespace = substr($object->id, 0, strpos($object->id, ':') + 1); // Get the namespace (with colon)
$allowed_namespaces = explode(" ", variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '));
$namespace_access = in_array($pid_namespace, $allowed_namespaces);
}
return ($namespace_access && user_access($perm));
}
function islandora_init() {
if (path_is_admin(current_path())) {
drupal_add_css(drupal_get_path('module', 'islandora') . '/css/islandora.admin.css');
}
}
/**
* Implements hook_forms().
*/
function islandora_forms($form_id) {
$forms = array();
if (strpos($form_id, 'islandora_solution_pack_form_') !== FALSE) {
$forms[$form_id] = array(
'callback' => 'islandora_solution_pack_form',
);
}
return $forms;
}
/**
* 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) {
if (!$object) {
return drupal_not_found();
}
module_load_include('inc', 'islandora', 'includes/utilities');
// Accumulate the output.
$output = array();
// Call cmodel oriented variants first.
foreach (islandora_build_hook_list(ISLANDORA_EDIT_HOOK, $object->models) as $hook) {
$temp = module_invoke_all($hook, $object);
if (!empty($temp)) {
$output = array_merge_recursive($output, $temp);
}
}
// Add in the default, if we did not get any results.
if (empty($output)) {
$output = islandora_default_islandora_edit_object($object);
}
arsort($output);
drupal_alter(ISLANDORA_EDIT_HOOK, $object, $output);
return implode('', $output);
}
/**
* edit properties form
* @param type $object_id
* @return string
*/
function islandora_edit_properties($object_id) {
$object = islandora_object_load($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_default_islandora_edit_object($fedora_object) {
$output = theme('islandora_default_edit', array(
'islandora_object' => $fedora_object,
));
return array('Default Edit output' => $output);
}
/**
* Page callback for the path "islandora".
*
* Redirects to the view of the object indicated by the Drupal variable
* islandora_repository_pid.
*/
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($fedora_object = NULL) {
module_load_include('inc', 'islandora', 'includes/breadcrumb');
module_load_include('inc', 'islandora', 'includes/utilities');
global $user;
if (!$fedora_object) {
return drupal_not_found();
}
// set breadcrumbs
drupal_set_breadcrumb(islandora_get_breadcrumbs($fedora_object));
// optional pager parameters
$page_number = (empty($_GET['page'])) ? '1' : $_GET['page'];
$page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize'];
// Accumulate the output.
$output = array();
// Call cmodel oriented variants first.
foreach (islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $fedora_object->models) as $hook) {
$temp = module_invoke_all($hook, $fedora_object, $user, $page_number, $page_size);
if (!empty($temp)) {
$output = array_merge_recursive($output, $temp);
}
}
// Add in the default, if we did not get any results.
if (empty($output)) {
$output = islandora_default_islandora_view_object($fedora_object);
}
arsort($output);
drupal_alter(ISLANDORA_VIEW_HOOK, $fedora_object, $output);
return implode('', $output);
}
/**
* 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 FedoraObject $object
* The object whose display we are to render.
* @return array
*/
function islandora_default_islandora_view_object($object) {
$output = theme('islandora_default', array('islandora_object' => $object));
return array('Default output' => $output);
}
/**
* Implements hook_theme().
*
* @return array
*/
function islandora_theme() {
return array(
'islandora_default' => array(
'file' => 'theme/islandora.theme.inc',
'template' => 'theme/islandora-object',
'variables' => array('islandora_object' => NULL),
),
'islandora_default_edit' => array(
'file' => 'theme/islandora.theme.inc',
'template' => 'theme/islandora-object-edit',
'variables' => array('islandora_object' => NULL),
),
);
}
/**
* Implements hook_permission().
*
* @return array
*/
function islandora_permission() {
return array(
FEDORA_VIEW => array(
'title' => t('View repository objects and datastreams'),
'description' => t('View objects in the repository and their associated datastreams. Note: Fedora XACML security policies may override this permission.')
),
FEDORA_ADD_DS => array(
'title' => t('Add datastreams to repository objects'),
'description' => t('Add datastreams to objects in the repository. Note: Fedora XACML security policies may override this position.')
),
FEDORA_METADATA_EDIT => array(
'title' => t('Edit metadata'),
'description' => t('Edit metadata for objects in the repository.')
),
FEDORA_INGEST => array(
'title' => t('Create new repository objects'),
'description' => t('Create new objects in the repository.')
),
FEDORA_PURGE => array(
'title' => t('Permanently remove objects from the repository'),
'description' => t('Permanently remove objects from the repository.')
),
FEDORA_MODIFY_STATE => array(
'title' => t('Change repository object states'),
'description' => t('Change the state of objects in the repository (e.g. from Active to Inactive).')
),
FEDORA_MANAGE => array(
'title' => t('View object management tabs'),
'description' => t('View tabs that provide object management functions.')
)
);
}
/**
* A helper function to get a connection and return an object
*
* @global object $user
* @param string $object_id
* @return FedoraObject
*/
function islandora_object_load($object_id) {
module_load_include('inc', 'islandora', 'includes/tuque');
$islandora_tuque = &drupal_static(__FUNCTION__);
if (!$islandora_tuque) {
$islandora_tuque = new IslandoraTuque();
}
if (IslandoraTuque::exists()) {
try {
$fedora_object = $islandora_tuque->repository->getObject($object_id);
} catch (Exception $e) {
return NULL;
}
drupal_alter('islandora_object', $fedora_object);
return $fedora_object;
}
else {
IslandoraTuque::getError();
return NULL;
}
}
/**
* A helper function to get a connection and purge an object
*
* @global object $user
* @param string $object_id
* @return FedoraObject
*/
function islandora_object_purge($object_id) {
if (!$object_id) {
drupal_set_message(t('Cannot remove object, object id not set'));
return;
}
// load object
$object = islandora_object_load($object_id);
if (!$object) {
drupal_set_message(t('Could not remove object, object not found'));
return;
}
module_load_include('inc', 'islandora', 'includes/utilities');
$content_models = $object->models;
$arr = array();
foreach (islandora_build_hook_list(ISLANDORA_PRE_PURGE_OBJECT_HOOK, $object->models) as $hook) {
$temp = module_invoke_all($hook, $object);
if (!empty($temp)) {
$arr = array_merge_recursive($arr, $temp);
}
}
if (isset($arr['delete']) && $arr['delete']) {
try {
$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 {
$object->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
}
/**
* Ingest access callback
*/
function islandora_ingest_access_callback($object, $perm) {
if (islandora_access_callback($object, $perm) === FALSE) {
return FALSE;
}
$ingest_registry = module_invoke_all('islandora_ingest_registry', $object);
if (count($ingest_registry) > 0) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* Content model, collection view and collection policy datastreams may now optionally define a version
* number in their top-level XML element as an attribute, as in:
* <content_model name="Collection" version="2" ...
*
* @param object $item
* @param string $dsid
* @param string $datastream_file
* @return
* int, or NULL if no version attribute was found.
*/
function islandora_get_islandora_datastream_version($item = NULL, $dsid = NULL, $datastream_file = NULL) {
$return = NULL;
// @TODO, need better check for $item
if ($item && $item[$dsid]) {
$doc = simplexml_load_string($item[$dsid]->content);
}
elseif (!empty($datastream_file)) {
$doc = simplexml_load_file($datastream_file);
}
if (!empty($doc) && $version = (int)$doc->attributes()->version) {
$return = $version;
}
return $return;
}
/**
* Implements hook_islandora_required_objects().
*/
function islandora_islandora_required_objects() {
// module path
$module_path = drupal_get_path('module', 'islandora');
return array(
'islandora' => array(
'title' => 'Islandora',
'objects' => array(
array(
'pid' => 'islandora:root',
'label' => 'Top-level collection',
'cmodel' => 'islandora:collectionCModel',
'datastreams' => array(
array(
'dsid' => 'COLLECTION_POLICY',
'label' => 'Collection policy',
'mimetype' => 'text/xml',
'control_group' => 'X',
'datastream_file' => "$module_path/xml/islandora_collection_policy.xml",
),
array(
'dsid' => 'TN',
'label' => 'Thumbnail',
'mimetype' => 'image/png',
'control_group' => 'M',
'datastream_file' => "$module_path/images/folder.png",
),
),
),
),
),
);
}