add closing dialogs, redirecting and removing content functionality to the winix framework
add such new methods to FunctionBase: - bool can_push_url_to_browser_history(); - void add_standard_models(); - void close_modal_dialogs(); - void prepare_doc_url(const wchar_t * local_url, pt::WTextStream & url); - void prepare_doc_url(const wchar_t * local_url, std::wstring & url); - std::wstring prepare_doc_url(const wchar_t * local_url = nullptr); - std::wstring prepare_doc_url(const std::wstring & local_url); - void redirect_to(const wchar_t * url, bool append_domain = true); - void redirect_to(const std::wstring & url, bool append_domain = true); - void redirect_to(const pt::WTextStream & url, bool append_domain = true); - void redirect_to(const wchar_t * url, const wchar_t * frame_url, const wchar_t * dom_target); - void redirect_to(const std::wstring & url, const std::wstring & frame_url, const std::wstring & dom_target); - void redirect_to(pt::WTextStream & url, pt::WTextStream & frame_url, pt::WTextStream & dom_target); - void redirect_to(pt::WTextStream & url, pt::WTextStream & frame_url, const wchar_t * dom_target); - void redirect_to(const wchar_t * url, const wchar_t * frame_url, pt::WTextStream & dom_target); - void retarged(const wchar_t * frame, const wchar_t * dom_target, const wchar_t * push_url = nullptr, const wchar_t * swap_algorithm = nullptr); - void retarged(const std::wstring & frame, const std::wstring & dom_target, const std::wstring & push_url, const wchar_t * swap_algorithm = nullptr); - void retarged(const wchar_t * frame, pt::WTextStream & dom_target, const wchar_t * push_url = nullptr, const wchar_t * swap_algorithm = nullptr); - void remove_content(pt::WTextStream & dom_target, bool close_dialogs = false); - void remove_content(const wchar_t * dom_target, bool has_postfix, long dom_target_postfix, bool close_dialogs = false); - void remove_content(const wchar_t * dom_target, long dom_target_postfix, bool close_dialogs = false); - void remove_content(const wchar_t * dom_target, bool close_dialogs = false); - void update_content(const wchar_t * frame, pt::WTextStream & dom_target, bool close_dialogs = false); - void update_content(const wchar_t * frame, const wchar_t * dom_target, bool has_postfix, long dom_target_postfix, bool close_dialogs = false); - void update_content(const wchar_t * frame, const wchar_t * dom_target, long dom_target_postfix, bool close_dialogs = false); - void update_content(const wchar_t * frame, const wchar_t * dom_target, bool close_dialogs = false); while here: - refactor PascalCase to snake_case in FunctionBase - add start_request() and finish_request() methods to FunctionBase - add has_*_access() methods to FunctionBase - fix: FunctionBase::clear() method was not called if a request was assigned to a job - add a WinixEzcHelper model - allow to serialize a header if the header value is neither a string nor an integer - refactor PascalCase to snake_case in functions: Emacs, Mkdir, Upload
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2023, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -57,18 +57,18 @@ Upload::Upload()
|
||||
}
|
||||
|
||||
|
||||
void Upload::Init()
|
||||
void Upload::init()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Upload::Finish()
|
||||
void Upload::finish()
|
||||
{
|
||||
CloseMagicLib();
|
||||
close_magic_lib();
|
||||
}
|
||||
|
||||
|
||||
bool Upload::HasAccess(const Item & item)
|
||||
bool Upload::has_upload_access(const Item & item)
|
||||
{
|
||||
// you can use 'upload' only in a directory
|
||||
if( item.type != Item::dir )
|
||||
@@ -91,9 +91,9 @@ return true;
|
||||
}
|
||||
|
||||
|
||||
bool Upload::HasAccess()
|
||||
bool Upload::has_access()
|
||||
{
|
||||
if( cur->request->is_item || !HasAccess(*cur->request->dir_tab.back()) )
|
||||
if( cur->request->is_item || !has_upload_access(*cur->request->dir_tab.back()) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -102,7 +102,7 @@ return true;
|
||||
|
||||
|
||||
|
||||
bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_filename)
|
||||
bool Upload::upload_save_static_file(const Item & item, const std::wstring & tmp_filename)
|
||||
{
|
||||
if( !system->MakeFilePath(item, path, false, true, config->upload_dirs_chmod, config->upload_group_int) )
|
||||
{
|
||||
@@ -131,7 +131,7 @@ bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_fi
|
||||
|
||||
|
||||
|
||||
void Upload::ResizeImage(Item & item)
|
||||
void Upload::resize_image(Item & item)
|
||||
{
|
||||
Image::Scale scale = system->image.GetImageScale(item.parent_id);
|
||||
system->image.Resize(item.id, scale.cx, scale.cy, scale.aspect_mode, scale.quality);
|
||||
@@ -139,7 +139,7 @@ void Upload::ResizeImage(Item & item)
|
||||
|
||||
|
||||
|
||||
void Upload::CreateThumb(Item & item)
|
||||
void Upload::create_thumb(Item & item)
|
||||
{
|
||||
Image::Scale scale = system->image.GetThumbScale(item.parent_id);
|
||||
system->image.CreateThumb(item.id, scale.cx, scale.cy, scale.aspect_mode, scale.quality);
|
||||
@@ -147,7 +147,7 @@ void Upload::CreateThumb(Item & item)
|
||||
|
||||
|
||||
|
||||
void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
|
||||
void Upload::upload_file(Item & item, const std::wstring & tmp_filename)
|
||||
{
|
||||
// we should add the file beforehand to get the proper item.id
|
||||
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
@@ -157,7 +157,7 @@ void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
|
||||
{
|
||||
if( system->CreateNewFile(item) )
|
||||
{
|
||||
if( UploadSaveStaticFile(item, tmp_filename) )
|
||||
if( upload_save_static_file(item, tmp_filename) )
|
||||
{
|
||||
ItemModelData item_model_data;
|
||||
item_model_data.prepare_unique_url = false;
|
||||
@@ -171,10 +171,10 @@ void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
|
||||
if( item.item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE )
|
||||
{
|
||||
if( config->image_resize )
|
||||
ResizeImage(item);
|
||||
resize_image(item);
|
||||
|
||||
if( config->create_thumb )
|
||||
CreateThumb(item);
|
||||
create_thumb(item);
|
||||
}
|
||||
|
||||
if( is_jquery_upload )
|
||||
@@ -191,7 +191,7 @@ void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
|
||||
}
|
||||
|
||||
|
||||
bool Upload::FunUploadCheckAbuse()
|
||||
bool Upload::fun_upload_check_abuse()
|
||||
{
|
||||
if( config->use_antispam_mechanism_for_not_logged_users )
|
||||
{
|
||||
@@ -218,7 +218,7 @@ return true;
|
||||
|
||||
|
||||
|
||||
void Upload::UploadMulti()
|
||||
void Upload::upload_multi()
|
||||
{
|
||||
cur->request->item.Clear(); // clearing and setting date
|
||||
cur->request->item.parent_id = cur->request->dir_tab.back()->id;
|
||||
@@ -238,19 +238,19 @@ void Upload::UploadMulti()
|
||||
cur->request->item.item_content.file_size = i->second.file_size;
|
||||
|
||||
functions->PrepareUrl(cur->request->item);
|
||||
AnalizeFileType(i->second.tmp_filename, cur->request->item.item_content.file_mime_type);
|
||||
UploadFile(cur->request->item, i->second.tmp_filename);
|
||||
analize_file_type(i->second.tmp_filename, cur->request->item.item_content.file_mime_type);
|
||||
upload_file(cur->request->item, i->second.tmp_filename);
|
||||
i->second.tmp_filename.clear();
|
||||
}
|
||||
|
||||
if( is_jquery_upload )
|
||||
CreateJqueryUploadAnswer();
|
||||
create_jquery_upload_answer();
|
||||
else
|
||||
system->RedirectToLastDir();
|
||||
}
|
||||
|
||||
|
||||
void Upload::UploadSingle()
|
||||
void Upload::upload_single()
|
||||
{
|
||||
cur->request->item.Clear(); // clearing and setting date
|
||||
|
||||
@@ -278,22 +278,22 @@ void Upload::UploadSingle()
|
||||
functions->PrepareUrl(cur->request->item);
|
||||
}
|
||||
|
||||
AnalizeFileType(post_file.tmp_filename, cur->request->item.item_content.file_mime_type);
|
||||
UploadFile(cur->request->item, post_file.tmp_filename);
|
||||
analize_file_type(post_file.tmp_filename, cur->request->item.item_content.file_mime_type);
|
||||
upload_file(cur->request->item, post_file.tmp_filename);
|
||||
post_file.tmp_filename.clear();
|
||||
|
||||
if( is_jquery_upload )
|
||||
CreateJqueryUploadAnswer();
|
||||
create_jquery_upload_answer();
|
||||
else
|
||||
if( is_ckeditor_upload )
|
||||
CreateCkeditorUploadAnswer();
|
||||
create_ckeditor_upload_answer();
|
||||
else
|
||||
if( cur->request->status == WINIX_ERR_OK )
|
||||
system->RedirectTo(cur->request->item, L"/cat");
|
||||
}
|
||||
|
||||
|
||||
void Upload::InitMagicLibIfNeeded()
|
||||
void Upload::init_magic_lib_if_needed()
|
||||
{
|
||||
if( !magic_cookie )
|
||||
{
|
||||
@@ -313,7 +313,7 @@ void Upload::InitMagicLibIfNeeded()
|
||||
}
|
||||
|
||||
log << logend;
|
||||
CloseMagicLib();
|
||||
close_magic_lib();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -324,7 +324,7 @@ void Upload::InitMagicLibIfNeeded()
|
||||
}
|
||||
|
||||
|
||||
void Upload::CloseMagicLib()
|
||||
void Upload::close_magic_lib()
|
||||
{
|
||||
if( magic_cookie )
|
||||
{
|
||||
@@ -335,7 +335,7 @@ void Upload::CloseMagicLib()
|
||||
}
|
||||
|
||||
|
||||
void Upload::AnalizeFileType(const std::wstring & file_path, std::wstring & file_type)
|
||||
void Upload::analize_file_type(const std::wstring & file_path, std::wstring & file_type)
|
||||
{
|
||||
file_type.clear();
|
||||
|
||||
@@ -375,7 +375,7 @@ void Upload::AnalizeFileType(const std::wstring & file_path, std::wstring & file
|
||||
/*
|
||||
* an answer for the 'upload' function
|
||||
*/
|
||||
void Upload::CreateJqueryUploadAnswer()
|
||||
void Upload::create_jquery_upload_answer()
|
||||
{
|
||||
Request & req = *cur->request;
|
||||
|
||||
@@ -420,7 +420,7 @@ void Upload::CreateJqueryUploadAnswer()
|
||||
* an answer for the ckeditor function
|
||||
* https://ckeditor.com/docs/ckeditor4/latest/guide/dev_file_upload.html
|
||||
*/
|
||||
void Upload::CreateCkeditorUploadAnswer()
|
||||
void Upload::create_ckeditor_upload_answer()
|
||||
{
|
||||
Request & req = *cur->request;
|
||||
|
||||
@@ -453,9 +453,9 @@ void Upload::CreateCkeditorUploadAnswer()
|
||||
}
|
||||
|
||||
|
||||
void Upload::MakePost()
|
||||
void Upload::make_post()
|
||||
{
|
||||
InitMagicLibIfNeeded();
|
||||
init_magic_lib_if_needed();
|
||||
cur->request->item_tab.clear();
|
||||
is_jquery_upload = cur->request->IsParam(L"jquery_upload");
|
||||
is_ckeditor_upload = cur->request->IsParam(L"ckeditor_upload");
|
||||
@@ -466,18 +466,18 @@ void Upload::MakePost()
|
||||
return;
|
||||
}
|
||||
|
||||
if( !FunUploadCheckAbuse() )
|
||||
if( !fun_upload_check_abuse() )
|
||||
return;
|
||||
|
||||
if( cur->request->post_file_tab.size() > 1 )
|
||||
UploadMulti();
|
||||
upload_multi();
|
||||
else
|
||||
UploadSingle();
|
||||
upload_single();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Upload::MakeGet()
|
||||
void Upload::make_get()
|
||||
{
|
||||
if( cur->request->IsParam(L"jquery_upload") )
|
||||
{
|
||||
@@ -492,19 +492,17 @@ void Upload::MakeGet()
|
||||
raw("order by item.sort_index asc, item.url asc, item.id asc").
|
||||
get_vector(cur->request->item_tab);
|
||||
|
||||
CreateJqueryUploadAnswer();
|
||||
create_jquery_upload_answer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Upload::Clear()
|
||||
void Upload::clear()
|
||||
{
|
||||
files.clear();
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
Reference in New Issue
Block a user