Commit 19baec16 authored by Karl's avatar Karl

Alle Parser die Json- oder XML-Ergebnisse benutzen sind jetzt durch ein...

Alle Parser die Json- oder XML-Ergebnisse benutzen sind jetzt durch ein try-catch vor abstürzen gesichert. Es fehlen lediglich die Parser die andere Methoden verwenden.
parent 5e7fc148
......@@ -16,34 +16,32 @@ class Blogsearch extends Searchengine
public function loadResults($result)
{
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = simplexml_load_string($result);
if (!$content) {
return;
}
$results = $content->xpath('//xml/docs/doc');
foreach ($results as $result) {
$title = $result->{"title"}->__toString();
$link = $result->{"url"}->__toString();
$anzeigeLink = $link;
$descr = $result->{"content"}->__toString();
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter
);
}
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
}
if (!$content) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
$results = $content->xpath('//xml/docs/doc');
# die(var_dump($results));
foreach ($results as $result) {
$title = $result->{"title"}->__toString();
$link = $result->{"url"}->__toString();
$anzeigeLink = $link;
$descr = $result->{"content"}->__toString();
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter
);
}
}
}
......@@ -18,33 +18,33 @@ class Dailymotion extends Searchengine
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = json_decode($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
}
if (!$content) {
return;
}
if (!$content) {
$results = $content->list;
foreach ($results as $result) {
$title = $result->title;
$link = $result->url;
$anzeigeLink = $link;
$descr = $result->description;
$image = $result->thumbnail_240_url;
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
$results = $content->list;
foreach ($results as $result) {
$title = $result->title;
$link = $result->url;
$anzeigeLink = $link;
$descr = $result->description;
$image = $result->thumbnail_240_url;
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image
);
}
}
}
......@@ -15,54 +15,52 @@ class Ebay extends Searchengine
public function loadResults($result)
{
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
}
if (!$content) {
return;
}
$results = $content;
$results = $results->{"searchResult"};
$count = 0;
foreach ($results->{"item"} as $result) {
$title = $result->{"title"}->__toString();
$link = $result->{"viewItemURL"}->__toString();
$anzeigeLink = $link;
$time = $result->{"listingInfo"}->{"endTime"}->__toString();
$time = date(DATE_RFC2822, strtotime($time));
$price = intval($result->{"sellingStatus"}->{"convertedCurrentPrice"}->__toString()) * 100;
$descr = "<p>Preis: " . $result->{"sellingStatus"}->{"convertedCurrentPrice"}->__toString() . " €</p>";
$descr .= "<p>Versandkosten: " . $result->{"shippingInfo"}->{"shippingServiceCost"}->__toString() . " €</p>";
if (isset($result->{"listingInfo"}->{"listingType"})) {
$descr .= "<p>Auktionsart: " . $result->{"listingInfo"}->{"listingType"}->__toString() . "</p>";
if (!$content) {
return;
}
$descr .= "<p>Auktionsende: " . $time . "</p>";
if (isset($result->{"primaryCategory"}->{"categoryName"})) {
$descr .= "<p class=\"text-muted\">Kategorie: " . $result->{"primaryCategory"}->{"categoryName"}->__toString() . "</p>";
}
$results = $content->{"searchResult"};
$count = 0;
foreach ($results->{"item"} as $result) {
$title = $result->{"title"}->__toString();
$link = $result->{"viewItemURL"}->__toString();
$anzeigeLink = $link;
$time = $result->{"listingInfo"}->{"endTime"}->__toString();
$time = date(DATE_RFC2822, strtotime($time));
$price = intval($result->{"sellingStatus"}->{"convertedCurrentPrice"}->__toString()) * 100;
$descr = "<p>Preis: " . $result->{"sellingStatus"}->{"convertedCurrentPrice"}->__toString() . " €</p>";
$descr .= "<p>Versandkosten: " . $result->{"shippingInfo"}->{"shippingServiceCost"}->__toString() . " €</p>";
if (isset($result->{"listingInfo"}->{"listingType"})) {
$descr .= "<p>Auktionsart: " . $result->{"listingInfo"}->{"listingType"}->__toString() . "</p>";
}
$image = $result->{"galleryURL"}->__toString();
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image,
$price
);
$count++;
$descr .= "<p>Auktionsende: " . $time . "</p>";
if (isset($result->{"primaryCategory"}->{"categoryName"})) {
$descr .= "<p class=\"text-muted\">Kategorie: " . $result->{"primaryCategory"}->{"categoryName"}->__toString() . "</p>";
}
$image = $result->{"galleryURL"}->__toString();
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image,
$price
);
$count++;
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -16,47 +16,48 @@ class Ecoshopper extends Searchengine
public function loadResults($result)
{
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
Log::error("Ergebnisse von Ecoshopper konnten nicht eingelesen werden");
return;
}
if (!$content) {
return;
}
$results = $content->xpath('//response/result[@name="response"]/doc');
foreach ($results as $result) {
$result = simplexml_load_string($result->saveXML());
$title = $result->xpath('//doc/str[@name="artikelName"]')[0]->__toString();
$link = $result->xpath('//doc/str[@name="artikelDeeplink"]')[0]->__toString();
$anzeigeLink = parse_url($link);
if (isset($anzeigeLink['query'])) {
parse_str($anzeigeLink['query'], $query);
if (isset($query['diurl'])) {
$anzeigeLink = $query['diurl'];
} else {
$anzeigeLink = $link;
}
if (!$content) {
return;
}
$results = $content->xpath('//response/result[@name="response"]/doc');
foreach ($results as $result) {
$result = simplexml_load_string($result->saveXML());
$title = $result->xpath('//doc/str[@name="artikelName"]')[0]->__toString();
$link = $result->xpath('//doc/str[@name="artikelDeeplink"]')[0]->__toString();
$anzeigeLink = parse_url($link);
if (isset($anzeigeLink['query'])) {
parse_str($anzeigeLink['query'], $query);
if (isset($query['diurl'])) {
$anzeigeLink = $query['diurl'];
} else {
$anzeigeLink = $link;
}
} else {
$anzeigeLink = $link;
$descr = $result->xpath('//doc/str[@name="artikelBeschreibung"]')[0]->__toString();
$image = $result->xpath('//doc/str[@name="artikelImageurl"]')[0]->__toString();
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image
);
}
$descr = $result->xpath('//doc/str[@name="artikelBeschreibung"]')[0]->__toString();
$image = $result->xpath('//doc/str[@name="artikelImageurl"]')[0]->__toString();
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image
);
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -19,59 +19,61 @@ class Europeana extends Searchengine
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = json_decode($result);
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
$results = $content->items;
foreach ($results as $result) {
if (isset($result->edmPreview)) {
$title = $result->title[0];
if (preg_match("/(.+)\?.*/si", $result->guid, $match)) {
$link = $match[1];
} else {
$link = "";
if (!$content) {
return;
}
$results = $content->items;
foreach ($results as $result) {
if (isset($result->edmPreview)) {
$title = $result->title[0];
if (preg_match("/(.+)\?.*/si", $result->guid, $match)) {
$link = $match[1];
} else {
$link = "";
}
$anzeigeLink = $link;
$descr = "";
$image = urldecode($result->edmPreview[0]);
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image
);
}
$anzeigeLink = $link;
$descr = "";
$image = urldecode($result->edmPreview[0]);
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
public function getNext(\App\MetaGer $metager, $result)
{
$start = ($metager->getPage()) * 10 + 1;
try {
$content = json_decode($result);
if (!$content) {
return;
}
$start = ($metager->getPage()) * 10 + 1;
if ($start > $content->totalResults) {
return;
}
$next = new Europeana(simplexml_load_string($this->engine), $metager);
$next->getString .= "&start=" . $start;
$next->hash = md5($next->host . $next->getString . $next->port . $next->name);
$this->next = $next;
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
if ($start > $content->totalResults) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
$next = new Europeana(simplexml_load_string($this->engine), $metager);
$next->getString .= "&start=" . $start;
$next->hash = md5($next->host . $next->getString . $next->port . $next->name);
$this->next = $next;
}
}
......@@ -18,59 +18,60 @@ class Exalead extends Searchengine
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
return;
}
if (!$content) {
return;
}
if (!$content) {
return;
}
$results = $content;
$prefix = "";
$namespace = "";
foreach ($results->getDocNamespaces() as $strPrefix => $strNamespace) {
if (strlen($strPrefix) == 0) {
$prefix = "a"; //Assign an arbitrary namespace prefix.
} else {
$prefix = "a";
$results = $content;
$prefix = "";
$namespace = "";
foreach ($results->getDocNamespaces() as $strPrefix => $strNamespace) {
if (strlen($strPrefix) == 0) {
$prefix = "a"; //Assign an arbitrary namespace prefix.
} else {
$prefix = "a";
}
$namespace = $strNamespace;
}
$namespace = $strNamespace;
}
$results->registerXPathNamespace($prefix, $namespace);
try {
$results = $results->xpath("//a:searchResult/a:item");
} catch (\ErrorException $e) {
return;
}
foreach ($results as $result) {
$results->registerXPathNamespace($prefix, $namespace);
try {
$result->registerXPathNamespace($prefix, $namespace);
$title = $result->xpath("a:metas/a:Meta[@name='title']/a:MetaString[@name='value']")[0]->__toString();
$link = $result->xpath("a:metas/a:Meta[@name='url']/a:MetaString[@name='value']")[0]->__toString();
$anzeigeLink = $link;
$descr = "";
if (sizeOf($result->xpath("a:metas/a:Meta[@name='metadesc']/a:MetaString[@name='value']")) === 0 && sizeOf($result->xpath("a:metas/a:Meta[@name='summary']/a:MetaText[@name='value']")) !== 0) {
$tmp = $result->xpath("a:metas/a:Meta[@name='summary']/a:MetaText[@name='value']");
foreach ($tmp as $el) {
$descr .= strip_tags($el->asXML());
$results = $results->xpath("//a:searchResult/a:item");
} catch (\ErrorException $e) {
return;
}
foreach ($results as $result) {
try {
$result->registerXPathNamespace($prefix, $namespace);
$title = $result->xpath("a:metas/a:Meta[@name='title']/a:MetaString[@name='value']")[0]->__toString();
$link = $result->xpath("a:metas/a:Meta[@name='url']/a:MetaString[@name='value']")[0]->__toString();
$anzeigeLink = $link;
$descr = "";
if (sizeOf($result->xpath("a:metas/a:Meta[@name='metadesc']/a:MetaString[@name='value']")) === 0 && sizeOf($result->xpath("a:metas/a:Meta[@name='summary']/a:MetaText[@name='value']")) !== 0) {
$tmp = $result->xpath("a:metas/a:Meta[@name='summary']/a:MetaText[@name='value']");
foreach ($tmp as $el) {
$descr .= strip_tags($el->asXML());
}
} else {
$descr = $result->xpath("a:metas/a:Meta[@name='metadesc']/a:MetaString[@name='value']")[0]->__toString();
}
} else {
$descr = $result->xpath("a:metas/a:Meta[@name='metadesc']/a:MetaString[@name='value']")[0]->__toString();
}
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter
);
} catch (\ErrorException $e) {
continue;
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter
);
} catch (\ErrorException $e) {
continue;
}
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -18,37 +18,37 @@ class Fernsehsuche extends Searchengine
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = json_decode($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
}
if (!$content) {
return;
}
$results = $content->response->docs;
foreach ($results as $result) {
try {
$title = $result->show . " : " . $result->title;
$link = urldecode($result->url);
$anzeigeLink = $link;
$descr = $result->description;
$image = "http://api-resources.fernsehsuche.de" . $result->thumbnail;
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image
);
} catch (\ErrorException $e) {
if (!$content) {
return;
}
$results = $content->response->docs;
foreach ($results as $result) {
try {
$title = $result->show . " : " . $result->title;
$link = urldecode($result->url);
$anzeigeLink = $link;
$descr = $result->description;
$image = "http://api-resources.fernsehsuche.de" . $result->thumbnail;
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image
);
} catch (\ErrorException $e) {
}
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -19,56 +19,57 @@ class Flickr extends Searchengine
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = simplexml_load_string($result);
if (!$content) {
return;
}
$results = $content->xpath('//photos/photo');
foreach ($results as $result) {
$title = $result["title"]->__toString();
$link = "https://www.flickr.com/photos/" . $result["owner"]->__toString() . "/" . $result["id"]->__toString();
$anzeigeLink = $link;
$descr = "";
$image = "http://farm" . $result["farm"]->__toString() . ".staticflickr.com/" . $result["server"]->__toString() . "/" . $result["id"]->__toString() . "_" . $result["secret"]->__toString() . "_t.jpg";
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image
);
}
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
$results = $content->xpath('//photos/photo');
foreach ($results as $result) {
$title = $result["title"]->__toString();
$link = "https://www.flickr.com/photos/" . $result["owner"]->__toString() . "/" . $result["id"]->__toString();
$anzeigeLink = $link;
$descr = "";
$image = "http://farm" . $result["farm"]->__toString() . ".staticflickr.com/" . $result["server"]->__toString() . "/" . $result["id"]->__toString() . "_" . $result["secret"]->__toString() . "_t.jpg";
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image
);
}
}
public function getNext(\App\MetaGer $metager, $result)
{
$page = $metager->getPage() + 1;
$result = preg_replace("/\r\n/si", "", $result);
$content = simplexml_load_string($result);
$results = $content->xpath('//photos')[0];
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = simplexml_load_string($result);
if (!$content) {
return;
}
$page = $metager->getPage() + 1;
$results = $content->xpath('//photos')[0];
if ($page >= intval($results["pages"]->__toString())) {
return;
}
$next = new Flickr(simplexml_load_string($this->engine), $metager);
$next->getString .= "&page=" . $page;
$next->hash = md5($next->host . $next->getString . $next->port . $next->name);
$this->next = $next;
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
if ($page >= intval($results["pages"]->__toString())) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
$next = new Flickr(simplexml_load_string($this->engine), $metager);
$next->getString .= "&page=" . $page;
$next->hash = md5($next->host . $next->getString . $next->port . $next->name);
$this->next = $next;
}
}
......@@ -19,36 +19,36 @@ class Mg_produkt2 extends Searchengine
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
Log::error("MG_Produkt konnte keine Ergebnisse bekommen");
return;
}
if (!$content) {
return;
}
if (!$content) {