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 ( 631104...a34b62 )
by Sebastian
02:00 queued 01:57
created

AbstractPlugin::pi_linkTP_fallback()   B

Complexity

Conditions 8
Paths 128

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 11
rs 8.2111
cc 8
nc 128
nop 4
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\Common;
14
15
use TYPO3\CMS\Core\Database\ConnectionPool;
16
use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
18
use TYPO3\CMS\Core\Utility\HttpUtility;
19
20
/**
21
 * Abstract plugin class for the 'dlf' extension
22
 *
23
 * @author Sebastian Meyer <[email protected]>
24
 * @package TYPO3
25
 * @subpackage dlf
26
 * @access public
27
 * @abstract
28
 */
29
abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Frontend\Plugin\AbstractPlugin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
{
31
    public $extKey = 'dlf';
32
    public $prefixId = 'tx_dlf';
33
    public $scriptRelPath = 'Classes/Common/AbstractPlugin.php';
34
    // Plugins are cached by default (@see setCache()).
35
    public $pi_USER_INT_obj = false;
36
    public $pi_checkCHash = true;
37
38
    /**
39
     * This holds the current document
40
     *
41
     * @var \Kitodo\Dlf\Common\Document
42
     * @access protected
43
     */
44
    protected $doc;
45
46
    /**
47
     * This holds the plugin's parsed template
48
     *
49
     * @var string
50
     * @access protected
51
     */
52
    protected $template = '';
53
54
    /**
55
     * This holds the plugin's service for template
56
     *
57
     * @var \TYPO3\CMS\Core\Service\MarkerBasedTemplateService
58
     * @access protected
59
     */
60
    protected $templateService;
61
62
    /**
63
     * Read and parse the template file
64
     *
65
     * @access protected
66
     *
67
     * @param string $part: Name of the subpart to load
68
     *
69
     * @return void
70
     */
71
    protected function getTemplate($part = '###TEMPLATE###')
72
    {
73
        $this->templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
74
        if (!empty($this->conf['templateFile'])) {
75
            // Load template file from configuration.
76
            $templateFile = $this->conf['templateFile'];
77
        } else {
78
            // Load default template from extension.
79
            $templateFile = 'EXT:' . $this->extKey . '/Resources/Private/Templates/' . Helper::getUnqualifiedClassName(get_class($this)) . '.tmpl';
80
        }
81
        // Substitute strings like "EXT:" in given template file location.
82
        $fileResource = $GLOBALS['TSFE']->tmpl->getFileName($templateFile);
83
        $this->template = $this->templateService->getSubpart(file_get_contents($fileResource), $part);
84
    }
85
86
    /**
87
     * All the needed configuration values are stored in class variables
88
     * Priority: Flexforms > TS-Templates > Extension Configuration > ext_localconf.php
89
     *
90
     * @access protected
91
     *
92
     * @param array $conf: Configuration array from TS-Template
93
     *
94
     * @return void
95
     */
96
    protected function init(array $conf)
97
    {
98
        // Read FlexForm configuration.
99
        $flexFormConf = [];
100
        $this->cObj->readFlexformIntoConf($this->cObj->data['pi_flexform'], $flexFormConf);
101
        if (!empty($flexFormConf)) {
102
            $conf = Helper::mergeRecursiveWithOverrule($flexFormConf, $conf);
103
        }
104
        // Read plugin TS configuration.
105
        $pluginConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_dlf_' . strtolower(Helper::getUnqualifiedClassName(get_class($this))) . '.'];
106
        if (is_array($pluginConf)) {
107
            $conf = Helper::mergeRecursiveWithOverrule($pluginConf, $conf);
108
        }
109
        // Read general TS configuration.
110
        $generalConf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$this->prefixId . '.'];
111
        if (is_array($generalConf)) {
112
            $conf = Helper::mergeRecursiveWithOverrule($generalConf, $conf);
113
        }
114
        // Read extension configuration.
115
        $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$this->extKey]);
116
        if (is_array($extConf)) {
117
            $conf = Helper::mergeRecursiveWithOverrule($extConf, $conf);
118
        }
119
        // Read TYPO3_CONF_VARS configuration.
120
        $varsConf = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey];
121
        if (is_array($varsConf)) {
122
            $conf = Helper::mergeRecursiveWithOverrule($varsConf, $conf);
123
        }
124
        $this->conf = $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...
125
        // Set default plugin variables.
126
        $this->pi_setPiVarDefaults();
127
        // Load translation files.
128
        $this->pi_loadLL('EXT:' . $this->extKey . '/Resources/Private/Language/' . Helper::getUnqualifiedClassName(get_class($this)) . '.xml');
