1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 04:23:01 +00:00

Implement initial pdf preview

This commit is contained in:
Starbeamrainbowlabs 2019-06-01 20:25:44 +01:00
parent a5572bcbd4
commit 02bc1ea7a2
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
5 changed files with 17 additions and 7 deletions

View file

@ -152,10 +152,10 @@
{ {
"id": "feature-upload", "id": "feature-upload",
"name": "Uploader", "name": "Uploader",
"version": "0.5.16", "version": "0.5.17",
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File\/' prefix.", "description": "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File\/' prefix.",
"lastupdate": 1559400139, "lastupdate": 1559416947,
"optional": false, "optional": false,
"extra_data": [] "extra_data": []
}, },

View file

@ -471,16 +471,15 @@ register_module([
$dimensions = $mime_type !== "image/svg+xml" ? getimagesize($env->storage_prefix . $filepath) : getsvgsize($env->storage_prefix . $filepath); $dimensions = $mime_type !== "image/svg+xml" ? getimagesize($env->storage_prefix . $filepath) : getsvgsize($env->storage_prefix . $filepath);
$fileTypeDisplay = substr($mime_type, 0, strpos($mime_type, "/")); $fileTypeDisplay = substr($mime_type, 0, strpos($mime_type, "/"));
$previewUrl = "?action=preview&size=$settings->default_preview_size&page=" . rawurlencode($env->page); $previewUrl = "?action=preview&size=$settings->default_preview_size&page=" . rawurlencode($env->page);
$originalUrl = $env->storage_prefix == "./" ? $filepath : "?action=preview&size=original&page=" . rawurlencode($env->page);
if($mime_type == "application/pdf")
$fileTypeDisplay = "pdf";
$preview_html = ""; $preview_html = "";
switch($fileTypeDisplay) switch($fileTypeDisplay)
{ {
case "application": case "application":
case "image": case "image":
if($mime_type == "application/pdf")
$fileTypeDisplay = "file";
$originalUrl = $env->storage_prefix == "./" ? $filepath : "?action=preview&size=original&page=" . rawurlencode($env->page);
$preview_sizes = [ 256, 512, 768, 1024, 1440, 1920 ]; $preview_sizes = [ 256, 512, 768, 1024, 1440, 1920 ];
$preview_html .= "\t\t\t<figure class='preview'> $preview_html .= "\t\t\t<figure class='preview'>
<a href='$originalUrl'><img src='$previewUrl' /></a> <a href='$originalUrl'><img src='$previewUrl' /></a>
@ -506,6 +505,11 @@ register_module([
$preview_html .= "\t\t\t<figure class='preview'> $preview_html .= "\t\t\t<figure class='preview'>
<audio src='$previewUrl' controls preload='metadata'>Your browser doesn't support HTML5 audio, but you can still <a href='$previewUrl'>download it</a> if you'd like.</audio> <audio src='$previewUrl' controls preload='metadata'>Your browser doesn't support HTML5 audio, but you can still <a href='$previewUrl'>download it</a> if you'd like.</audio>
</figure>"; </figure>";
break;
case "pdf":
$preview_html .= "\t\t\t<object type='application/pdf' data='$originalUrl'></object>";
break;
} }
$fileInfo = []; $fileInfo = [];

View file

@ -146,7 +146,8 @@
"audio/mp4", "audio/mp4",
"audio/mpeg", "audio/mpeg",
"audio/flac", "audio/flac",
"audio/ogg" "audio/ogg",
"application/pdf"
]}, ]},
"preview_file_type": { "type": "text", "description": "The default file type for previews.", "default": "image/png" }, "preview_file_type": { "type": "text", "description": "The default file type for previews.", "default": "image/png" },
"default_preview_size": { "type": "number", "description": "The default size of preview images in pixels.", "default": 640}, "default_preview_size": { "type": "number", "description": "The default size of preview images in pixels.", "default": 640},

View file

@ -164,6 +164,10 @@ input[type=button], input[type=submit]{
audio, video, img{ audio, video, img{
max-width:100%; max-width:100%;
} }
object {
width: 100%;
height: 90vh;
}
figure:not(.preview){ figure:not(.preview){
display:inline-block; display:inline-block;
} }

View file

@ -38,6 +38,7 @@ input[type=button], input[type=submit] { cursor: pointer; }
.link-display { margin-left: 0.5rem; } .link-display { margin-left: 0.5rem; }
audio, video, img { max-width: 100%; } audio, video, img { max-width: 100%; }
object { width: 100%; height: 90vh; }
figure:not(.preview) { display: inline-block; } figure:not(.preview) { display: inline-block; }
figure:not(.preview) > :first-child { display: block; } figure:not(.preview) > :first-child { display: block; }
figcaption { text-align: center; } figcaption { text-align: center; }