DuckDuckGoBridge.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * RssBridgeDuckDuckGo
  4. * Search DuckDuckGo for most recent pages regarding a specific topic.
  5. * Returns the most recent links in results, sorting by date (most recent first).
  6. *
  7. * @name DuckDuckGo
  8. * @description Returns most recent results from DuckDuckGo.
  9. * @maintainer Astalaseven
  10. * @use1(u="keyword")
  11. */
  12. class DuckDuckGoBridge extends BridgeAbstract{
  13. public function collectData(array $param){
  14. $html = '';
  15. $link = 'http://duckduckgo.com/html/?q='.$param[u].'+sort:date';
  16. $html = file_get_html($link) or $this->returnError('Could not request DuckDuckGo.', 404);
  17. foreach($html->find('div.results_links') as $element) {
  18. $item = new \Item();
  19. $item->uri = $element->find('a', 0)->href;
  20. $item->title = $element->find('a', 1)->innertext;
  21. $item->content = $element->find('div.snippet', 0)->plaintext;
  22. $this->items[] = $item;
  23. }
  24. }
  25. public function getName(){
  26. return 'DuckDuckGo';
  27. }
  28. public function getURI(){
  29. return 'https://duckduckgo.com';
  30. }
  31. public function getCacheDuration(){
  32. return 21600; // 6 hours
  33. }
  34. }