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

Move image server to core #136

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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 @@ -33,7 +33,7 @@ Install as usual, see [this](https://drupal.org/documentation/install/modules-th

Download the 2.0.2 version of the [Internet Archive BookReader](https://github.com/internetarchive/bookreader/tree/2.0.2)* to `sites/all/libraries/bookreader`, or run `drush iabookreader-plugin`. If you are upgrading from the 7.x-1.11 or older version of this module, you will need to replace your old copy of this library. *(Newer versions than 2.0.2 may work but have not been tested.)*

This module requires that you set up either Djatoka or an IIIF Image API compliant Image Sever. For Djatoka please follow the steps outlined at [here](https://wiki.duraspace.org/display/ISLANDORA/Djatoka).
This module requires that you set up either Djatoka or an IIIF Image API compliant Image Sever under Administration -> Islandora -> Image Server Configuration.

This module requires [Colorbox](https://www.drupal.org/project/colorbox) and its dependant library [Colorbox library](http://www.jacklmoore.com/colorbox/). Depending on the version of the Colorbox module and library you are using, there can be some issues with Colorbox finding the library. [This](https://www.drupal.org/node/1074474#comment-9137159) comment solves the issue.

Expand Down
53 changes: 2 additions & 51 deletions includes/admin.form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,13 @@
* The Drupal form definition.
*/
function islandora_internet_archive_bookreader_admin_settings_form(array $form, array &$form_state) {
form_load_include($form_state, 'inc', 'islandora', 'includes/imageserver');
$get_default_value = function($name, $default) use($form_state) {
return isset($form_state['values'][$name]) ? $form_state['values'][$name] : variable_get($name, $default);
};
$solr_enabled = module_exists('islandora_solr');
$form = array(
'islandora_internet_archive_bookreader_pagesource' => array(
'#type' => 'select',
'#title' => t('Image Server'),
'#description' => t('Select the image server to use with IA Bookreader'),
'#default_value' => variable_get('islandora_internet_archive_bookreader_pagesource', 'djatoka'),
'#options' => array(
'djatoka' => t('Adore-Djatoka Image Server'),
'iiif' => t('IIIF Image Server'),
),
),
'islandora_internet_archive_bookreader_pagesource' => islandora_imageserver_get_type_selectbox(),
'djatoka' => array(
'#type' => 'fieldset',
'#title' => t('Adore Djatoka Image Server Settings'),
Expand All @@ -55,47 +47,6 @@ function islandora_internet_archive_bookreader_admin_settings_form(array $form,
'#default_value' => variable_get('islandora_internet_archive_bookreader_use_backup_dsid', FALSE),
),
),
'iiif' => array(
'#type' => 'fieldset',
'#title' => t('IIIF Image Server Settings'),
'#description' => t('Settings for IIIF Image Server'),
'#states' => array(
'visible' => array(
':input[name="islandora_internet_archive_bookreader_pagesource"]' => array('value' => 'iiif'),
),
),
'islandora_internet_archive_bookreader_iiif_url' => array(
'#prefix' => '<div id="islandora-openseadragon-iiif-path-wrapper">',
'#suffix' => '</div>',
'#type' => 'textfield',
'#title' => t('IIIF Image Server Base URL'),
'#default_value' => variable_get('islandora_internet_archive_bookreader_iiif_url', 'iiif'),
'#description' => t('The location of the IIIF Image Server.'),
),
'islandora_internet_archive_bookreader_iiif_token_header' => array(
'#type' => 'checkbox',
'#title' => t('Add token as header'),
'#default_value' => variable_get('islandora_internet_archive_bookreader_iiif_token_header', FALSE),
'#description' => t('Instead of sending the token as a query parameter, it will be sent in the X-ISLANDORA-TOKEN header.'),
),
'islandora_internet_archive_bookreader_iiif_identifier' => array(
'#type' => 'textfield',
'#title' => t('IIIF Identifier'),
'#default_value' => variable_get('islandora_internet_archive_bookreader_iiif_identifier', '[islandora_iareader:url_token]'),
'#element_validate' => array('token_element_validate'),
'#token_types' => array('islandora_iareader'),
),
'islandora_internet_archive_bookreader_iiif_token_tree' => array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => theme('token_tree', array(
'token_types' => array('islandora_iareader'),
'global_types' => FALSE,
)),
),
),
'islandora_internet_archive_bookreader_ocr_filter_field' => array(
'#access' => $solr_enabled,
'#type' => 'textfield',
Expand Down
8 changes: 6 additions & 2 deletions includes/callback.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
/**
* Fetches page metadata for use in the viewer such as width and height.
*
* Prints a JSON object repersenting the metadata.
* Prints a JSON object representing the metadata.
* This function exits.
*
* Called from islandora_djatoka_book_reader.js.
*
* @param AbstractObject $object
* The page object to fetch the metadata from.
*/
Expand Down Expand Up @@ -88,8 +90,10 @@ function islandora_internet_archive_bookreader_search_callback($object_id, $term
* The DSID of the object with JP2/JPG datastreams.
*/
function islandora_internet_archive_bookreader_get_image_uri_callback($object_id) {
module_load_include('inc', 'islandora', 'includes/imageserver');
$dsid = 'JP2';
if (variable_get('islandora_internet_archive_bookreader_use_backup_dsid', FALSE)) {
if (variable_get('islandora_internet_archive_bookreader_use_backup_dsid', FALSE) &&
islandora_imageserver_get_settings()['type'] == 'djatoka') {
// TODO: We _think_ that Djatoka won't accept JP2s under 4 kibibytes, but
// it's unclear if that number is configured, or tied to something, or even
// if it's correct. We should investigate and make sure it's accurate.
Expand Down
35 changes: 30 additions & 5 deletions islandora_internet_archive_bookreader.install
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,44 @@
*/
function islandora_internet_archive_bookreader_uninstall() {
$variables = array(
'islandora_internet_archive_bookreader_djatoka_url',
'islandora_internet_archive_bookreader_compression',
'islandora_internet_archive_bookreader_ocr_field',
'islandora_internet_archive_bookreader_ocr_filter_field',
'islandora_internet_archive_bookreader_solr_result_count',
'islandora_internet_archive_bookreader_sequence_number',
'islandora_internet_archive_bookreader_overlay_opacity',
'islandora_internet_archive_bookreader_default_page_view',
'islandora_internet_archive_bookreader_iiif_url',
'islandora_internet_archive_bookreader_iiif_token_header',
'islandora_internet_archive_bookreader_iiif_identifier',
'islandora_internet_archive_bookreader_pagesource',
);
// Delete the Drupal variables defined by this module.
array_walk($variables, 'variable_del');
}

/**
* Implements hook_update_dependencies().
*/
function islandora_internet_archive_bookreader_update_dependencies() {
$dependencies = array(
'islandora_internet_archive_bookreader' => array(
7001 => array(
'islandora' => 7003,
),
),
);
return $dependencies;
}

/**
* Implements hook_update_N().
*
* Remove local imageserver settings, these are now in core Islandora.
*/
function islandora_internet_archive_bookreader_update_7001() {
$vars = array(
'islandora_internet_archive_bookreader_djatoka_url',
'islandora_internet_archive_bookreader_iiif_url',
'islandora_internet_archive_bookreader_iiif_token_header',
'islandora_internet_archive_bookreader_iiif_identifier',
'islandora_internet_archive_bookreader_pagesource',
);
array_walk($vars, 'variable_del');
}
87 changes: 0 additions & 87 deletions islandora_internet_archive_bookreader.module
Original file line number Diff line number Diff line change
Expand Up @@ -151,90 +151,3 @@ function islandora_internet_archive_bookreader_islandora_pageCModel_islandora_so
}
}
}

/**
* Implements hook_token_info().
*/
function islandora_internet_archive_bookreader_token_info() {
$info = array();

$info['types']['islandora_iareader'] = array(
'name' => t('Islandora IA Bookreader'),
'description' => t('Tokens for building IIIF identifer in Islandora IA Bookreader.'),
'needs-data' => 'islandora_iareader',
);

$info['tokens']['islandora_iareader']['pid'] = array(
'name' => t('PID'),
'description' => t('The objects PID.'),
);

$info['tokens']['islandora_iareader']['dsid'] = array(
'name' => t('DSID'),
'description' => t('The objects DSID.'),
);

$info['tokens']['islandora_iareader']['url'] = array(
'name' => t('URL'),
'description' => t('The URL to the object in Islandora.'),
);

$info['tokens']['islandora_iareader']['url_token'] = array(
'name' => t('URL with Token'),
'description' => t('The URL to the object in Islandora with token in the query string.'),
);

$info['tokens']['islandora_iareader']['token'] = array(
'name' => t('Token'),
'description' => t('The token that can be used to access the object in Islandora.'),
);

return $info;
}

/**
* Implements hook_tokens().
*/
function islandora_internet_archive_bookreader_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();

if ($type != 'islandora_iareader' || !isset($data['islandora_iareader'])) {
return $replacements;
}

$pid = $data['islandora_iareader']['pid'];
$dsid = $data['islandora_iareader']['dsid'];
$token = $data['islandora_iareader']['token'];

foreach ($tokens as $name => $original) {
if ($name == 'pid') {
$replacements[$original] = $pid;
}
elseif ($name == 'dsid') {
$replacements[$original] = $dsid;
}
elseif ($name == 'token') {
$replacements[$original] = $token;
}
elseif ($name == 'url' || $name == 'url_token') {
$options = array(
'absolute' => TRUE,
'language' => language_default(),
'https' => (function_exists('drupal_is_https') ?
drupal_is_https() :
(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')
),
);

if ($name == 'url_token') {
$options['query'] = array(
'token' => $token,
);
}

$replacements[$original] = url("islandora/object/{$pid}/datastream/{$dsid}/view", $options);
}
}

return $replacements;
}
5 changes: 1 addition & 4 deletions js/islandora_djatoka_book_reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@
//Do some sanitation on that base uri.
//Since it comes from an admin form, let's make sure there's a '/' at the
//end of it.
if (base_uri.charAt(base_uri.length) != '/') {
base_uri += '/';
}
var params = $.param({
'rft_id': resource_uri,
'url_ver': 'Z39.88-2004',
Expand All @@ -115,7 +112,7 @@
'svc.level': this.settings.compression,
'svc.rotate': 0
});
return (base_uri + 'resolver?' + params);
return (base_uri + '?' + params);
};

/**
Expand Down
17 changes: 10 additions & 7 deletions theme/theme.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ function template_preprocess_islandora_internet_archive_bookreader(array &$varia
module_load_include('inc', 'islandora_internet_archive_bookreader', 'includes/utilities');
module_load_include('inc', 'islandora_paged_content', 'includes/utilities');
module_load_include('inc', 'islandora', 'includes/authtokens');
module_load_include('inc', 'islandora', 'includes/imageserver');
$object = $variables['object'];
$dsid = $variables['datastream_id'];
$library_path = libraries_get_path('bookreader');
$colorbox_path = libraries_get_path('colorbox');
$module_path = drupal_get_path('module', 'islandora_internet_archive_bookreader');
$search_uri = module_exists('islandora_solr') ? url("internet_archive_bookreader_search/{$object->id}/TERM", array('absolute' => TRUE)) : NULL;
$perbook_view_mode = islandora_paged_content_get_viewing_hint($object);
$imageserver_settings = islandora_imageserver_get_settings();

if (isset($perbook_view_mode)) {
$view_mode = $perbook_view_mode == 'paged' ? 2 : 1;
Expand All @@ -28,7 +30,7 @@ function template_preprocess_islandora_internet_archive_bookreader(array &$varia
$view_mode = (int) variable_get('islandora_internet_archive_bookreader_default_page_view', 1);
}
$hascover = islandora_paged_content_get_hascover($object) == 'true' ? TRUE : FALSE;
$page_source = variable_get('islandora_internet_archive_bookreader_pagesource', 'djatoka');
$page_source = $imageserver_settings['type'];
$page_source_settings = array();
$pages = array();

Expand All @@ -48,30 +50,31 @@ function template_preprocess_islandora_internet_archive_bookreader(array &$varia
$page_source_settings = array(
'tokenUri' => url('internet_archive_bookreader_get_image_uri/PID', array('absolute' => TRUE)),
'dimensionsUri' => url('internet_archive_bookreader_dimensions/PID', array('absolute' => TRUE)),
'djatokaUri' => variable_get('islandora_paged_content_djatoka_url', 'http://localhost:8080/adore-djatoka'),
'djatokaUri' => $imageserver_settings['url'],
'compression' => variable_get('islandora_internet_archive_bookreader_compression', '4'),
'pages' => $pages,
'pageCount' => count($pages),
'useBackupUri' => $backup_uris,
);
}
elseif ($page_source == 'iiif') {
$identifier_string = variable_get('islandora_internet_archive_bookreader_iiif_identifier', '[islandora_iareader:url_token]');
$iiif_url = file_create_url(rtrim(variable_get('islandora_internet_archive_bookreader_iiif_url', 'iiif'), '/'));
$identifier_string = $imageserver_settings['iiif_identifier'];
$iiif_url = file_create_url(rtrim($imageserver_settings['url'], '/'));
foreach ($variables['pages'] as $page_pid => $info) {
$token = islandora_get_object_token($page_pid, $dsid, 2);
$page_info = array(
'pid' => $page_pid,
'dsid' => $dsid,
'token' => islandora_get_object_token($page_pid, $dsid, 2),
'token' => $token,
);
$identifier = token_replace($identifier_string, array('islandora_iareader' => $page_info));
$identifier = islandora_imageserver_get_identifier($identifier_string, $page_pid, $dsid, $token);
$pages[] = $info + $page_info + array('identifier' => urlencode($identifier));
}
$page_source_settings = array(
'iiifUri' => $iiif_url,
'pages' => $pages,
'pageCount' => count($pages),
'tokenHeader' => (bool) variable_get('islandora_internet_archive_bookreader_iiif_token_header', FALSE),
'tokenHeader' => (bool) $imageserver_settings['iiif_token_header'],
);
}

Expand Down