wok-tiny view wiki/stuff/var/www/wiki/plugins/wkp_Upload.sh @ rev 142

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Feb 27 17:43:23 2019 +0100 (2 months ago)
parents 48d2c4c7a227
children
line source
1 plugin="<a href=\"?action=upload\" title=\"Upload a file\">Upload</a>"
2 description_fr="Télécharge des fichiers complémentaires (ex: images)"
3 description="Upload page extra files (ex: images)"
5 case "$LANG" in
6 fr) UPLOAD="Chargement" ;;
7 *) UPLOAD="Upload" ;;
8 esac
10 template()
11 {
12 case "$(GET action)" in
13 edit) UPLOAD="<a href=\"$urlbase?action=upload\">$UPLOAD</a>"
14 html="$(sed "s|HISTORY|$(sedesc "$UPLOAD") / HISTORY|" <<EOT
15 $html
16 EOT
17 )" ;;
18 upload*) html="$(sed 's| / <a href.*recent.*</a>||;s|.*name="query".*||' <<EOT
19 $html
20 EOT
21 )" ;;
22 *) return 1 ;;
23 esac
24 return 0
25 }
27 action()
28 {
29 case "$1" in
30 upload) CONTENT="$(cat <<EOT
31 <form method="post" enctype="multipart/form-data" action="?action=uploadfile">
32 <input type="file" name="file" value="file"/>
33 <input type="submit"/>
34 <table>
35 EOT
36 for i in pages/data/* ; do
37 [ -e $i ] || continue
38 echo -n "<tr><td><input type=checkbox "
39 grep -qs "$i" pages/*.txt && echo "checked=checked "
40 echo "disabled=disabled /><a href="$i">$(basename $i)</a></td></tr>"
41 done
42 cat <<EOT
43 </table>
44 </form>
45 EOT
46 )"
47 PAGE_TITLE_link=false
48 editable=false
49 lang="${HTTP_ACCEPT_LANGUAGE%%[,;_-]*}"
50 PAGE_TITLE="$UPLOAD" ;;
51 uploadfile)
52 mkdir -p pages/data 2> /dev/null
53 name=$(FILE file name)
54 if [ -z "$name" ]; then
55 CONTENT="<script> history.go(-2); </script>"
56 return 1
57 fi
58 n=''
59 while [ -e pages/data/$n$name ]; do
60 n=$(($n+1))
61 done
62 filesize=$(stat -c "%s" $(FILE file tmpname))
63 ls pages/data | while read file; do
64 stat -c "%s %n" pages/data/$file
65 done | while read size file; do
66 [ $filesize = $size ] &&
67 cmp $(FILE file tmpname) $file > /dev/null &&
68 ln -s $(basename $file) pages/data/$n$name && break
69 done
70 if [ -L pages/data/$n$name ]; then
71 n=pages/data/$n$name
72 name="$(readlink $n)"
73 rm -f $n
74 n=""
75 else
76 mv $(FILE file tmpname) pages/data/$n$name
77 fi
78 rm -rf $(dirname $(FILE file tmpname) )
79 URL=pages/data/$n$name
80 PAGE_TITLE_link=false
81 editable=false
82 PAGE_TITLE="$UPLOAD"
83 CONTENT="$(cat <<EOT
84 <h1><a href="javascript:history.go(-2)">$EDIT_BUTTON</a></h1>
85 <p>
86 The file $(FILE file name) ($(FILE file size) bytes, $(FILE file type)) is
87 stored at <a href="$URL">$URL</a>.
88 </p>
89 EOT
90 )"
91 case "$(FILE file type)" in
92 image*) CONTENT="$(cat <<EOT
93 $CONTENT
94 <p>
95 You can insert this image with <b>[$URL]</b> see
96 <a href="?page=$HELP_BUTTON">$HELP_BUTTON</a> for details
97 </p>
98 <img src="$URL" alt="$URL" />
99 EOT
100 )"
101 esac ;;
102 *) return 1 ;;
103 esac
104 return 0
105 }
107 formatEnd()
108 {
109 CONTENT="$(sed 's|href="[^"]*page=pages/data/|href="pages/data/|g' <<EOT
110 $CONTENT
111 EOT
112 )"
113 }