]> git.plutz.net Git - rawnet/blobdiff - index.cgi
styling of channel display
[rawnet] / index.cgi
index fe324147c3ac60ce75dfd95067ec6ca7aece9862..9beb6a9d6674369ef5cd1e2ea273aa0025e43ece 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+USER_REGISTRATION=false
 USER_REQUIREEMAIL=false
 
 . "${_EXEC:-${0%/*}}"/cgilite/cgilite.sh
@@ -15,27 +16,69 @@ else
   markdown() { busybox awk -f "$_EXEC/cgilite/markdown.awk"; }
 fi
 
+checked(){
+  local check="$1"; shift 1;
+  for comp in "$@"; do
+    if [ "$check" = "$comp" ] || [ "$check" -eq "$comp" ]; then
+      printf 'checked="checked"'
+      break;
+    fi 2>/dev/null
+  done
+}
+selected(){
+  local check="$1"; shift 1;
+  for comp in "$@"; do
+    if [ "$check" = "$comp" ] || [ "$check" -eq "$comp" ]; then
+      printf 'selected="selected"'
+      break;
+    fi 2>/dev/null
+  done
+}
+
+w_user_login(){
+  if [ ! "$USER_ID" ]; then
+    cat <<-EOF
+       [form #user_login .login method=POST
+         [label Login]
+         [input name=uname placeholder="Username or Email" autocomplete=off]
+         [input type=password name=pw placeholder="Passphrase"]
+         [submit "action" "user_login" Login]
+         $([ "$USER_REGISTRATION" = true ] && printf '[a href="%s/register/" Register]' "$_BASE")
+       ]
+       EOF
+  elif [ "$USER_ID" ]; then
+    cat <<-EOF
+       [form #user_login .logout method=POST
+         [p Logged in as [span . $(HTML ${USER_NAME})]]
+         $([ "$USER_REGISTRATION" != true ] && printf '[a href="%s/invite/" Invite Friend]' "$_BASE")
+         [submit "action" "user_logout" Logout]
+       ]
+       EOF
+  fi
+}
+
 yield_page(){
   title="${1:-RAW:NET}" page="$2"
   printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \
                   "Content-Security-Policy: script-src 'none'" \
                   ''
-  { printf '[html
-    [head
-      [meta name="viewport" content="width=device-width"]
-      [link rel="stylesheet" type="text/css" href="%s/cgilite/common.css"]
-      [link rel="stylesheet" type="text/css" href="%s/rawnet.css"]
-      [title %s]
-    ] [body class="%s"
-  ' "$_BASE" "$_BASE" "$(HTML "$title")" "$page"
-  printf '
-      [header
-        [form method=POST action="%s/search/"
-          [input name=search placeholder="Search"]
-        ]
-      ]' "$_BASE"
+  { cat <<-EOF
+       [!DOCTYPE HTML]
+       [html [head
+         [meta name="viewport" content="width=device-width"]
+         [link rel="stylesheet" type="text/css" href="$_BASE/cgilite/common.css"]
+         [link rel="stylesheet" type="text/css" href="$_BASE/rawnet.css"]
+         [title . $(HTML "$title")]
+       ] [body class="$page"
+         [header
+           [form method=POST action="$_BASE/search/"
+             [input name=search placeholder="Search"]
+           ]
+           $(w_user_login)
+         ][main
+       EOF
   cat
-  printf '] ]'
+  printf ']]]'
   } |"$_EXEC/cgilite/html-sh.sed" -u
 }