77 lines
3.0 KiB
PHP
77 lines
3.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use Core\Http\Router;
|
|
use Core\Services\Database;
|
|
use Core\Services\Shortcodes;
|
|
use Plugins\Artists\ArtistsController;
|
|
|
|
require_once __DIR__ . '/ArtistsController.php';
|
|
|
|
Shortcodes::register('new-artists', static function (array $attrs = []): string {
|
|
$limit = max(1, min(20, (int)($attrs['limit'] ?? 6)));
|
|
$db = Database::get();
|
|
if (!($db instanceof \PDO)) {
|
|
return '';
|
|
}
|
|
|
|
try {
|
|
$stmt = $db->prepare("
|
|
SELECT name, slug, country, avatar_url
|
|
FROM ac_artists
|
|
WHERE is_active = 1
|
|
ORDER BY created_at DESC, id DESC
|
|
LIMIT :limit
|
|
");
|
|
$stmt->bindValue(':limit', $limit, \PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC) ?: [];
|
|
} catch (\Throwable $e) {
|
|
return '';
|
|
}
|
|
|
|
if (!$rows) {
|
|
return '<div class="ac-shortcode-empty">No artists available yet.</div>';
|
|
}
|
|
|
|
$cards = '';
|
|
foreach ($rows as $row) {
|
|
$name = htmlspecialchars((string)($row['name'] ?? ''), ENT_QUOTES, 'UTF-8');
|
|
$slug = rawurlencode((string)($row['slug'] ?? ''));
|
|
$country = htmlspecialchars(trim((string)($row['country'] ?? '')), ENT_QUOTES, 'UTF-8');
|
|
$avatar = trim((string)($row['avatar_url'] ?? ''));
|
|
$avatarHtml = $avatar !== ''
|
|
? '<img src="' . htmlspecialchars($avatar, ENT_QUOTES, 'UTF-8') . '" alt="" loading="lazy">'
|
|
: '<div class="ac-shortcode-cover-fallback">AC</div>';
|
|
|
|
$cards .= '<a class="ac-shortcode-artist-card" href="/artist?slug=' . $slug . '">'
|
|
. '<div class="ac-shortcode-artist-avatar">' . $avatarHtml . '</div>'
|
|
. '<div class="ac-shortcode-artist-meta">'
|
|
. '<div class="ac-shortcode-artist-name">' . $name . '</div>'
|
|
. ($country !== '' ? '<div class="ac-shortcode-artist-country">' . $country . '</div>' : '')
|
|
. '</div>'
|
|
. '</a>';
|
|
}
|
|
|
|
return '<section class="ac-shortcode-artists">'
|
|
. '<div class="ac-shortcode-block-head">New Artists</div>'
|
|
. '<div class="ac-shortcode-artists-grid">' . $cards . '</div>'
|
|
. '</section>';
|
|
});
|
|
|
|
return function (Router $router): void {
|
|
$controller = new ArtistsController();
|
|
$router->get('/artists', [$controller, 'index']);
|
|
$router->get('/artist', [$controller, 'show']);
|
|
$router->get('/admin/artists', [$controller, 'adminIndex']);
|
|
$router->post('/admin/artists/install', [$controller, 'adminInstall']);
|
|
$router->get('/admin/artists/new', [$controller, 'adminNew']);
|
|
$router->get('/admin/artists/edit', function () use ($controller): Core\Http\Response {
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
|
return $controller->adminEdit($id);
|
|
});
|
|
$router->post('/admin/artists/upload', [$controller, 'adminUpload']);
|
|
$router->post('/admin/artists/save', [$controller, 'adminSave']);
|
|
$router->post('/admin/artists/delete', [$controller, 'adminDelete']);
|
|
};
|