Skip to content

Commit f73b78f

Browse files
committed
Add search providers as an editable yaml file + allow searching tiles
1 parent 96ec1e0 commit f73b78f

37 files changed

+7013
-63
lines changed

app/Search.php

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Setting;
77
use Form;
88
use Cache;
9+
use Yaml;
910

1011
abstract class Search
1112
{
@@ -19,7 +20,7 @@ public static function providers()
1920
{
2021
$providers = self::standardProviders();
2122
$providers = $providers + self::appProviders();
22-
return $providers;
23+
return collect($providers);
2324
}
2425

2526
/**
@@ -41,38 +42,16 @@ public static function providerDetails($provider)
4142
*/
4243
public static function standardProviders()
4344
{
44-
return [
45-
'google' => [
46-
'url' => 'https://www.google.com/search',
47-
'var' => 'q',
48-
'method' => 'get',
49-
'type' => 'standard',
50-
],
51-
'ddg' => [
52-
'url' => 'https://duckduckgo.com/',
53-
'var' => 'q',
54-
'method' => 'get',
55-
'type' => 'standard',
56-
],
57-
'bing' => [
58-
'url' => 'https://www.bing.com/search',
59-
'var' => 'q',
60-
'method' => 'get',
61-
'type' => 'standard',
62-
],
63-
'qwant' => [
64-
'url' => 'https://www.qwant.com/',
65-
'var' => 'q',
66-
'method' => 'get',
67-
'type' => 'standard',
68-
],
69-
'startpage' => [
70-
'url' => 'https://www.startpage.com/do/dsearch',
71-
'var' => 'query',
72-
'method' => 'get',
73-
'type' => 'standard',
74-
],
75-
];
45+
// $providers = json_decode(file_get_contents(storage_path('app/searchproviders.json')));
46+
// print_r($providers);
47+
$providers = Yaml::parseFile(storage_path('app/searchproviders.yaml'));
48+
$all = [];
49+
foreach($providers as $key => $provider) {
50+
$all[$key] = $provider;
51+
$all[$key]['type'] = 'standard';
52+
}
53+
54+
return $all;
7655
}
7756

7857
/**
@@ -90,10 +69,11 @@ public static function appProviders()
9069
if(($provider = Item::isSearchProvider($app->class)) !== false) {
9170
$name = Item::nameFromClass($app->class);
9271
$providers[$app->id] = [
72+
'id' => $app->id,
9373
'type' => $provider->type,
9474
'class' => $app->class,
9575
'url' => $app->url,
96-
'title' => $app->title,
76+
'name' => $app->title,
9777
'colour' => $app->colour,
9878
'icon' => $app->icon,
9979
'description' => $app->description
@@ -133,12 +113,8 @@ public static function form()
133113
$output .= '<div id="search-container" class="input-container">';
134114
$output .= '<select name="provider">';
135115
foreach(self::providers() as $key => $searchprovider) {
136-
$selected = ($key === $user_search_provider) ? ' selected="selected"' : '';
137-
if (is_numeric($key)) {
138-
$output .= '<option value="'.$key.'"'.$selected.'>'.$searchprovider['title'].'</option>';
139-
} else {
140-
$output .= '<option value="'.$key.'"'.$selected.'>'.__('app.options.'.$key).'</option>';
141-
}
116+
$selected = ((string)$key === (string)$user_search_provider) ? ' selected="selected"' : '';
117+
$output .= '<option value="'.$key.'"'.$selected.'>'.$searchprovider['name'].'</option>';
142118
}
143119
$output .= '</select>';
144120
$output .= Form::text('q', null, ['class' => 'homesearch', 'autofocus' => 'autofocus', 'placeholder' => __('app.settings.search').'...']);

app/Setting.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public function getListValueAttribute()
7474
case 'select':
7575
if(!empty($this->value) && $this->value !== 'none') {
7676
$options = (array)json_decode($this->options);
77+
if($this->key === 'search_provider') {
78+
$options = Search::providers()->pluck('name', 'id')->toArray();
79+
}
7780
$value = __($options[$this->value]);
7881
} else {
7982
$value = __('app.options.none');
@@ -122,6 +125,9 @@ public function getEditValueAttribute()
122125
break;
123126
case 'select':
124127
$options = json_decode($this->options);
128+
if($this->key === 'search_provider') {
129+
$options = Search::providers()->pluck('name', 'id');
130+
}
125131
foreach($options as $key => $opt) {
126132
$options->$key = __($opt);
127133
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"laravel/framework": "^7.0",
1313
"laravel/tinker": "^2.0",
1414
"laravel/ui": "^2.4",
15-
"laravelcollective/html": "^6.0"
15+
"laravelcollective/html": "^6.0",
16+
"symfony/yaml": "^5.4"
1617
},
1718
"require-dev": {
1819
"filp/whoops": "~2.0",

composer.lock

Lines changed: 78 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@
228228
'URL' => Illuminate\Support\Facades\URL::class,
229229
'Validator' => Illuminate\Support\Facades\Validator::class,
230230
'View' => Illuminate\Support\Facades\View::class,
231+
'Yaml' => Symfony\Component\Yaml\Yaml::class,
231232

232233
'SupportedApps' => App\SupportedApps::class,
233234
'EnhancedApps' => App\EnhancedApps::class,

0 commit comments

Comments
 (0)