diff options
author | June McEnroe <june@causal.agency> | 2020-07-17 13:23:21 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-07-17 13:23:21 -0400 |
commit | 0a054aeb9ce8430a62be05283300ec34e9c2b0af (patch) | |
tree | 344ec24121d800a28df101defd9d01140dda4db1 /events.c | |
parent | Add margin to inputs (diff) | |
download | scooper-0a054aeb9ce8430a62be05283300ec34e9c2b0af.tar.gz scooper-0a054aeb9ce8430a62be05283300ec34e9c2b0af.zip |
Add export option
Adding the export query parameter to any page downloads a .html with the default stylesheet embedded, and all navigation, forms and internal links removed, for being able to share some part of a private instance of litterbox.
Diffstat (limited to 'events.c')
-rw-r--r-- | events.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/events.c b/events.c index 932f535..7f56081 100644 --- a/events.c +++ b/events.c @@ -36,6 +36,7 @@ static const char *timestamp(time_t time) { static enum kcgi_err dateForm(struct khtmlreq *html, struct kreq *req, const char *current) { + if (req->fieldmap[Export]) return KCGI_OK; struct tm tm = {0}; if (!strptime(current, "%F", &tm)) { tm = *gmtime(&(time_t) { time(NULL) }); @@ -66,6 +67,7 @@ dateForm(struct khtmlreq *html, struct kreq *req, const char *current) { static enum kcgi_err displayForm(struct khtmlreq *html, struct kreq *req, bool tidy) { + if (req->fieldmap[Export]) return KCGI_OK; return 0 || khtml_attr( html, KELEM_FORM, @@ -203,7 +205,7 @@ enum kcgi_err eventsPage(struct kreq *req) { struct khtmlreq html; error = error || khtml_open(&html, req, 0) - || htmlHead(&html, context) + || htmlHead(&html, req, context) || htmlNav(&html, req) || khtml_elem(&html, KELEM_DIV) || dateForm(&html, req, time) @@ -257,7 +259,7 @@ enum kcgi_err eventsPage(struct kreq *req) { event.target = sqlite3_column_text(events, i++); event.message = sqlite3_column_text(events, i++); - if (!rows) { + if (!rows && !req->fieldmap[Export]) { char *href = NULL; char *page = pageURL( network, context, Before, event.time + eventsOverlap, tidy @@ -291,7 +293,7 @@ enum kcgi_err eventsPage(struct kreq *req) { } if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db)); - if (rows && (rows == eventsLimit || req->fieldmap[Before])) { + if ((rows == eventsLimit || req->fieldmap[Before]) && !req->fieldmap[Export]) { char *href = pageURL( network, context, After, prevTime - eventsOverlap, tidy ); @@ -313,5 +315,5 @@ enum kcgi_err eventsPage(struct kreq *req) { if (error) return error; } - return htmlFooter(&html) || khtml_close(&html); + return htmlFooter(&html, req) || khtml_close(&html); } |