Browse Source

Merge branch '7.x' of github.com:Islandora/islandora into 7.x-release

pull/384/head
jonathangreen 12 years ago
parent
commit
92205bc581
  1. 2
      includes/add_datastream.form.inc
  2. 1
      includes/breadcrumb.inc
  3. 6
      includes/dublin_core.inc
  4. 39
      includes/ingest.form.inc
  5. 1
      includes/mime_detect.inc
  6. 120
      includes/utilities.inc
  7. 19
      islandora.install
  8. 44
      islandora.module
  9. 50
      theme/theme.inc

2
includes/add_datastream.form.inc

@ -32,7 +32,7 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb
'#attributes' => array( '#attributes' => array(
'enctype' => 'multipart/form-data', 'enctype' => 'multipart/form-data',
), ),
'fieldset' => array( 'dsid' => array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => 'Add a datastream', '#title' => 'Add a datastream',
'#collapsible' => FALSE, '#collapsible' => FALSE,

1
includes/breadcrumb.inc

@ -78,6 +78,7 @@ function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRe
and $parentObject <fedora-model:state> <info:fedora/fedora-system:def/model#Active> and $parentObject <fedora-model:state> <info:fedora/fedora-system:def/model#Active>
) )
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0> minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
minus $parentObject <mulgara:is> <info:fedora/' . $pid . '>
order by $title desc'; order by $title desc';
$results = $repository->ri->itqlQuery($query_string); $results = $repository->ri->itqlQuery($query_string);

6
includes/dublin_core.inc

@ -151,7 +151,7 @@ class DublinCore {
*/ */
public static function importFromXMLString($dc_xml) { public static function importFromXMLString($dc_xml) {
$dc_doc = new DomDocument(); $dc_doc = new DomDocument();
if ($dc_doc->loadXML($dc_xml)) { if (!empty($dc_xml) && $dc_doc->loadXML($dc_xml)) {
$oai_dc = $dc_doc->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', '*'); $oai_dc = $dc_doc->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', '*');
$new_dc = new DublinCore(); $new_dc = new DublinCore();
foreach ($oai_dc as $child) { foreach ($oai_dc as $child) {
@ -161,9 +161,7 @@ class DublinCore {
} }
return $new_dc; return $new_dc;
} }
else { return NULL;
return NULL;
}
} }
} }

39
includes/ingest.form.inc

