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.
*
* Redistribution and use in source and binary forms, with or without
@ -244,7 +244,7 @@ void Upload::UploadMulti()
}
if( is_jquery_upload )
CreateAnswer();
CreateJqueryUploadAnswer();
else
system->RedirectToLastDir();
}
@ -283,7 +283,10 @@ void Upload::UploadSingle()
post_file.tmp_filename.clear();
if( is_jquery_upload )
CreateAnswer();
CreateJqueryUploadAnswer();
else
if( is_ckeditor_upload )
CreateCkeditorUploadAnswer();
else
if( cur->request->status == WINIX_ERR_OK )
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()
{
InitMagicLibIfNeeded();
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()
/*
* an answer for the 'upload' function
*/
void Upload::CreateJqueryUploadAnswer()
{
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()
{
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").
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.
*
* Redistribution and use in source and binary forms, with or without
@ -61,6 +61,7 @@ private:
std::wstring path;
bool is_jquery_upload;
bool is_ckeditor_upload;
magic_t magic_cookie;
pt::Space files;
@ -75,7 +76,8 @@ private:
void UploadSingle();
void ResizeImage(Item & item);
void CreateThumb(Item & item);
void CreateAnswer();
void CreateJqueryUploadAnswer();
void CreateCkeditorUploadAnswer();
void InitMagicLibIfNeeded();
void CloseMagicLib();

View File

@ -34,22 +34,26 @@ editorElement.setAttribute( 'contenteditable', 'true' );
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',
filebrowserUploadUrl: '[doc_base_url][dir]upload?ckeditor_upload',
customConfig : '[doc_base_url]/var/ckeditor_winix.js',
//extraPlugins : 'sourcedialog',
extraPlugins : 'sourcedialog',
//removePlugins : 'sourcearea',
toolbar : 'winix',
height : '350px',
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>',
entities : false, // when true then ó becames &oacute,
toolbar_winix :
\[
\['Save','Preview','-'\],
\['Sourcedialog', 'Save','Preview','-'\],
\['Cut','Copy','Paste','PasteText','PasteFromWord','-'\],
\['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'\],

View File

@ -160,7 +160,7 @@
<td>
<span class="preview">
\{% 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>
</td>

View File

@ -256,7 +256,7 @@ cm.save()
[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]
[def winix_has_jquery true]