Version18.77.3

This commit is contained in:
Antonio Cañas Vargas 2019-03-16 16:15:15 +01:00
parent a95ad3969d
commit 8961260fbd
5 changed files with 106 additions and 63 deletions

View File

@ -2725,8 +2725,7 @@ a:hover img.CENTRE_PHOTO_SHOW
}
.MED_UPL_ICO /* Upload icon */
{
/* width:16px; */
height:16px;
height:20px;
margin:5px 20px;
vertical-align:middle;
}

View File

@ -771,44 +771,91 @@ function AJAXCreateObject () {
/****************************** Media uploader *******************************/
/*****************************************************************************/
function mediaActivateUpload (id) {
if (document.getElementById (id + '_par_upl').disabled) { // Upload disabled
function mediaClickOnActivateUpload (id) {
var par_upl = document.getElementById (id + '_par_upl');
document.getElementById (id + '_par_emb').disabled = true; // Disable embed
document.getElementById (id + '_par_upl').disabled = false; // Enable upload
if (par_upl.disabled) { // Click on highlighted icon
var par_emb = document.getElementById (id + '_par_emb');
var ico_upl = document.getElementById (id + '_ico_upl');
var ico_emb = document.getElementById (id + '_ico_emb');
var fil = document.getElementById (id + '_fil');
var url = document.getElementById (id + '_url');
var tit = document.getElementById (id + '_tit');
document.getElementById (id + '_ico_upl').style.opacity = '1'; // Highlight upload icon
document.getElementById (id + '_ico_emb').style.opacity = '0.3'; // Shadow embed icon
// Disable embed and enable upload
par_emb.disabled = true; // Disable embed
par_upl.disabled = false; // Enable upload
document.getElementById (id + '_fil').style.display = ''; // Show file input
document.getElementById (id + '_fil').disabled = false; // Enable file input
ico_upl.style.opacity = '1'; // Highlighted upload icon
ico_emb.style.opacity = '0.5'; // Normal embed icon
document.getElementById (id + '_url').style.display = ''; // Show URL input
document.getElementById (id + '_url').disabled = false; // Enable URL input
fil.style.display = ''; // Show file input
fil.disabled = false; // Enable file input
document.getElementById (id + '_tit').style.display = ''; // Show title input
document.getElementById (id + '_tit').disabled = false; // Enable title input
url.style.display = ''; // Show URL input
url.disabled = false; // Enable URL input
tit.style.display = ''; // Show title input
tit.disabled = false; // Enable title input
}
else // Click on shadowed icon
mediaDisableUploadAndEmbed (id);
}
function mediaActivateEmbed (id) {
if (document.getElementById (id + '_par_emb').disabled) { // Embed disabled
function mediaClickOnActivateEmbed (id) {
var par_emb = document.getElementById (id + '_par_emb');
document.getElementById (id + '_par_upl').disabled = true; // Disable upload
document.getElementById (id + '_par_emb').disabled = false; // Enable embed
if (par_emb.disabled) { // Click on highlighted icon
var par_upl = document.getElementById (id + '_par_upl');
var ico_upl = document.getElementById (id + '_ico_upl');
var ico_emb = document.getElementById (id + '_ico_emb');
var fil = document.getElementById (id + '_fil');
var url = document.getElementById (id + '_url');
var tit = document.getElementById (id + '_tit');
document.getElementById (id + '_ico_emb').style.opacity = '1'; // Highlight embed icon
document.getElementById (id + '_ico_upl').style.opacity = '0.3'; // Shadow upload icon
// Disable upload and enable embed
par_upl.disabled = true; // Disable upload
par_emb.disabled = false; // Enable embed
document.getElementById (id + '_fil').style.display = 'none'; // Hide file input
document.getElementById (id + '_fil').disabled = true; // Disable file input
ico_emb.style.opacity = '1'; // Highlighted embed icon
ico_upl.style.opacity = '0.5'; // Normal upload icon
document.getElementById (id + '_url').style.display = ''; // Show URL input
document.getElementById (id + '_url').disabled = false; // Enable URL input
fil.style.display = 'none'; // Hide file input
fil.disabled = true; // Disable file input
document.getElementById (id + '_tit').style.display = 'none'; // Hide title input
document.getElementById (id + '_tit').disabled = true; // Disable title input
url.style.display = ''; // Show URL input
url.disabled = false; // Enable URL input
tit.style.display = 'none'; // Hide title input
tit.disabled = true; // Disable title input
}
else // Click on shadowed icon
mediaDisableUploadAndEmbed (id);
}
function mediaDisableUploadAndEmbed (id) {
var par_upl = document.getElementById (id + '_par_upl');
var par_emb = document.getElementById (id + '_par_emb');
var ico_upl = document.getElementById (id + '_ico_upl');
var ico_emb = document.getElementById (id + '_ico_emb');
var fil = document.getElementById (id + '_fil');
var url = document.getElementById (id + '_url');
var tit = document.getElementById (id + '_tit');
par_upl.disabled = true; // Disable upload
par_emb.disabled = true; // Disable embed
ico_upl.style.opacity = '0.5'; // Normal upload icon
ico_emb.style.opacity = '0.5'; // Normal embed icon
fil.style.display = 'none'; // Hide file input
fil.disabled = true; // Disable file input
url.style.display = 'none'; // Hide URL input
url.disabled = true; // Disable URL input
tit.style.display = 'none'; // Hide title input
tit.disabled = true; // Disable title input
}
/*****************************************************************************/

View File

@ -454,8 +454,22 @@ ps2pdf source.ps destination.pdf
#define CSS_FILE "swad18.77.css"
#define JS_FILE "swad18.77.js"
/*
TODO: Mejorar javascript subida media
TODO: Cookies de terceros
Incrustar vídeos de YouTube hace que se guarden cookies de terceros,
lo cual implica tener que poner el maldito aviso.
Sólo se me ocurre que el usuario que quiera ver vídeos de YouTube
tendría que aceptar las cookies de terceros, que por defecto estarían bloqueadas.
Es decir, por defecto en vez de mostrarse un vídeo de YouTube
se mostraría un aviso indicando que si se desea ver el vídeo
hay que consentir las cookies de terceros.
Si el usuario acepta, a partir de ese momento se le mostrarían los vídeos.
Ese bloqueo o aceptación sería una opción en Perfil > Ajustes
que el usuario podría cambiar en cualquier momento.
TODO: Fix edition of media in test edition
Version 18.77.3: Mar 16, 2019 Embedded YouTube videos. Not finished. (240252 lines)
Version 18.77.2: Mar 14, 2019 Embedded YouTube videos. Not finished. (240267 lines)
Version 18.77.1: Mar 14, 2019 Embedded YouTube videos. Not finished. (240217 lines)
Version 18.77: Mar 14, 2019 Embedded YouTube videos. Not finished. (240214 lines)
7 changes necessary in database:

View File

@ -278,7 +278,7 @@ void Med_GetMediaDataFromRow (const char *Name,
/********* Draw input fields to upload an image/video inside a form **********/
/*****************************************************************************/
void Med_PutMediaUploader (int NumMediaInForm,const char *ClassMediaTitURL)
void Med_PutMediaUploader (int NumMediaInForm,const char *ClassInput)
{
extern const char *Txt_Image_video;
extern const char *Txt_Title_attribution;
@ -304,7 +304,7 @@ void Med_PutMediaUploader (int NumMediaInForm,const char *ClassMediaTitURL)
"<img src=\"%s/file-image.svg\""
" alt=\"%s\" title=\"%s\""
" class=\"MED_UPL_ICO ICO_HIGHLIGHT\""
" onclick=\"mediaActivateUpload('%s');\" />"
" onclick=\"mediaClickOnActivateUpload('%s');\" />"
"</div>", // <id>_ico_upl
Id,
Gbl.Prefs.URLIcons,
@ -325,7 +325,7 @@ void Med_PutMediaUploader (int NumMediaInForm,const char *ClassMediaTitURL)
"<img src=\"%s/youtube-brands.svg\""
" alt=\"%s\" title=\"%s\""
" class=\"MED_UPL_ICO ICO_HIGHLIGHT\""
" onclick=\"mediaActivateEmbed('%s');\" />"
" onclick=\"mediaClickOnActivateEmbed('%s');\" />"
"</div>", // <id>_ico_emb
Id,
Gbl.Prefs.URLIcons,
@ -343,10 +343,11 @@ void Med_PutMediaUploader (int NumMediaInForm,const char *ClassMediaTitURL)
/***** Media file *****/
fprintf (Gbl.F.Out,"<input id=\"%s_fil\" type=\"file\"" // <id>_fil
" name=\"%s\" accept=\"image/,video/\""
" disabled=\"disabled\""
" class=\"%s\" disabled=\"disabled\""
" style=\"display:none;\" />", // <id>_fil
Id,
ParamUploadMedia.File);
ParamUploadMedia.File,
ClassInput);
/***** Media URL *****/
fprintf (Gbl.F.Out,"<input id=\"%s_url\" type=\"url\"" // <id>_url
@ -356,7 +357,7 @@ void Med_PutMediaUploader (int NumMediaInForm,const char *ClassMediaTitURL)
" style=\"display:none;\" />", // <id>_url
Id,
ParamUploadMedia.URL,Txt_Link,
ClassMediaTitURL,Cns_MAX_CHARS_WWW);
ClassInput,Cns_MAX_CHARS_WWW);
/***** Media title *****/
fprintf (Gbl.F.Out,"<input id=\"%s_tit\" type=\"text\"" // <id>_tit
@ -366,7 +367,7 @@ void Med_PutMediaUploader (int NumMediaInForm,const char *ClassMediaTitURL)
" style=\"display:none;\" />", // <id>_tit
Id,
ParamUploadMedia.Title,Txt_Title_attribution,
ClassMediaTitURL,Med_MAX_CHARS_TITLE);
ClassInput,Med_MAX_CHARS_TITLE);
/***** End container *****/
fprintf (Gbl.F.Out,"</div>"); // container
@ -941,7 +942,6 @@ static void Med_GetAndProcessEmbedFromForm (const char *ParamURL,
char *PtrParams = NULL;
char *PtrCode = NULL;
size_t CodeLength;
char *Code;
enum
{
WRONG, // Bad formed YouTube URL
@ -1073,34 +1073,17 @@ static void Med_GetAndProcessEmbedFromForm (const char *ParamURL,
// Ale_ShowAlert (Ale_INFO,"DEBUG: PtrCode = '%s'",PtrCode);
/***** Step 5: Get video code *****/
CodeLength = strspn (PtrCode,Str_BIN_TO_BASE64URL);
if (CodeLength > 0)
if (CodeLength > 0 &&
CodeLength <= Med_BYTES_NAME)
{
/* Allocate space for YouTube code */
if ((Code = (char *) malloc (CodeLength + 1)) == NULL)
Lay_ShowErrorAndExit ("Error allocating memory for YouTube code.");
/***** Success! *****/
/* Copy code */
strncpy (Code,PtrCode,CodeLength);
Code[CodeLength] = '\0';
// Ale_ShowAlert (Ale_INFO,"DEBUG: Code = '%s'",Code);
strncpy (Media->Name,PtrCode,CodeLength);
Media->Name[CodeLength] = '\0';
// Ale_ShowAlert (Ale_INFO,"DEBUG: Media->Name = '%s'",Media->Name);
/* Overwrite current URL with the embed URL */
Med_FreeMediaURL (Media);
if (asprintf (&Media->URL,"https://www.youtube.com/embed/%s",
Code) < 0)
Lay_NotEnoughMemoryExit ();
if (strlen (Media->URL) <= Cns_MAX_BYTES_WWW)
{
/***** Success! *****/
// Ale_ShowAlert (Ale_INFO,"DEBUG: Media->URL = '%s'",Media->URL);
Media->Type = Med_YOUTUBE;
Media->Status = Med_PROCESSED;
}
else
Med_FreeMediaURL (Media);
/* Free YouTube code */
free ((void *) Code);
Media->Type = Med_YOUTUBE;
Media->Status = Med_PROCESSED;
}
}
}
@ -1501,13 +1484,13 @@ static void Med_ShowYoutube (struct Media *Media,
// allow="accelerometer; autoplay; encrypted-media;
// gyroscope; picture-in-picture" allowfullscreen>
// </iframe>
fprintf (Gbl.F.Out,"<iframe src=\"%s\""
fprintf (Gbl.F.Out,"<iframe src=\"https://www.youtube.com/embed/%s\""
" frameborder=\"0\""
" allow=\"accelerometer; autoplay; encrypted-media;"
" gyroscope; picture-in-picture\""
" allowfullscreen=\"allowfullscreen\""
" class=\"%s\"",
Media->URL,ClassMedia);
Media->Name,ClassMedia);
if (Media->Title)
if (Media->Title[0])
fprintf (Gbl.F.Out," title=\"%s\"",Media->Title);

View File

@ -143,7 +143,7 @@ void Med_GetMediaDataFromRow (const char *Name,
const char *URL,
struct Media *Media);
void Med_PutMediaUploader (int NumMediaInForm,const char *ClassMediaTitURL);
void Med_PutMediaUploader (int NumMediaInForm,const char *ClassInput);
void Med_GetMediaFromForm (int NumMediaInForm,struct Media *Media,
void (*GetMediaFromDB) (int NumMediaInForm,struct Media *Media));
void Med_SetParamNames (struct ParamUploadMedia *ParamUploadMedia,int NumMediaInForm);