diff --git a/local/config/vufind/config.ini b/local/config/vufind/config.ini index 2656d4f0842278822fee6bc602a479a79468e8c0..b37242be590372b08e457aab190fc7b2afd2cba8 100644 --- a/local/config/vufind/config.ini +++ b/local/config/vufind/config.ini @@ -637,6 +637,17 @@ coverimagesCache = true ; path relative to the base of your theme directory for a static image to display. noCoverAvailableImage = images/noCover2.gif + +; This setting controls how cover image URLs are loaded. They could be loaded as +; part of main request, or asynchronously. Asynchronous loading is disabled by +; default; to enable it, just uncomment the line below. +;ajaxcovers = true + +; When ajaxcovers is set to true, this setting controls whether the AJAX Handler +; GetRecordCover renders a fallback template (record/coverReplacement.phtml) in case +; no cover image could be loaded. +;useCoverFallbacksOnFail = false + ; You can select from Syndetics, SyndeticsPlus, Amazon Editorial, Amazon, Booksite ; and/or the Guardian ; Note: If the API key is omitted, e.g. "Guardian:", only the review title, byline, diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php index 401440dc5d3a359c44d3430868fd3fbff2128119..7d0686eb6114c51dbdc952d9d39a9e94e96c13ba 100644 --- a/module/finc/config/module.config.php +++ b/module/finc/config/module.config.php @@ -13,6 +13,8 @@ $config = [ 'finc\ILS\Logic\Holds' => 'VuFind\ILS\Logic\LogicFactory', 'finc\Rewrite\EblRewrite' => 'finc\Rewrite\EblRewriteFactory', 'finc\Listener\I18nDataDirListener' => 'Zend\ServiceManager\Factory\InvokableFactory', + 'finc\Cover\Loader' => 'VuFind\Cover\LoaderFactory', + 'finc\Cover\Router' => 'finc\Cover\RouterFactory', ], 'delegators' => [ 'VuFindSearch\Service' => [ @@ -23,6 +25,8 @@ $config = [ 'VuFind\Cache\Manager' => 'finc\Cache\Manager', 'VuFind\ILS\Connection' => 'finc\ILS\Connection', 'VuFind\ILS\Logic\Holds' => 'finc\ILS\Logic\Holds', + 'VuFind\Cover\Loader' => 'finc\Cover\Loader', + 'VuFind\Cover\Router' => 'finc\Cover\Router', ] ], 'controllers' => [ @@ -61,7 +65,9 @@ $config = [ 'finc\AjaxHandler\GetItemStatuses' => 'VuFind\AjaxHandler\GetItemStatusesFactory', 'finc\AjaxHandler\GetResolverLinks' => - 'finc\AjaxHandler\GetResolverLinksFactory' + 'finc\AjaxHandler\GetResolverLinksFactory', + 'finc\AjaxHandler\GetRecordCover' => + 'finc\AjaxHandler\GetRecordCoverFactory' ], 'aliases' => [ 'getAdditionalAccountInfo' => @@ -71,7 +77,9 @@ $config = [ 'getItemStatuses' => 'finc\AjaxHandler\GetItemStatuses', 'getResolverLinks' => - 'finc\AjaxHandler\GetResolverLinks' + 'finc\AjaxHandler\GetResolverLinks', + 'getRecordCover' => + 'finc\AjaxHandler\GetRecordCover', ] ], 'ils_driver' => [ diff --git a/module/finc/src/finc/AjaxHandler/GetRecordCover.php b/module/finc/src/finc/AjaxHandler/GetRecordCover.php new file mode 100644 index 0000000000000000000000000000000000000000..8c6333421a14867637c08a4ce3308124bf026029 --- /dev/null +++ b/module/finc/src/finc/AjaxHandler/GetRecordCover.php @@ -0,0 +1,151 @@ +<?php +/** this is a backport of the VF 7 core version. with the necessary + * adaptations. + * Remove this on upgrade + */ +/** + * GetRecordCover AJAX handler. + * + * PHP version 7 + * + * Copyright (C) Villanova University 2018. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @deprecated remove on VF 7 upgrade + * @category VuFind + * @package AJAX + * @author Josef Moravec <moravec@mzk.cz> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace finc\AjaxHandler; + +use VuFind\AjaxHandler\AbstractBase; +use VuFind\AjaxHandler\AjaxHandlerInterface; +use Zend\Mvc\Controller\Plugin\Params; +use Zend\View\Renderer\PhpRenderer; +use finc\Cover\Router as CoverRouter; +use VuFind\Exception\RecordMissing as RecordMissingException; +use VuFind\ILS\Driver\CacheTrait; +use VuFind\Record\Loader as RecordLoader; + +/** + * GetRecordCover AJAX handler. + * + * @category VuFind + * @package AJAX + * @author Josef Moravec <moravec@mzk.cz> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class GetRecordCover extends AbstractBase implements AjaxHandlerInterface +{ + use CacheTrait; + + /** + * Record loader + * + * @var RecordLoader + */ + protected $recordLoader; + + /** + * Cover router + * + * @var CoverRouter + */ + protected $coverRouter; + + /** + * PHP renderer + * + * @var PhpRenderer + */ + protected $renderer; + + /** + * If true we will render a fallback html template in case no image could be + * loaded + * + * @var bool + */ + protected $useCoverFallbacksOnFail = false; + + /** + * GetRecordCover constructor. + * + * @param RecordLoader $recordLoader Record loader + * @param CoverRouter $coverRouter Cover router + * @param PhpRenderer $renderer PHP renderer (only required if + * $userCoverFallbacksOnFail is set to true) + * @param bool $useCoverFallbacksOnFail If true we will render a + * fallback html template in case no image could be loaded + */ + public function __construct(RecordLoader $recordLoader, + CoverRouter $coverRouter, + ?PhpRenderer $renderer = null, + $useCoverFallbacksOnFail = false + ) { + $this->recordLoader = $recordLoader; + $this->coverRouter = $coverRouter; + $this->renderer = $renderer; + $this->useCoverFallbacksOnFail = $useCoverFallbacksOnFail; + } + + /** + * Handle request + * + * @param Params $params Request parameters + * + * @return array + * @throws \Exception + */ + public function handleRequest(Params $params) + { + $recordId = $params->fromQuery('recordId'); + $recordSource = $params->fromQuery('source', DEFAULT_SEARCH_BACKEND); + $size = $params->fromQuery('size', 'small'); + try { + $record = $this->recordLoader->load($recordId, $recordSource); + } catch (RecordMissingException $exception) { + return $this->formatResponse( + 'Could not load record: ' . $exception->getMessage(), + self::STATUS_HTTP_BAD_REQUEST + ); + } + + if (!in_array($size, ['small', 'medium', 'large'])) { + return $this->formatResponse( + 'Not valid size: ' . $size, + self::STATUS_HTTP_BAD_REQUEST + ); + } + + $url = $this->coverRouter->getUrl( + $record, $size ?? 'small', true, $this->useCoverFallbacksOnFail + ); + + return ($url || !$this->renderer || !$this->useCoverFallbacksOnFail) + ? $this->formatResponse(compact('url', 'size')) + : $this->formatResponse( + [ + 'html' => $this->renderer->render( + 'record/coverReplacement', + ['driver' => $record] + ) + ] + ); + } +} diff --git a/module/finc/src/finc/AjaxHandler/GetRecordCoverFactory.php b/module/finc/src/finc/AjaxHandler/GetRecordCoverFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..45fad1b98b8ccd1f9cff3b964de84f58862067ae --- /dev/null +++ b/module/finc/src/finc/AjaxHandler/GetRecordCoverFactory.php @@ -0,0 +1,82 @@ +<?php +/** this is a backport of the VF 7 core version. with the necessary + * adaptations. + * Remove this on upgrade + */ +/** + * Factory for GetRecordCover AJAX handler. + * + * PHP version 7 + * + * Copyright (C) Villanova University 2018. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @deprecated remove on upgrade + * @category VuFind + * @package AJAX + * @author Josef Moravec <moravec@mzk.cz> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace finc\AjaxHandler; + +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; +use Zend\ServiceManager\Factory\FactoryInterface; + +/** + * Factory for GetRecordCover AJAX handler. + * + * @category VuFind + * @package AJAX + * @author Josef Moravec <moravec@mzk.cz> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class GetRecordCoverFactory implements FactoryInterface +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function __invoke(ContainerInterface $container, $requestedName, + array $options = null + ) { + $config + = $container->get(\VuFind\Config\PluginManager::class)->get('config'); + $useFallbacks = $config->Content->useCoverFallbacksOnFail ?? false; + return new $requestedName( + $container->get(\VuFind\Record\Loader::class), + $container->get(\VuFind\Cover\Router::class), + // We only need the view renderer if we're going to use fallbacks: + $useFallbacks ? $container->get('ViewRenderer') : null, + $useFallbacks + ); + } +} diff --git a/module/finc/src/finc/Cover/Loader.php b/module/finc/src/finc/Cover/Loader.php new file mode 100644 index 0000000000000000000000000000000000000000..b67ff8ee24e3f877679eafc1cbee4f2ac09bfb07 --- /dev/null +++ b/module/finc/src/finc/Cover/Loader.php @@ -0,0 +1,97 @@ +<?php +/** + * Book Cover Generator + * + * PHP version 7 + * + * Copyright (C) Villanova University 2007. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Cover_Generator + * @author Andrew S. Nagy <vufind-tech@lists.sourceforge.net> + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/configuration:external_content Wiki + */ +namespace finc\Cover; + +/** + * Book Cover Generator + * + * @deprecated backport of VuFind 7 core version, remove on upgrade + * @category VuFind + * @package Cover_Generator + * @author Andrew S. Nagy <vufind-tech@lists.sourceforge.net> + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/configuration:external_content Wiki + */ +class Loader extends \VuFind\Cover\Loader +{ + /** + * Flag denoting the last loaded image was a FailImage + * + * @var bool + */ + protected $hasLoadedUnavailable = false; + + /** + * {@inheritdoc} + * Adds @see self::$hasLoadedUnavailable flag + * + * @return void + */ + public function loadUnavailable() + { + $this->hasLoadedUnavailable = true; + return parent::loadUnavailable(); + } + + /** + * Returns true if the last loaded image was the FailImage + * + * @return bool + */ + public function hasLoadedUnavailable() + { + return $this->hasLoadedUnavailable; + } + + /** + * Return API handlers + * + * @return \Generator Array with keys: key - API key, apiName - api name from + * configuration, handler - handler object + */ + public function getHandlers() + { + if (!isset($this->config->Content->coverimages)) { + return []; + } + $providers = explode(',', $this->config->Content->coverimages); + foreach ($providers as $provider) { + $provider = explode(':', trim($provider)); + $apiName = strtolower(trim($provider[0])); + $key = isset($provider[1]) ? trim($provider[1]) : null; + yield [ + 'key' => $key, + 'apiName' => $apiName, + 'handler' => $this->apiManager->get($apiName), + ]; + } + } + +} diff --git a/module/finc/src/finc/Cover/Router.php b/module/finc/src/finc/Cover/Router.php new file mode 100644 index 0000000000000000000000000000000000000000..8a758f27c9f6adb72c488431ee3a4584026c9fb0 --- /dev/null +++ b/module/finc/src/finc/Cover/Router.php @@ -0,0 +1,115 @@ +<?php +/** + * Cover image router + * + * PHP version 7 + * + * Copyright (C) Villanova University 2016. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Cover_Generator + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/configuration:external_content Wiki + */ +namespace finc\Cover; + +use finc\Cover\Loader as CoverLoader; +use VuFind\RecordDriver\AbstractBase as RecordDriver; + +/** + * Cover image router + * + * @deprecated backport of VuFind 7 core version, remove on upgrade + * @category VuFind + * @package Cover_Generator + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/configuration:external_content Wiki + */ +class Router implements \Zend\Log\LoggerAwareInterface +{ + use \VuFind\Log\LoggerAwareTrait; + + /** + * Base URL for dynamic cover images. + * + * @var string + */ + protected $dynamicUrl; + + /** + * Cover loader + * + * @var CoverLoader + */ + protected $coverLoader; + + /** + * Constructor + * + * @param string $url Base URL for dynamic cover images. + * @param CoverLoader $coverLoader Cover loader + */ + public function __construct($url, CoverLoader $coverLoader) + { + $this->dynamicUrl = $url; + $this->coverLoader = $coverLoader; + } + + /** + * This is an adaptation of the VuFind Version to fit the current (VF5) state + * + * Generate a thumbnail URL (return false if unsupported). + * + * @param RecordDriver $driver Record driver + * @param string $size Size of thumbnail (small, medium or large -- + * small is default). + * + * @return string|bool + */ + public function getUrl(RecordDriver $driver, $size = 'small', + $resolveDynamic = true, $testLoadImage = false + ) + { + // Try to build thumbnail: + $thumb = $driver->tryMethod('getThumbnail', [$size]); + + // No thumbnail? Return false: + if (empty($thumb)) { + return false; + } + + // Array? It's parameters to send to the cover generator: + if (is_array($thumb)) { + if (!$resolveDynamic) { + return null; + } + $settings = is_array($thumb) ? array_merge($thumb, ['size' => $size]) + : ['size' => $size]; + if ($testLoadImage) { + $this->coverLoader->loadImage($settings); + if ($this->coverLoader->hasLoadedUnavailable()) { + return false; + } + } + return $this->dynamicUrl . '?' . http_build_query($thumb); + } + + // Default case -- return fixed string: + return $thumb; + } +} diff --git a/module/finc/src/finc/Cover/RouterFactory.php b/module/finc/src/finc/Cover/RouterFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..95b59b8df5c3664d1a705c14ecf77a84b10058c8 --- /dev/null +++ b/module/finc/src/finc/Cover/RouterFactory.php @@ -0,0 +1,76 @@ +<?php +/** + * Cover router factory. + * + * PHP version 7 + * + * Copyright (C) Villanova University 2018. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Cover_Generator + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace finc\Cover; + +use Interop\Container\ContainerInterface; +use Zend\ServiceManager\Factory\FactoryInterface; + +/** + * Cover router factory. + * + * @category VuFind + * @package Cover_Generator + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class RouterFactory implements FactoryInterface +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, + array $options = null + ) { + if (!empty($options)) { + throw new \Exception('Unexpected options sent to factory.'); + } + // Try to get the base URL from the controller plugin; fail over to + // the view helper if that doesn't work. + try { + $base = $container->get('ControllerPluginManager')->get('url') + ->fromRoute('cover-show'); + } catch (\Exception $e) { + $base = $container->get('ViewRenderer')->plugin('url') + ->__invoke('cover-show'); + } + $coverLoader = $container->get(\finc\Cover\Loader::class); + return new $requestedName($base, $coverLoader); + } +} diff --git a/module/finc/src/finc/View/Helper/Root/Record.php b/module/finc/src/finc/View/Helper/Root/Record.php index 5a59179a709d672563e851cd8cc01eae53ce517b..2f6e266a607ef8b44f1c337d2096a17712188809 100644 --- a/module/finc/src/finc/View/Helper/Root/Record.php +++ b/module/finc/src/finc/View/Helper/Root/Record.php @@ -523,4 +523,63 @@ class Record extends \VuFind\View\Helper\Root\Record } return $queryParams; } + + /** + * Get the rendered cover plus some useful parameters. + * + * @deprecated used for VF7 ajaxcovers, remove on upgrade + * @param string $context Context of code being generated + * @param string $default The default size of the cover + * @param string $link The link for the anchor + * + * @return array + */ + public function getCoverDetails($context, $default, $link = false) + { + $details = compact('link', 'context') + [ + 'driver' => $this->driver, 'cover' => false, 'size' => false, + 'linkPreview' => $this->getPreviewCoverLinkSetting($context), + ]; + $preferredSize = $this->getCoverSize($context, $default); + if (empty($preferredSize)) { // covers disabled entirely + $details['html'] = ''; + } else { + // Find best option if more than one size is defined (e.g. small:medium) + foreach (explode(':', $preferredSize) as $size) { + if ($details['cover'] = $this->getThumbnail($size)) { + $details['size'] = $size; + break; + } + } + if ($details['size'] === false) { + // we need to set a size for the ajax covers to work correctly + list($details['size']) = explode(':', $preferredSize); + } + + $details['html'] = $this->contextHelper->renderInContext( + 'record/cover.phtml', $details + ); + } + return $details; + } + + /** + * Generate a thumbnail URL (return false if unsupported). + * + * @deprecated used for VF7 ajaxcovers, remove on upgrade + * @param string $size Size of thumbnail (small, medium or large -- small is + * default). + * + * @return string|bool + */ + public function getThumbnail($size = 'small') + { + // Find out whether or not AJAX covers are enabled; this will control + // whether dynamic URLs are resolved immediately or deferred until later + // (see third parameter of getUrl() below). + $ajaxcovers = $this->config->Content->ajaxcovers ?? false; + return $this->coverRouter + ? $this->coverRouter->getUrl($this->driver, $size, !$ajaxcovers) + : false; + } } diff --git a/themes/finc/js/covers.js b/themes/finc/js/covers.js new file mode 100644 index 0000000000000000000000000000000000000000..c251aefba80b034997452c4b1b7103e13847df78 --- /dev/null +++ b/themes/finc/js/covers.js @@ -0,0 +1,47 @@ +/* this is a backport from VF 7 core, remove on upgrade */ +/*global VuFind */ +function loadCoverByElement(data, element) { + var url = VuFind.path + '/AJAX/JSON?method=' + 'getRecordCover'; + var img = element.find('img'); + var spinner = element.children('div.spinner'); + var container = element.children('div.cover-container'); + var anchor = container.children('a.coverlink'); + function coverCallback(response) { + spinner.hide(); + container.show(); + if (typeof response.data.url !== 'undefined' && response.data.url !== false) { + img.attr("src", response.data.url); + container.children().not("img").hide(); + anchor.show(); + anchor.attr("href", response.data.url); + } else { + img.remove(); + if (typeof response.data.html !== 'undefined') { + container.html(response.data.html); + } else { + container.html(); + } + } + } + $.ajax({ + dataType: "json", + url: url, + method: "GET", + data: data, + element: element, + success: coverCallback + }); +} + +function loadCovers() { + $('.ajaxcover').each(function getDataAndLoadCovers() { + var img = $(this).find('img'); + var data = { + source: img.data('recordsource'), + recordId: img.data('recordid'), + size: img.data('coversize') + }; + loadCoverByElement(data, $(this)); + }); +} +$(document).ready(loadCovers); diff --git a/themes/finc/templates/record/cover.phtml b/themes/finc/templates/record/cover.phtml index 25c3a4a83873fab0b842a65d405672b1ab8d1537..af93f5da6ee32dd07521c4c5006ff8eda9fa2dbc 100644 --- a/themes/finc/templates/record/cover.phtml +++ b/themes/finc/templates/record/cover.phtml @@ -2,11 +2,21 @@ <?php /* Display thumbnail if appropriate: */ ?> <?php /* If you want to load covers in lightbox use .recordcover; the class .nocover prevents nocover images from loading in lightbox or can be used to hide the images */ ?> +<?php $alt = $alt ?? $this->transEsc('Cover Image')?> <?php if ($cover): ?> - <?php if ($this->link): ?><a href="<?=$this->escapeHtmlAttr($this->link)?>" data-lightbox-image aria-hidden="true"><?php endif; ?> - <img alt="<?=$this->transEsc('Cover Image')?>" <?php if ($linkPreview): ?>data-linkpreview="true" <?php endif; ?>class="recordcover" src="<?=$this->escapeHtmlAttr($cover); ?>" aria-hidden="true"/> + <?php if ($this->link): ?><a href="<?=$this->escapeHtmlAttr($this->link)?>" target="_blank" aria-hidden="true"><?php endif; ?> + <img alt="<?=$alt?>" <?php if ($linkPreview): ?>data-linkpreview="true" <?php endif; ?>class="recordcover" src="<?=$this->escapeHtmlAttr($cover); ?>" aria-hidden="true"/> <?php if ($this->link): ?></a><?php endif; ?> -<?php else: ?> +<?php elseif ($cover === false): ?> <img src="<?=$this->url('cover-unavailable')?>" <?php if ($linkPreview): ?>data-linkpreview="true" <?php endif; ?>class="nocover" alt="<?=$this->transEsc('No Cover Image')?>" aria-hidden="true" /> +<?php else: ?> + <div class="ajaxcover"> + <div class="spinner"><i class="fa fa-spinner fa-spin"></i> <?=$this->translate('Loading')?>...</div> + <div class="cover-container"> + <a class="coverlink"> + <img <?php if ($linkPreview): ?>data-linkpreview="true" <?php endif; ?>data-recordsource="<?=$this->escapeHtmlAttr($driver->getSourceIdentifier())?>" data-recordid="<?=$this->escapeHtmlAttr($driver->getUniqueID())?>" data-coversize="<?=$this->escapeHtmlAttr($size)?>" class="recordcover ajax" alt="<?=$this->escapeHtmlAttr($alt); ?>" /> + </a> + </div> + </div> <?php endif; ?> <!-- finc: record - cover - END --> diff --git a/themes/finc/templates/record/coverReplacement.phtml b/themes/finc/templates/record/coverReplacement.phtml new file mode 100644 index 0000000000000000000000000000000000000000..d74b4f1f8f5847b60f8da4fbe046abfddfab6438 --- /dev/null +++ b/themes/finc/templates/record/coverReplacement.phtml @@ -0,0 +1 @@ +<?= $this->record($this->driver)->getRecordIcon() ?> \ No newline at end of file diff --git a/themes/finc/theme.config.php b/themes/finc/theme.config.php index 4b4e93f7ae4fc661cb1da8d5c0bb202a26c87dc3..06d4ee532cace75b842d66ea554d8d5427d80d17 100644 --- a/themes/finc/theme.config.php +++ b/themes/finc/theme.config.php @@ -4,6 +4,7 @@ return [ 'js' => [ 'check_item_statuses.js', 'lightbox_form_cache.js', + 'covers.js' ], 'helpers' => [ 'aliases' => [ @@ -13,6 +14,7 @@ return [ 'sideFacet' => 'finc\View\Helper\Root\SideFacet', 'resultfeed' => 'finc\View\Helper\Root\ResultFeed', 'recordLink' => 'finc\View\Helper\Root\RecordLink', + 'record' => 'finc\View\Helper\Root\Record', ], 'factories' => [ 'finc\View\Helper\Root\BranchInfo' => @@ -23,7 +25,7 @@ return [ 'finc\View\Helper\Root\Factory::getInterlibraryLoanLink', 'finc\View\Helper\Root\SideFacet' => 'finc\View\Helper\Root\Factory::getSideFacet', - 'VuFind\View\Helper\Root\Record' => + 'finc\View\Helper\Root\Record' => 'finc\View\Helper\Root\Factory::getRecord', 'finc\View\Helper\Root\RecordLink' => 'finc\View\Helper\Root\Factory::getRecordLink',