mirror of https://github.com/acanas/swad-core.git
Version 20.71: May 10, 2021 New module swad_media_database for database queries related to media.
This commit is contained in:
parent
300662e301
commit
e61715a085
3
Makefile
3
Makefile
|
@ -49,7 +49,8 @@ OBJS = swad_account.o swad_action.o swad_agenda.o swad_alert.o \
|
||||||
swad_language.o swad_layout.o swad_link.o swad_log.o swad_logo.o \
|
swad_language.o swad_layout.o swad_link.o swad_log.o swad_logo.o \
|
||||||
swad_MAC.o swad_mail.o swad_main.o swad_maintenance.o swad_map.o \
|
swad_MAC.o swad_mail.o swad_main.o swad_maintenance.o swad_map.o \
|
||||||
swad_mark.o swad_match.o swad_match_print.o swad_match_result.o \
|
swad_mark.o swad_match.o swad_match_print.o swad_match_result.o \
|
||||||
swad_media.o swad_menu.o swad_message.o swad_MFU.o \
|
swad_media.o swad_media_database.o swad_menu.o swad_message.o \
|
||||||
|
swad_MFU.o \
|
||||||
swad_network.o swad_nickname.o swad_notice.o swad_notification.o \
|
swad_network.o swad_nickname.o swad_notice.o swad_notification.o \
|
||||||
swad_pagination.o swad_parameter.o swad_password.o swad_photo.o \
|
swad_pagination.o swad_parameter.o swad_password.o swad_photo.o \
|
||||||
swad_place.o swad_plugin.o swad_privacy.o swad_profile.o \
|
swad_place.o swad_plugin.o swad_privacy.o swad_profile.o \
|
||||||
|
|
|
@ -600,14 +600,15 @@ TODO: Salvador Romero Cort
|
||||||
|
|
||||||
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
|
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
|
||||||
*/
|
*/
|
||||||
#define Log_PLATFORM_VERSION "SWAD 20.70 (2021-05-07)"
|
#define Log_PLATFORM_VERSION "SWAD 20.71 (2021-05-10)"
|
||||||
#define CSS_FILE "swad20.45.css"
|
#define CSS_FILE "swad20.45.css"
|
||||||
#define JS_FILE "swad20.69.1.js"
|
#define JS_FILE "swad20.69.1.js"
|
||||||
/*
|
/*
|
||||||
TODO: Rename CENTRE to CENTER in help wiki.
|
TODO: Rename CENTRE to CENTER in help wiki.
|
||||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||||
|
|
||||||
Version 20.70: May 07, 2021 New module swad_follow_database for database queries related to followin/followers. (309943 lines)
|
Version 20.71: May 10, 2021 New module swad_media_database for database queries related to media. (310080 lines)
|
||||||
|
Version 20.70: May 07, 2021 New module swad_follow_database for database queries related to following/followers. (309943 lines)
|
||||||
Version 20.69.2: May 04, 2021 Fixed bug in removal of timeline favs. (309778 lines)
|
Version 20.69.2: May 04, 2021 Fixed bug in removal of timeline favs. (309778 lines)
|
||||||
Version 20.69.1: Apr 30, 2021 Code refactoring in JavaScript (firstChild instead of childNodes[0]). (309775 lines)
|
Version 20.69.1: Apr 30, 2021 Code refactoring in JavaScript (firstChild instead of childNodes[0]). (309775 lines)
|
||||||
Version 20.69: Apr 30, 2021 Changes in timeline to not repeat notes in new activity. (309773 lines)
|
Version 20.69: Apr 30, 2021 Changes in timeline to not repeat notes in new activity. (309773 lines)
|
||||||
|
|
459
swad_media.c
459
swad_media.c
|
@ -47,6 +47,7 @@
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
#include "swad_HTML.h"
|
#include "swad_HTML.h"
|
||||||
#include "swad_media.h"
|
#include "swad_media.h"
|
||||||
|
#include "swad_media_database.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/****************************** Public constants *****************************/
|
/****************************** Public constants *****************************/
|
||||||
|
@ -56,18 +57,6 @@
|
||||||
/***************************** Private constants *****************************/
|
/***************************** Private constants *****************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static const char *Med_StringsTypeDB[Med_NUM_TYPES] =
|
|
||||||
{
|
|
||||||
[Med_TYPE_NONE] = "none",
|
|
||||||
[Med_JPG ] = "jpg",
|
|
||||||
[Med_GIF ] = "gif",
|
|
||||||
[Med_MP4 ] = "mp4",
|
|
||||||
[Med_WEBM ] = "webm",
|
|
||||||
[Med_OGG ] = "ogg",
|
|
||||||
[Med_YOUTUBE ] = "youtube",
|
|
||||||
[Med_EMBED ] = "embed",
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char *Med_Extensions[Med_NUM_TYPES] =
|
static const char *Med_Extensions[Med_NUM_TYPES] =
|
||||||
{
|
{
|
||||||
[Med_TYPE_NONE] = "",
|
[Med_TYPE_NONE] = "",
|
||||||
|
@ -175,10 +164,8 @@ static void Med_ShowYoutube (const struct Med_Media *Media,const char *ClassMedi
|
||||||
static void Med_ShowEmbed (const struct Med_Media *Media,const char *ClassMedia);
|
static void Med_ShowEmbed (const struct Med_Media *Media,const char *ClassMedia);
|
||||||
static void Med_AlertThirdPartyCookies (void);
|
static void Med_AlertThirdPartyCookies (void);
|
||||||
|
|
||||||
static Med_Type_t Med_GetTypeFromStrInDB (const char *Str);
|
|
||||||
static Med_Type_t Med_GetTypeFromExtAndMIME (const char *Extension,
|
static Med_Type_t Med_GetTypeFromExtAndMIME (const char *Extension,
|
||||||
const char *MIMEType);
|
const char *MIMEType);
|
||||||
static const char *Med_GetStringTypeForDB (Med_Type_t Type);
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/********************** Media (image/video) constructor **********************/
|
/********************** Media (image/video) constructor **********************/
|
||||||
|
@ -268,15 +255,7 @@ void Med_GetMediaDataByCod (struct Med_Media *Media)
|
||||||
size_t Length;
|
size_t Length;
|
||||||
|
|
||||||
/***** Get data of a media from database *****/
|
/***** Get data of a media from database *****/
|
||||||
NumRows = (unsigned)
|
NumRows = Med_DB_GetMediaDataByCod (&mysql_res,Media->MedCod);
|
||||||
DB_QuerySELECT (&mysql_res,"can not get media",
|
|
||||||
"SELECT Type," // row[0]
|
|
||||||
"Name," // row[1]
|
|
||||||
"URL," // row[2]
|
|
||||||
"Title" // row[3]
|
|
||||||
" FROM med_media"
|
|
||||||
" WHERE MedCod=%ld",
|
|
||||||
Media->MedCod);
|
|
||||||
|
|
||||||
/***** Result should have a unique row *****/
|
/***** Result should have a unique row *****/
|
||||||
if (NumRows == 0) // Media not found
|
if (NumRows == 0) // Media not found
|
||||||
|
@ -288,7 +267,7 @@ void Med_GetMediaDataByCod (struct Med_Media *Media)
|
||||||
row = mysql_fetch_row (mysql_res);
|
row = mysql_fetch_row (mysql_res);
|
||||||
|
|
||||||
/***** Convert type string (row[0]) to type *****/
|
/***** Convert type string (row[0]) to type *****/
|
||||||
Media->Type = Med_GetTypeFromStrInDB (row[0]);
|
Media->Type = Med_DB_GetTypeFromStr (row[0]);
|
||||||
|
|
||||||
/***** Set status of media file *****/
|
/***** Set status of media file *****/
|
||||||
Media->Status = (Media->Type != Med_TYPE_NONE) ? Med_STORED_IN_DB :
|
Media->Status = (Media->Type != Med_TYPE_NONE) ? Med_STORED_IN_DB :
|
||||||
|
@ -385,87 +364,110 @@ void Med_PutMediaUploader (int NumMedia,const char *ClassInput)
|
||||||
/***** Create unique id for this media uploader *****/
|
/***** Create unique id for this media uploader *****/
|
||||||
Frm_SetUniqueId (Id);
|
Frm_SetUniqueId (Id);
|
||||||
|
|
||||||
/***** Start media uploader container *****/
|
/***** Begin media uploader container *****/
|
||||||
HTM_DIV_Begin ("class=\"MED_UPLOADER\""); // container
|
HTM_DIV_Begin ("class=\"MED_UPLOADER\""); // container
|
||||||
|
|
||||||
/***** Icon 'clip' *****/
|
/***** Icon 'clip' *****/
|
||||||
HTM_DIV_Begin ("id=\"%s_med_ico\"",Id); // <id>_med_ico
|
/* Begin container */
|
||||||
HTM_A_Begin ("href=\"\" onclick=\"mediaActivateMediaUploader('%s');return false;\"",
|
HTM_DIV_Begin ("id=\"%s_med_ico\"",Id); // <id>_med_ico
|
||||||
Id);
|
|
||||||
Ico_PutIcon ("paperclip.svg",Txt_Multimedia,"ICO_HIGHLIGHT ICOx16");
|
|
||||||
HTM_A_End ();
|
|
||||||
HTM_DIV_End (); // <id>_med_ico
|
|
||||||
|
|
||||||
/***** Start media uploader *****/
|
/* Icon 'clip' */
|
||||||
HTM_DIV_Begin ("id=\"%s_med_upl\" style=\"display:none;\"", // container <id>_med_upl
|
HTM_A_Begin ("href=\"\""
|
||||||
Id);
|
" onclick=\"mediaActivateMediaUploader('%s');return false;\"",
|
||||||
|
Id);
|
||||||
|
Ico_PutIcon ("paperclip.svg",Txt_Multimedia,"ICO_HIGHLIGHT ICOx16");
|
||||||
|
HTM_A_End ();
|
||||||
|
|
||||||
/***** Begin box *****/
|
/* End container */
|
||||||
Box_BoxBegin (NULL,Txt_Multimedia,
|
HTM_DIV_End (); // <id>_med_ico
|
||||||
NULL,NULL,
|
|
||||||
Hlp_Multimedia,Box_NOT_CLOSABLE);
|
|
||||||
|
|
||||||
/***** Action to perform on media *****/
|
/***** Begin media uploader *****/
|
||||||
Par_PutHiddenParamUnsigned (NULL,ParamUploadMedia.Action,(unsigned) Med_ACTION_NEW_MEDIA);
|
HTM_DIV_Begin ("id=\"%s_med_upl\" style=\"display:none;\"", // container <id>_med_upl
|
||||||
|
Id);
|
||||||
|
|
||||||
/***** Icons *****/
|
/***** Begin box *****/
|
||||||
/* Start icons */
|
Box_BoxBegin (NULL,Txt_Multimedia,
|
||||||
HTM_DIV_Begin ("class=\"PREF_CONTS\""); // icons containers
|
NULL,NULL,
|
||||||
HTM_DIV_Begin ("class=\"PREF_CONT\""); // icons container
|
Hlp_Multimedia,Box_NOT_CLOSABLE);
|
||||||
|
|
||||||
/* Draw icons */
|
/***** Action to perform on media *****/
|
||||||
for (NumUploader = 0;
|
Par_PutHiddenParamUnsigned (NULL,ParamUploadMedia.Action,
|
||||||
NumUploader < Med_NUM_MEDIA_UPLOADERS;
|
(unsigned) Med_ACTION_NEW_MEDIA);
|
||||||
NumUploader++)
|
|
||||||
Med_PutIconMediaUploader (Id,&MediaUploader[NumUploader]);
|
|
||||||
|
|
||||||
/* End icons */
|
/***** Icons *****/
|
||||||
HTM_DIV_End (); // icons container
|
/* Begin containers */
|
||||||
HTM_DIV_End (); // icons containers
|
HTM_DIV_Begin ("class=\"PREF_CONTS\"");
|
||||||
|
HTM_DIV_Begin ("class=\"PREF_CONT\"");
|
||||||
|
|
||||||
/***** Form types *****/
|
/* Draw icons */
|
||||||
for (NumUploader = 0;
|
for (NumUploader = 0;
|
||||||
NumUploader < Med_NUM_MEDIA_UPLOADERS;
|
NumUploader < Med_NUM_MEDIA_UPLOADERS;
|
||||||
NumUploader++)
|
NumUploader++)
|
||||||
Med_PutHiddenFormTypeMediaUploader (Id,&MediaUploader[NumUploader],
|
Med_PutIconMediaUploader (Id,&MediaUploader[NumUploader]);
|
||||||
&ParamUploadMedia);
|
|
||||||
|
|
||||||
/***** Media file *****/
|
/* End containers */
|
||||||
HTM_DIV_Begin (NULL);
|
HTM_DIV_End ();
|
||||||
HTM_INPUT_FILE (ParamUploadMedia.File,"image/,video/", // <id>_fil
|
HTM_DIV_End ();
|
||||||
HTM_DONT_SUBMIT_ON_CHANGE,
|
|
||||||
"id=\"%s_fil\" class=\"%s\""
|
|
||||||
" disabled=\"disabled\" style=\"display:none;\"",
|
|
||||||
Id,ClassInput);
|
|
||||||
HTM_DIV_End (); // <id>_fil
|
|
||||||
|
|
||||||
/***** Media URL *****/
|
/***** Form types *****/
|
||||||
HTM_DIV_Begin (NULL);
|
for (NumUploader = 0;
|
||||||
HTM_INPUT_URL (ParamUploadMedia.URL,"",HTM_DONT_SUBMIT_ON_CHANGE,// <id>_url
|
NumUploader < Med_NUM_MEDIA_UPLOADERS;
|
||||||
"id=\"%s_url\" class=\"%s\""
|
NumUploader++)
|
||||||
" placeholder=\"%s\" maxlength=\"%u\""
|
Med_PutHiddenFormTypeMediaUploader (Id,&MediaUploader[NumUploader],
|
||||||
" disabled=\"disabled\" style=\"display:none;\"",
|
&ParamUploadMedia);
|
||||||
Id,ClassInput,Txt_Link,Cns_MAX_CHARS_WWW);
|
|
||||||
HTM_DIV_End (); // <id>_url
|
|
||||||
|
|
||||||
/***** Media title *****/
|
/***** Media file *****/
|
||||||
HTM_DIV_Begin (NULL);
|
/* Begin container */
|
||||||
HTM_INPUT_TEXT (ParamUploadMedia.Title,Med_MAX_CHARS_TITLE,"",// <id>_tit
|
HTM_DIV_Begin (NULL);
|
||||||
HTM_DONT_SUBMIT_ON_CHANGE,
|
|
||||||
"id=\"%s_tit\" class=\"%s\""
|
|
||||||
" placeholder=\"%s\""
|
|
||||||
" disabled=\"disabled\" style=\"display:none;\"",
|
|
||||||
Id,ClassInput,Txt_Title_attribution);
|
|
||||||
HTM_DIV_End (); // <id>_tit
|
|
||||||
|
|
||||||
/***** End box *****/
|
/* Media file */
|
||||||
Box_BoxEnd ();
|
HTM_INPUT_FILE (ParamUploadMedia.File,"image/,video/",
|
||||||
|
HTM_DONT_SUBMIT_ON_CHANGE,
|
||||||
|
"id=\"%s_fil\" class=\"%s\"" // <id>_fil
|
||||||
|
" disabled=\"disabled\" style=\"display:none;\"",
|
||||||
|
Id,ClassInput);
|
||||||
|
|
||||||
/***** End media uploader *****/
|
/* End container */
|
||||||
HTM_DIV_End (); // container <id>_med_upl
|
HTM_DIV_End ();
|
||||||
|
|
||||||
|
/***** Media URL *****/
|
||||||
|
/* Begin container */
|
||||||
|
HTM_DIV_Begin (NULL);
|
||||||
|
|
||||||
|
/* Media URL */
|
||||||
|
HTM_INPUT_URL (ParamUploadMedia.URL,"",
|
||||||
|
HTM_DONT_SUBMIT_ON_CHANGE,
|
||||||
|
"id=\"%s_url\" class=\"%s\"" // <id>_url
|
||||||
|
" placeholder=\"%s\" maxlength=\"%u\""
|
||||||
|
" disabled=\"disabled\" style=\"display:none;\"",
|
||||||
|
Id,ClassInput,Txt_Link,Cns_MAX_CHARS_WWW);
|
||||||
|
|
||||||
|
/* End container */
|
||||||
|
HTM_DIV_End ();
|
||||||
|
|
||||||
|
/***** Media title *****/
|
||||||
|
/* Begin container */
|
||||||
|
HTM_DIV_Begin (NULL);
|
||||||
|
|
||||||
|
/* Media title */
|
||||||
|
HTM_INPUT_TEXT (ParamUploadMedia.Title,Med_MAX_CHARS_TITLE,"",
|
||||||
|
HTM_DONT_SUBMIT_ON_CHANGE,
|
||||||
|
"id=\"%s_tit\" class=\"%s\"" // <id>_tit
|
||||||
|
" placeholder=\"%s\""
|
||||||
|
" disabled=\"disabled\" style=\"display:none;\"",
|
||||||
|
Id,ClassInput,Txt_Title_attribution);
|
||||||
|
|
||||||
|
/* End container */
|
||||||
|
HTM_DIV_End ();
|
||||||
|
|
||||||
|
/***** End box *****/
|
||||||
|
Box_BoxEnd ();
|
||||||
|
|
||||||
|
/***** End media uploader *****/
|
||||||
|
HTM_DIV_End (); // container <id>_med_upl
|
||||||
|
|
||||||
/***** End media uploader container *****/
|
/***** End media uploader container *****/
|
||||||
HTM_DIV_End (); // container
|
HTM_DIV_End (); // container
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -476,13 +478,20 @@ static void Med_PutIconMediaUploader (const char UniqueId[Frm_MAX_BYTES_ID + 1],
|
||||||
struct MediaUploader *MediaUploader)
|
struct MediaUploader *MediaUploader)
|
||||||
{
|
{
|
||||||
/***** Icon to activate form in media uploader *****/
|
/***** Icon to activate form in media uploader *****/
|
||||||
HTM_DIV_Begin ("id=\"%s_%s\" class=\"PREF_OFF\"", // <id>_IconSuffix
|
/* Begin container */
|
||||||
|
HTM_DIV_Begin ("id=\"%s_%s\" class=\"PREF_OFF\"", // <id>_IconSuffix
|
||||||
UniqueId,MediaUploader->IconSuffix);
|
UniqueId,MediaUploader->IconSuffix);
|
||||||
HTM_A_Begin ("href=\"\" onclick=\"%s('%s');return false;\"",
|
|
||||||
MediaUploader->FunctionName,UniqueId);
|
/* Icon to upload media */
|
||||||
Ico_PutIcon (MediaUploader->Icon,MediaUploader->Title,"ICO_HIGHLIGHT ICOx16");
|
HTM_A_Begin ("href=\"\" onclick=\"%s('%s');return false;\"",
|
||||||
HTM_A_End ();
|
MediaUploader->FunctionName,UniqueId);
|
||||||
HTM_DIV_End (); // <id>_IconSuffix
|
Ico_PutIcon (MediaUploader->Icon,
|
||||||
|
MediaUploader->Title,
|
||||||
|
"ICO_HIGHLIGHT ICOx16");
|
||||||
|
HTM_A_End ();
|
||||||
|
|
||||||
|
/* End container */
|
||||||
|
HTM_DIV_End (); // <id>_IconSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -501,7 +510,7 @@ static void Med_PutHiddenFormTypeMediaUploader (const char UniqueId[Frm_MAX_BYTE
|
||||||
Par_PutHiddenParamUnsignedDisabled (Id,ParamUploadMedia->FormType,
|
Par_PutHiddenParamUnsignedDisabled (Id,ParamUploadMedia->FormType,
|
||||||
(unsigned) MediaUploader->FormType);
|
(unsigned) MediaUploader->FormType);
|
||||||
free (Id);
|
free (Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/******************** Get media (image/video) from form **********************/
|
/******************** Get media (image/video) from form **********************/
|
||||||
|
@ -626,10 +635,10 @@ static Med_Action_t Med_GetMediaActionFromForm (const char *ParamAction)
|
||||||
{
|
{
|
||||||
/***** Get parameter with the action to perform on media *****/
|
/***** Get parameter with the action to perform on media *****/
|
||||||
return (Med_Action_t)
|
return (Med_Action_t)
|
||||||
Par_GetParToUnsignedLong (ParamAction,
|
Par_GetParToUnsignedLong (ParamAction,
|
||||||
0,
|
0,
|
||||||
Med_NUM_ACTIONS - 1,
|
Med_NUM_ACTIONS - 1,
|
||||||
(unsigned long) Med_ACTION_DEFAULT);
|
(unsigned long) Med_ACTION_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -638,10 +647,11 @@ static Med_Action_t Med_GetMediaActionFromForm (const char *ParamAction)
|
||||||
|
|
||||||
static Med_FormType_t Usr_GetFormTypeFromForm (struct ParamUploadMedia *ParamUploadMedia)
|
static Med_FormType_t Usr_GetFormTypeFromForm (struct ParamUploadMedia *ParamUploadMedia)
|
||||||
{
|
{
|
||||||
return (Med_FormType_t) Par_GetParToUnsignedLong (ParamUploadMedia->FormType,
|
return (Med_FormType_t)
|
||||||
0,
|
Par_GetParToUnsignedLong (ParamUploadMedia->FormType,
|
||||||
Med_NUM_FORM_TYPES - 1,
|
0,
|
||||||
(unsigned long) Med_FORM_NONE);
|
Med_NUM_FORM_TYPES - 1,
|
||||||
|
(unsigned long) Med_FORM_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1381,19 +1391,7 @@ static bool Med_MoveTmpFileToDefDir (struct Med_Media *Media,
|
||||||
void Med_StoreMediaInDB (struct Med_Media *Media)
|
void Med_StoreMediaInDB (struct Med_Media *Media)
|
||||||
{
|
{
|
||||||
/***** Insert media into database *****/
|
/***** Insert media into database *****/
|
||||||
Media->MedCod =
|
Media->MedCod = Med_DB_StoreMedia (Media);
|
||||||
DB_QueryINSERTandReturnCode ("can not create media",
|
|
||||||
"INSERT INTO med_media"
|
|
||||||
" (Type,Name,URL,Title)"
|
|
||||||
" VALUES"
|
|
||||||
" ('%s','%s','%s','%s')",
|
|
||||||
Med_GetStringTypeForDB (Media->Type),
|
|
||||||
Media->Name ? Media->Name :
|
|
||||||
"",
|
|
||||||
Media->URL ? Media->URL :
|
|
||||||
"",
|
|
||||||
Media->Title ? Media->Title :
|
|
||||||
"");
|
|
||||||
Media->Status = Med_STORED_IN_DB;
|
Media->Status = Med_STORED_IN_DB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1413,70 +1411,71 @@ void Med_ShowMedia (const struct Med_Media *Media,
|
||||||
Media->Type == Med_TYPE_NONE)
|
Media->Type == Med_TYPE_NONE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/***** Start media container *****/
|
/***** Begin media container *****/
|
||||||
HTM_DIV_Begin ("class=\"%s\"",ClassContainer);
|
HTM_DIV_Begin ("class=\"%s\"",ClassContainer);
|
||||||
|
|
||||||
switch (Media->Type)
|
/***** Show media *****/
|
||||||
{
|
switch (Media->Type)
|
||||||
case Med_JPG:
|
{
|
||||||
case Med_GIF:
|
case Med_JPG:
|
||||||
case Med_MP4:
|
case Med_GIF:
|
||||||
case Med_WEBM:
|
case Med_MP4:
|
||||||
case Med_OGG:
|
case Med_WEBM:
|
||||||
/***** Show uploaded file *****/
|
case Med_OGG:
|
||||||
/* If no media to show ==> nothing to do */
|
/***** Show uploaded file *****/
|
||||||
if (!Media->Name)
|
/* If no media to show ==> nothing to do */
|
||||||
return;
|
if (!Media->Name)
|
||||||
if (!Media->Name[0])
|
return;
|
||||||
return;
|
if (!Media->Name[0])
|
||||||
|
return;
|
||||||
|
|
||||||
/* Start optional link to external URL */
|
/* Start optional link to external URL */
|
||||||
PutLink = false;
|
PutLink = false;
|
||||||
if (Media->URL)
|
if (Media->URL)
|
||||||
if (Media->URL[0])
|
if (Media->URL[0])
|
||||||
PutLink = true;
|
PutLink = true;
|
||||||
if (PutLink)
|
if (PutLink)
|
||||||
HTM_A_Begin ("href=\"%s\" target=\"_blank\"",Media->URL);
|
HTM_A_Begin ("href=\"%s\" target=\"_blank\"",Media->URL);
|
||||||
|
|
||||||
/* Build path to private directory with the media */
|
/* Build path to private directory with the media */
|
||||||
snprintf (PathMedPriv,sizeof (PathMedPriv),"%s/%c%c",
|
snprintf (PathMedPriv,sizeof (PathMedPriv),"%s/%c%c",
|
||||||
Cfg_PATH_MEDIA_PRIVATE,
|
Cfg_PATH_MEDIA_PRIVATE,
|
||||||
Media->Name[0],
|
Media->Name[0],
|
||||||
Media->Name[1]);
|
Media->Name[1]);
|
||||||
|
|
||||||
/* Show media */
|
/* Show media */
|
||||||
switch (Media->Type)
|
switch (Media->Type)
|
||||||
{
|
{
|
||||||
case Med_JPG:
|
case Med_JPG:
|
||||||
Med_ShowJPG (Media,PathMedPriv,ClassMedia);
|
Med_ShowJPG (Media,PathMedPriv,ClassMedia);
|
||||||
break;
|
break;
|
||||||
case Med_GIF:
|
case Med_GIF:
|
||||||
Med_ShowGIF (Media,PathMedPriv,ClassMedia);
|
Med_ShowGIF (Media,PathMedPriv,ClassMedia);
|
||||||
break;
|
break;
|
||||||
case Med_MP4:
|
case Med_MP4:
|
||||||
case Med_WEBM:
|
case Med_WEBM:
|
||||||
case Med_OGG:
|
case Med_OGG:
|
||||||
Med_ShowVideo (Media,PathMedPriv,ClassMedia);
|
Med_ShowVideo (Media,PathMedPriv,ClassMedia);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End optional link to external URL */
|
/* End optional link to external URL */
|
||||||
if (PutLink)
|
if (PutLink)
|
||||||
HTM_A_End ();
|
HTM_A_End ();
|
||||||
break;
|
break;
|
||||||
case Med_YOUTUBE:
|
case Med_YOUTUBE:
|
||||||
/***** Show embed YouTube video *****/
|
/***** Show embed YouTube video *****/
|
||||||
Med_ShowYoutube (Media,ClassMedia);
|
Med_ShowYoutube (Media,ClassMedia);
|
||||||
break;
|
break;
|
||||||
case Med_EMBED:
|
case Med_EMBED:
|
||||||
/***** Show other embed media *****/
|
/***** Show other embed media *****/
|
||||||
Med_ShowEmbed (Media,ClassMedia);
|
Med_ShowEmbed (Media,ClassMedia);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** End media container *****/
|
/***** End media container *****/
|
||||||
HTM_DIV_End ();
|
HTM_DIV_End ();
|
||||||
|
@ -1600,21 +1599,23 @@ static void Med_ShowGIF (const struct Med_Media *Media,
|
||||||
if (Fil_CheckIfPathExists (FullPathPNGPriv)) // The static PNG image
|
if (Fil_CheckIfPathExists (FullPathPNGPriv)) // The static PNG image
|
||||||
{
|
{
|
||||||
/***** Show static PNG and animated GIF *****/
|
/***** Show static PNG and animated GIF *****/
|
||||||
|
/* Begin container */
|
||||||
HTM_DIV_Begin ("class=\"MED_PLAY\""
|
HTM_DIV_Begin ("class=\"MED_PLAY\""
|
||||||
" onmouseover=\"toggleOnGIF(this,'%s');\""
|
" onmouseover=\"toggleOnGIF(this,'%s');\""
|
||||||
" onmouseout=\"toggleOffGIF(this,'%s');\"",
|
" onmouseout=\"toggleOffGIF(this,'%s');\"",
|
||||||
URL_GIF,
|
URL_GIF,
|
||||||
URL_PNG);
|
URL_PNG);
|
||||||
|
|
||||||
/* Image */
|
/* Image */
|
||||||
HTM_IMG (URL,FileNamePNG,Media->Title,
|
HTM_IMG (URL,FileNamePNG,Media->Title,
|
||||||
"class=\"%s\" lazyload=\"on\"",ClassMedia); // Lazy load of the media
|
"class=\"%s\" lazyload=\"on\"",ClassMedia); // Lazy load of the media
|
||||||
|
|
||||||
/* Overlay with GIF label */
|
/* Overlay with GIF label */
|
||||||
HTM_SPAN_Begin ("class=\"MED_PLAY_ICO\"");
|
HTM_SPAN_Begin ("class=\"MED_PLAY_ICO\"");
|
||||||
HTM_Txt ("GIF");
|
HTM_Txt ("GIF");
|
||||||
HTM_SPAN_End ();
|
HTM_SPAN_End ();
|
||||||
|
|
||||||
|
/* End container */
|
||||||
HTM_DIV_End ();
|
HTM_DIV_End ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1715,19 +1716,24 @@ static void Med_ShowYoutube (const struct Med_Media *Media,const char *ClassMedi
|
||||||
// allow="accelerometer; autoplay; encrypted-media;
|
// allow="accelerometer; autoplay; encrypted-media;
|
||||||
// gyroscope; picture-in-picture" allowfullscreen>
|
// gyroscope; picture-in-picture" allowfullscreen>
|
||||||
// </iframe>
|
// </iframe>
|
||||||
|
/* Begin container */
|
||||||
HTM_DIV_Begin ("class=\"MED_VIDEO_CONT\"");
|
HTM_DIV_Begin ("class=\"MED_VIDEO_CONT\"");
|
||||||
HTM_TxtF ("<iframe src=\"https://www.youtube.com/embed/%s\""
|
|
||||||
" frameborder=\"0\""
|
/* iframe for video */
|
||||||
" allow=\"accelerometer; autoplay; encrypted-media;"
|
HTM_TxtF ("<iframe src=\"https://www.youtube.com/embed/%s\""
|
||||||
" gyroscope; picture-in-picture\""
|
" frameborder=\"0\""
|
||||||
" allowfullscreen=\"allowfullscreen\""
|
" allow=\"accelerometer; autoplay; encrypted-media;"
|
||||||
" class=\"%s\"",
|
" gyroscope; picture-in-picture\""
|
||||||
Media->Name,ClassMedia);
|
" allowfullscreen=\"allowfullscreen\""
|
||||||
if (Media->Title)
|
" class=\"%s\"",
|
||||||
if (Media->Title[0])
|
Media->Name,ClassMedia);
|
||||||
HTM_TxtF (" title=\"%s\"",Media->Title);
|
if (Media->Title)
|
||||||
HTM_Txt (">"
|
if (Media->Title[0])
|
||||||
"</iframe>");
|
HTM_TxtF (" title=\"%s\"",Media->Title);
|
||||||
|
HTM_Txt (">"
|
||||||
|
"</iframe>");
|
||||||
|
|
||||||
|
/* End container */
|
||||||
HTM_DIV_End ();
|
HTM_DIV_End ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1755,18 +1761,23 @@ static void Med_ShowEmbed (const struct Med_Media *Media,const char *ClassMedia)
|
||||||
// style="border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%;"
|
// style="border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%;"
|
||||||
// allowfullscreen>
|
// allowfullscreen>
|
||||||
// </iframe>
|
// </iframe>
|
||||||
|
/* Begin container */
|
||||||
HTM_DIV_Begin ("class=\"MED_EMBED_CONT\"");
|
HTM_DIV_Begin ("class=\"MED_EMBED_CONT\"");
|
||||||
HTM_TxtF ("<iframe src=\"%s\""
|
|
||||||
" frameborder=\"0\""
|
/* iframe for external media */
|
||||||
" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\""
|
HTM_TxtF ("<iframe src=\"%s\""
|
||||||
" allowfullscreen=\"allowfullscreen\""
|
" frameborder=\"0\""
|
||||||
" class=\"%s\"",
|
" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\""
|
||||||
Media->URL,ClassMedia);
|
" allowfullscreen=\"allowfullscreen\""
|
||||||
if (Media->Title)
|
" class=\"%s\"",
|
||||||
if (Media->Title[0])
|
Media->URL,ClassMedia);
|
||||||
HTM_TxtF (" title=\"%s\"",Media->Title);
|
if (Media->Title)
|
||||||
HTM_Txt (">"
|
if (Media->Title[0])
|
||||||
"</iframe>");
|
HTM_TxtF (" title=\"%s\"",Media->Title);
|
||||||
|
HTM_Txt (">"
|
||||||
|
"</iframe>");
|
||||||
|
|
||||||
|
/* End container */
|
||||||
HTM_DIV_End ();
|
HTM_DIV_End ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2037,32 +2048,12 @@ void Med_RemoveMedia (long MedCod)
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** Step 2. Remove entry for this media from database *****/
|
/***** Step 2. Remove entry for this media from database *****/
|
||||||
DB_QueryDELETE ("can not remove media",
|
Med_DB_RemoveMedia (MedCod);
|
||||||
"DELETE FROM med_media"
|
|
||||||
" WHERE MedCod=%ld",
|
|
||||||
MedCod);
|
|
||||||
|
|
||||||
/***** Free media *****/
|
/***** Free media *****/
|
||||||
Med_MediaDestructor (&Media);
|
Med_MediaDestructor (&Media);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/************************ Get media type from string *************************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
static Med_Type_t Med_GetTypeFromStrInDB (const char *Str)
|
|
||||||
{
|
|
||||||
Med_Type_t Type;
|
|
||||||
|
|
||||||
for (Type = (Med_Type_t) 0;
|
|
||||||
Type <= (Med_Type_t) (Med_NUM_TYPES - 1);
|
|
||||||
Type++)
|
|
||||||
if (!strcasecmp (Str,Med_StringsTypeDB[Type]))
|
|
||||||
return Type;
|
|
||||||
|
|
||||||
return Med_TYPE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************************ Get media type from extension **********************/
|
/************************ Get media type from extension **********************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2122,17 +2113,3 @@ static Med_Type_t Med_GetTypeFromExtAndMIME (const char *Extension,
|
||||||
|
|
||||||
return Med_TYPE_NONE;
|
return Med_TYPE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/*************** Get string media type in database from type *****************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
static const char *Med_GetStringTypeForDB (Med_Type_t Type)
|
|
||||||
{
|
|
||||||
/***** Check if type is out of valid range *****/
|
|
||||||
if (Type > (Med_Type_t) (Med_NUM_TYPES - 1))
|
|
||||||
return Med_StringsTypeDB[Med_TYPE_NONE];
|
|
||||||
|
|
||||||
/***** Get string from type *****/
|
|
||||||
return Med_StringsTypeDB[Type];
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// swad_media.h: processing of image/video uploaded in a form
|
// swad_media.h: processing of image/video uploaded in a form
|
||||||
|
|
||||||
#ifndef _SWAD_IMG
|
#ifndef _SWAD_MED
|
||||||
#define _SWAD_IMG
|
#define _SWAD_MED
|
||||||
/*
|
/*
|
||||||
SWAD (Shared Workspace At a Distance in Spanish),
|
SWAD (Shared Workspace At a Distance in Spanish),
|
||||||
is a web platform developed at the University of Granada (Spain),
|
is a web platform developed at the University of Granada (Spain),
|
||||||
|
|
|
@ -0,0 +1,155 @@
|
||||||
|
// swad_media_database.c: processing of image/video operations with database
|
||||||
|
|
||||||
|
/*
|
||||||
|
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-2021 Antonio Cañas Vargas
|
||||||
|
|
||||||
|
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 *********************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
#include <string.h> // For string functions
|
||||||
|
|
||||||
|
#include "swad_database.h"
|
||||||
|
#include "swad_media.h"
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/****************************** Public constants *****************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************************** Private constants *****************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static const char *Med_DB_StrTypes[Med_NUM_TYPES] =
|
||||||
|
{
|
||||||
|
[Med_TYPE_NONE] = "none",
|
||||||
|
[Med_JPG ] = "jpg",
|
||||||
|
[Med_GIF ] = "gif",
|
||||||
|
[Med_MP4 ] = "mp4",
|
||||||
|
[Med_WEBM ] = "webm",
|
||||||
|
[Med_OGG ] = "ogg",
|
||||||
|
[Med_YOUTUBE ] = "youtube",
|
||||||
|
[Med_EMBED ] = "embed",
|
||||||
|
};
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******************************* Private types *******************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************** External global variables from others modules ****************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
extern struct Globals Gbl;
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************************** Private global variables *************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************************** Private prototypes ****************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static const char *Med_DB_GetStringType (Med_Type_t Type);
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/**** Get media name, title and URL from a query result and copy to struct ***/
|
||||||
|
/*****************************************************************************/
|
||||||
|
// Returns the number of rows got
|
||||||
|
|
||||||
|
unsigned Med_DB_GetMediaDataByCod (MYSQL_RES **mysql_res,long MedCod)
|
||||||
|
{
|
||||||
|
/***** Get data of a media from database *****/
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get media",
|
||||||
|
"SELECT Type," // row[0]
|
||||||
|
"Name," // row[1]
|
||||||
|
"URL," // row[2]
|
||||||
|
"Title" // row[3]
|
||||||
|
" FROM med_media"
|
||||||
|
" WHERE MedCod=%ld",
|
||||||
|
MedCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************************ Store media into database **************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
long Med_DB_StoreMedia (const struct Med_Media *Media)
|
||||||
|
{
|
||||||
|
/***** Insert media into database *****/
|
||||||
|
return DB_QueryINSERTandReturnCode ("can not create media",
|
||||||
|
"INSERT INTO med_media"
|
||||||
|
" (Type,Name,URL,Title)"
|
||||||
|
" VALUES"
|
||||||
|
" ('%s','%s','%s','%s')",
|
||||||
|
Med_DB_GetStringType (Media->Type),
|
||||||
|
Media->Name ? Media->Name :
|
||||||
|
"",
|
||||||
|
Media->URL ? Media->URL :
|
||||||
|
"",
|
||||||
|
Media->Title ? Media->Title :
|
||||||
|
"");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************************* Remove media from database ************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Med_DB_RemoveMedia (long MedCod)
|
||||||
|
{
|
||||||
|
/***** Remove entry for this media from database *****/
|
||||||
|
DB_QueryDELETE ("can not remove media",
|
||||||
|
"DELETE FROM med_media"
|
||||||
|
" WHERE MedCod=%ld",
|
||||||
|
MedCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************************ Get media type from string *************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
Med_Type_t Med_DB_GetTypeFromStr (const char *Str)
|
||||||
|
{
|
||||||
|
Med_Type_t Type;
|
||||||
|
|
||||||
|
for (Type = (Med_Type_t) 0;
|
||||||
|
Type <= (Med_Type_t) (Med_NUM_TYPES - 1);
|
||||||
|
Type++)
|
||||||
|
if (!strcasecmp (Str,Med_DB_StrTypes[Type]))
|
||||||
|
return Type;
|
||||||
|
|
||||||
|
return Med_TYPE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*************** Get string media type in database from type *****************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static const char *Med_DB_GetStringType (Med_Type_t Type)
|
||||||
|
{
|
||||||
|
/***** Check if type is out of valid range *****/
|
||||||
|
if (Type > (Med_Type_t) (Med_NUM_TYPES - 1))
|
||||||
|
return Med_DB_StrTypes[Med_TYPE_NONE];
|
||||||
|
|
||||||
|
/***** Get string from type *****/
|
||||||
|
return Med_DB_StrTypes[Type];
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
// swad_media_database.h: processing of image/video uploaded in a form
|
||||||
|
|
||||||
|
#ifndef _SWAD_MED_DB
|
||||||
|
#define _SWAD_MED_DB
|
||||||
|
/*
|
||||||
|
SWAD (Shared Workspace At a Distance in Spanish),
|
||||||
|
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-2021 Antonio Cañas Vargas
|
||||||
|
|
||||||
|
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 <mysql/mysql.h> // To access MySQL databases
|
||||||
|
|
||||||
|
// #include "swad_cryptography.h"
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************************** Public constants ******************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******************************* Public types ********************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************************** Public prototypes *****************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Med_DB_GetMediaDataByCod (MYSQL_RES **mysql_res,long MedCod);
|
||||||
|
|
||||||
|
long Med_DB_StoreMedia (const struct Med_Media *Media);
|
||||||
|
|
||||||
|
void Med_DB_RemoveMedia (long MedCod);
|
||||||
|
|
||||||
|
Med_Type_t Med_DB_GetTypeFromStr (const char *Str);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue