Completed
Branch master (b9fc31)
by Timo
05:19
created

PluginBase::getTemplateFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.125

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 4
cp 0.5
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1.125
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Plugin;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2010-2015 Timo Schmidt <[email protected]>
8
 *  (c) 2012-2015 Ingo Renner <[email protected]>
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 2 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use ApacheSolrForTypo3\Solr\ConnectionManager;
29
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService;
30
use ApacheSolrForTypo3\Solr\JavascriptManager;
31
use ApacheSolrForTypo3\Solr\Query;
32
use ApacheSolrForTypo3\Solr\Query\LinkBuilder;
33
use ApacheSolrForTypo3\Solr\Search;
34
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager;
35
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
36
use ApacheSolrForTypo3\Solr\Template;
37
use ApacheSolrForTypo3\Solr\ViewHelper\ViewHelperProvider;
38
use TYPO3\CMS\Core\Localization\LocalizationFactory;
39
use TYPO3\CMS\Core\Utility\ArrayUtility;
40
use TYPO3\CMS\Core\Utility\GeneralUtility;
41
use TYPO3\CMS\Frontend\Plugin\AbstractPlugin;
42
43
/**
44
 * Abstract base class for all solr plugins.
45
 *
46
 * Implements a main method and several abstract methods which
47
 * need to be implemented by an inheriting plugin.
48
 *
49
 * @author Ingo Renner <[email protected]>
50
 * @author Timo Schmidt <[email protected]>
51
 */
