A lot of things

This commit is contained in:
2026-06-16 16:21:43 +02:00
parent 4f9f6c63b3
commit 7e1e26f20b
126 changed files with 7917 additions and 204 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Helpers;
use App\Models\Entry;
use App\Models\EntryFile;
use App\Models\News;
use App\Services\XenforoApiService;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
@@ -62,13 +64,16 @@ class EntryHelpers {
};
}
public static function getLatestComments(Entry $entry, int $limit = 20): array {
public static function getLatestComments(Entry|News $entry, int $limit = 20): array {
if( !$entry->comments_thread_id ){
return [];
}
$cacheKey = "entry_comments_{$entry->id}";
if( is_a( $entry, News::class ) )
$cacheKey = "news_comments_{$entry->id}";
else
$cacheKey = "entry_comments_{$entry->id}";
return Cache::remember($cacheKey, now()->addDays(1), function () use ($entry, $limit) {
$service = app(XenforoApiService::class);
@@ -93,6 +98,25 @@ class EntryHelpers {
public static function enableOnlinePatcherBasedOnExtension(string $filename): bool
{
return Str::endsWith(Str::lower($filename), ['.ips', '.bps', '.xdelta', '.zip' ]);
return Str::endsWith(Str::lower($filename), ['.ips', '.bps', '.xdelta', '.ups', '.aps', '.ppf', '.zip' ]);
}
public static function getYoutubeVideoId(string $url): ?string
{
$pattern = '%(?:https?://)?(?:www\.|m\.)?(?:youtu\.be/|youtube(?:-nocookie)?\.com/(?:watch\?.*v=|embed/|v/|shorts/|live/))([\w-]{11})%i';
preg_match($pattern, $url, $matches);
return $matches[1] ?? null;
}
public static function fileAlreadyDownloaded(EntryFile $entryFile): bool
{
return session("downloaded_file_{$entryFile->file_uuid}", null ) !== null;
}
public static function markFileAsDownloaded(EntryFile $entryFile): bool
{
session(["downloaded_file_{$entryFile->file_uuid}" => 1]);
return true;
}
}