--- /dev/null
+body {
+ text-align: left;
+ background-color: #EEF;
+ color: #000;
+}
+
+.folder {
+ column-width: 16em;
+ -moz-column-width: 16em;
+ -webkit-column-width: 16em;
+ column-gap: .5em;
+ -moz-column-gap: .5em;
+ -webkit-column-gap: .5em;
+ column-rule: 1px solid #BBB;
+ -moz-column-rule: 1px solid #BBB;
+ -webkit-column-rule: 1px solid #BBB;
+
+ background-color: #FFF;
+ overflow: none;
+
+ padding: .1em 1em .5em 1em;
+ margin: 0em 1em 1em 0em ;
+
+ border-width: 1px;
+ border-style: solid;
+ -moz-border-radius: 1em 1em .5em .5em;
+ -webkit-border-radius: 1em 1em .5em .5em;
+ border-radius: 1em 1em .5em .5em;
+}
+
+.fName {
+ width: 100%;
+ margin: 0px 0px .2em 0px;
+ border-style: none none solid none;
+ border-width: 1px;
+ border-color: #999;
+ text-indent: 1.5em;
+ font-weight: bold;
+ font-size: 1.3em;
+ color: #333;
+ -moz-column-span: all;
+ -webkit-column-span: all;
+ column-span: all;
+}
+.fName a {
+ text-decoration: none;
+ font-weight: normal;
+ color: #333;
+}
+.efName {
+ width: 100%;
+ border-style: none none solid none;
+ border-width: 1px;
+ border-color: #999;
+ display: none;
+ -moz-column-span: all;
+ -webkit-column-span: all;
+ column-span: all;
+}
+.efName a {
+ text-decoration: none;
+}
+
+.edButton {
+ width: 4em;
+ margin: 2px;
+ text-decoration: none;
+}
+
+.bmEdit {
+ display: none;
+ margin: .3em 0em .3em 0em;
+ border-style: solid none solid none;
+ border-width: 1px;
+ border-color: #BBB;
+ -moz-break-inside: avoid;
+ -webkit-break-inside: avoid;
+ break-inside: avoid;
+}
+.bmDisplay img {
+ position: relative;
+ top: 4px;
+}
--- /dev/null
+#!/bin/zsh
+bdir="bookmarks/${REMOTE_USER}"
+icodir=icodir
+alias wget="/usr/bin/wget -T 5 -t 1 -q -U ''"
+
+if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then
+ (head -c "${CONTENT_LENGTH}" | sed 's:&:\n:g'; echo) >$bdir/$(date +%s)
+fi
+
+moveName="$(echo -en "$(sed -rn '/mn=.+&mc=.+/{s:(^|.+&)mn=(.+)(&.+|$):\2:;s:\+: :g;s:%:\\x:g;p}' <<<"$QUERY_STRING")")"
+moveCont="$(echo -en "$(sed -rn '/mn=.+&mc=.+/{s:(^|.+&)mc=(.+)(&.+|$):\2:;s:\+: :g;s:%:\\x:g;p}' <<<"$QUERY_STRING")")"
+[ -n "$moveName" -a -n "$moveCont" ] && move=true || move=false
+
+[ -d "$bdir" ] || mkdir -p "$bdir"
+names=$(sed -rn 's:^name=(.*)$:\1:pg' $bdir/$(ls $bdir |tail -n1))
+hidecmd=$(for each in $(echo $names); do echo "try{hide('e_$each');}catch(e){};"; done)
+showcmd=$(for each in $(echo $names); do echo "try{show('d_$each');}catch(e){};"; done)
+
+delFolder=false
+delBookmark=false
+
+echo "
+<form action='index.cgi' method='post' accept-charset='utf-8'>
+ <div style='display:none;'>
+ qs $QUERY_STRING
+ mn $moveName
+ mc $moveCont
+"
+
+cat $bdir/$(ls $bdir |tail -n1) |while read line; do
+ case "$line" in
+ deleteFolder=*) delFolder=true
+ ;;
+ deleteBookmark=*) delBookmark=true
+ ;;
+ folder=*) echo '<!-- FOLDER -->'
+ fId=$(sed 's:^folder=::' <<<"$line")
+ [ -z "$fId" ] && fId='###'
+ fName="$(echo -ne "$(sed 's:+: :g;s:%:\\x:g' <<<"$fId")")"
+ $delFolder || echo "
+ <input type='hidden' name='title' value='New Bookmark'>
+ <input type='submit' name='content' value='New Bookmark'>
+ </div><div class='folder'>
+ <div class='fName' id='fName_$fId'>
+ <a href='#' onclick='javascript:hide(\"fName_$fId\");show(\"efName_$fId\")'>→</a>$fName
+ </div><div class='efName' id='efName_$fId'>
+ <a href='#' onclick='javascript:hide(\"efName_$fId\");show(\"fName_$fId\")'>←</a>
+ <input type='submit' value='Rename'><input type='submit' name='deleteFolder' value='Remove'>
+ <input type='text' name='folder' value='$fName'>
+ </div>
+ "
+ delFolder=false
+ $move && echo "
+ <div class='moveButton'>
+ <input type='hidden' name='title' value='$moveName'>
+ <button type='submit' name='content' value='$moveCont'>Move Here</button>
+ </div>
+ "
+ ;;
+ title=*)
+ bmId=$(sed 's:^title=::' <<<"$line")
+ [ -z "$bmId" ] && bmId='###'
+ bmName="$(echo -ne "$(sed 's:+: :g;s:%:\\x:g' <<<"$bmId")")"
+ ;;
+ content=*)
+ bmLink="$(echo -ne "$(sed 's:^content=::;s:+: :g;s:%:\\x:g' <<<"$line")")"
+ bmBase="$(sed -r 's:^(https?\://[^/]+)/?.*$:\1:' <<<"$bmLink")"
+ bmFav="$(sed -r 's:^(https?\://[^/]+)/?.*$:\1/favicon.ico:' <<<"$bmLink")"
+ bmFavFile="$icodir/$(sed -r 's:^https?\://([^/]+)/?.*$:\1.ico:' <<<"$bmLink")"
+ [ -f "$bmFavFile" ] || (wget -O - "$bmLink" |head -c 4096 |\
+ sed -rn "/<link.*rel=[\"'](shortcut )?icon[\"'].*>/Is:^.*<link.*href=[\"']([^\"']*)[\"'].*$:\1:ip" |\
+ read p && [ -n "$p" ] && (wget -O "$bmFavFile" "$p" || wget -O "$bmFavFile" "$bmBase/$p") ||\
+ wget -O "$bmFavFile" "$bmFav"
+ ) &
+ [ "$bmName" = "$moveName" -a "$bmLink" = "$moveCont" ] && delBookmark=true
+ $delBookmark || echo "
+ <div class='bmDisplay' id='d_$bmId'>
+ <a class='edButton' href='#' onclick='javascript:${hidecmd}${showcmd}show(\"e_$bmId\");hide(\"d_$bmId\");'>→</a>
+ <img width=16 height=16 src='$bmFavFile'>
+ <a href='$bmLink'>$bmName</a>
+ </div><div class='bmEdit' id='e_$bmId'>
+ <a class='edButton' href='#' onclick='javascript:show(\"d_$bmId\");hide(\"e_$bmId\");'>←</a>
+ <input type='submit' value='Update'><input type='submit' name='deleteBookmark' value='Remove'><br>
+ <a href='?mn=$bmName&mc=$bmLink'>Move Bookmark</a><br>
+ Name: <input type='text' name='title' value='$bmName'><br>
+ Link: <input type='text' name='content' value='$bmLink'>
+ </div>
+ "
+ $delBookmark || ($move && echo "
+ <div class='moveButton'>
+ <input type='hidden' name='title' value='$moveName'>
+ <button type='submit' name='content' value='$moveCont'>Move Here</button>
+ </div>
+ ")
+ delBookmark=false
+ ;;
+ *) echo "<!-- $line -->"
+ ;;
+ esac
+done
+
+echo "
+ <input type='hidden' name='title' value='New Bookmark'>
+ <input type='submit' name='content' value='New Bookmark'>
+ </div>
+ <input type='submit' value='Submit Changes'>
+ <input type='submit' name='folder' value='New Folder'>
+</form>
+"