diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php index 6cfec1f114495fcfd0daa6badadcae9a5db5a7ab..c57c3b0e46300564dc142281639e8e9c737e021d 100644 --- a/module/finc/config/module.config.php +++ b/module/finc/config/module.config.php @@ -17,8 +17,7 @@ $config = [ 'finc\ILS\Logic\Holds' => 'VuFind\ILS\Logic\LogicFactory', 'finc\Rewrite\EblRewrite' => 'finc\Rewrite\EblRewriteFactory', 'finc\Listener\I18nDataDirListener' => 'Laminas\ServiceManager\Factory\InvokableFactory', - 'finc\Cover\Loader' => 'VuFind\Cover\LoaderFactory', - 'finc\Cover\Router' => 'finc\Cover\RouterFactory', + 'finc\Cover\Loader' => 'VuFind\Cover\LoaderFactory' ], 'delegators' => [ 'VuFindSearch\Service' => [ @@ -34,8 +33,7 @@ $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', + 'VuFind\Cover\Loader' => 'finc\Cover\Loader' ] ], 'controllers' => [ @@ -90,8 +88,6 @@ $config = [ 'VuFind\AjaxHandler\GetItemStatusesFactory', 'finc\AjaxHandler\GetResolverLinks' => 'finc\AjaxHandler\GetResolverLinksFactory', - 'finc\AjaxHandler\GetRecordCover' => - 'finc\AjaxHandler\GetRecordCoverFactory', 'finc\AjaxHandler\GetUserMediaReadyToPickup' => 'VuFind\AjaxHandler\AbstractIlsAndUserActionFactory', 'finc\AjaxHandler\GetUserPermanentLoans' => @@ -106,11 +102,9 @@ $config = [ 'finc\AjaxHandler\GetItemStatuses', 'getResolverLinks' => 'finc\AjaxHandler\GetResolverLinks', - 'getRecordCover' => - 'finc\AjaxHandler\GetRecordCover', 'getUserMediaReadyToPickup' => 'finc\AjaxHandler\GetUserMediaReadyToPickup', - 'getUserPermanentLoans' => + 'getUserPermanentLoans' => 'finc\AjaxHandler\GetUserPermanentLoans', ] ], diff --git a/module/finc/src/finc/AjaxHandler/GetRecordCover.php b/module/finc/src/finc/AjaxHandler/GetRecordCover.php deleted file mode 100644 index 1273bb12c285158f50711eb558a867555951c47a..0000000000000000000000000000000000000000 --- a/module/finc/src/finc/AjaxHandler/GetRecordCover.php +++ /dev/null @@ -1,144 +0,0 @@ -<?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 Laminas\Mvc\Controller\Plugin\Params; -use Laminas\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')) - : [""]; - } -} diff --git a/module/finc/src/finc/AjaxHandler/GetRecordCoverFactory.php b/module/finc/src/finc/AjaxHandler/GetRecordCoverFactory.php deleted file mode 100644 index 35850578735ab87dfdbeac50f3a2ea8b5f669936..0000000000000000000000000000000000000000 --- a/module/finc/src/finc/AjaxHandler/GetRecordCoverFactory.php +++ /dev/null @@ -1,82 +0,0 @@ -<?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 Laminas\ServiceManager\Exception\ServiceNotCreatedException; -use Laminas\ServiceManager\Exception\ServiceNotFoundException; -use Laminas\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 index 191c033eedfb322a6705907c526131a7157a544e..ed2f1d58505159b57230b25b9271ae1986a43e52 100644 --- a/module/finc/src/finc/Cover/Loader.php +++ b/module/finc/src/finc/Cover/Loader.php @@ -31,7 +31,6 @@ 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> @@ -80,39 +79,4 @@ class Loader extends \VuFind\Cover\Loader } return parent::getImage(); } - - /** - * 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 deleted file mode 100644 index 760d69e3a12062078f98ca8166e7c0f9cf8cc924..0000000000000000000000000000000000000000 --- a/module/finc/src/finc/Cover/Router.php +++ /dev/null @@ -1,114 +0,0 @@ -<?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 - */ -// Add "extends \VuFind\Cover\Router" to prevent "Whoops" error - #18898 - HR -class Router extends \VuFind\Cover\Router implements \Laminas\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; - } - if ($testLoadImage) { - $this->coverLoader->loadImage(array_merge($thumb, ['size' => $size])); - 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 deleted file mode 100644 index 1c6b62a6f2092a59d31ade7474d2300e2e126987..0000000000000000000000000000000000000000 --- a/module/finc/src/finc/Cover/RouterFactory.php +++ /dev/null @@ -1,76 +0,0 @@ -<?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 Laminas\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 91c038065151fb2ac981ee68a8c0a5fb5f0ed623..6ba3b5eed6de11e350167696a463e32c03068d5a 100644 --- a/module/finc/src/finc/View/Helper/Root/Record.php +++ b/module/finc/src/finc/View/Helper/Root/Record.php @@ -119,10 +119,10 @@ class Record extends \VuFind\View\Helper\Root\Record * * @param \Laminas\Config\Config $config VuFind configuration * @param \Laminas\View\Helper\Url $helper URL helper - * @param \VuFind\Auth\Manager $manager AuthManager - * @param mixed $rewrite Ebl rewrite service for VuFind - * @param mixed $resolverConfig Resolver.ini - * @param mixed $iconConfig iconMapping.ini + * @param \VuFind\Auth\Manager $manager AuthManager + * @param mixed $rewrite Ebl rewrite service for VuFind + * @param mixed $resolverConfig Resolver.ini + * @param mixed $iconConfig iconMapping.ini */ public function __construct( $config, @@ -601,66 +601,4 @@ class Record extends \VuFind\View\Helper\Root\Record } return $queryParams; } - - /** - * Get the rendered cover plus some useful parameters. - * - * @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 - * - * @deprecated used for VF7 ajaxcovers, remove on upgrade - * - * @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 - [$details['size']] = explode(':', $preferredSize); - } - - $details['html'] = $this->contextHelper->renderInContext( - 'record/cover.phtml', - $details - ); - } - return $details; - } - - /** - * Generate a thumbnail URL (return false if unsupported). - * - * @param string $size Size of thumbnail (small, medium or large -- small is - * default). - * - * @deprecated used for VF7 ajaxcovers, remove on upgrade - * - * @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/templates/record/cover.phtml b/themes/finc/templates/RecordDriver/DefaultRecord/cover.phtml similarity index 100% rename from themes/finc/templates/record/cover.phtml rename to themes/finc/templates/RecordDriver/DefaultRecord/cover.phtml diff --git a/themes/finc/templates/record/coverReplacement.phtml b/themes/finc/templates/record/coverReplacement.phtml index 4662e1b083a775660904a3f50b12e5df084023bd..d26b8d7bcb980e7a9d10d36e7f64b1cf126c1a32 100644 --- a/themes/finc/templates/record/coverReplacement.phtml +++ b/themes/finc/templates/record/coverReplacement.phtml @@ -1 +1 @@ -<?= $this->record($this->driver)->getRecordIcon('record-icon', $this->setIconText ?? true) ?> \ No newline at end of file +<?= $this->record($this->driver)->getRecordIcon('record-icon', false) ?> \ No newline at end of file