Completed
Branch master (33af51)
by Timo
04:12
created

PluginBase::initializeSearch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1.0046

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 10
cts 12
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
crap 1.0046
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\Domain\Search\ResultSet\SearchResultSetService;
29
use ApacheSolrForTypo3\Solr\JavascriptManager;
30
use ApacheSolrForTypo3\Solr\Query;
31
use ApacheSolrForTypo3\Solr\Search;
32
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
33
use ApacheSolrForTypo3\Solr\Template;
34
use ApacheSolrForTypo3\Solr\ViewHelper\ViewHelperProvider;
35
use TYPO3\CMS\Core\Utility\ArrayUtility;
36
use TYPO3\CMS\Core\Utility\GeneralUtility;
37
use TYPO3\CMS\Frontend\Plugin\AbstractPlugin;
38
39
/**
40
 * Abstract base class for all solr plugins.
41
 *
42
 * Implements a main method and several abstract methods which
43
 * need to be implemented by an inheriting plugin.
44
 *
45
 * @author Ingo Renner <[email protected]>
46
 * @author Timo Schmidt <[email protected]>
47
 */
48
abstract class PluginBase extends AbstractPlugin
49
{
50
    /**
51
     * @var string
52
     */
53
    public $prefixId = 'tx_solr';
54
55
    /**
56
     * @var string
57
     */
58
    public $extKey = 'solr';
59
60
    /**
61
     * The plugin's query
62
     *
63
     * @deprecated use $this->searchResultSet->getUsedQuery() instead, will be removed in version 5.0
64
     * @var Query
65
     */
66
    protected $query = null;
67
68
    /**
69
     * An instance of ApacheSolrForTypo3\Solr\Template
70
     *
71
     * @var Template
72
     */
73
    protected $template;
74
75
    /**
76
     * An instance of ApacheSolrForTypo3\Solr\JavascriptManager
77
     *
78
     * @var JavascriptManager
79
     */
80
    protected $javascriptManager;
81
82
    /**
83
     * An instance of the localization factory
84
     *
85
     * @var \TYPO3\CMS\Core\Localization\LocalizationFactory
86
     */
87
    protected $languageFactory;
88
89
    /**
90
     * The user's raw query.
91
     *
92
     * Private to enforce API usage.
93
     *
94
     * @var string
95
     */
96
    private $rawUserQuery;
97
98
    // Main
99
100
    /**
101
     * @var TypoScriptConfiguration
102
     */
103
    public $typoScriptConfiguration;
104
105
    /**
106
     * @var SearchResultSetService
107
     */
108
    private $searchResultsSetService;
109
110
    /**
111
     * The main method of the plugin
112
     *
113
     * @param string $content The plugin content
114
     * @param array $configuration The plugin configuration
115
     * @return string The content that is displayed on the website
116
     */
117 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...
118
    {
119
        /** @noinspection PhpUnusedLocalVariableInspection */
120 25
        $content = '';
121
122
        try {
123 25
            $this->initialize($configuration);
124 25
            $this->preRender();
125
126 25
            $actionResult = $this->performAction();
127
128 25
            if ($this->getSearchResultSetService()->getIsSolrAvailable()) {
129 25
                $content = $this->render($actionResult);
130
            } else {
131
                $content = $this->renderError();
132
            }
133
134 25
            $content = $this->postRender($content);
135
        } catch (\Exception $e) {
136
            if ($this->typoScriptConfiguration->getLoggingExceptions()) {
137
                GeneralUtility::devLog(
138
                    $e->getCode() . ': ' . $e->__toString(),
139
                    'solr',
140
                    3,
141
                    (array)$e
142
                );
143
            }
144
145
            $this->initializeTemplateEngine();
146
            $content = $this->renderException();
147
        }
148
149 25
        return $this->baseWrap($content);
150
    }
151
152
    /**
153
     * Adds the possibility to use stdWrap on the plugins content instead of wrapInBaseClass.
154
     * Defaults to wrapInBaseClass to ensure downward compatibility.
155
     *
156
     * @param string $content The plugin content
157
     * @return string
158
     */
159 25
    protected function baseWrap($content)
160
    {
161 25
        if (isset($this->conf['general.']['baseWrap.'])) {
162
            return $this->cObj->stdWrap($content,
163
                $this->conf['general.']['baseWrap.']);
164
        } else {
165 25
            return $this->pi_wrapInBaseClass($content);
166
        }
167
    }
168
169
    /**
170
     * Implements the action logic. The result of this method is passed to the
171
     * render method.
172
     *
173
     * @return string Action result
174
     */
175
    abstract protected function performAction();
176
177
    // Initialization
178
179
    /**
180
     * Initializes the plugin - configuration, language, caching, search...
181
     *
182
     * @param array $configuration configuration array as provided by the TYPO3 core
183
     */
184 25
    protected function initialize($configuration)
185
    {
186
        /** @var $configurationManager \ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager */
187 25
        $configurationManager = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\System\\Configuration\\ConfigurationManager');
188 25
        $typoScriptConfiguration = $configurationManager->getTypoScriptConfiguration()->mergeSolrConfiguration($configuration);
189 25
        $this->typoScriptConfiguration = $typoScriptConfiguration;
190
191 25
        $this->initializeLanguageFactory();
192 25
        $this->pi_setPiVarDefaults();
193 25
        $this->pi_loadLL();
194 25
        $this->pi_initPIflexForm();
195
196 25
        $this->overrideTyposcriptWithFlexformSettings();
197
198 25
        $this->initializeQuery();
199 25
        $this->initializeSearch();
200 25
        $this->initializeTemplateEngine();
201 25
        $this->initializeJavascriptManager();
202
203 25
        $this->postInitialize();
204 25
    }
205
206
    /**
207
     * Overwrites pi_setPiVarDefaults to add stdWrap-functionality to _DEFAULT_PI_VARS
208
     *
209
     * @author Grigori Prokhorov <[email protected]>
210
     * @author Ivan Kartolo <[email protected]>
211
     * @return void
212
     */
213 25
    public function pi_setPiVarDefaults()
214
    {
215 25
        if (is_array($this->conf['_DEFAULT_PI_VARS.'])) {
216
            foreach ($this->conf['_DEFAULT_PI_VARS.'] as $key => $defaultValue) {
217
                $this->conf['_DEFAULT_PI_VARS.'][$key] = $this->cObj->cObjGetSingle($this->conf['_DEFAULT_PI_VARS.'][$key],
218
                    $this->conf['_DEFAULT_PI_VARS.'][$key . '.']);
219
            }
220
221
            $piVars = is_array($this->piVars) ? $this->piVars : array();
222
            $this->piVars = $this->conf['_DEFAULT_PI_VARS.'];
223
            ArrayUtility::mergeRecursiveWithOverrule(
224
                $this->piVars,
225
                $piVars
226
            );
227
        }
228 25
    }
229
230
    /**
231
     * Overwrites pi_loadLL() to handle custom location of language files.
232
     *
233
     * Loads local-language values by looking for a "locallang" file in the
234
     * plugin class directory ($this->scriptRelPath) and if found includes it.
235
     * Also locallang values set in the TypoScript property "_LOCAL_LANG" are
236
     * merged onto the values found in the "locallang" file.
237
     * Supported file extensions xlf, xml, php
238
     *
239
     * @param string $languageFilePath path to the plugin language file in format EXT:....
240
     * @return void
241
     */
242 25
    public function pi_loadLL($languageFilePath = '')
243
    {
244 25
        if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
245 25
            $pathElements = pathinfo($this->scriptRelPath);
246 25
            $languageFileName = $pathElements['filename'];
0 ignored issues
show
Unused Code introduced by
$languageFileName 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...
247
248 25
            $basePath = 'EXT:' . $this->extKey . '/Resources/Private/Language/locallang.xlf';
249
            // Read the strings in the required charset (since TYPO3 4.2)
250 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...
251 25
                $this->LLkey, $GLOBALS['TSFE']->renderCharset, 3);
252
253 25
            $alternativeLanguageKeys = GeneralUtility::trimExplode(',',
254 25
                $this->altLLkey, true);
255 25
            foreach ($alternativeLanguageKeys as $languageKey) {
256
                $tempLL = $this->languageFactory->getParsedData($basePath, $languageKey, $GLOBALS['TSFE']->renderCharset, 3);
257
                if ($this->LLkey !== 'default' && isset($tempLL[$languageKey])) {
258
                    $this->LOCAL_LANG[$languageKey] = $tempLL[$languageKey];
259
                }
260
            }
261
            // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
262 25
            $translationInTypoScript = $this->typoScriptConfiguration->getLocalLangConfiguration();
263
264 25
            if (count($translationInTypoScript) == 0) {
265 24
                return;
266
            }
267
268
            // Clear the "unset memory"
269 1
            $this->LOCAL_LANG_UNSET = array();
270 1
            foreach ($translationInTypoScript as $languageKey => $languageArray) {
271
                // Remove the dot after the language key
272 1
                $languageKey = substr($languageKey, 0, -1);
273
                // Don't process label if the language is not loaded
274 1
                if (is_array($languageArray) && isset($this->LOCAL_LANG[$languageKey])) {
275 1
                    foreach ($languageArray as $labelKey => $labelValue) {
276 1
                        if (!is_array($labelValue)) {
277 1
                            $this->LOCAL_LANG[$languageKey][$labelKey][0]['target'] = $labelValue;
278 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...
279
280 1
                            if ($labelValue === '') {
281 1
                                $this->LOCAL_LANG_UNSET[$languageKey][$labelKey] = '';
282
                            }
283
                        }
284
                    }
285
                }
286
            }
287
        }
