ImageUtility::getAllowedFileExtensions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Image Utility.
5
 */
6
7
namespace HDNET\Focuspoint\Utility;
8
9
use TYPO3\CMS\Core\Utility\GeneralUtility;
10
use TYPO3\CMS\Core\Utility\PathUtility;
11
12
/**
13
 * Image Utility.
14
 */
15
class ImageUtility
16
{
17
    /**
18
     * Get the allowed file extensions for the focuspoint method.
19
     *
20
     * @return array
21
     */
22
    public static function getAllowedFileExtensions()
23
    {
24
        $configuredExtensions = GeneralUtility::trimExplode(
25
            ',',
26
            \mb_strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),
27
            true
28
        );
29
        $ignoreExtensions = ['pdf', 'ai', 'tga'];
30
31
        return \array_diff($configuredExtensions, $ignoreExtensions);
32
    }
33
34
    /**
35
     * Check if the given path or extension is valid for the focuspoint.
36
     *
37
     * @param $pathOrExtension
38
     *
39
     * @return bool
40
     */
41
    public static function isValidFileExtension($pathOrExtension)
42
    {
43
        $pathOrExtension = \mb_strtolower($pathOrExtension);
44
        $validExtensions = self::getAllowedFileExtensions();
45
        if (\in_array($pathOrExtension, $validExtensions, true)) {
46
            return true;
47
        }
48
49
        return \in_array(PathUtility::pathinfo($pathOrExtension, PATHINFO_EXTENSION), $validExtensions, true);
50
    }
51
}
52