mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-05 02:24:35 +02:00
[bridges] Change to extend from FeedExpander
This commit is contained in:
parent
11be7ccb60
commit
179e73fb80
12 changed files with 262 additions and 437 deletions
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
class NextgovBridge extends BridgeAbstract {
|
||||
class NextgovBridge extends FeedExpander {
|
||||
|
||||
const MAINTAINER = 'ORelio';
|
||||
const NAME = 'Nextgov Bridge';
|
||||
|
@ -26,57 +26,45 @@ class NextgovBridge extends BridgeAbstract {
|
|||
));
|
||||
|
||||
public function collectData(){
|
||||
$this->collectExpandableDatas(self::URI . 'rss/' . $this->getInput('category') . '/');
|
||||
}
|
||||
|
||||
function ExtractFromDelimiters($string, $start, $end) {
|
||||
if (strpos($string, $start) !== false) {
|
||||
$section_retrieved = substr($string, strpos($string, $start) + strlen($start));
|
||||
$section_retrieved = substr($section_retrieved, 0, strpos($section_retrieved, $end));
|
||||
return $section_retrieved;
|
||||
} return false;
|
||||
}
|
||||
protected function parseItem($newsItem){
|
||||
$item = $this->parseRSS_2_0_Item($newsItem);
|
||||
|
||||
function StripWithDelimiters($string, $start, $end) {
|
||||
while (strpos($string, $start) !== false) {
|
||||
$section_to_remove = substr($string, strpos($string, $start));
|
||||
$section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
|
||||
$string = str_replace($section_to_remove, '', $string);
|
||||
} return $string;
|
||||
}
|
||||
$item['content'] = '';
|
||||
|
||||
$category = $this->getInput('category');
|
||||
$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) {
|
||||
break;
|
||||
$namespaces = $newsItem->getNamespaces(true);
|
||||
if(isset($namespaces['media'])){
|
||||
$media = $newsItem->children($namespaces['media']);
|
||||
if(isset($media->content)){
|
||||
$attributes = $media->content->attributes();
|
||||
$item['content'] = '<img src="' . $attributes['url'] . '">';
|
||||
}
|
||||
|
||||
$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++;
|
||||
}
|
||||
|
||||
$item['content'] .= $this->ExtractContent($item['uri']);
|
||||
return $item;
|
||||
}
|
||||
|
||||
private function StripWithDelimiters($string, $start, $end) {
|
||||
while (strpos($string, $start) !== false) {
|
||||
$section_to_remove = substr($string, strpos($string, $start));
|
||||
$section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
|
||||
$string = str_replace($section_to_remove, '', $string);
|
||||
} return $string;
|
||||
}
|
||||
|
||||
private function ExtractContent($url){
|
||||
$article = $this->get_cached($url)
|
||||
or $this->returnServerError('Could not request Nextgov: ' . $url);
|
||||
|
||||
$contents = $article->find('div.wysiwyg', 0)->innertext;
|
||||
$contents = $this->StripWithDelimiters($contents, '<div class="ad-container">', '</div>');
|
||||
$contents = $this->StripWithDelimiters($contents, '<div', '</div>'); //ad outer div
|
||||
return $this->StripWithDelimiters($contents, '<script', '</script>');
|
||||
$contents = ($article_thumbnail == '' ? '' : '<p><img src="'.$article_thumbnail.'" /></p>')
|
||||
.'<p><b>'.$article_subtitle.'</b></p>'
|
||||
.trim($contents);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue