ArstechnicaBridge.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. #ini_set('display_errors', 'On');
  3. #error_reporting(E_ALL);
  4. class ArstechnicaBridge extends BridgeAbstract {
  5. public function loadMetadatas() {
  6. $this->maintainer = "prysme";
  7. $this->name = "ArstechnicaBridge";
  8. $this->uri = "http://arstechnica.com";
  9. $this->description = "The PC enthusiast's resource. Power users and the tools they love, without computing religion";
  10. }
  11. function StripWithDelimiters($string, $start, $end) {
  12. while (strpos($string, $start) !== false) {
  13. $section_to_remove = substr($string, strpos($string, $start));
  14. $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
  15. $string = str_replace($section_to_remove, '', $string);
  16. } return $string;
  17. }
  18. function StripCDATA($string) {
  19. $string = str_replace('<![CDATA[', '', $string);
  20. $string = str_replace(']]>', '', $string);
  21. return $string;
  22. }
  23. function ExtractContent($url) {
  24. #echo $url;
  25. $html2 = $this->getSimpleHTMLDOM($url);
  26. $text = $html2->find("section[id='article-guts']", 0);
  27. /*foreach ($text->find('<aside id="social-left">') as $node)
  28. { $node = NULL; }*/
  29. $text = $this->StripWithDelimiters($text->innertext,'<aside id="social-left">','</aside>');
  30. $text = $this->StripWithDelimiters($text,'<figcaption class="caption">','</figcaption>');
  31. $text = $this->StripWithDelimiters($text,'<div class="gallery shortcode-gallery">','</div>');
  32. //error_log("ICI", 0);
  33. //error_log($text, 0);
  34. return $text;
  35. }
  36. public function collectData(array $param) {
  37. $html = $this->getSimpleHTMLDOM('http://feeds.arstechnica.com/arstechnica/index') or $this->returnServerError('Could not request NextInpact.');
  38. $limit = 0;
  39. foreach($html->find('item') as $element) {
  40. if($limit < 5) {
  41. $item = array();
  42. $item['title'] = $this->StripCDATA($element->find('title', 0)->innertext);
  43. $item['uri'] = $this->StripCDATA($element->find('guid', 0)->plaintext);
  44. $item['author'] = $this->StripCDATA($element->find('author', 0)->innertext);
  45. $item['timestamp'] = strtotime($element->find('pubDate', 0)->plaintext);
  46. $item['content'] = $this->ExtractContent($item['uri']);
  47. //$item['content'] = $item['uri'];
  48. $this->items[] = $item;
  49. $limit++;
  50. }
  51. }
  52. }
  53. public function getCacheDuration() {
  54. return 7200; // 2h
  55. }
  56. }