mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-26 03:16:33 +03:00
[NextgovBridge] code simplification
Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
parent
03cbd756a6
commit
3fb8c5b916
1 changed files with 27 additions and 31 deletions
|
@ -44,43 +44,39 @@ class NextgovBridge extends BridgeAbstract {
|
|||
}
|
||||
|
||||
$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.'/';
|
||||
$html = $this->getSimpleHTMLDOM($url) or $this->returnServerError('Could not request Nextgov: '.$url);
|
||||
$limit = 0;
|
||||
|
||||
foreach ($html->find('item') as $element) {
|
||||
if ($limit < 10) {
|
||||
|
||||
$article_url = ExtractFromDelimiters($element->innertext, '<link>', '</link>');
|
||||
$article_author = ExtractFromDelimiters($element->innertext, 'dc/elements/1.1/">', '</dc:creator>');
|
||||
$article_title = $element->find('title', 0)->plaintext;
|
||||
$article_subtitle = $element->find('description', 0)->plaintext;
|
||||
$article_timestamp = strtotime($element->find('pubDate', 0)->plaintext);
|
||||
$article_thumbnail = ExtractFromDelimiters($element->innertext, '<media:content url="', '"');
|
||||
$article = $this->getSimpleHTMLDOM($article_url) or $this->returnServerError('Could not request Nextgov: '.$article_url);
|
||||
|
||||
$contents = $article->find('div.wysiwyg', 0)->innertext;
|
||||
$contents = StripWithDelimiters($contents, '<div class="ad-container">', '</div>');
|
||||
$contents = StripWithDelimiters($contents, '<div', '</div>'); //ad outer div
|
||||
$contents = StripWithDelimiters($contents, '<script', '</script>');
|
||||
$contents = ($article_thumbnail == '' ? '' : '<p><img src="'.$article_thumbnail.'" /></p>')
|
||||
.'<p><b>'.$article_subtitle.'</b></p>'
|
||||
.trim($contents);
|
||||
|
||||
$item = array();
|
||||
$item['uri'] = $article_url;
|
||||
$item['title'] = $article_title;
|
||||
$item['author'] = $article_author;
|
||||
$item['timestamp'] = $article_timestamp;
|
||||
$item['content'] = $contents;
|
||||
$this->items[] = $item;
|
||||
$limit++;
|
||||
if ($limit >= 10) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$article_url = ExtractFromDelimiters($element->innertext, '<link>', '</link>');
|
||||
$article_author = ExtractFromDelimiters($element->innertext, 'dc/elements/1.1/">', '</dc:creator>');
|
||||
$article_title = $element->find('title', 0)->plaintext;
|
||||
$article_subtitle = $element->find('description', 0)->plaintext;
|
||||
$article_timestamp = strtotime($element->find('pubDate', 0)->plaintext);
|
||||
$article_thumbnail = ExtractFromDelimiters($element->innertext, '<media:content url="', '"');
|
||||
$article = $this->getSimpleHTMLDOM($article_url) or $this->returnServerError('Could not request Nextgov: '.$article_url);
|
||||
|
||||
$contents = $article->find('div.wysiwyg', 0)->innertext;
|
||||
$contents = StripWithDelimiters($contents, '<div class="ad-container">', '</div>');
|
||||
$contents = StripWithDelimiters($contents, '<div', '</div>'); //ad outer div
|
||||
$contents = StripWithDelimiters($contents, '<script', '</script>');
|
||||
$contents = ($article_thumbnail == '' ? '' : '<p><img src="'.$article_thumbnail.'" /></p>')
|
||||
.'<p><b>'.$article_subtitle.'</b></p>'
|
||||
.trim($contents);
|
||||
|
||||
$item = array();
|
||||
$item['uri'] = $article_url;
|
||||
$item['title'] = $article_title;
|
||||
$item['author'] = $article_author;
|
||||
$item['timestamp'] = $article_timestamp;
|
||||
$item['content'] = $contents;
|
||||
$this->items[] = $item;
|
||||
$limit++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue