How about introducing a document converter (to html) to your template & server?
This can be quite useful if user wants to share documents (like .docx .odt formatted) with HFS.
There are all the codes for such a feature. Besides, you need to install
LibreOffice to your
server OS.
[+special:strings]
EnableDocConvert=1
[ajax.convertdoctohtml|public]
[ajax.convertdoctohtml|public]
{.set|LibreOfficePath|C:\Program Files\LibreOffice\program\soffice.exe.}
{.break|if={.not|{.!EnableDocConvert.}.}|reason=Doc Convert not enabled.}
{.break|if={.not|{.exists|{.^LibreOfficePath.}.}.}|reason=No LibreOffice installed.}
{.set|file|{.urlvar|file.}.}
{.set|target|{.vfs to disk|{.urlvar|path.}.}.}
{.set|folder|{.^target.}\{.^file.}.html.}
{.mkdir|{.^folder.}.}
{.save|{.^folder.}\index.html|{.replace|@@filename@@|{.^file.}|{.no pipe|{.$docview.html.}.}.}.}
{.set|cmd|"{.^LibreOfficePath.}" --convert-to html --outdir "{.^folder.}" --convert-images-to "gif" "{.^target.}\{.^file.}".}
{.^cmd.}
{.exec|{.^cmd.}|out=x.}
{.^x.}
OK
[docview.html]
<!DOCTYPE html>
<html>
<head>
{.$commonhead.}
<title>@@filename@@</title>
<script>
function getdoc () {
var xhr = new XMLHttpRequest();
var docfile = './'+'@@filename@@'.replace(/\..*$/, '')+'.html';
xhr.open('HEAD', docfile);
xhr.onload = function() {
if (xhr.status == '404') { // Conversion not completed yet
setTimeout(function() { getdoc(); }, 1000);
} else if (xhr.status == '200') { // Done, go
window.location.replace(docfile);
}
}
xhr.send();
}
getdoc();
</script>
</head>
<body>
{.$commonbody.upper.}
<h1 style="text-align: center;">{.!Converting document, please wait....}</h1>
{.$commonbody.lower.}
</body>
</html>
[+]
<script>
var converttohtml = function (file, path) {
notice('{.!Converting.} '+file+' {.!to .html format..} {.!Please wait.}', '{.!Conversion Started.}');
var xhr = new XMLHttpRequest();
xhr.open('POST', '/~ajax.convertdoctohtml?file='+file+'&path='+path);
xhr.onload = function() {
var response = xhr.responseText.trim();
if (response.substring('Doc Convert not enabled') >= -1) {
popup('{.!Conversion failed..}<br />{.!Doc Convert not enabled.}', '?alert');
} else if (response.substring('No LibreOffice installed') >= -1) {
popup('{.!Conversion failed..}<br />{.!Server has no LibreOffice installed..}', '?alert');
} else {
// popup('{.!Conversion started.}<br />{.!You may wait for a while to see specified .html file..}', '?alert');
setTimeout(function() {
previewfile('?open', path+file+'.html');
}, 1000);
}
}
xhr.send();
}
// Then use converttohtml('file.docx', '/my shared files/folder/'); to convert your file.
// There will be a folder named "file.docx.html" created, it contains an index.html for auto-refreshing and the converted file.html.
</script>
These codes presents in
new preview version of Takeback,
you may test it. Don't forget to enable that feature by editing it first.
Some code parts above contains APIs in Takeback. Change them to yours as well.
After all, just have fun!
Edit: Updated the code to avoid filename being parsed as response code.