|
1
|
|
|
<?php |
|
2
|
|
|
namespace Kitodo\Dlf\Plugin; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
8
|
|
|
* |
|
9
|
|
|
* @license GNU General Public License version 3 or later. |
|
10
|
|
|
* For the full copyright and license information, please read the |
|
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Plugin AudioPlayer for the 'dlf' extension |
|
16
|
|
|
* |
|
17
|
|
|
* @author Sebastian Meyer <[email protected]> |
|
18
|
|
|
* @package TYPO3 |
|
19
|
|
|
* @subpackage dlf |
|
20
|
|
|
* @access public |
|
21
|
|
|
*/ |
|
22
|
|
|
class AudioPlayer extends \Kitodo\Dlf\Common\AbstractPlugin { |
|
23
|
|
|
public $scriptRelPath = 'Classes/Plugin/AudioPlayer.php'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Holds the current audio file's URL, MIME type and optional label |
|
27
|
|
|
* |
|
28
|
|
|
* @var array |
|
29
|
|
|
* @access protected |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $audio = []; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Adds Player javascript |
|
35
|
|
|
* |
|
36
|
|
|
* @access protected |
|
37
|
|
|
* |
|
38
|
|
|
* @return string Player script tags ready for output |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function addPlayerJS() { |
|
41
|
|
|
$output = []; |
|
42
|
|
|
$output[] = '<link type="text/css" rel="stylesheet" href="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'Resources/Public/Javascript/jPlayer/blue.monday/css/jplayer.blue.monday.min.css">'; |
|
43
|
|
|
$output[] = '<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'Resources/Public/Javascript/jPlayer/jquery.jplayer.min.js"></script>'; |
|
44
|
|
|
$output[] = '<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'Resources/Public/Javascript/AudioPlayer/AudioPlayer.js"></script>'; |
|
45
|
|
|
// Add player configuration. |
|
46
|
|
|
$output[] = ' |
|
47
|
|
|
<style>#tx-dlf-audio { width: 100px; height: 100px; }</style> |
|
48
|
|
|
<script id="tx-dlf-audioplayer-initViewer" type="text/javascript"> |
|
49
|
|
|
$(document).ready(function() { |
|
50
|
|
|
AudioPlayer = new dlfAudioPlayer({ |
|
51
|
|
|
audio: { |
|
52
|
|
|
mimeType: "'.$this->audio['mimetype'].'", |
|
53
|
|
|
title: "'.$this->audio['label'].'", |
|
54
|
|
|
url: "'.$this->audio['url'].'" |
|
55
|
|
|
}, |
|
56
|
|
|
parentElId: "tx-dlf-audio", |
|
57
|
|
|
swfPath: "'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'Resources/Public/Javascript/jPlayer/jquery.jplayer.swf" |
|
58
|
|
|
}); |
|
59
|
|
|
}); |
|
60
|
|
|
</script>'; |
|
61
|
|
|
return implode("\n", $output); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* The main method of the PlugIn |
|
66
|
|
|
* |
|
67
|
|
|
* @access public |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $content: The PlugIn content |
|
70
|
|
|
* @param array $conf: The PlugIn configuration |
|
71
|
|
|
* |
|
72
|
|
|
* @return string The content that is displayed on the website |
|
73
|
|
|
*/ |
|
74
|
|
|
public function main($content, $conf) { |
|
75
|
|
|
$this->init($conf); |
|
76
|
|
|
// Load current document. |
|
77
|
|
|
$this->loadDocument(); |
|
78
|
|
|
if ($this->doc === NULL |
|
79
|
|
|
|| $this->doc->numPages < 1) { |
|
|
|
|
|
|
80
|
|
|
// Quit without doing anything if required variables are not set. |
|
81
|
|
|
return $content; |
|
82
|
|
|
} else { |
|
83
|
|
|
// Set default values if not set. |
|
84
|
|
|
// $this->piVars['page'] may be integer or string (physical structure @ID) |
|
85
|
|
|
if ((int) $this->piVars['page'] > 0 |
|
86
|
|
|
|| empty($this->piVars['page'])) { |
|
87
|
|
|
$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1); |
|
88
|
|
|
} else { |
|
89
|
|
|
$this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
$this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0); |
|
92
|
|
|
} |
|
93
|
|
|
// Check if there are any audio files available. |
|
94
|
|
|
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpAudio']])) { |
|
|
|
|
|
|
95
|
|
|
// Get audio data. |
|
96
|
|
|
$this->audio['url'] = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpAudio']]); |
|
97
|
|
|
$this->audio['label'] = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['label']; |
|
98
|
|
|
$this->audio['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpAudio']]); |
|
99
|
|
|
} else { |
|
100
|
|
|
// Quit without doing anything if required variables are not set. |
|
101
|
|
|
return $content; |
|
102
|
|
|
} |
|
103
|
|
|
// Load template file. |
|
104
|
|
|
$this->getTemplate(); |
|
105
|
|
|
// Fill in the template markers. |
|
106
|
|
|
$markerArray = [ |
|
107
|
|
|
'###PLAYER_JS###' => $this->addPlayerJS() |
|
108
|
|
|
]; |
|
109
|
|
|
$content .= $this->cObj->substituteMarkerArray($this->template, $markerArray); |
|
|
|
|
|
|
110
|
|
|
return $this->pi_wrapInBaseClass($content); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|