52
abstract class PluginBase extends AbstractPlugin
53
{
54
    /**
55
     * @var string
56
     */
57
    public $prefixId = 'tx_solr';
58
59
    /**
60
     * @var string
61
     */
62
    public $extKey = 'solr';
63
64
    /**
65
     * An instance of ApacheSolrForTypo3\Solr\Template
66
     *
67
     * @var Template
68
     */
69
    protected $template;
70
71
    /**
72
     * An instance of ApacheSolrForTypo3\Solr\JavascriptManager
73
     *
74
     * @var JavascriptManager
75
     */
76
    protected $javascriptManager;
77
78
    /**
79
     * An instance of the localization factory
80
     *
81
     * @var \TYPO3\CMS\Core\Localization\LocalizationFactory
82
     */
83
    protected $languageFactory;
84
85
    /**
86
     * The user's raw query.
87
     *
88
     * Private to enforce API usage.
89
     *
90
     * @var string
91
     */
92
    private $rawUserQuery;
93
94
    // Main
95
96
    /**
97
     * @var TypoScriptConfiguration
98
     */
99
    public $typoScriptConfiguration;
100
101
    /**
102
     * @var SearchResultSetService
103
     */
104
    private $searchResultsSetService;
105
106
    /**
107
     * The main method of the plugin
108
     *
109
     * @param string $content The plugin content
110
     * @param array $configuration The plugin configuration
111
     * @return string The content that is displayed on the website
112
     */
113 25
    public function main($content, $configuration)
0 ignored issues
show
Unused Code introduced by
The parameter $content is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
114
    {
115
        /** @noinspection PhpUnusedLocalVariableInspection */
116 25
        $content = '';
117
118
        try {
119 25
            $this->initialize($configuration);
120 25
            $this->preRender();
121
122 25
            $actionResult = $this->performAction();
123
124 25
            if ($this->getSearchResultSetService()->getIsSolrAvailable()) {
125 25
                $content = $this->render($actionResult);
126 25
            } else {
127
                $content = $this->renderError();
128
            }
129
130 25
            $content = $this->postRender($content);
131 25
        } catch (\Exception $e) {
132
            if ($this->typoScriptConfiguration->getLoggingExceptions()) {
133
                GeneralUtility::devLog(
134
                    $e->getCode() . ': ' . $e->__toString(),
135
                    'solr',
136
                    3,
137
                    (array)$e
138
                );
139
            }
140
141
            $this->initializeTemplateEngine();
142
            $content = $this->renderException();
143
        }
144
145 25
        return $this->baseWrap($content);
146
    }
147
148
    /**
149
     * Adds the possibility to use stdWrap on the plugins content instead of wrapInBaseClass.
150
     * Defaults to wrapInBaseClass to ensure downward compatibility.
151
     *
152
     * @param string $content The plugin content
153
     * @return string
154
     */
155 25
    protected function baseWrap($content)
156
    {
157 25
        $baseWrap = $this->typoScriptConfiguration->getObjectByPath('plugin.tx_solr.general.baseWrap.');
158 25
        if (isset($baseWrap)) {
159 25
            return $this->cObj->stdWrap($content,
160 25
                $baseWrap);
161
        } else {
162
            return $this->pi_wrapInBaseClass($content);
163
        }
164
    }
165
166
    /**
167
     * Implements the action logic. The result of this method is passed to the
168
     * render method.
169
     *
170
     * @return string Action result
171
     */
172
    abstract protected function performAction();
173
174
    // Initialization
175
176
    /**
177
     * Initializes the plugin - configuration, language, caching, search...
178
     *
179
     * @param array $configuration configuration array as provided by the TYPO3 core
180
     */
181 25
    protected function initialize($configuration)
182
    {
183
        /** @var $configurationManager \ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager */
184 25
        $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
185 25
        $typoScriptConfiguration = $configurationManager->getTypoScriptConfiguration()->mergeSolrConfiguration($configuration);
186 25
        $this->typoScriptConfiguration = $typoScriptConfiguration;
187
188 25
        $this->initializeLanguageFactory();
189 25
        $this->pi_setPiVarDefaults();
190 25
        $this->pi_loadLL();
191 25
        $this->pi_initPIflexForm();
192
193 25
        $this->overrideTyposcriptWithFlexformSettings();
194
195 25
        $this->initializeQuery();
196 25
        $this->initializeSearch();
197 25
        $this->initializeTemplateEngine();
198 25
        $this->initializeJavascriptManager();
199
200 25
        $this->postInitialize();
201 25
    }
202
203
    /**
204
     * Overwrites pi_setPiVarDefaults to add stdWrap-functionality to _DEFAULT_PI_VARS
205
     *
206
     * @author Grigori Prokhorov <[email protected]>
207
     * @author Ivan Kartolo <[email protected]>
208
     * @return void
209
     */
210 25
    public function pi_setPiVarDefaults()
211
    {
212 25
        if (is_array($this->conf['_DEFAULT_PI_VARS.'])) {
213
            foreach ($this->conf['_DEFAULT_PI_VARS.'] as $key => $defaultValue) {
214
                $this->conf['_DEFAULT_PI_VARS.'][$key] = $this->cObj->cObjGetSingle($this->conf['_DEFAULT_PI_VARS.'][$key],
215
                    $this->conf['_DEFAULT_PI_VARS.'][$key . '.']);
216
            }
217
218
            $piVars = is_array($this->piVars) ? $this->piVars : [];
219
            $this->piVars = $this->conf['_DEFAULT_PI_VARS.'];
220
            ArrayUtility::mergeRecursiveWithOverrule(
221
                $this->piVars,
222
                $piVars
223
            );
224
        }
225 25
    }
226
227
    /**
228
     * Overwrites pi_loadLL() to handle custom location of language files.
229
     *
230
     * Loads local-language values by looking for a "locallang" file in the
231
     * plugin class directory ($this->scriptRelPath) and if found includes it.
232
     * Also locallang values set in the TypoScript property "_LOCAL_LANG" are
233
     * merged onto the values found in the "locallang" file.
234
     * Supported file extensions xlf, xml, php
235
     *
236
     * @param string $languageFilePath path to the plugin language file in format EXT:....
237
     * @return void
238
     */
239 25
    public function pi_loadLL($languageFilePath = '')
240
    {
241 25
        if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
242 25
            $basePath = 'EXT:' . $this->extKey . '/Resources/Private/Language/locallang.xlf';
243
            // Read the strings in the required charset (since TYPO3 4.2)
244 25
            $this->LOCAL_LANG = $this->languageFactory->getParsedData($basePath,
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->languageFactory->...FE']->renderCharset, 3) can also be of type boolean. However, the property $LOCAL_LANG is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
245 25
                $this->LLkey, $GLOBALS['TSFE']->renderCharset, 3);
246
247 25
            $alternativeLanguageKeys = GeneralUtility::trimExplode(',',
248 25
                $this->altLLkey, true);
249 25
            foreach ($alternativeLanguageKeys as $languageKey) {
250
                $tempLL = $this->languageFactory->getParsedData($basePath, $languageKey, $GLOBALS['TSFE']->renderCharset, 3);
251
                if ($this->LLkey !== 'default' && isset($tempLL[$languageKey])) {
252
                    $this->LOCAL_LANG[$languageKey] = $tempLL[$languageKey];
253
                }
254 25
            }
255
            // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
256 25
            $translationInTypoScript = $this->typoScriptConfiguration->getLocalLangConfiguration();
257
258 25
            if (count($translationInTypoScript) == 0) {
259 24
                return;
260
            }
261
262
            // Clear the "unset memory"
263 1
            $this->LOCAL_LANG_UNSET = [];
264 1
            foreach ($translationInTypoScript as $languageKey => $languageArray) {
265
                // Remove the dot after the language key
266 1
                $languageKey = substr($languageKey, 0, -1);
267
                // Don't process label if the language is not loaded
268 1
                if (is_array($languageArray) && isset($this->LOCAL_LANG[$languageKey])) {
269 1
                    foreach ($languageArray as $labelKey => $labelValue) {
270 1
                        if (!is_array($labelValue)) {
271 1
                            $this->LOCAL_LANG[$languageKey][$labelKey][0]['target'] = $labelValue;
272 1
                            $this->LOCAL_LANG_charset[$languageKey][$labelKey] = 'utf-8';
0 ignored issues
show
Bug introduced by
The property LOCAL_LANG_charset does not seem to exist. Did you mean LOCAL_LANG?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
273
274 1
                            if ($labelValue === '') {
275
                                $this->LOCAL_LANG_UNSET[$languageKey][$labelKey] = '';
276
                            }
277 1
                        }
278 1
                    }
279 1
                }
280 1
            }
281 1
        }
282 1
        $this->LOCAL_LANG_loaded = 1;
0 ignored issues
show
Documentation Bug introduced by
The property $LOCAL_LANG_loaded was declared of type boolean, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
283 1
    }
