tinycm diff plugins/export/export.cgi @ rev 28

Bunch of improvments and fixes
author Christophe Lincoln <pankso@slitaz.org>
date Mon Jan 06 14:49:12 2014 +0000 (2014-01-06)
parents 9d0f7be12384
children 4521322899ee
line diff
     1.1 --- a/plugins/export/export.cgi	Sun Apr 22 10:49:23 2012 +0100
     1.2 +++ b/plugins/export/export.cgi	Mon Jan 06 14:49:12 2014 +0000
     1.3 @@ -4,6 +4,14 @@
     1.4  #
     1.5  . /usr/lib/slitaz/httphelper
     1.6  
     1.7 +#
     1.8 +# NOTE: Exporting wiki and make all url's work is is a bit tricky and
     1.9 +# actually don't work as expected. The goal is to have a SliTaz codex
    1.10 +# online thta can be include on the ISO, so we could have an export
    1.11 +# including a small CGI script to simply display wiki pages via HTTPd
    1.12 +# knowing that with HTML we must also deal with ../../
    1.13 +#
    1.14 +
    1.15  if [ "$(GET export)" ]; then
    1.16  	d="Export"
    1.17  	date=$(date "+%Y%m%d")
    1.18 @@ -14,8 +22,8 @@
    1.19  	cat << EOT 
    1.20  <h2>Export</h2>
    1.21  <p>
    1.22 -$(gettext "Export to HTML and create a tarball of your text content or
    1.23 -uploaded files.")
    1.24 +$(gettext "EXPERIMENTAL: Export to HTML and create a tarball of your text
    1.25 +content or plugins files.")
    1.26  </p>
    1.27  <form method="get" action="$WEB_URL">
    1.28  	<select name="export">
    1.29 @@ -50,21 +58,18 @@
    1.30  	}
    1.31  	# Export requested content
    1.32  	case " $(GET export) " in
    1.33 -		*\ uploads\ *)
    1.34 -			export="uploads"
    1.35 +		*\ cloud\ *)
    1.36 +			export="cloud"
    1.37  			tmpdir="content"
    1.38  			echo '<pre>'
    1.39  			gettext "Exporting:"; echo " $export"
    1.40  			gen_tarball
    1.41  			echo '</pre>' 
    1.42  			dl_link ;;
    1.43 -		*)
    1.44 -			[ "$(GET export)" == "export" ] && exit 0
    1.45 -			export="$(GET export)"
    1.46 -			format="html"
    1.47 +		*\ wiki\ *)
    1.48 +			export="wiki"
    1.49  			echo '<pre>'
    1.50  			gettext "Exporting:"; echo " $export"
    1.51 -			gettext "Creating tmp directory:"; echo " PID $$ DATE $date"
    1.52  			mkdir -p $tmpdir/$export
    1.53  			gettext "Copying CSS style and images..."; echo
    1.54  			cp -a style.css images $tmpdir/$export
    1.55 @@ -72,28 +77,35 @@
    1.56  			for d in $(find . -type f | sed s'!./!!')
    1.57  			do
    1.58  				d=${d%.txt}
    1.59 -				[ "$d" == "help" ] && continue
    1.60 +				[ "$d" == "en/help" ] && continue
    1.61  				gettext "Exporting: "; echo "$d.txt"
    1.62  				mkdir -p $tmpdir/$export/$(dirname $d)
    1.63  				f=$tmpdir/$export/$d.html
    1.64 -				html_header > $f
    1.65 -				sed -i '/functions.js/'d $f
    1.66 -				sed -i '/favicon.ico/'d $f
    1.67 +				html_header > ${f}
    1.68 +				sed -i '/functions.js/'d ${f}
    1.69 +				sed -i '/favicon.ico/'d ${f}
    1.70 +				sed -i s'/index.cgi/index.html/'/ ${f}
    1.71 +				doc="[0-9a-zA-Z\.\#/~\_%=\?\&,\+\:@;!\(\)\*\$'\-]*"
    1.72 +				#
    1.73 +				# The sed from wiki url's to html bug if there is 2 link
    1.74 +				# on same line: [test|Test] tralala [en/index|English]
    1.75 +				#
    1.76  				cat $d.txt | wiki_parser | sed \
    1.77 -					-e '/functions.js/'d \
    1.78 -					-e s'/?d=//'g \
    1.79 -					-e s"#href='\([^']*\)*\>#\0.html#"g >> $f 
    1.80 -				html_footer >> $f
    1.81 +					s"#href='\([^]]*\)?d=\($doc\)'>#href='\2.html'>#"g >> ${f} 
    1.82 +				html_footer >> ${f}
    1.83  			done
    1.84  			cd $tmpdir/$export
    1.85 -			[ "$format" == "html" ] && css_path
    1.86 +			css_path
    1.87  			gen_tarball
    1.88 -			gettext "Removing temporary files..."; echo
    1.89  			rm -rf $tmp/export/$$
    1.90  			echo '</pre>'
    1.91  			dl_link ;;
    1.92 +		*\ export\ ) html_footer && exit 0 ;;
    1.93 +		*)
    1.94 +			echo '<pre>'
    1.95 +			gettext "Export not yet implemented for"; echo ": $(GET export)"
    1.96 +			echo '</pre>' ;;
    1.97  	esac
    1.98  	
    1.99 -	html_footer
   1.100 -	exit 0
   1.101 +	html_footer && exit 0
   1.102  fi