From 9bb1b6d63e52019cd4cbee0858cdbc6024d44a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Tue, 29 Dec 2015 23:44:28 +0100 Subject: [PATCH] Version 15.82.1 --- swad_changelog.h | 3 ++- swad_message.c | 20 +++++++++----- swad_social.c | 69 +++++++++++++++++++++++++++++++++++++----------- 3 files changed, 69 insertions(+), 23 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index feaa44be8..bfa5d951b 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -116,13 +116,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.82 (2015-12-29)" +#define Log_PLATFORM_VERSION "SWAD 15.82.1 (2015-12-29)" #define CSS_FILE "swad15.80.css" #define JS_FILE "swad15.77.7.js" // 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 /* + Version 15.82.1: Dec 29, 2015 Public social posts are displayed in timeline. (189176 lines) Version 15.82: Dec 29, 2015 Public social post is received and stored in a new database table. (189136 lines) 1 change necessary in database: CREATE TABLE IF NOT EXISTS social_post (PstCod INT NOT NULL AUTO_INCREMENT,Content LONGTEXT NOT NULL,UNIQUE INDEX(PstCod),FULLTEXT(Content)) ENGINE = MYISAM; diff --git a/swad_message.c b/swad_message.c index 31dec8f37..58feea408 100644 --- a/swad_message.c +++ b/swad_message.c @@ -2347,14 +2347,19 @@ void Msg_GetDistinctCoursesInMyMessages (Msg_TypeOfMessages_t TypeOfMessages) switch (TypeOfMessages) { case Msg_MESSAGES_RECEIVED: - sprintf (Query,"SELECT DISTINCT courses.CrsCod,courses.ShortName FROM msg_rcv,msg_snt,courses" - " WHERE msg_rcv.UsrCod='%ld' AND msg_rcv.MsgCod=msg_snt.MsgCod AND msg_snt.CrsCod=courses.CrsCod" + sprintf (Query,"SELECT DISTINCT courses.CrsCod,courses.ShortName" + " FROM msg_rcv,msg_snt,courses" + " WHERE msg_rcv.UsrCod='%ld'" + " AND msg_rcv.MsgCod=msg_snt.MsgCod" + " AND msg_snt.CrsCod=courses.CrsCod" " ORDER BY courses.ShortName", Gbl.Usrs.Me.UsrDat.UsrCod); break; case Msg_MESSAGES_SENT: - sprintf (Query,"SELECT DISTINCT courses.CrsCod,courses.ShortName FROM msg_snt,courses" - " WHERE msg_snt.UsrCod='%ld' AND msg_snt.CrsCod=courses.CrsCod" + sprintf (Query,"SELECT DISTINCT courses.CrsCod,courses.ShortName" + " FROM msg_snt,courses" + " WHERE msg_snt.UsrCod='%ld'" + " AND msg_snt.CrsCod=courses.CrsCod" " ORDER BY courses.ShortName", Gbl.Usrs.Me.UsrDat.UsrCod); break; @@ -2588,13 +2593,14 @@ void Msg_GetMsgSubject (long MsgCod,char *Subject) static void Msg_GetMsgContent (long MsgCod,char *Content) { - char Query[512]; + char Query[128]; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned long NumRows; /***** Get content of message from database *****/ - sprintf (Query,"SELECT Content FROM msg_content WHERE MsgCod='%ld'",MsgCod); + sprintf (Query,"SELECT Content FROM msg_content WHERE MsgCod='%ld'", + MsgCod); NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get the content of a message"); /***** Result should have a unique row *****/ @@ -2604,7 +2610,7 @@ static void Msg_GetMsgContent (long MsgCod,char *Content) /***** Get number of rows *****/ row = mysql_fetch_row (mysql_res); - /****** Get location (row[0]) *****/ + /****** Get content (row[0]) *****/ strncpy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT); Content[Cns_MAX_BYTES_LONG_TEXT] = '\0'; diff --git a/swad_social.c b/swad_social.c index 04c2e79ef..1861d9bc6 100644 --- a/swad_social.c +++ b/swad_social.c @@ -27,6 +27,7 @@ #include // For PATH_MAX #include // For malloc and free +#include // For string functions #include // For time_t #include "swad_constant.h" @@ -105,6 +106,8 @@ extern struct Globals Gbl; /***************************** Private prototypes ****************************/ /*****************************************************************************/ +static void Soc_GetAndWriteSocialPost (long PstCod); + static unsigned long Soc_ShowTimeline (const char *Query); static Soc_SocialEvent_t Soc_GetSocialEventFromDB (const char *Str); static void Soc_WriteEventDate (time_t TimeUTC); @@ -166,6 +169,43 @@ void Soc_ReceiveSocialPost (void) Soc_StoreSocialEvent (Soc_EVENT_SOCIAL_POST,PstCod); } +/*****************************************************************************/ +/***************** Get from database and write public post *******************/ +/*****************************************************************************/ + +static void Soc_GetAndWriteSocialPost (long PstCod) + { + char Query[128]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned long NumRows; + char Content[Cns_MAX_BYTES_LONG_TEXT+1]; + + /***** Get social post from database *****/ + sprintf (Query,"SELECT Content FROM social_post WHERE PstCod='%ld'", + PstCod); + NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get the content of a social post"); + + /***** Result should have a unique row *****/ + if (NumRows == 1) + { + /***** Get number of rows *****/ + row = mysql_fetch_row (mysql_res); + + /****** Get content (row[0]) *****/ + strncpy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT); + Content[Cns_MAX_BYTES_LONG_TEXT] = '\0'; + } + else + Content[0] = '\0'; + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + /***** Write content *****/ + Msg_WriteMsgContent (Content,Cns_MAX_BYTES_LONG_TEXT,true,false); + } + /*****************************************************************************/ /*********** Show social activity (timeline) of a selected user **************/ /*****************************************************************************/ @@ -248,7 +288,7 @@ static unsigned long Soc_ShowTimeline (const char *Query) time_t DateTimeUTC; // Date-time of the event bool ShowPhoto = false; char PhotoURL[PATH_MAX+1]; - char *SummaryStr; + char SummaryStr[Cns_MAX_BYTES_TEXT+1]; /***** Get timeline from database *****/ NumEvents = DB_QuerySELECT (Query,&mysql_res,"can not get your notifications"); @@ -256,10 +296,6 @@ static unsigned long Soc_ShowTimeline (const char *Query) /***** List my timeline *****/ if (NumEvents) // Events found { - /***** Allocate memory for the summary of the notification *****/ - if ((SummaryStr = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) - Lay_ShowErrorAndExit ("Not enough memory to store the summary of the notification."); - /***** Initialize structure with user's data *****/ Usr_UsrDataConstructor (&UsrDat); @@ -349,9 +385,15 @@ static unsigned long Soc_ShowTimeline (const char *Query) /* Write date and time */ Soc_WriteEventDate (DateTimeUTC); - /* Write event type and location */ - if (SocialEvent != Soc_EVENT_SOCIAL_POST) + if (SocialEvent == Soc_EVENT_SOCIAL_POST) { + fprintf (Gbl.F.Out,"
"); + Soc_GetAndWriteSocialPost (Cod); + fprintf (Gbl.F.Out,"
"); + } + else + { + /* Write event type and location */ fprintf (Gbl.F.Out,"
"); Soc_StartFormGoToAction (SocialEvent,Crs.CrsCod,Cod); Act_LinkFormSubmit (Txt_SOCIAL_EVENT[SocialEvent], @@ -379,12 +421,12 @@ static unsigned long Soc_ShowTimeline (const char *Query) else if (Cty.CtyCod > 0) fprintf (Gbl.F.Out,"
%s: %s
", Txt_Country,Cty.Name[Gbl.Prefs.Language]); - } - /* Write content of the event */ - Soc_GetEventSummary (SocialEvent,Cod, - SummaryStr,Soc_MAX_BYTES_SUMMARY); - fprintf (Gbl.F.Out,"
%s
",SummaryStr); + /* Write content of the event */ + Soc_GetEventSummary (SocialEvent,Cod, + SummaryStr,Soc_MAX_BYTES_SUMMARY); + fprintf (Gbl.F.Out,"
%s
",SummaryStr); + } /* End of right part */ fprintf (Gbl.F.Out,"
"); @@ -399,9 +441,6 @@ static unsigned long Soc_ShowTimeline (const char *Query) /***** Free memory used for user's data *****/ Usr_UsrDataDestructor (&UsrDat); - - /***** Free summary *****/ - free ((void *) SummaryStr); } /***** Free structure that stores the query result *****/