129
    }
130
131
    /**
132
     * Loads the current document into $this->doc
133
     *
134
     * @access protected
135
     *
136
     * @return void
137
     */
138
    protected function loadDocument()
139
    {
140
        // Check for required variable.
141
        if (
142
            !empty($this->piVars['id'])
143
            && !empty($this->conf['pages'])
144
        ) {
145
            // Should we exclude documents from other pages than $this->conf['pages']?
146
            $pid = (!empty($this->conf['excludeOther']) ? intval($this->conf['pages']) : 0);
147
            // Get instance of \Kitodo\Dlf\Common\Document.
148
            $this->doc = Document::getInstance($this->piVars['id'], $pid);
149
            if (!$this->doc->ready) {
150
                // Destroy the incomplete object.
151
                $this->doc = null;
152
                Helper::devLog('Failed to load document with UID ' . $this->piVars['id'], DEVLOG_SEVERITY_ERROR);
153
            } else {
154
                // Set configuration PID.
155
                $this->doc->cPid = $this->conf['pages'];
156
            }
157
        } elseif (!empty($this->piVars['recordId'])) {
158
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
159
                ->getQueryBuilderForTable('tx_dlf_documents');
160
161
            // Get UID of document with given record identifier.
162
            $result = $queryBuilder
163
                ->select('tx_dlf_documents.uid AS uid')
164
                ->from('tx_dlf_documents')
165
                ->where(
166
                    $queryBuilder->expr()->eq('tx_dlf_documents.record_id', $queryBuilder->expr()->literal($this->piVars['recordId'])),
167
                    Helper::whereExpression('tx_dlf_documents')
168
                )
169
                ->setMaxResults(1)
170
                ->execute();
171
172
            if ($resArray = $result->fetch()) {
173
                $this->piVars['id'] = $resArray['uid'];
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...
174
                // Set superglobal $_GET array and unset variables to avoid infinite looping.
175
                $_GET[$this->prefixId]['id'] = $this->piVars['id'];
176
                unset($this->piVars['recordId'], $_GET[$this->prefixId]['recordId']);
177
                // Try to load document.
178
                $this->loadDocument();
179
            } else {
180
                Helper::devLog('Failed to load document with record ID "' . $this->piVars['recordId'] . '"', DEVLOG_SEVERITY_ERROR);
181
            }
182
        } else {
183
            Helper::devLog('Invalid UID ' . $this->piVars['id'] . ' or PID ' . $this->conf['pages'] . ' for document loading', DEVLOG_SEVERITY_ERROR);
184
        }
185
    }
186
187
    /**
188
     * The main method of the PlugIn
189
     *
190
     * @access public
191
     *
192
     * @param string $content: The PlugIn content
193
     * @param array $conf: The PlugIn configuration
194
     *
195
     * @abstract
196
     *
197
     * @return string The content that is displayed on the website
198
     */
199
    abstract public function main($content, $conf);
200
201
    /**
202
     * Parses a string into a Typoscript array
203
     *
204
     * @access protected
205
     *
206
     * @param string $string: The string to parse
207
     *
208
     * @return array The resulting typoscript array
209
     */
210
    protected function parseTS($string = '')
211
    {
212
        $parser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
213
        $parser->parse($string);
214
        return $parser->setup;
215
    }
216
217
    /**
218
     * Link string to the current page.
219
     * @see \TYPO3\CMS\Frontend\Plugin\AbstractPlugin->pi_linkTP()
220
     *
221
     * @access public
222
     *
223
     * @param string $str: The content string to wrap in <a> tags
224
     * @param array $urlParameters: Array with URL parameters as key/value pairs
225
     * @param bool $cache: Should the "no_cache" parameter be added?
226
     * @param int $altPageId: Alternative page ID for the link.
227
     *
228
     * @return string The input string wrapped in <a> tags
229
     */
230
    public function pi_linkTP($str, $urlParameters = [], $cache = false, $altPageId = 0)
231
    {
232
        // Remove when we don't need to support TYPO3 8.7 anymore.
233
        if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getNumericTypo3Version(), '9.0.0', '<')) {
234
            return $this->pi_linkTP_fallback($str, $urlParameters, $cache, $altPageId);
0 ignored issues
show
Deprecated Code introduced by
The function Kitodo\Dlf\Common\Abstra...n::pi_linkTP_fallback() has been deprecated. ( Ignorable by Annotation )

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

234
            return /** @scrutinizer ignore-deprecated */ $this->pi_linkTP_fallback($str, $urlParameters, $cache, $altPageId);
Loading history...
235
        }
