From 4f9e03f34670cf2b5a7aaa191bcae8cc72803c23 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Wed, 3 Aug 2016 13:16:47 +0200 Subject: [PATCH] Create nested function to receive article or element author This fixes an error that occurred by attempting to access an object that did not exist (author). --- bridges/FuturaSciencesBridge.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/bridges/FuturaSciencesBridge.php b/bridges/FuturaSciencesBridge.php index 9cf893f3..f8d03984 100644 --- a/bridges/FuturaSciencesBridge.php +++ b/bridges/FuturaSciencesBridge.php @@ -7,7 +7,7 @@ class FuturaSciencesBridge extends BridgeAbstract { $this->name = $this->getName(); $this->uri = $this->getURI(); $this->description = 'Returns the newest articles.'; - $this->update = '2016-03-20'; + $this->update = '2016-08-03'; $this->parameters[] = '[ @@ -149,6 +149,23 @@ class FuturaSciencesBridge extends BridgeAbstract { return $string; } + // Extracts the author from an article or element + function ExtractAuthor($article, $element){ + $article_author = $article->find('span.author', 0); + if($article_author){ + $authorname = trim(str_replace(', Futura-Sciences', '', $article_author->plaintext)); + if(empty($authorname)){ + $element_author = $element->find('author', 0); + if($element_author) + $authorname = StripCDATA($element_author->plaintext); + else + return ''; + } + return $authorname; + } + return ''; + } + if (empty($param['feed'])) $this->returnError('Please select a feed to display.'.$url, 400); if ($param['feed'] !== preg_replace('/[^a-zA-Z-\/]+/', '', $param['feed']) || substr_count($param['feed'], '/') > 1 || strlen($param['feed'] > 64)) @@ -163,9 +180,6 @@ class FuturaSciencesBridge extends BridgeAbstract { $article_url = str_replace('#xtor=RSS-8', '', StripCDATA($element->find('guid', 0)->plaintext)); $article = $this->file_get_html($article_url) or $this->returnError('Could not request Futura-Sciences: '.$article_url, 500); $contents = $article->find('div.content', 0)->innertext; - $author = trim(str_replace(', Futura-Sciences', '', $article->find('span.author', 0)->plaintext)); - if (empty($author)) - $author = StripCDATA($element->find('author', 0)->plaintext); foreach (array( '
author = $author; + $item->author = ExtractAuthor($article, $element); $item->uri = $article_url; $item->title = StripCDATA($element->find('title', 0)->innertext); $item->thumbnailUri = StripCDATA($element->find('enclosure', 0)->url);