search functionality and settings fixes

This commit is contained in:
Chris
2018-02-05 14:21:54 +00:00
parent ae3d27aca8
commit ba273ffbcf
13 changed files with 314 additions and 39 deletions

View File

@@ -32,6 +32,8 @@ class SettingsController extends Controller
{
$setting = Setting::find($id);
if((bool)$setting->system === true) return abort(404);
if (!is_null($setting)) {
return view('settings.edit')->with([
'setting' => $setting,
@@ -80,4 +82,21 @@ class SettingsController extends Controller
]);
}
}
/**
* @param int $id
*
* @return \Illuminate\Http\RedirectResponse
*/
public function clear($id)
{
$setting = Setting::find($id);
if((bool)$setting->system !== true) {
$setting->value = '';
$setting->save();
}
return redirect()->route('settings.index')->with([
'success' => 'You have successfully edited this Setting!',
]);
}
}

View File

@@ -15,7 +15,9 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
if(!file_exists(database_path(env('DB_DATABASE')))) {
$alt_bg = '';
if(!is_file(database_path(env('DB_DATABASE')))) {
// first time setup
touch(database_path(env('DB_DATABASE')));
Artisan::call('migrate', array('--path' => 'database/migrations', '--force' => true, '--seed' => true));
@@ -24,9 +26,10 @@ class AppServiceProvider extends ServiceProvider
//Artisan::call('config:cache');
//Artisan::call('route:cache');
}
$alt_bg = '';
if($bg_image = Setting::fetch('background_image')) {
$alt_bg = ' style="background-image: url('.asset('storage/'.$bg_image).')"';
if(is_file(database_path(env('DB_DATABASE')))) {
if($bg_image = Setting::fetch('background_image')) {
$alt_bg = ' style="background-image: url('.asset('storage/'.$bg_image).')"';
}
}
view()->share('alt_bg', $alt_bg);

View File

@@ -4,6 +4,7 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Input;
use Form;
class Setting extends Model
{
@@ -39,6 +40,79 @@ class Setting extends Model
];
}
public function getListValueAttribute()
{
switch($this->type) {
case 'image':
if(!empty($this->value)) {
$value = '<a href="'.asset('storage/'.$this->value).'" title="View" target="_blank">View</a>';
} else {
$value = '- not set -';
}
break;
case 'boolean':
if((bool)$this->value === true) {
$value = 'Yes';
} else {
$value = 'No';
}
break;
case 'select':
if(!empty($this->value) || $this->value !== 'none') {
$options = (array)json_decode($this->options);
$value = $options[$this->value];
} else {
$value = '- not set -';
}
break;
default:
$value = $this->value;
break;
}
return $value;
}
public function getEditValueAttribute()
{
switch($this->type) {
case 'image':
$value = '';
if(isset($this->value) && !empty($this->value)) {
$value .= '<a class="setting-view-image" href="'.asset('storage/'.$this->value).'" title="View" target="_blank"><img src="'.asset('storage/'.$this->value).'" /></a>';
}
$value .= Form::file('value', ['class' => 'form-control']);
if(isset($this->value) && !empty($this->value)) {
$value .= '<a class="settinglink" href="'.route('settings.clear', $this->id).'" title="Remove">Reset back to default</a>';
}
break;
case 'boolean':
$checked = false;
if(isset($this->value) && (bool)$this->value === true) $checked = true;
$set_checked = ($checked) ? ' checked="checked"' : '';
$value = '
<label class="switch">
<input type="hidden" name="value" value="0" />
<input type="checkbox" name="value" value="1"'.$set_checked.' />
<span class="slider round"></span>
</label>';
break;
case 'select':
$options = json_decode($this->options);
$value = Form::select('value', $options, null, ['class' => 'form-control']);
break;
default:
$value = Form::text('value', null, ['class' => 'form-control']);
break;
}
return $value;
}
public function group()
{
return $this->belongsTo('App\SettingGroup', 'group_id');
@@ -85,4 +159,42 @@ class Setting extends Model
{
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();
$options = (array)json_decode($search_provider->options);
$name = $options[$search_provider->value];
if((bool)$homepage_search && (bool)$search_provider->value) {
switch($search_provider->value) {
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;
}
$output .= '<div class="searchform">';
$output .= Form::open(['url' => $url, 'method' => 'get']);
$output .= '<div class="input-container">';
$output .= Form::text($var, null, ['class' => 'homesearch', 'placeholder' => $name.' search...']);
$output .= '<button type="submit">Search</button>';
$output .= '</div>';
$output .= Form::close();
$output .= '</div>';
}
return $output;
}
}