From 7749a2f39f2f86aac5dd85ae66897a0d39e5e0e9 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 4 May 2012 11:26:50 -0300 Subject: [PATCH] Introduce and use function to render an image. This function tries to make use of imagecache(_external) if it is avaiable; otherwise, falls back to using theme('image'). --- CollectionClass.inc | 11 +------- fedora_repository.module | 55 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/CollectionClass.inc b/CollectionClass.inc index 9cebc3ce..81f5f143 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -706,16 +706,7 @@ class CollectionClass { "fedora/repository/{$result['thumbnail']}": "$obj_path/TN"); - $thumbnail = NULL; - if ($thumbnail === NULL && - module_exists('imagecache_external') && - is_callable('theme_imagecache_external_image') && - variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE)) { - $thumbnail = theme('imagecache_external_image', 'fedora_repository_collection_thumbnail', $tn_path, $truncated_title, $title); - } - if ($thumbnail === NULL) { - $thumbnail = theme('image', $tn_path, $truncated_title, $title, array(), FALSE); - } + $thumbnail = _fedora_repository_render_image($tn_path); $results[] = array( 'data' => l($thumbnail, $obj_path, array( diff --git a/fedora_repository.module b/fedora_repository.module index 67397716..3ff8b292 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -2384,7 +2384,10 @@ function fedora_repository_forms($form_id) { return $forms; } -function usc_mirc_imagecache_default_presets() { +/** + * Implementation of hook_imagecache_default_presets(). + */ +function fedora_repository_imagecache_default_presets() { return array( 'fedora_repository_collection_thumbnail' => array( 'presetname' => 'fedora_repository_collection_thumbnail', @@ -2403,3 +2406,53 @@ function usc_mirc_imagecache_default_presets() { ), ); } + +/** + * Actually render an image, given an arbitrary path and preset. + * + * Note: If imagecache_external is not available, the full-sized image will be + * produced... Might want to look into restricting the display size by adding + * the width and height attributes to the theme('image') call, based on the + * selected preset? (get the presets and figure out the size from its actions?) + * + * @param $tn_path string + * @param $imagecache_preset string + * @return + * Markup for the image, making use of imagecache_external if it is available. + */ +function _fedora_repository_render_image($tn_path, $imagecache_preset = 'fedora_repository_collection_thumbnail') { + $thumbnail = NULL; + if ($thumbnail === NULL && + module_exists('imagecache_external') && + is_callable('theme_imagecache_external_image') && + variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE)) { + $thumbnail = theme('imagecache_external_image', $imagecache_preset, $tn_path, $truncated_title, $title); + } + if ($thumbnail === NULL) { + $thumbnail = theme('image', $tn_path, $truncated_title, $title, array(), FALSE); + } + + return $thumbnail; +} + +/** + * Render an image, given a PID, DSID and preset. + * + * Produces a Drupal path for the image, passes to + * _fedora_repository_render_image(), and returns the result. + * + * @see _fedora_repository_render_image() + * @param $pid string + * A string containing a Fedora PID. + * @param $dsid + * A string indicating a DSID on the object indicated by $pid. + * @param $imagecache_preset + * An imagecache preset with which to render the image; defaults to + * fedora_repository_collection_thumbnail, which is added in this module's + * implementation of hook_imagecache_default_presets(). + */ +function fedora_repository_render_image($pid, $dsid, $imagecache_preset = 'fedora_repository_collection_thumbnail') { + $tn_path = "fedora/repository/$pid/$dsid"; + + return _fedora_repository_render_image($tn_path, $imagecache_preset); +}