Initial dev export (exclude uploads/runtime)
This commit is contained in:
540
plugins/artists/ArtistsController.php
Normal file
540
plugins/artists/ArtistsController.php
Normal file
@@ -0,0 +1,540 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plugins\Artists;
|
||||
|
||||
use Core\Http\Response;
|
||||
use Core\Services\Auth;
|
||||
use Core\Views\View;
|
||||
use Core\Services\Database;
|
||||
use PDO;
|
||||
use Throwable;
|
||||
|
||||
class ArtistsController
|
||||
{
|
||||
private View $view;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->view = new View(__DIR__ . '/views');
|
||||
}
|
||||
|
||||
public function index(): Response
|
||||
{
|
||||
$db = Database::get();
|
||||
$page = null;
|
||||
$artists = [];
|
||||
if ($db instanceof PDO) {
|
||||
try {
|
||||
$stmt = $db->prepare("SELECT title, content_html FROM ac_pages WHERE slug = 'artists' AND is_published = 1 LIMIT 1");
|
||||
$stmt->execute();
|
||||
$page = $stmt->fetch(PDO::FETCH_ASSOC) ?: null;
|
||||
$listStmt = $db->query("
|
||||
SELECT id, name, slug, country, avatar_url
|
||||
FROM ac_artists
|
||||
WHERE is_active = 1
|
||||
ORDER BY created_at DESC
|
||||
");
|
||||
$artists = $listStmt ? $listStmt->fetchAll(PDO::FETCH_ASSOC) : [];
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
}
|
||||
|
||||
return new Response($this->view->render('site/index.php', [
|
||||
'title' => (string)($page['title'] ?? 'Artists'),
|
||||
'content_html' => (string)($page['content_html'] ?? ''),
|
||||
'artists' => $artists,
|
||||
]));
|
||||
}
|
||||
|
||||
public function show(): Response
|
||||
{
|
||||
$slug = trim((string)($_GET['slug'] ?? ''));
|
||||
$artist = null;
|
||||
$artistReleases = [];
|
||||
if ($slug !== '') {
|
||||
$db = Database::get();
|
||||
if ($db instanceof PDO) {
|
||||
$stmt = $db->prepare("SELECT * FROM ac_artists WHERE slug = :slug AND is_active = 1 LIMIT 1");
|
||||
$stmt->execute([':slug' => $slug]);
|
||||
$artist = $stmt->fetch(PDO::FETCH_ASSOC) ?: null;
|
||||
if ($artist) {
|
||||
try {
|
||||
$artistIdReady = false;
|
||||
$probe = $db->query("SHOW COLUMNS FROM ac_releases LIKE 'artist_id'");
|
||||
if ($probe && $probe->fetch(PDO::FETCH_ASSOC)) {
|
||||
$artistIdReady = true;
|
||||
}
|
||||
|
||||
if ($artistIdReady) {
|
||||
$relStmt = $db->prepare("
|
||||
SELECT id, title, slug, release_date, cover_url, artist_name
|
||||
FROM ac_releases
|
||||
WHERE is_published = 1
|
||||
AND (artist_id = :artist_id OR artist_name = :artist_name)
|
||||
ORDER BY release_date DESC, created_at DESC
|
||||
LIMIT 2
|
||||
");
|
||||
$relStmt->execute([
|
||||
':artist_id' => (int)($artist['id'] ?? 0),
|
||||
':artist_name' => (string)($artist['name'] ?? ''),
|
||||
]);
|
||||
} else {
|
||||
$relStmt = $db->prepare("
|
||||
SELECT id, title, slug, release_date, cover_url, artist_name
|
||||
FROM ac_releases
|
||||
WHERE is_published = 1
|
||||
AND artist_name = :artist_name
|
||||
ORDER BY release_date DESC, created_at DESC
|
||||
LIMIT 2
|
||||
");
|
||||
$relStmt->execute([
|
||||
':artist_name' => (string)($artist['name'] ?? ''),
|
||||
]);
|
||||
}
|
||||
|
||||
$artistReleases = $relStmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
|
||||
} catch (Throwable $e) {
|
||||
$artistReleases = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Response($this->view->render('site/show.php', [
|
||||
'title' => $artist ? (string)$artist['name'] : 'Artist Profile',
|
||||
'artist' => $artist,
|
||||
'artist_releases' => $artistReleases,
|
||||
]));
|
||||
}
|
||||
|
||||
public function adminIndex(): Response
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return new Response('', 302, ['Location' => '/admin/login']);
|
||||
}
|
||||
if (!Auth::hasRole(['admin', 'manager'])) {
|
||||
return new Response('', 302, ['Location' => '/admin']);
|
||||
}
|
||||
$tableReady = $this->artistsTableReady();
|
||||
$socialReady = $this->socialColumnReady();
|
||||
$artists = [];
|
||||
$pageId = 0;
|
||||
$pagePublished = 0;
|
||||
if ($tableReady) {
|
||||
$db = Database::get();
|
||||
if ($db instanceof PDO) {
|
||||
$stmt = $db->query("SELECT id, name, slug, country, avatar_url, is_active FROM ac_artists ORDER BY created_at DESC");
|
||||
$artists = $stmt ? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
|
||||
$pageStmt = $db->prepare("SELECT id, is_published FROM ac_pages WHERE slug = 'artists' LIMIT 1");
|
||||
$pageStmt->execute();
|
||||
$pageRow = $pageStmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($pageRow) {
|
||||
$pageId = (int)($pageRow['id'] ?? 0);
|
||||
$pagePublished = (int)($pageRow['is_published'] ?? 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Response($this->view->render('admin/index.php', [
|
||||
'title' => 'Artists',
|
||||
'table_ready' => $tableReady,
|
||||
'social_ready' => $socialReady,
|
||||
'artists' => $artists,
|
||||
'page_id' => $pageId,
|
||||
'page_published' => $pagePublished,
|
||||
]));
|
||||
}
|
||||
|
||||
public function adminNew(): Response
|
||||
{
|
||||
return $this->adminEdit(0);
|
||||
}
|
||||
|
||||
public function adminEdit(int $id = 0): Response
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return new Response('', 302, ['Location' => '/admin/login']);
|
||||
}
|
||||
if (!Auth::hasRole(['admin', 'manager'])) {
|
||||
return new Response('', 302, ['Location' => '/admin']);
|
||||
}
|
||||
$artist = [
|
||||
'id' => 0,
|
||||
'name' => '',
|
||||
'slug' => '',
|
||||
'bio' => '',
|
||||
'credits' => '',
|
||||
'country' => '',
|
||||
'avatar_url' => '',
|
||||
'social_links' => '',
|
||||
'is_active' => 1,
|
||||
];
|
||||
if ($id > 0) {
|
||||
$db = Database::get();
|
||||
if ($db instanceof PDO) {
|
||||
$stmt = $db->prepare("SELECT * FROM ac_artists WHERE id = :id LIMIT 1");
|
||||
$stmt->execute([':id' => $id]);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row) {
|
||||
$artist = array_merge($artist, $row);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($_GET['avatar_url']) && $artist['avatar_url'] === '') {
|
||||
$artist['avatar_url'] = (string)$_GET['avatar_url'];
|
||||
}
|
||||
return new Response($this->view->render('admin/edit.php', [
|
||||
'title' => $id > 0 ? 'Edit Artist' : 'New Artist',
|
||||
'artist' => $artist,
|
||||
'error' => '',
|
||||
]));
|
||||
}
|
||||
|
||||
public function adminSave(): Response
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return new Response('', 302, ['Location' => '/admin/login']);
|
||||
}
|
||||
if (!Auth::hasRole(['admin', 'manager'])) {
|
||||
return new Response('', 302, ['Location' => '/admin']);
|
||||
}
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$name = trim((string)($_POST['name'] ?? ''));
|
||||
$slug = trim((string)($_POST['slug'] ?? ''));
|
||||
$bio = trim((string)($_POST['bio'] ?? ''));
|
||||
$credits = trim((string)($_POST['credits'] ?? ''));
|
||||
$country = trim((string)($_POST['country'] ?? ''));
|
||||
$avatarUrl = trim((string)($_POST['avatar_url'] ?? ''));
|
||||
$socialLinks = [
|
||||
'website' => $this->normalizeUrl(trim((string)($_POST['social_website'] ?? ''))),
|
||||
'instagram' => $this->normalizeUrl(trim((string)($_POST['social_instagram'] ?? ''))),
|
||||
'soundcloud' => $this->normalizeUrl(trim((string)($_POST['social_soundcloud'] ?? ''))),
|
||||
'spotify' => $this->normalizeUrl(trim((string)($_POST['social_spotify'] ?? ''))),
|
||||
'youtube' => $this->normalizeUrl(trim((string)($_POST['social_youtube'] ?? ''))),
|
||||
'tiktok' => $this->normalizeUrl(trim((string)($_POST['social_tiktok'] ?? ''))),
|
||||
'bandcamp' => $this->normalizeUrl(trim((string)($_POST['social_bandcamp'] ?? ''))),
|
||||
'beatport' => $this->normalizeUrl(trim((string)($_POST['social_beatport'] ?? ''))),
|
||||
'facebook' => $this->normalizeUrl(trim((string)($_POST['social_facebook'] ?? ''))),
|
||||
'x' => $this->normalizeUrl(trim((string)($_POST['social_x'] ?? ''))),
|
||||
];
|
||||
$socialLinks = array_filter($socialLinks, static fn($value) => $value !== '');
|
||||
$socialJson = $socialLinks ? json_encode($socialLinks, JSON_UNESCAPED_SLASHES) : null;
|
||||
$socialReady = $this->socialColumnReady();
|
||||
$creditsReady = $this->creditsColumnReady();
|
||||
$isActive = isset($_POST['is_active']) ? 1 : 0;
|
||||
|
||||
if ($name === '') {
|
||||
return $this->saveError($id, 'Name is required.');
|
||||
}
|
||||
$slug = $slug !== '' ? $this->slugify($slug) : $this->slugify($name);
|
||||
|
||||
$db = Database::get();
|
||||
if (!$db instanceof PDO) {
|
||||
return $this->saveError($id, 'Database unavailable.');
|
||||
}
|
||||
|
||||
$dupStmt = $id > 0
|
||||
? $db->prepare("SELECT id FROM ac_artists WHERE slug = :slug AND id != :id LIMIT 1")
|
||||
: $db->prepare("SELECT id FROM ac_artists WHERE slug = :slug LIMIT 1");
|
||||
$params = $id > 0 ? [':slug' => $slug, ':id' => $id] : [':slug' => $slug];
|
||||
$dupStmt->execute($params);
|
||||
if ($dupStmt->fetch()) {
|
||||
return $this->saveError($id, 'Slug already exists.');
|
||||
}
|
||||
|
||||
try {
|
||||
if ($id > 0) {
|
||||
$stmt = $db->prepare("
|
||||
UPDATE ac_artists
|
||||
SET name = :name, slug = :slug, bio = :bio" . ($creditsReady ? ", credits = :credits" : "") . ", country = :country,
|
||||
avatar_url = :avatar_url" . ($socialReady ? ", social_links = :social_links" : "") . ",
|
||||
is_active = :is_active
|
||||
WHERE id = :id
|
||||
");
|
||||
$params = [
|
||||
':name' => $name,
|
||||
':slug' => $slug,
|
||||
':bio' => $bio !== '' ? $bio : null,
|
||||
':country' => $country !== '' ? $country : null,
|
||||
':avatar_url' => $avatarUrl !== '' ? $avatarUrl : null,
|
||||
':is_active' => $isActive,
|
||||
':id' => $id,
|
||||
];
|
||||
if ($creditsReady) {
|
||||
$params[':credits'] = $credits !== '' ? $credits : null;
|
||||
}
|
||||
if ($socialReady) {
|
||||
$params[':social_links'] = $socialJson;
|
||||
}
|
||||
$stmt->execute($params);
|
||||
} else {
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO ac_artists (name, slug, bio" . ($creditsReady ? ", credits" : "") . ", country, avatar_url" . ($socialReady ? ", social_links" : "") . ", is_active)
|
||||
VALUES (:name, :slug, :bio" . ($creditsReady ? ", :credits" : "") . ", :country, :avatar_url" . ($socialReady ? ", :social_links" : "") . ", :is_active)
|
||||
");
|
||||
$params = [
|
||||
':name' => $name,
|
||||
':slug' => $slug,
|
||||
':bio' => $bio !== '' ? $bio : null,
|
||||
':country' => $country !== '' ? $country : null,
|
||||
':avatar_url' => $avatarUrl !== '' ? $avatarUrl : null,
|
||||
':is_active' => $isActive,
|
||||
];
|
||||
if ($creditsReady) {
|
||||
$params[':credits'] = $credits !== '' ? $credits : null;
|
||||
}
|
||||
if ($socialReady) {
|
||||
$params[':social_links'] = $socialJson;
|
||||
}
|
||||
$stmt->execute($params);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
error_log('AC artists save error: ' . $e->getMessage());
|
||||
return $this->saveError($id, 'Unable to save artist. Check table columns and input.');
|
||||
}
|
||||
|
||||
return new Response('', 302, ['Location' => '/admin/artists']);
|
||||
}
|
||||
|
||||
public function adminDelete(): Response
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return new Response('', 302, ['Location' => '/admin/login']);
|
||||
}
|
||||
if (!Auth::hasRole(['admin', 'manager'])) {
|
||||
return new Response('', 302, ['Location' => '/admin']);
|
||||
}
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$db = Database::get();
|
||||
if ($db instanceof PDO && $id > 0) {
|
||||
$stmt = $db->prepare("DELETE FROM ac_artists WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
}
|
||||
return new Response('', 302, ['Location' => '/admin/artists']);
|
||||
}
|
||||
|
||||
public function adminUpload(): Response
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return new Response('', 302, ['Location' => '/admin/login']);
|
||||
}
|
||||
if (!Auth::hasRole(['admin', 'manager'])) {
|
||||
return new Response('', 302, ['Location' => '/admin']);
|
||||
}
|
||||
$file = $_FILES['artist_avatar'] ?? null;
|
||||
$artistId = (int)($_POST['artist_id'] ?? 0);
|
||||
if (!$file || !isset($file['tmp_name'])) {
|
||||
return $this->uploadRedirect($artistId);
|
||||
}
|
||||
if ($file['error'] !== UPLOAD_ERR_OK) {
|
||||
return $this->uploadRedirect($artistId, $this->uploadErrorMessage((int)$file['error']));
|
||||
}
|
||||
|
||||
$tmp = (string)$file['tmp_name'];
|
||||
if ($tmp === '' || !is_uploaded_file($tmp)) {
|
||||
return $this->uploadRedirect($artistId);
|
||||
}
|
||||
|
||||
$info = getimagesize($tmp);
|
||||
if ($info === false) {
|
||||
return $this->uploadRedirect($artistId, 'Avatar must be an image.');
|
||||
}
|
||||
$ext = image_type_to_extension($info[2], false);
|
||||
$allowed = ['jpg', 'jpeg', 'png', 'webp'];
|
||||
if (!in_array($ext, $allowed, true)) {
|
||||
return $this->uploadRedirect($artistId, 'Avatar must be JPG, PNG, or WEBP.');
|
||||
}
|
||||
|
||||
$uploadDir = __DIR__ . '/../../uploads/media';
|
||||
if (!is_dir($uploadDir) && !mkdir($uploadDir, 0755, true)) {
|
||||
return $this->uploadRedirect($artistId, 'Upload directory is not writable.');
|
||||
}
|
||||
if (!is_writable($uploadDir)) {
|
||||
return $this->uploadRedirect($artistId, 'Upload directory is not writable.');
|
||||
}
|
||||
|
||||
$baseName = preg_replace('~[^a-z0-9]+~', '-', strtolower((string)$file['name'])) ?? 'avatar';
|
||||
$baseName = trim($baseName, '-');
|
||||
$fileName = ($baseName !== '' ? $baseName : 'avatar') . '-' . date('YmdHis') . '.' . $ext;
|
||||
$dest = $uploadDir . '/' . $fileName;
|
||||
if (!move_uploaded_file($tmp, $dest)) {
|
||||
return $this->uploadRedirect($artistId, 'Upload failed.');
|
||||
}
|
||||
|
||||
$fileUrl = '/uploads/media/' . $fileName;
|
||||
$fileType = (string)($file['type'] ?? '');
|
||||
$fileSize = (int)($file['size'] ?? 0);
|
||||
|
||||
$db = Database::get();
|
||||
if ($db instanceof PDO) {
|
||||
try {
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO ac_media (file_name, file_url, file_type, file_size, folder_id)
|
||||
VALUES (:name, :url, :type, :size, NULL)
|
||||
");
|
||||
$stmt->execute([
|
||||
':name' => (string)$file['name'],
|
||||
':url' => $fileUrl,
|
||||
':type' => $fileType,
|
||||
':size' => $fileSize,
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($artistId > 0 && $db instanceof PDO) {
|
||||
$stmt = $db->prepare("UPDATE ac_artists SET avatar_url = :url WHERE id = :id");
|
||||
$stmt->execute([':url' => $fileUrl, ':id' => $artistId]);
|
||||
}
|
||||
|
||||
return $this->uploadRedirect($artistId, '', $fileUrl);
|
||||
}
|
||||
|
||||
public function adminInstall(): Response
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return new Response('', 302, ['Location' => '/admin/login']);
|
||||
}
|
||||
if (!Auth::hasRole(['admin', 'manager'])) {
|
||||
return new Response('', 302, ['Location' => '/admin']);
|
||||
}
|
||||
|
||||
$db = Database::get();
|
||||
if ($db instanceof PDO) {
|
||||
try {
|
||||
$db->exec("
|
||||
CREATE TABLE IF NOT EXISTS ac_artists (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(200) NOT NULL,
|
||||
slug VARCHAR(200) NOT NULL UNIQUE,
|
||||
bio MEDIUMTEXT NULL,
|
||||
credits MEDIUMTEXT NULL,
|
||||
country VARCHAR(120) NULL,
|
||||
avatar_url VARCHAR(255) NULL,
|
||||
social_links TEXT NULL,
|
||||
is_active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
");
|
||||
$db->exec("ALTER TABLE ac_artists ADD COLUMN credits MEDIUMTEXT NULL");
|
||||
$db->exec("ALTER TABLE ac_artists ADD COLUMN social_links TEXT NULL");
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
}
|
||||
|
||||
return new Response('', 302, ['Location' => '/admin/artists']);
|
||||
}
|
||||
|
||||
private function artistsTableReady(): bool
|
||||
{
|
||||
$db = Database::get();
|
||||
if (!$db instanceof PDO) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$stmt = $db->query("SELECT 1 FROM ac_artists LIMIT 1");
|
||||
return $stmt !== false;
|
||||
} catch (Throwable $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function socialColumnReady(): bool
|
||||
{
|
||||
$db = Database::get();
|
||||
if (!$db instanceof PDO) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$stmt = $db->query("SHOW COLUMNS FROM ac_artists LIKE 'social_links'");
|
||||
$row = $stmt ? $stmt->fetch(PDO::FETCH_ASSOC) : null;
|
||||
return (bool)$row;
|
||||
} catch (Throwable $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function creditsColumnReady(): bool
|
||||
{
|
||||
$db = Database::get();
|
||||
if (!$db instanceof PDO) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$stmt = $db->query("SHOW COLUMNS FROM ac_artists LIKE 'credits'");
|
||||
$row = $stmt ? $stmt->fetch(PDO::FETCH_ASSOC) : null;
|
||||
return (bool)$row;
|
||||
} catch (Throwable $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function saveError(int $id, string $message): Response
|
||||
{
|
||||
return new Response($this->view->render('admin/edit.php', [
|
||||
'title' => $id > 0 ? 'Edit Artist' : 'New Artist',
|
||||
'artist' => [
|
||||
'id' => $id,
|
||||
'name' => (string)($_POST['name'] ?? ''),
|
||||
'slug' => (string)($_POST['slug'] ?? ''),
|
||||
'bio' => (string)($_POST['bio'] ?? ''),
|
||||
'credits' => (string)($_POST['credits'] ?? ''),
|
||||
'country' => (string)($_POST['country'] ?? ''),
|
||||
'avatar_url' => (string)($_POST['avatar_url'] ?? ''),
|
||||
'social_links' => '',
|
||||
'is_active' => isset($_POST['is_active']) ? 1 : 0,
|
||||
],
|
||||
'error' => $message,
|
||||
]));
|
||||
}
|
||||
|
||||
private function slugify(string $value): string
|
||||
{
|
||||
$value = strtolower(trim($value));
|
||||
$value = preg_replace('~[^a-z0-9]+~', '-', $value) ?? $value;
|
||||
$value = trim($value, '-');
|
||||
return $value !== '' ? $value : 'artist';
|
||||
}
|
||||
|
||||
private function uploadRedirect(int $artistId, string $error = '', string $url = ''): Response
|
||||
{
|
||||
if ($artistId > 0) {
|
||||
$target = '/admin/artists/edit?id=' . $artistId;
|
||||
} else {
|
||||
$target = '/admin/artists/new';
|
||||
}
|
||||
if ($url !== '') {
|
||||
$target .= '&avatar_url=' . rawurlencode($url);
|
||||
}
|
||||
if ($error !== '') {
|
||||
$target .= '&upload_error=' . rawurlencode($error);
|
||||
}
|
||||
return new Response('', 302, ['Location' => $target]);
|
||||
}
|
||||
|
||||
private function uploadErrorMessage(int $code): string
|
||||
{
|
||||
$max = (string)ini_get('upload_max_filesize');
|
||||
$map = [
|
||||
UPLOAD_ERR_INI_SIZE => "File exceeds upload_max_filesize ({$max}).",
|
||||
UPLOAD_ERR_FORM_SIZE => 'File exceeds form limit.',
|
||||
UPLOAD_ERR_PARTIAL => 'File was only partially uploaded.',
|
||||
UPLOAD_ERR_NO_TMP_DIR => 'Missing temp upload directory.',
|
||||
UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.',
|
||||
UPLOAD_ERR_EXTENSION => 'Upload stopped by a PHP extension.',
|
||||
UPLOAD_ERR_NO_FILE => 'No file uploaded.',
|
||||
];
|
||||
return $map[$code] ?? 'Upload failed.';
|
||||
}
|
||||
|
||||
private function normalizeUrl(string $value): string
|
||||
{
|
||||
if ($value === '') {
|
||||
return '';
|
||||
}
|
||||
if (preg_match('~^(https?://)~i', $value)) {
|
||||
return $value;
|
||||
}
|
||||
return 'https://' . $value;
|
||||
}
|
||||
}
|
||||
21
plugins/artists/plugin.json
Normal file
21
plugins/artists/plugin.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Artists",
|
||||
"version": "0.1.0",
|
||||
"description": "Public artist listings and profiles.",
|
||||
"author": "AudioCore",
|
||||
"admin_nav": {
|
||||
"label": "Artists",
|
||||
"url": "/admin/artists",
|
||||
"roles": ["admin", "manager"],
|
||||
"icon": "fa-solid fa-user"
|
||||
},
|
||||
"pages": [
|
||||
{
|
||||
"slug": "artists",
|
||||
"title": "Artists",
|
||||
"content_html": "<section class=\"card\"><div class=\"badge\">Artists</div><h1 style=\"margin-top:16px; font-size:28px;\">Artists</h1><p style=\"color:var(--muted);\">Add your artist roster here.</p></section>"
|
||||
}
|
||||
],
|
||||
"entry": "plugin.php",
|
||||
"default_enabled": false
|
||||
}
|
||||
23
plugins/artists/plugin.php
Normal file
23
plugins/artists/plugin.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Core\Http\Router;
|
||||
use Plugins\Artists\ArtistsController;
|
||||
|
||||
require_once __DIR__ . '/ArtistsController.php';
|
||||
|
||||
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']);
|
||||
};
|
||||
129
plugins/artists/views/admin/edit.php
Normal file
129
plugins/artists/views/admin/edit.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
$pageTitle = $title ?? 'Edit Artist';
|
||||
$artist = $artist ?? [];
|
||||
$error = $error ?? '';
|
||||
$uploadError = (string)($_GET['upload_error'] ?? '');
|
||||
$socialLinks = [];
|
||||
if (!empty($artist['social_links'])) {
|
||||
$decoded = json_decode((string)$artist['social_links'], true);
|
||||
if (is_array($decoded)) {
|
||||
$socialLinks = $decoded;
|
||||
}
|
||||
}
|
||||
ob_start();
|
||||
?>
|
||||
<section class="admin-card">
|
||||
<div class="badge">Artists</div>
|
||||
<div style="display:flex; align-items:center; justify-content:space-between; gap:16px; margin-top:16px;">
|
||||
<div>
|
||||
<h1 style="font-size:28px; margin:0;"><?= htmlspecialchars($pageTitle, ENT_QUOTES, 'UTF-8') ?></h1>
|
||||
<p style="color: var(--muted); margin-top:6px;">Create or update an artist profile.</p>
|
||||
</div>
|
||||
<a href="/admin/artists" class="btn outline">Back</a>
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div style="margin-top:16px; color:#f3b0b0; font-size:13px;"><?= htmlspecialchars($error, ENT_QUOTES, 'UTF-8') ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($uploadError !== ''): ?>
|
||||
<div style="margin-top:12px; color:#f3b0b0; font-size:13px;"><?= htmlspecialchars($uploadError, ENT_QUOTES, 'UTF-8') ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="/admin/artists/upload" enctype="multipart/form-data" id="artistAvatarUpload" style="margin-top:18px;">
|
||||
<div class="admin-card" style="padding:14px; background: rgba(10,10,12,0.6);">
|
||||
<div class="label">Upload avatar</div>
|
||||
<input type="hidden" name="artist_id" value="<?= (int)($artist['id'] ?? 0) ?>">
|
||||
<label for="artistAvatarFile" id="artistAvatarDropzone" style="display:flex; flex-direction:column; gap:8px; align-items:center; justify-content:center; padding:18px; border-radius:14px; border:1px dashed rgba(255,255,255,0.2); background: rgba(0,0,0,0.2); cursor:pointer;">
|
||||
<div style="font-size:11px; text-transform:uppercase; letter-spacing:0.2em; color:var(--muted);">Drag & Drop</div>
|
||||
<div style="font-size:13px; color:var(--text);">or click to upload</div>
|
||||
<div id="artistAvatarFileName" style="font-size:11px; color:var(--muted);">No file selected</div>
|
||||
</label>
|
||||
<input class="input" type="file" id="artistAvatarFile" name="artist_avatar" accept="image/*" style="display:none;">
|
||||
<div style="margin-top:10px; display:flex; justify-content:flex-end;">
|
||||
<button type="submit" class="btn small">Upload</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form method="post" action="/admin/artists/save" style="margin-top:16px; display:grid; gap:16px;">
|
||||
<input type="hidden" name="id" value="<?= (int)($artist['id'] ?? 0) ?>">
|
||||
<div class="admin-card" style="padding:16px;">
|
||||
<div style="display:grid; gap:12px;">
|
||||
<label class="label">Name</label>
|
||||
<input class="input" name="name" value="<?= htmlspecialchars((string)($artist['name'] ?? ''), ENT_QUOTES, 'UTF-8') ?>" placeholder="Artist name">
|
||||
<label class="label">Slug</label>
|
||||
<input class="input" name="slug" value="<?= htmlspecialchars((string)($artist['slug'] ?? ''), ENT_QUOTES, 'UTF-8') ?>" placeholder="artist-name">
|
||||
<label class="label">Country</label>
|
||||
<input class="input" name="country" value="<?= htmlspecialchars((string)($artist['country'] ?? ''), ENT_QUOTES, 'UTF-8') ?>" placeholder="UK">
|
||||
<div style="display:flex; align-items:center; justify-content:space-between; gap:12px;">
|
||||
<label class="label" style="margin:0;">Avatar URL</label>
|
||||
<button type="button" class="btn outline small" data-media-picker="artist_avatar_url" data-media-picker-mode="url">Pick from Media</button>
|
||||
</div>
|
||||
<input class="input" id="artist_avatar_url" name="avatar_url" value="<?= htmlspecialchars((string)($artist['avatar_url'] ?? ''), ENT_QUOTES, 'UTF-8') ?>" placeholder="https://...">
|
||||
<label class="label">Bio</label>
|
||||
<textarea class="input" name="bio" rows="6" style="resize:vertical; font-family:'IBM Plex Mono', monospace; font-size:13px; line-height:1.6;"><?= htmlspecialchars((string)($artist['bio'] ?? ''), ENT_QUOTES, 'UTF-8') ?></textarea>
|
||||
<label class="label">Artist Credits</label>
|
||||
<textarea class="input" name="credits" rows="4" style="resize:vertical; font-family:'IBM Plex Mono', monospace; font-size:13px; line-height:1.6;" placeholder="Written by..., Vocals by..., Produced by..."><?= htmlspecialchars((string)($artist['credits'] ?? ''), ENT_QUOTES, 'UTF-8') ?></textarea>
|
||||
<div class="admin-card" style="padding:14px; background: rgba(10,10,12,0.6);">
|
||||
<div class="label">Social Links</div>
|
||||
<div style="margin-top:10px; display:grid; gap:10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));">
|
||||
<input class="input" name="social_website" placeholder="Website URL" value="<?= htmlspecialchars((string)($socialLinks['website'] ?? ''), ENT_QUOTES, 'UTF-8') ?>">
|
||||
<input class="input" name="social_instagram" placeholder="Instagram URL" value="<?= htmlspecialchars((string)($socialLinks['instagram'] ?? ''), ENT_QUOTES, 'UTF-8') ?>">
|
||||
<input class="input" name="social_soundcloud" placeholder="SoundCloud URL" value="<?= htmlspecialchars((string)($socialLinks['soundcloud'] ?? ''), ENT_QUOTES, 'UTF-8') ?>">
|
||||
<input class="input" name="social_spotify" placeholder="Spotify URL" value="<?= htmlspecialchars((string)($socialLinks['spotify'] ?? ''), ENT_QUOTES, 'UTF-8') ?>">
|
||||
<input class="input" name="social_youtube" placeholder="YouTube URL" value="<?= htmlspecialchars((string)($socialLinks['youtube'] ?? ''), ENT_QUOTES, 'UTF-8') ?>">
|
||||
<input class="input" name="social_tiktok" placeholder="TikTok URL" value="<?= htmlspecialchars((string)($socialLinks['tiktok'] ?? ''), ENT_QUOTES, 'UTF-8') ?>">
|
||||
<input class="input" name="social_bandcamp" placeholder="Bandcamp URL" value="<?= htmlspecialchars((string)($socialLinks['bandcamp'] ?? ''), ENT_QUOTES, 'UTF-8') ?>">
|
||||
<input class="input" name="social_beatport" placeholder="Beatport URL" value="<?= htmlspecialchars((string)($socialLinks['beatport'] ?? ''), ENT_QUOTES, 'UTF-8') ?>">
|
||||
<input class="input" name="social_facebook" placeholder="Facebook URL" value="<?= htmlspecialchars((string)($socialLinks['facebook'] ?? ''), ENT_QUOTES, 'UTF-8') ?>">
|
||||
<input class="input" name="social_x" placeholder="X / Twitter URL" value="<?= htmlspecialchars((string)($socialLinks['x'] ?? ''), ENT_QUOTES, 'UTF-8') ?>">
|
||||
</div>
|
||||
</div>
|
||||
<label style="display:flex; align-items:center; gap:8px; font-size:12px; color:var(--muted); text-transform:uppercase; letter-spacing:0.2em;">
|
||||
<input type="checkbox" name="is_active" value="1" <?= ((int)($artist['is_active'] ?? 1) === 1) ? 'checked' : '' ?>>
|
||||
Active
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display:flex; justify-content:flex-end; gap:12px; align-items:center;">
|
||||
<button type="submit" class="btn">Save artist</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</section>
|
||||
<script>
|
||||
(function () {
|
||||
const dropzone = document.getElementById('artistAvatarDropzone');
|
||||
const fileInput = document.getElementById('artistAvatarFile');
|
||||
const fileName = document.getElementById('artistAvatarFileName');
|
||||
if (!dropzone || !fileInput || !fileName) {
|
||||
return;
|
||||
}
|
||||
|
||||
dropzone.addEventListener('dragover', (event) => {
|
||||
event.preventDefault();
|
||||
dropzone.style.borderColor = 'var(--accent)';
|
||||
});
|
||||
|
||||
dropzone.addEventListener('dragleave', () => {
|
||||
dropzone.style.borderColor = 'rgba(255,255,255,0.2)';
|
||||
});
|
||||
|
||||
dropzone.addEventListener('drop', (event) => {
|
||||
event.preventDefault();
|
||||
dropzone.style.borderColor = 'rgba(255,255,255,0.2)';
|
||||
if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files.length) {
|
||||
fileInput.files = event.dataTransfer.files;
|
||||
fileName.textContent = event.dataTransfer.files[0].name;
|
||||
}
|
||||
});
|
||||
|
||||
fileInput.addEventListener('change', () => {
|
||||
fileName.textContent = fileInput.files.length ? fileInput.files[0].name : 'No file selected';
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
<?php
|
||||
$content = ob_get_clean();
|
||||
require __DIR__ . '/../../../../modules/admin/views/layout.php';
|
||||
97
plugins/artists/views/admin/index.php
Normal file
97
plugins/artists/views/admin/index.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
$pageTitle = 'Artists';
|
||||
$tableReady = $table_ready ?? false;
|
||||
$artists = $artists ?? [];
|
||||
$pageId = (int)($page_id ?? 0);
|
||||
$pagePublished = (int)($page_published ?? 0);
|
||||
$socialReady = (bool)($social_ready ?? false);
|
||||
ob_start();
|
||||
?>
|
||||
<section class="admin-card">
|
||||
<div class="badge">Artists</div>
|
||||
<div style="display:flex; align-items:center; justify-content:space-between; gap:16px; margin-top:16px;">
|
||||
<div>
|
||||
<h1 style="font-size:28px; margin:0;">Artists</h1>
|
||||
<p style="color: var(--muted); margin-top:6px;">Artists plugin admin placeholder.</p>
|
||||
</div>
|
||||
<a href="/admin/artists/new" class="btn">New Artist</a>
|
||||
</div>
|
||||
|
||||
<?php if (!$tableReady): ?>
|
||||
<div class="admin-card" style="margin-top:16px; padding:16px; display:flex; align-items:center; justify-content:space-between; gap:16px;">
|
||||
<div>
|
||||
<div style="font-weight:600;">Database not initialized</div>
|
||||
<div style="color: var(--muted); font-size:13px; margin-top:4px;">Create the artists table before adding records.</div>
|
||||
</div>
|
||||
<form method="post" action="/admin/artists/install">
|
||||
<button type="submit" class="btn small">Create Tables</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<?php if (!$socialReady): ?>
|
||||
<div class="admin-card" style="margin-top:16px; padding:14px; display:flex; align-items:center; justify-content:space-between; gap:16px;">
|
||||
<div>
|
||||
<div style="font-weight:600;">Social links not enabled</div>
|
||||
<div style="color: var(--muted); font-size:12px; margin-top:4px;">Click create tables to add the social links column.</div>
|
||||
</div>
|
||||
<form method="post" action="/admin/artists/install">
|
||||
<button type="submit" class="btn small">Update Table</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="admin-card" style="margin-top:16px; padding:14px; display:flex; align-items:center; justify-content:space-between; gap:16px;">
|
||||
<div>
|
||||
<div style="font-weight:600;">Artists page</div>
|
||||
<div style="color: var(--muted); font-size:12px; margin-top:4px;">
|
||||
Slug: <code>artists</code>
|
||||
<?php if ($pageId > 0): ?>
|
||||
· Status: <?= $pagePublished === 1 ? 'Published' : 'Draft' ?>
|
||||
<?php else: ?>
|
||||
· Not created
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($pageId > 0): ?>
|
||||
<a href="/admin/pages/edit?id=<?= $pageId ?>" class="btn outline small">Edit Page Content</a>
|
||||
<?php else: ?>
|
||||
<span class="pill">Re-enable plugin to create</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if (!$artists): ?>
|
||||
<div style="margin-top:18px; color: var(--muted); font-size:13px;">No artists yet.</div>
|
||||
<?php else: ?>
|
||||
<div style="margin-top:18px; display:grid; gap:12px;">
|
||||
<?php foreach ($artists as $artist): ?>
|
||||
<div class="admin-card" style="padding:14px; display:flex; align-items:center; justify-content:space-between; gap:16px;">
|
||||
<div style="display:flex; gap:12px; align-items:center;">
|
||||
<div style="width:44px; height:44px; border-radius:12px; overflow:hidden; background:rgba(255,255,255,0.06); display:grid; place-items:center;">
|
||||
<?php if (!empty($artist['avatar_url'])): ?>
|
||||
<img src="<?= htmlspecialchars((string)$artist['avatar_url'], ENT_QUOTES, 'UTF-8') ?>" alt="" style="width:100%; height:100%; object-fit:cover;">
|
||||
<?php else: ?>
|
||||
<span style="font-size:12px; color:var(--muted);">N/A</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div>
|
||||
<div style="font-weight:600;"><?= htmlspecialchars((string)$artist['name'], ENT_QUOTES, 'UTF-8') ?></div>
|
||||
<div style="font-size:12px; color:var(--muted);"><?= htmlspecialchars((string)$artist['slug'], ENT_QUOTES, 'UTF-8') ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="display:flex; gap:8px; align-items:center;">
|
||||
<?php if ((int)$artist['is_active'] !== 1): ?>
|
||||
<span class="pill">Inactive</span>
|
||||
<?php endif; ?>
|
||||
<a href="/admin/artists/edit?id=<?= (int)$artist['id'] ?>" class="btn outline small">Edit</a>
|
||||
<form method="post" action="/admin/artists/delete" onsubmit="return confirm('Delete this artist?');">
|
||||
<input type="hidden" name="id" value="<?= (int)$artist['id'] ?>">
|
||||
<button type="submit" class="btn outline small">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
<?php
|
||||
$content = ob_get_clean();
|
||||
require __DIR__ . '/../../../../modules/admin/views/layout.php';
|
||||
236
plugins/artists/views/site/index.php
Normal file
236
plugins/artists/views/site/index.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
$pageTitle = $title ?? 'Artists';
|
||||
$artists = $artists ?? [];
|
||||
|
||||
function ac_country_code(string $country): string {
|
||||
$code = strtoupper(trim($country));
|
||||
if ($code === '') {
|
||||
return '';
|
||||
}
|
||||
if ($code === 'UK') {
|
||||
$code = 'GB';
|
||||
}
|
||||
if (!preg_match('/^[A-Z]{2}$/', $code)) {
|
||||
return '';
|
||||
}
|
||||
return strtolower($code);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<section class="card" style="display:grid; gap:18px;">
|
||||
<div style="display:flex; align-items:center; justify-content:space-between; gap:16px;">
|
||||
<div class="badge">Artists</div>
|
||||
<div class="view-toggle" role="group" aria-label="View toggle">
|
||||
<button type="button" class="view-btn active" id="artistGridBtn" aria-label="Grid view">
|
||||
<i class="fa-duotone fa-grid-round-2"></i>
|
||||
<span>Grid</span>
|
||||
</button>
|
||||
<button type="button" class="view-btn" id="artistListBtn" aria-label="List view">
|
||||
<i class="fa-duotone fa-list-ol"></i>
|
||||
<span>List</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!$artists): ?>
|
||||
<div style="color:var(--muted); font-size:14px;">No artists published yet.</div>
|
||||
<?php else: ?>
|
||||
<div id="artistView" class="artist-grid">
|
||||
<?php foreach ($artists as $artist): ?>
|
||||
<a class="artist-card" href="/artist?slug=<?= htmlspecialchars((string)$artist['slug'], ENT_QUOTES, 'UTF-8') ?>">
|
||||
<div class="artist-avatar">
|
||||
<?php if (!empty($artist['avatar_url'])): ?>
|
||||
<img src="<?= htmlspecialchars((string)$artist['avatar_url'], ENT_QUOTES, 'UTF-8') ?>" alt="">
|
||||
<?php else: ?>
|
||||
<div class="artist-avatar-placeholder">AC</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="artist-info">
|
||||
<div class="artist-name">
|
||||
<?= htmlspecialchars((string)$artist['name'], ENT_QUOTES, 'UTF-8') ?>
|
||||
</div>
|
||||
<?php $flag = ac_country_code((string)($artist['country'] ?? '')); ?>
|
||||
<?php if ($flag !== ''): ?>
|
||||
<div class="artist-meta">
|
||||
<span class="fi fi-<?= htmlspecialchars($flag, ENT_QUOTES, 'UTF-8') ?>"></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.artist-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
.artist-list {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
.artist-card {
|
||||
border-radius: 18px;
|
||||
padding: 6px;
|
||||
background: transparent;
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
color: inherit;
|
||||
}
|
||||
.artist-card:hover .artist-avatar {
|
||||
box-shadow: 0 12px 30px rgba(0,0,0,0.35);
|
||||
transform: scale(1.02);
|
||||
}
|
||||
.artist-card .artist-avatar {
|
||||
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
.artist-avatar {
|
||||
width: 140px;
|
||||
height: 140px;
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
background: rgba(255,255,255,0.06);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
.artist-avatar img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
.artist-avatar-placeholder {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
letter-spacing: 0.2em;
|
||||
}
|
||||
.artist-info {
|
||||
display: none;
|
||||
gap: 6px;
|
||||
}
|
||||
.artist-name {
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.artist-meta {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
display: inline-flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
.view-toggle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px;
|
||||
border-radius: 999px;
|
||||
background: rgba(10,10,12,0.6);
|
||||
border: 1px solid rgba(255,255,255,0.12);
|
||||
box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04);
|
||||
}
|
||||
.view-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid transparent;
|
||||
background: transparent;
|
||||
color: rgba(255,255,255,0.7);
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.2em;
|
||||
cursor: pointer;
|
||||
}
|
||||
.view-btn i {
|
||||
font-size: 12px;
|
||||
}
|
||||
.view-btn.active {
|
||||
background: linear-gradient(135deg, rgba(34,242,165,0.2), rgba(34,167,255,0.12));
|
||||
border-color: rgba(34,242,165,0.35);
|
||||
color: #f3fff9;
|
||||
box-shadow: 0 6px 16px rgba(34,242,165,0.2);
|
||||
}
|
||||
.view-btn:not(.active):hover {
|
||||
color: rgba(255,255,255,0.95);
|
||||
background: rgba(255,255,255,0.06);
|
||||
}
|
||||
.flag {
|
||||
font-size: 14px;
|
||||
}
|
||||
.artist-list .artist-card {
|
||||
grid-template-columns: 64px 1fr;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid rgba(255,255,255,0.08);
|
||||
background: rgba(12,12,14,0.5);
|
||||
}
|
||||
.artist-list .artist-avatar {
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
}
|
||||
.artist-list .artist-info {
|
||||
display: grid;
|
||||
}
|
||||
@media (max-width: 700px) {
|
||||
.artist-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
.artist-card {
|
||||
padding: 4px;
|
||||
}
|
||||
.artist-avatar {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
aspect-ratio: 1 / 1;
|
||||
}
|
||||
.view-btn span {
|
||||
display: none;
|
||||
}
|
||||
.view-btn {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
padding: 0;
|
||||
justify-content: center;
|
||||
}
|
||||
.artist-list .artist-card {
|
||||
grid-template-columns: 1fr;
|
||||
align-items: flex-start;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
(function () {
|
||||
const gridBtn = document.getElementById('artistGridBtn');
|
||||
const listBtn = document.getElementById('artistListBtn');
|
||||
const view = document.getElementById('artistView');
|
||||
if (!gridBtn || !listBtn || !view) {
|
||||
return;
|
||||
}
|
||||
gridBtn.addEventListener('click', () => {
|
||||
view.classList.add('artist-grid');
|
||||
view.classList.remove('artist-list');
|
||||
gridBtn.classList.add('active');
|
||||
listBtn.classList.remove('active');
|
||||
});
|
||||
listBtn.addEventListener('click', () => {
|
||||
view.classList.add('artist-list');
|
||||
view.classList.remove('artist-grid');
|
||||
listBtn.classList.add('active');
|
||||
gridBtn.classList.remove('active');
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
<?php
|
||||
$content = ob_get_clean();
|
||||
require __DIR__ . '/../../../../views/site/layout.php';
|
||||
239
plugins/artists/views/site/show.php
Normal file
239
plugins/artists/views/site/show.php
Normal file
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
use Core\Services\Settings;
|
||||
|
||||
$pageTitle = $title ?? 'Artist';
|
||||
$artist = $artist ?? null;
|
||||
$proUrl = Settings::get('fontawesome_pro_url', '');
|
||||
$faUrl = $proUrl !== '' ? $proUrl : Settings::get('fontawesome_url', '');
|
||||
$hasPro = $proUrl !== '';
|
||||
$hasIcons = $faUrl !== '';
|
||||
$artistReleases = is_array($artist_releases ?? null) ? $artist_releases : [];
|
||||
$socialLinks = [];
|
||||
if ($artist && !empty($artist['social_links'])) {
|
||||
$decoded = json_decode((string)$artist['social_links'], true);
|
||||
if (is_array($decoded)) {
|
||||
$socialLinks = $decoded;
|
||||
}
|
||||
}
|
||||
$iconMap = [
|
||||
'website' => ['label' => 'Website', 'icon' => 'fa-duotone fa-globe-pointer'],
|
||||
'instagram' => ['label' => 'Instagram', 'icon' => 'fa-brands fa-instagram'],
|
||||
'soundcloud' => ['label' => 'SoundCloud', 'icon' => 'fa-brands fa-soundcloud'],
|
||||
'spotify' => ['label' => 'Spotify', 'icon' => 'fa-brands fa-spotify'],
|
||||
'youtube' => ['label' => 'YouTube', 'icon' => 'fa-brands fa-youtube'],
|
||||
'tiktok' => ['label' => 'TikTok', 'icon' => 'fa-brands fa-tiktok'],
|
||||
'bandcamp' => ['label' => 'Bandcamp', 'icon' => 'fa-brands fa-bandcamp'],
|
||||
'beatport' => ['label' => 'Beatport', 'icon' => 'fa-solid fa-music'],
|
||||
'facebook' => ['label' => 'Facebook', 'icon' => 'fa-brands fa-facebook'],
|
||||
'x' => ['label' => 'X', 'icon' => 'fa-brands fa-x-twitter'],
|
||||
];
|
||||
function ac_normalize_url(string $value): string {
|
||||
if ($value === '') {
|
||||
return '';
|
||||
}
|
||||
if (preg_match('~^(https?://)~i', $value)) {
|
||||
return $value;
|
||||
}
|
||||
return 'https://' . $value;
|
||||
}
|
||||
ob_start();
|
||||
?>
|
||||
<section class="card" style="display:grid; gap:16px;">
|
||||
<div class="badge">Artist</div>
|
||||
<?php if (!$artist): ?>
|
||||
<h1 style="margin:0; font-size:28px;">Artist not found</h1>
|
||||
<p style="color:var(--muted);">This profile is unavailable.</p>
|
||||
<?php else: ?>
|
||||
<div style="display:grid; gap:18px;">
|
||||
<div style="display:flex; align-items:center; gap:20px;">
|
||||
<div style="width:160px; height:160px; border-radius:24px; overflow:hidden; background:rgba(255,255,255,0.06); display:grid; place-items:center;">
|
||||
<?php if (!empty($artist['avatar_url'])): ?>
|
||||
<img src="<?= htmlspecialchars((string)$artist['avatar_url'], ENT_QUOTES, 'UTF-8') ?>" alt="" style="width:100%; height:100%; object-fit:cover;">
|
||||
<?php else: ?>
|
||||
<span style="font-size:12px; color:var(--muted); letter-spacing:0.2em;">AC</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div>
|
||||
<div class="badge">Profile</div>
|
||||
<h1 style="margin:6px 0 0; font-size:34px;"><?= htmlspecialchars((string)$artist['name'], ENT_QUOTES, 'UTF-8') ?></h1>
|
||||
<?php if (!empty($artist['country'])): ?>
|
||||
<?php
|
||||
$code = strtolower((string)$artist['country']);
|
||||
if ($code === 'uk') { $code = 'gb'; }
|
||||
?>
|
||||
<div style="margin-top:8px; color:var(--muted); font-size:13px;">
|
||||
<span class="fi fi-<?= htmlspecialchars($code, ENT_QUOTES, 'UTF-8') ?>"></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($artist['bio'])): ?>
|
||||
<div style="color:var(--muted); line-height:1.7;">
|
||||
<?= nl2br(htmlspecialchars((string)$artist['bio'], ENT_QUOTES, 'UTF-8')) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($artist['credits'])): ?>
|
||||
<div style="padding:14px; border-radius:18px; border:1px solid rgba(255,255,255,0.08); background: rgba(0,0,0,0.25);">
|
||||
<div class="badge">Credits</div>
|
||||
<div style="margin-top:8px; color:var(--muted); line-height:1.7;">
|
||||
<?= nl2br(htmlspecialchars((string)$artist['credits'], ENT_QUOTES, 'UTF-8')) ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($socialLinks): ?>
|
||||
<div style="display:flex; flex-wrap:wrap; gap:10px;">
|
||||
<?php foreach ($socialLinks as $key => $url): ?>
|
||||
<?php
|
||||
$meta = $iconMap[$key] ?? ['label' => ucfirst($key), 'icon' => 'fa-solid fa-link'];
|
||||
$label = $meta['label'];
|
||||
$icon = $meta['icon'];
|
||||
$normalized = ac_normalize_url((string)$url);
|
||||
$safeUrl = htmlspecialchars($normalized, ENT_QUOTES, 'UTF-8');
|
||||
?>
|
||||
<?php if ($hasIcons && $icon !== ''): ?>
|
||||
<a class="pill social-icon" href="<?= $safeUrl ?>" target="_blank" rel="noopener" aria-label="<?= htmlspecialchars($label, ENT_QUOTES, 'UTF-8') ?>">
|
||||
<i class="<?= htmlspecialchars($icon, ENT_QUOTES, 'UTF-8') ?>"></i>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<a class="pill" href="<?= $safeUrl ?>" target="_blank" rel="noopener">
|
||||
<?= htmlspecialchars($label, ENT_QUOTES, 'UTF-8') ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($artistReleases): ?>
|
||||
<div class="artist-release-panel">
|
||||
<div class="artist-release-panel-head">
|
||||
<div class="badge">Latest Releases</div>
|
||||
<a href="/releases?artist=<?= urlencode((string)($artist['name'] ?? '')) ?>" class="badge artist-view-all-link">View all</a>
|
||||
</div>
|
||||
<div class="artist-release-grid">
|
||||
<?php foreach ($artistReleases as $release): ?>
|
||||
<a class="artist-release-card" href="/release?slug=<?= htmlspecialchars((string)($release['slug'] ?? ''), ENT_QUOTES, 'UTF-8') ?>">
|
||||
<div class="artist-release-cover">
|
||||
<?php if (!empty($release['cover_url'])): ?>
|
||||
<img src="<?= htmlspecialchars((string)$release['cover_url'], ENT_QUOTES, 'UTF-8') ?>" alt="">
|
||||
<?php else: ?>
|
||||
<span>AC</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="artist-release-meta">
|
||||
<div class="artist-release-title"><?= htmlspecialchars((string)($release['title'] ?? ''), ENT_QUOTES, 'UTF-8') ?></div>
|
||||
<?php if (!empty($release['release_date'])): ?>
|
||||
<div class="artist-release-date"><?= htmlspecialchars((string)$release['release_date'], ENT_QUOTES, 'UTF-8') ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.social-icon {
|
||||
color: var(--text);
|
||||
}
|
||||
.social-icon i {
|
||||
font-size: 14px;
|
||||
}
|
||||
.artist-release-panel {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
margin-top: 6px;
|
||||
padding: 14px;
|
||||
border-radius: 18px;
|
||||
border: 1px solid rgba(255,255,255,0.08);
|
||||
background: rgba(0,0,0,0.24);
|
||||
}
|
||||
.artist-release-panel-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
.artist-view-all-link {
|
||||
text-decoration: none;
|
||||
color: rgba(255,255,255,0.72);
|
||||
transition: color .18s ease;
|
||||
}
|
||||
.artist-view-all-link:hover {
|
||||
color: #ffffff;
|
||||
}
|
||||
.artist-release-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
.artist-release-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
border-radius: 12px;
|
||||
border: 1px solid rgba(255,255,255,0.08);
|
||||
background: rgba(0,0,0,0.22);
|
||||
padding: 8px;
|
||||
transition: transform .18s ease, border-color .18s ease, background .18s ease;
|
||||
}
|
||||
.artist-release-card:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: rgba(255,255,255,0.18);
|
||||
background: rgba(0,0,0,0.28);
|
||||
}
|
||||
.artist-release-cover {
|
||||
width: 58px;
|
||||
height: 58px;
|
||||
flex: 0 0 58px;
|
||||
border-radius: 9px;
|
||||
overflow: hidden;
|
||||
background: rgba(255,255,255,0.06);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
letter-spacing: .14em;
|
||||
}
|
||||
.artist-release-cover img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
.artist-release-title {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
line-height: 1.25;
|
||||
}
|
||||
.artist-release-date {
|
||||
margin-top: 4px;
|
||||
font-size: 10px;
|
||||
color: var(--muted);
|
||||
}
|
||||
.artist-release-meta {
|
||||
min-width: 0;
|
||||
}
|
||||
@media (max-width: 900px) {
|
||||
.artist-release-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
@media (max-width: 520px) {
|
||||
.artist-release-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.artist-release-card {
|
||||
padding: 7px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
$content = ob_get_clean();
|
||||
require __DIR__ . '/../../../../views/site/layout.php';
|
||||
Reference in New Issue
Block a user