optical preparation for vcard display
authorpaul <paul@plutz.net>
Mon, 7 Oct 2013 03:39:26 +0000 (03:39 +0000)
committerpaul <paul@plutz.net>
Mon, 7 Oct 2013 03:39:26 +0000 (03:39 +0000)
svn path=/trunk/; revision=10

pages/attendees.sh
templates/attendees.css.sh
templates/attendees.html.sh
templates/view_attendee.sh

index 75092c1..b6088d6 100755 (executable)
@@ -38,7 +38,7 @@ vcf_parse() {
     s:^X-YAHOO(;[^"\:]+|;"[^"]+")*\:(.*)$:018 IMPP\1\:ymsgr\:\2:p;
     s:^X-SIP(;[^"\:]+|;"[^"]+")*\:(sip\:)?(.*)$:018 IMPP\1\:sip\:\3:p;
     s:^ADR:019 ADR:p;
-    s:^LABEL:020 LABEL:p;
+    s:^LABEL(;[^"\:]+|;"[^"]+")*\:(.*)$:019 ADR;LABEL="\2"\1\::p;
     s:^URL:021 URL:p;
     s:^X-EVOLUTION-BLOG-URL:021 URL:p;
     s:^LANG:022 LANG:p;
@@ -56,12 +56,12 @@ vcf_parse() {
     s:^X-EVOLUTION-SPOUSE:025 RELATED\;TYPE=spouse;VALUE=text:p;
     s:^X-KADDRESSBOOK-X-SpouseName:025 RELATED\;TYPE=spouse;VALUE=text:p;
 
-    s:^BEGIN.*$::;
+    s:^BEGIN.*$:000 &:p;
     s:^CALADRURI.*$::;
     s:^CALURI.*$::;
     s:^CLASS.*$::;
     s:^CLIENTPIDMAP.*$::;
-    s:^END.*$::;
+    s:^END.*$:100 &:p;
     s:^FBURL.*$::;
     s:^GEO.*$::;
     s:^MAILER.*$::;
@@ -73,38 +73,60 @@ vcf_parse() {
     s:^SOURCE.*$::;
     s:^TZ.*$::;
     s:^UID.*$::;
-    s:^VERSION.*$::;
+    s:^VERSION.*$:000 VERSION\:4.0:p;
     s:^XML.*$::;
 
     s:^([A-Z].*)$:024 \1:p;
     ' \
   | sort |while read -r line; do
     case "$line" in
-      001*)
-       echo -E "$line"
-       ;;
-      002*)
+      00[012]*)
        echo -E "$line"
        ;;
       003*)
-       fn=$(echo "$line" |sed -r 's:^[0-9]{3} ([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:\3:g' |tr -d '\r')
+       fn=$(echo -E "$line" |sed -r 's:^[0-9]{3} ([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:\3:g' |tr -d '\r')
        ;;
       004*)
-       n=$(echo "$line" |sed -rn 's:^([0-9]{3} )([^;\:]+)(;[^"\:]+|;"[^"]+")*\:([^;]*)(\;[^;]*)(\;[^;]*)?(\;[^;]*)?(\;[^;]*)?$:\7 \5 \6 \4 \8:gp' |sed -r 's:,: :;s:\;: :g;s: +: :g' |tr -d '\r')
+       n=$(echo -E "$line" \
+         |sed -rn 's:^([0-9]{3} )([^;\:]+)(;[^"\:]+|;"[^"]+")*\:([^;]*)(\;[^;]*)(\;[^;]*)?(\;[^;]*)?(\;[^;]*)?$:\7 \5 \6 \4 \8:gp' \
+         |sed -r 's:,: :;s:\;: :g;s: +: :g' \
+         |tr -d '\r'
+       )
        ;;
       005*)
-       nick=$(echo "$line" |sed -r 's:^[0-9]{3} ([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:\3:g' |tr -d '\r')
+       nick=$(echo -E "$line" |sed -r 's:^[0-9]{3} ([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:\3:g' |tr -d '\r')
        ;;
-      *) [ -n "$fn" -a -n "$nick" ] && fn="$fn aka. $nick"
-         [ -n "$n"  -a -n "$nick" ] &&  n="$n aka. $nick"
-        [ -n "$fn" -a -z "$n" ] && echo "003 FN:$fn"
-        [ -n "$n" ]             && echo "003 FN:$n"
-        [ -z "$fn" -a -z "$n" ] && echo "003 FN:$nick"
+      *) [ -n "$n" ] && fn="$n"
+        [ -n "$fn" -a -n "$nick" ] && fn="$fn aka. $nick"
+        [ -n "$fn" ] && echo -E "003 FN:$fn" \
+                     || echo -E "003 FN:$nick"
         echo -E "$line"
         cat
        ;;
     esac
-  done | sed -r 's:^[0-9]{3} ([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:key=\1\nvalue=\3\ntag=\2:g'
+  done |tr -d '\r' \
+  | sed -r 's:^[0-9]{3} ([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:key="\1"\nvalue="\3"\ntag=\2:g' \
+  | while read -r line; do
+    case "$line" in
+      key=*) echo -E "$line"
+       ;;
+      value=*) echo -E "$line"
+       ;;
+      tag=*) ot=''
+            echo -E "$line" \
+            | sed -r 's:^tag=::;s:\;([A-Z+_-]+="[^"]+"|[A-Z+_-]+=[^\;]+):\n\1:g;' \
+            | sed -r 's:([A-Z+_-]+)="?(.*)"?:tag\[\1\]="\2":g' \
+            | sed -r '/^ *$/d' \
+            | sort |while read -r tag; do
+              nt="$(echo -E "$tag" |sed -r 's:^tag\[([A-Z+_-]+)\]="(.*)"$:\1:')"
+              nv="$(echo -E "$tag" |sed -r 's:^tag\[([A-Z+_-]+)\]="(.*)"$:\2:')"
+              [ "$nt" = "$ot" ] && vl="$nv,$vl" || vl="$nv"
+              echo -E "tag[$nt]=\"$vl\""
+              ot="$nt"
+            done
+       ;;
+    esac
+  done
 }
 
 case "$1" in
index a5d9035..52e771f 100644 (file)
@@ -6,10 +6,37 @@ cat <<EOF
 #cardlist {}
 
 .cardlist .card {
-  margin: 2px;
+  margin: 4px;
   border-width: 1px;
   border-style: solid;
-  padding: .5em 1em;
+  padding: .5em 1em 1em .5em;
+  min-height: 160px;
+  display: block;
+}
+
+.cardlist .card .PHOTO {
+  float: left;
+  position: absolute;
+  border-width: 1px;
+  border-style: solid;
+  padding: 1px;
+  margin: 1em .5em;
+  width: 96px;
+  max-height: 144px;
+}
+.cardlist .card .KEY {
+  margin-left: 120px;
+  font: normal bold 1em sans-serif;
+}
+
+.cardlist .card .VALUE {
+  font: normal normal 1em sans-serif;
+}
+
+.cardlist .card .FN {
+  margin: .25em .5em 1em 120px;
+  font: normal bold 2em sans-serif;
 }
 
 EOF
index 92b169c..002db63 100644 (file)
@@ -1,3 +1,5 @@
+. ${_EXEC}/templates/view_attendee.sh
+
 cat <<EOF
 <div class="filter">
 <form action="/" method="GET">
@@ -30,11 +32,7 @@ cat <<EOF
 <div class="cardlist">
   $(listcards |while read card; do
     echo '<div class="card">'
-    vcf_parse "$card" |sed -r '
-      s:^key=(.+)$:  <span class="label">\1</span>:g
-      s:^value=(.*)$:<span class="value">\1</span>:g
-      s:^tag=(.*)$:  <span class="tag"  >\1</span><br />:g
-    '
+    view_attendee "$card"
     echo '</div>'
   done)
 </div>
index e69de29..fa9241e 100755 (executable)
@@ -0,0 +1,95 @@
+declare -A item_name
+
+item_name[PHOTO]="Foto"
+item_name[LOGO]="Logo"
+item_name[FN]="Voller Name"
+item_name[SOUND]="Aussprache"
+item_name[GENDER]="Geschlecht"
+item_name[KIND]="Typ"
+item_name[TITLE]="Beruf"
+item_name[ROLE]="Position"
+item_name[ORG]="Organisation"
+item_name[MEMBER]="Mitglied"
+item_name[CATEGORIES]="Kategorien"
+item_name[ANNIVERSARY]="Jubiläum"
+item_name[BDAY]="Geburtstag"
+item_name[EMAIL]="E-Mail"
+item_name[TEL]="Telefon"
+item_name[IMPP]="Chat"
+item_name[ADR]="Anschrift"
+item_name[URL]="Webseite"
+item_name[LANG]="Sprache"
+item_name[NOTE]="Notiz"
+item_name
+item_name[RELATED]="Kontakte"
+item_name
+item_name[BEGIN]=""
+item_name[CALADRURI]=""
+item_name[CALURI]=""
+item_name[CLASS]=""
+item_name[CLIENTPIDMAP]=""
+item_name[END]=""
+item_name[FBURL]=""
+item_name[GEO]=""
+item_name[MAILER]=""
+item_name[NAME]=""
+item_name[PRODID]=""
+item_name[PROFILE]=""
+item_name[REV]=""
+item_name[SORT-STRING]=""
+item_name[SOURCE]=""
+item_name[TZ]=""
+item_name[UID]=""
+item_name[VERSION]=""
+item_name[XML]=""
+
+l10n() {
+  [ -n "$item_name[$1]" ] && echo "$item_name[$1]" || echo "$1"
+}
+
+view_card_item() {
+  debug "Item: $key"
+  case "$key" in
+    BEGIN|VERSION|END);;
+    PHOTO)
+      debug "Type: $tag[TYPE]"
+      echo "<img class=\"PHOTO\" src=\"data:image/$tag[TYPE];base64,$value\"/>"
+      ;;
+    FN)
+      echo "<h2 CLASS=\"FN\">$value</h2>"
+      ;;
+    *)
+      echo "<span class=\"KEY $key\">$(l10n "$key")"
+      [ -n "$tag[TYPE]" ] && echo "($tag[TYPE])"
+      echo ":</span>"
+      ;|
+    EMAIL)
+      echo "<a href=\"mailto:$value\" class=\"VALUE $key\">$value</a><br/>"
+      ;;
+    IMPP)
+      echo "<a href=\"$value\" class=\"VALUE $key\">"$(echo "$value" |cut -d: -f2-)"</a><br/>"
+      ;;
+    *)
+      echo "<span class=\"VALUE $key\">$value</span><br/>"
+      ;;
+  esac
+}
+
+view_attendee() {  #Parameter: Cardfile
+  key=""
+  vcf_parse "$1" |while read -r line; do
+    declare -A tag
+    case "$line" in
+      value*) eval "$line";;
+      tag*)   eval "$line";;
+      key*)
+        if [ -z "$key" ]; then
+          eval "$line"
+        else
+          view_card_item
+          eval "$line"
+        fi
+      ;;
+    esac
+  done
+}