A lot of things.
This commit is contained in:
@@ -74,4 +74,9 @@ class XenForoGuard implements Guard
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function logout(): void
|
||||
{
|
||||
redirect('/');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,10 +4,13 @@ namespace App\Auth;
|
||||
|
||||
use App\Services\XenforoService;
|
||||
use App\XenForoDataTypes\XenForoData;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Models\Contracts\HasName;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Contracts\Auth\Access\Authorizable;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
class XenForoUser extends XenForoData implements Authenticatable, Authorizable {
|
||||
class XenForoUser extends XenForoData implements Authenticatable, Authorizable, FilamentUser, HasName {
|
||||
|
||||
use \Illuminate\Foundation\Auth\Access\Authorizable;
|
||||
|
||||
@@ -75,4 +78,31 @@ class XenForoUser extends XenForoData implements Authenticatable, Authorizable {
|
||||
|
||||
return ($this->permissions[$permissionGroup][$permissionName] ?? 0) === true;
|
||||
}
|
||||
|
||||
/* FILAMENT COMPATIBILITY */
|
||||
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
return $this->is_admin === 1;
|
||||
}
|
||||
|
||||
public function getFilamentName(): string
|
||||
{
|
||||
return $this->username ?? "XF";
|
||||
}
|
||||
|
||||
public function getAttributeValue($key)
|
||||
{
|
||||
return $this->{$key} ?? null;
|
||||
}
|
||||
|
||||
public function getKey()
|
||||
{
|
||||
return $this->data->user_id;
|
||||
}
|
||||
|
||||
public function getKeyName()
|
||||
{
|
||||
return 'user_id';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ class EntryHelpers {
|
||||
*/
|
||||
public static function buildCompleteTitle( string $section, array $fields = [] ){
|
||||
|
||||
$fields = array_merge( ['entry_title' => 'Untitled', 'game_name' => '', 'languages_string' => '', 'platform_name' => ''], $fields );
|
||||
|
||||
return match ($section) {
|
||||
'translations' => sprintf('%s (%s Translation) %s', $fields['entry_title'] ?? $fields['game_name'], $fields['languages_string'], $fields['platform_name']),
|
||||
'romhacks' => sprintf('%s (%s) Romhack', $fields['entry_title'], $fields['platform_name']),
|
||||
|
||||
@@ -22,6 +22,7 @@ class DynamicLoadController extends Controller
|
||||
}
|
||||
|
||||
return [
|
||||
'user_id' => $user_id,
|
||||
'username' => $user->username,
|
||||
'avatar_url' => $user->getAvatarUrl(),
|
||||
'avatar_color' => XenForoHelpers::getAvatarColor( $user ),
|
||||
|
||||
@@ -18,6 +18,11 @@ class EntryController extends Controller
|
||||
return view('entries.index');
|
||||
}
|
||||
|
||||
public function section_redirect(string $section)
|
||||
{
|
||||
return redirect( databaseRoute( ['types' => [ $section ] ] ) );
|
||||
}
|
||||
|
||||
public function show(string $section, Entry $entry): View
|
||||
{
|
||||
if (!in_array($section, self::SECTION_TYPES))
|
||||
@@ -48,4 +53,15 @@ class EntryController extends Controller
|
||||
|
||||
}
|
||||
|
||||
public function drafts(): View
|
||||
{
|
||||
$drafts = Entry::where('user_id', \Auth::user()->user_id )
|
||||
->where('state', 'draft')
|
||||
->with('game.platform', 'status')
|
||||
->orderBy('updated_at', 'desc')
|
||||
->paginate(20);
|
||||
|
||||
return view('entries.drafts', compact('drafts'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
72
app/Http/Controllers/ModCP/AuthorController.php
Normal file
72
app/Http/Controllers/ModCP/AuthorController.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ModCP;
|
||||
|
||||
use App\Helpers\EntryHelpers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Author;
|
||||
use App\Models\Language;
|
||||
use App\Rules\XfUserExists;
|
||||
use App\Traits\ModCPSearch;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AuthorController extends Controller
|
||||
{
|
||||
|
||||
use ModCPSearch;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$items = Author::withCount('entries')
|
||||
->orderBy('name')
|
||||
->tap(fn($query) => $this->applySearch($query, ['name']))
|
||||
->paginate(30)
|
||||
->withQueryString();
|
||||
|
||||
return view('modcp.authors', [
|
||||
'items' => $items
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255|unique:authors,name',
|
||||
'owner_user_id' => [ 'nullable', 'integer', new XfUserExists ],
|
||||
'website' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
Author::create([
|
||||
'name' => trim( $request->name ),
|
||||
'slug' => EntryHelpers::uniqueSlug( $request->name, Author::class ),
|
||||
'user_id' => $request->owner_user_id,
|
||||
'website' => $request->website,
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Author added.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Author $author)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255|unique:authors,name,' . $author->id,
|
||||
'owner_user_id' => [ 'nullable', 'integer', new XfUserExists ],
|
||||
'website' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
$author->update([
|
||||
'name' => trim($request->name),
|
||||
'slug' => EntryHelpers::uniqueSlug( $request->name, Author::class, $author->id ),
|
||||
'user_id' => $request->owner_user_id,
|
||||
'website' => $request->website,
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Author updated.');
|
||||
}
|
||||
|
||||
public function destroy(Author $author)
|
||||
{
|
||||
$author->delete();
|
||||
return back()->with('success', 'Author deleted.');
|
||||
}
|
||||
}
|
||||
75
app/Http/Controllers/ModCP/GameController.php
Normal file
75
app/Http/Controllers/ModCP/GameController.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ModCP;
|
||||
|
||||
use App\Helpers\EntryHelpers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Game;
|
||||
use App\Models\Genre;
|
||||
use App\Models\Platform;
|
||||
use App\Traits\ModCPSearch;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GameController extends Controller
|
||||
{
|
||||
|
||||
use ModCPSearch;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$items = Game::withCount('entries')->orderBy('name')
|
||||
->tap(fn($query) => $this->applySearch($query, ['name']))
|
||||
->paginate(30)->withQueryString();
|
||||
$platforms = Platform::orderBy('name')->get();
|
||||
$genres = Genre::orderBy('name')->get();
|
||||
|
||||
return view('modcp.games', [
|
||||
'items' => $items,
|
||||
'platforms' => $platforms,
|
||||
'genres' => $genres,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'platform_id' => 'required|integer|exists:platforms,id',
|
||||
'genre_id' => 'required|integer|exists:genres,id',
|
||||
]);
|
||||
|
||||
Game::create([
|
||||
'name' => trim($request->name),
|
||||
'platform_id' => $request->platform_id,
|
||||
'genre_id' => $request->genre_id,
|
||||
'slug' => EntryHelpers::uniqueSlug($request->name, Game::class),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Game added.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Game $game)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'platform_id' => 'required|integer|exists:platforms,id',
|
||||
'genre_id' => 'required|integer|exists:genres,id'
|
||||
]);
|
||||
|
||||
$game->update([
|
||||
'name' => trim($request->name),
|
||||
'platform_id' => $request->platform_id,
|
||||
'genre_id' => $request->genre_id,
|
||||
'slug' => EntryHelpers::uniqueSlug($request->name, Game::class, $game->id),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Game updated.');
|
||||
}
|
||||
|
||||
public function destroy(Game $game)
|
||||
{
|
||||
$game->delete();
|
||||
return back()->with('success', 'Game deleted.');
|
||||
}
|
||||
}
|
||||
68
app/Http/Controllers/ModCP/GenreController.php
Normal file
68
app/Http/Controllers/ModCP/GenreController.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ModCP;
|
||||
|
||||
use App\Helpers\EntryHelpers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Genre;
|
||||
use App\Models\Language;
|
||||
use App\Traits\ModCPSearch;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GenreController extends Controller
|
||||
{
|
||||
|
||||
use ModCPSearch;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$items = Genre::withCount('games')
|
||||
->orderBy('name')
|
||||
->tap(fn($query) => $this->applySearch($query, ['name']))
|
||||
->paginate(30)
|
||||
->withQueryString();
|
||||
|
||||
return view('modcp.resources', [
|
||||
'items' => $items,
|
||||
'title' => 'Genres',
|
||||
'singular' => 'Genre',
|
||||
'storeRoute' => 'modcp.genres.store',
|
||||
'updateRoute' => 'modcp.genres.update',
|
||||
'destroyRoute' => 'modcp.genres.destroy'
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255|unique:genres,name',
|
||||
]);
|
||||
|
||||
Genre::create([
|
||||
'name' => trim($request->name),
|
||||
'slug' => EntryHelpers::uniqueSlug( $request->name, Genre::class ),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Genre added.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Genre $genre)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255|unique:genres,name,' . $genre->id,
|
||||
]);
|
||||
|
||||
$genre->update([
|
||||
'name' => trim($request->name),
|
||||
'slug' => EntryHelpers::uniqueSlug( $request->name, Genre::class, $genre->id ),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Genre updated.');
|
||||
}
|
||||
|
||||
public function destroy(Genre $genre)
|
||||
{
|
||||
$genre->delete();
|
||||
return back()->with('success', 'Genre deleted.');
|
||||
}
|
||||
}
|
||||
67
app/Http/Controllers/ModCP/LanguageController.php
Normal file
67
app/Http/Controllers/ModCP/LanguageController.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ModCP;
|
||||
|
||||
use App\Helpers\EntryHelpers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Language;
|
||||
use App\Traits\ModCPSearch;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LanguageController extends Controller
|
||||
{
|
||||
|
||||
use ModCPSearch;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$items = Language::withCount('entries')
|
||||
->orderBy('name')
|
||||
->tap(fn($query) => $this->applySearch($query, ['name']))
|
||||
->paginate(30)
|
||||
->withQueryString();
|
||||
|
||||
return view('modcp.resources', [
|
||||
'items' => $items,
|
||||
'title' => 'Languages',
|
||||
'singular' => 'Language',
|
||||
'storeRoute' => 'modcp.languages.store',
|
||||
'updateRoute' => 'modcp.languages.update',
|
||||
'destroyRoute' => 'modcp.languages.destroy'
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255|unique:languages,name',
|
||||
]);
|
||||
|
||||
Language::create([
|
||||
'name' => trim($request->name),
|
||||
'slug' => EntryHelpers::uniqueSlug( $request->name, Language::class ),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Language added.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Language $language)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255|unique:languages,name,' . $language->id,
|
||||
]);
|
||||
|
||||
$language->update([
|
||||
'name' => trim($request->name),
|
||||
'slug' => EntryHelpers::uniqueSlug( $request->name, Language::class, $language->id ),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Language updated.');
|
||||
}
|
||||
|
||||
public function destroy(Language $language)
|
||||
{
|
||||
$language->delete();
|
||||
return back()->with('success', 'Language deleted.');
|
||||
}
|
||||
}
|
||||
68
app/Http/Controllers/ModCP/PlatformController.php
Normal file
68
app/Http/Controllers/ModCP/PlatformController.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ModCP;
|
||||
|
||||
use App\Helpers\EntryHelpers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Platform;
|
||||
use App\Models\Language;
|
||||
use App\Traits\ModCPSearch;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PlatformController extends Controller
|
||||
{
|
||||
|
||||
use ModCPSearch;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$items = Platform::withCount(['games','entries'])
|
||||
->orderBy('name')
|
||||
->tap(fn($query) => $this->applySearch($query, ['name']))
|
||||
->paginate(30)
|
||||
->withQueryString();
|
||||
|
||||
return view('modcp.resources', [
|
||||
'items' => $items,
|
||||
'title' => 'Platforms',
|
||||
'singular' => 'Platform',
|
||||
'storeRoute' => 'modcp.platforms.store',
|
||||
'updateRoute' => 'modcp.platforms.update',
|
||||
'destroyRoute' => 'modcp.platforms.destroy'
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255|unique:platforms,name',
|
||||
]);
|
||||
|
||||
Platform::create([
|
||||
'name' => trim($request->name),
|
||||
'slug' => EntryHelpers::uniqueSlug( $request->name, Platform::class ),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Platform added.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Platform $platform)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255|unique:platforms,name,' . $platform->id,
|
||||
]);
|
||||
|
||||
$platform->update([
|
||||
'name' => trim($request->name),
|
||||
'slug' => EntryHelpers::uniqueSlug( $request->name, Platform::class, $platform->id ),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Platform updated.');
|
||||
}
|
||||
|
||||
public function destroy(Platform $platform)
|
||||
{
|
||||
$platform->delete();
|
||||
return back()->with('success', 'Platform deleted.');
|
||||
}
|
||||
}
|
||||
78
app/Http/Controllers/ModCPController.php
Normal file
78
app/Http/Controllers/ModCPController.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Jobs\RestoreXenForoCommentsThread;
|
||||
use App\Models\Entry;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModCPController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$stats = [
|
||||
'pending' => Entry::where('state', 'pending')->count(),
|
||||
'locked' => Entry::where('state', 'locked')->count(),
|
||||
'total' => Entry::count()
|
||||
];
|
||||
|
||||
if( \Auth::user()->can('is-admin') ){
|
||||
$stats['draft'] = Entry::where('state', 'draft')->count();
|
||||
$stats['hidden'] = Entry::where('state', 'hidden')->count();
|
||||
$stats['deleted'] = Entry::where('state', 'deleted')->count();
|
||||
}
|
||||
|
||||
$recentDeleted = Entry::onlyTrashed()->latest('deleted_at')->limit(5)->get();
|
||||
|
||||
return view('modcp.index', compact('stats', 'recentDeleted'));
|
||||
}
|
||||
|
||||
public function locked()
|
||||
{
|
||||
$entries = Entry::where('state', 'locked')
|
||||
->with(['game.platform', 'authors'])
|
||||
->latest()->paginate(25);
|
||||
|
||||
return view('modcp.entries', compact('entries'))->with('pageTitle', "Locked Entries")->with('state', 'locked');
|
||||
}
|
||||
|
||||
public function draft()
|
||||
{
|
||||
$entries = Entry::where('state', 'draft')
|
||||
->with(['game.platform', 'authors'])
|
||||
->latest()->paginate(25);
|
||||
|
||||
return view('modcp.entries', compact('entries'))->with('pageTitle', "Draft Entries")->with('state', 'draft');
|
||||
}
|
||||
|
||||
public function hidden()
|
||||
{
|
||||
$entries = Entry::where('state', 'hidden')
|
||||
->with(['game.platform', 'authors'])
|
||||
->latest()->paginate(25);
|
||||
|
||||
return view('modcp.entries', compact('entries'))->with('pageTitle', "Hidden Entries")->with('state', 'hidden');
|
||||
}
|
||||
|
||||
public function deleted()
|
||||
{
|
||||
$entries = Entry::onlyTrashed()
|
||||
->with(['game.platform', 'authors'])
|
||||
->latest('deleted_at')->paginate(25);
|
||||
return view('modcp.deleted', compact('entries'));
|
||||
}
|
||||
|
||||
public function restore(Entry $entry)
|
||||
{
|
||||
$entry->restore();
|
||||
RestoreXenForoCommentsThread::dispatch($entry->comments_thread_id);
|
||||
$entry->update(['state' => 'draft']);
|
||||
return back()->with('success', "Entry restored");
|
||||
}
|
||||
|
||||
public function destroy(Entry $entry)
|
||||
{
|
||||
$entry->forceDelete();
|
||||
return back()->with('success', "Entry permanently deleted");
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Exceptions\SubmissionException;
|
||||
use App\Helpers\FormHelpers;
|
||||
use App\Http\Requests\StoreDraftRequest;
|
||||
use App\Http\Requests\StoreEntryRequest;
|
||||
use App\Jobs\DeleteXenForoCommentsThread;
|
||||
use App\Models\Author;
|
||||
use App\Models\Entry;
|
||||
use App\Models\EntryFile;
|
||||
@@ -17,6 +19,7 @@ use App\Models\Modification;
|
||||
use App\Models\Platform;
|
||||
use App\Models\Status;
|
||||
use App\Services\SubmissionsService;
|
||||
use App\Services\XenforoApiService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -82,7 +85,22 @@ class SubmissionController extends Controller
|
||||
return view('submissions.edit', $data);
|
||||
}
|
||||
|
||||
public function store(StoreEntryRequest $request, string $section){
|
||||
public function destroy(Request $request, string $section, Entry $entry)
|
||||
{
|
||||
if( $entry->type !== $section )
|
||||
abort(404);
|
||||
|
||||
if( $entry->comments_thread_id)
|
||||
DeleteXenForoCommentsThread::dispatch( $entry->comments_thread_id );
|
||||
|
||||
$entry->delete();
|
||||
return redirect( route('entries.index') )->with('success', "Entry successfully deleted.");
|
||||
}
|
||||
|
||||
public function store(Request $request, string $section){
|
||||
|
||||
$request = $request->input('submit-state') === 'draft' ? app(StoreDraftRequest::class) : app(StoreEntryRequest::class);
|
||||
$request->validateResolved();
|
||||
|
||||
try {
|
||||
$entry = $this->services->storeEntry($request, $section);
|
||||
@@ -100,8 +118,11 @@ class SubmissionController extends Controller
|
||||
|
||||
}
|
||||
|
||||
public function update(StoreEntryRequest $request, string $section, Entry $entry)
|
||||
public function update(Request $request, string $section, Entry $entry)
|
||||
{
|
||||
$request = $request->input('submit-state') === 'draft' ? app(StoreDraftRequest::class) : app(StoreEntryRequest::class);
|
||||
$request->validateResolved();
|
||||
|
||||
try {
|
||||
$entry = $this->services->editEntry($request, $section, $entry);
|
||||
|
||||
|
||||
22
app/Http/Controllers/ToolsController.php
Normal file
22
app/Http/Controllers/ToolsController.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ToolsController extends Controller
|
||||
{
|
||||
|
||||
public function patcher()
|
||||
{
|
||||
|
||||
$patches = [
|
||||
'file' => 'ZELDA.ips',
|
||||
'name' => "Meltin",
|
||||
'description' => 'Blablabla',
|
||||
'outputName' => 'Game...'
|
||||
];
|
||||
|
||||
return view('tools.patcher', compact('patches'));
|
||||
}
|
||||
}
|
||||
26
app/Http/Requests/StoreDraftRequest.php
Normal file
26
app/Http/Requests/StoreDraftRequest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
class StoreDraftRequest extends StoreEntryRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = parent::rules();
|
||||
$rules['submit-state'] = 'required|string|in:draft';
|
||||
|
||||
$rules = array_map(function($rule){
|
||||
if( is_array($rule) ){
|
||||
return array_map( fn($r) => $r === 'required' ? 'nullable' : $r, $rule);
|
||||
}
|
||||
|
||||
return preg_replace(
|
||||
['/\brequired_without\S*/', '/required_with\S*/', '/\brequired\b/'],
|
||||
['nullable', 'nullable', 'nullable'],
|
||||
$rule
|
||||
);
|
||||
}, $rules );
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,8 @@ class StoreEntryRequest extends FormRequest
|
||||
if( $isEdit && $this->user()->can('moderate', $this->route('entry') ) ){
|
||||
$rules['staff_comment'] = 'nullable|string';
|
||||
$rules['owner_user_id'] = [ 'required', 'integer', new XfUserExists ];
|
||||
$rules['comments_thread_id'] = 'nullable|integer';
|
||||
$rules['featured'] = 'nullable|boolean';
|
||||
}
|
||||
|
||||
return $rules;
|
||||
|
||||
34
app/Jobs/DeleteXenForoCommentsThread.php
Normal file
34
app/Jobs/DeleteXenForoCommentsThread.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Entry;
|
||||
use App\Services\XenforoApiService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
|
||||
class DeleteXenForoCommentsThread implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public $tries = 3;
|
||||
public $backoff = 10;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(
|
||||
protected int $threadId,
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(XenforoApiService $service): void
|
||||
{
|
||||
$service->deleteThreadWithEntry($this->threadId);
|
||||
}
|
||||
}
|
||||
34
app/Jobs/RestoreXenForoCommentsThread.php
Normal file
34
app/Jobs/RestoreXenForoCommentsThread.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Entry;
|
||||
use App\Services\XenforoApiService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
|
||||
class RestoreXenForoCommentsThread implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public $tries = 3;
|
||||
public $backoff = 10;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(
|
||||
protected int $threadId,
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(XenforoApiService $service): void
|
||||
{
|
||||
$service->restoreThreadWithEntry($this->threadId);
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,12 @@ namespace App\Livewire;
|
||||
use App\Models\Author;
|
||||
use App\Models\Entry;
|
||||
use App\Models\Game;
|
||||
use App\Models\Genre;
|
||||
use App\Models\Language;
|
||||
use App\Models\Modification;
|
||||
use App\Models\Platform;
|
||||
use App\Models\Status;
|
||||
use Livewire\Attributes\Url;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
@@ -20,18 +22,21 @@ class Database extends Component
|
||||
* entry_title search
|
||||
* @var string
|
||||
*/
|
||||
#[Url(as: 's',except: '')]
|
||||
public string $search = '';
|
||||
|
||||
/**
|
||||
* type filter.
|
||||
* @var array
|
||||
*/
|
||||
#[Url(except:[])]
|
||||
public array $types = [];
|
||||
|
||||
/**
|
||||
* Games IDs filter.
|
||||
* @var array
|
||||
*/
|
||||
#[Url(except:[])]
|
||||
public array $games = [];
|
||||
|
||||
/**
|
||||
@@ -44,24 +49,35 @@ class Database extends Component
|
||||
* Platform IDs filter.
|
||||
* @var array
|
||||
*/
|
||||
#[Url(except:[])]
|
||||
public array $platforms = [];
|
||||
|
||||
/**
|
||||
* Genre IDs filter.
|
||||
* @var array
|
||||
*/
|
||||
#[Url(except:[])]
|
||||
public array $genres = [];
|
||||
|
||||
/**
|
||||
* Status IDs filter.
|
||||
* @var array
|
||||
*/
|
||||
#[Url(except:[])]
|
||||
public array $statuses = [];
|
||||
|
||||
/**
|
||||
* Authors IDs filter.
|
||||
* @var array
|
||||
*/
|
||||
#[Url(except:[])]
|
||||
public array $authors = [];
|
||||
|
||||
/**
|
||||
* Authors mode and/or.
|
||||
* @var string
|
||||
*/
|
||||
#[Url(except:'or')]
|
||||
public string $authorsMode = 'or';
|
||||
|
||||
/**
|
||||
@@ -74,36 +90,42 @@ class Database extends Component
|
||||
* Languages IDs filter.
|
||||
* @var array
|
||||
*/
|
||||
#[Url(except:[])]
|
||||
public array $languages = [];
|
||||
|
||||
/**
|
||||
* Languages mode and/or
|
||||
* @var string
|
||||
*/
|
||||
#[Url(except:'or')]
|
||||
public string $languagesMode = 'or';
|
||||
|
||||
/**
|
||||
* Modifications IDs filter.
|
||||
* @var array
|
||||
*/
|
||||
#[Url(except:[])]
|
||||
public array $modifications = [];
|
||||
|
||||
/**
|
||||
* Modifications mode and/or.
|
||||
* @var string
|
||||
*/
|
||||
#[Url(except:'or')]
|
||||
public string $modificationsMode = 'or';
|
||||
|
||||
/**
|
||||
* Sort by field.
|
||||
* @var string
|
||||
*/
|
||||
#[Url(as: 'sort',except: 'created_at')]
|
||||
public string $sortBy = 'created_at';
|
||||
|
||||
/**
|
||||
* asc/desc
|
||||
* @var string
|
||||
*/
|
||||
#[Url(as: 'dir',except: 'desc')]
|
||||
public string $sortDir = 'desc';
|
||||
|
||||
/**
|
||||
@@ -134,6 +156,7 @@ class Database extends Component
|
||||
public function updatedTypes(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedGames(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedPlatforms(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedGenres(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedStatuses(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedAuthors(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedAuthorsMode(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
@@ -145,7 +168,7 @@ class Database extends Component
|
||||
public function clearFilters(): void
|
||||
{
|
||||
$this->reset([
|
||||
'search', 'types', 'platforms', 'statuses', 'authors', 'authorsMode', 'languages', 'languagesMode', 'modifications', 'modificationsMode'
|
||||
'search', 'types', 'platforms', 'genres', 'statuses', 'authors', 'authorsMode', 'languages', 'languagesMode', 'modifications', 'modificationsMode'
|
||||
]);
|
||||
$this->resetPage();
|
||||
}
|
||||
@@ -165,7 +188,7 @@ class Database extends Component
|
||||
private function buildQuery()
|
||||
{
|
||||
$query = Entry::query()->published()->with([
|
||||
'game.platform', 'status', 'authors', 'languages'
|
||||
'game.platform', 'game.genre', 'status', 'authors', 'languages'
|
||||
]);
|
||||
|
||||
if( $this->search ) {
|
||||
@@ -186,6 +209,12 @@ class Database extends Component
|
||||
});
|
||||
}
|
||||
|
||||
if( $this->genres ) {
|
||||
$query->where(function($q) {
|
||||
$q->whereHas('game', fn($q2) => $q2->whereIn('genre_id', $this->genres) );
|
||||
});
|
||||
}
|
||||
|
||||
if( $this->games ){
|
||||
$query->whereIn('game_id', $this->games);
|
||||
}
|
||||
@@ -233,6 +262,7 @@ class Database extends Component
|
||||
'entries' => $this->buildQuery()->paginate(self::PAGINATION),
|
||||
'allGames' => Game::orderBy('name')->get(),
|
||||
'allPlatforms' => Platform::orderBy('name')->get(),
|
||||
'allGenres' => Genre::orderBy('name')->get(),
|
||||
'allStatuses' => Status::orderBy('name')->get(),
|
||||
'allAuthors' => Author::orderBy('name')->get(),
|
||||
'allLanguages' => Language::orderBy('name')->get(),
|
||||
|
||||
@@ -14,7 +14,7 @@ class XfUserSelector extends Component
|
||||
public ?int $selected = null;
|
||||
public ?string $selectedUsername = null;
|
||||
|
||||
public function mount( ?int $initialUserId ){
|
||||
public function mount( ?int $initialUserId = null ){
|
||||
if( $initialUserId ){
|
||||
$user = DB::connection('xenforo')->table('user')->where('user_id', $initialUserId)->first();
|
||||
if( $user ){
|
||||
|
||||
@@ -2,11 +2,29 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Auth\XenForoUser;
|
||||
use App\Services\XenforoService;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Author extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name', 'slug', 'user_id', 'website'
|
||||
];
|
||||
|
||||
public function entries(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Entry::class, 'entry_authors');
|
||||
}
|
||||
|
||||
public function user(): ?XenForoUser
|
||||
{
|
||||
if( !$this->user_id )
|
||||
return null;
|
||||
|
||||
return app(XenforoService::class)->getXfUser($this->user_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
class EntryFile extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'entry_id', 'filename', 'filepath', 'favorite_server', 'favorite_at', 'filesize', 'state', 'file_uuid'
|
||||
'entry_id', 'filename', 'filepath', 'favorite_server', 'favorite_at', 'filesize', 'state', 'file_uuid', 'online_patcher', 'secondary_online_patcher',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
||||
@@ -21,4 +21,9 @@ class Game extends Model
|
||||
{
|
||||
return $this->belongsTo(Genre::class);
|
||||
}
|
||||
|
||||
public function entries(): Game|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Entry::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,15 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Genre extends Model
|
||||
{
|
||||
protected $fillable = [ 'name', 'slug' ];
|
||||
|
||||
public function games(): HasMany
|
||||
{
|
||||
return $this->hasMany(Game::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,15 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Language extends Model
|
||||
{
|
||||
protected $fillable = [ 'name', 'slug' ];
|
||||
|
||||
public function entries(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Entry::class, 'entry_languages');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Platform extends Model
|
||||
{
|
||||
@@ -14,4 +15,13 @@ class Platform extends Model
|
||||
'name', 'slug', 'short_name'
|
||||
];
|
||||
|
||||
public function games(): HasMany
|
||||
{
|
||||
return $this->hasMany(Game::class);
|
||||
}
|
||||
|
||||
public function entries(): HasMany
|
||||
{
|
||||
return $this->hasMany(Entry::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ class EntryPolicy
|
||||
return false;
|
||||
}
|
||||
|
||||
public function skipQueue(User $user, Entry $entry): bool
|
||||
public function skipQueue(User $user, ?Entry $entry = null): bool
|
||||
{
|
||||
return $user->_can( 'romhackplaza', 'canSubmitEntryInPublished' );
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Auth\XenForoGuard;
|
||||
use App\Auth\XenForoUser;
|
||||
use App\Policies\TempFilePolicy;
|
||||
use App\Services\TemporaryFileService;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
@@ -28,5 +30,12 @@ class AppServiceProvider extends ServiceProvider
|
||||
});
|
||||
|
||||
\Gate::policy(TemporaryFileService::class, TempFilePolicy::class );
|
||||
|
||||
Gate::define('is-admin', function (XenForoUser $user) {
|
||||
return $user->is_admin === 1;
|
||||
});
|
||||
Gate::define('is-mod', function (XenForoUser $user) {
|
||||
return $user->is_moderator === 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class ManagePanelProvider extends PanelProvider
|
||||
->default()
|
||||
->id('manage')
|
||||
->path('manage')
|
||||
->login()
|
||||
->authGuard('xenforo')
|
||||
->colors([
|
||||
'primary' => Color::Amber,
|
||||
])
|
||||
|
||||
@@ -17,6 +17,7 @@ use App\Models\Genre;
|
||||
use App\Models\Language;
|
||||
use App\Models\Modification;
|
||||
use App\Models\Platform;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -28,9 +29,9 @@ class SubmissionsService {
|
||||
|
||||
/**
|
||||
* Request for store/edit.
|
||||
* @var StoreEntryRequest|null
|
||||
* @var Request|null
|
||||
*/
|
||||
private ?StoreEntryRequest $request = null;
|
||||
private ?Request $request = null;
|
||||
|
||||
/**
|
||||
* Section for store/edit.
|
||||
@@ -72,7 +73,9 @@ class SubmissionsService {
|
||||
'done' => true,
|
||||
'error' => null,
|
||||
'uuid' => $uuid,
|
||||
'state' => $file->state
|
||||
'state' => $file->state,
|
||||
'meta_online_patcher' => $file->online_patcher,
|
||||
'meta_secondary_online_patcher' => $file->secondary_online_patcher,
|
||||
];
|
||||
|
||||
$file = Cache::get("uploaded_file_{$uuid}");
|
||||
@@ -86,7 +89,9 @@ class SubmissionsService {
|
||||
'done' => true,
|
||||
'error' => null,
|
||||
'uuid' => $uuid,
|
||||
'state' => $file['state']
|
||||
'state' => $file['state'],
|
||||
'meta_online_patcher' => false,
|
||||
'meta_secondary_online_patcher' => false,
|
||||
];
|
||||
|
||||
return null;
|
||||
@@ -102,7 +107,7 @@ class SubmissionsService {
|
||||
* @throws SubmissionException
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function storeEntry( StoreEntryRequest $request, string $section ){
|
||||
public function storeEntry( Request $request, string $section ){
|
||||
|
||||
// STEP 1 : Prepare basic fields.
|
||||
|
||||
@@ -188,23 +193,30 @@ class SubmissionsService {
|
||||
$this->Step13_CreateCommentsThread( $entry );
|
||||
|
||||
// Step 14: Refresh XF count.
|
||||
XenForoHelpers::updateEntriesCount( $entry->user_id );
|
||||
if( $entry->state !== 'draft')
|
||||
XenForoHelpers::updateEntriesCount( $entry->user_id );
|
||||
|
||||
return $entry;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @return null|int
|
||||
*
|
||||
* @throws SubmissionException
|
||||
*/
|
||||
private function Step2_CreateAndReturnGameId(): int {
|
||||
private function Step2_CreateAndReturnGameId(): ?int {
|
||||
|
||||
// Already existing game.
|
||||
if( $this->request->input('game_id') )
|
||||
return $this->request->input('game_id');
|
||||
|
||||
// No fields like a draft.
|
||||
if( !$this->request->input('new-game-title') &&
|
||||
!$this->request->input('new-game-platform') &&
|
||||
!$this->request->input('new-game-genre') )
|
||||
return null;
|
||||
|
||||
// Need to create a game.
|
||||
$game = $this->createGameFromFormFields();
|
||||
|
||||
@@ -244,14 +256,14 @@ class SubmissionsService {
|
||||
|
||||
$fields['entry_title'] = $this->request->input('entry_title') ?? null;
|
||||
if( section_must_be( [ 'homebrew', 'translations' ], $this->section ) && $gameId ){
|
||||
$fields['game_name'] = Game::find( $gameId )->name;
|
||||
$fields['game_name'] = $gameId ? Game::find( $gameId )->name : null;
|
||||
}
|
||||
if( section_must_be( 'translations', $this->section ) ) {
|
||||
$fields['languages_string'] = Language::whereIn('id', $this->request->input('languages', []))->pluck('name')->implode(', ');
|
||||
}
|
||||
if( section_must_be(['romhacks', 'translations', 'homebrew', 'lua-scripts', 'tutorials'], $this->section ) ) {
|
||||
// TODO: Add single platform ID compatibility.
|
||||
$fields['platform_name'] = Game::find( $gameId )->platform->name;
|
||||
$fields['platform_name'] = $gameId ? Game::find( $gameId )->platform->name : null;
|
||||
}
|
||||
|
||||
return EntryHelpers::buildCompleteTitle( $this->section, $fields );
|
||||
@@ -268,7 +280,7 @@ class SubmissionsService {
|
||||
if( !$uuidData )
|
||||
$uuidData = $this->request->input('files_uuid', [] );
|
||||
|
||||
foreach ( $uuidData as $uuid ) {
|
||||
foreach ( $uuidData ?? [] as $uuid ) {
|
||||
$fileData = Cache::pull("uploaded_file_{$uuid}");
|
||||
if( !$fileData )
|
||||
throw new SubmissionException( "File {$uuid} has expired. Please delete all your files and retry. If it's an edition, delete all your new files and retry." );
|
||||
@@ -294,7 +306,7 @@ class SubmissionsService {
|
||||
*/
|
||||
private function Step8_SaveHashes( int $entryId ): void
|
||||
{
|
||||
foreach ( $this->request->input('hashes', [] ) as $hash ) {
|
||||
foreach ( $this->request->input('hashes', [] ) ?? [] as $hash ) {
|
||||
if( !isset($hash['filename'], $hash['hash_crc32'], $hash['hash_sha1'], $hash['verified']) ) {
|
||||
continue;
|
||||
}
|
||||
@@ -320,7 +332,7 @@ class SubmissionsService {
|
||||
// TODO: Code fragment to be replaced by edit version.
|
||||
|
||||
// Existing authors.
|
||||
foreach ( $this->request->input('authors', [] ) as $authorId ) {
|
||||
foreach ( $this->request->input('authors', [] ) ?? [] as $authorId ) {
|
||||
$author = Author::find( $authorId );
|
||||
if( !$author )
|
||||
throw new SubmissionException( "Author {$authorId} does not exist." );
|
||||
@@ -328,7 +340,7 @@ class SubmissionsService {
|
||||
}
|
||||
|
||||
// New Authors
|
||||
foreach ( $this->request->input('new-authors', [] ) as $authorName ) {
|
||||
foreach ( $this->request->input('new-authors', [] ) ?? [] as $authorName ) {
|
||||
$authorName = trim( $authorName );
|
||||
if( $authorName === '' )
|
||||
continue;
|
||||
@@ -352,7 +364,7 @@ class SubmissionsService {
|
||||
|
||||
// TODO: Replace by edit version
|
||||
|
||||
foreach ( $this->request->input('modifications', [] ) as $modificationId ) {
|
||||
foreach ( $this->request->input('modifications', [] ) ?? [] as $modificationId ) {
|
||||
$modification = Modification::find( $modificationId );
|
||||
if( !$modification )
|
||||
throw new SubmissionException( "Modification {$modificationId} does not exist." );
|
||||
@@ -370,7 +382,7 @@ class SubmissionsService {
|
||||
{
|
||||
// TODO: Replace by edit version.
|
||||
|
||||
foreach ( $this->request->input('languages', [] ) as $languageId ) {
|
||||
foreach ( $this->request->input('languages', [] ) ?? [] as $languageId ) {
|
||||
$language = Language::find( $languageId );
|
||||
if( !$language )
|
||||
throw new SubmissionException( "Language {$languageId} does not exist." );
|
||||
@@ -381,7 +393,7 @@ class SubmissionsService {
|
||||
|
||||
private function Step12a_PrepareGalleryImages( Entry $entry ): void
|
||||
{
|
||||
foreach ( $this->request->input('gallery', [] ) as $imagePath ) {
|
||||
foreach ( $this->request->input('gallery', [] ) ?? [] as $imagePath ) {
|
||||
EntryGallery::create([
|
||||
'entry_id' => $entry->id,
|
||||
'image' => $imagePath,
|
||||
@@ -396,6 +408,10 @@ class SubmissionsService {
|
||||
*/
|
||||
private function Step12b_MoveMainImage( Entry $entry ): void {
|
||||
$mainImage = $entry->main_image;
|
||||
|
||||
if( !$mainImage )
|
||||
return;
|
||||
|
||||
$newPath = 'entries/main-images/' . basename($mainImage);
|
||||
|
||||
if( !Storage::disk('public')->move($mainImage, $newPath) )
|
||||
@@ -406,7 +422,7 @@ class SubmissionsService {
|
||||
|
||||
private function Step12c_SaveGalleryImages( Entry $entry ): void
|
||||
{
|
||||
foreach ( $entry->gallery as $galleryItem ) {
|
||||
foreach ( $entry->gallery ?? [] as $galleryItem ) {
|
||||
$newPath = 'entries/gallery-images/' . $entry->id . '/' . basename($galleryItem->image);
|
||||
|
||||
if( !Storage::disk('public')->move($galleryItem->image, $newPath) )
|
||||
@@ -416,7 +432,7 @@ class SubmissionsService {
|
||||
}
|
||||
}
|
||||
|
||||
public function editEntry( StoreEntryRequest $request, string $section, Entry $entry ): Entry
|
||||
public function editEntry(Request $request, string $section, Entry $entry ): Entry
|
||||
{
|
||||
|
||||
// STEP 1: Prepare basic fields and keep in save some others fields.
|
||||
@@ -477,6 +493,8 @@ class SubmissionsService {
|
||||
'youtube_link' => $this->request->input('youtube_video'),
|
||||
'user_id' => $user_id,
|
||||
'complete_title' => $completeTitle,
|
||||
'comments_thread_id' => $this->request->input('comments_thread_id'),
|
||||
'featured' => $this->request->input('featured'),
|
||||
];
|
||||
|
||||
if( \Auth::user()->can('moderate', $this->entry) ){
|
||||
@@ -505,9 +523,6 @@ class SubmissionsService {
|
||||
// STEP 11: Prepare new gallery images and prepare deletion of others ones.
|
||||
$galleryPaths = $this->eStep11a_UpdateGalleryImages();
|
||||
|
||||
// STEP 13: Try to create comments area if it doesn't exist.
|
||||
$this->Step13_CreateCommentsThread( $this->entry );
|
||||
|
||||
return $this->entry;
|
||||
|
||||
});
|
||||
@@ -519,9 +534,14 @@ class SubmissionsService {
|
||||
$this->eStep11c_UpdateGalleryImages( $galleryPaths );
|
||||
|
||||
// STEP 12: Refresh XF count.
|
||||
if( $oldUserId )
|
||||
XenForoHelpers::updateEntriesCount( $oldUserId );
|
||||
XenForoHelpers::updateEntriesCount( $entry->user_id );
|
||||
if( $entry->state !== 'draft' ) {
|
||||
if ($oldUserId)
|
||||
XenForoHelpers::updateEntriesCount($oldUserId);
|
||||
XenForoHelpers::updateEntriesCount($entry->user_id);
|
||||
}
|
||||
|
||||
// STEP 13: Try to create comments area if it doesn't exist.
|
||||
$this->Step13_CreateCommentsThread( $this->entry );
|
||||
|
||||
return $entry;
|
||||
}
|
||||
@@ -550,6 +570,12 @@ class SubmissionsService {
|
||||
|
||||
}
|
||||
|
||||
// In draft.
|
||||
if( !$this->request->input('new-game-title') &&
|
||||
!$this->request->input('new-game-platform') &&
|
||||
!$this->request->input('new-game-genre') )
|
||||
return $this->entry->game_id;
|
||||
|
||||
// Need to create a game.
|
||||
$game = $this->createGameFromFormFields();
|
||||
|
||||
@@ -562,8 +588,8 @@ class SubmissionsService {
|
||||
*/
|
||||
private function eStep6_UpdateEntryFiles(int $entryId ): void
|
||||
{
|
||||
$requestUuids = $this->request->input('files_uuid', []);
|
||||
$requestStates = $this->request->input('files_state', []);
|
||||
$requestUuids = $this->request->input('files_uuid', []) ?? [];
|
||||
$requestStates = $this->request->input('files_state', []) ?? [];
|
||||
$existingUuids = EntryFile::where( 'entry_id', $entryId )->pluck('file_uuid')->toArray();
|
||||
|
||||
$needDeletion = array_diff( $existingUuids, $requestUuids );
|
||||
@@ -626,7 +652,7 @@ class SubmissionsService {
|
||||
private function eStep8_UpdateAuthors(): void
|
||||
{
|
||||
$syncAuthorsId = [];
|
||||
$requestAuthorsId = $this->request->input('authors', [] );
|
||||
$requestAuthorsId = $this->request->input('authors', [] ) ?? [];
|
||||
|
||||
if( !empty( $requestAuthorsId ) ){
|
||||
$valid = Author::whereIn( 'id', $requestAuthorsId )->pluck('id')->toArray();
|
||||
@@ -638,7 +664,7 @@ class SubmissionsService {
|
||||
$syncAuthorsId = array_merge( $syncAuthorsId, $requestAuthorsId );
|
||||
}
|
||||
|
||||
foreach ( $this->request->input('new-authors', [] ) as $authorName ) {
|
||||
foreach ( $this->request->input('new-authors', [] ) ?? [] as $authorName ) {
|
||||
$authorName = trim($authorName);
|
||||
if ($authorName === '')
|
||||
continue;
|
||||
@@ -660,7 +686,7 @@ class SubmissionsService {
|
||||
*/
|
||||
private function eStep9_UpdateRomhacksModifications(): void
|
||||
{
|
||||
$requestModifications = $this->request->input('modifications', [] );
|
||||
$requestModifications = $this->request->input('modifications', [] ) ?? [];
|
||||
if( !empty( $requestModifications ) ){
|
||||
$valid = Modification::whereIn( 'id', $requestModifications )->pluck('id')->toArray();
|
||||
|
||||
@@ -681,7 +707,7 @@ class SubmissionsService {
|
||||
*/
|
||||
private function eStep10_UpdateLanguages(): void
|
||||
{
|
||||
$requestLanguages = $this->request->input('languages', [] );
|
||||
$requestLanguages = $this->request->input('languages', [] ) ?? [];
|
||||
if( !empty( $requestLanguages ) ){
|
||||
$valid = Language::whereIn( 'id', $requestLanguages )->pluck('id')->toArray();
|
||||
if( count( $valid ) !== count( $requestLanguages ) ){
|
||||
@@ -695,7 +721,7 @@ class SubmissionsService {
|
||||
|
||||
private function eStep11a_UpdateGalleryImages(): array
|
||||
{
|
||||
$requestGallery = $this->request->input('gallery', [] );
|
||||
$requestGallery = $this->request->input('gallery', [] ) ?? [];
|
||||
$existingGalleryPaths = $this->entry->gallery->pluck('image')->toArray();
|
||||
|
||||
$needDeletion = array_diff( $existingGalleryPaths, $requestGallery );
|
||||
@@ -723,6 +749,12 @@ class SubmissionsService {
|
||||
if( $currentMainImagePath === $oldMainImagePath )
|
||||
return;
|
||||
|
||||
if( !$currentMainImagePath ) {
|
||||
if( $oldMainImagePath && Storage::disk('public')->exists($oldMainImagePath) )
|
||||
Storage::disk('public')->delete($oldMainImagePath);
|
||||
return;
|
||||
}
|
||||
|
||||
$newPath = 'entries/main-images/' . basename( $currentMainImagePath );
|
||||
|
||||
if( !Storage::disk('public')->move( $currentMainImagePath, $newPath ) ){
|
||||
@@ -755,6 +787,9 @@ class SubmissionsService {
|
||||
|
||||
private function Step13_CreateCommentsThread( Entry $entry ): void
|
||||
{
|
||||
if( $entry->state !== 'published' )
|
||||
return;
|
||||
|
||||
if( !$entry->comments_thread_id )
|
||||
CreateXenForoCommentsThread::dispatch( $entry );
|
||||
// app(XenforoApiService::class)->createCommentsThread( $entry );
|
||||
|
||||
@@ -48,6 +48,19 @@ class XenforoApiService {
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
private function delete(string $endpoint, ?int $customUserId = null, array $data = [] ): mixed
|
||||
{
|
||||
$response = Http::withHeaders([
|
||||
'XF-Api-Key' => $this->apiKey,
|
||||
'XF-Api-User' => $customUserId ?? $this->superUserId,
|
||||
])->delete("{$this->apiUrl}/{$endpoint}", $data);
|
||||
|
||||
if( !$response->ok() )
|
||||
return null;
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
public function getUserAlerts(int $userId): mixed
|
||||
{
|
||||
if( app(XenforoService::class)->getXfUser($userId)?->alerts_unviewed > 0 ) {
|
||||
@@ -121,4 +134,14 @@ class XenforoApiService {
|
||||
return $response['success'] ?? false;
|
||||
}
|
||||
|
||||
public function deleteThreadWithEntry(int $threadId): bool
|
||||
{
|
||||
return (bool) $this->delete( "threads/{$threadId}", data: ['reason' => "Deletion with entry." ] );
|
||||
}
|
||||
|
||||
public function restoreThreadWithEntry(int $threadId): bool
|
||||
{
|
||||
return (bool) $this->post("threads/{$threadId}/undelete" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
23
app/Traits/ModCPSearch.php
Normal file
23
app/Traits/ModCPSearch.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
trait ModCPSearch
|
||||
{
|
||||
protected function applySearch(Builder $query, array $columns = ['name'] ): Builder
|
||||
{
|
||||
$search = request('s', '');
|
||||
if( !$search )
|
||||
return $query;
|
||||
|
||||
return $query->where(function ($query) use ($columns, $search) {
|
||||
foreach ($columns as $i => $column) {
|
||||
$method = $i === 0 ? 'where' : 'orWhere';
|
||||
$query->{$method}($column, 'LIKE', "%{$search}%");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
29
app/View/Components/ModCPSearch.php
Normal file
29
app/View/Components/ModCPSearch.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class ModCPSearch extends Component
|
||||
{
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public string $placeholder = "Search...",
|
||||
public string $param = 's'
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*/
|
||||
public function render(): View|Closure|string
|
||||
{
|
||||
return view('components.modcp-search');
|
||||
}
|
||||
}
|
||||
@@ -24,3 +24,40 @@ if( !function_exists( 'section_must_not_be' ) ){
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( !function_exists( 'databaseRoute' ) ){
|
||||
|
||||
function databaseRoute( array $params = [] ): string
|
||||
{
|
||||
$defaults = [
|
||||
'types' => [],
|
||||
'platforms' => [],
|
||||
'genres' => [],
|
||||
'games' => [],
|
||||
'statuses' => [],
|
||||
'authors' => [],
|
||||
'authorsMode' => 'or',
|
||||
'languages' => [],
|
||||
'languagesMode' => 'or',
|
||||
'modifications' => [],
|
||||
'modificationsMode' => 'or',
|
||||
'sort' => 'created_at',
|
||||
'dir' => 'desc',
|
||||
's' => ''
|
||||
];
|
||||
|
||||
$query = array_filter(
|
||||
array_merge($defaults, $params),
|
||||
fn($v,$k) => match(true){
|
||||
is_array($v) => !empty($v),
|
||||
in_array($k, ['authorsMode', 'languagesMode', 'modificationsMode']) => $v !== 'or',
|
||||
$k === 'sort' => $v !== 'created_at',
|
||||
$k === 'dir' => $v !== 'desc',
|
||||
default => $v !== '',
|
||||
},
|
||||
ARRAY_FILTER_USE_BOTH
|
||||
);
|
||||
|
||||
return route('entries.index', $query );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user