288 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...
289 1
    }
290
291
    /**
292
     * Allows to override TypoScript settings with Flexform values.
293
     *
294
     */
295 3
    protected function overrideTyposcriptWithFlexformSettings()
296
    {
297 3
    }
298
299
    /**
300
     * Initializes the query from the GET query parameter.
301
     *
302
     */
303 25
    protected function initializeQuery()
304
    {
305 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...
306 25
    }
307
308
    /**
309
     * Initializes the Solr connection and tests the connection through a ping.
310
     *
311
     */
312 25
    protected function initializeSearch()
313
    {
314 25
        $solrConnection = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\ConnectionManager')->getConnectionByPageId(
315 25
            $GLOBALS['TSFE']->id,
316 25
            $GLOBALS['TSFE']->sys_language_uid,
317 25
            $GLOBALS['TSFE']->MP
318
        );
319
320 25
        $search = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Search', $solrConnection);
321
        /** @var $this->searchService ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService */
322 25
        $this->searchResultsSetService = GeneralUtility::makeInstance('ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService', $this->typoScriptConfiguration, $search, $this);
323 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...
324 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...
325 25
    }
326
327
    /**
328
     * @return SearchResultSetService
329
     */
330 25
    public function getSearchResultSetService()
331
    {
332 25
        return $this->searchResultsSetService;
333
    }
