slitaz-pizza view web/lib/libpizza @ rev 14

Add Gravatar support to flavor status page
author Christophe Lincoln <pankso@slitaz.org>
date Mon Mar 26 13:05:04 2012 +0200 (2012-03-26)
parents 3d50b39eb83d
children 32928f4ae2b2
line source
1 #!/bin/sh
2 #
3 # Common functions for Pizza CGI/SHell web interface.
4 #
6 [ -f "/etc/slitaz/pizza.conf" ] && . /etc/slitaz/pizza.conf
7 [ -f "../pizza.conf" ] && . ../pizza.conf
8 . ./db.conf
9 . /usr/lib/slitaz/httphelper
10 header
12 # xHTML header.
13 cat lib/header.html || exit 1
15 # Status function.
16 status() {
17 if [ $? = 0 ]; then
18 echo " <span class="span-ok">OK</span>"
19 else
20 echo " <span class="span-red">Failed</span>"
21 fi
22 }
24 # Put some colors in log and DB files.
25 highlighter() {
26 case $1 in
27 log)
28 sed -e ':a;s/^\(.\{1,73\}\)OK$/\1 OK/;ta' \
29 -e ':a;s/^\(.\{1,73\}\)Failed$/\1 Failed/;ta' |
30 sed -e 's|\[[0-9G\.KM]* .||g' -e 's|.\[18G| |' \
31 -e 's|.\[1m|<b>|' -e 's|.\[0m|</b>|' \
32 -e 's#OK#<span class="span-ok">OK</span>#g' \
33 -e 's#Failed#<span class="span-red">Failed</span>#g' ;;
34 activity)
35 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
36 esac
37 }
39 # Log activities, we want first letter capitalized.
40 log() {
41 grep ^[A-Z] | \
42 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
43 }
45 # Usage: error string
46 error() {
47 echo "<span class="span-red">ERROR: $@</span>"
48 }
50 # Pizza notification function: notify "message" "icon"
51 notify() {
52 img=info
53 [ "$2" ] && img=$2
54 cat << EOT
55 <script type="text/javascript">
56 document.write('<div id="notify"><img src="images/$img.png" />$1</div>');
57 fadeNotify('notify', 100, 0, 300);
58 setTimeout('hideNotify()', 6200);
59 </script>
60 EOT
61 }
63 # Get and display Gravatar image: get_gravatar email size
64 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
65 get_gravatar() {
66 email=$1
67 size=$2
68 [ "$size" ] || size=48
69 url="http://www.gravatar.com/avatar"
70 md5=$(echo -n $email | md5sum | cut -d " " -f 1)
71 echo "<img src='$url/$md5?d=identicon&s=$size' alt='[ Gravatar ]' />"
72 }