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

PageGrid::getEntry()   B

Complexity

Conditions 8
Paths 48

Size

Total Lines 37
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 25
c 0
b 0
f 0
dl 0
loc 37
rs 8.4444
cc 8
nc 48
nop 2
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;
14
15
use Kitodo\Dlf\Common\Helper;
16
17
/**
18
 * Plugin 'Page Grid' for the 'dlf' extension
19
 *
20
 * @author Henrik Lochmann <[email protected]>
21
 * @author Sebastian Meyer <[email protected]>
22
 * @package TYPO3
23
 * @subpackage dlf
24
 * @access public
25
 */
26
class PageGrid extends \Kitodo\Dlf\Common\AbstractPlugin
27
{
28
    public $scriptRelPath = 'Classes/Plugin/PageGrid.php';
29
30
    /**
31
     * Renders entry for one page of the current document.
32
     *
33
     * @access protected
34
     *
35
     * @param int $number: The page to render
36
     * @param string $template: Parsed template subpart
37
     *
38
     * @return string The rendered entry ready for output
39
     */
40
    protected function getEntry($number, $template)
41
    {
42
        // Set current page if applicable.
43
        if (!empty($this->piVars['page']) && $this->piVars['page'] == $number) {
44
            $markerArray['###STATE###'] = 'cur';
45
        } else {
46
            $markerArray['###STATE###'] = 'no';
47
        }
48
        // Set page number.
49
        $markerArray['###NUMBER###'] = $number;
50
        // Set pagination.
51
        $markerArray['###PAGINATION###'] = htmlspecialchars($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$number]]['orderlabel']);
52
        // Get thumbnail or placeholder.
53
        if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$number]]['files'][$this->conf['fileGrpThumbs']])) {
54
            $thumbnailFile = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$number]]['files'][$this->conf['fileGrpThumbs']]);
55
        } elseif (!empty($this->conf['placeholder'])) {
56
            $thumbnailFile = $GLOBALS['TSFE']->tmpl->getFileName($this->conf['placeholder']);
57
        } else {
58
            $thumbnailFile = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Images/PageGridPlaceholder.jpg';
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Core\Utility\E...tUtility::siteRelPath() has been deprecated: use extPath() or GeneralUtility::getFileAbsFileName() together with PathUtility::getAbsoluteWebPath() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

58
            $thumbnailFile = /** @scrutinizer ignore-deprecated */ \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Images/PageGridPlaceholder.jpg';

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
59
        }
60
        $thumbnail = '<img alt="' . $markerArray['###PAGINATION###'] . '" src="' . $thumbnailFile . '" />';
61
        // Get new plugin variables for typolink.
62
        $piVars = $this->piVars;
63
        // Unset no longer needed plugin variables.
64
        // unset($piVars['pagegrid']) is for DFG Viewer compatibility!
65
        unset($piVars['pointer'], $piVars['DATA'], $piVars['pagegrid']);
66
        $piVars['page'] = $number;
67
        $linkConf = [
68
            'useCacheHash' => 1,
69
            'parameter' => $this->conf['targetPid'],
70
            'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0,
71
            'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'],
72
            'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $piVars, '', true, false),
73
            'title' => $markerArray['###PAGINATION###']
74
        ];
75
        $markerArray['###THUMBNAIL###'] = $this->cObj->typoLink($thumbnail, $linkConf);
76
        return $this->templateService->substituteMarkerArray($template, $markerArray);
77
    }
78
79
    /**
80
     * Renders the page browser
81
     *
82
     * @access protected
83
     *
84
     * @return string The rendered page browser ready for output
85
     */
86
    protected function getPageBrowser()
87
    {
88
        // Get overall number of pages.
89
        $maxPages = intval(ceil($this->doc->numPages / $this->conf['limit']));
90
        // Return empty pagebrowser if there is just one page.
91
        if ($maxPages < 2) {
92
            return '';
93
        }
94
        // Get separator.
95
        $separator = $this->pi_getLL('separator', ' - ', true);
96
        // Add link to previous page.
97
        if ($this->piVars['pointer'] > 0) {
98
            $output = $this->pi_linkTP_keepPIvars($this->pi_getLL('prevPage', '&lt;', true), ['pointer' => $this->piVars['pointer'] - 1, 'page' => (($this->piVars['pointer'] - 1) * $this->conf['limit']) + 1], true) . $separator;
99
        } else {
100
            $output = '<span class="prev-page not-active">' . $this->pi_getLL('prevPage', '&lt;', true) . '</span>' . $separator;
101
        }
102
        $i = 0;
103
        // Add links to pages.
104
        while ($i < $maxPages) {
105
            if ($i < 3 || ($i > $this->piVars['pointer'] - 3 && $i < $this->piVars['pointer'] + 3) || $i > $maxPages - 4) {
106
                if ($this->piVars['pointer'] != $i) {
107
                    $output .= $this->pi_linkTP_keepPIvars(sprintf($this->pi_getLL('page', '%d', true), $i + 1), ['pointer' => $i, 'page' => ($i * $this->conf['limit']) + 1], true) . $separator;
108
                } else {
109
                    $output .= '<span class="active">' . sprintf($this->pi_getLL('page', '%d', true), $i + 1) . '</span>' . $separator;
110
                }
111
                $skip = true;
112
            } elseif ($skip == true) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $skip does not seem to be defined for all execution paths leading up to this point.
Loading history...
113
                $output .= '<span class="skipped">' . $this->pi_getLL('skip', '...', true) . '</span>' . $separator;
114
                $skip = false;
115
            }
116
            $i++;
117
        }