334
335
    /**
336
     * Initializes the template engine and returns the initialized instance.
337
     *
338
     * @return Template
339
     * @throws \UnexpectedValueException if a view helper provider fails to implement interface ApacheSolrForTypo3\Solr\ViewHelper\ViewHelperProvider
340
     */
341 25
    protected function initializeTemplateEngine()
342
    {
343 25
        $templateFile = $this->getTemplateFile();
344 25
        $subPart = $this->getSubpart();
345
346 25
        $flexformTemplateFile = $this->pi_getFFvalue(
347 25
            $this->cObj->data['pi_flexform'],
348 25
            'templateFile',
349 25
            'sOptions'
350
        );
351 25
        if (!empty($flexformTemplateFile)) {
352
            $templateFile = $flexformTemplateFile;
353
        }
354
355
        /** @var Template $template */
356 25
        $template = GeneralUtility::makeInstance(
357 25
            'ApacheSolrForTypo3\\Solr\\Template',
358 25
            $this->cObj,
359
            $templateFile,
360
            $subPart
361
        );
362 25
        $template->addViewHelperIncludePath($this->extKey,
363 25
            'Classes/ViewHelper/');
364 25
        $template->addViewHelper('LLL', array(
365 25
            'languageFile' => 'EXT:solr/Resources/Private/Language/locallang.xlf',
366 25
            'llKey' => $this->LLkey
367
        ));
368
369
        // can be used for view helpers that need configuration during initialization
370 25
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr'][$this->getPluginKey()]['addViewHelpers'])) {
371
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr'][$this->getPluginKey()]['addViewHelpers'] as $classReference) {
372
                $viewHelperProvider = &GeneralUtility::getUserObj($classReference);
373
374
                if ($viewHelperProvider instanceof ViewHelperProvider) {
375
                    $viewHelpers = $viewHelperProvider->getViewHelpers();
376
                    foreach ($viewHelpers as $helperName => $helperObject) {
377
                        // TODO check whether $helperAdded is TRUE, throw an exception if not
378
                        $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...
379
                            $helperObject);
380
                    }
381
                } else {
382
                    throw new \UnexpectedValueException(
383
                        get_class($viewHelperProvider) . ' must implement interface ApacheSolrForTypo3\Solr\ViewHelper\ViewHelperProvider',
384
                        1310387296
385
                    );
386
                }
