SiliconBridge.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. class SiliconBridge extends BridgeAbstract {
  3. public function loadMetadatas() {
  4. $this->maintainer = "ORelio";
  5. $this->name = "Silicon.fr";
  6. $this->uri = "http://www.silicon.fr/";
  7. $this->description = "Returns the newest articles.";
  8. $this->update = "2015-09-08";
  9. }
  10. public function collectData(array $param) {
  11. function StripCDATA($string) {
  12. $string = str_replace('<![CDATA[', '', $string);
  13. $string = str_replace(']]>', '', $string);
  14. return $string;
  15. }
  16. $feedUrl = 'http://www.silicon.fr/feed';
  17. $html = $this->file_get_html($feedUrl) or $this->returnError('Could not request Silicon: '.$feedUrl, 500);
  18. $limit = 0;
  19. foreach($html->find('item') as $element) {
  20. if($limit < 5) {
  21. //Retrieve article Uri and get that page
  22. $article_uri = $element->innertext;
  23. $article_uri = substr($article_uri, strpos($article_uri, '<link>') + 6);
  24. $article_uri = substr($article_uri, 0, strpos($article_uri, '</link>'));
  25. $article_html = $this->file_get_html($article_uri) or $this->returnError('Could not request Silicon: '.$article_uri, 500);
  26. //Build article contents from corresponding elements
  27. $thumbnailUri = $element->find('enclosure', 0)->url;
  28. $article_content = '<p><img src="'.$thumbnailUri.'" /></p>'
  29. .'<p><b>'.$article_html->find('div.entry-excerpt', 0)->plaintext.'</b></p>'
  30. .$article_html->find('div.entry-content', 0)->innertext;
  31. //Remove useless scripts left in the page
  32. while (strpos($article_content, '<script') !== false) {
  33. $script_section = substr($article_content, strpos($article_content, '<script'));
  34. $script_section = substr($script_section, 0, strpos($script_section, '</script>') + 9);
  35. $article_content = str_replace($script_section, '', $article_content);
  36. }
  37. //Build and add final item
  38. $item = new \Item();
  39. $item->uri = $article_uri;
  40. $item->thumbnailUri = $thumbnailUri;
  41. $item->title = StripCDATA($element->find('title', 0)->innertext);
  42. $item->author = StripCDATA($element->find('dc:creator', 0)->innertext);
  43. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  44. $item->content = $article_content;
  45. $this->items[] = $item;
  46. $limit++;
  47. }
  48. }
  49. }
  50. public function getName() {
  51. return 'Silicon Bridge';
  52. }
  53. public function getURI() {
  54. return 'http://www.silicon.fr/';
  55. }
  56. public function getCacheDuration() {
  57. return 1800; // 30 minutes
  58. // return 0;
  59. }
  60. }