DuckDuckGoBridge.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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->parameters[] = array(
  9. 'u'=>array(
  10. 'name'=>'keyword',
  11. 'required'=>true)
  12. );
  13. }
  14. public function collectData(array $param){
  15. $html = '';
  16. $link = 'http://duckduckgo.com/html/?q='.$param['u'].'+sort:date';
  17. $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request DuckDuckGo.');
  18. foreach($html->find('div.results_links') as $element) {
  19. $item = array();
  20. $item['uri'] = $element->find('a', 0)->href;
  21. $item['title'] = $element->find('a', 1)->innertext;
  22. $item['content'] = $element->find('div.snippet', 0)->plaintext;
  23. $this->items[] = $item;
  24. }
  25. }
  26. public function getCacheDuration(){
  27. return 21600; // 6 hours
  28. }
  29. }