Initial commit

This commit is contained in:
2026-05-20 18:25:15 +02:00
commit 95f0b4ff01
288 changed files with 90909 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Helpers;
use Illuminate\Support\Str;
class EntryHelpers {
/**
* Create a unique slug.
*
* @param string $title
* @param class-string $model The model with a 'slug' field.
* @param int|null $ignoreId Ignore specific ID, like when edition
*
* @return string The original slug if no duplicates, otherwise with a number at the end.
*/
public static function uniqueSlug(string $title, string $model, ?int $ignoreId = null ): string {
$slug = Str::slug($title);
$baseSlug = $slug;
$i = 1;
while(
$model::where( 'slug', $slug )
->when($ignoreId, fn($q) => $q->where('id', '!=', $ignoreId))
->exists() && $i < 100
){
$slug = $baseSlug . '-' . $i++;
}
if( $i >= 100 ){
$slug = Str::uuid(); // Fallback...
}
return $slug;
}
/**
* Build complete title.
*
* @param string $section
* @param array $fields
*
* @return string
*/
public static function buildCompleteTitle( string $section, array $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']),
'homebrew' => sprintf('%s (%s) Homebrew', $fields['game_name'], $fields['platform_name']),
'utilities' => sprintf('%s - Utility', $fields['entry_title']),
'documents' => sprintf('%s - Document', $fields['entry_title']),
'lua-scripts' => sprintf('%s (%s) LUA Script', $fields['entry_title'], $fields['platform_name']),
'tutorials' => sprintf('%s - Tutorial', $fields['entry_title']),
default => $fields['entry_title'],
};
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Helpers;
class FormHelpers {
private static array $formWords = [
'translations' => [
'page_title' => "Submit a translation",
'about_the' => "About the translation",
'entry_title' => "Custom title",
'entry_title_helper' => "If the translation have a custom title. If not, leave it blank and the game title will be taken.",
'version' => "Patch version",
'status' => "Status",
'release_date' => "Release date",
'release_date_helper' => "If only initial release exist, the release date.",
'description' => "Description",
'about_game' => "Game Information",
'attachments' => "Attachments",
'authors' => "Team members",
'related_links' => "Related links",
'release_site' => "Release site",
'release_site_helper' => "Project entry on site/blog/forum/Github.",
'youtube_video' => "YouTube video",
],
'romhacks' => [
'page_title' => "Submit a romhack",
'about_the' => "About the romhack",
'entry_title' => "Hack title",
'type_of_hack' => "Type of hack",
'version' => "Patch version",
'status' => "Status",
'release_date' => "Release date",
'release_date_helper' => "If only initial release exist, the release date.",
'description' => "Description",
'about_game' => "Game Information",
'attachments' => "Attachments",
'authors' => "Team members",
'related_links' => "Related links",
'release_site' => "Release site",
'release_site_helper' => "Project entry on site/blog/forum/Github.",
'youtube_video' => "YouTube video",
],
];
public static function getEntryFormWords( string $section ){
return self::$formWords[$section] ?? [];
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Helpers;
use App\Auth\XenForoUser;
class XenForoHelpers {
const array XF_AVATAR_COLORS = ['#FF6B6B','#FF9F43','#48DBFB','#1DD1A1','#5F27CD','#341f97','#EE5A24','#009432'];
/**
* Have XenForo default profile picture letter.
*
* @param ?XenForoUser $user If null, default : actual user.
*
* @return string
*/
public static function getAvatarLetter( ?XenForoUser $user = null ): string {
if( $user === null ) {
$user = \Auth::user();
if( $user === null ) {
return '';
}
}
return strtoupper(mb_substr($user->data->username, 0, 1));
}
public static function getAvatarColor( ?XenForoUser $user = null ): string {
if( $user === null ) {
$user = \Auth::user();
if( $user === null ) {
return '';
}
}
return self::XF_AVATAR_COLORS[ crc32( $user->data->username ) % count( self::XF_AVATAR_COLORS ) ];
}
}