From c844c8b188332e2cb55aece69b02a2b999d01ec6 Mon Sep 17 00:00:00 2001
From: lealife
Date: Sat, 10 Oct 2015 16:18:26 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E5=A4=96=E9=93=BE=E5=9B=BE?=
=?UTF-8?q?=E7=89=87,=20=E5=A4=8D=E5=88=B6=E5=88=B0leanote?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/FileController.go | 28 ++++++++++--------
.../plugins/paste/classes/Clipboard.js | 5 ++--
.../tinymce/plugins/paste/classes/Plugin.js | 24 +--------------
public/tinymce/plugins/paste/plugin.dev.js | 2 +-
public/tinymce/plugins/paste/plugin.js | 29 +++----------------
public/tinymce/plugins/paste/plugin.min.js | 2 +-
6 files changed, 26 insertions(+), 64 deletions(-)
diff --git a/app/controllers/FileController.go b/app/controllers/FileController.go
index 7ec448e..ce0e691 100644
--- a/app/controllers/FileController.go
+++ b/app/controllers/FileController.go
@@ -234,35 +234,39 @@ func (c File) CopyImage(userId, fileId, toUserId string) revel.Result {
return c.RenderJson(re)
}
-// 复制外网的图片, 成公共图片 放在/upload下
+// 复制外网的图片
// 都要好好的计算大小
func (c File) CopyHttpImage(src string) revel.Result {
re := info.NewRe()
- fileUrlPath := "upload/" + c.GetUserId() + "/images"
- dir := revel.BasePath + "/public/" + fileUrlPath
+
+ // 生成上传路径
+ newGuid := NewGuid()
+ userId := c.GetUserId()
+ fileUrlPath := "files/" + Digest3(userId) + "/" + userId + "/" + Digest2(newGuid) + "/images"
+ dir := revel.BasePath + "/" + fileUrlPath
err := os.MkdirAll(dir, 0755)
if err != nil {
return c.RenderJson(re)
}
filesize, filename, _, ok := netutil.WriteUrl(src, dir)
-
+
if !ok {
re.Msg = "copy error"
return c.RenderJson(re)
}
-
+
// File
fileInfo := info.File{Name: filename,
Title: filename,
- Path: fileUrlPath + "/" + filename,
- Size: filesize}
-
- id := bson.NewObjectId();
+ Path: fileUrlPath + "/" + filename,
+ Size: filesize}
+
+ id := bson.NewObjectId()
fileInfo.FileId = id
-
+
re.Id = id.Hex()
- re.Item = fileInfo.Path
+// re.Item = fileInfo.Path
re.Ok, re.Msg = fileService.AddImage(fileInfo, "", c.GetUserId(), true)
-
+
return c.RenderJson(re)
}
diff --git a/public/tinymce/plugins/paste/classes/Clipboard.js b/public/tinymce/plugins/paste/classes/Clipboard.js
index 69b1b54..f3f7094 100644
--- a/public/tinymce/plugins/paste/classes/Clipboard.js
+++ b/public/tinymce/plugins/paste/classes/Clipboard.js
@@ -47,8 +47,9 @@ define("tinymce/pasteplugin/Clipboard", [
ajaxPost("/file/copyHttpImage", {src: src}, function(ret) {
if(reIsOk(ret)) {
// 将图片替换之
- var src = urlPrefix + "/" + ret.Item;
- var dom = editor.dom
+ // var src = urlPrefix + "/" + ret.Item;
+ var src = urlPrefix + "/file/outputImage?fileId=" + ret.Id;
+ var dom = editor.dom;
for(var i in ids) {
var id = ids[i];
var imgElm = dom.get(id);
diff --git a/public/tinymce/plugins/paste/classes/Plugin.js b/public/tinymce/plugins/paste/classes/Plugin.js
index 3bcf652..db45622 100644
--- a/public/tinymce/plugins/paste/classes/Plugin.js
+++ b/public/tinymce/plugins/paste/classes/Plugin.js
@@ -44,26 +44,11 @@ define("tinymce/pasteplugin/Plugin", [
}
}
}
-
- function togglePasteCopyImage() {
- if (clipboard.copyImage) {
- this.active(false);
- clipboard.copyImage = false
- } else {
- clipboard.copyImage = true;
- this.active(true);
- if (!userIsInformed2) {
- editor.windowManager.alert(
- "When copy other site's images (not in leanote) into editor, it will copy the image into your album."
- );
- userIsInformed2 = true;
- }
- }
- }
self.clipboard = clipboard = new Clipboard(editor);
self.quirks = new Quirks(editor);
self.wordFilter = new WordFilter(editor);
+ clipboard.copyImage = true;
if (editor.settings.paste_as_text) {
self.clipboard.pasteFormat = "text";
@@ -116,13 +101,6 @@ define("tinymce/pasteplugin/Plugin", [
onclick: togglePlainTextPaste,
active: self.clipboard.pasteFormat == "text"
});
-
- editor.addButton('pasteCopyImage', {
- icon: 'copy',
- tooltip: "When Paste other site's image, copy it into my album as public image",
- onclick: togglePasteCopyImage,
- active: self.clipboard.copyImage === true
- });
editor.addMenuItem('pastetext', {
text: 'Paste as text',
diff --git a/public/tinymce/plugins/paste/plugin.dev.js b/public/tinymce/plugins/paste/plugin.dev.js
index 647a97a..b583377 100644
--- a/public/tinymce/plugins/paste/plugin.dev.js
+++ b/public/tinymce/plugins/paste/plugin.dev.js
@@ -117,4 +117,4 @@
writeScripts();
})(this);
-// $hash: e0933a5a75e12f26b54b4e7b86f5bdc2
\ No newline at end of file
+// $hash: cb0df1bfb67ded475df65e7e75c7998f
\ No newline at end of file
diff --git a/public/tinymce/plugins/paste/plugin.js b/public/tinymce/plugins/paste/plugin.js
index 3b1966f..75f634b 100644
--- a/public/tinymce/plugins/paste/plugin.js
+++ b/public/tinymce/plugins/paste/plugin.js
@@ -232,8 +232,9 @@ define("tinymce/pasteplugin/Clipboard", [
ajaxPost("/file/copyHttpImage", {src: src}, function(ret) {
if(reIsOk(ret)) {
// 将图片替换之
- var src = urlPrefix + "/" + ret.Item;
- var dom = editor.dom
+ // var src = urlPrefix + "/" + ret.Item;
+ var src = urlPrefix + "/file/outputImage?fileId=" + ret.Id;
+ var dom = editor.dom;
for(var i in ids) {
var id = ids[i];
var imgElm = dom.get(id);
@@ -1103,26 +1104,11 @@ define("tinymce/pasteplugin/Plugin", [
}
}
}
-
- function togglePasteCopyImage() {
- if (clipboard.copyImage) {
- this.active(false);
- clipboard.copyImage = false
- } else {
- clipboard.copyImage = true;
- this.active(true);
- if (!userIsInformed2) {
- editor.windowManager.alert(
- "When copy other site's images (not in leanote) into editor, it will copy the image into your album."
- );
- userIsInformed2 = true;
- }
- }
- }
self.clipboard = clipboard = new Clipboard(editor);
self.quirks = new Quirks(editor);
self.wordFilter = new WordFilter(editor);
+ clipboard.copyImage = true;
if (editor.settings.paste_as_text) {
self.clipboard.pasteFormat = "text";
@@ -1175,13 +1161,6 @@ define("tinymce/pasteplugin/Plugin", [
onclick: togglePlainTextPaste,
active: self.clipboard.pasteFormat == "text"
});
-
- editor.addButton('pasteCopyImage', {
- icon: 'copy',
- tooltip: "When Paste other site's image, copy it into my album as public image",
- onclick: togglePasteCopyImage,
- active: self.clipboard.copyImage === true
- });
editor.addMenuItem('pastetext', {
text: 'Paste as text',
diff --git a/public/tinymce/plugins/paste/plugin.min.js b/public/tinymce/plugins/paste/plugin.min.js
index 59116e3..ee88713 100644
--- a/public/tinymce/plugins/paste/plugin.min.js
+++ b/public/tinymce/plugins/paste/plugin.min.js
@@ -1 +1 @@
-!function(a,b){"use strict";function c(a,b){for(var c,d=[],f=0;f]+src=\"data:image[^>]+>/g,"")),c=d.fire("BeforePastePreProcess",{content:a}),c=d.fire("PastePreProcess",c),a=c.content,!c.isDefaultPrevented()){if(d.hasEventListeners("PastePostProcess")&&!c.isDefaultPrevented()){var g=f.add(d.getBody(),"div",{style:"display:none"},a);c=d.fire("PastePostProcess",{node:g}),f.remove(g),a=c.node.innerHTML}if(!c.isDefaultPrevented()){var h=d.selection.getNode();if("PRE"==h.nodeName){if(!b)try{b=$(a).text()}catch(i){}b=b.replace(//g,">"),d.insertRawContent(b)}else if(p.copyImage){var j=UrlPrefix,k={},l=(new Date).getTime();try{for(var m=$(""+a+"
"),g&&/^(PRE|DIV)$/.test(g.nodeName)||!h?a=c.filter(a,[[/\n/g,"
"]]):(a=c.filter(a,[[/\n\n/g,"
"+e],[/^(.*<\/p>)()$/,e+"$1"],[/\n/g,"
"]]),-1!=a.indexOf("
")&&(a=e+a)),f(a,b)}function h(){var a=d.dom,b=d.getBody(),c=d.dom.getViewPort(d.getWin()),e=d.inline?b.scrollTop:c.y,f=d.inline?b.clientHeight:c.h;i(),m=a.add(d.getBody(),"div",{id:"mcepastebin",contentEditable:!0,"data-mce-bogus":"1",style:"position: absolute; top: "+(e+20)+"px;width: 10px; height: "+(f-40)+"px; overflow: hidden; opacity: 0"},r),a.setStyle(m,"left","rtl"==a.getStyle(b,"direction",!0)?65535:-65535),a.bind(m,"beforedeactivate focusin focusout",function(a){a.stopPropagation()}),n=d.selection.getRng(),m.focus(),d.selection.select(m,!0)}function i(){m&&(d.dom.unbind(m),d.dom.remove(m),n&&d.selection.setRng(n)),o=!1,m=n=null}function j(){return m?m.innerHTML:r}function k(a){var b={},c=a.clipboardData||d.getDoc().dataTransfer;if(c&&c.types){b["text/plain"]=c.getData("Text");for(var e=0;ei?c&&(c=c.parent.parent):(d=c,c=null)),c&&c.name==g?c.append(a):(d=d||c,c=new e(g,1),h>1&&c.attr("start",""+h),a.wrap(c)),a.name="li",b.value="";var j=b.next;j&&3==j.type&&(j.value=j.value.replace(/^\u00a0+/,"")),i>f&&d&&d.lastChild.append(c),f=i}for(var c,d,f=1,g=a.getAll("p"),h=0;h/gi,/<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,[/<(\/?)s>/gi,"<$1strike>"],[/ /gi,"\xa0"],[/([\s\u00a0]*)<\/span>/gi,function(a,b){return b.length>0?b.replace(/./," ").slice(Math.floor(b.length/2)).split("").join("\xa0"):""}]]);var p=i.paste_word_valid_elements;p||(p="@[style],-strong/b,-em/i,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,-table,-tr,-td[colspan|rowspan],-th,-thead,-tfoot,-tbody,-a[!href],sub,sup,strike,br");var q=new c({valid_elements:p}),r=new b({},q);r.addAttributeFilter("style",function(a){for(var b,c=a.length;c--;)b=a[c],b.attr("style",l(b,b.attr("style"))),"span"!=b.name||b.attributes.length||b.unwrap()});var s=r.parse(o);k(s),j.content=new d({},q).serialize(s)}})}return h.isWordContent=g,h}),d("tinymce/pasteplugin/Quirks",["tinymce/Env","tinymce/util/Tools","tinymce/pasteplugin/WordFilter","tinymce/pasteplugin/Utils"],function(a,b,c,d){return function(e){function f(a){e.on("BeforePastePreProcess",function(b){b.content=a(b.content)})}function g(a){return a=d.filter(a,[/^[\s\S]*|[\s\S]*$/g,[/\u00a0<\/span>/g,"\xa0"],/
$/])}function h(a){if(!c.isWordContent(a))return a;var f=[];b.each(e.schema.getBlockElements(),function(a,b){f.push(b)});var g=new RegExp("(?:
[\\s\\r\\n]+|
)*(<\\/?("+f.join("|")+")[^>]*>)(?:
[\\s\\r\\n]+|
)*","g");return a=d.filter(a,[[g,"$1"]]),a=d.filter(a,[[/
/g,"
"],[/
/g," "],[/
/g,"
"]])}function i(a){return(e.settings.paste_remove_styles||e.settings.paste_remove_styles_if_webkit!==!1)&&(a=a.replace(/ style=\"[^\"]+\"/g,"")),a}a.webkit&&(f(i),f(g)),a.ie&&f(h)}}),d("tinymce/pasteplugin/Plugin",["tinymce/PluginManager","tinymce/pasteplugin/Clipboard","tinymce/pasteplugin/WordFilter","tinymce/pasteplugin/Quirks"],function(a,b,c,d){var e,f;a.add("paste",function(a){function g(){"text"==i.pasteFormat?(this.active(!1),i.pasteFormat="html"):(i.pasteFormat="text",this.active(!0),e||(a.windowManager.alert("Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off."),e=!0))}function h(){i.copyImage?(this.active(!1),i.copyImage=!1):(i.copyImage=!0,this.active(!0),f||(a.windowManager.alert("When copy other site's images (not in leanote) into editor, it will copy the image into your album."),f=!0))}var i,j=this,k=a.settings;j.clipboard=i=new b(a),j.quirks=new d(a),j.wordFilter=new c(a),a.settings.paste_as_text&&(j.clipboard.pasteFormat="text"),k.paste_preprocess&&a.on("PastePreProcess",function(a){k.paste_preprocess.call(j,j,a)}),k.paste_postprocess&&a.on("PastePostProcess",function(a){k.paste_postprocess.call(j,j,a)}),a.addCommand("mceInsertClipboardContent",function(a,b){b.content&&j.clipboard.pasteHtml(b.content),b.text&&j.clipboard.pasteText(b.text)}),a.paste_block_drop&&a.on("dragend dragover draggesture dragdrop drop drag",function(a){a.preventDefault(),a.stopPropagation()}),a.settings.paste_data_images||a.on("drop",function(a){var b=a.dataTransfer;b&&b.files&&b.files.length>0&&a.preventDefault()}),a.addButton("pastetext",{icon:"pastetext",tooltip:"Paste as text",onclick:g,active:"text"==j.clipboard.pasteFormat}),a.addButton("pasteCopyImage",{icon:"copy",tooltip:"When Paste other site's image, copy it into my album as public image",onclick:h,active:j.clipboard.copyImage===!0}),a.addMenuItem("pastetext",{text:"Paste as text",selectable:!0,active:i.pasteFormat,onclick:g})})}),f(["tinymce/pasteplugin/Utils","tinymce/pasteplugin/WordFilter"])}(this);
\ No newline at end of file
+!function(a,b){"use strict";function c(a,b){for(var c,d=[],f=0;f]+src=\"data:image[^>]+>/g,"")),c=d.fire("BeforePastePreProcess",{content:a}),c=d.fire("PastePreProcess",c),a=c.content,!c.isDefaultPrevented()){if(d.hasEventListeners("PastePostProcess")&&!c.isDefaultPrevented()){var g=f.add(d.getBody(),"div",{style:"display:none"},a);c=d.fire("PastePostProcess",{node:g}),f.remove(g),a=c.node.innerHTML}if(!c.isDefaultPrevented()){var h=d.selection.getNode();if("PRE"==h.nodeName){if(!b)try{b=$(a).text()}catch(i){}b=b.replace(//g,">"),d.insertRawContent(b)}else if(p.copyImage){var j=UrlPrefix,k={},l=(new Date).getTime();try{for(var m=$(""+a+"
"),g&&/^(PRE|DIV)$/.test(g.nodeName)||!h?a=c.filter(a,[[/\n/g,"
"]]):(a=c.filter(a,[[/\n\n/g,"
"+e],[/^(.*<\/p>)()$/,e+"$1"],[/\n/g,"
"]]),-1!=a.indexOf("
")&&(a=e+a)),f(a,b)}function h(){var a=d.dom,b=d.getBody(),c=d.dom.getViewPort(d.getWin()),e=d.inline?b.scrollTop:c.y,f=d.inline?b.clientHeight:c.h;i(),m=a.add(d.getBody(),"div",{id:"mcepastebin",contentEditable:!0,"data-mce-bogus":"1",style:"position: absolute; top: "+(e+20)+"px;width: 10px; height: "+(f-40)+"px; overflow: hidden; opacity: 0"},r),a.setStyle(m,"left","rtl"==a.getStyle(b,"direction",!0)?65535:-65535),a.bind(m,"beforedeactivate focusin focusout",function(a){a.stopPropagation()}),n=d.selection.getRng(),m.focus(),d.selection.select(m,!0)}function i(){m&&(d.dom.unbind(m),d.dom.remove(m),n&&d.selection.setRng(n)),o=!1,m=n=null}function j(){return m?m.innerHTML:r}function k(a){var b={},c=a.clipboardData||d.getDoc().dataTransfer;if(c&&c.types){b["text/plain"]=c.getData("Text");for(var e=0;ei?c&&(c=c.parent.parent):(d=c,c=null)),c&&c.name==g?c.append(a):(d=d||c,c=new e(g,1),h>1&&c.attr("start",""+h),a.wrap(c)),a.name="li",b.value="";var j=b.next;j&&3==j.type&&(j.value=j.value.replace(/^\u00a0+/,"")),i>f&&d&&d.lastChild.append(c),f=i}for(var c,d,f=1,g=a.getAll("p"),h=0;h/gi,/<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,[/<(\/?)s>/gi,"<$1strike>"],[/ /gi,"\xa0"],[/([\s\u00a0]*)<\/span>/gi,function(a,b){return b.length>0?b.replace(/./," ").slice(Math.floor(b.length/2)).split("").join("\xa0"):""}]]);var p=i.paste_word_valid_elements;p||(p="@[style],-strong/b,-em/i,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,-table,-tr,-td[colspan|rowspan],-th,-thead,-tfoot,-tbody,-a[!href],sub,sup,strike,br");var q=new c({valid_elements:p}),r=new b({},q);r.addAttributeFilter("style",function(a){for(var b,c=a.length;c--;)b=a[c],b.attr("style",l(b,b.attr("style"))),"span"!=b.name||b.attributes.length||b.unwrap()});var s=r.parse(o);k(s),j.content=new d({},q).serialize(s)}})}return h.isWordContent=g,h}),d("tinymce/pasteplugin/Quirks",["tinymce/Env","tinymce/util/Tools","tinymce/pasteplugin/WordFilter","tinymce/pasteplugin/Utils"],function(a,b,c,d){return function(e){function f(a){e.on("BeforePastePreProcess",function(b){b.content=a(b.content)})}function g(a){return a=d.filter(a,[/^[\s\S]*|[\s\S]*$/g,[/\u00a0<\/span>/g,"\xa0"],/
$/])}function h(a){if(!c.isWordContent(a))return a;var f=[];b.each(e.schema.getBlockElements(),function(a,b){f.push(b)});var g=new RegExp("(?:
[\\s\\r\\n]+|
)*(<\\/?("+f.join("|")+")[^>]*>)(?:
[\\s\\r\\n]+|
)*","g");return a=d.filter(a,[[g,"$1"]]),a=d.filter(a,[[/
/g,"
"],[/
/g," "],[/
/g,"
"]])}function i(a){return(e.settings.paste_remove_styles||e.settings.paste_remove_styles_if_webkit!==!1)&&(a=a.replace(/ style=\"[^\"]+\"/g,"")),a}a.webkit&&(f(i),f(g)),a.ie&&f(h)}}),d("tinymce/pasteplugin/Plugin",["tinymce/PluginManager","tinymce/pasteplugin/Clipboard","tinymce/pasteplugin/WordFilter","tinymce/pasteplugin/Quirks"],function(a,b,c,d){var e;a.add("paste",function(a){function f(){"text"==g.pasteFormat?(this.active(!1),g.pasteFormat="html"):(g.pasteFormat="text",this.active(!0),e||(a.windowManager.alert("Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off."),e=!0))}var g,h=this,i=a.settings;h.clipboard=g=new b(a),h.quirks=new d(a),h.wordFilter=new c(a),g.copyImage=!0,a.settings.paste_as_text&&(h.clipboard.pasteFormat="text"),i.paste_preprocess&&a.on("PastePreProcess",function(a){i.paste_preprocess.call(h,h,a)}),i.paste_postprocess&&a.on("PastePostProcess",function(a){i.paste_postprocess.call(h,h,a)}),a.addCommand("mceInsertClipboardContent",function(a,b){b.content&&h.clipboard.pasteHtml(b.content),b.text&&h.clipboard.pasteText(b.text)}),a.paste_block_drop&&a.on("dragend dragover draggesture dragdrop drop drag",function(a){a.preventDefault(),a.stopPropagation()}),a.settings.paste_data_images||a.on("drop",function(a){var b=a.dataTransfer;b&&b.files&&b.files.length>0&&a.preventDefault()}),a.addButton("pastetext",{icon:"pastetext",tooltip:"Paste as text",onclick:f,active:"text"==h.clipboard.pasteFormat}),a.addMenuItem("pastetext",{text:"Paste as text",selectable:!0,active:g.pasteFormat,onclick:f})})}),f(["tinymce/pasteplugin/Utils","tinymce/pasteplugin/WordFilter"])}(this);
\ No newline at end of file