-
Notifications
You must be signed in to change notification settings - Fork 228
/
AbstractMediaViewHelper.php
executable file
·91 lines (84 loc) · 2.68 KB
/
AbstractMediaViewHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\Media;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* Base class for media related view helpers.
*/
abstract class AbstractMediaViewHelper extends AbstractTagBasedViewHelper
{
/**
*
* @var string
*/
protected $mediaSource;
/**
* Initialize arguments.
*
* @return void
* @api
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument(
'src',
'mixed',
'Path to the media resource(s). Can contain single or multiple paths for videos/audio (either CSV, ' .
'array or implementing Traversable).',
true
);
$this->registerArgument(
'relative',
'boolean',
'If FALSE media URIs are rendered absolute. URIs in backend mode are always absolute.',
false,
true
);
}
/**
* Turns a relative source URI into an absolute URL
* if required
*
* @param string $src
* @param array $arguments
* @return string
*/
public static function preprocessSourceUri($src, array $arguments)
{
$src = str_replace('%2F', '/', rawurlencode($src));
if (substr($src, 0, 1) !== '/' && substr($src, 0, 4) !== 'http') {
$src = $GLOBALS['TSFE']->absRefPrefix . $src;
}
if (false === empty($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_vhs.']['settings.']['prependPath'])) {
$src = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_vhs.']['settings.']['prependPath'] . $src;
} elseif ('BE' === TYPO3_MODE || false === (boolean) $arguments['relative']) {
$src = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . ltrim($src, '/');
}
return $src;
}
/**
* Returns an array of sources resolved from src argument
* which can be either an array, CSV or implement Traversable
* to be consumed by ViewHelpers handling multiple sources.
*
* @param array $arguments
* @return array
*/
public static function getSourcesFromArgument(array $arguments)
{
$src = $arguments['src'];
if ($src instanceof \Traversable) {
$src = iterator_to_array($src);
} elseif (true === is_string($src)) {
$src = GeneralUtility::trimExplode(',', $src, true);
}
return $src;
}
}