tinycm view plugins/export/export.cgi @ rev 8

Tiny edits
author Paul Issott <paul@slitaz.org>
date Sun Apr 22 10:49:23 2012 +0100 (2012-04-22)
parents 4067b670d4ee
children 09f5185ff6e0
line source
1 #!/bin/sh
2 #
3 # TinyCM Plugin - Export to static content
4 #
5 . /usr/lib/slitaz/httphelper
7 if [ "$(GET export)" ]; then
8 d="Export"
9 date=$(date "+%Y%m%d")
10 tmpdir="$tmp/export/$$/wiki-$date"
11 header
12 html_header
13 user_box
14 cat << EOT
15 <h2>Export</h2>
16 <p>
17 $(gettext "Export to HTML and create a tarball of your text content or
18 uploaded files.")
19 </p>
20 <form method="get" action="$WEB_URL">
21 <select name="export">
22 EOT
23 for c in $(ls -1 content/)
24 do
25 echo "<option value="$c">$c</option>"
26 done
27 cat << EOT
28 </select>
29 <input type="submit" value="$(gettext "Export")" />
30 </form>
31 EOT
32 # Functions
33 css_path() {
34 # Sed CSS style path in all documents
35 sed -i s'/style.css/..\/style.css/' */*.html
36 sed -i s'/style.css/..\/..\/style.css/' */*/*.html
37 sed -i s'/style.css/..\/..\/..\/style.css/' */*/*/*.html
38 }
39 gen_tarball() {
40 gettext "Creating tarball"; echo -n ": "
41 cd $tmpdir && mkdir $tiny/$cache/export
42 # Clean cache
43 find $tiny/$cache/export -mtime +1 | xargs rm -rf
44 tar czf $tiny/$cache/export/$export-$date.tar.gz $export
45 cd $tiny/$cache/export && du -sh $export-$date.tar.gz
46 }
47 dl_link() {
48 gettext "Download"; echo \
49 ": <a href='cache/export/$export-$date.tar.gz'>$export-$date.tar.gz</a>"
50 }
51 # Export requested content
52 case " $(GET export) " in
53 *\ uploads\ *)
54 export="uploads"
55 tmpdir="content"
56 echo '<pre>'
57 gettext "Exporting:"; echo " $export"
58 gen_tarball
59 echo '</pre>'
60 dl_link ;;
61 *)
62 [ "$(GET export)" == "export" ] && exit 0
63 export="$(GET export)"
64 format="html"
65 echo '<pre>'
66 gettext "Exporting:"; echo " $export"
67 gettext "Creating tmp directory:"; echo " PID $$ DATE $date"
68 mkdir -p $tmpdir/$export
69 gettext "Copying CSS style and images..."; echo
70 cp -a style.css images $tmpdir/$export
71 cd $content/$export
72 for d in $(find . -type f | sed s'!./!!')
73 do
74 d=${d%.txt}
75 [ "$d" == "help" ] && continue
76 gettext "Exporting: "; echo "$d.txt"
77 mkdir -p $tmpdir/$export/$(dirname $d)
78 f=$tmpdir/$export/$d.html
79 html_header > $f
80 sed -i '/functions.js/'d $f
81 sed -i '/favicon.ico/'d $f
82 cat $d.txt | wiki_parser | sed \
83 -e '/functions.js/'d \
84 -e s'/?d=//'g \
85 -e s"#href='\([^']*\)*\>#\0.html#"g >> $f
86 html_footer >> $f
87 done
88 cd $tmpdir/$export
89 [ "$format" == "html" ] && css_path
90 gen_tarball
91 gettext "Removing temporary files..."; echo
92 rm -rf $tmp/export/$$
93 echo '</pre>'
94 dl_link ;;
95 esac
97 html_footer
98 exit 0
99 fi