diff --git a/app/Models/parserSkripte/Allesklar.php b/app/Models/parserSkripte/Allesklar.php index 8e43b26ddb4e783a6d3f29646d394e636ee3d754..3e054e652fad1711e88e6f87384dab8858dc16b7 100644 --- a/app/Models/parserSkripte/Allesklar.php +++ b/app/Models/parserSkripte/Allesklar.php @@ -46,10 +46,10 @@ class Allesklar extends Searchengine $this->gefVon, $this->counter ); - } catch (\InvalidArgumentException $e) { - + } catch (\Exception $e) { + Log::error("A problem occurred parsing results from $this->name"); + return; } - }); } diff --git a/app/Models/parserSkripte/BASE.php b/app/Models/parserSkripte/BASE.php index dc9d75cbace71e4c7941ec3eb8c2e27d9120a97f..e5c223e4537a1a7b65124a14c726b2a2e572ad30 100644 --- a/app/Models/parserSkripte/BASE.php +++ b/app/Models/parserSkripte/BASE.php @@ -15,20 +15,6 @@ class BASE extends Searchengine public function loadResults($result) { - - $title = ""; - $link = ""; - $anzeigeLink = $link; - $descr = ""; - - /*$this->counter++; - $this->results[] = new \App\Models\Result( - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter - );*/ + return; } } diff --git a/app/Models/parserSkripte/Bing.php b/app/Models/parserSkripte/Bing.php index 8cf01e0e74855af821eb97b9dfbbe83035749e51..fcdce0dcea311c3d8f9b9d40222f1c8f0811329f 100644 --- a/app/Models/parserSkripte/Bing.php +++ b/app/Models/parserSkripte/Bing.php @@ -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(); @@ -37,7 +35,8 @@ class Bing extends Searchengine $this->counter ); }); - } catch (\ErrorException $e) { + } catch (\Exception $e) { + Log::error("A problem occurred parsing results from $this->name"); return; } diff --git a/app/Models/parserSkripte/Blogsearch.php b/app/Models/parserSkripte/Blogsearch.php index c167afc247c252f9467e33d040e1140c52f0dd6d..a6cc51d4ce692ef111444313bcbf93f8e326c6d1 100644 --- a/app/Models/parserSkripte/Blogsearch.php +++ b/app/Models/parserSkripte/Blogsearch.php @@ -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 - ); - } } - } diff --git a/app/Models/parserSkripte/Dailymotion.php b/app/Models/parserSkripte/Dailymotion.php index e21138d779032fde14aad3f6240329632bbbfe27..f249c1038ff05d0112c4ef81666b1de9f9c035a4 100644 --- a/app/Models/parserSkripte/Dailymotion.php +++ b/app/Models/parserSkripte/Dailymotion.php @@ -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 - ); - } } } diff --git a/app/Models/parserSkripte/Ebay.php b/app/Models/parserSkripte/Ebay.php index f3c6de8768511dd7cbbc1ccd17f17867c299fe63..8a1cfa342eea036eba4e35a0dc1540093b83f171 100644 --- a/app/Models/parserSkripte/Ebay.php +++ b/app/Models/parserSkripte/Ebay.php @@ -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; } - } } diff --git a/app/Models/parserSkripte/Ecoshopper.php b/app/Models/parserSkripte/Ecoshopper.php index 3b013d142df9cde559f6114b2b23767871dcb7f4..fca12fbbd84391aee4987edcda06271bdb66a110 100644 --- a/app/Models/parserSkripte/Ecoshopper.php +++ b/app/Models/parserSkripte/Ecoshopper.php @@ -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; } } } diff --git a/app/Models/parserSkripte/Europeana.php b/app/Models/parserSkripte/Europeana.php index 9ea0a4ea70e149742364bfea0e81e67f24bf0383..3aa5d10d6304623571ea040dc817b79c4bad75a0 100644 --- a/app/Models/parserSkripte/Europeana.php +++ b/app/Models/parserSkripte/Europeana.php @@ -3,6 +3,7 @@ namespace app\Models\parserSkripte; use App\Models\Searchengine; +use Log; class Europeana extends Searchengine { @@ -18,52 +19,61 @@ class Europeana 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) { + 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 = ""; + $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; - $content = json_decode($result); - if ($start > $content->totalResults) { + 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("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; } } diff --git a/app/Models/parserSkripte/Exalead.php b/app/Models/parserSkripte/Exalead.php index 7a132b0be5433f6714a2f818af547647bb661755..6ba8b3b19caf5cb5e9b89a3eda85c9bd87c0f9cc 100644 --- a/app/Models/parserSkripte/Exalead.php +++ b/app/Models/parserSkripte/Exalead.php @@ -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; } } } diff --git a/app/Models/parserSkripte/Fernsehsuche.php b/app/Models/parserSkripte/Fernsehsuche.php index 817c64452a1936e3017563c79bca6ac5e7a123ff..b195a89c45eac3358a141f118926036caf978dba 100644 --- a/app/Models/parserSkripte/Fernsehsuche.php +++ b/app/Models/parserSkripte/Fernsehsuche.php @@ -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; } } } diff --git a/app/Models/parserSkripte/Flickr.php b/app/Models/parserSkripte/Flickr.php index 73329cb901f1054d27a589b4f1e6e6f752cdf8db..ad6c00f6ff808554d42702cdfc198a0c2bd3b418 100644 --- a/app/Models/parserSkripte/Flickr.php +++ b/app/Models/parserSkripte/Flickr.php @@ -3,6 +3,7 @@ namespace app\Models\parserSkripte; use App\Models\Searchengine; +use Log; class Flickr extends Searchengine { @@ -18,55 +19,57 @@ class Flickr 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; + } - if (!$content) { + $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("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) { - abort(500, "$result is not a valid xml string"); - } - 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; } } diff --git a/app/Models/parserSkripte/Mg_produkt2.php b/app/Models/parserSkripte/Mg_produkt2.php index 839a20025c228518ec9a29603241403c867117f6..831daf7ef6dd9f2f575247ee06e24b9bcc32bbba 100644 --- a/app/Models/parserSkripte/Mg_produkt2.php +++ b/app/Models/parserSkripte/Mg_produkt2.php @@ -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) { + $results = $content->xpath('//response/result[@name="response"]/doc'); + foreach ($results as $result) { + $result = simplexml_load_string($result->saveXML()); + $title = $result->xpath('/doc/arr[@name="artikelName"]')[0]->{"str"}->__toString(); + $link = $result->xpath('/doc/arr[@name="artikelDeeplink"]')[0]->{"str"}->__toString(); + $anzeigeLink = parse_url($link); + parse_str($anzeigeLink['query'], $query); + $anzeigeLink = $query['diurl']; + $descr = $result->xpath('/doc/arr[@name="artikelBeschreibung"]')[0]->{"str"}->__toString(); + $image = $result->xpath('/doc/arr[@name="artikelImageurl"]')[0]->{"str"}->__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; } - $results = $content->xpath('//response/result[@name="response"]/doc'); - foreach ($results as $result) { - $result = simplexml_load_string($result->saveXML()); - $title = $result->xpath('/doc/arr[@name="artikelName"]')[0]->{"str"}->__toString(); - $link = $result->xpath('/doc/arr[@name="artikelDeeplink"]')[0]->{"str"}->__toString(); - $anzeigeLink = parse_url($link); - parse_str($anzeigeLink['query'], $query); - $anzeigeLink = $query['diurl']; - $descr = $result->xpath('/doc/arr[@name="artikelBeschreibung"]')[0]->{"str"}->__toString(); - $image = $result->xpath('/doc/arr[@name="artikelImageurl"]')[0]->{"str"}->__toString(); - $this->counter++; - $this->results[] = new \App\Models\Result( - $this->engine, - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter, - false, - $image - ); - } } } diff --git a/app/Models/parserSkripte/Openclipart.php b/app/Models/parserSkripte/Openclipart.php index ffbf59497762dcfeafc2517f8817ab764531a184..f2b44ce1fdc2daa5cbc122bf23258171525c457c 100644 --- a/app/Models/parserSkripte/Openclipart.php +++ b/app/Models/parserSkripte/Openclipart.php @@ -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; } } diff --git a/app/Models/parserSkripte/Opencrawlastronomie.php b/app/Models/parserSkripte/Opencrawlastronomie.php index 2cb36444db0e1cecf02136ad640e15d052fcecf3..47d101249e79b98407d2756c23b44b43c38b1f8b 100644 --- a/app/Models/parserSkripte/Opencrawlastronomie.php +++ b/app/Models/parserSkripte/Opencrawlastronomie.php @@ -15,39 +15,39 @@ 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) { - if ($count > 10) { - break; + if (!$content) { + return; } - $title = $result->{"title"}->__toString(); - $link = $result->{"link"}->__toString(); - $anzeigeLink = $link; - $descr = strip_tags($result->{"description"}->__toString()); - $this->counter++; - $this->results[] = new \App\Models\Result( - $this->engine, - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter - ); - $count++; - + $results = $content->xpath('//rss/channel/item'); + $count = 0; + foreach ($results as $result) { + if ($count > 10) { + break; + } + + $title = $result->{"title"}->__toString(); + $link = $result->{"link"}->__toString(); + $anzeigeLink = $link; + $descr = strip_tags($result->{"description"}->__toString()); + $this->counter++; + $this->results[] = new \App\Models\Result( + $this->engine, + $title, + $link, + $anzeigeLink, + $descr, + $this->gefVon, + $this->counter + ); + $count++; + } + } catch (\Exception $e) { + Log::error("A problem occurred parsing results from $this->name"); + return; } - } } diff --git a/app/Models/parserSkripte/Opencrawlregengergie.php b/app/Models/parserSkripte/Opencrawlregengergie.php index e601ce52b99892794d0f03454d987444d562e5c9..b261b3151007973c02663055962b8056546553b7 100644 --- a/app/Models/parserSkripte/Opencrawlregengergie.php +++ b/app/Models/parserSkripte/Opencrawlregengergie.php @@ -15,39 +15,39 @@ 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) { - if ($count > 10) { - break; + if (!$content) { + return; } - $title = $result->{"title"}->__toString(); - $link = $result->{"link"}->__toString(); - $anzeigeLink = $link; - $descr = strip_tags($result->{"description"}->__toString()); - $this->counter++; - $this->results[] = new \App\Models\Result( - $this->engine, - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter - ); - $count++; - + $results = $content->xpath('//rss/channel/item'); + $count = 0; + foreach ($results as $result) { + if ($count > 10) { + break; + } + + $title = $result->{"title"}->__toString(); + $link = $result->{"link"}->__toString(); + $anzeigeLink = $link; + $descr = strip_tags($result->{"description"}->__toString()); + $this->counter++; + $this->results[] = new \App\Models\Result( + $this->engine, + $title, + $link, + $anzeigeLink, + $descr, + $this->gefVon, + $this->counter + ); + $count++; + } + } catch (\Exception $e) { + Log::error("A problem occurred parsing results from $this->name"); + return; } - } } diff --git a/app/Models/parserSkripte/Opencrawltauchen.php b/app/Models/parserSkripte/Opencrawltauchen.php index db07e29d1772cc5c72564ca02dd97a2a7cfd8998..b947c36f78cc8c1a0d2b59737b594b03414fcd24 100644 --- a/app/Models/parserSkripte/Opencrawltauchen.php +++ b/app/Models/parserSkripte/Opencrawltauchen.php @@ -15,38 +15,39 @@ 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) { - if ($count > 10) { - break; + if (!$content) { + return; } - $title = $result->{"title"}->__toString(); - $link = $result->{"link"}->__toString(); - $anzeigeLink = $link; - $descr = strip_tags($result->{"description"}->__toString()); - $this->counter++; - $this->results[] = new \App\Models\Result( - $this->engine, - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter - ); - $count++; - + $results = $content->xpath('//rss/channel/item'); + $count = 0; + foreach ($results as $result) { + if ($count > 10) { + break; + } + + $title = $result->{"title"}->__toString(); + $link = $result->{"link"}->__toString(); + $anzeigeLink = $link; + $descr = strip_tags($result->{"description"}->__toString()); + $this->counter++; + $this->results[] = new \App\Models\Result( + $this->engine, + $title, + $link, + $anzeigeLink, + $descr, + $this->gefVon, + $this->counter + ); + $count++; + } + } catch (\Exception $e) { + Log::error("A problem occurred parsing results from $this->name"); + return; } } } diff --git a/app/Models/parserSkripte/Overture.php b/app/Models/parserSkripte/Overture.php index be3c320c48955b745f27c20d47bbc7ef9af99275..4685f4837392eac1898bca3e102e47a8ca0db316 100644 --- a/app/Models/parserSkripte/Overture.php +++ b/app/Models/parserSkripte/Overture.php @@ -3,6 +3,7 @@ namespace app\Models\parserSkripte; use App\Models\Searchengine; +use Log; class Overture extends Searchengine { @@ -18,59 +19,77 @@ class Overture 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; + } - if (!$content) { - return; - } - $results = $content->xpath('//Results/ResultSet[@id="inktomi"]/Listing'); - foreach ($results as $result) { - $title = $result["title"]; - $link = $result->{"ClickUrl"}->__toString(); - $anzeigeLink = $result["siteHost"]; - $descr = $result["description"]; - $this->counter++; - $this->results[] = new \App\Models\Result( - $this->engine, - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter - ); - } + $results = $content->xpath('//Results/ResultSet[@id="inktomi"]/Listing'); + foreach ($results as $result) { + $title = $result["title"]; + $link = $result->{"ClickUrl"}->__toString(); + $anzeigeLink = $result["siteHost"]; + $descr = $result["description"]; + $this->counter++; + $this->results[] = new \App\Models\Result( + $this->engine, + $title, + $link, + $anzeigeLink, + $descr, + $this->gefVon, + $this->counter + ); + } - # Nun noch die Werbeergebnisse: - $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 - ); + # Nun noch die Werbeergebnisse: + $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) { + 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 { $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])) { diff --git a/app/Models/parserSkripte/OvertureAds.php b/app/Models/parserSkripte/OvertureAds.php index e48bc7ed6732c3fdbbd4bd9e85b46da268dbadb8..d11b42b062276c343f0695685cdd2b2095bae3ae 100644 --- a/app/Models/parserSkripte/OvertureAds.php +++ b/app/Models/parserSkripte/OvertureAds.php @@ -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 - ); - } } } diff --git a/app/Models/parserSkripte/Pixabay.php b/app/Models/parserSkripte/Pixabay.php index d5ee4dee913cc0d1dd319209f51b8e8f2d1c96bd..ea0cd2d1a9b344bfc633ca6a40e31b9e9201a23e 100644 --- a/app/Models/parserSkripte/Pixabay.php +++ b/app/Models/parserSkripte/Pixabay.php @@ -3,6 +3,7 @@ namespace app\Models\parserSkripte; use App\Models\Searchengine; +use Log; class Pixabay extends Searchengine { @@ -18,46 +19,64 @@ class Pixabay 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->hits; + foreach ($results as $result) { + $title = $result->tags; + $link = $result->pageURL; + $anzeigeLink = $link; + $descr = ""; + $image = $result->previewURL; + $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->hits; - foreach ($results as $result) { - $title = $result->tags; - $link = $result->pageURL; - $anzeigeLink = $link; - $descr = ""; - $image = $result->previewURL; - $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; - $content = json_decode($result); - if ($page * 20 > $content->total) { + try { + $content = json_decode($result); + if (!$content) { + return; + } + + $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; + } + $next = new Pixabay(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("A problem occurred parsing results from $this->name"); return; } - $next = new Pixabay(simplexml_load_string($this->engine), $metager); - $next->getString .= "&page=" . $page; - $next->hash = md5($next->host . $next->getString . $next->port . $next->name); - $this->next = $next; } } diff --git a/app/Models/parserSkripte/Qip.php b/app/Models/parserSkripte/Qip.php index c043b7f27482f2ee193b74bdf6a104bd4ab0756f..b786656eefd5a850b40ea5120b885421180d077b 100644 --- a/app/Models/parserSkripte/Qip.php +++ b/app/Models/parserSkripte/Qip.php @@ -18,29 +18,30 @@ 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; + } - if (!$content) { + $results = $content->xpath('//channel/item'); + foreach ($results as $result) { + $title = $result->{"title"}->__toString(); + $link = $result->{"link"}->__toString(); + $anzeigeLink = $link; + $descr = $result->{"description"}->__toString(); + $this->counter++; + $this->results[] = new \App\Models\Result( + $this->engine, + $title, + $link, + $anzeigeLink, + $descr, + $this->gefVon, + $this->counter + ); + } + } catch (\Exception $e) { + Log::error("A problem occurred parsing results from $this->name"); return; } - $results = $content->xpath('//channel/item'); - foreach ($results as $result) { - $title = $result->{"title"}->__toString(); - $link = $result->{"link"}->__toString(); - $anzeigeLink = $link; - $descr = $result->{"description"}->__toString(); - $this->counter++; - $this->results[] = new \App\Models\Result( - $this->engine, - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter - ); - } } } diff --git a/app/Models/parserSkripte/Radiobrowser.php b/app/Models/parserSkripte/Radiobrowser.php index 1fbc12ae26009dc4180fdc78d3ad19b3834fe556..fb9d5edcd015fac02c6d71131dc7e310186952d6 100644 --- a/app/Models/parserSkripte/Radiobrowser.php +++ b/app/Models/parserSkripte/Radiobrowser.php @@ -3,6 +3,7 @@ namespace app\Models\parserSkripte; use App\Models\Searchengine; +use Log; class Radiobrowser extends Searchengine { @@ -18,45 +19,45 @@ class Radiobrowser 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; - } - - foreach ($content as $result) { - $title = $result->name; - $link = $result->homepage; - $anzeigeLink = $link; - $descr = ""; - if ($result->tags != "") { - $descr .= "Tags: " . $result->tags; + if (!$content) { + return; } - if ($result->tags != "") { - if ($descr != "") { - $descr .= " - "; + + foreach ($content as $result) { + $title = $result->name; + $link = $result->homepage; + $anzeigeLink = $link; + $descr = ""; + if ($result->tags != "") { + $descr .= "Tags: " . $result->tags; } - $descr .= "Country: " . $result->country; - } - if ($result->tags != "") { - if ($descr != "") { - $descr .= " - "; + if ($result->tags != "") { + if ($descr != "") { + $descr .= " - "; + } + $descr .= "Country: " . $result->country; + } + if ($result->tags != "") { + if ($descr != "") { + $descr .= " - "; + } + $descr .= "Language: " . $result->language; } - $descr .= "Language: " . $result->language; + $this->counter++; + $this->results[] = new \App\Models\Result( + $this->engine, + $title, + $link, + $anzeigeLink, + $descr, + $this->gefVon, + $this->counter, + false + ); } - $this->counter++; - $this->results[] = new \App\Models\Result( - $this->engine, - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter, - false - ); + } catch (\Exception $e) { + Log::error("A problem occurred parsing results from $this->name"); + return; } } } diff --git a/app/Models/parserSkripte/Tuhh.php b/app/Models/parserSkripte/Tuhh.php index 6c91509100ea021a535147406dce9927cd9f0e9d..05c8bc326910bc0529ab152c6242b7dfee02c149 100644 --- a/app/Models/parserSkripte/Tuhh.php +++ b/app/Models/parserSkripte/Tuhh.php @@ -15,37 +15,38 @@ 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) { - break; + if (!$content) { + return; } - $title = $result->{"title"}->__toString(); - $link = $result->{"link"}["href"]->__toString(); - $anzeigeLink = $link; - $descr = strip_tags($result->{"summary"}->__toString()); - $this->counter++; - $this->results[] = new \App\Models\Result( - $this->engine, - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter - ); - $count++; + $count = 0; + foreach ($content->{"entry"} as $result) { + if ($count > 10) { + break; + } + + $title = $result->{"title"}->__toString(); + $link = $result->{"link"}["href"]->__toString(); + $anzeigeLink = $link; + $descr = strip_tags($result->{"summary"}->__toString()); + $this->counter++; + $this->results[] = new \App\Models\Result( + $this->engine, + $title, + $link, + $anzeigeLink, + $descr, + $this->gefVon, + $this->counter + ); + $count++; + } + } catch (\Exception $e) { + Log::error("A problem occurred parsing results from $this->name"); + return; } - } } diff --git a/app/Models/parserSkripte/Yacy.php b/app/Models/parserSkripte/Yacy.php index 05ac7e562c393b72c415abd3013ac22c538ae70a..83f0c5a6de669ca2fe25f695dd8b50b7bbe08a29 100644 --- a/app/Models/parserSkripte/Yacy.php +++ b/app/Models/parserSkripte/Yacy.php @@ -15,38 +15,38 @@ class Yacy 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("//rss/channel/item"); + if (!$results) { + return; + } + + foreach ($results as $res) { + $title = $res->{"title"}; + $link = $res->{"link"}; + $anzeigeLink = $link; + $descr = $res->{"description"}; + + $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) { - return; - } - - $results = $content->xpath("//rss/channel/item"); - if (!$results) { + Log::error("A problem occurred parsing results from $this->name"); return; } - - foreach ($results as $res) { - $title = $res->{"title"}; - $link = $res->{"link"}; - $anzeigeLink = $link; - $descr = $res->{"description"}; - - $this->counter++; - $this->results[] = new \App\Models\Result( - $this->engine, - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter - ); - } } } diff --git a/app/Models/parserSkripte/Yacyunih.php b/app/Models/parserSkripte/Yacyunih.php index beefd276e7c3e705d27ebf5696311f7e03b3aafc..a8585f4f3bf6f6c5fc0cf132a060f6dd3afc48a3 100644 --- a/app/Models/parserSkripte/Yacyunih.php +++ b/app/Models/parserSkripte/Yacyunih.php @@ -15,43 +15,41 @@ 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; + if (!$content) { + return; } - $title = $result->{"title"}->__toString(); - $link = $result->{"link"}->__toString(); - $anzeigeLink = $link; - $descr = strip_tags($result->{"description"}->__toString()); - $this->counter++; - $this->results[] = new \App\Models\Result( - $this->engine, - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter - ); - $count++; - + $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; + $descr = strip_tags($result->{"description"}->__toString()); + $this->counter++; + $this->results[] = new \App\Models\Result( + $this->engine, + $title, + $link, + $anzeigeLink, + $descr, + $this->gefVon, + $this->counter + ); + $count++; + } + } catch (\Exception $e) { + Log::error("A problem occurred parsing results from $this->name"); + return; } - } } diff --git a/app/Models/parserSkripte/Yandex.php b/app/Models/parserSkripte/Yandex.php index 9a29c72659bc705155a9bcf1afe61a9c95c5e73d..acf4bc0bc99cdeef1e243c9ebd63b0ee3b16db8e 100644 --- a/app/Models/parserSkripte/Yandex.php +++ b/app/Models/parserSkripte/Yandex.php @@ -3,6 +3,7 @@ namespace app\Models\parserSkripte; use App\Models\Searchengine; +use Log; class Yandex extends Searchengine { @@ -18,59 +19,57 @@ class Yandex 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; + } - if (!$content) { - return; - } - $results = $content; - try { - $results = $results->xpath("//yandexsearch/response/results/grouping/group"); - } catch (\ErrorException $e) { - return; - } - foreach ($results as $result) { - $title = strip_tags($result->{"doc"}->{"title"}->asXML()); - $link = $result->{"doc"}->{"url"}->__toString(); - $anzeigeLink = $link; - $descr = strip_tags($result->{"doc"}->{"headline"}->asXML()); - if (!$descr) { - $descr = strip_tags($result->{"doc"}->{"passages"}->asXML()); + $results = $content->xpath("//yandexsearch/response/results/grouping/group"); + foreach ($results as $result) { + $title = strip_tags($result->{"doc"}->{"title"}->asXML()); + $link = $result->{"doc"}->{"url"}->__toString(); + $anzeigeLink = $link; + $descr = strip_tags($result->{"doc"}->{"headline"}->asXML()); + if (!$descr) { + $descr = strip_tags($result->{"doc"}->{"passages"}->asXML()); + } + $this->counter++; + $this->results[] = new \App\Models\Result( + $this->engine, + $title, + $link, + $anzeigeLink, + $descr, + $this->gefVon, + $this->counter + ); } - $this->counter++; - $this->results[] = new \App\Models\Result( - $this->engine, - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter - ); + } catch (\Exception $e) { + Log::error("A problem occurred parsing results from $this->name"); + return; } } public function getNext(\App\MetaGer $metager, $result) { - # Wir müssen herausfinden, ob es überhaupt noch weitere Ergebnisse von Yandex gibt: + $result = preg_replace("/\r\n/si", "", $result); 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); } catch (\Exception $e) { + Log::error("A problem occurred parsing results from $this->name"); 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; } }