summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/locales/en.ini1
-rw-r--r--src/locales/es.ini1
-rw-r--r--src/node/handler/ImportHandler.js164
-rw-r--r--src/node/hooks/express/importexport.js6
-rw-r--r--src/static/css/pad.css19
-rw-r--r--src/static/js/pad_impexp.js11
-rw-r--r--src/templates/pad.html3
7 files changed, 91 insertions, 114 deletions
diff --git a/src/locales/en.ini b/src/locales/en.ini
index e542594d..9e1feea7 100644
--- a/src/locales/en.ini
+++ b/src/locales/en.ini
@@ -41,6 +41,7 @@ pad.importExport.exportword = Microsoft Word
pad.importExport.exportpdf = PDF
pad.importExport.exportopen = ODF (Open Document Format)
pad.importExport.exportdokuwiki = DokuWiki
+pad.importExport.abiword.innerHTML = You only can import from plain text or html formats. For more advanced import features please <a href="https://github.com/ether/etherpad-lite/wiki/How-to-enable-importing-and-exporting-different-file-formats-in-Ubuntu-or-OpenSuse-or-SLES-with-AbiWord">install abiword</a>.
pad.modals.connected = Connected.
pad.modals.reconnecting = Reconnecting to your pad..
pad.modals.forcereconnect = Force reconnect
diff --git a/src/locales/es.ini b/src/locales/es.ini
index d698b752..ad834013 100644
--- a/src/locales/es.ini
+++ b/src/locales/es.ini
@@ -46,6 +46,7 @@ pad.importExport.exportword = Microsoft Word
pad.importExport.exportpdf = PDF
pad.importExport.exportopen = ODF (Open Document Format)
pad.importExport.exportdokuwiki = DokuWiki
+pad.importExport.abiword.innerHTML = Sólo puede importar formatos de texto plano o html. Para funciones más avanzadas instale <a href="https://github.com/ether/etherpad-lite/wiki/How-to-enable-importing-and-exporting-different-file-formats-in-Ubuntu-or-OpenSuse-or-SLES-with-AbiWord">abiword</a>.
pad.modals.connected = Conectado.
pad.modals.reconnecting = Reconectando a tu pad..
pad.modals.forcereconnect = Reconexión forzosa
diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js
index 788706ce..815e5357 100644
--- a/src/node/handler/ImportHandler.js
+++ b/src/node/handler/ImportHandler.js
@@ -4,6 +4,7 @@
/*
* 2011 Peter 'Pita' Martischka (Primary Technology Ltd)
+ * 2012 Iván Eixarch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,26 +19,20 @@
* limitations under the License.
*/
-var ERR = require("async-stacktrace");
-var padManager = require("../db/PadManager");
-var padMessageHandler = require("./PadMessageHandler");
-var async = require("async");
-var fs = require("fs");
-var settings = require('../utils/Settings');
-var formidable = require('formidable');
-var os = require("os");
+var ERR = require("async-stacktrace")
+ , padManager = require("../db/PadManager")
+ , padMessageHandler = require("./PadMessageHandler")
+ , async = require("async")
+ , fs = require("fs")
+ , path = require("path")
+ , settings = require('../utils/Settings')
+ , formidable = require('formidable')
+ , os = require("os")
+ , importHtml = require("../utils/ImportHtml");
//load abiword only if its enabled
if(settings.abiword != null)
var abiword = require("../utils/Abiword");
-
-var tempDirectory = "/tmp/";
-
-//tempDirectory changes if the operating system is windows
-if(os.type().indexOf("Windows") > -1)
-{
- tempDirectory = process.env.TEMP;
-}
/**
* do a requested import
@@ -45,32 +40,27 @@ if(os.type().indexOf("Windows") > -1)
exports.doImport = function(req, res, padId)
{
//pipe to a file
- //convert file to text via abiword
- //set text in the pad
+ //convert file to html via abiword
+ //set html in the pad
- var srcFile, destFile;
- var pad;
- var text;
+ var srcFile, destFile
+ , pad
+ , text;
async.series([
//save the uploaded file to /tmp
- function(callback)
- {
+ function(callback) {
var form = new formidable.IncomingForm();
form.keepExtensions = true;
- form.uploadDir = tempDirectory;
- form.parse(req, function(err, fields, files)
- {
+ form.parse(req, function(err, fields, files) {
//the upload failed, stop at this point
- if(err || files.file === undefined)
- {
+ if(err || files.file === undefined) {
console.warn("Uploading Error: " + err.stack);
callback("uploadFailed");
}
//everything ok, continue
- else
- {
+ else {
//save the path of the uploaded file
srcFile = files.file.path;
callback();
@@ -80,57 +70,48 @@ exports.doImport = function(req, res, padId)
//ensure this is a file ending we know, else we change the file ending to .txt
//this allows us to accept source code files like .c or .java
- function(callback)
- {
- var fileEnding = (srcFile.split(".")[1] || "").toLowerCase();
- var knownFileEndings = ["txt", "doc", "docx", "pdf", "odt", "html", "htm"];
-
- //find out if this is a known file ending
- var fileEndingKnown = false;
- for(var i in knownFileEndings)
- {
- if(fileEnding == knownFileEndings[i])
- {
- fileEndingKnown = true;
- }
- }
+ function(callback) {
+ var fileEnding = path.extname(srcFile).toLowerCase()
+ , knownFileEndings = [".txt", ".doc", ".docx", ".pdf", ".odt", ".html", ".htm"]
+ , fileEndingKnown = (knownFileEndings.indexOf(fileEnding) > -1);
//if the file ending is known, continue as normal
- if(fileEndingKnown)
- {
+ if(fileEndingKnown) {
callback();
}
//we need to rename this file with a .txt ending
- else
- {
+ else {
var oldSrcFile = srcFile;
- srcFile = srcFile.split(".")[0] + ".txt";
+ srcFile = path.join(path.dirname(srcFile),path.basename(srcFile, fileEnding)+".txt");
fs.rename(oldSrcFile, srcFile, callback);
}
},
- //convert file to text
- function(callback)
- {
+ //convert file to html
+ function(callback) {
var randNum = Math.floor(Math.random()*0xFFFFFFFF);
- destFile = tempDirectory + "eplite_import_" + randNum + ".txt";
- abiword.convertFile(srcFile, destFile, "txt", function(err){
- //catch convert errors
- if(err){
- console.warn("Converting Error:", err);
- return callback("convertFailed");
- } else {
- callback();
- }
- });
+ destFile = path.join(os.tmpDir(), "eplite_import_" + randNum + ".htm");
+
+ if (abiword) {
+ abiword.convertFile(srcFile, destFile, "htm", function(err) {
+ //catch convert errors
+ if(err) {
+ console.warn("Converting Error:", err);
+ return callback("convertFailed");
+ } else {
+ callback();
+ }
+ });
+ } else {
+ // if no abiword only rename
+ fs.rename(srcFile, destFile, callback);
+ }
},
//get the pad object
- function(callback)
- {
- padManager.getPad(padId, function(err, _pad)
- {
+ function(callback) {
+ padManager.getPad(padId, function(err, _pad){
if(ERR(err, callback)) return;
pad = _pad;
callback();
@@ -138,52 +119,47 @@ exports.doImport = function(req, res, padId)
},
//read the text
- function(callback)
- {
- fs.readFile(destFile, "utf8", function(err, _text)
- {
+ function(callback) {
+ fs.readFile(destFile, "utf8", function(err, _text){
if(ERR(err, callback)) return;
text = _text;
//node on windows has a delay on releasing of the file lock.
//We add a 100ms delay to work around this
- if(os.type().indexOf("Windows") > -1)
- {
- setTimeout(function()
- {
- callback();
- }, 100);
- }
- else
- {
- callback();
- }
+ if(os.type().indexOf("Windows") > -1){
+ setTimeout(function() {callback();}, 100);
+ } else {
+ callback();
+ }
});
},
//change text of the pad and broadcast the changeset
- function(callback)
- {
- pad.setText(text);
+ function(callback) {
+ var fileEnding = path.extname(srcFile).toLowerCase();
+ if (abiword || fileEnding == ".htm" || fileEnding == ".html") {
+ importHtml.setPadHTML(pad, text);
+ } else {
+ pad.setText(text);
+ }
padMessageHandler.updatePadClients(pad, callback);
},
//clean up temporary files
- function(callback)
- {
+ function(callback) {
+ //for node < 0.7 compatible
+ var fileExists = fs.exists || path.exists;
async.parallel([
- function(callback)
- {
- fs.unlink(srcFile, callback);
+ function(callback){
+ fileExists (srcFile, function(exist) { (exist)? fs.unlink(srcFile, callback): callback(); });
},
- function(callback)
- {
- fs.unlink(destFile, callback);
+ function(callback){
+ fileExists (destFile, function(exist) { (exist)? fs.unlink(destFile, callback): callback(); });
}
], callback);
}
- ], function(err)
- {
+ ], function(err) {
+
var status = "ok";
//check for known errors and replace the status
diff --git a/src/node/hooks/express/importexport.js b/src/node/hooks/express/importexport.js
index 9e78f34d..9754ffa6 100644
--- a/src/node/hooks/express/importexport.js
+++ b/src/node/hooks/express/importexport.js
@@ -28,12 +28,6 @@ exports.expressCreateServer = function (hook_name, args, cb) {
//handle import requests
args.app.post('/p/:pad/import', function(req, res, next) {
- //if abiword is disabled, skip handling this request
- if(settings.abiword == null) {
- next();
- return;
- }
-
hasPadAccess(req, res, function() {
importHandler.doImport(req, res, req.params.pad);
});
diff --git a/src/static/css/pad.css b/src/static/css/pad.css
index 64f9f0d4..c3deebc1 100644
--- a/src/static/css/pad.css
+++ b/src/static/css/pad.css
@@ -571,15 +571,20 @@ table#otheruserstable {
#exportdokuwiki {
background-position: 0px -459px
}
-#importstatusball {
- display: none
-}
-#importarrow {
- display: none
+
+/* hidden element */
+#importstatusball,
+#importarrow,
+#importmessagesuccess,
+#importmessageabiword {
+ display: none;
}
-#importmessagesuccess {
- display: none
+
+#importmessageabiword {
+ color: #900;
+ font-size: small;
}
+
#importsubmitinput {
height: 25px;
width: 85px;
diff --git a/src/static/js/pad_impexp.js b/src/static/js/pad_impexp.js
index 08dd4293..4b4733a5 100644
--- a/src/static/js/pad_impexp.js
+++ b/src/static/js/pad_impexp.js
@@ -218,6 +218,9 @@ var padimpexp = (function()
$("#exporthtmla").attr("href", pad_root_path + "/export/html");
$("#exportplaina").attr("href", pad_root_path + "/export/txt");
$("#exportdokuwikia").attr("href", pad_root_path + "/export/dokuwiki");
+
+ // activate action to import in the form
+ $("#importform").attr('action', pad_root_url + "/import");
//hide stuff thats not avaible if abiword is disabled
if(clientVars.abiwordAvailable == "no")
@@ -225,8 +228,8 @@ var padimpexp = (function()
$("#exportworda").remove();
$("#exportpdfa").remove();
$("#exportopena").remove();
- $(".importformdiv").remove();
- $("#import").html("Import is not available. To enable import please install abiword");
+
+ $("#importmessageabiword").show();
}
else if(clientVars.abiwordAvailable == "withoutPDF")
{
@@ -237,16 +240,12 @@ var padimpexp = (function()
$("#importexport").css({"height":"142px"});
$("#importexportline").css({"height":"142px"});
-
- $("#importform").attr('action', pad_root_url + "/import");
}
else
{
$("#exportworda").attr("href", pad_root_path + "/export/doc");
$("#exportpdfa").attr("href", pad_root_path + "/export/pdf");
$("#exportopena").attr("href", pad_root_path + "/export/odt");
-
- $("#importform").attr('action', pad_root_path + "/import");
}
$("#impexp-close").click(function()
diff --git a/src/templates/pad.html b/src/templates/pad.html
index c1300d5e..c2382183 100644
--- a/src/templates/pad.html
+++ b/src/templates/pad.html
@@ -246,7 +246,8 @@
<h1 data-l10n-id="pad.importExport.import_export"></h1>
<div class="column acl-write">
<% e.begin_block("importColumn"); %>
- <h2 data-l10n-id="pad.importExport.import"></h2><br>
+ <h2 data-l10n-id="pad.importExport.import"></h2>
+ <div class="importmessage" id="importmessageabiword" data-l10n-id="pad.importExport.abiword"></div><br>
<form id="importform" method="post" action="" target="importiframe" enctype="multipart/form-data">
<div class="importformdiv" id="importformfilediv">
<input type="file" name="file" size="15" id="importfileinput">