Merge pull request #5193 from pixelfed/staging

Add custom css to admin dashboard
This commit is contained in:
daniel 2024-06-29 18:39:57 -06:00 committed by GitHub
commit 054e24835d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 569 additions and 495 deletions

View file

@ -2,57 +2,45 @@
namespace App\Http\Controllers;
use App\{
AccountInterstitial,
Contact,
Hashtag,
Instance,
Newsroom,
OauthClient,
Profile,
Report,
Status,
StatusHashtag,
Story,
User
};
use DB, Cache, Storage;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;
use App\Http\Controllers\Admin\{
AdminAutospamController,
AdminDirectoryController,
AdminDiscoverController,
AdminHashtagsController,
AdminInstanceController,
AdminReportController,
// AdminGroupsController,
AdminMediaController,
AdminSettingsController,
// AdminStorageController,
AdminSupportController,
AdminUserController
};
use Illuminate\Validation\Rule;
use App\Services\AdminStatsService;
use App\Contact;
use App\Http\Controllers\Admin\AdminAutospamController;
use App\Http\Controllers\Admin\AdminDirectoryController;
use App\Http\Controllers\Admin\AdminDiscoverController;
use App\Http\Controllers\Admin\AdminHashtagsController;
use App\Http\Controllers\Admin\AdminInstanceController;
use App\Http\Controllers\Admin\AdminMediaController;
use App\Http\Controllers\Admin\AdminReportController;
use App\Http\Controllers\Admin\AdminSettingsController;
use App\Http\Controllers\Admin\AdminUserController;
use App\Instance;
use App\Models\CustomEmoji;
use App\Newsroom;
use App\OauthClient;
use App\Profile;
use App\Services\AccountService;
use App\Services\AdminStatsService;
use App\Services\ConfigCacheService;
use App\Services\StatusService;
use App\Services\StoryService;
use App\Models\CustomEmoji;
use App\Status;
use App\Story;
use App\User;
use Cache;
use DB;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Storage;
class AdminController extends Controller
{
use AdminReportController,
AdminAutospamController,
use AdminAutospamController,
AdminDirectoryController,
AdminDiscoverController,
AdminHashtagsController,
// AdminGroupsController,
AdminMediaController,
AdminSettingsController,
AdminInstanceController,
// AdminStorageController,
AdminMediaController,
AdminReportController,
AdminSettingsController,
AdminUserController;
public function __construct()
@ -67,9 +55,27 @@ class AdminController extends Controller
return view('admin.home');
}
public function customCss()
{
return view('admin.settings.customcss');
}
public function saveCustomCss(Request $request)
{
$this->validate($request, [
'css' => 'sometimes|max:5000',
'show' => 'sometimes',
]);
ConfigCacheService::put('uikit.custom.css', $request->input('css'));
ConfigCacheService::put('uikit.show_custom.css', $request->boolean('show'));
return view('admin.settings.customcss');
}
public function stats()
{
$data = AdminStatsService::get();
return view('admin.stats', compact('data'));
}
@ -83,25 +89,27 @@ class AdminController extends Controller
$users = User::orderByDesc('id')->cursorPaginate(10);
$res = [
"next_page_url" => $users->nextPageUrl(),
"data" => $users->map(function($user) {
'next_page_url' => $users->nextPageUrl(),
'data' => $users->map(function ($user) {
$account = AccountService::get($user->profile_id, true);
if (! $account) {
return [
"id" => $user->profile_id,
"username" => $user->username,
"status" => "deleted",
"avatar" => "/storage/avatars/default.jpg",
"created_at" => $user->created_at
'id' => $user->profile_id,
'username' => $user->username,
'status' => 'deleted',
'avatar' => '/storage/avatars/default.jpg',
'created_at' => $user->created_at,
];
}
$account['user_id'] = $user->id;
return $account;
})
->filter(function ($user) {
return $user;
})
}),
];
return $res;
}
@ -112,14 +120,15 @@ class AdminController extends Controller
->cursorPaginate(10);
$res = [
"next_page_url" => $posts->nextPageUrl(),
"data" => $posts->map(function($post) {
'next_page_url' => $posts->nextPageUrl(),
'data' => $posts->map(function ($post) {
$status = StatusService::get($post->id, false);
if (! $status) {
return ["id" => $post->id, "created_at" => $post->created_at];
return ['id' => $post->id, 'created_at' => $post->created_at];
}
return $status;
})
}),
];
return $res;
@ -140,6 +149,7 @@ class AdminController extends Controller
return $s;
})
->toArray();
return view('admin.statuses.home', compact('statuses', 'data'));
}
@ -157,8 +167,8 @@ class AdminController extends Controller
'filter' => [
'nullable',
'string',
Rule::in(['all', 'local', 'remote'])
]
Rule::in(['all', 'local', 'remote']),
],
]);
$search = $request->input('search');
$filter = $request->input('filter');
@ -174,6 +184,7 @@ class AdminController extends Controller
if ($filter == 'remote') {
return $q->whereNotNull('domain');
}
return $q;
})->orderByDesc('id')
->simplePaginate($limit);
@ -185,6 +196,7 @@ class AdminController extends Controller
{
$profile = Profile::findOrFail($id);
$user = $profile->user;
return view('admin.profiles.edit', compact('profile', 'user'));
}
@ -203,25 +215,28 @@ class AdminController extends Controller
->orderByDesc('id')
->paginate(10);
}
return view('admin.apps.home', compact('apps'));
}
public function messagesHome(Request $request)
{
$messages = Contact::orderByDesc('id')->paginate(10);
return view('admin.messages.home', compact('messages'));
}
public function messagesShow(Request $request, $id)
{
$message = Contact::findOrFail($id);
return view('admin.messages.show', compact('message'));
}
public function messagesMarkRead(Request $request)
{
$this->validate($request, [
'id' => 'required|integer|min:1'
'id' => 'required|integer|min:1',
]);
$id = $request->input('id');
$message = Contact::findOrFail($id);
@ -230,12 +245,13 @@ class AdminController extends Controller
}
$message->read_at = now();
$message->save();
return;
}
public function newsroomHome(Request $request)
{
$newsroom = Newsroom::latest()->paginate(10);
return view('admin.newsroom.home', compact('newsroom'));
}
@ -247,6 +263,7 @@ class AdminController extends Controller
public function newsroomEdit(Request $request, $id)
{
$news = Newsroom::findOrFail($id);
return view('admin.newsroom.edit', compact('news'));
}
@ -254,6 +271,7 @@ class AdminController extends Controller
{
$news = Newsroom::findOrFail($id);
$news->delete();
return redirect('/i/admin/newsroom');
}
@ -262,7 +280,7 @@ class AdminController extends Controller
$this->validate($request, [
'title' => 'required|string|min:1|max:100',
'summary' => 'nullable|string|max:200',
'body' => 'nullable|string'
'body' => 'nullable|string',
]);
$changed = false;
$changedFields = [];
@ -280,7 +298,7 @@ class AdminController extends Controller
'auth_only' => 'boolean',
'show_link' => 'boolean',
'force_modal' => 'boolean',
'published' => 'published'
'published' => 'published',
];
foreach ($fields as $field => $type) {
switch ($type) {
@ -320,16 +338,16 @@ class AdminController extends Controller
$news->save();
}
$redirect = $news->published_at ? $news->permalink() : $news->editUrl();
return redirect($redirect);
}
public function newsroomStore(Request $request)
{
$this->validate($request, [
'title' => 'required|string|min:1|max:100',
'summary' => 'nullable|string|max:200',
'body' => 'nullable|string'
'body' => 'nullable|string',
]);
$changed = false;
$changedFields = [];
@ -347,7 +365,7 @@ class AdminController extends Controller
'auth_only' => 'boolean',
'show_link' => 'boolean',
'force_modal' => 'boolean',
'published' => 'published'
'published' => 'published',
];
foreach ($fields as $field => $type) {
switch ($type) {
@ -387,6 +405,7 @@ class AdminController extends Controller
$news->save();
}
$redirect = $news->published_at ? $news->permalink() : $news->editUrl();
return redirect($redirect);
}
@ -398,7 +417,7 @@ class AdminController extends Controller
public function diagnosticsDecrypt(Request $request)
{
$this->validate($request, [
'payload' => 'required'
'payload' => 'required',
]);
$key = 'exception_report:';
@ -409,7 +428,7 @@ class AdminController extends Controller
}
$res = [
'decrypted' => substr($decrypted, strlen($key))
'decrypted' => substr($decrypted, strlen($key)),
];
return response()->json($res);
@ -419,6 +438,7 @@ class AdminController extends Controller
{
$stories = Story::with('profile')->latest()->paginate(10);
$stats = StoryService::adminStats();
return view('admin.stories.home', compact('stories', 'stats'));
}
@ -428,12 +448,13 @@ class AdminController extends Controller
return view('admin.custom-emoji.not-enabled');
}
$this->validate($request, [
'sort' => 'sometimes|in:all,local,remote,duplicates,disabled,search'
'sort' => 'sometimes|in:all,local,remote,duplicates,disabled,search',
]);
if ($request->has('cc')) {
Cache::forget('pf:admin:custom_emoji:stats');
Cache::forget('pf:custom_emoji');
return redirect(route('admin.custom-emoji'));
}
@ -470,6 +491,7 @@ class AdminController extends Controller
$q = $q->groupBy('shortcode');
}
}
return $q;
}
})
@ -503,12 +525,14 @@ class AdminController extends Controller
$emoji->save();
$key = CustomEmoji::CACHE_KEY.str_replace(':', '', $emoji->shortcode);
Cache::forget($key);
return redirect()->back();
}
public function customEmojiAdd(Request $request)
{
abort_unless((bool) config_cache('federation.custom_emoji.enabled'), 404);
return view('admin.custom-emoji.add');
}
@ -525,9 +549,9 @@ class AdminController extends Controller
Rule::unique('custom_emoji')->where(function ($query) use ($request) {
return $query->whereDomain(config('pixelfed.domain.app'))
->whereShortcode($request->input('shortcode'));
})
}),
],
'emoji' => 'required|file|mimes:jpg,png|max:' . (config('federation.custom_emoji.max_size') / 1000)
'emoji' => 'required|file|mimes:jpg,png|max:'.(config('federation.custom_emoji.max_size') / 1000),
]);
$emoji = new CustomEmoji;
@ -540,6 +564,7 @@ class AdminController extends Controller
$emoji->media_path = 'emoji/'.$fileName;
$emoji->save();
Cache::forget('pf:custom_emoji');
return redirect(route('admin.custom-emoji'));
}
@ -550,6 +575,7 @@ class AdminController extends Controller
Storage::delete("public/{$emoji->media_path}");
Cache::forget('pf:custom_emoji');
$emoji->delete();
return redirect(route('admin.custom-emoji'));
}
@ -558,6 +584,7 @@ class AdminController extends Controller
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'));
}
}

View file

@ -0,0 +1,45 @@
@extends('admin.partial.template-full')
@section('section')
</div>
<div class="header bg-primary pb-3 mt-n4">
<div class="container-fluid">
<div class="header-body">
<div class="row align-items-center py-4">
<div class="col-lg-6 col-7">
<p class="display-1 text-white d-inline-block mb-0">Custom CSS</p>
<p class="lead mb-0 text-white">Customize your instance with custom css.</p>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid mt-4">
<div class="col-12 col-md-6">
<form method="post">
@csrf
<div class="form-group">
<div class="custom-control custom-checkbox">
<input
type="checkbox"
name="show"
class="custom-control-input"
id="customCheck1"
{{ (bool) config_cache('uikit.show_custom.css') ? 'checked' : null}}
>
<label class="custom-control-label" for="customCheck1">Enable Custom CSS</label>
</div>
</div>
<div class="form-group">
<label for="css" class="font-weight-bold">Custom CSS</label>
<textarea
class="form-control"
id="css"
name="css"
rows="5">{!!config_cache('uikit.custom.css')!!}</textarea>
</div>
<button class="btn btn-primary">Save</button>
</form>
</div>
</div>
@endsection

View file

@ -3,6 +3,8 @@
Route::domain(config('pixelfed.domain.admin'))->prefix('i/admin')->group(function () {
Route::redirect('/', '/dashboard');
Route::redirect('timeline', config('app.url').'/timeline');
Route::get('settings/custom-css', 'AdminController@customCss')->name('admin.custom-css');
Route::post('settings/custom-css', 'AdminController@saveCustomCss');
Route::get('dashboard', 'AdminController@home')->name('admin.home');
Route::get('stats', 'AdminController@stats')->name('admin.stats');
Route::get('reports', 'AdminController@reports')->name('admin.reports');