• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FluidTYPO3 / vhs / 13566190336

27 Feb 2025 12:18PM UTC coverage: 72.127% (-0.6%) from 72.746%
13566190336

push

github

NamelessCoder
[TER] 7.1.0

5649 of 7832 relevant lines covered (72.13%)

20.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.75
/Classes/ViewHelpers/Media/AbstractMediaViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Media;
3

4
/*
5
 * This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use FluidTYPO3\Vhs\Traits\TagViewHelperCompatibility;
12
use FluidTYPO3\Vhs\Utility\ContextUtility;
13
use TYPO3\CMS\Core\Utility\GeneralUtility;
14
use TYPO3\CMS\Core\Utility\PathUtility;
15
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
16

17
/**
18
 * Base class for media related view helpers.
19
 */
20
abstract class AbstractMediaViewHelper extends AbstractTagBasedViewHelper
21
{
22
    use TagViewHelperCompatibility;
23

24
    protected string $mediaSource = '';
25

26
    public function initializeArguments(): void
27
    {
28
        parent::initializeArguments();
42✔
29
        $this->registerArgument(
42✔
30
            'src',
42✔
31
            'mixed',
42✔
32
            'Path to the media resource(s). Can contain single or multiple paths for videos/audio (either CSV, ' .
42✔
33
            'array or implementing Traversable).',
42✔
34
            true
42✔
35
        );
42✔
36
        $this->registerArgument(
42✔
37
            'relative',
42✔
38
            'boolean',
42✔
39
            'If FALSE media URIs are rendered absolute. URIs in backend mode are always absolute.',
42✔
40
            false,
42✔
41
            true
42✔
42
        );
42✔
43
    }
44

45
    /**
46
     * Turns a relative source URI into an absolute URL
47
     * if required.
48
     */
49
    public static function preprocessSourceUri(string $src, array $arguments): string
50
    {
51
        $src = str_replace('%2F', '/', rawurlencode($src));
7✔
52
        if (substr($src, 0, 1) !== '/' && substr($src, 0, 4) !== 'http') {
7✔
53
            $src = $GLOBALS['TSFE']->absRefPrefix . $src;
7✔
54
        }
55
        if (!empty($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_vhs.']['settings.']['prependPath'])) {
7✔
56
            $src = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_vhs.']['settings.']['prependPath'] . $src;
×
57
        } elseif (ContextUtility::isBackend() || !$arguments['relative']) {
7✔
58
            /** @var string $siteUrl */
59
            $siteUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
×
60
            $src = $siteUrl . ltrim($src, '/');
×
61
        }
62
        if (empty($src)) {
7✔
63
            // Do not pass an empty $src to PathUtility, it requires non-empty strings on 10.4.
64
            return '';
7✔
65
        }
66
        return PathUtility::getAbsoluteWebPath($src);
×
67
    }
68

69
    /**
70
     * Returns an array of sources resolved from src argument
71
     * which can be either an array, CSV or implement Traversable
72
     * to be consumed by ViewHelpers handling multiple sources.
73
     */
74
    public static function getSourcesFromArgument(array $arguments): array
75
    {
76
        $src = $arguments['src'];
×
77
        if ($src instanceof \Traversable) {
×
78
            $src = iterator_to_array($src);
×
79
        } elseif (is_string($src)) {
×
80
            $src = GeneralUtility::trimExplode(',', $src, true);
×
81
        }
82
        return $src;
×
83
    }
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc