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,18 +16,13 @@ class Blogsearch extends Searchengine ...@@ -16,18 +16,13 @@ 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);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
}
if (!$content) { if (!$content) {
return; return;
} }
$results = $content->xpath('//xml/docs/doc'); $results = $content->xpath('//xml/docs/doc');
# die(var_dump($results));
foreach ($results as $result) { foreach ($results as $result) {
$title = $result->{"title"}->__toString(); $title = $result->{"title"}->__toString();
$link = $result->{"url"}->__toString(); $link = $result->{"url"}->__toString();
...@@ -44,6 +39,9 @@ class Blogsearch extends Searchengine ...@@ -44,6 +39,9 @@ class Blogsearch extends Searchengine
$this->counter $this->counter
); );
} }
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
} }
} }
...@@ -18,10 +18,6 @@ class Dailymotion extends Searchengine ...@@ -18,10 +18,6 @@ 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) {
abort(500, "$result is not a valid xml string");
}
if (!$content) { if (!$content) {
return; return;
} }
...@@ -46,5 +42,9 @@ class Dailymotion extends Searchengine ...@@ -46,5 +42,9 @@ class Dailymotion extends Searchengine
$image $image
); );
} }
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
} }
} }
...@@ -15,18 +15,14 @@ class Ebay extends Searchengine ...@@ -15,18 +15,14 @@ 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) {
abort(500, "$result is not a valid xml string");
}
if (!$content) { if (!$content) {
return; return;
} }
$results = $content;
$results = $results->{"searchResult"}; $results = $content->{"searchResult"};
$count = 0; $count = 0;
foreach ($results->{"item"} as $result) { foreach ($results->{"item"} as $result) {
$title = $result->{"title"}->__toString(); $title = $result->{"title"}->__toString();
...@@ -61,8 +57,10 @@ class Ebay extends Searchengine ...@@ -61,8 +57,10 @@ class Ebay extends Searchengine
$price $price
); );
$count++; $count++;
} }
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
} }
} }
...@@ -16,16 +16,13 @@ class Ecoshopper extends Searchengine ...@@ -16,16 +16,13 @@ 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) {
Log::error("Ergebnisse von Ecoshopper konnten nicht eingelesen werden");
return;
}
if (!$content) { if (!$content) {
return; return;
} }
$results = $content->xpath('//response/result[@name="response"]/doc'); $results = $content->xpath('//response/result[@name="response"]/doc');
foreach ($results as $result) { foreach ($results as $result) {
$result = simplexml_load_string($result->saveXML()); $result = simplexml_load_string($result->saveXML());
...@@ -58,5 +55,9 @@ class Ecoshopper extends Searchengine ...@@ -58,5 +55,9 @@ class Ecoshopper extends Searchengine
$image $image
); );
} }
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
} }
} }
...@@ -19,13 +19,10 @@ class Europeana extends Searchengine ...@@ -19,13 +19,10 @@ 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) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) { if (!$content) {
return; return;
} }
$results = $content->items; $results = $content->items;
foreach ($results as $result) { foreach ($results as $result) {
if (isset($result->edmPreview)) { if (isset($result->edmPreview)) {
...@@ -52,20 +49,21 @@ class Europeana extends Searchengine ...@@ -52,20 +49,21 @@ class Europeana extends Searchengine
); );
} }
} }
} 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);
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) { if (!$content) {
return; return;
} }
$start = ($metager->getPage()) * 10 + 1;
if ($start > $content->totalResults) { if ($start > $content->totalResults) {
return; return;
} }
...@@ -73,5 +71,9 @@ class Europeana extends Searchengine ...@@ -73,5 +71,9 @@ class Europeana extends Searchengine
$next->getString .= "&start=" . $start; $next->getString .= "&start=" . $start;
$next->hash = md5($next->host . $next->getString . $next->port . $next->name); $next->hash = md5($next->host . $next->getString . $next->port . $next->name);
$this->next = $next; $this->next = $next;
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
} }
} }
...@@ -18,13 +18,10 @@ class Exalead extends Searchengine ...@@ -18,13 +18,10 @@ 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) {
return;
}
if (!$content) { if (!$content) {
return; return;
} }
$results = $content; $results = $content;
$prefix = ""; $prefix = "";
$namespace = ""; $namespace = "";
...@@ -72,5 +69,9 @@ class Exalead extends Searchengine ...@@ -72,5 +69,9 @@ class Exalead extends Searchengine
continue; continue;
} }
} }
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
} }
} }
...@@ -18,10 +18,6 @@ class Fernsehsuche extends Searchengine ...@@ -18,10 +18,6 @@ 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) {
abort(500, "$result is not a valid xml string");
}
if (!$content) { if (!$content) {
return; return;
} }
...@@ -50,5 +46,9 @@ class Fernsehsuche extends Searchengine ...@@ -50,5 +46,9 @@ class Fernsehsuche extends Searchengine
} }
} }
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
} }
} }
...@@ -19,13 +19,10 @@ class Flickr extends Searchengine ...@@ -19,13 +19,10 @@ class Flickr 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) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) { if (!$content) {
return; return;
} }
$results = $content->xpath('//photos/photo'); $results = $content->xpath('//photos/photo');
foreach ($results as $result) { foreach ($results as $result) {
$title = $result["title"]->__toString(); $title = $result["title"]->__toString();
...@@ -46,23 +43,23 @@ class Flickr extends Searchengine ...@@ -46,23 +43,23 @@ class Flickr extends Searchengine
$image $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)
{ {
$page = $metager->getPage() + 1;
$result = preg_replace("/\r\n/si", "", $result); $result = preg_replace("/\r\n/si", "", $result);
$content = simplexml_load_string($result);
$results = $content->xpath('//photos')[0];
try { try {
$content = simplexml_load_string($result); $content = simplexml_load_string($result);
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) { if (!$content) {
return; return;
} }
$page = $metager->getPage() + 1;
$results = $content->xpath('//photos')[0];
if ($page >= intval($results["pages"]->__toString())) { if ($page >= intval($results["pages"]->__toString())) {
return; return;
} }
...@@ -70,5 +67,9 @@ class Flickr extends Searchengine ...@@ -70,5 +67,9 @@ class Flickr extends Searchengine
$next->getString .= "&page=" . $page; $next->getString .= "&page=" . $page;
$next->hash = md5($next->host . $next->getString . $next->port . $next->name); $next->hash = md5($next->host . $next->getString . $next->port . $next->name);
$this->next = $next; $this->next = $next;
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
} }
} }
...@@ -19,14 +19,10 @@ class Mg_produkt2 extends Searchengine ...@@ -19,14 +19,10 @@ class Mg_produkt2 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) {
Log::error("MG_Produkt konnte keine Ergebnisse bekommen");
return;
}
if (!$content) { if (!$content) {
return; return;
} }
$results = $content->xpath('//response/result[@name="response"]/doc'); $results = $content->xpath('//response/result[@name="response"]/doc');
foreach ($results as $result) { foreach ($results as $result) {
$result = simplexml_load_string($result->saveXML()); $result = simplexml_load_string($result->saveXML());
...@@ -50,5 +46,9 @@ class Mg_produkt2 extends Searchengine ...@@ -50,5 +46,9 @@ class Mg_produkt2 extends Searchengine
$image $image
); );
} }
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
} }
} }
...@@ -15,15 +15,13 @@ class Opencrawlastronomie extends Searchengine ...@@ -15,15 +15,13 @@ class Opencrawlastronomie 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) {
abort(500, "$result is not a valid xml string");
}
if (!$content) { if (!$content) {
return; return;
} }
$results = $content->xpath('//rss/channel/item'); $results = $content->xpath('//rss/channel/item');
$count = 0; $count = 0;
foreach ($results as $result) { foreach ($results as $result) {
...@@ -46,8 +44,10 @@ class Opencrawlastronomie extends Searchengine ...@@ -46,8 +44,10 @@ class Opencrawlastronomie extends Searchengine
$this->counter $this->counter
); );
$count++; $count++;
} }
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
} }
} }
...@@ -15,15 +15,13 @@ class Opencrawlregengergie extends Searchengine ...@@ -15,15 +15,13 @@ class Opencrawlregengergie 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) {
abort(500, "$result is not a valid xml string");
}
if (!$content) { if (!$content) {
return; return;
} }
$results = $content->xpath('//rss/channel/item'); $results = $content->xpath('//rss/channel/item');
$count = 0; $count = 0;
foreach ($results as $result) { foreach ($results as $result) {
...@@ -46,8 +44,10 @@ class Opencrawlregengergie extends Searchengine ...@@ -46,8 +44,10 @@ class Opencrawlregengergie extends Searchengine
$this->counter $this->counter
); );
$count++; $count++;
} }
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
} }
} }
...@@ -15,15 +15,13 @@ class Opencrawltauchen extends Searchengine ...@@ -15,15 +15,13 @@ class Opencrawltauchen 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) {
abort(500, "$result is not a valid xml string");
}
if (!$content) { if (!$content) {
return; return;
} }
$results = $content->xpath('//rss/channel/item'); $results = $content->xpath('//rss/channel/item');
$count = 0; $count = 0;
foreach ($results as $result) { foreach ($results as $result) {
...@@ -46,7 +44,10 @@ class Opencrawltauchen extends Searchengine ...@@ -46,7 +44,10 @@ class Opencrawltauchen extends Searchengine
$this->counter $this->counter
); );
$count++; $count++;
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
} }
} }
} }
...@@ -19,13 +19,10 @@ class Overture extends Searchengine ...@@ -19,13 +19,10 @@ class Overture 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) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) { if (!$content) {
return; return;
} }
$results = $content->xpath('//Results/ResultSet[@id="inktomi"]/Listing'); $results = $content->xpath('//Results/ResultSet[@id="inktomi"]/Listing');
foreach ($results as $result) { foreach ($results as $result) {
$title = $result["title"]; $title = $result["title"];
...@@ -62,10 +59,27 @@ class Overture extends Searchengine ...@@ -62,10 +59,27 @@ class Overture extends Searchengine
$this->counter $this->counter
); );
} }
} 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)
{ {
$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");
return;