ArstechnicaBridge.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. $this->update = "01/08/2016";
  11. }
  12. public function collectData(array $param) {
  13. function StripWithDelimiters($string, $start, $end) {
  14. while (strpos($string, $start) !== false) {
  15. $section_to_remove = substr($string, strpos($string, $start));
  16. $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
  17. $string = str_replace($section_to_remove, '', $string);
  18. } return $string;
  19. }
  20. function StripCDATA($string) {
  21. $string = str_replace('<![CDATA[', '', $string);
  22. $string = str_replace(']]>', '', $string);
  23. return $string;
  24. }
  25. function ExtractContent($url) {
  26. #echo $url;
  27. $html2 = file_get_html($url);
  28. $text = $html2->find("section[id='article-guts']", 0);
  29. /*foreach ($text->find('<aside id="social-left">') as $node)
  30. { $node = NULL; }*/
  31. $text = StripWithDelimiters($text->innertext,'<aside id="social-left">','</aside>');
  32. $text = StripWithDelimiters($text,'<figcaption class="caption">','</figcaption>');
  33. $text = StripWithDelimiters($text,'<div class="gallery shortcode-gallery">','</div>');
  34. //error_log("ICI", 0);
  35. //error_log($text, 0);
  36. return $text;
  37. }
  38. $html = $this->file_get_html('http://feeds.arstechnica.com/arstechnica/index') or $this->returnError('Could not request NextInpact.', 404);
  39. $limit = 0;
  40. foreach($html->find('item') as $element) {
  41. if($limit < 5) {
  42. $item = new \Item();
  43. $item->title = StripCDATA($element->find('title', 0)->innertext);
  44. $item->uri = StripCDATA($element->find('guid', 0)->plaintext);
  45. $item->thumbnailUri = StripCDATA($element->find('enclosure', 0)->url);
  46. $item->author = StripCDATA($element->find('author', 0)->innertext);
  47. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  48. $item->content = ExtractContent($item->uri);
  49. //$item->content = $item->uri;
  50. $this->items[] = $item;
  51. $limit++;
  52. }
  53. }
  54. }
  55. public function getName() {
  56. return 'ArsTechnica';
  57. }
  58. public function getCacheDuration() {
  59. return 7200; // 2h
  60. }
  61. public function getURI() {
  62. return "http://arstechnica.com";
  63. }
  64. }