diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index abdcd9a7..e5d9175f 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -12,6 +12,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; use App\SupportedApps; use App\Jobs\ProcessApps; +use App\Search; class ItemController extends Controller { @@ -168,6 +169,8 @@ class ItemController extends Controller $item = Item::create($request->all()); + Search::storeSearchProvider($request->input('class'), $item); + $item->parents()->sync($request->tags); $route = route('dash', [], false); @@ -241,6 +244,8 @@ class ItemController extends Controller $item = Item::find($id); $item->update($request->all()); + Search::storeSearchProvider($request->input('class'), $item); + $item->parents()->sync($request->tags); $route = route('dash', [], false); diff --git a/app/Item.php b/app/Item.php index 69953e16..10f00045 100644 --- a/app/Item.php +++ b/app/Item.php @@ -163,6 +163,12 @@ class Item extends Model return (bool)($app instanceof \App\EnhancedApps); } + public static function isSearchProvider($class) + { + $app = new $class; + return ((bool)($app instanceof \App\EnhancedApps)) ? $app : false; + } + public function enabled() { if($this->enhanced()) { diff --git a/app/Search.php b/app/Search.php new file mode 100644 index 00000000..babccaa3 --- /dev/null +++ b/app/Search.php @@ -0,0 +1,61 @@ + [ + 'url' => 'https://www.google.com/search', + 'var' => 'q', + 'method' => 'get', + ], + 'ddg' => [ + 'url' => 'https://duckduckgo.com/', + 'var' => 'q', + 'method' => 'get', + ], + 'bing' => [ + 'url' => 'https://www.bing.com/search', + 'var' => 'q', + 'method' => 'get', + ], + ]; + } + + public static function storeSearchProvider($class, $app) + { + if(!empty($class)) { + if(($provider = Item::isSearchProvider($class)) !== false) { + $providers = Cache::get('search_providers', []); + $name = Item::nameFromClass($class); + + $search = new $class; + + $providers[strtolower($name)] = [ + 'method' => $search->method; + ]; + } + } + } + +} \ No newline at end of file diff --git a/app/SearchInterface.php b/app/SearchInterface.php new file mode 100644 index 00000000..5ea3b5fd --- /dev/null +++ b/app/SearchInterface.php @@ -0,0 +1,10 @@ +options); - $name = $options[$user_search_provider]; if((bool)$user_search_provider) { - switch($user_search_provider) { - case 'google': - $url = 'https://www.google.com/search'; - $var = 'q'; - break; - case 'ddg': - $url = 'https://duckduckgo.com/'; - $var = 'q'; - break; - case 'bing': - $url = 'https://www.bing.com/search'; - $var = 'q'; - break; - case 'startpage': - $url = 'https://www.startpage.com/'; - $var = 'q'; - } + $name = 'app.options.'.$user_search_provider; + $provider = Search::providerDetails($user_search_provider); + $output .= '
'; - $output .= Form::open(['url' => $url, 'method' => 'get']); + $output .= Form::open(['url' => $provider->url, 'method' => $provider->method]); $output .= '
'; - $output .= Form::text($var, null, ['class' => 'homesearch', 'autofocus' => 'autofocus', 'placeholder' => __($name).' '.__('app.settings.search').'...']); + $output .= Form::text($provider->var, null, ['class' => 'homesearch', 'autofocus' => 'autofocus', 'placeholder' => __($name).' '.__('app.settings.search').'...']); $output .= ''; $output .= '
'; $output .= Form::close();