Custom export
-
Hi,
I’ve had a look through previous support topics about naming of files, spaces etc and saw that changing the plugin to be able to support arbitary filenames on export would be quite difficult.
I hope you don’t mind, but I worked out a way to do it. It’s a bit of a hack at the moment, and only works if you don’t enable frefix from what I can see.
In ewz-webform.php line 633, I changed
$fp = popen("zip -0 -j -q - $fnames", 'r');
to
$fp = popen("/usr/local/bin/createZipForCompetition.sh $fnames", 'r');
The original zip command is passed a list of image files and the csv – which then get zipped up and downloaded. The replacement command takes that and processes them into a zip in the exact format I need.
I’ve put the script I created to do the processing at the end (works on RHEL, but nothing Linux variant specific here).
So – after all that – here’s the request. I don’t want to have to go in and update the EWZ code after each update. Would it be possible to have a configuration option added which would be the full path to a custom script (which takes parameters of all the filenames and the csv). If this is present in the configuration then show an extra button of something like ‘Customised Download’.
Based on the script below I think that this might allow others to do downloads in the format they need, without relying on changes to the core plugin.
The plugin does everything we need – but I wanted to make it easier for our competition secretary to download in the exact format for import into our projection software. Thanks for creating such a great plugin!
Many thanks,
Will.—-
#!/bin/bash # Given a list of files, create a zip suitable for download # One of the files will be a CSV TMPDIR=/tmp/CompetitionZIP_$$ mkdir $TMPDIR mkdir $TMPDIR/orig mkdir $TMPDIR/out # store arguments in a special array args=("$@") # get number of elements ELEMENTS=${#args[@]} # echo each element in array # for loop for (( i=0;i<$ELEMENTS;i++)); do # echo "Processing ${args[${i}]}" # echo cp "${args[${i}]}" $TMPDIR/orig/ cp "${args[${i}]}" $TMPDIR/orig/ done # We've now copied all the files into the target location # Next we need to process the CSV file LINECOUNT=<code></code>cat $TMPDIR/orig/*.csv | wc -l<code></code> # echo "Lines to handle = $LINECOUNT" for (( i=2;i<=$LINECOUNT;i++)); do IMAGEAUTHOR=<code>cat $TMPDIR/orig/*.csv | sed -n -e 1p -e ${i}p | csvcut -c "Display Name" | tail -n 1 | tr -d '"'</code> IMAGEFILE=<code>cat $TMPDIR/orig/*.csv | sed -n -e 1p -e ${i}p | csvcut -c "Filename" | tail -n 1 | tr -d '"'</code> IMAGETITLE=<code>cat $TMPDIR/orig/*.csv | sed -n -e 1p -e ${i}p | csvcut -c "Title" | tail -n 1 | tr -d '"'</code> IMAGETYPE=<code>cat $TMPDIR/orig/*.csv | sed -n -e 1p -e ${i}p | csvcut -c "Tp" | tail -n 1 | tr -d '"'</code> # echo "===== ENTRY $i" # echo "Author : >$IMAGEAUTHOR<" # echo "Filename : >$IMAGEFILE<" # echo "Title : >$IMAGETITLE<" # echo "Type : >$IMAGETYPE<" if [ -z "$IMAGEAUTHOR" ] then # echo "***** NO AUTHOR - giving up" continue fi if [ -z "$IMAGEFILE" ] then # echo "***** NO FILE - giving up" continue fi if [ -z "$IMAGETITLE" ] then # echo "***** NO TITLE - giving up" continue fi if [ -z "$IMAGETYPE" ] then # echo "***** NO TYPE - giving up" continue fi # echo mv "$TMPDIR/orig/$IMAGEFILE" "$TMPDIR/out/${IMAGEAUTHOR}-${IMAGETITLE}.jpg" mv "$TMPDIR/orig/$IMAGEFILE" "$TMPDIR/out/${IMAGEAUTHOR}-${IMAGETITLE}.jpg" done zip -q -0 ${TMPDIR}/generatedzip.zip ${TMPDIR}/out/* cat ${TMPDIR}/generatedzip.zip rm -rf ${TMPDIR}
- The topic ‘Custom export’ is closed to new replies.