WeLiveSecurityBridge.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. class WeLiveSecurityBridge extends FeedExpander {
  3. const MAINTAINER = 'ORelio';
  4. const NAME = 'We Live Security';
  5. const URI = 'http://www.welivesecurity.com/';
  6. const DESCRIPTION = 'Returns the newest articles.';
  7. private function stripWithDelimiters($string, $start, $end){
  8. while(strpos($string, $start) !== false) {
  9. $section_to_remove = substr($string, strpos($string, $start));
  10. $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
  11. $string = str_replace($section_to_remove, '', $string);
  12. }
  13. return $string;
  14. }
  15. protected function parseItem($item){
  16. $item = parent::parseItem($item);
  17. $article_html = getSimpleHTMLDOMCached($item['uri']);
  18. if(!$article_html) {
  19. $item['content'] .= '<p>Could not request ' . $this->getName() . ': ' . $item['uri'] . '</p>';
  20. return $item;
  21. }
  22. $article_content = $article_html->find('div.wlistingsingletext', 0)->innertext;
  23. $article_content = $this->stripWithDelimiters($article_content, '<script', '</script>');
  24. $article_content = '<p><b>'
  25. . $item['content']
  26. . '</b></p>'
  27. . trim($article_content);
  28. $item['content'] = $article_content;
  29. return $item;
  30. }
  31. public function collectData(){
  32. $feed = static::URI . 'feed/';
  33. $this->collectExpandableDatas($feed);
  34. }
  35. }