From e63838faebc5cb1c8a7fbfebb17304e4f7d996c4 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sat, 20 Jul 2024 15:13:27 +0200 Subject: [PATCH] improve frontend of emacs, ckeditor, tinymce, nicedit, meta and env functions Improves in emacs: - use htmx to send content to the controller - show txt and formatted_txt content in the second panel - show two tabs if "tabs" winix parameter is used - add an option to show either one or two panels - correctly resize the editor window (F11) when two panels are shown Improves in ckeditor: - use htmx to send content to the controller - do not check automatically for ckeditor update Improves in tinymce/nicedit/meta/env: - use htmx to send content to the controller while here: - change PascalCase to snake_case in meta/env controllers - update CodeMirror editor to 5.65.16 - udpate Showdown (markdown to html converter) to 2.1.0 --- winixd/functions/ckeditor.cpp | 32 ++- winixd/functions/ckeditor.h | 18 +- winixd/functions/emacs.cpp | 54 +++-- winixd/functions/emacs.h | 17 +- winixd/functions/env.cpp | 34 ++- winixd/functions/env.h | 26 +- winixd/functions/functionbase.cpp | 217 ++++++++++++++++- winixd/functions/functionbase.h | 25 ++ winixd/functions/meta.cpp | 33 ++- winixd/functions/meta.h | 22 +- winixd/functions/nicedit.cpp | 33 ++- winixd/functions/nicedit.h | 14 +- winixd/functions/tinymce.cpp | 32 ++- winixd/functions/tinymce.h | 17 +- winixd/html/ckeditor.html | 6 +- winixd/html/fun_ckeditor.html | 113 +++++---- winixd/html/fun_emacs.html | 86 ++++--- winixd/html/fun_emacs_post.html | 98 ++++---- winixd/html/fun_env.html | 29 ++- winixd/html/fun_meta.html | 37 ++- winixd/html/fun_nicedit.html | 82 +++++-- winixd/html/fun_tinymce.html | 98 ++++---- winixd/html/index_head_adder.html | 385 ++++++++++++++++++++++++------ winixd/locale/en | 24 +- winixd/locale/pl | 23 +- winixd/models/itemcontent.h | 2 - winixd/templates/misc.cpp | 14 +- 27 files changed, 1075 insertions(+), 496 deletions(-) diff --git a/winixd/functions/ckeditor.cpp b/winixd/functions/ckeditor.cpp index af2da3f..4866404 100644 --- a/winixd/functions/ckeditor.cpp +++ b/winixd/functions/ckeditor.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2008-2014, Tomasz Sowa + * Copyright (c) 2008-2024, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,14 +36,10 @@ #include "functions.h" - -namespace Winix +namespace Winix::Fun { -namespace Fun -{ - Ckeditor::Ckeditor() { fun.url = L"ckeditor"; @@ -57,7 +53,16 @@ void Ckeditor::init() bool Ckeditor::has_access() { - return functions->fun_emacs.has_access(); + FunctionBase * emacs = functions->Find(L"emacs"); + + if( emacs ) + { + return emacs->has_access(); + } + else + { + return false; + } } @@ -73,13 +78,20 @@ void Ckeditor::make_get() void Ckeditor::make_post() { - functions->fun_emacs.make_post(); -} + FunctionBase * emacs = functions->Find(L"emacs"); + if( emacs ) + { + emacs->make_post(); + } + else + { + log << log2 << "Ckeditor: I cannot save your content, there is no emacs function available" << logend; + } +} } // namespace -} // namespace Winix diff --git a/winixd/functions/ckeditor.h b/winixd/functions/ckeditor.h index 158ee04..4265d4e 100644 --- a/winixd/functions/ckeditor.h +++ b/winixd/functions/ckeditor.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2011-2014, Tomasz Sowa + * Copyright (c) 2011-2024, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,11 +37,8 @@ #include "functionbase.h" -namespace Winix -{ - -namespace Fun +namespace Winix::Fun { @@ -50,16 +47,15 @@ class Ckeditor : public FunctionBase public: Ckeditor(); - void init(); - bool has_access(); - void make_get(); - void make_post(); + + void init() override; + bool has_access() override; + void make_get() override; + void make_post() override; }; } // namespace -} // namespace Winix - #endif diff --git a/winixd/functions/emacs.cpp b/winixd/functions/emacs.cpp index 70716d1..e5aec42 100644 --- a/winixd/functions/emacs.cpp +++ b/winixd/functions/emacs.cpp @@ -37,14 +37,10 @@ #include "functions.h" - -namespace Winix +namespace Winix::Fun { -namespace Fun -{ - Emacs::Emacs() { fun.url = L"emacs"; @@ -128,13 +124,30 @@ return WINIX_NOTIFY_CODE_ADD; } -// IMPROVEME -// make some kind of utils and put this method there -// because this method is used from ckeditor and other editors too +void Emacs::push_url_to_current_function(const wchar_t * local_url) +{ + if( cur->request->is_htmx_request ) + { + pt::WTextStream url; + + if( cur->request->IsParam(L"tabs") ) + prepare_current_function(L"/tabs", url); + else + prepare_current_function(nullptr, url); + + cur->request->out_headers.add(Header::hx_push_url, url); + } +} + + +/* + * this make_post() is used from Ckeditor, Tinymce and Nicedit as well + */ void Emacs::make_post() { bool status = false; bool adding = !cur->request->is_item; + std::wstring old_url; if( !adding ) old_url = cur->request->item.url; @@ -163,38 +176,29 @@ void Emacs::make_post() } cur->request->status = status ? WINIX_ERR_OK : WINIX_ERR_PERMISSION_DENIED; - answer.add(L"status", status); if( status ) { - if( adding ) - { - system->RedirectToLastFunction(nullptr, false); - answer.add(L"redirect_to", cur->request->redirect_to); - - if( cur->request->container_type != Request::ContainerType::container_raw ) - { - cur->request->redirect_to.clear(); - } - } - functions->CheckSpecialFile(cur->request->item); + bool was_url_changed = (adding || cur->request->item.url != old_url); + redirect_if_needed(was_url_changed); } - cur->request->models.Add(L"answer", answer); + if( adding ) + { + // App::AddDefaultModels() is called before make_post() and didn't see the item yet + cur->request->models.Add(L"item", cur->request->item); + } } void Emacs::clear() { - answer.clear(); } - - } // namespace -} // namespace Winix + diff --git a/winixd/functions/emacs.h b/winixd/functions/emacs.h index 1285c14..41472c1 100644 --- a/winixd/functions/emacs.h +++ b/winixd/functions/emacs.h @@ -37,11 +37,8 @@ #include "functionbase.h" -namespace Winix -{ - -namespace Fun +namespace Winix::Fun { @@ -50,25 +47,21 @@ class Emacs : public FunctionBase public: Emacs(); - bool has_access(); - void make_post(); + bool has_access() override; + void make_post() override; private: bool has_emacs_access(const Item & item); - void clear(); + void clear() override; int notify_code_edit(); int notify_code_add(); - - std::wstring old_url; - pt::Space answer; + void push_url_to_current_function(const wchar_t * local_url = nullptr) override; }; } // namespace -} // namespace Winix - #endif diff --git a/winixd/functions/env.cpp b/winixd/functions/env.cpp index f2d3aab..c888e39 100644 --- a/winixd/functions/env.cpp +++ b/winixd/functions/env.cpp @@ -37,13 +37,10 @@ #include "core/misc.h" -namespace Winix +namespace Winix::Fun { -namespace Fun -{ - Env::Env() { fun.url = L"env"; @@ -68,15 +65,15 @@ return true; -bool Env::Parse(const std::wstring & env_str) +bool Env::parse(const std::wstring & env_str) { return (conf_parser.parse_space(env_str, space) == pt::SpaceParser::ok); } -bool Env::EditAdminEnv(const std::wstring & env_str) +bool Env::edit_admin_env(const std::wstring & env_str) { - if( Parse(env_str) ) + if( parse(env_str) ) { user_wrapper.user->admin_env = space; @@ -102,9 +99,9 @@ return false; } -bool Env::EditEnv(const std::wstring & env_str) +bool Env::edit_env(const std::wstring & env_str) { - if( Parse(env_str) ) + if( parse(env_str) ) { user_wrapper.user->env = space; @@ -131,7 +128,7 @@ return false; -void Env::SaveEnv() +void Env::save_env() { const std::wstring & env_str = cur->request->PostVar(L"envvar"); bool status = false; @@ -140,27 +137,29 @@ void Env::SaveEnv() { if( cur->session->puser->is_super_user ) { - status = EditAdminEnv(env_str); + status = edit_admin_env(env_str); if( status ) { //slog << loginfo << T(L"env_admin_changed_successfully") << logend; + redirect_if_needed(); } } } else { - status = EditEnv(env_str); + status = edit_env(env_str); if( status ) { //slog << loginfo << T(L"env_changed_successfully") << logend; + redirect_if_needed(); } } } -void Env::RegisterModels() +void Env::register_models() { cur->request->models.Add(L"users", system->users); cur->request->models.Add(L"env_user", user_wrapper); @@ -192,7 +191,7 @@ void Env::make_post() { if( user_wrapper.user ) { - SaveEnv(); + save_env(); } else { @@ -201,7 +200,7 @@ void Env::make_post() } } - RegisterModels(); + register_models(); } @@ -210,7 +209,7 @@ void Env::make_get() user_wrapper.user = cur->session->puser; user_wrapper.set_connector(model_connector); - RegisterModels(); + register_models(); } @@ -223,6 +222,3 @@ void Env::clear() } // namespace - -} // namespace Winix - diff --git a/winixd/functions/env.h b/winixd/functions/env.h index 49489f1..9304dbc 100644 --- a/winixd/functions/env.h +++ b/winixd/functions/env.h @@ -40,11 +40,7 @@ #include "space/spaceparser.h" -namespace Winix -{ - - -namespace Fun +namespace Winix::Fun { @@ -54,10 +50,10 @@ public: Env(); - bool has_access(); - void make_post(); - void make_get(); - void clear(); + bool has_access() override; + void make_post() override; + void make_get() override; + void clear() override; private: @@ -66,13 +62,13 @@ private: pt::Space space; UserWrapper user_wrapper; - bool EditAdminEnv(const std::wstring & env_str); - bool EditEnv(const std::wstring & env_str); + bool edit_admin_env(const std::wstring & env_str); + bool edit_env(const std::wstring & env_str); - bool Parse(const std::wstring & env_str); - void SaveEnv(); + bool parse(const std::wstring & env_str); + void save_env(); - void RegisterModels(); + void register_models(); }; @@ -80,6 +76,4 @@ private: } // namespace -} // namespace Winix - #endif diff --git a/winixd/functions/functionbase.cpp b/winixd/functions/functionbase.cpp index 9703af2..080479a 100644 --- a/winixd/functions/functionbase.cpp +++ b/winixd/functions/functionbase.cpp @@ -659,6 +659,115 @@ std::wstring FunctionBase::prepare_doc_url(const std::wstring & local_url) } +void FunctionBase::prepare_current_dir(const wchar_t * local_url, pt::WTextStream & url) +{ + prepare_doc_url(nullptr, url); + + for(Item * dir : cur->request->dir_tab) + { + if( !dir->url.empty() ) + url << L"/" << dir->url; + } + + if( local_url ) + { + url << local_url; + } +} + + +void FunctionBase::prepare_current_dir(const wchar_t * local_url, std::wstring & url) +{ + pt::WTextStream stream; + prepare_current_dir(local_url, stream); + stream.to_str(url); +} + + +std::wstring FunctionBase::prepare_current_dir(const wchar_t * local_url) +{ + std::wstring url; + prepare_current_dir(local_url, url); + return url; +} + + +std::wstring FunctionBase::prepare_current_dir(const std::wstring & local_url) +{ + return prepare_current_dir(local_url.c_str()); +} + + +void FunctionBase::prepare_current_item(const wchar_t * local_url, pt::WTextStream & url) +{ + prepare_current_dir(nullptr, url); + + if( cur->request->is_item ) + url << L"/" << cur->request->item.url; + + if( local_url ) + { + url << local_url; + } +} + + +void FunctionBase::prepare_current_item(const wchar_t * local_url, std::wstring & url) +{ + pt::WTextStream stream; + prepare_current_item(local_url, stream); + stream.to_str(url); +} + + +std::wstring FunctionBase::prepare_current_item(const wchar_t * local_url) +{ + std::wstring url; + prepare_current_item(local_url, url); + return url; +} + + +std::wstring FunctionBase::prepare_current_item(const std::wstring & local_url) +{ + return prepare_current_item(local_url.c_str()); +} + + +void FunctionBase::prepare_current_function(const wchar_t * local_url, pt::WTextStream & url) +{ + prepare_current_item(nullptr, url); + url << L"/" << fun.url; + + if( local_url ) + { + url << local_url; + } +} + + +void FunctionBase::prepare_current_function(const wchar_t * local_url, std::wstring & url) +{ + pt::WTextStream stream; + prepare_current_function(local_url, stream); + stream.to_str(url); +} + + +std::wstring FunctionBase::prepare_current_function(const wchar_t * local_url) +{ + std::wstring url; + prepare_current_function(local_url, url); + return url; +} + + +std::wstring FunctionBase::prepare_current_function(const std::wstring & local_url) +{ + return prepare_current_function(local_url.c_str()); +} + + void FunctionBase::redirect_to(const wchar_t * url, bool append_domain) { if( cur->request->is_htmx_request ) @@ -674,16 +783,19 @@ void FunctionBase::redirect_to(const wchar_t * url, bool append_domain) } else { - if( append_domain ) + if( cur->request->container_type == Request::ContainerType::container_raw ) { - prepare_doc_url(url, cur->request->redirect_to); - } - else - { - cur->request->redirect_to = url; - } + if( append_domain ) + { + prepare_doc_url(url, cur->request->redirect_to); + } + else + { + cur->request->redirect_to = url; + } - cur->request->redirect_type = Header::status_303_see_other; + cur->request->redirect_type = Header::status_303_see_other; + } } } @@ -899,8 +1011,93 @@ void FunctionBase::update_content(const wchar_t * frame, const wchar_t * dom_tar void FunctionBase::close_modal_dialogs() { - pt::Space & trigger = cur->request->out_headers.get_add_space(Header::hx_trigger); - trigger.add(L"winix:closedialogs", true); + if( cur->request->is_htmx_request ) + { + pt::Space & trigger = cur->request->out_headers.get_add_space(Header::hx_trigger); + trigger.add(L"winix:closedialogs", true); + } +} + + +void FunctionBase::push_url_to_current_dir(const wchar_t * local_url) +{ + if( cur->request->is_htmx_request ) + { + pt::WTextStream url; + prepare_current_dir(local_url, url); + cur->request->out_headers.add(Header::hx_push_url, url); + } +} + + +void FunctionBase::push_url_to_current_item(const wchar_t * local_url) +{ + if( cur->request->is_htmx_request ) + { + pt::WTextStream url; + prepare_current_item(local_url, url); + cur->request->out_headers.add(Header::hx_push_url, url); + } +} + + +void FunctionBase::push_url_to_current_function(const wchar_t * local_url) +{ + if( cur->request->is_htmx_request ) + { + pt::WTextStream url; + prepare_current_function(local_url, url); + cur->request->out_headers.add(Header::hx_push_url, url); + } +} + + +void FunctionBase::redirect_to_current_dir() +{ + pt::WTextStream url; + prepare_current_dir(nullptr, url); + redirect_to(url, false); +} + + +void FunctionBase::redirect_to_current_item() +{ + pt::WTextStream url; + prepare_current_item(nullptr, url); + redirect_to(url, false); +} + + +void FunctionBase::redirect_to_current_function() +{ + pt::WTextStream url; + prepare_current_function(nullptr, url); + redirect_to(url, false); +} + + +void FunctionBase::redirect_if_needed(bool was_url_changed) +{ + if( cur->request->container_type == Request::ContainerType::container_raw ) + { + /* save_and_close is not used at the moment anywhere in templates */ + if( cur->request->post_in.has_key(L"save_and_close") ) + { + redirect_to_current_item(); + } + else + if( was_url_changed ) + { + if( cur->request->is_htmx_request ) + { + push_url_to_current_function(); + } + else + { + system->RedirectToLastFunction(nullptr, false); + } + } + } } diff --git a/winixd/functions/functionbase.h b/winixd/functions/functionbase.h index 2c5c337..3fdeee9 100644 --- a/winixd/functions/functionbase.h +++ b/winixd/functions/functionbase.h @@ -185,6 +185,21 @@ public: virtual std::wstring prepare_doc_url(const wchar_t * local_url = nullptr); virtual std::wstring prepare_doc_url(const std::wstring & local_url); + virtual void prepare_current_dir(const wchar_t * local_url, pt::WTextStream & url); + virtual void prepare_current_dir(const wchar_t * local_url, std::wstring & url); + virtual std::wstring prepare_current_dir(const wchar_t * local_url = nullptr); + virtual std::wstring prepare_current_dir(const std::wstring & local_url); + + virtual void prepare_current_item(const wchar_t * local_url, pt::WTextStream & url); + virtual void prepare_current_item(const wchar_t * local_url, std::wstring & url); + virtual std::wstring prepare_current_item(const wchar_t * local_url); + virtual std::wstring prepare_current_item(const std::wstring & local_url); + + virtual void prepare_current_function(const wchar_t * local_url, pt::WTextStream & url); + virtual void prepare_current_function(const wchar_t * local_url, std::wstring & url); + virtual std::wstring prepare_current_function(const wchar_t * local_url); + virtual std::wstring prepare_current_function(const std::wstring & local_url); + virtual void redirect_to(const wchar_t * url, bool append_domain = true); virtual void redirect_to(const std::wstring & url, bool append_domain = true); virtual void redirect_to(const pt::WTextStream & url, bool append_domain = true); @@ -211,6 +226,16 @@ public: virtual void close_modal_dialogs(); + virtual void push_url_to_current_dir(const wchar_t * local_url = nullptr); + virtual void push_url_to_current_item(const wchar_t * local_url = nullptr); + virtual void push_url_to_current_function(const wchar_t * local_url = nullptr); + + virtual void redirect_to_current_dir(); + virtual void redirect_to_current_item(); + virtual void redirect_to_current_function(); + + virtual void redirect_if_needed(bool was_url_changed = false); + /* * DEPRECATED diff --git a/winixd/functions/meta.cpp b/winixd/functions/meta.cpp index c02e84b..6d75f61 100644 --- a/winixd/functions/meta.cpp +++ b/winixd/functions/meta.cpp @@ -36,13 +36,10 @@ #include "core/log.h" -namespace Winix +namespace Winix::Fun { -namespace Fun -{ - Meta::Meta() { fun.url = L"meta"; @@ -60,7 +57,7 @@ bool Meta::has_access() -bool Meta::Parse(const std::wstring & meta_str) +bool Meta::parse(const std::wstring & meta_str) { return (conf_parser.parse_space(meta_str, space) == pt::SpaceParser::ok); } @@ -68,9 +65,9 @@ bool Meta::Parse(const std::wstring & meta_str) -bool Meta::EditAdminMeta(Item & item, const std::wstring & meta_str) +bool Meta::edit_admin_meta(Item & item, const std::wstring & meta_str) { - if( Parse(meta_str) ) + if( parse(meta_str) ) { item.propagate_connector(); item.item_content.admin_meta = space; @@ -99,9 +96,9 @@ return false; -bool Meta::EditMeta(Item & item, const std::wstring & meta_str) +bool Meta::edit_meta(Item & item, const std::wstring & meta_str) { - if( Parse(meta_str) ) + if( parse(meta_str) ) { item.propagate_connector(); item.item_content.meta = space; @@ -130,7 +127,7 @@ return false; -void Meta::ChangeAdminMeta() +void Meta::change_admin_meta() { // IMPROVE ME we need to show an error msg if the user is not an admin @@ -138,23 +135,23 @@ void Meta::ChangeAdminMeta() { const std::wstring & meta_str = cur->request->PostVar(L"itemmeta"); - if( EditAdminMeta(*cur->request->last_item, meta_str) ) + if( edit_admin_meta(*cur->request->last_item, meta_str) ) { - system->RedirectToLastItem(); + redirect_if_needed(); } } } -void Meta::ChangeMeta() +void Meta::change_meta() { if( system->HasWriteAccess(*cur->request->last_item) ) { const std::wstring & meta_str = cur->request->PostVar(L"itemmeta"); - if( EditMeta(*cur->request->last_item, meta_str) ) + if( edit_meta(*cur->request->last_item, meta_str) ) { - system->RedirectToLastItem(); + redirect_if_needed(); } } } @@ -164,9 +161,9 @@ void Meta::ChangeMeta() void Meta::make_post() { if( cur->request->IsParam(L"a") ) - ChangeAdminMeta(); + change_admin_meta(); else - ChangeMeta(); + change_meta(); } @@ -174,5 +171,3 @@ void Meta::make_post() } // namespace -} // namespace Winix - diff --git a/winixd/functions/meta.h b/winixd/functions/meta.h index b1edda0..4804c79 100644 --- a/winixd/functions/meta.h +++ b/winixd/functions/meta.h @@ -38,11 +38,8 @@ #include "functionbase.h" #include "space/spaceparser.h" -namespace Winix -{ - -namespace Fun +namespace Winix::Fun { @@ -52,26 +49,25 @@ public: Meta(); - bool has_access(); - void make_post(); + bool has_access() override; + void make_post() override; - bool EditAdminMeta(Item & item, const std::wstring & meta_str); - bool EditMeta(Item & item, const std::wstring & meta_str); private: pt::SpaceParser conf_parser; pt::Space space; - bool Parse(const std::wstring & meta_str); - void ChangeAdminMeta(); - void ChangeMeta(); + bool edit_admin_meta(Item & item, const std::wstring & meta_str); + bool edit_meta(Item & item, const std::wstring & meta_str); + + bool parse(const std::wstring & meta_str); + void change_admin_meta(); + void change_meta(); }; } // namespace -} // namespace Winix - #endif diff --git a/winixd/functions/nicedit.cpp b/winixd/functions/nicedit.cpp index f5f8d4d..3a9affe 100644 --- a/winixd/functions/nicedit.cpp +++ b/winixd/functions/nicedit.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2011-2014, Tomasz Sowa + * Copyright (c) 2011-2024, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,14 +36,10 @@ #include "functions.h" - -namespace Winix +namespace Winix::Fun { -namespace Fun -{ - Nicedit::Nicedit() { fun.url = L"nicedit"; @@ -52,19 +48,36 @@ Nicedit::Nicedit() bool Nicedit::has_access() { - return functions->fun_emacs.has_access(); + FunctionBase * emacs = functions->Find(L"emacs"); + + if( emacs ) + { + return emacs->has_access(); + } + else + { + return false; + } } void Nicedit::make_post() { - functions->fun_emacs.make_post(); -} + FunctionBase * emacs = functions->Find(L"emacs"); + if( emacs ) + { + emacs->make_post(); + } + else + { + log << log2 << "Nicedit: I cannot save your content, there is no emacs function available" << logend; + } +} } // namespace -} // namespace Winix + diff --git a/winixd/functions/nicedit.h b/winixd/functions/nicedit.h index 1a4ff7c..5cef3f6 100644 --- a/winixd/functions/nicedit.h +++ b/winixd/functions/nicedit.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2011-2014, Tomasz Sowa + * Copyright (c) 2011-2024, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,11 +37,8 @@ #include "functionbase.h" -namespace Winix -{ - -namespace Fun +namespace Winix::Fun { @@ -50,14 +47,13 @@ class Nicedit : public FunctionBase public: Nicedit(); - bool has_access(); - void make_post(); + + bool has_access() override; + void make_post() override; }; } // namespace -} // namespace Winix - #endif diff --git a/winixd/functions/tinymce.cpp b/winixd/functions/tinymce.cpp index d6df705..3fc3cbc 100644 --- a/winixd/functions/tinymce.cpp +++ b/winixd/functions/tinymce.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2008-2021, Tomasz Sowa + * Copyright (c) 2008-2024, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,13 +36,10 @@ #include "functions.h" -namespace Winix +namespace Winix::Fun { -namespace Fun -{ - Tinymce::Tinymce() { fun.url = L"tinymce"; @@ -57,7 +54,16 @@ void Tinymce::init() bool Tinymce::has_access() { - return functions->fun_emacs.has_access(); + FunctionBase * emacs = functions->Find(L"emacs"); + + if( emacs ) + { + return emacs->has_access(); + } + else + { + return false; + } } @@ -71,10 +77,18 @@ void Tinymce::make_get() } - void Tinymce::make_post() { - functions->fun_emacs.make_post(); + FunctionBase * emacs = functions->Find(L"emacs"); + + if( emacs ) + { + emacs->make_post(); + } + else + { + log << log2 << "Tinymce: I cannot save your content, there is no emacs function available" << logend; + } } @@ -82,5 +96,3 @@ void Tinymce::make_post() } // namespace -} // namespace Winix - diff --git a/winixd/functions/tinymce.h b/winixd/functions/tinymce.h index e856c0e..5b8961c 100644 --- a/winixd/functions/tinymce.h +++ b/winixd/functions/tinymce.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2010-2014, Tomasz Sowa + * Copyright (c) 2010-2024, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,11 +37,8 @@ #include "functionbase.h" -namespace Winix -{ - -namespace Fun +namespace Winix::Fun { @@ -50,16 +47,14 @@ class Tinymce : public FunctionBase public: Tinymce(); - void init(); - bool has_access(); - void make_get(); - void make_post(); + void init() override; + bool has_access() override; + void make_get() override; + void make_post() override; }; } // namespace -} // namespace Winix - #endif diff --git a/winixd/html/ckeditor.html b/winixd/html/ckeditor.html index 45b7157..7f46faf 100644 --- a/winixd/html/ckeditor.html +++ b/winixd/html/ckeditor.html @@ -88,7 +88,8 @@ coreStyles_underline : //config.allowedContent : true, // allowes all disallowedContent : 'p(western)', // from copying from Office -extraAllowedContent : 'aside caption figure figcaption article footer header section div (*); ul(*); ol(*); h1(*); h2(*); h3(*); h4(*); h5(*); h6(*); p(*); table(*); tr(*); td(*);' +extraAllowedContent : 'aside caption figure figcaption article footer header section div (*); ul(*); ol(*); h1(*); h2(*); h3(*); h4(*); h5(*); h6(*); p(*); table(*); tr(*); td(*);', +versionCheck: false }); @@ -167,7 +168,8 @@ coreStyles_underline : //config.allowedContent : true, // allowes all disallowedContent : 'p(western)', // from copying from Office -extraAllowedContent : 'aside caption figure figcaption article footer header section (*); ul(*); h1(*); h2(*); p(*)' +extraAllowedContent : 'aside caption figure figcaption article footer header section (*); ul(*); h1(*); h2(*); p(*)', +versionCheck: false }); diff --git a/winixd/html/fun_ckeditor.html b/winixd/html/fun_ckeditor.html index 883c485..230a379 100644 --- a/winixd/html/fun_ckeditor.html +++ b/winixd/html/fun_ckeditor.html @@ -1,7 +1,18 @@
-[if request.is_item]

