]> git.plutz.net Git - webpoll/blobdiff - poll.sh
optional bookmarking of poll and admin pages
[webpoll] / poll.sh
diff --git a/poll.sh b/poll.sh
index d7c0defa4b0cc896a24965327d2e2a6e7b8081e6..5624284347abf702012712528d37fb126fa39f12 100644 (file)
--- a/poll.sh
+++ b/poll.sh
@@ -6,6 +6,15 @@ file="${_DATA}/${id}"
 #cancel if poll is invalid
 [ "$id" -a -f "$file" ] || REDIRECT "$_BASE/"
 
+if expr match "$bookmarks" ".*${id}.*" >/dev/null; then
+  :
+elif [ "$bookmarks" ]; then
+  SET_COOKIE +$((182 * 86400)) bookmarks="${bookmarks} ${id}" Path="${_BASE}/"
+fi
+
+admin="$(expr match "$bookmarks" ".*$id/\([a-zA-Z0-9:=]\{16\}\).*")"
+admin="$(DBM "$file" get adminkey |grep -xF "$admin")"
+
 tkey() {
   # convert time stamps for use in POST keys
   local str="$1" out
@@ -79,7 +88,7 @@ table_poll() {
   if [ "$splittimes" = yes -o "$todall" ]; then
     printf '[tr .tod [th]'
     for time in $timelist; do
-      [ "${time#*_}" = "${time}" ] && time="${time}_"
+      [ "${time#*_}" = "${time}" ] && time="_${time}"
       printf '[th . %s]' "${time#*_}"
     done
     printf '[th]]\n'
@@ -196,6 +205,10 @@ if [ "$REQUEST_METHOD" = POST ]; then
     DBM "$file" delete "reply_yes_${delete}"
     DBM "$file" delete "reply_no_${delete}"
     DBM "$file" delete "reply_maybe_${delete}"
+
+  elif [ "$(POST bookmark)" -a ! "$bookmarks" ]; then
+    SET_COOKIE +$((182 * 86400)) bookmarks="${id}" Path="${_BASE}/"
+
   fi
   REDIRECT "${_BASE}${PATH_INFO}"
   
@@ -209,6 +222,13 @@ else
            $(DBM "$file" get description |markdown)
          ]
          $(table_poll || printf '[p Poll parameters are invalid]')
+          $(if [ "$admin" ]; then
+            printf '[section .bookmark You have bookmarked the admin page of this poll: [a href="./%s" modify poll]]' "$(URL ${id}/${admin})"
+          elif [ "$bookmarks" ]; then
+            printf '[section .bookmark This poll has been bookmarked and is accessible via a link on the front page.]'
+          else
+            printf '[section .bookmark Polls are accessible only via their URL. You can set a Cookie to bookmark all polls you visit. Bookmarked polls will be listed on the frontpage.<br/> [submit "bookmark" "add" Set Cookie]]'
+          fi)
        ]
        EOF
 fi