284
285
    /**
286
     * Allows to override TypoScript settings with Flexform values.
287
     *
288
     */
289 3
    protected function overrideTyposcriptWithFlexformSettings()
290
    {
291 3
    }
292
293
    /**
294
     * Initializes the query from the GET query parameter.
295
     *
296
     */
297 25
    protected function initializeQuery()
298
    {
299 25
        $this->rawUserQuery = GeneralUtility::_GET('q');
0 ignored issues
show
Documentation Bug introduced by
It seems like \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('q') can also be of type array. However, the property $rawUserQuery is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
300 25
    }
301
302
    /**
303
     * Initializes the Solr connection and tests the connection through a ping.
304
     *
305
     */
306 25
    protected function initializeSearch()
307
    {
308 25
        $solrConnection = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionByPageId(
309 25
            $GLOBALS['TSFE']->id,
310 25
            $GLOBALS['TSFE']->sys_language_uid,
311 25
            $GLOBALS['TSFE']->MP
312 25
        );
313
314 25
        $search = GeneralUtility::makeInstance(Search::class, $solrConnection);
315
        /** @var $this->searchService ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService */
316 25
        $this->searchResultsSetService = GeneralUtility::makeInstance(SearchResultSetService::class, $this->typoScriptConfiguration, $search, $this);
317 25
        $this->solrAvailable = $this->searchResultsSetService->getIsSolrAvailable();
0 ignored issues
show
Bug introduced by
The property solrAvailable does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
318 25
        $this->search = $this->searchResultsSetService->getSearch();
0 ignored issues
show
Bug introduced by
The property search does not seem to exist. Did you mean searchResultsSetService?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
319 25
    }
320
321
    /**
322
     * @return SearchResultSetService
323
     */
324 25
    public function getSearchResultSetService()
325
    {
326 25
        return $this->searchResultsSetService;
327
    }
328
329
    /**
330
     * Initializes the template engine and returns the initialized instance.
331
     *
332
     * @throws \UnexpectedValueException if a view helper provider fails to implement interface ApacheSolrForTypo3\Solr\ViewHelper\ViewHelperProvider
333
     */
334 25
    protected function initializeTemplateEngine()
