Browse Source

Add a more generic approach for PDF download tool

tags/v1.3.0
Sebastian Meyer 8 years ago
parent
commit
01c9bcbb24
  1. 131
      dlf/common/class.tx_dlf_document.php
  2. 3
      dlf/ext_conf_template.txt
  3. 4
      dlf/ext_localconf.php
  4. 6
      dlf/ext_tables.php
  5. 4
      dlf/locallang.xml
  6. 2
      dlf/plugins/pageview/class.tx_dlf_pageview.php
  7. 71
      dlf/plugins/toolbox/tools/dfgviewer/class.tx_dlf_toolsDfgviewer.php
  8. 37
      dlf/plugins/toolbox/tools/dfgviewer/locallang.xml
  9. 3
      dlf/plugins/toolbox/tools/dfgviewer/setup.txt
  10. 24
      dlf/plugins/toolbox/tools/dfgviewer/template.tmpl
  11. 130
      dlf/plugins/toolbox/tools/pdf/class.tx_dlf_toolsPdf.php
  12. 12
      dlf/plugins/toolbox/tools/pdf/locallang.xml
  13. 3
      dlf/plugins/toolbox/tools/pdf/setup.txt
  14. 3
      dlf/plugins/toolbox/tools/pdf/template.tmpl

131
dlf/common/class.tx_dlf_document.php

