NextgovBridge.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }
  48. return $string;
  49. }
  50. private function extractContent($url){
  51. $article = getSimpleHTMLDOMCached($url)
  52. or returnServerError('Could not request Nextgov: ' . $url);
  53. $contents = $article->find('div.wysiwyg', 0)->innertext;
  54. $contents = $this->stripWithDelimiters($contents, '<div class="ad-container">', '</div>');
  55. $contents = $this->stripWithDelimiters($contents, '<div', '</div>'); //ad outer div
  56. return $this->stripWithDelimiters($contents, '<script', '</script>');
  57. $contents = ($article_thumbnail == '' ? '' : '<p><img src="' . $article_thumbnail . '" /></p>')
  58. . '<p><b>'
  59. . $article_subtitle
  60. . '</b></p>'
  61. . trim($contents);
  62. }
  63. }