/**
  * Returns a COMPLETE list of phash-integers matching the search-result composed of the search-words in the sWArr array.
  * The list of phash integers are unsorted and should be used for subsequent selection of index_phash records for display of the result.
  *
  * @param array $sWArr Search word array
  * @return string List of integers
  */
 public function getPhashList($sWArr)
 {
     // Initialize variables:
     $c = 0;
     $totalHashList = array();
     // This array accumulates the phash-values
     // Traverse searchwords; for each, select all phash integers and merge/diff/intersect them with previous word (based on operator)
     foreach ($sWArr as $k => $v) {
         // Making the query for a single search word based on the search-type
         $sWord = $v['sword'];
         $theType = (string) $this->piVars['type'];
         if (strstr($sWord, ' ')) {
             // If there are spaces in the search-word, make a full text search instead.
             $theType = 20;
         }
         $this->timeTracker->push('SearchWord "' . $sWord . '" - $theType=' . $theType);
         // Perform search for word:
         switch ($theType) {
             case '1':
                 // Part of word
                 $res = $this->searchWord($sWord, Utility\LikeWildcard::BOTH);
                 break;
             case '2':
                 // First part of word
                 $res = $this->searchWord($sWord, Utility\LikeWildcard::RIGHT);
                 break;
             case '3':
                 // Last part of word
                 $res = $this->searchWord($sWord, Utility\LikeWildcard::LEFT);
                 break;
             case '10':
                 // Sounds like
                 /**
                  * Indexer object
                  *
                  * @var \TYPO3\CMS\IndexedSearch\Indexer
                  */
                 // Initialize the indexer-class
                 $indexerObj = GeneralUtility::makeInstance(\TYPO3\CMS\IndexedSearch\Indexer::class);
                 // Perform metaphone search
                 $res = $this->searchMetaphone($indexerObj->metaphone($sWord, $this->storeMetaphoneInfoAsWords));
                 unset($indexerObj);
                 break;
             case '20':
                 // Sentence
                 $res = $this->searchSentence($sWord);
                 $this->piVars['order'] = 'mtime';
                 // If there is a fulltext search for a sentence there is a likeliness that sorting cannot be done by the rankings from the rel-table (because no relations will exist for the sentence in the word-table). So therefore mtime is used instead. It is not required, but otherwise some hits may be left out.
                 break;
             default:
                 // Distinct word
                 $res = $this->searchDistinct($sWord);
         }
         // If there was a query to do, then select all phash-integers which resulted from this.
         if ($res) {
             // Get phash list by searching for it:
             $phashList = array();
             while ($row = $this->databaseConnection->sql_fetch_assoc($res)) {
                 $phashList[] = $row['phash'];
             }
             $this->databaseConnection->sql_free_result($res);
             // Here the phash list are merged with the existing result based on whether we are dealing with OR, NOT or AND operations.
             if ($c) {
                 switch ($v['oper']) {
                     case 'OR':
                         $totalHashList = array_unique(array_merge($phashList, $totalHashList));
                         break;
                     case 'AND NOT':
                         $totalHashList = array_diff($totalHashList, $phashList);
                         break;
                     default:
                         // AND...
                         $totalHashList = array_intersect($totalHashList, $phashList);
                 }
             } else {
                 $totalHashList = $phashList;
             }
         }
         $this->timeTracker->pull();
         $c++;
     }
     return implode(',', $totalHashList);
 }
 /**
  * Handles a frontend request
  *
  * @param \Psr\Http\Message\ServerRequestInterface $request
  * @return NULL|\Psr\Http\Message\ResponseInterface
  */
 public function handleRequest(\Psr\Http\Message\ServerRequestInterface $request)
 {
     $response = null;
     $this->request = $request;
     $this->initializeTimeTracker();
     // Hook to preprocess the current request:
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
             $hookParameters = array();
             GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
         }
         unset($hookFunction);
         unset($hookParameters);
     }
     $this->initializeController();
     if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_force'] && !GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
         $this->controller->pageUnavailableAndExit('This page is temporarily unavailable.');
     }
     $this->controller->connectToDB();
     $this->controller->sendRedirect();
     // Output compression
     // Remove any output produced until now
     $this->bootstrap->endOutputBufferingAndCleanPreviousOutput();
     $this->initializeOutputCompression();
     // Initializing the Frontend User
     $this->timeTracker->push('Front End user initialized', '');
     $this->controller->initFEuser();
     $this->timeTracker->pull();
     // Initializing a possible logged-in Backend User
     /** @var $GLOBALS['BE_USER'] \TYPO3\CMS\Backend\FrontendBackendUserAuthentication */
     $GLOBALS['BE_USER'] = $this->controller->initializeBackendUser();
     // Process the ID, type and other parameters.
     // After this point we have an array, $page in TSFE, which is the page-record
     // of the current page, $id.
     $this->timeTracker->push('Process ID', '');
     // Initialize admin panel since simulation settings are required here:
     if ($this->controller->isBackendUserLoggedIn()) {
         $GLOBALS['BE_USER']->initializeAdminPanel();
         $this->bootstrap->initializeBackendRouter()->loadExtensionTables();
     } else {
         $this->bootstrap->loadCachedTca();
     }
     $this->controller->checkAlternativeIdMethods();
     $this->controller->clear_preview();
     $this->controller->determineId();
     // Now, if there is a backend user logged in and he has NO access to this page,
     // then re-evaluate the id shown! _GP('ADMCMD_noBeUser') is placed here because
     // \TYPO3\CMS\Version\Hook\PreviewHook might need to know if a backend user is logged in.
     if ($this->controller->isBackendUserLoggedIn() && (!$GLOBALS['BE_USER']->extPageReadAccess($this->controller->page) || GeneralUtility::_GP('ADMCMD_noBeUser'))) {
         // Remove user
         unset($GLOBALS['BE_USER']);
         $this->controller->beUserLogin = false;
         // Re-evaluate the page-id.
         $this->controller->checkAlternativeIdMethods();
         $this->controller->clear_preview();
         $this->controller->determineId();
     }
     $this->controller->makeCacheHash();
     $this->timeTracker->pull();
     // Admin Panel & Frontend editing
     if ($this->controller->isBackendUserLoggedIn()) {
         $GLOBALS['BE_USER']->initializeFrontendEdit();
         if ($GLOBALS['BE_USER']->adminPanel instanceof AdminPanelView) {
             $this->bootstrap->initializeLanguageObject();
         }
         if ($GLOBALS['BE_USER']->frontendEdit instanceof FrontendEditingController) {
             $GLOBALS['BE_USER']->frontendEdit->initConfigOptions();
         }
     }
     // Starts the template
     $this->timeTracker->push('Start Template', '');
     $this->controller->initTemplate();
     $this->timeTracker->pull();
     // Get from cache
     $this->timeTracker->push('Get Page from cache', '');
     $this->controller->getFromCache();
     $this->timeTracker->pull();
     // Get config if not already gotten
     // After this, we should have a valid config-array ready
     $this->controller->getConfigArray();
     // Setting language and locale
     $this->timeTracker->push('Setting language and locale', '');
     $this->controller->settingLanguage();
     $this->controller->settingLocale();
     $this->timeTracker->pull();
     // Convert POST data to utf-8 for internal processing if metaCharset is different
     $this->controller->convPOSTCharset();
     $this->controller->initializeRedirectUrlHandlers();
     $this->controller->handleDataSubmission();
     // Check for shortcut page and redirect
     $this->controller->checkPageForShortcutRedirect();
     $this->controller->checkPageForMountpointRedirect();
     // Generate page
     $this->controller->setUrlIdToken();
     $this->timeTracker->push('Page generation', '');
     if ($this->controller->isGeneratePage()) {
         $this->controller->generatePage_preProcessing();
         $temp_theScript = $this->controller->generatePage_whichScript();
         if ($temp_theScript) {
             include $temp_theScript;
         } else {
             PageGenerator::pagegenInit();
             // Global content object
             $this->controller->newCObj();
             // Content generation
             if (!$this->controller->isINTincScript()) {
                 PageGenerator::renderContent();
                 $this->controller->setAbsRefPrefix();
             }
         }
         $this->controller->generatePage_postProcessing();
     } elseif ($this->controller->isINTincScript()) {
         PageGenerator::pagegenInit();
         // Global content object
         $this->controller->newCObj();
     }
     $this->controller->releaseLocks();
     $this->timeTracker->pull();
     // Render non-cached parts
     if ($this->controller->isINTincScript()) {
         $this->timeTracker->push('Non-cached objects', '');
         $this->controller->INTincScript();
         $this->timeTracker->pull();
     }
     // Output content
     $sendTSFEContent = false;
     if ($this->controller->isOutputting()) {
         $this->timeTracker->push('Print Content', '');
         $this->controller->processOutput();
         $sendTSFEContent = true;
         $this->timeTracker->pull();
     }
     // Store session data for fe_users
     $this->controller->storeSessionData();
     // Statistics
     $GLOBALS['TYPO3_MISC']['microtime_end'] = microtime(true);
     $this->controller->setParseTime();
     if (isset($this->controller->config['config']['debug'])) {
         $debugParseTime = (bool) $this->controller->config['config']['debug'];
     } else {
         $debugParseTime = !empty($this->controller->TYPO3_CONF_VARS['FE']['debug']);
     }
     if ($this->controller->isOutputting() && $debugParseTime) {
         $this->controller->content .= LF . '<!-- Parsetime: ' . $this->controller->scriptParseTime . 'ms -->';
     }
     $this->controller->redirectToExternalUrl();
     // Preview info
     $this->controller->previewInfo();
     // Hook for end-of-frontend
     $this->controller->hook_eofe();
     // Finish timetracking
     $this->timeTracker->pull();
     // Check memory usage
     MonitorUtility::peakMemoryUsage();
     // beLoginLinkIPList
     echo $this->controller->beLoginLinkIPList();
     // Admin panel
     if ($this->controller->isBackendUserLoggedIn() && $GLOBALS['BE_USER'] instanceof FrontendBackendUserAuthentication) {
         if ($GLOBALS['BE_USER']->extAdmEnabled) {
             // Style sheet is also used for frontend editing.
             $this->controller->content = str_ireplace('</head>', $GLOBALS['BE_USER']->adminPanel->getAdminPanelHeaderData() . '</head>', $this->controller->content);
         }
         if ($GLOBALS['BE_USER']->isAdminPanelVisible()) {
             $this->controller->content = str_ireplace('</body>', $GLOBALS['BE_USER']->displayAdminPanel() . '</body>', $this->controller->content);
         }
     }
     if ($sendTSFEContent) {
         /** @var \TYPO3\CMS\Core\Http\Response $response */
         $response = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Http\Response::class);
         $response->getBody()->write($this->controller->content);
     }
     // Debugging Output
     if (isset($GLOBALS['error']) && is_object($GLOBALS['error']) && @is_callable(array($GLOBALS['error'], 'debugOutput'))) {
         $GLOBALS['error']->debugOutput();
     }
     if (TYPO3_DLOG) {
         GeneralUtility::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => true));
     }
     return $response;
 }
 /**
  * Push function wrapper for TT logging
  *
  * @param string $msg Title to set
  * @param string $key Key (?)
  * @return void
  */
 public function log_push($msg, $key)
 {
     $this->timeTracker->push($msg, $key);
 }