Skip to content

Commit

Permalink
Add several new features (#862 #863 #864)
Browse files Browse the repository at this point in the history
- contact page with editable content
- additional footer link
- custom navbar title / logo text
- small optimizations for guest mode
  • Loading branch information
Kovah committed Nov 16, 2024
1 parent bba868d commit 0dccd1a
Show file tree
Hide file tree
Showing 19 changed files with 301 additions and 19 deletions.
6 changes: 5 additions & 1 deletion app/Http/Controllers/Admin/SystemSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ public function update(SystemSettingsUpdateRequest $request): RedirectResponse
public function updateGuest(SystemSettingsUpdateRequest $request): RedirectResponse
{
$guestSettings = app(GuestSettings::class);
$systemSettings = app(SystemSettings::class);

$settings = $request->except(['_token', 'guest_share']);
$systemSettings->guest_access_enabled = $request->input('guest_access_enabled');

$settings = $request->except(['_token', 'guest_share', 'guest_access_enabled']);

foreach ($settings as $key => $value) {
$guestSettings->$key = $value;
Expand All @@ -56,6 +59,7 @@ public function updateGuest(SystemSettingsUpdateRequest $request): RedirectRespo
}
}

$systemSettings->save();
$guestSettings->save();

flash(trans('settings.settings_saved'));
Expand Down
20 changes: 20 additions & 0 deletions app/Http/Controllers/ContactController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Controllers;

use App\Settings\SystemSettings;

class ContactController extends Controller
{
public function __invoke(SystemSettings $systemSettings)
{
if (!$systemSettings->contact_page_enabled) {
abort(404);
}

return view('app.contact', [
'title' => $systemSettings->contact_page_title,
'content' => $systemSettings->contact_page_content,
]);
}
}
2 changes: 2 additions & 0 deletions app/Http/Middleware/SettingsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function handle(Request $request, Closure $next): mixed

if ($userLocale = usersettings('locale')) {
app()->setLocale($userLocale);
} else {
app()->setLocale(guestsettings('locale'));
}

return $next($request);
Expand Down
37 changes: 36 additions & 1 deletion app/Http/Requests/SystemSettingsUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,49 @@ public function rules(): array
return [
'system_page_title' => [
'max:256',
'nullable',
'string',
],
'system_guest_access' => [
'system_logo_text' => [
'max:20',
'nullable',
'string',
],
'additional_footer_link_url' => [
'nullable',
'string',
'required_with:additional_footer_link_text'
],
'additional_footer_link_text' => [
'max:20',
'nullable',
'string',
'required_with:additional_footer_link_url'
],
'contact_page_enabled' => [
'boolean',
],
'contact_page_title' => [
'max:20',
'nullable',
'string',
],
'contact_page_content' => [
'max:10000',
'nullable',
'string',
],
'system_custom_header_content' => [
'nullable',
'string',
],
// Guest settings
'system_guest_access' => [
'boolean',
],
'guest_locale' => [
'string',
],
'guest_listitem_count' => [
'integer',
],
Expand Down
2 changes: 2 additions & 0 deletions app/Settings/GuestSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class GuestSettings extends Settings
public bool $links_new_tab;
public int $darkmode_setting;

public string $locale;

public bool $share_email;
public bool $share_buffer;
public bool $share_evernote;
Expand Down
10 changes: 10 additions & 0 deletions app/Settings/SystemSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@
class SystemSettings extends Settings
{
public ?string $page_title;
public ?string $logo_text;

public ?string $cron_token;

public ?string $custom_header_content;

public ?string $additional_footer_link_url;
public ?string $additional_footer_link_text;

public bool $contact_page_enabled;
public ?string $contact_page_title;
public ?string $contact_page_content;

public bool $guest_access_enabled;
public bool $setup_completed;

Expand Down
1 change: 1 addition & 0 deletions config/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* put them (manually) here.
*/
'settings' => [
\App\Settings\GuestSettings::class,
\App\Settings\SystemSettings::class,
\App\Settings\UserSettings::class,
],
Expand Down
20 changes: 20 additions & 0 deletions database/settings/2024_11_16_092942_extend_system_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Spatie\LaravelSettings\Migrations\SettingsMigration;

Class ExtendSystemSettings extends SettingsMigration

Check notice on line 5 in database/settings/2024_11_16_092942_extend_system_settings.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

database/settings/2024_11_16_092942_extend_system_settings.php#L5

Each class must be in a namespace of at least one level (a top-level vendor name)

Check notice on line 5 in database/settings/2024_11_16_092942_extend_system_settings.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

database/settings/2024_11_16_092942_extend_system_settings.php#L5

PHP keywords must be lowercase; expected "class" but found "Class"
{
public function up(): void
{
$this->migrator->add('system.logo_text', null);

$this->migrator->add('system.additional_footer_link_url', null);
$this->migrator->add('system.additional_footer_link_text', null);

$this->migrator->add('system.contact_page_enabled', false);
$this->migrator->add('system.contact_page_title', null);
$this->migrator->add('system.contact_page_content', null);

$this->migrator->add('guest.locale', config('app.fallback_locale'));
}
}
1 change: 1 addition & 0 deletions lang/en_US/linkace.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
'menu' => 'Menu',
'entries' => 'Entries',
'feed' => 'Feed',
'contact' => 'Contact',

'continue_adding' => 'Continue Adding',

Expand Down
11 changes: 11 additions & 0 deletions lang/en_US/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,22 @@
'two_factor_regenerate_recovery_codes' => 'Generate new Recovery Codes',

'page_title' => 'Page Title',
'logo_text' => 'Custom Logo Text',
'guest_access' => 'Enable Guest Access',
'guest_access_help' => 'If enabled, guest will be able to see all links that are not private.',
'custom_header_content' => 'Custom Header Content',
'custom_header_content_help' => 'Content entered here will be placed before the &lt;/head&gt; tag on all LinkAce sites. Useful to place analytics or customization scripts. Caution: contents are not escaped and may break the site!',

'additional_footer_link' => 'Additional Link in the Footer',
'additional_footer_link_url' => 'Link URL',
'additional_footer_link_text' => 'Link Text',

'contact_page' => 'Contact/About Page',
'contact_page_info' => 'The contact/about page can be used to display additional information about your bookmarks. The link is visible in the footer. Markdown is supported.',
'contact_page_enabled' => 'Enable the contact/about page',
'contact_page_title' => 'Custom title for the page',
'contact_page_content' => 'Content of the page',

'cron_token' => 'Cron Token',
'cron_token_generate' => 'Generate Token',
'cron_token_generate_confirm' => 'Do you really want to generate a new token?',
Expand Down
4 changes: 4 additions & 0 deletions resources/assets/sass/custom/_app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ body:not(.bookmarklet) {
}
}

.navbar-brand {
font-family: $font-family-sans-condensed;
}

.card-table {
margin: -#{$card-border-width};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,137 @@
<div class="col-12 col-sm-8 col-md-6">

<div class="mb-4">
<label class="form-label" for="guest_access_enabled">
@lang('settings.guest_access')
<label class="form-label" for="logo_text">
@lang('settings.logo_text')
</label>
<select id="guest_access_enabled" name="guest_access_enabled"
class="simple-select {{ $errors->has('guest_access_enabled') ? ' is-invalid' : '' }}">
<x-forms.yes-no-options :setting="systemsettings('guest_access_enabled')"/>
<input type="text" id="logo_text" name="logo_text" class="form-control" maxlength="20"
value="{{ old('logo_text') ?: systemsettings('logo_text') }}">
@if ($errors->has('logo_text'))
<p class="invalid-feedback mt-1" role="alert">
{{ $errors->first('logo_text') }}
</p>
@endif
</div>

</div>
</div>

<div class="row my-4">
<div class="col-12"><h5>@lang('settings.additional_footer_link')</h5></div>
<div class="col-12 col-sm-8 col-md-6">

<div class="mb-4">
<label class="form-label" for="additional_footer_link_url">
@lang('settings.additional_footer_link_url')
</label>
<input type="url" id="additional_footer_link_url" name="additional_footer_link_url"
class="form-control"
value="{{ old('additional_footer_link_url') ?: systemsettings('additional_footer_link_url') }}">
@if ($errors->has('additional_footer_link_url'))
<p class="invalid-feedback mt-1" role="alert">
{{ $errors->first('additional_footer_link_url') }}
</p>
@endif
</div>

</div>
<div class="col-12 col-sm-8 col-md-6">

<div class="mb-4">
<label class="form-label" for="additional_footer_link_text">
@lang('settings.additional_footer_link_text')
</label>
<input type="text" id="additional_footer_link_text" name="additional_footer_link_text"
class="form-control" maxlength="20"
value="{{ old('additional_footer_link_text') ?: systemsettings('additional_footer_link_text') }}">
@if ($errors->has('additional_footer_link_text'))
<p class="invalid-feedback mt-1" role="alert">
{{ $errors->first('additional_footer_link_text') }}
</p>
@endif
</div>

</div>
</div>

<div class="row my-4">
<div class="col-12">
<h5>@lang('settings.contact_page')</h5>
<p class="my-3 small">@lang('settings.contact_page_info')</p>
</div>
<div class="col-12 col-sm-8 col-md-6">

<div class="mb-4">
<label class="form-label" for="contact_page_enabled">
@lang('settings.contact_page_enabled')
</label>
<select id="contact_page_enabled" name="contact_page_enabled"
class="simple-select {{ $errors->has('contact_page_enabled') ? ' is-invalid' : '' }}">
<x-forms.yes-no-options :setting="systemsettings('contact_page_enabled')"/>
</select>
<p class="small text-pale mt-1">@lang('settings.guest_access_help')</p>
@if ($errors->has('guest_access_enabled'))
@if ($errors->has('contact_page_enabled'))
<p class="invalid-feedback" role="alert">
{{ $errors->first('guest_access_enabled') }}
{{ $errors->first('contact_page_enabled') }}
</p>
@endif
</div>

</div>
<div class="col-12 col-sm-8 col-md-6">

<div class="mb-4">
<label class="form-label" for="contact_page_title">
@lang('settings.contact_page_title')
</label>
<input type="text" id="contact_page_title" name="contact_page_title"
class="form-control" maxlength="20"
value="{{ old('contact_page_title') ?: systemsettings('contact_page_title') }}">
@if ($errors->has('contact_page_title'))
<p class="invalid-feedback mt-1" role="alert">
{{ $errors->first('contact_page_title') }}
</p>
@endif
</div>

</div>
<div class="col-12">

<div class="mb-4">
<label class="form-label" for="contact_page_content">
@lang('settings.contact_page_content')
</label>
<textarea name="contact_page_content" id="contact_page_content" rows="4"
class="form-control{{ $errors->has('contact_page_content') ? ' is-invalid' : '' }}"
>{{ old('contact_page_content', systemsettings('contact_page_content')) }}</textarea>
@error('contact_page_content')
<p class="invalid-feedback" role="alert">
{{ $errors->first('contact_page_content') }}
</p>
@enderror
</div>

</div>
</div>

<div class="row">
<div class="col-12 col-sm-8 col-md-6">

<div class="mb-4">
<label class="form-label" for="custom_header_content">
@lang('settings.custom_header_content')
</label>

<textarea name="custom_header_content" id="custom_header_content" rows="4"
class="form-control{{ $errors->has('custom_header_content') ? ' is-invalid' : '' }}"
>{{ old('custom_header_content', systemsettings('custom_header_content')) }}</textarea>
<p class="small text-pale mt-1">@lang('settings.custom_header_content_help')</p>

@error('custom_header_content')
<p class="invalid-feedback" role="alert">
{{ $errors->first('custom_header_content') }}
</p>
@enderror
</div>

</div>
</div>

Expand Down
Loading

0 comments on commit 0dccd1a

Please sign in to comment.