64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
if (!defined('_CAN_LOAD_FILES_'))
|
|
exit;
|
|
|
|
require 'lib/doofinder_api.php';
|
|
|
|
class Antadis_Doofinder extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'antadis_doofinder';
|
|
$this->tab = 'front_office_features';
|
|
$this->version = '1.0';
|
|
$this->author = 'Antadis';
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Antadis Doofinder');
|
|
$this->description = $this->l('Search on doofinder');
|
|
|
|
$this->confirmUninstall = $this->l('Are you sure ?');
|
|
|
|
$this->hash = '8483db4a599703a6e069ad2ecf59e17d';
|
|
$this->api_key = 'eu1-cd36e2fd8bc321bce51d34ddf758c5dfa0e37150';
|
|
}
|
|
|
|
public function install(){
|
|
if ( !parent::install() || !$this->registerHook('header')){
|
|
$this->uninstall();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function uninstall(){
|
|
if( !parent::uninstall()){
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function hookHeader($params)
|
|
{
|
|
$this->context->controller->addJS(($this->_path) . 'js/search.js');
|
|
}
|
|
|
|
public function ajaxSearch($input = false)
|
|
{
|
|
if (empty($input) || !$input) {
|
|
// http_response_code(500);
|
|
return false;
|
|
}
|
|
|
|
$df = new DoofinderApi($this->hash, $this->api_key);
|
|
$output = $df->query($input, 1, array('rpp' => 100, 'sort' => array(array('_score' => 'desc') )) );
|
|
|
|
return array(
|
|
'results' => $output->getResults()
|
|
);
|
|
}
|
|
}
|