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

PdfDownloadTool::getWorkLink()   B

Complexity

Conditions 7
Paths 27

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 25
rs 8.8333
cc 7
nc 27
nop 0
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
 * PDF Download tool for the plugin 'Toolbox' of the 'dlf' extension
19
 *
20
 * @author Sebastian Meyer <[email protected]>
21
 * @author Alexander Bigga <[email protected]>
22
 * @package TYPO3
23
 * @subpackage dlf
24
 * @access public
25
 */
26
class PdfDownloadTool extends \Kitodo\Dlf\Common\AbstractPlugin
27
{
28
    public $scriptRelPath = 'Classes/Plugin/Tools/PdfDownloadTool.php';
29
30
    /**
31
     * The main method of the PlugIn
32
     *
33
     * @access public
34
     *
35
     * @param string $content: The PlugIn content
36
     * @param array $conf: The PlugIn configuration
37
     *
38
     * @return string The content that is displayed on the website
39
     */
40
    public function main($content, $conf)
41
    {
42
        $this->init($conf);
43
        // Merge configuration with conf array of toolbox.
44
        if (!empty($this->cObj->data['conf'])) {
45
            $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...
46
        }
47
        // Load current document.
48
        $this->loadDocument();
49
        if (
50
            $this->doc === null
51
            || $this->doc->numPages < 1
52
            || empty($this->conf['fileGrpDownload'])
53
        ) {
54
            // Quit without doing anything if required variables are not set.
55
            return $content;
56
        } else {
57
            if (!empty($this->piVars['logicalPage'])) {
58
                $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...
59
                // The logical page parameter should not appear again
60
                unset($this->piVars['logicalPage']);
61
            }
62
            // Set default values if not set.
63
            // $this->piVars['page'] may be integer or string (physical structure @ID)
64
            if (
65
                (int) $this->piVars['page'] > 0
66
                || empty($this->piVars['page'])
67
            ) {
68
                $this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
69
            } else {
70
                $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
71
            }
72
            $this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
73
        }
74
        // Load template file.
75
        $this->getTemplate();
76
        // Get single page downloads.
77
        $markerArray['###PAGE###'] = $this->getPageLink();
78
        // Get work download.
79
        $markerArray['###WORK###'] = $this->getWorkLink();
80
        $content .= $this->templateService->substituteMarkerArray($this->template, $markerArray);
81
        return $this->pi_wrapInBaseClass($content);
82
    }
83
84
    /**
85
     * Get page's download link
86
     *
87
     * @access protected
88
     *
89
     * @return string Link to downloadable page
90
     */
91
    protected function getPageLink()
92
    {
93
        $page1Link = '';
94
        $page2Link = '';
95
        $pageNumber = $this->piVars['page'];
96
        // Get image link.
97
        $details = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber]];
98
        $file = $details['files'][$this->conf['fileGrpDownload']];
99
        if (!empty($file)) {
100
            $page1Link = $this->doc->getFileLocation($file);
101
        }
102
        // Get second page, too, if double page view is activated.
103
        if (
104
            $this->piVars['double']
105
            && $pageNumber < $this->doc->numPages
106
        ) {
107
            $details = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber + 1]];
108
            $file = $details['files'][$this->conf['fileGrpDownload']];
109
            if (!empty($file)) {
110
                $page2Link = $this->doc->getFileLocation($file);
111
            }
112
        }
113
        if (
114
            empty($page1Link)
115
            && empty($page2Link)
116
        ) {
117
            Helper::devLog('File not found in fileGrp "' . $this->conf['fileGrpDownload'] . '"', DEVLOG_SEVERITY_WARNING);
118
        }
119
        // Wrap URLs with HTML.
120
        $linkConf = [
121
            'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0,
122
            'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http']
123
        ];
124
        if (!empty($page1Link)) {
125
            $linkConf['parameter'] = $page1Link;
126
            if ($this->piVars['double']) {
127
                $linkConf['title'] = $this->pi_getLL('leftPage', '');
128
                $page1Link = $this->cObj->typoLink($this->pi_getLL('leftPage', ''), $linkConf);
129
            } else {
130
                $linkConf['title'] = $this->pi_getLL('singlePage', '');
131
                $page1Link = $this->cObj->typoLink($this->pi_getLL('singlePage', ''), $linkConf);
132
            }
133
        }
134
        if (!empty($page2Link)) {
135
            $linkConf['parameter'] = $page2Link;
136
            $linkConf['title'] = $this->pi_getLL('rightPage', '');
137
            $page2Link = $this->cObj->typoLink($this->pi_getLL('rightPage', ''), $linkConf);
138
        }
139
        return $page1Link . $page2Link;
140
    }
141
142
    /**
143
     * Get work's download link
144
     *
145
     * @access protected
146
     *
147
     * @return string Link to downloadable work
148
     */
149
    protected function getWorkLink()
150
    {
151
        $workLink = '';
152
        // Get work link.
153
        if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$this->conf['fileGrpDownload']])) {
154
            $workLink = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$this->conf['fileGrpDownload']]);
155
        } else {
156
            $details = $this->doc->getLogicalStructure($this->doc->toplevelId);
157
            if (!empty($details['files'][$this->conf['fileGrpDownload']])) {
158
                $workLink = $this->doc->getFileLocation($details['files'][$this->conf['fileGrpDownload']]);
159
            }
160
        }
161
        // Wrap URLs with HTML.
162
        if (!empty($workLink)) {
163
            $linkConf = [
164
                'parameter' => $workLink,
165
                'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0,
166
                'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'],
167
                'title' => $this->pi_getLL('work', '')
168
            ];
169
            $workLink = $this->cObj->typoLink($this->pi_getLL('work', ''), $linkConf);
170
        } else {
171
            Helper::devLog('File not found in fileGrp "' . $this->conf['fileGrpDownload'] . '"', DEVLOG_SEVERITY_WARNING);
172
        }
173
        return $workLink;
174
    }
175
}
176