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
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->xpath('//xml/docs/doc');
# die(var_dump($results));
foreach ($results as $result) {
$title = $result->{"title"}->__toString();
$link = $result->{"url"}->__toString();
......@@ -44,6 +39,9 @@ class Blogsearch extends Searchengine
$this->counter
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -18,10 +18,6 @@ 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;
}
......@@ -46,5 +42,9 @@ class Dailymotion extends Searchengine
$image
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -15,18 +15,14 @@ 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"};
$results = $content->{"searchResult"};
$count = 0;
foreach ($results->{"item"} as $result) {
$title = $result->{"title"}->__toString();
......@@ -61,8 +57,10 @@ class Ebay extends Searchengine
$price
);
$count++;
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -16,16 +16,13 @@ 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());
......@@ -58,5 +55,9 @@ class Ecoshopper extends Searchengine
$image
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -19,13 +19,10 @@ 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)) {
......@@ -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)
{
$start = ($metager->getPage()) * 10 + 1;
try {
$content = json_decode($result);
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
$start = ($metager->getPage()) * 10 + 1;
if ($start > $content->totalResults) {
return;
}
......@@ -73,5 +71,9 @@ class Europeana extends Searchengine
$next->getString .= "&start=" . $start;
$next->hash = md5($next->host . $next->getString . $next->port . $next->name);
$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
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
return;
}
if (!$content) {
return;
}
$results = $content;
$prefix = "";
$namespace = "";
......@@ -72,5 +69,9 @@ class Exalead extends Searchengine
continue;
}
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -18,10 +18,6 @@ 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;
}
......@@ -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
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
$results = $content->xpath('//photos/photo');
foreach ($results as $result) {
$title = $result["title"]->__toString();
......@@ -46,23 +43,23 @@ class Flickr extends Searchengine
$image
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
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];
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
$page = $metager->getPage() + 1;
$results = $content->xpath('//photos')[0];
if ($page >= intval($results["pages"]->__toString())) {
return;
}
......@@ -70,5 +67,9 @@ class Flickr extends Searchengine
$next->getString .= "&page=" . $page;
$next->hash = md5($next->host . $next->getString . $next->port . $next->name);
$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
$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;
}
$results = $content->xpath('//response/result[@name="response"]/doc');
foreach ($results as $result) {
$result = simplexml_load_string($result->saveXML());
......@@ -50,5 +46,9 @@ class Mg_produkt2 extends Searchengine
$image
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -15,15 +15,13 @@ class Opencrawlastronomie 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->xpath('//rss/channel/item');
$count = 0;
foreach ($results as $result) {
......@@ -46,8 +44,10 @@ class Opencrawlastronomie extends Searchengine
$this->counter
);
$count++;
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -15,15 +15,13 @@ class Opencrawlregengergie 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->xpath('//rss/channel/item');
$count = 0;
foreach ($results as $result) {
......@@ -46,8 +44,10 @@ class Opencrawlregengergie extends Searchengine
$this->counter
);
$count++;
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -15,15 +15,13 @@ class Opencrawltauchen 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->xpath('//rss/channel/item');
$count = 0;
foreach ($results as $result) {
......@@ -46,7 +44,10 @@ class Opencrawltauchen extends Searchengine
$this->counter
);
$count++;
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -19,13 +19,10 @@ class Overture extends Searchengine
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
$results = $content->xpath('//Results/ResultSet[@id="inktomi"]/Listing');
foreach ($results as $result) {
$title = $result["title"];
......@@ -62,10 +59,27 @@ class Overture extends Searchengine
$this->counter
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
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;
}
# Auslesen der Argumente für die nächste Suchseite:
$result = preg_replace("/\r\n/si", "", $result);
try {
......
......@@ -19,11 +19,6 @@ class Pixabay 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;
}
......@@ -48,10 +43,20 @@ class Pixabay extends Searchengine
$image
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
public function getNext(\App\MetaGer $metager, $result)
{
try {
$content = json_decode($result);
if (!$content) {
return;
}
$page = $metager->getPage() + 1;
try {
$content = json_decode($result);
......@@ -69,5 +74,9 @@ class Pixabay extends Searchengine
$next->getString .= "&page=" . $page;
$next->hash = md5($next->host . $next->getString . $next->port . $next->name);
$this->next = $next;
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -18,13 +18,10 @@ class Qip extends Searchengine
$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->xpath('//channel/item');
foreach ($results as $result) {
$title = $result->{"title"}->__toString();
......@@ -42,5 +39,9 @@ class Qip extends Searchengine
$this->counter
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -19,13 +19,10 @@ class Radiobrowser 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;
}
foreach ($content as $result) {
$title = $result->name;
$link = $result->homepage;
......@@ -58,5 +55,9 @@ class Radiobrowser extends Searchengine
false
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -15,15 +15,13 @@ class Tuhh 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;
}
$count = 0;
foreach ($content->{"entry"} as $result) {
if ($count > 10) {
......@@ -46,6 +44,9 @@ class Tuhh extends Searchengine
);
$count++;
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -15,13 +15,9 @@ class Yacy 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;
}
......@@ -48,5 +44,9 @@ class Yacy extends Searchengine
$this->counter
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name");
return;
}
}
}
......@@ -15,26 +15,22 @@ class Yacyunih 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->xpath('//rss/channel/item');
if (!$results) {
return;
}
$count = 0;
foreach ($results as $result) {
if ($count > 10) {
break;
}
$title = $result->{"title"}->__toString();
$link = $result->{"link"}->__toString();
$anzeigeLink = $link;
......@@ -50,8 +46,10 @@ class Yacyunih extends Searchengine
$this->counter
);
$count++;
}
} catch (\Exception $e) {