Commit cf21fe1c authored by Karl's avatar Karl
Browse files

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 ef4aa52c
...@@ -16,34 +16,32 @@ class Blogsearch extends Searchengine ...@@ -16,34 +16,32 @@ class Blogsearch extends Searchengine
public function loadResults($result) public function loadResults($result)
{ {
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = simplexml_load_string($result); $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) { } catch (\Exception $e) {
abort(500, "$result is not a valid xml string"); Log::error("A problem occurred parsing results from $this->name");
}
if (!$content) {
return; 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 ...@@ -18,33 +18,33 @@ class Dailymotion extends Searchengine
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = json_decode($result); $content = json_decode($result);
} catch (\Exception $e) { if (!$content) {
abort(500, "$result is not a valid xml string"); 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; 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 ...@@ -15,54 +15,52 @@ class Ebay extends Searchengine
public function loadResults($result) public function loadResults($result)
{ {
$result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = simplexml_load_string($result); $content = simplexml_load_string($result);
} catch (\Exception $e) { if (!$content) {
abort(500, "$result is not a valid xml string"); return;
}
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>";
} }
$descr .= "<p>Auktionsende: " . $time . "</p>"; $results = $content->{"searchResult"};
if (isset($result->{"primaryCategory"}->{"categoryName"})) { $count = 0;
$descr .= "<p class=\"text-muted\">Kategorie: " . $result->{"primaryCategory"}->{"categoryName"}->__toString() . "</p>"; 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(); $descr .= "<p>Auktionsende: " . $time . "</p>";
$this->counter++; if (isset($result->{"primaryCategory"}->{"categoryName"})) {
$this->results[] = new \App\Models\Result( $descr .= "<p class=\"text-muted\">Kategorie: " . $result->{"primaryCategory"}->{"categoryName"}->__toString() . "</p>";
$this->engine, }
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image,
$price
);
$count++;
$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 ...@@ -16,47 +16,48 @@ class Ecoshopper extends Searchengine
public function loadResults($result) public function loadResults($result)
{ {
$result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = simplexml_load_string($result); $content = simplexml_load_string($result);
} catch (\Exception $e) { if (!$content) {
Log::error("Ergebnisse von Ecoshopper konnten nicht eingelesen werden"); return;
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 { } else {
$anzeigeLink = $link; $anzeigeLink = $link;
} }
$descr = $result->xpath('//doc/str[@name="artikelBeschreibung"]')[0]->__toString();
} else { $image = $result->xpath('//doc/str[@name="artikelImageurl"]')[0]->__toString();
$anzeigeLink = $link; $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(); } catch (\Exception $e) {
$image = $result->xpath('//doc/str[@name="artikelImageurl"]')[0]->__toString(); Log::error("A problem occurred parsing results from $this->name");
$this->counter++; return;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter,
false,
$image
);
} }
} }
} }
...@@ -19,59 +19,61 @@ class Europeana extends Searchengine ...@@ -19,59 +19,61 @@ class Europeana extends Searchengine
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = json_decode($result); $content = json_decode($result);
} catch (\Exception $e) { if (!$content) {
Log::error("Results from $this->name are not a valid json string"); return;
return; }
}
if (!$content) { $results = $content->items;
return; foreach ($results as $result) {
} if (isset($result->edmPreview)) {
$results = $content->items; $title = $result->title[0];
foreach ($results as $result) { if (preg_match("/(.+)\?.*/si", $result->guid, $match)) {
if (isset($result->edmPreview)) { $link = $match[1];
$title = $result->title[0]; } else {
if (preg_match("/(.+)\?.*/si", $result->guid, $match)) { $link = "";
$link = $match[1]; }
} else { $anzeigeLink = $link;
$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) public function getNext(\App\MetaGer $metager, $result)
{ {
$start = ($metager->getPage()) * 10 + 1;
try { try {
$content = json_decode($result); $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) { } catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string"); Log::error("A problem occurred parsing results from $this->name");
return;
}
if (!$content) {
return;
}
if ($start > $content->totalResults) {
return; 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 ...@@ -18,59 +18,60 @@ class Exalead extends Searchengine
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = simplexml_load_string($result); $content = simplexml_load_string($result);
} catch (\Exception $e) { if (!$content) {
return; return;
} }
if (!$content) { $results = $content;
return; $prefix = "";
} $namespace = "";
$results = $content; foreach ($results->getDocNamespaces() as $strPrefix => $strNamespace) {
$prefix = ""; if (strlen($strPrefix) == 0) {
$namespace = ""; $prefix = "a"; //Assign an arbitrary namespace prefix.
foreach ($results->getDocNamespaces() as $strPrefix => $strNamespace) { } else {
if (strlen($strPrefix) == 0) { $prefix = "a";
$prefix = "a"; //Assign an arbitrary namespace prefix. }
} else { $namespace = $strNamespace;
$prefix = "a";
} }
$namespace = $strNamespace; $results->registerXPathNamespace($prefix, $namespace);
}
$results->registerXPathNamespace($prefix, $namespace);
try {
$results = $results->xpath("//a:searchResult/a:item");
} catch (\ErrorException $e) {
return;
}
foreach ($results as $result) {
try { try {
$result->registerXPathNamespace($prefix, $namespace); $results = $results->xpath("//a:searchResult/a:item");
$title = $result->xpath("a:metas/a:Meta[@name='title']/a:MetaString[@name='value']")[0]->__toString(); } catch (\ErrorException $e) {
$link = $result->xpath("a:metas/a:Meta[@name='url']/a:MetaString[@name='value']")[0]->__toString(); return;
$anzeigeLink = $link; }
$descr = ""; foreach ($results as $result) {
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) { try {
$tmp = $result->xpath("a:metas/a:Meta[@name='summary']/a:MetaText[@name='value']"); $result->registerXPathNamespace($prefix, $namespace);
foreach ($tmp as $el) { $title = $result->xpath("a:metas/a:Meta[@name='title']/a:MetaString[@name='value']")[0]->__toString();
$descr .= strip_tags($el->asXML()); $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->counter++;
$this->results[] = new \App\Models\Result( $this->results[] = new \App\Models\Result(
$this->engine, $this->engine,
$title, $title,
$link, $link,
$anzeigeLink, $anzeigeLink,
$descr, $descr,
$this->gefVon, $this->gefVon,
$this->counter $this->counter
); );
} catch (\ErrorException $e) { } catch (\ErrorException $e) {
continue; continue;
}
} }
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
} }
} }
} }
...@@ -18,37 +18,37 @@ class Fernsehsuche extends Searchengine ...@@ -18,37 +18,37 @@ class Fernsehsuche extends Searchengine
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
try { try {
$content = json_decode($result); $content = json_decode($result);
} catch (\Exception $e) { if (!$content) {
abort(500, "$result is not a valid xml string"); return;
} }
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) {
$results = $content->response->docs;
foreach ($results as $result) {
try {
$title = $result->show . " : " . $result->title;
$link = urldecode($result->url);
$anzeigeLink = $link