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.
Passed
Pull Request — master (#496)
by Alexander
03:06
created

SearchInDocumentTool::getEncryptedCoreName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
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
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
18
/**
19
 * SearchInDocument tool for the plugin 'Toolbox' of the 'dlf' extension
20
 *
21
 * @author Sebastian Meyer <[email protected]>
22
 * @author Alexander Bigga <[email protected]>
23
 * @package TYPO3
24
 * @subpackage dlf
25
 * @access public
26
 */
27
class SearchInDocumentTool extends \Kitodo\Dlf\Common\AbstractPlugin
28
{
29
    public $scriptRelPath = 'Classes/Plugin/Tools/SearchInDocumentTool.php';
30
31
    /**
32
     * The main method of the PlugIn
33
     *
34
     * @access public
35
     *
36
     * @param string $content: The PlugIn content
37
     * @param array $conf: The PlugIn configuration
38
     *
39
     * @return string The content that is displayed on the website
40
     */
41
    public function main($content, $conf)
42
    {
43
44
        $this->init($conf);
45
46
        // Merge configuration with conf array of toolbox.
47
        if (!empty($this->cObj->data['conf'])) {
48
            $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...
49
        }
50
51
        $this->addSearchInDocumentJS();
52
53
        // Load current document.
54
        $this->loadDocument();
55
        if (
56
            $this->doc === null
57
            || $this->doc->numPages < 1
58
            || empty($this->conf['fileGrpFulltext'])
59
            || empty($this->conf['solrcore'])
60
        ) {
61
            // Quit without doing anything if required variables are not set.
62
            return $content;
63
        } else {
64
            if (!empty($this->piVars['logicalPage'])) {
65
                $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...
66
                // The logical page parameter should not appear again
67
                unset($this->piVars['logicalPage']);
68
            }
69
            // Set default values if not set.
70
            // $this->piVars['page'] may be integer or string (physical structure @ID)
71
            if (
72
                (int) $this->piVars['page'] > 0
73
                || empty($this->piVars['page'])
74
            ) {
75
                $this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
76
            } else {
77
                $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
78
            }
79
        }
80
81
        // Quit if no fulltext file is present
82
        $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpFulltext']];
83
        if (empty($fullTextFile)) {
84
            return $content;
85
        }
86
87
        // Load template file.
88
        $this->getTemplate();
89
90
        // Configure @action URL for form.
91
        $linkConf = [
92
            'parameter' => $GLOBALS['TSFE']->id,
93
            'forceAbsoluteUrl' => 1
94
        ];
95
96
        $encryptedSolr = $this->getEncryptedCoreName();
97
        // Fill markers.
98
        $markerArray = [
99
            '###ACTION_URL###' => $this->cObj->typoLink_URL($linkConf),
100
            '###LABEL_QUERY###' => $this->pi_getLL('label.query'),
101
            '###LABEL_DELETE_SEARCH###' => $this->pi_getLL('label.delete_search'),
102
            '###LABEL_LOADING###' => $this->pi_getLL('label.loading'),
103
            '###LABEL_SUBMIT###' => $this->pi_getLL('label.submit'),
104
            '###LABEL_SEARCH_IN_DOCUMENT###' => $this->pi_getLL('label.searchInDocument'),
105
            '###LABEL_NEXT###' => $this->pi_getLL('label.next'),
106
            '###LABEL_PREVIOUS###' => $this->pi_getLL('label.previous'),
107
            '###LABEL_PAGE###' => $this->pi_getLL('label.logicalPage'),
108
            '###CURRENT_DOCUMENT###' => $this->doc->uid,
109
            '###SOLR_ENCRYPTED###' => isset($encryptedSolr['encrypted']) ? $encryptedSolr['encrypted'] : '',
110
            '###SOLR_HASH###' => isset($encryptedSolr['hash']) ? $encryptedSolr['hash'] : '',
111
        ];
112
113
        $content .= $this->templateService->substituteMarkerArray($this->template, $markerArray);
114
        return $this->pi_wrapInBaseClass($content);
115
    }
116
117
    /**
118
     * Adds the JS files necessary for search in document
119
     *
120
     * @access protected
121
     *
122
     * @return void
123
     */
124
    protected function addSearchInDocumentJS()
125
    {
126
        $pageRenderer = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
127
        $pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/Search/SearchInDocument.js');
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

127
        $pageRenderer->addJsFooterFile(/** @scrutinizer ignore-deprecated */ \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/Search/SearchInDocument.js');

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...
128
    }
129
130
    /**
131
     * Get the encrypted Solr core name
132
     *
133
     * @access protected
134
     *
135
     * @return array with encrypted core name and hash
136
     */
137
    protected function getEncryptedCoreName()
138
    {
139
        // Get core name.
140
        $name = Helper::getIndexNameFromUid($this->conf['solrcore'], 'tx_dlf_solrcores');
141
        // Encrypt core name.
142
        if (!empty($name)) {
143
            $name = Helper::encrypt($name);
144
        }
145
        return $name;
146
    }
147
}
148