From 6dc6bab5568858fbea3bf0f6d89588d070cacb4f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 17 Nov 2015 10:38:00 +0100 Subject: [PATCH] Support of 'small', 'mini' and '' image size everywhere. --- htdocs/core/class/html.form.class.php | 13 +++++++--- htdocs/core/lib/functions.lib.php | 6 ++--- .../install/mysql/migration/3.8.0-3.9.0.sql | 1 + htdocs/product/class/product.class.php | 25 +++++++++---------- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 9f56fe507bb22..6974daabc0096 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5304,7 +5304,7 @@ static function showphoto($modulepart, $object, $width=100, $height=0, $caneditf $entity = (! empty($object->entity) ? $object->entity : $conf->entity); $id = (! empty($object->id) ? $object->id : $object->rowid); - $ret='';$dir='';$file='';$altfile='';$email=''; + $ret='';$dir='';$file='';$originalfile='';$altfile='';$email=''; if ($modulepart=='societe') { @@ -5313,9 +5313,11 @@ static function showphoto($modulepart, $object, $width=100, $height=0, $caneditf $smallfile=preg_replace('/(\.png|\.gif|\.jpg|\.jpeg|\.bmp)/i','_small\\1',$smallfile); if (! empty($object->logo)) { + // TODO Introduce get_exdir if ((string) $imagesize == 'mini') $file=$id.'/logos/thumbs/'.getImageFileNameForSize($object->logo, '_mini'); else if ((string) $imagesize == 'small') $file=$id.'/logos/thumbs/'.getImageFileNameForSize($object->logo, '_small'); else $file=$id.'/logos/thumbs/'.$smallfile; + $originalfile=$id.'/logos/thumbs/'.$smallfile; } } else if ($modulepart=='contact') @@ -5323,9 +5325,11 @@ static function showphoto($modulepart, $object, $width=100, $height=0, $caneditf $dir=$conf->societe->multidir_output[$entity].'/contact'; if (! empty($object->photo)) { + // TODO Introduce get_exdir if ((string) $imagesize == 'mini') $file=$id.'/photos/thumbs/'.getImageFileNameForSize($object->photo, '_mini'); else if ((string) $imagesize == 'small') $file=$id.'/photos/thumbs/'.getImageFileNameForSize($object->photo, '_small'); else $file=$id.'/photos/'.$object->photo; + $originalfile=$id.'/photos/'.$object->photo; } } else if ($modulepart=='userphoto') @@ -5336,6 +5340,7 @@ static function showphoto($modulepart, $object, $width=100, $height=0, $caneditf if ((string) $imagesize == 'mini') $file=get_exdir($id, 2, 0, 0, $object, 'user').getImageFileNameForSize($object->photo, '_mini'); else if ((string) $imagesize == 'small') $file=get_exdir($id, 2, 0, 0, $object, 'user').getImageFileNameForSize($object->photo, '_small'); else $file=get_exdir($id, 2, 0, 0, $object, 'user').$object->photo; + $originalfile=get_exdir($id, 2, 0, 0, $object, 'user').$object->photo; } if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility $email=$object->email; @@ -5348,6 +5353,7 @@ static function showphoto($modulepart, $object, $width=100, $height=0, $caneditf if ((string) $imagesize == 'mini') $file=get_exdir($id, 2, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_mini'); else if ((string) $imagesize == 'small') $file=get_exdir($id, 2, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_small'); else $file=get_exdir($id, 2, 0, 0, $object, 'member').'photos/'.$object->photo; + $originalfile=get_exdir($id, 2, 0, 0, $object, 'member').'photos/'.$object->photo; } if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility $email=$object->email; @@ -5360,6 +5366,7 @@ static function showphoto($modulepart, $object, $width=100, $height=0, $caneditf if ((string) $imagesize == 'mini') $file=get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.getImageFileNameForSize($object->photo, '_mini'); else if ((string) $imagesize == 'small') $file=get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.getImageFileNameForSize($object->photo, '_small'); else $file=get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.$object->photo; + $originalfile=get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.$object->photo; } if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility $email=$object->email; @@ -5369,13 +5376,13 @@ static function showphoto($modulepart, $object, $width=100, $height=0, $caneditf { if ($file && file_exists($dir."/".$file)) { - if ($addlinktofullsize) $ret.=''; + if ($addlinktofullsize) $ret.=''; $ret.='Photo'; if ($addlinktofullsize) $ret.=''; } else if ($altfile && file_exists($dir."/".$altfile)) { - if ($addlinktofullsize) $ret.=''; + if ($addlinktofullsize) $ret.=''; $ret.='Photo alt'; if ($addlinktofullsize) $ret.=''; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 4a94863e8c4e4..5685a2fbb92cc 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -892,7 +892,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r $showimage=$object->is_photo_available($conf->product->multidir_output[$object->entity]); $maxvisiblephotos=(isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO)?$conf->global->PRODUCT_MAX_VISIBLE_PHOTO:5); if ($conf->browser->phone) $maxvisiblephotos=1; - if ($showimage) $morehtmlleft.='
'.$object->show_photos($conf->product->multidir_output[$object->entity],1,-$maxvisiblephotos,0,0,0,$width,0).'
'; + if ($showimage) $morehtmlleft.='
'.$object->show_photos($conf->product->multidir_output[$object->entity],'small',-$maxvisiblephotos,0,0,0,$width,0).'
'; else { $nophoto='/public/theme/common/nophoto.png'; @@ -901,7 +901,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r } else { - if ($showimage) $morehtmlleft.='
'.$form->showphoto($modulepart,$object,0,0,0,'photoref','',1,0,$maxvisiblephotos).'
'; + if ($showimage) $morehtmlleft.='
'.$form->showphoto($modulepart,$object,0,0,0,'photoref','small',1,0,$maxvisiblephotos).'
'; } if ($showbarcode) $morehtmlleft.='
'.$form->showbarcode($object).'
'; if ($object->element == 'societe' && ! empty($conf->use_javascript_ajax) && $user->rights->societe->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { @@ -5325,7 +5325,7 @@ function natural_search($fields, $value, $mode=0, $nofirstand=0) * * @param string $file Original filename (full or relative path) * @param string $extName Extension to differenciate thumb file name ('', '_small', '_mini') - * @param string $extImgTarget Force image extension for thumbs. Use '' to keep same extension than original image. + * @param string $extImgTarget Force image extension for thumbs. Use '' to keep same extension than original image. Use '.png' for generated thumb files. * @return string New file name (full or relative path, including the thumbs/) */ function getImageFileNameForSize($file, $extName, $extImgTarget='') diff --git a/htdocs/install/mysql/migration/3.8.0-3.9.0.sql b/htdocs/install/mysql/migration/3.8.0-3.9.0.sql index a1a64fcfbce22..75d9e03cda9d1 100755 --- a/htdocs/install/mysql/migration/3.8.0-3.9.0.sql +++ b/htdocs/install/mysql/migration/3.8.0-3.9.0.sql @@ -15,6 +15,7 @@ -- To make pk to be auto increment (postgres): VPGSQL8.2 NOT POSSIBLE. MUST DELETE/CREATE TABLE -- To set a field as NULL: VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name DROP NOT NULL; -- To set a field as default NULL: VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET DEFAULT NULL; +-- Note: fields with type BLOB/TEXT can't have default value. -- -- VPGSQL8.2 DELETE FROM llx_usergroup_user WHERE fk_user NOT IN (SELECT rowid from llx_user); -- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 30c6d82d73f3d..258e79be2c0de 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3503,13 +3503,13 @@ function is_photo_available($sdir) * TODO Move this into html.formproduct.class.php * * @param string $sdir Directory to scan - * @param int $size 0=original size, 1 use thumbnail if possible + * @param int $size 0=original size, 1='small' use thumbnail if possible * @param int $nbmax Nombre maximum de photos (0=pas de max) * @param int $nbbyrow Number of image per line or -1 to use div. Used only if size=1. * @param int $showfilename 1=Show filename * @param int $showaction 1=Show icon with action links (resize, delete) - * @param int $maxHeight Max height of image when size=1 - * @param int $maxWidth Max width of image when size=1 + * @param int $maxHeight Max height of original image when size='small' (so we can use original even if small requested). If 0, always use 'small' thumb image. + * @param int $maxWidth Max width of original image when size='small' * @param int $nolink Do not add a href link to view enlarged imaged into a new tab * @return string Html code to show photo. Number of photos shown is saved in this->nbphoto */ @@ -3557,14 +3557,12 @@ function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5,$showfilename=0,$showacti $photo = $file; $viewfilename = $file; - if ($size == 1) { // Format vignette - // On determine nom du fichier vignette - $photo_vignette=''; - if (preg_match('/(\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $photo, $regs)) { - $photo_vignette=preg_replace('/'.$regs[0].'/i', '', $photo)."_small".$regs[0]; - if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; - } + if ($size == 1 || $size == 'small') { // Format vignette + // Find name of thumb file + $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small', '.png')); + if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; + // Get filesize of original file $imgarray=dol_getImageSize($dir.$photo); @@ -3584,7 +3582,8 @@ function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5,$showfilename=0,$showacti // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine $alt=$langs->transnoentitiesnoconv('File').': '.$pdir.$photo; $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height']; - if ($photo_vignette && $imgarray['height'] > $maxHeight) + + if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) { $return.= ''; $return.= 'dol_use_jmobile?'max-height':'height').'="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">'; @@ -3626,7 +3625,7 @@ function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5,$showfilename=0,$showacti else if ($nbbyrow < 0) $return.=''; } - if ($size == 0) { // Format origine + if (empty($size)) { // Format origine $return.= ''; if ($showfilename) $return.= '
'.$viewfilename; @@ -3650,7 +3649,7 @@ function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5,$showfilename=0,$showacti } } - if ($size==1) + if ($size==1 || $size='small') { if ($nbbyrow > 0) {