diff --git a/README.md b/README.md index defdd01..2d5e37a 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/includes/admin.form.inc b/includes/admin.form.inc index e6f08f9..9fd5cf6 100644 --- a/includes/admin.form.inc +++ b/includes/admin.form.inc @@ -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'), @@ -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' => '
', - '#suffix' => '
', - '#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', diff --git a/includes/callback.inc b/includes/callback.inc index 70e8108..3b4106b 100644 --- a/includes/callback.inc +++ b/includes/callback.inc @@ -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. */ @@ -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. diff --git a/islandora_internet_archive_bookreader.install b/islandora_internet_archive_bookreader.install index 8cde14c..97b3bda 100644 --- a/islandora_internet_archive_bookreader.install +++ b/islandora_internet_archive_bookreader.install @@ -10,7 +10,6 @@ */ 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', @@ -18,11 +17,37 @@ function islandora_internet_archive_bookreader_uninstall() { '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'); +} diff --git a/islandora_internet_archive_bookreader.module b/islandora_internet_archive_bookreader.module index 12fe7bc..6dda926 100644 --- a/islandora_internet_archive_bookreader.module +++ b/islandora_internet_archive_bookreader.module @@ -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; -} diff --git a/js/islandora_djatoka_book_reader.js b/js/islandora_djatoka_book_reader.js index 34b164d..da694a1 100644 --- a/js/islandora_djatoka_book_reader.js +++ b/js/islandora_djatoka_book_reader.js @@ -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', @@ -115,7 +112,7 @@ 'svc.level': this.settings.compression, 'svc.rotate': 0 }); - return (base_uri + 'resolver?' + params); + return (base_uri + '?' + params); }; /** diff --git a/theme/theme.inc b/theme/theme.inc index 4854611..d70ba64 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -12,6 +12,7 @@ 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'); @@ -19,6 +20,7 @@ function template_preprocess_islandora_internet_archive_bookreader(array &$varia $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; @@ -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(); @@ -48,7 +50,7 @@ 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), @@ -56,22 +58,23 @@ function template_preprocess_islandora_internet_archive_bookreader(array &$varia ); } 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'], ); }