Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c2a726...77fa83 )
by Sebastian
18s queued 13s
created

ImageDownloadTool   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 18
eloc 53
c 0
b 0
f 0
dl 0
loc 102
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B main() 0 42 10
B getImage() 0 34 8
1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
13
namespace Kitodo\Dlf\Plugin\Tools;
14
15
use Kitodo\Dlf\Common\Helper;
16
17
/**
18
 * Image Download tool for the plugin 'Toolbox' of the 'dlf' extension
19
 *
20
 * @author Alexander Bigga <[email protected]>
21
 * @package TYPO3
22
 * @subpackage dlf
23
 * @access public
24
 */
25
class ImageDownloadTool extends \Kitodo\Dlf\Common\AbstractPlugin
26
{
27
    public $scriptRelPath = 'Classes/Plugin/Tools/ImageDownloadTool.php';
28
29
    /**
30
     * The main method of the PlugIn
31
     *
32
     * @access public
33
     *
34
     * @param string $content: The PlugIn content
35
     * @param array $conf: The PlugIn configuration
36
     *
37
     * @return string The content that is displayed on the website
38
     */
39
    public function main($content, $conf)
40
    {
41
        $this->init($conf);
42
        // Merge configuration with conf array of toolbox.
43
        if (!empty($this->cObj->data['conf'])) {
44
            $this->conf = Helper::mergeRecursiveWithOverrule($this->cObj->data['conf'], $this->conf);
0 ignored issues
show
Bug Best Practice introduced by
The property conf does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
45
        }
46
        // Load current document.
47
        $this->loadDocument();
48
        if (
49
            $this->doc === null
50
            || $this->doc->numPages < 1
51
            || empty($this->conf['fileGrpsImageDownload'])
52
        ) {
53
            // Quit without doing anything if required variables are not set.
54
            return $content;
55
        } else {
56
            if (!empty($this->piVars['logicalPage'])) {
57
                $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
0 ignored issues
show
Bug Best Practice introduced by
The property piVars does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
58
                // The logical page parameter should not appear again
59
                unset($this->piVars['logicalPage']);
60
            }
61
            // Set default values if not set.
62
            // $this->piVars['page'] may be integer or string (physical structure @ID)
63
            if (
64
                (int) $this->piVars['page'] > 0
65
                || empty($this->piVars['page'])
66
            ) {
67
                $this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
68
            } else {
69
                $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
70
            }
71
            $this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
72
        }
73
        // Load template file.
74
        $this->getTemplate();
75
        // Get left or single page download.
76
        $markerArray['###IMAGE_LEFT###'] = $this->piVars['double'] == 1 ? $this->getImage($this->piVars['page'], $this->pi_getLL('leftPage', '')) : $this->getImage($this->piVars['page'], $this->pi_getLL('singlePage', ''));
77
        // Get right page download.
78
        $markerArray['###IMAGE_RIGHT###'] = $this->piVars['double'] == 1 ? $this->getImage($this->piVars['page'] + 1, $this->pi_getLL('rightPage', '')) : '';
79
        $content .= $this->templateService->substituteMarkerArray($this->template, $markerArray);
80
        return $this->pi_wrapInBaseClass($content);
81
    }
82
83
    /**
84
     * Get image's URL and MIME type
85
     *
86
     * @access protected
87
     *
88
     * @param int $page: Page number
89
     * @param string $label: Link title and label
90
     *
91
     * @return string Link to image file with given label
92
     */
93
    protected function getImage($page, $label)
94
    {
95
        $image = [];
96
        // Get @USE value of METS fileGrp.
97
        $fileGrps = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['fileGrpsImageDownload']);
98
        while ($fileGrp = @array_pop($fileGrps)) {
99
            // Get image link.
100
            if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp])) {
101
                $image['url'] = $this->doc->getDownloadLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]);
102
                $image['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]);
103
                switch ($image['mimetype']) {
104
                    case 'image/jpeg':
105
                        $mimetypeLabel = '(JPG)';
106
                        break;
107
                    case 'image/tiff':
108
                        $mimetypeLabel = '(TIFF)';
109
                        break;
110
                    default:
111
                        $mimetypeLabel = '';
112
                }
113
                $linkConf = [
114
                    'parameter' => $image['url'],
115
                    'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0,
116
                    'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'],
117
                    'title' => $label . ' ' . $mimetypeLabel,
118
                    'additionalParams' => '',
119
                ];
120
                $imageLink = $this->cObj->typoLink($label . ' ' . $mimetypeLabel, $linkConf);
121
                break;
122
            } else {
123
                Helper::devLog('File not found in fileGrp "' . $fileGrp . '"', DEVLOG_SEVERITY_WARNING);
124
            }
125
        }
126
        return $imageLink;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $imageLink does not seem to be defined for all execution paths leading up to this point.
Loading history...
127
    }
128
}
129