Skip to content
Snippets Groups Projects
Commit 6a6eecf0 authored by Demian Katz's avatar Demian Katz Committed by GitHub
Browse files

Added linkPreviewsToCovers configuration setting. (#762)

parent acb73a3d
No related merge requests found
...@@ -694,6 +694,12 @@ authors = Wikipedia ...@@ -694,6 +694,12 @@ authors = Wikipedia
; http://code.google.com/apis/books/branding.html before using Google Book Search. ; http://code.google.com/apis/books/branding.html before using Google Book Search.
;previews = Google,OpenLibrary,HathiTrust ;previews = Google,OpenLibrary,HathiTrust
; This setting controls whether or not cover images are linked to previews when
; available. Legal settings are false (never link), * (always link; default), or
; a comma-separated list of templates in which linking should occur (see coversize
; above for a list of legal values).
;linkPreviewsToCovers = *
; Possible HathiRights options = pd,ic,op,orph,und,umall,ic-world,nobody,pdus,cc-by,cc-by-nd, ; Possible HathiRights options = pd,ic,op,orph,und,umall,ic-world,nobody,pdus,cc-by,cc-by-nd,
; cc-by-nc-nd,cc-by-nc,cc-by-nc-sa,cc-by-sa,orphcand,cc-zero,und-world,icus ; cc-by-nc-nd,cc-by-nc,cc-by-nc-sa,cc-by-sa,orphcand,cc-zero,und-world,icus
; Default is "pd,ic-world" if unset here. ; Default is "pd,ic-world" if unset here.
......
...@@ -441,6 +441,28 @@ class Record extends AbstractHelper ...@@ -441,6 +441,28 @@ class Record extends AbstractHelper
return $details['html']; return $details['html'];
} }
/**
* Should cover images be linked to previews (when applicable) in the provided
* template context?
*
* @param string $context Context of code being generated
*
* @return bool
*/
protected function getPreviewCoverLinkSetting($context)
{
static $previewContexts = false;
if (false === $previewContexts) {
$previewContexts = isset($this->config->Content->linkPreviewsToCovers)
? array_map(
'trim',
explode(',', $this->config->Content->linkPreviewsToCovers)
) : ['*'];
}
return in_array('*', $previewContexts)
|| in_array($context, $previewContexts);
}
/** /**
* Get the rendered cover plus some useful parameters. * Get the rendered cover plus some useful parameters.
* *
...@@ -453,7 +475,8 @@ class Record extends AbstractHelper ...@@ -453,7 +475,8 @@ class Record extends AbstractHelper
public function getCoverDetails($context, $default, $link = false) public function getCoverDetails($context, $default, $link = false)
{ {
$details = compact('link', 'context') + [ $details = compact('link', 'context') + [
'driver' => $this->driver, 'cover' => false, 'size' => false 'driver' => $this->driver, 'cover' => false, 'size' => false,
'linkPreview' => $this->getPreviewCoverLinkSetting($context),
]; ];
$preferredSize = $this->getCoverSize($context, $default); $preferredSize = $this->getCoverSize($context, $default);
if (empty($preferredSize)) { // covers disabled entirely if (empty($preferredSize)) { // covers disabled entirely
......
...@@ -43,7 +43,7 @@ function applyPreviewUrl($link, url) { ...@@ -43,7 +43,7 @@ function applyPreviewUrl($link, url) {
// Update associated record thumbnail, if any: // Update associated record thumbnail, if any:
$link.parents('.result,.record') $link.parents('.result,.record')
.find('.recordcover').parents('a').attr('href', url); .find('.recordcover[data-linkpreview="true"]').parents('a').attr('href', url);
} }
function processBookInfo(booksInfo, previewClass, viewOptions) { function processBookInfo(booksInfo, previewClass, viewOptions) {
......
<? /* Display thumbnail if appropriate: */ ?> <? /* Display thumbnail if appropriate: */ ?>
<? if ($cover): ?> <? if ($cover): ?>
<? if ($this->link): ?><a href="<?=$this->escapeHtmlAttr($this->link)?>"><? endif; ?> <? if ($this->link): ?><a href="<?=$this->escapeHtmlAttr($this->link)?>"><? endif; ?>
<img alt="<?=$this->transEsc('Cover Image')?>" class="recordcover" src="<?=$this->escapeHtmlAttr($cover); ?>"/> <img alt="<?=$this->transEsc('Cover Image')?>" <? if ($linkPreview): ?>data-linkpreview="true" <? endif; ?>class="recordcover" src="<?=$this->escapeHtmlAttr($cover); ?>"/>
<? if ($this->link): ?></a><? endif; ?> <? if ($this->link): ?></a><? endif; ?>
<? else: ?> <? else: ?>
<img src="<?=$this->url('cover-unavailable')?>" class="recordcover" alt="<?=$this->transEsc('No Cover Image')?>"/> <img src="<?=$this->url('cover-unavailable')?>" <? if ($linkPreview): ?>data-linkpreview="true" <? endif; ?>class="recordcover" alt="<?=$this->transEsc('No Cover Image')?>"/>
<? endif; ?> <? endif; ?>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment