Skip to content

Commit

Permalink
fix attachment template if no password is set
Browse files Browse the repository at this point in the history
  • Loading branch information
bennet0496 committed Mar 20, 2024
1 parent a8b67d7 commit 51c0c14
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
9 changes: 2 additions & 7 deletions attachment_tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<div style=""><p>The file %FILENAME% was attached as a Filelink. It can be downloaded from the link below.</p></div>
<div style="border: 1px solid rgb(205, 205, 205); border-radius: 5px; margin-top: 10px; margin-bottom: 10px; padding: 15px; display: grid; grid-template-columns: 0fr 1fr 0fr 0fr; align-items: center;" class="cloudAttachmentItem" data-content-location="%FILEURL%" data-service-url="">
<a href="%FILEURL%" style="color: rgb(15, 126, 219) !important; grid-area: 1 / 2;">%FILENAME%</a>
<img style="grid-area: 1 / 1 / span %ICONSPAN%; margin-right: 5px; z-index: 0" alt="Mime Icon" src="data:image/png;base64,%ICONBLOB%" width="32" height="32" />
<img style="grid-area: 1 / 1 / span %ICONSPAN%; margin-right: 5px; margin-left: 22px; margin-top: 20px; z-index: 1;" alt="Paperclip Icon" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iNDgiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iNDgiPjxwYXRoIGQ9Ik00NjAtODBxLTkxIDAtMTU1LjUtNjIuNVQyNDAtMjk2di00MzBxMC02NCA0NS41LTEwOVQzOTUtODgwcTY1IDAgMTEwIDQ1dDQ1IDExMHYzOTRxMCAzOC0yNiA2NC41VDQ2MC0yNDBxLTM4IDAtNjQtMjguNVQzNzAtMzM2di0zOTJoNDB2Mzk1cTAgMjIgMTQuNSAzNy41VDQ2MC0yODBxMjEgMCAzNS41LTE1dDE0LjUtMzZ2LTM5NXEwLTQ4LTMzLjUtODFUMzk1LTg0MHEtNDggMC04MS41IDMzVDI4MC03MjZ2NDMycTAgNzMgNTMgMTIzLjVUNDYwLTEyMHE3NSAwIDEyNy41LTUxVDY0MC0yOTZ2LTQzMmg0MHY0MzFxMCA5MS02NC41IDE1NFQ0NjAtODBaIi8+PC9zdmc+" width="16" height="16" /><br />
<img style="grid-area: 1 / 1 / span 5; margin-right: 5px; z-index: 0" alt="Mime Icon" src="data:image/png;base64,%ICONBLOB%" width="32" height="32" />
<img style="grid-area: 1 / 1 / span 5; margin-right: 5px; margin-left: 22px; margin-top: 20px; z-index: 1;" alt="Paperclip Icon" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iNDgiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iNDgiPjxwYXRoIGQ9Ik00NjAtODBxLTkxIDAtMTU1LjUtNjIuNVQyNDAtMjk2di00MzBxMC02NCA0NS41LTEwOVQzOTUtODgwcTY1IDAgMTEwIDQ1dDQ1IDExMHYzOTRxMCAzOC0yNiA2NC41VDQ2MC0yNDBxLTM4IDAtNjQtMjguNVQzNzAtMzM2di0zOTJoNDB2Mzk1cTAgMjIgMTQuNSAzNy41VDQ2MC0yODBxMjEgMCAzNS41LTE1dDE0LjUtMzZ2LTM5NXEwLTQ4LTMzLjUtODFUMzk1LTg0MHEtNDggMC04MS41IDMzVDI4MC03MjZ2NDMycTAgNzMgNTMgMTIzLjVUNDYwLTEyMHE3NSAwIDEyNy41LTUxVDY0MC0yOTZ2LTQzMmg0MHY0MzFxMCA5MS02NC41IDE1NFQ0NjAtODBaIi8+PC9zdmc+" width="16" height="16" /><br />
<span style="grid-column: 2 / span 3; font-size: small;">
<span>Size: </span><span style="color: rgb(89, 89, 89);">%FILESIZE%</span><br />
</span>
Expand All @@ -20,11 +20,6 @@
<span style="grid-column: 2 / span 3; font-size: small;">
<span>Checksum: </span><span style="color: rgb(89, 89, 89);">%CHECKSUM%</span><br />
</span>
%BEGINPASSWORD%
<span style="grid-column: 2 / span 3; font-size: small;">
<span>Password: </span><span style="color: rgb(89, 89, 89);">%PASSWORD%</span><br />
</span>
%ENDPASSWORD%
<span style="grid-column: 2 / span 3; font-size: small;">
<span>Available until: </span><span style="color: rgb(89, 89, 89);">%VALIDUNTIL%, after which the download link will expire</span><br />
</span>
Expand Down
45 changes: 45 additions & 0 deletions attachment_tmpl_pass.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<title>%FILENAME% - Filelink Attachment</title>
<meta charset="utf-8" />
</head>
<body>
<div style="padding: 15px; font-family: Calibri, sans-serif;">
<div style=""><p>The file %FILENAME% was attached as a Filelink. It can be downloaded from the link below.</p></div>
<div style="border: 1px solid rgb(205, 205, 205); border-radius: 5px; margin-top: 10px; margin-bottom: 10px; padding: 15px; display: grid; grid-template-columns: 0fr 1fr 0fr 0fr; align-items: center;" class="cloudAttachmentItem" data-content-location="%FILEURL%" data-service-url="">
<a href="%FILEURL%" style="color: rgb(15, 126, 219) !important; grid-area: 1 / 2;">%FILENAME%</a>
<img style="grid-area: 1 / 1 / span 6; margin-right: 5px; z-index: 0" alt="Mime Icon" src="data:image/png;base64,%ICONBLOB%" width="32" height="32" />
<img style="grid-area: 1 / 1 / span 6; margin-right: 5px; margin-left: 22px; margin-top: 20px; z-index: 1;" alt="Paperclip Icon" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iNDgiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iNDgiPjxwYXRoIGQ9Ik00NjAtODBxLTkxIDAtMTU1LjUtNjIuNVQyNDAtMjk2di00MzBxMC02NCA0NS41LTEwOVQzOTUtODgwcTY1IDAgMTEwIDQ1dDQ1IDExMHYzOTRxMCAzOC0yNiA2NC41VDQ2MC0yNDBxLTM4IDAtNjQtMjguNVQzNzAtMzM2di0zOTJoNDB2Mzk1cTAgMjIgMTQuNSAzNy41VDQ2MC0yODBxMjEgMCAzNS41LTE1dDE0LjUtMzZ2LTM5NXEwLTQ4LTMzLjUtODFUMzk1LTg0MHEtNDggMC04MS41IDMzVDI4MC03MjZ2NDMycTAgNzMgNTMgMTIzLjVUNDYwLTEyMHE3NSAwIDEyNy41LTUxVDY0MC0yOTZ2LTQzMmg0MHY0MzFxMCA5MS02NC41IDE1NFQ0NjAtODBaIi8+PC9zdmc+" width="16" height="16" /><br />
<span style="grid-column: 2 / span 3; font-size: small;">
<span>Size: </span><span style="color: rgb(89, 89, 89);">%FILESIZE%</span><br />
</span>
<span style="grid-column: 2 / span 3; font-size: small;">
<span>Link: </span><a href="%FILEURL%" style="color: rgb(89, 89, 89) !important;">%FILEURL%</a><br />
</span>
<span style="grid-column: 2 / span 3; font-size: small;">
<span>Checksum: </span><span style="color: rgb(89, 89, 89);">%CHECKSUM%</span><br />
</span>
<span style="grid-column: 2 / span 3; font-size: small;">
<span>Password: </span><span style="color: rgb(89, 89, 89);">%PASSWORD%</span><br />
</span>
<span style="grid-column: 2 / span 3; font-size: small;">
<span>Available until: </span><span style="color: rgb(89, 89, 89);">%VALIDUNTIL%, after which the download link will expire</span><br />
</span>
<br />
</div>
<div style="margin-top: 15px; color: rgb(100,100,100); font-size: 11pt; margin-left: 15px">
<p>
Attachments hosted on %SERVERURL% and subject to the server provider's terms of service and privacy policy.
<b>Beyond the attachment becoming unavailable after the expiration date, the sender may delete the attachment
at any point; download and save the file to retain a local copy.</b>
Be careful who's attachments you trust, especially with executables and office documents.
</p>
</div>
<div style="margin-top: 15px; color: rgb(200,200,200); font-size: 10pt; margin-left: 15px">
<p>Generated with <a style="color: rgb(200,200,200);" href="https://github.com/bennet0496/nextcloud_attachments">nextcloud_attachments</a> for Roundcube by <a style="color: rgb(200,200,200);" href="https://github.com/bennet0496">Bennet B.</a></p>
<p style="margin-top: -16px">Icons: <a style="color: rgb(200,200,200);" href="https://github.com/ubuntu/yaru">Ubuntu Yaru</a> (CC BY-SA 4.0) and <a style="color: rgb(200,200,200);" href="https://developers.google.com/fonts/docs/material_icons">Material Icons</a> (Apache License 2.0).</p>
</div>
</div>
</body>
</html>
19 changes: 9 additions & 10 deletions hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,15 @@ public function upload(array $data): array
return ["status" => false, "abort" => true];
}

