DuckDuckGoBridge.php 1.2 KB

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