From 32b7fa2fcb8d77cab49f0b17af75669139901859 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 10 Apr 2025 08:25:35 +0200 Subject: Shorten link label in Attachments. --- html.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'html.c') diff --git a/html.c b/html.c index a598038..e303d72 100644 --- a/html.c +++ b/html.c @@ -2439,13 +2439,19 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, name = NULL; } else { + xs *d_href = xs_dup(o_href); + if (strlen(d_href) > 64) { + d_href[64] = '\0'; + d_href = xs_str_cat(d_href, "..."); + } + xs_html_add(content_attachments, xs_html_tag("p", xs_html_tag("a", xs_html_attr("href", o_href), xs_html_text(L("Attachment")), xs_html_text(": "), - xs_html_text(o_href)))); + xs_html_text(d_href)))); /* do not generate an Alt... */ name = NULL; -- cgit From cbe25ddb853281aa800befea31e8f6dac0206411 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 10 Apr 2025 08:40:54 +0200 Subject: Hide the scheduled post date and time behind a 'details'. --- html.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index e303d72..b5d8946 100644 --- a/html.c +++ b/html.c @@ -457,18 +457,22 @@ xs_html *html_note(snac *user, const char *summary, if (edit_id == NULL || is_draft || is_scheduled(user, edit_id)) { xs_html_add(form, xs_html_tag("p", - xs_html_text(L("Post date and time (empty, right now; in the future, schedule for later):")), - xs_html_sctag("br", NULL), - xs_html_sctag("input", - xs_html_attr("type", "date"), - xs_html_attr("value", post_date ? post_date : ""), - xs_html_attr("name", "post_date")), - xs_html_text(" "), - xs_html_sctag("input", - xs_html_attr("type", "time"), - xs_html_attr("value", post_time ? post_time : ""), - xs_html_attr("step", "1"), - xs_html_attr("name", "post_time")))); + xs_html_tag("details", + xs_html_tag("summary", + xs_html_text(L("Scheduled post..."))), + xs_html_tag("p", + xs_html_text(L("Post date and time:")), + xs_html_sctag("br", NULL), + xs_html_sctag("input", + xs_html_attr("type", "date"), + xs_html_attr("value", post_date ? post_date : ""), + xs_html_attr("name", "post_date")), + xs_html_text(" "), + xs_html_sctag("input", + xs_html_attr("type", "time"), + xs_html_attr("value", post_time ? post_time : ""), + xs_html_attr("step", "1"), + xs_html_attr("name", "post_time")))))); } if (edit_id) -- cgit From 9a238a937e31b36e7ee35109c09764019ee3af1f Mon Sep 17 00:00:00 2001 From: default Date: Sun, 13 Apr 2025 09:23:43 +0200 Subject: Added some preliminary support for time zones (for scheduled posts). --- html.c | 10 ++++++--- xs_time.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index b5d8946..afbc716 100644 --- a/html.c +++ b/html.c @@ -4359,19 +4359,23 @@ int html_post_handler(const xs_dict *req, const char *q_path, } if (xs_is_string(post_date) && *post_date) { - xs *local_pubdate = xs_fmt("%sT%s", post_date, + xs *post_pubdate = xs_fmt("%sT%s", post_date, xs_is_string(post_time) && *post_time ? post_time : "00:00:00"); - time_t t = xs_parse_iso_date(local_pubdate, 1); + time_t t = xs_parse_iso_date(post_pubdate, 0); if (t != 0) { + const char *tz = xs_dict_get_def(snac.config, "tz", "UTC"); + + t -= xs_tz_offset(tz); + xs *iso_date = xs_str_iso_date(t); msg = xs_dict_set(msg, "published", iso_date); snac_debug(&snac, 1, xs_fmt("Published date: [%s]", iso_date)); } else - snac_log(&snac, xs_fmt("Invalid post date: [%s]", local_pubdate)); + snac_log(&snac, xs_fmt("Invalid post date: [%s]", post_pubdate)); } /* is the published date from the future? */ diff --git a/xs_time.h b/xs_time.h index 0e004dc..eaced75 100644 --- a/xs_time.h +++ b/xs_time.h @@ -15,6 +15,8 @@ time_t xs_parse_time(const char *str, const char *fmt, int local); #define xs_parse_localtime(str, fmt) xs_parse_time(str, fmt, 1) #define xs_parse_utctime(str, fmt) xs_parse_time(str, fmt, 0) xs_str *xs_str_time_diff(time_t time_diff); +xs_list *xs_tz_list(void); +int xs_tz_offset(const char *tz); #ifdef XS_IMPLEMENTATION @@ -106,6 +108,75 @@ time_t xs_parse_iso_date(const char *iso_date, int local) } +/** timezones **/ + +/* intentionally dead simple */ + +struct { + const char *tz; /* timezone name */ + float h_offset; /* hour offset */ +} xs_tz[] = { + { "UTC", 0 }, + { "GMT", 0 }, + { "GMT+1", -1 }, + { "GMT+2", -2 }, + { "GMT+3", -3 }, + { "GMT+4", -4 }, + { "GMT+5", -5 }, + { "GMT+6", -6 }, + { "GMT+7", -7 }, + { "GMT+8", -8 }, + { "GMT+9", -9 }, + { "GMT+10", -10 }, + { "GMT+11", -11 }, + { "GMT+12", -12 }, + { "GMT-1", 1 }, + { "GMT-2", 2 }, + { "GMT-3", 3 }, + { "GMT-4", 4 }, + { "GMT-5", 5 }, + { "GMT-6", 6 }, + { "GMT-7", 7 }, + { "GMT-8", 8 }, + { "GMT-9", 9 }, + { "GMT-10", 10 }, + { "GMT-11", 11 }, + { "GMT-12", 12 }, + { "GMT-13", 13 }, + { "GMT-14", 14 }, + { "GMT-15", 15 }, + { "CET", -1 }, + { "CST", -6 }, + { "MST", -7 }, + { "PST", -8 }, + { NULL, 0 } +}; + + +xs_list *xs_tz_list(void) +/* returns the list of supported timezones */ +{ + xs_list *l = xs_list_new(); + + for (int n = 0; xs_tz[n].tz != NULL; n++) + l = xs_list_append(l, xs_tz[n].tz); + + return l; +} + + +int xs_tz_offset(const char *tz) +/* returns the offset in seconds from the specified Time Zone to UTC */ +{ + for (int n = 0; xs_tz[n].tz != NULL; n++) { + if (strcmp(xs_tz[n].tz, tz) == 0) + return xs_tz[n].h_offset * 3600; + } + + return 0; +} + + #endif /* XS_IMPLEMENTATION */ #endif /* _XS_TIME_H */ -- cgit From f1f288699805b13bcd8f296667923ae5d2ae45ed Mon Sep 17 00:00:00 2001 From: default Date: Sun, 13 Apr 2025 09:33:17 +0200 Subject: Fixed offset sign because I'm a MORON. --- html.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'html.c') diff --git a/html.c b/html.c index afbc716..b04e001 100644 --- a/html.c +++ b/html.c @@ -4367,7 +4367,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, if (t != 0) { const char *tz = xs_dict_get_def(snac.config, "tz", "UTC"); - t -= xs_tz_offset(tz); + t += xs_tz_offset(tz); xs *iso_date = xs_str_iso_date(t); msg = xs_dict_set(msg, "published", iso_date); -- cgit From fb9e0fd21b7210e2ff71cc364b2285b1231fff60 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 13 Apr 2025 10:04:31 +0200 Subject: Mention the timezone in the 'post date and time' prompt. --- html.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'html.c') diff --git a/html.c b/html.c index b04e001..68a6b73 100644 --- a/html.c +++ b/html.c @@ -455,13 +455,15 @@ xs_html *html_note(snac *user, const char *summary, } if (edit_id == NULL || is_draft || is_scheduled(user, edit_id)) { + xs *pdat = xs_fmt(L("Post date and time (timezone: %s):"), xs_dict_get_def(user->config, "tz", "UTC")); + xs_html_add(form, xs_html_tag("p", xs_html_tag("details", xs_html_tag("summary", xs_html_text(L("Scheduled post..."))), xs_html_tag("p", - xs_html_text(L("Post date and time:")), + xs_html_text(pdat), xs_html_sctag("br", NULL), xs_html_sctag("input", xs_html_attr("type", "date"), -- cgit From 81538904210e9092760ce7c6b043eaaa166509b6 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 13 Apr 2025 14:12:37 +0200 Subject: More timezone tweaks. --- html.c | 2 +- xs_time.h | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index 68a6b73..a6f79de 100644 --- a/html.c +++ b/html.c @@ -4369,7 +4369,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, if (t != 0) { const char *tz = xs_dict_get_def(snac.config, "tz", "UTC"); - t += xs_tz_offset(tz); + t -= xs_tz_offset(tz); xs *iso_date = xs_str_iso_date(t); msg = xs_dict_set(msg, "published", iso_date); diff --git a/xs_time.h b/xs_time.h index 4da9463..6872c51 100644 --- a/xs_time.h +++ b/xs_time.h @@ -116,7 +116,36 @@ struct { const char *tz; /* timezone name */ float h_offset; /* hour offset */ } xs_tz[] = { - { "UTC", 0 }, + { "UTC", 0 }, + { "WET (Western European Time)", 0 }, + { "WEST (Western European Summer Time)", 1 }, + { "CET (Central European Time)", 1 }, + { "CEST (Central European Summer Time)", 2 }, + { "EET (Eastern European Time)", 2 }, + { "EEST (Eastern European Summer Time)", 3 }, + { "MSK (Moskow Time Zone)", 3 }, + { "EST (Eastern Time Zone)", -5 }, + { "AST (Atlantic Time Zone)", -4 }, + { "ADT (Atlantic Daylight Time Zone)", -3 }, + { "CST (Central Time Zone)", -6 }, + { "CDT (Central Daylight Time Zone)", -5 }, + { "MST (Mountain Time Zone)", -7 }, + { "MDT (Mountain Daylight Time Zone)", -6 }, + { "PST (Pacific Time Zone)", -8 }, + { "PDT (Pacific Daylight Time Zone)", -7 }, + { "AKST (Alaska Time Zone)", -9 }, + { "AKDT (Alaska Daylight Time Zone)", -8 }, + { "China Time Zone", 8 }, + { "IST (Israel Standard Time)", 2 }, + { "IDT (Israel Daylight Standard Time)", 3 }, + { "WITA (Western Indonesia Time)", 8 }, + { "AWST (Australian Western Time)", 8 }, + { "ACST (Australian Eastern Time)", 9.5 }, + { "ACDT (Australian Daylight Eastern Time)", 10.5 }, + { "AEST (Australian Eastern Time)", 10 }, + { "AEDT (Australian Daylight Eastern Time)", 11 }, + { "NZST (New Zealand Time)", 12 }, + { "NZDT (New Zealand Daylight Time)", 13 }, { "GMT", 0 }, { "GMT+1", -1 }, { "GMT+2", -2 }, @@ -144,13 +173,6 @@ struct { { "GMT-12", 12 }, { "GMT-13", 13 }, { "GMT-14", 14 }, - { "GMT-15", 15 }, - { "WET", 0 }, - { "CET", -1 }, - { "AST", -4 }, - { "CST", -6 }, - { "MST", -7 }, - { "PST", -8 }, { NULL, 0 } }; -- cgit From 848bd3e865fb2daf75d76cbb75a4a39f9b82b516 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 13 Apr 2025 14:30:50 +0200 Subject: Cache the timezone inside the snac struct. --- data.c | 2 ++ html.c | 6 ++---- snac.h | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'html.c') diff --git a/data.c b/data.c index 6661472..440e9df 100644 --- a/data.c +++ b/data.c @@ -282,6 +282,8 @@ int user_open(snac *user, const char *uid) } else srv_log(xs_fmt("error parsing '%s'", cfg_file)); + + user->tz = xs_dict_get_def(user->config, "tz", "UTC"); } else srv_debug(2, xs_fmt("error opening '%s' %d", cfg_file, errno)); diff --git a/html.c b/html.c index a6f79de..2e7f87c 100644 --- a/html.c +++ b/html.c @@ -455,7 +455,7 @@ xs_html *html_note(snac *user, const char *summary, } if (edit_id == NULL || is_draft || is_scheduled(user, edit_id)) { - xs *pdat = xs_fmt(L("Post date and time (timezone: %s):"), xs_dict_get_def(user->config, "tz", "UTC")); + xs *pdat = xs_fmt(L("Post date and time (timezone: %s):"), user->tz); xs_html_add(form, xs_html_tag("p", @@ -4367,9 +4367,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, time_t t = xs_parse_iso_date(post_pubdate, 0); if (t != 0) { - const char *tz = xs_dict_get_def(snac.config, "tz", "UTC"); - - t -= xs_tz_offset(tz); + t -= xs_tz_offset(snac.tz); xs *iso_date = xs_str_iso_date(t); msg = xs_dict_set(msg, "published", iso_date); diff --git a/snac.h b/snac.h index 0d2aafe..5a19467 100644 --- a/snac.h +++ b/snac.h @@ -61,6 +61,7 @@ typedef struct { xs_str *actor; /* actor url */ xs_str *md5; /* actor url md5 */ const xs_dict *lang;/* string translation dict */ + const char *tz; /* configured timezone */ } snac; typedef struct { -- cgit From a28638b4c18abacabd02fef4a51dde80bf4d5db4 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 13 Apr 2025 14:39:46 +0200 Subject: More timezone work. --- html.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'html.c') diff --git a/html.c b/html.c index 2e7f87c..d807f4b 100644 --- a/html.c +++ b/html.c @@ -1318,6 +1318,27 @@ xs_html *html_top_controls(snac *user) xs_html_attr("value", lang))); } + /* timezone */ + xs_html *tz_select = xs_html_tag("select", + xs_html_attr("name", "tz")); + + xs *tzs = xs_tz_list(); + const char *tz; + + xs_list_foreach(tzs, tz) { + if (strcmp(tz, user->tz) == 0) + xs_html_add(tz_select, + xs_html_tag("option", + xs_html_text(tz), + xs_html_attr("value", tz), + xs_html_attr("selected", "selected"))); + else + xs_html_add(tz_select, + xs_html_tag("option", + xs_html_text(tz), + xs_html_attr("value", tz))); + } + xs *user_setup_action = xs_fmt("%s/admin/user-setup", user->actor); xs_html_add(top_controls, @@ -1513,6 +1534,11 @@ xs_html *html_top_controls(snac *user) xs_html_sctag("br", NULL), lang_select), + xs_html_tag("p", + xs_html_text(L("Time zone:")), + xs_html_sctag("br", NULL), + tz_select), + xs_html_tag("p", xs_html_text(L("New password:")), xs_html_sctag("br", NULL), @@ -4755,6 +4781,8 @@ int html_post_handler(const xs_dict *req, const char *q_path, snac.config = xs_dict_set(snac.config, "show_contact_metrics", xs_stock(XSTYPE_FALSE)); if ((v = xs_dict_get(p_vars, "web_ui_lang")) != NULL) snac.config = xs_dict_set(snac.config, "lang", v); + if ((v = xs_dict_get(p_vars, "tz")) != NULL) + snac.config = xs_dict_set(snac.config, "tz", v); snac.config = xs_dict_set(snac.config, "latitude", xs_dict_get_def(p_vars, "latitude", "")); snac.config = xs_dict_set(snac.config, "longitude", xs_dict_get_def(p_vars, "longitude", "")); -- cgit