387
            }
388
        }
389
390 25
        $template = $this->postInitializeTemplateEngine($template);
391
392 25
        $this->template = $template;
393 25
    }
394
395
    /**
396
     * Initializes the javascript manager.
397
     *
398
     */
399 25
    protected function initializeJavascriptManager()
400
    {
401 25
        $this->javascriptManager = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\JavascriptManager');
402 25
    }
403
404
    /**
405
     * Initializes the language factory;
406
     */
407 25
    protected function initializeLanguageFactory()
408
    {
409 25
        $this->languageFactory = GeneralUtility::makeInstance('TYPO3\CMS\Core\Localization\LocalizationFactory');
410 25
    }
411
412
    /**
413
     * This method is called after initializing in the initialize method.
414
     * Overwrite this method to do your own initialization.
415
     *
416
     * @return void
417
     */
418 3
    protected function postInitialize()
419
    {
420 3
    }
421
422
    /**
423
     * Overwrite this method to do own initialisations  of the template.
424
     *
425
     * @param Template $template Template
426
     * @return Template
427
     */
428
    protected function postInitializeTemplateEngine(Template $template)
429
    {
430
        return $template;
431
    }
432
433
    // Rendering
434
435
    /**
436
     * This method executes the requested commands and applies the changes to
437
     * the template.
438
     *
439
     * @param $actionResult
440
     * @return string Rendered plugin content
441
     */
442
    abstract protected function render($actionResult);
443
444
    /**
445
     * Renders a solr error.
446
     *
447
     * @return string A representation of the error that should be understandable for the user.
448
     */
449
    protected function renderError()
450
    {
451
        $this->template->workOnSubpart('solr_search_unavailable');
452
453
        return $this->template->render();
454
    }
455
456
    /**
457
     * Renders a solr exception.
458
     *
459
     * @return string A representation of the exception that should be understandable for the user.
460
     */
461
    protected function renderException()
462
    {
463
        $this->template->workOnSubpart('solr_search_error');
464
465
        return $this->template->render();
466
    }
467
468
    /**
469
     * Should be overwritten to do things before rendering.
470
     *
471
     */
472 2
    protected function preRender()
473
    {
474 2
    }
475
476
    /**
477
     * Overwrite this method to perform changes to the content after rendering.
478
     *
479
     * @param string $content The content rendered by the plugin so far
480
     * @return string The content that should be presented on the website, might be different from the output rendered before
481
     */
482 25
    protected function postRender($content)
