Commit 525e8380 authored by Liang Ding's avatar Liang Ding

#12029

parent 67da0283
......@@ -142,10 +142,8 @@ public class AdminConsole {
try {
final JSONObject qiniu = optionQueryService.getOptions(Option.CATEGORY_C_QINIU);
dataModel.put(Option.ID_C_QINIU_ACCESS_KEY, "");
dataModel.put(Option.ID_C_QINIU_BUCKET, "");
dataModel.put(Option.ID_C_QINIU_DOMAIN, "");
dataModel.put(Option.ID_C_QINIU_SECRET_KEY, "");
dataModel.put("qiniuUploadToken", "");
if (null != qiniu) {
final Auth auth = Auth.create(qiniu.optString(Option.ID_C_QINIU_ACCESS_KEY),
......
......@@ -18,6 +18,7 @@ package org.b3log.solo.processor.console;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Keys;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
......@@ -73,7 +74,7 @@ public class PreferenceConsole {
*/
@Inject
private OptionMgmtService optionMgmtService;
/**
* Option query service.
*/
......@@ -435,7 +436,7 @@ public class PreferenceConsole {
jsonObject.put(Keys.MSG, e.getMessage());
}
}
/**
* Gets Qiniu preference.
*
......@@ -458,11 +459,11 @@ public class PreferenceConsole {
* @throws Exception exception
*/
@RequestProcessing(value = PREFERENCE_URI_PREFIX + "qiniu", method = HTTPRequestMethod.GET)
public void getQiniuPreference(final HttpServletRequest request, final HttpServletResponse response,
public void getQiniuPreference(final HttpServletRequest request, final HttpServletResponse response,
final HTTPRequestContext context) throws Exception {
if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
......@@ -526,13 +527,16 @@ public class PreferenceConsole {
final String accessKey = requestJSONObject.optString(Option.ID_C_QINIU_ACCESS_KEY);
final String secretKey = requestJSONObject.optString(Option.ID_C_QINIU_SECRET_KEY);
final String domain = requestJSONObject.optString(Option.ID_C_QINIU_DOMAIN);
String domain = requestJSONObject.optString(Option.ID_C_QINIU_DOMAIN);
final String bucket = requestJSONObject.optString(Option.ID_C_QINIU_BUCKET);
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
if (StringUtils.isNotBlank(domain) && !StringUtils.endsWith(domain, "/")) {
domain += "/";
}
final JSONObject accessKeyOpt = new JSONObject();
accessKeyOpt.put(Keys.OBJECT_ID, Option.ID_C_QINIU_ACCESS_KEY);
accessKeyOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_QINIU);
......
......@@ -3,6 +3,12 @@
"staticServePath": "${staticServePath}",
"servePath": "${servePath}"
};
var qiniu = {
"qiniuUploadToken": "${qiniuUploadToken}",
"qiniuDomain": "${qiniuDomain}"
};
var Label = {
"skinDirName": "${skinDirName}",
"editorType": "${editorType}",
......
......@@ -533,6 +533,7 @@ admin.editors.KindEditor = {
} else {
try {
this[conf.id] = KindEditor.create('#' + conf.id, {
'uploadJson' : 'kindeditor/php/upyunUpload.php',
langType: language,
items: ["formatblock", "fontname", "fontsize", "|", "bold", "italic", "underline", "strikethrough", "forecolor", "|",
"link", "unlink", "image", "media", "|", "pagebreak", "emoticons", "code", "/",
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* jQuery File Upload Processing Plugin 1.3.1
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2012, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
/* jshint nomen:false */
/* global define, require, window */
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define([
'jquery',
'./jquery.fileupload'
], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS:
factory(require('jquery'));
} else {
// Browser globals:
factory(
window.jQuery
);
}
}(function ($) {
'use strict';
var originalAdd = $.blueimp.fileupload.prototype.options.add;
// The File Upload Processing plugin extends the fileupload widget
// with file processing functionality:
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
options: {
// The list of processing actions:
processQueue: [
/*
{
action: 'log',
type: 'debug'
}
*/
],
add: function (e, data) {
var $this = $(this);
data.process(function () {
return $this.fileupload('process', data);
});
originalAdd.call(this, e, data);
}
},
processActions: {
/*
log: function (data, options) {
console[options.type](
'Processing "' + data.files[data.index].name + '"'
);
}
*/
},
_processFile: function (data, originalData) {
var that = this,
dfd = $.Deferred().resolveWith(that, [data]),
chain = dfd.promise();
this._trigger('process', null, data);
$.each(data.processQueue, function (i, settings) {
var func = function (data) {
if (originalData.errorThrown) {
return $.Deferred()
.rejectWith(that, [originalData]).promise();
}
return that.processActions[settings.action].call(
that,
data,
settings
);
};
chain = chain.pipe(func, settings.always && func);
});
chain
.done(function () {
that._trigger('processdone', null, data);
that._trigger('processalways', null, data);
})
.fail(function () {
that._trigger('processfail', null, data);
that._trigger('processalways', null, data);
});
return chain;
},
// Replaces the settings of each processQueue item that
// are strings starting with an "@", using the remaining
// substring as key for the option map,
// e.g. "@autoUpload" is replaced with options.autoUpload:
_transformProcessQueue: function (options) {
var processQueue = [];
$.each(options.processQueue, function () {
var settings = {},
action = this.action,
prefix = this.prefix === true ? action : this.prefix;
$.each(this, function (key, value) {
if ($.type(value) === 'string' &&
value.charAt(0) === '@') {
settings[key] = options[
value.slice(1) || (prefix ? prefix +
key.charAt(0).toUpperCase() + key.slice(1) : key)
];
} else {
settings[key] = value;
}
});
processQueue.push(settings);
});
options.processQueue = processQueue;
},
// Returns the number of files currently in the processsing queue:
processing: function () {
return this._processing;
},
// Processes the files given as files property of the data parameter,
// returns a Promise object that allows to bind callbacks:
process: function (data) {
var that = this,
options = $.extend({}, this.options, data);
if (options.processQueue && options.processQueue.length) {
this._transformProcessQueue(options);
if (this._processing === 0) {
this._trigger('processstart');
}
$.each(data.files, function (index) {
var opts = index ? $.extend({}, options) : options,
func = function () {
if (data.errorThrown) {
return $.Deferred()
.rejectWith(that, [data]).promise();
}
return that._processFile(opts, data);
};
opts.index = index;
that._processing += 1;
that._processingQueue = that._processingQueue.pipe(func, func)
.always(function () {
that._processing -= 1;
if (that._processing === 0) {
that._trigger('processstop');
}
});
});
}
return this._processingQueue;
},
_create: function () {
this._super();
this._processing = 0;
this._processingQueue = $.Deferred().resolveWith(this)
.promise();
}
});
}));
/*
* jQuery File Upload Validation Plugin 1.1.3
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2013, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
/* global define, require, window */
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define([
'jquery',
'./jquery.fileupload-process'
], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS:
factory(require('jquery'));
} else {
// Browser globals:
factory(
window.jQuery
);
}
}(function ($) {
'use strict';
// Append to the default processQueue:
$.blueimp.fileupload.prototype.options.processQueue.push(
{
action: 'validate',
// Always trigger this action,
// even if the previous action was rejected:
always: true,
// Options taken from the global options map:
acceptFileTypes: '@',
maxFileSize: '@',
minFileSize: '@',
maxNumberOfFiles: '@',
disabled: '@disableValidation'
}
);
// The File Upload Validation plugin extends the fileupload widget
// with file validation functionality:
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
options: {
/*
// The regular expression for allowed file types, matches
// against either file type or file name:
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
// The maximum allowed file size in bytes:
maxFileSize: 10000000, // 10 MB
// The minimum allowed file size in bytes:
minFileSize: undefined, // No minimal file size
// The limit of files to be uploaded:
maxNumberOfFiles: 10,
*/
// Function returning the current number of files,
// has to be overriden for maxNumberOfFiles validation:
getNumberOfFiles: $.noop,
// Error and info messages:
messages: {
maxNumberOfFiles: 'Maximum number of files exceeded',
acceptFileTypes: 'File type not allowed',
maxFileSize: 'File is too large',
minFileSize: 'File is too small'
}
},
processActions: {
validate: function (data, options) {
if (options.disabled) {
return data;
}
var dfd = $.Deferred(),
settings = this.options,
file = data.files[data.index],
fileSize;
if (options.minFileSize || options.maxFileSize) {
fileSize = file.size;
}
if ($.type(options.maxNumberOfFiles) === 'number' &&
(settings.getNumberOfFiles() || 0) + data.files.length >
options.maxNumberOfFiles) {
file.error = settings.i18n('maxNumberOfFiles');
} else if (options.acceptFileTypes &&
!(options.acceptFileTypes.test(file.type) ||
options.acceptFileTypes.test(file.name))) {
file.error = settings.i18n('acceptFileTypes');
} else if (fileSize > options.maxFileSize) {
file.error = settings.i18n('maxFileSize');
} else if ($.type(fileSize) === 'number' &&
fileSize < options.minFileSize) {
file.error = settings.i18n('minFileSize');
} else {
delete file.error;
}
if (file.error || data.files.error) {
data.files.error = true;
dfd.rejectWith(this, [data]);
} else {
dfd.resolveWith(this, [data]);
}
return dfd.promise();
}
}
});
}));
......@@ -2,6 +2,11 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{#advimage_dlg.dialog_title}</title>
<script type="text/javascript" src="../../../jquery/jquery.min.js"></script>
<script type="text/javascript" src="../../../jquery/file-upload-9.10.1/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../../../jquery/file-upload-9.10.1/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="../../../jquery/file-upload-9.10.1/jquery.fileupload.js"></script>
<script type="text/javascript" src="../../../jquery/file-upload-9.10.1/jquery.fileupload-process.js"></script>
<script type="text/javascript" src="../../tiny_mce_popup.js"></script>
<script type="text/javascript" src="../../utils/mctabs.js"></script>
<script type="text/javascript" src="../../utils/form_utils.js"></script>
......@@ -12,7 +17,8 @@
</head>
<body id="advimage" style="display: none" role="application" aria-labelledby="app_title">
<span id="app_title" style="display:none">{#advimage_dlg.dialog_title}</span>
<form onsubmit="ImageDialog.insert();return false;" action="#">
<form onsubmit="ImageDialog.insert();
return false;" action="#">
<div class="tabs">
<ul>
<li id="general_tab" class="current" aria-controls="general_panel"><span><a href="javascript:mcTabs.displayTab('general_tab','general_panel');" onmousedown="return false;">{#advimage_dlg.tab_general}</a></span></li>
......@@ -47,7 +53,10 @@
</tr>
<tr>
<td><label for="src_list">{#advimage_dlg.image_list}</label></td>
<td><select id="src_list" name="src_list" onchange="document.getElementById('src').value = this.options[this.selectedIndex].value;document.getElementById('alt').value = this.options[this.selectedIndex].text;document.getElementById('title').value = this.options[this.selectedIndex].text;ImageDialog.showPreviewImage(this.options[this.selectedIndex].value);"><option value=""></option></select></td>
<td><select id="src_list" name="src_list" onchange="document.getElementById('src').value = this.options[this.selectedIndex].value;
document.getElementById('alt').value = this.options[this.selectedIndex].text;
document.getElementById('title').value = this.options[this.selectedIndex].text;
ImageDialog.showPreviewImage(this.options[this.selectedIndex].value);"><option value=""></option></select></td>
</tr>
<tr>
<td class="column1"><label id="altlabel" for="alt">{#advimage_dlg.alt}</label></td>
......@@ -83,7 +92,8 @@
<table role="presentation" border="0" cellpadding="4" cellspacing="0">
<tr>
<td class="column1"><label id="alignlabel" for="align">{#advimage_dlg.align}</label></td>
<td><select id="align" name="align" onchange="ImageDialog.updateStyle('align');ImageDialog.changeAppearance();">
<td><select id="align" name="align" onchange="ImageDialog.updateStyle('align');
ImageDialog.changeAppearance();">
<option value="">{#not_set}</option>
<option value="baseline">{#advimage_dlg.align_baseline}</option>
<option value="top">{#advimage_dlg.align_top}</option>
......@@ -128,18 +138,24 @@
<tr>
<td class="column1"><label id="vspacelabel" for="vspace">{#advimage_dlg.vspace}</label></td>
<td><input name="vspace" type="text" id="vspace" value="" size="3" maxlength="3" class="number" onchange="ImageDialog.updateStyle('vspace');ImageDialog.changeAppearance();" onblur="ImageDialog.updateStyle('vspace');ImageDialog.changeAppearance();" />
<td><input name="vspace" type="text" id="vspace" value="" size="3" maxlength="3" class="number" onchange="ImageDialog.updateStyle('vspace');
ImageDialog.changeAppearance();" onblur="ImageDialog.updateStyle('vspace');
ImageDialog.changeAppearance();" />
</td>
</tr>
<tr>
<td class="column1"><label id="hspacelabel" for="hspace">{#advimage_dlg.hspace}</label></td>
<td><input name="hspace" type="text" id="hspace" value="" size="3" maxlength="3" class="number" onchange="ImageDialog.updateStyle('hspace');ImageDialog.changeAppearance();" onblur="ImageDialog.updateStyle('hspace');ImageDialog.changeAppearance();" /></td>
<td><input name="hspace" type="text" id="hspace" value="" size="3" maxlength="3" class="number" onchange="ImageDialog.updateStyle('hspace');
ImageDialog.changeAppearance();" onblur="ImageDialog.updateStyle('hspace');
ImageDialog.changeAppearance();" /></td>
</tr>
<tr>
<td class="column1"><label id="borderlabel" for="border">{#advimage_dlg.border}</label></td>
<td><input id="border" name="border" type="text" value="" size="3" maxlength="3" class="number" onchange="ImageDialog.updateStyle('border');ImageDialog.changeAppearance();" onblur="ImageDialog.updateStyle('border');ImageDialog.changeAppearance();" /></td>
<td><input id="border" name="border" type="text" value="" size="3" maxlength="3" class="number" onchange="ImageDialog.updateStyle('border');
ImageDialog.changeAppearance();" onblur="ImageDialog.updateStyle('border');
ImageDialog.changeAppearance();" /></td>
</tr>
<tr>
......
......@@ -6,6 +6,8 @@ var ImageDialog = {
if (url = tinyMCEPopup.getParam("external_image_list_url"))
document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>');
ImageDialog.uploadImage();
},
init: function (ed) {
var f = document.forms[0], nl = f.elements, ed = tinyMCEPopup.editor, dom = ed.dom, n = ed.selection.getNode(), fl = tinyMCEPopup.getParam('external_image_list', 'tinyMCEImageList');
......@@ -475,41 +477,46 @@ var ImageDialog = {
changeMouseMove: function () {
},
uploadImage: function () {
$('#imageUpload').fileupload({
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
maxFileSize: 1024 * 1024, // 1M
multipart: true,
pasteZone: null,
dropZone: null,
url: "http://upload.qiniu.com/",
formData: function (form) {
var data = form.serializeArray();
data.push({name: 'token', value: '${qiniuUploadToken}'});
data.push({name: 'key', value: 'avatar/${currentUser.oId}'});
return data;
},
submit: function (e, data) {
},
done: function (e, data) {
// console.log(data.result)
var qiniuKey = data.result.key;
if (!qiniuKey) {
alert("Upload error");
return;
}
$(function () {
var qiniu = window.parent.qiniu;
console.log(qiniu);
$('#imageUpload').fileupload({
multipart: true,
pasteZone: null,
dropZone: null,
url: "http://upload.qiniu.com/",
formData: function (form) {
var data = form.serializeArray();
data.push({name: 'token', value: qiniu.qiniuUploadToken});
return data;
},
submit: function (e, data) {
},
done: function (e, data) {
// console.log(data.result)
var qiniuKey = data.result.key;
if (!qiniuKey) {
alert("Upload error");
return;
}
var t = new Date().getTime();
$('#src').val('7xjz0r.com1.z0.glb.clouddn.com/' + qiniuKey + '?' + t);
ImageDialog.showPreviewImage('7xjz0r.com1.z0.glb.clouddn.com/' + qiniuKey + '?' + t);
},
fail: function (e, data) {
alert("Upload error: " + data.errorThrown);
}
}).on('fileuploadprocessalways', function (e, data) {
var currentFile = data.files[data.index];
if (data.files.error && currentFile.error) {
alert(currentFile.error);
}
var t = new Date().getTime();
$('#src').val(qiniu.qiniuDomain + qiniuKey + '?' + t);
ImageDialog.showPreviewImage(qiniu.qiniuDomain + qiniuKey + '?' + t);
},
fail: function (e, data) {
alert("Upload error: " + data.errorThrown);
}
}).on('fileuploadprocessalways', function (e, data) {
var currentFile = data.files[data.index];
if (data.files.error && currentFile.error) {
alert(currentFile.error);
}
});
});
},
showPreviewImage: function (u, st) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment