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

FileUrlViewHelper::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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