Skip to content

Commit

Permalink
Merge pull request #13 from slub/add-provider-logo
Browse files Browse the repository at this point in the history
Bring back provider logo - only if configured
  • Loading branch information
Alexander Bigga authored Nov 20, 2020
2 parents ea78f0e + 13919af commit 51ff7db
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 5 deletions.
86 changes: 86 additions & 0 deletions Classes/ViewHelpers/ProviderLogoCachedViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
namespace Slub\DigitalCollections\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) 2019 Alexander Bigga <[email protected]>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script 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.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;

/**
* ViewHelper to get the provider logo from cache
*
* @package TYPO3
*/
class ProviderLogoCachedViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
/**
* Initialize arguments.
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('logo', 'string', 'URI of the provider logo', true);
}

/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$logoUrl = $arguments['logo'];
// is valid uri?
if (GeneralUtility::isValidUrl($logoUrl)) {
// calculate cache identifier
$logoInfo = pathinfo($logoUrl);
$cacheIdentifier = md5($logoUrl) . '.' . $logoInfo['extension'];
$logoFile = Environment::getPublicPath() . '/fileadmin/_temp_/' . $cacheIdentifier;
// if file exists and is not too old - take it
if (file_exists($LogoFile)) {
// if not older than one day:
if ((time() - filemtime($calfile) < 86400)) {
return $cacheIdentifier;
}
}

// file not present or too old --> fetch new
$context = stream_context_create(array(
'http' => array(
'timeout' => 10
)
)
);
$logo = @file_get_contents($logoUrl, false, $context, 0, 1024*100);
// Save value in cache
if ($logo) {
GeneralUtility::writeFile($logoFile, $logo);
return $cacheIdentifier;
}
}
return FALSE;
}
}
2 changes: 2 additions & 0 deletions Configuration/TypoScript/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ page {
solrHost = {$config.kitodo.solr.host}/{$config.kitodo.solr.coreName}
solrTimeout = {$config.kitodo.solr.timeout}
}

showProviderLogo = 0
}
variables {
content < styles.content.get
Expand Down
11 changes: 11 additions & 0 deletions Resources/Private/Javascript/DigitalcollectionsScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ $(function () {
}
});

if ($('.provider img').length > 0) {
// Avoid broken image display if METS definitions are wrong
$('.provider img').each(function() {
if((typeof this.naturalWidth != "undefined" && this.naturalWidth == 0 ) || this.readyState == 'uninitialized' ) {
$(this).parents('.document-functions').addClass('missing-provider-image');
}
});
} else {
$('.provider').parents('.document-functions').addClass('missing-provider-image');
}

// Copy selected page number to mobile meta (in order to transform select field to ui button)
if ($('.pages select option[selected]')[0]) {
$('dl.mobile-meta').append('<dt class="mobile-page-number">No.</dt><dd class="mobile-page-number">' + $('.pages select option[selected]').text() + '</dd>');
Expand Down
28 changes: 27 additions & 1 deletion Resources/Private/Less/Structure.less
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,16 @@ a {
border-bottom: 1px solid @lightgrey-color;
.transition();
> a {
display: none; // Kill the logo inside the control bar in order to use the new logobar (.tx-dlf-logobar)
flex: 0 0 70px;
img {
margin-top: 5px;
width: 70px;
height: 33px;
}
}
// > a {
// display: none; // Kill the logo inside the control bar in order to use the new logobar (.tx-dlf-logobar)
// }
.mobile-meta {
position: relative;
font-size: 12px;
Expand Down Expand Up @@ -276,6 +284,19 @@ a {
.transform(translateY(-100%));
}
}
&.missing-provider-image {
.provider {
> a {
display: none;
img {
display: none;
}
}
.mobile-meta {
padding-left: 10px;
}
}
}
}
@media screen and (min-width: @phoneLandscapeViewportWidth) {
.tx-dlf-logobar {
Expand Down Expand Up @@ -324,6 +345,11 @@ a {
display: none;
}
}
&.missing-provider-image {
ul {
left: 20px;
}
}
}
}
@media screen and (min-width: @desktopViewportWidth) {
Expand Down
22 changes: 20 additions & 2 deletions Resources/Private/Partials/KitodoPageView.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,26 @@
</f:if>
<div class="document-functions">
<f:comment><!-- [provider logo] ----------------------------- --></f:comment>
<div class="provider">
<dl class="mobile-meta">
<div class="provider">
<f:alias map="{providerLogoUrl: '{dc:xpath(xpath:\'(//mets:amdSec/mets:rightsMD/mets:mdWrap[@OTHERMDTYPE=\"DVRIGHTS\"]/mets:xmlData/dv:rights/dv:ownerLogo)[1]\')}',
providerTitle: '{dc:xpath(xpath:\'(//mets:amdSec/mets:rightsMD/mets:mdWrap[@OTHERMDTYPE=\"DVRIGHTS\"]/mets:xmlData/dv:rights/dv:owner)[1]\')}',
providerUri: '{dc:xpath(xpath:\'(//mets:amdSec/mets:rightsMD/mets:mdWrap[@OTHERMDTYPE=\"DVRIGHTS\"]/mets:xmlData/dv:rights/dv:ownerSiteURL)[1]\', htmlspecialchars:\'FALSE\')}'}">
<f:if condition="{settings.showProviderLogo} && {dc:providerLogoCached(logo:'{providerLogoUrl}')}">
<f:if condition="{providerLogoUrl}">
<f:link.external
uri="{providerUri}"
title="{providerTitle}">
<img src="/fileadmin/_temp_/{dc:providerLogoCached(logo:'{providerLogoUrl}')}"
width="108"
title="{providerTitle}"
alt="Logo von {providerTitle}"
/>
</f:link.external>
</f:if>
</f:if>
</f:alias>

<dl class="mobile-meta">
<dt class="tx-dlf-title">Titel</dt>
<dd class="tx-dlf-title">
<a href="#">{docTitle}</a>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Css/Digitalcollections.css

Large diffs are not rendered by default.

Loading

0 comments on commit 51ff7db

Please sign in to comment.