2013-12-16 15:29:33 +01:00
|
|
|
<?php
|
|
|
|
class DuckDuckGoBridge extends BridgeAbstract{
|
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "Astalaseven";
|
|
|
|
const NAME = "DuckDuckGo";
|
|
|
|
const URI = "https://duckduckgo.com/";
|
2016-09-25 17:04:28 +02:00
|
|
|
const CACHE_TIMEOUT = 21600; // 6h
|
2016-10-19 00:40:34 +02:00
|
|
|
const DESCRIPTION = "Returns results from DuckDuckGo.";
|
|
|
|
|
|
|
|
const SORT_DATE = '+sort:date';
|
|
|
|
const SORT_RELEVANCE = '';
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const PARAMETERS = array( array(
|
2016-08-27 21:03:26 +02:00
|
|
|
'u'=>array(
|
2016-08-22 01:25:56 +02:00
|
|
|
'name'=>'keyword',
|
2016-10-19 00:40:34 +02:00
|
|
|
'required'=>true),
|
|
|
|
'sort'=>array(
|
|
|
|
'name'=>'sort by',
|
|
|
|
'type'=>'list',
|
|
|
|
'required'=>false,
|
|
|
|
'values'=>array(
|
|
|
|
'date'=>self::SORT_DATE,
|
|
|
|
'relevance'=>self::SORT_RELEVANCE
|
|
|
|
),
|
|
|
|
'defaultValue'=>self::SORT_DATE
|
|
|
|
)
|
2016-08-27 21:03:26 +02:00
|
|
|
));
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2017-02-01 01:58:05 +01:00
|
|
|
$html = getSimpleHTMLDOM(self::URI.'html/?kd=-1&q='.$this->getInput('u').$this->getInput('sort'))
|
2016-09-25 23:22:33 +02:00
|
|
|
or returnServerError('Could not request DuckDuckGo.');
|
2013-12-16 15:29:33 +01:00
|
|
|
|
|
|
|
foreach($html->find('div.results_links') as $element) {
|
2016-08-22 18:55:59 +02: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 15:29:33 +01:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|