From 481314cd238e5356003e6faa961213dfce59e257 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 11 Mar 2024 22:42:26 -0600 Subject: [PATCH] Update custom emoji, add config_cache support --- app/Http/Controllers/AdminController.php | 12 ++++++------ app/Models/CustomEmoji.php | 2 +- app/Services/ConfigCacheService.php | 1 + app/Services/CustomEmojiService.php | 4 ++-- resources/views/admin/diagnostics/home.blade.php | 4 ++-- resources/views/auth/register.blade.php | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index e54908a41..102c1a901 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -424,7 +424,7 @@ class AdminController extends Controller public function customEmojiHome(Request $request) { - if(!config('federation.custom_emoji.enabled')) { + if(!(bool) config_cache('federation.custom_emoji.enabled')) { return view('admin.custom-emoji.not-enabled'); } $this->validate($request, [ @@ -497,7 +497,7 @@ class AdminController extends Controller public function customEmojiToggleActive(Request $request, $id) { - abort_unless(config('federation.custom_emoji.enabled'), 404); + abort_unless((bool) config_cache('federation.custom_emoji.enabled'), 404); $emoji = CustomEmoji::findOrFail($id); $emoji->disabled = !$emoji->disabled; $emoji->save(); @@ -508,13 +508,13 @@ class AdminController extends Controller public function customEmojiAdd(Request $request) { - abort_unless(config('federation.custom_emoji.enabled'), 404); + abort_unless((bool) config_cache('federation.custom_emoji.enabled'), 404); return view('admin.custom-emoji.add'); } public function customEmojiStore(Request $request) { - abort_unless(config('federation.custom_emoji.enabled'), 404); + abort_unless((bool) config_cache('federation.custom_emoji.enabled'), 404); $this->validate($request, [ 'shortcode' => [ 'required', @@ -545,7 +545,7 @@ class AdminController extends Controller public function customEmojiDelete(Request $request, $id) { - abort_unless(config('federation.custom_emoji.enabled'), 404); + abort_unless((bool) config_cache('federation.custom_emoji.enabled'), 404); $emoji = CustomEmoji::findOrFail($id); Storage::delete("public/{$emoji->media_path}"); Cache::forget('pf:custom_emoji'); @@ -555,7 +555,7 @@ class AdminController extends Controller public function customEmojiShowDuplicates(Request $request, $id) { - abort_unless(config('federation.custom_emoji.enabled'), 404); + abort_unless((bool) config_cache('federation.custom_emoji.enabled'), 404); $emoji = CustomEmoji::orderBy('id')->whereDisabled(false)->whereShortcode($id)->firstOrFail(); $emojis = CustomEmoji::whereShortcode($id)->where('id', '!=', $emoji->id)->cursorPaginate(10); return view('admin.custom-emoji.duplicates', compact('emoji', 'emojis')); diff --git a/app/Models/CustomEmoji.php b/app/Models/CustomEmoji.php index 1ff026a19..47aa0d1a8 100644 --- a/app/Models/CustomEmoji.php +++ b/app/Models/CustomEmoji.php @@ -18,7 +18,7 @@ class CustomEmoji extends Model public static function scan($text, $activitypub = false) { - if(config('federation.custom_emoji.enabled') == false) { + if((bool) config_cache('federation.custom_emoji.enabled') == false) { return []; } diff --git a/app/Services/ConfigCacheService.php b/app/Services/ConfigCacheService.php index 8205dc3bd..7e60942ca 100644 --- a/app/Services/ConfigCacheService.php +++ b/app/Services/ConfigCacheService.php @@ -97,6 +97,7 @@ class ConfigCacheService 'captcha.active.register', 'captcha.triggers.login.enabled', 'captcha.triggers.login.attempts', + 'federation.custom_emoji.enabled', // 'system.user_mode' ]; diff --git a/app/Services/CustomEmojiService.php b/app/Services/CustomEmojiService.php index a95c93a2a..468772b5f 100644 --- a/app/Services/CustomEmojiService.php +++ b/app/Services/CustomEmojiService.php @@ -13,7 +13,7 @@ class CustomEmojiService { public static function get($shortcode) { - if(config('federation.custom_emoji.enabled') == false) { + if((bool) config_cache('federation.custom_emoji.enabled') == false) { return; } @@ -22,7 +22,7 @@ class CustomEmojiService public static function import($url, $id = false) { - if(config('federation.custom_emoji.enabled') == false) { + if((bool) config_cache('federation.custom_emoji.enabled') == false) { return; } diff --git a/resources/views/admin/diagnostics/home.blade.php b/resources/views/admin/diagnostics/home.blade.php index db44a2332..204f6ce67 100644 --- a/resources/views/admin/diagnostics/home.blade.php +++ b/resources/views/admin/diagnostics/home.blade.php @@ -358,7 +358,7 @@ FEDERATION PF_NETWORK_TIMELINE - {{config_cache('federation.network_timeline') ? '✅ true' : '❌ false' }} + {{(bool) config_cache('federation.network_timeline') ? '✅ true' : '❌ false' }} FEDERATION @@ -368,7 +368,7 @@ FEDERATION CUSTOM_EMOJI - {{config_cache('federation.custom_emoji.enabled') ? '✅ true' : '❌ false' }} + {{(bool) config_cache('federation.custom_emoji.enabled') ? '✅ true' : '❌ false' }} FEDERATION diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index a2c008bd7..3cb70c7fe 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -81,7 +81,7 @@ - @if(config('captcha.enabled') || config('captcha.active.register')) + @if((bool) config_cache('captcha.enabled') && (bool) config_cache('captcha.active.register'))
{!! Captcha::display() !!}