Skip to content
Snippets Groups Projects
Commit 4b6ecc25 authored by Karl Hasselbring's avatar Karl Hasselbring
Browse files

Merge branch '167-codekommentare-refactoring' into 'development'

Die MetaGer.php ist grundsätzlich aufgeräumt, aber es gibt noch ein paar zu groß…

…e Funktionen und wenig Kommentare

See merge request !360
parents 9fe94eb8 daeb4bf0
No related branches found
No related tags found
2 merge requests!361Development,!360Die MetaGer.php ist grundsätzlich aufgeräumt, aber es gibt noch ein paar zu groß…
...@@ -51,9 +51,11 @@ class MetaGer ...@@ -51,9 +51,11 @@ class MetaGer
public function __construct() public function __construct()
{ {
# Timer starten
$this->starttime = microtime(true); $this->starttime = microtime(true);
# Versuchen Blacklists einzulesen
if (file_exists(config_path() . "/blacklistDomains.txt") && file_exists(config_path() . "/blacklistUrl.txt")) { if (file_exists(config_path() . "/blacklistDomains.txt") && file_exists(config_path() . "/blacklistUrl.txt")) {
# Blacklists einlesen:
$tmp = file_get_contents(config_path() . "/blacklistDomains.txt"); $tmp = file_get_contents(config_path() . "/blacklistDomains.txt");
$this->domainsBlacklisted = explode("\n", $tmp); $this->domainsBlacklisted = explode("\n", $tmp);
$tmp = file_get_contents(config_path() . "/blacklistUrl.txt"); $tmp = file_get_contents(config_path() . "/blacklistUrl.txt");
...@@ -62,6 +64,7 @@ class MetaGer ...@@ -62,6 +64,7 @@ class MetaGer
Log::warning("Achtung: Eine, oder mehrere Blacklist Dateien, konnten nicht geöffnet werden"); Log::warning("Achtung: Eine, oder mehrere Blacklist Dateien, konnten nicht geöffnet werden");
} }
# Parser Skripte einhängen
$dir = app_path() . "/Models/parserSkripte/"; $dir = app_path() . "/Models/parserSkripte/";
foreach (scandir($dir) as $filename) { foreach (scandir($dir) as $filename) {
$path = $dir . $filename; $path = $dir . $filename;
...@@ -70,9 +73,11 @@ class MetaGer ...@@ -70,9 +73,11 @@ class MetaGer
} }
} }
# Spracherkennung starten
$this->languageDetect = new TextLanguageDetect(); $this->languageDetect = new TextLanguageDetect();
$this->languageDetect->setNameMode("2"); $this->languageDetect->setNameMode("2");
# Cachebarkeit testen
try { try {
Cache::has('test'); Cache::has('test');
$this->canCache = true; $this->canCache = true;
...@@ -81,19 +86,7 @@ class MetaGer ...@@ -81,19 +86,7 @@ class MetaGer
} }
} }
public function getHashCode() # Erstellt aus den gesammelten Ergebnissen den View
{
$string = url()->full();
return md5($string);
}
public function rankAll()
{
foreach ($this->engines as $engine) {
$engine->rank($this);
}
}
public function createView() public function createView()
{ {
$viewResults = []; $viewResults = [];
...@@ -127,60 +120,39 @@ class MetaGer ...@@ -127,60 +120,39 @@ class MetaGer
->with('metager', $this) ->with('metager', $this)
->with('browser', (new Agent())->browser()); ->with('browser', (new Agent())->browser());
} }
} } else {
switch ($this->out) {
switch ($this->out) { case 'results':
case 'results': return view('metager3results')
return view('metager3results') ->with('results', $viewResults)
->with('results', $viewResults) ->with('eingabe', $this->eingabe)
->with('eingabe', $this->eingabe) ->with('mobile', $this->mobile)
->with('mobile', $this->mobile) ->with('warnings', $this->warnings)
->with('warnings', $this->warnings) ->with('errors', $this->errors)
->with('errors', $this->errors) ->with('metager', $this)
->with('metager', $this) ->with('browser', (new Agent())->browser());
->with('browser', (new Agent())->browser()); break;
break; case 'results-with-style':
case 'results-with-style': return view('metager3')
return view('metager3') ->with('results', $viewResults)
->with('results', $viewResults) ->with('eingabe', $this->eingabe)
->with('eingabe', $this->eingabe) ->with('mobile', $this->mobile)
->with('mobile', $this->mobile) ->with('warnings', $this->warnings)
->with('warnings', $this->warnings) ->with('errors', $this->errors)
->with('errors', $this->errors) ->with('metager', $this)
->with('metager', $this) ->with('suspendheader', "yes")
->with('suspendheader', "yes") ->with('browser', (new Agent())->browser());
->with('browser', (new Agent())->browser()); break;
break; default:
default: return view('metager3')
return view('metager3') ->with('eingabe', $this->eingabe)
->with('eingabe', $this->eingabe) ->with('mobile', $this->mobile)
->with('mobile', $this->mobile) ->with('warnings', $this->warnings)
->with('warnings', $this->warnings) ->with('errors', $this->errors)
->with('errors', $this->errors) ->with('metager', $this)
->with('metager', $this) ->with('browser', (new Agent())->browser());
->with('browser', (new Agent())->browser()); break;
break; }
}
}
private function createLogs()
{
$redis = Redis::connection('redisLogs');
try
{
$logEntry = "";
$logEntry .= "[" . date(DATE_RFC822, mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y"))) . "]";
$logEntry .= " pid=" . getmypid();
$logEntry .= " ref=" . $this->request->header('Referer');
$useragent = $this->request->header('User-Agent');
$useragent = str_replace("(", " ", $useragent);
$useragent = str_replace(")", " ", $useragent);
$useragent = str_replace(" ", "", $useragent);
$logEntry .= " time=" . round((microtime(true) - $this->starttime), 2) . " serv=" . $this->fokus;
$logEntry .= " search=" . $this->eingabe;
$redis->rpush('logs.search', $logEntry);
} catch (\Exception $e) {
return;
} }
} }
...@@ -193,7 +165,6 @@ class MetaGer ...@@ -193,7 +165,6 @@ class MetaGer
} }
} }
#$this->results = $results;
} }
public function combineResults() public function combineResults()
...@@ -222,6 +193,7 @@ class MetaGer ...@@ -222,6 +193,7 @@ class MetaGer
return ($a->getRank() < $b->getRank()) ? 1 : -1; return ($a->getRank() < $b->getRank()) ? 1 : -1;
}); });
# Validate Results # Validate Results
$newResults = []; $newResults = [];
foreach ($this->results as $result) { foreach ($this->results as $result) {
...@@ -325,6 +297,7 @@ class MetaGer ...@@ -325,6 +297,7 @@ class MetaGer
} }
return $results; return $results;
} }
public function parseAdgoal($results) public function parseAdgoal($results)
{ {
$publicKey = getenv('adgoal_public'); $publicKey = getenv('adgoal_public');
...@@ -391,7 +364,6 @@ class MetaGer ...@@ -391,7 +364,6 @@ class MetaGer
public function createSearchEngines(Request $request) public function createSearchEngines(Request $request)
{ {
if (!$request->has("eingabe")) { if (!$request->has("eingabe")) {
return; return;
} }
...@@ -400,10 +372,11 @@ class MetaGer ...@@ -400,10 +372,11 @@ class MetaGer
$xml = simplexml_load_file($this->sumaFile); $xml = simplexml_load_file($this->sumaFile);
$enabledSearchengines = []; $enabledSearchengines = [];
$overtureEnabled = false; $overtureEnabled = false;
$countSumas = 0; $sumaCount = 0;
$sumas = $xml->xpath("suma"); $sumas = $xml->xpath("suma");
if ($this->fokus === "angepasst") {
foreach ($sumas as $suma) { foreach ($sumas as $suma) {
if ($this->fokus === "angepasst") {
if ($request->has($suma["name"]) if ($request->has($suma["name"])
|| ($this->fokus !== "bilder" || ($this->fokus !== "bilder"
&& ($suma["name"]->__toString() === "qualigo" && ($suma["name"]->__toString() === "qualigo"
...@@ -418,15 +391,12 @@ class MetaGer ...@@ -418,15 +391,12 @@ class MetaGer
$overtureEnabled = true; $overtureEnabled = true;
} }
if ($suma["name"]->__toString() !== "qualigo" && $suma["name"]->__toString() !== "similar_product_ads" && $suma["name"]->__toString() !== "overtureAds") { if ($suma["name"]->__toString() !== "qualigo" && $suma["name"]->__toString() !== "similar_product_ads" && $suma["name"]->__toString() !== "overtureAds") {
$countSumas += 1; $sumaCount += 1;
} }
$enabledSearchengines[] = $suma; $enabledSearchengines[] = $suma;
} }
} }
} } else {
} else {
foreach ($sumas as $suma) {
$types = explode(",", $suma["type"]); $types = explode(",", $suma["type"]);
if (in_array($this->fokus, $types) if (in_array($this->fokus, $types)
|| ($this->fokus !== "bilder" || ($this->fokus !== "bilder"
...@@ -441,9 +411,8 @@ class MetaGer ...@@ -441,9 +411,8 @@ class MetaGer
$overtureEnabled = true; $overtureEnabled = true;
} }
if ($suma["name"]->__toString() !== "qualigo" && $suma["name"]->__toString() !== "similar_product_ads" && $suma["name"]->__toString() !== "overtureAds") { if ($suma["name"]->__toString() !== "qualigo" && $suma["name"]->__toString() !== "similar_product_ads" && $suma["name"]->__toString() !== "overtureAds") {
$countSumas += 1; $sumaCount += 1;
} }
$enabledSearchengines[] = $suma; $enabledSearchengines[] = $suma;
} }
} }
...@@ -471,30 +440,13 @@ class MetaGer ...@@ -471,30 +440,13 @@ class MetaGer
$enabledSearchengines[] = $minisucherEngine; $enabledSearchengines[] = $minisucherEngine;
} }
#die(var_dump($enabledSearchengines)); if ($sumaCount <= 0) {
if ($countSumas <= 0) {
$this->errors[] = "Achtung: Sie haben in ihren Einstellungen keine Suchmaschine ausgewählt."; $this->errors[] = "Achtung: Sie haben in ihren Einstellungen keine Suchmaschine ausgewählt.";
} }
$engines = []; $engines = [];
$siteSearchFailed = false; # Wenn eine Sitesearch durchgeführt werden soll, überprüfen wir ob eine der Suchmaschinen überhaupt eine Sitesearch unterstützt
if (strlen($this->site) > 0) { $siteSearchFailed = $this->checkCanNotSitesearch($enabledSearchengines);
# Wenn eine Sitesearch durchgeführt werden soll, überprüfen wir ob eine der Suchmaschinen überhaupt eine Sitesearch unterstützt:
$enginesWithSite = 0;
foreach ($enabledSearchengines as $engine) {
if (isset($engine['hasSiteSearch']) && $engine['hasSiteSearch']->__toString() === "1") {
$enginesWithSite++;
}
}
if ($enginesWithSite === 0) {
$this->errors[] = "Sie wollten eine Sitesearch auf " . $this->site . " durchführen. Leider unterstützen die eingestellten Suchmaschinen diese nicht. Sie können <a href=\"" . $this->generateSearchLink("web", false) . "\">hier</a> die Sitesearch im Web-Fokus durchführen. Es werden ihnen Ergebnisse ohne Sitesearch angezeigt.";
$siteSearchFailed = true;
} else {
$this->warnings[] = "Sie führen eine Sitesearch durch. Es werden nur Ergebnisse von der Seite: <a href=\"http://" . $this->site . "\" target=\"_blank\">\"" . $this->site . "\"</a> angezeigt.";
}
}
$typeslist = []; $typeslist = [];
$counter = 0; $counter = 0;
...@@ -552,6 +504,36 @@ class MetaGer ...@@ -552,6 +504,36 @@ class MetaGer
$engine->startSearch($this); $engine->startSearch($this);
} }
$this->adjustFocus($sumas, $enabledSearchengines);
/* Nun passiert ein elementarer Schritt.
* Wir warten auf die Antwort der Suchmaschinen, da wir vorher nicht weiter machen können.
* Aber natürlich nicht ewig.
* Die Verbindung steht zu diesem Zeitpunkt und auch unsere Request wurde schon gesendet.
* Wir geben der Suchmaschine nun bis zu 500ms Zeit zu antworten.
*/
# Wir zählen die Suchmaschinen, die durch den Cache beantwortet wurden:
$enginesToLoad = 0;
$canBreak = false;
foreach ($engines as $engine) {
if ($engine->cached) {
$enginesToLoad--;
if ($overtureEnabled && ($engine->name === "overture" || $engine->name === "overtureAds")) {
$canBreak = true;
}
}
}
$enginesToLoad += count($engines);
$this->waitForResults($enginesToLoad, $overtureEnabled, $canBreak);
$this->retrieveResults($engines);
}
public function adjustFocus($sumas, $enabledSearchengines)
{
# Jetzt werden noch alle Kategorien der Settings durchgegangen und die jeweils enthaltenen namen der Suchmaschinen gespeichert. # Jetzt werden noch alle Kategorien der Settings durchgegangen und die jeweils enthaltenen namen der Suchmaschinen gespeichert.
$foki = []; $foki = [];
foreach ($sumas as $suma) { foreach ($sumas as $suma) {
...@@ -577,6 +559,7 @@ class MetaGer ...@@ -577,6 +559,7 @@ class MetaGer
$realEngNames[] = $nam; $realEngNames[] = $nam;
} }
} }
# Anschließend werden diese beiden Listen verglichen (jeweils eine der Fokuslisten für jeden Fokus), um herauszufinden ob sie vielleicht identisch sind. Ist dies der Fall, so hat der Nutzer anscheinend Suchmaschinen eines kompletten Fokus eingestellt. Der Fokus wird dementsprechend angepasst. # Anschließend werden diese beiden Listen verglichen (jeweils eine der Fokuslisten für jeden Fokus), um herauszufinden ob sie vielleicht identisch sind. Ist dies der Fall, so hat der Nutzer anscheinend Suchmaschinen eines kompletten Fokus eingestellt. Der Fokus wird dementsprechend angepasst.
foreach ($foki as $fok => $engs) { foreach ($foki as $fok => $engs) {
$isFokus = true; $isFokus = true;
...@@ -598,26 +581,29 @@ class MetaGer ...@@ -598,26 +581,29 @@ class MetaGer
$this->fokus = $fok; $this->fokus = $fok;
} }
} }
}
# Nun passiert ein elementarer Schritt. public function checkCanNotSitesearch($enabledSearchengines)
# Wir warten auf die Antwort der Suchmaschinen, da wir vorher nicht weiter machen können. {
# aber natürlich nicht ewig. if (strlen($this->site) > 0) {
# Die Verbindung steht zu diesem Zeitpunkt und auch unsere Request wurde schon gesendet. $enginesWithSite = 0;
# Wir geben der Suchmaschine nun bis zu 500ms Zeit zu antworten. foreach ($enabledSearchengines as $engine) {
if (isset($engine['hasSiteSearch']) && $engine['hasSiteSearch']->__toString() === "1") {
# Wir zählen die Suchmaschinen, die durch den Cache beantwortet wurden: $enginesWithSite++;
$enginesToLoad = 0;
$canBreak = false;
foreach ($engines as $engine) {
if ($engine->cached) {
$enginesToLoad--;
if ($overtureEnabled && ($engine->name === "overture" || $engine->name === "overtureAds")) {
$canBreak = true;
} }
}
if ($enginesWithSite === 0) {
$this->errors[] = "Sie wollten eine Sitesearch auf " . $this->site . " durchführen. Leider unterstützen die eingestellten Suchmaschinen diese nicht. Sie können <a href=\"" . $this->generateSearchLink("web", false) . "\">hier</a> die Sitesearch im Web-Fokus durchführen. Es werden ihnen Ergebnisse ohne Sitesearch angezeigt.";
return true;
} else {
$this->warnings[] = "Sie führen eine Sitesearch durch. Es werden nur Ergebnisse von der Seite: <a href=\"http://" . $this->site . "\" target=\"_blank\">\"" . $this->site . "\"</a> angezeigt.";
return false;
} }
} }
$enginesToLoad += count($engines); }
public function waitForResults($enginesToLoad, $overtureEnabled, $canBreak)
{
$loadedEngines = 0; $loadedEngines = 0;
$timeStart = microtime(true); $timeStart = microtime(true);
while (true) { while (true) {
...@@ -643,24 +629,26 @@ class MetaGer ...@@ -643,24 +629,26 @@ class MetaGer
} }
usleep(50000); usleep(50000);
} }
}
public function retrieveResults($engines)
{
# Von geladenen Engines die Ergebnisse holen
foreach ($engines as $engine) { foreach ($engines as $engine) {
if (!$engine->loaded) { if (!$engine->loaded) {
try { try {
$engine->retrieveResults($this); $engine->retrieveResults($this);
} catch (\ErrorException $e) { } catch (\ErrorException $e) {
Log::error($e); Log::error($e);
} }
} }
} }
# und verwerfen den Rest: # Nicht fertige Engines verwefen
foreach ($engines as $engine) { foreach ($engines as $engine) {
if (!$engine->loaded) { if (!$engine->loaded) {
$engine->shutdown(); $engine->shutdown();
} }
} }
$this->engines = $engines; $this->engines = $engines;
...@@ -668,6 +656,7 @@ class MetaGer ...@@ -668,6 +656,7 @@ class MetaGer
public function parseFormData(Request $request) public function parseFormData(Request $request)
{ {
# Sichert, dass der request in UTF-8 formatiert ist
if ($request->input('encoding', '') !== "utf8") { if ($request->input('encoding', '') !== "utf8") {
# In früheren Versionen, als es den Encoding Parameter noch nicht gab, wurden die Daten in ISO-8859-1 übertragen # In früheren Versionen, als es den Encoding Parameter noch nicht gab, wurden die Daten in ISO-8859-1 übertragen
$input = $request->all(); $input = $request->all();
...@@ -678,14 +667,12 @@ class MetaGer ...@@ -678,14 +667,12 @@ class MetaGer
} }
$this->url = $request->url(); $this->url = $request->url();
# Zunächst überprüfen wir die eingegebenen Einstellungen: # Zunächst überprüfen wir die eingegebenen Einstellungen:
# FOKUS # Fokus
$this->fokus = trans('fokiNames.' $this->fokus = trans('fokiNames.' . $request->input('focus', 'web'));
. $request->input('focus', 'web'));
if (strpos($this->fokus, ".")) { if (strpos($this->fokus, ".")) {
$this->fokus = trans('fokiNames.web'); $this->fokus = trans('fokiNames.web');
} }
# Suma-File
# SUMA-FILE
if (App::isLocale("en")) { if (App::isLocale("en")) {
$this->sumaFile = config_path() . "/sumas.xml"; $this->sumaFile = config_path() . "/sumas.xml";
} else { } else {
...@@ -694,18 +681,15 @@ class MetaGer ...@@ -694,18 +681,15 @@ class MetaGer
if (!file_exists($this->sumaFile)) { if (!file_exists($this->sumaFile)) {
die("Suma-File konnte nicht gefunden werden"); die("Suma-File konnte nicht gefunden werden");
} }
# Sucheingabe
# Sucheingabe:
$this->eingabe = trim($request->input('eingabe', '')); $this->eingabe = trim($request->input('eingabe', ''));
if (strlen($this->eingabe) === 0) { if (strlen($this->eingabe) === 0) {
$this->warnings[] = 'Achtung: Sie haben keinen Suchbegriff eingegeben. Sie können ihre Suchbegriffe oben eingeben und es erneut versuchen.'; $this->warnings[] = 'Achtung: Sie haben keinen Suchbegriff eingegeben. Sie können ihre Suchbegriffe oben eingeben und es erneut versuchen.';
} }
$this->q = $this->eingabe; $this->q = $this->eingabe;
# IP
# IP:
$this->ip = $request->ip(); $this->ip = $request->ip();
# Language
# Language:
if (isset($_SERVER['HTTP_LANGUAGE'])) { if (isset($_SERVER['HTTP_LANGUAGE'])) {
$this->language = $_SERVER['HTTP_LANGUAGE']; $this->language = $_SERVER['HTTP_LANGUAGE'];
} else { } else {
...@@ -713,9 +697,8 @@ class MetaGer ...@@ -713,9 +697,8 @@ class MetaGer
} }
# Category # Category
$this->category = $request->input('category', ''); $this->category = $request->input('category', '');
# Request Times: # Request Times
$this->time = $request->input('time', 1000); $this->time = $request->input('time', 1000);
# Page # Page
$this->page = 1; $this->page = 1;
# Lang # Lang
...@@ -725,18 +708,15 @@ class MetaGer ...@@ -725,18 +708,15 @@ class MetaGer
} }
$this->agent = new Agent(); $this->agent = new Agent();
$this->mobile = $this->agent->isMobile(); $this->mobile = $this->agent->isMobile();
# Sprüche
#Sprüche
$this->sprueche = $request->input('sprueche', 'off'); $this->sprueche = $request->input('sprueche', 'off');
if ($this->sprueche === "off") { if ($this->sprueche === "off") {
$this->sprueche = true; $this->sprueche = true;
} else { } else {
$this->sprueche = false; $this->sprueche = false;
} }
# Ergebnisse pro Seite: # Ergebnisse pro Seite:
$this->resultCount = $request->input('resultCount', '20'); $this->resultCount = $request->input('resultCount', '20');
# Manchmal müssen wir Parameter anpassen um den Sucheinstellungen gerecht zu werden: # Manchmal müssen wir Parameter anpassen um den Sucheinstellungen gerecht zu werden:
if ($request->has('dart')) { if ($request->has('dart')) {
$this->time = 10000; $this->time = 10000;
...@@ -777,24 +757,22 @@ class MetaGer ...@@ -777,24 +757,22 @@ class MetaGer
if ($request->has('password')) { if ($request->has('password')) {
$this->password = $request->input('password'); $this->password = $request->input('password');
} }
if ($request->has('quicktips')) { if ($request->has('quicktips')) {
$this->quicktips = false; $this->quicktips = false;
} else { } else {
$this->quicktips = true; $this->quicktips = true;
} }
$this->out = $request->input('out', "html"); $this->out = $request->input('out', "html");
# Standard output format html
if ($this->out !== "html" && $this->out !== "json" && $this->out !== "results" && $this->out !== "results-with-style") { if ($this->out !== "html" && $this->out !== "json" && $this->out !== "results" && $this->out !== "results-with-style") {
$this->out = "html"; $this->out = "html";
} }
$this->request = $request; $this->request = $request;
} }
public function checkSpecialSearches(Request $request) public function checkSpecialSearches(Request $request)
{ {
# Site Search: # Site Search
if (preg_match("/(.*)\bsite:(\S+)(.*)/si", $this->q, $match)) { if (preg_match("/(.*)\bsite:(\S+)(.*)/si", $this->q, $match)) {
$this->site = $match[2]; $this->site = $match[2];
$this->q = $match[1] . $match[3]; $this->q = $match[1] . $match[3];
...@@ -802,8 +780,9 @@ class MetaGer ...@@ -802,8 +780,9 @@ class MetaGer
if ($request->has('site')) { if ($request->has('site')) {
$this->site = $request->input('site'); $this->site = $request->input('site');
} }
# Host Blacklisting
# Wenn die Suchanfrage um das Schlüsselwort "-host:*" ergänzt ist, sollen bestimmte Hosts nicht eingeblendet werden # Wenn die Suchanfrage um das Schlüsselwort "-host:*" ergänzt ist, sollen bestimmte Hosts nicht eingeblendet werden
# Wir prüfen, ob das hier der Fall ist:
while (preg_match("/(.*)(^|\s)-host:(\S+)(.*)/si", $this->q, $match)) { while (preg_match("/(.*)(^|\s)-host:(\S+)(.*)/si", $this->q, $match)) {
$this->hostBlacklist[] = $match[3]; $this->hostBlacklist[] = $match[3];
$this->q = $match[1] . $match[4]; $this->q = $match[1] . $match[4];
...@@ -816,8 +795,9 @@ class MetaGer ...@@ -816,8 +795,9 @@ class MetaGer
$hostString = rtrim($hostString, ", "); $hostString = rtrim($hostString, ", ");
$this->warnings[] = "Ergebnisse von folgenden Hosts werden nicht angezeigt: \"" . $hostString . "\""; $this->warnings[] = "Ergebnisse von folgenden Hosts werden nicht angezeigt: \"" . $hostString . "\"";
} }
# Domain Blacklisting
# Wenn die Suchanfrage um das Schlüsselwort "-domain:*" ergänzt ist, sollen bestimmte Domains nicht eingeblendet werden # Wenn die Suchanfrage um das Schlüsselwort "-domain:*" ergänzt ist, sollen bestimmte Domains nicht eingeblendet werden
# Wir prüfen, ob das hier der Fall ist:
while (preg_match("/(.*)(^|\s)-domain:(\S+)(.*)/si", $this->q, $match)) { while (preg_match("/(.*)(^|\s)-domain:(\S+)(.*)/si", $this->q, $match)) {
$this->domainBlacklist[] = $match[3]; $this->domainBlacklist[] = $match[3];
$this->q = $match[1] . $match[4]; $this->q = $match[1] . $match[4];
...@@ -831,8 +811,8 @@ class MetaGer ...@@ -831,8 +811,8 @@ class MetaGer
$this->warnings[] = "Ergebnisse von folgenden Domains werden nicht angezeigt: \"" . $domainString . "\""; $this->warnings[] = "Ergebnisse von folgenden Domains werden nicht angezeigt: \"" . $domainString . "\"";
} }
# Stopwords
# Alle mit "-" gepräfixten Worte sollen aus der Suche ausgeschlossen werden. # Alle mit "-" gepräfixten Worte sollen aus der Suche ausgeschlossen werden.
# Wir prüfen, ob das hier der Fall ist:
while (preg_match("/(.*)(^|\s)-(\S+)(.*)/si", $this->q, $match)) { while (preg_match("/(.*)(^|\s)-(\S+)(.*)/si", $this->q, $match)) {
$this->stopWords[] = $match[3]; $this->stopWords[] = $match[3];
$this->q = $match[1] . $match[4]; $this->q = $match[1] . $match[4];
...@@ -846,7 +826,7 @@ class MetaGer ...@@ -846,7 +826,7 @@ class MetaGer
$this->warnings[] = "Sie machen eine Ausschlusssuche. Ergebnisse mit folgenden Wörtern werden nicht angezeigt: \"" . $stopwordsString . "\""; $this->warnings[] = "Sie machen eine Ausschlusssuche. Ergebnisse mit folgenden Wörtern werden nicht angezeigt: \"" . $stopwordsString . "\"";
} }
# Meldung über eine Phrasensuche # Phrasensuche
$p = ""; $p = "";
$tmp = $this->q; $tmp = $this->q;
while (preg_match("/(.*)\"(.+)\"(.*)/si", $tmp, $match)) { while (preg_match("/(.*)\"(.+)\"(.*)/si", $tmp, $match)) {
...@@ -863,125 +843,68 @@ class MetaGer ...@@ -863,125 +843,68 @@ class MetaGer
} }
public function getFokus() public function nextSearchLink()
{
return $this->fokus;
}
public function getIp()
{
return $this->ip;
}
public function getEingabe()
{
return $this->eingabe;
}
public function getQ()
{
return $this->q;
}
public function getUrl()
{
return $this->url;
}
public function getTime()
{
return $this->time;
}
public function getLanguage()
{
return $this->language;
}
public function getLang()
{
return $this->lang;
}
public function getSprueche()
{
return $this->sprueche;
}
public function getCategory()
{
return $this->category;
}
public function getPhrases()
{
return $this->phrases;
}
public function getPage()
{
return $this->page;
}
public function getSumaFile()
{ {
return $this->sumaFile; if (isset($this->next) && isset($this->next['engines']) && count($this->next['engines']) > 0) {
$requestData = $this->request->except(['page', 'out']);
$requestData['next'] = md5(serialize($this->next));
$link = action('MetaGerSearch@search', $requestData);
} else {
$link = "#";
}
return $link;
} }
public function getUserHostBlacklist() public function rankAll()
{ {
return $this->hostBlacklist; foreach ($this->engines as $engine) {
$engine->rank($this);
}
} }
public function getUserDomainBlacklist() # Hilfsfunktionen
{
return $this->domainBlacklist;
}
public function getDomainBlacklist() public function showQuicktips()
{ {
return $this->domainsBlacklisted; return $this->quicktips;
} }
public function getUrlBlacklist() public function popAd()
{
return $this->urlsBlacklisted;
}
public function getLanguageDetect()
{
return $this->languageDetect;
}
public function getStopWords()
{
return $this->stopWords;
}
public function getHostCount($host)
{
if (isset($this->addedHosts[$host])) {
return $this->addedHosts[$host];
} else {
return 0;
}
}
public function getStartCount()
{
return $this->startCount;
}
public function addHostCount($host)
{ {
$hash = md5($host); if (count($this->ads) > 0) {
if (isset($this->addedHosts[$hash])) { return get_object_vars(array_shift($this->ads));
$this->addedHosts[$hash] += 1;
} else { } else {
$this->addedHosts[$hash] = 1; return null;
} }
} }
public function canCache() public function canCache()
{ {
return $this->canCache; return $this->canCache;
} }
public function getSite()
public function createLogs()
{ {
return $this->site; $redis = Redis::connection('redisLogs');
try
{
$logEntry = "";
$logEntry .= "[" . date(DATE_RFC822, mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y"))) . "]";
$logEntry .= " pid=" . getmypid();
$logEntry .= " ref=" . $this->request->header('Referer');
$useragent = $this->request->header('User-Agent');
$useragent = str_replace("(", " ", $useragent);
$useragent = str_replace(")", " ", $useragent);
$useragent = str_replace(" ", "", $useragent);
$logEntry .= " time=" . round((microtime(true) - $this->starttime), 2) . " serv=" . $this->fokus;
$logEntry .= " search=" . $this->eingabe;
$redis->rpush('logs.search', $logEntry);
} catch (\Exception $e) {
return;
}
} }
public function addLink($link) public function addLink($link)
{ {
if (strpos($link, "http://") === 0) { if (strpos($link, "http://") === 0) {
...@@ -1007,6 +930,18 @@ class MetaGer ...@@ -1007,6 +930,18 @@ class MetaGer
} }
} }
public function addHostCount($host)
{
$hash = md5($host);
if (isset($this->addedHosts[$hash])) {
$this->addedHosts[$hash] += 1;
} else {
$this->addedHosts[$hash] = 1;
}
}
# Generators
public function generateSearchLink($fokus, $results = true) public function generateSearchLink($fokus, $results = true)
{ {
$requestData = $this->request->except(['page', 'next']); $requestData = $this->request->except(['page', 'next']);
...@@ -1056,44 +991,143 @@ class MetaGer ...@@ -1056,44 +991,143 @@ class MetaGer
return $link; return $link;
} }
public function nextSearchLink() # Komplexe Getter
public function getHostCount($host)
{ {
if (isset($this->next) && isset($this->next['engines']) && count($this->next['engines']) > 0) { if (isset($this->addedHosts[$host])) {
$requestData = $this->request->except(['page', 'out']); return $this->addedHosts[$host];
$requestData['next'] = md5(serialize($this->next));
$link = action('MetaGerSearch@search', $requestData);
} else { } else {
$link = "#"; return 0;
} }
}
public function getImageProxyLink($link)
{
$requestData = [];
$requestData["url"] = $link;
$link = action('Pictureproxy@get', $requestData);
return $link; return $link;
} }
public function getHashCode()
{
$string = url()->full();
return md5($string);
}
# Einfache Getter
public function getSite()
{
return $this->site;
}
public function getTab() public function getTab()
{ {
return $this->tab; return $this->tab;
} }
public function getResults() public function getResults()
{ {
return $this->results; return $this->results;
} }
public function popAd()
public function getFokus()
{ {
if (count($this->ads) > 0) { return $this->fokus;
return get_object_vars(array_shift($this->ads)); }
} else {
return null;
}
public function getIp()
{
return $this->ip;
} }
public function getImageProxyLink($link)
public function getEingabe()
{ {
$requestData = []; return $this->eingabe;
$requestData["url"] = $link;
$link = action('Pictureproxy@get', $requestData);
return $link;
} }
public function showQuicktips()
public function getQ()
{ {
return $this->quicktips; return $this->q;
}
public function getUrl()
{
return $this->url;
}
public function getTime()
{
return $this->time;
}
public function getLanguage()
{
return $this->language;
}
public function getLang()
{
return $this->lang;
}
public function getSprueche()
{
return $this->sprueche;
}
public function getCategory()
{
return $this->category;
}
public function getPhrases()
{
return $this->phrases;
}
public function getPage()
{
return $this->page;
}
public function getSumaFile()
{
return $this->sumaFile;
}
public function getUserHostBlacklist()
{
return $this->hostBlacklist;
}
public function getUserDomainBlacklist()
{
return $this->domainBlacklist;
}
public function getDomainBlacklist()
{
return $this->domainsBlacklisted;
}
public function getUrlBlacklist()
{
return $this->urlsBlacklisted;
}
public function getLanguageDetect()
{
return $this->languageDetect;
}
public function getStopWords()
{
return $this->stopWords;
}
public function getStartCount()
{
return $this->startCount;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment