2 namespace TYPO3\CMS\IndexedSearch\Controller
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Html\HtmlParser
;
18 use TYPO3\CMS\Core\Utility\GeneralUtility
;
19 use TYPO3\CMS\Core\Utility\MathUtility
;
20 use TYPO3\CMS\Extbase\Utility\LocalizationUtility
;
23 * Index search frontend
25 * Creates a search form for indexed search. Indexing must be enabled
26 * for this to make sense.
28 class SearchController
extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
31 * previously known as $this->piVars['sword']
35 protected $sword = null
;
40 protected $searchWords = array();
45 protected $searchData;
48 * This is the id of the site root.
49 * This value may be a comma separated list of integer (prepared for this)
50 * Root-page PIDs to search in (rl0 field where clause, see initialize() function)
52 * If this value is set to less than zero (eg. -1) searching will happen
53 * in ALL of the page tree with no regard to branches at all.
56 protected $searchRootPageIdList = 0;
61 protected $defaultResultNumber = 10;
66 * @var \TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository
68 protected $searchRepository = null
;
73 * @var \TYPO3\CMS\IndexedSearch\Lexer
78 * External parser objects
81 protected $externalParsers = array();
84 * Will hold the first row in result - used to calculate relative hit-ratings.
88 protected $firstRow = array();
95 protected $domainRecords = array();
98 * Required fe_groups memberships for display of a result.
102 protected $requiredFrontendUsergroups = array();
105 * Page tree sections for search result.
109 protected $resultSections = array();
112 * Caching of page path
116 protected $pathCache = array();
123 protected $iconFileNameCache = array();
126 * Indexer configuration, coming from $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['indexed_search']
130 protected $indexerConfig = array();
133 * Flag whether metaphone search should be enabled
137 protected $enableMetaphoneSearch = false
;
140 * @var \TYPO3\CMS\Extbase\Service\TypoScriptService
142 protected $typoScriptService;
145 * @param \TYPO3\CMS\Extbase\Service\TypoScriptService $typoScriptService
147 public function injectTypoScriptService(\TYPO3\CMS\Extbase\Service\TypoScriptService
$typoScriptService)
149 $this->typoScriptService
= $typoScriptService;
153 * sets up all necessary object for searching
155 * @param array $searchData The incoming search parameters
156 * @return array Search parameters
158 public function initialize($searchData = array())
160 if (!is_array($searchData)) {
161 $searchData = array();
164 $this->loadSettings();
166 // setting default values
167 if (is_array($this->settings
['defaultOptions'])) {
168 $searchData = array_merge($this->settings
['defaultOptions'], $searchData);
170 // Indexer configuration from Extension Manager interface:
171 $this->indexerConfig
= unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['indexed_search']);
172 $this->enableMetaphoneSearch
= (bool
)$this->indexerConfig
['enableMetaphoneSearch'];
173 $this->initializeExternalParsers();
174 // If "_sections" is set, this value overrides any existing value.
175 if ($searchData['_sections']) {
176 $searchData['sections'] = $searchData['_sections'];
178 // If "_sections" is set, this value overrides any existing value.
179 if ($searchData['_freeIndexUid'] !== '' && $searchData['_freeIndexUid'] !== '_') {
180 $searchData['freeIndexUid'] = $searchData['_freeIndexUid'];
182 $searchData['numberOfResults'] = MathUtility
::forceIntegerInRange($searchData['numberOfResults'], 1, 100000, $this->defaultResultNumber
);
183 // This gets the search-words into the $searchWordArray
184 $this->sword
= $searchData['sword'];
185 // Add previous search words to current
186 if ($searchData['sword_prev_include'] && $searchData['sword_prev']) {
187 $this->sword
= trim($searchData['sword_prev']) . ' ' . $this->sword
;
189 $this->searchWords
= $this->getSearchWords($searchData['defaultOperand']);
190 // This is the id of the site root.
191 // This value may be a commalist of integer (prepared for this)
192 $this->searchRootPageIdList
= (int)$GLOBALS['TSFE']->config
['rootLine'][0]['uid'];
193 // Setting the list of root PIDs for the search. Notice, these page IDs MUST
194 // have a TypoScript template with root flag on them! Basically this list is used
195 // to select on the "rl0" field and page ids are registered as "rl0" only if
196 // a TypoScript template record with root flag is there.
197 // This happens AFTER the use of $this->searchRootPageIdList above because
198 // the above will then fetch the menu for the CURRENT site - regardless
199 // of this kind of searching here. Thus a general search will lookup in
200 // the WHOLE database while a specific section search will take the current sections.
201 if ($this->settings
['rootPidList']) {
202 $this->searchRootPageIdList
= implode(',', GeneralUtility
::intExplode(',', $this->settings
['rootPidList']));
204 $this->searchRepository
= GeneralUtility
::makeInstance(\TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository
::class);
205 $this->searchRepository
->initialize($this->settings
, $searchData, $this->externalParsers
, $this->searchRootPageIdList
);
206 $this->searchData
= $searchData;
207 // Calling hook for modification of initialized content
208 if ($hookObj = $this->hookRequest('initialize_postProc')) {
209 $hookObj->initialize_postProc();
215 * Performs the search, the display and writing stats
217 * @param array $search the search parameters, an associative array
219 * @ignorevalidation $search
221 public function searchAction($search = array())
223 $searchData = $this->initialize($search);
224 // Find free index uid:
225 $freeIndexUid = $searchData['freeIndexUid'];
226 if ($freeIndexUid == -2) {
227 $freeIndexUid = $this->settings
['defaultFreeIndexUidList'];
228 } elseif (!isset($searchData['freeIndexUid'])) {
229 // index configuration is disabled
232 $indexCfgs = GeneralUtility
::intExplode(',', $freeIndexUid);
233 $resultsets = array();
234 foreach ($indexCfgs as $freeIndexUid) {
236 $tstamp1 = GeneralUtility
::milliseconds();
237 if ($hookObj = $this->hookRequest('getResultRows')) {
238 $resultData = $hookObj->getResultRows($this->searchWords
, $freeIndexUid);
240 $resultData = $this->searchRepository
->doSearch($this->searchWords
, $freeIndexUid);
242 // Display search results
243 $tstamp2 = GeneralUtility
::milliseconds();
244 if ($hookObj = $this->hookRequest('getDisplayResults')) {
245 $resultsets[$freeIndexUid] = $hookObj->getDisplayResults($this->searchWords
, $resultData, $freeIndexUid);
247 $resultsets[$freeIndexUid] = $this->getDisplayResults($this->searchWords
, $resultData, $freeIndexUid);
249 $tstamp3 = GeneralUtility
::milliseconds();
250 // Create header if we are searching more than one indexing configuration
251 if (count($indexCfgs) > 1) {
252 if ($freeIndexUid > 0) {
253 $indexCfgRec = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('title', 'index_config', 'uid=' . (int)$freeIndexUid . $GLOBALS['TSFE']->cObj
->enableFields('index_config'));
254 $categoryTitle = $indexCfgRec['title'];
256 $categoryTitle = LocalizationUtility
::translate('indexingConfigurationHeader.' . $freeIndexUid, 'IndexedSearch');
258 $resultsets[$freeIndexUid]['categoryTitle'] = $categoryTitle;
260 // Write search statistics
261 $this->writeSearchStat($searchData, $this->searchWords
, $resultData['count'], array($tstamp1, $tstamp2, $tstamp3));
263 $this->view
->assign('resultsets', $resultsets);
264 $this->view
->assign('searchParams', $searchData);
265 $this->view
->assign('searchWords', $this->searchWords
);
268 /****************************************
269 * functions to make the result rows and result sets
270 * ready for the output
271 ***************************************/
273 * Compiles the HTML display of the incoming array of result rows.
275 * @param array $searchWords Search words array (for display of text describing what was searched for)
276 * @param array $resultData Array with result rows, count, first row.
277 * @param int $freeIndexUid Pointing to which indexing configuration you want to search in. -1 means no filtering. 0 means only regular indexed content.
280 protected function getDisplayResults($searchWords, $resultData, $freeIndexUid = -1)
283 'count' => $resultData['count'],
284 'searchWords' => $searchWords
286 // Perform display of result rows array
288 // Set first selected row (for calculation of ranking later)
289 $this->firstRow
= $resultData['firstRow'];
290 // Result display here
291 $result['rows'] = $this->compileResultRows($resultData['resultRows'], $freeIndexUid);
292 $result['affectedSections'] = $this->resultSections
;
294 if ($resultData['count']) {
295 // could we get this in the view?
296 if ($this->searchData
['group'] == 'sections' && $freeIndexUid <= 0) {
297 $resultSectionsCount = count($this->resultSections
);
298 $result['sectionText'] = sprintf(LocalizationUtility
::translate('result.' . ($resultSectionsCount > 1 ?
'inNsections' : 'inNsection'), 'IndexedSearch'), $resultSectionsCount);
302 // Print a message telling which words in which sections we searched for
303 if (substr($this->searchData
['sections'], 0, 2) === 'rl') {
304 $result['searchedInSectionInfo'] = LocalizationUtility
::translate('result.inSection', 'IndexedSearch') . ' "' . $this->getPathFromPageId(substr($this->searchData
['sections'], 4)) . '"';
310 * Takes the array with resultrows as input and returns the result-HTML-code
311 * Takes the "group" var into account: Makes a "section" or "flat" display.
313 * @param array $resultRows Result rows
314 * @param int $freeIndexUid Pointing to which indexing configuration you want to search in. -1 means no filtering. 0 means only regular indexed content.
315 * @return string HTML
317 protected function compileResultRows($resultRows, $freeIndexUid = -1)
319 $finalResultRows = array();
320 // Transfer result rows to new variable,
321 // performing some mapping of sub-results etc.
322 $newResultRows = array();
323 foreach ($resultRows as $row) {
324 $id = md5($row['phash_grouping']);
325 if (is_array($newResultRows[$id])) {
327 if (!$newResultRows[$id]['show_resume'] && $row['show_resume']) {
329 $subrows = $newResultRows[$id]['_sub'];
330 unset($newResultRows[$id]['_sub']);
331 $subrows[] = $newResultRows[$id];
333 $newResultRows[$id] = $row;
334 $newResultRows[$id]['_sub'] = $subrows;
336 $newResultRows[$id]['_sub'][] = $row;
339 $newResultRows[$id] = $row;
342 $resultRows = $newResultRows;
343 $this->resultSections
= array();
344 if ($freeIndexUid <= 0 && $this->searchData
['group'] == 'sections') {
345 $rl2flag = substr($this->searchData
['sections'], 0, 2) == 'rl';
347 foreach ($resultRows as $row) {
348 $id = $row['rl0'] . '-' . $row['rl1'] . ($rl2flag ?
'-' . $row['rl2'] : '');
349 $sections[$id][] = $row;
351 $this->resultSections
= array();
352 foreach ($sections as $id => $resultRows) {
353 $rlParts = explode('-', $id);
355 $theId = $rlParts[2];
356 $theRLid = 'rl2_' . $rlParts[2];
357 } elseif ($rlParts[1]) {
358 $theId = $rlParts[1];
359 $theRLid = 'rl1_' . $rlParts[1];
361 $theId = $rlParts[0];
364 $sectionName = $this->getPathFromPageId($theId);
365 $sectionName = ltrim($sectionName, '/');
366 if (!trim($sectionName)) {
367 $sectionTitleLinked = LocalizationUtility
::translate('result.unnamedSection', 'IndexedSearch') . ':';
369 $onclick = 'document.forms[\'tx_indexedsearch\'][\'tx_indexedsearch_pi2[search][_sections]\'].value=' . GeneralUtility
::quoteJSvalue($theRLid) . ';document.forms[\'tx_indexedsearch\'].submit();return false;';
370 $sectionTitleLinked = '<a href="#" onclick="' . htmlspecialchars($onclick) . '">' . $sectionName . ':</a>';
372 $resultRowsCount = count($resultRows);
373 $this->resultSections
[$id] = array($sectionName, $resultRowsCount);
374 // Add section header
375 $finalResultRows[] = array(
376 'isSectionHeader' => true
,
377 'numResultRows' => $resultRowsCount,
379 'sectionTitle' => $sectionTitleLinked
381 // Render result rows
382 foreach ($resultRows as $row) {
383 $finalResultRows[] = $this->compileSingleResultRow($row);
387 // flat mode or no sections at all
388 foreach ($resultRows as $row) {
389 $finalResultRows[] = $this->compileSingleResultRow($row);
392 return $finalResultRows;
396 * This prints a single result row, including a recursive call for subrows.
398 * @param array $row Search result row
399 * @param int $headerOnly 1=Display only header (for sub-rows!), 2=nothing at all
400 * @return string HTML code
402 protected function compileSingleResultRow($row, $headerOnly = 0)
404 $specRowConf = $this->getSpecialConfigurationForResultRow($row);
406 $resultData['headerOnly'] = $headerOnly;
407 $resultData['CSSsuffix'] = $specRowConf['CSSsuffix'] ?
'-' . $specRowConf['CSSsuffix'] : '';
408 if ($this->multiplePagesType($row['item_type'])) {
409 $dat = unserialize($row['cHashParams']);
410 $pp = explode('-', $dat['key']);
411 if ($pp[0] != $pp[1]) {
412 $resultData['titleaddition'] = ', ' . LocalizationUtility
::translate('result.page', 'IndexedSearch') . ' ' . $dat['key'];
414 $resultData['titleaddition'] = ', ' . LocalizationUtility
::translate('result.pages', 'IndexedSearch') . ' ' . $pp[0];
417 $title = $resultData['item_title'] . $resultData['titleaddition'];
418 $title = $GLOBALS['TSFE']->csConvObj
->crop('utf-8', $title, $this->settings
['results.']['titleCropAfter'], $this->settings
['results.']['titleCropSignifier']);
419 // If external media, link to the media-file instead.
420 if ($row['item_type']) {
421 if ($row['show_resume']) {
422 // Can link directly.
423 $targetAttribute = '';
424 if ($GLOBALS['TSFE']->config
['config']['fileTarget']) {
425 $targetAttribute = ' target="' . htmlspecialchars($GLOBALS['TSFE']->config
['config']['fileTarget']) . '"';
427 $title = '<a href="' . htmlspecialchars($row['data_filename']) . '"' . $targetAttribute . '>' . htmlspecialchars($title) . '</a>';
429 // Suspicious, so linking to page instead...
431 unset($copiedRow['cHashParams']);
432 $title = $this->linkPage($row['page_id'], $title, $copiedRow);
436 // Prepare search words for markup in content:
437 $markUpSwParams = array();
438 if ($this->settings
['forwardSearchWordsInResultLink']['_typoScriptNodeValue']) {
439 if ($this->settings
['forwardSearchWordsInResultLink']['no_cache']) {
440 $markUpSwParams = array('no_cache' => 1);
442 foreach ($this->searchWords
as $d) {
443 $markUpSwParams['sword_list'][] = $d['sword'];
446 $title = $this->linkPage($row['data_page_id'], $title, $row, $markUpSwParams);
448 $resultData['title'] = $title;
449 $resultData['icon'] = $this->makeItemTypeIcon($row['item_type'], '', $specRowConf);
450 $resultData['rating'] = $this->makeRating($row);
451 $resultData['description'] = $this->makeDescription(
453 (bool
)!($this->searchData
['extResume'] && !$headerOnly),
454 $this->settings
['results.']['summaryCropAfter']
456 $resultData['language'] = $this->makeLanguageIndication($row);
457 $resultData['size'] = GeneralUtility
::formatSize($row['item_size']);
458 $resultData['created'] = $row['item_crdate'];
459 $resultData['modified'] = $row['item_mtime'];
460 $pI = parse_url($row['data_filename']);
462 $targetAttribute = '';
463 if ($GLOBALS['TSFE']->config
['config']['fileTarget']) {
464 $targetAttribute = ' target="' . htmlspecialchars($GLOBALS['TSFE']->config
['config']['fileTarget']) . '"';
466 $resultData['path'] = '<a href="' . htmlspecialchars($row['data_filename']) . '"' . $targetAttribute . '>' . htmlspecialchars($row['data_filename']) . '</a>';
468 $pathId = $row['data_page_id'] ?
: $row['page_id'];
469 $pathMP = $row['data_page_id'] ?
$row['data_page_mp'] : '';
470 $pathStr = $this->getPathFromPageId($pathId, $pathMP);
471 $resultData['path'] = $this->linkPage($pathId, $pathStr, array(
472 'cHashParams' => $row['cHashParams'],
473 'data_page_type' => $row['data_page_type'],
474 'data_page_mp' => $pathMP,
475 'sys_language_uid' => $row['sys_language_uid']
477 // check if the access is restricted
478 if (is_array($this->requiredFrontendUsergroups
[$pathId]) && !empty($this->requiredFrontendUsergroups
[$pathId])) {
479 $resultData['access'] = '<img src="' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::siteRelPath('indexed_search')
480 . 'Resources/Public/Icons/FileTypes/locked.gif" width="12" height="15" vspace="5" title="'
481 . sprintf(LocalizationUtility
::translate('result.memberGroups', 'IndexedSearch'), implode(',', array_unique($this->requiredFrontendUsergroups
[$pathId])))
485 // If there are subrows (eg. subpages in a PDF-file or if a duplicate page
486 // is selected due to user-login (phash_grouping))
487 if (is_array($row['_sub'])) {
488 $resultData['subresults'] = array();
489 if ($this->multiplePagesType($row['item_type'])) {
490 $resultData['subresults']['header'] = LocalizationUtility
::translate('result.otherMatching', 'IndexedSearch');
491 foreach ($row['_sub'] as $subRow) {
492 $resultData['subresults']['items'][] = $this->compileSingleResultRow($subRow, 1);
495 $resultData['subresults']['header'] = LocalizationUtility
::translate('result.otherMatching', 'IndexedSearch');
496 $resultData['subresults']['info'] = LocalizationUtility
::translate('result.otherPageAsWell', 'IndexedSearch');
503 * Returns configuration from TypoScript for result row based
504 * on ID / location in page tree!
506 * @param array $row Result row
507 * @return array Configuration array
509 protected function getSpecialConfigurationForResultRow($row)
511 $pathId = $row['data_page_id'] ?
: $row['page_id'];
512 $pathMP = $row['data_page_id'] ?
$row['data_page_mp'] : '';
513 $rl = $GLOBALS['TSFE']->sys_page
->getRootLine($pathId, $pathMP);
514 $specConf = $this->settings
['specialConfiguration']['0'];
516 foreach ($rl as $dat) {
517 if (is_array($this->settings
['specialConfiguration'][$dat['uid']])) {
518 $specConf = $this->settings
['specialConfiguration'][$dat['uid']];
519 $specConf['_pid'] = $dat['uid'];
528 * Return the rating-HTML code for the result row. This makes use of the $this->firstRow
530 * @param array $row Result row array
531 * @return string String showing ranking value
532 * @todo can this be a ViewHelper?
534 protected function makeRating($row)
536 switch ((string)$this->searchData
['sortOrder']) {
538 return $row['order_val'] . ' ' . LocalizationUtility
::translate('result.ratingMatches', 'IndexedSearch');
541 return ceil(MathUtility
::forceIntegerInRange((255 - $row['order_val']), 1, 255) / 255 * 100) . '%';
544 if ($this->firstRow
['order_val2']) {
545 // (3 MSB bit, 224 is highest value of order_val1 currently)
546 $base = $row['order_val1'] * 256;
548 $freqNumber = $row['order_val2'] / $this->firstRow
['order_val2'] * pow(2, 12);
549 $total = MathUtility
::forceIntegerInRange($base +
$freqNumber, 0, 32767);
550 return ceil(log($total) / log(32767) * 100) . '%';
555 $total = MathUtility
::forceIntegerInRange($row['order_val'], 0, $max);
556 return ceil(log($total) / log($max) * 100) . '%';
559 return $GLOBALS['TSFE']->cObj
->calcAge($GLOBALS['EXEC_TIME'] - $row['item_crdate'], 0);
562 return $GLOBALS['TSFE']->cObj
->calcAge($GLOBALS['EXEC_TIME'] - $row['item_mtime'], 0);
570 * Returns the HTML code for language indication.
572 * @param array $row Result row
573 * @return string HTML code for result row.
575 protected function makeLanguageIndication($row)
578 // If search result is a TYPO3 page:
579 if ((string)$row['item_type'] === '0') {
580 // If TypoScript is used to render the flag:
581 if (is_array($this->settings
['flagRendering'])) {
582 /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */
583 $cObj = GeneralUtility
::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class);
584 $cObj->setCurrentVal($row['sys_language_uid']);
585 $typoScriptArray = $this->typoScriptService
->convertPlainArrayToTypoScriptArray($this->settings
['flagRendering']);
586 $output = $cObj->cObjGetSingle($this->settings
['flagRendering']['_typoScriptNodeValue'], $typoScriptArray);
593 * Return icon for file extension
595 * @param string $imageType File extension / item type
596 * @param string $alt Title attribute value in icon.
597 * @param array $specRowConf TypoScript configuration specifically for search result.
598 * @return string <img> tag for icon
600 public function makeItemTypeIcon($imageType, $alt, $specRowConf)
602 // Build compound key if item type is 0, iconRendering is not used
603 // and specialConfiguration.[pid].pageIcon was set in TS
604 if ($imageType === '0' && $specRowConf['_pid'] && is_array($specRowConf['pageIcon']) && !is_array($this->settings
['iconRendering'])) {
605 $imageType .= ':' . $specRowConf['_pid'];
607 if (!isset($this->iconFileNameCache
[$imageType])) {
608 $this->iconFileNameCache
[$imageType] = '';
609 // If TypoScript is used to render the icon:
610 if (is_array($this->settings
['iconRendering'])) {
611 /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */
612 $cObj = GeneralUtility
::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
::class);
613 $cObj->setCurrentVal($imageType);
614 $typoScriptArray = $this->typoScriptService
->convertPlainArrayToTypoScriptArray($this->settings
['iconRendering']);
615 $this->iconFileNameCache
[$imageType] = $cObj->cObjGetSingle($this->settings
['iconRendering']['_typoScriptNodeValue'], $typoScriptArray);
617 // Default creation / finding of icon:
619 if ($imageType === '0' ||
substr($imageType, 0, 2) == '0:') {
620 if (is_array($specRowConf['pageIcon'])) {
621 $this->iconFileNameCache
[$imageType] = $GLOBALS['TSFE']->cObj
->cObjGetSingle('IMAGE', $specRowConf['pageIcon']);
623 $icon = 'EXT:indexed_search/Resources/Public/Icons/FileTypes/pages.gif';
625 } elseif ($this->externalParsers
[$imageType]) {
626 $icon = $this->externalParsers
[$imageType]->getIcon($imageType);
629 $fullPath = GeneralUtility
::getFileAbsFileName($icon);
631 $info = @getimagesize
($fullPath);
632 $iconPath = \TYPO3\CMS\Core\Utility\PathUtility
::stripPathSitePrefix($fullPath);
633 $this->iconFileNameCache
[$imageType] = is_array($info) ?
'<img src="' . $iconPath . '" ' . $info[3] . ' title="' . htmlspecialchars($alt) . '" alt="" />' : '';
638 return $this->iconFileNameCache
[$imageType];
642 * Returns the resume for the search-result.
644 * @param array $row Search result row
645 * @param bool $noMarkup If noMarkup is FALSE, then the index_fulltext table is used to select the content of the page, split it with regex to display the search words in the text.
646 * @param int $length String length
647 * @return string HTML string
648 * @todo overwork this
650 protected function makeDescription($row, $noMarkup = false
, $length = 180)
652 if ($row['show_resume']) {
655 $res = $this->getDatabaseConnection()->exec_SELECTquery('*', 'index_fulltext', 'phash=' . (int)$row['phash']);
656 if ($ftdrow = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
657 // Cut HTTP references after some length
658 $content = preg_replace('/(http:\\/\\/[^ ]{' . $this->settings
['results.']['hrefInSummaryCropAfter'] . '})([^ ]+)/i', '$1...', $ftdrow['fulltextdata']);
659 $markedSW = $this->markupSWpartsOfString($content);
661 $this->getDatabaseConnection()->sql_free_result($res);
663 if (!trim($markedSW)) {
664 $outputStr = $GLOBALS['TSFE']->csConvObj
->crop('utf-8', $row['item_description'], $length, $this->settings
['results.']['summaryCropSignifier']);
665 $outputStr = htmlspecialchars($outputStr);
667 $output = $outputStr ?
: $markedSW;
668 $output = $GLOBALS['TSFE']->csConv($output, 'utf-8');
670 $output = '<span class="noResume">' . LocalizationUtility
::translate('result.noResume', 'IndexedSearch') . '</span>';
676 * Marks up the search words from $this->searchWords in the $str with a color.
678 * @param string $str Text in which to find and mark up search words. This text is assumed to be UTF-8 like the search words internally is.
679 * @return string Processed content
681 protected function markupSWpartsOfString($str)
683 $htmlParser = GeneralUtility
::makeInstance(HtmlParser
::class);
685 $str = str_replace(' ', ' ', $htmlParser->bidir_htmlspecialchars($str, -1));
686 $str = preg_replace('/\\s\\s+/', ' ', $str);
688 // Prepare search words for regex:
689 foreach ($this->searchWords
as $d) {
690 $swForReg[] = preg_quote($d['sword'], '/');
692 $regExString = '(' . implode('|', $swForReg) . ')';
693 // Split and combine:
694 $parts = preg_split('/' . $regExString . '/i', ' ' . $str . ' ', 20000, PREG_SPLIT_DELIM_CAPTURE
);
696 $summaryMax = $this->settings
['results.']['markupSW_summaryMax'];
697 $postPreLgd = $this->settings
['results.']['markupSW_postPreLgd'];
698 $postPreLgd_offset = $this->settings
['results.']['markupSW_postPreLgd_offset'];
699 $divider = $this->settings
['results.']['markupSW_divider'];
700 $occurencies = (count($parts) - 1) / 2;
702 $postPreLgd = MathUtility
::forceIntegerInRange($summaryMax / $occurencies, $postPreLgd, $summaryMax / 2);
707 // Shorten in-between strings:
708 foreach ($parts as $k => $strP) {
710 // Find length of the summary part:
711 $strLen = $GLOBALS['TSFE']->csConvObj
->strlen('utf-8', $parts[$k]);
712 $output[$k] = $parts[$k];
713 // Possibly shorten string:
715 // First entry at all (only cropped on the frontside)
716 if ($strLen > $postPreLgd) {
717 $output[$k] = $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $GLOBALS['TSFE']->csConvObj
->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
719 } elseif ($summaryLgd > $summaryMax ||
!isset($parts[$k +
1])) {
720 // In case summary length is exceed OR if there are no more entries at all:
721 if ($strLen > $postPreLgd) {
722 $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $GLOBALS['TSFE']->csConvObj
->crop('utf-8', $parts[$k], ($postPreLgd - $postPreLgd_offset))) . $divider;
725 if ($strLen > $postPreLgd * 2) {
726 $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $GLOBALS['TSFE']->csConvObj
->crop('utf-8', $parts[$k], ($postPreLgd - $postPreLgd_offset))) . $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $GLOBALS['TSFE']->csConvObj
->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
729 $summaryLgd +
= $GLOBALS['TSFE']->csConvObj
->strlen('utf-8', $output[$k]);
731 $output[$k] = htmlspecialchars($output[$k]);
732 // If summary lgd is exceed, break the process:
733 if ($summaryLgd > $summaryMax) {
737 $summaryLgd +
= $GLOBALS['TSFE']->csConvObj
->strlen('utf-8', $strP);
738 $output[$k] = '<strong class="tx-indexedsearch-redMarkup">' . htmlspecialchars($parts[$k]) . '</strong>';
742 return implode('', $output);
746 * Write statistics information to database for the search operation
748 * @param array $searchParams search params
749 * @param array $searchWords Search Word array
750 * @param int $count Number of hits
751 * @param int $pt Milliseconds the search took
754 protected function writeSearchStat($searchParams, $searchWords, $count, $pt)
756 $insertFields = array(
757 'searchstring' => $this->sword
,
758 'searchoptions' => serialize(array($searchParams, $searchWords, $pt)),
759 'feuser_id' => (int)$GLOBALS['TSFE']->fe_user
->user
['uid'],
760 // cookie as set or retrieved. If people has cookies disabled this will vary all the time
761 'cookie' => $GLOBALS['TSFE']->fe_user
->id
,
763 'IP' => GeneralUtility
::getIndpEnv('REMOTE_ADDR'),
764 // Number of hits on the search
765 'hits' => (int)$count,
767 'tstamp' => $GLOBALS['EXEC_TIME']
769 $this->getDatabaseConnection()->exec_INSERTquery('index_stat_search', $insertFields);
770 $newId = $this->getDatabaseConnection()->sql_insert_id();
772 foreach ($searchWords as $val) {
773 $insertFields = array(
774 'word' => $val['sword'],
775 'index_stat_search_id' => $newId,
777 'tstamp' => $GLOBALS['EXEC_TIME'],
778 // search page id for indexed search stats
779 'pageid' => $GLOBALS['TSFE']->id
781 $this->getDatabaseConnection()->exec_INSERTquery('index_stat_word', $insertFields);
787 * Splits the search word input into an array where each word is represented by an array with key "sword"
788 * holding the search word and key "oper" holding the SQL operator (eg. AND, OR)
790 * Only words with 2 or more characters are accepted
791 * Max 200 chars total
792 * Space is used to split words, "" can be used search for a whole string
793 * AND, OR and NOT are prefix words, overruling the default operator
794 * +/|/- equals AND, OR and NOT as operators.
795 * All search words are converted to lowercase.
797 * $defOp is the default operator. 1=OR, 0=AND
799 * @param bool $defaultOperator If TRUE, the default operator will be OR, not AND
800 * @return array Search words if any found
802 protected function getSearchWords($defaultOperator)
804 // Shorten search-word string to max 200 bytes (does NOT take multibyte charsets into account - but never mind,
805 // shortening the string here is only a run-away feature!)
806 $searchWords = substr($this->sword
, 0, 200);
807 // Convert to UTF-8 + conv. entities (was also converted during indexing!)
808 $searchWords = $GLOBALS['TSFE']->csConvObj
->utf8_encode($searchWords, $GLOBALS['TSFE']->metaCharset
);
809 $searchWords = $GLOBALS['TSFE']->csConvObj
->entities_to_utf8($searchWords, true
);
811 if ($hookObj = $this->hookRequest('getSearchWords')) {
812 $sWordArray = $hookObj->getSearchWords_splitSWords($searchWords, $defaultOperator);
815 if ($this->searchData
['searchType'] == 20) {
818 'sword' => trim($searchWords),
823 // case-sensitive. Defines the words, which will be
824 // operators between words
825 $operatorTranslateTable = array(
828 array('-', 'AND NOT'),
829 // Add operators for various languages
830 // Converts the operators to UTF-8 and lowercase
831 array($GLOBALS['TSFE']->csConvObj
->conv_case('utf-8', $GLOBALS['TSFE']->csConvObj
->utf8_encode(LocalizationUtility
::translate('localizedOperandAnd', 'IndexedSearch'), $GLOBALS['TSFE']->renderCharset
), 'toLower'), 'AND'),
832 array($GLOBALS['TSFE']->csConvObj
->conv_case('utf-8', $GLOBALS['TSFE']->csConvObj
->utf8_encode(LocalizationUtility
::translate('localizedOperandOr', 'IndexedSearch'), $GLOBALS['TSFE']->renderCharset
), 'toLower'), 'OR'),
833 array($GLOBALS['TSFE']->csConvObj
->conv_case('utf-8', $GLOBALS['TSFE']->csConvObj
->utf8_encode(LocalizationUtility
::translate('localizedOperandNot', 'IndexedSearch'), $GLOBALS['TSFE']->renderCharset
), 'toLower'), 'AND NOT')
835 $swordArray = \TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility
::getExplodedSearchString($searchWords, $defaultOperator == 1 ?
'OR' : 'AND', $operatorTranslateTable);
836 if (is_array($swordArray)) {
837 $sWordArray = $this->procSearchWordsByLexer($swordArray);
845 * Post-process the search word array so it will match the words that was indexed (including case-folding if any)
846 * If any words are splitted into multiple words (eg. CJK will be!) the operator of the main word will remain.
848 * @param array $searchWords Search word array
849 * @return array Search word array, processed through lexer
851 protected function procSearchWordsByLexer($searchWords)
853 $newSearchWords = array();
854 // Init lexer (used to post-processing of search words)
855 $lexerObjRef = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['lexer'] ?
: \TYPO3\CMS\IndexedSearch\Lexer
::class;
856 $this->lexerObj
= GeneralUtility
::getUserObj($lexerObjRef);
857 // Traverse the search word array
858 foreach ($searchWords as $wordDef) {
859 // No space in word (otherwise it might be a sentense in quotes like "there is").
860 if (strpos($wordDef['sword'], ' ') === false
) {
861 // Split the search word by lexer:
862 $res = $this->lexerObj
->split2Words($wordDef['sword']);
863 // Traverse lexer result and add all words again:
864 foreach ($res as $word) {
865 $newSearchWords[] = array(
867 'oper' => $wordDef['oper']
871 $newSearchWords[] = $wordDef;
874 return $newSearchWords;
878 * Sort options about the search form
880 * @param array $search The search data / params
882 * @ignorevalidation $search
884 public function formAction($search = array())
886 $searchData = $this->initialize($search);
887 // Adding search field value
888 $this->view
->assign('sword', $this->sword
);
889 // Additonal keyword => "Add to current search words"
890 $showAdditionalKeywordSearch = $this->settings
['clearSearchBox'] && $this->settings
['clearSearchBox']['enableSubSearchCheckBox'];
891 if ($showAdditionalKeywordSearch) {
892 $this->view
->assign('previousSearchWord', $this->settings
['clearSearchBox'] ?
'' : $this->sword
);
894 $this->view
->assign('showAdditionalKeywordSearch', $showAdditionalKeywordSearch);
896 if ($search['extendedSearch']) {
898 $allSearchTypes = $this->getAllAvailableSearchTypeOptions();
899 $this->view
->assign('allSearchTypes', $allSearchTypes);
900 $allDefaultOperands = $this->getAllAvailableOperandsOptions();
901 $this->view
->assign('allDefaultOperands', $allDefaultOperands);
902 $showTypeSearch = !empty($allSearchTypes) ||
!empty($allDefaultOperands);
903 $this->view
->assign('showTypeSearch', $showTypeSearch);
905 $allMediaTypes = $this->getAllAvailableMediaTypesOptions();
906 $this->view
->assign('allMediaTypes', $allMediaTypes);
907 $allLanguageUids = $this->getAllAvailableLanguageOptions();
908 $this->view
->assign('allLanguageUids', $allLanguageUids);
909 $showMediaAndLanguageSearch = !empty($allMediaTypes) ||
!empty($allLanguageUids);
910 $this->view
->assign('showMediaAndLanguageSearch', $showMediaAndLanguageSearch);
912 $allSections = $this->getAllAvailableSectionsOptions();
913 $this->view
->assign('allSections', $allSections);
914 // Free Indexing Configurations
915 $allIndexConfigurations = $this->getAllAvailableIndexConfigurationsOptions();
916 $this->view
->assign('allIndexConfigurations', $allIndexConfigurations);
918 $allSortOrders = $this->getAllAvailableSortOrderOptions();
919 $this->view
->assign('allSortOrders', $allSortOrders);
920 $allSortDescendings = $this->getAllAvailableSortDescendingOptions();
921 $this->view
->assign('allSortDescendings', $allSortDescendings);
922 $showSortOrders = !empty($allSortOrders) ||
!empty($allSortDescendings);
923 $this->view
->assign('showSortOrders', $showSortOrders);
925 $allNumberOfResults = $this->getAllAvailableNumberOfResultsOptions();
926 $this->view
->assign('allNumberOfResults', $allNumberOfResults);
927 $allGroups = $this->getAllAvailableGroupOptions();
928 $this->view
->assign('allGroups', $allGroups);
930 $this->view
->assign('searchParams', $searchData);
933 /****************************************
934 * building together the available options for every dropdown
935 ***************************************/
937 * get the values for the "type" selector
939 * @return array Associative array with options
941 protected function getAllAvailableSearchTypeOptions()
943 $allOptions = array();
944 $types = array(0, 1, 2, 3, 10, 20);
945 $blindSettings = $this->settings
['blind'];
946 if (!$blindSettings['searchType']) {
947 foreach ($types as $typeNum) {
948 $allOptions[$typeNum] = LocalizationUtility
::translate('searchTypes.' . $typeNum, 'IndexedSearch');
951 // Remove this option if metaphone search is disabled)
952 if (!$this->enableMetaphoneSearch
) {
953 unset($allOptions[10]);
955 // disable single entries by TypoScript
956 $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['searchType']);
961 * get the values for the "defaultOperand" selector
963 * @return array Associative array with options
965 protected function getAllAvailableOperandsOptions()
967 $allOptions = array();
968 $blindSettings = $this->settings
['blind'];
969 if (!$blindSettings['defaultOperand']) {
971 0 => LocalizationUtility
::translate('defaultOperands.0', 'IndexedSearch'),
972 1 => LocalizationUtility
::translate('defaultOperands.1', 'IndexedSearch')
975 // disable single entries by TypoScript
976 $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['defaultOperand']);
981 * get the values for the "media type" selector
983 * @return array Associative array with options
985 protected function getAllAvailableMediaTypesOptions()
987 $allOptions = array();
988 $mediaTypes = array(-1, 0, -2);
989 $blindSettings = $this->settings
['blind'];
990 if (!$blindSettings['mediaType']) {
991 foreach ($mediaTypes as $mediaType) {
992 $allOptions[$mediaType] = LocalizationUtility
::translate('mediaTypes.' . $mediaType, 'IndexedSearch');
994 // Add media to search in:
995 $additionalMedia = trim($this->settings
['mediaList']);
996 if ($additionalMedia !== '') {
997 $additionalMedia = GeneralUtility
::trimExplode(',', $additionalMedia, true
);
999 $additionalMedia = array();
1001 foreach ($this->externalParsers
as $extension => $obj) {
1002 // Skip unwanted extensions
1003 if (!empty($additionalMedia) && !in_array($extension, $additionalMedia)) {
1006 if ($name = $obj->searchTypeMediaTitle($extension)) {
1007 $translatedName = LocalizationUtility
::translate('mediaTypes.' . $extension, 'IndexedSearch');
1008 $allOptions[$extension] = $translatedName ?
: $name;
1012 // disable single entries by TypoScript
1013 $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['mediaType']);
1018 * get the values for the "language" selector
1020 * @return array Associative array with options
1022 protected function getAllAvailableLanguageOptions()
1024 $allOptions = array(
1025 '-1' => LocalizationUtility
::translate('languageUids.-1', 'IndexedSearch'),
1026 '0' => LocalizationUtility
::translate('languageUids.0', 'IndexedSearch')
1028 $blindSettings = $this->settings
['blind'];
1029 if (!$blindSettings['languageUid']) {
1030 // Add search languages
1031 $res = $this->getDatabaseConnection()->exec_SELECTquery('*', 'sys_language', '1=1' . $GLOBALS['TSFE']->cObj
->enableFields('sys_language'));
1033 while ($lang = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
1034 $allOptions[$lang['uid']] = $lang['title'];
1037 // disable single entries by TypoScript
1038 $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['languageUid']);
1040 $allOptions = array();
1046 * get the values for the "section" selector
1047 * Here values like "rl1_" and "rl2_" + a rootlevel 1/2 id can be added
1048 * to perform searches in rootlevel 1+2 specifically. The id-values can even
1049 * be commaseparated. Eg. "rl1_1,2" would search for stuff inside pages on
1050 * menu-level 1 which has the uid's 1 and 2.
1052 * @return array Associative array with options
1054 protected function getAllAvailableSectionsOptions()
1056 $allOptions = array();
1057 $sections = array(0, -1, -2, -3);
1058 $blindSettings = $this->settings
['blind'];
1059 if (!$blindSettings['sections']) {
1060 foreach ($sections as $section) {
1061 $allOptions[$section] = LocalizationUtility
::translate('sections.' . $section, 'IndexedSearch');
1064 // Creating levels for section menu:
1065 // This selects the first and secondary menus for the "sections" selector - so we can search in sections and sub sections.
1066 if ($this->settings
['displayLevel1Sections']) {
1067 $firstLevelMenu = $this->getMenuOfPages($this->searchRootPageIdList
);
1068 $labelLevel1 = LocalizationUtility
::translate('sections.rootLevel1', 'IndexedSearch');
1069 $labelLevel2 = LocalizationUtility
::translate('sections.rootLevel2', 'IndexedSearch');
1070 foreach ($firstLevelMenu as $firstLevelKey => $menuItem) {
1071 if (!$menuItem['nav_hide']) {
1072 $allOptions['rl1_' . $menuItem['uid']] = trim($labelLevel1 . ' ' . $menuItem['title']);
1073 if ($this->settings
['displayLevel2Sections']) {
1074 $secondLevelMenu = $this->getMenuOfPages($menuItem['uid']);
1075 foreach ($secondLevelMenu as $secondLevelKey => $menuItemLevel2) {
1076 if (!$menuItemLevel2['nav_hide']) {
1077 $allOptions['rl2_' . $menuItemLevel2['uid']] = trim($labelLevel2 . ' ' . $menuItemLevel2['title']);
1079 unset($secondLevelMenu[$secondLevelKey]);
1082 $allOptions['rl2_' . implode(',', array_keys($secondLevelMenu))] = LocalizationUtility
::translate('sections.rootLevel2All', 'IndexedSearch');
1085 unset($firstLevelMenu[$firstLevelKey]);
1088 $allOptions['rl1_' . implode(',', array_keys($firstLevelMenu))] = LocalizationUtility
::translate('sections.rootLevel1All', 'IndexedSearch');
1090 // disable single entries by TypoScript
1091 $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['sections']);
1096 * get the values for the "freeIndexUid" selector
1098 * @return array Associative array with options
1100 protected function getAllAvailableIndexConfigurationsOptions()
1102 $allOptions = array(
1103 '-1' => LocalizationUtility
::translate('indexingConfigurations.-1', 'IndexedSearch'),
1104 '-2' => LocalizationUtility
::translate('indexingConfigurations.-2', 'IndexedSearch'),
1105 '0' => LocalizationUtility
::translate('indexingConfigurations.0', 'IndexedSearch')
1107 $blindSettings = $this->settings
['blind'];
1108 if (!$blindSettings['indexingConfigurations']) {
1109 // add an additional index configuration
1110 if ($this->settings
['defaultFreeIndexUidList']) {
1111 $uidList = GeneralUtility
::intExplode(',', $this->settings
['defaultFreeIndexUidList']);
1112 $indexCfgRecords = $this->getDatabaseConnection()->exec_SELECTgetRows('uid,title', 'index_config', 'uid IN (' . implode(',', $uidList) . ')' . $GLOBALS['TSFE']->cObj
->enableFields('index_config'), '', '', '', 'uid');
1113 foreach ($uidList as $uidValue) {
1114 if (is_array($indexCfgRecords[$uidValue])) {
1115 $allOptions[$uidValue] = $indexCfgRecords[$uidValue]['title'];
1119 // disable single entries by TypoScript
1120 $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['indexingConfigurations']);
1122 $allOptions = array();
1128 * get the values for the "section" selector
1129 * Here values like "rl1_" and "rl2_" + a rootlevel 1/2 id can be added
1130 * to perform searches in rootlevel 1+2 specifically. The id-values can even
1131 * be commaseparated. Eg. "rl1_1,2" would search for stuff inside pages on
1132 * menu-level 1 which has the uid's 1 and 2.
1134 * @return array Associative array with options
1136 protected function getAllAvailableSortOrderOptions()
1138 $allOptions = array();
1139 $sortOrders = array('rank_flag', 'rank_freq', 'rank_first', 'rank_count', 'mtime', 'title', 'crdate');
1140 $blindSettings = $this->settings
['blind'];
1141 if (!$blindSettings['sortOrder']) {
1142 foreach ($sortOrders as $order) {
1143 $allOptions[$order] = LocalizationUtility
::translate('sortOrders.' . $order, 'IndexedSearch');
1146 // disable single entries by TypoScript
1147 $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['sortOrder.']);
1152 * get the values for the "group" selector
1154 * @return array Associative array with options
1156 protected function getAllAvailableGroupOptions()
1158 $allOptions = array();
1159 $blindSettings = $this->settings
['blind'];
1160 if (!$blindSettings['groupBy']) {
1161 $allOptions = array(
1162 'sections' => LocalizationUtility
::translate('groupBy.sections', 'IndexedSearch'),
1163 'flat' => LocalizationUtility
::translate('groupBy.flat', 'IndexedSearch')
1166 // disable single entries by TypoScript
1167 $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['groupBy.']);
1172 * get the values for the "sortDescending" selector
1174 * @return array Associative array with options
1176 protected function getAllAvailableSortDescendingOptions()
1178 $allOptions = array();
1179 $blindSettings = $this->settings
['blind'];
1180 if (!$blindSettings['descending']) {
1181 $allOptions = array(
1182 0 => LocalizationUtility
::translate('sortOrders.descending', 'IndexedSearch'),
1183 1 => LocalizationUtility
::translate('sortOrders.ascending', 'IndexedSearch')
1186 // disable single entries by TypoScript
1187 $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['descending.']);
1192 * get the values for the "results" selector
1194 * @return array Associative array with options
1196 protected function getAllAvailableNumberOfResultsOptions()
1198 $allOptions = array();
1199 $blindSettings = $this->settings
['blind'];
1200 if (!$blindSettings['numberOfResults']) {
1201 $allOptions = array(
1208 // disable single entries by TypoScript
1209 $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['numberOfResults']);
1214 * removes blinding entries from the option list of a selector
1216 * @param array $allOptions associative array containing all options
1217 * @param array $blindOptions associative array containing the optionkey as they key and the value = 1 if it should be removed
1218 * @return array Options from $allOptions with some options removed
1220 protected function removeOptionsFromOptionList($allOptions, $blindOptions)
1222 if (is_array($blindOptions)) {
1223 foreach ($blindOptions as $key => $val) {
1225 unset($allOptions[$key]);
1233 * Links the $linkText to page $pageUid
1235 * @param int $pageUid Page id
1236 * @param string $linkText Title String to link
1237 * @param array $row Result row
1238 * @param array $markUpSwParams Additional parameters for marking up seach words
1239 * @return string <A> tag wrapped title string.
1240 * @todo make use of the UriBuilder
1242 protected function linkPage($pageUid, $linkText, $row = array(), $markUpSwParams = array())
1244 // Parameters for link
1245 $urlParameters = (array)unserialize($row['cHashParams']);
1246 // Add &type and &MP variable:
1247 if ($row['data_page_mp']) {
1248 $urlParameters['MP'] = $row['data_page_mp'];
1250 if ($row['sys_language_uid']) {
1251 $urlParameters['L'] = $row['sys_language_uid'];
1254 $urlParameters = array_merge($urlParameters, $markUpSwParams);
1255 // This will make sure that the path is retrieved if it hasn't been
1256 // already. Used only for the sake of the domain_record thing.
1257 if (!is_array($this->domainRecords
[$pageUid])) {
1258 $this->getPathFromPageId($pageUid);
1261 // If external domain, then link to that:
1262 if (!empty($this->domainRecords
[$pageUid])) {
1263 $scheme = GeneralUtility
::getIndpEnv('TYPO3_SSL') ?
'https://' : 'http://';
1264 $firstDomain = reset($this->domainRecords
[$pageUid]);
1265 $additionalParams = '';
1266 if (is_array($urlParameters) && !empty($urlParameters)) {
1267 $additionalParams = GeneralUtility
::implodeArrayForUrl('', $urlParameters);
1269 $uri = $scheme . $firstDomain . '/index.php?id=' . $pageUid . $additionalParams;
1270 if ($target = $this->settings
['detectDomainRecords.']['target']) {
1271 $target = ' target="' . $target . '"';
1274 $uriBuilder = $this->controllerContext
->getUriBuilder();
1275 $uri = $uriBuilder->setTargetPageUid($pageUid)->setTargetPageType($row['data_page_type'])->setUseCacheHash(true
)->setArguments($urlParameters)->build();
1277 return '<a href="' . htmlspecialchars($uri) . '"' . $target . '>' . htmlspecialchars($linkText) . '</a>';
1281 * Return the menu of pages used for the selector.
1283 * @param int $pageUid Page ID for which to return menu
1284 * @return array Menu items (for making the section selector box)
1286 protected function getMenuOfPages($pageUid)
1288 if ($this->settings
['displayLevelxAllTypes']) {
1290 $res = $this->getDatabaseConnection()->exec_SELECTquery('title,uid', 'pages', 'pid=' . (int)$pageUid . $GLOBALS['TSFE']->cObj
->enableFields('pages'), '', 'sorting');
1291 while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
1292 $menu[$row['uid']] = $GLOBALS['TSFE']->sys_page
->getPageOverlay($row);
1294 $this->getDatabaseConnection()->sql_free_result($res);
1296 $menu = $GLOBALS['TSFE']->sys_page
->getMenu($pageUid);
1302 * Returns the path to the page $id
1304 * @param int $id Page ID
1305 * @param string $pathMP Content of the MP (mount point) variable
1306 * @return string Path (HTML-escaped)
1308 protected function getPathFromPageId($id, $pathMP = '')
1310 $identStr = $id . '|' . $pathMP;
1311 if (!isset($this->pathCache
[$identStr])) {
1312 $this->requiredFrontendUsergroups
[$id] = array();
1313 $this->domainRecords
[$id] = array();
1314 $rl = $GLOBALS['TSFE']->sys_page
->getRootLine($id, $pathMP);
1316 $pageCount = count($rl);
1317 if (is_array($rl) && !empty($rl)) {
1318 $breadcrumbWrap = isset($this->settings
['breadcrumbWrap']) ?
$this->settings
['breadcrumbWrap'] : '/';
1319 $breadcrumbWraps = $GLOBALS['TSFE']->tmpl
->splitConfArray(array('wrap' => $breadcrumbWrap), $pageCount);
1320 foreach ($rl as $k => $v) {
1322 if ($v['fe_group'] && ($v['uid'] == $id ||
$v['extendToSubpages'])) {
1323 $this->requiredFrontendUsergroups
[$id][] = $v['fe_group'];
1326 if ($this->settings
['detectDomainRcords']) {
1327 $domainName = $this->getFirstSysDomainRecordForPage($v['uid']);
1329 $this->domainRecords
[$id][] = $domainName;
1330 // Set path accordingly
1331 $path = $domainName . $path;
1335 // Stop, if we find that the current id is the current root page.
1336 if ($v['uid'] == $GLOBALS['TSFE']->config
['rootLine'][0]['uid']) {
1337 array_pop($breadcrumbWraps);
1340 $path = $GLOBALS['TSFE']->cObj
->wrap(htmlspecialchars($v['title']), array_pop($breadcrumbWraps)['wrap']) . $path;
1343 $this->pathCache
[$identStr] = $path;
1345 return $this->pathCache
[$identStr];
1349 * Gets the first sys_domain record for the page, $id
1351 * @param int $id Page id
1352 * @return string Domain name
1354 protected function getFirstSysDomainRecordForPage($id)
1356 $res = $this->getDatabaseConnection()->exec_SELECTquery('domainName', 'sys_domain', 'pid=' . (int)$id . $GLOBALS['TSFE']->cObj
->enableFields('sys_domain'), '', 'sorting');
1357 $row = $this->getDatabaseConnection()->sql_fetch_assoc($res);
1358 return rtrim($row['domainName'], '/');
1362 * simple function to initialize possible external parsers
1363 * feeds the $this->externalParsers array
1367 protected function initializeExternalParsers()
1369 // Initialize external document parsers for icon display and other soft operations
1370 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['external_parsers'])) {
1371 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['external_parsers'] as $extension => $_objRef) {
1372 $this->externalParsers
[$extension] = GeneralUtility
::getUserObj($_objRef);
1373 // Init parser and if it returns FALSE, unset its entry again
1374 if (!$this->externalParsers
[$extension]->softInit($extension)) {
1375 unset($this->externalParsers
[$extension]);
1382 * Returns an object reference to the hook object if any
1384 * @param string $functionName Name of the function you want to call / hook key
1385 * @return object|NULL Hook object, if any. Otherwise NULL.
1387 protected function hookRequest($functionName)
1389 // Hook: menuConfig_preProcessModMenu
1390 if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['pi1_hooks'][$functionName]) {
1391 $hookObj = GeneralUtility
::getUserObj($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['pi1_hooks'][$functionName]);
1392 if (method_exists($hookObj, $functionName)) {
1393 $hookObj->pObj
= $this;
1401 * Returns if an item type is a multipage item type
1403 * @param string $item_type Item type
1404 * @return bool TRUE if multipage capable
1406 protected function multiplePagesType($item_type)
1408 return is_object($this->externalParsers
[$item_type]) && $this->externalParsers
[$item_type]->isMultiplePageExtension($item_type);
1412 * Getter for database connection
1414 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1416 protected function getDatabaseConnection()
1418 return $GLOBALS['TYPO3_DB'];
1423 * Load settings and apply stdWrap to them
1425 protected function loadSettings()
1427 if (!is_array($this->settings
['results.'])) {
1428 $this->settings
['results.'] = array();
1430 $typoScriptArray = $this->typoScriptService
->convertPlainArrayToTypoScriptArray($this->settings
['results']);
1432 $this->settings
['results.']['summaryCropAfter'] = MathUtility
::forceIntegerInRange(
1433 $GLOBALS['TSFE']->cObj
->stdWrap($typoScriptArray['summaryCropAfter'], $typoScriptArray['summaryCropAfter.']),
1436 $this->settings
['results.']['summaryCropSignifier'] = $GLOBALS['TSFE']->cObj
->stdWrap($typoScriptArray['summaryCropSignifier'], $typoScriptArray['summaryCropSignifier.']);
1437 $this->settings
['results.']['titleCropAfter'] = MathUtility
::forceIntegerInRange(
1438 $GLOBALS['TSFE']->cObj
->stdWrap($typoScriptArray['titleCropAfter'], $typoScriptArray['titleCropAfter.']),
1441 $this->settings
['results.']['titleCropSignifier'] = $GLOBALS['TSFE']->cObj
->stdWrap($typoScriptArray['titleCropSignifier'], $typoScriptArray['titleCropSignifier.']);
1442 $this->settings
['results.']['markupSW_summaryMax'] = MathUtility
::forceIntegerInRange(
1443 $GLOBALS['TSFE']->cObj
->stdWrap($typoScriptArray['markupSW_summaryMax'], $typoScriptArray['markupSW_summaryMax.']),
1446 $this->settings
['results.']['markupSW_postPreLgd'] = MathUtility
::forceIntegerInRange(
1447 $GLOBALS['TSFE']->cObj
->stdWrap($typoScriptArray['markupSW_postPreLgd'], $typoScriptArray['markupSW_postPreLgd.']),
1450 $this->settings
['results.']['markupSW_postPreLgd_offset'] = MathUtility
::forceIntegerInRange(
1451 $GLOBALS['TSFE']->cObj
->stdWrap($typoScriptArray['markupSW_postPreLgd_offset'], $typoScriptArray['markupSW_postPreLgd_offset.']),
1454 $this->settings
['results.']['markupSW_divider'] = $GLOBALS['TSFE']->cObj
->stdWrap($typoScriptArray['markupSW_divider'], $typoScriptArray['markupSW_divider.']);
1455 $this->settings
['results.']['hrefInSummaryCropAfter'] = MathUtility
::forceIntegerInRange(
1456 $GLOBALS['TSFE']->cObj
->stdWrap($typoScriptArray['hrefInSummaryCropAfter'], $typoScriptArray['hrefInSummaryCropAfter.']),
1459 $this->settings
['results.']['hrefInSummaryCropSignifier'] = $GLOBALS['TSFE']->cObj
->stdWrap($typoScriptArray['hrefInSummaryCropSignifier'], $typoScriptArray['hrefInSummaryCropSignifier.']);