335
    {
336 25
        $templateFile = $this->getTemplateFile();
337 25
        $subPart = $this->getSubpart();
338
339 25
        $flexformTemplateFile = $this->pi_getFFvalue(
340 25
            $this->cObj->data['pi_flexform'],
341 25
            'templateFile',
342
            'sOptions'
343 25
        );
344 25
        if (!empty($flexformTemplateFile)) {
345
            $templateFile = $flexformTemplateFile;
346
        }
347
348
        /** @var Template $template */
349 25
        $template = GeneralUtility::makeInstance(
350 25
            Template::class,
351 25
            $this->cObj,
352 25
            $templateFile,
353
            $subPart
354 25
        );
355 25
        $template->addViewHelperIncludePath($this->extKey,
356 25
            'Classes/ViewHelper/');
357 25
        $template->addViewHelper('LLL', [
358 25
            'languageFile' => 'EXT:solr/Resources/Private/Language/locallang.xlf',
359 25
            'llKey' => $this->LLkey
360 25
        ]);
361
362
        // can be used for view helpers that need configuration during initialization
363 25
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr'][$this->getPluginKey()]['addViewHelpers'])) {
364
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr'][$this->getPluginKey()]['addViewHelpers'] as $classReference) {
365
                $viewHelperProvider = &GeneralUtility::getUserObj($classReference);
366
367
                if ($viewHelperProvider instanceof ViewHelperProvider) {
368
                    $viewHelpers = $viewHelperProvider->getViewHelpers();
369
                    foreach ($viewHelpers as $helperName => $helperObject) {
370
                        // TODO check whether $helperAdded is TRUE, throw an exception if not
371
                        $helperAdded = $template->addViewHelperObject($helperName,
0 ignored issues
show
Unused Code introduced by
$helperAdded is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
372
                            $helperObject);
373
                    }
374
                } else {
375
                    throw new \UnexpectedValueException(
376
                        get_class($viewHelperProvider) . ' must implement interface ' . ViewHelperProvider::class,
377
                        1310387296
378
                    );
379
                }
380
            }
381
        }
382
383 25
        $template = $this->postInitializeTemplateEngine($template);
384
385 25
        $this->template = $template;
386 25
    }
387
388
    /**
389
     * Initializes the javascript manager.
390
     *
391
     */
392 25
    protected function initializeJavascriptManager()
393
    {
394 25
        $this->javascriptManager = GeneralUtility::makeInstance(JavascriptManager::class);
395 25
    }
396
397
    /**
398
     * Initializes the language factory;
399
     */
400 25
    protected function initializeLanguageFactory()
401
    {
402 25
        $this->languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
403 25
    }
404
405
    /**
406
     * This method is called after initializing in the initialize method.
407
     * Overwrite this method to do your own initialization.
408
     *
409
     * @return void
410
     */
411 3
    protected function postInitialize()
412
    {
413 3
    }
414
415
    /**
416
     * Overwrite this method to do own initialisations  of the template.
417
     *
418
     * @param Template $template Template
419
     * @return Template
420
     */
421
    protected function postInitializeTemplateEngine(Template $template)
422
    {
423
        return $template;
424
    }
425
426
    // Rendering
427
428
    /**
429
     * This method executes the requested commands and applies the changes to
430
     * the template.
431
     *
432
     * @param $actionResult
433
     * @return string Rendered plugin content
434
     */
435
    abstract protected function render($actionResult);
436
437
    /**
438
     * Renders a solr error.
439
     *
440
     * @return string A representation of the error that should be understandable for the user.
441
     */
442
    protected function renderError()
443
    {
444
        $this->template->workOnSubpart('solr_search_unavailable');
445
446
        return $this->template->render();
447
    }
448
449
    /**
450
     * Renders a solr exception.
451
     *
452
     * @return string A representation of the exception that should be understandable for the user.
453
     */
454
    protected function renderException()
455
    {
456
        $this->template->workOnSubpart('solr_search_error');
457
458
        return $this->template->render();
459
    }
460
461
    /**
462
     * Should be overwritten to do things before rendering.
463
     *
464
     */
465 2
    protected function preRender()
466
    {
467 2
    }
