2013-12-16 18:29:33 +04:00
|
|
|
<?php
|
|
|
|
class DuckDuckGoBridge extends BridgeAbstract{
|
|
|
|
|
2016-08-27 22:03:26 +03:00
|
|
|
public $maintainer = "Astalaseven";
|
|
|
|
public $name = "DuckDuckGo";
|
|
|
|
public $uri = "https://duckduckgo.com/";
|
|
|
|
public $description = "Returns most recent results from DuckDuckGo.";
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-27 22:03:26 +03:00
|
|
|
public $parameters = array( array(
|
|
|
|
'u'=>array(
|
2016-08-22 02:25:56 +03:00
|
|
|
'name'=>'keyword',
|
|
|
|
'required'=>true)
|
2016-08-27 22:03:26 +03:00
|
|
|
));
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
public function collectData(){
|
|
|
|
$param=$this->parameters[$this->queriedContext];
|
2013-12-16 18:29:33 +04:00
|
|
|
$html = '';
|
2016-08-25 02:24:53 +03:00
|
|
|
$link = 'http://duckduckgo.com/html/?q='.$param['u']['value'].'+sort:date';
|
2013-12-16 18:29:33 +04:00
|
|
|
|
2016-07-08 20:06:35 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request DuckDuckGo.');
|
2013-12-16 18:29:33 +04:00
|
|
|
|
|
|
|
foreach($html->find('div.results_links') as $element) {
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
|
|
|
$item['uri'] = $element->find('a', 0)->href;
|
|
|
|
$item['title'] = $element->find('a', 1)->innertext;
|
|
|
|
$item['content'] = $element->find('div.snippet', 0)->plaintext;
|
2013-12-16 18:29:33 +04:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
|
|
|
return 21600; // 6 hours
|
|
|
|
}
|
|
|
|
}
|