Add MIME type to pageview image and fulltext URLs

This commit is contained in:
Sebastian Meyer 2016-05-23 13:41:22 +02:00
parent e7c3f92312
commit a3b679c783
2 changed files with 74 additions and 33 deletions

View File

@ -367,6 +367,35 @@ final class tx_dlf_document {
} }
/**
* This gets the MIME type of a file representing a physical page
*
* @access public
*
* @param string $id: The @ID attribute of the file node
*
* @return string The file's MIME type
*/
public function getFileMimeType($id) {
if (!empty($id) && ($mimetype = $this->mets->xpath('./mets:fileSec/mets:fileGrp/mets:file[@ID="'.$id.'"]/@MIMETYPE'))) {
return (string) $mimetype[0];
} else {
if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_document->getFileMimeType('.$id.')] There is no file node with @ID "'.$id.'" or no MIME type specified', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return '';
}
}
/** /**
* This is a singleton class, thus an instance must be created by this method * This is a singleton class, thus an instance must be created by this method
* *

View File

@ -55,7 +55,7 @@ class tx_dlf_pageview extends tx_dlf_plugin {
protected $hasFulltexts = false; protected $hasFulltexts = false;
/** /**
* Holds the current images' URLs * Holds the current images' URLs and MIME types
* *
* @var array * @var array
* @access protected * @access protected
@ -90,10 +90,12 @@ class tx_dlf_pageview extends tx_dlf_plugin {
$output = array (); $output = array ();
// Add OpenLayers library. // Add OpenLayers library.
$output[] = ' $output[] = '<link type="text/css" rel="stylesheet" href="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'lib/OpenLayers/ol3.css">';
<link type="text/css" rel="stylesheet" href="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'lib/OpenLayers/ol3.css">
<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'lib/OpenLayers/glif.min.js"></script> $output[] = '<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'lib/OpenLayers/glif.min.js"></script>';
<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'lib/OpenLayers/ol3-dlf.js"></script>';
$output[] = '<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'lib/OpenLayers/ol3-dlf.js"></script>';
return implode("\n", $output); return implode("\n", $output);
} }
@ -116,14 +118,19 @@ class tx_dlf_pageview extends tx_dlf_plugin {
$output[] = $this->addOpenLayersJS(); $output[] = $this->addOpenLayersJS();
// Add viewer library. // Add viewer library.
$output[] = ' $output[] = '<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_utils.js"></script>';
<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_utils.js"></script>
<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_ol3.js"></script> $output[] = '<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_ol3.js"></script>';
<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_ol3_styles.js"></script>
<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_altoparser.js"></script> $output[] = '<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_ol3_styles.js"></script>';
<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_pageview_imagemanipulation_control.js"></script>
<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_pageview_fulltext_control.js"></script> $output[] = '<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_altoparser.js"></script>';
<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_pageview.js"></script>';
$output[] = '<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_pageview_imagemanipulation_control.js"></script>';
$output[] = '<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_pageview_fulltext_control.js"></script>';
$output[] = '<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/pageview/tx_dlf_pageview.js"></script>';
// Add viewer configuration. // Add viewer configuration.
$output[] = ' $output[] = '
@ -145,17 +152,17 @@ class tx_dlf_pageview extends tx_dlf_plugin {
} }
/** /**
* Get image's URL * Get image's URL and MIME type
* *
* @access protected * @access protected
* *
* @param integer $page: Page number * @param integer $page: Page number
* *
* @return string URL of image file * @return array URL and MIME type of image file
*/ */
protected function getImageUrl($page) { protected function getImage($page) {
$imageUrl = ''; $image = array ();
// Get @USE value of METS fileGrp. // Get @USE value of METS fileGrp.
$fileGrps = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['fileGrps']); $fileGrps = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['fileGrps']);
@ -165,7 +172,9 @@ class tx_dlf_pageview extends tx_dlf_plugin {
// Get image link. // Get image link.
if (!empty($this->doc->physicalPagesInfo[$this->doc->physicalPages[$page]]['files'][$fileGrp])) { if (!empty($this->doc->physicalPagesInfo[$this->doc->physicalPages[$page]]['files'][$fileGrp])) {
$imageUrl = $this->doc->getFileLocation($this->doc->physicalPagesInfo[$this->doc->physicalPages[$page]]['files'][$fileGrp]); $image['url'] = $this->doc->getFileLocation($this->doc->physicalPagesInfo[$this->doc->physicalPages[$page]]['files'][$fileGrp]);
$image['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalPagesInfo[$this->doc->physicalPages[$page]]['files'][$fileGrp]);
break; break;
@ -173,7 +182,7 @@ class tx_dlf_pageview extends tx_dlf_plugin {
if (TYPO3_DLOG) { if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_pageview->getImageUrl('.$page.')] File not found in fileGrp "'.$fileGrp.'"', $this->extKey, SYSLOG_SEVERITY_WARNING); \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_pageview->getImage('.$page.')] File not found in fileGrp "'.$fileGrp.'"', $this->extKey, SYSLOG_SEVERITY_WARNING);
} }
@ -181,24 +190,24 @@ class tx_dlf_pageview extends tx_dlf_plugin {
} }
return $imageUrl; return $image;
} }
/** /**
* Get ALTO XML URL * Get fulltext URL and MIME type
* *
* @access protected * @access protected
* *
* @param integer $page: Page number * @param integer $page: Page number
* *
* @return string URL of image file * @return array URL and MIME type of fulltext file
*/ */
protected function getAltoUrl($page) { protected function getFulltext($page) {
$fulltext = array ();
// Get @USE value of METS fileGrp. // Get @USE value of METS fileGrp.
// we need USE="FULLTEXT"
$fileGrpFulltext = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['fileGrpFulltext']); $fileGrpFulltext = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['fileGrpFulltext']);
while ($fileGrpFulltext = @array_pop($fileGrpFulltext)) { while ($fileGrpFulltext = @array_pop($fileGrpFulltext)) {
@ -206,10 +215,13 @@ class tx_dlf_pageview extends tx_dlf_plugin {
// Get fulltext link. // Get fulltext link.
if (!empty($this->doc->physicalPagesInfo[$this->doc->physicalPages[$page]]['files'][$fileGrpFulltext])) { if (!empty($this->doc->physicalPagesInfo[$this->doc->physicalPages[$page]]['files'][$fileGrpFulltext])) {
$fulltextUrl = $this->doc->getFileLocation($this->doc->physicalPagesInfo[$this->doc->physicalPages[$page]]['files'][$fileGrpFulltext]); $fulltext['url'] = $this->doc->getFileLocation($this->doc->physicalPagesInfo[$this->doc->physicalPages[$page]]['files'][$fileGrpFulltext]);
// Build typolink configuration array. // Build typolink configuration array.
$fulltextUrl = '/index.php?eID=tx_dlf_fulltext_eid&url='. $fulltextUrl; // @TODO change hardcoded path to real typolink configuration
$fulltext['url'] = '/index.php?eID=tx_dlf_fulltext_eid&url='.$fulltext['url'];
$fulltext['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalPagesInfo[$this->doc->physicalPages[$page]]['files'][$fileGrpFulltext]);
$this->hasFulltexts = true; $this->hasFulltexts = true;
@ -219,7 +231,7 @@ class tx_dlf_pageview extends tx_dlf_plugin {
if (TYPO3_DLOG) { if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_pageview->getImageUrl('.$page.')] File not found in fileGrp "'.$fileGrp.'"', $this->extKey, SYSLOG_SEVERITY_WARNING); \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_pageview->getFulltext('.$page.')] File not found in fileGrp "'.$fileGrp.'"', $this->extKey, SYSLOG_SEVERITY_WARNING);
} }
@ -227,7 +239,7 @@ class tx_dlf_pageview extends tx_dlf_plugin {
} }
return $fulltextUrl; return $fulltext;
} }
@ -309,13 +321,13 @@ class tx_dlf_pageview extends tx_dlf_plugin {
} }
// Get image data. // Get image data.
$this->images[0] = $this->getImageUrl($this->piVars['page']); $this->images[0] = $this->getImage($this->piVars['page']);
$this->fulltexts[0] = $this->getAltoUrl($this->piVars['page']); $this->fulltexts[0] = $this->getFulltext($this->piVars['page']);
if ($this->piVars['double'] && $this->piVars['page'] < $this->doc->numPages) { if ($this->piVars['double'] && $this->piVars['page'] < $this->doc->numPages) {
$this->images[1] = $this->getImageUrl($this->piVars['page'] + 1); $this->images[1] = $this->getImage($this->piVars['page'] + 1);
$this->fulltexts[1] = $this->getAltoUrl($this->piVars['page'] + 1); $this->fulltexts[1] = $this->getFulltext($this->piVars['page'] + 1);
} }