A lot of things

- Added Database page.
- Added Xenforo API compatibility
- Added Hovercard
- Added Notifications
This commit is contained in:
2026-05-24 11:47:20 +02:00
parent 7cd6dfddda
commit a778222564
51 changed files with 3228 additions and 38 deletions

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Services;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
class XenforoApiService {
private string $apiKey;
private int $superUserId;
private string $apiUrl;
public function __construct(){
$this->apiKey = config('services.xf_api.key');
$this->superUserId = config('services.xf_api.user');
$this->apiUrl = config('services.xf_api.url');
}
/**
* @throws ConnectionException
*/
private function get(string $endpoint, ?int $customUserId = null ): mixed
{
$response = Http::withHeaders([
'XF-Api-Key' => $this->apiKey,
'XF-Api-User' => $customUserId ?? $this->superUserId,
])->get("{$this->apiUrl}/{$endpoint}");
if( !$response->ok() )
return null;
return $response->json();
}
private function post(string $endpoint, ?int $customUserId = null, array $data = [] ): mixed
{
$response = Http::withHeaders([
'XF-Api-Key' => $this->apiKey,
'XF-Api-User' => $customUserId ?? $this->superUserId,
])->post("{$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 )
return $this->get("alerts?page=1&cutoff=7days", $userId);
return Cache::remember("xf_alerts_{$userId}", 60, function() use($userId) {
return $this->get("alerts?page=1&cutoff=7days", $userId);
});
}
public function markAllNotificationsRead(int $userId): void
{
Cache::forget("xf_alerts_{$userId}");
$this->post("alerts/marl-all", $userId );
}
}

View File

@@ -2,6 +2,8 @@
namespace App\Services;
use App\Auth\XenForoUser;
use App\XenForoDataTypes\XenForoUserGroup;
use Illuminate\Support\Facades\Cache;
class XenforoService {
@@ -10,6 +12,45 @@ class XenforoService {
private const int TTL_PERMISSIONS = 300;
private const int TTL_ROUTES = 86400;
/**
* Get specific XenForo user.
*
* @param int $xfUserId
*
* @return XenForoUser|null
*/
public function getXfUser( int $xfUserId ): ?XenForoUser {
$xfUser = \DB::connection('xenforo')
->table('user')
->where('user_id', $xfUserId)
->first();
if(!$xfUser)
return null;
return new XenForoUser($xfUser);
}
/**
* Get specific XenForo user group.
*
* @param int $xfUserGroupId
*
* @return XenForoUserGroup|null
*/
public function getXfUserGroup( int $xfUserGroupId ): ?XenForoUserGroup {
$xfUserGroup = \DB::connection('xenforo')
->table('user_group')
->where('user_group_id', $xfUserGroupId)
->first();
if(!$xfUserGroup)
return null;
return new XenForoUserGroup($xfUserGroup);
}
/**
* Get permissions for a specific user ID.
*