@ -80,6 +80,24 @@ final class tx_dlf_document {
public $extKey = 'dlf';
/**
* This holds the file ID -> USE concordance
* @see _getFileGrps()
*
* @var array
* @access protected
*/
protected $fileGrps = array ();
/**
* Are the file groups loaded?
* @see $fileGrps
*
* @var boolean
* @access protected
*/
protected $fileGrpsLoaded = FALSE;
/**
* This holds the configuration for all supported metadata encodings
* @see loadFormats()
*
@ -550,6 +568,23 @@ final class tx_dlf_document {
}
// Get the files this structure element is pointing at.
$details['files'] = array ();
$fileUse = $this->_getFileGrps();
// Get the file representations from fileSec node.
foreach ($structure->children('http://www.loc.gov/METS/')->fptr as $fptr) {
// Check if file has valid @USE attribute.
if (!empty($fileUse[(string) $fptr->attributes()->FILEID])) {
$details['files'][$fileUse[(string) $fptr->attributes()->FILEID]] = (string) $fptr->attributes()->FILEID;
}
}
// Keep for later usage.
$this->logicalUnits[$details['id']] = $details;
@ -1577,6 +1612,66 @@ final class tx_dlf_document {
}
/**
* This builds the file ID -> USE concordance
*
* @access protected
*
* @return array Array of file use groups with file IDs
*/
protected function _getFileGrps() {
if (!$this->fileGrpsLoaded) {
// Get configured USE attributes.
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$this->extKey]);
$useGrps = t3lib_div::trimExplode(',', $extConf['fileGrps']);
if (!empty($extConf['fileGrpThumbs'])) {
$useGrps[] = $extConf['fileGrpThumbs'];
}
if (!empty($extConf['fileGrpDownload'])) {
$useGrps[] = $extConf['fileGrpDownload'];
}
if (!empty($extConf['fileGrpFulltext'])) {
$useGrps[] = $extConf['fileGrpFulltext'];
}
// Get all file groups.
$fileGrps = $this->mets->xpath('./mets:fileSec/mets:fileGrp');
// Build concordance for configured USE attributes.
foreach ($fileGrps as $fileGrp) {
if (in_array((string) $fileGrp['USE'], $useGrps)) {
foreach ($fileGrp->children('http://www.loc.gov/METS/')->file as $file) {
$this->fileGrps[(string) $file->attributes()->ID] = (string) $fileGrp['USE'];
}
}
}
$this->fileGrpsLoaded = TRUE;
}
return $this->fileGrps;
}
/**
* This returns $this->location via __get()
*
* @access protected
@ -1695,40 +1790,8 @@ final class tx_dlf_document {
if ($pageNodes) {
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$this->extKey]);
$useGrps = t3lib_div::trimExplode(',', $extConf['fileGrps']);
if (!empty($extConf['fileGrpThumbs'])) {
$useGrps[] = $extConf['fileGrpThumbs'];
}
if (!empty($extConf['fileGrpFulltext'])) {
$useGrps[] = $extConf['fileGrpFulltext'];
}
// Yes. Get concordance of @FILEID and @USE attributes.
$fileUse = array ();
$fileGrps = $this->mets->xpath('./mets:fileSec/mets:fileGrp');
foreach ($fileGrps as $fileGrp) {
if (in_array((string) $fileGrp['USE'], $useGrps)) {
foreach ($fileGrp->children('http://www.loc.gov/METS/')->file as $file) {
$fileUse[(string) $file->attributes()->ID] = (string) $fileGrp['USE'];
}
}
}
// Get file groups.
$fileUse = $this->_getFileGrps();
// Get the physical sequence's metadata.
$physNode = $this->mets->xpath('./mets:structMap[@TYPE="PHYSICAL"]/mets:div[@TYPE="physSequence"]');

3
dlf/ext_conf_template.txt

@ -25,6 +25,9 @@ fileGrps = MIN,DEFAULT,MAX
# cat=Files; type=string; label=LLL:EXT:dlf/locallang.xml:config.fileGrpThumbs
fileGrpThumbs = THUMBS
# cat=Files; type=string; label=LLL:EXT:dlf/locallang.xml:config.fileGrpDownload
fileGrpDownload = DOWNLOAD
# cat=Files; type=string; label=LLL:EXT:dlf/locallang.xml:config.fileGrpFulltext
fileGrpFulltext = FULLTEXT

4
dlf/ext_localconf.php

@ -52,10 +52,6 @@ t3lib_extMgm::addPItoST43($_EXTKEY, 'plugins/toolbox/class.tx_dlf_toolbox.php',
t3lib_extMgm::addPItoST43($_EXTKEY, 'plugins/validator/class.tx_dlf_validator.php', '_validator', 'list_type', FALSE);
// Register tools for toolbox plugin.
t3lib_extMgm::addPItoST43($_EXTKEY, 'plugins/toolbox/tools/dfgviewer/class.tx_dlf_toolsDfgviewer.php', '_toolsDfgviewer', '', FALSE);
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/plugins/toolbox/tools'][t3lib_extMgm::getCN($_EXTKEY).'_toolsDfgviewer'] = 'LLL:EXT:dlf/locallang.xml:tx_dlf_toolbox.toolsDfgviewer';
t3lib_extMgm::addPItoST43($_EXTKEY, 'plugins/toolbox/tools/pdf/class.tx_dlf_toolsPdf.php', '_toolsPdf', '', FALSE);
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/plugins/toolbox/tools'][t3lib_extMgm::getCN($_EXTKEY).'_toolsPdf'] = 'LLL:EXT:dlf/locallang.xml:tx_dlf_toolbox.toolsPdf';

6
dlf/ext_tables.php

@ -344,12 +344,6 @@ t3lib_extMgm::addPlugin(array('LLL:EXT:dlf/locallang.xml:tt_content.dlf_validato
t3lib_extMgm::addPiFlexFormValue($_EXTKEY.'_validator', 'FILE:EXT:'.$_EXTKEY.'/plugins/validator/flexform.xml');
// Tool "toolsDfgviewer".
t3lib_extMgm::addStaticFile($_EXTKEY, 'plugins/toolbox/tools/dfgviewer/', 'Tool: DFG Viewer');
// Tool "toolsPdf".
t3lib_extMgm::addStaticFile($_EXTKEY, 'plugins/toolbox/tools/pdf/', 'Tool: PDF Download');
// Register modules.
if (TYPO3_MODE == 'BE') {

4
dlf/locallang.xml

@ -133,7 +133,6 @@
<label index="tx_dlf_libraries.tab1">General</label>
<label index="tx_dlf_libraries.tab2">Translation</label>
<label index="tx_dlf_libraries.tab3">Catalogs</label>
<label index="tx_dlf_toolbox.toolsDfgviewer">Link to DFG Viewer</label>
<label index="tx_dlf_toolbox.toolsPdf">PDF Download</label>
<label index="tt_content.dlf_collection">DLF: Collection</label>
<label index="tt_content.dlf_feeds">DLF: Feeds</label>
@ -157,6 +156,7 @@
<label index="config.unhideOnIndex">Unhide indexed documents?: Should hidden documents be unhidden when re-indexing them? (default is "FALSE")</label>
<label index="config.fileGrps">Page fileGrps: comma-separated list of @USE attribute values ordered by increasing size (default is "MIN,DEFAULT,MAX")</label>
<label index="config.fileGrpThumbs">Thumbnail fileGrp: @USE attribute value (default is "THUMBS")</label>
<label index="config.fileGrpDownload">Download fileGrp: @USE attribute value (default is "DOWNLOAD")</label>
<label index="config.fileGrpFulltext">Fulltext fileGrp: @USE attribute value (default is "FULLTEXT")</label>
<label index="config.solrConnect">Solr Connection</label>
<label index="config.solrHost">Solr Server Host: (default is "localhost")</label>
@ -310,7 +310,6 @@
<label index="tx_dlf_libraries.tab1">Allgemein</label>
<label index="tx_dlf_libraries.tab2">Übersetzung</label>
<label index="tx_dlf_libraries.tab3">Kataloge</label>
<label index="tx_dlf_toolbox.toolsDfgviewer">Link zum DFG-Viewer</label>
<label index="tx_dlf_toolbox.toolsPdf">PDF-Download</label>
<label index="tt_content.dlf_collection">DLF: Kollektion</label>
<label index="tt_content.dlf_feeds">DLF: Feeds</label>
@ -334,6 +333,7 @@
<label index="config.unhideOnIndex">Indexierte Dokumente einblenden?: Sollen ausgeblendete Dokumente bei der erneuten Indexierung wieder eingeblendet werden? (Standard ist "FALSE")</label>
<label index="config.fileGrps">Seiten fileGrps: Komma-getrennte Liste der @USE Attributwerte der Seitenansichten nach aufsteigender Größe sortiert (Standard ist "MIN,DEFAULT,MAX")</label>
<label index="config.fileGrpThumbs">Vorschau fileGrp: @USE Attributwert der Vorschaubilder (Standard ist "THUMBS")</label>
<label index="config.fileGrpDownload">Download fileGrp: @USE Attributwert der Downloads (Standard ist "DOWNLOAD")</label>
<label index="config.fileGrpFulltext">Volltext fileGrp: @USE Attributwert der Volltexte (Standard ist "FULLTEXT")</label>
<label index="config.solrConnect">Solr Verbindung</label>
<label index="config.solrHost">Solr Server Host: (Standard ist "localhost")</label>

2
dlf/plugins/pageview/class.tx_dlf_pageview.php

@ -242,7 +242,7 @@ class tx_dlf_pageview extends tx_dlf_plugin {
if (TYPO3_DLOG) {
t3lib_div::devLog('[tx_dlf_pageview->getImage('.$page.')] File not found in fileGrp "'.$fileGrp.'"', $this->extKey, SYSLOG_SEVERITY_WARNING);
t3lib_div::devLog('[tx_dlf_pageview->getImageUrl('.$page.')] File not found in fileGrp "'.$fileGrp.'"', $this->extKey, SYSLOG_SEVERITY_WARNING);
}

71
dlf/plugins/toolbox/tools/dfgviewer/class.tx_dlf_toolsDfgviewer.php

@ -1,71 +0,0 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2011 Goobi. Digitalisieren im Verein e.V. <contact@goobi.org>
* 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 2 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!
***************************************************************/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*/
/**
* Tool 'Link to DFG Viewer' for the plugin 'DLF: Toolbox' of the 'dlf' extension.
*
* @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* @package TYPO3
* @subpackage tx_dlf
* @access public
*/
class tx_dlf_toolsDfgviewer extends tx_dlf_plugin {
// Changed to prevent overwriting the main extension's parameters.
public $prefixId = 'tx_dlf_toolsDfgviewer';
public $scriptRelPath = 'plugins/toolbox/tools/dfgviewer/class.tx_dlf_toolsDfgviewer.php';
/**
* The main method of the PlugIn
*
* @access public
*
* @param string $content: The PlugIn content
* @param array $conf: The PlugIn configuration
*
* @return string The content that is displayed on the website
*/
public function main($content, $conf) {
$this->init($conf);
// Turn cache off.
$this->setCache(FALSE);
return '';
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/plugins/toolbox/tools/dfgviewer/class.tx_dlf_toolsDfgviewer.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/plugins/toolbox/tools/dfgviewer/class.tx_dlf_toolsDfgviewer.php']);
}
?>

37
dlf/plugins/toolbox/tools/dfgviewer/locallang.xml

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<!--
Copyright notice
(c) 2011 Goobi. Digitalisieren im Verein e.V. <contact@goobi.org>
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 2 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!
-->
<T3locallang>
<meta type="array">
<type>module</type>
<description>Language labels for tool tx_dlf_dfgviewer</description>
</meta>
<data type="array">
<languageKey index="default" type="array">
<label index="label">Link to DFG Viewer</label>
</languageKey>
<languageKey index="de" type="array">
<label index="label">Link zum DFG-Viewer</label>
</languageKey>
</data>
</T3locallang>

3
dlf/plugins/toolbox/tools/dfgviewer/setup.txt

@ -1,3 +0,0 @@
plugin.tx_dlf_toolsDfgviewer {
recordId.field = record_id
}

24
dlf/plugins/toolbox/tools/dfgviewer/template.tmpl

@ -1,24 +0,0 @@
<!--
Copyright notice
(c) 2011 Goobi. Digitalisieren im Verein e.V. <contact@goobi.org>
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 2 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!
-->
<!-- ###TEMPLATE### -->
<!-- ###TEMPLATE### -->

130
dlf/plugins/toolbox/tools/pdf/class.tx_dlf_toolsPdf.php

@ -2,7 +2,7 @@
/***************************************************************
* Copyright notice
*
* (c) 2011 Goobi. Digitalisieren im Verein e.V. <contact@goobi.org>
* (c) 2014 Goobi. Digitalisieren im Verein e.V. <contact@goobi.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
@ -59,6 +59,23 @@ class tx_dlf_toolsPdf extends tx_dlf_plugin {
// Turn cache off.
$this->setCache(FALSE);
// Load current document.
$this->loadDocument();
if ($this->doc === NULL || $this->doc->numPages < 1 || empty($this->conf['fileGrpDownload'])) {
// Quit without doing anything if required variables are not set.
return $content;
} else {
// Set default values if not set.
$this->piVars['page'] = t3lib_div::intInRange($this->piVars['page'], 1, $this->doc->numPages, 1);
$this->piVars['double'] = t3lib_div::intInRange($this->piVars['double'], 0, 1, 0);
}
// Load template file.
if (!empty($this->conf['templateFile'])) {
@ -70,14 +87,119 @@ class tx_dlf_toolsPdf extends tx_dlf_plugin {
}
// TODO: Just a quick and dirty hack so far!
$ppn = preg_replace('/oai\:[\w\-\:]*id-/', '', $this->cObj->data['record_id']);
$content = $this->cObj->substituteMarkerArray($this->template, array ('###LINK###' => '<a href="http://digital.slub-dresden.de/fileadmin/data/'.$ppn.'/'.$ppn.'_tif/jpegs/'.$ppn.'.pdf" target="_blank" title="PDF Download">PDF Download</a>'));
// Get single page downloads.
$markerArray['###PAGE###'] = $this->getPageLink();
// Get work download.
$markerArray['###WORK###'] = $this->getWorkLink();
$content .= $this->cObj->substituteMarkerArray($this->template, $markerArray);
return $this->pi_wrapInBaseClass($content);
}
/**
* Get page's download link
*
* @access protected
*
* @return string Link to downloadable page
*/
protected function getPageLink() {
$pageLink = array ();
// Get image link.
if (!empty($this->doc->physicalPagesInfo[$this->doc->physicalPages[$this->piVars['page']]]['files'][$this->conf['fileGrpDownload']])) {
$pageLink[] = $this->doc->getFileLocation($this->doc->physicalPagesInfo[$this->doc->physicalPages[$this->piVars['page']]]['files'][$this->conf['fileGrpDownload']]);
// Get second page, too, if double page view is activated.
if ($this->piVars['double'] && $this->piVars['page'] < $this->doc->numPages) {
$pageLink[] = $this->doc->getFileLocation($this->doc->physicalPagesInfo[$this->doc->physicalPages[$this->piVars['page'] + 1]]['files'][$this->conf['fileGrpDownload']]);
}
} else {
if (TYPO3_DLOG) {
t3lib_div::devLog('[tx_dlf_toolsPdf->getPageLink()] File not found in fileGrp "'.$this->conf['fileGrpDownload'].'"', $this->extKey, SYSLOG_SEVERITY_WARNING);
}
}
// Wrap URLs with HTML.
if (!empty($pageLink)) {
if (count($pageLink) > 1) {
$pageLink[0] = $this->pi_linkToPage($this->pi_getLL('leftPage', ''), $pageLink[0], '_blank', array ('title' => $this->pi_getLL('leftPage', '')));
$pageLink[1] = $this->pi_linkToPage($this->pi_getLL('rightPage', ''), $pageLink[1], '_blank', array ('title' => $this->pi_getLL('rightPage', '')));
} else {
$pageLink[0] = $this->pi_linkToPage($this->pi_getLL('singlePage', ''), $pageLink[0], '_blank', array ('title' => $this->pi_getLL('singlePage', '')));
}
}
return implode('', $pageLink);
}
/**
* Get work's download link
*
* @access protected
*
* @return string Link to downloadable work
*/
protected function getWorkLink() {
$workLink = '';
// Get work link.
if (!empty($this->doc->physicalPagesInfo[$this->doc->physicalPages[0]]['files'][$this->conf['fileGrpDownload']])) {
$workLink = $this->doc->getFileLocation($this->doc->physicalPagesInfo[$this->doc->physicalPages[0]]['files'][$this->conf['fileGrpDownload']]);
} else {
$details = $this->doc->getLogicalStructure($this->doc->toplevelId);
if (!empty($details['files'][$this->conf['fileGrpDownload']])) {
$workLink = $this->doc->getFileLocation($details['files'][$this->conf['fileGrpDownload']]);
}
}
// Wrap URLs with HTML.
if (!empty($workLink)) {
$workLink = $this->pi_linkToPage($this->pi_getLL('work', ''), $workLink, '_blank', array ('title' => $this->pi_getLL('work', '')));
} else {
if (TYPO3_DLOG) {
t3lib_div::devLog('[tx_dlf_toolsPdf->getWorkLink()] File not found in fileGrp "'.$this->conf['fileGrpDownload'].'"', $this->extKey, SYSLOG_SEVERITY_WARNING);
}
}
return $workLink;
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/plugins/toolbox/tools/pdf/class.tx_dlf_toolsPdf.php']) {

12
dlf/plugins/toolbox/tools/pdf/locallang.xml

@ -24,14 +24,20 @@
<T3locallang>
<meta type="array">
<type>module</type>
<description>Language labels for tool tx_dlf_pdf</description>
<description>Language labels for tool tx_dlf_toolsPdf</description>
</meta>
<data type="array">
<languageKey index="default" type="array">
<label index="label">PDF Download</label>
<label index="singlePage">Download single page</label>
<label index="leftPage">Download left page</label>
<label index="rightPage">Download right page</label>
<label index="work">Download whole work</label>
</languageKey>
<languageKey index="de" type="array">
<label index="label">PDF-Download</label>
<label index="singlePage">Einzelseite herunterladen</label>
<label index="leftPage">Linke Seite herunterladen</label>
<label index="rightPage">Rechte Seite herunterladen</label>
<label index="work">Ganzes Werk herunterladen</label>
</languageKey>
</data>
</T3locallang>

3
dlf/plugins/toolbox/tools/pdf/setup.txt

@ -1,3 +0,0 @@
plugin.tx_dlf_toolsPdf {
docId.field = uid
}

3
dlf/plugins/toolbox/tools/pdf/template.tmpl

@ -21,5 +21,6 @@
This copyright notice MUST APPEAR in all copies of the script!
-->
<!-- ###TEMPLATE### -->
<span class="tx-dlf-tools-pdf">###LINK###</span>
<span class="tx-dlf-tools-pdf-site">###PAGE###</span>
<span class="tx-dlf-tools-pdf-work">###WORK###</span>
<!-- ###TEMPLATE### -->
Loading…
Cancel
Save