{edit}

[else]

{add}

[end] +[frame "ckeditor"] +

+ [if request.is_item] + {edit} + [else] + {add} + [end] +

+[end] + +[# ckeditor needs javascript to work properly so we assume that the save method] +[# will be made only through ajax (htmx)]
[if one [mount_type_is "cms"] [any [mount_type_is "thread"] [thread_mount_arg_is "subject"]]] @@ -15,22 +26,25 @@
- + [frame "ckeditor"] + + [end]
[end]
- [if mount_type_is "cms"][end] - [if mount_type_is "thread"][end] - [if mount_type_is "ticket"][end] - - [# template fun_ls.html uses the name: itemcontent to refer to this textarea item] + [if mount_type_is "cms"][end] + [if mount_type_is "thread"][end] + [if mount_type_is "ticket"][end] + + [# template fun_ls.html uses the name: itemcontent to refer to this textarea item] -
-
[item.content.print_content]
-
+
+
[item.content.print_content]
+ +
@@ -38,56 +52,51 @@
- [if not user_logged] -
- -
- -
-
+
+ [frame "ckeditor"] -
- -
- -
-
- - [include "antispam.html"] - [end] + [if not user_logged] +
+ +
+ +
+
+ +
+ +
+ +
+
+ + [include "antispam.html"] + [end] + + [if winix_function_param_is "postredirect"] + + [end] + [# IMPROVEME put some kind of a status msg here] -
-
- - - -
- {ckeditor_update_progressbar_img_alt} + + [if request.is_item]{change}[else]{add}[end] + +
+
+
+
-
- -
-
- -
-
- + [end]
- [if winix_function_param_is "postredirect"] - - [end] [include "ckeditor.html"] [ckeditor_old_browsers_support] diff --git a/winixd/html/fun_emacs.html b/winixd/html/fun_emacs.html index 9bd6ca7..fae9860 100644 --- a/winixd/html/fun_emacs.html +++ b/winixd/html/fun_emacs.html @@ -1,10 +1,22 @@
-[if request.is_item]

{edit}

[else]

{add}

[end] + +[frame "emacs"] +

+ [if request.is_item] + {edit} + [else] + {add} + [end] +

+[end] - - +
@@ -16,41 +28,59 @@
- + [frame "emacs"] + + [end]
[include "fun_emacs_post.html"] - [if not user_logged] -
- -
- -
-
+
+ [frame "emacs"] -
- -
- + [if not user_logged] +
+ +
+ +
+
+ +
+ +
+ +
+
+ + [include "antispam.html"] + [end] + + [if winix_function_param_is "postredirect"] + + [end] + + [# IMPROVEME put some kind of a status msg here] + +
+
-
- [include "antispam.html"] - [end] - - [if winix_function_param_is "postredirect"] -
- + [end]
- [end] -
- -
- -
diff --git a/winixd/html/fun_emacs_post.html b/winixd/html/fun_emacs_post.html index 6711a61..d90e6a7 100644 --- a/winixd/html/fun_emacs_post.html +++ b/winixd/html/fun_emacs_post.html @@ -15,31 +15,10 @@ [# CodeMirror doesn't work correctly inside fieldset tag -- horizontal scroll is broken] -
+ [if not [winix_function_param_is "tabs"]] - +
[# uk-child-width-1-1 or uk-child-width-1-2 class will be added by js] -
-
- -
- - -[if false] - - -
    - -
  • -
  • -
  • -
    + -
  • - -
-[end] + +
+ + [else] + + + +
    + +
  • + +
  • + +
  • +
    +
    +
  • + +
+ [end] @@ -64,22 +66,30 @@
- - - - -[if false] - [if user_can_use_bbcode]{form_emacs_content_type_bbcode}[end] -[end] - + + + [if false] + [if user_can_use_bbcode]{form_emacs_content_type_bbcode}[end] + [end]
+[if not [winix_function_param_is "tabs"]] +
+ + +
+[end] + + diff --git a/winixd/html/fun_env.html b/winixd/html/fun_env.html index ae83887..dfc1adf 100644 --- a/winixd/html/fun_env.html +++ b/winixd/html/fun_env.html @@ -62,13 +62,30 @@ -
- -
+
+ [frame "env"] - [if winix_function_param_is "postredirect"] - - [end] + [if winix_function_param_is "postredirect"] + + [end] + +
+ +
+ + [end] +
diff --git a/winixd/html/fun_meta.html b/winixd/html/fun_meta.html index 5d6c80a..238a85a 100644 --- a/winixd/html/fun_meta.html +++ b/winixd/html/fun_meta.html @@ -9,7 +9,11 @@ -
+
-
- -
+
+ [frame "meta"] + + [if winix_function_param_is "postredirect"] + + [end] + +
+ +
+ + [end] +
+ - [if winix_function_param_is "postredirect"] - - [end] diff --git a/winixd/html/fun_nicedit.html b/winixd/html/fun_nicedit.html index ed237b2..38cf126 100644 --- a/winixd/html/fun_nicedit.html +++ b/winixd/html/fun_nicedit.html @@ -1,9 +1,19 @@
-[if request.is_item]

{edit}

[else]

{add}

[end] +[frame "nicedit"] +

+ [if request.is_item] + {edit} + [else] + {add} + [end] +

+[end] -
+[# nicedit needs javascript to work properly so we assume that the save method] +[# will be made only through ajax (htmx)] + [if one [mount_type_is "cms"] [any [mount_type_is "thread"] [thread_mount_arg_is "subject"]]]
@@ -16,7 +26,9 @@
- + [frame "nicedit"] + + [end]
[end] @@ -27,7 +39,7 @@ [if mount_type_is "ticket"][end]
- +
@@ -36,34 +48,52 @@
+
+ [frame "nicedit"] - [if not user_logged] -
- -
- -
-
+ [if not user_logged] +
+ +
+ +
+
-
- -
- -
-
- - [include "antispam.html"] - [end] +
+ +
+ +
+
+ + [include "antispam.html"] + [end] - [if winix_function_param_is "postredirect"] - - [end] + [if winix_function_param_is "postredirect"] + + [end] -
- + [# IMPROVEME put some kind of a status msg here] + +
+ +
+ + [end]
diff --git a/winixd/html/fun_tinymce.html b/winixd/html/fun_tinymce.html index 30f1ba1..2533956 100644 --- a/winixd/html/fun_tinymce.html +++ b/winixd/html/fun_tinymce.html @@ -1,7 +1,18 @@
-[if request.is_item]

{edit}

[else]

{add}

[end] +[frame "tinymce"] +

+ [if request.is_item] + {edit} + [else] + {add} + [end] +

+[end] + +[# tinymce needs javascript to work properly so we assume that the save method] +[# will be made only through ajax (htmx)]
[if one [mount_type_is "cms"] [any [mount_type_is "thread"] [thread_mount_arg_is "subject"]]] @@ -15,7 +26,9 @@
- + [frame "tinymce"] + + [end]
[end] @@ -26,7 +39,8 @@ [if mount_type_is "ticket"][end]
-
[item.content.print_content]
+
[item.content.print_content]
+
@@ -34,54 +48,50 @@
- [if not user_logged] -
- -
- -
-
+
+ [frame "tinymce"] -
- -
- -
-
+ [if not user_logged] +
+ +
+ +
+
+ +
+ +
+ +
+
+ + [include "antispam.html"] + [end] + + [if winix_function_param_is "postredirect"] + + [end] - [include "antispam.html"] - [end] - [if winix_function_param_is "postredirect"] - - [end] - -
-
+ [# IMPROVEME put some kind of a status msg here] - - -
- {tinymce_update_progressbar_img_alt} + + [if request.is_item]{change}[else]{add}[end] + +
+
+
+
-
- -
-
- -
-
- + [end]
diff --git a/winixd/html/index_head_adder.html b/winixd/html/index_head_adder.html index ba22d7e..bd307ae 100644 --- a/winixd/html/index_head_adder.html +++ b/winixd/html/index_head_adder.html @@ -55,72 +55,95 @@ [end] +[if or [winix_function_is "emacs"] [winix_function_is "ckeditor"] [winix_function_is "tinymce"] [winix_function_is "nicedit"] [winix_function_is "env"] [winix_function_is "meta"]] + -[if or [winix_function_is "emacs"] [winix_function_is "env"] [winix_function_is "meta"]] - - - - - - - - - - [if false] - - [end] - - - - -[if false] - - + [end] - - - +[if or [winix_function_is "emacs"] [winix_function_is "env"] [winix_function_is "meta"]] + + + + + + + + + + [if false] + + [end] + + + + + [if false] + + + [end] + + + + + [# markdown to html converter ] [# https://github.com/showdownjs/showdown ] - + - + .CodeMirror \{ + border: 1px solid #dedede; + \} + [end] @@ -262,8 +451,25 @@ cm.save() [def winix_has_jquery true] [end] - - + + + [end] @@ -277,13 +483,46 @@ cm.save() [def winix_has_jquery true] [end] - - + + [end] [if winix_function_is "nicedit"] + [# the path is set in the fun_nicedit.html too for downloading a gif file] + + + [end] diff --git a/winixd/locale/en b/winixd/locale/en index 1347b42..53b3bdb 100644 --- a/winixd/locale/en +++ b/winixd/locale/en @@ -108,8 +108,10 @@ short_url = Short url title = Title nick = Nick change = Change +change_and_close = Change and close edit = Edit add = Add +add_and_close = Add and close move = Move copy = Copy user = User @@ -127,15 +129,6 @@ rebus_need_to_solve = Solve the rebus please! edit_ticket_header = Edit ticket create_ticket_header = Create a new ticket - - - - -ckeditor_update_button = Update -ckeditor_update_progressbar_img_alt = Progressbar - - - form_ticket_type = Ticket type form_ticket_status = Status form_ticket_priority = Priority @@ -173,6 +166,9 @@ form_emacs_content_cms = Content form_emacs_content_thread = Post form_emacs_content_ticket = Info +form_emacs_content_edit = Content +form_emacs_content_preview = Preview + form_emacs_content_type = Message type form_emacs_content_type_text = text @@ -182,6 +178,10 @@ form_emacs_content_type_bbcode = bbcode form_emacs_content_type_other = other \(no formatting\) form_emacs_content_type_markdown = markdown +form_emacs_view_type = View +form_emacs_view_type_one_panel = One panel +form_emacs_view_type_two_panels = Two panels + last_header = Last logged users last_tab_login = Login @@ -355,8 +355,6 @@ upload_button_download = Download upload_button_edit = Edit upload_error = Error: upload_processing = Processing... -upload_content_edit = Content -upload_content_preview = Preview who_header = Sessions @@ -508,10 +506,6 @@ stat_template_from_mount_point = from the mount point subject_header = Edit subject - -tinymce_update_button = Update -tinymce_update_progressbar_img_alt = Progressbar - uname_header = System uname_components = Components uname_available_plugins = Plugins diff --git a/winixd/locale/pl b/winixd/locale/pl index ed98702..9753689 100644 --- a/winixd/locale/pl +++ b/winixd/locale/pl @@ -112,8 +112,10 @@ short_url = Krótki url title = Tytuł nick = Nick change = Zmień +change_and_close = Zmień i zamknij edit = Edytuj add = Dodaj +add_and_close = Dodaj i zamknij move = Przenieś copy = Kopiuj user = Użytkownik @@ -133,15 +135,6 @@ rebus_need_to_solve = Proszę rozwiązać rebus! edit_ticket_header = Edytuj zgłoszenie create_ticket_header = Nowe zgłoszenie - - - - -ckeditor_update_button = Aktualizuj -ckeditor_update_progressbar_img_alt = Progressbar - - - form_ticket_type = Rodzaj zgłoszenia form_ticket_status = Status form_ticket_priority = Priorytet @@ -178,6 +171,9 @@ form_emacs_content_cms = Zawartość form_emacs_content_thread = Post form_emacs_content_ticket = Opis +form_emacs_content_edit = Zawartość +form_emacs_content_preview = Podgląd + form_emacs_content_type = Rodzaj wiadomości form_emacs_content_type_text = text @@ -187,6 +183,9 @@ form_emacs_content_type_bbcode = bbcode form_emacs_content_type_other = inny \(brak formatowania\) form_emacs_content_type_markdown = markdown +form_emacs_view_type = Widok +form_emacs_view_type_one_panel = Jeden panel +form_emacs_view_type_two_panels = Dwa panele last_header = Ostatnio logowani użytkownicy last_tab_login = Login @@ -375,8 +374,6 @@ upload_button_download = Ściągnij upload_button_edit = Edytuj upload_error = Błąd: upload_processing = Przygotowywanie... -upload_content_edit = Zawartość -upload_content_preview = Podgląd who_header = Lista sesji @@ -526,10 +523,6 @@ stat_template_from_mount_point = z punktu montowania subject_header = Zmień tytuł - -tinymce_update_button = Aktualizuj -tinymce_update_progressbar_img_alt = Progressbar - uname_header = System uname_components = Komponenty uname_available_plugins = Pluginy diff --git a/winixd/models/itemcontent.h b/winixd/models/itemcontent.h index 5d6cf97..953f128 100644 --- a/winixd/models/itemcontent.h +++ b/winixd/models/itemcontent.h @@ -233,13 +233,11 @@ public: /* * parsed object content - * IMPROVEME not used in winix yet */ std::wstring content_parsed; /* * parsed content type - * IMPROVEME not used in winix yet */ ContentType content_parsed_type; diff --git a/winixd/templates/misc.cpp b/winixd/templates/misc.cpp index 9f1ed83..f27f4b9 100644 --- a/winixd/templates/misc.cpp +++ b/winixd/templates/misc.cpp @@ -51,34 +51,34 @@ extern Ezc::Vars ezc_vars; void HtmlEscapeFormTxt(HtmlTextStream & out, const std::wstring & in) { std::wstring::const_iterator i; -int was_enter = 0; // how many enteres there were before +int was_nl = 0; // how many new line characters there were before if( in.empty() ) return; - out << R("

"); // !! pozbyc sie wstawianie tego html tutaj (wrzucic w jakis sposob do szablonow) + out << R("

"); // skipping first new line characters for(i = in.begin() ; i != in.end() && (*i==13 || *i==10) ; ++i); for( ; i != in.end() ; ++i ) { - if( *i == 13 ) // skipping stupid characters (\r\n\ in dos mode) + if( *i == 13 ) continue; if( *i == 10 ) { - ++was_enter; + ++was_nl; } else { - if( was_enter == 1 ) + if( was_nl == 1 ) out << R("
\n"); else - if( was_enter > 1 ) + if( was_nl > 1 ) out << R("

\n

"); - was_enter = 0; + was_nl = 0; } out << *i;