From 07ba36135375b7f4cc91dee14f420b5f5b9651d6 Mon Sep 17 00:00:00 2001 From: alyx Date: Sat, 25 May 2024 01:31:08 -0400 Subject: visit list markup --- visitors.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file 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 `:`. +// 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 + $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; + +?> + + + + + + +

Guestbook

+
+ list_rows() as $row): + $author_link = $row['website'] ? + ''.$row['name'].'' : + (($row['email'] && $ed_1_or_3) ? + ''.$row['name'].'' : + $row['name']); + $email_element = $row['email'] && (($row['website'] && $ed_1_or_3) || !$ed_1_or_3) ? + match ($config['email_display']) { + 0, 1 => 'e-mail icon', + 2, 3 => '[e-mail]', + 4 => 'mail: '.str_replace(['@', '.'], [' at ', ' dot '], $row['email']).'' + } : ''; ?> +
data-visit-id= data-visit-name="" data-visit-message="" data-visit-email="" data-visit-website=""> +
+    + + +
+ +
+ +
+ + -- cgit v1.2.3-54-g00ecf