diff options
Diffstat (limited to 'templates')
| -rw-r--r-- | templates/note.php | 16 | ||||
| -rw-r--r-- | templates/note_attachment.php | 17 |
2 files changed, 20 insertions, 13 deletions
diff --git a/templates/note.php b/templates/note.php index b5b07df..736d5f9 100644 --- a/templates/note.php +++ b/templates/note.php @@ -78,19 +78,9 @@ if ($user != null) { <?php if (count($note->attachments) > 0): ?> <div class="attachments"> - <?php foreach ($note->attachments as $attachment): ?> - <div> - <?php if ($attachment->isImage()): ?> - <img src="<?= $attachment->href ?>" alt="<?= htmlspecialchars($attachment->description ?? '') ?>" - title="<?= htmlspecialchars($attachment->description ?? '') ?>"> - <?php else: ?> - <a class="file" href="<?= $attachment->href ?>" target="_blank" download> - <span class="material-symbols attach-file"></span> - <span><?= htmlspecialchars($attachment->description ?? basename($attachment->href)) ?></span> - </a> - <?php endif; ?> - </div> - <?php endforeach; ?> + <?php foreach ($note->attachments as $attachment) { + call_template('note_attachment', ['attachment' => $attachment]); + } ?> </div> <?php endif; ?> diff --git a/templates/note_attachment.php b/templates/note_attachment.php new file mode 100644 index 0000000..c139a00 --- /dev/null +++ b/templates/note_attachment.php @@ -0,0 +1,17 @@ +<?php +$filename = basename($attachment->href); +if (!$attachment->isImage() && $attachment->description) { + $filename = $attachment->description; +} +?> +<div> + <?php if ($attachment->isImage()): ?> + <img src="<?= $attachment->href ?>" alt="<?= htmlspecialchars($attachment->description ?? '') ?>" + title="<?= htmlspecialchars($attachment->description ?? '') ?>"> + <?php else: ?> + <a class="file" href="<?= $attachment->href ?>" target="_blank" download="<?= htmlspecialchars($filename) ?>"> + <span class="material-symbols attach-file"></span> + <span><?= htmlspecialchars($filename) ?></span> + </a> + <?php endif; ?> +</div>
\ No newline at end of file |
