aboutsummaryrefslogtreecommitdiffstats
path: root/visitors.php
diff options
context:
space:
mode:
authoralyx <alyx@aleteoryx.me>2024-05-25 01:31:08 -0400
committeralyx <alyx@aleteoryx.me>2024-05-25 01:31:08 -0400
commit07ba36135375b7f4cc91dee14f420b5f5b9651d6 (patch)
tree030c8da830ee6c2b416f89cc7e5905d9ce4305f7 /visitors.php
parent3688cda46f3fb5ef51a85433a4cbaba5636e07f7 (diff)
downloadvisitors_dot_php-07ba36135375b7f4cc91dee14f420b5f5b9651d6.tar.gz
visitors_dot_php-07ba36135375b7f4cc91dee14f420b5f5b9651d6.tar.bz2
visitors_dot_php-07ba36135375b7f4cc91dee14f420b5f5b9651d6.zip
visit list markup
Diffstat (limited to 'visitors.php')
-rw-r--r--visitors.php66
1 files changed, 60 insertions, 6 deletions
diff --git a/visitors.php b/visitors.php
index b93a67b..d50082d 100644
--- a/visitors.php
+++ b/visitors.php
@@ -41,14 +41,16 @@ $config['form_mode'] = 0;
// 3 - Show the text `[e-mail]` with a `mailto:` link, or use the username text for the link if no website is present
// 4 - Show the e-mail as escaped text, e.g. 'alyx at aleteoryx dot me'
-$config['email_display'] = 0;
+$config['email_display'] = 2;
-// E-Mail icon: ?string
+// E-Mail icon/link: ?string
//
-// Should be the link to an icon for email display modes 0 and 1. Supports base64. If null or empty, defaults to a builtin image.
+// Link should be a link to an image for the email icon. Icon should be the icon's data, base64 encoded, prefixed with `<mimetype>:`.
+// Only set one, or neither. This option only applies for email_display modes 0 and 1.
-//$config['email_icon'] = '/static/my_cool_email_icon.gif';
+//$config['email_link'] = '/static/my_cool_email_icon.gif';
+//$config['email_icon'] = 'image/png:...';
/* CONFIG OPTIONS - BACKEND */
@@ -79,6 +81,17 @@ $config['db'] = 'visitors.csv';
/* --- END OF CONFIG, CODE BELOW, PROBABLY DON'T EDIT PAST THIS POINT --- */
+/* CONFIG FIXING */
+
+if (!isset($config['email_link'])) { // stolen from <https://forum.melonland.net/Themes/pimp-my-classic/images/email_sm.gif>
+ $config['email_icon'] ??= 'image/gif:R0lGODlhEAAQALMEAAAAADExY2NjMWNjzv///5ycY5yc/86cY87O///OnP//zv///wAAAAAAAAAAAAAAACH5BAEAAAQALAAAAAAQABAAAARfkJBCqy1CyrK690qmcUd5KKiSiNuSvio7LWVinqs2w2kuDaSbLTYgDAwcHmplCAwWBprplTA0nwiDspp1LhBZq9gKvn6z4DS6izWo1W6z+w2/Hsd46yBACAD+gIGABBEAOw==';
+ if (!$config['use_path_info']) {
+ [$mime, $base64] = explode(':', $config['email_icon'], 2);
+ $config['email_link'] = 'data:'.$mime.';base64,'.$base64;
+ unset($config['email_icon']);
+ }
+}
+
/* DATABASES */
// db_row: ['id' => int (only for list_rows), 'name' => string, 'message' => string, 'email' => ?string, 'website' => ?string, 'timestamp' => string (or DateTimeInterface for list_rows)]
@@ -125,7 +138,7 @@ abstract class FileDatabase extends Database {
}
protected function _append_row(array $db_row) {
- array_unshift($this->data, array(...$db_row, 'id' => max(array_map(fn($a) => $a['id'], $this->data))));
+ array_unshift($this->data, array(...$db_row, 'id' => count($this->data) ? max(array_map(fn($a) => $a['id'], $this->data)) : 0));
$this->save();
}
@@ -178,7 +191,7 @@ final class JsonlDatabase extends FileDatabase {
// notes: `id` is not stable
final class CsvDatabase extends FileDatabase {
- private const array KEY_ORDER = ['name', 'message', 'email', 'website', 'timestamp'];
+ private const array KEY_ORDER = ['id', 'name', 'message', 'email', 'website', 'timestamp'];
protected function save() {
$fp = fopen($this->file, 'w');
@@ -243,3 +256,44 @@ function get_database_for_file(string $file): Database {
};
}
+$db = get_database_for_file($config['db']);
+
+//$db->append_row('foo', 'bar');
+
+/* ACTUAL UI */
+
+$ed_1_or_3 = $config['email_display'] == 1 || $config['email_display'] == 3;
+
+?>
+<!doctype html>
+<html>
+<head>
+<?php ?>
+</head>
+<body>
+ <h1>Guestbook</h1>
+ <main>
+ <?php foreach($db->list_rows() as $row):
+ $author_link = $row['website'] ?
+ '<a href="'.$row['website'].'">'.$row['name'].'</a>' :
+ (($row['email'] && $ed_1_or_3) ?
+ '<a href="mailto:'.$row['email'].'">'.$row['name'].'</a>' :
+ $row['name']);
+ $email_element = $row['email'] && (($row['website'] && $ed_1_or_3) || !$ed_1_or_3) ?
+ match ($config['email_display']) {
+ 0, 1 => '<a href="mailto:'.$row['email'].'"><img alt="e-mail icon" src="'.($config['email_link']??'./email_icon').'" /></a>',
+ 2, 3 => '<a href="mailto:'.$row['email'].'">[e-mail]</a>',
+ 4 => 'mail:&nbsp<u>'.str_replace(['@', '.'], [' at ', ' dot '], $row['email']).'</u>'
+ } : ''; ?>
+ <article id=visit-<?= $row['id'] ?> data-visit-id=<?= $row['id'] ?> data-visit-name="<?= $row['name'] ?>" data-visit-message="<?= $row['message'] ?>" data-visit-email="<?= $row['email'] ?>" data-visit-website="<?= $row['website'] ?>">
+ <div class='visit-info'>
+ <span class='author-link'><?= $author_link ?></span>&nbsp;&nbsp;<span class='email'><?= $email_element ?></span>
+ <span class='wide'>
+ <time datetime="<?= $row['timestamp']->format(DATE_ISO8601) ?>"><?= $row['timestamp']->format("Y/m/d H:i") ?></time>
+ </div>
+ <q><?= $row['message'] ?></q>
+ </article>
+ <?php endforeach; ?>
+ </main>
+</body>
+</html>