Version 22.118.13:May 31, 2023 Code refactoring in forums.

This commit is contained in:
acanas 2023-05-31 09:29:23 +02:00
parent bf031de6db
commit 31642fe486
10 changed files with 45 additions and 36 deletions

View File

@ -629,10 +629,11 @@ TODO: Emilce Barrera Mesa: Podr
TODO: Emilce Barrera Mesa: Mis estudiantes presentan muchas dificultades a la hora de poner la foto porque la plataforma es muy exigente respecto al fondo de la imagen.
*/
#define Log_PLATFORM_VERSION "SWAD 22.118.11 (2023-05-30)"
#define Log_PLATFORM_VERSION "SWAD 22.118.13 (2023-05-31)"
#define CSS_FILE "swad22.118.5.css"
#define JS_FILE "swad22.49.js"
/*
Version 22.118.13:May 31, 2023 Code refactoring in forums. (337417 lines)
Version 22.118.12:May 30, 2023 Code refactoring in forums and messages. (337408 lines)
Version 22.118.11:May 30, 2023 Code refactoring in strings. (337391 lines)
Version 22.118.10:May 30, 2023 Draw logo in head even if it does not exist. (337359 lines)

View File

@ -119,10 +119,11 @@ typedef enum
Cns_FULL_NAME,
} Cns_ShrtOrFullName_t;
#define Cns_NUM_DISABLED_ENABLED 2
typedef enum
{
Cns_DISABLED,
Cns_ENABLED,
} Cns_Enabled_t;
} Cns_DisabledOrEnabled_t;
#endif

View File

@ -906,14 +906,30 @@ static void For_ShowAForumPost (struct For_Forums *Forums,
extern const char *Txt_FORUM_Post_banned;
extern const char *Txt_FORUM_Post_X_banned;
extern const char *Txt_This_post_has_been_banned_probably_for_not_satisfy_the_rules_of_the_forums;
static const char *Icon[Cns_NUM_DISABLED_ENABLED] =
{
[Cns_DISABLED] = "eye-slash.svg",
[Cns_ENABLED ] = "eye.svg",
};
static Ico_Color_t Color[Cns_NUM_DISABLED_ENABLED] =
{
[Cns_DISABLED] = Ico_RED,
[Cns_ENABLED ] = Ico_GREEN,
};
static const char **TxtAllowedBanned[Cns_NUM_DISABLED_ENABLED] =
{
[Cns_DISABLED] = &Txt_FORUM_Post_X_banned,
[Cns_ENABLED ] = &Txt_FORUM_Post_X_allowed,
};
struct Usr_Data UsrDat;
time_t CreatTimeUTC; // Creation time of a post
char OriginalContent[Cns_MAX_BYTES_LONG_TEXT + 1];
char Subject[Cns_MAX_BYTES_SUBJECT + 1];
char Content[Cns_MAX_BYTES_LONG_TEXT + 1];
struct Med_Media Media;
Cns_Enabled_t Enabled;
Cns_DisabledOrEnabled_t DisabledOrEnabled;
char *Title;
Act_Action_t NextAction;
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
@ -922,13 +938,13 @@ static void For_ShowAForumPost (struct For_Forums *Forums,
Med_MediaConstructor (&Media);
/***** Check if post is enabled *****/
Enabled = For_DB_GetIfPstIsEnabled (Forums->PstCod);
DisabledOrEnabled = For_DB_GetIfPstIsDisabledOrEnabled (Forums->PstCod);
/***** Get data of post *****/
For_GetPstData (Forums->PstCod,&UsrDat.UsrCod,&CreatTimeUTC,
Subject,OriginalContent,&Media);
if (Enabled == Cns_ENABLED)
if (DisabledOrEnabled == Cns_ENABLED)
/* Return this subject as last subject */
Str_Copy (LastSubject,Subject,Cns_MAX_BYTES_SUBJECT);
@ -964,7 +980,7 @@ static void For_ShowAForumPost (struct For_Forums *Forums,
NewPst ? "MSG_BG_NEW" :
"MSG_BG",
The_GetSuffix ());
switch (Enabled)
switch (DisabledOrEnabled)
{
case Cns_DISABLED:
HTM_TxtF ("[%s]",Txt_FORUM_Post_banned);
@ -986,29 +1002,18 @@ static void For_ShowAForumPost (struct For_Forums *Forums,
if (ICanModerateForum)
{
Frm_BeginFormAnchor (Enabled == Cns_ENABLED ? For_ActionsDisPstFor[Forums->Forum.Type] :
For_ActionsEnbPstFor[Forums->Forum.Type],
For_FORUM_POSTS_SECTION_ID);
NextAction = DisabledOrEnabled == Cns_ENABLED ? For_ActionsDisPstFor[Forums->Forum.Type] :
For_ActionsEnbPstFor[Forums->Forum.Type];
Frm_BeginFormAnchor (NextAction,For_FORUM_POSTS_SECTION_ID);
For_PutParsForum (Forums);
Ico_PutIconLink (Enabled == Cns_ENABLED ? "eye.svg" :
"eye-slash.svg",
Enabled == Cns_ENABLED ? Ico_GREEN :
Ico_RED,
Enabled == Cns_ENABLED ? For_ActionsDisPstFor[Forums->Forum.Type] :
For_ActionsEnbPstFor[Forums->Forum.Type]);
Ico_PutIconLink (Icon[DisabledOrEnabled],Color[DisabledOrEnabled],NextAction);
Frm_EndForm ();
}
else
{
if (asprintf (&Title,Enabled == Cns_ENABLED ? Txt_FORUM_Post_X_allowed :
Txt_FORUM_Post_X_banned,
PstNum) < 0)
if (asprintf (&Title,*TxtAllowedBanned[DisabledOrEnabled],PstNum) < 0)
Err_NotEnoughMemoryExit ();
Ico_PutIcon (Enabled == Cns_ENABLED ? "eye.svg" :
"eye-slash.svg",
Enabled == Cns_ENABLED ? Ico_GREEN :
Ico_RED,
Title,
Ico_PutIcon (Icon[DisabledOrEnabled],Color[DisabledOrEnabled],Title,
"ICO_HIDDEN ICO16x16");
free (Title);
}
@ -1030,15 +1035,15 @@ static void For_ShowAForumPost (struct For_Forums *Forums,
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CURRENT_CRS);
Usr_WriteAuthor (&UsrDat,Enabled);
if (Enabled == Cns_ENABLED)
Usr_WriteAuthor (&UsrDat,DisabledOrEnabled);
if (DisabledOrEnabled == Cns_ENABLED)
/* Write number of posts from this user */
For_WriteNumberOfPosts (Forums,UsrDat.UsrCod);
HTM_TD_End ();
/***** Write post content *****/
HTM_TD_Begin ("class=\"LT MSG_TXT_%s\"",The_GetSuffix ());
switch (Enabled)
switch (DisabledOrEnabled)
{
case Cns_DISABLED:
HTM_Txt (Txt_This_post_has_been_banned_probably_for_not_satisfy_the_rules_of_the_forums);
@ -2402,7 +2407,7 @@ void For_GetThreadData (struct For_Thread *Thr)
for (Order = (Dat_StartEndTime_t) 0;
Order <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
Order++)
Thr->Enabled[Order] = For_DB_GetIfPstIsEnabled (Thr->PstCod[Order]);
Thr->Enabled[Order] = For_DB_GetIfPstIsDisabledOrEnabled (Thr->PstCod[Order]);
/***** Get number of posts in this thread *****/
Thr->NumPosts = For_DB_GetNumPstsInThr (Thr->ThrCod);

View File

@ -77,7 +77,7 @@ struct For_Thread
long PstCod[Dat_NUM_START_END_TIME];
long UsrCod[Dat_NUM_START_END_TIME];
time_t WriteTime[Dat_NUM_START_END_TIME];
Cns_Enabled_t Enabled[Dat_NUM_START_END_TIME];
Cns_DisabledOrEnabled_t Enabled[Dat_NUM_START_END_TIME];
char Subject[Cns_MAX_BYTES_SUBJECT + 1];
unsigned NumPosts;
unsigned NumUnreadPosts; // Number of my unread posts in thread

View File

@ -969,7 +969,7 @@ void For_DB_InsertPstIntoDisabled (long PstCod)
/*********************** Get if a forum post is disabled *********************/
/*****************************************************************************/
Cns_Enabled_t For_DB_GetIfPstIsEnabled (long PstCod)
Cns_DisabledOrEnabled_t For_DB_GetIfPstIsDisabledOrEnabled (long PstCod)
{
/***** Trivial check: post code should be > 0 *****/
if (PstCod <= 0)

View File

@ -98,7 +98,7 @@ void For_DB_RemoveExpiredClipboards (void);
//--------------------------- Disabled posts ----------------------------------
void For_DB_InsertPstIntoDisabled (long PstCod);
Cns_Enabled_t For_DB_GetIfPstIsEnabled (long PstCod);
Cns_DisabledOrEnabled_t For_DB_GetIfPstIsDisabledOrEnabled (long PstCod);
void For_DB_RemovePstFromDisabled (long PstCod);
void For_DB_RemoveDisabledPstsInThread (long ThrCod);

View File

@ -158,7 +158,7 @@ void Pag_WriteLinksToPagesCentered (Pag_WhatPaginate_t WhatPaginate,
void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
struct Pag_Pagination *Pagination,
const void *Context,long Cod,
Cns_Enabled_t FirstMsgEnabled,
Cns_DisabledOrEnabled_t FirstMsgDisabledOrEnabled,
const char *Subject,const char *ClassTxt,
bool LinkToPagCurrent)
{
@ -281,7 +281,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
}
else
HTM_SPAN_Begin ("class=\"%s_%s\"",ClassTxt,The_GetSuffix ());
switch (FirstMsgEnabled)
switch (FirstMsgDisabledOrEnabled)
{
case Cns_DISABLED:
HTM_TxtF ("[%s]",Txt_FORUM_Post_banned);

View File

@ -84,7 +84,7 @@ void Pag_WriteLinksToPagesCentered (Pag_WhatPaginate_t WhatPaginate,
void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
struct Pag_Pagination *Pagination,
const void *Context,long Cod,
Cns_Enabled_t FirstMsgEnabled,
Cns_DisabledOrEnabled_t FirstMsgEnabled,
const char *Subject,const char *ClassTxt,
bool LinkToPagCurrent);
void Pag_PutParPagNum (Pag_WhatPaginate_t WhatPaginate,unsigned NumPage);

View File

@ -6340,7 +6340,8 @@ unsigned Usr_GetTotalNumberOfUsers (void)
/*****************************************************************************/
// Input: UsrDat must hold user's data
void Usr_WriteAuthor (struct Usr_Data *UsrDat,Cns_Enabled_t Enabled)
void Usr_WriteAuthor (struct Usr_Data *UsrDat,
Cns_DisabledOrEnabled_t DisabledOrEnabled)
{
extern const char *Txt_Unknown_or_without_photo;
static const char *ClassPhoto[PhoSha_NUM_SHAPES] =
@ -6354,7 +6355,7 @@ void Usr_WriteAuthor (struct Usr_Data *UsrDat,Cns_Enabled_t Enabled)
/***** Write author name or don't write it? *****/
WriteAuthor = false;
if (Enabled == Cns_ENABLED)
if (DisabledOrEnabled == Cns_ENABLED)
if (UsrDat->UsrCod > 0)
WriteAuthor = true;

View File

@ -433,7 +433,8 @@ void Usr_ShowWarningNoUsersFound (Rol_Role_t Role);
unsigned Usr_GetTotalNumberOfUsers (void);
void Usr_WriteAuthor (struct Usr_Data *UsrDat,Cns_Enabled_t Enabled);
void Usr_WriteAuthor (struct Usr_Data *UsrDat,
Cns_DisabledOrEnabled_t DisabledOrEnabled);
void Usr_WriteAuthor1Line (long UsrCod,bool Hidden);
void Usr_ShowTableCellWithUsrData (struct Usr_Data *UsrDat,unsigned NumRows);