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) |
|
|
|
|
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 |
|
$baseWrap = $this->typoScriptConfiguration->getObjectByPath('plugin.tx_solr.general.baseWrap.'); |
162
|
25 |
|
if (isset($baseWrap)) { |
163
|
25 |
|
return $this->cObj->stdWrap($content, |
164
|
|
|
$baseWrap); |
165
|
|
|
} else { |
166
|
|
|
return $this->pi_wrapInBaseClass($content); |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Implements the action logic. The result of this method is passed to the |
172
|
|
|
* render method. |
173
|
|
|
* |
174
|
|
|
* @return string Action result |
175
|
|
|
*/ |
176
|
|
|
abstract protected function performAction(); |
177
|
|
|
|
178
|
|
|
// Initialization |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Initializes the plugin - configuration, language, caching, search... |
182
|
|
|
* |
183
|
|
|
* @param array $configuration configuration array as provided by the TYPO3 core |
184
|
|
|
*/ |
185
|
25 |
|
protected function initialize($configuration) |
186
|
|
|
{ |
187
|
|
|
/** @var $configurationManager \ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager */ |
188
|
25 |
|
$configurationManager = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\System\\Configuration\\ConfigurationManager'); |
189
|
25 |
|
$typoScriptConfiguration = $configurationManager->getTypoScriptConfiguration()->mergeSolrConfiguration($configuration); |
190
|
25 |
|
$this->typoScriptConfiguration = $typoScriptConfiguration; |
191
|
|
|
|
192
|
25 |
|
$this->initializeLanguageFactory(); |
193
|
25 |
|
$this->pi_setPiVarDefaults(); |
194
|
25 |
|
$this->pi_loadLL(); |
195
|
25 |
|
$this->pi_initPIflexForm(); |
196
|
|
|
|
197
|
25 |
|
$this->overrideTyposcriptWithFlexformSettings(); |
198
|
|
|
|
199
|
25 |
|
$this->initializeQuery(); |
200
|
25 |
|
$this->initializeSearch(); |
201
|
25 |
|
$this->initializeTemplateEngine(); |
202
|
25 |
|
$this->initializeJavascriptManager(); |
203
|
|
|
|
204
|
25 |
|
$this->postInitialize(); |
205
|
25 |
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Overwrites pi_setPiVarDefaults to add stdWrap-functionality to _DEFAULT_PI_VARS |
209
|
|
|
* |
210
|
|
|
* @author Grigori Prokhorov <[email protected]> |
211
|
|
|
* @author Ivan Kartolo <[email protected]> |
212
|
|
|
* @return void |
213
|
|
|
*/ |
214
|
25 |
|
public function pi_setPiVarDefaults() |
215
|
|
|
{ |
216
|
25 |
|
if (is_array($this->conf['_DEFAULT_PI_VARS.'])) { |
217
|
|
|
foreach ($this->conf['_DEFAULT_PI_VARS.'] as $key => $defaultValue) { |
218
|
|
|
$this->conf['_DEFAULT_PI_VARS.'][$key] = $this->cObj->cObjGetSingle($this->conf['_DEFAULT_PI_VARS.'][$key], |
219
|
|
|
$this->conf['_DEFAULT_PI_VARS.'][$key . '.']); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
$piVars = is_array($this->piVars) ? $this->piVars : array(); |
223
|
|
|
$this->piVars = $this->conf['_DEFAULT_PI_VARS.']; |
224
|
|
|
ArrayUtility::mergeRecursiveWithOverrule( |
225
|
|
|
$this->piVars, |
226
|
|
|
$piVars |
227
|
|
|
); |
228
|
|
|
} |
229
|
25 |
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Overwrites pi_loadLL() to handle custom location of language files. |
233
|
|
|
* |
234
|
|
|
* Loads local-language values by looking for a "locallang" file in the |
235
|
|
|
* plugin class directory ($this->scriptRelPath) and if found includes it. |
236
|
|
|
* Also locallang values set in the TypoScript property "_LOCAL_LANG" are |
237
|
|
|
* merged onto the values found in the "locallang" file. |
238
|
|
|
* Supported file extensions xlf, xml, php |
239
|
|
|
* |
240
|
|
|
* @param string $languageFilePath path to the plugin language file in format EXT:.... |
241
|
|
|
* @return void |
242
|
|
|
*/ |
243
|
25 |
|
public function pi_loadLL($languageFilePath = '') |
244
|
|
|
{ |
245
|
25 |
|
if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) { |
246
|
25 |
|
$pathElements = pathinfo($this->scriptRelPath); |
247
|
25 |
|
$languageFileName = $pathElements['filename']; |
|
|
|
|
248
|
|
|
|
249
|
25 |
|
$basePath = 'EXT:' . $this->extKey . '/Resources/Private/Language/locallang.xlf'; |
250
|
|
|
// Read the strings in the required charset (since TYPO3 4.2) |
251
|
25 |
|
$this->LOCAL_LANG = $this->languageFactory->getParsedData($basePath, |
|
|
|
|
252
|
25 |
|
$this->LLkey, $GLOBALS['TSFE']->renderCharset, 3); |
253
|
|
|
|
254
|
25 |
|
$alternativeLanguageKeys = GeneralUtility::trimExplode(',', |
255
|
25 |
|
$this->altLLkey, true); |
256
|
25 |
|
foreach ($alternativeLanguageKeys as $languageKey) { |
257
|
|
|
$tempLL = $this->languageFactory->getParsedData($basePath, $languageKey, $GLOBALS['TSFE']->renderCharset, 3); |
258
|
|
|
if ($this->LLkey !== 'default' && isset($tempLL[$languageKey])) { |
259
|
|
|
$this->LOCAL_LANG[$languageKey] = $tempLL[$languageKey]; |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
// Overlaying labels from TypoScript (including fictitious language keys for non-system languages!): |
263
|
25 |
|
$translationInTypoScript = $this->typoScriptConfiguration->getLocalLangConfiguration(); |
264
|
|
|
|
265
|
25 |
|
if (count($translationInTypoScript) == 0) { |
266
|
24 |
|
return; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
// Clear the "unset memory" |
270
|
1 |
|
$this->LOCAL_LANG_UNSET = array(); |
271
|
1 |
|
foreach ($translationInTypoScript as $languageKey => $languageArray) { |
272
|
|
|
// Remove the dot after the language key |
273
|
1 |
|
$languageKey = substr($languageKey, 0, -1); |
274
|
|
|
// Don't process label if the language is not loaded |
275
|
1 |
|
if (is_array($languageArray) && isset($this->LOCAL_LANG[$languageKey])) { |
276
|
1 |
|
foreach ($languageArray as $labelKey => $labelValue) { |
277
|
1 |
|
if (!is_array($labelValue)) { |
278
|
1 |
|
$this->LOCAL_LANG[$languageKey][$labelKey][0]['target'] = $labelValue; |
279
|
1 |
|
$this->LOCAL_LANG_charset[$languageKey][$labelKey] = 'utf-8'; |
|
|
|
|
280
|
|
|
|
281
|
1 |
|
if ($labelValue === '') { |
282
|
1 |
|
$this->LOCAL_LANG_UNSET[$languageKey][$labelKey] = ''; |
283
|
|
|
} |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
} |
289
|
1 |
|
$this->LOCAL_LANG_loaded = 1; |
|
|
|
|
290
|
1 |
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Allows to override TypoScript settings with Flexform values. |
294
|
|
|
* |
295
|
|
|
*/ |
296
|
3 |
|
protected function overrideTyposcriptWithFlexformSettings() |
297
|
|
|
{ |
298
|
3 |
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Initializes the query from the GET query parameter. |
302
|
|
|
* |
303
|
|
|
*/ |
304
|
25 |
|
protected function initializeQuery() |
305
|
|
|
{ |
306
|
25 |
|
$this->rawUserQuery = GeneralUtility::_GET('q'); |
|
|
|
|
307
|
25 |
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Initializes the Solr connection and tests the connection through a ping. |
311
|
|
|
* |
312
|
|
|
*/ |
313
|
25 |
|
protected function initializeSearch() |
314
|
|
|
{ |
315
|
25 |
|
$solrConnection = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\ConnectionManager')->getConnectionByPageId( |
316
|
25 |
|
$GLOBALS['TSFE']->id, |
317
|
25 |
|
$GLOBALS['TSFE']->sys_language_uid, |
318
|
25 |
|
$GLOBALS['TSFE']->MP |
319
|
|
|
); |
320
|
|
|
|
321
|
25 |
|
$search = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Search', $solrConnection); |
322
|
|
|
/** @var $this->searchService ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService */ |
323
|
25 |
|
$this->searchResultsSetService = GeneralUtility::makeInstance('ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService', $this->typoScriptConfiguration, $search, $this); |
324
|
25 |
|
$this->solrAvailable = $this->searchResultsSetService->getIsSolrAvailable(); |
|
|
|
|
325
|
25 |
|
$this->search = $this->searchResultsSetService->getSearch(); |
|
|
|
|
326
|
25 |
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @return SearchResultSetService |
330
|
|
|
*/ |
331
|
25 |
|
public function getSearchResultSetService() |
332
|
|
|
{ |
333
|
25 |
|
return $this->searchResultsSetService; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Initializes the template engine and returns the initialized instance. |
338
|
|
|
* |
339
|
|
|
* @return Template |
340
|
|
|
* @throws \UnexpectedValueException if a view helper provider fails to implement interface ApacheSolrForTypo3\Solr\ViewHelper\ViewHelperProvider |
341
|
|
|
*/ |
342
|
25 |
|
protected function initializeTemplateEngine() |
343
|
|
|
{ |
344
|
25 |
|
$templateFile = $this->getTemplateFile(); |
345
|
25 |
|
$subPart = $this->getSubpart(); |
346
|
|
|
|
347
|
25 |
|
$flexformTemplateFile = $this->pi_getFFvalue( |
348
|
25 |
|
$this->cObj->data['pi_flexform'], |
349
|
25 |
|
'templateFile', |
350
|
25 |
|
'sOptions' |
351
|
|
|
); |
352
|
25 |
|
if (!empty($flexformTemplateFile)) { |
353
|
|
|
$templateFile = $flexformTemplateFile; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** @var Template $template */ |
357
|
25 |
|
$template = GeneralUtility::makeInstance( |
358
|
25 |
|
'ApacheSolrForTypo3\\Solr\\Template', |
359
|
25 |
|
$this->cObj, |
360
|
|
|
$templateFile, |
361
|
|
|
$subPart |
362
|
|
|
); |
363
|
25 |
|
$template->addViewHelperIncludePath($this->extKey, |
364
|
25 |
|
'Classes/ViewHelper/'); |
365
|
25 |
|
$template->addViewHelper('LLL', array( |
366
|
25 |
|
'languageFile' => 'EXT:solr/Resources/Private/Language/locallang.xlf', |
367
|
25 |
|
'llKey' => $this->LLkey |
368
|
|
|
)); |
369
|
|
|
|
370
|
|
|
// can be used for view helpers that need configuration during initialization |
371
|
25 |
|
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr'][$this->getPluginKey()]['addViewHelpers'])) { |
372
|
|
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr'][$this->getPluginKey()]['addViewHelpers'] as $classReference) { |
373
|
|
|
$viewHelperProvider = &GeneralUtility::getUserObj($classReference); |
374
|
|
|
|
375
|
|
|
if ($viewHelperProvider instanceof ViewHelperProvider) { |
376
|
|
|
$viewHelpers = $viewHelperProvider->getViewHelpers(); |
377
|
|
|
foreach ($viewHelpers as $helperName => $helperObject) { |
378
|
|
|
// TODO check whether $helperAdded is TRUE, throw an exception if not |
379
|
|
|
$helperAdded = $template->addViewHelperObject($helperName, |
|
|
|
|
380
|
|
|
$helperObject); |
381
|
|
|
} |
382
|
|
|
} else { |
383
|
|
|
throw new \UnexpectedValueException( |
384
|
|
|
get_class($viewHelperProvider) . ' must implement interface ApacheSolrForTypo3\Solr\ViewHelper\ViewHelperProvider', |
385
|
|
|
1310387296 |
386
|
|
|
); |
387
|
|
|
} |
388
|
|
|
} |
389
|
|
|
} |
390
|
|
|
|
391
|
25 |
|
$template = $this->postInitializeTemplateEngine($template); |
392
|
|
|
|
393
|
25 |
|
$this->template = $template; |
394
|
25 |
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* Initializes the javascript manager. |
398
|
|
|
* |
399
|
|
|
*/ |
400
|
25 |
|
protected function initializeJavascriptManager() |
401
|
|
|
{ |
402
|
25 |
|
$this->javascriptManager = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\JavascriptManager'); |
403
|
25 |
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* Initializes the language factory; |
407
|
|
|
*/ |
408
|
25 |
|
protected function initializeLanguageFactory() |
409
|
|
|
{ |
410
|
25 |
|
$this->languageFactory = GeneralUtility::makeInstance('TYPO3\CMS\Core\Localization\LocalizationFactory'); |
411
|
25 |
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* This method is called after initializing in the initialize method. |
415
|
|
|
* Overwrite this method to do your own initialization. |
416
|
|
|
* |
417
|
|
|
* @return void |
418
|
|
|
*/ |
419
|
3 |
|
protected function postInitialize() |
420
|
|
|
{ |
421
|
3 |
|
} |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* Overwrite this method to do own initialisations of the template. |
425
|
|
|
* |
426
|
|
|
* @param Template $template Template |
427
|
|
|
* @return Template |
428
|
|
|
*/ |
429
|
|
|
protected function postInitializeTemplateEngine(Template $template) |
430
|
|
|
{ |
431
|
|
|
return $template; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
// Rendering |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* This method executes the requested commands and applies the changes to |
438
|
|
|
* the template. |
439
|
|
|
* |
440
|
|
|
* @param $actionResult |
441
|
|
|
* @return string Rendered plugin content |
442
|
|
|
*/ |
443
|
|
|
abstract protected function render($actionResult); |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* Renders a solr error. |
447
|
|
|
* |
448
|
|
|
* @return string A representation of the error that should be understandable for the user. |
449
|
|
|
*/ |
450
|
|
|
protected function renderError() |
451
|
|
|
{ |
452
|
|
|
$this->template->workOnSubpart('solr_search_unavailable'); |
453
|
|
|
|
454
|
|
|
return $this->template->render(); |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
/** |
458
|
|
|
* Renders a solr exception. |
459
|
|
|
* |
460
|
|
|
* @return string A representation of the exception that should be understandable for the user. |
461
|
|
|
*/ |
462
|
|
|
protected function renderException() |
463
|
|
|
{ |
464
|
|
|
$this->template->workOnSubpart('solr_search_error'); |
465
|
|
|
|
466
|
|
|
return $this->template->render(); |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* Should be overwritten to do things before rendering. |
471
|
|
|
* |
472
|
|
|
*/ |
473
|
2 |
|
protected function preRender() |
474
|
|
|
{ |
475
|
2 |
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* Overwrite this method to perform changes to the content after rendering. |
479
|
|
|
* |
480
|
|
|
* @param string $content The content rendered by the plugin so far |
481
|
|
|
* @return string The content that should be presented on the website, might be different from the output rendered before |
482
|
|
|
*/ |
483
|
25 |
|
protected function postRender($content) |
484
|
|
|
{ |
485
|
25 |
|
if (isset($this->conf['stdWrap.'])) { |
486
|
|
|
$content = $this->cObj->stdWrap($content, $this->conf['stdWrap.']); |
487
|
|
|
} |
488
|
|
|
|
489
|
25 |
|
return $content; |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
// Helper methods |
493
|
|
|
|
494
|
|
|
/** |
495
|
|
|
* Determines the template file from the configuration. |
496
|
|
|
* |
497
|
|
|
* Overwrite this method to use a different template. |
498
|
|
|
* |
499
|
|
|
* @return string The template file name to be used for the plugin |
500
|
|
|
*/ |
501
|
25 |
|
protected function getTemplateFile() |
502
|
|
|
{ |
503
|
25 |
|
return $this->typoScriptConfiguration->getTemplateByFileKey($this->getTemplateFileKey()); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* This method should be implemented to return the TSconfig key which |
508
|
|
|
* contains the template name for this template. |
509
|
|
|
* |
510
|
|
|
* @see initializeTemplateEngine() |
511
|
|
|
* @return string The TSconfig key containing the template name |
512
|
|
|
*/ |
513
|
|
|
abstract protected function getTemplateFileKey(); |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* Gets the plugin's template instance. |
517
|
|
|
* |
518
|
|
|
* @return Template The plugin's template. |
519
|
|
|
*/ |
520
|
25 |
|
public function getTemplate() |
521
|
|
|
{ |
522
|
25 |
|
return $this->template; |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* Gets the plugin's javascript manager. |
527
|
|
|
* |
528
|
|
|
* @return JavascriptManager The plugin's javascript manager. |
529
|
|
|
*/ |
530
|
25 |
|
public function getJavascriptManager() |
531
|
|
|
{ |
532
|
25 |
|
return $this->javascriptManager; |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
/** |
536
|
|
|
* Should return the relevant subpart of the template. |
537
|
|
|
* |
538
|
|
|
* @see initializeTemplateEngine() |
539
|
|
|
* @return string The subpart of the template to be used |
540
|
|
|
*/ |
541
|
|
|
abstract protected function getSubpart(); |
542
|
|
|
|
543
|
|
|
/** |
544
|
|
|
* This method should return the plugin key. Reads some configuration |
545
|
|
|
* options in initializeTemplateEngine() |
546
|
|
|
* |
547
|
|
|
* @see initializeTemplateEngine() |
548
|
|
|
* @return string The plugin key |
549
|
|
|
*/ |
550
|
|
|
abstract protected function getPluginKey(); |
551
|
|
|
|
552
|
|
|
/** |
553
|
|
|
* Gets the target page Id for links. Might have been set through either |
554
|
|
|
* flexform or TypoScript. If none is set, TSFE->id is used. |
555
|
|
|
* |
556
|
|
|
* @return int The page Id to be used for links |
557
|
|
|
*/ |
558
|
18 |
|
public function getLinkTargetPageId() |
559
|
|
|
{ |
560
|
18 |
|
return $this->typoScriptConfiguration->getSearchTargetPage(); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
/** |
564
|
|
|
* Gets the user's query term and cleans it so that it can be used in |
565
|
|
|
* templates f.e. |
566
|
|
|
* |
567
|
|
|
* @return string The cleaned user query. |
568
|
|
|
*/ |
569
|
25 |
|
public function getCleanUserQuery() |
570
|
|
|
{ |
571
|
25 |
|
$userQuery = $this->getRawUserQuery(); |
572
|
|
|
|
573
|
25 |
|
if (!is_null($userQuery)) { |
574
|
21 |
|
$userQuery = Query::cleanKeywords($userQuery); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
// escape triple hashes as they are used in the template engine |
578
|
|
|
// TODO remove after switching to fluid templates |
579
|
25 |
|
$userQuery = Template::escapeMarkers($userQuery); |
580
|
|
|
|
581
|
25 |
|
return $userQuery; |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
/** |
585
|
|
|
* Gets the raw user query |
586
|
|
|
* |
587
|
|
|
* @return string Raw user query. |
588
|
|
|
*/ |
589
|
25 |
|
public function getRawUserQuery() |
590
|
|
|
{ |
591
|
25 |
|
return $this->rawUserQuery; |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
/** |
595
|
|
|
* @return string |
596
|
|
|
*/ |
597
|
25 |
|
protected function getCurrentUrlWithQueryLinkBuilder() |
598
|
|
|
{ |
599
|
25 |
|
$currentUrl = $this->pi_linkTP_keepPIvars_url(); |
600
|
25 |
|
$resultService = $this->getSearchResultSetService(); |
601
|
|
|
|
602
|
25 |
|
if (!$resultService instanceof SearchResultSetService) { |
603
|
|
|
return $currentUrl; |
604
|
|
|
} |
605
|
|
|
|
606
|
25 |
|
if ($resultService->getIsSolrAvailable() && $this->getSearchResultSetService()->getHasSearched()) { |
607
|
4 |
|
$queryLinkBuilder = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query\\LinkBuilder', $this->getSearchResultSetService()->getSearch()->getQuery()); |
608
|
4 |
|
$currentUrl = $queryLinkBuilder->getQueryUrl(); |
609
|
4 |
|
return $currentUrl; |
610
|
|
|
} |
611
|
25 |
|
return $currentUrl; |
612
|
|
|
} |
613
|
|
|
} |
614
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.