- added to Request: is_htmx_request (bool) - true if the request is made by htmx library (ajax)

- commented out using mount_page_arg_is "subject" and "info" from fun_cat.html and fun_run.html - they will be removed soon
- some improvements in fun_reply.html, fun_showthreads.html and fun_thread.html (scrolling)
This commit is contained in:
Tomasz Sowa 2021-05-31 10:58:34 +02:00
parent e6fae4598c
commit 22de3322ae
18 changed files with 112 additions and 34 deletions

View File

@ -940,6 +940,7 @@ void App::ReadRequest()
CheckIE();
CheckKonqueror();
CheckHtmx();
if( cur.request->using_ssl )
log << log3 << "App: connection secure through SSL" << logend;
@ -1125,6 +1126,15 @@ void App::CheckSSL()
}
void App::CheckHtmx()
{
// fastcgi will change the header to hx_request
cur.request->is_htmx_request = (cur.request->headers_in.has_key(L"HX-Request") || cur.request->headers_in.has_key(L"hx_request"));
}
void App::SetSubdomain()
{
CreateSubdomain(config.base_url.c_str(), cur.request->env_http_host.c_str(), cur.request->subdomain);
@ -1801,7 +1811,7 @@ size_t output_size = 0;
source = &json_out_stream.Str(); // json_out_stream was prepared by CreateJSONAnswer()
}
else
if( cur.request->headers_in.has_key(L"HX-Request") || cur.request->headers_in.has_key(L"hx_request") ) // fastcgi will change the header to hx_request
if( cur.request->is_htmx_request )
{
source = CreateFrameAnswer();

View File

@ -230,6 +230,7 @@ private:
void CheckKonqueror();
void CheckRequestMethod();
void CheckSSL();
void CheckHtmx();
void SetSubdomain();

View File

@ -134,6 +134,7 @@ void Request::Clear()
send_as_attachment = false;
using_ssl = false;
is_htmx_request = false;
start_time = 0;
start_date.Clear();

View File

@ -170,6 +170,8 @@ struct Request
// true if we are using an encrypted connection (SSL)
bool using_ssl;
// true if the request is being made by ajax by htmx library
bool is_htmx_request;
/*
request input variables representing the winix filesystem

View File

@ -539,11 +539,18 @@ bool Functions::CheckAntispamCounter()
// !!uwaga zwracana wartosc zmieniona (true/false)
// !! IMPROVE ME in emacs.cpp there is a similar function
bool Functions::CheckAbuse()
bool Functions::CheckAbuse(SLog * slog)
{
if( !system->rebus.CheckRebus() )
{
cur->request->status = WINIX_ERR_INCORRECT_REBUS;
if( slog )
{
// put to locale
(*slog) << logerror << T(L"rebus_need_to_solve") << logend;
}
return true;
}
@ -566,7 +573,6 @@ return false;
// returning true if the 'url' has to be changed
void Functions::ReadItemUrlSubject(Item & item, Item::Type item_type)
{

View File

@ -176,7 +176,7 @@ public:
void CheckGetPostTimes(time_t difference = 10);
bool CheckAbuse();
bool CheckAbuse(SLog * slog = nullptr);
// !! dac lepsze nazwy
void ReadItemFilterHtml(Item & item);

View File

@ -1,8 +1,10 @@
[if item_content_type_is "other"][item_print_content][else]
[if false]
[if mount_page_arg_is "subject"][if mount_page_arg_is "info"]<h1 class="withinfo">[else]<h1>[end][item_subject]</h1>[end]
[if mount_page_arg_is "info"][include "item_info.html"][end]
[end]
[if one item_filetype_is_image]
<a href="[item_link]"><img class="catimage" [if not item_has_thumb]height="100"[end] src="[item_link]/download[if item_has_thumb]/thumb[end]" alt="[item_subject]"></a>

View File

@ -1,9 +1,11 @@
<div class="winix">
<div class="winix winix-thread-reply">
<h1>{thread_header_reply}</h1>
<form class="uk-form-stacked" method="post" action="[doc_base_url][dir][item_url]/reply" [if winix_has_htmx]hx-post="[doc_base_url][dir][item_url]/reply"[end]>
[# it would be better to have to 'item' objects: one for item_url and the other for item_content]
[# this will be added when ezc will have its own objects templates]
<form class="uk-form-stacked" method="post" action="[doc_base_url][dir][item_url]/reply" [if winix_has_htmx]hx-post="[doc_base_url][dir][item_url]/reply/scrolldown"[end]>
[if thread_mount_arg_is "subject"]
<div class="uk-margin">
@ -26,7 +28,7 @@
[if mount_type_is "thread"]<label for="winix_content_id">{form_emacs_content_thread}</label>[end]
<div class="uk-form-controls">
<textarea class="uk-textarea" id="winix_content_id" rows="10" cols="60" name="itemcontent"></textarea>
<textarea class="uk-textarea" id="winix_content_id" rows="10" cols="60" name="itemcontent">[item_content]</textarea>
</div>
</div>
@ -74,3 +76,14 @@
</form>
</div>
<div class="winix-fake-div"></div>
[if any winix_has_htmx winix_is_htmx_request winix_has_uikit]
<script>
[# how does it work?]
UIkit.scroll(".winix-fake-div").scrollTo(".winix-thread-reply");
</script>
[end]

View File

@ -1,7 +1,8 @@
[if item_content_type_is "other"][item_run][else]
<div>
[if false]
[if mount_page_arg_is "subject"]
<h1>[item_subject]</h1>
[end]
@ -9,6 +10,7 @@
[if mount_page_arg_is "info"]
[include "item_info.html"]
[end]
[end]
[item_run]

View File

@ -1,4 +1,4 @@
<div class="winix winix-threads-list">
<div class="winix">
[if mount_page_arg_is "subject"]<h1[if mount_page_arg_is "info"] class="withinfo"[end]>[dir_last_subject]</h1>[end]
[if mount_page_arg_is "info"][include "dir_last_info.html"][end]
@ -16,7 +16,7 @@
<tr><th>{thread_tab_title}</th><th>{thread_tab_author}</th><th>{thread_tab_replies}</th><th>{thread_tab_last_post}</th></tr>
[for thread_sort_tab]
<tr>
<td><a class="winix-thread-link" href="[doc_base_url][dir][thread_sort_tab_url]" [if winix_has_htmx]hx-get="[doc_base_url][dir][thread_sort_tab_url]" hx-push-url="true"[end]>[thread_sort_tab_subject]</a></td> [# dodac sprawdzanie subject empty]
<td><a class="winix-thread-link" href="[doc_base_url][dir][thread_sort_tab_url]" [if winix_has_htmx]hx-get="[doc_base_url][dir][thread_sort_tab_url]/-/scrolltop" hx-push-url="true"[end]>[thread_sort_tab_subject]</a></td> [# dodac sprawdzanie subject empty]
<td>[thread_sort_tab_user]</td><td class="smallfont">[thread_sort_tab_replies]</td>
<td>[thread_sort_tab_last_item_date_modification_nice] ([thread_sort_tab_last_item_user])</td>
</tr>
@ -27,11 +27,3 @@
</div>
[if false]
[if any winix_has_htmx winix_is_htmx_request winix_has_uikit]
<script>
[# fixme: not working in this way]
UIkit.scroll(".winix-thread-link").scrollTo(".winix-threads-list");
</script>
[end]
[end]

View File

@ -1,4 +1,4 @@
<div class="winix">
<div class="winix winix-thread">
[if mount_page_arg_is "subject"]<h1[if mount_page_arg_is "info"] class="winix_withinfo"[end]>[item_subject]</h1>[end]
[if false]
@ -55,4 +55,24 @@
</div>
[if winix_function_param_is "scrolltop"]
<div class="winix-fake-div"></div>
[if winix_has_uikit]
<script>
[# how does it work?]
UIkit.scroll(".winix-fake-div").scrollTo(".winix-thread");
</script>
[end]
[end]
[if winix_function_param_is "scrolldown"]
<div class="winix-fake-div"></div>
[if winix_has_uikit]
<script>
[# how does it work?]
UIkit.scroll(".winix-fake-div").scrollTo(".winix-fake-div");
</script>
[end]
[end]

View File

@ -108,6 +108,7 @@ add_page = Add page
edit_page = Edit page
rebus_how_is_it = Rebus: How is it
rebus_need_to_solve = Solve the rebus please!
edit_ticket_header = Edit ticket
create_ticket_header = Create a new ticket
@ -542,7 +543,7 @@ notify_footer4 = in your user control panel.
# IMPROVE ME now they are not used, and should be moved to slog
winix_err_3 = Incorrect directory.
winix_err_18 = You are suspected to be a spammer, you cannot send anything without logging first.
winix_err_19 = Solve the rebus please!
winix_err_25 = Passwords are different!
winix_err_26 = A password should consist of at least five characters.

View File

@ -113,6 +113,8 @@ add_page = Dodaj stronę
edit_page = Edytuj stronę
rebus_how_is_it = Rebus: Ile to jest
rebus_need_to_solve = Proszę rozwiązać rebus!
edit_ticket_header = Edytuj zgłoszenie
create_ticket_header = Nowe zgłoszenie
@ -558,7 +560,7 @@ notify_footer4 = w swoim panelu użytkownika.
# those errors are taken automatically by [winix_err_msg_from_locales]
winix_err_3 = Nieprawidłowy katalog.
winix_err_18 = Jesteś podejrzany jako spamer, nie możesz nic wysłać do czasu zalogowania się!
winix_err_19 = Proszę rozwiązać rebus!
winix_err_25 = Podane hasła różnią się od siebie!
winix_err_26 = Hasło powinno składać się z co najmniej pięciu znaków.

View File

@ -95,6 +95,10 @@ void CreateThread::SendNotify(const Item & item)
void CreateThread::MakePost()
{
// is it a correct bahavior to set spam_score in session?
// after the first mistake the person will not be allowed to post anything
cur->session->spam_score = 0;
cur->request->item.Clear();
functions->ReadItem(cur->request->item, Item::file);
functions->SetUser(cur->request->item);

View File

@ -112,6 +112,10 @@ void Reply::MakePost()
// !! jak bedzie dostepne assert
// ASSERT(files_dir)
// is it a correct bahavior to set spam_score in session?
// after the first mistake the person will not be allowed to post anything
cur->session->spam_score = 0;
thread = Thread::get_thread(model_connector, cur->request->item.id);
if( !thread.found() )
@ -143,8 +147,18 @@ void Reply::MakePost()
cur->request->last_item = &cur->request->item;
cur->request->item.item_content.guest_name.clear();
if( functions->CheckAbuse() )
if( functions->CheckAbuse(&slog) )
{
// temporary: to show values in the html form
// this will be changed when a new ezc objects will be implemented
// there'll be two objects: one registered as [item..] and the other registered as [answer..]
// (one for url and the other for content)
cur->request->item.item_content.content_raw = answer.item_content.content_raw;
cur->request->item.item_content.content_raw_type = answer.item_content.content_raw_type;
cur->request->item.item_content.guest_name = answer.item_content.guest_name;
return;
}
plugin->Call(WINIX_PL_THREAD_PREPARE_TO_REPLY_IN_THREAD, &answer);
@ -157,7 +171,17 @@ void Reply::MakePost()
if( cur->request->status == WINIX_ERR_OK )
{
log << log2 << "Reply: added an answer in a thread" << logend;
thread_info->MakeRedirectIfPossible(cur->request->item);
const wchar_t * postfix = nullptr;
if( cur->request->IsParam(L"scrollup") )
postfix = L"/-/scrollup";
if( cur->request->IsParam(L"scrolldown") )
postfix = L"/-/scrolldown";
thread_info->MakeRedirectIfPossible(cur->request->item, postfix);
SendNotify(cur->request->item);
}
else
@ -172,12 +196,14 @@ void Reply::MakeGet()
{
/*
* workaround:
* html form showed the nick name from item
* html form showed the nick name from item (and content)
* this will be removed when new ezc object templates will be implemented
* we can provide two item templates: one for [item_url] and the rest for the html form
* [item_url] is used in <form...>
*/
cur->request->item.item_content.guest_name.clear();
cur->request->item.item_content.content_raw.clear();
}

View File

@ -194,7 +194,7 @@ void ThreadInfo::Repair()
void ThreadInfo::MakeRedirectIfPossible(const Item & item)
void ThreadInfo::MakeRedirectIfPossible(const Item & item, const wchar_t * postfix)
{
PluginRes res = plugin->Call(WINIX_PL_THREAD_CAN_MAKE_REDIRECT);
@ -204,7 +204,7 @@ void ThreadInfo::MakeRedirectIfPossible(const Item & item)
return;
}
system->RedirectTo(item);
system->RedirectTo(item, postfix);
}

View File

@ -99,7 +99,7 @@ public:
// repairing the database
void Repair();
void MakeRedirectIfPossible(const Item & item);
void MakeRedirectIfPossible(const Item & item, const wchar_t * postfix = nullptr);
private:

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -377,11 +377,7 @@ void winix_locale_tab_name(Info & i)
void winix_is_htmx_request(Info & i)
{
if( cur->request->headers_in.has_key(L"HX-Request") || cur->request->headers_in.has_key(L"hx_request") )
{
// fastcgi will change the header to hx_request
i.res = true;
}
i.res = cur->request->is_htmx_request;
}