Skip to content

Commit 41ced5e

Browse files
committed
Merge pull request #2859 from cmbirk/develop
Check for SOffice before removing export links
2 parents 34d757f + d6033de commit 41ced5e

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

src/node/handler/PadMessageHandler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,8 @@ function handleClientReady(client, message)
12341234
"serverTimestamp": new Date().getTime(),
12351235
"userId": author,
12361236
"abiwordAvailable": settings.abiwordAvailable(),
1237+
"sofficeAvailable": settings.sofficeAvailable(),
1238+
"exportAvailable": settings.exportAvailable(),
12371239
"plugins": {
12381240
"plugins": plugins.plugins,
12391241
"parts": plugins.parts,

src/node/hooks/express/importexport.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ exports.expressCreateServer = function (hook_name, args, cb) {
1313
}
1414

1515
//if abiword is disabled, and this is a format we only support with abiword, output a message
16-
if (settings.abiword == null &&
16+
if (settings.exportAvailable() == "no" &&
1717
["odt", "pdf", "doc"].indexOf(req.params.type) !== -1) {
18-
res.send("Abiword is not enabled at this Etherpad instance. Set the path to Abiword in settings.json to enable this feature");
18+
res.send("This export is not enabled at this Etherpad instance. Set the path to Abiword or SOffice in settings.json to enable this feature");
1919
return;
2020
}
2121

src/node/utils/Settings.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,27 @@ exports.abiwordAvailable = function()
222222
}
223223
};
224224

225+
exports.sofficeAvailable = function () {
226+
if(exports.soffice != null) {
227+
return os.type().indexOf("Windows") != -1 ? "withoutPDF": "yes";
228+
} else {
229+
return "no";
230+
}
231+
};
232+
233+
exports.exportAvailable = function () {
234+
var abiword = exports.abiwordAvailable();
235+
var soffice = exports.sofficeAvailable();
236+
237+
if(abiword == "no" && soffice == "no") {
238+
return "no";
239+
} else if ((abiword == "withoutPDF" && soffice == "no") || (abiword == "no" && soffice == "withoutPDF")) {
240+
return "withoutPDF";
241+
} else {
242+
return "yes";
243+
}
244+
};
245+
225246
// Provide git version if available
226247
exports.getGitCommit = function() {
227248
var version = "";
@@ -375,6 +396,20 @@ exports.reloadSettings = function reloadSettings() {
375396
}
376397
}
377398

399+
if(exports.soffice) {
400+
fs.exists(exports.soffice, function (exists) {
401+
if(!exists) {
402+
var sofficeError = "SOffice does not exist at this path, check your settings file";
403+
404+
if(!exports.suppressErrorsInPadText) {
405+
exports.defaultPadText = exports.defaultPadText + "\nError: " + sofficeError + suppressDisableMsg;
406+
}
407+
console.error(sofficeError);
408+
exports.soffice = null;
409+
}
410+
});
411+
}
412+
378413
if (!exports.sessionKey) {
379414
try {
380415
exports.sessionKey = fs.readFileSync("./SESSIONKEY.txt","utf8");

src/static/js/pad_impexp.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This code is mostly from the old Etherpad. Please help us to comment this code.
2+
* This code is mostly from the old Etherpad. Please help us to comment this code.
33
* This helps other people to understand this code better and helps them to improve it.
44
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
55
*/
@@ -46,7 +46,7 @@ var padimpexp = (function()
4646
$('#importmessagefail').fadeOut("fast");
4747
var ret = window.confirm(html10n.get("pad.impexp.confirmimport"));
4848
if (ret)
49-
{
49+
{
5050
currentImportTimer = window.setTimeout(function()
5151
{
5252
if (!currentImportTimer)
@@ -61,7 +61,7 @@ var padimpexp = (function()
6161
{
6262
disabled: true
6363
}).val(html10n.get("pad.impexp.importing"));
64-
64+
6565
window.setTimeout(function()
6666
{
6767
$('#importfileinput').attr(
@@ -104,15 +104,15 @@ var padimpexp = (function()
104104
function importErrorMessage(status)
105105
{
106106
var msg="";
107-
107+
108108
if(status === "convertFailed"){
109109
msg = html10n.get("pad.impexp.convertFailed");
110110
} else if(status === "uploadFailed"){
111111
msg = html10n.get("pad.impexp.uploadFailed");
112112
} else if(status === "padHasData"){
113113
msg = html10n.get("pad.impexp.padHasData");
114114
}
115-
115+
116116
function showError(fade)
117117
{
118118
$('#importmessagefail').html('<strong style="color: red">'+html10n.get('pad.impexp.importfailed')+':</strong> ' + (msg || html10n.get('pad.impexp.copypaste','')))[(fade ? "fadeIn" : "show")]();
@@ -206,23 +206,23 @@ var padimpexp = (function()
206206

207207
// activate action to import in the form
208208
$("#importform").attr('action', pad_root_url + "/import");
209-
210-
//hide stuff thats not avaible if abiword is disabled
211-
if(clientVars.abiwordAvailable == "no")
209+
210+
//hide stuff thats not avaible if abiword/soffice is disabled
211+
if(clientVars.exportAvailable == "no")
212212
{
213213
$("#exportworda").remove();
214214
$("#exportpdfa").remove();
215215
$("#exportopena").remove();
216216

217217
$("#importmessageabiword").show();
218218
}
219-
else if(clientVars.abiwordAvailable == "withoutPDF")
219+
else if(clientVars.exportAvailable == "withoutPDF")
220220
{
221221
$("#exportpdfa").remove();
222-
222+
223223
$("#exportworda").attr("href", pad_root_path + "/export/doc");
224224
$("#exportopena").attr("href", pad_root_path + "/export/odt");
225-
225+
226226
$("#importexport").css({"height":"142px"});
227227
$("#importexportline").css({"height":"142px"});
228228
}
@@ -232,7 +232,7 @@ var padimpexp = (function()
232232
$("#exportpdfa").attr("href", pad_root_path + "/export/pdf");
233233
$("#exportopena").attr("href", pad_root_path + "/export/odt");
234234
}
235-
235+
236236
addImportFrames();
237237
$("#importfileinput").change(fileInputUpdated);
238238
$('#importform').unbind("submit").submit(fileInputSubmit);

0 commit comments

Comments
 (0)