Commit b1b2583e authored by Dominik Hebeler's avatar Dominik Hebeler

Added advertisements when yahoo is disabled

parent 0c3a9ff2
...@@ -554,7 +554,9 @@ class MetaGer ...@@ -554,7 +554,9 @@ class MetaGer
# Check if this engine can use eventually defined parameter-filter # Check if this engine can use eventually defined parameter-filter
if ($valid) { if ($valid) {
foreach ($this->parameterFilter as $filterName => $filter) { foreach ($this->parameterFilter as $filterName => $filter) {
if (empty($filter->sumas->$suma)) { # We need to check if the searchengine supports the parameter value, too
$value = $request->input($filter->{"get-parameter"}, "");
if (empty($filter->sumas->$suma) || empty($filter->sumas->{$suma}->values->{$value})) {
$valid = false; $valid = false;
break; break;
} }
...@@ -582,6 +584,13 @@ class MetaGer ...@@ -582,6 +584,13 @@ class MetaGer
} }
# Implements Yahoo Ads if Yahoo is not enabled as a searchengine
if (empty($this->enabledSearchengines["yahoo"]) && $this->fokus != "bilder" && !empty($this->sumaFile->sumas->{"yahoo-ads"})) {
$this->enabledSearchengines["yahoo-ads"] = $this->sumaFile->sumas->{"yahoo-ads"};
}
#die(var_dump($this->enabledSearchengines));
if (sizeof($this->enabledSearchengines) === 0) { if (sizeof($this->enabledSearchengines) === 0) {
$filter = ""; $filter = "";
foreach ($this->queryFilter as $queryFilter => $filterPhrase) { foreach ($this->queryFilter as $queryFilter => $filterPhrase) {
......
...@@ -11,6 +11,9 @@ class OvertureAds extends Searchengine ...@@ -11,6 +11,9 @@ class OvertureAds extends Searchengine
public function __construct($name, \StdClass $engine, \App\MetaGer $metager) public function __construct($name, \StdClass $engine, \App\MetaGer $metager)
{ {
parent::__construct($name, $engine, $metager); parent::__construct($name, $engine, $metager);
# We need some Affil-Data for the advertisements
$this->getString .= $this->getOvertureAffilData($metager->getUrl());
$this->hash = md5($this->engine->host . $this->getString . $this->engine->port . $this->name);
} }
public function loadResults($result) public function loadResults($result)
...@@ -24,10 +27,10 @@ class OvertureAds extends Searchengine ...@@ -24,10 +27,10 @@ class OvertureAds extends Searchengine
$ads = $content->xpath('//Results/ResultSet[@id="searchResults"]/Listing'); $ads = $content->xpath('//Results/ResultSet[@id="searchResults"]/Listing');
foreach ($ads as $ad) { foreach ($ads as $ad) {
$title = $ad["title"]; $title = $ad["title"];
$link = $ad->{"ClickUrl"}->__toString(); $link = $ad->{"ClickUrl"}->__toString();
$anzeigeLink = $ad["siteHost"]; $anzeigeLink = $ad["siteHost"];
$descr = $ad["description"]; $descr = $ad["description"];
$this->counter++; $this->counter++;
$this->ads[] = new \App\Models\Result( $this->ads[] = new \App\Models\Result(
$this->engine, $this->engine,
...@@ -35,8 +38,10 @@ class OvertureAds extends Searchengine ...@@ -35,8 +38,10 @@ class OvertureAds extends Searchengine
$link, $link,
$anzeigeLink, $anzeigeLink,
$descr, $descr,
$this->engine->{"display-name"},$this->engine->homepage, $this->engine->{"display-name"},
$this->counter $this->engine->{"homepage"},
$this->counter,
[]
); );
} }
} catch (\Exception $e) { } catch (\Exception $e) {
...@@ -46,4 +51,67 @@ class OvertureAds extends Searchengine ...@@ -46,4 +51,67 @@ class OvertureAds extends Searchengine
} }
} }
public function getNext(\App\MetaGer $metager, $result)
{
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = simplexml_load_string($result);
if (!$content) {
return;
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name:");
Log::error($e->getMessage());
return;
}
if (!$content) {
return;
}
// Yahoo liefert, wenn es keine weiteren Ergebnisse hat immer wieder die gleichen Ergebnisse
// Wir müssen also überprüfen, ob wir am Ende der Ergebnisse sind
$resultCount = $content->xpath('//Results/ResultSet[@id="inktomi"]/MetaData/TotalHits');
$results = $content->xpath('//Results/ResultSet[@id="inktomi"]/Listing');
if (isset($resultCount[0]) && sizeof($results) > 0) {
$resultCount = intval($resultCount[0]->__toString());
$lastResultOnPage = intval($results[sizeof($results) - 1]["rank"]);
if ($resultCount <= $lastResultOnPage) {
return;
}
} else {
return;
}
$nextArgs = $content->xpath('//Results/NextArgs');
if (isset($nextArgs[0])) {
$nextArgs = $nextArgs[0]->__toString();
} else {
$nextArgs = $content->xpath('//Results/ResultSet[@id="inktomi"]/NextArgs');
if (isset($nextArgs[0])) {
$nextArgs = $nextArgs[0]->__toString();
} else {
return;
}
}
# Erstellen des neuen Suchmaschinenobjekts und anpassen des GetStrings:
$next = new Overture($this->name, $this->engine, $metager);
$next->getString = preg_replace("/&Keywords=.*?&/si", "&", $next->getString) . "&" . $nextArgs;
$next->hash = md5($next->engine->host . $next->getString . $next->engine->port . $next->name);
$this->next = $next;
}
# Liefert Sonderdaten für Yahoo
private function getOvertureAffilData($url)
{
$affil_data = 'ip=' . $this->ip;
$affil_data .= '&ua=' . $this->useragent;
$affilDataValue = $this->urlEncode($affil_data);
# Wir benötigen die ServeUrl:
$serveUrl = $this->urlEncode($url);
return "&affilData=" . $affilDataValue . "&serveUrl=" . $serveUrl;
}
} }
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