Passed
Pull Request — master (#108)
by Ralf
02:30
created

FileUrlViewHelper::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
namespace EWW\Dpf\ViewHelpers;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
class FileUrlViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
{
19
    /**
20
     * Secret API key for delivering inactive documents.
21
     * @var string
22
     */
23
    private $secretKey;
24
25
    /**
26
     * Initialize secret key from plugin TYPOScript configuration.
27
     */
28
    public function initialize() {
29
        parent::initialize();
30
31
        $configurationManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
0 ignored issues
show
Unused Code introduced by
The assignment to $configurationManager is dead and can be removed.
Loading history...
Bug introduced by
The type EWW\Dpf\ViewHelpers\GeneralUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
        $settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
0 ignored issues
show
Bug introduced by
The type EWW\Dpf\ViewHelpers\ConfigurationManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
34
        if (isset($settings['plugin.']['tx_dpf.']['settings.']['deliverInactiveSecretKey'])) {
35
            $this->secretKey = $settings['plugin.']['tx_dpf.']['settings.']['deliverInactiveSecretKey'];
36
        }
37
    }
38
39
    /**
40
     *
41
     * @param string $uri
42
     *
43
     */
44
    public function render($uri)
45
    {
46
        $fileUri = $this->buildFileUri($uri);
47
48
        // pass configured API secret key parameter to enable dissemination for inactive documents
49
        if (isset($this->secretKey)) {
50
            $fileUri .= '?tx_dpf[deliverInactive]=6fc4d012-11ac-46bf-9bfc-82240628656b';
51
        }
52
53
        return $fileUri;
54
    }
55
56
    /**
57
     * Construct file URI
58
     */
59
    protected function buildFileUri($uri)
60
    {
61
62
        $uploadFileUrl = new \EWW\Dpf\Helper\UploadFileUrl;
63
64
        $regex = '/\/(\w*:\d*)\/datastreams\/(\w*-\d*)/';
65
        preg_match($regex, $uri, $treffer);
66
67
        if (!empty($treffer)) {
68
            $qid = $treffer[1];
69
            $fid = $treffer[2];
70
            return $uploadFileUrl->getBaseUrl() . '/api/' . urlencode($qid) . '/attachment/' . $fid;
71
        }
72
73
        return $uri;
74
    }
75
76
}
77