118
        // Add link to next page.
119
        if ($this->piVars['pointer'] < $maxPages - 1) {
120
            $output .= $this->pi_linkTP_keepPIvars($this->pi_getLL('nextPage', '&gt;', true), ['pointer' => $this->piVars['pointer'] + 1, 'page' => ($this->piVars['pointer'] + 1) * $this->conf['limit'] + 1], true);
121
        } else {
122
            $output .= '<span class="next-page not-active">' . $this->pi_getLL('nextPage', '&gt;', true) . '</span>';
123
        }
124
        return $output;
125
    }
126
127
    /**
128
     * The main method of the PlugIn
129
     *
130
     * @access public
131
     *
132
     * @param string $content: The PlugIn content
133
     * @param array $conf: The PlugIn configuration
134
     *
135
     * @return string The content that is displayed on the website
136
     */
137
    public function main($content, $conf)
138
    {
139
        $this->init($conf);
140
        $this->loadDocument();
141
        if (
142
            $this->doc === null
143
            || $this->doc->numPages < 1
144
            || empty($this->conf['fileGrpThumbs'])
145
        ) {
146
            // Quit without doing anything if required variables are not set.
147
            return $content;
148
        } else {
149
            // Set default values for page if not set.
150
            $this->piVars['pointer'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['pointer'], 0, $this->doc->numPages, 0);
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...
151
        }
152
        // Load template file.
153
        $this->getTemplate();
154
        $entryTemplate = $this->templateService->getSubpart($this->template, '###ENTRY###');
155
        if (empty($entryTemplate)) {
156
            Helper::devLog('No template subpart for list entry found', DEVLOG_SEVERITY_WARNING);
157
            // Quit without doing anything if required variables are not set.
158
            return $content;
159
        }
160
        if (!empty($this->piVars['logicalPage'])) {
161
            $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
162
            // The logical page parameter should not appear
163
            unset($this->piVars['logicalPage']);
164
        }
165
        // Set some variable defaults.
166
        // $this->piVars['page'] may be integer or string (physical structure @ID)
167
        if (
168
            (int) $this->piVars['page'] > 0
169
            || empty($this->piVars['page'])
170
        ) {
171
            $this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
172
        } else {
173
            $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
174
        }
175
        if (!empty($this->piVars['page'])) {
176
            $this->piVars['pointer'] = intval(floor(($this->piVars['page'] - 1) / $this->conf['limit']));
177
        }
178
        if (
179
            !empty($this->piVars['pointer'])
180
            && (($this->piVars['pointer'] * $this->conf['limit']) + 1) <= $this->doc->numPages
181
        ) {
182
            $this->piVars['pointer'] = max(intval($this->piVars['pointer']), 0);
183
        } else {
184
            $this->piVars['pointer'] = 0;
185
        }
186
        // Iterate through visible page set and display thumbnails.
187
        for ($i = $this->piVars['pointer'] * $this->conf['limit'], $j = ($this->piVars['pointer'] + 1) * $this->conf['limit']; $i < $j; $i++) {
188
            // +1 because page counting starts at 1.
189
            $number = $i + 1;
190
            if ($number > $this->doc->numPages) {
191
                break;
192
            } else {
193
                $content .= $this->getEntry($number, $entryTemplate);
194
            }
195
        }
196
        // Render page browser.
197
        $markerArray['###PAGEBROWSER###'] = $this->getPageBrowser();
198
        // Merge everything with template.
199
        $content = $this->templateService->substituteMarkerArray($this->templateService->substituteSubpart($this->template, '###ENTRY###', $content, true), $markerArray);
200
        return $this->pi_wrapInBaseClass($content);
201
    }
202
}
203