//fill out template attachment HTML
$tmpl = file_get_contents(dirname(__FILE__) . "/attachment_tmpl.html");
$tmpl = "";

if (isset($form_params["password"])) {
//fill out template attachment HTML with Password
$tmpl = file_get_contents(dirname(__FILE__) . "/attachment_tmpl_pass.html");
} else {
//fill out template attachment HTML
$tmpl = file_get_contents(dirname(__FILE__) . "/attachment_tmpl.html");
}

$fs = filesize($data["path"]);
$u = ["", "k", "M", "G", "T"];
Expand All @@ -582,14 +589,8 @@ public function upload(array $data): array
$tmpl = str_replace("%ICONBLOB%", base64_encode($mime_icon), $tmpl);
$tmpl = str_replace("%CHECKSUM%", strtoupper($checksum) . " " . hash_file($checksum, $data["path"]), $tmpl);

$icon_rows = 5;
if (isset($form_params["password"])){
$tmpl = str_replace("%PASSWORD%", $form_params["password"], $tmpl);
$tmpl = str_replace("%BEGINPASSWORD%", "", $tmpl);
$tmpl = str_replace("%ENDPASSWORD%", "", $tmpl);
$icon_rows++;
} else {
$tmpl = preg_replace("/%BEGINPASSWORD%.*?%ENDPASSWORD%/", "", $tmpl);
}

if (isset($form_params["expireDate"]) && isset($expire_date)){
Expand All @@ -598,8 +599,6 @@ public function upload(array $data): array
$tmpl = str_replace("%VALIDUNTIL%", "deletion", $tmpl);
}

$tmpl = str_replace("%ICONSPAN%", $icon_rows, $tmpl);

// Minimize HTML
// https://stackoverflow.com/a/6225706
$search = array(
Expand Down

0 comments on commit 51c0c14

Please sign in to comment.