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 ( 4d9a1f...4f5b1d )
by Alexander
19s queued 13s
created

SearchInDocumentTool::getEncryptedCoreName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
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
use TYPO3\CMS\Core\Utility\MathUtility;
18
19
/**
20
 * SearchInDocument tool for the plugin 'Toolbox' of the 'dlf' extension
21
 *
22
 * @author Sebastian Meyer <[email protected]>
23
 * @author Alexander Bigga <[email protected]>
24
 * @author Beatrycze Volk <[email protected]>
25
 * @package TYPO3
26
 * @subpackage dlf
27
 * @access public
28
 */
29
class SearchInDocumentTool extends \Kitodo\Dlf\Common\AbstractPlugin
30
{
31
    public $scriptRelPath = 'Classes/Plugin/Tools/SearchInDocumentTool.php';
32
33
    /**
34
     * The main method of the PlugIn
35
     *
36
     * @access public
37
     *
38
     * @param string $content: The PlugIn content
39
     * @param array $conf: The PlugIn configuration
40
     *
41
     * @return string The content that is displayed on the website
42
     */
43
    public function main($content, $conf)
44
    {
45
46
        $this->init($conf);
47
48
        // Merge configuration with conf array of toolbox.
49
        if (!empty($this->cObj->data['conf'])) {
50
            $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...
51
        }
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'] = 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
        $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->conf['fileGrpFulltext']);
83
        while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) {
84
            if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$fileGrpFulltext])) {
85
                $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$fileGrpFulltext];
86
                break;
87
            }
88
        }
89
        if (empty($fullTextFile)) {
90
            return $content;
91
        }
92
93
        // Load template file.
94
        $this->getTemplate();
95
96
        // Configure @action URL for form.
97
        $linkConf = [
98
            'parameter' => $GLOBALS['TSFE']->id,
99
            'forceAbsoluteUrl' => 1,
100
            'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http']
101
        ];
102
103
        $encryptedSolr = $this->getEncryptedCoreName();
104
        // Fill markers.
105
        $markerArray = [
106
            '###ACTION_URL###' => $this->cObj->typoLink_URL($linkConf),
107
            '###LABEL_QUERY###' => htmlspecialchars($this->pi_getLL('label.query')),
108
            '###LABEL_DELETE_SEARCH###' => htmlspecialchars($this->pi_getLL('label.delete_search')),
109
            '###LABEL_LOADING###' => htmlspecialchars($this->pi_getLL('label.loading')),
110
            '###LABEL_SUBMIT###' => htmlspecialchars($this->pi_getLL('label.submit')),
111
            '###LABEL_SEARCH_IN_DOCUMENT###' => htmlspecialchars($this->pi_getLL('label.searchInDocument')),
112
            '###LABEL_NEXT###' => htmlspecialchars($this->pi_getLL('label.next')),
113
            '###LABEL_PREVIOUS###' => htmlspecialchars($this->pi_getLL('label.previous')),
114
            '###LABEL_PAGE###' => htmlspecialchars($this->pi_getLL('label.logicalPage')),
115
            '###LABEL_NORESULT###' => htmlspecialchars($this->pi_getLL('label.noresult')),
116
            '###CURRENT_DOCUMENT###' => $this->doc->uid,
117
            '###SOLR_ENCRYPTED###' => $encryptedSolr ?: '',
118
        ];
119
120
        $content .= $this->templateService->substituteMarkerArray($this->template, $markerArray);
121
        return $this->pi_wrapInBaseClass($content);
122
    }
123
124
    /**
125
     * Get the encrypted Solr core name
126
     *
127
     * @access protected
128
     *
129
     * @return string with encrypted core name
130
     */
131
    protected function getEncryptedCoreName()
132
    {
133
        // Get core name.
134
        $name = Helper::getIndexNameFromUid($this->conf['solrcore'], 'tx_dlf_solrcores');
135
        // Encrypt core name.
136
        if (!empty($name)) {
137
            $name = Helper::encrypt($name);
138
        }
139
        return $name;
140
    }
141
}
142