NextgovBridge.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. class NextgovBridge extends FeedExpander {
  3. const MAINTAINER = 'ORelio';
  4. const NAME = 'Nextgov Bridge';
  5. const URI = 'https://www.nextgov.com/';
  6. const DESCRIPTION = 'USA Federal technology news, best practices, and web 2.0 tools.';
  7. const PARAMETERS = array( array(
  8. 'category'=>array(
  9. 'name'=>'Category',
  10. 'type'=>'list',
  11. 'values'=>array(
  12. 'All'=>'all',
  13. 'Technology News'=>'technology-news',
  14. 'CIO Briefing'=>'cio-briefing',
  15. 'Emerging Tech'=>'emerging-tech',
  16. 'Cloud'=>'cloud-computing',
  17. 'Cybersecurity'=>'cybersecurity',
  18. 'Mobile'=>'mobile',
  19. 'Health'=>'health',
  20. 'Defense'=>'defense',
  21. 'Big Data'=>'big-data'
  22. )
  23. )
  24. ));
  25. public function collectData(){
  26. $this->collectExpandableDatas(self::URI . 'rss/' . $this->getInput('category') . '/', 10);
  27. }
  28. protected function parseItem($newsItem){
  29. $item = parent::parseItem($newsItem);
  30. $item['content'] = '';
  31. $namespaces = $newsItem->getNamespaces(true);
  32. if(isset($namespaces['media'])){
  33. $media = $newsItem->children($namespaces['media']);
  34. if(isset($media->content)){
  35. $attributes = $media->content->attributes();
  36. $item['content'] = '<img src="' . $attributes['url'] . '">';
  37. }
  38. }
  39. $item['content'] .= $this->ExtractContent($item['uri']);
  40. return $item;
  41. }
  42. private function StripWithDelimiters($string, $start, $end) {
  43. while (strpos($string, $start) !== false) {
  44. $section_to_remove = substr($string, strpos($string, $start));
  45. $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
  46. $string = str_replace($section_to_remove, '', $string);
  47. } return $string;
  48. }
  49. private function ExtractContent($url){
  50. $article = getSimpleHTMLDOMCached($url)
  51. or returnServerError('Could not request Nextgov: ' . $url);
  52. $contents = $article->find('div.wysiwyg', 0)->innertext;
  53. $contents = $this->StripWithDelimiters($contents, '<div class="ad-container">', '</div>');
  54. $contents = $this->StripWithDelimiters($contents, '<div', '</div>'); //ad outer div
  55. return $this->StripWithDelimiters($contents, '<script', '</script>');
  56. $contents = ($article_thumbnail == '' ? '' : '<p><img src="'.$article_thumbnail.'" /></p>')
  57. .'<p><b>'.$article_subtitle.'</b></p>'
  58. .trim($contents);
  59. }
  60. }