468
469
    /**
470
     * Overwrite this method to perform changes to the content after rendering.
471
     *
472
     * @param string $content The content rendered by the plugin so far
473
     * @return string The content that should be presented on the website, might be different from the output rendered before
474
     */
475 25
    protected function postRender($content)
476
    {
477 25
        if (isset($this->conf['stdWrap.'])) {
478
            $content = $this->cObj->stdWrap($content, $this->conf['stdWrap.']);
479
        }
480
481 25
        return $content;
482
    }
483
484
    // Helper methods
485
486
    /**
487
     * Determines the template file from the configuration.
488
     *
489
     * Overwrite this method to use a different template.
490
     *
491
     * @return string The template file name to be used for the plugin
492
     */
493 25
    protected function getTemplateFile()
494
    {
495 25
        return $this->typoScriptConfiguration->getTemplateByFileKey($this->getTemplateFileKey());
496
    }
497
498
    /**
499
     * This method should be implemented to return the TSconfig key which
500
     * contains the template name for this template.
501
     *
502
     * @see initializeTemplateEngine()
503
     * @return string The TSconfig key containing the template name
504
     */
505
    abstract protected function getTemplateFileKey();
506
507
    /**
508
     * Gets the plugin's template instance.
509
     *
510
     * @return Template The plugin's template.
511
     */
512 25
    public function getTemplate()
513
    {
514 25
        return $this->template;
515
    }
516
517
    /**
518
     * Gets the plugin's javascript manager.
519
     *
520
     * @return JavascriptManager The plugin's javascript manager.
521
     */
522 25
    public function getJavascriptManager()
523
    {
524 25
        return $this->javascriptManager;
525
    }
526
527
    /**
528
     * Should return the relevant subpart of the template.
529
     *
530
     * @see initializeTemplateEngine()
531
     * @return string The subpart of the template to be used
532
     */
533
    abstract protected function getSubpart();
534
535
    /**
536
     * This method should return the plugin key. Reads some configuration
537
     * options in initializeTemplateEngine()
538
     *
539
     * @see initializeTemplateEngine()
540
     * @return string The plugin key
541
     */
542
    abstract protected function getPluginKey();
543
544
    /**
545
     * Gets the target page Id for links. Might have been set through either
546
     * flexform or TypoScript. If none is set, TSFE->id is used.
547
     *
548
     * @return int The page Id to be used for links
549
     */
550 18
    public function getLinkTargetPageId()
551
    {
552 18
        return $this->typoScriptConfiguration->getSearchTargetPage();
553
    }
554
555
    /**
556
     * Gets the user's query term and cleans it so that it can be used in
557
     * templates f.e.
558
     *
559
     * @return string The cleaned user query.
560
     */
561 25
    public function getCleanUserQuery()
562
    {
563 25
        $userQuery = $this->getRawUserQuery();
564
565 25
        if (!is_null($userQuery)) {
566 21
            $userQuery = Query::cleanKeywords($userQuery);
567 21
        }
568
569
        // escape triple hashes as they are used in the template engine
570
        // TODO remove after switching to fluid templates
571 25
        $userQuery = Template::escapeMarkers($userQuery);
572
573 25
        return $userQuery;
574
    }
575
576
    /**
577
     * Gets the raw user query
578
     *
579
     * @return string Raw user query.
580
     */
581 25
    public function getRawUserQuery()
582
    {
583 25
        return $this->rawUserQuery;
584
    }
585
586
    /**
587
     * @return string
588
     */
589 25
    protected function getCurrentUrlWithQueryLinkBuilder()
590
    {
591 25
        $currentUrl = $this->pi_linkTP_keepPIvars_url();
592 25
        $resultService = $this->getSearchResultSetService();
593
594 25
        if (!$resultService instanceof SearchResultSetService) {
595
            return $currentUrl;
596
        }
597
598 25
        if ($resultService->getIsSolrAvailable() && $this->getSearchResultSetService()->getHasSearched()) {
599 4
            $queryLinkBuilder = GeneralUtility::makeInstance(LinkBuilder::class, $this->getSearchResultSetService()->getSearch()->getQuery());
600 4
            $currentUrl = $queryLinkBuilder->getQueryUrl();
601 4
            return $currentUrl;
602
        }
603 25
        return $currentUrl;
604
    }
605
}
606