swad-core/swad_network.c

399 lines
14 KiB
C
Raw Permalink Normal View History

2014-12-01 23:55:08 +01:00
// swad_network.c: users' webs and social networks
/*
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.
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public 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 ***********************************/
/*****************************************************************************/
#include <string.h>
#include "swad_action_list.h"
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
#include "swad_error.h"
2020-04-14 17:15:17 +02:00
#include "swad_figure.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
#include "swad_hierarchy_type.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2014-12-01 23:55:08 +01:00
#include "swad_parameter.h"
2015-03-14 17:39:04 +01:00
#include "swad_profile.h"
#include "swad_network.h"
#include "swad_network_database.h"
2014-12-01 23:55:08 +01:00
#include "swad_theme.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
2017-01-29 21:41:08 +01:00
#define Net_WEB_SOCIAL_NET_DEFAULT Net_WWW
2014-12-01 23:55:08 +01:00
2017-03-07 19:55:29 +01:00
#define Net_MAX_BYTES_NETWORK_NAME 32
2017-01-17 03:10:43 +01:00
2019-11-22 01:04:03 +01:00
static const char *Net_WebsAndSocialNetworksIcons[Net_NUM_WEBS_AND_SOCIAL_NETWORKS] =
2015-12-12 19:47:10 +01:00
{
[Net_WWW ] = "globe-americas.svg",
2019-11-22 01:04:03 +01:00
[Net_500PX ] = "500px-brands.svg",
[Net_DELICIOUS ] = "delicious-brands.svg",
[Net_DEVIANTART ] = "deviantart-brands.svg",
[Net_DIASPORA ] = "diaspora-brands.svg",
[Net_EDMODO ] = "edmodo64x64.png",
[Net_FACEBOOK ] = "facebook-brands.svg",
[Net_FLICKR ] = "flickr-brands.svg",
[Net_FOURSQUARE ] = "foursquare-brands.svg",
[Net_GITHUB ] = "github-brands.svg",
[Net_GNU_SOCIAL ] = "gnusocial64x64.png",
[Net_GOOGLE_PLUS ] = "google-plus-brands.svg",
[Net_GOOGLE_SCHOLAR] = "googlescholar.svg",
[Net_IDENTICA ] = "identica64x64.png",
[Net_INSTAGRAM ] = "instagram-brands.svg",
[Net_LINKEDIN ] = "linkedin-brands.svg",
[Net_ORCID ] = "orcid64x64.png",
[Net_PAPERLI ] = "paperli64x64.png",
[Net_PINTEREST ] = "pinterest-brands.svg",
[Net_RESEARCH_GATE ] = "researchgate-brands.svg",
[Net_RESEARCHERID ] = "researcherid64x64.png",
[Net_SCOOPIT ] = "scoopit64x64.png",
[Net_SLIDESHARE ] = "slideshare-brands.svg",
[Net_STACK_OVERFLOW] = "stack-overflow-brands.svg",
[Net_STORIFY ] = "storify64x64.png",
[Net_TUMBLR ] = "tumblr-brands.svg",
2020-03-06 12:22:20 +01:00
[Net_TWITCH ] = "twitch-brands.svg",
2019-11-22 01:04:03 +01:00
[Net_TWITTER ] = "twitter-brands.svg",
[Net_WIKIPEDIA ] = "wikipedia-w-brands.svg",
[Net_YOUTUBE ] = "youtube-brands.svg",
2015-12-12 19:47:10 +01:00
};
2019-11-22 01:04:03 +01:00
static const char *Net_WebsAndSocialNetworksTitle[Net_NUM_WEBS_AND_SOCIAL_NETWORKS] =
2014-12-01 23:55:08 +01:00
{
2019-11-22 01:04:03 +01:00
[Net_WWW ] = "WWW",
[Net_500PX ] = "500px",
[Net_DELICIOUS ] = "Delicious",
[Net_DEVIANTART ] = "DeviantArt",
[Net_DIASPORA ] = "Diaspora",
[Net_EDMODO ] = "Edmodo",
[Net_FACEBOOK ] = "Facebook",
[Net_FLICKR ] = "Flickr",
[Net_FOURSQUARE ] = "Foursquare",
[Net_GITHUB ] = "GitHub",
[Net_GNU_SOCIAL ] = "GNU Social",
[Net_GOOGLE_PLUS ] = "Google+",
[Net_GOOGLE_SCHOLAR] = "Google Scholar",
[Net_IDENTICA ] = "identi.ca",
[Net_INSTAGRAM ] = "Instagram",
[Net_LINKEDIN ] = "LinkedIn",
[Net_ORCID ] = "ORCID",
[Net_PAPERLI ] = "Paper.li",
[Net_PINTEREST ] = "Pinterest",
[Net_RESEARCH_GATE ] = "Research Gate",
[Net_RESEARCHERID ] = "ResearcherID",
[Net_SCOOPIT ] = "Scoop.it",
[Net_SLIDESHARE ] = "Slideshare",
[Net_STACK_OVERFLOW] = "Stack Overflow",
[Net_STORIFY ] = "Storify",
[Net_TUMBLR ] = "Tumblr",
2020-03-06 12:22:20 +01:00
[Net_TWITCH ] = "Twitch",
2019-11-22 01:04:03 +01:00
[Net_TWITTER ] = "Twitter",
[Net_WIKIPEDIA ] = "Wikipedia",
[Net_YOUTUBE ] = "YouTube",
2014-12-01 23:55:08 +01:00
};
2018-10-08 18:41:56 +02:00
#define Net_MY_WEBS_ID "my_webs_section"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2015-03-14 17:39:04 +01:00
static void Net_ShowAWebOrSocialNet (const char *URL,
const char *Icon,const char *Title);
2016-11-07 16:35:58 +01:00
2020-04-08 03:41:05 +02:00
static void Net_PutIconsWebsSocialNetworks (__attribute__((unused)) void *Args);
2016-11-07 16:35:58 +01:00
2014-12-01 23:55:08 +01:00
static void Net_GetMyWebsAndSocialNetsFromForm (void);
/*****************************************************************************/
/************************** Show webs / social networks **********************/
/*****************************************************************************/
void Net_ShowWebsAndSocialNets (const struct Usr_Data *UsrDat)
2014-12-01 23:55:08 +01:00
{
Net_WebsAndSocialNetworks_t NumURL;
2017-03-07 01:56:41 +01:00
char URL[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
/***** Begin container *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"REC_WEBS\"");
2014-12-01 23:55:08 +01:00
/***** Show link to public profile *****/
Net_ShowAWebOrSocialNet (Prf_GetURLPublicProfile (URL,UsrDat->Nickname),
"swad64x64.png",Cfg_PLATFORM_SHORT_NAME);
/***** Show the rest of webs / social networks *****/
for (NumURL = (Net_WebsAndSocialNetworks_t) 0;
NumURL <= (Net_WebsAndSocialNetworks_t) (Net_NUM_WEBS_AND_SOCIAL_NETWORKS - 1);
NumURL++)
{
/***** Check if exists the web / social network for this user *****/
Net_DB_GetURL (UsrDat->UsrCod,NumURL,URL);
if (URL[0])
/* Show the web / social network */
Net_ShowAWebOrSocialNet (URL,
Net_WebsAndSocialNetworksIcons[NumURL],
Net_WebsAndSocialNetworksTitle[NumURL]);
}
2014-12-01 23:55:08 +01:00
2015-03-14 17:39:04 +01:00
/***** End container *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}
2015-03-14 17:39:04 +01:00
/*****************************************************************************/
/************************** Show a web / social network **********************/
/*****************************************************************************/
static void Net_ShowAWebOrSocialNet (const char *URL,
const char *Icon,const char *Title)
{
/***** Write link and icon *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"ICO_HIGHLIGHT\" style=\"display:inline;\"");
HTM_A_Begin ("href=\"%s\" target=\"_blank\" title=\"%s\"",URL,Title);
Ico_PutIcon (Icon,Ico_BLACK,Title,"ICO16x16");
HTM_A_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2015-03-14 17:39:04 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* Show form to edit my social networks ******************/
/*****************************************************************************/
void Net_ShowFormMyWebsAndSocialNets (void)
{
2016-11-13 13:44:20 +01:00
extern const char *Hlp_PROFILE_Webs;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Webs_social_networks;
2019-02-18 19:35:52 +01:00
extern const char *Txt_Save_changes;
2014-12-01 23:55:08 +01:00
Net_WebsAndSocialNetworks_t NumURL;
2017-03-07 01:56:41 +01:00
char URL[Cns_MAX_BYTES_WWW + 1];
2019-11-04 09:45:57 +01:00
char StrName[32];
2018-10-08 18:41:56 +02:00
/***** Begin section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_Begin (Net_MY_WEBS_ID);
2014-12-01 23:55:08 +01:00
/***** Begin box *****/
HTM_DIV_Begin ("class=\"REC_CONT\"");
Box_BoxBegin (Txt_Webs_social_networks,
Net_PutIconsWebsSocialNetworks,NULL,
Hlp_PROFILE_Webs,Box_NOT_CLOSABLE);
/***** Begin form *****/
Frm_BeginFormAnchor (ActChgMyNet,Net_MY_WEBS_ID);
/***** Begin table *****/
HTM_TABLE_BeginPadding (2);
/***** List webs and social networks *****/
for (NumURL = (Net_WebsAndSocialNetworks_t) 0;
NumURL <= (Net_WebsAndSocialNetworks_t) (Net_NUM_WEBS_AND_SOCIAL_NETWORKS - 1);
NumURL++)
{
/***** Get user's web / social network from database *****/
Net_DB_GetURL (Gbl.Usrs.Me.UsrDat.UsrCod,NumURL,URL);
/***** Row for this web / social network *****/
snprintf (StrName,sizeof (StrName),"URL%u",(unsigned) NumURL);
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"REC_C1_BOT LM\"");
HTM_LABEL_Begin ("for=\"%s\" class=\"FORM_IN_%s\"",
StrName,The_GetSuffix ());
Ico_PutIcon (Net_WebsAndSocialNetworksIcons[NumURL],Ico_BLACK,
Net_WebsAndSocialNetworksTitle[NumURL],
"CONTEXT_OPT CONTEXT_ICO16x16");
HTM_TxtF ("&nbsp;%s:",Net_WebsAndSocialNetworksTitle[NumURL]);
HTM_LABEL_End ();
HTM_TD_End ();
HTM_TD_Begin ("class=\"REC_C2_BOT LM\"");
HTM_INPUT_URL (StrName,URL,HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"%s\""
" class=\"REC_C2_BOT_INPUT INPUT_%s\"",
StrName,
The_GetSuffix ());
HTM_TD_End ();
HTM_TR_End ();
}
/***** End table *****/
HTM_TABLE_End ();
/***** Confirm button *****/
Btn_PutConfirmButton (Txt_Save_changes);
/***** End form *****/
Frm_EndForm ();
/***** End box *****/
Box_BoxEnd ();
HTM_DIV_End ();
2018-10-08 18:41:56 +02:00
/***** End section *****/
2019-10-26 01:56:36 +02:00
HTM_SECTION_End ();
2014-12-01 23:55:08 +01:00
}
2016-11-07 16:35:58 +01:00
/*****************************************************************************/
/************** Put contextual icons in my web / social networks *************/
/*****************************************************************************/
2020-04-08 03:41:05 +02:00
static void Net_PutIconsWebsSocialNetworks (__attribute__((unused)) void *Args)
2016-11-07 16:35:58 +01:00
{
2020-04-08 03:41:05 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_SOCIAL_NETWORKS);
2016-11-07 16:35:58 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/**************** Update and show data from identified user ******************/
/*****************************************************************************/
void Net_UpdateMyWebsAndSocialNets (void)
{
/***** Get my web and social networks from form *****/
Net_GetMyWebsAndSocialNetsFromForm ();
/***** Show form again *****/
2018-10-09 13:41:55 +02:00
Rec_ShowMySharedRecordAndMore ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********* Get data fields about web and social networks from form ***********/
/*****************************************************************************/
static void Net_GetMyWebsAndSocialNetsFromForm (void)
{
2019-02-18 19:35:52 +01:00
Net_WebsAndSocialNetworks_t NumURL;
char ParName[3 + 10 + 1];
2017-03-07 01:56:41 +01:00
char URL[Cns_MAX_BYTES_WWW + 1];
2014-12-01 23:55:08 +01:00
2019-02-18 19:35:52 +01:00
/***** Get URLs *****/
2019-12-15 20:02:34 +01:00
for (NumURL = (Net_WebsAndSocialNetworks_t) 0;
NumURL <= (Net_WebsAndSocialNetworks_t) (Net_NUM_WEBS_AND_SOCIAL_NETWORKS - 1);
2019-02-18 19:35:52 +01:00
NumURL++)
{
/***** Get URL from the form *****/
snprintf (ParName,sizeof (ParName),"URL%u",(unsigned) NumURL);
Par_GetParText (ParName,URL,Cns_MAX_BYTES_WWW);
2019-02-18 19:35:52 +01:00
if (URL[0])
/***** Insert or replace web / social network *****/
Net_DB_UpdateMyWeb (NumURL,URL);
2019-02-18 19:35:52 +01:00
else
/***** Remove web / social network *****/
Net_DB_RemoveMyWeb (NumURL);
2019-02-18 19:35:52 +01:00
}
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Show stats about users' webs / social networks ***************/
/*****************************************************************************/
void Net_ShowWebAndSocialNetworksStats (void)
{
2017-12-19 18:41:19 +01:00
extern const char *Hlp_ANALYTICS_Figures_webs_social_networks;
extern const char *Net_DB_WebsAndSocialNetworks[Net_NUM_WEBS_AND_SOCIAL_NETWORKS];
2019-02-12 14:46:14 +01:00
extern const char *Txt_FIGURE_TYPES[Fig_NUM_FIGURES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Web_social_network;
2020-05-07 14:15:39 +02:00
extern const char *Txt_Number_of_users;
2014-12-01 23:55:08 +01:00
extern const char *Txt_PERCENT_of_users;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumNetworks;
unsigned NumNetwork;
2014-12-01 23:55:08 +01:00
Net_WebsAndSocialNetworks_t Web;
2017-03-07 19:55:29 +01:00
char NetName[Net_MAX_BYTES_NETWORK_NAME + 1];
2017-05-25 19:57:34 +02:00
unsigned NumUsrsTotal;
2014-12-01 23:55:08 +01:00
unsigned NumUsrs;
2017-05-25 19:57:34 +02:00
/***** Get total number of users in current scope *****/
NumUsrsTotal = Usr_GetTotalNumberOfUsers ();
2014-12-01 23:55:08 +01:00
/***** Get number of users with a web / social network *****/
NumNetworks = Net_DB_GetWebAndSocialNetworksStats (&mysql_res);
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
Box_BoxTableBegin (Txt_FIGURE_TYPES[Fig_SOCIAL_NETWORKS],NULL,NULL,
2017-12-19 18:41:19 +01:00
Hlp_ANALYTICS_Figures_webs_social_networks,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
HTM_TR_Begin (NULL);
HTM_TH (Txt_Web_social_network,HTM_HEAD_RIGHT);
HTM_TH (Txt_Number_of_users ,HTM_HEAD_RIGHT);
HTM_TH (Txt_PERCENT_of_users ,HTM_HEAD_RIGHT);
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** For each web / social network... *****/
for (NumNetwork = 0;
NumNetwork < NumNetworks;
NumNetwork++)
2014-12-01 23:55:08 +01:00
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get web / social network (row[0]) */
Str_Copy (NetName,row[0],sizeof (NetName) - 1);
for (Web = (Net_WebsAndSocialNetworks_t) 0;
Web <= (Net_WebsAndSocialNetworks_t) (Net_NUM_WEBS_AND_SOCIAL_NETWORKS - 1);
Web++)
if (!strcmp (Net_DB_WebsAndSocialNetworks[Web],NetName))
break;
if (Web < Net_NUM_WEBS_AND_SOCIAL_NETWORKS)
{
/* Get number of users (row[1]) */
if (sscanf (row[1],"%u",&NumUsrs) != 1)
Err_ShowErrorAndExit ("Error when getting number of files.");
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"LM DAT_%s\"",
The_GetSuffix ());
Ico_PutIcon (Net_WebsAndSocialNetworksIcons[Web],Ico_BLACK,
Net_WebsAndSocialNetworksTitle[Web],"ICOx16");
HTM_NBSPTxt (Net_WebsAndSocialNetworksTitle[Web]);
HTM_TD_End ();
HTM_TD_Unsigned (NumUsrs);
HTM_TD_Percentage (NumUsrs,NumUsrsTotal);
HTM_TR_End ();
}
2014-12-01 23:55:08 +01:00
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}