483
    {
484 25
        if (isset($this->conf['stdWrap.'])) {
485
            $content = $this->cObj->stdWrap($content, $this->conf['stdWrap.']);
486
        }
487
488 25
        return $content;
489
    }
490
491
    // Helper methods
492
493
    /**
494
     * Determines the template file from the configuration.
495
     *
496
     * Overwrite this method to use a different template.
497
     *
498
     * @return string The template file name to be used for the plugin
499
     */
500 25
    protected function getTemplateFile()
501
    {
502 25
        return $this->typoScriptConfiguration->getTemplateByFileKey($this->getTemplateFileKey());
503
    }
504
505
    /**
506
     * This method should be implemented to return the TSconfig key which
507
     * contains the template name for this template.
508
     *
509
     * @see initializeTemplateEngine()
510
     * @return string The TSconfig key containing the template name
511
     */
512
    abstract protected function getTemplateFileKey();
513
514
    /**
515
     * Gets the plugin's template instance.
516
     *
517
     * @return Template The plugin's template.
518
     */
519 25
    public function getTemplate()
520
    {
521 25
        return $this->template;
522
    }
523
524
    /**
525
     * Gets the plugin's javascript manager.
526
     *
527
     * @return JavascriptManager The plugin's javascript manager.
528
     */
529 25
    public function getJavascriptManager()
530
    {
531 25
        return $this->javascriptManager;
532
    }
533
534
    /**
535
     * Should return the relevant subpart of the template.
536
     *
537
     * @see initializeTemplateEngine()
538
     * @return string The subpart of the template to be used
539
     */
540
    abstract protected function getSubpart();
541
542
    /**
543
     * This method should return the plugin key. Reads some configuration
544
     * options in initializeTemplateEngine()
545
     *
546
     * @see initializeTemplateEngine()
547
     * @return string The plugin key
548
     */
549
    abstract protected function getPluginKey();
550
551
    /**
552
     * Gets the target page Id for links. Might have been set through either
553
     * flexform or TypoScript. If none is set, TSFE->id is used.
554
     *
555
     * @return int The page Id to be used for links
556
     */
557 18
    public function getLinkTargetPageId()
558
    {
559 18
        return $this->typoScriptConfiguration->getSearchTargetPage();
560
    }
561
562
    /**
563
     * Gets the user's query term and cleans it so that it can be used in
564
     * templates f.e.
565
     *
566
     * @return string The cleaned user query.
567
     */
568 25
    public function getCleanUserQuery()
569
    {
570 25
        $userQuery = $this->getRawUserQuery();
571
572 25
        if (!is_null($userQuery)) {
573 21
            $userQuery = Query::cleanKeywords($userQuery);
574
        }
575
576
        // escape triple hashes as they are used in the template engine
577
        // TODO remove after switching to fluid templates
578 25
        $userQuery = Template::escapeMarkers($userQuery);
579
580 25
        return $userQuery;
581
    }
582
583
    /**
584
     * Gets the raw user query
585
     *
586
     * @return string Raw user query.
587
     */
588 25
    public function getRawUserQuery()
589
    {
590 25
        return $this->rawUserQuery;
591
    }
592
593
    /**
594
     * @return string
595
     */
596 25
    protected function getCurrentUrlWithQueryLinkBuilder()
597
    {
598 25
        $currentUrl = $this->pi_linkTP_keepPIvars_url();
599 25
        $resultService = $this->getSearchResultSetService();
600
601 25
        if (!$resultService instanceof SearchResultSetService) {
602
            return $currentUrl;
603
        }
604
605 25
        if ($resultService->getIsSolrAvailable() && $this->getSearchResultSetService()->getHasSearched()) {
606 4
            $queryLinkBuilder = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query\\LinkBuilder', $this->getSearchResultSetService()->getSearch()->getQuery());
607 4
            $currentUrl = $queryLinkBuilder->getQueryUrl();
608 4
            return $currentUrl;
609
        }
610 25
        return $currentUrl;
611
    }
612
}
613