allow to upload files from the ckeditor

while here:
- update ckeditor to 4.21.0
- add a Sourcedialog plugin to the ckeditor
This commit is contained in:
Tomasz Sowa 2023-04-09 14:10:21 +02:00
parent 6a2da642b0
commit a49b10ed2d
Signed by: tomasz.sowa
GPG Key ID: 662CC1438638588B
5 changed files with 87 additions and 39 deletions

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2008-2022, Tomasz Sowa * Copyright (c) 2008-2023, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -244,7 +244,7 @@ void Upload::UploadMulti()
} }
if( is_jquery_upload ) if( is_jquery_upload )
CreateAnswer(); CreateJqueryUploadAnswer();
else else
system->RedirectToLastDir(); system->RedirectToLastDir();
} }
@ -283,7 +283,10 @@ void Upload::UploadSingle()
post_file.tmp_filename.clear(); post_file.tmp_filename.clear();
if( is_jquery_upload ) if( is_jquery_upload )
CreateAnswer(); CreateJqueryUploadAnswer();
else
if( is_ckeditor_upload )
CreateCkeditorUploadAnswer();
else else
if( cur->request->status == WINIX_ERR_OK ) if( cur->request->status == WINIX_ERR_OK )
system->RedirectTo(cur->request->item, L"/cat"); system->RedirectTo(cur->request->item, L"/cat");
@ -369,32 +372,10 @@ void Upload::AnalizeFileType(const std::wstring & file_path, std::wstring & file
} }
/*
void Upload::MakePost() * an answer for the 'upload' function
{ */
InitMagicLibIfNeeded(); void Upload::CreateJqueryUploadAnswer()
cur->request->item_tab.clear();
is_jquery_upload = cur->request->IsParam(L"jquery_upload");
if( cur->request->post_file_tab.empty() )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( !FunUploadCheckAbuse() )
return;
if( cur->request->post_file_tab.size() > 1 )
UploadMulti();
else
UploadSingle();
}
void Upload::CreateAnswer()
{ {
Request & req = *cur->request; Request & req = *cur->request;
@ -435,6 +416,67 @@ void Upload::CreateAnswer()
} }
/*
* an answer for the ckeditor function
* https://ckeditor.com/docs/ckeditor4/latest/guide/dev_file_upload.html
*/
void Upload::CreateCkeditorUploadAnswer()
{
Request & req = *cur->request;
files.add(L"uploaded", 1);
files.add(L"fileName", req.item.url);
std::wstring link;
system->CreateItemLink(req.item, link);
files.add(L"url", link);
/*
* if uploaded directly from the ckeditor (by drag and drop) then the placed image
* is very small, add "width" and "height" in such a case
*/
//files.add(L"width", "600");
//files.add(L"height", "500");
/*
* if there was an error add "error" item e.g.
* "error": {
* "message": "The file is too big."
* }
*/
files.serialize_to_json_stream(cur->request->out_bin_stream, false);
cur->request->send_bin_stream = true;
cur->request->use_ezc_engine = false;
cur->request->container_type = Request::container_raw;
cur->request->out_headers.add(Header::content_type, Header::application_json);
}
void Upload::MakePost()
{
InitMagicLibIfNeeded();
cur->request->item_tab.clear();
is_jquery_upload = cur->request->IsParam(L"jquery_upload");
is_ckeditor_upload = cur->request->IsParam(L"ckeditor_upload");
if( cur->request->post_file_tab.empty() )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( !FunUploadCheckAbuse() )
return;
if( cur->request->post_file_tab.size() > 1 )
UploadMulti();
else
UploadSingle();
}
void Upload::MakeGet() void Upload::MakeGet()
{ {
if( cur->request->IsParam(L"jquery_upload") ) if( cur->request->IsParam(L"jquery_upload") )
@ -450,7 +492,7 @@ void Upload::MakeGet()
raw("order by item.sort_index asc, item.url asc, item.id asc"). raw("order by item.sort_index asc, item.url asc, item.id asc").
get_vector(cur->request->item_tab); get_vector(cur->request->item_tab);
CreateAnswer(); CreateJqueryUploadAnswer();
} }
} }

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2010-2022, Tomasz Sowa * Copyright (c) 2010-2023, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -61,6 +61,7 @@ private:
std::wstring path; std::wstring path;
bool is_jquery_upload; bool is_jquery_upload;
bool is_ckeditor_upload;
magic_t magic_cookie; magic_t magic_cookie;
pt::Space files; pt::Space files;
@ -75,7 +76,8 @@ private:
void UploadSingle(); void UploadSingle();
void ResizeImage(Item & item); void ResizeImage(Item & item);
void CreateThumb(Item & item); void CreateThumb(Item & item);
void CreateAnswer(); void CreateJqueryUploadAnswer();
void CreateCkeditorUploadAnswer();
void InitMagicLibIfNeeded(); void InitMagicLibIfNeeded();
void CloseMagicLib(); void CloseMagicLib();

