Add: cration de vignette sur les photos des produits (ne gre pour le moment que le format jpg et png)
This commit is contained in:
parent
6b2b5f4956
commit
97fdd81283
@ -74,20 +74,31 @@ class Form
|
||||
\return string Code html du texte,picto
|
||||
*/
|
||||
function textwithtooltip($text,$htmltext,$tooltipon=1,$direction=0,$img='')
|
||||
{
|
||||
global $conf;
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (! $htmltext) return $text;
|
||||
|
||||
$paramfortooltiptext ='';
|
||||
$paramfortooltippicto ='';
|
||||
if ($conf->use_javascript)
|
||||
{
|
||||
// Sanitize tooltip
|
||||
$htmltext=ereg_replace("'","\'",$htmltext);
|
||||
$htmltext=ereg_replace("'","\'",$htmltext);
|
||||
if ($tooltipon==1 || $tooltipon==3)
|
||||
{
|
||||
$paramfortooltiptext ='';
|
||||
$paramfortooltippicto ='';
|
||||
|
||||
// Sanitize tooltip
|
||||
$htmltext=ereg_replace("'","\'",$htmltext);
|
||||
$htmltext=ereg_replace("'","\'",$htmltext);
|
||||
|
||||
if ($conf->use_ajax && $tooltipon == 4)
|
||||
{
|
||||
$s = '<script type=\'text/javascript\'>
|
||||
new Tip(\'tip1\', \''.$htmltext.'\');';
|
||||
$s.= '</script>';
|
||||
$s.= '<span id="tip1">'.$text.'</span>';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($conf->use_javascript)
|
||||
{
|
||||
if ($tooltipon==1 || $tooltipon==3)
|
||||
{
|
||||
$paramfortooltiptext.=' onmouseover="showtip(\''.$htmltext.'\')"';
|
||||
$paramfortooltiptext.=' onMouseout="hidetip()"';
|
||||
}
|
||||
@ -96,7 +107,7 @@ class Form
|
||||
$paramfortooltippicto.=' onmouseover="showtip(\''.$htmltext.'\')"';
|
||||
$paramfortooltippicto.=' onMouseout="hidetip()"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$s="";
|
||||
$s.='<table class="nobordernopadding"><tr>';
|
||||
@ -121,8 +132,9 @@ class Form
|
||||
}
|
||||
}
|
||||
$s.='</tr></table>';
|
||||
return $s;
|
||||
}
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Affiche un texte avec picto help qui affiche un tooltip
|
||||
|
||||
@ -1470,7 +1470,7 @@ function doliMoveFileUpload($src_file, $dest_file)
|
||||
// On renomme les fichiers avec extention executable car si on a mis le rep
|
||||
// documents dans un rep de la racine web (pas bien), cela permet d'executer
|
||||
// du code a la demande.
|
||||
if (eregi('\.php|\.pl|\.cgi$',$file_name))
|
||||
if (eregi('\.htm|\.html|\.php|\.pl|\.cgi$',$file_name))
|
||||
{
|
||||
$file_name.= '.txt';
|
||||
}
|
||||
@ -2927,4 +2927,93 @@ function print_date_range($date_start,$date_end)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* \brief Création d'une vignette à partir d'une image ($file)
|
||||
* \brief Les extension prise en compte sont jpg et png
|
||||
* \param file Chemin du fichier image à redimensionner
|
||||
* \param maxWidth Largeur maximum que dois faire la miniature (160 par défaut)
|
||||
* \param maxHeight Hauteur maximum que dois faire l'image (120 par défaut)
|
||||
* \return imgThumbName Chemin de la vignette
|
||||
*/
|
||||
function vignette($file, $maxWidth = 160, $maxHeight = 120){
|
||||
|
||||
// Vérification des erreurs dans les paramètres de la fonction
|
||||
//============================================================
|
||||
if(!file_exists($file)){
|
||||
// Si le fichier passé en paramètre n'existe pas
|
||||
return 'Le fichier '.$file.' n\'a pas été trouvé sur le serveur.';
|
||||
}
|
||||
elseif(empty($file)){
|
||||
// Si le fichier n'a pas été indiqué
|
||||
return 'Nom du fichier non renseigné.';
|
||||
}
|
||||
elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < 0){
|
||||
// Si la largeur max est incorrecte (n'est pas numérique, est vide, ou est inférieure à 0)
|
||||
return 'Valeur de la largeur incorrecte.';
|
||||
}
|
||||
elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < 0){
|
||||
// Si la hauteur max est incorrecte (n'est pas numérique, est vide, ou est inférieure à 0)
|
||||
return 'Valeur de la hauteur incorrecte.';
|
||||
}
|
||||
//============================================================
|
||||
|
||||
$fichier = realpath($file); // Chemin canonique absolu de l'image
|
||||
$dir = dirname($file).'/'; // Chemin du dossier contenant l'image
|
||||
$infoImg = getimagesize($fichier); // Récupération des infos de l'image
|
||||
$imgWidth = $infoImg[0]; // Largeur de l'image
|
||||
$imgHeight = $infoImg[1]; // Hauteur de l'image
|
||||
|
||||
// Initialisation des variables selon l'extension de l'image
|
||||
switch($infoImg[2]){
|
||||
case 2:
|
||||
$img = imagecreatefromjpeg($fichier); // Création d'une nouvelle image jpeg à partir du fichier
|
||||
$extImg = '.jpg'; // Extension de l'image
|
||||
break;
|
||||
case 3:
|
||||
$img = imagecreatefrompng($fichier); // Création d'une nouvelle image png à partir du fichier
|
||||
$extImg = '.png';
|
||||
}
|
||||
|
||||
// Initialisation des dimensions de la vignette si elles sont supérieures à l'original
|
||||
if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; }
|
||||
if($maxHeight > $imgHeight){ $maxHeight = $imgHeight; }
|
||||
|
||||
$whFact = $maxWidth/$maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette
|
||||
$imgWhFact = $imgWidth/$imgHeight; // Facteur largeur/hauteur de l'original
|
||||
|
||||
// Fixe les dimensions de la vignette
|
||||
if($whFact < $imgWhFact){
|
||||
// Si largeur déterminante
|
||||
$thumbWidth = $maxWidth;
|
||||
$thumbHeight = $thumbWidth / $imgWhFact;
|
||||
} else {
|
||||
// Si hauteur déterminante
|
||||
$thumbHeight = $maxHeight;
|
||||
$thumbWidth = $thumbHeight * $imgWhFact;
|
||||
}
|
||||
|
||||
$imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight); // Création de la vignette
|
||||
|
||||
imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insère l'image de base redimensionnée
|
||||
|
||||
$fileName = basename($file, $extImg); // Nom du fichier sans son extension
|
||||
$imgThumbName = $dir.$fileName.'_small'.$extImg; // Chemin complet du fichier de la vignette
|
||||
|
||||
//Création du fichier de la vignette
|
||||
$fp = fopen($imgThumbName, "w");
|
||||
fclose($fp);
|
||||
|
||||
// Renvoi la vignette créée
|
||||
switch($infoImg[2]){
|
||||
case 2:
|
||||
imagejpeg($imgThumb, $imgThumbName, 50); // Renvoi d'une image jpeg avec une qualité de 50
|
||||
break;
|
||||
case 3:
|
||||
imagepng($imgThumb, $imgThumbName);
|
||||
}
|
||||
|
||||
return $imgThumbName;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -2131,19 +2131,24 @@ class Product
|
||||
$dir .= "photos/";
|
||||
|
||||
if (! file_exists($dir))
|
||||
{
|
||||
dolibarr_syslog("Product Create $dir");
|
||||
create_exdir($dir);
|
||||
}
|
||||
{
|
||||
dolibarr_syslog("Product Create $dir");
|
||||
create_exdir($dir);
|
||||
}
|
||||
|
||||
if (file_exists($dir))
|
||||
{
|
||||
// Crée fichier en taille vignette
|
||||
// \todo A faire
|
||||
|
||||
// Crée fichier en taille origine
|
||||
doliMoveFileUpload($files['tmp_name'], $dir . $files['name']);
|
||||
}
|
||||
{
|
||||
$originImage = $dir . $files['name'];
|
||||
|
||||
// Crée fichier en taille origine
|
||||
doliMoveFileUpload($files['tmp_name'], $originImage);
|
||||
|
||||
if (file_exists($originImage))
|
||||
{
|
||||
// Crée fichier en taille vignette
|
||||
vignette($originImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2158,10 +2163,10 @@ class Product
|
||||
$dir .= "photos/";
|
||||
|
||||
if (! file_exists($dir))
|
||||
{
|
||||
dolibarr_syslog("Product Create $dir");
|
||||
create_exdir($dir);
|
||||
}
|
||||
{
|
||||
dolibarr_syslog("Product Create $dir");
|
||||
create_exdir($dir);
|
||||
}
|
||||
|
||||
if (file_exists($dir))
|
||||
{
|
||||
@ -2182,7 +2187,7 @@ class Product
|
||||
/**
|
||||
* \brief Affiche la première photo du produit
|
||||
* \param sdir Répertoire à scanner
|
||||
* \return boolean true si photo dispo, flase sinon
|
||||
* \return boolean true si photo dispo, false sinon
|
||||
*/
|
||||
function is_photo_available($sdir)
|
||||
{
|
||||
@ -2191,14 +2196,14 @@ class Product
|
||||
|
||||
$nbphoto=0;
|
||||
if (file_exists($dir))
|
||||
{
|
||||
$handle=opendir($dir);
|
||||
|
||||
while (($file = readdir($handle)) != false)
|
||||
{
|
||||
if (is_file($dir.$file)) return true;
|
||||
}
|
||||
}
|
||||
{
|
||||
$handle=opendir($dir);
|
||||
|
||||
while (($file = readdir($handle)) != false)
|
||||
{
|
||||
if (is_file($dir.$file)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2222,21 +2227,20 @@ class Product
|
||||
$handle=opendir($dir);
|
||||
|
||||
while (($file = readdir($handle)) != false)
|
||||
{
|
||||
$photo='';
|
||||
if (is_file($dir.$file)) $photo = $file;
|
||||
{
|
||||
$photo='';
|
||||
|
||||
if ($photo)
|
||||
{
|
||||
$nbphoto++;
|
||||
|
||||
if ($size == 1) { // Format vignette
|
||||
|
||||
// On determine nom du fichier vignette
|
||||
$photo_vignette='';
|
||||
if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$photo,$regs)) {
|
||||
$photo_vignette=eregi_replace($regs[0],'',$photo)."_small".$regs[0];
|
||||
}
|
||||
if (is_file($dir.$file) && !eregi('\_small',$file))
|
||||
{
|
||||
$nbphoto++;
|
||||
$photo = $file;
|
||||
|
||||
if ($size == 1) { // Format vignette
|
||||
// On determine nom du fichier vignette
|
||||
$photo_vignette='';
|
||||
if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$photo,$regs)) {
|
||||
$photo_vignette=eregi_replace($regs[0],'',$photo)."_small".$regs[0];
|
||||
}
|
||||
|
||||
|
||||
if ($nbbyrow && $nbphoto == 1) print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
|
||||
@ -2247,7 +2251,7 @@ class Product
|
||||
print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$photo).'" alt="Taille origine" target="_blank">';
|
||||
|
||||
// Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
|
||||
if ($photo_vignette && is_file($photo_vignette)) {
|
||||
if ($photo_vignette && is_file($dir.$photo_vignette)) {
|
||||
print '<img border="0" height="120" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$photo_vignette).'">';
|
||||
}
|
||||
else {
|
||||
@ -2298,39 +2302,39 @@ class Product
|
||||
$tabobj=array();
|
||||
|
||||
if (file_exists($dir))
|
||||
{
|
||||
$handle=opendir($dir);
|
||||
|
||||
while (($file = readdir($handle)) != false)
|
||||
{
|
||||
if (is_file($dir.$file))
|
||||
{
|
||||
$handle=opendir($dir);
|
||||
|
||||
while (($file = readdir($handle)) != false)
|
||||
{
|
||||
if (is_file($dir.$file) && !eregi('\_small',$file))
|
||||
{
|
||||
$nbphoto++;
|
||||
$photo = $file;
|
||||
$nbphoto++;
|
||||
$photo = $file;
|
||||
|
||||
// On determine nom du fichier vignette
|
||||
$photo_vignette='';
|
||||
if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$photo,$regs))
|
||||
{
|
||||
$photo_vignette=eregi_replace($regs[0],'',$photo).'_small'.$regs[0];
|
||||
}
|
||||
|
||||
// Objet
|
||||
$obj=array();
|
||||
$obj['photo']=$photo;
|
||||
if ($photo_vignette && is_file($dir.$photo_vignette)) $obj['photo_vignette']=$photo_vignette;
|
||||
else $obj['photo_vignette']="";
|
||||
|
||||
// On determine nom du fichier vignette
|
||||
$photo_vignette='';
|
||||
if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$photo,$regs))
|
||||
{
|
||||
$photo_vignette=eregi_replace($regs[0],'',$photo)."_small".$regs[0];
|
||||
}
|
||||
|
||||
// Objet
|
||||
$obj=array();
|
||||
$obj['photo']=$photo;
|
||||
if ($photo_vignette && is_file($photo_vignette)) $obj['photo_vignette']=$photo_vignette;
|
||||
else $obj['photo_vignette']="";
|
||||
|
||||
$tabobj[$nbphoto-1]=$obj;
|
||||
|
||||
// On continue ou on arrete de boucler ?
|
||||
if ($nbmax && $nbphoto >= $nbmax) break;
|
||||
$tabobj[$nbphoto-1]=$obj;
|
||||
|
||||
// On continue ou on arrete de boucler ?
|
||||
if ($nbmax && $nbphoto >= $nbmax) break;
|
||||
}
|
||||
}
|
||||
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
return $tabobj;
|
||||
}
|
||||
|
||||
|
||||
@ -661,12 +661,12 @@ if ($_GET["id"] || $_GET["ref"])
|
||||
if ($product->isproduct() && $conf->stock->enabled) $nblignes++;
|
||||
if ($product->isservice()) $nblignes++;
|
||||
if ($product->is_photo_available($conf->produit->dir_output))
|
||||
{
|
||||
{
|
||||
// Photo
|
||||
print '<td valign="middle" align="center" rowspan="'.$nblignes.'">';
|
||||
$nbphoto=$product->show_photos($conf->produit->dir_output,1,1,0);
|
||||
print '</td>';
|
||||
}
|
||||
}
|
||||
print '</tr>';
|
||||
|
||||
// Libelle
|
||||
|
||||
@ -178,12 +178,19 @@ if ($_GET["id"] || $_GET["ref"])
|
||||
print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">';
|
||||
|
||||
// Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
|
||||
if ($obj['photo_vignette']) $filename=$obj['photo_vignette'];
|
||||
else $filename=$obj['photo'];
|
||||
if ($obj['photo_vignette'])
|
||||
{
|
||||
$filename=$obj['photo_vignette'];
|
||||
$viewfilename=$obj['photo'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$filename=$obj['photo'];
|
||||
}
|
||||
print '<img border="0" height="120" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$filename).'">';
|
||||
|
||||
print '</a>';
|
||||
print '<br>'.$langs->trans("File").': '.dolibarr_trunc($filename,16);
|
||||
print '<br>'.$langs->trans("File").': '.dolibarr_trunc($viewfilename,16);
|
||||
if ($user->rights->produit->creer)
|
||||
{
|
||||
print '<br>'.'<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&action=delete&file='.urlencode($pdir.$filename).'">'.img_delete().'</a>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user