[NextgovBridge] code simplification

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-08-29 13:57:02 +02:00
parent 03cbd756a6
commit 3fb8c5b916

View file

@ -44,16 +44,14 @@ class NextgovBridge extends BridgeAbstract {
} }
$category = $this->getInput('category'); $category = $this->getInput('category');
if (empty($category))
$category = 'all';
if ($category !== preg_replace('/[^a-z-]+/', '', $category) || strlen($category > 32))
$this->returnClientError('Invalid "category" parameter.');
$url = $this->getURI().'rss/'.$category.'/'; $url = $this->getURI().'rss/'.$category.'/';
$html = $this->getSimpleHTMLDOM($url) or $this->returnServerError('Could not request Nextgov: '.$url); $html = $this->getSimpleHTMLDOM($url) or $this->returnServerError('Could not request Nextgov: '.$url);
$limit = 0; $limit = 0;
foreach ($html->find('item') as $element) { foreach ($html->find('item') as $element) {
if ($limit < 10) { if ($limit >= 10) {
break;
}
$article_url = ExtractFromDelimiters($element->innertext, '<link>', '</link>'); $article_url = ExtractFromDelimiters($element->innertext, '<link>', '</link>');
$article_author = ExtractFromDelimiters($element->innertext, 'dc/elements/1.1/">', '</dc:creator>'); $article_author = ExtractFromDelimiters($element->innertext, 'dc/elements/1.1/">', '</dc:creator>');
@ -81,6 +79,4 @@ class NextgovBridge extends BridgeAbstract {
$limit++; $limit++;
} }
} }
}
} }