summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-06-24 22:35:29 +0500
committerilotterytea <iltsu@alright.party>2025-06-24 22:35:29 +0500
commitc734db91064944637e361f90ed90b30d48a7d910 (patch)
tree641e8a7246039d98b13fa43b0d370460168a17e2
parent2bdd40b6320d1504bb15f48242068534482c9b54 (diff)
feat: flash (.swf) support
-rw-r--r--.gitignore1
-rw-r--r--lib/file.php8
-rw-r--r--lib/thumbnails.php10
-rw-r--r--public/catalogue.php2
-rw-r--r--public/index.php12
-rw-r--r--public/upload.php8
6 files changed, 34 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index b677f44..9bc8494 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@ config.php
*.ini
*.db
userdata/
+ruffle/
TOS.txt
PRIVACY.txt \ No newline at end of file
diff --git a/lib/file.php b/lib/file.php
index fc3e38a..61c4fb8 100644
--- a/lib/file.php
+++ b/lib/file.php
@@ -4,16 +4,20 @@ include_once $_SERVER['DOCUMENT_ROOT'] . '/../config.php';
function verify_mimetype(string $file_path, string $mimetype): bool
{
$path = escapeshellarg($file_path);
+ $output = [];
+ $exitCode = 0;
if (str_starts_with($mimetype, 'image/')) {
$output = shell_exec("identify -quiet -ping $path");
return !empty($output);
} else if (str_starts_with($mimetype, 'video/') || str_starts_with($mimetype, 'audio/')) {
- $output = [];
- $exitCode = 0;
$cmd = "ffprobe -v error -i $path 2>&1";
exec($cmd, $output, $exitCode);
return $exitCode === 0;
+ } else if ($mimetype == 'application/x-shockwave-flash') {
+ $cmd = "swfdump $path 2>&1";
+ exec($cmd, $output, $exitCode);
+ return $exitCode === 0;
}
throw new RuntimeException("Illegal type for MIME verifications: $mimetype");
diff --git a/lib/thumbnails.php b/lib/thumbnails.php
index 5afc775..5e99087 100644
--- a/lib/thumbnails.php
+++ b/lib/thumbnails.php
@@ -10,7 +10,15 @@ function generate_image_thumbnail(string $src_path, string $dst_path, int $width
$result_code = null;
- exec(command: "magick $input_path -resize {$width}x{$height} -loop 0 $output_path", result_code: $result_code);
+ if (str_ends_with($src_path, ".swf")) {
+ exec(command: "swfrender $input_path -o $output_path", result_code: $result_code);
+ if ($result_code != 0) {
+ return $result_code;
+ }
+ exec(command: "magick $output_path -resize {$width}x{$height} -loop 0 $output_path", result_code: $result_code);
+ } else {
+ exec(command: "magick $input_path -resize {$width}x{$height} -loop 0 $output_path", result_code: $result_code);
+ }
return $result_code;
}
diff --git a/public/catalogue.php b/public/catalogue.php
index 9836cbf..f2a5cd6 100644
--- a/public/catalogue.php
+++ b/public/catalogue.php
@@ -77,7 +77,7 @@ unset($f);
<div class="brick<?= isset($file['color']) ? " {$file['color']}" : '' ?>">
<a href="/<?= sprintf('%s.%s', $file['id'], $file['extension']) ?>">
<i title="<?= $file['thumb_title'] ?>">
- <?php if (str_starts_with($file['mime'], 'image/') || str_starts_with($file['mime'], 'video/')): ?>
+ <?php if (str_starts_with($file['mime'], 'image/') || str_starts_with($file['mime'], 'video/') || $file['mime'] == 'application/x-shockwave-flash'): ?>
<img src="<?= sprintf('%s/%s.webp', FILE_THUMBNAIL_DIRECTORY_PREFIX, $file['id']) ?>"
alt="No thumbnail." loading="lazy">
<?php elseif (str_starts_with($file['mime'], 'audio/')): ?>
diff --git a/public/index.php b/public/index.php
index 556349f..a9ddec3 100644
--- a/public/index.php
+++ b/public/index.php
@@ -248,6 +248,12 @@ $privacy_exists = is_file($_SERVER['DOCUMENT_ROOT'] . '/static/PRIVACY.txt');
</audio>
<?php elseif (str_starts_with($file['mime'], 'text/')): ?>
<pre><?= file_get_contents(FILE_UPLOAD_DIRECTORY . "/{$file['id']}.{$file['extension']}") ?></pre>
+ <?php elseif ($file['mime'] == 'application/x-shockwave-flash' && !empty(RUFFLE_DRIVER_PATH)): ?>
+ <noscript>JavaScript is required to play Flash</noscript>
+ <object>
+ <embed src="<?= $file['full_url'] ?>" width="<?= $file['width'] - 4 ?>"
+ height="<?= $file['height'] ?>">
+ </object>
<?php else: ?>
<p><i>This file cannot be displayed.</i></p>
<?php endif; ?>
@@ -452,6 +458,10 @@ $privacy_exists = is_file($_SERVER['DOCUMENT_ROOT'] . '/static/PRIVACY.txt');
</main>
</body>
+<?php if ($file && $file['mime'] == 'application/x-shockwave-flash' && !empty(RUFFLE_DRIVER_PATH)): ?>
+ <script src="<?= RUFFLE_DRIVER_PATH ?>"></script>
+<?php endif; ?>
+
<?php if ($file): ?>
<script>
const fileTabButtons = document.getElementById('file-tab-buttons');
@@ -649,7 +659,7 @@ $privacy_exists = is_file($_SERVER['DOCUMENT_ROOT'] . '/static/PRIVACY.txt');
thumbnailPath = '/static/img/icons/file_audio.png';
} else if (file.mime.startsWith('text/')) {
thumbnailPath = '/static/img/icons/file_text.png';
- } else if (!file.mime.startsWith('image/') && !file.mime.startsWith('video/')) {
+ } else if (!file.mime.startsWith('image/') && !file.mime.startsWith('video/') && file.mime != 'application/x-shockwave-flash') {
thumbnailPath = '/static/img/icons/file.png';
} else {
thumbnailSize = 'max-width:100%; max-height: 100%;';
diff --git a/public/upload.php b/public/upload.php
index 3ec525a..c5a2e7e 100644
--- a/public/upload.php
+++ b/public/upload.php
@@ -207,7 +207,7 @@ try {
if (
FILE_THUMBNAILS && (
(
- str_starts_with($file_data['mime'], 'image/') &&
+ (str_starts_with($file_data['mime'], 'image/') || $file_data['mime'] == 'application/x-shockwave-flash') &&
$thumbnail_error = generate_image_thumbnail(
FILE_UPLOAD_DIRECTORY . "/{$file_id}.{$file_data['extension']}",
FILE_THUMBNAIL_DIRECTORY . "/{$file_id}.webp",
@@ -237,7 +237,8 @@ try {
'duration' => null,
'line_count' => null,
];
- $metadata_should_be_created = in_array(explode('/', $file_data['mime'])[0], ['image', 'video', 'audio', 'text']);
+ $metadata_should_be_created = in_array(explode('/', $file_data['mime'])[0], ['image', 'video', 'audio', 'text']) || $file_data['mime'] == 'application/x-shockwave-flash';
+ $file_path_escaped = escapeshellarg($file_path);
if (str_starts_with($file_data['mime'], 'image/')) {
[$width, $height] = explode('x', trim(shell_exec('identify -format "%wx%h" ' . escapeshellarg($file_path) . '[0]')));
@@ -253,6 +254,9 @@ try {
$file_data['metadata']['duration'] = intval(round(trim(shell_exec('ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 ' . escapeshellarg($file_path))), 2));
} else if (str_starts_with($file_data['mime'], 'text/')) {
$file_data['metadata']['line_count'] = intval(trim(shell_exec('wc -l < ' . escapeshellarg($file_path))));
+ } else if ($file_data['mime'] == 'application/x-shockwave-flash') {
+ $file_data['metadata']['width'] = intval(substr(trim(shell_exec("swfdump -X $file_path_escaped")), 3));
+ $file_data['metadata']['height'] = intval(substr(trim(shell_exec("swfdump -Y $file_path_escaped")), 3));
}
$file_data['urls'] = [