summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--contexts.c1
-rw-r--r--html.c54
-rw-r--r--networks.c1
-rw-r--r--server.h3
4 files changed, 59 insertions, 0 deletions
diff --git a/contexts.c b/contexts.c
index 7adfa34..c75202a 100644
--- a/contexts.c
+++ b/contexts.c
@@ -41,6 +41,7 @@ enum kcgi_err pageContexts(struct kreq *req) {
 		|| khtml_open(&html, req, KHTML_PRETTY)
 		|| htmlHead(&html, network)
 		|| htmlNav(&html, network, NULL)
+		|| htmlSearch(&html, network, NULL)
 		|| khtml_elem(&html, KELEM_UL);
 	if (error) return error;
 
diff --git a/html.c b/html.c
index ad80b6f..59ecc30 100644
--- a/html.c
+++ b/html.c
@@ -89,3 +89,57 @@ htmlNav(struct khtmlreq *html, const char *network, const char *context) {
 
 	return khtml_closeelem(html, 2);
 }
+
+enum kcgi_err
+htmlSearch(struct khtmlreq *html, const char *network, const char *context) {
+	char label[256];
+	snprintf(
+		label, sizeof(label), "Search%s%s",
+		(network ? " " : ""), (context ? context : network ? network : "")
+	);
+
+	enum kcgi_err error = 0
+		|| khtml_attr(
+			html, KELEM_FORM,
+			KATTR_METHOD, "get",
+			KATTR_ACTION, Pages[Search],
+			KATTR__MAX
+		)
+		|| khtml_attr(
+			html, KELEM_INPUT,
+			KATTR_TYPE, "search",
+			KATTR_NAME, Keys[Query].name,
+			KATTR__MAX
+		)
+		|| khtml_attr(
+			html, KELEM_INPUT,
+			KATTR_TYPE, "submit",
+			KATTR_VALUE, label,
+			KATTR__MAX
+		);
+	if (error) return error;
+
+	if (network) {
+		error = khtml_attr(
+			html, KELEM_INPUT,
+			KATTR_TYPE, "hidden",
+			KATTR_NAME, Keys[Network].name,
+			KATTR_VALUE, network,
+			KATTR__MAX
+		);
+		if (error) return error;
+	}
+
+	if (context) {
+		error = khtml_attr(
+			html, KELEM_INPUT,
+			KATTR_TYPE, "hidden",
+			KATTR_NAME, Keys[Context].name,
+			KATTR_VALUE, context,
+			KATTR__MAX
+		);
+		if (error) return error;
+	}
+
+	return khtml_closeelem(html, 1);
+}
diff --git a/networks.c b/networks.c
index 15ca95d..a81722c 100644
--- a/networks.c
+++ b/networks.c
@@ -37,6 +37,7 @@ enum kcgi_err pageNetworks(struct kreq *req) {
 		|| khtml_open(&html, req, KHTML_PRETTY)
 		|| htmlHead(&html, "Networks")
 		|| htmlNav(&html, NULL, NULL)
+		|| htmlSearch(&html, NULL, NULL)
 		|| khtml_elem(&html, KELEM_UL);
 	if (error) return error;
 
diff --git a/server.h b/server.h
index 80eb5bb..9b665d7 100644
--- a/server.h
+++ b/server.h
@@ -127,3 +127,6 @@ enum kcgi_err htmlHead(struct khtmlreq *html, const char *title);
 enum kcgi_err htmlNav(
 	struct khtmlreq *html, const char *network, const char *context
 );
+enum kcgi_err htmlSearch(
+	struct khtmlreq *html, const char *network, const char *context
+);