Version 15.194.2

This commit is contained in:
Antonio Cañas Vargas 2016-04-14 19:19:55 +02:00
parent 2cc8a82af1
commit 65671ee700
7 changed files with 47 additions and 54 deletions

View File

@ -137,13 +137,14 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 15.194.1 (2016-04-14)"
#define Log_PLATFORM_VERSION "SWAD 15.194.2 (2016-04-14)"
#define CSS_FILE "swad15.193.css"
#define JS_FILE "swad15.193.js"
// Number of lines (includes comments but not blank lines) has been got with the following command:
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
/*
Version 15.194.2: Apr 14, 2016 Code refactoring related to uploading images. (199384 lines)
Version 15.194.1: Apr 14, 2016 Code refactoring related to uploading images. (199391 lines)
Version 15.194: Apr 14, 2016 Code refactoring related to uploading images. (199391 lines)
Version 15.193: Apr 14, 2016 New layout of button used to upload images. (199357 lines)

View File

@ -3905,11 +3905,10 @@ void For_RecForumPst (void)
ParamUploadImg.Action = "ImgAct";
ParamUploadImg.File = "ImgFil";
ParamUploadImg.Title = "ImgTit";
Img_GetImageFromForm (-1,&Image,NULL,
&ParamUploadImg,
For_IMAGE_SAVED_MAX_WIDTH,
For_IMAGE_SAVED_MAX_HEIGHT,
For_IMAGE_SAVED_QUALITY);
Image.Width = For_IMAGE_SAVED_MAX_WIDTH;
Image.Height = For_IMAGE_SAVED_MAX_HEIGHT;
Image.Quality = For_IMAGE_SAVED_QUALITY;
Img_GetImageFromForm (-1,&Image,NULL,&ParamUploadImg);
/***** Create a new message *****/
if (PstIsAReply) // This post is a reply to another posts in the thread

View File

