Skip to content
Snippets Groups Projects
Commit a6c60fcf authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Einen Teil der Logik von MetaGer habe ich nun nach PHP überführt

parent 446fb9f9
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,8 @@ use App\Http\Controllers\Controller; ...@@ -6,6 +6,8 @@ use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\MetaGer\Forwarder; use App\MetaGer\Forwarder;
use App\MetaGer\Results; use App\MetaGer\Results;
use App;
use App\MetaGer\Search;
class MetaGerSearch extends Controller class MetaGerSearch extends Controller
{ {
...@@ -28,8 +30,52 @@ class MetaGerSearch extends Controller ...@@ -28,8 +30,52 @@ class MetaGerSearch extends Controller
public function search(Request $request) public function search(Request $request)
{ {
$results = new Results($request); # Zunächst überprüfen wir die eingegebenen Einstellungen:
return $results->loadSearchEngines(); # FOKUS
$fokus = $request->input('focus', 'web');
$fokus = trans('fokiNames.'.$fokus);
if(strpos($fokus,".")){
$fokus = trans('fokiNames.web');
}
define("FOKUS", $fokus);
# SUMA-FILE
if(App::isLocale("en")){
define("SUMA_FILE", config_path() . "/sumasEn.xml");
}else{
define("SUMA_FILE", config_path() . "/sumas.xml");
}
if(!file_exists(SUMA_FILE)){
die("Suma-File konnte nicht gefunden werden");
}
# Sucheingabe:
$eingabe = trim($request->input('eingabe', ''));
if(strlen($eingabe) === 0){
return 'Achtung: Sie haben keinen Suchbegriff eingegeben. Sie können ihre Suchbegriffe oben eingeben und es erneut versuchen.';
}else{
define("Q", $eingabe);
}
# IP:
if( isset($_SERVER['HTTP_FROM']) )
{
define("IP", $_SERVER['HTTP_FROM']);
}else
{
define("IP", "127.0.0.1");
}
# Language:
if( isset($_SERVER['HTTP_LANGUAGE']) )
{
define("LANGUAGE", $_SERVER['HTTP_LANGUAGE']);
}else
{
define("LANGUAGE", "");
}
# Category
define("CATEGORY", $request->input('category', ''));
$searchengines = Search::loadSearchEngines($request);
$results = new Results($searchengines);
return $results->results;
} }
} }
\ No newline at end of file
...@@ -2,30 +2,31 @@ ...@@ -2,30 +2,31 @@
namespace App\MetaGer; namespace App\MetaGer;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use File;
class Results class Results
{ {
private $request;
private $fokiNames = []; private $fokiNames = [];
private $fokus; private $fokus;
function __construct (Request $request) function __construct ($engines)
{ {
$this->request = $request; $this->results = $this->loadResults($engines);
$this->fokiNames[] = trans('fokiNames.web');
$this->fokiNames[] = trans('fokiNames.nachrichten');
$this->fokiNames[] = trans('fokiNames.wissenschaft');
$this->fokiNames[] = trans('fokiNames.produktsuche');
$this->fokiNames[] = trans('fokiNames.bilder');
$this->fokiNames[] = trans('fokiNames.angepasst');
} }
public function loadSearchEngines () private function loadResults($engines)
{ {
# Wenn keine persönlichen Einstellungen gesetzt sind, dafür aber ein existierender Fokus von uns, # Das Laden der Ergebnisse besteht aus 2 Elementaren Schritten:
# werden die zu dem Fokus gehörenden Suchmaschinen angeschaltet. # 1. GET-Requests abarbeiten
return $this->request->input('focus', 'test'); # 2. Ergebnisse parsen
return var_dump($this->fokiNames);
# 1. GET-Requests abarbeiten
# Wir generiern zunächst alle GET-Strings:
$getStrings = [];
foreach($engines as $engine)
{
$getStrings[] = $engine->generateGetString();
}
return print_r($getStrings, TRUE);
} }
} }
\ No newline at end of file
<?php
namespace App\MetaGer;
use Illuminate\Http\Request;
use App\MetaGer\Searchengine;
class Search
{
public static function loadSearchEngines(Request $request)
{
# Überprüfe, welche Sumas eingeschaltet sind
$xml = simplexml_load_file(SUMA_FILE);
$enabledSearchengines = [];
$overtureEnabled = FALSE;
if(FOKUS === "angepasst")
{
$sumas = $xml->xpath("suma");
foreach($sumas as $suma)
{
if($request->has($suma["service"])
|| ( FOKUS !== "bilder"
&& ($suma["name"]->__toString() === "qualigo"
|| $suma["name"]->__toString() === "similar_product_ads"
|| ( !$overtureEnabled && $suma["name"]->__toString() === "overtureAds" )
)
)
){
if($suma["name"]->__toString() === "overture")
{
$overtureEnabled = TRUE;
}
$enabledSearchengines[] = $suma;
}
}
}else{
$sumas = $xml->xpath("suma");
foreach($sumas as $suma){
$types = explode(",",$suma["type"]);
if(in_array(FOKUS, $types)
|| ( FOKUS !== "bilder"
&& ($suma["name"]->__toString() === "qualigo"
|| $suma["name"]->__toString() === "similar_product_ads"
|| ( !$overtureEnabled && $suma["name"]->__toString() === "overtureAds" )
)
)
){
if($suma["name"]->__toString() === "overture")
{
$overtureEnabled = TRUE;
}
$enabledSearchengines[] = $suma;
}
}
}
$engines = [];
foreach($enabledSearchengines as $engine){
$engines[] = new Searchengine($engine);
}
return $engines;
}
}
\ No newline at end of file
<?php
namespace App\MetaGer;
class Searchengine
{
function __construct(\SimpleXMLElement $engine)
{
foreach($engine->attributes() as $key => $value){
$this->$key = $value->__toString();
}
# User-Agent definieren:
if( isset($_SERVER['HTTP_USER_AGENT']))
{
$this->useragent = $_SERVER['HTTP_USER_AGENT'];
}else
{
$this->useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1";
}
}
public function generateGetString()
{
$getString = "";
# Protokoll:
if($this->port === "443"){
$getString .= "https://";
}else{
$getString .= "http://";
}
# Host:
$getString .= $this->host;
# Port:
$getString .= ":" . $this->port;
# Skript:
$getString .= $this->skript;
# FormData:
$getString .= "?" . $this->formData;
# Wir müssen noch einige Platzhalter in dem GET-String ersetzen:
if( strpos($getString, "<<USERAGENT>>") ){
$getString = str_replace("<<USERAGENT>>", $this->urlEncode($this->useragent), $getString);
}
if( strpos($getString, "<<QUERY>>") )
{
$getString = str_replace("<<QUERY>>", $this->urlEncode(Q), $getString);
}
if( strpos($getString, "<<IP>>") )
{
$getString = str_replace("<<IP>>", $this->urlEncode(IP), $getString);
}
if( strpos($getString, "<<LANGUAGE>>") )
{
$getString = str_replace("<<LANGUAGE>>", $this->urlEncode(LANGUAGE), $getString);
}
if( strpos($getString, "<<CATEGORY>>") )
{
$getString = str_replace("<<CATEGORY>>", $this->urlEncode(CATEGORY), $getString);
}
return $getString;
}
private function urlEncode($string)
{
if(isset($this->inputEncoding))
{
return urlencode(mb_convert_encoding($string, $this->inputEncoding));
}else
{
return urlencode($string);
}
}
private function getOvertureAffilData()
{
$xfip="$_SERVER['HTTP_X_FORWARDED_FOR']";
$xfip=~ s/^(\d+\.\d+\.\d+)\.\d+/$1\.0/;
my $overt_ip=$ENV{'HTTP_FROM'};
my $overt_xfip=$xfip;
# anonymisierte IPs an Overture:
$overt_ip=~s#(\d+)\.(\d+)\.(\d+)\.\d+#$1\.$2\.$3\.0#;
$overt_xfip=~s#(\d+)\.(\d+)\.(\d+)\.\d+#$1\.$2\.$3\.0#;
$affil_data .= 'ip=' . $overt_ip;
$affil_data .= '&ua=' . $self->{useragent};
if ($xfip) {
$affil_data .= '&xfip=' . $overt_xfip;
}
$affil_data = URI::Escape::uri_escape_utf8($affil_data);
$affilDataValue=$affil_data;
# Wir benötigen die ServeUrl:
$serveUrl = $cgi->self_url();#URI::Escape::uri_escape_utf8($cgi->self_url());
$serveUrl = URI::Escape::uri_escape_utf8($serveUrl);
return "&affilData=" . $affilDataValue . "&serveUrl=" . $serveUrl;
}
}
\ No newline at end of file
metager.ini *.xml
\ No newline at end of file \ No newline at end of file
...@@ -202,8 +202,7 @@ return [ ...@@ -202,8 +202,7 @@ return [
'URL' => Illuminate\Support\Facades\URL::class, 'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class, 'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class, 'View' => Illuminate\Support\Facades\View::class,
'LaravelLocalization' => Mcamara\LaravelLocalization\Facades\LaravelLocalization::class, 'LaravelLocalization' => Mcamara\LaravelLocalization\Facades\LaravelLocalization::class,
], ],
]; ];
<?php <?php
return [ return [
'web' => "web", 'web' => "web",
'nachrichten' => "news", 'news' => "nachrichten",
'wissenschaft' => 'science', 'science' => 'wissenschaft',
'produktsuche' => 'shopping', 'shopping' => 'produktsuche',
'bilder' => 'picture', 'picture' => 'bilder',
'angepasst' => 'custom' 'custom' => 'angepasst'
]; ];
\ No newline at end of file
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