mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-11-01 05:27:45 +09:00
Changes to search
This commit is contained in:
@@ -15,10 +15,12 @@ class SearchController extends Controller
|
|||||||
|
|
||||||
$provider = Search::providerDetails($requestprovider);
|
$provider = Search::providerDetails($requestprovider);
|
||||||
|
|
||||||
if($provider->type == 'external') {
|
if($provider->type == 'standard') {
|
||||||
return redirect($provider->url.'?'.$provider->var.'='.urlencode($query));
|
return redirect($provider->url.'?'.$provider->var.'='.urlencode($query));
|
||||||
} else {
|
} elseif($provider->type == 'external') {
|
||||||
// get results
|
$class = new $provider->class;
|
||||||
|
//print_r($provider);
|
||||||
|
return $class->getResults($query, $provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
//print_r($provider);
|
//print_r($provider);
|
||||||
|
|||||||
@@ -10,21 +10,35 @@ use Cache;
|
|||||||
abstract class Search
|
abstract class Search
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of all search providers
|
||||||
|
*
|
||||||
|
* @return Array
|
||||||
|
*/
|
||||||
public static function providers()
|
public static function providers()
|
||||||
{
|
{
|
||||||
$providers = self::standardProviders();
|
$providers = self::standardProviders();
|
||||||
$providers = $providers + self::appProviders();
|
$providers = $providers + self::appProviders();
|
||||||
// Need something to add in none standard providers
|
|
||||||
//die(print_r($providers));
|
|
||||||
return $providers;
|
return $providers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets details for a single provider
|
||||||
|
*
|
||||||
|
* @return Object
|
||||||
|
*/
|
||||||
public static function providerDetails($provider)
|
public static function providerDetails($provider)
|
||||||
{
|
{
|
||||||
$providers = self::providers();
|
$providers = self::providers();
|
||||||
|
if(!isset($providers[$provider])) return false;
|
||||||
return (object)$providers[$provider] ?? false;
|
return (object)$providers[$provider] ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of the standard providers
|
||||||
|
*
|
||||||
|
* @return Array
|
||||||
|
*/
|
||||||
public static function standardProviders()
|
public static function standardProviders()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@@ -32,23 +46,29 @@ abstract class Search
|
|||||||
'url' => 'https://www.google.com/search',
|
'url' => 'https://www.google.com/search',
|
||||||
'var' => 'q',
|
'var' => 'q',
|
||||||
'method' => 'get',
|
'method' => 'get',
|
||||||
'type' => 'external',
|
'type' => 'standard',
|
||||||
],
|
],
|
||||||
'ddg' => [
|
'ddg' => [
|
||||||
'url' => 'https://duckduckgo.com/',
|
'url' => 'https://duckduckgo.com/',
|
||||||
'var' => 'q',
|
'var' => 'q',
|
||||||
'method' => 'get',
|
'method' => 'get',
|
||||||
'type' => 'external',
|
'type' => 'standard',
|
||||||
],
|
],
|
||||||
'bing' => [
|
'bing' => [
|
||||||
'url' => 'https://www.bing.com/search',
|
'url' => 'https://www.bing.com/search',
|
||||||
'var' => 'q',
|
'var' => 'q',
|
||||||
'method' => 'get',
|
'method' => 'get',
|
||||||
'type' => 'external',
|
'type' => 'standard',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loops through users apps to see if app is a search provider, might be worth
|
||||||
|
* looking into caching this at some point
|
||||||
|
*
|
||||||
|
* @return Array
|
||||||
|
*/
|
||||||
public static function appProviders()
|
public static function appProviders()
|
||||||
{
|
{
|
||||||
$providers = [];
|
$providers = [];
|
||||||
@@ -59,6 +79,8 @@ abstract class Search
|
|||||||
$name = Item::nameFromClass($app->class);
|
$name = Item::nameFromClass($app->class);
|
||||||
$providers[strtolower($name)] = [
|
$providers[strtolower($name)] = [
|
||||||
'type' => $provider->type,
|
'type' => $provider->type,
|
||||||
|
'class' => $app->class,
|
||||||
|
'url' => $app->url,
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -66,27 +88,9 @@ abstract class Search
|
|||||||
return $providers;
|
return $providers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function storeSearchProvider($class, $app)
|
/**
|
||||||
{
|
* Outputs the search form
|
||||||
if(!empty($class)) {
|
*
|
||||||
if(($provider = Item::isSearchProvider($class)) !== false) {
|
|
||||||
$providers = Cache::get('search_providers', []);
|
|
||||||
$name = Item::nameFromClass($class);
|
|
||||||
|
|
||||||
$search = new $class;
|
|
||||||
|
|
||||||
$providers[strtolower($name)] = [
|
|
||||||
'url' => '',
|
|
||||||
'var' => '',
|
|
||||||
'type' => $search->type,
|
|
||||||
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return html
|
* @return html
|
||||||
*/
|
*/
|
||||||
public static function form()
|
public static function form()
|
||||||
@@ -100,10 +104,7 @@ abstract class Search
|
|||||||
//die(var_dump($user_search_provider));
|
//die(var_dump($user_search_provider));
|
||||||
// return early if search isn't applicable
|
// return early if search isn't applicable
|
||||||
if((bool)$homepage_search !== true) return $output;
|
if((bool)$homepage_search !== true) return $output;
|
||||||
if($user_search_provider === 'none') return $output;
|
$user_search_provider = $user_search_provider ?? 'none';
|
||||||
if(empty($user_search_provider)) return $output;
|
|
||||||
if(is_null($user_search_provider)) return $output;
|
|
||||||
|
|
||||||
|
|
||||||
if((bool)$homepage_search && (bool)$search_provider) {
|
if((bool)$homepage_search && (bool)$search_provider) {
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ use GuzzleHttp\Client;
|
|||||||
|
|
||||||
interface SearchInterface
|
interface SearchInterface
|
||||||
{
|
{
|
||||||
public function getResults();
|
public function getResults($query, $providerdetails);
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user