Newer
Older
namespace App;
use App;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;
use Jenssegers\Agent\Agent;
use Log;
use Monospice\LaravelRedisSentinel\RedisSentinel;

Dominik Hebeler
committed
use Predis\Connection\ConnectionException;
class MetaGer
{
# Einstellungen für die Suche
public $alteredQuery = "";
public $alterationOverrideQuery = "";
protected $fokus;
protected $eingabe;
protected $q;
protected $page;
protected $lang;
protected $cache = "";
protected $site;
protected $time = 2000;
protected $hostBlacklist = [];
protected $domainBlacklist = [];
private $urlBlacklist = [];
protected $stopWords = [];
protected $phrases = [];
protected $engines = [];
protected $results = [];
protected $queryFilter = [];
protected $parameterFilter = [];
protected $ads = [];
protected $infos = [];
protected $warnings = [];
protected $errors = [];
protected $addedHosts = [];
protected $startCount = 0;
protected $canCache = false;
protected $ip;
protected $language;
protected $agent;
protected $apiKey = "";
# Konfigurationseinstellungen:
protected $sumaFile;
protected $mobile;
protected $resultCount;
protected $sprueche;
protected $domainsBlacklisted = [];
protected $adDomainsBlacklisted = [];
protected $urlsBlacklisted = [];
protected $url;
protected $fullUrl;
protected $languageDetect;
protected $verificationId;
protected $verificationCount;
protected $redisResultWaitingKey, $redisResultEngineList, $redisEngineResult, $redisCurrentResultList;
public function __construct($hash = "")
{
# Timer starten
$this->starttime = microtime(true);
# Versuchen Blacklists einzulesen
if (file_exists(config_path() . "/blacklistDomains.txt") && file_exists(config_path() . "/blacklistUrl.txt")) {
$tmp = file_get_contents(config_path() . "/blacklistDomains.txt");
$this->domainsBlacklisted = explode("\n", $tmp);
$tmp = file_get_contents(config_path() . "/blacklistUrl.txt");
$this->urlsBlacklisted = explode("\n", $tmp);
} else {
Log::warning("Achtung: Eine, oder mehrere Blacklist Dateien, konnten nicht geöffnet werden");
# Versuchen Blacklists einzulesen
if (file_exists(config_path() . "/adBlacklistDomains.txt") && file_exists(config_path() . "/adBlacklistUrl.txt")) {
$tmp = file_get_contents(config_path() . "/adBlacklistDomains.txt");
$this->adDomainsBlacklisted = explode("\n", $tmp);
$tmp = file_get_contents(config_path() . "/adBlacklistUrl.txt");
$this->adUrlsBlacklisted = explode("\n", $tmp);
} else {
Log::warning("Achtung: Eine, oder mehrere Blacklist Dateien, konnten nicht geöffnet werden");
}
# Parser Skripte einhängen
$dir = app_path() . "/Models/parserSkripte/";
foreach (scandir($dir) as $filename) {
$path = $dir . $filename;
if (is_file($path)) {
# Cachebarkeit testen

Dominik Hebeler
committed
try {
Cache::has('test');
$this->canCache = true;
} catch (ConnectionException $e) {
$this->canCache = false;
}
if ($hash === "") {
$this->searchUid = md5(uniqid());
} else {
$this->searchUid = $hash;
}
$redisPrefix = "search";
# This is a list on which the MetaGer process can do a blocking pop to wait for new results
$this->redisResultWaitingKey = $redisPrefix . "." . $this->searchUid . ".ready";
# This is a list of searchengines which have delivered results for this search
$this->redisResultEngineList = $redisPrefix . "." . $this->searchUid . ".engines";
# This is the key where the results of the engine are stored as well as some statistical data
$this->redisEngineResult = $redisPrefix . "." . $this->searchUid . ".results.";
# A list of all search results already delivered to the user (sorted of course)
$this->redisCurrentResultList = $redisPrefix . "." . $this->searchUid . ".currentResults";
}
# Erstellt aus den gesammelten Ergebnissen den View
{

Aria Givi
committed
# Hiermit werden die evtl. ausgewählten SuMas extrahiert, damit die Input-Boxen richtig gesetzt werden können
$focusPages = [];

Aria Givi
committed
foreach ($this->request->all() as $key => $value) {
if (starts_with($key, 'engine_') && $value === 'on') {
$focusPages[] = $key;

Aria Givi
committed
}
}
$viewResults = [];
# Wir extrahieren alle notwendigen Variablen und geben Sie an unseren View:
foreach ($this->results as $result) {
$viewResults[] = get_object_vars($result);
}
# Wir müssen natürlich noch den Log für die durchgeführte Suche schreiben:
$this->createLogs();
if ($this->fokus === "bilder") {
switch ($this->out) {
case 'results':
return view('resultpages.results_images')
->with('results', $viewResults)
->with('eingabe', $this->eingabe)
->with('mobile', $this->mobile)
->with('warnings', $this->warnings)
->with('errors', $this->errors)
->with('metager', $this)
->with('browser', (new Agent())->browser());
default:
return view('resultpages.resultpage_images')
->with('results', $viewResults)
->with('eingabe', $this->eingabe)
->with('mobile', $this->mobile)
->with('warnings', $this->warnings)
->with('errors', $this->errors)
->with('metager', $this)
->with('browser', (new Agent())->browser())
->with('quicktips', action('MetaGerSearch@quicktips', ["search" => $this->eingabe]))
->with('focus', $this->fokus)
->with('resultcount', count($this->results));
} else {
switch ($this->out) {
case 'results':
return view('resultpages.results')
->with('results', $viewResults)
->with('eingabe', $this->eingabe)
->with('mobile', $this->mobile)
->with('warnings', $this->warnings)
->with('errors', $this->errors)
->with('metager', $this)
->with('browser', (new Agent())->browser())
->with('fokus', $this->fokus);
break;
case 'results-with-style':
return view('resultpages.resultpage')
->with('results', $viewResults)
->with('eingabe', $this->eingabe)
->with('mobile', $this->mobile)
->with('warnings', $this->warnings)
->with('errors', $this->errors)
->with('metager', $this)
->with('suspendheader', "yes")
->with('browser', (new Agent())->browser())
->with('fokus', $this->fokus);
break;
return view('resultpages.metager3rich')
->with('eingabe', $this->eingabe)
->with('mobile', $this->mobile)
->with('warnings', $this->warnings)
->with('errors', $this->errors)
->with('browser', (new Agent())->browser())
->with('fokus', $this->fokus);
return view('resultpages.metager3resultsrss20')
->with('results', $viewResults)
->with('eingabe', $this->eingabe)
->with('resultcount', sizeof($viewResults))
->with('fokus', $this->fokus);
return response()->view('resultpages.metager3resultsatom10', ['results' => $viewResults, 'eingabe' => $this->eingabe, 'metager' => $this, 'resultcount' => sizeof($viewResults), 'key' => $this->apiKey, 'apiAuthorized' => $this->apiAuthorized])->header('Content-Type', 'application/xml');
return response()->view('resultpages.metager3resultsatom10', ['results' => $viewResults, 'eingabe' => $this->eingabe, 'metager' => $this, 'resultcount' => sizeof($viewResults), 'key' => $this->apiKey, 'apiAuthorized' => true])
->header('Content-Type', 'application/xml');
# Wir geben die Ergebniszahl und die benötigte Zeit zurück:
return sizeof($viewResults) . ";" . round((microtime(true) - $this->starttime), 2);
default:
return view('resultpages.resultpage')
->with('eingabe', $this->eingabe)

Aria Givi
committed
->with('focusPages', $focusPages)
->with('mobile', $this->mobile)
->with('warnings', $this->warnings)
->with('errors', $this->errors)
->with('metager', $this)
->with('browser', (new Agent())->browser())
->with('quicktips', action('MetaGerSearch@quicktips', ["search" => $this->eingabe]))
->with('resultcount', count($this->results))
->with('focus', $this->fokus);
break;
}
}
}
{
$this->combineResults($engines);
if ($this->fokus == "nachrichten") {
$this->results = array_filter($this->results, function ($v, $k) {
return !is_null($v->getRank());
}, ARRAY_FILTER_USE_BOTH);
uasort($this->results, function ($a, $b) {
$datea = $a->getDate();
$dateb = $b->getDate();
return $dateb - $datea;
});
} else {
uasort($this->results, function ($a, $b) {
if ($a->getRank() == $b->getRank()) {
return 0;
}
return ($a->getRank() < $b->getRank()) ? 1 : -1;
});
}
# Validate Results
$newResults = [];
foreach ($this->results as $result) {
if ($result->isValid($this)) {
$newResults[] = $result;
}
}
$this->results = $newResults;
# Validate Advertisements
$newResults = [];
foreach ($this->ads as $ad) {
if (($ad->strippedHost !== "" && (in_array($ad->strippedHost, $this->adDomainsBlacklisted) ||
in_array($ad->strippedLink, $this->adUrlsBlacklisted))) || ($ad->strippedHostAnzeige !== "" && (in_array($ad->strippedHostAnzeige, $this->adDomainsBlacklisted) ||
in_array($ad->strippedLinkAnzeige, $this->adUrlsBlacklisted)))
continue;
}
$newResults[] = $ad;
}
$this->ads = $newResults;
if (!$this->apiAuthorized) {
$this->results = $this->parseAdgoal($this->results);
}
# Human Verification
$this->results = $this->humanVerification($this->results);
$this->ads = $this->humanVerification($this->ads);
$counter = 0;
$firstRank = 0;
if (count($this->results) <= 0) {
if (strlen($this->site) > 0) {
$no_sitesearch_query = str_replace(urlencode("site:" . $this->site), "", $this->fullUrl);
$this->errors[] = trans('metaGer.results.failedSitesearch', ['altSearch' => $no_sitesearch_query]);
} else {
$this->errors[] = trans('metaGer.results.failed');
}

Dominik Hebeler
committed
if ($this->canCache() && isset($this->next) && count($this->next) > 0 && count($this->results) > 0) {
$page = $this->page + 1;
'page' => $page,
'engines' => $this->next,
Cache::put($this->getSearchUid(), serialize($this->next), 60 * 60);

Dominik Hebeler
committed
} else {
$this->next = [];
}
public function combineResults($engines)
{
foreach ($engines as $engine) {
if (isset($engine->next)) {
$this->next[] = $engine->next;
}
if (isset($engine->last)) {
$this->last[] = $engine->last;
}
foreach ($engine->results as $result) {
if ($result->valid) {
$this->results[] = $result;
}
}
foreach ($engine->ads as $ad) {
$this->ads[] = $ad;
}
}
}
public function parseAdgoal($results)
{
$publicKey = getenv('adgoal_public');
$privateKey = getenv('adgoal_private');
if ($publicKey === false) {
return $results;
}
$tldList = "";
try {
foreach ($results as $result) {
if (!$result->new) {
continue;
}
if (strpos($link, "http") !== 0) {
$link = "http://" . $link;
}
$tldList .= parse_url($link, PHP_URL_HOST) . ",";
$result->tld = parse_url($link, PHP_URL_HOST);
}
$tldList = rtrim($tldList, ",");
# Hashwert
$hash = md5("meta" . $publicKey . $tldList . "GER");
# Query
$link = "https://api.smartredirect.de/api_v2/CheckForAffiliateUniversalsearchMetager.php?p=" . urlencode($publicKey) . "&k=" . urlencode($hash) . "&tld=" . urlencode($tldList) . "&q=" . urlencode($query);
$answer = json_decode(file_get_contents($link));
# Nun müssen wir nur noch die Links für die Advertiser ändern:
foreach ($answer as $el) {
$hoster = $el[0];
$hash = $el[1];
foreach ($results as $result) {
if ($result->new && $hoster === $result->tld && !$result->partnershop) {
# Hier ist ein Advertiser:
# Das Logo hinzufügen:
if ($result->image !== "") {
$result->logo = "https://img.smartredirect.de/logos_v2/60x30/" . urlencode($hash) . ".gif";
} else {
$result->image = "https://img.smartredirect.de/logos_v2/120x60/" . urlencode($hash) . ".gif";
}
# Den Link hinzufügen:
$publicKey = $publicKey;
$targetUrl = $result->link;
$gateHash = md5($targetUrl . $privateKey);
$newLink = "https://api.smartredirect.de/api_v2/ClickGate.php?p=" . urlencode($publicKey) . "&k=" . urlencode($gateHash) . "&url=" . urlencode($targetUrl) . "&q=" . urlencode($query);
$result->link = $newLink;
$result->partnershop = true;
}
}
}
} catch (\ErrorException $e) {
return $results;
}
return $results;
}
public function humanVerification($results)
{
# Let's check if we need to implement a redirect for human verification
if ($this->verificationCount > 10) {
foreach ($results as $result) {
$link = $result->link;
$day = Carbon::now()->day;
$pw = md5($this->verificationId . $day . $link . env("PROXY_PASSWORD"));
$url = route('humanverification', ['mm' => $this->verificationId, 'pw' => $pw, "url" => urlencode(str_replace("/", "<<SLASH>>", base64_encode($link)))]);
$proxyPw = md5($this->verificationId . $day . $result->proxyLink . env("PROXY_PASSWORD"));
$proxyUrl = route('humanverification', ['mm' => $this->verificationId, 'pw' => $proxyPw, "url" => urlencode(str_replace("/", "<<SLASH>>", base64_encode($result->proxyLink)))]);
$result->proxyLink = $proxyUrl;
public function authorize($key)
{
$postdata = http_build_query(array(
'dummy' => rand(),
));
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata,
),
);
$context = stream_context_create($opts);
try {
$link = "https://key.metager3.de/" . urlencode($key) . "/request-permission/api-access";
$result = json_decode(file_get_contents($link, false, $context));
if ($result->{'api-access'} == true) {
return true;
} else {
return false;
}
} catch (\ErrorException $e) {
return false;
}
}
/*
* Die Erstellung der Suchmaschinen bis die Ergebnisse da sind mit Unterfunktionen
*/
public function createSearchEngines(Request $request, &$timings)
{
if (!empty($timings)) {
$timings["createSearchEngines"]["start"] = microtime(true) - $timings["starttime"];
}
# Wenn es kein Suchwort gibt
if (!$request->filled("eingabe") || $this->q === "") {
}
$overtureEnabled = false;
# Check if selected focus is valid
if (empty($this->sumaFile->foki->{$this->fokus})) {
$this->fokus = "web";
$sumaNames = $this->sumaFile->foki->{$this->fokus}->sumas;
$sumas = [];
foreach ($sumaNames as $sumaName) {
$sumas[$sumaName] = $this->sumaFile->sumas->{$sumaName};
}
if (!empty($timings)) {
$timings["createSearchEngines"]["created engine array"] = microtime(true) - $timings["starttime"];
}
if (!empty($timings)) {
$timings["createSearchEngines"]["removed ads"] = microtime(true) - $timings["starttime"];
}
# Check if this engine is disabled and can't be used
$disabled = empty($suma->disabled) ? false : $suma->disabled;
$autoDisabled = empty($suma->{"auto-disabled"}) ? false : $suma->{"auto-disabled"};
if (
$disabled || $autoDisabled
|| \Cookie::get($this->getFokus() . "_engine_" . $sumaName) === "off"
) {
continue;
# Check if this engine can use potentially defined query-filter
foreach ($this->queryFilter as $filterName => $filter) {
if (empty($this->sumaFile->filter->{"query-filter"}->$filterName->sumas->$sumaName)) {
$valid = false;
break;
# Check if this engine can use potentially defined parameter-filter
if ($valid) {
foreach ($this->parameterFilter as $filterName => $filter) {
# We need to check if the searchengine supports the parameter value, too
if (empty($filter->sumas->$sumaName) || empty($filter->sumas->{$sumaName}->values->{$filter->value})) {
# Check if this engine should only be active when filter is used
# This search engine should only be used when a parameter filter of it is used
$validTmp = false;
foreach ($this->parameterFilter as $filterName => $filter) {
$validTmp = true;
break;
}
}
if (!$validTmp) {
$valid = false;
}
}
}
if (!empty($timings)) {
$timings["createSearchEngines"]["filtered invalid engines"] = microtime(true) - $timings["starttime"];
}
# Include Yahoo Ads if Yahoo is not enabled as a searchengine
if (!$this->apiAuthorized && $this->fokus != "bilder" && empty($this->enabledSearchengines["yahoo"]) && isset($this->sumaFile->sumas->{"yahoo-ads"})) {
$this->enabledSearchengines["yahoo-ads"] = $this->sumaFile->sumas->{"yahoo-ads"};
}
# Special case if search engines are disabled
# Since bing is normally only active if a filter is set but it should be active, too if yahoo is disabled
if ($this->getFokus() === "web" && empty($this->enabledSearchengines["yahoo"]) && \Cookie::get("web_engine_bing") !== "off") {
$this->enabledSearchengines["bing"] = $this->sumaFile->sumas->{"bing"};
}
if (sizeof($this->enabledSearchengines) === 0) {
$filter = "";
foreach ($this->queryFilter as $queryFilter => $filterPhrase) {
$filter .= trans($this->sumaFile->filter->{"query-filter"}->{$queryFilter}->name) . ",";
}
$filter = rtrim($filter, ",");
$error = trans('metaGer.engines.noSpecialSearch', [
'fokus' => trans($this->sumaFile->foki->{$this->fokus}->{"display-name"}),
$this->errors[] = $error;
$this->setEngines($request);
if (!empty($timings)) {
$timings["createSearchEngines"]["saved engines"] = microtime(true) - $timings["starttime"];
}
private function removeAdsFromListIfAdfree(&$sumas)
{
if ($this->apiAuthorized) {
foreach ($sumas as $sumaName => $suma) {
$ads = $suma->ads ?? false;
if ($ads) {
unset($sumas[$sumaName]);
$adBackups = $suma->{"ad-backups"} ?? [];
$adBackupName = $adBackups->{$this->fokus} ?? null;
if (isset($adBackupName)) {
$this->sumaFile->sumas->{$adBackupName}->{"filter-opt-in"} = false;
}
}
}
}
}
public function setEngines(Request $request, $enabledSearchengines = [])
{
if ($this->requestIsCached($request)) {
# If this is a page other than 1 the request is "cached"
$engines = $this->getCachedEngines($request);
# We need to edit some Options of the Cached Search Engines
$engine->setResultHash($this->getSearchUid());
$this->engines = $engines;
if (sizeof($enabledSearchengines) > 0) {
$this->enabledSearchengines = $enabledSearchengines;
}
$this->actuallyCreateSearchEngines($this->enabledSearchengines);
if (!empty($timings)) {
$timings["startSearch"]["start"] = microtime(true) - $timings["starttime"];
}
# Check all engines for Cached responses
if ($this->canCache()) {
$keys = [];
foreach ($this->engines as $engine) {
$keys[] = $engine->hash;
}
$cacheValues = Cache::many($keys);
foreach ($this->engines as $engine) {
if ($cacheValues[$engine->hash] !== null) {
$engine->cached = true;
$engine->retrieveResults($this, $cacheValues[$engine->hash]);
}
}
}
if (!empty($timings)) {
$timings["startSearch"]["cache checked"] = microtime(true) - $timings["starttime"];
}
# Wir starten alle Suchen
foreach ($this->engines as $engine) {
}
if (!empty($timings)) {
$timings["startSearch"]["searches started"] = microtime(true) - $timings["starttime"];
}
}
# Spezielle Suchen und Sumas
public function sumaIsSelected($suma, $request, $custom)
if ($custom) {
if ($request->filled("engine_" . strtolower($suma["name"]))) {
return true;
}
} else {
$types = explode(",", $suma["type"]);
if (in_array($this->fokus, $types)) {
return true;
}
}
return false;
}
public function actuallyCreateSearchEngines($enabledSearchengines)
{
$engines = [];
foreach ($enabledSearchengines as $engineName => $engine) {
if (!isset($engine->{"parser-class"})) {
# Setze Pfad zu Parser
$path = "App\\Models\\parserSkripte\\" . $engine->{"parser-class"};
# Prüfe ob Parser vorhanden
if (!file_exists(app_path() . "/Models/parserSkripte/" . $engine->{"parser-class"} . ".php")) {
Log::error("Konnte " . $engine->{"display-name"} . " nicht abfragen, da kein Parser existiert");
$this->errors[] = trans('metaGer.engines.noParser', ['engine' => $engine->{"display-name"}]);
continue;
}
# Es wird versucht die Suchengine zu erstellen
$time = microtime();
try {
$tmp = new $path($engineName, $engine, $this);
} catch (\ErrorException $e) {
Log::error("Konnte " . $engine->{"display-name"} . " nicht abfragen. " . $e);
continue;
}
$this->engines = $engines;
}
public function getAvailableParameterFilter()
{
$parameterFilter = $this->sumaFile->filter->{"parameter-filter"};
$availableFilter = [];
foreach ($parameterFilter as $filterName => $filter) {
$values = clone $filter->values;
# Check if any of the enabled search engines provide this filter
foreach ($this->enabledSearchengines as $engineName => $engine) {
if (!empty($filter->sumas->$engineName)) {
if (empty($availableFilter[$filterName])) {
$availableFilter[$filterName] = $filter;
foreach($availableFilter[$filterName]->values as $key => $value){
if($key !== "nofilter"){
unset($availableFilter[$filterName]->values->{$key});
}
}
}
if (empty($availableFilter[$filterName]->values)) {
$availableFilter[$filterName]->values = new \stdClass();
}
foreach ($filter->sumas->{$engineName}->values as $key => $value) {
$availableFilter[$filterName]->values->{$key} = $values->$key;
# We will also add the filter from the opt-in search engines (the searchengines that are only used when a filter of it is too)
foreach ($this->sumaFile->foki->{$this->fokus}->sumas as $suma) {
if ($this->sumaFile->sumas->{$suma}->{"filter-opt-in"} && \Cookie::get($this->getFokus() . "_engine_" . $suma) !== "off") {
if (!empty($filter->sumas->{$suma})) {
# If the searchengine is disabled this filter shouldn't be available
if ((!empty($this->sumaFile->sumas->{$suma}->disabled) && $this->sumaFile->sumas->{$suma}->disabled === true)
|| (!empty($this->sumaFile->sumas->{$suma}->{"auto-disabled"}) && $this->sumaFile->sumas->{$suma}->{"auto-disabled"} === true)
) {
if (empty($availableFilter[$filterName])) {
$availableFilter[$filterName] = $filter;
foreach($availableFilter[$filterName]->values as $key => $value){
if($key !== "nofilter"){
unset($availableFilter[$filterName]->values->{$key});
}
}
}
if (empty($availableFilter[$filterName]->values)) {
$availableFilter[$filterName]->values = new \stdClass();
}
foreach ($filter->sumas->{$suma}->values as $key => $value) {
$availableFilter[$filterName]->values->{$key} = $values->$key;
# Set the current values for the filters
foreach ($availableFilter as $filterName => $filter) {
if (\Request::filled($filter->{"get-parameter"})) {
$filter->value = \Request::input($filter->{"get-parameter"});
} else if (\Cookie::get($this->getFokus() . "_setting_" . $filter->{"get-parameter"}) !== null) {
$filter->value = \Cookie::get($this->getFokus() . "_setting_" . $filter->{"get-parameter"});
}
}
public function isBildersuche()
{
return $this->fokus === "bilder";
}
public function sumaIsAdsuche($suma, $overtureEnabled)
{
$sumaName = $suma["name"]->__toString();
return
$sumaName === "qualigo"
|| $sumaName === "similar_product_ads"
|| (!$overtureEnabled && $sumaName === "overtureAds");
}
public function sumaIsDisabled($suma)
{
return
isset($suma['disabled'])
&& $suma['disabled']->__toString() === "1";
}
public function sumaIsOverture($suma)
{
return
$suma["name"]->__toString() === "overture"
|| $suma["name"]->__toString() === "overtureAds";
}
public function sumaIsNotAdsuche($suma)
{
return
$suma["name"]->__toString() !== "qualigo"
&& $suma["name"]->__toString() !== "similar_product_ads"
&& $suma["name"]->__toString() !== "overtureAds";
}
public function requestIsCached($request)
{
return
$request->filled('next')
&& Cache::has($request->input('next'))
&& unserialize(Cache::get($request->input('next')))['page'] > 1;
}
public function getCachedEngines($request)
{
$next = unserialize(Cache::get($request->input('next')));
$this->page = $next['page'];
$engines = $next['engines'];
return $engines;
}
public function waitForMainResults()
$engines = $this->engines;
$mainEngines = $this->sumaFile->foki->{$this->fokus}->main;
foreach ($mainEngines as $mainEngine) {
foreach ($engines as $engine) {
if ($engine->name === $mainEngine && !$engine->loaded) {
$enginesToWaitFor[] = $engine;
}

Dominik Hebeler
committed
$answered = [];
$results = null;
# If there is no main searchengine to wait for or if the only main engine is yahoo-ads we will define a timeout of 1s
$forceTimeout = null;
if (sizeof($enginesToWaitFor) === 1 && $enginesToWaitFor[0]->name === "yahoo-ads") {
$forceTimeout = 1;
}
while (sizeof($enginesToWaitFor) > 0 || ($forceTimeout !== null && (microtime(true) - $timeStart) < $forceTimeout)) {
foreach ($enginesToWaitFor as $index => $engine) {
if (Redis::get($engine->hash) !== null) {
$answered[] = $engine;
unset($enginesToWaitFor[$index]);
break;
}
if ((microtime(true) - $timeStart) >= 2) {

Dominik Hebeler
committed
}
public function retrieveResults()
$engines = $this->engines;
# Von geladenen Engines die Ergebnisse holen
foreach ($engines as $engine) {
if (!$engine->loaded) {
try {
$engine->retrieveResults($this);
} catch (\ErrorException $e) {
Log::error($e);
}
}
if (!empty($engine->totalResults) && $engine->totalResults > $this->totalResults) {
$this->totalResults = $engine->totalResults;
}
if (!empty($engine->alteredQuery) && !empty($engine->alterationOverrideQuery)) {
$this->alteredQuery = $engine->alteredQuery;
$this->alterationOverrideQuery = $engine->alterationOverrideQuery;
}
}
* Ende Suchmaschinenerstellung und Ergebniserhalt
*/
public function parseFormData(Request $request)
{
# Sichert, dass der request in UTF-8 formatiert ist
if ($request->input('encoding', 'utf8') !== "utf8") {
# In früheren Versionen, als es den Encoding Parameter noch nicht gab, wurden die Daten in ISO-8859-1 übertragen
$input = $request->all();
foreach ($input as $key => $value) {
$input[$key] = mb_convert_encoding("$value", "UTF-8", "ISO-8859-1");
}
$request->replace($input);
}
$this->url = $request->url();
$this->fullUrl = $request->fullUrl();
# Zunächst überprüfen wir die eingegebenen Einstellungen:
# Fokus
$this->fokus = $request->input('focus', 'web');
# Suma-File
if (App::isLocale("en")) {
$this->sumaFile = config_path() . "/sumasEn.json";
} else {
$this->sumaFile = config_path() . "/sumas.json";
if (!file_exists($this->sumaFile)) {

Karl
committed
die(trans('metaGer.formdata.cantLoad'));
} else {
$this->sumaFile = json_decode(file_get_contents($this->sumaFile));
# Sucheingabe
$this->eingabe = trim($request->input('eingabe', ''));
$this->q = $this->eingabe;
# IP
$this->ip = $this->anonymizeIp($request->ip());

Dominik Hebeler
committed
$this->useragent = $request->header('User-Agent');
# Language
if (isset($_SERVER['HTTP_LANGUAGE'])) {
$this->language = $_SERVER['HTTP_LANGUAGE'];
} else {
$this->language = "";
}
# Lang
$this->lang = $request->input('lang', 'all');
if ($this->lang !== "de" && $this->lang !== "en" && $this->lang !== "all") {
$this->lang = "all";

Dominik Hebeler
committed
$this->agent = new Agent();
$this->mobile = $this->agent->isMobile();
# Sprüche
$this->sprueche = $request->input('sprueche', 'on');
if ($this->sprueche === "on") {
$this->sprueche = true;
} else {
$this->sprueche = false;
}
$this->newtab = $request->input('newtab', 'on');
if ($this->newtab === "on") {
$this->newtab = "_blank";
} else {
$this->newtab = "_self";
}
if ($request->filled("key") && $request->input('key') === getenv("mainz_key")) {
# Theme
$this->theme = preg_replace("/[^[:alnum:][:space:]]/u", '', $request->input('theme', 'default'));
# Ergebnisse pro Seite:
$this->resultCount = $request->input('resultCount', '20');
if ($request->filled('minism') && ($request->filled('fportal') || $request->filled('harvest'))) {
$input = $request->all();
$newInput = [];
foreach ($input as $key => $value) {
if ($key !== "fportal" && $key !== "harvest") {
$newInput[$key] = $value;
}
}
$request->replace($newInput);
if (App::isLocale("en")) {
$this->sprueche = "off";
if ($this->resultCount <= 0 || $this->resultCount > 200) {
$this->resultCount = 1000;
if ($request->filled('onenewspageAll') || $request->filled('onenewspageGermanyAll')) {
$this->time = 5000;
$this->cache = "cache";
}
$this->password = $request->input('password');
}
$this->quicktips = false;