Merge branch 'develop' of github.com:ether/etherpad-lite into focus-on-password

pull/1221/head
John McLear 2012-12-03 11:37:01 +00:00
commit bef25b40f8
9 changed files with 92 additions and 117 deletions

View File

@ -65,7 +65,7 @@
"maxAge" : 21600, // 60 * 60 * 6 = 6 hours "maxAge" : 21600, // 60 * 60 * 6 = 6 hours
/* This is the path to the Abiword executable. Setting it to null, disables abiword. /* This is the path to the Abiword executable. Setting it to null, disables abiword.
Abiword is needed to enable the import/export of pads*/ Abiword is needed to advanced import/export features of pads*/
"abiword" : null, "abiword" : null,
/* This setting is used if you require authentication of all users. /* This setting is used if you require authentication of all users.

View File

@ -44,6 +44,7 @@ pad.importExport.exportword = Microsoft Word
pad.importExport.exportpdf = PDF pad.importExport.exportpdf = PDF
pad.importExport.exportopen = ODF (Open Document Format) pad.importExport.exportopen = ODF (Open Document Format)
pad.importExport.exportdokuwiki = DokuWiki 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.connected = Connected.
pad.modals.reconnecting = Reconnecting to your pad.. pad.modals.reconnecting = Reconnecting to your pad..
pad.modals.forcereconnect = Force reconnect pad.modals.forcereconnect = Force reconnect

View File

@ -46,6 +46,7 @@ pad.importExport.exportword = Microsoft Word
pad.importExport.exportpdf = PDF pad.importExport.exportpdf = PDF
pad.importExport.exportopen = ODF (Open Document Format) pad.importExport.exportopen = ODF (Open Document Format)
pad.importExport.exportdokuwiki = DokuWiki 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.connected = Conectado.
pad.modals.reconnecting = Reconectando a tu pad.. pad.modals.reconnecting = Reconectando a tu pad..
pad.modals.forcereconnect = Reconexión forzosa pad.modals.forcereconnect = Reconexión forzosa

View File

@ -4,6 +4,7 @@
/* /*
* 2011 Peter 'Pita' Martischka (Primary Technology Ltd) * 2011 Peter 'Pita' Martischka (Primary Technology Ltd)
* 2012 Iván Eixarch
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,26 +19,20 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace"); var ERR = require("async-stacktrace")
var padManager = require("../db/PadManager"); , padManager = require("../db/PadManager")
var padMessageHandler = require("./PadMessageHandler"); , padMessageHandler = require("./PadMessageHandler")
var async = require("async"); , async = require("async")
var fs = require("fs"); , fs = require("fs")
var settings = require('../utils/Settings'); , path = require("path")
var formidable = require('formidable'); , settings = require('../utils/Settings')
var os = require("os"); , formidable = require('formidable')
, os = require("os")
, importHtml = require("../utils/ImportHtml");
//load abiword only if its enabled //load abiword only if its enabled
if(settings.abiword != null) if(settings.abiword != null)
var abiword = require("../utils/Abiword"); 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 * do a requested import
@ -45,32 +40,27 @@ if(os.type().indexOf("Windows") > -1)
exports.doImport = function(req, res, padId) exports.doImport = function(req, res, padId)
{ {
//pipe to a file //pipe to a file
//convert file to text via abiword //convert file to html via abiword
//set text in the pad //set html in the pad
var srcFile, destFile; var srcFile, destFile
var pad; , pad
var text; , text;
async.series([ async.series([
//save the uploaded file to /tmp //save the uploaded file to /tmp
function(callback) function(callback) {
{
var form = new formidable.IncomingForm(); var form = new formidable.IncomingForm();
form.keepExtensions = true; 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 //the upload failed, stop at this point
if(err || files.file === undefined) if(err || files.file === undefined) {
{
console.warn("Uploading Error: " + err.stack); console.warn("Uploading Error: " + err.stack);
callback("uploadFailed"); callback("uploadFailed");
} }
//everything ok, continue //everything ok, continue
else else {
{
//save the path of the uploaded file //save the path of the uploaded file
srcFile = files.file.path; srcFile = files.file.path;
callback(); 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 //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 //this allows us to accept source code files like .c or .java
function(callback) function(callback) {
{ var fileEnding = path.extname(srcFile).toLowerCase()
var fileEnding = (srcFile.split(".")[1] || "").toLowerCase(); , knownFileEndings = [".txt", ".doc", ".docx", ".pdf", ".odt", ".html", ".htm"]
var knownFileEndings = ["txt", "doc", "docx", "pdf", "odt", "html", "htm"]; , fileEndingKnown = (knownFileEndings.indexOf(fileEnding) > -1);
//find out if this is a known file ending
var fileEndingKnown = false;
for(var i in knownFileEndings)
{
if(fileEnding == knownFileEndings[i])
{
fileEndingKnown = true;
}
}
//if the file ending is known, continue as normal //if the file ending is known, continue as normal
if(fileEndingKnown) if(fileEndingKnown) {
{
callback(); callback();
} }
//we need to rename this file with a .txt ending //we need to rename this file with a .txt ending
else else {
{
var oldSrcFile = srcFile; var oldSrcFile = srcFile;
srcFile = srcFile.split(".")[0] + ".txt"; srcFile = path.join(path.dirname(srcFile),path.basename(srcFile, fileEnding)+".txt");
fs.rename(oldSrcFile, srcFile, callback); fs.rename(oldSrcFile, srcFile, callback);
} }
}, },
//convert file to text //convert file to html
function(callback) function(callback) {
{
var randNum = Math.floor(Math.random()*0xFFFFFFFF); var randNum = Math.floor(Math.random()*0xFFFFFFFF);
destFile = tempDirectory + "eplite_import_" + randNum + ".txt"; destFile = path.join(os.tmpDir(), "eplite_import_" + randNum + ".htm");
abiword.convertFile(srcFile, destFile, "txt", function(err){
//catch convert errors if (abiword) {
if(err){ abiword.convertFile(srcFile, destFile, "htm", function(err) {
console.warn("Converting Error:", err); //catch convert errors
return callback("convertFailed"); if(err) {
} else { console.warn("Converting Error:", err);
callback(); return callback("convertFailed");
} } else {
}); callback();
}
});
} else {
// if no abiword only rename
fs.rename(srcFile, destFile, callback);
}
}, },
//get the pad object //get the pad object
function(callback) function(callback) {
{ padManager.getPad(padId, function(err, _pad){
padManager.getPad(padId, function(err, _pad)
{
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
pad = _pad; pad = _pad;
callback(); callback();
@ -138,52 +119,47 @@ exports.doImport = function(req, res, padId)
}, },
//read the text //read the text
function(callback) function(callback) {
{ fs.readFile(destFile, "utf8", function(err, _text){
fs.readFile(destFile, "utf8", function(err, _text)
{
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
text = _text; text = _text;
//node on windows has a delay on releasing of the file lock. //node on windows has a delay on releasing of the file lock.
//We add a 100ms delay to work around this //We add a 100ms delay to work around this
if(os.type().indexOf("Windows") > -1) if(os.type().indexOf("Windows") > -1){
{ setTimeout(function() {callback();}, 100);
setTimeout(function() } else {
{ callback();
callback(); }
}, 100);
}
else
{
callback();
}
}); });
}, },
//change text of the pad and broadcast the changeset //change text of the pad and broadcast the changeset
function(callback) function(callback) {
{ var fileEnding = path.extname(srcFile).toLowerCase();
pad.setText(text); if (abiword || fileEnding == ".htm" || fileEnding == ".html") {
importHtml.setPadHTML(pad, text);
} else {
pad.setText(text);
}
padMessageHandler.updatePadClients(pad, callback); padMessageHandler.updatePadClients(pad, callback);
}, },
//clean up temporary files //clean up temporary files
function(callback) function(callback) {
{ //for node < 0.7 compatible
var fileExists = fs.exists || path.exists;
async.parallel([ async.parallel([
function(callback) function(callback){
{ fileExists (srcFile, function(exist) { (exist)? fs.unlink(srcFile, callback): callback(); });
fs.unlink(srcFile, callback);
}, },
function(callback) function(callback){
{ fileExists (destFile, function(exist) { (exist)? fs.unlink(destFile, callback): callback(); });
fs.unlink(destFile, callback);
} }
], callback); ], callback);
} }
], function(err) ], function(err) {
{
var status = "ok"; var status = "ok";
//check for known errors and replace the status //check for known errors and replace the status

View File

@ -66,8 +66,6 @@ exports.restartServer = function () {
} else { } else {
console.log( "SSL -- not enabled!" );
var http = require('http'); var http = require('http');
server = http.createServer(app); server = http.createServer(app);
} }

View File

@ -28,12 +28,6 @@ exports.expressCreateServer = function (hook_name, args, cb) {
//handle import requests //handle import requests
args.app.post('/p/:pad/import', function(req, res, next) { 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() { hasPadAccess(req, res, function() {
importHandler.doImport(req, res, req.params.pad); importHandler.doImport(req, res, req.params.pad);
}); });

View File

@ -585,15 +585,20 @@ table#otheruserstable {
#exportdokuwiki { #exportdokuwiki {
background-position: 0px -459px background-position: 0px -459px
} }
#importstatusball {
display: none /* hidden element */
#importstatusball,
#importarrow,
#importmessagesuccess,
#importmessageabiword {
display: none;
} }
#importarrow {
display: none #importmessageabiword {
} color: #900;
#importmessagesuccess { font-size: small;
display: none
} }
#importsubmitinput { #importsubmitinput {
height: 25px; height: 25px;
width: 85px; width: 85px;

View File

@ -218,6 +218,9 @@ var padimpexp = (function()
$("#exporthtmla").attr("href", pad_root_path + "/export/html"); $("#exporthtmla").attr("href", pad_root_path + "/export/html");
$("#exportplaina").attr("href", pad_root_path + "/export/txt"); $("#exportplaina").attr("href", pad_root_path + "/export/txt");
$("#exportdokuwikia").attr("href", pad_root_path + "/export/dokuwiki"); $("#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 //hide stuff thats not avaible if abiword is disabled
if(clientVars.abiwordAvailable == "no") if(clientVars.abiwordAvailable == "no")
@ -225,8 +228,8 @@ var padimpexp = (function()
$("#exportworda").remove(); $("#exportworda").remove();
$("#exportpdfa").remove(); $("#exportpdfa").remove();
$("#exportopena").remove(); $("#exportopena").remove();
$(".importformdiv").remove();
$("#import").html("Import is not available. To enable import please install abiword"); $("#importmessageabiword").show();
} }
else if(clientVars.abiwordAvailable == "withoutPDF") else if(clientVars.abiwordAvailable == "withoutPDF")
{ {
@ -237,16 +240,12 @@ var padimpexp = (function()
$("#importexport").css({"height":"142px"}); $("#importexport").css({"height":"142px"});
$("#importexportline").css({"height":"142px"}); $("#importexportline").css({"height":"142px"});
$("#importform").attr('action', pad_root_url + "/import");
} }
else else
{ {
$("#exportworda").attr("href", pad_root_path + "/export/doc"); $("#exportworda").attr("href", pad_root_path + "/export/doc");
$("#exportpdfa").attr("href", pad_root_path + "/export/pdf"); $("#exportpdfa").attr("href", pad_root_path + "/export/pdf");
$("#exportopena").attr("href", pad_root_path + "/export/odt"); $("#exportopena").attr("href", pad_root_path + "/export/odt");
$("#importform").attr('action', pad_root_path + "/import");
} }
$("#impexp-close").click(function() $("#impexp-close").click(function()

View File

@ -258,7 +258,8 @@
<h1 data-l10n-id="pad.importExport.import_export"></h1> <h1 data-l10n-id="pad.importExport.import_export"></h1>
<div class="column acl-write"> <div class="column acl-write">
<% e.begin_block("importColumn"); %> <% 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"> <form id="importform" method="post" action="" target="importiframe" enctype="multipart/form-data">
<div class="importformdiv" id="importformfilediv"> <div class="importformdiv" id="importformfilediv">
<input type="file" name="file" size="15" id="importfileinput"> <input type="file" name="file" size="15" id="importfileinput">