]> git.plutz.net Git - bookman/blobdiff - index.cgi
make "new folder" button visible again
[bookman] / index.cgi
index 4f24149bd8f53024b5903c7e4a1ed37196185b22..e96c9f01e750c7c323a8b7d031177918f6c96e7f 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -92,8 +92,8 @@ QRYID="$(GET    id |checkid)"
 BDB="users/${COKID}"
 
 if [ -n "$QRYID" ]; then
-  printf '%s 303 See Other\r\n' "$SERVER_PROTOCOL"
-  printf 'Location: %s\r\n' "${SCRIPT_NAME}?${QUERY_STRING#id=*&}"
+  printf 'Status: 303 See Other\r\n'
+  printf 'Location: %s\r\n' "${SCRIPT_NAME}?${QUERY_STRING#id=????????????}"
   SET_COOKIE +8640000 "id=${QRYID}"
   printf '\r\n'
   exit 0
@@ -103,6 +103,7 @@ elif [ -z "$COKID" -a -z "$QRYID" ]; then
   cat <<-EOF
        <!DOCTYPE HTML>
        <HTML><head>
+         <meta name="viewport" content="width=device-width" />
          <title>Bookman - New Collection</title>
        </head><body id="newcollection">
          <h1>You have not yet set up a collection on this server.</h1>
@@ -111,12 +112,13 @@ elif [ -z "$COKID" -a -z "$QRYID" ]; then
        EOF
   exit 0
 elif ! [ -d "${BDB}" ]; then
-  printf '%s 404 Not Found\r\n' "$SERVER_PROTOCOL"
+  printf 'Status: 404 Not Found\r\n'
   printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
 
   cat <<-EOF
        <!DOCTYPE HTML>
        <HTML><head>
+         <meta name="viewport" content="width=device-width" />
          <title>Bookman - 404</title>
        </head><body id="missingcollection">
          <h1>The collection you requested does not exist on this server.</h1>
@@ -132,7 +134,7 @@ case "$(GET action)" in
 
     { git init "users/${NEWID}" || mkdir -p "users/${NEWID}"; } >&-
 
-    printf '%s 303 See Other\r\n' "$SERVER_PROTOCOL"
+    printf 'Status: 303 See Other\r\n'
     printf 'Location: %s\r\n' "${SCRIPT_NAME}?id=${NEWID}"
     SET_COOKIE +8640000 "id=${NEWID}"
     printf '\r\n'
@@ -173,8 +175,11 @@ case "$(GET action)" in
     file="${BDB}/${fid}.bm"
     tfile="${BDB}/${target}.bm"
     if [ "$(POST control)" = confirm -a -f "$file" ]; then
-      if [ "$target" = "____________" ] || tail -n+2 "$file" >>"$tfile"; then
-        rm -f "$file" >&-
+      if [ "$target" = "____________" ]; then
+        rm -f "$file" "${file%.bm}.cache" >&-
+        git -C "${BDB}" commit -m "Deleted folder ${fid}" -- "${fid}.bm" >&-
+      elif tail -n+2 "$file" >>"$tfile"; then
+        rm -f "$file" "${file%.bm}.cache" >&-
         git -C "${BDB}" commit -m "Deleted folder ${fid}" -- "${fid}.bm" "${target}.bm" >&-
       fi
     fi
@@ -202,12 +207,19 @@ case "$(GET action)" in
     url="$(POST url |head -n1)"
     file="${BDB}/${fid}.bm"
     bid="$(timeid)"
-    if [ -n "$name" -a -f "${file}" ]; then
+    ctl="$(POST control)"
+    [ "$url" = "${url#*://}" ] && url="http://$url"
+
+    if [ -n "$name" -a -n "$url" -a -f "${file}" -a "$ctl" = "confirm" ]; then
       printf '%s\t%s\t%s\n' "$bid" "$(HTML "$name")" "$url" >>"${file}"
       git -C "${BDB}" commit -m "New Bookmark: ${name} in ${fid}" -- "${fid}.bm" >&-
+      getFavicon "$url" "$bid"
+      REDIRECT "${SCRIPT_NAME}#${fid}"
+    elif [ "$ctl" = "confirm" ]; then
+      REDIRECT "${SCRIPT_NAME}?newbm=${fid}&nbmurl=${url}&nbmname=${name}"
+    else
+      REDIRECT "${SCRIPT_NAME}#${fid}"
     fi
-    getFavicon "$url" "$bid"
-    REDIRECT "${SCRIPT_NAME}#${fid}"
     ;;
   modbookmark)
     bid="$(POST bid | checkid)"
@@ -272,6 +284,44 @@ case "$(GET action)" in
     ;;
 esac
 
+bookmarkgen(){
+  fid="$(GET newbm |checkid)"
+  name="$(GET nbmname)"
+  url="$(GET nbmurl)"
+  file="${BDB}/${fid}.bm"
+
+  if [ -z "$name" -a -n "$url" ]; then
+    name="$(wget -O- "$url" \
+            | head -c4096 \
+            | sed -rn ':X;$bY;N;bX;:Y; s;^.*<title[^>]*>([^<]+)<.*$;\1;p;'
+          )"
+  fi
+
+  if [ -n "$fid" -o -n "$name" -o -n "$url" ]; then
+    [ "$url" = "${url#*://}" ] && url="http://$url"
+    cat <<-EOF
+       <form class="dialog newbookmark" method="POST" action="${SCRIPT_NAME}?action=newbookmark">
+          <h1>New Bookmark</h1>
+         <label>Folder:</label>
+         <select name="fid">
+           $(list_folders |while read id n; do
+             [ "$id" = "$fid" ] \
+             && printf '<option value="%s" selected="selected">%s</option>' "$id" "$n" \
+             || printf '<option value="%s">%s</option>' "$id" "$n"
+           done)
+           $(printf '<option value="%s">%s</option>' $(list_folders))
+         </select>
+         <label>Name:</label>
+         <input type="text" name="name" value="$(HTML ${name})")" placeholder="Name" />
+         <label>URL:</label>
+         <input type="text" name="url"  value="$(HTML "${url}")")" placeholder="URL" />
+         <button type="submit" name="control" value="confirm">OK</button>
+         <button type="submit" name="control" value="cancel">Cancel</button>
+       </form>
+       EOF
+  fi
+}
+
 bookmarkmod(){
   bmod="$(GET bmodify |checkid)"
   bmove="$(GET bmove |checkid)"
@@ -282,7 +332,7 @@ bookmarkmod(){
        $(grep -m1 "^${bmod}" "$file")
        EOF
     cat <<-EOF
-       <form class="modbookmark" method="POST" action="${SCRIPT_NAME}?action=modbookmark">
+       <form class="dialog modbookmark" method="POST" action="${SCRIPT_NAME}?action=modbookmark">
          <input type="hidden" name="bid" value="${bid}" />
          <h1>Modify: ${name}</h1>
          <label class="tab">Modify</label>
@@ -301,7 +351,7 @@ bookmarkmod(){
        $(grep -m1 "^${bmove}" "$file")
        EOF
     cat <<-EOF
-       <form class="modbookmark" method="POST" action="${SCRIPT_NAME}?action=movebookmark">
+       <form class="dialog modbookmark" method="POST" action="${SCRIPT_NAME}?action=movebookmark">
          <input type="hidden" name="bid" value="${bid}" />
          <h1>Move: ${name}</h1>
          <a class="tab" href="${SCRIPT_NAME}?bmodify=${bid}">Modify</a>
@@ -358,7 +408,7 @@ foldermod(){
   if [ -n "$fmodify" ]; then
     read fid fname order <"${BDB}/${fmodify}.bm"
     cat <<-EOF
-       <form class="modfolder rename" method="POST" action="${SCRIPT_NAME}?action=modfolder">
+       <form class="dialog modfolder rename" method="POST" action="${SCRIPT_NAME}?action=modfolder">
           <h1>Rename Folder: ${fname}</h1>
          <input type="hidden" name="fid" value="${fid}" />
          <label class="tab">Rename</label>
@@ -374,7 +424,7 @@ foldermod(){
   elif [ -n "$fdelete" ]; then
     read fid fname order <"${BDB}/${fdelete}.bm"
     cat <<-EOF
-       <form class="modfolder delete" method="POST" action="${SCRIPT_NAME}?action=delfolder">
+       <form class="dialog modfolder delete" method="POST" action="${SCRIPT_NAME}?action=delfolder">
           <h1>Delete Folder: ${fname}</h1>
          <input type="hidden" name="fid" value="${fid}" />
          <a class="tab" href="${SCRIPT_NAME}?fmodify=${fid}">Rename</a>
@@ -393,7 +443,7 @@ foldermod(){
   elif [ -n "$fmove" ]; then
     read fid fname order <"${BDB}/${fmove}.bm"
     cat <<-EOF
-       <form class="modfolder move" method="POST" action="${SCRIPT_NAME}?action=movefolder">
+       <form class="dialog modfolder move" method="POST" action="${SCRIPT_NAME}?action=movefolder">
           <h1>Move Folder: ${fname}</h1>
          <input type="hidden" name="fid" value="${fid}" />
          <a class="tab" href="${SCRIPT_NAME}?fmodify=${fid}">Rename</a>
@@ -416,7 +466,7 @@ show_folders(){
   | while read fid fname order; do
     file="${BDB}/${fid}.bm"
     cache="${BDB}/${fid}.cache"
-    if [ "${cache}" -nt "${file}" ]; then
+    if [ "${cache}" -nt "${file}" -a "${cache}" -nt "$0" ]; then
       cat "$cache"
     else
       tee "$cache" <<-EOF
@@ -424,12 +474,7 @@ show_folders(){
          <h1>${fname}</h1>
          <a class="modify" href="${SCRIPT_NAME}?fmodify=${fid}">Modify folder "${fname}"</a>
          $(show_bookmarks "$fid")
-          <form class="newbookmark" method="POST" action="${SCRIPT_NAME}?action=newbookmark">
-           <input type="hidden" name="fid" value="${fid}" />
-           <input type="text" name="name" value="" placeholder="Name" />
-           <input type="text" name="url"  value="" placeholder="URL" />
-           <button type="submit">New Bookmark</button>
-          </form>
+          <a class="new bookmark" href="${SCRIPT_NAME}?newbm=${fid}">New Bookmark</a>
        </section>
        EOF
     fi
@@ -442,16 +487,21 @@ printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
 cat <<EOF
 <!DOCTYPE HTML>
 <HTML><head>
+  <meta name="viewport" content="width=device-width" />
   <title>Bookman - Your Collection</title>
   <link rel="stylesheet" type="text/css" href="bookmarks.css" />
 </head><body id="collection">
   $(foldermod)
   $(bookmarkmod)
+  $(bookmarkgen)
   $(show_folders)
   <form class="newfolder" method="POST" action="${SCRIPT_NAME}?action=newfolder">
     <input type="text" name="name" value="" placeholder="New Folder" />
     <button type="submit">New</button>
   </form>
+  <footer>
+    <a href="${SCRIPT_NAME}?id=${COKID}">Permalink for this Collection</a>
+  </footer>
 </body></HTML>
 EOF