mirror of
https://github.com/acanas/swad-core.git
synced 2024-06-11 03:05:40 +02:00
Version 15.131.1
This commit is contained in:
parent
2bc9939cab
commit
c5c3116f56
|
@ -121,13 +121,14 @@
|
||||||
/****************************** Public constants *****************************/
|
/****************************** Public constants *****************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#define Log_PLATFORM_VERSION "SWAD 15.131 (2016-01-26)"
|
#define Log_PLATFORM_VERSION "SWAD 15.131.1 (2016-01-26)"
|
||||||
#define CSS_FILE "swad15.121.7.css"
|
#define CSS_FILE "swad15.121.7.css"
|
||||||
#define JS_FILE "swad15.121.7.js"
|
#define JS_FILE "swad15.121.7.js"
|
||||||
|
|
||||||
// Number of lines (includes comments but not blank lines) has been got with the following command:
|
// Number of lines (includes comments but not blank lines) has been got with the following command:
|
||||||
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
|
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
|
||||||
/*
|
/*
|
||||||
|
Version 15.131.1: Jan 26, 2016 Optimization in the function that insert links in text. (194993 lines)
|
||||||
Version 15.131: Jan 26, 2016 Link around @nickname is inserted as form. (195011 lines)
|
Version 15.131: Jan 26, 2016 Link around @nickname is inserted as form. (195011 lines)
|
||||||
Version 15.130.2: Jan 26, 2016 Optimization in the function that insert links in text. (194928 lines)
|
Version 15.130.2: Jan 26, 2016 Optimization in the function that insert links in text. (194928 lines)
|
||||||
Version 15.130.1: Jan 26, 2016 Fixed bug when mentioning an user who does not exist. (194914 lines)
|
Version 15.130.1: Jan 26, 2016 Fixed bug when mentioning an user who does not exist. (194914 lines)
|
||||||
|
|
166
swad_string.c
166
swad_string.c
|
@ -100,6 +100,7 @@ action="https://localhost/swad/es" method="post">
|
||||||
#define ANCHOR_1_URL "<a href=\""
|
#define ANCHOR_1_URL "<a href=\""
|
||||||
#define ANCHOR_2_URL "\" target=\"_blank\">"
|
#define ANCHOR_2_URL "\" target=\"_blank\">"
|
||||||
#define ANCHOR_3_URL "</a>"
|
#define ANCHOR_3_URL "</a>"
|
||||||
|
#define ANCHOR_3_NICK "</a></form>"
|
||||||
|
|
||||||
#define MAX_LINKS 1000
|
#define MAX_LINKS 1000
|
||||||
|
|
||||||
|
@ -108,9 +109,9 @@ action="https://localhost/swad/es" method="post">
|
||||||
void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScreen)
|
void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScreen)
|
||||||
{
|
{
|
||||||
extern const char *Txt_STR_LANG_ID[1+Txt_NUM_LANGUAGES];
|
extern const char *Txt_STR_LANG_ID[1+Txt_NUM_LANGUAGES];
|
||||||
char Anchor1Nick[1024];
|
char Params[256+256+Ses_LENGTH_SESSION_ID+256];
|
||||||
char Anchor2Nick[1024];
|
char Anchor1Nick[256+256+256+Ses_LENGTH_SESSION_ID+256+256];
|
||||||
char Anchor3Nick[64];
|
char Anchor2Nick[256+Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64];
|
||||||
size_t TxtLength;
|
size_t TxtLength;
|
||||||
size_t TxtLengthWithInsertedAnchors;
|
size_t TxtLengthWithInsertedAnchors;
|
||||||
|
|
||||||
|
@ -151,38 +152,26 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre
|
||||||
char LimitedURL[MAX_BYTES_LIMITED_URL+1];
|
char LimitedURL[MAX_BYTES_LIMITED_URL+1];
|
||||||
char Ch;
|
char Ch;
|
||||||
|
|
||||||
/****** Initialize lengths *****/
|
/****** Initialize constant anchors and their lengths *****/
|
||||||
TxtLength = strlen (Txt);
|
TxtLength = strlen (Txt);
|
||||||
|
|
||||||
// In this case the length of anchor is fixed
|
// For URLs the length of anchor is fixed
|
||||||
// so it can be calculated once
|
// so it can be calculated once
|
||||||
Anchor1URLLength = strlen (ANCHOR_1_URL);
|
Anchor1URLLength = strlen (ANCHOR_1_URL);
|
||||||
Anchor2URLLength = strlen (ANCHOR_2_URL);
|
Anchor2URLLength = strlen (ANCHOR_2_URL);
|
||||||
Anchor3URLLength = strlen (ANCHOR_3_URL);
|
Anchor3URLLength = strlen (ANCHOR_3_URL);
|
||||||
AnchorURLTotalLength = Anchor1URLLength + Anchor2URLLength + Anchor3URLLength;
|
AnchorURLTotalLength = Anchor1URLLength +
|
||||||
|
Anchor2URLLength +
|
||||||
|
Anchor3URLLength;
|
||||||
|
|
||||||
if (Gbl.Usrs.Me.Logged) // In this case the length of anchor is variable
|
// For nicknames the length of anchor is variable
|
||||||
// so it can be calculated for each link
|
// so it can be calculated for each link,
|
||||||
{
|
// except the third part that is fixed
|
||||||
sprintf (Anchor3Nick,"</a>"
|
Anchor3NickLength = strlen (ANCHOR_3_NICK);
|
||||||
"</form>");
|
|
||||||
Anchor3NickLength = strlen (Anchor3Nick);
|
|
||||||
}
|
|
||||||
else // In this case the length of anchor is fixed
|
|
||||||
// so it can be calculated once
|
|
||||||
{
|
|
||||||
sprintf (Anchor1Nick,"<a href=\"%s/%s?usr=",
|
|
||||||
Cfg_HTTPS_URL_SWAD_CGI,
|
|
||||||
Txt_STR_LANG_ID[Gbl.Prefs.Language]);
|
|
||||||
sprintf (Anchor2Nick,"\" target=\"_blank\">");
|
|
||||||
sprintf (Anchor3Nick,"</a>");
|
|
||||||
Anchor1NickLength = strlen (Anchor1Nick);
|
|
||||||
Anchor2NickLength = strlen (Anchor2Nick);
|
|
||||||
Anchor3NickLength = strlen (Anchor3Nick);
|
|
||||||
AnchorNickTotalLength = Anchor1NickLength + Anchor2NickLength + Anchor3NickLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**************************************************************/
|
||||||
/***** Find starts and ends of links (URLs and nicknames) *****/
|
/***** Find starts and ends of links (URLs and nicknames) *****/
|
||||||
|
/**************************************************************/
|
||||||
for (PtrSrc = Txt;
|
for (PtrSrc = Txt;
|
||||||
*PtrSrc;)
|
*PtrSrc;)
|
||||||
/* Check if the next char is the start of a URL */
|
/* Check if the next char is the start of a URL */
|
||||||
|
@ -305,45 +294,46 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre
|
||||||
Links[NumLinks].Anchor1Nick = NULL;
|
Links[NumLinks].Anchor1Nick = NULL;
|
||||||
Links[NumLinks].Anchor2Nick = NULL;
|
Links[NumLinks].Anchor2Nick = NULL;
|
||||||
|
|
||||||
LengthVisibleLink = Links[NumLinks].NumActualBytes;
|
/* Create id for this form */
|
||||||
|
Gbl.Form.Num++;
|
||||||
if (Gbl.Usrs.Me.Logged) // In this case the length of anchor is variable
|
if (Gbl.Usrs.Me.Logged)
|
||||||
// so it must be calculated for each link
|
|
||||||
{
|
|
||||||
/* Create unique id for this form */
|
|
||||||
Gbl.Form.Num++;
|
|
||||||
sprintf (Gbl.Form.UniqueId,"form_%s_%d",
|
sprintf (Gbl.Form.UniqueId,"form_%s_%d",
|
||||||
Gbl.UniqueNameEncrypted,Gbl.Form.Num);
|
Gbl.UniqueNameEncrypted,Gbl.Form.Num);
|
||||||
|
else
|
||||||
|
sprintf (Gbl.Form.Id,"form_%d",Gbl.Form.Num);
|
||||||
|
|
||||||
/* Store first part of anchor */
|
/* Store first part of anchor */
|
||||||
sprintf (Anchor1Nick,"<form method=\"post\" action=\"%s/%s\" id=\"%s\">"
|
Act_SetParamsForm (Params,ActSeePubPrf,true);
|
||||||
"<input type=\"hidden\" name=\"ses\" value=\"%s\">"
|
sprintf (Anchor1Nick,"<form method=\"post\" action=\"%s/%s\" id=\"%s\">"
|
||||||
"<input type=\"hidden\" name=\"usr\" value=\"",
|
"%s"
|
||||||
Cfg_HTTPS_URL_SWAD_CGI,
|
"<input type=\"hidden\" name=\"usr\" value=\"",
|
||||||
Txt_STR_LANG_ID[Gbl.Prefs.Language],
|
Cfg_HTTPS_URL_SWAD_CGI,
|
||||||
Gbl.Form.UniqueId,
|
Txt_STR_LANG_ID[Gbl.Prefs.Language],
|
||||||
Gbl.Session.Id);
|
Gbl.Usrs.Me.Logged ? Gbl.Form.UniqueId :
|
||||||
Anchor1NickLength = strlen (Anchor1Nick);
|
Gbl.Form.Id,
|
||||||
if ((Links[NumLinks].Anchor1Nick = (char *) malloc (Anchor1NickLength+1)) == NULL)
|
Params);
|
||||||
Lay_ShowErrorAndExit ("Not enough memory to insert link.");
|
Anchor1NickLength = strlen (Anchor1Nick);
|
||||||
strcpy (Links[NumLinks].Anchor1Nick,Anchor1Nick);
|
if ((Links[NumLinks].Anchor1Nick = (char *) malloc (Anchor1NickLength+1)) == NULL)
|
||||||
Links[NumLinks].Anchor1NickLength = Anchor1NickLength;
|
Lay_ShowErrorAndExit ("Not enough memory to insert link.");
|
||||||
|
strcpy (Links[NumLinks].Anchor1Nick,Anchor1Nick);
|
||||||
|
Links[NumLinks].Anchor1NickLength = Anchor1NickLength;
|
||||||
|
|
||||||
/* Store second part of anchor */
|
/* Store second part of anchor */
|
||||||
sprintf (Anchor2Nick,"\">"
|
sprintf (Anchor2Nick,"\">"
|
||||||
"<a href=\"\""
|
"<a href=\"\""
|
||||||
" onclick=\"document.getElementById('%s').submit();"
|
" onclick=\"document.getElementById('%s').submit();"
|
||||||
"return false;\">",
|
"return false;\">",
|
||||||
Gbl.Form.UniqueId);
|
Gbl.Usrs.Me.Logged ? Gbl.Form.UniqueId :
|
||||||
Anchor2NickLength = strlen (Anchor2Nick);
|
Gbl.Form.Id);
|
||||||
if ((Links[NumLinks].Anchor2Nick = (char *) malloc (Anchor2NickLength+1)) == NULL)
|
Anchor2NickLength = strlen (Anchor2Nick);
|
||||||
Lay_ShowErrorAndExit ("Not enough memory to insert link.");
|
if ((Links[NumLinks].Anchor2Nick = (char *) malloc (Anchor2NickLength+1)) == NULL)
|
||||||
strcpy (Links[NumLinks].Anchor2Nick,Anchor2Nick);
|
Lay_ShowErrorAndExit ("Not enough memory to insert link.");
|
||||||
Links[NumLinks].Anchor2NickLength = Anchor2NickLength;
|
strcpy (Links[NumLinks].Anchor2Nick,Anchor2Nick);
|
||||||
|
Links[NumLinks].Anchor2NickLength = Anchor2NickLength;
|
||||||
|
|
||||||
AnchorNickTotalLength = Anchor1NickLength + Anchor2NickLength + Anchor3NickLength;
|
AnchorNickTotalLength = Anchor1NickLength + Anchor2NickLength + Anchor3NickLength;
|
||||||
}
|
|
||||||
|
|
||||||
|
LengthVisibleLink = Links[NumLinks].NumActualBytes;
|
||||||
if (NumLinks == 0)
|
if (NumLinks == 0)
|
||||||
Links[NumLinks].AddedLengthUntilHere = AnchorNickTotalLength + LengthVisibleLink;
|
Links[NumLinks].AddedLengthUntilHere = AnchorNickTotalLength + LengthVisibleLink;
|
||||||
else
|
else
|
||||||
|
@ -360,7 +350,9 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre
|
||||||
else // Character distinct to 'h' or '@'
|
else // Character distinct to 'h' or '@'
|
||||||
PtrSrc++;
|
PtrSrc++;
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
/***** If there are one or more links (URLs or nicknames) in text *****/
|
/***** If there are one or more links (URLs or nicknames) in text *****/
|
||||||
|
/**********************************************************************/
|
||||||
if (NumLinks)
|
if (NumLinks)
|
||||||
{
|
{
|
||||||
/***** Insert links from end to start of text,
|
/***** Insert links from end to start of text,
|
||||||
|
@ -373,8 +365,9 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre
|
||||||
{
|
{
|
||||||
IsNickname = (*(Links[NumLink].PtrStart) == '@');
|
IsNickname = (*(Links[NumLink].PtrStart) == '@');
|
||||||
|
|
||||||
/* Step 1: Move forward the text after the link (URL or nickname)
|
/***** Step 1: Move forward the text after the link (URL or nickname)
|
||||||
(it's mandatory to do the copy in reverse order to avoid overwriting source) */
|
(it's mandatory to do the copy in reverse order
|
||||||
|
to avoid overwriting source) *****/
|
||||||
for (i = 0,
|
for (i = 0,
|
||||||
PtrSrc = (NumLink == NumLinks - 1) ? Txt + TxtLength :
|
PtrSrc = (NumLink == NumLinks - 1) ? Txt + TxtLength :
|
||||||
Links[NumLink + 1].PtrStart - 1,
|
Links[NumLink + 1].PtrStart - 1,
|
||||||
|
@ -384,11 +377,11 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre
|
||||||
i++)
|
i++)
|
||||||
*PtrDst-- = *PtrSrc--;
|
*PtrDst-- = *PtrSrc--;
|
||||||
|
|
||||||
/* Step 2: Insert Anchor3Nick or ANCHOR_3_URL */
|
/***** Step 2: Insert ANCHOR_3_NICK or ANCHOR_3_URL *****/
|
||||||
if (IsNickname)
|
if (IsNickname)
|
||||||
{
|
{
|
||||||
Length = Anchor3NickLength;
|
Length = Anchor3NickLength;
|
||||||
PtrSrc = Anchor3Nick + Length - 1;
|
PtrSrc = ANCHOR_3_NICK + Length - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -400,7 +393,8 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre
|
||||||
i++)
|
i++)
|
||||||
*PtrDst-- = *PtrSrc--;
|
*PtrDst-- = *PtrSrc--;
|
||||||
|
|
||||||
/* Step 3: Move forward the link (URL or nickname) to be shown on screen */
|
/***** Step 3: Move forward the link (URL or nickname)
|
||||||
|
to be shown on screen *****/
|
||||||
if (IsNickname ||
|
if (IsNickname ||
|
||||||
Links[NumLink].NumActualBytes <= MaxCharsURLOnScreen)
|
Links[NumLink].NumActualBytes <= MaxCharsURLOnScreen)
|
||||||
{
|
{
|
||||||
|
@ -425,19 +419,11 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre
|
||||||
i++)
|
i++)
|
||||||
*PtrDst-- = *PtrSrc--;
|
*PtrDst-- = *PtrSrc--;
|
||||||
|
|
||||||
/* Step 4: Insert Anchor2Nick or ANCHOR_2_URL */
|
/***** Step 4: Insert Anchor2Nick or ANCHOR_2_URL *****/
|
||||||
if (IsNickname)
|
if (IsNickname)
|
||||||
{
|
{
|
||||||
if (Gbl.Usrs.Me.Logged) // In this case the length of anchor is variable
|
Length = Links[NumLink].Anchor2NickLength;
|
||||||
{
|
PtrSrc = Links[NumLink].Anchor2Nick + Length - 1;
|
||||||
Length = Links[NumLink].Anchor2NickLength;
|
|
||||||
PtrSrc = Links[NumLink].Anchor2Nick + Length - 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Length = Anchor2NickLength;
|
|
||||||
PtrSrc = Anchor2Nick + Length - 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -449,27 +435,19 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre
|
||||||
i++)
|
i++)
|
||||||
*PtrDst-- = *PtrSrc--;
|
*PtrDst-- = *PtrSrc--;
|
||||||
|
|
||||||
/* Step 5: Insert link into directive A
|
/***** Step 5: Insert link into directive A
|
||||||
(it's mandatory to do the copy in reverse order
|
(it's mandatory to do the copy in reverse order
|
||||||
to avoid overwriting source URL or nickname) */
|
to avoid overwriting source URL or nickname) *****/
|
||||||
for (i = 0, PtrSrc = Links[NumLink].PtrEnd;
|
for (i = 0, PtrSrc = Links[NumLink].PtrEnd;
|
||||||
i < Links[NumLink].NumActualBytes;
|
i < Links[NumLink].NumActualBytes;
|
||||||
i++)
|
i++)
|
||||||
*PtrDst-- = *PtrSrc--;
|
*PtrDst-- = *PtrSrc--;
|
||||||
|
|
||||||
/* Step 6: Insert Anchor1Nick or ANCHOR_1_URL */
|
/***** Step 6: Insert Anchor1Nick or ANCHOR_1_URL *****/
|
||||||
if (IsNickname)
|
if (IsNickname)
|
||||||
{
|
{
|
||||||
if (Gbl.Usrs.Me.Logged) // In this case the length of anchor is variable
|
Length = Links[NumLink].Anchor1NickLength;
|
||||||
{
|
PtrSrc = Links[NumLink].Anchor1Nick + Length - 1;
|
||||||
Length = Links[NumLink].Anchor1NickLength;
|
|
||||||
PtrSrc = Links[NumLink].Anchor1Nick + Length - 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Length = Anchor1NickLength;
|
|
||||||
PtrSrc = Anchor1Nick + Length - 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -483,7 +461,9 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************/
|
||||||
/***** Free memory for anchors *****/
|
/***** Free memory for anchors *****/
|
||||||
|
/***********************************/
|
||||||
for (NumLink = 0;
|
for (NumLink = 0;
|
||||||
NumLink < NumLinks;
|
NumLink < NumLinks;
|
||||||
NumLink++)
|
NumLink++)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user