263 lines
10 KiB
PHP
263 lines
10 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
include_once('src/storage.php');
|
|
include_once('src/telegram.php');
|
|
|
|
if (empty($_GET['id'])) {
|
|
$newId = bin2hex(random_bytes(16));
|
|
header("Location: ?id=$newId");
|
|
exit;
|
|
}
|
|
|
|
$id = htmlspecialchars($_GET['id']);
|
|
|
|
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
|
$bookmark = $protocol . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
|
|
|
|
$alerts = [
|
|
'primary' => [],
|
|
'success' => [],
|
|
'warning' => [],
|
|
'danger' => []
|
|
];
|
|
|
|
$data = ['img' => '', 'name' => '', 'url' => '', 'desc' => ''];
|
|
|
|
try {
|
|
$data = Storage::get($id);
|
|
}
|
|
catch(Exception $ex) {
|
|
$alerts['danger'][] = '❌ Error reading database';
|
|
}
|
|
|
|
$img = $data['img'];
|
|
// echo '<pre>'; print_r($img); echo '</pre>';
|
|
$name = $data['name'];
|
|
$url = $data['url'];
|
|
$desc = $data['desc'];
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] === 'POST' && isset($_GET['upload'])) {
|
|
http_response_code(202);
|
|
|
|
$targetDir = "uppies/";
|
|
$file = $_FILES["files"];
|
|
$targetFile = $targetDir . basename($file["name"][0]);
|
|
$imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));
|
|
|
|
// Create the uploads directory if it doesn't exist
|
|
if (!is_dir($targetDir)) {
|
|
mkdir($targetDir, 0775, true);
|
|
}
|
|
|
|
// Check if the file is actually an image
|
|
$check = getimagesize($file["tmp_name"][0]);
|
|
if ($check === false) {
|
|
exit("❌ Error: File is not a valid image.");
|
|
}
|
|
|
|
// Allow only specific image file formats
|
|
$allowedTypes = ["jpg", "jpeg", "png", "gif"];
|
|
if (!in_array($imageFileType, $allowedTypes)) {
|
|
exit("❌ Error: Only JPG, JPEG, PNG and GIF files allowed.");
|
|
}
|
|
|
|
// Limit file size (e.g., 5MB)
|
|
if ($file["size"][0] > 100 * 1024 * 1024) {
|
|
exit("❌ Error: File too large (max. 100 MB)");
|
|
}
|
|
|
|
// generate destination file name
|
|
$finalPath = $targetDir . $id . '.' . $imageFileType;
|
|
|
|
// Move uploaded file to the target directory
|
|
if (move_uploaded_file($file["tmp_name"][0], $finalPath)) {
|
|
try {
|
|
Storage::set_img($id, $id . '.' . $imageFileType);
|
|
}
|
|
catch(Exception $ex) {
|
|
exit("❌ Database error.");
|
|
}
|
|
|
|
http_response_code(200);
|
|
exit($finalPath);
|
|
}
|
|
|
|
exit("❌ General error saving the file.");
|
|
}
|
|
|
|
else if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['desc']) && isset($_POST['name']) && isset($_POST['url'])) {
|
|
$name = htmlspecialchars(trim($_POST['name']));
|
|
$url = htmlspecialchars(trim($_POST['url']));
|
|
$desc = htmlspecialchars(trim($_POST['desc']));
|
|
|
|
if (!empty($name) && !empty($desc) && !empty($url)) {
|
|
try {
|
|
Storage::set_data($id, $name, $url, $desc);
|
|
Telegram::report("EF Conbook Artist Credits Submission\nname: $name\nurl: $url\ntext:\n$desc");
|
|
$alerts['success'][] = '✅ Entry saved';
|
|
}
|
|
catch(Exception $ex) {
|
|
$alerts['danger'][] = $ex;
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html prefix="og: http://ogp.me/ns#" lang="en">
|
|
<head>
|
|
<title>Artist Credits</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<meta name="description" content="Submit Artist Credits to the Eurofurence Conbook Team" />
|
|
<meta name="keywords" content="eurofurence, Conbook, artist credits" />
|
|
<meta name="robots" content="index, follow, noodp" />
|
|
<meta name="author" content="The Eurofurence Conbook Team" />
|
|
<meta name="rating" content="general" />
|
|
|
|
<link rel="shortcut icon" href="favicon.png">
|
|
|
|
<meta property="og:image" content="img/ogp.jpg" />
|
|
<meta property="og:image:secure_url" content="img/ogp.jpg" />
|
|
<meta property="og:image:type" content="image/jpeg" />
|
|
<meta property="og:image:width" content="344" />
|
|
<meta property="og:image:height" content="247" />
|
|
<meta property="og:image:alt" content="A dog on a cloud." />
|
|
<meta property="og:title" content="Conbook Art Credits" />
|
|
<meta property="og:description" content="Submit Artist Credits to the Eurofurence Conbook Team" />
|
|
<meta property="og:type" content="website" />
|
|
<meta property="og:url" content="https://dogpixels.net/ef/conbook-artist-credits" />
|
|
<meta property="og:site_name" content="Conbook Art Credits" />
|
|
|
|
<meta name="twitter:card" content="summary_large_image" />
|
|
<meta name="twitter:title" content="Conbook Art Credits" />
|
|
<meta name="twitter:description" content="Submit Artist Credits to the Eurofurence Conbook Team" />
|
|
<meta name="twitter:image" content="img/ogp.jpg" />
|
|
|
|
<link rel="stylesheet" href="css/uikit.min.css" type="text/css" />
|
|
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
|
|
|
<script src="js/uikit.min.js"></script>
|
|
<script src="js/uikit-icons.min.js"></script>
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<h1>Conbook Artist Credit Form</h1>
|
|
<p>
|
|
Thank you for submitting art to the Eurofurence Conbook. In the event of your art making an appearance in the book, your are eligible to an entry in the artist credits.<br />
|
|
Edit your entry below before <strong>the end of July</strong> to make sure you are credited appropriately.
|
|
</p>
|
|
|
|
<p>Bookmark this page or save the following url to be able to edit your entry later:</p>
|
|
<div class="uk-width-1-1 uk-grid-collapse" uk-grid>
|
|
<div class="uk-width-3-4@m">
|
|
<input type="text" id="bookmark" disabled value="<?= $bookmark ?>" class="uk-input" />
|
|
</div>
|
|
<div class="uk-width-1-4@m">
|
|
<button type="button" id="copyUrl" class="uk-button uk-button-primary uk-width-1-1" title="✅ Copied">Copy to Clipboard</button>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="uk-margin">
|
|
<hr />
|
|
<p>Please make sure your profile image is large enough for print. Don't worry about cropping or aspect ratio, it will be adjusted into the layout by us.</p>
|
|
<section class="uk-child-width-1-2@m" uk-grid>
|
|
<div>
|
|
<div class="js-upload uk-placeholder uk-margin-top uk-position-relative">
|
|
<div id="img"></div>
|
|
<!-- <img id="img" src="" alt="No image uploaded yet" /> -->
|
|
<span uk-icon="icon: cloud-upload"></span>
|
|
<span class="uk-text-middle">Upload Your Profile Image<br />PNG, JPG or GIF<br />min. 500 x 500 @ 300 dpi<br /></span>
|
|
<div uk-form-custom>
|
|
<input type="file">
|
|
<span class="uk-link">SELECT FILE</span>
|
|
</div>
|
|
</div>
|
|
<progress id="js-progressbar" class="uk-progress" value="0" max="100" hidden></progress>
|
|
</div>
|
|
|
|
<div>
|
|
<form action="" method="POST">
|
|
<input type="text" name="name" id="name" maxlength="80" value="<?= $name ?>" placeholder="Your nickname (max. 80 characters)" class="uk-input uk-margin-top" />
|
|
<input type="text" name="url" id="url" maxlength="256" value="<?= $url ?>" placeholder="Your gallery link / homepage (max. 256 characters)" class="uk-input uk-margin-top" />
|
|
<input type="text" name="desc" id="desc" maxlength="400" value="<?= $desc ?>" placeholder="Your description (max. 400 characters)" class="uk-input uk-margin-top" />
|
|
<input type="submit" value="Save" class="uk-button uk-button-primary uk-margin-top" />
|
|
</form>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
|
|
<footer>
|
|
<hr />
|
|
<p>If you need assistance, please contact <a href="https://help.eurofurence.org/contact/conbook" target="_blank">The Conbook Department</a>.</p>
|
|
</footer>
|
|
|
|
<script>
|
|
document.getElementById('copyUrl').addEventListener('click', (e) => {
|
|
var furl = document.getElementById('bookmark');
|
|
furl.setSelectionRange(0, furl.value.length);
|
|
navigator.clipboard.writeText(furl.value);
|
|
furl.setSelectionRange(0, 0);
|
|
e.target.innerText = "✅ copied";
|
|
// setTimeout(() => {e.target.innerText = "Copy to Clipboard"}, 3000);
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
<?php
|
|
foreach ($alerts as $status => $msgs) {
|
|
foreach ($msgs as $msg) {
|
|
echo 'UIkit.notification("' . $msg . '", "' . $status . '");';
|
|
}
|
|
}
|
|
?>
|
|
</script>
|
|
|
|
<?php if ($img !== '') { ?>
|
|
<script>
|
|
document.getElementById('img').style.backgroundImage = 'url(uppies/<?= $img ?>?' + new Date().getTime() + ')';
|
|
</script>
|
|
<?php } ?>
|
|
|
|
<script>
|
|
var bar = document.getElementById('js-progressbar');
|
|
|
|
UIkit.upload('.js-upload', {
|
|
url: '<?= $bookmark ?>&upload',
|
|
|
|
loadStart: function (e) {
|
|
bar.removeAttribute('hidden');
|
|
bar.max = e.total;
|
|
bar.value = e.loaded;
|
|
},
|
|
|
|
progress: function (e) {
|
|
bar.max = e.total;
|
|
bar.value = e.loaded;
|
|
},
|
|
|
|
loadEnd: function (e) {
|
|
bar.max = e.total;
|
|
bar.value = e.loaded;
|
|
},
|
|
|
|
completeAll: function (r) {
|
|
if (r.status == 200) {
|
|
console.log(r);
|
|
document.getElementById('img').style.backgroundImage = 'url(' + r.responseText + '?' + new Date().getTime() + ')';
|
|
UIkit.notification('✅ Image saved', 'success');
|
|
}
|
|
else {
|
|
UIkit.notification(r.responseText, 'danger');
|
|
}
|
|
|
|
setTimeout(function () {
|
|
bar.setAttribute('hidden', 'hidden');
|
|
}, 1000);
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|