-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable default cover images #4061
Merged
demiankatz
merged 26 commits into
vufind-org:dev
from
ThoWagen:pull-request/disable-default-cover-images
Nov 25, 2024
Merged
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
89367b2
disable default cover images
ThoWagen 2303baa
updated comments
ThoWagen 68ecd79
renamed exception
ThoWagen ac168ee
fixed doc comment
ThoWagen 7bc40ce
added comment in configs
ThoWagen adc7567
updated comment and added testcase for deactivated setting
ThoWagen e9a72f0
Merge branch 'dev' into pull-request/disable-default-cover-images
demiankatz 9cdb407
added demo cover loader
ThoWagen f547606
readded default no qr code availabe image
ThoWagen c02ae99
Add DemoAjax.
demiankatz 258fba0
Merge branch 'add-demo-covers' into pull-request/disable-default-cove…
demiankatz 162947f
Add DemoAjax version.
demiankatz 06650fe
Revise comment.
demiankatz 2000215
combined demo and demoajax and hiding one pixel image as default inst…
ThoWagen 9acfcc9
added hidden-image.gif
ThoWagen c99f342
Fix comment formatting.
demiankatz d06e002
Fix return type.
demiankatz 4c3598f
Merge remote-tracking branch 'origin/dev' into pull-request/disable-d…
demiankatz 826806a
Favor record ID for more consistent generation.
demiankatz 21d94dd
Add Mink test.
demiankatz 1c48f06
disable cover image cache in browsers for tests and wait for complete…
ThoWagen d51c09e
Merge branch 'dev' into pull-request/disable-default-cover-images
ThoWagen f37deb8
fixed cs and tests
ThoWagen 8dce3d1
using VuFind.setInnerHtml
ThoWagen 02d7117
using array instead of laminas config
ThoWagen 3c9070e
Update module/VuFind/src/VuFind/Cover/RouterFactory.php
demiankatz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
|
||
/** | ||
* Demo cover content loader. | ||
* | ||
* PHP version 8 | ||
* | ||
* Copyright (C) Hebis Verbundzentrale 2024. | ||
* | ||
* 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 Content | ||
* @author Thomas Wagener <[email protected]> | ||
* @author Demian Katz <[email protected]> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
|
||
namespace VuFind\Content\Covers; | ||
|
||
use VuFindTheme\ThemeInfo; | ||
|
||
use function count; | ||
|
||
/** | ||
* Demo cover content loader. | ||
* | ||
* @category VuFind | ||
* @package Content | ||
* @author Thomas Wagener <[email protected]> | ||
* @author Demian Katz <[email protected]> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
class Demo extends \VuFind\Content\AbstractCover | ||
{ | ||
/** | ||
* Constructor | ||
* | ||
* @param ThemeInfo $themeInfo Theme info | ||
* @param string $baseUrl VuFind's base URL | ||
*/ | ||
public function __construct(protected ThemeInfo $themeInfo, protected string $baseUrl) | ||
{ | ||
$this->directUrls = true; | ||
$this->mandatoryBacklinkLocations = ['core']; | ||
} | ||
|
||
/** | ||
* Does this plugin support the provided ID array? | ||
* | ||
* @param array $ids IDs that will later be sent to load() -- see below. | ||
* | ||
* @return bool | ||
*/ | ||
public function supports($ids) | ||
{ | ||
// We won't know what we need until we parse the path string; accept | ||
// everything at this stage: | ||
return true; | ||
} | ||
|
||
/** | ||
* Get image location from local file storage. | ||
* | ||
* @param string $key If backlink functionality should be used | ||
* @param string $size Size of image to load (small/medium/large) | ||
* @param array $ids Associative array of identifiers (keys may include 'isbn' | ||
* pointing to an ISBN object and 'issn' pointing to a string) | ||
* | ||
* @return string|bool | ||
*/ | ||
public function getUrl($key, $size, $ids) | ||
{ | ||
$cover = $this->getCover($ids); | ||
if ($path = $cover['file'] ?? null) { | ||
return 'file://' . $path; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Get cover metadata for a particular API key and set of IDs (or empty array). | ||
* | ||
* @param ?string $key If backlink functionality should be used | ||
* @param string $size Size of image to load (small/medium/large) | ||
* @param array $ids Associative array of identifiers (keys may include 'isbn' | ||
* pointing to an ISBN object, 'issn' pointing to a string and 'oclc' pointing | ||
* to an OCLC number string) | ||
* | ||
* @return array Array with keys: url, backlink_url, backlink_text | ||
*/ | ||
public function getMetadata(?string $key, string $size, array $ids) | ||
{ | ||
$cover = $this->getCover($ids); | ||
$path = $cover['relativeFile'] ?? null; | ||
if (empty($path)) { | ||
return []; | ||
} | ||
$res = [ | ||
'url' => $this->baseUrl . 'themes/' . $cover['theme'] . '/' . $path, | ||
]; | ||
if ($key === 'true') { | ||
$res['backlink_url'] = 'https://vufind.org'; | ||
$res['backlink_text'] = 'vufind.org'; | ||
} | ||
return $res; | ||
} | ||
|
||
/** | ||
* Selects demo covers or no cover based on the $ids array and returns location information. | ||
* | ||
* @param array $ids Associative array of identifiers (keys may include 'isbn' | ||
* pointing to an ISBN object and 'issn' pointing to a string) | ||
* | ||
* @return array | ||
*/ | ||
protected function getCover($ids) | ||
{ | ||
$covers = $this->themeInfo->findInThemes('images/demo-cover-*'); | ||
// selects either one of the available demo covers or no image | ||
// evenly distributed based on the checksum of the ids. | ||
$coverNum = crc32($ids['recordid'] ?? serialize($ids)) % (count($covers) + 1); | ||
return $covers[$coverNum] ?? []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/** | ||
* Demo cover loader factory | ||
* | ||
* PHP version 8 | ||
* | ||
* Copyright (C) Hebis Verbundzentrale 2024. | ||
* | ||
* 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 Content | ||
* @author Thomas Wagener <[email protected]> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development:plugins:record_drivers Wiki | ||
*/ | ||
|
||
namespace VuFind\Content\Covers; | ||
|
||
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; | ||
use Laminas\ServiceManager\Exception\ServiceNotFoundException; | ||
use Psr\Container\ContainerExceptionInterface as ContainerException; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* Demo cover loader factory | ||
* | ||
* @category VuFind | ||
* @package Content | ||
* @author Thomas Wagener <[email protected]> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development:plugins:record_drivers Wiki | ||
*/ | ||
class DemoFactory implements \Laminas\ServiceManager\Factory\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&\Throwable if any other error occurs | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function __invoke( | ||
ContainerInterface $container, | ||
$requestedName, | ||
array $options = null | ||
) { | ||
if (!empty($options)) { | ||
throw new \Exception('Unexpected options passed to factory.'); | ||
} | ||
$helpers = $container->get('ViewHelperManager'); | ||
$basePath = ($helpers->get('url'))('home'); | ||
$baseUrl = ($helpers->get('serverurl'))($basePath); | ||
return new $requestedName($container->get(\VuFindTheme\ThemeInfo::class), $baseUrl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
laminas-config has just been abandoned; I'm beginning work to remove it from the project. I'd suggest using a plain array here, and using
->toArray
in the factory, so we don't introduce a new dependency on the abandoned project.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might also make sense to default this to an empty array so that you don't have to modify tests when there is no configuration being tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Are there any problems with replacing laminas-config with arrays that would be good to keep in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My plan is to create a
VuFind\Config\Config
that provides backward-compatibility withLaminas\Config\Config
as a first phase. We might decide to keep that in the long term, but I think it's more likely that we'll quickly deprecate it and try to phase it out in favor of arrays. Really, the Laminas Config object was mainly useful for accessing deep configs in older versions of PHP prior to the introduction of null coalescing. Now that we have??
, it's pretty easy to access deeply-nested array properties as long as you provide a default to fall back on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks