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

Try a fx for pizza help page (not displaying actually)
author Christophe Lincoln <pankso@slitaz.org>
date Thu Mar 16 18:01:36 2017 +0100 (2017-03-16)
parents c83842a21724
children b03531b3e96b
line source
1 #!/bin/sh
2 #
3 # Common functions for Pizza CGI/SHell web interface.
4 #
5 . /usr/lib/slitaz/httphelper.sh
6 header
8 [ -f "/etc/slitaz/pizza.conf" ] && . /etc/slitaz/pizza.conf
9 [ -f "../pizza.conf" ] && . ../pizza.conf
10 . ./db.conf
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/.*'$(echo -ne '\r')'\[/[/' \
32 -e 's|.\[1m|<b>|' -e 's|.\[0m|</b>|' \
33 -e 's#OK#<span class="span-ok">OK</span>#g' \
34 -e 's#Failed#<span class="span-red">Failed</span>#g' ;;
35 activity)
36 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
37 esac
38 }
40 # Log activities, we want first letter capitalized.
41 log() {
42 grep ^[A-Z] | \
43 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
44 }
46 # Usage: error string
47 error() {
48 echo "<span class=\"span-red\">ERROR: $@</span>"
49 }
51 # Pizza notification function: notify "message" "icon"
52 notify() {
53 img=info
54 [ "$2" ] && img=$2
55 cat << EOT
56 <script type="text/javascript">
57 document.write('<div id="notify"><img src="images/$img.png" />$1</div>');
58 fadeNotify('notify', 100, 0, 300);
59 setTimeout('hideNotify()', 6200);
60 </script>
61 EOT
62 }
64 # Get and display Gravatar image: get_gravatar email size
65 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
66 get_gravatar() {
67 email=$1
68 size=$2
69 [ "$size" ] || size=48
70 url="http://www.gravatar.com/avatar"
71 md5=$(echo -n $email | md5sum | cut -d " " -f 1)
72 echo "<img src='$url/$md5?d=identicon&s=$size' alt='[ Gravatar ]' />"
73 }