Fix: Meilleur gestion erreur sur generation vignettes
New: Conserve la transparence dans la generation des vignettes.
This commit is contained in:
parent
b22a3491c8
commit
809ae9ef22
@ -55,7 +55,8 @@ if ( (isset($_POST["action"]) && $_POST["action"] == 'update')
|
|||||||
{
|
{
|
||||||
$original_file=$reg[1];
|
$original_file=$reg[1];
|
||||||
|
|
||||||
if (eregi('(\.png|\.jpg|\.jpeg)$',$original_file))
|
$isimage=image_format_supported($original_file);
|
||||||
|
if ($isimage >= 0)
|
||||||
{
|
{
|
||||||
dolibarr_syslog("Move file ".$_FILES["logo"]["tmp_name"]." to ".$conf->societe->dir_logos.'/'.$original_file);
|
dolibarr_syslog("Move file ".$_FILES["logo"]["tmp_name"]." to ".$conf->societe->dir_logos.'/'.$original_file);
|
||||||
if (! is_dir($conf->societe->dir_logos))
|
if (! is_dir($conf->societe->dir_logos))
|
||||||
@ -66,21 +67,27 @@ if ( (isset($_POST["action"]) && $_POST["action"] == 'update')
|
|||||||
{
|
{
|
||||||
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO",$original_file);
|
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO",$original_file);
|
||||||
|
|
||||||
// Création de la vignette de la page login
|
// Create thumbs of logo
|
||||||
$imgThumbSmall = vignette($conf->societe->dir_logos.'/'.$original_file, 200, 100, '_small',80);
|
if ($isimage > 0)
|
||||||
if (eregi('([^\\\/:]+)$',$imgThumbSmall,$reg))
|
|
||||||
{
|
{
|
||||||
$imgThumbSmall = $reg[1];
|
$imgThumbSmall = vignette($conf->societe->dir_logos.'/'.$original_file, 200, 100, '_small',80);
|
||||||
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$imgThumbSmall);
|
if (eregi('([^\\\/:]+)$',$imgThumbSmall,$reg))
|
||||||
}
|
{
|
||||||
|
$imgThumbSmall = $reg[1];
|
||||||
|
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$imgThumbSmall);
|
||||||
|
}
|
||||||
|
else dolibarr_syslog($imgThumbSmall);
|
||||||
|
|
||||||
// Création de la vignette de la page "Société/Institution"
|
// Création de la vignette de la page "Société/Institution"
|
||||||
$imgThumbMini = vignette($conf->societe->dir_logos.'/'.$original_file, 100, 30, '_mini',80);
|
$imgThumbMini = vignette($conf->societe->dir_logos.'/'.$original_file, 100, 30, '_mini',80);
|
||||||
if (eregi('([^\\\/:]+)$',$imgThumbMini,$reg))
|
if (eregi('([^\\\/:]+)$',$imgThumbMini,$reg))
|
||||||
{
|
{
|
||||||
$imgThumbMini = $reg[1];
|
$imgThumbMini = $reg[1];
|
||||||
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$imgThumbMini);
|
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$imgThumbMini);
|
||||||
|
}
|
||||||
|
else dolibarr_syslog($imgThumbMini);
|
||||||
}
|
}
|
||||||
|
else dolibarr_syslog($langs->trans("ErrorImageFormatNotSupported"),LOG_WARNING);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -114,41 +121,60 @@ if ( (isset($_POST["action"]) && $_POST["action"] == 'update')
|
|||||||
if ($_GET["action"] == 'addthumb')
|
if ($_GET["action"] == 'addthumb')
|
||||||
{
|
{
|
||||||
if (file_exists($conf->societe->dir_logos.'/'.$_GET["file"]))
|
if (file_exists($conf->societe->dir_logos.'/'.$_GET["file"]))
|
||||||
{
|
{
|
||||||
// Création de la vignette de la page login
|
$isimage=image_format_supported($original_file);
|
||||||
$imgThumbSmall = vignette($conf->societe->dir_logos.'/'.$_GET["file"], 200, 100, '_small',80);
|
|
||||||
if (eregi('([^\\\/:]+)$',$imgThumbSmall,$reg))
|
|
||||||
{
|
|
||||||
$imgThumbSmall = $reg[1];
|
|
||||||
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$imgThumbSmall);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Création de la vignette de la page "Société/Institution"
|
// Create thumbs of logo
|
||||||
$imgThumbMini = vignette($conf->societe->dir_logos.'/'.$_GET["file"], 100, 30, '_mini',80);
|
if ($isimage > 0)
|
||||||
if (eregi('([^\\\/:]+)$',$imgThumbMini,$reg))
|
|
||||||
{
|
{
|
||||||
$imgThumbMini = $reg[1];
|
// Création de la vignette de la page login
|
||||||
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$imgThumbMini);
|
$imgThumbSmall = vignette($conf->societe->dir_logos.'/'.$_GET["file"], 200, 100, '_small',80);
|
||||||
|
if (eregi('([^\\\/:]+)$',$imgThumbSmall,$reg))
|
||||||
|
{
|
||||||
|
$imgThumbSmall = $reg[1];
|
||||||
|
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$imgThumbSmall);
|
||||||
|
}
|
||||||
|
else dolibarr_syslog($imgThumbSmall);
|
||||||
|
|
||||||
|
// Création de la vignette de la page "Société/Institution"
|
||||||
|
$imgThumbMini = vignette($conf->societe->dir_logos.'/'.$_GET["file"], 100, 30, '_mini',80);
|
||||||
|
if (eregi('([^\\\/:]+)$',$imgThumbMini,$reg))
|
||||||
|
{
|
||||||
|
$imgThumbMini = $reg[1];
|
||||||
|
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$imgThumbMini);
|
||||||
|
}
|
||||||
|
else dolibarr_syslog($imgThumbMini);
|
||||||
|
|
||||||
|
Header("Location: ".$_SERVER["PHP_SELF"]);
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
Header("Location: ".$_SERVER["PHP_SELF"]);
|
{
|
||||||
exit;
|
$message .= '<div class="error">'.$langs->trans("ErrorImageFormatNotSupported").'</div>';
|
||||||
|
dolibarr_syslog($langs->transnoentities("ErrorImageFormatNotSupported"),LOG_WARNING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$message .= '<div class="error">'.$langs->trans("ErrorFileDoesNotExists",$_GET["file"]).'</div>';
|
||||||
|
dolibarr_syslog($langs->transnoentities("ErrorFileDoesNotExists",$_GET["file"]),LOG_WARNING);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_GET["action"] == 'removelogo')
|
if ($_GET["action"] == 'removelogo')
|
||||||
{
|
{
|
||||||
$logofile=$conf->societe->dir_logos.'/'.$mysoc->logo;
|
$logofile=$conf->societe->dir_logos.'/'.$mysoc->logo;
|
||||||
@unlink($logofile);
|
dol_delete_file($logofile);
|
||||||
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO");
|
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO");
|
||||||
$mysoc->logo='';
|
$mysoc->logo='';
|
||||||
|
|
||||||
$logosmallfile=$conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_small;
|
$logosmallfile=$conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_small;
|
||||||
@unlink($logosmallfile);
|
dol_delete_file($logosmallfile);
|
||||||
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL");
|
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL");
|
||||||
$mysoc->logo_small='';
|
$mysoc->logo_small='';
|
||||||
|
|
||||||
$logominifile=$conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_mini;
|
$logominifile=$conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_mini;
|
||||||
@unlink($logominifile);
|
dol_delete_file($logominifile);
|
||||||
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI");
|
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI");
|
||||||
$mysoc->logo_mini='';
|
$mysoc->logo_mini='';
|
||||||
}
|
}
|
||||||
@ -241,7 +267,7 @@ if ((isset($_GET["action"]) && $_GET["action"] == 'edit')
|
|||||||
{
|
{
|
||||||
print '<a href="'.$_SERVER["PHP_SELF"].'?action=removelogo">'.img_delete($langs->trans("Delete")).'</a>';
|
print '<a href="'.$_SERVER["PHP_SELF"].'?action=removelogo">'.img_delete($langs->trans("Delete")).'</a>';
|
||||||
print ' ';
|
print ' ';
|
||||||
print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode($mysoc->logo_mini).'">';
|
print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode('/thumbs/'.$mysoc->logo_mini).'">';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -483,7 +509,7 @@ else
|
|||||||
}
|
}
|
||||||
else if ($mysoc->logo_mini && file_exists($conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_mini))
|
else if ($mysoc->logo_mini && file_exists($conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_mini))
|
||||||
{
|
{
|
||||||
print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.$mysoc->logo_mini.'">';
|
print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode('/thumbs/'.$mysoc->logo_mini).'">';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -35,6 +35,7 @@ ErrorCantLoadUserFromDolibarrDatabase=Failed to find user <b>%s</b> in Dolibarr
|
|||||||
ErrorNoVATRateDefinedForSellerCountry=Error, no vat rates defined for country '%s'.
|
ErrorNoVATRateDefinedForSellerCountry=Error, no vat rates defined for country '%s'.
|
||||||
ErrorFailedToSaveFile=Error, failed to save file.
|
ErrorFailedToSaveFile=Error, failed to save file.
|
||||||
ErrorOnlyPngJpgSupported=Error, only .png and .jpg image format file are supported.
|
ErrorOnlyPngJpgSupported=Error, only .png and .jpg image format file are supported.
|
||||||
|
ErrorImageFormatNotSupported=Your PHP does not support functions to convert images of this format.
|
||||||
DolibarrInHttpAuthenticationSoPasswordUseless=Dolibarr authentication mode is setup to <b>%s</b> in configuration file <b>conf.php</b>.<br>This means that password database is extern to Dolibarr, so changing this field may have no effects.
|
DolibarrInHttpAuthenticationSoPasswordUseless=Dolibarr authentication mode is setup to <b>%s</b> in configuration file <b>conf.php</b>.<br>This means that password database is extern to Dolibarr, so changing this field may have no effects.
|
||||||
Undefined=Undefined
|
Undefined=Undefined
|
||||||
PasswordForgotten=Password forgotten ?
|
PasswordForgotten=Password forgotten ?
|
||||||
|
|||||||
@ -35,6 +35,7 @@ ErrorCantLoadUserFromDolibarrDatabase=Impossible de trouver l'utilisateur <b>%s<
|
|||||||
ErrorNoVATRateDefinedForSellerCountry=Erreur, aucun taux tva défini pour le pays '%s'.
|
ErrorNoVATRateDefinedForSellerCountry=Erreur, aucun taux tva défini pour le pays '%s'.
|
||||||
ErrorFailedToSaveFile=Erreur, l'enregistrement du fichier a échoué.
|
ErrorFailedToSaveFile=Erreur, l'enregistrement du fichier a échoué.
|
||||||
ErrorOnlyPngJpgSupported=Erreur, seuls les formats images .jpg et .png sont supportés.
|
ErrorOnlyPngJpgSupported=Erreur, seuls les formats images .jpg et .png sont supportés.
|
||||||
|
ErrorImageFormatNotSupported=Votre PHP ne supporte pas les fonctions de conversion de ce format d'image.
|
||||||
DolibarrInHttpAuthenticationSoPasswordUseless=Dolibarr est configuré en mode authentification <b>%s</b> dans son fichier de configuration <b>conf.php</b>.<br>Cela signifie que la base des mots de passe est externe à Dolibarr, aussi toute modification de ce champ peut s'avérer sans effet.
|
DolibarrInHttpAuthenticationSoPasswordUseless=Dolibarr est configuré en mode authentification <b>%s</b> dans son fichier de configuration <b>conf.php</b>.<br>Cela signifie que la base des mots de passe est externe à Dolibarr, aussi toute modification de ce champ peut s'avérer sans effet.
|
||||||
Undefined=Non défini
|
Undefined=Non défini
|
||||||
PasswordForgotten=Mot de passe oublié ?
|
PasswordForgotten=Mot de passe oublié ?
|
||||||
|
|||||||
@ -170,7 +170,7 @@ function dolibarr_syslog($message, $level=LOG_INFO)
|
|||||||
|
|
||||||
if ($conf->syslog->enabled)
|
if ($conf->syslog->enabled)
|
||||||
{
|
{
|
||||||
//print $level.' - '.$conf->global->SYSLOG_LEVEL.' - '.$conf->syslog->enabled;
|
//print $level.' - '.$conf->global->SYSLOG_LEVEL.' - '.$conf->syslog->enabled." \n";
|
||||||
if ($level > $conf->global->SYSLOG_LEVEL) return;
|
if ($level > $conf->global->SYSLOG_LEVEL) return;
|
||||||
|
|
||||||
// Ajout user a la log
|
// Ajout user a la log
|
||||||
@ -184,7 +184,11 @@ function dolibarr_syslog($message, $level=LOG_INFO)
|
|||||||
else $file=fopen(SYSLOG_FILE,"a+");
|
else $file=fopen(SYSLOG_FILE,"a+");
|
||||||
if ($file)
|
if ($file)
|
||||||
{
|
{
|
||||||
fwrite($file,strftime("%Y-%m-%d %H:%M:%S",time())." ".$level." ".$message."\n");
|
$liblevelarray=array('0'=>'ERROR','1'=>'ERROR','2'=>'ERROR','3'=>'ERROR','4'=>'ERROR',
|
||||||
|
'5'=>'WARN','6'=>'DEBUG','7'=>'DEBUG');
|
||||||
|
$liblevel=$liblevelarray[$level];
|
||||||
|
if (! $liblevel) $liblevel='UNDEF';
|
||||||
|
fwrite($file,strftime("%Y-%m-%d %H:%M:%S",time())." ".sprintf("%-5s",$liblevel)." ".$message."\n");
|
||||||
fclose($file);
|
fclose($file);
|
||||||
}
|
}
|
||||||
elseif (! defined("SYSLOG_FILE_NO_ERROR"))
|
elseif (! defined("SYSLOG_FILE_NO_ERROR"))
|
||||||
@ -1103,6 +1107,34 @@ function img_allow($allow)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Return if a filename is file name of a supported image format
|
||||||
|
\param file Filename
|
||||||
|
\return int -1=Not image filename, 0=Image filename but format not supported by PHP, 1=Image filename with format supported
|
||||||
|
*/
|
||||||
|
function image_format_supported($file)
|
||||||
|
{
|
||||||
|
// Case filename is not a format image
|
||||||
|
if (! eregi('(\.png|\.jpg|\.jpeg)$',$file,$reg)) return -1;
|
||||||
|
|
||||||
|
// Case filename is a format image but not supported by this PHP
|
||||||
|
$imgfonction='';
|
||||||
|
if (strtolower($reg[1]) == '.png') $imgfonction = 'imagecreatefrompng';
|
||||||
|
if (strtolower($reg[1]) == '.jpg') $imgfonction = 'imagecreatefromjpeg';
|
||||||
|
if (strtolower($reg[1]) == '.jpeg') $imgfonction = 'imagecreatefromjpeg';
|
||||||
|
if ($imgfonction)
|
||||||
|
{
|
||||||
|
if (! function_exists($imgfonction))
|
||||||
|
{
|
||||||
|
// Fonctions de conversion non presente dans ce PHP
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Case filename is a format image and supported by this PHP
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Affiche info admin
|
\brief Affiche info admin
|
||||||
\param text Texte info
|
\param text Texte info
|
||||||
@ -1142,7 +1174,7 @@ function dol_loginfunction($notused,$pearstatus)
|
|||||||
print "<html>\n";
|
print "<html>\n";
|
||||||
print "<head>\n";
|
print "<head>\n";
|
||||||
print '<meta name="robots" content="noindex,nofollow">'."\n"; // Evite indexation par robots
|
print '<meta name="robots" content="noindex,nofollow">'."\n"; // Evite indexation par robots
|
||||||
print "<title>Dolibarr Authentification</title>\n";
|
print "<title>Dolibarr login</title>\n";
|
||||||
|
|
||||||
print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/'.$conf->css.'">'."\n";
|
print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/'.$conf->css.'">'."\n";
|
||||||
|
|
||||||
@ -1208,17 +1240,26 @@ function dol_loginfunction($notused,$pearstatus)
|
|||||||
print '<td><input name="username" class="flat" size="15" maxlength="25" value="" tabindex="1" /></td>';
|
print '<td><input name="username" class="flat" size="15" maxlength="25" value="" tabindex="1" /></td>';
|
||||||
|
|
||||||
if ($conf->main_authentication) $title.=$langs->trans("AuthenticationMode").': '.$conf->main_authentication;
|
if ($conf->main_authentication) $title.=$langs->trans("AuthenticationMode").': '.$conf->main_authentication;
|
||||||
// Affiche logo du theme si existe, sinon logo commun
|
|
||||||
|
// Show logo (search in order: small company logo, large company logo, theme logo, common logo)
|
||||||
|
$width=0;
|
||||||
$urllogo=DOL_URL_ROOT.'/theme/login_logo.png';
|
$urllogo=DOL_URL_ROOT.'/theme/login_logo.png';
|
||||||
if (is_readable($conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_small))
|
if (is_readable($conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_small))
|
||||||
{
|
{
|
||||||
$urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode($mysoc->logo_small);
|
$urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode('/thumbs/'.$mysoc->logo_small);
|
||||||
|
}
|
||||||
|
elseif (is_readable($conf->societe->dir_logos.'/'.$mysoc->logo))
|
||||||
|
{
|
||||||
|
$urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode($mysoc->logo);
|
||||||
|
$width=96;
|
||||||
}
|
}
|
||||||
elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/login_logo.png'))
|
elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/login_logo.png'))
|
||||||
{
|
{
|
||||||
$urllogo=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/login_logo.png';
|
$urllogo=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/login_logo.png';
|
||||||
}
|
}
|
||||||
print '<td rowspan="2"><img title="'.$title.'" src="'.$urllogo.'"></td>';
|
print '<td rowspan="2"><img title="'.$title.'" src="'.$urllogo.'"';
|
||||||
|
if ($width) print ' width="'.$width.'"';
|
||||||
|
print '></td>';
|
||||||
|
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
@ -1468,7 +1509,7 @@ function dolibarr_print_error($db='',$error='')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dolibarr_syslog("Error $syslog");
|
dolibarr_syslog("Error $syslog",LOG_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1807,8 +1848,8 @@ function dol_delete_file($file)
|
|||||||
foreach (glob($file) as $filename)
|
foreach (glob($file) as $filename)
|
||||||
{
|
{
|
||||||
$ok=unlink($filename);
|
$ok=unlink($filename);
|
||||||
if ($ok) dolibarr_syslog("Removed file $filename");
|
if ($ok) dolibarr_syslog("Removed file $filename",LOG_DEBUG);
|
||||||
else dolibarr_syslog("Failed to remove file $filename");
|
else dolibarr_syslog("Failed to remove file $filename",LOG_ERROR);
|
||||||
}
|
}
|
||||||
return $ok;
|
return $ok;
|
||||||
}
|
}
|
||||||
@ -2953,122 +2994,131 @@ function print_date_range($date_start,$date_end)
|
|||||||
* \param quality Qualité de compression jpeg
|
* \param quality Qualité de compression jpeg
|
||||||
* \return imgThumbName Chemin de la vignette
|
* \return imgThumbName Chemin de la vignette
|
||||||
*/
|
*/
|
||||||
function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50){
|
function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50)
|
||||||
|
{
|
||||||
|
dolibarr_syslog("functions.inc::vignette file=".$file." extName=".$extName);
|
||||||
|
|
||||||
// Vérification des erreurs dans les paramètres de la fonction
|
// Vérification des erreurs dans les paramètres de la fonction
|
||||||
//============================================================
|
//============================================================
|
||||||
if(!file_exists($file)){
|
if(!file_exists($file)){
|
||||||
// Si le fichier passé en paramètre n'existe pas
|
// Si le fichier passé en paramètre n'existe pas
|
||||||
return 'Le fichier '.$file.' n\'a pas été trouvé sur le serveur.';
|
return 'Le fichier '.$file.' n\'a pas été trouvé sur le serveur.';
|
||||||
}
|
}
|
||||||
elseif(!eregi('(\.jpg|\.jpeg|\.png)$',$file))
|
elseif(!eregi('(\.jpg|\.jpeg|\.png)$',$file))
|
||||||
{
|
{
|
||||||
// Todo: Ajouter création vignette pour les autres formats d'images
|
// Todo: Ajouter création vignette pour les autres formats d'images
|
||||||
return 'Le fichier '.$file.' n\'est pas géré pour le moment.';
|
return 'Le fichier '.$file.' n\'est pas géré pour le moment.';
|
||||||
}
|
}
|
||||||
elseif(empty($file)){
|
elseif(empty($file)){
|
||||||
// Si le fichier n'a pas été indiqué
|
// Si le fichier n'a pas été indiqué
|
||||||
return 'Nom du fichier non renseigné.';
|
return 'Nom du fichier non renseigné.';
|
||||||
}
|
}
|
||||||
elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < 0){
|
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)
|
// Si la largeur max est incorrecte (n'est pas numérique, est vide, ou est inférieure à 0)
|
||||||
return 'Valeur de la largeur incorrecte.';
|
return 'Valeur de la largeur incorrecte.';
|
||||||
}
|
}
|
||||||
elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < 0){
|
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)
|
// Si la hauteur max est incorrecte (n'est pas numérique, est vide, ou est inférieure à 0)
|
||||||
return 'Valeur de la hauteur incorrecte.';
|
return 'Valeur de la hauteur incorrecte.';
|
||||||
}
|
}
|
||||||
//============================================================
|
//============================================================
|
||||||
|
|
||||||
$fichier = realpath($file); // Chemin canonique absolu de l'image
|
$fichier = realpath($file); // Chemin canonique absolu de l'image
|
||||||
$dir = dirname($file).'/'; // Chemin du dossier contenant l'image
|
$dir = dirname($file).'/'; // Chemin du dossier contenant l'image
|
||||||
$dirthumb = $dir.'thumbs/'; // Chemin du dossier contenant les vignettes
|
$dirthumb = $dir.'thumbs/'; // Chemin du dossier contenant les vignettes
|
||||||
$infoImg = getimagesize($fichier); // Récupération des infos de l'image
|
$infoImg = getimagesize($fichier); // Récupération des infos de l'image
|
||||||
$imgWidth = $infoImg[0]; // Largeur de l'image
|
$imgWidth = $infoImg[0]; // Largeur de l'image
|
||||||
$imgHeight = $infoImg[1]; // Hauteur de l'image
|
$imgHeight = $infoImg[1]; // Hauteur de l'image
|
||||||
|
|
||||||
// Si l'image est plus petite que la largeur et le hauteur max, on ne crée pas de vignette
|
// Si l'image est plus petite que la largeur et le hauteur max, on ne crée pas de vignette
|
||||||
if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight)
|
if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight)
|
||||||
{
|
{
|
||||||
return 'Le fichier '.$file.' ne nécessite pas de création de vignette';
|
return 'Le fichier '.$file.' ne nécessite pas de création de vignette';
|
||||||
}
|
}
|
||||||
|
|
||||||
$imgfonction='';
|
$imgfonction='';
|
||||||
switch($infoImg[2]){
|
switch($infoImg[2]){
|
||||||
case 2:
|
case 2:
|
||||||
$imgfonction = 'imagecreatefromjpeg';
|
$imgfonction = 'imagecreatefromjpeg';
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
$imgfonction = 'imagecreatefrompng';
|
$imgfonction = 'imagecreatefrompng';
|
||||||
}
|
}
|
||||||
if ($imgfonction)
|
if ($imgfonction)
|
||||||
{
|
{
|
||||||
if (! function_exists($imgfonction))
|
if (! function_exists($imgfonction))
|
||||||
{
|
{
|
||||||
// Fonctions de conversion non presente dans ce PHP
|
// Fonctions de conversion non presente dans ce PHP
|
||||||
return 'Creation de vignette impossible. Ce PHP ne supporte pas les fonctions du module GD '.$imgfonction;
|
return 'Creation de vignette impossible. Ce PHP ne supporte pas les fonctions du module GD '.$imgfonction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// On crée le répertoire contenant les vignettes
|
// On crée le répertoire contenant les vignettes
|
||||||
if (! file_exists($dirthumb))
|
if (! file_exists($dirthumb))
|
||||||
{
|
{
|
||||||
dolibarr_syslog("Product Create $dirthumb");
|
dolibarr_syslog("Product Create $dirthumb");
|
||||||
create_exdir($dirthumb);
|
create_exdir($dirthumb);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialisation des variables selon l'extension de l'image
|
// Initialisation des variables selon l'extension de l'image
|
||||||
switch($infoImg[2]){
|
switch($infoImg[2]){
|
||||||
case 2:
|
case 2:
|
||||||
$img = imagecreatefromjpeg($fichier); // Création d'une nouvelle image jpeg à partir du fichier
|
$img = imagecreatefromjpeg($fichier); // Création d'une nouvelle image jpeg à partir du fichier
|
||||||
$extImg = '.jpg'; // Extension de l'image
|
$extImg = '.jpg'; // Extension de l'image
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
$img = imagecreatefrompng($fichier); // Création d'une nouvelle image png à partir du fichier
|
$img = imagecreatefrompng($fichier); // Création d'une nouvelle image png à partir du fichier
|
||||||
$extImg = '.png';
|
$extImg = '.png';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialisation des dimensions de la vignette si elles sont supérieures à l'original
|
// Initialisation des dimensions de la vignette si elles sont supérieures à l'original
|
||||||
if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; }
|
if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; }
|
||||||
if($maxHeight > $imgHeight){ $maxHeight = $imgHeight; }
|
if($maxHeight > $imgHeight){ $maxHeight = $imgHeight; }
|
||||||
|
|
||||||
$whFact = $maxWidth/$maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette
|
$whFact = $maxWidth/$maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette
|
||||||
$imgWhFact = $imgWidth/$imgHeight; // Facteur largeur/hauteur de l'original
|
$imgWhFact = $imgWidth/$imgHeight; // Facteur largeur/hauteur de l'original
|
||||||
|
|
||||||
// Fixe les dimensions de la vignette
|
// Fixe les dimensions de la vignette
|
||||||
if($whFact < $imgWhFact){
|
if($whFact < $imgWhFact){
|
||||||
// Si largeur déterminante
|
// Si largeur déterminante
|
||||||
$thumbWidth = $maxWidth;
|
$thumbWidth = $maxWidth;
|
||||||
$thumbHeight = $thumbWidth / $imgWhFact;
|
$thumbHeight = $thumbWidth / $imgWhFact;
|
||||||
} else {
|
} else {
|
||||||
// Si hauteur déterminante
|
// Si hauteur déterminante
|
||||||
$thumbHeight = $maxHeight;
|
$thumbHeight = $maxHeight;
|
||||||
$thumbWidth = $thumbHeight * $imgWhFact;
|
$thumbWidth = $thumbHeight * $imgWhFact;
|
||||||
}
|
}
|
||||||
|
|
||||||
$imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight); // Création de la vignette
|
$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
|
// This is to keep transparent alpha channel if exists (PHP >= 4.2)
|
||||||
|
if (function_exists('imagesavealpha'))
|
||||||
|
{
|
||||||
|
imagesavealpha($imgThumb, true);
|
||||||
|
$trans_colour = imagecolorallocatealpha($imgThumb, 0, 0, 0, 127);
|
||||||
|
imagefill($imgThumb, 0, 0, $trans_colour);
|
||||||
|
}
|
||||||
|
|
||||||
$fileName = eregi_replace('(\.jpeg|\.jpg|\.png)$','',$file); // On enleve extension quelquesoit la casse
|
imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insère l'image de base redimensionnée
|
||||||
$fileName = basename($fileName);
|
|
||||||
$imgThumbName = $dirthumb.$fileName.$extName.$extImg; // Chemin complet du fichier de la vignette
|
|
||||||
|
|
||||||
//Création du fichier de la vignette
|
$fileName = eregi_replace('(\.jpeg|\.jpg|\.png)$','',$file); // On enleve extension quelquesoit la casse
|
||||||
$fp = fopen($imgThumbName, "w");
|
$fileName = basename($fileName);
|
||||||
fclose($fp);
|
$imgThumbName = $dirthumb.$fileName.$extName.$extImg; // Chemin complet du fichier de la vignette
|
||||||
|
|
||||||
// Renvoi la vignette créée
|
//Création du fichier de la vignette
|
||||||
switch($infoImg[2]){
|
$fp = fopen($imgThumbName, "w");
|
||||||
case 2:
|
fclose($fp);
|
||||||
imagejpeg($imgThumb, $imgThumbName, $quality); // Renvoi d'une image jpeg avec une qualité de 50 par défaut
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
imagepng($imgThumb, $imgThumbName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $imgThumbName;
|
// Renvoi la vignette créée
|
||||||
|
switch($infoImg[2]){
|
||||||
|
case 2:
|
||||||
|
imagejpeg($imgThumb, $imgThumbName, $quality); // Renvoi d'une image jpeg avec une qualité de 50 par défaut
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
imagepng($imgThumb, $imgThumbName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $imgThumbName;
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -194,19 +194,26 @@ if ($mode == 'dolibarr') $disabled='';
|
|||||||
print '<td><input '.$disabled.' name="username" class="flat" size="15" maxlength="25" value="" tabindex="1" /></td>';
|
print '<td><input '.$disabled.' name="username" class="flat" size="15" maxlength="25" value="" tabindex="1" /></td>';
|
||||||
|
|
||||||
$title='';
|
$title='';
|
||||||
// Affiche logo du theme si existe, sinon logo commun
|
|
||||||
|
// Show logo (search in order: small company logo, large company logo, theme logo, common logo)
|
||||||
|
$width=0;
|
||||||
$urllogo=DOL_URL_ROOT.'/theme/login_logo.png';
|
$urllogo=DOL_URL_ROOT.'/theme/login_logo.png';
|
||||||
if (is_readable($conf->societe->dir_logos.'/'.$mysoc->logo))
|
if (is_readable($conf->societe->dir_logos.'/thumbs/'.$mysoc->logo_small))
|
||||||
{
|
{
|
||||||
$urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode($mysoc->logo);
|
$urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode('/thumbs/'.$mysoc->logo_small);
|
||||||
$height=100; // \TODO Forcer la hauteur uniquement si hauteur > 100 ou largeur > 100
|
}
|
||||||
|
elseif (is_readable($conf->societe->dir_logos.'/'.$mysoc->logo))
|
||||||
|
{
|
||||||
|
$urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode($mysoc->logo);
|
||||||
|
$width=96;
|
||||||
}
|
}
|
||||||
elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/login_logo.png'))
|
elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/login_logo.png'))
|
||||||
{
|
{
|
||||||
$urllogo=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/login_logo.png';
|
$urllogo=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/login_logo.png';
|
||||||
$height=80;
|
|
||||||
}
|
}
|
||||||
print '<td><img title="'.$title.'" height="'.$height.'" src="'.$urllogo.'"></td>';
|
print '<td><img title="'.$title.'" src="'.$urllogo.'"';
|
||||||
|
if ($width) print ' width="'.$width.'"';
|
||||||
|
print '></td>';
|
||||||
|
|
||||||
print '</tr>'."\n";
|
print '</tr>'."\n";
|
||||||
|
|
||||||
|
|||||||
@ -63,14 +63,7 @@ if ($modulepart)
|
|||||||
if ($modulepart == 'companylogo')
|
if ($modulepart == 'companylogo')
|
||||||
{
|
{
|
||||||
$accessallowed=1;
|
$accessallowed=1;
|
||||||
if (eregi('_small',$original_file) || eregi('_mini',$original_file))
|
$original_file=$conf->societe->dir_logos.'/'.$original_file;
|
||||||
{
|
|
||||||
$original_file=$conf->societe->dir_logos.'/thumbs/'.$original_file;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$original_file=$conf->societe->dir_logos.'/'.$original_file;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapping pour les photos utilisateurs
|
// Wrapping pour les photos utilisateurs
|
||||||
@ -274,7 +267,7 @@ if (eregi('\.\.',$original_file) || eregi('[<>|]',$original_file))
|
|||||||
clearstatcache();
|
clearstatcache();
|
||||||
$filename = basename($original_file);
|
$filename = basename($original_file);
|
||||||
|
|
||||||
dolibarr_syslog("viewimage.php download $original_file $filename content-type=$type");
|
dolibarr_syslog("viewimage.php return file $original_file $filename content-type=$type");
|
||||||
|
|
||||||
if (! file_exists($original_file))
|
if (! file_exists($original_file))
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user