View File

@ -34,22 +34,26 @@ editorElement.setAttribute( 'contenteditable', 'true' );
CKEDITOR.inline( '[0]', CKEDITOR.inline( '[0]',
{ {
// https://ckeditor.com/docs/ckeditor4/latest/guide/dev_file_browse_upload.html
// config.filebrowserBrowseUrl - setting contains the location of an external file browser
// that should be launched when the Browse Server button is pressed.
// config.filebrowserUploadUrl - setting contains the location of a script that handles file uploads.
// If set, the Upload tab will appear in some dialog windows — the ones
// where such functionality is available, i.e. Link, Image.
filebrowserBrowseUrl: '[doc_base_url][dir]ls?ckeditor_browse&fullscreen', filebrowserBrowseUrl: '[doc_base_url][dir]ls?ckeditor_browse&fullscreen',
filebrowserUploadUrl: '[doc_base_url][dir]upload?ckeditor_upload',
customConfig : '[doc_base_url]/var/ckeditor_winix.js', customConfig : '[doc_base_url]/var/ckeditor_winix.js',
extraPlugins : 'sourcedialog',
//extraPlugins : 'sourcedialog',
//removePlugins : 'sourcearea', //removePlugins : 'sourcearea',
toolbar : 'winix', toolbar : 'winix',
height : '350px', height : '350px',
scayt_autoStartup : false, // spellchecker disabled scayt_autoStartup : false, // spellchecker disabled
//docType : '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
docType : '<!DOCTYPE html>', docType : '<!DOCTYPE html>',
entities : false, // when true then ó becames &oacute, entities : false, // when true then ó becames &oacute,
toolbar_winix : toolbar_winix :
\[ \[
\['Save','Preview','-'\], \['Sourcedialog', 'Save','Preview','-'\],
\['Cut','Copy','Paste','PasteText','PasteFromWord','-'\], \['Cut','Copy','Paste','PasteText','PasteFromWord','-'\],
\['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'\], \['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'\],

View File

@ -160,7 +160,7 @@
<td> <td>
<span class="preview"> <span class="preview">
\{% if (file.thumbnailUrl) \{ %\} \{% if (file.thumbnailUrl) \{ %\}
<a href="\{%=file.url%\}" title="\{%=file.name%\}" download="\{%=file.name%\}" data-gallery><img src="\{%=file.thumbnailUrl%\}"></a> <a href="\{%=file.url%\}" title="\{%=file.name%\}" download="\{%=file.name%\}" data-gallery><img style="max-height: 150px;" src="\{%=file.thumbnailUrl%\}"></a>
\{% \} %\} \{% \} %\}
</span> </span>
</td> </td>

View File

@ -256,7 +256,7 @@ cm.save()
[if winix_function_is "ckeditor"] [if winix_function_is "ckeditor"]
<script type="text/javascript" src="[doc_base_url_common]/ckeditor/4.20.1/ckeditor.js"></script> <script type="text/javascript" src="[doc_base_url_common]/ckeditor/4.21.0/ckeditor.js"></script>
[if not winix_has_jquery] [if not winix_has_jquery]
[def winix_has_jquery true] [def winix_has_jquery true]