Passed
Pull Request — master (#108)
by Ralf
06:26 queued 47s
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
use TYPO3\CMS\Core\Utility\GeneralUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Core\Utility\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...
18
19
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...
20
{
21
    /**
22
     * Secret API key for delivering inactive documents.
23
     * @var string
24
     */
25
    private $secretKey;
26
27
    /**
28
     * Initialize secret key from plugin TYPOScript configuration.
29
     */
30
    public function initialize() {
31
        parent::initialize();
32
33
        $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...
34
        $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...
35
36
        if (isset($settings['plugin.']['tx_dpf.']['settings.']['deliverInactiveSecretKey'])) {
37
            $this->secretKey = $settings['plugin.']['tx_dpf.']['settings.']['deliverInactiveSecretKey'];
38
        }
39
    }
40
41
    /**
42
     *
43
     * @param string $uri
44
     *
45
     */
46
    public function render($uri)
47
    {
48
        $fileUri = $this->buildFileUri($uri);
49
50
        // pass configured API secret key parameter to enable dissemination for inactive documents
51
        if (isset($this->secretKey)) {
52
            $fileUri .= '?tx_dpf[deliverInactive]=6fc4d012-11ac-46bf-9bfc-82240628656b';
53
        }
54
55
        return $fileUri;
56
    }
57
58
    /**
59
     * Construct file URI
60
     */
61
    protected function buildFileUri($uri)
62
    {
63
64
        $uploadFileUrl = new \EWW\Dpf\Helper\UploadFileUrl;
65
66
        $regex = '/\/(\w*:\d*)\/datastreams\/(\w*-\d*)/';
67
        preg_match($regex, $uri, $treffer);
68
69
        if (!empty($treffer)) {
70
            $qid = $treffer[1];
71
            $fid = $treffer[2];
72
            return $uploadFileUrl->getBaseUrl() . '/api/' . urlencode($qid) . '/attachment/' . $fid;
73
        }
74
75
        return $uri;
76
    }
77
78
}
79