TYPO3 CMS  TYPO3_6-2
SearchController.php
Go to the documentation of this file.
1 <?php
3 
18 
30 
31  // previously known as $this->piVars['sword']
32  protected $sword = NULL;
33 
34  protected $searchWords = array();
35 
36  protected $searchData;
37 
47  protected $searchRootPageIdList = 0;
48 
49  protected $defaultResultNumber = 10;
50 
56  protected $searchRepository = NULL;
57 
63  protected $lexerObj;
64 
69  protected $externalParsers = array();
70 
76  protected $firstRow = array();
77 
83  protected $domainRecords = array();
84 
90  protected $requiredFrontendUsergroups = array();
91 
97  protected $resultSections = array();
98 
104  protected $pathCache = array();
105 
111  protected $iconFileNameCache = array();
112 
118  protected $indexerConfig = array();
119 
125  protected $enableMetaphoneSearch = FALSE;
126 
132 
139  public function initialize($searchData = array()) {
140  if (!is_array($searchData)) {
141  $searchData = array();
142  }
143  // setting default values
144  if (is_array($this->settings['defaultOptions'])) {
145  $searchData = array_merge($this->settings['defaultOptions'], $searchData);
146  }
147  // Indexer configuration from Extension Manager interface:
148  $this->indexerConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['indexed_search']);
149  $this->enableMetaphoneSearch = $this->indexerConfig['enableMetaphoneSearch'] ? TRUE : FALSE;
150  $this->initializeExternalParsers();
151  // If "_sections" is set, this value overrides any existing value.
152  if ($searchData['_sections']) {
153  $searchData['sections'] = $searchData['_sections'];
154  }
155  // If "_sections" is set, this value overrides any existing value.
156  if ($searchData['_freeIndexUid'] !== '' && $searchData['_freeIndexUid'] !== '_') {
157  $searchData['freeIndexUid'] = $searchData['_freeIndexUid'];
158  }
159  $searchData['numberOfResults'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($searchData['numberOfResults'], 1, 100, $this->defaultResultNumber);
160  // This gets the search-words into the $searchWordArray
161  $this->sword = $searchData['sword'];
162  // Add previous search words to current
163  if ($searchData['sword_prev_include'] && $searchData['sword_prev']) {
164  $this->sword = trim($searchData['sword_prev']) . ' ' . $this->sword;
165  }
166  $this->searchWords = $this->getSearchWords($searchData['defaultOperand']);
167  // This is the id of the site root.
168  // This value may be a commalist of integer (prepared for this)
169  $this->searchRootPageIdList = (int)$GLOBALS['TSFE']->config['rootLine'][0]['uid'];
170  // Setting the list of root PIDs for the search. Notice, these page IDs MUST
171  // have a TypoScript template with root flag on them! Basically this list is used
172  // to select on the "rl0" field and page ids are registered as "rl0" only if
173  // a TypoScript template record with root flag is there.
174  // This happens AFTER the use of $this->searchRootPageIdList above because
175  // the above will then fetch the menu for the CURRENT site - regardless
176  // of this kind of searching here. Thus a general search will lookup in
177  // the WHOLE database while a specific section search will take the current sections.
178  if ($this->settings['rootPidList']) {
179  $this->searchRootPageIdList = implode(',', GeneralUtility::intExplode(',', $this->settings['rootPidList']));
180  }
181  $this->searchRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\IndexedSearch\\Domain\\Repository\\IndexSearchRepository');
182  $this->searchRepository->initialize($this->settings, $searchData, $this->externalParsers, $this->searchRootPageIdList);
183  $this->searchData = $searchData;
184  // Calling hook for modification of initialized content
185  if ($hookObj = $this->hookRequest('initialize_postProc')) {
186  $hookObj->initialize_postProc();
187  }
188  return $searchData;
189  }
190 
198  public function searchAction($search = array()) {
199  $searchData = $this->initialize($search);
200  // Find free index uid:
201  $freeIndexUid = $searchData['freeIndexUid'];
202  if ($freeIndexUid == -2) {
203  $freeIndexUid = $this->settings['defaultFreeIndexUidList'];
204  } elseif (!isset($searchData['freeIndexUid'])) {
205  // index configuration is disabled
206  $freeIndexUid = -1;
207  }
208  $indexCfgs = GeneralUtility::intExplode(',', $freeIndexUid);
209  $resultsets = array();
210  foreach ($indexCfgs as $freeIndexUid) {
211  // Get result rows
212  $tstamp1 = GeneralUtility::milliseconds();
213  if ($hookObj = $this->hookRequest('getResultRows')) {
214  $resultData = $hookObj->getResultRows($this->searchWords, $freeIndexUid);
215  } else {
216  $resultData = $this->searchRepository->doSearch($this->searchWords, $freeIndexUid);
217  }
218  // Display search results
219  $tstamp2 = GeneralUtility::milliseconds();
220  if ($hookObj = $this->hookRequest('getDisplayResults')) {
221  $resultsets[$freeIndexUid] = $hookObj->getDisplayResults($this->searchWords, $resultData, $freeIndexUid);
222  } else {
223  $resultsets[$freeIndexUid] = $this->getDisplayResults($this->searchWords, $resultData, $freeIndexUid);
224  }
225  $tstamp3 = GeneralUtility::milliseconds();
226  // Create header if we are searching more than one indexing configuration
227  if (count($indexCfgs) > 1) {
228  if ($freeIndexUid > 0) {
229  $indexCfgRec = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('title', 'index_config', 'uid=' . (int)$freeIndexUid . $GLOBALS['TSFE']->cObj->enableFields('index_config'));
230  $categoryTitle = $indexCfgRec['title'];
231  } else {
232  $categoryTitle = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('indexingConfigurationHeader.' . $freeIndexUid, 'IndexedSearch');
233  }
234  $resultsets[$freeIndexUid]['categoryTitle'] = $categoryTitle;
235  }
236  // Write search statistics
237  $this->writeSearchStat($searchData, $this->searchWords, $resultData['count'], array($tstamp1, $tstamp2, $tstamp3));
238  }
239  $this->view->assign('resultsets', $resultsets);
240  $this->view->assign('searchParams', $searchData);
241  $this->view->assign('searchWords', $this->searchWords);
242  }
243 
244  /****************************************
245  * functions to make the result rows and result sets
246  * ready for the output
247  ***************************************/
256  protected function getDisplayResults($searchWords, $resultData, $freeIndexUid = -1) {
257  $result = array(
258  'count' => $resultData['count'],
259  'searchWords' => $searchWords
260  );
261  // Perform display of result rows array
262  if ($resultData) {
263  // Set first selected row (for calculation of ranking later)
264  $this->firstRow = $resultData['firstRow'];
265  // Result display here
266  $result['rows'] = $this->compileResultRows($resultData['resultRows'], $freeIndexUid);
267  $result['affectedSections'] = $this->resultSections;
268  // Browsing box
269  if ($resultData['count']) {
270  // could we get this in the view?
271  if ($this->searchData['group'] == 'sections' && $freeIndexUid <= 0) {
272  $result['sectionText'] = sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('result.' . (count($this->resultSections) > 1 ? 'inNsections' : 'inNsection'), 'IndexedSearch'), count($this->resultSections));
273  }
274  }
275  }
276  // Print a message telling which words in which sections we searched for
277  if (substr($this->searchData['sections'], 0, 2) == 'rl') {
278  $result['searchedInSectionInfo'] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('result.inSection', 'IndexedSearch') . ' "' . preg_replace('#^/#', '', $this->getPathFromPageId(substr($this->searchData['sections'], 4))) . '"';
279  }
280  return $result;
281  }
282 
291  protected function compileResultRows($resultRows, $freeIndexUid = -1) {
292  $finalResultRows = array();
293  // Transfer result rows to new variable,
294  // performing some mapping of sub-results etc.
295  $newResultRows = array();
296  foreach ($resultRows as $row) {
297  $id = md5($row['phash_grouping']);
298  if (is_array($newResultRows[$id])) {
299  // swapping:
300  if (!$newResultRows[$id]['show_resume'] && $row['show_resume']) {
301  // Remove old
302  $subrows = $newResultRows[$id]['_sub'];
303  unset($newResultRows[$id]['_sub']);
304  $subrows[] = $newResultRows[$id];
305  // Insert new:
306  $newResultRows[$id] = $row;
307  $newResultRows[$id]['_sub'] = $subrows;
308  } else {
309  $newResultRows[$id]['_sub'][] = $row;
310  }
311  } else {
312  $newResultRows[$id] = $row;
313  }
314  }
315  $resultRows = $newResultRows;
316  $this->resultSections = array();
317  if ($freeIndexUid <= 0 && $this->searchData['group'] == 'sections') {
318  $rl2flag = substr($this->searchData['sections'], 0, 2) == 'rl';
319  $sections = array();
320  foreach ($resultRows as $row) {
321  $id = $row['rl0'] . '-' . $row['rl1'] . ($rl2flag ? '-' . $row['rl2'] : '');
322  $sections[$id][] = $row;
323  }
324  $this->resultSections = array();
325  foreach ($sections as $id => $resultRows) {
326  $rlParts = explode('-', $id);
327  if ($rlParts[2]) {
328  $theId = $rlParts[2];
329  $theRLid = 'rl2_' . $rlParts[2];
330  } elseif ($rlParts[1]) {
331  $theId = $rlParts[1];
332  $theRLid = 'rl1_' . $rlParts[1];
333  } else {
334  $theId = $rlParts[0];
335  $theRLid = '0';
336  }
337  $sectionName = $this->getPathFromPageId($theId);
338  $sectionName = ltrim($sectionName, '/');
339  if (!trim($sectionName)) {
340  $sectionTitleLinked = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('result.unnamedSection', 'IndexedSearch') . ':';
341  } else {
342  $onclick = 'document.forms[\'tx_indexedsearch\'][\'tx_indexedsearch_pi2[search][_sections]\'].value=' . GeneralUtility::quoteJSvalue($theRLid) . ';document.forms[\'tx_indexedsearch\'].submit();return false;';
343  $sectionTitleLinked = '<a href="#" onclick="' . htmlspecialchars($onclick) . '">' . htmlspecialchars($sectionName) . ':</a>';
344  }
345  $this->resultSections[$id] = array($sectionName, count($resultRows));
346  // Add section header
347  $finalResultRows[] = array(
348  'isSectionHeader' => TRUE,
349  'numResultRows' => count($resultRows),
350  'sectionId' => $id,
351  'sectionTitle' => $sectionTitleLinked
352  );
353  // Render result rows
354  foreach ($resultRows as $row) {
355  $finalResultRows[] = $this->compileSingleResultRow($row);
356  }
357  }
358  } else {
359  // flat mode or no sections at all
360  foreach ($resultRows as $row) {
361  $finalResultRows[] = $this->compileSingleResultRow($row);
362  }
363  }
364  return $finalResultRows;
365  }
366 
374  protected function compileSingleResultRow($row, $headerOnly = 0) {
375  $specRowConf = $this->getSpecialConfigurationForResultRow($row);
376  $resultData = $row;
377  $resultData['headerOnly'] = $headerOnly;
378  $resultData['CSSsuffix'] = $specRowConf['CSSsuffix'] ? '-' . $specRowConf['CSSsuffix'] : '';
379  if ($this->multiplePagesType($row['item_type'])) {
380  $dat = unserialize($row['cHashParams']);
381  $pp = explode('-', $dat['key']);
382  if ($pp[0] != $pp[1]) {
383  $resultData['titleaddition'] = ', ' . \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('result.page', 'IndexedSearch') . ' ' . $dat['key'];
384  } else {
385  $resultData['titleaddition'] = ', ' . \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('result.pages', 'IndexedSearch') . ' ' . $pp[0];
386  }
387  }
388  $title = $resultData['item_title'] . $resultData['titleaddition'];
389  // If external media, link to the media-file instead.
390  if ($row['item_type']) {
391  if ($row['show_resume']) {
392  // Can link directly.
393  $targetAttribute = '';
394  if ($GLOBALS['TSFE']->config['config']['fileTarget']) {
395  $targetAttribute = ' target="' . htmlspecialchars($GLOBALS['TSFE']->config['config']['fileTarget']) . '"';
396  }
397  $title = '<a href="' . htmlspecialchars($row['data_filename']) . '"' . $targetAttribute . '>' . htmlspecialchars($title) . '</a>';
398  } else {
399  // Suspicious, so linking to page instead...
400  $copiedRow = $row;
401  unset($copiedRow['cHashParams']);
402  $title = $this->linkPage($row['page_id'], $title, $copiedRow);
403  }
404  } else {
405  // Else the page:
406  // Prepare search words for markup in content:
407  if ($this->settings['forwardSearchWordsInResultLink']) {
408  $markUpSwParams = array('no_cache' => 1);
409  foreach ($this->searchWords as $d) {
410  $markUpSwParams['sword_list'][] = $d['sword'];
411  }
412  } else {
413  $markUpSwParams = array();
414  }
415  $title = $this->linkPage($row['data_page_id'], $title, $row, $markUpSwParams);
416  }
417  $resultData['title'] = $title;
418  $resultData['icon'] = $this->makeItemTypeIcon($row['item_type'], '', $specRowConf);
419  $resultData['rating'] = $this->makeRating($row);
420  $resultData['description'] = $this->makeDescription($row, $this->searchData['extResume'] && !$headerOnly ? 0 : 1);
421  $resultData['language'] = $this->makeLanguageIndication($row);
422  $resultData['size'] = GeneralUtility::formatSize($row['item_size']);
423  $resultData['created'] = $row['item_crdate'];
424  $resultData['modified'] = $row['item_mtime'];
425  $pI = parse_url($row['data_filename']);
426  if ($pI['scheme']) {
427  $targetAttribute = '';
428  if ($GLOBALS['TSFE']->config['config']['fileTarget']) {
429  $targetAttribute = ' target="' . htmlspecialchars($GLOBALS['TSFE']->config['config']['fileTarget']) . '"';
430  }
431  $resultData['path'] = '<a href="' . htmlspecialchars($row['data_filename']) . '"' . $targetAttribute . '>' . htmlspecialchars($row['data_filename']) . '</a>';
432  } else {
433  $pathId = $row['data_page_id'] ?: $row['page_id'];
434  $pathMP = $row['data_page_id'] ? $row['data_page_mp'] : '';
435  $pathStr = $this->getPathFromPageId($pathId, $pathMP);
436  $resultData['path'] = $this->linkPage($pathId, $pathStr, array(
437  'cHashParams' => $row['cHashParams'],
438  'data_page_type' => $row['data_page_type'],
439  'data_page_mp' => $pathMP,
440  'sys_language_uid' => $row['sys_language_uid']
441  ));
442  // check if the access is restricted
443  if (is_array($this->requiredFrontendUsergroups[$pathId]) && count($this->requiredFrontendUsergroups[$pathId])) {
444  $resultData['access'] = '<img src="' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('indexed_search') . 'pi/res/locked.gif" width="12" height="15" vspace="5" title="' . sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('result.memberGroups', 'IndexedSearch'), implode(',', array_unique($this->requiredFrontendUsergroups[$pathId]))) . '" alt="" />';
445  }
446  }
447  // If there are subrows (eg. subpages in a PDF-file or if a duplicate page
448  // is selected due to user-login (phash_grouping))
449  if (is_array($row['_sub'])) {
450  $resultData['subresults'] = array();
451  if ($this->multiplePagesType($row['item_type'])) {
452  $resultData['subresults']['header'] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('result.otherMatching', 'IndexedSearch');
453  foreach ($row['_sub'] as $subRow) {
454  $resultData['subresults']['items'][] = $this->compileSingleResultRow($subRow, 1);
455  }
456  } else {
457  $resultData['subresults']['header'] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('result.otherMatching', 'IndexedSearch');
458  $resultData['subresults']['info'] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('result.otherPageAsWell', 'IndexedSearch');
459  }
460  }
461  return $resultData;
462  }
463 
471  protected function getSpecialConfigurationForResultRow($row) {
472  $pathId = $row['data_page_id'] ?: $row['page_id'];
473  $pathMP = $row['data_page_id'] ? $row['data_page_mp'] : '';
474  $rl = $GLOBALS['TSFE']->sys_page->getRootLine($pathId, $pathMP);
475  $specConf = $this->settings['specialConfiguration']['0'];
476  if (is_array($rl)) {
477  foreach ($rl as $dat) {
478  if (is_array($this->settings['specialConfiguration'][$dat['uid']])) {
479  $specConf = $this->settings['specialConfiguration'][$dat['uid']];
480  $specConf['_pid'] = $dat['uid'];
481  break;
482  }
483  }
484  }
485  return $specConf;
486  }
487 
495  protected function makeRating($row) {
496  switch ((string) $this->searchData['sortOrder']) {
497  case 'rank_count':
498  return $row['order_val'] . ' ' . \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('result.ratingMatches', 'IndexedSearch');
499  break;
500  case 'rank_first':
501  return ceil(\TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((255 - $row['order_val']), 1, 255) / 255 * 100) . '%';
502  break;
503  case 'rank_flag':
504  if ($this->firstRow['order_val2']) {
505  // (3 MSB bit, 224 is highest value of order_val1 currently)
506  $base = $row['order_val1'] * 256;
507  // 15-3 MSB = 12
508  $freqNumber = $row['order_val2'] / $this->firstRow['order_val2'] * pow(2, 12);
509  $total = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($base + $freqNumber, 0, 32767);
510  return ceil(log($total) / log(32767) * 100) . '%';
511  }
512  break;
513  case 'rank_freq':
514  $max = 10000;
515  $total = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($row['order_val'], 0, $max);
516  return ceil(log($total) / log($max) * 100) . '%';
517  break;
518  case 'crdate':
519  return $GLOBALS['TSFE']->cObj->calcAge($GLOBALS['EXEC_TIME'] - $row['item_crdate'], 0);
520  break;
521  case 'mtime':
522  return $GLOBALS['TSFE']->cObj->calcAge($GLOBALS['EXEC_TIME'] - $row['item_mtime'], 0);
523  break;
524  default:
525  return ' ';
526  }
527  }
528 
535  protected function makeLanguageIndication($row) {
536  $output = '&nbsp;';
537  // If search result is a TYPO3 page:
538  if ((string) $row['item_type'] === '0') {
539  // If TypoScript is used to render the flag:
540  if (is_array($this->settings['flagRendering'])) {
542  $cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
543  $cObj->setCurrentVal($row['sys_language_uid']);
544  $typoScriptArray = $this->typoScriptService->convertPlainArrayToTypoScriptArray($this->settings['flagRendering']);
545  $output = $cObj->cObjGetSingle($this->settings['flagRendering']['_typoScriptNodeValue'], $typoScriptArray);
546  } else {
547  // ... otherwise, get flag from sys_language record:
548  $languageRow = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('flag, title', 'sys_language', 'uid=' . (int)$row['sys_language_uid'] . $GLOBALS['TSFE']->cObj->enableFields('sys_language'));
549  // Flag code:
550  $flag = $languageRow['flag'];
551  if ($flag) {
552  // FIXME not all flags from typo3/gfx/flags
553  // are available in media/flags/
554  $file = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix(PATH_tslib) . 'media/flags/flag_' . $flag;
555  $imgInfo = @getimagesize((PATH_site . $file));
556  if (is_array($imgInfo)) {
557  $output = '<img src="' . $file . '" ' . $imgInfo[3] . ' title="' . htmlspecialchars($languageRow['title']) . '" alt="' . htmlspecialchars($languageRow['title']) . '" />';
558  }
559  }
560  }
561  }
562  return $output;
563  }
564 
574  public function makeItemTypeIcon($imageType, $alt, $specRowConf) {
575  // Build compound key if item type is 0, iconRendering is not used
576  // and specialConfiguration.[pid].pageIcon was set in TS
577  if ($imageType === '0' && $specRowConf['_pid'] && is_array($specRowConf['pageIcon']) && !is_array($this->settings['iconRendering'])) {
578  $imageType .= ':' . $specRowConf['_pid'];
579  }
580  if (!isset($this->iconFileNameCache[$imageType])) {
581  $this->iconFileNameCache[$imageType] = '';
582  // If TypoScript is used to render the icon:
583  if (is_array($this->settings['iconRendering'])) {
585  $cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
586  $cObj->setCurrentVal($imageType);
587  $typoScriptArray = $this->typoScriptService->convertPlainArrayToTypoScriptArray($this->settings['iconRendering']);
588  $this->iconFileNameCache[$imageType] = $cObj->cObjGetSingle($this->settings['iconRendering']['_typoScriptNodeValue'], $typoScriptArray);
589  } else {
590  // Default creation / finding of icon:
591  $icon = '';
592  if ($imageType === '0' || substr($imageType, 0, 2) == '0:') {
593  if (is_array($specRowConf['pageIcon'])) {
594  $this->iconFileNameCache[$imageType] = $GLOBALS['TSFE']->cObj->cObjGetSingle('IMAGE', $specRowConf['pageIcon']);
595  } else {
596  $icon = 'EXT:indexed_search/pi/res/pages.gif';
597  }
598  } elseif ($this->externalParsers[$imageType]) {
599  $icon = $this->externalParsers[$imageType]->getIcon($imageType);
600  }
601  if ($icon) {
602  $fullPath = GeneralUtility::getFileAbsFileName($icon);
603  if ($fullPath) {
604  $info = @getimagesize($fullPath);
606  $this->iconFileNameCache[$imageType] = is_array($info) ? '<img src="' . $iconPath . '" ' . $info[3] . ' title="' . htmlspecialchars($alt) . '" alt="" />' : '';
607  }
608  }
609  }
610  }
611  return $this->iconFileNameCache[$imageType];
612  }
613 
623  protected function makeDescription($row, $noMarkup = FALSE, $length = 180) {
624  if ($row['show_resume']) {
625  if (!$noMarkup) {
626  $markedSW = '';
627  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'index_fulltext', 'phash=' . (int)$row['phash']);
628  if ($ftdrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
629  // Cut HTTP references after some length
630  $content = preg_replace('/(http:\\/\\/[^ ]{60})([^ ]+)/i', '$1...', $ftdrow['fulltextdata']);
631  $markedSW = $this->markupSWpartsOfString($content);
632  }
633  $GLOBALS['TYPO3_DB']->sql_free_result($res);
634  }
635  if (!trim($markedSW)) {
636  $outputStr = $GLOBALS['TSFE']->csConvObj->crop('utf-8', $row['item_description'], $length);
637  $outputStr = htmlspecialchars($outputStr);
638  }
639  $output = $outputStr ?: $markedSW;
640  $output = $GLOBALS['TSFE']->csConv($output, 'utf-8');
641  } else {
642  $output = '<span class="noResume">' . \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('result.noResume', 'IndexedSearch') . '</span>';
643  }
644  return $output;
645  }
646 
653  protected function markupSWpartsOfString($str) {
654  $htmlParser = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Html\\HtmlParser');
655  // Init:
656  $str = str_replace('&nbsp;', ' ', $htmlParser->bidir_htmlspecialchars($str, -1));
657  $str = preg_replace('/\\s\\s+/', ' ', $str);
658  $swForReg = array();
659  // Prepare search words for regex:
660  foreach ($this->searchWords as $d) {
661  $swForReg[] = preg_quote($d['sword'], '/');
662  }
663  $regExString = '(' . implode('|', $swForReg) . ')';
664  // Split and combine:
665  $parts = preg_split('/' . $regExString . '/i', ' ' . $str . ' ', 20000, PREG_SPLIT_DELIM_CAPTURE);
666  // Constants:
667  $summaryMax = 300;
668  $postPreLgd = 60;
669  $postPreLgd_offset = 5;
670  $divider = ' ... ';
671  $occurencies = (count($parts) - 1) / 2;
672  if ($occurencies) {
673  $postPreLgd = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($summaryMax / $occurencies, $postPreLgd, $summaryMax / 2);
674  }
675  // Variable:
676  $summaryLgd = 0;
677  $output = array();
678  // Shorten in-between strings:
679  foreach ($parts as $k => $strP) {
680  if ($k % 2 == 0) {
681  // Find length of the summary part:
682  $strLen = $GLOBALS['TSFE']->csConvObj->strlen('utf-8', $parts[$k]);
683  $output[$k] = $parts[$k];
684  // Possibly shorten string:
685  if (!$k) {
686  // First entry at all (only cropped on the frontside)
687  if ($strLen > $postPreLgd) {
688  $output[$k] = $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $GLOBALS['TSFE']->csConvObj->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
689  }
690  } elseif ($summaryLgd > $summaryMax || !isset($parts[($k + 1)])) {
691  // In case summary length is exceed OR if there are no more entries at all:
692  if ($strLen > $postPreLgd) {
693  $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $GLOBALS['TSFE']->csConvObj->crop('utf-8', $parts[$k], ($postPreLgd - $postPreLgd_offset))) . $divider;
694  }
695  } else {
696  if ($strLen > $postPreLgd * 2) {
697  $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)));
698  }
699  }
700  $summaryLgd += $GLOBALS['TSFE']->csConvObj->strlen('utf-8', $output[$k]);
701  // Protect output:
702  $output[$k] = htmlspecialchars($output[$k]);
703  // If summary lgd is exceed, break the process:
704  if ($summaryLgd > $summaryMax) {
705  break;
706  }
707  } else {
708  $summaryLgd += $GLOBALS['TSFE']->csConvObj->strlen('utf-8', $strP);
709  $output[$k] = '<strong class="tx-indexedsearch-redMarkup">' . htmlspecialchars($parts[$k]) . '</strong>';
710  }
711  }
712  // Return result:
713  return implode('', $output);
714  }
715 
725  protected function writeSearchStat($searchParams, $searchWords, $count, $pt) {
726  $insertFields = array(
727  'searchstring' => $this->sword,
728  'searchoptions' => serialize(array($searchParams, $searchWords, $pt)),
729  'feuser_id' => (int)$GLOBALS['TSFE']->fe_user->user['uid'],
730  // cookie as set or retrieved. If people has cookies disabled this will vary all the time
731  'cookie' => $GLOBALS['TSFE']->fe_user->id,
732  // Remote IP address
733  'IP' => GeneralUtility::getIndpEnv('REMOTE_ADDR'),
734  // Number of hits on the search
735  'hits' => (int)$count,
736  // Time stamp
737  'tstamp' => $GLOBALS['EXEC_TIME']
738  );
739  $GLOBALS['TYPO3_DB']->exec_INSERTquery('index_stat_search', $insertFields);
740  $newId = $GLOBALS['TYPO3_DB']->sql_insert_id();
741  if ($newId) {
742  foreach ($searchWords as $val) {
743  $insertFields = array(
744  'word' => $val['sword'],
745  'index_stat_search_id' => $newId,
746  // Time stamp
747  'tstamp' => $GLOBALS['EXEC_TIME'],
748  // search page id for indexed search stats
749  'pageid' => $GLOBALS['TSFE']->id
750  );
751  $GLOBALS['TYPO3_DB']->exec_INSERTquery('index_stat_word', $insertFields);
752  }
753  }
754  }
755 
771  protected function getSearchWords($defaultOperator) {
772  // Shorten search-word string to max 200 bytes (does NOT take multibyte charsets into account - but never mind, shortening the string here is only a run-away feature!)
773  $searchWords = substr($this->sword, 0, 200);
774  // Convert to UTF-8 + conv. entities (was also converted during indexing!)
775  $searchWords = $GLOBALS['TSFE']->csConvObj->utf8_encode($searchWords, $GLOBALS['TSFE']->metaCharset);
776  $searchWords = $GLOBALS['TSFE']->csConvObj->entities_to_utf8($searchWords, TRUE);
777  $sWordArray = FALSE;
778  if ($hookObj = $this->hookRequest('getSearchWords')) {
779  $sWordArray = $hookObj->getSearchWords_splitSWords($searchWords, $defaultOperator);
780  } else {
781  // sentence
782  if ($this->searchData['searchType'] == 20) {
783  $sWordArray = array(
784  array(
785  'sword' => trim($searchWords),
786  'oper' => 'AND'
787  )
788  );
789  } else {
790  // case-sensitive. Defines the words, which will be
791  // operators between words
792  $operatorTranslateTable = array(
793  array('+', 'AND'),
794  array('|', 'OR'),
795  array('-', 'AND NOT'),
796  // Add operators for various languages
797  // Converts the operators to UTF-8 and lowercase
798  array($GLOBALS['TSFE']->csConvObj->conv_case('utf-8', $GLOBALS['TSFE']->csConvObj->utf8_encode(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('localizedOperandAnd', 'IndexedSearch'), $GLOBALS['TSFE']->renderCharset), 'toLower'), 'AND'),
799  array($GLOBALS['TSFE']->csConvObj->conv_case('utf-8', $GLOBALS['TSFE']->csConvObj->utf8_encode(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('localizedOperandOr', 'IndexedSearch'), $GLOBALS['TSFE']->renderCharset), 'toLower'), 'OR'),
800  array($GLOBALS['TSFE']->csConvObj->conv_case('utf-8', $GLOBALS['TSFE']->csConvObj->utf8_encode(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('localizedOperandNot', 'IndexedSearch'), $GLOBALS['TSFE']->renderCharset), 'toLower'), 'AND NOT')
801  );
802  $search = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\SearchResultContentObject');
803  $search->default_operator = $defaultOperator == 1 ? 'OR' : 'AND';
804  $search->operator_translate_table = $operatorTranslateTable;
805  $search->register_and_explode_search_string($searchWords);
806  if (is_array($search->sword_array)) {
807  $sWordArray = $this->procSearchWordsByLexer($search->sword_array);
808  } else {
809  $sWordArray = array();
810  }
811  }
812  }
813  return $sWordArray;
814  }
815 
823  protected function procSearchWordsByLexer($searchWords) {
824  $newSearchWords = array();
825  // Init lexer (used to post-processing of search words)
826  $lexerObjRef = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['lexer'] ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['lexer'] : 'EXT:indexed_search/Classes/Lexer.php:&TYPO3\\CMS\\IndexedSearch\\Lexer';
827  $this->lexerObj = GeneralUtility::getUserObj($lexerObjRef);
828  // Traverse the search word array
829  foreach ($searchWords as $wordDef) {
830  // No space in word (otherwise it might be a sentense in quotes like "there is").
831  if (strpos($wordDef['sword'], ' ') === FALSE) {
832  // Split the search word by lexer:
833  $res = $this->lexerObj->split2Words($wordDef['sword']);
834  // Traverse lexer result and add all words again:
835  foreach ($res as $word) {
836  $newSearchWords[] = array(
837  'sword' => $word,
838  'oper' => $wordDef['oper']
839  );
840  }
841  } else {
842  $newSearchWords[] = $wordDef;
843  }
844  }
845  return $newSearchWords;
846  }
847 
855  public function formAction($search = array()) {
856  $searchData = $this->initialize($search);
857  // Adding search field value
858  $this->view->assign('sword', $this->sword);
859  // Additonal keyword => "Add to current search words"
860  $showAdditionalKeywordSearch = $this->settings['clearSearchBox'] && $this->settings['clearSearchBox']['enableSubSearchCheckBox'];
861  if ($showAdditionalKeywordSearch) {
862  $this->view->assign('previousSearchWord', $this->settings['clearSearchBox'] ? '' : $this->sword);
863  }
864  $this->view->assign('showAdditionalKeywordSearch', $showAdditionalKeywordSearch);
865  // Extended search
866  if ($search['extendedSearch']) {
867  // "Search for"
868  $allSearchTypes = $this->getAllAvailableSearchTypeOptions();
869  $this->view->assign('allSearchTypes', $allSearchTypes);
870  $allDefaultOperands = $this->getAllAvailableOperandsOptions();
871  $this->view->assign('allDefaultOperands', $allDefaultOperands);
872  $showTypeSearch = count($allSearchTypes) || count($allDefaultOperands);
873  $this->view->assign('showTypeSearch', $showTypeSearch);
874  // "Search in"
875  $allMediaTypes = $this->getAllAvailableMediaTypesOptions();
876  $this->view->assign('allMediaTypes', $allMediaTypes);
877  $allLanguageUids = $this->getAllAvailableLanguageOptions();
878  $this->view->assign('allLanguageUids', $allLanguageUids);
879  $showMediaAndLanguageSearch = count($allMediaTypes) || count($allLanguageUids);
880  $this->view->assign('showMediaAndLanguageSearch', $showMediaAndLanguageSearch);
881  // Sections
882  $allSections = $this->getAllAvailableSectionsOptions();
883  $this->view->assign('allSections', $allSections);
884  // Free Indexing Configurations
885  $allIndexConfigurations = $this->getAllAvailableIndexConfigurationsOptions();
886  $this->view->assign('allIndexConfigurations', $allIndexConfigurations);
887  // Sorting
888  $allSortOrders = $this->getAllAvailableSortOrderOptions();
889  $this->view->assign('allSortOrders', $allSortOrders);
890  $allSortDescendings = $this->getAllAvailableSortDescendingOptions();
891  $this->view->assign('allSortDescendings', $allSortDescendings);
892  $showSortOrders = count($allSortOrders) || count($allSortDescendings);
893  $this->view->assign('showSortOrders', $showSortOrders);
894  // Limits
895  $allNumberOfResults = $this->getAllAvailableNumberOfResultsOptions();
896  $this->view->assign('allNumberOfResults', $allNumberOfResults);
897  $allGroups = $this->getAllAvailableGroupOptions();
898  $this->view->assign('allGroups', $allGroups);
899  }
900  $this->view->assign('searchParams', $searchData);
901  }
902 
903  /****************************************
904  * building together the available options for every dropdown
905  ***************************************/
911  protected function getAllAvailableSearchTypeOptions() {
912  $allOptions = array();
913  $types = array(0, 1, 2, 3, 10, 20);
914  $blindSettings = $this->settings['blind'];
915  if (!$blindSettings['searchType']) {
916  foreach ($types as $typeNum) {
917  $allOptions[$typeNum] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('searchTypes.' . $typeNum, 'IndexedSearch');
918  }
919  }
920  // Remove this option if metaphone search is disabled)
921  if (!$this->enableMetaphoneSearch) {
922  unset($allOptions[10]);
923  }
924  // disable single entries by TypoScript
925  $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['searchType']);
926  return $allOptions;
927  }
928 
934  protected function getAllAvailableOperandsOptions() {
935  $allOptions = array();
936  $blindSettings = $this->settings['blind'];
937  if (!$blindSettings['defaultOperand']) {
938  $allOptions = array(
939  0 => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('defaultOperands.0', 'IndexedSearch'),
940  1 => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('defaultOperands.1', 'IndexedSearch')
941  );
942  }
943  // disable single entries by TypoScript
944  $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['defaultOperand']);
945  return $allOptions;
946  }
947 
953  protected function getAllAvailableMediaTypesOptions() {
954  $allOptions = array();
955  $mediaTypes = array(-1, 0, -2);
956  $blindSettings = $this->settings['blind'];
957  if (!$blindSettings['mediaType']) {
958  foreach ($mediaTypes as $mediaType) {
959  $allOptions[$mediaType] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('mediaTypes.' . $mediaType, 'IndexedSearch');
960  }
961  // Add media to search in:
962  $additionalMedia = trim($this->settings['mediaList']);
963  if (strlen($additionalMedia) > 0) {
964  $additionalMedia = GeneralUtility::trimExplode(',', $additionalMedia, TRUE);
965  } else {
966  $additionalMedia = array();
967  }
968  foreach ($this->externalParsers as $extension => $obj) {
969  // Skip unwanted extensions
970  if (count($additionalMedia) && !in_array($extension, $additionalMedia)) {
971  continue;
972  }
973  if ($name = $obj->searchTypeMediaTitle($extension)) {
974  $translatedName = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('mediaTypes.' . $extension, 'IndexedSearch');
975  $allOptions[$extension] = $translatedName ?: $name;
976  }
977  }
978  }
979  // disable single entries by TypoScript
980  $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['mediaType']);
981  return $allOptions;
982  }
983 
989  protected function getAllAvailableLanguageOptions() {
990  $allOptions = array(
991  '-1' => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('languageUids.-1', 'IndexedSearch'),
992  '0' => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('languageUids.0', 'IndexedSearch')
993  );
994  $blindSettings = $this->settings['blind'];
995  if (!$blindSettings['languageUid']) {
996  // Add search languages
997  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_language', '1=1' . $GLOBALS['TSFE']->cObj->enableFields('sys_language'));
998  if ($res) {
999  while ($lang = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1000  $allOptions[$lang['uid']] = $lang['title'];
1001  }
1002  }
1003  // disable single entries by TypoScript
1004  $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['languageUid']);
1005  } else {
1006  $allOptions = array();
1007  }
1008  return $allOptions;
1009  }
1010 
1020  protected function getAllAvailableSectionsOptions() {
1021  $allOptions = array();
1022  $sections = array(0, -1, -2, -3);
1023  $blindSettings = $this->settings['blind'];
1024  if (!$blindSettings['sections']) {
1025  foreach ($sections as $section) {
1026  $allOptions[$section] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('sections.' . $section, 'IndexedSearch');
1027  }
1028  }
1029  // Creating levels for section menu:
1030  // This selects the first and secondary menus for the "sections" selector - so we can search in sections and sub sections.
1031  if ($this->settings['displayLevel1Sections']) {
1032  $firstLevelMenu = $this->getMenuOfPages($this->searchRootPageIdList);
1033  $labelLevel1 = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('sections.rootLevel1', 'IndexedSearch');
1034  $labelLevel2 = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('sections.rootLevel2', 'IndexedSearch');
1035  foreach ($firstLevelMenu as $firstLevelKey => $menuItem) {
1036  if (!$menuItem['nav_hide']) {
1037  $allOptions['rl1_' . $menuItem['uid']] = trim($labelLevel1 . ' ' . $menuItem['title']);
1038  if ($this->settings['displayLevel2Sections']) {
1039  $secondLevelMenu = $this->getMenuOfPages($menuItem['uid']);
1040  foreach ($secondLevelMenu as $secondLevelKey => $menuItemLevel2) {
1041  if (!$menuItemLevel2['nav_hide']) {
1042  $allOptions['rl2_' . $menuItemLevel2['uid']] = trim($labelLevel2 . ' ' . $menuItemLevel2['title']);
1043  } else {
1044  unset($secondLevelMenu[$secondLevelKey]);
1045  }
1046  }
1047  $allOptions['rl2_' . implode(',', array_keys($secondLevelMenu))] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('sections.rootLevel2All', 'IndexedSearch');
1048  }
1049  } else {
1050  unset($firstLevelMenu[$firstLevelKey]);
1051  }
1052  }
1053  $allOptions['rl1_' . implode(',', array_keys($firstLevelMenu))] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('sections.rootLevel1All', 'IndexedSearch');
1054  }
1055  // disable single entries by TypoScript
1056  $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['sections']);
1057  return $allOptions;
1058  }
1059 
1066  $allOptions = array(
1067  '-1' => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('indexingConfigurations.-1', 'IndexedSearch'),
1068  '-2' => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('indexingConfigurations.-2', 'IndexedSearch'),
1069  '0' => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('indexingConfigurations.0', 'IndexedSearch')
1070  );
1071  $blindSettings = $this->settings['blind'];
1072  if (!$blindSettings['indexingConfigurations']) {
1073  // add an additional index configuration
1074  if ($this->settings['defaultFreeIndexUidList']) {
1075  $uidList = GeneralUtility::intExplode(',', $this->settings['defaultFreeIndexUidList']);
1076  $indexCfgRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title', 'index_config', 'uid IN (' . implode(',', $uidList) . ')' . $GLOBALS['TSFE']->cObj->enableFields('index_config'), '', '', '', 'uid');
1077  foreach ($uidList as $uidValue) {
1078  if (is_array($indexCfgRecords[$uidValue])) {
1079  $allOptions[$uidValue] = $indexCfgRecords[$uidValue]['title'];
1080  }
1081  }
1082  }
1083  // disable single entries by TypoScript
1084  $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['indexingConfigurations']);
1085  } else {
1086  $allOptions = array();
1087  }
1088  return $allOptions;
1089  }
1090 
1100  protected function getAllAvailableSortOrderOptions() {
1101  $allOptions = array();
1102  $sortOrders = array('rank_flag', 'rank_freq', 'rank_first', 'rank_count', 'mtime', 'title', 'crdate');
1103  $blindSettings = $this->settings['blind'];
1104  if (!$blindSettings['sortOrder']) {
1105  foreach ($sortOrders as $order) {
1106  $allOptions[$order] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('sortOrders.' . $order, 'IndexedSearch');
1107  }
1108  }
1109  // disable single entries by TypoScript
1110  $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['sortOrder.']);
1111  return $allOptions;
1112  }
1113 
1119  protected function getAllAvailableGroupOptions() {
1120  $allOptions = array();
1121  $blindSettings = $this->settings['blind'];
1122  if (!$blindSettings['groupBy']) {
1123  $allOptions = array(
1124  'sections' => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('groupBy.sections', 'IndexedSearch'),
1125  'flat' => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('groupBy.flat', 'IndexedSearch')
1126  );
1127  }
1128  // disable single entries by TypoScript
1129  $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['groupBy.']);
1130  return $allOptions;
1131  }
1132 
1139  $allOptions = array();
1140  $blindSettings = $this->settings['blind'];
1141  if (!$blindSettings['descending']) {
1142  $allOptions = array(
1143  0 => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('sortOrders.descending', 'IndexedSearch'),
1144  1 => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('sortOrders.ascending', 'IndexedSearch')
1145  );
1146  }
1147  // disable single entries by TypoScript
1148  $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['descending.']);
1149  return $allOptions;
1150  }
1151 
1158  $allOptions = array();
1159  $blindSettings = $this->settings['blind'];
1160  if (!$blindSettings['numberOfResults']) {
1161  $allOptions = array(
1162  10 => 10,
1163  25 => 25,
1164  50 => 50,
1165  100 => 100
1166  );
1167  }
1168  // disable single entries by TypoScript
1169  $allOptions = $this->removeOptionsFromOptionList($allOptions, $blindSettings['numberOfResults']);
1170  return $allOptions;
1171  }
1172 
1180  protected function removeOptionsFromOptionList($allOptions, $blindOptions) {
1181  if (is_array($blindOptions)) {
1182  foreach ($blindOptions as $key => $val) {
1183  if ($val == 1) {
1184  unset($allOptions[$key]);
1185  }
1186  }
1187  }
1188  return $allOptions;
1189  }
1190 
1201  protected function linkPage($pageUid, $linkText, $row = array(), $markUpSwParams = array()) {
1202  // Parameters for link
1203  $urlParameters = (array) unserialize($row['cHashParams']);
1204  // Add &type and &MP variable:
1205  if ($row['data_page_mp']) {
1206  $urlParameters['MP'] = $row['data_page_mp'];
1207  }
1208  if ($row['sys_language_uid']) {
1209  $urlParameters['L'] = $row['sys_language_uid'];
1210  }
1211  // markup-GET vars:
1212  $urlParameters = array_merge($urlParameters, $markUpSwParams);
1213  // This will make sure that the path is retrieved if it hasn't been
1214  // already. Used only for the sake of the domain_record thing.
1215  if (!is_array($this->domainRecords[$pageUid])) {
1216  $this->getPathFromPageId($pageUid);
1217  }
1218  $target = '';
1219  // If external domain, then link to that:
1220  if (count($this->domainRecords[$pageUid])) {
1221  $scheme = GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https://' : 'http://';
1222  $firstDomain = reset($this->domainRecords[$pageUid]);
1223  $additionalParams = '';
1224  if (is_array($urlParameters)) {
1225  if (count($urlParameters)) {
1226  $additionalParams = GeneralUtility::implodeArrayForUrl('', $urlParameters);
1227  }
1228  }
1229  $uri = $scheme . $firstDomain . '/index.php?id=' . $pageUid . $additionalParams;
1230  if ($target = $this->settings['detectDomainRecords.']['target']) {
1231  $target = ' target="' . $target . '"';
1232  }
1233  } else {
1234  $uriBuilder = $this->controllerContext->getUriBuilder();
1235  $uri = $uriBuilder->setTargetPageUid($pageUid)->setTargetPageType($row['data_page_type'])->setUseCacheHash(TRUE)->setArguments($urlParameters)->build();
1236  }
1237  return '<a href="' . htmlspecialchars($uri) . '"' . $target . '>' . htmlspecialchars($linkText) . '</a>';
1238  }
1239 
1246  protected function getMenuOfPages($pageUid) {
1247  if ($this->settings['displayLevelxAllTypes']) {
1248  $menu = array();
1249  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('title,uid', 'pages', 'pid=' . (int)$pageUid . $GLOBALS['TSFE']->cObj->enableFields('pages'), '', 'sorting');
1250  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1251  $menu[$row['uid']] = $GLOBALS['TSFE']->sys_page->getPageOverlay($row);
1252  }
1253  $GLOBALS['TYPO3_DB']->sql_free_result($res);
1254  } else {
1255  $menu = $GLOBALS['TSFE']->sys_page->getMenu($pageUid);
1256  }
1257  return $menu;
1258  }
1259 
1267  protected function getPathFromPageId($id, $pathMP = '') {
1268  $identStr = $id . '|' . $pathMP;
1269  if (!isset($this->pathCache[$identStr])) {
1270  $this->requiredFrontendUsergroups[$id] = array();
1271  $this->domainRecords[$id] = array();
1272  $rl = $GLOBALS['TSFE']->sys_page->getRootLine($id, $pathMP);
1273  $path = '';
1274  if (is_array($rl) && count($rl)) {
1275  foreach ($rl as $k => $v) {
1276  // Check fe_user
1277  if ($v['fe_group'] && ($v['uid'] == $id || $v['extendToSubpages'])) {
1278  $this->requiredFrontendUsergroups[$id][] = $v['fe_group'];
1279  }
1280  // Check sys_domain
1281  if ($this->settings['detectDomainRcords']) {
1282  $domainName = $this->getFirstSysDomainRecordForPage($v['uid']);
1283  if ($domainName) {
1284  $this->domainRecords[$id][] = $domainName;
1285  // Set path accordingly
1286  $path = $domainName . $path;
1287  break;
1288  }
1289  }
1290  // Stop, if we find that the current id is the current root page.
1291  if ($v['uid'] == $GLOBALS['TSFE']->config['rootLine'][0]['uid']) {
1292  break;
1293  }
1294  $path = '/' . $v['title'] . $path;
1295  }
1296  }
1297  $this->pathCache[$identStr] = $path;
1298  }
1299  return $this->pathCache[$identStr];
1300  }
1301 
1308  protected function getFirstSysDomainRecordForPage($id) {
1309  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('domainName', 'sys_domain', 'pid=' . (int)$id . $GLOBALS['TSFE']->cObj->enableFields('sys_domain'), '', 'sorting');
1310  $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
1311  return rtrim($row['domainName'], '/');
1312  }
1313 
1320  protected function initializeExternalParsers() {
1321  // Initialize external document parsers for icon display and other soft operations
1322  if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['external_parsers'])) {
1323  foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['external_parsers'] as $extension => $_objRef) {
1324  $this->externalParsers[$extension] = GeneralUtility::getUserObj($_objRef);
1325  // Init parser and if it returns FALSE, unset its entry again
1326  if (!$this->externalParsers[$extension]->softInit($extension)) {
1327  unset($this->externalParsers[$extension]);
1328  }
1329  }
1330  }
1331  }
1332 
1339  protected function hookRequest($functionName) {
1340  // Hook: menuConfig_preProcessModMenu
1341  if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['pi1_hooks'][$functionName]) {
1342  $hookObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['pi1_hooks'][$functionName]);
1343  if (method_exists($hookObj, $functionName)) {
1344  $hookObj->pObj = $this;
1345  return $hookObj;
1346  }
1347  }
1348  return NULL;
1349  }
1350 
1357  protected function multiplePagesType($item_type) {
1358  return is_object($this->externalParsers[$item_type]) && $this->externalParsers[$item_type]->isMultiplePageExtension($item_type);
1359  }
1360 
1361 }
getDisplayResults($searchWords, $resultData, $freeIndexUid=-1)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
makeDescription($row, $noMarkup=FALSE, $length=180)
linkPage($pageUid, $linkText, $row=array(), $markUpSwParams=array())
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
static implodeArrayForUrl($name, array $theArray, $str='', $skipBlank=FALSE, $rawurlencodeParamName=FALSE)
static formatSize($sizeInBytes, $labels='')
static translate($key, $extensionName, $arguments=NULL)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)
writeSearchStat($searchParams, $searchWords, $count, $pt)