diff options
Diffstat (limited to 'html.c')
-rw-r--r-- | html.c | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/html.c b/html.c index a28d84b..2f6be5f 100644 --- a/html.c +++ b/html.c @@ -30,18 +30,30 @@ const char *htmlStylesheet = "stylesheet.css"; -enum kcgi_err htmlHead(struct khtmlreq *html, const char *title) { +static enum kcgi_err htmlCSS(struct khtmlreq *html, struct kreq *req) { + if (req->fieldmap[Export]) { + return 0 + || khtml_elem(html, KELEM_STYLE) + || khttp_puts(req, CSS) + || khtml_closeelem(html, 1); + } else { + return khtml_attr( + html, KELEM_LINK, + KATTR_REL, "stylesheet", + KATTR_HREF, htmlStylesheet, + KATTR__MAX + ); + } +} + +enum kcgi_err +htmlHead(struct khtmlreq *html, struct kreq *req, const char *title) { return khtml_elem(html, KELEM_DOCTYPE) || khtml_attr(html, KELEM_META, KATTR_CHARSET, "utf-8", KATTR__MAX) || khtml_elem(html, KELEM_TITLE) || khtml_puts(html, title) || khtml_closeelem(html, 1) - || khtml_attr( - html, KELEM_LINK, - KATTR_REL, "stylesheet", - KATTR_HREF, htmlStylesheet, - KATTR__MAX - ) + || htmlCSS(html, req) || khtml_elem(html, KELEM_H1) || khtml_puts(html, title) || khtml_closeelem(html, 1); @@ -60,6 +72,8 @@ htmlHidden(struct khtmlreq *html, struct kreq *req, enum Key key) { } enum kcgi_err htmlNav(struct khtmlreq *html, struct kreq *req) { + if (req->fieldmap[Export]) return KCGI_OK; + enum kcgi_err error = 0 || khtml_elem(html, KELEM_NAV) || khtml_elem(html, KELEM_OL) @@ -255,10 +269,10 @@ static const char *timestamp(time_t time) { } static enum kcgi_err -eventTime(struct khtmlreq *html, const struct Event *event) { +eventTime(struct khtmlreq *html, struct kreq *req, struct Event *event) { char *page = NULL; char *href = NULL; - if (event->network && event->context) { + if (event->network && event->context && !req->fieldmap[Export]) { page = khttp_urlpart( NULL, NULL, Pages[Events], Keys[Network].name, event->network, @@ -290,6 +304,12 @@ eventTime(struct khtmlreq *html, const struct Event *event) { static enum kcgi_err eventNetwork(struct khtmlreq *html, struct kreq *req, struct Event *event) { if (!req->fieldmap[Query] || req->fieldmap[Network]) return KCGI_OK; + if (req->fieldmap[Export]) { + return 0 + || khtml_attr(html, KELEM_TD, KATTR_CLASS, "network", KATTR__MAX) + || khtml_puts(html, event->network) + || khtml_closeelem(html, 1); + } char *href = khttp_urlpart( NULL, NULL, Pages[Search], Keys[Query].name, req->fieldmap[Query]->parsed.s, @@ -309,6 +329,12 @@ eventNetwork(struct khtmlreq *html, struct kreq *req, struct Event *event) { static enum kcgi_err eventContext(struct khtmlreq *html, struct kreq *req, struct Event *event) { if (!req->fieldmap[Query] || req->fieldmap[Context]) return KCGI_OK; + if (req->fieldmap[Export]) { + return 0 + || khtml_attr(html, KELEM_TD, KATTR_CLASS, "context", KATTR__MAX) + || khtml_puts(html, event->context) + || khtml_closeelem(html, 1); + } char *href = khttp_urlpart( NULL, NULL, Pages[Search], Keys[Query].name, req->fieldmap[Query]->parsed.s, @@ -445,7 +471,7 @@ htmlEvent(struct khtmlreq *html, struct kreq *req, struct Event *event) { KATTR_CLASS, KATTRX_STRING, type, KATTR__MAX ) - || eventTime(html, event) + || eventTime(html, req, event) || eventNetwork(html, req, event) || eventContext(html, req, event) || eventNick(html, event) @@ -461,7 +487,8 @@ static const char *Columns = { "network, channel, query, nick, user, target, message" }; -enum kcgi_err htmlFooter(struct khtmlreq *html) { +enum kcgi_err htmlFooter(struct khtmlreq *html, struct kreq *req) { + if (req->fieldmap[Export]) return KCGI_OK; return 0 || khtml_closeto(html, 0) || khtml_elem(html, KELEM_FOOTER) |