Skip to content

Commit

Permalink
initial commit - version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Bigga committed Mar 31, 2020
1 parent 092e6f4 commit 1dc6759
Show file tree
Hide file tree
Showing 103 changed files with 17,647 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea/
.DS_Store
node_modules/
.vscode/
*.map
105 changes: 105 additions & 0 deletions Classes/Helpers/CoreVersionCondition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace Slub\DigitalCollections\Helpers;

use TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractCondition;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;

/**
* This TypoScript condition compares an integer to the current TYPO3 version
*
* = Example =
* [Slub\DigitalCollections\Helpers\CoreVersionCondition < 9.3]
* page.6 = TEXT
* page.6.value = TYPO3 CORE VERSION IS LOWER THAN 9.3
* page.6.wrap = <div>|</div>
* [global]
*
*/
class CoreVersionCondition extends AbstractCondition
{
/**
* Evaluate condition
*
* @param array $conditionParameters
* @return bool
*/
public function matchCondition(array $conditionParameters)
{
if (empty($conditionParameters)) {
return false;
}

$coreVersion = VersionNumberUtility::getNumericTypo3Version();
$coreVersionInteger = VersionNumberUtility::convertVersionNumberToInteger($coreVersion);
foreach ($conditionParameters as $expression) {
if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($expression)) {
$expression = '=' . $expression;
}
if ($this->compareNumber($expression, $coreVersionInteger)) {
return true;
}
}

return false;
}

/**
* Evaluates a $leftValue based on an operator: "<", ">", "<=", ">=", "!=" or "="
*
* @param string $test The value to compare with on the form [operator][number]. Eg. "< 123
* @param float $leftValue The value on the left side
* @return bool If $value is "50" and $test is "< 123" then it will return TRUE.
*/
protected function compareNumber($test, $leftValue)
{
if (preg_match('/^(!?=+|<=?|>=?)\\s*([^\\s]*)\\s*$/', $test, $matches)) {
$operator = $matches[1];
$rightValue = $matches[2];
switch ($operator) {
case '>=':
return $leftValue >= VersionNumberUtility::convertVersionNumberToInteger($rightValue);
case '<=':
return $leftValue <= VersionNumberUtility::convertVersionNumberToInteger($rightValue);
case '!=':
// multiple values may be split with '|'
// see if none matches ("not in list")
$found = false;
$rightValueParts = GeneralUtility::trimExplode('|', $rightValue);
foreach ($rightValueParts as $rightValueSingle) {
if ($leftValue == VersionNumberUtility::convertVersionNumberToInteger($rightValueSingle)) {
$found = true;
break;
}
}
return $found === false;
case '<':
return $leftValue < VersionNumberUtility::convertVersionNumberToInteger($rightValue);
case '>':
return $leftValue > VersionNumberUtility::convertVersionNumberToInteger($rightValue);
default:
// nothing valid found except '=', use '='
// multiple values may be split with '|'
// see if one matches ("in list")
$found = false;
$rightValueParts = GeneralUtility::trimExplode('|', $rightValue);
foreach ($rightValueParts as $rightValueSingle) {
if ($leftValue == VersionNumberUtility::convertVersionNumberToInteger($rightValueSingle)) {
$found = true;
break;
}
}
return $found;
}
}
return false;
}
}
202 changes: 202 additions & 0 deletions Classes/Helpers/GetDoc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<?php
namespace Slub\DigitalCollections\Helpers;

/***************************************************************
* Copyright notice
*
* (c) 2017 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;

if (!defined('TYPO3_DLOG')) {
define('TYPO3_DLOG', 0);
}

class GetDoc
{
/**
* This holds the current document
*
* @var tx_dlf_document
* @access protected
*/
protected $doc;

/**
* Get page's download link
*
* @access public
*
* @param integer $pagenumber:The current page numbert
*
* @return string: The left and right download url
*/
public function getPageLink($pagenumber)
{

if (!$this->init()) {
return '';
}

$details = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pagenumber]];
$file = $details['files']['DOWNLOAD'];

if (!empty($file)) {

$pageLink = $this->doc->getFileLocation($file);

}

return $pageLink;
}

/**
* Get work's download link
*
* @access public
*
* @return string: The left and right download url
*/
public function getWorkLink()
{

if (!$this->init()) {
return '';
}

// Get work link.
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files']['DOWNLOAD'])) {

$workLink = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files']['DOWNLOAD']);

} else {

$details = $this->doc->getLogicalStructure($this->doc->toplevelId);

if (!empty($details['files']['DOWNLOAD'])) {

$workLink = $this->doc->getFileLocation($details['files']['DOWNLOAD']);

}

}

return $workLink;
}

/**
* get xpath result
*
* @access public
*
* @param string $content: The PlugIn content
*
* @return string The content that is displayed on the website
*/
public function getXpath($xpath)
{
if (!$this->init()) {
return '';
}
return $this->doc->mets->xpath($xpath);
}

/**
* Initialize and load the document
*
* @access protected
*
* @return boolean
*/
protected function init()
{
// Load current document.
$this->loadDocument();

if ($this->doc === null) {

// Quit without doing anything if required variables are not set.
return null;

}

$this->doc->mets->registerXPathNamespace('mets', 'http://www.loc.gov/METS/');
$this->doc->mets->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3');
$this->doc->mets->registerXPathNamespace('dv', 'http://dfg-viewer.de/');
$this->doc->mets->registerXPathNamespace('slub', 'http://slub-dresden.de/');

return true;
}

/**
* Loads the current document into $this->doc
*
* @access protected
*
* @return void
*/
protected function loadDocument()
{
$piVarsSet = GeneralUtility::_GPmerged('set');

$piVars = GeneralUtility::_GPmerged('tx_dlf');

// overwrite tx_dlf[] parameters by (old) set[] ones
if (!empty($piVarsSet['mets'])) {
$piVars['id'] = $piVarsSet['mets'];
}
if (!empty($piVarsSet['double'])) {
$piVars['double'] = $piVarsSet['double'];
}
if (!empty($piVarsSet['image'])) {
$piVars['page'] = $piVarsSet['image'];
}

// Check for required variable.
if (!empty($piVars['id'])) {

// Get instance of tx_dlf_document.
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getNumericTypo3Version(), '8.7.0', '>=')) {
$this->doc =& \Kitodo\Dlf\Common\Document::getInstance($piVars['id'], 0);
} else {
$this->doc =& \tx_dlf_document::getInstance($piVars['id'], 0);
}


if (!$this->doc->ready) {

// Destroy the incomplete object.
$this->doc = null;

if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_plugin->loadDocument()] Failed to load document with UID "'.$piVars['id'].'"', $this->extKey, SYSLOG_SEVERITY_ERROR);
}
} else {

// Set configuration PID.
$this->doc->cPid = $this->conf['pages'];
}
} else {
if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_plugin->loadDocument()] Failed to load document with record ID "'.$this->piVars['recordId'].'"', $this->extKey, SYSLOG_SEVERITY_ERROR);
}
}
}
}
Loading

0 comments on commit 1dc6759

Please sign in to comment.