2016-07-26 21:20:13 +02:00
|
|
|
<?php
|
|
|
|
class NextgovBridge extends BridgeAbstract {
|
|
|
|
|
2016-08-27 21:03:26 +02:00
|
|
|
public $maintainer = 'ORelio';
|
|
|
|
public $name = 'Nextgov Bridge';
|
|
|
|
public $uri = 'https://www.nextgov.com/';
|
|
|
|
public $description = 'USA Federal technology news, best practices, and web 2.0 tools.';
|
2016-07-26 21:20:13 +02:00
|
|
|
|
2016-08-27 21:03:26 +02:00
|
|
|
public $parameters = array( array(
|
|
|
|
'category'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'Category',
|
|
|
|
'type'=>'list',
|
|
|
|
'values'=>array(
|
2016-08-27 21:03:26 +02:00
|
|
|
'All'=>'all',
|
|
|
|
'Technology News'=>'technology-news',
|
|
|
|
'CIO Briefing'=>'cio-briefing',
|
|
|
|
'Emerging Tech'=>'emerging-tech',
|
|
|
|
'Cloud'=>'cloud-computing',
|
|
|
|
'Cybersecurity'=>'cybersecurity',
|
|
|
|
'Mobile'=>'mobile',
|
|
|
|
'Health'=>'health',
|
|
|
|
'Defense'=>'defense',
|
|
|
|
'Big Data'=>'big-data'
|
2016-08-22 01:25:56 +02:00
|
|
|
)
|
2016-08-27 21:03:26 +02:00
|
|
|
)
|
|
|
|
));
|
2016-07-26 21:20:13 +02:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
|
|
|
$param=$this->parameters[$this->queriedContext];
|
2016-07-26 21:20:13 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
$category = $param['category']['value'];
|
2016-07-26 21:20:13 +02:00
|
|
|
if (empty($category))
|
|
|
|
$category = 'all';
|
|
|
|
if ($category !== preg_replace('/[^a-z-]+/', '', $category) || strlen($category > 32))
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnClientError('Invalid "category" parameter.');
|
2016-07-26 21:20:13 +02:00
|
|
|
$url = $this->getURI().'rss/'.$category.'/';
|
2016-08-09 14:57:42 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM($url) or $this->returnServerError('Could not request Nextgov: '.$url);
|
2016-07-26 21:20:13 +02:00
|
|
|
$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="', '"');
|
2016-08-09 14:57:42 +02:00
|
|
|
$article = $this->getSimpleHTMLDOM($article_url) or $this->returnServerError('Could not request Nextgov: '.$article_url);
|
2016-07-26 21:20:13 +02:00
|
|
|
|
|
|
|
$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);
|
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
|
|
|
$item['uri'] = $article_url;
|
|
|
|
$item['title'] = $article_title;
|
|
|
|
$item['author'] = $article_author;
|
|
|
|
$item['timestamp'] = $article_timestamp;
|
|
|
|
$item['content'] = $contents;
|
2016-07-26 21:20:13 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
$limit++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-08-09 14:57:42 +02:00
|
|
|
}
|