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:
2023-04-09 14:10:21 +02:00
parent 6a2da642b0
commit a49b10ed2d
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();