From 2da712c546935cea1cd6ec18e9624bfb40d0a5f6 Mon Sep 17 00:00:00 2001 From: yqjiang Date: Tue, 10 Sep 2013 16:06:01 +0000 Subject: [PATCH 01/14] add nonsort and trailing space --- includes/tuque_wrapper.inc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index 96f9919c..d7c8d512 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -207,6 +207,7 @@ class IslandoraFedoraApiM extends FedoraApiM { 'params' => $params, ); islandora_alter_datastream($object, $datastream, $context); + $params=$context['params']; if (isset($params['lastModifiedDate'])) { $params['lastModifiedDate'] = (string) $object[$dsid]->createdDate; } @@ -244,6 +245,7 @@ class IslandoraFedoraApiM extends FedoraApiM { 'params' => $params, ); islandora_alter_object($object, $context); + $params=$context['params']; try { if ($context['block']) { throw new Exception('Modify Object was blocked.'); From 4925bc85fdd15e00553895d50c4a40752dafaad9 Mon Sep 17 00:00:00 2001 From: yqjiang Date: Wed, 11 Sep 2013 12:43:02 +0000 Subject: [PATCH 02/14] fix the code format --- includes/tuque_wrapper.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index d7c8d512..2aa85a8b 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -207,7 +207,7 @@ class IslandoraFedoraApiM extends FedoraApiM { 'params' => $params, ); islandora_alter_datastream($object, $datastream, $context); - $params=$context['params']; + $params = $context['params']; if (isset($params['lastModifiedDate'])) { $params['lastModifiedDate'] = (string) $object[$dsid]->createdDate; } @@ -245,7 +245,7 @@ class IslandoraFedoraApiM extends FedoraApiM { 'params' => $params, ); islandora_alter_object($object, $context); - $params=$context['params']; + $params = $context['params']; try { if ($context['block']) { throw new Exception('Modify Object was blocked.'); From f780e964b85ef6aec8ca8e9b2096faf92723a315 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Fri, 20 Sep 2013 10:54:44 +0000 Subject: [PATCH 03/14] Changes required for metadata display refinements. --- includes/metadata.inc | 123 ++++++++++++++++++++ islandora.api.php | 28 +++++ islandora.module | 32 +++++ theme/islandora-dublin-core-display.tpl.php | 17 +++ theme/theme.inc | 18 +++ 5 files changed, 218 insertions(+) create mode 100644 includes/metadata.inc create mode 100644 theme/islandora-dublin-core-display.tpl.php diff --git a/includes/metadata.inc b/includes/metadata.inc new file mode 100644 index 00000000..49b6e417 --- /dev/null +++ b/includes/metadata.inc @@ -0,0 +1,123 @@ + t('None'), + 'description' => t("Don't show any metadata for displaying"), + ); + $viewers = array_merge_recursive($no_viewer, $defined_displays); + + $form['viewers'] = array( + '#type' => 'item', + '#title' => t('Select a viewer'), + '#description' => t('Preferred metadata display for Islandora. These may be provided by third-party modules.'), + '#tree' => TRUE, + '#theme' => 'islandora_viewers_table', + ); + + foreach ($viewers as $name => $profile) { + $options[$name] = ''; + $form['viewers']['name'][$name] = array( + '#type' => 'hidden', + '#value' => $name, + ); + $form['viewers']['label'][$name] = array( + '#type' => 'item', + '#markup' => $profile['label'], + ); + $form['viewers']['description'][$name] = array( + '#type' => 'item', + '#markup' => $profile['description'], + ); + $form['viewers']['configuration'][$name] = array( + '#type' => 'item', + '#markup' => (isset($profile['configuration']) AND $profile['configuration'] != '') ? l(t('configure'), $profile['configuration']) : '', + ); + } + $form['viewers']['default'] = array( + '#type' => 'radios', + '#options' => isset($options) ? $options : array(), + '#default_value' => variable_get('islandora_metadata_display', 'dublin_core'), + ); + } + else { + $form['viewers']['no_viewers'] = array( + '#markup' => t('No viewers detected.'), + ); + } + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save configuration'), + ); + return $form; +} + +/** + * Submit handler for the metadata display form which sets the default viewer. + * + * @param array $form + * An array representing a Drupal form. + * @param array $form_state + * An array containing the Drupal form state. + */ +function islandora_metadata_display_form_submit($form, $form_state) { + variable_set('islandora_metadata_display', $form_state['values']['viewers']['default']); + drupal_set_message(t('The configuration options have been saved.')); +} + +/** + * Metadata display callback for rendering Dublin Core metadata. + * + * @param AbstractObject $object + * An AbstractObject representing an object within Fedora. + * + * @return string + * Markup representing the rendered metadata from Dublin Core. + */ +function islandora_metadata_display_callback(AbstractObject $object) { + $elements = array( + 'islandora_object' => $object, + ); + return theme('islandora_dublin_core_display', $elements); +} diff --git a/islandora.api.php b/islandora.api.php index 0dff8d89..bed9b401 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -691,3 +691,31 @@ function hook_islandora_update_related_objects_properties(AbstractObject $object function hook_islandora_breadcrumbs_alter(&$breadcrumbs, $context) { } + +/** + * Registry hook for metadata display viewers. + * + * Modules can use this hook to override the default Dublin Core display. + * This hook lets Islandora know which viewers there are available. + * + * @return array + * An associative array where the values are the following: + * -label: Human readable display label for selection. + * -description: A description of what the metadata display viewer does. + * -callback: A callable function that provides the markup to be passed + * off to the template files. + * -configuration (Optional): A path to the administration page for the + * metadata display. + + * @see islandora_retrieve_metadata_markup() + */ +function hook_islandora_metadata_display_info() { + return array( + 'hookable_displays_yay' => array( + 'label' => t('Hookable display yay!'), + 'description' => t('This is purely an example of how to implement this.'), + 'callback' => 'hookable_displays_some_function_that_returns_markup', + 'configuration' => 'admin/hookable_displays_yay/somepath', + ), + ); +} diff --git a/islandora.module b/islandora.module index ebf7f916..f8e97c71 100644 --- a/islandora.module +++ b/islandora.module @@ -99,6 +99,14 @@ function islandora_menu() { 'type' => MENU_NORMAL_ITEM, 'weight' => -1, ); + $items['admin/islandora/metadata'] = array( + 'title' => 'Metadata Display', + 'description' => 'Configure settings for metadata display on Islandora objects', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('islandora_metadata_display_form'), + 'file' => 'includes/metadata.inc', + 'access arguments' => array('adminisiter site configuration'), + ); $items['admin/islandora/solution_packs'] = array( 'title' => 'Solution packs', 'description' => 'Install content models and collections required by installed solution packs.', @@ -445,6 +453,17 @@ function islandora_theme() { 'file' => 'theme/theme.inc', 'variables' => array('datastream' => NULL), ), + 'islandora_dublin_core_display' => array( + 'file' => 'theme/theme.inc', + 'template' => 'theme/islandora-dublin-core-display', + // We can add PIDs to the end of this pattern in our preprocess function + // and templates will be able to have have a pid appended to the + // template name to overide a template on a per object basis. + // An example template might be named: + // "islandora-dublin-core-display--islandora-27.tpl.php". + 'pattern' => 'islandora_dublin_core_display__', + 'variables' => array('islandora_object' => NULL), + ), ); } @@ -1602,3 +1621,16 @@ function islandora_islandora_datastream_modified(AbstractObject $object, Abstrac )); islandora_derivative_logging($logging_results); } + +/** + * Implements hook_islandora_metadata_display_info(). + */ +function islandora_islandora_metadata_display_info() { + return array( + 'dublin_core' => array( + 'label' => t('Dublin Core'), + 'description' => t('Dublin Core metadata'), + 'callback' => 'islandora_metadata_display_callback', + ), + ); +} diff --git a/theme/islandora-dublin-core-display.tpl.php b/theme/islandora-dublin-core-display.tpl.php new file mode 100644 index 00000000..63fc60a6 --- /dev/null +++ b/theme/islandora-dublin-core-display.tpl.php @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/theme/theme.inc b/theme/theme.inc index 895ec8fe..f12814cb 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -423,3 +423,21 @@ function theme_islandora_datastream_version_link(array $vars) { return ''; } } + +/** + * Implements hook_preprocess(). + */ +function islandora_preprocess_islandora_dublin_core_display(array &$variables) { + $islandora_object = $variables['islandora_object']; + if (islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['DC'])) { + try { + $dc = $islandora_object['DC']->content; + $dc_object = DublinCore::importFromXMLString($dc); + } + catch (Exception $e) { + drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE); + } + } + $variables['islandora_dublin_core'] = isset($dc_object) ? $dc_object : NULL; + $variables['dc_array'] = isset($dc_object) ? $dc_object->asArray() : array(); +} From a7bd089e2be16772c1445b61dda3fdcd94b28a40 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Mon, 23 Sep 2013 12:01:48 +0000 Subject: [PATCH 04/14] Update to include two separate metadata callbacks as opposed to one. --- includes/metadata.inc | 63 +++++++++++++++++-- islandora.api.php | 3 +- islandora.module | 14 ++++- .../islandora-dublin-core-description.tpl.php | 20 ++++++ theme/islandora-dublin-core-display.tpl.php | 18 ++++++ theme/theme.inc | 18 +++++- 6 files changed, 128 insertions(+), 8 deletions(-) create mode 100644 theme/islandora-dublin-core-description.tpl.php diff --git a/includes/metadata.inc b/includes/metadata.inc index 49b6e417..9f8a51ed 100644 --- a/includes/metadata.inc +++ b/includes/metadata.inc @@ -16,13 +16,39 @@ function islandora_retrieve_metadata_markup(AbstractObject $object) { $viewers = module_invoke_all('islandora_metadata_display_info'); $viewer = variable_get('islandora_metadata_display', 'dublin_core'); - - if (isset($viewers[$viewer]['callback'])) { - return call_user_func($viewers[$viewer]['callback'], $object); + $markup = ''; + if (isset($viewers[$viewer]['metadata callback'])) { + $markup = call_user_func($viewers[$viewer]['metadata callback'], $object); + // The callback doesn't have any markup provided for this particular object, + // default back to the dublin_core display. + if ($markup === FALSE) { + $markup = call_user_func($viewers['dublin_core']['metadata callback'], $object); + } } - else { - return ''; + return $markup; +} + +/** + * Retrieves the metadata display description for an Islandora object. + * + * @param AbstractObject $object + * An AbstractObject representing an object within Fedora. + * @return string + * Markup to be rendered for description on Islandora object pages. + */ +function islandora_retrieve_description_markup(AbstractObject $object) { + $viewers = module_invoke_all('islandora_metadata_display_info'); + $viewer = variable_get('islandora_metadata_display', 'dublin_core'); + $markup = ''; + if (isset($viewers[$viewer]['description callback'])) { + $markup = call_user_func($viewers[$viewer]['description callback'], $object); + // The callback doesn't have any markup provided for this particular object, + // default back to the dublin_core display. + if ($markup === FALSE) { + $markup = call_user_func($viewers['dublin_core']['description callback'], $object); + } } + return $markup; } /** @@ -121,3 +147,30 @@ function islandora_metadata_display_callback(AbstractObject $object) { ); return theme('islandora_dublin_core_display', $elements); } + +/** + * Metadata description callback for rendering Dublin Core description. + * + * @param AbstractObject $object + * An AbstractObject representing an object within Fedora. + * + * @return string + * Markup representing the rendered metadata from Dublin Core. + */ +function islandora_metadata_description_callback(AbstractObject $islandora_object) { + if (islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['DC'])) { + try { + $dc = $islandora_object['DC']->content; + $dc_object = DublinCore::importFromXMLString($dc); + } + catch (Exception $e) { + drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE); + } + } + $dc_array = isset($dc_object) ? $dc_object->asArray() : array(); + $elements = array( + 'islandora_object' => $islandora_object, + 'dc_array' => $dc_array, + ); + return theme('islandora_dublin_core_description', $elements); +} \ No newline at end of file diff --git a/islandora.api.php b/islandora.api.php index bed9b401..b942052d 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -714,7 +714,8 @@ function hook_islandora_metadata_display_info() { 'hookable_displays_yay' => array( 'label' => t('Hookable display yay!'), 'description' => t('This is purely an example of how to implement this.'), - 'callback' => 'hookable_displays_some_function_that_returns_markup', + 'metadata callback' => 'hookable_displays_some_function_that_returns_metadata_markup', + 'description callback' => 'hookable_displays_some_function_that_returns_description_markup', 'configuration' => 'admin/hookable_displays_yay/somepath', ), ); diff --git a/islandora.module b/islandora.module index f8e97c71..2179d292 100644 --- a/islandora.module +++ b/islandora.module @@ -464,6 +464,17 @@ function islandora_theme() { 'pattern' => 'islandora_dublin_core_display__', 'variables' => array('islandora_object' => NULL), ), + 'islandora_dublin_core_description' => array( + 'file' => 'theme/theme.inc', + 'template' => 'theme/islandora-dublin-core-description', + // We can add PIDs to the end of this pattern in our preprocess function + // and templates will be able to have have a pid appended to the + // template name to overide a template on a per object basis. + // An example template might be named: + // "islandora-dublin-core-description--islandora-27.tpl.php". + 'pattern' => 'islandora_dublin_core_description__', + 'variables' => array('islandora_object' => NULL), + ), ); } @@ -1630,7 +1641,8 @@ function islandora_islandora_metadata_display_info() { 'dublin_core' => array( 'label' => t('Dublin Core'), 'description' => t('Dublin Core metadata'), - 'callback' => 'islandora_metadata_display_callback', + 'metadata callback' => 'islandora_metadata_display_callback', + 'description callback' => 'islandora_metadata_description_callback', ), ); } diff --git a/theme/islandora-dublin-core-description.tpl.php b/theme/islandora-dublin-core-description.tpl.php new file mode 100644 index 00000000..2ff54cdc --- /dev/null +++ b/theme/islandora-dublin-core-description.tpl.php @@ -0,0 +1,20 @@ + + diff --git a/theme/islandora-dublin-core-display.tpl.php b/theme/islandora-dublin-core-display.tpl.php index 63fc60a6..0dbc9235 100644 --- a/theme/islandora-dublin-core-display.tpl.php +++ b/theme/islandora-dublin-core-display.tpl.php @@ -1,3 +1,21 @@ + \ No newline at end of file + From 131f6e5afccb4fed8905d738415496cb9502f243 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 24 Sep 2013 18:29:30 +0000 Subject: [PATCH 08/14] Fix comment. --- includes/metadata.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/metadata.inc b/includes/metadata.inc index dc948e7b..31035ff2 100644 --- a/includes/metadata.inc +++ b/includes/metadata.inc @@ -9,7 +9,9 @@ * * @param AbstractObject $object * An AbstractObject representing an object within Fedora. - * + * @param bool $print + * Whether the object is being printed. + * * @return string * Markup to be rendered for display on Islandora object pages. */ From 0fdc31acc68ec94dad84e712e34da78e65eb1078 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 24 Sep 2013 19:31:35 +0000 Subject: [PATCH 09/14] Update API comments. --- includes/metadata.inc | 2 +- islandora.api.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/metadata.inc b/includes/metadata.inc index 31035ff2..94dcced6 100644 --- a/includes/metadata.inc +++ b/includes/metadata.inc @@ -11,7 +11,7 @@ * An AbstractObject representing an object within Fedora. * @param bool $print * Whether the object is being printed. - * + * * @return string * Markup to be rendered for display on Islandora object pages. */ diff --git a/islandora.api.php b/islandora.api.php index e647b95b..24d24528 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -703,9 +703,11 @@ function hook_islandora_breadcrumbs_alter(&$breadcrumbs, $context) { * -label: Human readable display label for selection. * -description: A description of what the metadata display viewer does. * -metadata callback: A callable function that provides the markup to be - * passed off to the template files. + * passed off to the template files. Returns markup or FALSE if the viewer + * wishes to default back to the Dublin Core display for the current object. * -description callback: A callable function that provides the markup to be - * passed for the description. + * passed for the description. Returns markup or FALSE if the viewer + * wishes to default back to the Dublin Core display for the current object. * -configuration (Optional): A path to the administration page for the * metadata display. From 1474681f0ef75a7554d3b26f9f9dc683c5109496 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Wed, 25 Sep 2013 12:30:12 +0000 Subject: [PATCH 10/14] Redundant metadata call. --- includes/metadata.inc | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/includes/metadata.inc b/includes/metadata.inc index 94dcced6..bf59b830 100644 --- a/includes/metadata.inc +++ b/includes/metadata.inc @@ -164,19 +164,8 @@ function islandora_metadata_display_callback(AbstractObject $object, $print = FA * Markup representing the rendered metadata from Dublin Core. */ function islandora_metadata_description_callback(AbstractObject $islandora_object) { - if (islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['DC'])) { - try { - $dc = $islandora_object['DC']->content; - $dc_object = DublinCore::importFromXMLString($dc); - } - catch (Exception $e) { - drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE); - } - } - $dc_array = isset($dc_object) ? $dc_object->asArray() : array(); $elements = array( 'islandora_object' => $islandora_object, - 'dc_array' => $dc_array, ); return theme('islandora_dublin_core_description', $elements); } From 5e1e12ff2463162fdd1ba6257f817b4bf9ce9f28 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Wed, 25 Sep 2013 13:01:13 +0000 Subject: [PATCH 11/14] Add print variable. --- islandora.module | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/islandora.module b/islandora.module index 55cbcb29..95003bf9 100644 --- a/islandora.module +++ b/islandora.module @@ -462,7 +462,10 @@ function islandora_theme() { // An example template might be named: // "islandora-dublin-core-display--islandora-27.tpl.php". 'pattern' => 'islandora_dublin_core_display__', - 'variables' => array('islandora_object' => NULL), + 'variables' => array( + 'islandora_object' => NULL, + 'print' => NULL, + ), ), 'islandora_dublin_core_description' => array( 'file' => 'theme/theme.inc', From d1b26132d994985617cef6485205ff156941f7e4 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Wed, 25 Sep 2013 14:43:40 +0000 Subject: [PATCH 12/14] Check to see if function exists before calling it. --- includes/derivatives.inc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/includes/derivatives.inc b/includes/derivatives.inc index c66944b1..8a6627e5 100644 --- a/includes/derivatives.inc +++ b/includes/derivatives.inc @@ -60,9 +60,14 @@ function islandora_do_derivatives(AbstractObject $object, array $options) { require_once $hook['file']; } foreach ($hook['function'] as $function) { - $logging = call_user_func($function, $object, $options['force']); - if (!empty($logging)) { - $results[] = $logging; + if (function_exists($function)) { + $logging = call_user_func($function, $object, $options['force']); + if (!empty($logging)) { + $results[] = $logging; + } + } + else { + watchdog('islandora', 'Unable to call derivative function @function as it was not found!', array('@function' => $function), WATCHDOG_ERROR); } } } From 3f1319f51a409118f7866e63ce559088713bea5e Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Wed, 25 Sep 2013 15:00:46 +0000 Subject: [PATCH 13/14] Remove comment. --- theme/islandora-dublin-core-display.tpl.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/theme/islandora-dublin-core-display.tpl.php b/theme/islandora-dublin-core-display.tpl.php index 1a967599..da67de18 100644 --- a/theme/islandora-dublin-core-display.tpl.php +++ b/theme/islandora-dublin-core-display.tpl.php @@ -9,8 +9,6 @@ * - $dc_array: The DC datastream object values as a sanitized array. This * includes label, value and class name. * - $islandora_object_label: The sanitized object label. -* - $parent_collections: An array containing parent collection(s) info. -* Includes collection object, label, url and rendered link. * * @see template_preprocess_islandora_dublin_core_display() * @see theme_islandora_dublin_core_display() From be4d218af17a12a9e21bcd6c01086ea3bf2541b5 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 26 Sep 2013 17:33:44 +0000 Subject: [PATCH 14/14] Add sanitation function. --- includes/utilities.inc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/includes/utilities.inc b/includes/utilities.inc index 6366305e..2139ae09 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -908,3 +908,19 @@ function islandora_as_renderable_array(&$markup_array) { } unset($value); } + +/** + * Sanitizes an input string to be valid XML. + * + * @param string $input + * An input string. + * @param string $replacement + * What we are replacing invalid characters with, defaults to ''. + * + * @return string + * The sanitized string. + */ +function islandora_sanitize_input_for_valid_xml($input, $replacement = '') { + $input = preg_replace('/[^\x9\xA\xD\x20-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', $replacement, $input); + return $input; +}