Commit 29a6022f authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Datenschutzerklärung erweitert und einige Formatierungen durchgeführt

parent 764b5d00
<?php
namespace App;
use Illuminate\Http\Request;
use Jenssegers\Agent\Agent;
use App;
use Storage;
use Log;
use Config;
use Redis;
use App\lib\TextLanguageDetect\TextLanguageDetect;
use App\lib\TextLanguageDetect\LanguageDetect\TextLanguageDetectException;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Jenssegers\Agent\Agent;
use LaravelLocalization;
use Log;
use Redis;
class MetaGer
{
# Einstellungen für die Suche
protected $fokus;
protected $eingabe;
protected $q;
protected $category;
protected $time;
protected $page;
protected $lang;
protected $cache = "";
protected $site;
protected $hostBlacklist = [];
protected $domainBlacklist = [];
protected $stopWords = [];
protected $phrases = [];
protected $engines = [];
protected $results = [];
protected $ads = [];
protected $warnings = [];
protected $errors = [];
protected $addedHosts = [];
# Daten über die Abfrage
protected $ip;
protected $language;
protected $agent;
# Konfigurationseinstellungen:
protected $sumaFile;
protected $mobile;
protected $resultCount;
protected $sprueche;
# Einstellungen für die Suche
protected $fokus;
protected $eingabe;
protected $q;
protected $category;
protected $time;
protected $page;
protected $lang;
protected $cache = "";
protected $site;
protected $hostBlacklist = [];
protected $domainBlacklist = [];
protected $stopWords = [];
protected $phrases = [];
protected $engines = [];
protected $results = [];
protected $ads = [];
protected $warnings = [];
protected $errors = [];
protected $addedHosts = [];
# Daten über die Abfrage
protected $ip;
protected $language;
protected $agent;
# Konfigurationseinstellungen:
protected $sumaFile;
protected $mobile;
protected $resultCount;
protected $sprueche;
protected $domainsBlacklisted = [];
protected $urlsBlacklisted = [];
protected $urlsBlacklisted = [];
protected $url;
protected $languageDetect;
function __construct()
{
$this->starttime = microtime(true);
if( file_exists(config_path() . "/blacklistDomains.txt") && file_exists(config_path() . "/blacklistUrl.txt") )
{
public function __construct()
{
$this->starttime = microtime(true);
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);
$tmp = file_get_contents(config_path() . "/blacklistUrl.txt");
$this->urlsBlacklisted = explode("\n", $tmp);
}else
{
$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");
}
$this->languageDetect = new TextLanguageDetect();
$this->languageDetect->setNameMode("2");
}
}
public function getHashCode ()
public function getHashCode()
{
$string = url()->full();
return md5($string);
}
public function rankAll ()
public function rankAll()
{
foreach( $this->engines as $engine )
{
foreach ($this->engines as $engine) {
$engine->rank($this);
}
}
public function createView()
{
$viewResults = [];
public function createView()
{
$viewResults = [];
# Wir extrahieren alle notwendigen Variablen und geben Sie an unseren View:
foreach($this->results as $result)
{
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)
{
if ($this->fokus === "bilder") {
switch ($this->out) {
case 'results':
return view('metager3bilderresults')
->with('results', $viewResults)
......@@ -153,7 +144,7 @@ class MetaGer
->with('browser', (new Agent())->browser());
break;
}
}
}
private function createLogs()
{
......@@ -161,87 +152,94 @@ class MetaGer
try
{
$logEntry = "";
$logEntry .= "[" . date(DATE_RFC822, mktime(date("H"),date("i"), date("s"), date("m"), date("d"), date("Y"))) . "]";
$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 .= " time=" . round((microtime(true) - $this->starttime), 2) . " serv=" . $this->fokus;
$logEntry .= " search=" . $this->eingabe;
$redis->rpush('logs.search', $logEntry);
}catch( \Exception $e)
{
} catch (\Exception $e) {
return;
}
}
public function removeInvalids ()
public function removeInvalids()
{
$results = [];
foreach($this->results as $result)
{
if($result->isValid($this))
foreach ($this->results as $result) {
if ($result->isValid($this)) {
$results[] = $result;
}
}
#$this->results = $results;
}
public function combineResults ()
{
foreach($this->engines as $engine)
{
foreach($engine->results as $result)
{
if($result->valid)
public function combineResults()
{
foreach ($this->engines as $engine) {
foreach ($engine->results as $result) {
if ($result->valid) {
$this->results[] = $result;
}
}
foreach($engine->ads as $ad)
{
foreach ($engine->ads as $ad) {
$this->ads[] = $ad;
}
}
uasort($this->results, function($a, $b){
if($a->getRank() == $b->getRank())
}
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))
foreach ($this->results as $result) {
if ($result->isValid($this)) {
$newResults[] = $result;
}
}
$this->results = $newResults;
$counter = 0;
$counter = 0;
$firstRank = 0;
foreach($this->results as $result)
{
if($counter === 0)
foreach ($this->results as $result) {
if ($counter === 0) {
$firstRank = $result->rank;
}
$counter++;
$result->number = $counter;
$confidence = 0;
if($firstRank > 0)
$confidence = $result->rank/$firstRank;
else
$confidence = 0;
if ($firstRank > 0) {
$confidence = $result->rank / $firstRank;
} else {
$confidence = 0;
if($confidence > 0.65)
}
if ($confidence > 0.65) {
$result->color = "#FF4000";
elseif($confidence > 0.4)
} elseif ($confidence > 0.4) {
$result->color = "#FF0080";
elseif($confidence > 0.2)
} elseif ($confidence > 0.2) {
$result->color = "#C000C0";
else
} else {
$result->color = "#000000";
}
}
//Get current page form url e.g. &page=6
$currentPage = LengthAwarePaginator::resolveCurrentPage();
$offset= $currentPage-1;
$offset = $currentPage - 1;
//Create a new Laravel collection from the array data
$collection = new Collection($this->results);
......@@ -259,72 +257,63 @@ class MetaGer
$currentPageSearchResults = $this->parseAdgoal($currentPageSearchResults);
//Create our paginator and pass it to the view
$paginatedSearchResults= new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);
$paginatedSearchResults = new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);
$paginatedSearchResults->setPath('/meta/meta.ger3');
foreach($this->request->all() as $key => $value)
{
if( $key === "out" )
foreach ($this->request->all() as $key => $value) {
if ($key === "out") {
continue;
}
$paginatedSearchResults->addQuery($key, $value);
}
$this->results = $paginatedSearchResults;
if( LaravelLocalization::getCurrentLocale() === "en" )
{
if (LaravelLocalization::getCurrentLocale() === "en") {
$this->ads = [];
}
$this->validated = false;
if( isset($this->password) )
{
if (isset($this->password)) {
# Wir bieten einen bezahlten API-Zugriff an, bei dem dementsprechend die Werbung ausgeblendet wurde:
# Aktuell ist es nur die Uni-Mainz. Deshalb überprüfen wir auch nur diese.
$password = getenv('mainz');
$eingabe = $this->eingabe;
$eingabe = $this->eingabe;
$password = md5($eingabe . $password);
if( $this->password === $password )
{
$this->ads = [];
if ($this->password === $password) {
$this->ads = [];
$this->validated = true;
}
}
}
}
public function parseBoost($results)
{
foreach($results as $result)
{
if(preg_match('/^(http[s]?\:\/\/)?(www.)?amazon\.de/',$result->anzeigeLink))
{
if(preg_match('/\?/',$result->anzeigeLink))
{
$result->link .= '&tag=boostmg01-21';
} else
{
$result->link .= '?tag=boostmg01-21';
}
$result->partnershop = true;
}
}
return $results;
foreach ($results as $result) {
if (preg_match('/^(http[s]?\:\/\/)?(www.)?amazon\.de/', $result->anzeigeLink)) {
if (preg_match('/\?/', $result->anzeigeLink)) {
$result->link .= '&tag=boostmg01-21';
} else {
$result->link .= '?tag=boostmg01-21';
}
$result->partnershop = true;
}
}
return $results;
}
public function parseAdgoal($results)
{
$publicKey = getenv('adgoal_public');
$publicKey = getenv('adgoal_public');
$privateKey = getenv('adgoal_private');
if( $publicKey === FALSE )
{
if ($publicKey === false) {
return $results;
}
$tldList = "";
try{
foreach($results as $result)
{
try {
foreach ($results as $result) {
$link = $result->anzeigeLink;
if(strpos($link, "http") !== 0)
{
if (strpos($link, "http") !== 0) {
$link = "http://" . $link;
}
$tldList .= parse_url($link, PHP_URL_HOST) . ",";
......@@ -335,105 +324,103 @@ class MetaGer
# Hashwert
$hash = md5("meta" . $publicKey . $tldList . "GER");
# Query
# Query
$query = urlencode($this->q);
$link = "https://api.smartredirect.de/api_v2/CheckForAffiliateUniversalsearchMetager.php?p=" . $publicKey . "&k=" . $hash . "&tld=" . $tldList . "&q=" . $query;
$link = "https://api.smartredirect.de/api_v2/CheckForAffiliateUniversalsearchMetager.php?p=" . $publicKey . "&k=" . $hash . "&tld=" . $tldList . "&q=" . $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)
{
foreach ($answer as $el) {
$hoster = $el[0];
$hash = $el[1];
$hash = $el[1];
foreach($results as $result)
{
if( $hoster === $result->tld )
{
foreach ($results as $result) {
if ($hoster === $result->tld) {
# Hier ist ein Advertiser:
# Das Logo hinzufügen:
if( $result->image !== "" )
if ($result->image !== "") {
$result->logo = "https://img.smartredirect.de/logos_v2/60x30/" . $hash . ".gif";
else
} else {
$result->image = "https://img.smartredirect.de/logos_v2/120x60/" . $hash . ".gif";
}
# Den Link hinzufügen:
$publicKey = $publicKey;
$targetUrl = $result->anzeigeLink;
if(strpos($targetUrl, "http") !== 0)
if (strpos($targetUrl, "http") !== 0) {
$targetUrl = "http://" . $targetUrl;
$gateHash = md5($targetUrl . $privateKey);
$newLink = "https://api.smartredirect.de/api_v2/ClickGate.php?p=" . $publicKey . "&k=" . $gateHash . "&url=" . urlencode($targetUrl) . "&q=" . $query;
$result->link = $newLink;
}
$gateHash = md5($targetUrl . $privateKey);
$newLink = "https://api.smartredirect.de/api_v2/ClickGate.php?p=" . $publicKey . "&k=" . $gateHash . "&url=" . urlencode($targetUrl) . "&q=" . $query;
$result->link = $newLink;
$result->partnershop = true;
}
}
}
}catch(\ErrorException $e)
{
} catch (\ErrorException $e) {
return $results;
}
return $results;
}
public function createSearchEngines (Request $request)
{
public function createSearchEngines(Request $request)
{
if( !$request->has("eingabe") )
if (!$request->has("eingabe")) {
return;
}
# Überprüfe, welche Sumas eingeschaltet sind
$xml = simplexml_load_file($this->sumaFile);
# Überprüfe, welche Sumas eingeschaltet sind
$xml = simplexml_load_file($this->sumaFile);
$enabledSearchengines = [];
$overtureEnabled = FALSE;
$countSumas = 0;
$sumas = $xml->xpath("suma");
if($this->fokus === "angepasst")
{
foreach($sumas as $suma)
{
if($request->has($suma["name"])
|| ( $this->fokus !== "bilder"
&& ($suma["name"]->__toString() === "qualigo"
|| $suma["name"]->__toString() === "similar_product_ads"
|| ( !$overtureEnabled && $suma["name"]->__toString() === "overtureAds" )
)
)
){
if(!(isset($suma['disabled']) && $suma['disabled']->__toString() === "1"))
{
if($suma["name"]->__toString() === "overture" || $suma["name"]->__toString() === "overtureAds")
{
$overtureEnabled = TRUE;
$overtureEnabled = false;
$countSumas = 0;
$sumas = $xml->xpath("suma");
if ($this->fokus === "angepasst") {
foreach ($sumas as $suma) {
if ($request->has($suma["name"])
|| ($this->fokus !== "bilder"
&& ($suma["name"]->__toString() === "qualigo"
|| $suma["name"]->__toString() === "similar_product_ads"
|| (!$overtureEnabled && $suma["name"]->__toString() === "overtureAds")
)
)
) {
if (!(isset($suma['disabled']) && $suma['disabled']->__toString() === "1")) {
if ($suma["name"]->__toString() === "overture" || $suma["name"]->__toString() === "overtureAds") {
$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;
}
$enabledSearchengines[] = $suma;
}
}
}
}else{
foreach($sumas as $suma){
$types = explode(",",$suma["type"]);
if(in_array($this->fokus, $types)
|| ( $this->fokus !== "bilder"
&& ($suma["name"]->__toString() === "qualigo"
|| $suma["name"]->__toString() === "similar_product_ads"
|| ( !$overtureEnabled && $suma["name"]->__toString() === "overtureAds" )
)
)
){
if(!(isset($suma['disabled']) && $suma['disabled']->__toString() === "1"))
{
if($suma["name"]->__toString() === "overture" || $suma["name"]->__toString() === "overtureAds")
{
$overtureEnabled = TRUE;
} else {
foreach ($sumas as $suma) {
$types = explode(",", $suma["type"]);
if (in_array($this->fokus, $types)
|| ($this->fokus !== "bilder"
&& ($suma["name"]->__toString() === "qualigo"
|| $suma["name"]->__toString() === "similar_product_ads"
|| (!$overtureEnabled && $suma["name"]->__toString() === "overtureAds")
)
)
) {
if (!(isset($suma['disabled']) && $suma['disabled']->__toString() === "1")) {
if ($suma["name"]->__toString() === "overture" || $suma["name"]->__toString() === "overtureAds") {
$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;
}
$enabledSearchengines[] = $suma;
}
}
......@@ -442,71 +429,63 @@ class MetaGer
# Sonderregelung für alle Suchmaschinen, die zu den Minisuchern gehören. Diese können alle gemeinsam über einen Link abgefragt werden
$subcollections = [];
$tmp = [];
foreach($enabledSearchengines as $engine )
{
if( isset($engine['minismCollection']) )
$tmp = [];
foreach ($enabledSearchengines as $engine) {
if (isset($engine['minismCollection'])) {
$subcollections[] = $engine['minismCollection']->__toString();
else
} else {
$tmp[] = $engine;
}
}
$enabledSearchengines = $tmp;
if( sizeof($subcollections) > 0)
{
$count = sizeof($subcollections) * 10;
$minisucherEngine = $xml->xpath('suma[@name="minism"]')[0];
$subcollections = urlencode("(" . implode(" OR ", $subcollections) . ")");
if (sizeof($subcollections) > 0) {
$count = sizeof($subcollections) * 10;
$minisucherEngine = $xml->xpath('suma[@name="minism"]')[0];
$subcollections = urlencode("(" . implode(" OR ", $subcollections) . ")");
$minisucherEngine["formData"] = str_replace("<<SUBCOLLECTIONS>>", $subcollections, $minisucherEngine["formData"]);
$minisucherEngine["formData"] = str_replace("<<COUNT>>", $count, $minisucherEngine["formData"]);
$enabledSearchengines[] = $minisucherEngine;
$enabledSearchengines[] = $minisucherEngine;
}
#die(var_dump($enabledSearchengines));
if( $countSumas <= 0 )
{
if ($countSumas <= 0) {
$this->errors[] = "Achtung: Sie haben in ihren Einstellungen keine Suchmaschine ausgewählt.";
}
$engines = [];
$engines = [];
$siteSearchFailed = false;
if( strlen($this->site) > 0 )
{
if (strlen($this->site) > 0) {
# Wenn eine Sitesearch durchgeführt werden soll, überprüfen wir ob eine der Suchmaschinen überhaupt eine Sitesearch unterstützt: