/** * Generates a html link - an anchor tag. * * TODO currently everything in $additionalQueryParameters is prefixed with tx_solr, * allow arbitrary parameters, too (either filter them out or introduce a new 4th parameter) * * @param string $linkText Link Text * @param array $additionalQueryParameters Additional query parameters * @param array $typolinkOptions Typolink Options * @return string A html link */ public function getQueryLink($linkText, array $additionalQueryParameters = array(), array $typolinkOptions = array()) { $queryParameters = array_merge($this->getPluginParameters(), $additionalQueryParameters); $queryParameters = $this->removeUnwantedUrlParameters($queryParameters); $queryGetParameter = ''; $keywords = $this->query->getKeywords(); if (!empty($keywords)) { $queryGetParameter = '&q=' . $keywords; } $linkConfiguration = array('useCacheHash' => FALSE, 'no_cache' => FALSE, 'parameter' => $this->linkTargetPageId, 'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', array($this->prefix => $queryParameters), '', TRUE) . $this->getUrlParameters() . $queryGetParameter); // merge linkConfiguration with typolinkOptions $linkConfiguration = array_merge($linkConfiguration, $typolinkOptions); return $this->contentObject->typoLink($linkText, $linkConfiguration); }
/** * Generates a URL. * * TODO currently everything in $additionalQueryParameters is prefixed with tx_solr, * allow arbitrary parameters, too (either filter them out or introduce a new 3rd parameter) * * @param array $additionalQueryParameters Additional query parameters * @param array $typolinkOptions Typolink Options * @return string A query URL */ public function getQueryUrl(array $additionalQueryParameters = array(), array $typolinkOptions = array()) { $queryParameters = array_merge($this->getPluginParameters(), $additionalQueryParameters); $queryParameters = $this->removeUnwantedUrlParameters($queryParameters); $queryKeywords = ''; if ($this->query) { $queryKeywords = $this->query->getKeywords(); } $queryGetParameter = ''; if (!empty($queryKeywords)) { $queryGetParameter = '&q=' . $queryKeywords; } $linkConfiguration = array('useCacheHash' => FALSE, 'no_cache' => FALSE, 'parameter' => $this->linkTargetPageId, 'additionalParams' => $queryGetParameter . t3lib_div::implodeArrayForUrl('', array($this->prefix => $queryParameters), '', TRUE) . $this->getUrlParameters()); // merge linkConfiguration with typolinkOptions $linkConfiguration = array_merge($linkConfiguration, $typolinkOptions); return htmlspecialchars($this->contentObject->typoLink_URL($linkConfiguration)); }
/** * Processes a query and its response after searching for that query. * * @param Tx_Solr_Query The query that has been searched for. * @param Apache_Solr_Response The response for the last query. */ public function processResponse(Tx_Solr_Query $query, Apache_Solr_Response $response) { $urlParameters = t3lib_div::_GP('tx_solr'); $keywords = $query->getKeywords(); $filters = isset($urlParameters['filter']) ? $urlParameters['filter'] : array(); if (empty($keywords)) { // do not track empty queries return; } $keywords = t3lib_div::removeXSS($keywords); $keywords = htmlentities($keywords, ENT_QUOTES, $GLOBALS['TSFE']->metaCharset); $configuration = Tx_Solr_Util::getSolrConfiguration(); if ($configuration['search.']['frequentSearches.']['useLowercaseKeywords']) { $keywords = strtolower($keywords); } $ipMaskLength = (int) $configuration['statistics.']['anonymizeIP']; $insertFields = array('pid' => $GLOBALS['TSFE']->id, 'root_pid' => $GLOBALS['TSFE']->tmpl->rootLine[0]['uid'], 'tstamp' => $GLOBALS['EXEC_TIME'], 'language' => $GLOBALS['TSFE']->sys_language_uid, 'num_found' => $response->response->numFound, 'suggestions_shown' => (int) get_object_vars($response->spellcheck->suggestions), 'time_total' => $response->debug->timing->time, 'time_preparation' => $response->debug->timing->prepare->time, 'time_processing' => $response->debug->timing->process->time, 'feuser_id' => (int) $GLOBALS['TSFE']->fe_user->user['uid'], 'cookie' => $GLOBALS['TSFE']->fe_user->id, 'ip' => $this->applyIpMask(t3lib_div::getIndpEnv('REMOTE_ADDR'), $ipMaskLength), 'page' => (int) $urlParameters['page'], 'keywords' => $keywords, 'filters' => serialize($filters), 'sorting' => $urlParameters['sort'] ? $urlParameters['sort'] : '', 'parameters' => serialize($response->responseHeader->params)); $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_solr_statistics', $insertFields); }