From 976cbb81c5682b9db358c55437ac1ee90007986a Mon Sep 17 00:00:00 2001 From: Martin Dahl Date: Fri, 21 Dec 2012 16:33:13 +0100 Subject: [PATCH] Opdteret til moreinfo.addi.dk --- js/ting-covers.js | 4 +++ .../AdditionalInformationService.php | 25 +++++++++---------- ting_covers.pages.inc | 13 ++++++++-- ting_covers.theme.inc | 6 +++-- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/js/ting-covers.js b/js/ting-covers.js index 28a5f64..1164186 100644 --- a/js/ting-covers.js +++ b/js/ting-covers.js @@ -25,6 +25,10 @@ $('.ting-cover:not(.ting-cover-processing, .ting-cover-processed)', context).each(function(i, e) { coverData.push(Drupal.extractCoverData(e)); }).addClass('ting-cover-processing'); + + // $('.ting-cover', context).each(function(i, e) { + // coverData.push(Drupal.extractCoverData(e)); + // }).addClass('ting-cover-processing'); if (coverData.length > 0) { //Retrieve covers diff --git a/lib/addi-client/AdditionalInformationService.php b/lib/addi-client/AdditionalInformationService.php index 4c1946c..24a10ee 100644 --- a/lib/addi-client/AdditionalInformationService.php +++ b/lib/addi-client/AdditionalInformationService.php @@ -57,9 +57,8 @@ protected function sendRequest($identifiers) 'authenticationGroup' => $this->group, 'authenticationPassword' => $this->password); $client = new SoapClient($this->wsdlUrl); - - $startTime = explode(' ', microtime()); - $response = $client->additionalInformation(array( + $startTime = explode(' ', microtime()); + $response = $client->moreInfo(array( 'authentication' => $authInfo, 'identifier' => $identifiers)); @@ -75,7 +74,7 @@ protected function sendRequest($identifiers) { throw new AdditionalInformationServiceException($response->requestStatus->statusEnum.': '.$response->requestStatus->errorText); } - + if (!is_array($response->identifierInformation)) { $response->identifierInformation = array($response->identifierInformation); @@ -91,26 +90,26 @@ protected function extractAdditionalInformation($idName, $response) foreach($response->identifierInformation as $info) { $thumbnailUrl = $detailUrl = NULL; - if (isset($info->identifierKnown) && $info->identifierKnown && $info->image ) + if (isset($info->identifierKnown) && $info->identifierKnown && $info->coverImage ) { - if (!is_array($info->image)) + if (!is_array($info->coverImage)) { - $info->image = array($info->image); + $info->coverImage = array($info->coverImage); } - - foreach ($info->image as $image) + + foreach ($info->coverImage as $image) { switch ($image->imageSize) { case 'thumbnail': - $thumbnailUrl = $image->_; + $thumbnailUrl = $image->_; break; case 'detail': - $detailUrl = $image->_; + $detailUrl = $image->_; break; default: - // Do nothing other image sizes may appear but ignore them for now + // Do nothing other image sizes may appear but ignore them for now } - } + } $additionalInfo = new AdditionalInformation($thumbnailUrl, $detailUrl); $additionalInformations[$info->identifier->$idName] = $additionalInfo; diff --git a/ting_covers.pages.inc b/ting_covers.pages.inc index c8762cb..a2db1f2 100644 --- a/ting_covers.pages.inc +++ b/ting_covers.pages.inc @@ -5,7 +5,7 @@ */ function ting_covers_objects() { $covers = array(); - $missing_images_local_ids = array(); + $missing_images = $missing_images_local_ids = array(); foreach ($_POST['coverData'] as $cover_info) { //Reverse cover_info before and after explode to make sure that we explode around @@ -24,6 +24,10 @@ function ting_covers_objects() { } else { //Mark the image for retrieval; $missing_images_local_ids[] = $local_id; + if (!isset($missing_images['i_' . $local_id])) { + $missing_images['i_' . $local_id] = array(); + } + $missing_images['i_' . $local_id][$image_style] = TRUE; } } @@ -45,6 +49,9 @@ function ting_covers_objects() { //No cover image found? Cache this for future reference to avoid unnecessary requests if (!$source_url) { + // foreach ($missing_images['i_' . $local_id] as $image_style => $holder) { + // $covers[$local_id.':'.$image_style] = image_style_url($image_style, 'public://manual/DEFAULT_COVER_IMAGE.jpg'); + // } cache_set('ting_covers:'.$local_id, 1, 'cache', $_SERVER['REQUEST_TIME'] + TING_COVERS_CACHE_LIFETIME); continue; } @@ -52,7 +59,9 @@ function ting_covers_objects() { //Try to download the image locally if ($file = _ting_covers_pages_fetch_image(ting_covers_object_path($local_id), $source_url)) { //Generate a path corresponding to the downloaded image, styled - $covers[$local_id.':'.$image_style] = image_style_url($image_style, $file->uri); + foreach ($missing_images['i_' . $local_id] as $image_style => $holder) { + $covers[$local_id.':'.$image_style] = image_style_url($image_style, $file->uri); + } } } } catch (Exception $e) { diff --git a/ting_covers.theme.inc b/ting_covers.theme.inc index 8057562..30a8179 100644 --- a/ting_covers.theme.inc +++ b/ting_covers.theme.inc @@ -12,9 +12,9 @@ function template_preprocess_ting_object_cover(&$variables) { //If we already have the image available locally then just use it $path = ting_covers_object_path($object->localId); - if (file_exists($path)) { - //Generate an alt tag + //Generate an alt tag $alt = implode(', ', $object->creators).': '.$object->title; + if (file_exists($path)) { $variables['image'] = theme('image_style', array('style_name' => $variables['image_style'], 'path' => $path, 'alt' => $alt)); @@ -24,6 +24,8 @@ function template_preprocess_ting_object_cover(&$variables) { //We know that there is no cover available for this object so avoid //further javascript processing $variables['classes'][] = 'ting-cover-processed'; + // $variables['image'] = theme('image_style', array('style_name' => $variables['image_style'], 'path' => 'public://manual/DEFAULT_COVER_IMAGE.jpg', 'alt' => $alt)); + } }