236
        // -->
237
        $conf = [];
238
        if (!$cache) {
239
            $conf['no_cache'] = true;
240
        }
241
        $conf['parameter'] = $altPageId ?: ($this->pi_tmpPageId ?: 'current');
242
        $conf['additionalParams'] = $this->conf['parent.']['addParams'] . HttpUtility::buildQueryString($urlParameters, '&', true) . $this->pi_moreParams;
243
        // Add additional configuration for absolute URLs.
244
        $conf['forceAbsoluteUrl'] = !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0;
245
        $conf['forceAbsoluteUrl.']['scheme'] = !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http';
246
        return $this->cObj->typoLink($str, $conf);
247
    }
248
249
    /**
250
     * Link string to the current page (fallback for TYPO3 8.7)
251
     * @see $this->pi_linkTP()
252
     *
253
     * @deprecated
254
     *
255
     * @access public
256
     *
257
     * @param string $str: The content string to wrap in <a> tags
258
     * @param array $urlParameters: Array with URL parameters as key/value pairs
259
     * @param bool $cache: Should the "no_cache" parameter be added?
260
     * @param int $altPageId: Alternative page ID for the link.
261
     *
262
     * @return string The input string wrapped in <a> tags
263
     */
264
    public function pi_linkTP_fallback($str, $urlParameters = [], $cache = false, $altPageId = 0)
265
    {
266
        $conf = [];
267
        $conf['useCacheHash'] = $this->pi_USER_INT_obj ? 0 : $cache;
268
        $conf['no_cache'] = $this->pi_USER_INT_obj ? 0 : !$cache;
269
        $conf['parameter'] = $altPageId ? $altPageId : ($this->pi_tmpPageId ? $this->pi_tmpPageId : $this->frontendController->id);
270
        $conf['additionalParams'] = $this->conf['parent.']['addParams'] . GeneralUtility::implodeArrayForUrl('', $urlParameters, '', true) . $this->pi_moreParams;
271
        // Add additional configuration for absolute URLs.
272
        $conf['forceAbsoluteUrl'] = !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0;
273
        $conf['forceAbsoluteUrl.']['scheme'] = !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http';
274
        return $this->cObj->typoLink($str, $conf);
275
    }
276
277
    /**
278
     * Wraps the input string in a <div> tag with the class attribute set to the class name
279
     * @see \TYPO3\CMS\Frontend\Plugin\AbstractPlugin->pi_wrapInBaseClass()
280
     *
281
     * @access public
282
     *
283
     * @param string $content: HTML content to wrap in the div-tags with the class of the plugin
284
     *
285
     * @return string HTML content wrapped, ready to return to the parent object.
286
     */
287
    public function pi_wrapInBaseClass($content)
288
    {
289
        if (!$this->frontendController->config['config']['disableWrapInBaseClass']) {
290
            // Use class name instead of $this->prefixId for content wrapping because $this->prefixId is the same for all plugins.
291
            $content = '<div class="tx-dlf-' . strtolower(Helper::getUnqualifiedClassName(get_class($this))) . '">' . $content . '</div>';
292
            if (!$this->frontendController->config['config']['disablePrefixComment']) {
293
                $content = "\n\n<!-- BEGIN: Content of extension '" . $this->extKey . "', plugin '" . Helper::getUnqualifiedClassName(get_class($this)) . "' -->\n\n" . $content . "\n\n<!-- END: Content of extension '" . $this->extKey . "', plugin '" . Helper::getUnqualifiedClassName(get_class($this)) . "' -->\n\n";
294
            }
295
        }
296
        return $content;
297
    }
298
299
    /**
300
     * Sets some configuration variables if the plugin is cached.
301
     *
302
     * @access protected
303
     *
304
     * @param bool $cache: Should the plugin be cached?
305
     *
306
     * @return void
307
     */
308
    protected function setCache($cache = true)
309
    {
310
        if ($cache) {
311
            // Set cObject type to "USER" (default).
312
            $this->pi_USER_INT_obj = false;
313
            $this->pi_checkCHash = true;
314
            if (count($this->piVars)) {
315
                // Check cHash or disable caching.
316
                $GLOBALS['TSFE']->reqCHash();
317
            }
318
        } else {
319
            // Set cObject type to "USER_INT".
320
            $this->pi_USER_INT_obj = true;
321
            $this->pi_checkCHash = false;
322
            // Plugins are of type "USER" by default, so convert it to "USER_INT".
323
            $this->cObj->convertToUserIntObject();
324
        }
325
    }
326
}
327