119 lines
5.1 KiB
PHP
119 lines
5.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
|
|
*
|
|
* This file is part of the Kitodo and TYPO3 projects.
|
|
*
|
|
* @license GNU General Public License version 3 or later.
|
|
* For the full copyright and license information, please read the
|
|
* LICENSE.txt file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Kitodo\Dlf\Plugin;
|
|
|
|
/**
|
|
* Plugin AudioPlayer for the 'dlf' extension
|
|
*
|
|
* @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
|
|
* @package TYPO3
|
|
* @subpackage dlf
|
|
* @access public
|
|
*/
|
|
class AudioPlayer extends \Kitodo\Dlf\Common\AbstractPlugin
|
|
{
|
|
public $scriptRelPath = 'Classes/Plugin/AudioPlayer.php';
|
|
|
|
/**
|
|
* Holds the current audio file's URL, MIME type and optional label
|
|
*
|
|
* @var array
|
|
* @access protected
|
|
*/
|
|
protected $audio = [];
|
|
|
|
/**
|
|
* Adds Player javascript
|
|
*
|
|
* @access protected
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function addPlayerJS()
|
|
{
|
|
$pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
|
|
// Add AudioPlayer library.
|
|
$pageRenderer->addCssFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/jPlayer/blue.monday/css/jplayer.blue.monday.min.css');
|
|
$pageRenderer->addCssInlineBlock('kitodo-audioplayer-configuration', '#tx-dlf-audio { width: 100px; height: 100px; }');
|
|
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/jPlayer/jquery.jplayer.min.js');
|
|
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/AudioPlayer/AudioPlayer.js');
|
|
// Add AudioPlayer configuration.
|
|
$audioplayerConfiguration = '
|
|
$(document).ready(function() {
|
|
AudioPlayer = new dlfAudioPlayer({
|
|
audio: {
|
|
mimeType: "' . $this->audio['mimetype'] . '",
|
|
title: "' . $this->audio['label'] . '",
|
|
url: "' . $this->audio['url'] . '"
|
|
},
|
|
parentElId: "tx-dlf-audio",
|
|
swfPath: "' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/jPlayer/jquery.jplayer.swf"
|
|
});
|
|
});
|
|
';
|
|
$pageRenderer->addJsFooterInlineCode('kitodo-audioplayer-configuration', $audioplayerConfiguration);
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
// Load current document.
|
|
$this->loadDocument();
|
|
if (
|
|
$this->doc === null
|
|
|| $this->doc->numPages < 1
|
|
) {
|
|
// Quit without doing anything if required variables are not set.
|
|
return $content;
|
|
} else {
|
|
// Set default values if not set.
|
|
// $this->piVars['page'] may be integer or string (physical structure @ID)
|
|
if (
|
|
(int) $this->piVars['page'] > 0
|
|
|| empty($this->piVars['page'])
|
|
) {
|
|
$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
|
|
} else {
|
|
$this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
|
|
}
|
|
$this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
|
|
}
|
|
// Check if there are any audio files available.
|
|
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpAudio']])) {
|
|
// Get audio data.
|
|
$this->audio['url'] = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpAudio']]);
|
|
$this->audio['label'] = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['label'];
|
|
$this->audio['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpAudio']]);
|
|
} else {
|
|
// Quit without doing anything if required variables are not set.
|
|
return $content;
|
|
}
|
|
// Load template file.
|
|
$this->getTemplate();
|
|
// Fill in the template markers (currently: none).
|
|
$markerArray = [];
|
|
$content .= $this->templateService->substituteMarkerArray($this->template, $markerArray);
|
|
return $this->pi_wrapInBaseClass($content);
|
|
}
|
|
}
|