mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-10-31 04:57:47 +09:00
additions to search
This commit is contained in:
26
app/Http/Controllers/SearchController.php
Normal file
26
app/Http/Controllers/SearchController.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Search;
|
||||||
|
|
||||||
|
class SearchController extends Controller
|
||||||
|
{
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
$requestprovider = $request->input('provider');
|
||||||
|
$query = $request->input('q');
|
||||||
|
|
||||||
|
$provider = Search::providerDetails($requestprovider);
|
||||||
|
|
||||||
|
if($provider->type == 'external') {
|
||||||
|
return redirect($provider->url.'?'.$provider->var.'='.urlencode($query));
|
||||||
|
} else {
|
||||||
|
// get results
|
||||||
|
}
|
||||||
|
|
||||||
|
//print_r($provider);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -118,4 +118,10 @@ class SettingsController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function search(Request $request)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ class Item extends Model
|
|||||||
public static function isSearchProvider($class)
|
public static function isSearchProvider($class)
|
||||||
{
|
{
|
||||||
$app = new $class;
|
$app = new $class;
|
||||||
return ((bool)($app instanceof \App\EnhancedApps)) ? $app : false;
|
return ((bool)($app instanceof \App\SearchInterface)) ? $app : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enabled()
|
public function enabled()
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use App\Item;
|
use App\Item;
|
||||||
|
use App\Setting;
|
||||||
|
use Form;
|
||||||
|
use Cache;
|
||||||
|
|
||||||
abstract class Search
|
abstract class Search
|
||||||
{
|
{
|
||||||
@@ -10,8 +13,9 @@ abstract class Search
|
|||||||
public static function providers()
|
public static function providers()
|
||||||
{
|
{
|
||||||
$providers = self::standardProviders();
|
$providers = self::standardProviders();
|
||||||
|
$providers = $providers + self::appProviders();
|
||||||
// Need something to add in none standard providers
|
// Need something to add in none standard providers
|
||||||
|
//die(print_r($providers));
|
||||||
return $providers;
|
return $providers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,20 +32,40 @@ 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',
|
||||||
],
|
],
|
||||||
'ddg' => [
|
'ddg' => [
|
||||||
'url' => 'https://duckduckgo.com/',
|
'url' => 'https://duckduckgo.com/',
|
||||||
'var' => 'q',
|
'var' => 'q',
|
||||||
'method' => 'get',
|
'method' => 'get',
|
||||||
|
'type' => 'external',
|
||||||
],
|
],
|
||||||
'bing' => [
|
'bing' => [
|
||||||
'url' => 'https://www.bing.com/search',
|
'url' => 'https://www.bing.com/search',
|
||||||
'var' => 'q',
|
'var' => 'q',
|
||||||
'method' => 'get',
|
'method' => 'get',
|
||||||
|
'type' => 'external',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function appProviders()
|
||||||
|
{
|
||||||
|
$providers = [];
|
||||||
|
$userapps = Item::all();
|
||||||
|
foreach($userapps as $app) {
|
||||||
|
if(empty($app->class)) continue;
|
||||||
|
if(($provider = Item::isSearchProvider($app->class)) !== false) {
|
||||||
|
$name = Item::nameFromClass($app->class);
|
||||||
|
$providers[strtolower($name)] = [
|
||||||
|
'type' => $provider->type,
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $providers;
|
||||||
|
}
|
||||||
|
|
||||||
public static function storeSearchProvider($class, $app)
|
public static function storeSearchProvider($class, $app)
|
||||||
{
|
{
|
||||||
if(!empty($class)) {
|
if(!empty($class)) {
|
||||||
@@ -52,10 +76,59 @@ abstract class Search
|
|||||||
$search = new $class;
|
$search = new $class;
|
||||||
|
|
||||||
$providers[strtolower($name)] = [
|
$providers[strtolower($name)] = [
|
||||||
'method' => $search->method,
|
'url' => '',
|
||||||
|
'var' => '',
|
||||||
|
'type' => $search->type,
|
||||||
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return html
|
||||||
|
*/
|
||||||
|
public static function form()
|
||||||
|
{
|
||||||
|
$output = '';
|
||||||
|
$homepage_search = Setting::fetch('homepage_search');
|
||||||
|
$search_provider = Setting::where('key', '=', 'search_provider')->first();
|
||||||
|
$user_search_provider = Setting::fetch('search_provider');
|
||||||
|
//die(print_r($search_provider));
|
||||||
|
|
||||||
|
//die(var_dump($user_search_provider));
|
||||||
|
// return early if search isn't applicable
|
||||||
|
if((bool)$homepage_search !== true) return $output;
|
||||||
|
if($user_search_provider === 'none') return $output;
|
||||||
|
if(empty($user_search_provider)) return $output;
|
||||||
|
if(is_null($user_search_provider)) return $output;
|
||||||
|
|
||||||
|
|
||||||
|
if((bool)$homepage_search && (bool)$search_provider) {
|
||||||
|
|
||||||
|
if((bool)$user_search_provider) {
|
||||||
|
$name = 'app.options.'.$user_search_provider;
|
||||||
|
$provider = self::providerDetails($user_search_provider);
|
||||||
|
|
||||||
|
$output .= '<div class="searchform">';
|
||||||
|
$output .= Form::open(['url' => 'search', 'method' => 'get']);
|
||||||
|
$output .= '<div id="search-container" class="input-container">';
|
||||||
|
$output .= '<select name="provider">';
|
||||||
|
foreach(self::providers() as $key => $searchprovider) {
|
||||||
|
$selected = ($key === $user_search_provider) ? ' selected="selected"' : '';
|
||||||
|
$output .= '<option value="'.$key.'"'.$selected.'>'.__('app.options.'.$key).'</option>';
|
||||||
|
}
|
||||||
|
$output .= '</select>';
|
||||||
|
$output .= Form::text('q', null, ['class' => 'homesearch', 'autofocus' => 'autofocus', 'placeholder' => __('app.settings.search').'...']);
|
||||||
|
$output .= '<button type="submit">'.ucwords(__('app.settings.search')).'</button>';
|
||||||
|
$output .= '</div>';
|
||||||
|
$output .= Form::close();
|
||||||
|
$output .= '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -217,43 +217,6 @@ class Setting extends Model
|
|||||||
return array_key_exists($key, Setting::$cache);
|
return array_key_exists($key, Setting::$cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return html
|
|
||||||
*/
|
|
||||||
public static function search()
|
|
||||||
{
|
|
||||||
$output = '';
|
|
||||||
$homepage_search = self::fetch('homepage_search');
|
|
||||||
$search_provider = self::where('key', '=', 'search_provider')->first();
|
|
||||||
$user_search_provider = self::fetch('search_provider');
|
|
||||||
//die(print_r($search_provider));
|
|
||||||
|
|
||||||
//die(var_dump($user_search_provider));
|
|
||||||
// return early if search isn't applicable
|
|
||||||
if((bool)$homepage_search !== true) return $output;
|
|
||||||
if($user_search_provider === 'none') return $output;
|
|
||||||
if(empty($user_search_provider)) return $output;
|
|
||||||
if(is_null($user_search_provider)) return $output;
|
|
||||||
|
|
||||||
|
|
||||||
if((bool)$homepage_search && (bool)$search_provider) {
|
|
||||||
|
|
||||||
if((bool)$user_search_provider) {
|
|
||||||
$name = 'app.options.'.$user_search_provider;
|
|
||||||
$provider = Search::providerDetails($user_search_provider);
|
|
||||||
|
|
||||||
$output .= '<div class="searchform">';
|
|
||||||
$output .= Form::open(['url' => $provider->url, 'method' => $provider->method]);
|
|
||||||
$output .= '<div class="input-container">';
|
|
||||||
$output .= Form::text($provider->var, null, ['class' => 'homesearch', 'autofocus' => 'autofocus', 'placeholder' => __($name).' '.__('app.settings.search').'...']);
|
|
||||||
$output .= '<button type="submit">'.ucwords(__('app.settings.search')).'</button>';
|
|
||||||
$output .= '</div>';
|
|
||||||
$output .= Form::close();
|
|
||||||
$output .= '</div>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The users that belong to the setting.
|
* The users that belong to the setting.
|
||||||
|
|||||||
2
public/css/app.css
vendored
2
public/css/app.css
vendored
File diff suppressed because one or more lines are too long
2
public/mix-manifest.json
generated
2
public/mix-manifest.json
generated
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"/css/app.css": "/css/app.css?id=d346be37404d0fda1d66",
|
"/css/app.css": "/css/app.css?id=550061ee14223568c451",
|
||||||
"/js/app.js": "/js/app.js?id=0db2e72b5cd42d83e306"
|
"/js/app.js": "/js/app.js?id=0db2e72b5cd42d83e306"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -693,7 +693,7 @@ div.create {
|
|||||||
border-bottom: 1px solid rgba(255,255,255,0.35);
|
border-bottom: 1px solid rgba(255,255,255,0.35);
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 500px;
|
max-width: 620px;
|
||||||
form {
|
form {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
@@ -703,6 +703,8 @@ div.create {
|
|||||||
box-shadow: 0px 0px 5px 0 rgba(0,0,0,0.4);
|
box-shadow: 0px 0px 5px 0 rgba(0,0,0,0.4);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
|
||||||
}
|
}
|
||||||
input {
|
input {
|
||||||
padding: 17px 15px;
|
padding: 17px 15px;
|
||||||
@@ -726,6 +728,12 @@ div.create {
|
|||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
background: $app-red;
|
background: $app-red;
|
||||||
}
|
}
|
||||||
|
select {
|
||||||
|
padding: 0 10px;
|
||||||
|
background: #f5f5f5;
|
||||||
|
border: none;
|
||||||
|
border-right: 1px solid #ddd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ui-autocomplete {
|
.ui-autocomplete {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ return [
|
|||||||
'options.startpage' => 'StartPage',
|
'options.startpage' => 'StartPage',
|
||||||
'options.yes' => 'Yes',
|
'options.yes' => 'Yes',
|
||||||
'options.no' => 'No',
|
'options.no' => 'No',
|
||||||
|
'options.nzbhydra' => 'NZBHydra',
|
||||||
|
|
||||||
'buttons.save' => 'Save',
|
'buttons.save' => 'Save',
|
||||||
'buttons.cancel' => 'Cancel',
|
'buttons.cancel' => 'Cancel',
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{!! App\Setting::search() !!}
|
{!! App\Search::form() !!}
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ Route::post('appload', 'ItemController@appload')->name('appload');
|
|||||||
Route::post('test_config', 'ItemController@testConfig')->name('test_config');
|
Route::post('test_config', 'ItemController@testConfig')->name('test_config');
|
||||||
Route::get('/get_stats/{id}', 'ItemController@getStats')->name('get_stats');
|
Route::get('/get_stats/{id}', 'ItemController@getStats')->name('get_stats');
|
||||||
|
|
||||||
|
Route::get('/search', 'SearchController@index')->name('search');
|
||||||
|
|
||||||
Route::get('view/{name_view}', function ($name_view) {
|
Route::get('view/{name_view}', function ($name_view) {
|
||||||
return view('SupportedApps::'.$name_view)->render();
|
return view('SupportedApps::'.$name_view)->render();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user