0.9.0 - the ZapV version updated to current php standards. Brave search used, while Bing and Google search api are deprecated
This commit is contained in:
parent
3d4298fe8b
commit
4ddaddda3d
31 changed files with 1778 additions and 1 deletions
70
resource/Brave.class.php
Normal file
70
resource/Brave.class.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
class Brave implements Search {
|
||||
private $key = BRAVE_API_KEY;
|
||||
private $base_url = BRAVE_BASE;
|
||||
private $q_prefix = '?q=';
|
||||
private $count_prefix = '&count=';
|
||||
private $adultPrefix = '&safesearch=';
|
||||
|
||||
private $word;
|
||||
private $start;
|
||||
private $size;
|
||||
private $myCurl;
|
||||
|
||||
public function __construct() {
|
||||
if (ZAP_ADULT == true) {
|
||||
$this->adultPrefix .= 'off';
|
||||
} else {
|
||||
$this->adultPrefix .= 'strict';
|
||||
}
|
||||
}
|
||||
|
||||
public function setQuery($word) {
|
||||
$this->word = $word;
|
||||
|
||||
$request = $this->q_prefix . urlencode($word);
|
||||
if (isset($this->start)) {
|
||||
$request .= '&offset=' . $this->start;
|
||||
}
|
||||
$request .= $this->count_prefix . (isset($this->size) ? (int)$this->size : 3);
|
||||
$request .= $this->adultPrefix;
|
||||
|
||||
$this->myCurl = new ZAPCurl($this->base_url . $request, false);
|
||||
$this->myCurl->setHeader('X-Subscription-Token', $this->key);
|
||||
$this->myCurl->setHeader('Accept', 'application/json');
|
||||
}
|
||||
|
||||
public function setParam($key, $value) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
|
||||
public function getData() {
|
||||
$return_array = $this->prepareData();
|
||||
return $return_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a project wide universal array with results
|
||||
*/
|
||||
private function prepareData() {
|
||||
$json = $this->myCurl->fetchCurlData();
|
||||
$se_data = json_decode($json, true);
|
||||
|
||||
if (!isset($se_data['results'][0]['properties']['url'])) {
|
||||
$data['result'] = false;
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data['result'] = true;
|
||||
$data['engine'] = __CLASS__;
|
||||
$i = 0;
|
||||
foreach($se_data['results'] as $result) {
|
||||
$data['results'][$i]['clickurl'] = $result['properties']['url'];
|
||||
$data['results'][$i]['referer'] = isset($result['url']) ? $result['url'] : '';
|
||||
$data['results'][$i]['thumb'] = isset($result['thumbnail']['src']) ? $result['thumbnail']['src'] : '';
|
||||
$i++;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
?>
|
||||
25
resource/Search.interface.php
Executable file
25
resource/Search.interface.php
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
/**
|
||||
* Interface for search engine implementations
|
||||
*/
|
||||
interface Search {
|
||||
/**
|
||||
* Set query word to search for
|
||||
* @param string $word
|
||||
*/
|
||||
public function setQuery($word);
|
||||
|
||||
/**
|
||||
* Set additional parameters
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function setParam($key, $value);
|
||||
|
||||
/**
|
||||
* Get received data as array
|
||||
* @return array
|
||||
*/
|
||||
public function getData();
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue