swad-core/swad_timeline.c

2222 lines
79 KiB
C
Raw Normal View History

2019-03-12 21:25:55 +01:00
// swad_timeline.c: social timeline
2015-12-28 19:23:42 +01:00
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2021-02-09 12:43:45 +01:00
Copyright (C) 1999-2021 Antonio Ca<EFBFBD>as Vargas
2015-12-28 19:23:42 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General 3 License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/*********************************** Headers *********************************/
/*****************************************************************************/
2019-02-24 15:15:43 +01:00
#define _GNU_SOURCE // For asprintf
2015-12-28 19:23:42 +01:00
#include <linux/limits.h> // For PATH_MAX
2019-02-24 15:15:43 +01:00
#include <stdio.h> // For asprintf
2015-12-28 20:46:48 +01:00
#include <stdlib.h> // For malloc and free
2015-12-29 23:44:28 +01:00
#include <string.h> // For string functions
2015-12-28 19:23:42 +01:00
#include <sys/types.h> // For time_t
#include "swad_database.h"
2020-04-20 01:26:46 +02:00
#include "swad_exam_announcement.h"
2020-04-14 17:15:17 +02:00
#include "swad_figure.h"
2015-12-29 14:24:37 +01:00
#include "swad_follow.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2020-04-14 17:15:17 +02:00
#include "swad_forum.h"
2015-12-28 19:23:42 +01:00
#include "swad_global.h"
2020-04-14 17:15:17 +02:00
#include "swad_message.h"
2015-12-29 01:28:17 +01:00
#include "swad_notice.h"
2021-02-08 19:04:47 +01:00
#include "swad_photo.h"
2016-01-02 01:56:48 +01:00
#include "swad_profile.h"
2019-03-26 11:53:21 +01:00
#include "swad_setting.h"
2019-03-12 21:25:55 +01:00
#include "swad_timeline.h"
2021-02-08 16:24:29 +01:00
#include "swad_timeline_favourite.h"
2021-02-11 00:58:53 +01:00
#include "swad_timeline_note.h"
2021-02-08 18:33:16 +01:00
#include "swad_timeline_share.h"
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
2019-11-24 23:51:03 +01:00
/************************* Private constants and types ***********************/
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2021-02-08 13:37:25 +01:00
// Number of recent publishings got and shown the first time, before refreshing
2021-02-10 00:52:33 +01:00
// Don't use big numbers because dynamic memory will be allocated to stored publications
2021-02-08 13:37:25 +01:00
#define TL_MAX_REC_PUBS_TO_GET_AND_SHOW 10 // Recent publishings to show (first time)
2021-02-10 00:52:33 +01:00
#define TL_MAX_NEW_PUBS_TO_GET_AND_SHOW 100 // New publishings retrieved
2021-02-08 13:37:25 +01:00
#define TL_MAX_OLD_PUBS_TO_GET_AND_SHOW 20 // Old publishings are retrieved in packs of this size
#define TL_MAX_CHARS_IN_POST 1000 // Maximum number of characters in a post
2019-03-29 00:57:51 +01:00
2021-02-08 22:33:41 +01:00
#define TL_MAX_BYTES_SUBQUERY (128 - 1)
2015-12-28 19:23:42 +01:00
2019-11-24 23:51:03 +01:00
/*
2021-02-09 12:43:45 +01:00
mysql> SHOW TABLES LIKE 'tl_%';
+-----------------------+
| Tables_in_swad (tl_%) |
+-----------------------+
| tl_comments |
| tl_comments_fav |
| tl_notes |
| tl_notes_fav |
| tl_posts |
| tl_pubs |
| tl_timelines |
+-----------------------+
7 rows in set (0.00 sec)
2019-11-24 23:51:03 +01:00
The timeline is a set of publications.
A publication can be:
2021-02-09 12:43:45 +01:00
<EFBFBD> an original note (22783, 83% of 27396)
<EFBFBD> a shared note ( 750, 3% of 27396)
<EFBFBD> a comment to a note ( 3863, 14% of 27396)
2021-02-10 14:51:05 +01:00
*Numbers are got from swad.ugr.es on february 2020
2021-02-09 12:43:45 +01:00
____tl_pubs____ _tl_comments_
| | | |
| Publication p |---------->| Comment c |-----+
| (comment) | | (to note 2) | |
|_______________| |_____________| |
| | | | |
<EFBFBD> ... <EFBFBD> <EFBFBD> ... <EFBFBD> |
<EFBFBD> ... <EFBFBD> <EFBFBD> ... <EFBFBD> |
|_______________| |_____________| |
| | | | |
|Publication i+4|---------->| Comment 1 |---+ |
| (comment) | | (to note n) | | |
|_______________| |_____________| | |
| | (3863) | |
|Publication i+3|-- | |
|(original note)| \ | |
|_______________| \ ___tl_notes____ | | _exam_announcements_
| | \ | | | | | |
|Publication i+2|-- ---->| Note n |<-+ | | Exam announcement | (5571)
|(original note)| \ |(exam announc.)|-(2639)->|____________________|
|_______________| \ |_______________| 12% ____files____
| | \ | | | | |
|Publication i+1|-- ---->| Note n-1 |-(64)--->| Public file | (1473406)
|(original note)| \ | (public file) | <1% |_____________|
|_______________| \ |_______________| | _notices_
| | \ | | | | |
| Publication i |-- ---->| Note n-2 |-(16693)>| Notice | (14793)
|(original note)| \ | (notice) | 73% |_________|
|_______________| \ |_______________| | __tl_posts___
| | \ | | | | |
<EFBFBD> ... <EFBFBD> ---->| Note n-3 |-(3119)->| Post s |
<EFBFBD> ... <EFBFBD> | (tl. post) | 14% | |
|_______________| |_______________| | |_____________|
| | | | | | |
| Publication 3 | <EFBFBD> ... <EFBFBD> | <EFBFBD> ... <EFBFBD> (3119)
| (shared note) |--- <EFBFBD> ... <EFBFBD> | <EFBFBD> ... <EFBFBD>
|_______________| \ |_______________| | |_____________|
| | \ | | | | |
| Publication 2 | ---->| Note 2 |<---+ | Post 1 |
|(original note)|--------->| (tl. post) |-------->| |
|_______________| |_______________| |_____________|
| | | | _forum_post_
| Publication 1 |--------->| Note 1 | | |
|(original note)| | (forum post) |-(268)-->| Forum post | (66226)
|_______________| |_______________| 1% |____________|
(27396) (22783)
2019-11-25 23:18:08 +01:00
2019-11-24 23:51:03 +01:00
A note can be:
2021-02-09 12:43:45 +01:00
<EFBFBD> a timeline post ( 3119, 14% of 22783)
<EFBFBD> a public file ( 64, <1% of 22783)
<EFBFBD> an exam announcement ( 2639, 12% of 22783)
<EFBFBD> a notice (16693, 73% of 22783)
<EFBFBD> a forum post ( 268, 1% of 22783)
2019-11-24 23:51:03 +01:00
written by an author in a date-time.
2015-12-28 19:23:42 +01:00
2021-02-09 12:43:45 +01:00
A note can have comments attached to it.
2019-11-24 23:51:03 +01:00
__________________
|@author |
| Note |
|__________________|
|@author |
| Comment 1 |
|______________|
|@author |
| Comment 2 |
|______________|
| |
| ... |
|______________|
|@author |
| Comment n |
|______________|
*/
2021-02-11 00:58:53 +01:00
2021-02-08 23:52:51 +01:00
struct TL_SubQueries
{
2021-02-09 13:23:29 +01:00
char *TablePublishers;
2021-02-08 23:52:51 +01:00
char Publishers[TL_MAX_BYTES_SUBQUERY + 1];
char RangeBottom[TL_MAX_BYTES_SUBQUERY + 1];
char RangeTop[TL_MAX_BYTES_SUBQUERY + 1];
char AlreadyExists[TL_MAX_BYTES_SUBQUERY + 1];
};
2021-02-08 13:37:25 +01:00
2021-02-08 22:56:05 +01:00
struct TL_RangePubsToGet
{
long Top;
long Bottom;
};
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
2019-11-21 16:47:07 +01:00
/************************* Private global variables **************************/
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2020-04-11 00:57:25 +02:00
Usr_Who_t TL_GlobalWho;
2021-02-08 13:37:25 +01:00
#define TL_DEFAULT_WHO Usr_WHO_FOLLOWED
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2021-02-08 22:33:41 +01:00
static void TL_GetAndShowOldTimeline (struct TL_Timeline *Timeline);
2016-01-14 01:39:02 +01:00
2021-02-10 10:20:35 +01:00
static void TL_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline);
2021-02-08 22:45:06 +01:00
static unsigned TL_GetMaxPubsToGet (const struct TL_Timeline *Timeline);
2019-03-12 21:25:55 +01:00
static long TL_GetPubCodFromSession (const char *FieldName);
2021-02-10 18:41:42 +01:00
static void TL_UpdateFirstLastPubCodesIntoSession (const struct TL_Timeline *Timeline);
2021-02-10 00:52:33 +01:00
static void TL_CreateTmpTableCurrentTimeline (const struct TL_Timeline *Timeline);
2021-02-08 22:33:41 +01:00
static void TL_CreateTmpTablePublishers (void);
static void TL_DropTmpTablesUsedToQueryTimeline (void);
static void TL_CreateSubQueryPublishers (const struct TL_Timeline *Timeline,
2021-02-08 23:52:51 +01:00
struct TL_SubQueries *SubQueries);
2021-02-09 20:42:24 +01:00
static void TL_CreateSubQueryAlreadyExists (const struct TL_Timeline *Timeline,
struct TL_SubQueries *SubQueries);
2021-02-09 13:23:29 +01:00
static void TL_CreateSubQueryRangeBottom (const struct TL_RangePubsToGet *RangePubsToGet,
2021-02-08 23:52:51 +01:00
struct TL_SubQueries *SubQueries);
2021-02-09 13:23:29 +01:00
static void TL_CreateSubQueryRangeTop (const struct TL_RangePubsToGet *RangePubsToGet,
2021-02-08 23:52:51 +01:00
struct TL_SubQueries *SubQueries);
2021-02-10 14:51:05 +01:00
static void TL_AllocateListPubs (struct TL_Timeline *Timeline,
unsigned MaxPubsToGet);
static void TL_FreeListPubs (const struct TL_Timeline *Timeline);
2021-02-09 13:23:29 +01:00
static void TL_SelectTheMostRecentPub (const struct TL_SubQueries *SubQueries,
2021-02-10 19:53:57 +01:00
struct TL_Publication *Pub);
2016-01-10 03:10:40 +01:00
2020-04-11 00:57:25 +02:00
static void TL_ShowTimeline (struct TL_Timeline *Timeline,
2019-03-13 10:23:41 +01:00
const char *Title,long NotCodToHighlight);
2020-04-08 03:41:05 +02:00
static void TL_PutIconsTimeline (__attribute__((unused)) void *Args);
2017-02-24 03:38:18 +01:00
2020-04-11 00:57:25 +02:00
static void TL_PutFormWho (struct TL_Timeline *Timeline);
2019-11-12 00:31:41 +01:00
static Usr_Who_t TL_GetWhoFromDB (void);
2021-02-11 00:58:53 +01:00
static void TL_SetGlobalWho (Usr_Who_t Who);
2020-04-11 00:57:25 +02:00
static void TL_SaveWhoInDB (struct TL_Timeline *Timeline);
2019-03-12 21:25:55 +01:00
static void TL_ShowWarningYouDontFollowAnyUser (void);
2021-02-10 00:52:33 +01:00
static void TL_InsertNewPubsInTimeline (struct TL_Timeline *Timeline);
static void TL_ShowOldPubsInTimeline (struct TL_Timeline *Timeline);
2019-03-12 21:25:55 +01:00
static void TL_PutLinkToViewNewPublications (void);
static void TL_PutLinkToViewOldPublications (void);
2020-04-11 00:57:25 +02:00
static void TL_PutFormToWriteNewPost (struct TL_Timeline *Timeline);
2016-01-15 10:48:49 +01:00
2019-03-12 21:25:55 +01:00
static long TL_ReceivePost (void);
2015-12-30 12:40:13 +01:00
2021-02-11 00:58:53 +01:00
static long TL_Pub_GetNotCodFromPubCod (long PubCod);
2019-03-12 21:25:55 +01:00
2021-02-09 17:31:44 +01:00
static void TL_GetDataOfPublicationFromNextRow (MYSQL_RES *mysql_res,
2021-02-10 19:53:57 +01:00
struct TL_Publication *Pub);
2019-03-12 21:25:55 +01:00
static TL_PubType_t TL_GetPubTypeFromStr (const char *Str);
2016-01-08 01:53:37 +01:00
2021-02-11 00:58:53 +01:00
static void TL_Pub_ResetPublication (struct TL_Publication *Pub);
2015-12-29 23:44:28 +01:00
2019-03-12 21:25:55 +01:00
static void TL_ClearTimelineThisSession (void);
2016-01-12 19:43:17 +01:00
2015-12-29 14:24:37 +01:00
/*****************************************************************************/
2020-04-11 00:57:25 +02:00
/************************ Initialize global timeline *************************/
2015-12-29 14:24:37 +01:00
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
void TL_InitTimelineGbl (struct TL_Timeline *Timeline)
2017-02-24 03:38:18 +01:00
{
2020-04-11 00:57:25 +02:00
/***** Reset timeline context *****/
TL_ResetTimeline (Timeline);
2017-02-24 03:38:18 +01:00
/***** Mark all my notifications about timeline as seen *****/
2019-03-12 21:25:55 +01:00
TL_MarkMyNotifAsSeen ();
2017-02-24 03:38:18 +01:00
/***** Get which users *****/
2020-04-11 00:57:25 +02:00
Timeline->Who = TL_GetGlobalWho ();
}
/*****************************************************************************/
/*************************** Reset timeline context **************************/
/*****************************************************************************/
void TL_ResetTimeline (struct TL_Timeline *Timeline)
{
2021-02-09 13:23:29 +01:00
Timeline->UsrOrGbl = TL_TIMELINE_GBL;
Timeline->Who = TL_DEFAULT_WHO;
2021-02-08 22:33:41 +01:00
Timeline->WhatToGet = TL_GET_RECENT_TIMELINE;
2021-02-10 14:51:05 +01:00
Timeline->Pubs.Num = 0,
Timeline->Pubs.Lst = NULL,
Timeline->NotCod = -1L;
Timeline->PubCod = -1L;
2020-04-11 00:57:25 +02:00
}
/*****************************************************************************/
2021-02-08 13:53:19 +01:00
/**************** Show highlighted note and global timeline ******************/
2020-04-11 00:57:25 +02:00
/*****************************************************************************/
void TL_ShowTimelineGbl (void)
{
struct TL_Timeline Timeline;
/***** Initialize timeline *****/
TL_InitTimelineGbl (&Timeline);
2019-02-21 20:04:05 +01:00
/***** Save which users in database *****/
2020-04-11 00:57:25 +02:00
TL_SaveWhoInDB (&Timeline);
2021-02-08 13:53:19 +01:00
/***** Show highlighted note and global timeline *****/
2020-04-11 00:57:25 +02:00
TL_ShowNoteAndTimelineGbl (&Timeline);
2017-02-24 03:38:18 +01:00
}
2021-02-08 13:53:19 +01:00
/*****************************************************************************/
/**************** Show highlighted note and global timeline ******************/
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
void TL_ShowNoteAndTimelineGbl (struct TL_Timeline *Timeline)
2015-12-29 14:24:37 +01:00
{
2016-01-25 14:40:57 +01:00
long PubCod;
2021-02-11 00:58:53 +01:00
struct TL_Not_Note Not;
2021-02-08 13:53:19 +01:00
/***** Initialize note code to -1 ==> no highlighted note *****/
2021-02-10 19:53:57 +01:00
Not.NotCod = -1L;
2021-02-08 13:53:19 +01:00
/***** Get parameter with the code of a publication *****/
// This parameter is optional. It can be provided by a notification.
// If > 0 ==> the note is shown highlighted above the timeline
PubCod = TL_GetParamPubCod ();
/***** If a note should be highlighted ==> get code of note from database *****/
if (PubCod > 0)
2021-02-11 00:58:53 +01:00
Not.NotCod = TL_Pub_GetNotCodFromPubCod (PubCod);
2021-02-08 13:53:19 +01:00
/***** If a note should be highlighted ==> show it above the timeline *****/
2021-02-10 19:53:57 +01:00
if (Not.NotCod > 0)
2021-02-08 13:53:19 +01:00
/***** Show the note highlighted above the timeline *****/
2021-02-11 00:58:53 +01:00
TL_Not_ShowHighlightedNote (Timeline,&Not);
2021-02-08 13:53:19 +01:00
/***** Show timeline with possible highlighted note *****/
2021-02-10 19:53:57 +01:00
TL_ShowTimelineGblHighlightingNot (Timeline,Not.NotCod);
2021-02-08 13:53:19 +01:00
}
/*****************************************************************************/
2021-02-08 16:24:29 +01:00
/******************* Show global timeline highlighting a note ****************/
2021-02-08 13:53:19 +01:00
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
void TL_ShowTimelineGblHighlightingNot (struct TL_Timeline *Timeline,
long NotCod)
2016-01-15 14:46:44 +01:00
{
2017-02-27 19:52:04 +01:00
extern const char *Txt_Timeline;
2015-12-29 14:24:37 +01:00
2021-02-10 10:20:35 +01:00
/***** Get list of pubications/notes to show in timeline *****/
2021-02-09 12:43:45 +01:00
Timeline->UsrOrGbl = TL_TIMELINE_GBL;
2021-02-08 22:33:41 +01:00
Timeline->WhatToGet = TL_GET_RECENT_TIMELINE;
2021-02-10 10:20:35 +01:00
TL_GetListPubsToShowInTimeline (Timeline);
2015-12-29 14:24:37 +01:00
/***** Show timeline *****/
2021-02-10 00:52:33 +01:00
TL_ShowTimeline (Timeline,Txt_Timeline,NotCod);
/***** Free memory used for publications *****/
2021-02-10 14:51:05 +01:00
TL_FreeListPubs (Timeline);
2015-12-29 14:24:37 +01:00
}
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********************* Show timeline of a selected user **********************/
2015-12-29 14:24:37 +01:00
/*****************************************************************************/
2020-04-11 00:57:25 +02:00
void TL_ShowTimelineUsr (struct TL_Timeline *Timeline)
2015-12-29 14:24:37 +01:00
{
2020-04-11 00:57:25 +02:00
TL_ShowTimelineUsrHighlightingNot (Timeline,-1L);
2016-01-15 14:46:44 +01:00
}
2015-12-29 14:24:37 +01:00
2021-02-08 16:24:29 +01:00
/*****************************************************************************/
/************ Show timeline of a selected user highlighting a note ***********/
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
void TL_ShowTimelineUsrHighlightingNot (struct TL_Timeline *Timeline,
long NotCod)
2016-01-15 14:46:44 +01:00
{
2017-02-27 19:52:04 +01:00
extern const char *Txt_Timeline_OF_A_USER;
2016-01-08 10:27:58 +01:00
2021-02-10 10:20:35 +01:00
/***** Get list of pubications/notes to show in timeline *****/
2021-02-09 12:43:45 +01:00
Timeline->UsrOrGbl = TL_TIMELINE_USR;
2021-02-08 22:33:41 +01:00
Timeline->WhatToGet = TL_GET_RECENT_TIMELINE;
2021-02-10 10:20:35 +01:00
TL_GetListPubsToShowInTimeline (Timeline);
2016-01-10 03:10:40 +01:00
/***** Show timeline *****/
2020-04-11 00:57:25 +02:00
TL_ShowTimeline (Timeline,
2021-02-10 00:52:33 +01:00
Str_BuildStringStr (Txt_Timeline_OF_A_USER,
Gbl.Usrs.Other.UsrDat.FirstName),
2019-12-30 18:08:31 +01:00
NotCod);
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2016-01-10 03:10:40 +01:00
2021-02-10 00:52:33 +01:00
/***** Free memory used for publications *****/
2021-02-10 14:51:05 +01:00
TL_FreeListPubs (Timeline);
2016-01-10 03:10:40 +01:00
}
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************** Refresh new publications in timeline via AJAX ****************/
2016-01-14 01:39:02 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_RefreshNewTimelineGbl (void)
2016-01-10 03:10:40 +01:00
{
2020-04-11 00:57:25 +02:00
struct TL_Timeline Timeline;
2018-10-30 03:29:40 +01:00
2017-02-06 01:23:33 +01:00
if (Gbl.Session.IsOpen) // If session has been closed, do not write anything
{
2020-04-11 00:57:25 +02:00
/***** Reset timeline context *****/
TL_ResetTimeline (&Timeline);
2017-02-24 03:38:18 +01:00
/***** Get which users *****/
2020-04-11 00:57:25 +02:00
Timeline.Who = TL_GetGlobalWho ();
2017-02-24 03:38:18 +01:00
2021-02-10 10:20:35 +01:00
/***** Get list of pubications/notes to show in timeline *****/
2021-02-09 12:43:45 +01:00
Timeline.UsrOrGbl = TL_TIMELINE_GBL;
2021-02-08 22:33:41 +01:00
Timeline.WhatToGet = TL_GET_ONLY_NEW_PUBS;
2021-02-10 10:20:35 +01:00
TL_GetListPubsToShowInTimeline (&Timeline);
2016-01-10 03:10:40 +01:00
2017-02-06 01:23:33 +01:00
/***** Show new timeline *****/
2021-02-10 00:52:33 +01:00
TL_InsertNewPubsInTimeline (&Timeline);
/***** Free memory used for publications *****/
2021-02-10 14:51:05 +01:00
TL_FreeListPubs (&Timeline);
2017-02-06 01:23:33 +01:00
}
2016-01-14 01:39:02 +01:00
}
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/**************** View old publications in timeline via AJAX *****************/
2016-01-14 01:39:02 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_RefreshOldTimelineGbl (void)
2016-01-14 01:39:02 +01:00
{
2020-04-11 00:57:25 +02:00
struct TL_Timeline Timeline;
/***** Reset timeline context *****/
TL_ResetTimeline (&Timeline);
2017-02-24 03:38:18 +01:00
/***** Get which users *****/
2020-04-11 00:57:25 +02:00
Timeline.Who = TL_GetGlobalWho ();
2017-02-24 03:38:18 +01:00
2019-03-06 10:13:39 +01:00
/***** Show old publications *****/
2021-02-09 12:43:45 +01:00
Timeline.UsrOrGbl = TL_TIMELINE_GBL;
2021-02-08 22:33:41 +01:00
Timeline.WhatToGet = TL_GET_ONLY_OLD_PUBS;
TL_GetAndShowOldTimeline (&Timeline);
2016-01-14 01:39:02 +01:00
}
2019-03-12 21:25:55 +01:00
void TL_RefreshOldTimelineUsr (void)
2016-01-14 01:39:02 +01:00
{
2020-04-11 00:57:25 +02:00
struct TL_Timeline Timeline;
2017-02-17 10:17:39 +01:00
/***** Get user whom profile is displayed *****/
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) // Existing user
2020-04-11 00:57:25 +02:00
{
/***** Reset timeline context *****/
TL_ResetTimeline (&Timeline);
2019-03-06 10:13:39 +01:00
/***** If user exists, show old publications *****/
2021-02-09 12:43:45 +01:00
Timeline.UsrOrGbl = TL_TIMELINE_USR;
2021-02-08 22:33:41 +01:00
Timeline.WhatToGet = TL_GET_ONLY_OLD_PUBS;
TL_GetAndShowOldTimeline (&Timeline);
2020-04-11 00:57:25 +02:00
}
2016-01-14 01:39:02 +01:00
}
2016-01-10 14:27:35 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
/**************** Get and show old publications in timeline ******************/
2016-01-10 14:27:35 +01:00
/*****************************************************************************/
2021-02-08 22:33:41 +01:00
static void TL_GetAndShowOldTimeline (struct TL_Timeline *Timeline)
2016-01-10 14:27:35 +01:00
{
2021-02-10 10:20:35 +01:00
/***** Get list of pubications/notes to show in timeline *****/
TL_GetListPubsToShowInTimeline (Timeline);
2016-01-10 14:27:35 +01:00
2016-01-10 16:57:02 +01:00
/***** Show old timeline *****/
2021-02-10 00:52:33 +01:00
TL_ShowOldPubsInTimeline (Timeline);
/***** Free memory used for publications *****/
2021-02-10 14:51:05 +01:00
TL_FreeListPubs (Timeline);
2016-01-10 14:27:35 +01:00
}
2016-01-25 21:48:08 +01:00
/*****************************************************************************/
/************ Mark all my notifications about timeline as seen ***************/
/*****************************************************************************/
2017-02-24 03:38:18 +01:00
// Must be executed as a priori function
2016-01-25 21:48:08 +01:00
2019-03-12 21:25:55 +01:00
void TL_MarkMyNotifAsSeen (void)
2016-01-25 21:48:08 +01:00
{
Ntf_MarkNotifAsSeen (Ntf_EVENT_TIMELINE_COMMENT,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_MarkNotifAsSeen (Ntf_EVENT_TIMELINE_FAV ,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_MarkNotifAsSeen (Ntf_EVENT_TIMELINE_SHARE ,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
Ntf_MarkNotifAsSeen (Ntf_EVENT_TIMELINE_MENTION,-1L,-1L,Gbl.Usrs.Me.UsrDat.UsrCod);
}
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
2021-02-10 10:20:35 +01:00
/************ Get list of pubications/notes to show in timeline **************/
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
2021-02-10 10:20:35 +01:00
static void TL_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline)
2016-01-10 03:10:40 +01:00
{
2021-02-08 23:52:51 +01:00
struct TL_SubQueries SubQueries;
2021-02-08 22:56:05 +01:00
struct TL_RangePubsToGet RangePubsToGet;
2021-02-08 22:45:06 +01:00
unsigned MaxPubsToGet = TL_GetMaxPubsToGet (Timeline);
2016-01-17 01:50:43 +01:00
unsigned NumPub;
2016-01-10 16:57:02 +01:00
2019-03-12 21:25:55 +01:00
/***** Clear timeline for this session in database *****/
2021-02-08 22:33:41 +01:00
if (Timeline->WhatToGet == TL_GET_RECENT_TIMELINE)
2019-03-12 21:25:55 +01:00
TL_ClearTimelineThisSession ();
2016-01-13 00:45:16 +01:00
2021-02-09 20:42:24 +01:00
/***** Create temporary table with notes in current timeline *****/
2021-02-10 00:52:33 +01:00
TL_CreateTmpTableCurrentTimeline (Timeline);
2016-01-17 01:50:43 +01:00
2016-01-17 19:56:56 +01:00
/***** Create temporary table and subquery with potential publishers *****/
2021-02-08 23:52:51 +01:00
TL_CreateSubQueryPublishers (Timeline,&SubQueries);
2016-01-17 01:50:43 +01:00
2016-01-17 19:56:56 +01:00
/***** Create subquery to get only notes not present in timeline *****/
2021-02-09 20:42:24 +01:00
TL_CreateSubQueryAlreadyExists (Timeline,&SubQueries);
2016-01-13 00:24:26 +01:00
2019-03-06 10:13:39 +01:00
/***** Get the publications in timeline *****/
2016-01-17 21:22:01 +01:00
/* Initialize range of pubs:
2019-11-25 13:29:56 +01:00
tl_pubs
2016-01-17 21:22:01 +01:00
_____
|_____|11
|_____|10
_|_____| 9 <-- RangePubsToGet.Top
Get / |_____| 8
pubs | |_____| 7
from < |_____| 6
this | |_____| 5
range \_|_____| 4
|_____| 3 <-- RangePubsToGet.Bottom
|_____| 2
|_____| 1
0
*/
2021-02-08 22:33:41 +01:00
switch (Timeline->WhatToGet)
2016-01-17 21:22:01 +01:00
{
2019-03-12 21:25:55 +01:00
case TL_GET_ONLY_NEW_PUBS: // Get the publications (without limit) newer than LastPubCod
2016-01-17 21:22:01 +01:00
/* This query is made via AJAX automatically from time to time */
2021-02-09 13:57:17 +01:00
RangePubsToGet.Top = 0; // +Infinite
2019-03-12 21:25:55 +01:00
RangePubsToGet.Bottom = TL_GetPubCodFromSession ("LastPubCod");
2016-01-17 21:22:01 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_GET_ONLY_OLD_PUBS: // Get some limited publications older than FirstPubCod
2016-01-17 21:22:01 +01:00
/* This query is made via AJAX
2019-03-06 10:13:39 +01:00
when I click in link to get old publications */
2019-03-12 21:25:55 +01:00
RangePubsToGet.Top = TL_GetPubCodFromSession ("FirstPubCod");
2021-02-09 13:57:17 +01:00
RangePubsToGet.Bottom = 0; // -Infinite
break;
case TL_GET_RECENT_TIMELINE: // Get some limited recent publications
default:
/* This is the first query to get initial timeline shown
==> no notes yet in current timeline table */
RangePubsToGet.Top = 0; // +Infinite
RangePubsToGet.Bottom = 0; // -Infinite
2016-01-17 21:22:01 +01:00
break;
}
2021-02-09 14:46:46 +01:00
/* Create subquery with bottom range of publications to get from tl_pubs.
Bottom publication code remains unchanged in all iterations of the next loop. */
TL_CreateSubQueryRangeBottom (&RangePubsToGet,&SubQueries);
2016-01-17 21:22:01 +01:00
2016-01-17 01:50:43 +01:00
/*
2016-01-17 20:06:25 +01:00
With the current approach, we select one by one
2019-03-06 10:13:39 +01:00
the publications and notes in a loop. In each iteration,
we get the more recent publication (original, shared or commment)
of every set of publications corresponding to the same note,
2016-01-17 21:22:01 +01:00
checking that the note is not already retrieved.
2019-03-06 10:13:39 +01:00
After getting a publication, its note code is stored
2016-01-17 21:22:01 +01:00
in order to not get it again.
2016-01-17 20:06:25 +01:00
As an alternative, we tried to get the maximum PubCod,
2019-03-06 10:13:39 +01:00
i.e more recent publication (original, shared or commment),
of every set of publications corresponding to the same note:
2019-11-25 13:29:56 +01:00
"SELECT MAX(PubCod) AS NewestPubCod FROM tl_pubs ...
2016-01-17 01:50:43 +01:00
" GROUP BY NotCod ORDER BY NewestPubCod DESC LIMIT ..."
2016-01-17 20:06:25 +01:00
but this query is slow (several seconds) with a big table.
2019-11-24 23:51:03 +01:00
*/
2021-02-10 00:52:33 +01:00
/* Allocate memory to store publications */
2021-02-10 14:51:05 +01:00
TL_AllocateListPubs (Timeline,MaxPubsToGet);
2021-02-10 00:52:33 +01:00
2021-02-10 10:20:35 +01:00
for (NumPub = 0;
2021-02-08 22:45:06 +01:00
NumPub < MaxPubsToGet;
2016-01-17 01:50:43 +01:00
NumPub++)
{
2021-02-09 14:46:46 +01:00
/* Create subquery with top range of publications to get from tl_pubs
In each iteration of this loop, top publication code is changed to a lower value */
TL_CreateSubQueryRangeTop (&RangePubsToGet,&SubQueries);
2016-01-17 21:22:01 +01:00
2019-11-25 13:29:56 +01:00
/* Select the most recent publication from tl_pubs */
2021-02-10 14:51:05 +01:00
TL_SelectTheMostRecentPub (&SubQueries,&Timeline->Pubs.Lst[NumPub]);
if (Timeline->Pubs.Lst[NumPub].PubCod <= 0) // Nothing got ==> abort loop
2019-03-06 10:13:39 +01:00
break; // Last publication
2021-02-10 10:20:35 +01:00
/* Insert note in temporary tables with just retrieved notes.
These tables will be used to not get notes already shown */
2021-02-11 00:58:53 +01:00
TL_Not_InsertNoteInJustRetrievedNotes (Timeline->Pubs.Lst[NumPub].NotCod);
2021-02-10 10:20:35 +01:00
if (Timeline->WhatToGet == TL_GET_ONLY_OLD_PUBS)
2021-02-11 00:58:53 +01:00
TL_Not_InsertNoteInVisibleTimeline (Timeline->Pubs.Lst[NumPub].NotCod);
2021-02-10 10:20:35 +01:00
2021-02-10 14:51:05 +01:00
RangePubsToGet.Top = Timeline->Pubs.Lst[NumPub].PubCod; // Narrow the range for the next iteration
2016-01-10 03:10:40 +01:00
}
2021-02-10 18:41:42 +01:00
Timeline->Pubs.Num = NumPub; // Number of publications actually got
2016-01-08 10:27:58 +01:00
2021-02-10 18:41:42 +01:00
/***** Update first (oldest) and last (more recent) publication codes
into session for next refresh *****/
TL_UpdateFirstLastPubCodesIntoSession (Timeline);
2016-01-10 03:10:40 +01:00
2016-01-17 01:50:43 +01:00
/***** Add notes just retrieved to current timeline for this session *****/
2021-02-11 00:58:53 +01:00
TL_Not_AddNotesJustRetrievedToTimelineThisSession ();
2021-02-10 14:51:05 +01:00
/***** Drop temporary tables *****/
TL_DropTmpTablesUsedToQueryTimeline ();
2016-01-10 03:10:40 +01:00
}
2016-01-08 10:27:58 +01:00
2021-02-08 22:45:06 +01:00
/*****************************************************************************/
/********* Get maximum number of publications to get from database ***********/
/*****************************************************************************/
static unsigned TL_GetMaxPubsToGet (const struct TL_Timeline *Timeline)
{
static const unsigned MaxPubsToGet[TL_NUM_WHAT_TO_GET] =
{
[TL_GET_RECENT_TIMELINE] = TL_MAX_REC_PUBS_TO_GET_AND_SHOW,
2021-02-09 13:57:17 +01:00
[TL_GET_ONLY_NEW_PUBS ] = TL_MAX_NEW_PUBS_TO_GET_AND_SHOW,
2021-02-08 22:45:06 +01:00
[TL_GET_ONLY_OLD_PUBS ] = TL_MAX_OLD_PUBS_TO_GET_AND_SHOW,
};
return MaxPubsToGet[Timeline->WhatToGet];
}
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************* Get last/first publication code stored in session *************/
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
2016-01-10 16:57:02 +01:00
// FieldName can be:
// "LastPubCod"
// "FirstPubCod"
2016-01-08 10:27:58 +01:00
2019-03-12 21:25:55 +01:00
static long TL_GetPubCodFromSession (const char *FieldName)
2016-01-10 03:10:40 +01:00
{
2019-03-04 14:36:29 +01:00
extern const char *Txt_The_session_has_expired;
2016-01-10 03:10:40 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-01-10 16:57:02 +01:00
long PubCod;
2016-01-10 03:10:40 +01:00
2019-03-06 10:13:39 +01:00
/***** Get last publication code from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get publication code from session",
2019-03-13 00:54:35 +01:00
"SELECT %s FROM sessions"
" WHERE SessionId='%s'",
2018-11-01 21:59:42 +01:00
FieldName,Gbl.Session.Id) != 1)
2019-03-04 14:36:29 +01:00
Lay_ShowErrorAndExit (Txt_The_session_has_expired);
2016-01-10 03:10:40 +01:00
2019-03-06 10:13:39 +01:00
/***** Get last publication code *****/
2016-01-10 03:10:40 +01:00
row = mysql_fetch_row (mysql_res);
2016-01-10 16:57:02 +01:00
if (sscanf (row[0],"%ld",&PubCod) != 1)
PubCod = 0;
2016-01-10 03:10:40 +01:00
2016-01-23 01:38:55 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-10 16:57:02 +01:00
return PubCod;
2015-12-29 14:24:37 +01:00
}
2016-01-09 21:55:06 +01:00
/*****************************************************************************/
2021-02-10 18:41:42 +01:00
/************* Update first (oldest) and last (more recent) ***************/
/************* publication codes into session for next refresh ***************/
2016-01-09 21:55:06 +01:00
/*****************************************************************************/
2021-02-10 18:41:42 +01:00
static void TL_UpdateFirstLastPubCodesIntoSession (const struct TL_Timeline *Timeline)
2016-01-09 21:55:06 +01:00
{
2021-02-10 18:41:42 +01:00
long FirstPubCod;
2016-01-10 16:57:02 +01:00
2021-02-10 18:41:42 +01:00
switch (Timeline->WhatToGet)
{
case TL_GET_ONLY_NEW_PUBS:
DB_QueryUPDATE ("can not update first/last publication codes into session",
"UPDATE sessions"
" SET LastPubCod="
"(SELECT IFNULL(MAX(PubCod),0)"
" FROM tl_pubs)" // The most recent publication
" WHERE SessionId='%s'",
Gbl.Session.Id);
break;
case TL_GET_ONLY_OLD_PUBS:
// The oldest publication code retrieved and shown
FirstPubCod = Timeline->Pubs.Num ? Timeline->Pubs.Lst[Timeline->Pubs.Num - 1].PubCod :
0;
DB_QueryUPDATE ("can not update first/last publication codes into session",
"UPDATE sessions"
" SET FirstPubCod=%ld"
" WHERE SessionId='%s'",
FirstPubCod,
Gbl.Session.Id);
break;
case TL_GET_RECENT_TIMELINE:
// The oldest publication code retrieved and shown
FirstPubCod = Timeline->Pubs.Num ? Timeline->Pubs.Lst[Timeline->Pubs.Num - 1].PubCod :
0;
DB_QueryUPDATE ("can not update first/last publication codes into session",
"UPDATE sessions"
" SET FirstPubCod=%ld,"
"LastPubCod="
"(SELECT IFNULL(MAX(PubCod),0)"
" FROM tl_pubs)" // The most recent publication
" WHERE SessionId='%s'",
FirstPubCod,
Gbl.Session.Id);
break;
}
2021-02-08 22:33:41 +01:00
}
/*****************************************************************************/
/************* Create temporary tables used to query timeline ****************/
/*****************************************************************************/
2021-02-10 00:52:33 +01:00
static void TL_CreateTmpTableCurrentTimeline (const struct TL_Timeline *Timeline)
2021-02-08 22:33:41 +01:00
{
2021-02-10 00:52:33 +01:00
/***** Create temporary table with notes just retrieved *****/
2021-02-08 22:33:41 +01:00
DB_Query ("can not create temporary table",
2021-02-10 00:52:33 +01:00
"CREATE TEMPORARY TABLE tl_tmp_just_retrieved_notes "
"(NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod))"
2021-02-08 22:33:41 +01:00
" ENGINE=MEMORY");
2021-02-10 00:52:33 +01:00
if (Timeline->WhatToGet == TL_GET_ONLY_OLD_PUBS)
/***** Create temporary table with all notes visible in timeline *****/
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE tl_tmp_visible_timeline "
"(NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod))"
" ENGINE=MEMORY"
" SELECT NotCod FROM tl_timelines WHERE SessionId='%s'",
Gbl.Session.Id);
2021-02-09 20:42:24 +01:00
}
2021-02-08 22:33:41 +01:00
static void TL_CreateTmpTablePublishers (void)
{
/***** Create temporary table with me and the users I follow *****/
DB_Query ("can not create temporary table",
2021-02-09 00:09:14 +01:00
"CREATE TEMPORARY TABLE tl_tmp_publishers "
2021-02-08 22:33:41 +01:00
"(UsrCod INT NOT NULL,"
"UNIQUE INDEX(UsrCod))"
" ENGINE=MEMORY"
" SELECT %ld AS UsrCod" // Me
" UNION"
" SELECT FollowedCod AS UsrCod" // Users I follow
" FROM usr_follow"
" WHERE FollowerCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
2016-01-09 21:55:06 +01:00
}
2016-01-09 15:00:14 +01:00
/*****************************************************************************/
2016-01-13 00:24:26 +01:00
/*************** Drop temporary tables used to query timeline ****************/
2016-01-09 15:00:14 +01:00
/*****************************************************************************/
2021-02-08 22:33:41 +01:00
static void TL_DropTmpTablesUsedToQueryTimeline (void)
2016-01-09 15:00:14 +01:00
{
2018-11-02 22:41:02 +01:00
DB_Query ("can not remove temporary tables",
2019-11-25 13:29:56 +01:00
"DROP TEMPORARY TABLE IF EXISTS "
2021-02-10 00:52:33 +01:00
"tl_tmp_just_retrieved_notes,"
"tl_tmp_visible_timeline,"
2021-02-09 00:09:14 +01:00
"tl_tmp_publishers");
2021-02-08 22:33:41 +01:00
}
/*****************************************************************************/
/******* Create temporary table and subquery with potential publishers *******/
/*****************************************************************************/
static void TL_CreateSubQueryPublishers (const struct TL_Timeline *Timeline,
2021-02-08 23:52:51 +01:00
struct TL_SubQueries *SubQueries)
2021-02-08 22:33:41 +01:00
{
/***** Create temporary table and subquery with potential publishers *****/
switch (Timeline->UsrOrGbl)
{
2021-02-09 13:23:29 +01:00
case TL_TIMELINE_USR: // Show the timeline of a user
SubQueries->TablePublishers = "";
sprintf (SubQueries->Publishers,"tl_pubs.PublisherCod=%ld AND ",
2021-02-08 22:33:41 +01:00
Gbl.Usrs.Other.UsrDat.UsrCod);
break;
2021-02-09 13:23:29 +01:00
case TL_TIMELINE_GBL: // Show the global timeline
2021-02-08 22:33:41 +01:00
switch (Timeline->Who)
{
case Usr_WHO_ME: // Show my timeline
2021-02-09 13:23:29 +01:00
SubQueries->TablePublishers = "";
snprintf (SubQueries->Publishers,sizeof (SubQueries->Publishers),
"tl_pubs.PublisherCod=%ld AND ",
Gbl.Usrs.Me.UsrDat.UsrCod);
2021-02-08 22:33:41 +01:00
break;
case Usr_WHO_FOLLOWED: // Show the timeline of the users I follow
TL_CreateTmpTablePublishers ();
2021-02-09 13:23:29 +01:00
SubQueries->TablePublishers = ",tl_tmp_publishers";
Str_Copy (SubQueries->Publishers,
"tl_pubs.PublisherCod=tl_tmp_publishers.UsrCod AND ",
TL_MAX_BYTES_SUBQUERY);
2021-02-08 22:33:41 +01:00
break;
case Usr_WHO_ALL: // Show the timeline of all users
2021-02-09 13:23:29 +01:00
SubQueries->TablePublishers = "";
2021-02-08 23:52:51 +01:00
SubQueries->Publishers[0] = '\0';
2021-02-08 22:33:41 +01:00
break;
default:
Lay_WrongWhoExit ();
break;
}
break;
}
}
/*****************************************************************************/
/********* Create subquery to get only notes not present in timeline *********/
/*****************************************************************************/
2021-02-09 20:42:24 +01:00
static void TL_CreateSubQueryAlreadyExists (const struct TL_Timeline *Timeline,
struct TL_SubQueries *SubQueries)
2021-02-08 22:33:41 +01:00
{
2021-02-09 20:42:24 +01:00
switch (Timeline->WhatToGet)
{
case TL_GET_RECENT_TIMELINE:
2021-02-10 00:52:33 +01:00
case TL_GET_ONLY_NEW_PUBS:
2021-02-09 20:42:24 +01:00
Str_Copy (SubQueries->AlreadyExists,
" tl_pubs.NotCod NOT IN"
2021-02-10 00:52:33 +01:00
" (SELECT NotCod FROM tl_tmp_just_retrieved_notes)", // Avoid notes just retrieved
2021-02-09 20:42:24 +01:00
TL_MAX_BYTES_SUBQUERY);
2021-02-10 00:52:33 +01:00
break;
2021-02-09 20:42:24 +01:00
case TL_GET_ONLY_OLD_PUBS:
Str_Copy (SubQueries->AlreadyExists,
" tl_pubs.NotCod NOT IN"
2021-02-10 00:52:33 +01:00
" (SELECT NotCod FROM tl_tmp_visible_timeline)", // Avoid notes already shown
2021-02-09 20:42:24 +01:00
TL_MAX_BYTES_SUBQUERY);
break;
}
2016-01-09 15:00:14 +01:00
}
2021-02-08 22:56:05 +01:00
/*****************************************************************************/
/***** Create subqueries with range of publications to get from tl_pubs ******/
/*****************************************************************************/
2021-02-09 13:23:29 +01:00
static void TL_CreateSubQueryRangeBottom (const struct TL_RangePubsToGet *RangePubsToGet,
2021-02-08 23:52:51 +01:00
struct TL_SubQueries *SubQueries)
2021-02-08 22:56:05 +01:00
{
if (RangePubsToGet->Bottom > 0)
2021-02-09 13:23:29 +01:00
sprintf (SubQueries->RangeBottom,"tl_pubs.PubCod>%ld AND ",
RangePubsToGet->Bottom);
2021-02-08 22:56:05 +01:00
else
2021-02-08 23:52:51 +01:00
SubQueries->RangeBottom[0] = '\0';
2021-02-08 22:56:05 +01:00
}
2021-02-09 13:23:29 +01:00
static void TL_CreateSubQueryRangeTop (const struct TL_RangePubsToGet *RangePubsToGet,
2021-02-08 23:52:51 +01:00
struct TL_SubQueries *SubQueries)
2021-02-08 22:56:05 +01:00
{
if (RangePubsToGet->Top > 0)
2021-02-09 13:23:29 +01:00
sprintf (SubQueries->RangeTop,"tl_pubs.PubCod<%ld AND ",
RangePubsToGet->Top);
2021-02-08 22:56:05 +01:00
else
2021-02-08 23:52:51 +01:00
SubQueries->RangeTop[0] = '\0';
}
2021-02-10 10:20:35 +01:00
/*****************************************************************************/
/******** Allocate/free list to store publications/notes in timeline *********/
/*****************************************************************************/
2021-02-10 14:51:05 +01:00
static void TL_AllocateListPubs (struct TL_Timeline *Timeline,
unsigned MaxPubsToGet)
2021-02-10 10:20:35 +01:00
{
/***** Reset number of publications in list *****/
2021-02-10 14:51:05 +01:00
Timeline->Pubs.Num = 0;
2021-02-10 10:20:35 +01:00
/***** Allocate memory to store publications *****/
2021-02-10 14:51:05 +01:00
if ((Timeline->Pubs.Lst = (struct TL_Publication *) malloc (MaxPubsToGet *
sizeof (struct TL_Publication))) == NULL)
Lay_ShowErrorAndExit ("Error allocating memory for list of publications.");
2021-02-10 10:20:35 +01:00
}
2021-02-10 14:51:05 +01:00
static void TL_FreeListPubs (const struct TL_Timeline *Timeline)
2021-02-10 10:20:35 +01:00
{
/***** Free memory used for publications *****/
2021-02-10 14:51:05 +01:00
free (Timeline->Pubs.Lst);
2021-02-10 10:20:35 +01:00
}
2021-02-08 23:52:51 +01:00
/*****************************************************************************/
/************** Select the most recent publication from tl_pubs **************/
/*****************************************************************************/
2021-02-09 13:23:29 +01:00
static void TL_SelectTheMostRecentPub (const struct TL_SubQueries *SubQueries,
2021-02-10 19:53:57 +01:00
struct TL_Publication *Pub)
2021-02-08 23:52:51 +01:00
{
MYSQL_RES *mysql_res;
unsigned NumPubs = 0; // Initialized to avoid warning
2021-02-09 13:23:29 +01:00
NumPubs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get publication",
2021-02-09 19:45:03 +01:00
"SELECT tl_pubs.PubCod," // row[0]
"tl_pubs.NotCod," // row[1]
"tl_pubs.PublisherCod," // row[2]
"tl_pubs.PubType" // row[3]
2021-02-09 13:23:29 +01:00
" FROM tl_pubs%s"
" WHERE %s%s%s%s"
" ORDER BY tl_pubs.PubCod DESC LIMIT 1",
SubQueries->TablePublishers,
SubQueries->RangeBottom,
SubQueries->RangeTop,
SubQueries->Publishers,
SubQueries->AlreadyExists);
2021-02-10 00:52:33 +01:00
2021-02-08 23:52:51 +01:00
if (NumPubs == 1)
2021-02-09 19:45:03 +01:00
/* Get data of publication */
2021-02-10 19:53:57 +01:00
TL_GetDataOfPublicationFromNextRow (mysql_res,Pub);
2021-02-08 23:52:51 +01:00
else
2021-02-09 19:45:03 +01:00
/* Reset data of publication */
2021-02-11 00:58:53 +01:00
TL_Pub_ResetPublication (Pub);
2021-02-08 23:52:51 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2021-02-08 22:56:05 +01:00
}
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************************* Show timeline *******************************/
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2016-01-17 21:22:01 +01:00
/* _____
/ |_____| just_now_timeline_list (Posts retrieved automatically
| |_____| via AJAX from time to time.
| |_____| They are transferred inmediately
2016-01-17 19:56:56 +01:00
| | to new_timeline_list.)
2016-01-17 21:22:01 +01:00
Hidden < __v__
| |_____| new_timeline_list (Posts retrieved but hidden.
| |_____| When user clicks to view them,
| |_____| they are transferred
\ |_____| to visible timeline_list.)
2016-01-17 19:56:56 +01:00
|
2016-01-17 21:22:01 +01:00
__v__
/ |_____| timeline_list (Posts visible on page)
| |_____|
Visible | |_____|
on < |_____|
page | |_____|
| |_____|
\ |_____|
2016-01-17 19:56:56 +01:00
^
2016-01-17 21:22:01 +01:00
__|__
/ |_____| old_timeline_list (Posts just retrieved via AJAX
| |_____| when user clicks "see more".
| |_____| They are transferred inmediately
Hidden < |_____| to timeline_list.)
| |_____|
| |_____|
\ |_____|
2016-01-17 19:56:56 +01:00
*/
2020-04-11 00:57:25 +02:00
static void TL_ShowTimeline (struct TL_Timeline *Timeline,
2019-03-13 10:23:41 +01:00
const char *Title,long NotCodToHighlight)
2015-12-28 19:23:42 +01:00
{
2019-03-12 21:25:55 +01:00
extern const char *Hlp_START_Timeline;
2015-12-31 18:40:45 +01:00
unsigned long NumPub;
2021-02-11 00:58:53 +01:00
struct TL_Not_Note Not;
2017-02-24 03:38:18 +01:00
bool GlobalTimeline = (Gbl.Usrs.Other.UsrDat.UsrCod <= 0);
2018-10-10 23:56:42 +02:00
bool ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
2015-12-28 19:23:42 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Title,
2020-04-08 03:41:05 +02:00
TL_PutIconsTimeline,NULL,
2019-03-12 21:25:55 +01:00
Hlp_START_Timeline,Box_NOT_CLOSABLE);
2015-12-30 18:36:10 +01:00
2017-02-24 03:38:18 +01:00
/***** Put form to select users whom public activity is displayed *****/
if (GlobalTimeline)
2020-04-11 00:57:25 +02:00
TL_PutFormWho (Timeline);
2017-02-24 03:38:18 +01:00
2016-01-12 14:17:47 +01:00
/***** Form to write a new post *****/
2018-10-10 14:03:06 +02:00
if (GlobalTimeline || ItsMe)
2020-04-11 00:57:25 +02:00
TL_PutFormToWriteNewPost (Timeline);
2016-01-08 15:08:30 +01:00
2019-03-06 10:13:39 +01:00
/***** New publications refreshed dynamically via AJAX *****/
2017-02-24 03:38:18 +01:00
if (GlobalTimeline)
2016-01-14 14:24:20 +01:00
{
2019-03-06 10:13:39 +01:00
/* Link to view new publications via AJAX */
2019-03-12 21:25:55 +01:00
TL_PutLinkToViewNewPublications ();
2016-01-09 15:00:14 +01:00
2019-03-06 10:13:39 +01:00
/* Hidden list where insert just received (not visible) publications via AJAX */
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("id=\"just_now_timeline_list\" class=\"TL_LIST\"");
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2016-01-14 15:12:42 +01:00
2019-03-06 10:13:39 +01:00
/* Hidden list where insert new (not visible) publications via AJAX */
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("id=\"new_timeline_list\" class=\"TL_LIST\"");
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2016-01-14 14:24:20 +01:00
}
2016-01-10 14:27:35 +01:00
2019-03-06 10:13:39 +01:00
/***** List recent publications in timeline *****/
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("id=\"timeline_list\" class=\"TL_LIST\"");
2021-02-09 17:31:44 +01:00
for (NumPub = 0;
2021-02-10 14:51:05 +01:00
NumPub < Timeline->Pubs.Num;
2016-01-12 14:17:47 +01:00
NumPub++)
{
2019-03-12 21:25:55 +01:00
/* Get data of note */
2021-02-10 19:53:57 +01:00
Not.NotCod = Timeline->Pubs.Lst[NumPub].NotCod;
2021-02-11 00:58:53 +01:00
TL_Not_GetDataOfNoteByCod (&Not);
2016-01-05 04:54:00 +01:00
2019-03-12 21:25:55 +01:00
/* Write note */
2021-02-11 00:58:53 +01:00
TL_Not_WriteNote (Timeline,&Not,
Timeline->Pubs.Lst[NumPub].TopMessage,
Timeline->Pubs.Lst[NumPub].PublisherCod,
Not.NotCod == NotCodToHighlight ? TL_HIGHLIGHT :
TL_DONT_HIGHLIGHT,
TL_DONT_SHOW_ALONE);
2016-01-12 14:17:47 +01:00
}
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2015-12-30 18:36:10 +01:00
2021-02-10 14:51:05 +01:00
if (Timeline->Pubs.Num == TL_MAX_REC_PUBS_TO_GET_AND_SHOW)
2016-01-12 14:17:47 +01:00
{
2019-03-06 10:13:39 +01:00
/***** Link to view old publications via AJAX *****/
2019-03-12 21:25:55 +01:00
TL_PutLinkToViewOldPublications ();
2016-01-10 14:27:35 +01:00
2019-03-06 10:13:39 +01:00
/***** Hidden list where insert old publications via AJAX *****/
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("id=\"old_timeline_list\" class=\"TL_LIST\"");
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2016-01-12 14:17:47 +01:00
}
2016-01-10 14:27:35 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-01-10 03:10:40 +01:00
}
2016-11-07 10:40:27 +01:00
/*****************************************************************************/
/********************* Put contextual icons in timeline **********************/
/*****************************************************************************/
2020-04-08 03:41:05 +02:00
static void TL_PutIconsTimeline (__attribute__((unused)) void *Args)
2016-11-07 10:40:27 +01:00
{
2020-04-08 03:41:05 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_TIMELINE);
2016-11-07 10:40:27 +01:00
}
2017-02-24 10:34:21 +01:00
/*****************************************************************************/
/***************** Start a form in global or user timeline *******************/
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
void TL_FormStart (const struct TL_Timeline *Timeline,
Act_Action_t ActionGbl,
Act_Action_t ActionUsr)
2017-02-24 10:34:21 +01:00
{
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
2018-11-09 20:47:39 +01:00
Frm_StartFormAnchor (ActionUsr,"timeline");
2020-03-27 14:56:54 +01:00
Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
2017-02-24 10:34:21 +01:00
}
else
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActionGbl);
2020-04-11 00:57:25 +02:00
Usr_PutHiddenParamWho (Timeline->Who);
2017-02-24 10:34:21 +01:00
}
}
2017-02-24 03:38:18 +01:00
/*****************************************************************************/
2019-02-21 21:12:04 +01:00
/******** Show form to select users whom public activity is displayed ********/
2017-02-24 03:38:18 +01:00
/*****************************************************************************/
2020-04-11 00:57:25 +02:00
static void TL_PutFormWho (struct TL_Timeline *Timeline)
2017-02-24 03:38:18 +01:00
{
2019-11-12 00:31:41 +01:00
Usr_Who_t Who;
unsigned Mask = 1 << Usr_WHO_ME |
1 << Usr_WHO_FOLLOWED |
1 << Usr_WHO_ALL;
2017-02-24 03:38:18 +01:00
2019-03-26 11:53:21 +01:00
/***** Setting selector for which users *****/
Set_StartSettingsHead ();
Set_StartOneSettingSelector ();
2019-11-12 00:31:41 +01:00
for (Who = (Usr_Who_t) 0;
Who <= (Usr_Who_t) (Usr_NUM_WHO - 1);
Who++)
if (Mask & (1 << Who))
{
HTM_DIV_Begin ("class=\"%s\"",
2020-04-11 00:57:25 +02:00
Who == Timeline->Who ? "PREF_ON" :
"PREF_OFF");
2021-02-10 19:53:57 +01:00
Frm_StartForm (ActSeeTmlGbl);
2019-11-12 00:31:41 +01:00
Par_PutHiddenParamUnsigned (NULL,"Who",(unsigned) Who);
Usr_PutWhoIcon (Who);
Frm_EndForm ();
HTM_DIV_End ();
}
2019-03-26 11:53:21 +01:00
Set_EndOneSettingSelector ();
Set_EndSettingsHead ();
2017-02-24 11:01:28 +01:00
/***** Show warning if I do not follow anyone *****/
2020-04-11 00:57:25 +02:00
if (Timeline->Who == Usr_WHO_FOLLOWED)
2019-03-12 21:25:55 +01:00
TL_ShowWarningYouDontFollowAnyUser ();
2017-02-24 03:38:18 +01:00
}
/*****************************************************************************/
/********* Get parameter with which users to view in global timeline *********/
/*****************************************************************************/
2020-04-11 00:57:25 +02:00
void TL_GetParamWho (void)
2017-02-24 03:38:18 +01:00
{
2020-04-11 00:57:25 +02:00
Usr_Who_t Who;
2017-02-24 03:38:18 +01:00
/***** Get which users I want to see *****/
2020-04-11 00:57:25 +02:00
Who = Usr_GetHiddenParamWho ();
2019-11-12 00:31:41 +01:00
/***** If parameter Who is not present, get it from database *****/
2020-04-11 00:57:25 +02:00
if (Who == Usr_WHO_UNKNOWN)
Who = TL_GetWhoFromDB ();
2019-11-12 00:31:41 +01:00
/***** If parameter Who is unknown, set it to default *****/
2020-04-11 00:57:25 +02:00
if (Who == Usr_WHO_UNKNOWN)
Who = TL_DEFAULT_WHO;
/***** Set global variable *****/
2021-02-11 00:58:53 +01:00
TL_SetGlobalWho (Who);
2019-02-21 20:04:05 +01:00
}
/*****************************************************************************/
2020-04-11 00:57:25 +02:00
/********* Get which users to view in global timeline from database **********/
2019-02-21 20:04:05 +01:00
/*****************************************************************************/
2019-11-12 00:31:41 +01:00
static Usr_Who_t TL_GetWhoFromDB (void)
2019-02-21 20:04:05 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned UnsignedNum;
2019-11-12 00:31:41 +01:00
Usr_Who_t Who = Usr_WHO_UNKNOWN;
2019-02-21 20:04:05 +01:00
/***** Get which users from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get timeline users from user's last data",
"SELECT TimelineUsrs" // row[0]
" FROM usr_last WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod) == 1)
{
row = mysql_fetch_row (mysql_res);
2019-11-12 00:31:41 +01:00
/* Get who */
2019-02-21 20:04:05 +01:00
if (sscanf (row[0],"%u",&UnsignedNum) == 1)
2019-11-12 00:31:41 +01:00
if (UnsignedNum < Usr_NUM_WHO)
Who = (Usr_Who_t) UnsignedNum;
2019-02-21 20:04:05 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2019-11-12 00:31:41 +01:00
return Who;
2019-02-21 20:04:05 +01:00
}
/*****************************************************************************/
2020-04-11 00:57:25 +02:00
/******** Save which users to view in global timeline into database **********/
2019-02-21 20:04:05 +01:00
/*****************************************************************************/
2020-04-11 00:57:25 +02:00
static void TL_SaveWhoInDB (struct TL_Timeline *Timeline)
2019-02-21 20:04:05 +01:00
{
if (Gbl.Usrs.Me.Logged)
{
2020-04-11 00:57:25 +02:00
if (Timeline->Who == Usr_WHO_UNKNOWN)
Timeline->Who = TL_DEFAULT_WHO;
2019-02-21 20:04:05 +01:00
/***** Update which users in database *****/
2019-11-12 00:31:41 +01:00
// Who is stored in usr_last for next time I log in
2019-02-21 20:04:05 +01:00
DB_QueryUPDATE ("can not update timeline users in user's last data",
2019-04-01 11:15:38 +02:00
"UPDATE usr_last SET TimelineUsrs=%u"
" WHERE UsrCod=%ld",
2020-04-11 00:57:25 +02:00
(unsigned) Timeline->Who,
2019-02-21 20:04:05 +01:00
Gbl.Usrs.Me.UsrDat.UsrCod);
}
2017-02-24 03:38:18 +01:00
}
2020-04-11 00:57:25 +02:00
/*****************************************************************************/
/**** Set/get global variable with which users to view in global timeline ****/
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
static void TL_SetGlobalWho (Usr_Who_t Who)
2020-04-11 00:57:25 +02:00
{
TL_GlobalWho = Who;
}
Usr_Who_t TL_GetGlobalWho (void)
{
return TL_GlobalWho;
}
2017-02-24 11:01:28 +01:00
/*****************************************************************************/
/********* Get parameter with which users to view in global timeline *********/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_ShowWarningYouDontFollowAnyUser (void)
2017-02-24 11:01:28 +01:00
{
extern const char *Txt_You_dont_follow_any_user;
2019-02-22 14:04:54 +01:00
unsigned NumFollowing;
unsigned NumFollowers;
2017-02-24 11:01:28 +01:00
/***** Check if I follow someone *****/
2019-02-22 14:04:54 +01:00
Fol_GetNumFollow (Gbl.Usrs.Me.UsrDat.UsrCod,&NumFollowing,&NumFollowers);
if (!NumFollowing)
2017-02-24 11:01:28 +01:00
{
/***** Show warning if I do not follow anyone *****/
2019-02-16 18:25:41 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_You_dont_follow_any_user);
2017-02-24 11:01:28 +01:00
2019-10-24 09:46:20 +02:00
/***** Contextual menu *****/
Mnu_ContextMenuBegin ();
Fol_PutLinkWhoToFollow (); // Users to follow
Mnu_ContextMenuEnd ();
2017-02-24 11:01:28 +01:00
}
}
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************* Show new publications in timeline ***********************/
2016-01-10 03:10:40 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
// The publications are inserted as list elements of a hidden list
2016-01-09 21:55:06 +01:00
2021-02-10 00:52:33 +01:00
static void TL_InsertNewPubsInTimeline (struct TL_Timeline *Timeline)
2016-01-10 03:10:40 +01:00
{
unsigned long NumPub;
2021-02-11 00:58:53 +01:00
struct TL_Not_Note Not;
2016-01-10 03:10:40 +01:00
2019-03-06 10:13:39 +01:00
/***** List new publications timeline *****/
2016-01-10 03:10:40 +01:00
for (NumPub = 0;
2021-02-10 14:51:05 +01:00
NumPub < Timeline->Pubs.Num;
2016-01-10 03:10:40 +01:00
NumPub++)
{
2019-03-12 21:25:55 +01:00
/* Get data of note */
2021-02-10 19:53:57 +01:00
Not.NotCod = Timeline->Pubs.Lst[NumPub].NotCod;
2021-02-11 00:58:53 +01:00
TL_Not_GetDataOfNoteByCod (&Not);
2016-01-10 03:10:40 +01:00
2019-03-12 21:25:55 +01:00
/* Write note */
2021-02-11 00:58:53 +01:00
TL_Not_WriteNote (Timeline,&Not,
2021-02-10 14:51:05 +01:00
Timeline->Pubs.Lst[NumPub].TopMessage,
Timeline->Pubs.Lst[NumPub].PublisherCod,
2021-02-11 00:58:53 +01:00
TL_DONT_HIGHLIGHT,
TL_DONT_SHOW_ALONE);
2016-01-10 03:10:40 +01:00
}
2016-01-10 16:57:02 +01:00
}
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********************* Show old publications in timeline *********************/
2016-01-10 16:57:02 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
// The publications are inserted as list elements of a hidden list
2016-01-10 16:57:02 +01:00
2021-02-10 00:52:33 +01:00
static void TL_ShowOldPubsInTimeline (struct TL_Timeline *Timeline)
2016-01-10 16:57:02 +01:00
{
unsigned long NumPub;
2021-02-11 00:58:53 +01:00
struct TL_Not_Note Not;
2016-01-10 16:57:02 +01:00
2019-03-06 10:13:39 +01:00
/***** List old publications in timeline *****/
2021-02-10 00:52:33 +01:00
for (NumPub = 0;
2021-02-10 14:51:05 +01:00
NumPub < Timeline->Pubs.Num;
2016-01-17 01:50:43 +01:00
NumPub++)
2016-01-10 16:57:02 +01:00
{
2019-03-12 21:25:55 +01:00
/* Get data of note */
2021-02-10 19:53:57 +01:00
Not.NotCod = Timeline->Pubs.Lst[NumPub].NotCod;
2021-02-11 00:58:53 +01:00
TL_Not_GetDataOfNoteByCod (&Not);
2016-01-10 16:57:02 +01:00
2019-03-12 21:25:55 +01:00
/* Write note */
2021-02-11 00:58:53 +01:00
TL_Not_WriteNote (Timeline,&Not,
2021-02-10 14:51:05 +01:00
Timeline->Pubs.Lst[NumPub].TopMessage,
Timeline->Pubs.Lst[NumPub].PublisherCod,
2021-02-11 00:58:53 +01:00
TL_DONT_HIGHLIGHT,
TL_DONT_SHOW_ALONE);
2016-01-10 16:57:02 +01:00
}
2015-12-28 19:23:42 +01:00
}
2016-01-09 19:06:01 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
/***************** Put link to view new publications in timeline *************/
2016-01-09 19:06:01 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutLinkToViewNewPublications (void)
2016-01-09 19:06:01 +01:00
{
2019-02-24 15:15:43 +01:00
extern const char *The_ClassFormInBoxBold[The_NUM_THEMES];
2016-01-09 20:11:44 +01:00
extern const char *Txt_See_new_activity;
2016-01-09 19:06:01 +01:00
2019-03-06 10:13:39 +01:00
/***** Link to view (show hidden) new publications *****/
2016-01-09 20:11:44 +01:00
// div is hidden. When new posts arrive to the client via AJAX, div is shown
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"view_new_posts_container\""
" class=\"TL_WIDTH TL_SEP VERY_LIGHT_BLUE\""
" style=\"display:none;\"");
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"\" class=\"%s\""
" onclick=\"moveNewTimelineToTimeline();return false;\"",
The_ClassFormInBoxBold[Gbl.Prefs.Theme]);
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%s (",Txt_See_new_activity);
2019-11-07 10:24:00 +01:00
HTM_SPAN_Begin ("id=\"view_new_posts_count\"");
2019-11-10 13:51:07 +01:00
HTM_Unsigned (0);
2019-11-07 10:24:00 +01:00
HTM_SPAN_End ();
2019-11-10 13:51:07 +01:00
HTM_Txt (")");
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-09 19:06:01 +01:00
}
2016-01-10 14:27:35 +01:00
/*****************************************************************************/
2019-03-06 10:13:39 +01:00
/***************** Put link to view old publications in timeline *************/
2016-01-10 14:27:35 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_PutLinkToViewOldPublications (void)
2016-01-10 14:27:35 +01:00
{
2019-02-24 15:15:43 +01:00
extern const char *The_ClassFormInBoxBold[The_NUM_THEMES];
2016-01-10 14:27:35 +01:00
extern const char *Txt_See_more;
2019-03-06 10:13:39 +01:00
/***** Animated link to view old publications *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"view_old_posts_container\""
" class=\"TL_WIDTH TL_SEP VERY_LIGHT_BLUE\"");
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"\" class=\"%s\" onclick=\""
"document.getElementById('get_old_timeline').style.display='none';" // Icon to be hidden on click
"document.getElementById('getting_old_timeline').style.display='';" // Icon to be shown on click
"refreshOldTimeline();"
"return false;\"",
The_ClassFormInBoxBold[Gbl.Prefs.Theme]);
2019-10-30 00:42:01 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,"recycle16x16.gif","Txt_See_more",
2019-10-30 22:31:03 +01:00
"class=\"ICO20x20\" id=\"get_old_timeline\"");
2019-10-30 00:42:01 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,"working16x16.gif",Txt_See_more,
2019-10-30 22:31:03 +01:00
"class=\"ICO20x20\" style=\"display:none;\" id=\"getting_old_timeline\""); // Animated icon hidden
2019-10-30 00:42:01 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,"recycle16x16.gif","Txt_See_more",
2019-10-30 22:31:03 +01:00
"class=\"ICO20x20\" style=\"display:none;\" id=\"get_old_timeline\"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",Txt_See_more);
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-10 14:27:35 +01:00
}
2016-01-13 12:59:23 +01:00
/*****************************************************************************/
/*************** Write sharer/commenter if distinct to author ****************/
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
void TL_WriteTopMessage (TL_TopMessage_t TopMessage,long PublisherCod)
2016-01-13 12:59:23 +01:00
{
2017-02-17 01:59:58 +01:00
extern const char *Txt_My_public_profile;
extern const char *Txt_Another_user_s_profile;
2019-03-12 21:25:55 +01:00
extern const char *Txt_TIMELINE_NOTE_TOP_MESSAGES[TL_NUM_TOP_MESSAGES];
2021-02-09 17:31:44 +01:00
struct UsrData PublisherDat;
bool ItsMe = Usr_ItsMe (PublisherCod);
2016-01-13 12:59:23 +01:00
2019-03-12 21:25:55 +01:00
if (TopMessage != TL_TOP_MESSAGE_NONE)
2016-01-19 00:50:35 +01:00
{
2017-02-17 06:32:57 +01:00
/***** Initialize structure with user's data *****/
2021-02-09 17:31:44 +01:00
Usr_UsrDataConstructor (&PublisherDat);
2017-02-17 01:59:58 +01:00
2017-02-17 06:32:57 +01:00
/***** Get user's data *****/
2021-02-09 17:31:44 +01:00
PublisherDat.UsrCod = PublisherCod;
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&PublisherDat,Usr_DONT_GET_PREFS)) // Really we only need EncryptedUsrCod and FullName
2016-01-13 12:59:23 +01:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_TOP_CONT TL_TOP_PUBLISHER TL_WIDTH\"");
2016-01-19 00:50:35 +01:00
/***** Show user's name inside form to go to user's public profile *****/
2018-11-09 20:47:39 +01:00
Frm_StartFormUnique (ActSeeOthPubPrf);
2021-02-09 17:31:44 +01:00
Usr_PutParamUsrCodEncrypted (PublisherDat.EncryptedUsrCod);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (ItsMe ? Txt_My_public_profile :
2019-11-20 11:04:54 +01:00
Txt_Another_user_s_profile,
"BT_LINK TL_TOP_PUBLISHER",NULL);
2021-02-09 17:31:44 +01:00
HTM_Txt (PublisherDat.FullName);
2019-11-18 20:12:10 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-01-13 12:59:23 +01:00
2016-01-19 00:50:35 +01:00
/***** Show action made *****/
2019-11-11 00:15:44 +01:00
HTM_TxtF (" %s:",Txt_TIMELINE_NOTE_TOP_MESSAGES[TopMessage]);
2019-10-24 00:04:40 +02:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-13 12:59:23 +01:00
}
2016-01-19 00:50:35 +01:00
2017-02-17 06:32:57 +01:00
/***** Free memory used for user's data *****/
2021-02-09 17:31:44 +01:00
Usr_UsrDataDestructor (&PublisherDat);
2016-01-19 00:50:35 +01:00
}
2016-01-13 12:59:23 +01:00
}
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************* Write the date of creation of a note ********************/
2015-12-28 19:23:42 +01:00
/*****************************************************************************/
// TimeUTC holds UTC date and time in UNIX format (seconds since 1970)
2021-02-11 00:58:53 +01:00
void TL_WriteDateTime (time_t TimeUTC)
2015-12-28 19:23:42 +01:00
{
2018-11-09 20:47:39 +01:00
char IdDateTime[Frm_MAX_BYTES_ID + 1];
2015-12-28 19:23:42 +01:00
2016-01-11 19:28:43 +01:00
/***** Create unique Id *****/
2018-11-09 20:47:39 +01:00
Frm_SetUniqueId (IdDateTime);
2016-01-10 23:00:15 +01:00
/***** Container where the date-time is written *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"%s\" class=\"TL_RIGHT_TIME DAT_LIGHT\"",IdDateTime);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-10 23:00:15 +01:00
/***** Script to write date and time in browser local time *****/
// This must be out of the div where the output is written
// because it will be evaluated in a loop in JavaScript
2019-11-01 23:35:55 +01:00
Dat_WriteLocalDateHMSFromUTC (IdDateTime,TimeUTC,
2019-11-02 12:10:58 +01:00
Gbl.Prefs.DateFormat,Dat_SEPARATOR_COMMA,
2019-11-02 11:45:41 +01:00
true,true,false,0x6);
2015-12-28 19:23:42 +01:00
}
2016-01-02 01:56:48 +01:00
/*****************************************************************************/
/***************** Get from database and write public post *******************/
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
void TL_GetAndWritePost (long PstCod)
2016-01-02 01:56:48 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
2021-02-08 16:24:29 +01:00
struct TL_PostContent Content;
2016-04-08 16:37:59 +02:00
/***** Initialize image *****/
2019-11-24 23:51:03 +01:00
Med_MediaConstructor (&Content.Media);
2016-01-02 01:56:48 +01:00
2019-03-12 21:25:55 +01:00
/***** Get post from database *****/
2018-11-01 21:59:42 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get the content"
2019-03-12 21:25:55 +01:00
" of a post",
2019-11-25 09:06:27 +01:00
"SELECT Txt," // row[0]
2019-03-18 15:42:22 +01:00
"MedCod" // row[1]
2019-11-25 13:29:56 +01:00
" FROM tl_posts"
2019-03-12 21:25:55 +01:00
" WHERE PstCod=%ld",
2018-11-01 21:59:42 +01:00
PstCod);
2016-01-02 01:56:48 +01:00
/***** Result should have a unique row *****/
if (NumRows == 1)
{
2016-01-27 13:20:08 +01:00
row = mysql_fetch_row (mysql_res);
2016-04-08 16:37:59 +02:00
/****** Get content (row[0]) *****/
2019-11-24 23:51:03 +01:00
Str_Copy (Content.Txt,row[0],
2017-01-17 03:10:43 +01:00
Cns_MAX_BYTES_LONG_TEXT);
2016-04-08 16:37:59 +02:00
2019-03-18 15:42:22 +01:00
/***** Get media (row[1]) *****/
2019-11-24 23:51:03 +01:00
Content.Media.MedCod = Str_ConvertStrCodToLongCod (row[1]);
Med_GetMediaDataByCod (&Content.Media);
2016-01-02 01:56:48 +01:00
}
else
2019-11-24 23:51:03 +01:00
Content.Txt[0] = '\0';
2016-01-02 01:56:48 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Write content *****/
2019-11-24 23:51:03 +01:00
if (Content.Txt[0])
2016-04-15 14:30:28 +02:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_TXT\"");
2019-11-24 23:51:03 +01:00
Msg_WriteMsgContent (Content.Txt,Cns_MAX_BYTES_LONG_TEXT,true,false);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-04-15 14:30:28 +02:00
}
2016-04-08 16:37:59 +02:00
/***** Show image *****/
2019-11-24 23:51:03 +01:00
Med_ShowMedia (&Content.Media,"TL_PST_MED_CONT TL_RIGHT_WIDTH",
"TL_PST_MED TL_RIGHT_WIDTH");
2016-04-08 16:37:59 +02:00
2016-04-08 23:30:43 +02:00
/***** Free image *****/
2019-11-24 23:51:03 +01:00
Med_MediaDestructor (&Content.Media);
2016-01-02 01:56:48 +01:00
}
2015-12-29 13:18:25 +01:00
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
/********************* Publish note/comment in timeline **********************/
2016-01-01 20:19:43 +01:00
/*****************************************************************************/
2021-02-10 19:53:57 +01:00
// Pub->PubCod is set by the function
2016-01-01 20:19:43 +01:00
2021-02-11 00:58:53 +01:00
void TL_PublishPubInTimeline (struct TL_Publication *Pub)
2016-01-01 20:19:43 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Publish note in timeline *****/
2021-02-10 19:53:57 +01:00
Pub->PubCod =
2021-02-11 00:58:53 +01:00
DB_QueryINSERTandReturnCode ("can not publish note/comment",
2019-11-25 13:29:56 +01:00
"INSERT INTO tl_pubs"
2018-11-03 01:45:36 +01:00
" (NotCod,PublisherCod,PubType,TimePublish)"
" VALUES"
" (%ld,%ld,%u,NOW())",
2021-02-10 19:53:57 +01:00
Pub->NotCod,
Pub->PublisherCod,
(unsigned) Pub->PubType);
2019-03-06 10:13:39 +01:00
2019-03-12 21:25:55 +01:00
/***** Increment number of publications in user's figures *****/
2021-02-10 19:53:57 +01:00
Prf_IncrementNumPubsUsr (Pub->PublisherCod);
2015-12-28 20:46:48 +01:00
}
2015-12-30 02:08:08 +01:00
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/********************** Form to write a new publication **********************/
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
2020-04-11 00:57:25 +02:00
static void TL_PutFormToWriteNewPost (struct TL_Timeline *Timeline)
2015-12-30 12:40:13 +01:00
{
2019-03-12 21:25:55 +01:00
extern const char *Txt_New_TIMELINE_post;
2016-01-08 15:08:30 +01:00
bool ShowPhoto;
2017-01-15 22:58:26 +01:00
char PhotoURL[PATH_MAX + 1];
2015-12-30 12:40:13 +01:00
2016-01-09 15:00:14 +01:00
/***** Start list *****/
2019-10-26 12:25:27 +02:00
HTM_UL_Begin ("class=\"TL_LIST\"");
2019-10-26 22:49:13 +02:00
HTM_LI_Begin ("class=\"TL_WIDTH\"");
2016-01-08 15:08:30 +01:00
2016-01-20 14:07:15 +01:00
/***** Left: write author's photo (my photo) *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_LEFT_PHOTO\"");
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (&Gbl.Usrs.Me.UsrDat,PhotoURL);
2016-01-08 15:08:30 +01:00
Pho_ShowUsrPhoto (&Gbl.Usrs.Me.UsrDat,ShowPhoto ? PhotoURL :
NULL,
2019-03-29 11:24:02 +01:00
"PHOTO45x60",Pho_ZOOM,false);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-02 01:56:48 +01:00
2019-11-20 10:17:42 +01:00
/***** Right: author's name, time, textarea *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_RIGHT_CONT TL_RIGHT_WIDTH\"");
2016-01-02 01:56:48 +01:00
2019-11-20 10:17:42 +01:00
/* Author name */
2021-02-11 00:58:53 +01:00
TL_Not_WriteAuthorNote (&Gbl.Usrs.Me.UsrDat);
2019-11-07 10:24:00 +01:00
2019-11-20 10:17:42 +01:00
/* Form to write the post */
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_FORM_NEW_PST TL_RIGHT_WIDTH\"");
2021-02-10 19:53:57 +01:00
TL_FormStart (Timeline,ActRcvTL_PstGbl,ActRcvTL_PstUsr);
2019-11-20 10:17:42 +01:00
TL_PutTextarea (Txt_New_TIMELINE_post,"TL_PST_TEXTAREA TL_RIGHT_WIDTH");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-11-20 10:17:42 +01:00
HTM_DIV_End ();
2015-12-30 12:40:13 +01:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-08 15:08:30 +01:00
2016-01-09 15:00:14 +01:00
/***** End list *****/
2019-10-26 22:49:13 +02:00
HTM_LI_End ();
2019-10-26 02:19:42 +02:00
HTM_UL_End ();
2015-12-30 12:40:13 +01:00
}
2016-01-15 10:48:49 +01:00
/*****************************************************************************/
/*** Put textarea and button inside a form to submit a new post or comment ***/
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
void TL_PutTextarea (const char *Placeholder,const char *ClassTextArea)
2016-01-15 10:48:49 +01:00
{
extern const char *Txt_Post;
2018-11-09 20:47:39 +01:00
char IdDivImgButton[Frm_MAX_BYTES_ID + 1];
2016-01-15 10:48:49 +01:00
2016-04-08 17:38:24 +02:00
/***** Set unique id for the hidden div *****/
2018-11-09 20:47:39 +01:00
Frm_SetUniqueId (IdDivImgButton);
2016-01-15 10:48:49 +01:00
/***** Textarea to write the content *****/
2019-11-24 23:51:03 +01:00
HTM_TEXTAREA_Begin ("name=\"Txt\" rows=\"1\" maxlength=\"%u\""
2019-10-31 17:42:05 +01:00
" placeholder=\"%s&hellip;\" class=\"%s\""
" onfocus=\"expandTextarea(this,'%s','6');\"",
TL_MAX_CHARS_IN_POST,
Placeholder,ClassTextArea,
IdDivImgButton);
HTM_TEXTAREA_End ();
2016-04-08 17:38:24 +02:00
/***** Start concealable div *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("id=\"%s\" style=\"display:none;\"",IdDivImgButton);
2016-04-08 17:38:24 +02:00
/***** Help on editor *****/
Lay_HelpPlainEditor ();
2016-01-15 10:48:49 +01:00
2016-04-08 16:37:59 +02:00
/***** Attached image (optional) *****/
2019-03-28 08:32:47 +01:00
Med_PutMediaUploader (-1,"TL_MED_INPUT_WIDTH");
2016-04-08 02:16:23 +02:00
2016-04-08 17:38:24 +02:00
/***** Submit button *****/
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (NULL,"BT_SUBMIT_INLINE BT_CREATE",NULL);
2019-11-11 00:15:44 +01:00
HTM_Txt (Txt_Post);
HTM_BUTTON_End ();
2016-04-08 17:38:24 +02:00
/***** End hidden div *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-15 10:48:49 +01:00
}
2015-12-30 12:40:13 +01:00
/*****************************************************************************/
/******************* Receive and store a new public post *********************/
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_ReceivePostUsr (void)
2016-01-02 01:56:48 +01:00
{
2020-04-11 00:57:25 +02:00
struct TL_Timeline Timeline;
2019-12-05 15:47:23 +01:00
long NotCod;
2020-04-11 00:57:25 +02:00
/***** Reset timeline context *****/
TL_ResetTimeline (&Timeline);
2016-01-02 01:56:48 +01:00
/***** Get user whom profile is displayed *****/
Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ();
2016-01-15 14:46:44 +01:00
/***** Show user's profile *****/
2016-06-12 19:55:33 +02:00
Prf_ShowUserProfile (&Gbl.Usrs.Other.UsrDat);
2016-01-02 01:56:48 +01:00
2016-01-02 02:33:23 +01:00
/***** Start section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (TL_TIMELINE_SECTION_ID);
2016-01-02 02:33:23 +01:00
2019-03-29 01:23:33 +01:00
/***** Receive and store post, and
write updated timeline after publication (user) *****/
2019-12-05 15:47:23 +01:00
NotCod = TL_ReceivePost ();
2020-04-11 00:57:25 +02:00
TL_ShowTimelineUsrHighlightingNot (&Timeline,NotCod);
2016-01-02 02:33:23 +01:00
/***** End section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2016-01-02 01:56:48 +01:00
}
2019-03-29 01:23:33 +01:00
void TL_ReceivePostGbl (void)
{
2020-04-11 00:57:25 +02:00
struct TL_Timeline Timeline;
2019-03-29 01:23:33 +01:00
long NotCod;
2020-04-11 00:57:25 +02:00
/***** Initialize timeline *****/
TL_InitTimelineGbl (&Timeline);
2019-03-29 01:23:33 +01:00
/***** Receive and store post *****/
NotCod = TL_ReceivePost ();
/***** Write updated timeline after publication (global) *****/
2020-04-11 00:57:25 +02:00
TL_ShowTimelineGblHighlightingNot (&Timeline,NotCod);
2019-03-29 01:23:33 +01:00
}
2019-03-12 21:25:55 +01:00
// Returns the code of the note just created
static long TL_ReceivePost (void)
2015-12-30 12:40:13 +01:00
{
2021-02-08 16:24:29 +01:00
struct TL_PostContent Content;
2015-12-30 12:40:13 +01:00
long PstCod;
2021-02-10 19:53:57 +01:00
struct TL_Publication Pub;
2015-12-30 12:40:13 +01:00
2016-01-15 14:46:44 +01:00
/***** Get the content of the new post *****/
2019-11-24 23:51:03 +01:00
Par_GetParAndChangeFormat ("Txt",Content.Txt,Cns_MAX_BYTES_LONG_TEXT,
2015-12-30 12:40:13 +01:00
Str_TO_RIGOROUS_HTML,true);
2016-04-08 23:30:43 +02:00
/***** Initialize image *****/
2019-11-24 23:51:03 +01:00
Med_MediaConstructor (&Content.Media);
2016-04-08 23:30:43 +02:00
2016-04-08 16:37:59 +02:00
/***** Get attached image (action, file and title) *****/
2019-11-24 23:51:03 +01:00
Content.Media.Width = TL_IMAGE_SAVED_MAX_WIDTH;
Content.Media.Height = TL_IMAGE_SAVED_MAX_HEIGHT;
Content.Media.Quality = TL_IMAGE_SAVED_QUALITY;
2020-03-17 00:35:11 +01:00
Med_GetMediaFromForm (-1L,-1L,-1,&Content.Media,NULL,NULL);
2019-03-17 14:47:58 +01:00
Ale_ShowAlerts (NULL);
2016-04-08 16:37:59 +02:00
2019-11-24 23:51:03 +01:00
if (Content.Txt[0] || // Text not empty
Content.Media.Status == Med_PROCESSED) // A media is attached
2016-01-09 15:00:14 +01:00
{
2019-03-19 11:20:29 +01:00
/***** Store media in filesystem and database *****/
2019-11-24 23:51:03 +01:00
Med_RemoveKeepOrStoreMedia (-1L,&Content.Media);
2019-03-18 15:42:22 +01:00
2016-01-11 01:30:23 +01:00
/***** Publish *****/
2016-01-09 15:00:14 +01:00
/* Insert post content in the database */
2018-11-03 01:45:36 +01:00
PstCod =
DB_QueryINSERTandReturnCode ("can not create post",
2019-11-25 13:29:56 +01:00
"INSERT INTO tl_posts"
2019-11-25 09:06:27 +01:00
" (Txt,MedCod)"
2018-11-03 01:45:36 +01:00
" VALUES"
2019-03-18 15:42:22 +01:00
" ('%s',%ld)",
2019-11-24 23:51:03 +01:00
Content.Txt,
Content.Media.MedCod);
2015-12-30 12:40:13 +01:00
2019-03-12 21:25:55 +01:00
/* Insert post in notes */
2021-02-11 00:58:53 +01:00
TL_Not_StoreAndPublishNoteInternal (TL_NOTE_POST,PstCod,&Pub);
2016-01-25 11:43:14 +01:00
/***** Analyze content and store notifications about mentions *****/
2021-02-10 19:53:57 +01:00
Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (Pub.PubCod,Content.Txt);
2016-01-09 15:00:14 +01:00
}
2016-04-08 23:30:43 +02:00
else // Text and image are empty
2021-02-10 19:53:57 +01:00
Pub.NotCod = -1L;
2016-01-15 14:46:44 +01:00
2016-04-08 23:30:43 +02:00
/***** Free image *****/
2019-11-24 23:51:03 +01:00
Med_MediaDestructor (&Content.Media);
2016-04-08 16:37:59 +02:00
2021-02-10 19:53:57 +01:00
return Pub.NotCod;
2015-12-30 12:40:13 +01:00
}
2016-01-07 00:42:35 +01:00
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
/*************** Put parameter with the code of a publication ****************/
2016-01-07 00:42:35 +01:00
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
void TL_PutHiddenParamPubCod (long PubCod)
2016-01-07 00:42:35 +01:00
{
2021-02-11 00:58:53 +01:00
Par_PutHiddenParamLong (NULL,"PubCod",PubCod);
2016-01-07 11:31:36 +01:00
}
2016-01-19 02:08:44 +01:00
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
/**************** Get parameter with the code of a publication ***************/
2016-01-19 02:08:44 +01:00
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
long TL_GetParamPubCod (void)
2016-01-19 02:08:44 +01:00
{
2021-02-11 00:58:53 +01:00
/***** Get comment code *****/
return Par_GetParToLong ("PubCod");
2016-01-19 02:08:44 +01:00
}
2016-01-08 15:08:30 +01:00
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
/*********** Create a notification for the author of a post/comment **********/
2016-01-08 15:08:30 +01:00
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
void TL_CreateNotifToAuthor (long AuthorCod,long PubCod,
Ntf_NotifyEvent_t NotifyEvent)
2016-01-08 15:08:30 +01:00
{
2021-02-11 00:58:53 +01:00
struct UsrData UsrDat;
bool CreateNotif;
bool NotifyByEmail;
2016-01-08 15:08:30 +01:00
2021-02-11 00:58:53 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2016-01-20 14:07:15 +01:00
2021-02-11 00:58:53 +01:00
UsrDat.UsrCod = AuthorCod;
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS))
{
/***** This fav must be notified by email? *****/
CreateNotif = (UsrDat.NtfEvents.CreateNotif & (1 << NotifyEvent));
NotifyByEmail = CreateNotif &&
(UsrDat.NtfEvents.SendEmail & (1 << NotifyEvent));
2016-01-08 15:08:30 +01:00
2021-02-11 00:58:53 +01:00
/***** Create notification for the author of the post.
If this author wants to receive notifications by email,
activate the sending of a notification *****/
if (CreateNotif)
Ntf_StoreNotifyEventToOneUser (NotifyEvent,&UsrDat,PubCod,
(Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL :
0),
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ctr.CtrCod,
Gbl.Hierarchy.Deg.DegCod,
Gbl.Hierarchy.Crs.CrsCod);
2019-03-18 15:42:22 +01:00
}
2016-01-20 14:29:42 +01:00
2021-02-11 00:58:53 +01:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
2016-01-01 20:19:43 +01:00
}
2016-01-25 20:28:33 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/*********************** Get code of note of a publication *******************/
2016-01-25 20:28:33 +01:00
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
static long TL_Pub_GetNotCodFromPubCod (long PubCod)
2016-01-25 20:28:33 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long NotCod = -1L;
2019-03-12 21:25:55 +01:00
/***** Get code of note from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get code of note",
2019-11-25 13:29:56 +01:00
"SELECT NotCod FROM tl_pubs"
2019-03-12 21:25:55 +01:00
" WHERE PubCod=%ld",
2018-11-01 21:59:42 +01:00
PubCod) == 1) // Result should have a unique row
2016-01-25 20:28:33 +01:00
{
2019-03-12 21:25:55 +01:00
/* Get code of note */
2016-01-25 20:28:33 +01:00
row = mysql_fetch_row (mysql_res);
NotCod = Str_ConvertStrCodToLongCod (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NotCod;
}
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/*************** Get code of publication of the original note ****************/
2016-01-24 14:26:35 +01:00
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
long TL_Not_GetPubCodOfOriginalNote (long NotCod)
2016-01-24 14:26:35 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-01-25 20:28:33 +01:00
long OriginalPubCod = -1L;
2016-01-24 14:26:35 +01:00
2019-03-12 21:25:55 +01:00
/***** Get code of publication of the original note *****/
if (DB_QuerySELECT (&mysql_res,"can not get code of publication",
2019-11-25 13:29:56 +01:00
"SELECT PubCod FROM tl_pubs"
2018-11-01 21:59:42 +01:00
" WHERE NotCod=%ld AND PubType=%u",
2019-03-12 21:25:55 +01:00
NotCod,(unsigned) TL_PUB_ORIGINAL_NOTE) == 1) // Result should have a unique row
2016-01-24 14:26:35 +01:00
{
2019-03-12 21:25:55 +01:00
/* Get code of publication (row[0]) */
2016-01-24 14:26:35 +01:00
row = mysql_fetch_row (mysql_res);
2016-01-25 20:28:33 +01:00
OriginalPubCod = Str_ConvertStrCodToLongCod (row[0]);
2016-01-24 14:26:35 +01:00
}
2016-01-25 20:28:33 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return OriginalPubCod;
2016-01-24 14:26:35 +01:00
}
2016-01-08 10:13:28 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/************* Remove all the content of a user from database ****************/
2016-01-08 10:13:28 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_RemoveUsrContent (long UsrCod)
2016-01-08 10:13:28 +01:00
{
2016-01-20 14:29:42 +01:00
/***** Remove favs for comments *****/
2019-03-12 21:25:55 +01:00
/* Remove all favs made by this user in any comment */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove favs",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments_fav"
2019-03-12 21:25:55 +01:00
" WHERE UsrCod=%ld",
2018-11-02 22:00:31 +01:00
UsrCod);
2016-01-20 14:29:42 +01:00
/* Remove all favs for all comments of this user */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove favs",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments_fav"
" USING tl_pubs,tl_comments_fav"
" WHERE tl_pubs.PublisherCod=%ld" // Author of the comment
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments_fav.PubCod",
2019-03-12 21:25:55 +01:00
UsrCod,(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-20 14:29:42 +01:00
2019-03-12 21:25:55 +01:00
/* Remove all favs for all comments in all the notes of the user */
DB_QueryDELETE ("can not remove comments",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments_fav"
" USING tl_notes,tl_pubs,tl_comments_fav"
" WHERE tl_notes.UsrCod=%ld" // Author of the note
" AND tl_notes.NotCod=tl_pubs.NotCod"
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments_fav.PubCod",
2019-03-12 21:25:55 +01:00
UsrCod,(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-20 14:29:42 +01:00
/***** Remove favs for notes *****/
2019-03-12 21:25:55 +01:00
/* Remove all favs made by this user in any note */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove favs",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_notes_fav"
2019-03-12 21:25:55 +01:00
" WHERE UsrCod=%ld",
2018-11-02 22:00:31 +01:00
UsrCod);
2016-01-19 09:34:01 +01:00
/* Remove all favs for all notes of this user */
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove favs",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_notes_fav"
" USING tl_notes,tl_notes_fav"
" WHERE tl_notes.UsrCod=%ld" // Author of the note
" AND tl_notes.NotCod=tl_notes_fav.NotCod",
2018-11-02 22:00:31 +01:00
UsrCod);
2016-01-19 09:34:01 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove comments *****/
/* Remove content of all the comments in all the notes of the user */
DB_QueryDELETE ("can not remove comments",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments"
" USING tl_notes,tl_pubs,tl_comments"
" WHERE tl_notes.UsrCod=%ld"
" AND tl_notes.NotCod=tl_pubs.NotCod"
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments.PubCod",
2019-03-12 21:25:55 +01:00
UsrCod,(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-08 10:13:28 +01:00
2019-03-12 21:25:55 +01:00
/* Remove all the comments from any user in any note of the user */
DB_QueryDELETE ("can not remove comments",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_pubs"
" USING tl_notes,tl_pubs"
" WHERE tl_notes.UsrCod=%ld"
" AND tl_notes.NotCod=tl_pubs.NotCod"
" AND tl_pubs.PubType=%u",
2019-03-12 21:25:55 +01:00
UsrCod,(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-08 10:13:28 +01:00
2019-03-12 21:25:55 +01:00
/* Remove content of all the comments of the user in any note */
DB_QueryDELETE ("can not remove comments",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_comments"
" USING tl_pubs,tl_comments"
" WHERE tl_pubs.PublisherCod=%ld"
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments.PubCod",
2019-03-12 21:25:55 +01:00
UsrCod,(unsigned) TL_PUB_COMMENT_TO_NOTE);
2016-01-08 10:13:28 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove all the posts of the user *****/
DB_QueryDELETE ("can not remove posts",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_posts"
2018-11-02 22:00:31 +01:00
" WHERE PstCod IN"
2019-11-25 13:29:56 +01:00
" (SELECT Cod FROM tl_notes"
2018-11-02 22:00:31 +01:00
" WHERE UsrCod=%ld AND NoteType=%u)",
2019-03-12 21:25:55 +01:00
UsrCod,(unsigned) TL_NOTE_POST);
2016-01-08 10:13:28 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove all the publications of any user authored by the user *****/
DB_QueryDELETE ("can not remove publications",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_pubs"
" USING tl_notes,tl_pubs"
" WHERE tl_notes.UsrCod=%ld"
" AND tl_notes.NotCod=tl_pubs.NotCod",
2018-11-02 22:00:31 +01:00
UsrCod);
2016-01-11 14:42:54 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove all the publications of the user *****/
DB_QueryDELETE ("can not remove publications",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_pubs"
2019-03-12 21:25:55 +01:00
" WHERE PublisherCod=%ld",
2018-11-02 22:00:31 +01:00
UsrCod);
2016-01-08 10:13:28 +01:00
2019-03-12 21:25:55 +01:00
/***** Remove all the notes of the user *****/
DB_QueryDELETE ("can not remove notes",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_notes"
2019-03-12 21:25:55 +01:00
" WHERE UsrCod=%ld",
2018-11-02 22:00:31 +01:00
UsrCod);
2016-01-08 10:13:28 +01:00
}
2016-01-19 01:12:20 +01:00
/*****************************************************************************/
2016-01-19 12:54:27 +01:00
/************************ Show sharers or favouriters ************************/
2016-01-19 01:12:20 +01:00
/*****************************************************************************/
2021-02-08 16:24:29 +01:00
void TL_ShowNumSharersOrFavers (unsigned NumUsrs)
2019-03-29 00:57:51 +01:00
{
2021-02-08 19:04:47 +01:00
/***** Show number of sharers or favers
(users who have shared or marked this note as favourite) *****/
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%u",NumUsrs);
2019-03-29 00:57:51 +01:00
}
2021-02-08 16:24:29 +01:00
void TL_ShowSharersOrFavers (MYSQL_RES **mysql_res,
unsigned NumUsrs,unsigned NumFirstUsrs)
2016-01-19 01:12:20 +01:00
{
MYSQL_ROW row;
unsigned NumUsr;
unsigned NumUsrsShown = 0;
struct UsrData UsrDat;
bool ShowPhoto;
2017-01-28 15:58:46 +01:00
char PhotoURL[PATH_MAX + 1];
2016-01-19 01:12:20 +01:00
2016-01-19 01:31:35 +01:00
if (NumUsrs)
2016-01-19 01:12:20 +01:00
{
2018-11-01 21:59:42 +01:00
/***** A list of users has been got from database *****/
2016-01-19 01:31:35 +01:00
if (NumFirstUsrs)
2016-01-19 01:12:20 +01:00
{
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** List users *****/
for (NumUsr = 0;
2016-01-19 01:31:35 +01:00
NumUsr < NumFirstUsrs;
2016-01-19 01:12:20 +01:00
NumUsr++)
{
/***** Get user *****/
2018-11-01 21:59:42 +01:00
row = mysql_fetch_row (*mysql_res);
2016-01-19 01:12:20 +01:00
/* Get user's code (row[0]) */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Get user's data and show user's photo *****/
2019-03-19 13:22:14 +01:00
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS))
2016-01-19 01:12:20 +01:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"TL_SHARER\"");
2017-01-28 15:58:46 +01:00
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (&UsrDat,PhotoURL);
2016-01-19 01:12:20 +01:00
Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL :
NULL,
2019-02-24 15:15:43 +01:00
"PHOTO12x16",Pho_ZOOM,true); // Use unique id
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2016-01-19 01:12:20 +01:00
NumUsrsShown++;
}
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
}
}
2021-02-08 20:16:00 +01:00
/*****************************************************************************/
/********************* Form to show all favers/sharers ***********************/
/*****************************************************************************/
void TL_PutFormToSeeAllFaversSharers (Act_Action_t ActionGbl,Act_Action_t ActionUsr,
const char *ParamFormat,long ParamCod,
TL_HowManyUsrs_t HowManyUsrs)
{
extern const char *Txt_View_all_USERS;
switch (HowManyUsrs)
{
case TL_SHOW_FEW_USRS:
/***** Form and icon to mark note as favourite *****/
TL_FormFavSha (ActionGbl,ActionUsr,
ParamFormat,ParamCod,
TL_ICON_ELLIPSIS,Txt_View_all_USERS);
break;
case TL_SHOW_ALL_USRS:
Ico_PutIconOff (TL_ICON_ELLIPSIS,Txt_View_all_USERS);
break;
}
}
/*****************************************************************************/
/******* Form to fav/unfav or share/unshare in global or user timeline *******/
/*****************************************************************************/
void TL_FormFavSha (Act_Action_t ActionGbl,Act_Action_t ActionUsr,
const char *ParamFormat,long ParamCod,
const char *Icon,const char *Title)
{
char *OnSubmit;
char ParamStr[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
/***** Create parameter string *****/
sprintf (ParamStr,ParamFormat,ParamCod);
/*
+---------------------------------------------------------------------------+
| div which content will be updated (parent of parent of form) |
| +---------------------+ +-------+ +-------------------------------------+ |
| | div (parent of form)| | div | | div for users | |
| | +-----------------+ | | for | | +------+ +------+ +------+ +------+ | |
| | | this form | | | num. | | | | | | | | | form | | |
| | | +-------------+ | | | of | | | user | | user | | user | | to | | |
| | | | fav icon | | | | users | | | 1 | | 2 | | 3 | | show | | |
| | | +-------------+ | | | | | | | | | | | | all | | |
| | +-----------------+ | | | | +------+ +------+ +------+ +------+ | |
| +---------------------+ +-------+ +-------------------------------------+ |
+---------------------------------------------------------------------------+
*/
/***** Form and icon to mark note as favourite *****/
/* Form with icon */
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
if (asprintf (&OnSubmit,"updateDivFaversSharers(this,"
"'act=%ld&ses=%s&%s&OtherUsrCod=%s');"
" return false;", // return false is necessary to not submit form
Act_GetActCod (ActionUsr),
Gbl.Session.Id,
ParamStr,
Gbl.Usrs.Other.UsrDat.EncryptedUsrCod) < 0)
Lay_NotEnoughMemoryExit ();
Frm_StartFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit);
}
else
{
if (asprintf (&OnSubmit,"updateDivFaversSharers(this,"
"'act=%ld&ses=%s&%s');"
" return false;", // return false is necessary to not submit form
Act_GetActCod (ActionGbl),
Gbl.Session.Id,
ParamStr) < 0)
Lay_NotEnoughMemoryExit ();
Frm_StartFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit);
}
Ico_PutIconLink (Icon,Title);
Frm_EndForm ();
/* Free allocated memory */
free (OnSubmit);
}
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2019-11-25 13:29:56 +01:00
/***************** Get data of publication using its code ********************/
2016-01-08 01:53:37 +01:00
/*****************************************************************************/
2021-02-09 17:31:44 +01:00
static void TL_GetDataOfPublicationFromNextRow (MYSQL_RES *mysql_res,
2021-02-10 19:53:57 +01:00
struct TL_Publication *Pub)
2016-01-08 01:53:37 +01:00
{
2019-11-22 01:04:03 +01:00
static const TL_TopMessage_t TopMessages[TL_NUM_PUB_TYPES] =
2016-01-25 17:23:14 +01:00
{
2019-11-22 01:04:03 +01:00
[TL_PUB_UNKNOWN ] = TL_TOP_MESSAGE_NONE,
[TL_PUB_ORIGINAL_NOTE ] = TL_TOP_MESSAGE_NONE,
[TL_PUB_SHARED_NOTE ] = TL_TOP_MESSAGE_SHARED,
[TL_PUB_COMMENT_TO_NOTE] = TL_TOP_MESSAGE_COMMENTED,
2016-01-25 17:23:14 +01:00
};
2021-02-09 17:31:44 +01:00
MYSQL_ROW row;
/***** Get next row from result *****/
row = mysql_fetch_row (mysql_res);
2021-02-08 19:04:47 +01:00
/*
row[0]: PubCod
row[1]: NotCod
row[2]: PublisherCod
row[3]: PubType
*/
2021-02-09 17:31:44 +01:00
2019-03-12 21:25:55 +01:00
/***** Get code of publication (row[0]) *****/
2021-02-10 19:53:57 +01:00
Pub->PubCod = Str_ConvertStrCodToLongCod (row[0]);
2016-01-08 01:53:37 +01:00
2019-03-12 21:25:55 +01:00
/***** Get note code (row[1]) *****/
2021-02-10 19:53:57 +01:00
Pub->NotCod = Str_ConvertStrCodToLongCod (row[1]);
2016-01-08 01:53:37 +01:00
2016-01-19 21:07:52 +01:00
/***** Get publisher's code (row[2]) *****/
2021-02-10 19:53:57 +01:00
Pub->PublisherCod = Str_ConvertStrCodToLongCod (row[2]);
2016-01-08 01:53:37 +01:00
2019-03-06 10:13:39 +01:00
/***** Get type of publication (row[3]) *****/
2021-02-10 19:53:57 +01:00
Pub->PubType = TL_GetPubTypeFromStr ((const char *) row[3]);
Pub->TopMessage = TopMessages[Pub->PubType];
2016-01-08 01:53:37 +01:00
}
2016-01-11 20:54:14 +01:00
/*****************************************************************************/
2019-11-25 13:29:56 +01:00
/******* Get publication type from string number coming from database ********/
2016-01-11 20:54:14 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static TL_PubType_t TL_GetPubTypeFromStr (const char *Str)
2016-01-11 20:54:14 +01:00
{
unsigned UnsignedNum;
if (sscanf (Str,"%u",&UnsignedNum) == 1)
2019-03-12 21:25:55 +01:00
if (UnsignedNum < TL_NUM_PUB_TYPES)
return (TL_PubType_t) UnsignedNum;
2016-01-11 20:54:14 +01:00
2019-03-12 21:25:55 +01:00
return TL_PUB_UNKNOWN;
2016-01-11 20:54:14 +01:00
}
2021-02-09 19:45:03 +01:00
/*****************************************************************************/
/************************ Reset fields of publication ************************/
/*****************************************************************************/
2021-02-11 00:58:53 +01:00
static void TL_Pub_ResetPublication (struct TL_Publication *Pub)
2021-02-09 19:45:03 +01:00
{
2021-02-10 19:53:57 +01:00
Pub->PubCod = -1L;
Pub->NotCod = -1L;
Pub->PublisherCod = -1L;
Pub->PubType = TL_PUB_UNKNOWN;
Pub->TopMessage = TL_TOP_MESSAGE_NONE;
2021-02-09 19:45:03 +01:00
}
2016-01-12 20:58:19 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/******************* Clear unused old timelines in database ******************/
2016-01-12 20:58:19 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_ClearOldTimelinesDB (void)
2016-01-12 20:58:19 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Remove timelines for expired sessions *****/
DB_QueryDELETE ("can not remove old timelines",
2019-11-25 13:29:56 +01:00
"DELETE LOW_PRIORITY FROM tl_timelines"
2018-11-02 22:00:31 +01:00
" WHERE SessionId NOT IN (SELECT SessionId FROM sessions)");
2016-01-12 20:58:19 +01:00
}
2016-01-12 19:43:17 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/**************** Clear timeline for this session in database ****************/
2016-01-12 19:43:17 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
static void TL_ClearTimelineThisSession (void)
2016-01-12 19:43:17 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Remove timeline for this session *****/
DB_QueryDELETE ("can not remove timeline",
2019-11-25 13:29:56 +01:00
"DELETE FROM tl_timelines"
2019-03-12 21:25:55 +01:00
" WHERE SessionId='%s'",
2018-11-02 22:00:31 +01:00
Gbl.Session.Id);
2016-01-12 19:43:17 +01:00
}
2016-01-12 20:58:19 +01:00
2016-01-22 12:05:25 +01:00
/*****************************************************************************/
2019-11-25 13:29:56 +01:00
/***************** Get notification of a new publication *********************/
2016-01-22 12:05:25 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
void TL_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
char **ContentStr,
long PubCod,bool GetContent)
2016-01-22 12:05:25 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2021-02-10 19:53:57 +01:00
struct TL_Publication Pub;
2021-02-11 00:58:53 +01:00
struct TL_Not_Note Not;
2021-02-08 16:24:29 +01:00
struct TL_PostContent Content;
2017-01-15 22:58:26 +01:00
size_t Length;
2016-01-28 13:14:16 +01:00
bool ContentCopied = false;
2016-01-22 12:05:25 +01:00
2016-01-23 01:38:55 +01:00
/***** Return nothing on error *****/
2021-02-10 19:53:57 +01:00
Pub.PubType = TL_PUB_UNKNOWN;
2017-03-06 13:01:16 +01:00
SummaryStr[0] = '\0'; // Return nothing on error
2019-11-24 23:51:03 +01:00
Content.Txt[0] = '\0';
2016-01-22 12:05:25 +01:00
2019-03-12 21:25:55 +01:00
/***** Get summary and content from post from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get data of publication",
2021-02-09 12:43:45 +01:00
"SELECT PubCod," // row[0]
"NotCod," // row[1]
"PublisherCod," // row[2]
"PubType" // row[3]
2019-11-25 13:29:56 +01:00
" FROM tl_pubs WHERE PubCod=%ld",
2018-11-01 21:59:42 +01:00
PubCod) == 1) // Result should have a unique row
2021-02-09 17:31:44 +01:00
/* Get data of publication from row */
2021-02-10 19:53:57 +01:00
TL_GetDataOfPublicationFromNextRow (mysql_res,&Pub);
2016-01-22 12:05:25 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-23 01:38:55 +01:00
/***** Get summary and content *****/
2021-02-10 19:53:57 +01:00
switch (Pub.PubType)
2016-01-23 01:38:55 +01:00
{
2019-03-12 21:25:55 +01:00
case TL_PUB_UNKNOWN:
2016-01-23 01:38:55 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_PUB_ORIGINAL_NOTE:
case TL_PUB_SHARED_NOTE:
/* Get data of note */
2021-02-10 19:53:57 +01:00
Not.NotCod = Pub.NotCod;
2021-02-11 00:58:53 +01:00
TL_Not_GetDataOfNoteByCod (&Not);
2016-01-23 01:38:55 +01:00
2021-02-10 19:53:57 +01:00
if (Not.NoteType == TL_NOTE_POST)
2016-01-23 01:38:55 +01:00
{
2019-03-12 21:25:55 +01:00
/***** Get content of post from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get the content of a post",
2019-11-25 09:06:27 +01:00
"SELECT Txt" // row[0]
2019-11-25 13:29:56 +01:00
" FROM tl_posts"
2018-11-01 21:59:42 +01:00
" WHERE PstCod=%ld",
2021-02-10 19:53:57 +01:00
Not.Cod) == 1) // Result should have a unique row
2016-01-23 01:38:55 +01:00
{
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
/****** Get content (row[0]) *****/
2019-11-24 23:51:03 +01:00
Str_Copy (Content.Txt,row[0],
2017-01-17 03:10:43 +01:00
Cns_MAX_BYTES_LONG_TEXT);
2016-01-23 01:38:55 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-28 13:14:16 +01:00
/***** Copy content string *****/
if (GetContent)
2017-01-15 22:58:26 +01:00
{
2019-11-24 23:51:03 +01:00
Length = strlen (Content.Txt);
2017-01-15 22:58:26 +01:00
if ((*ContentStr = (char *) malloc (Length + 1)) != NULL)
2016-01-28 13:14:16 +01:00
{
2019-11-24 23:51:03 +01:00
Str_Copy (*ContentStr,Content.Txt,
2017-01-17 03:10:43 +01:00
Length);
2016-01-28 13:14:16 +01:00
ContentCopied = true;
}
2017-01-15 22:58:26 +01:00
}
2016-01-28 13:14:16 +01:00
2016-01-23 01:38:55 +01:00
/***** Copy summary string *****/
2019-11-24 23:51:03 +01:00
Str_LimitLengthHTMLStr (Content.Txt,Ntf_MAX_CHARS_SUMMARY);
Str_Copy (SummaryStr,Content.Txt,
2017-03-08 14:12:33 +01:00
Ntf_MAX_BYTES_SUMMARY);
2016-01-23 01:38:55 +01:00
}
else
2021-02-11 00:58:53 +01:00
TL_Not_GetNoteSummary (&Not,SummaryStr);
2016-01-23 01:38:55 +01:00
break;
2019-03-12 21:25:55 +01:00
case TL_PUB_COMMENT_TO_NOTE:
/***** Get content of post from database *****/
2018-11-01 21:59:42 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get the content"
2019-03-12 21:25:55 +01:00
" of a comment to a note",
2019-11-25 09:06:27 +01:00
"SELECT Txt" // row[0]
2019-11-25 13:29:56 +01:00
" FROM tl_comments"
2018-11-01 21:59:42 +01:00
" WHERE PubCod=%ld",
2021-02-10 19:53:57 +01:00
Pub.PubCod) == 1) // Result should have a unique row
2016-01-23 01:38:55 +01:00
{
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
/****** Get content (row[0]) *****/
2019-11-24 23:51:03 +01:00
Str_Copy (Content.Txt,row[0],
2017-01-17 03:10:43 +01:00
Cns_MAX_BYTES_LONG_TEXT);
2016-01-23 01:38:55 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-01-28 13:14:16 +01:00
/***** Copy content string *****/
if (GetContent)
2017-01-15 22:58:26 +01:00
{
2019-11-24 23:51:03 +01:00
Length = strlen (Content.Txt);
2017-01-15 22:58:26 +01:00
if ((*ContentStr = (char *) malloc (Length + 1)) != NULL)
2016-01-28 13:14:16 +01:00
{
2019-11-24 23:51:03 +01:00
Str_Copy (*ContentStr,Content.Txt,
2017-01-17 03:10:43 +01:00
Length);
2016-01-28 13:14:16 +01:00
ContentCopied = true;
}
2017-01-15 22:58:26 +01:00
}
2016-01-28 13:14:16 +01:00
2016-01-23 01:38:55 +01:00
/***** Copy summary string *****/
2019-11-24 23:51:03 +01:00
Str_LimitLengthHTMLStr (Content.Txt,Ntf_MAX_CHARS_SUMMARY);
Str_Copy (SummaryStr,Content.Txt,
2017-03-08 14:12:33 +01:00
Ntf_MAX_BYTES_SUMMARY);
2016-01-23 01:38:55 +01:00
break;
}
2016-01-28 13:14:16 +01:00
/***** Create empty content string if nothing copied *****/
if (GetContent && !ContentCopied)
if ((*ContentStr = (char *) malloc (1)) != NULL)
(*ContentStr)[0] = '\0';
2016-01-22 12:05:25 +01:00
}
2016-01-28 13:14:16 +01:00
2019-03-06 10:13:39 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
/****************** Get number of publications from a user *******************/
2019-03-06 10:13:39 +01:00
/*****************************************************************************/
2019-03-12 21:25:55 +01:00
unsigned long TL_GetNumPubsUsr (long UsrCod)
2019-03-06 10:13:39 +01:00
{
/***** Get number of posts from a user from database *****/
2019-03-12 21:25:55 +01:00
return DB_QueryCOUNT ("can not get number of publications from a user",
2019-11-25 13:29:56 +01:00
"SELECT COUNT(*) FROM tl_pubs"
2019-03-06 10:13:39 +01:00
" WHERE PublisherCod=%ld",
UsrCod);
}