@ -31,8 +31,15 @@
* The form definition of the current step. * The form definition of the current step.
*/ */
function islandora_ingest_form(array $form, array &$form_state, array $configuration) { function islandora_ingest_form(array $form, array &$form_state, array $configuration) {
islandora_ingest_form_init_form_state_storage($form_state, $configuration); try {
return islandora_ingest_form_execute_step($form, $form_state); islandora_ingest_form_init_form_state_storage($form_state, $configuration);
return islandora_ingest_form_execute_step($form, $form_state);
}
catch(Exception $e) {
drupal_set_message($e->getMessage(), 'error');
return array(array(
'#markup' => l(t('Back'), 'javascript:window.history.back();', array('external' => TRUE))));
}
} }
/** /**
@ -42,21 +49,16 @@ function islandora_ingest_form(array $form, array &$form_state, array $configura
* *
* @todo Add hook for manipulating/validating the configuration. * @todo Add hook for manipulating/validating the configuration.
* *
* @see islandora_ingest_form()
*
* @throws InvalidArgumentException * @throws InvalidArgumentException
* *
* @param array $configuration * @param array $configuration
* The key value pairs that are used to build the multi-paged ingest process. * The key value pairs that are used to build the multi-paged ingest process.
*
* @see islandora_ingest_form()
*
* @return bool
* TRUE if the configuration is valid, FALSE otherwise.
*/ */
function islandora_ingest_form_validiate_configuration(array $configuration) { function islandora_ingest_form_validate_configuration(array $configuration) {
if (empty($configuration['models'])) { if (empty($configuration['models'])) {
$message = t('Ingest configuration not vaild, no models were given'); throw new InvalidArgumentException('Ingest configuration not vaild, no models were given');
drupal_set_message($message, 'error');
throw new InvalidArgumentException($message);
} }
} }
@ -71,8 +73,8 @@ function islandora_ingest_form_validiate_configuration(array $configuration) {
*/ */
function islandora_ingest_form_init_form_state_storage(array &$form_state, array $configuration) { function islandora_ingest_form_init_form_state_storage(array &$form_state, array $configuration) {
if (empty($form_state['islandora'])) { if (empty($form_state['islandora'])) {
// Validate the configuration before using it. // Validate the configuration before we use it.
islandora_ingest_form_validiate_configuration($configuration); islandora_ingest_form_validate_configuration($configuration);
$object = islandora_ingest_form_prepare_new_object($configuration); $object = islandora_ingest_form_prepare_new_object($configuration);
$form_state['islandora'] = array( $form_state['islandora'] = array(
'step_id' => NULL, 'step_id' => NULL,
@ -233,12 +235,19 @@ function islandora_ingest_form_decrement_step(array &$form_state) {
* The list of key/value pairs of configuration. * The list of key/value pairs of configuration.
*/ */
function islandora_ingest_get_approximate_steps(array $configuration) { function islandora_ingest_get_approximate_steps(array $configuration) {
$fake_form_state = array( try {
islandora_ingest_form_validate_configuration($configuration);
}
catch(InvalidArgumentException $e) {
// Don't log or display exception.
return array();
}
$stubbed_form_state = array(
'islandora' => array( 'islandora' => array(
'shared_storage' => $configuration, 'shared_storage' => $configuration,
), ),
); );
$steps = islandora_ingest_form_get_steps($fake_form_state); $steps = islandora_ingest_form_get_steps($stubbed_form_state);
drupal_static_reset('islandora_ingest_form_get_steps'); drupal_static_reset('islandora_ingest_form_get_steps');
return $steps; return $steps;
} }

1
includes/mime_detect.inc

@ -139,6 +139,7 @@ class MimeDetect {
'txt' => 'text/plain', 'txt' => 'text/plain',
// images: // images:
"bmp" => "image/bmp", "bmp" => "image/bmp",
'dng' => 'image/x-adobe-dng',
"gif" => "image/gif", "gif" => "image/gif",
"ief" => "image/ief", "ief" => "image/ief",
"jpeg" => "image/jpeg", "jpeg" => "image/jpeg",

120
includes/utilities.inc

@ -79,6 +79,19 @@ function islandora_is_valid_pid($pid) {
return drupal_strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid)); return drupal_strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid));
} }
/**
* Checks if the given namespace is valid.
*
* @param string $namespace
* The namespace to check without the ":" character.
*
* @return bool
* TRUE if valid, FALSE otherwise.
*/
function islandora_is_valid_namespace($namespace) {
return drupal_strlen(trim($namespace)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+$/', trim($namespace));
}
/** /**
* Checks if the given datastream id is valid. * Checks if the given datastream id is valid.
* *
@ -560,9 +573,10 @@ function islandora_directory_exists_message($path) {
/** /**
* Gets the default value for the given system_settings_form() element. * Gets the default value for the given system_settings_form() element.
* *
* Checks the $form_state for the default value if not it checks variable_get(). * Checks the $form_state for the default value if not it checks
* Assumes #tree is FALSE. This is only really required for elements that utilize * variable_get(). Assumes #tree is FALSE. This is only really required
* AJAX, as their value can change before the submit actually takes place. * for elements that utilize AJAX, as their value can change before the
* submit actually takes place.
* *
* @param string $name * @param string $name
* The name of the system settings form element. * The name of the system settings form element.
@ -579,10 +593,11 @@ function islandora_system_settings_form_default_value($name, $default_value, arr
} }
/** /**
* Returns basic information about DS-COMPOSITE-MODEL * Returns basic information about DS-COMPOSITE-MODEL.
* *
* @param string $pid * @param string $pid
* pid of content model containing DS_COMP stream * PID of content model containing DS_COMP stream.
*
* @return array * @return array
* array of values in the following form * array of values in the following form
* *
@ -607,9 +622,7 @@ function islandora_system_settings_form_default_value($name, $default_value, arr
* [optional] => true * [optional] => true
* [mimetype] => application/rdf+xml * [mimetype] => application/rdf+xml
* ) * )
*
*/ */
function islandora_get_comp_ds_mappings($pid) { function islandora_get_comp_ds_mappings($pid) {
$cm_object = islandora_object_load($pid); $cm_object = islandora_object_load($pid);
if (!isset($cm_object) || !isset($cm_object['DS-COMPOSITE-MODEL'])) { if (!isset($cm_object) || !isset($cm_object['DS-COMPOSITE-MODEL'])) {
@ -632,3 +645,96 @@ function islandora_get_comp_ds_mappings($pid) {
} }
return $mappings; return $mappings;
} }
/**
* Checks that the given/current account has all the given permissions.
*
* @param array $perms
* The permissions to check.
* @param mixed $account
* (optional) The account to check, if not given use currently logged in user.
*
* @return bool
* TRUE if the account has all the given permissions, FALSE otherwise.
*/
function islandora_user_access_all(array $perms, $account = NULL) {
foreach ($perms as $perm) {
if (!user_access($perm, $account)) {
return FALSE;
}
}
return TRUE;
}
/**
* Checks that the given/current account has at one of the given permissions.
*
* @param array $perms
* The permissions to check.
* @param mixed $account
* (optional) The account to check, if not given use currently logged in user.
*
* @return bool
* TRUE if the account has at least one of the given permissions, FALSE
* otherwise.
*/
function islandora_user_access_any(array $perms, $account = NULL) {
foreach ($perms as $perm) {
if (user_access($perm, $account)) {
return TRUE;
}
}
return FALSE;
}
/**
* Gets the list of allowed namespaces as defined by 'islandora_pids_allowed'.
*
* @return array
* The list of namespaces striped of trailing ":" characters.
*/
function islandora_get_allowed_namespaces() {
$matches = array();
$allowed_namespaces = variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora:');
preg_match_all('/([A-Za-z0-9-\.]+):/', $allowed_namespaces, $matches);
return $matches[1];
}
/**
* Gets a list of all existing content models.
*
* If 'islandora_namespace_restriction_enforced' is set to true only return
* content models in the allowed namespace.
*
* @param bool $ignore_system_namespace
* Ignore content models in the 'fedora-system' namespace.
*
* @return array
* An associative array of all existing content models.
* - pid: The PID of the content model object.
* - pid: The PID of the content model object.
* - label: The label of the content model object.
*/
function islandora_get_content_models($ignore_system_namespace = TRUE) {
module_load_include('inc', 'islandora', 'includes/utilities');
$tuque = islandora_get_tuque_connection();
$query = 'select $object $label from <#ri>
where ($object <fedora-model:label> $label
and ($object <fedora-model:hasModel> <info:fedora/fedora-system:ContentModel-3.0>
or $object <fedora-rels-ext:isMemberOfCollection> <info:fedora/islandora:ContentModelsCollection>)
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $label';
$content_models = array();
$results = $tuque->repository->ri->itqlQuery($query, 'unlimited');
foreach ($results as $result) {
$content_model = $result['object']['value'];
$label = $result['label']['value'];
$namespace = islandora_get_namespace($content_model);
$ignore = $ignore_system_namespace && $namespace == 'fedora-system';
$ignore |= !islandora_namespace_accessible($namespace);
if (!$ignore) {
$content_models[$content_model] = array('pid' => $content_model, 'label' => $label);
}
}
return $content_models;
}

19
islandora.install

@ -5,6 +5,25 @@
* This file contains all install related hooks. * This file contains all install related hooks.
*/ */
/**
* Implements hook_requirements().
*/
function islandora_requirements($phase) {
$requirements = array();
// Ensure translations don't break at install time
$t = get_t();
if (!class_exists('XSLTProcessor', FALSE)) {
$requirements['islandora_xsltprocessor']['title'] = $t('Islandora XSLTProcessor Prerequisite');
$requirements['islandora_xsltprocessor']['value'] = $t('Not installed');
$link = l($t('PHP XSL extension'), 'http://us2.php.net/manual/en/book.xsl.php', array('attributes' => array('target'=>'_blank')));
$requirements['islandora_xsltprocessor']['description'] = $t('The !xsllink is required. Check your installed PHP extensions and php.ini file.', array('!xsllink' => $link));
$requirements['islandora_xsltprocessor']['severity'] = REQUIREMENT_ERROR;
}
return $requirements;
}
/** /**
* Implements hook_install(). * Implements hook_install().
* *

44
islandora.module

@ -120,6 +120,7 @@ function islandora_menu() {
FEDORA_METADATA_EDIT, FEDORA_METADATA_EDIT,
FEDORA_ADD_DS, FEDORA_ADD_DS,
FEDORA_PURGE, FEDORA_PURGE,
FEDORA_INGEST
), 2), ), 2),
); );
@ -228,6 +229,15 @@ function islandora_menu() {
'access arguments' => array(FEDORA_PURGE, 2, 4), 'access arguments' => array(FEDORA_PURGE, 2, 4),
'load arguments' => array(2), 'load arguments' => array(2),
); );
$items['islandora/object/%islandora_object/print'] = array(
'title' => 'Print Object',
'page callback' => 'islandora_print_object',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(FEDORA_VIEW_OBJECTS, 2),
'load arguments' => array(2),
);
$items['islandora/ingest'] = array( $items['islandora/ingest'] = array(
'title' => 'Add an Object', 'title' => 'Add an Object',
'page callback' => 'islandora_ingest_callback', 'page callback' => 'islandora_ingest_callback',
@ -271,6 +281,11 @@ function islandora_theme() {
'file' => 'includes/solution_packs.inc', 'file' => 'includes/solution_packs.inc',
'render element' => 'form', 'render element' => 'form',
), ),
// Print object view.
'islandora_object_print' => array(
'file' => 'theme/theme.inc',
'variables' => array('object' => NULL, 'content' => array()),
),
); );
} }
@ -836,10 +851,18 @@ function islandora_add_object(NewFedoraObject &$object) {
* An object to delete. * An object to delete.
* *
* @return bool * @return bool
* The ingested FedoraObject, after running the pre/post ingest hooks. * TRUE if successful, FALSE otherwise.
*/ */
function islandora_delete_object(FedoraObject &$object) { function islandora_delete_object(FedoraObject &$object) {
return $object->repository->purgeObject($object->id); try {
$object->repository->purgeObject($object->id);
$object = NULL;
return TRUE;
}
catch(Exception $e) {
// Exception message gets logged in Tuque Wrapper.
return FALSE;
}
} }
/** /**
@ -928,3 +951,20 @@ function islandora_entity_property_info() {
return $info; return $info;
} }
/**
* Renders the print page for the given object.
*
* Modules can either implement preprocess functions to append content onto the
* 'content' variable, or override the display by providing a theme suggestion.
*
* @param FedoraObject $object
* The object.
*
* @return array
* A renderable array.
*/
function islandora_print_object(FedoraObject $object) {
drupal_set_title($object->label);
return theme('islandora_object_print', array('object' => $object));
}

50
theme/theme.inc

@ -107,19 +107,53 @@ function islandora_preprocess_islandora_default(&$variables) {
} }
} }
$variables['datastreams'] = $datastreams; $variables['datastreams'] = $datastreams;
try { // Objects in fcrepo4 don't always contain a DC datastream.
$dc = $islandora_object['DC']->content; if (isset($islandora_object['DC'])) {
$dc_object = DublinCore::importFromXMLString($dc); $dc_object = DublinCore::importFromXMLString($islandora_object['DC']->content);
$dc_array = $dc_object->asArray(); $dc_array = $dc_object->asArray();
} }
catch (Exception $e) {
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE);
}
$variables['dc_array'] = isset($dc_array) ? $dc_array : array(); $variables['dc_array'] = isset($dc_array) ? $dc_array : array();
$variables['islandora_dublin_core'] = isset($dc_object) ? $dc_object : NULL; $variables['islandora_dublin_core'] = isset($dc_object) ? $dc_object : NULL;
$variables['islandora_object_label'] = $islandora_object->label; $variables['islandora_object_label'] = $islandora_object->label;
global $base_url;
if (isset($islandora_object['TN'])) { if (isset($islandora_object['TN'])) {
$variables['islandora_thumbnail_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/TN/view'; $variables['islandora_thumbnail_url'] = url("islandora/object/{$islandora_object->id}/datastream/TN/view");
} }
} }
/**
* Implements hook_preprocess_theme().
*/
function islandora_preprocess_islandora_object_print(array &$variables) {
// Apply the print CSS in non print context.
$only_print_media = function($o) {
return $o['media'] == 'print';
};
$css = array_filter(drupal_add_css(), $only_print_media);
foreach ($css as $data => $options) {
$options['media'] = 'all';
drupal_add_css($data, $options);
}
// Allow modules to define their own theme suggestions for the given object.
// Suggestions are defined as islandora_object_print__CMODEL__PID. For
// example for the image object islandora:1234.
// islandora_object_print__islandora_imagecmodel
// islandora_object_print__islandora_imagecmodel__islandora_1234
// would be valid theme suggestions. This step up does not support objects
// with multiple content models in which each content model provides a theme
// suggestion.
$object = $variables['object'];
$pid = strtolower(preg_replace('/[^a-zA-Z0-9_]/', '_', $object->id));
$models = array_diff($object->models, array('fedora-system:FedoraObject-3.0'));
foreach ($models as $model) {
$model = strtolower(preg_replace('/[^a-zA-Z0-9_]/', '_', $model));
$suggestions = theme_get_suggestions(array($model, $pid), 'islandora_object_print');
$variables['theme_hook_suggestions'] = array_merge($variables['theme_hook_suggestions'], $suggestions);
}
}
/**
* Implements theme_hook().
*/
function theme_islandora_object_print(array &$variables) {
return drupal_render($variables['content']);
}

Loading…
Cancel
Save