Commit 46c5929a authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Noch ein stückchen der MetaGer Suche eingebaut

parent a6c60fcf
......@@ -72,10 +72,13 @@ class MetaGerSearch extends Controller
}
# Category
define("CATEGORY", $request->input('category', ''));
# Request Times:
define("TIME", $request->input('time', 1));
$searchengines = Search::loadSearchEngines($request);
$results = new Results($searchengines);
return $results->results;
return print_r($results->results, TRUE);
}
}
\ No newline at end of file
<?php
namespace App\MetaGer;
class Result
{
function __construct ( $titel, $link, $anzeigeLink , $descr )
{
$this->titel = $titel;
$this->link = $link;
$this->anzeigeLink = $anzeigeLink;
$this->descr = $descr;
}
}
\ No newline at end of file
......@@ -7,9 +7,11 @@ class Results
{
private $fokiNames = [];
private $fokus;
public $results = [];
function __construct ($engines)
{
$this->results = $this->loadResults($engines);
$this->results[] = $this->loadResults($engines);
}
private function loadResults($engines)
......@@ -18,15 +20,83 @@ class Results
# 1. GET-Requests abarbeiten
# 2. Ergebnisse parsen
# 1. GET-Requests abarbeiten
# Wir generiern zunächst alle GET-Strings:
$getStrings = [];
# Wir initialisieren Multi Curl
$mh = curl_multi_init();
# Fügen die Curl Handles der Suchmaschinen hinzu
foreach($engines as $engine)
{
$getStrings[] = $engine->generateGetString();
$engine->addCurlHandle($mh);
}
# Nun führen wir die Get-Requests aus und warten auf alle Ergebnisse:
$running = null;
do
{
curL_multi_exec($mh, $running);
}while($running);
# Und beenden noch alle Handles
foreach($engines as $engine)
{
$engine->removeCurlHandle($mh);
}
# Und auch den Multicurl-Handle:
curl_multi_close($mh);
# Jetzt müssen wir die Suchmaschinen nur noch alle Ergebnisse in den Speicher laden lassen:
foreach($engines as $engine)
{
$engine->loadResults();
return $engine->results;
}
}
private function get($getStrings){
# Nimmt ein array aus getStrings entgegen und liefert ein Array aus Antworten zurück:
# Zunächst alle Curl Abfragen initialisieren, aber noch nicht ausführen:
#return $getStrings;
#$getStrings = array($getStrings[0]);
$ch = [];
foreach($getStrings as $getString)
{
$tmp = curl_init($getString);
curl_setopt($tmp, CURLOPT_RETURNTRANSFER, true);
curl_setopt($tmp, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($tmp, CURLOPT_CONNECTTIMEOUT , TIME);
$ch[] = $tmp;
}
# Nun initialisieren wir Multicurl:
$mh = curl_multi_init();
foreach($ch as $handle)
{
curl_multi_add_handle($mh, $handle);
}
# Nun führen wir die Get-Requests aus und warten auf alle Ergebnisse:
$running = null;
do
{
curL_multi_exec($mh, $running);
}while($running);
# Wir haben alle Ergebnisse und schließen die Handles
foreach($ch as $handle)
{
curl_multi_remove_handle($mh, $handle);
}
# Und auch den Multicurl-Handle:
curl_multi_close($mh);
$results = [];
foreach($ch as $handle)
{
$results[] = curl_multi_getcontent($handle);
}
return print_r($getStrings, TRUE);
return $results;
}
}
\ No newline at end of file
......@@ -20,12 +20,12 @@ class Search
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" )
)
)
# || ( FOKUS !== "bilder"
# && ($suma["name"]->__toString() === "qualigo"
# || $suma["name"]->__toString() === "similar_product_ads"
# || ( !$overtureEnabled && $suma["name"]->__toString() === "overtureAds" )
# )
# )
){
if($suma["name"]->__toString() === "overture")
{
......@@ -39,12 +39,12 @@ class Search
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" )
)
)
# || ( FOKUS !== "bilder"
# && ($suma["name"]->__toString() === "qualigo"
# || $suma["name"]->__toString() === "similar_product_ads"
# || ( !$overtureEnabled && $suma["name"]->__toString() === "overtureAds" )
# )
# )
){
if($suma["name"]->__toString() === "overture")
{
......@@ -57,7 +57,8 @@ class Search
$engines = [];
foreach($enabledSearchengines as $engine){
$engines[] = new Searchengine($engine);
$path = "App\MetaGer\parserSkripte\\" . $engine["name"]->__toString();
$engines[] = new $path($engine);
}
return $engines;
......
<?php
namespace App\MetaGer;
use Request;
class Searchengine
abstract class Searchengine
{
protected $ch; # Curl Handle zum erhalten der Ergebnisse
function __construct(\SimpleXMLElement $engine)
{
foreach($engine->attributes() as $key => $value){
......@@ -20,9 +21,25 @@ class Searchengine
$this->useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1";
}
$this->ch = curl_init($this->generateGetString());
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT , TIME);
}
public abstract function loadResults();
public function addCurlHandle ($mh)
{
curl_multi_add_handle($mh, $this->ch);
}
public function generateGetString()
public function removeCurlHandle ($mh)
{
curl_multi_remove_handle($mh, $this->ch);
}
private function generateGetString()
{
$getString = "";
# Protokoll:
......@@ -64,6 +81,11 @@ class Searchengine
{
$getString = str_replace("<<CATEGORY>>", $this->urlEncode(CATEGORY), $getString);
}
if( strpos($getString, "<<AFFILDATA>>") )
{
$getString = str_replace("<<AFFILDATA>>", $this->getOvertureAffilData(), $getString);
}
return $getString;
}
......@@ -80,23 +102,14 @@ class Searchengine
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 = 'ip=' . IP;
$affil_data .= '&ua=' . $this->useragent;
if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
$affil_data .= '&xfip=' . $_SERVER['HTTP_X_FORWARDED_FOR'];
}
$affil_data = URI::Escape::uri_escape_utf8($affil_data);
$affilDataValue=$affil_data;
$affilDataValue = $this->urlEncode($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);
$serveUrl = $this->urlEncode(Request::url());#
return "&affilData=" . $affilDataValue . "&serveUrl=" . $serveUrl;
}
}
\ No newline at end of file
<?php
namespace app\MetaGer\parserSkripte;
use App\MetaGer\Searchengine;
class Fastbot extends Searchengine
{
public $results = [];
function __construct (\SimpleXMLElement $engine)
{
parent::__construct($engine);
}
public function loadResults ()
{
$result = curl_multi_getcontent($this->ch);
foreach( explode("\n", $result) as $line )
{
$line = trim($line);
if( strlen($line) > 0 ){
# Hier bekommen wir jedes einzelne Ergebnis
$result = explode("|:|", $line);
$link = $result[1];
$link = substr($link, strpos($link, "href=\"") + 6);
$link = substr($link, 0, strpos($link, "\""));
$this->results[] = new \App\MetaGer\Result(
trim(strip_tags($result[1])),
$link,
$result[3],
$result[2]
);
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment