Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add core image server settings #725

Open
wants to merge 7 commits into
base: 7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Set the URL.

If using IIIF choose to send token as a header and choose the token to use.

Any [IIIF](http://iiif.io) image server can be used the the IIIF tile source. The IIIF tile source provides a full URL to the datastream to be displayed as the IIIF `identifier`. The IIIF server needs to be configured to resolve this full URL to retrieve the image.
Any [IIIF](http://iiif.io) image server can be used the the IIIF tile source. The IIIF tile source provides an templated identifier which the IIIF server must be configured to resolve. This could be the full URL to the datastream to be displayed or something more complex. The IIIF server needs to be configured to resolve this full URL to retrieve the image.
adam-vessey marked this conversation as resolved.
Show resolved Hide resolved

The [Cantaloupe 🍈](https://medusa-project.github.io/cantaloupe/) IIIF image server can be configured to resolve these identifiers using the [`HttpResolver`](https://medusa-project.github.io/cantaloupe/manual/3.3/resolvers.html#HttpResolver) with no prefix specified.

Expand Down
109 changes: 84 additions & 25 deletions includes/imageserver.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,7 @@ function islandora_imageserver_admin_form(array $form, array &$form_state) {
$settings = islandora_imageserver_get_settings();

$form = array(
'type' => array(
'#type' => 'select',
'#title' => t('Image Server'),
'#description' => t('Select the image server to configure, used by the Paged Content, OpenSeadragon, & Internet Archive Bookreader modules.'),
'#default_value' => $settings['type'],
'#options' => array(
'none' => t('No image server configured'),
'iiif' => t('IIIF image server'),
'djatoka' => t('Adore-Djatoka image server'),
),
),
'type' => islandora_imageserver_get_type_selectbox(FALSE),
'url' => array(
'#prefix' => '<div id="islandora-imageserver-path-wrapper">',
'#suffix' => '</div>',
Expand Down Expand Up @@ -89,35 +79,64 @@ function islandora_imageserver_admin_form(array $form, array &$form_state) {
'#type' => 'submit',
'#value' => t('Save configuration'),
'#weight' => 0,
'#name' => 'save_config',
),
'reset' => array(
'#type' => 'submit',
'#value' => t('Reset to defaults'),
'#weight' => 1,
'#submit' => array('islandora_imageserver_admin_submit_reset'),
adam-vessey marked this conversation as resolved.
Show resolved Hide resolved
'#name' => 'reset_config',
),
),
);
return $form;
}

/**
* Delete configured settings, returning us to default settings.
* Settings reset confirmation form.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal $form_state.
*
* @return mixed
* The created form.
*/
function islandora_imageserver_admin_reset_confirm_form(array $form, array &$form_state) {
$form = array(
'reset_confirm' => array(
'#type' => 'hidden',
'#value' => 1,
),
);
adam-vessey marked this conversation as resolved.
Show resolved Hide resolved
return confirm_form(
$form,
t("Do you really want to reset the Image Server settings?"),
'admin/islandora/image_server',
t("This action cannot be undone."),
t("Reset")
);
}

/**
* Implements hook_form_submit().
*/
function islandora_imageserver_admin_submit_reset() {
variable_del('islandora_imageserver_settings');
function islandora_imageserver_admin_reset_confirm_form_submit(array $form, array &$form_state) {
variable_set('islandora_imageserver_settings', islandora_imageserver_get_default_settings());
adam-vessey marked this conversation as resolved.
Show resolved Hide resolved
drupal_set_message(t('Settings reset.'), 'status');
drupal_goto('admin/islandora/image_server');
adam-vessey marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Implements hook_form_submit().
*/
function islandora_imageserver_admin_form_submit(array $form, array &$form_state) {
$type = $form_state['values']['type'];
if ($type == 'none') {
variable_del('islandora_imageserver_settings');
if (isset($form_state['triggering_element']) && $form_state['triggering_element']['#name'] == 'reset_config') {
drupal_goto('admin/islandora/image_server/reset');
}
else {
$type = $form_state['values']['type'];
$settings = islandora_imageserver_get_settings();
$settings['type'] = $type;
$settings['url'] = rtrim($form_state['values']['url'], '/');
Expand All @@ -130,8 +149,8 @@ function islandora_imageserver_admin_form_submit(array $form, array &$form_state
$settings['iiif_identifier'] = ISLANDORA_IMAGESERVER_DEFAULT_TOKEN;
}
variable_set('islandora_imageserver_settings', $settings);
drupal_set_message(t("Settings saved successfully."), 'status');
}
drupal_set_message(t("Settings saved successfully."), 'status');
}

/**
Expand Down Expand Up @@ -167,7 +186,7 @@ function islandora_imageserver_admin_form_access_message(array &$form_state) {
$url = islandora_imageserver_get_default_value($form_state, 'url');

if ($type == 'djatoka') {
$url = url("{$url}", array(
$url = url($url, array(
'absolute' => TRUE,
'query' => array(
'url_ver' => 'Z39.88-2004',
Expand All @@ -186,6 +205,10 @@ function islandora_imageserver_admin_form_access_message(array &$form_state) {
)
);
}
else {
// None, so don't confirm.
return "";
}

if (isset($url) && !empty($url)) {
$result = drupal_http_request($url);
Expand Down Expand Up @@ -216,16 +239,26 @@ function islandora_imageserver_admin_form_access_message(array &$form_state) {
* Configuration to access the image server.
*/
function islandora_imageserver_get_settings() {
$defaults = array(
$defaults = islandora_imageserver_get_default_settings();

$settings = variable_get('islandora_imageserver_settings', array()) + $defaults;

return $settings;
}

/**
* Return the default image server settings.
*
* @return array
* The settings.
*/
function islandora_imageserver_get_default_settings() {
return array(
'type' => 'none',
'url' => '',
'iiif_token_header' => FALSE,
'iiif_identifier' => ISLANDORA_IMAGESERVER_DEFAULT_TOKEN,
);

$settings = variable_get('islandora_imageserver_settings', array()) + $defaults;

return $settings;
}

/**
Expand Down Expand Up @@ -274,3 +307,29 @@ function islandora_imageserver_get_identifier($string_token, $pid, $dsid, $autht
);
return token_replace($string_token, $parts);
}

/**
* Create the select box form element with the currently configured type.
*
* @param bool $disabled
* Whether the element should be disabled.
*
* @return array
* The form element.
*/
function islandora_imageserver_get_type_selectbox($disabled = TRUE) {
$settings = islandora_imageserver_get_settings();
$description = $disabled ? t("Configured at Admin ≫ Islandora ≫ Image server configuration.") : t("Select the image server to configure.");
return array(
'#type' => 'select',
'#title' => t('Image Server'),
'#description' => $description,
'#default_value' => $settings['type'],
'#disabled' => $disabled,
'#options' => array(
'none' => t('No image server configured'),
'iiif' => t('IIIF image server'),
'djatoka' => t('Adore-Djatoka image server'),
),
);
}
4 changes: 2 additions & 2 deletions islandora.install
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function islandora_update_7003() {
else {
$openseadragon_settings['url'] = variable_get('islandora_openseadragon_iiif_url', 'iiif');
$openseadragon_settings['iiif_token_header'] = variable_get('islandora_openseadragon_iiif_token_header', FALSE);
$openseadragon_settings['iiif_identifier'] = explode(":", variable_get('islandora_openseadragon_iiif_identifier', '[islandora_openseadragon:url_token]'))[1];
$openseadragon_settings['iiif_identifier'] = str_replace('[islandora_openseadragon:', '[islandora:', variable_get('islandora_openseadragon_iiif_identifier', '[islandora_openseadragon:url_token]'));
}
}
if (module_exists('islandora_internet_archive_bookreader')) {
Expand All @@ -180,7 +180,7 @@ function islandora_update_7003() {
else {
$iabv_settings['url'] = variable_get('islandora_internet_archive_bookreader_iiif_url', 'iiif');
$iabv_settings['iiif_token_header'] = variable_get('islandora_internet_archive_bookreader_iiif_token_header', FALSE);
$iabv_settings['iiif_identifier'] = explode(":", variable_get('islandora_internet_archive_bookreader_iiif_identifier', '[islandora_iareader:url_token]'))[1];
$iabv_settings['iiif_identifier'] = str_replace('[islandora_iareader:', '[islandora:', variable_get('islandora_internet_archive_bookreader_iiif_identifier', '[islandora_iareader:url_token]'));
}
}
if (isset($openseadragon_settings) && isset($iabv_settings)) {
Expand Down
9 changes: 9 additions & 0 deletions islandora.module
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ function islandora_menu() {
'type' => MENU_NORMAL_ITEM,
'file' => 'includes/imageserver.inc',
);
$items['admin/islandora/image_server/reset'] = array(
'title' => 'Image server configuration reset confirmation',
'description' => 'Image server configuration reset confirmation',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_imageserver_admin_reset_confirm_form'),
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
'file' => 'includes/imageserver.inc',
);

return $items;
}
Expand Down