tinycm diff plugins/export/export.cgi @ rev 6
Add plugins (skel and export)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed Apr 11 15:59:53 2012 +0200 (2012-04-11) |
parents | |
children | 4067b670d4ee |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/plugins/export/export.cgi Wed Apr 11 15:59:53 2012 +0200 1.3 @@ -0,0 +1,99 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# TinyCM Plugin - Export to static content 1.7 +# 1.8 +. /usr/lib/slitaz/httphelper 1.9 + 1.10 +if [ "$(GET export)" ]; then 1.11 + d="Export" 1.12 + date=$(date "+%Y%m%d") 1.13 + tmpdir="$tmp/export/$$/wiki-$date" 1.14 + header 1.15 + html_header 1.16 + user_box 1.17 + cat << EOT 1.18 +<h2>Export</h2> 1.19 +<p> 1.20 +$(gettext "Export to HTML and ceate a tarball of your text content or 1.21 +uploaded files.") 1.22 +</p> 1.23 +<form method="get" action="$WEB_URL"> 1.24 + <select name="export"> 1.25 +EOT 1.26 + for c in $(ls -1 content/) 1.27 + do 1.28 + echo "<option value="$c">$c</option>" 1.29 + done 1.30 + cat << EOT 1.31 + </select> 1.32 + <input type="submit" value="$(gettext "Export")" /> 1.33 +</form> 1.34 +EOT 1.35 + # Functions 1.36 + css_path() { 1.37 + # Sed CSS style path in all documents 1.38 + sed -i s'/style.css/..\/style.css/' */*.html 1.39 + sed -i s'/style.css/..\/..\/style.css/' */*/*.html 1.40 + sed -i s'/style.css/..\/..\/..\/style.css/' */*/*/*.html 1.41 + } 1.42 + gen_tarball() { 1.43 + gettext "Creating tarball"; echo -n ": " 1.44 + cd $tmpdir && mkdir $TINYCM/$cache/export 1.45 + # Clean cache 1.46 + find $TINYCM/$cache/export -mtime +1 | xargs rm -rf 1.47 + tar czf $TINYCM/$cache/export/$export-$date.tar.gz $export 1.48 + cd $TINYCM/$cache/export && du -sh $export-$date.tar.gz 1.49 + } 1.50 + dl_link() { 1.51 + gettext "Download"; echo \ 1.52 + ": <a href='cache/export/$export-$date.tar.gz'>$export-$date.tar.gz</a>" 1.53 + } 1.54 + # Export requested content 1.55 + case " $(GET export) " in 1.56 + *\ uploads\ *) 1.57 + export="uploads" 1.58 + tmpdir="content" 1.59 + echo '<pre>' 1.60 + gettext "Exporting:"; echo " $export" 1.61 + gen_tarball 1.62 + echo '</pre>' 1.63 + dl_link ;; 1.64 + *) 1.65 + [ "$(GET export)" == "export" ] && exit 0 1.66 + export="$(GET export)" 1.67 + format="html" 1.68 + echo '<pre>' 1.69 + gettext "Exporting:"; echo " $export" 1.70 + gettext "Creating tmp directory:"; echo " PID $$ DATE $date" 1.71 + mkdir -p $tmpdir/$export 1.72 + gettext "Copying CSS style and images..."; echo 1.73 + cp -a style.css images $tmpdir/$export 1.74 + cd $content/$export 1.75 + for d in $(find . -type f | sed s'!./!!') 1.76 + do 1.77 + d=${d%.txt} 1.78 + [ "$d" == "help" ] && continue 1.79 + gettext "Exporting: "; echo "$d.txt" 1.80 + mkdir -p $tmpdir/$export/$(dirname $d) 1.81 + f=$tmpdir/$export/$d.html 1.82 + html_header > $f 1.83 + sed -i '/functions.js/'d $f 1.84 + sed -i '/favicon.ico/'d $f 1.85 + cat $d.txt | wiki_parser | sed \ 1.86 + -e '/functions.js/'d \ 1.87 + -e s'/?d=//'g \ 1.88 + -e s"#href='\([^']*\)*\>#\0.html#"g >> $f 1.89 + html_footer >> $f 1.90 + done 1.91 + cd $tmpdir/$export 1.92 + [ "$format" == "html" ] && css_path 1.93 + gen_tarball 1.94 + gettext "Removing temporary files..."; echo 1.95 + rm -rf $tmp/export/$$ 1.96 + echo '</pre>' 1.97 + dl_link ;; 1.98 + esac 1.99 + 1.100 + html_footer 1.101 + exit 0 1.102 +fi