@ -64,9 +64,9 @@ extern struct Globals Gbl;
/***************************** Internal prototypes ***************************/
/*****************************************************************************/
static void Img_ProcessImage (const char *FileNameImgOriginal,
const char *FileNameImgProcessed,
unsigned Width,unsigned Height,unsigned Quality);
static void Img_ProcessImage (struct Image *Image,
const char *FileNameImgOriginal,
const char *FileNameImgProcessed);
/*****************************************************************************/
/*************************** Reset image fields ******************************/
@ -206,10 +206,9 @@ void Img_PutImageUploader (const char *ClassImgTit,
/***************************** Get image from form ***************************/
/*****************************************************************************/
void Img_GetImageFromForm (unsigned NumOpt,struct Image *Image,
void Img_GetImageFromForm (int NumOpt,struct Image *Image,
void (*GetImageFromDB) (int NumOpt,struct Image *Image),
struct ParamUploadImg *ParamUploadImg,
unsigned Width,unsigned Height,unsigned Quality)
struct ParamUploadImg *ParamUploadImg)
{
char Title[Img_MAX_BYTES_TITLE+1];
size_t Length;
@ -225,8 +224,7 @@ void Img_GetImageFromForm (unsigned NumOpt,struct Image *Image,
{
case Img_ACTION_NEW_IMAGE: // Upload new image
/***** Get new image (if present ==> process and create temporary file) *****/
Img_GetAndProcessImageFileFromForm (Image,ParamUploadImg->File,
Width,Height,Quality);
Img_GetAndProcessImageFileFromForm (Image,ParamUploadImg->File);
if (Image->Status != Img_FILE_PROCESSED) // No new image received-processed successfully
{
/* Reset image name */
@ -241,8 +239,7 @@ void Img_GetImageFromForm (unsigned NumOpt,struct Image *Image,
break;
case Img_ACTION_CHANGE_IMAGE: // Replace old image by new image
/***** Get new image (if present ==> process and create temporary file) *****/
Img_GetAndProcessImageFileFromForm (Image,ParamUploadImg->File,
Width,Height,Quality);
Img_GetAndProcessImageFileFromForm (Image,ParamUploadImg->File);
if (Image->Status != Img_FILE_PROCESSED && // No new image received-processed successfully
GetImageFromDB != NULL)
/* Get image name */
@ -292,8 +289,7 @@ Img_Action_t Img_GetImageActionFromForm (const char *ParamAction)
/**************************** Get image from form ****************************/
/*****************************************************************************/
void Img_GetAndProcessImageFileFromForm (struct Image *Image,const char *ParamFile,
unsigned Width,unsigned Height,unsigned Quality)
void Img_GetAndProcessImageFileFromForm (struct Image *Image,const char *ParamFile)
{
struct Param *Param;
char FileNameImgSrc[PATH_MAX+1];
@ -363,7 +359,7 @@ void Img_GetAndProcessImageFileFromForm (struct Image *Image,const char *ParamFi
sprintf (FileNameImgTmp,"%s/%s/%s/%s.jpg",
Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_IMG,Cfg_FOLDER_IMG_TMP,
Image->Name);
Img_ProcessImage (FileNameImgOrig,FileNameImgTmp,Width,Height,Quality);
Img_ProcessImage (Image,FileNameImgOrig,FileNameImgTmp);
Image->Status = Img_FILE_PROCESSED;
/***** Remove temporary original file *****/
@ -375,16 +371,18 @@ void Img_GetAndProcessImageFileFromForm (struct Image *Image,const char *ParamFi
/************ Process original image generating processed image **************/
/*****************************************************************************/
static void Img_ProcessImage (const char *FileNameImgOriginal,
const char *FileNameImgProcessed,
unsigned Width,unsigned Height,unsigned Quality)
static void Img_ProcessImage (struct Image *Image,
const char *FileNameImgOriginal,
const char *FileNameImgProcessed)
{
char Command[1024+PATH_MAX*2];
int ReturnCode;
sprintf (Command,"convert %s -resize '%ux%u>' -quality %u %s",
FileNameImgOriginal,
Width,Height,Quality,
Image->Width,
Image->Height,
Image->Quality,
FileNameImgProcessed);
ReturnCode = system (Command);
if (ReturnCode == -1)

View File

@ -89,6 +89,9 @@ struct Image
char Name[Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64+1];
char *Title; // Title/attribution (it must be initialized to NULL
// in order to not trying to free it when no memory allocated)
unsigned Width;
unsigned Height;
unsigned Quality;
};
struct ParamUploadImg
@ -113,12 +116,10 @@ void Img_GetImageNameAndTitleFromRow (const char *Name,const char *Title,
void Img_PutImageUploader (const char *ClassImgTit,
struct ParamUploadImg *ParamUploadImg);
void Img_GetImageFromForm (int NumOpt,struct Image *Image,
void (*GetImageFromDB) (unsigned NumOpt,struct Image *Image),
struct ParamUploadImg *ParamUploadImg,
unsigned Width,unsigned Height,unsigned Quality);
void (*GetImageFromDB) (int NumOpt,struct Image *Image),
struct ParamUploadImg *ParamUploadImg);
Img_Action_t Img_GetImageActionFromForm (const char *ParamAction);
void Img_GetAndProcessImageFileFromForm (struct Image *Image,const char *ParamFile,
unsigned Width,unsigned Height,unsigned Quality);
void Img_GetAndProcessImageFileFromForm (struct Image *Image,const char *ParamFile);
void Img_MoveImageToDefinitiveDirectory (struct Image *Image);
void Img_ShowImage (struct Image *Image,const char *ClassImg);

View File

@ -780,11 +780,10 @@ void Msg_RecMsgFromUsr (void)
ParamUploadImg.Action = "ImgAct";
ParamUploadImg.File = "ImgFil";
ParamUploadImg.Title = "ImgTit";
Img_GetImageFromForm (-1,&Image,NULL,
&ParamUploadImg,
Msg_IMAGE_SAVED_MAX_WIDTH,
Msg_IMAGE_SAVED_MAX_HEIGHT,
Msg_IMAGE_SAVED_QUALITY);
Image.Width = Msg_IMAGE_SAVED_MAX_WIDTH;
Image.Height = Msg_IMAGE_SAVED_MAX_HEIGHT;
Image.Quality = Msg_IMAGE_SAVED_QUALITY;
Img_GetImageFromForm (-1,&Image,NULL,&ParamUploadImg);
/***** Loop over the list Gbl.Usrs.Select.All, that holds the list of the
recipients, creating a received message for each recipient *****/

View File

@ -2096,11 +2096,10 @@ static long Soc_ReceiveSocialPost (void)
ParamUploadImg.Action = "ImgAct";
ParamUploadImg.File = "ImgFil";
ParamUploadImg.Title = "ImgTit";
Img_GetImageFromForm (-1,&Image,NULL,
&ParamUploadImg,
Soc_IMAGE_SAVED_MAX_WIDTH,
Soc_IMAGE_SAVED_MAX_HEIGHT,
Soc_IMAGE_SAVED_QUALITY);
Image.Width = Soc_IMAGE_SAVED_MAX_WIDTH;
Image.Height = Soc_IMAGE_SAVED_MAX_HEIGHT;
Image.Quality = Soc_IMAGE_SAVED_QUALITY;
Img_GetImageFromForm (-1,&Image,NULL,&ParamUploadImg);
if (Content[0] || // Text not empty
Image.Name[0]) // An image is attached
@ -2856,11 +2855,10 @@ static long Soc_ReceiveComment (void)
ParamUploadImg.Action = "ImgAct";
ParamUploadImg.File = "ImgFil";
ParamUploadImg.Title = "ImgTit";
Img_GetImageFromForm (-1,&Image,NULL,
&ParamUploadImg,
Soc_IMAGE_SAVED_MAX_WIDTH,
Soc_IMAGE_SAVED_MAX_HEIGHT,
Soc_IMAGE_SAVED_QUALITY);
Image.Width = Soc_IMAGE_SAVED_MAX_WIDTH;
Image.Height = Soc_IMAGE_SAVED_MAX_HEIGHT;
Image.Quality = Soc_IMAGE_SAVED_QUALITY;
Img_GetImageFromForm (-1,&Image,NULL,&ParamUploadImg);
if (Content[0] || // Text not empty
Image.Name[0]) // An image is attached

View File

@ -5189,12 +5189,10 @@ static void Tst_GetQstFromForm (char *Stem,char *Feedback)
ParamUploadImg.Action = "ImgAct";
ParamUploadImg.File = "ImgFil";
ParamUploadImg.Title = "ImgTit";
Img_GetImageFromForm (-1,&Gbl.Test.Image,
Tst_GetImageFromDB,
&ParamUploadImg,
Tst_IMAGE_SAVED_MAX_WIDTH,
Tst_IMAGE_SAVED_MAX_HEIGHT,
Tst_IMAGE_SAVED_QUALITY);
Gbl.Test.Image.Width = Tst_IMAGE_SAVED_MAX_WIDTH;
Gbl.Test.Image.Height = Tst_IMAGE_SAVED_MAX_HEIGHT;
Gbl.Test.Image.Quality = Tst_IMAGE_SAVED_QUALITY;
Img_GetImageFromForm (-1,&Gbl.Test.Image,Tst_GetImageFromDB,&ParamUploadImg);
/***** Get answers *****/
Gbl.Test.Shuffle = false;
@ -5253,12 +5251,11 @@ static void Tst_GetQstFromForm (char *Stem,char *Feedback)
ParamUploadImg.Action = ParamAction;
ParamUploadImg.File = ParamFile;
ParamUploadImg.Title = ParamTitle;
Gbl.Test.Answer.Options[NumOpt].Image.Width = Tst_IMAGE_SAVED_MAX_WIDTH;
Gbl.Test.Answer.Options[NumOpt].Image.Height = Tst_IMAGE_SAVED_MAX_HEIGHT;
Gbl.Test.Answer.Options[NumOpt].Image.Quality = Tst_IMAGE_SAVED_QUALITY;
Img_GetImageFromForm ((int) NumOpt,&Gbl.Test.Answer.Options[NumOpt].Image,
Tst_GetImageFromDB,
&ParamUploadImg,
Tst_IMAGE_SAVED_MAX_WIDTH,
Tst_IMAGE_SAVED_MAX_HEIGHT,
Tst_IMAGE_SAVED_QUALITY);
Tst_GetImageFromDB,&ParamUploadImg);
}
}