git.shiar.nl
/
minimedit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
028bc42
)
edit: support ckeditor uploadUrl protocol
author
Mischa POSLAWSKY
<perl@shiar.org>
Thu, 14 Jun 2018 16:33:58 +0000
(18:33 +0200)
committer
Mischa POSLAWSKY
<perl@shiar.org>
Thu, 14 Jun 2018 20:42:56 +0000
(22:42 +0200)
edit.js
patch
|
blob
|
history
edit/index.php
patch
|
blob
|
history
diff --git
a/edit.js
b/edit.js
index 049bbd0d13aff7e939e34fbf6b110ca63effeb47..b7ce591ffc1011937854568a1629f4da3da3c101 100644
(file)
--- a/
edit.js
+++ b/
edit.js
@@
-65,11
+65,12
@@
CKEDITOR.on('instanceCreated', function (event) {
editor.on('configLoaded', function () {
var config = editor.config;
config.language = 'nl';
editor.on('configLoaded', function () {
var config = editor.config;
config.language = 'nl';
- config.extraPlugins = 'sourcedialog,inlinesave,placeholder';
+ config.extraPlugins = 'sourcedialog,inlinesave,placeholder
,uploadimage
';
config.format_tags = 'h2;h3;h4;p';
config.allowedContent = true;
config.entities = false; // keep unicode
config.filebrowserImageUploadUrl = '/edit?output=ckescript';
config.format_tags = 'h2;h3;h4;p';
config.allowedContent = true;
config.entities = false; // keep unicode
config.filebrowserImageUploadUrl = '/edit?output=ckescript';
+ config.uploadUrl = '/edit?output=ckjson';
config.pasteFilter = pastefilter;
config.contentsCss = document.styleSheets[0].href;
config.toolbar = [
config.pasteFilter = pastefilter;
config.contentsCss = document.styleSheets[0].href;
config.toolbar = [
diff --git
a/edit/index.php
b/edit/index.php
index 19c02d9698a670ee3363792a93aec73ebae67460..5c5ee3d595ae3514e44288cb17ca36eab15ba4d7 100644
(file)
--- a/
edit/index.php
+++ b/
edit/index.php
@@
-5,8
+5,10
@@
if (empty($User['admin']))
abort("geen beheersrechten", '401 unauthorised');
if ($_FILES) {
abort("geen beheersrechten", '401 unauthorised');
if ($_FILES) {
+ $response = ['uploaded' => 0];
try {
$img = @$_FILES['upload'];
try {
$img = @$_FILES['upload'];
+ $response['fileName'] = $img['name'];
if (!$img or $img['error'] !== UPLOAD_ERR_OK)
throw new Exception('bestand niet goed ontvangen: '.$img['error']);
if (!$img or $img['error'] !== UPLOAD_ERR_OK)
throw new Exception('bestand niet goed ontvangen: '.$img['error']);
@@
-16,22
+18,33
@@
if ($_FILES) {
}
$target = $datadir.'/'.$img['name'];
}
$target = $datadir.'/'.$img['name'];
+ $response['url'] = str_replace('%2F', '/', urlencode($target));
if (!@move_uploaded_file($img['tmp_name'], $target)) {
throw new Exception('bestand kon niet worden opgeslagen');
}
if (!@move_uploaded_file($img['tmp_name'], $target)) {
throw new Exception('bestand kon niet worden opgeslagen');
}
+ $response['uploaded']++;
}
catch (Exception $e) {
}
catch (Exception $e) {
-
abort($e->getMessage(), '409 upload error')
;
+
$response['error'] = ['message' => $e->getMessage()]
;
}
switch (@$_GET['output']) {
}
switch (@$_GET['output']) {
+ case 'ckjson':
+ print json_encode($response);
+ exit;
case 'ckescript':
case 'ckescript':
+ if (empty($response['url'])) break;
printf('<script>window.parent.CKEDITOR.tools.callFunction(%s)</script>',
printf('<script>window.parent.CKEDITOR.tools.callFunction(%s)</script>',
- "{$_GET['CKEditorFuncNum']}, '
$target
'"
+ "{$_GET['CKEditorFuncNum']}, '
{$response['url']}
'"
);
break;
default:
);
break;
default:
- abort($target);
+ if (empty($response['url'])) break;
+ print $target;
+ }
+
+ if (isset($response['error'])) {
+ abort($response['error']['message'], '409 upload error');
}
exit;
}
}
exit;
}