Commit 5e7fc148 authored by Karl's avatar Karl

Merge branch '400-bildersuche-kaputt' into...

Merge branch '400-bildersuche-kaputt' into 403-parser-skripte-vor-absturzen-durch-falsche-ergebnisse-sichern
parents 84053650 3d2325fe
......@@ -49,7 +49,6 @@ class Allesklar extends Searchengine
} catch (\InvalidArgumentException $e) {
}
});
}
......
......@@ -16,9 +16,7 @@ class Bing extends Searchengine
public function loadResults($result)
{
try
{
try {
$crawler = new Crawler($result);
$crawler->filter('ol#b_results > li.b_algo')->each(function (Crawler $node, $i) {
$title = $node->filter('li h2 > a')->text();
......
......@@ -3,6 +3,7 @@
namespace app\Models\parserSkripte;
use App\Models\Searchengine;
use Log;
class Europeana extends Searchengine
{
......@@ -19,13 +20,12 @@ class Europeana extends Searchengine
try {
$content = json_decode($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid json string");
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)) {
......@@ -56,8 +56,16 @@ class Europeana extends Searchengine
public function getNext(\App\MetaGer $metager, $result)
{
$start = ($metager->getPage()) * 10 + 1;
$content = json_decode($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;
}
if ($start > $content->totalResults) {
return;
}
......
......@@ -3,6 +3,7 @@
namespace app\Models\parserSkripte;
use App\Models\Searchengine;
use Log;
class Flickr extends Searchengine
{
......@@ -19,9 +20,9 @@ class Flickr extends Searchengine
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
......@@ -56,7 +57,8 @@ class Flickr extends Searchengine
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
......
......@@ -3,6 +3,7 @@
namespace app\Models\parserSkripte;
use App\Models\Searchengine;
use Log;
class Openclipart extends Searchengine
{
......@@ -18,45 +19,54 @@ class Openclipart extends Searchengine
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = json_decode($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid json string");
}
if (!$content) {
return;
}
if (!$content) {
$results = $content->payload;
foreach ($results as $result) {
$title = $result->title;
$link = $result->detail_link;
$anzeigeLink = $link;
$descr = $result->description;
$image = $result->svg->png_thumb;
$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->payload;
foreach ($results as $result) {
$title = $result->title;
$link = $result->detail_link;
$anzeigeLink = $link;
$descr = $result->description;
$image = $result->svg->png_thumb;
$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)
{
$content = json_decode($result);
if ($content->info->current_page > $content->info->pages) {
try {
$content = json_decode($result);
if (!$content) {
return;
}
if ($content->info->current_page > $content->info->pages) {
return;
}
$next = new Openclipart(simplexml_load_string($this->engine), $metager);
$next->getString .= "&page=" . ($metager->getPage() + 1);
$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;
}
$next = new Openclipart(simplexml_load_string($this->engine), $metager);
$next->getString .= "&page=" . ($metager->getPage() + 1);
$next->hash = md5($next->host . $next->getString . $next->port . $next->name);
$this->next = $next;
}
}
......@@ -3,6 +3,7 @@
namespace app\Models\parserSkripte;
use App\Models\Searchengine;
use Log;
class Overture extends Searchengine
{
......@@ -19,9 +20,9 @@ class Overture extends Searchengine
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
......@@ -70,7 +71,11 @@ class Overture extends Searchengine
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
$nextArgs = $content->xpath('//Results/NextArgs');
if (isset($nextArgs[0])) {
......
......@@ -17,31 +17,31 @@ class OvertureAds extends Searchengine
$result = preg_replace("/\r\n/si", "", $result);
try {
$content = simplexml_load_string($result);
if (!$content) {
return;
}
$ads = $content->xpath('//Results/ResultSet[@id="searchResults"]/Listing');
foreach ($ads as $ad) {
$title = $ad["title"];
$link = $ad->{"ClickUrl"}->__toString();
$anzeigeLink = $ad["siteHost"];
$descr = $ad["description"];
$this->counter++;
$this->ads[] = 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;
}
$ads = $content->xpath('//Results/ResultSet[@id="searchResults"]/Listing');
foreach ($ads as $ad) {
$title = $ad["title"];
$link = $ad->{"ClickUrl"}->__toString();
$anzeigeLink = $ad["siteHost"];
$descr = $ad["description"];
$this->counter++;
$this->ads[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->gefVon,
$this->counter
);
}
}
}
......@@ -3,6 +3,7 @@
namespace app\Models\parserSkripte;
use App\Models\Searchengine;
use Log;
class Pixabay extends Searchengine
{
......@@ -19,7 +20,8 @@ class Pixabay extends Searchengine
try {
$content = json_decode($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid json string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
......@@ -50,8 +52,16 @@ class Pixabay extends Searchengine
public function getNext(\App\MetaGer $metager, $result)
{
$page = $metager->getPage() + 1;
$content = json_decode($result);
$page = $metager->getPage() + 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;
}
if ($page * 20 > $content->total) {
return;
}
......
......@@ -3,6 +3,7 @@
namespace app\Models\parserSkripte;
use App\Models\Searchengine;
use Log;
class Radiobrowser extends Searchengine
{
......@@ -19,13 +20,12 @@ class Radiobrowser extends Searchengine
try {
$content = json_decode($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid json string");
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;
......
......@@ -3,6 +3,7 @@
namespace app\Models\parserSkripte;
use App\Models\Searchengine;
use Log;
class Yandex extends Searchengine
{
......@@ -19,12 +20,13 @@ class Yandex extends Searchengine
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
$results = $content;
try {
$results = $results->xpath("//yandexsearch/response/results/grouping/group");
......@@ -56,21 +58,25 @@ class Yandex extends Searchengine
{
# Wir müssen herausfinden, ob es überhaupt noch weitere Ergebnisse von Yandex gibt:
try {
$content = simplexml_load_string($result);
$content = simplexml_load_string($result);
if (!$content) {
return;
}
$resultCount = intval($content->xpath('//yandexsearch/response/results/grouping/found[@priority="all"]')[0]->__toString());
$pageLast = $content->xpath('//yandexsearch/response/results/grouping/page')[0];
$pageLast = intval($pageLast["last"]->__toString());
if (count($this->results) <= 0 || $pageLast >= $resultCount) {
return;
}
$next = new Yandex(simplexml_load_string($this->engine), $metager);
$next->getString .= "&page=" . ($metager->getPage() + 1);
$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 (count($this->results) <= 0 || $pageLast >= $resultCount) {
return;
}
$next = new Yandex(simplexml_load_string($this->engine), $metager);
$next->getString .= "&page=" . ($metager->getPage() + 1);
$next->hash = md5($next->host . $next->getString . $next->port . $next->name);
$this->next = $next;
}
}
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