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

Improve PDF preview when embedded in pages - fixes #202

This commit is contained in:
Starbeamrainbowlabs 2020-08-06 15:28:24 +01:00
parent 492816b4c0
commit e3e2a01435
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 48 additions and 13 deletions

View file

@ -26,6 +26,7 @@ Make sure you have PHP 7.3+ when you update past this point! It isn't the end of
- `comment_enabled` controls whether _anyone_ is allowed to comment at all or not
- `comment_hide_all` determines whether the commenting system displays anything at all (if disabled, it's (almost) like the `feature-comments` doesn't exist - consider using the downloader to exclude the commenting system instead of enabling this setting)
- `avatars_gravatar_enabled` determines whether redirects to [gravatar.com](https://gravatar.com/) should be performed if a user hasn't yet uploaded an avatar (if disabled then a blank image is returned instead of a redirect).
- PDF previews now show the browser's UI when embedded in pages with the `![alt text](File/somefile.png)` syntax
### Changed
- **New policy:** Only [officially supported](https://www.php.net/supported-versions.php) versions of PHP are officially supported by Pepperminty Wiki.
@ -53,6 +54,7 @@ Make sure you have PHP 7.3+ when you update past this point! It isn't the end of
- Fixed an obscure bug in the search engine when excluding terms that appear both in a page's title and body
- Squashed a warning at the top of search results (more insight is needed though to squash the inconsistencies in the search index that creep in though)
- Removed annoying scrollbars when editing long pages
- Fixed an obscure warning when previewing PDFs
## v0.21.1-hotfix1

View file

@ -387,8 +387,7 @@ register_module([
break;
case "application":
if($mime_type == "application/pdf")
{
if($mime_type == "application/pdf") {
$preview = new imagick();
$preview->readImage("{$filepath}[0]");
$preview->setResolution(300,300);

View file

@ -647,8 +647,12 @@ class PeppermintParsedown extends ParsedownExtra
$previewSize = 300;
$previewUrl = "?action=preview&size=$previewSize&page=" . rawurlencode($pagename);
$previewType = substr($mime_type, 0, strpos($mime_type, "/"));
if($mime_type == "application/pdf")
$previewType = "pdf";
$previewHtml = "";
switch(substr($mime_type, 0, strpos($mime_type, "/")))
switch($previewType)
{
case "video":
$previewHtml .= "<video src='$previewUrl' controls preload='metadata'>$pagename</video>\n";
@ -656,6 +660,9 @@ class PeppermintParsedown extends ParsedownExtra
case "audio":
$previewHtml .= "<audio src='$previewUrl' controls preload='metadata'>$pagename</audio>\n";
break;
case "pdf":
$previewHtml .= "<object type='application/pdf' data='$previewUrl' style='width: {$previewStyle}px;'></object>";
break;
case "application":
case "image":
default:
@ -1124,7 +1131,11 @@ class PeppermintParsedown extends ParsedownExtra
{
// We have a short url! Expand it.
$shortImageUrl = $imageUrl;
$imageUrl = "index.php?action=preview&size=" . max($imageSize["x"], $imageSize["y"]) ."&page=" . rawurlencode($imageUrl);
$imageUrl = "index.php?action=preview";
if($imageSize !== false) $imageUrl .= "&size=" . max($imageSize["x"], $imageSize["y"]);
else $imageUrl .= "&size=original";
// This has to be last in order for the extension auto-detection to work correctly
$imageUrl .= "&page=" . rawurlencode($shortImageUrl);
}
$style = "";
@ -1135,9 +1146,30 @@ class PeppermintParsedown extends ParsedownExtra
$urlExtension = pathinfo($imageUrl, PATHINFO_EXTENSION);
$urlType = system_extension_mime_type($urlExtension);
$embed_type = substr($urlType, 0, strpos($urlType, "/"));
if($urlType == "application/pdf") $embed_type = "pdf";
$result = [];
switch(substr($urlType, 0, strpos($urlType, "/")))
switch($embed_type)
{
case "pdf":
$imageUrl = preg_replace("/&size=[0-9]+/", "&size=original", $imageUrl);
if($imageSize === false) $style .= "width: 100%;";
else $style = str_replace("max-width", "width", $style);
$result = [
"extent" => strlen($matches[0]),
"element" => [
"name" => "object",
"text" => "",
"attributes" => [
"type" => "application/pdf",
"data" => $imageUrl,
"style" => trim($style)
]
]
];
break;
case "audio":
$result = [
"extent" => strlen($matches[0]),
@ -1189,14 +1221,16 @@ class PeppermintParsedown extends ParsedownExtra
// ~ Image linker ~
$imageHref = $shortImageUrl !== false ? "?page=" . rawurlencode($shortImageUrl) : $imageUrl;
$result["element"] = [
"name" => "a",
"attributes" => [
"href" => $imageHref
],
"text" => [$result["element"]],
"handler" => "elements"
];
if($embed_type !== "pdf") {
$result["element"] = [
"name" => "a",
"attributes" => [
"href" => $imageHref
],
"text" => [$result["element"]],
"handler" => "elements"
];
}
// ~