|
|
|
@ -2,82 +2,91 @@
|
|
|
|
|
|
|
|
|
|
$GLOBALS['sprites'] = false; |
|
|
|
|
|
|
|
|
|
function sprite ($img, $nom) { |
|
|
|
|
function sprite($img, $nom) { |
|
|
|
|
// Extraire le nom du fichier, soit directement soit dans <img src> |
|
|
|
|
if (@file_exists($img)) $src = $img; |
|
|
|
|
else { |
|
|
|
|
$src = extraire_attribut($img, "src"); |
|
|
|
|
$src = preg_replace(",\?[0-9]*$,", "", $src); |
|
|
|
|
// Si pas de fichier, ignorer |
|
|
|
|
if (!@file_exists($src)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (@file_exists($img)) { |
|
|
|
|
$src = $img; |
|
|
|
|
} else { |
|
|
|
|
$src = extraire_attribut($img, 'src'); |
|
|
|
|
$src = preg_replace(',\?[0-9]*$,', '', $src); |
|
|
|
|
// Si pas de fichier, ignorer |
|
|
|
|
if (!@file_exists($src)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$GLOBALS['sprites']["$nom"]["fichiers"][] = $src; |
|
|
|
|
$GLOBALS['sprites']["$nom"]['fichiers'][] = $src; |
|
|
|
|
|
|
|
|
|
$largeur = largeur($img); |
|
|
|
|
$hauteur = hauteur($img); |
|
|
|
|
if ($largeur > $GLOBALS['sprites']["$nom"]["largeur"]) $GLOBALS['sprites']["$nom"]["largeur"] = $largeur; |
|
|
|
|
$hauteur_old = max(0, $GLOBALS['sprites']["$nom"]["hauteur"]); |
|
|
|
|
$GLOBALS['sprites']["$nom"]["hauteur"] += $hauteur; |
|
|
|
|
if ($largeur > $GLOBALS['sprites']["$nom"]['largeur']) { |
|
|
|
|
$GLOBALS['sprites']["$nom"]['largeur'] = $largeur; |
|
|
|
|
} |
|
|
|
|
$hauteur_old = max(0, $GLOBALS['sprites']["$nom"]['hauteur']); |
|
|
|
|
$GLOBALS['sprites']["$nom"]['hauteur'] += $hauteur; |
|
|
|
|
|
|
|
|
|
$alt = extraire_attribut($img, "alt"); |
|
|
|
|
$class = extraire_attribut($img, "class"); |
|
|
|
|
$alt = extraire_attribut($img, 'alt'); |
|
|
|
|
$class = extraire_attribut($img, 'class'); |
|
|
|
|
$fichier = sous_repertoire(_DIR_VAR, 'cache-sprites').$nom; |
|
|
|
|
//$fichier .= "?m=spiprempdate[$fichier]"; |
|
|
|
|
|
|
|
|
|
$date_src = @filemtime($src); |
|
|
|
|
if ($date_src > $GLOBALS['sprites']["$nom"]["date"]) $GLOBALS['sprites']["$nom"]["date"] = $date_src; |
|
|
|
|
if ($date_src > $GLOBALS['sprites']["$nom"]['date']) { |
|
|
|
|
$GLOBALS['sprites']["$nom"]['date'] = $date_src; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return "<img src='".find_in_path("rien.gif")."' width='".$largeur."px' height='".$hauteur."px' style='width: ".$largeur."px; height: ".$hauteur."px; background: url($fichier) 0px -".$hauteur_old."px;' alt='$alt' class='$class' />"; |
|
|
|
|
return "<img src='".find_in_path('rien.gif')."' width='".$largeur."px' height='".$hauteur."px' style='width: ".$largeur.'px; height: '.$hauteur."px; background: url($fichier) 0px -".$hauteur_old."px;' alt='$alt' class='$class' />"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function creer_sprites_terminaison_fichier_image($fichier) { |
|
|
|
|
if (preg_match(",^(?>.*)(?<=\.(gif|jpg|png)),", $fichier, $regs)) { |
|
|
|
|
if (preg_match(',^(?>.*)(?<=\.(gif|jpg|png)),', $fichier, $regs)) { |
|
|
|
|
$terminaison = $regs[1]; |
|
|
|
|
return $terminaison; |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function creer_sprites($flux) { |
|
|
|
|
$sprites = $GLOBALS['sprites']; |
|
|
|
|
$page = $flux['data']['texte']; |
|
|
|
|
if ($sprites) { |
|
|
|
|
foreach($sprites as $key => $sprite) { |
|
|
|
|
foreach ($sprites as $key => $sprite) { |
|
|
|
|
$fichier_sprite = sous_repertoire(_DIR_VAR, 'cache-sprites').$key; |
|
|
|
|
$ext = creer_sprites_terminaison_fichier_image($fichier_sprite); |
|
|
|
|
$nom_fichier_sprite = substr($fichier_sprite, 0, strlen($fichier_sprite) - 4); |
|
|
|
|
|
|
|
|
|
$date_max = $sprite["date"]; |
|
|
|
|
$date_max = $sprite['date']; |
|
|
|
|
$date_src = @filemtime($fichier_sprite); |
|
|
|
|
$largeur = $sprite["largeur"]; |
|
|
|
|
$hauteur = $sprite["hauteur"]; |
|
|
|
|
$largeur = $sprite['largeur']; |
|
|
|
|
$hauteur = $sprite['hauteur']; |
|
|
|
|
|
|
|
|
|
$creer = false; |
|
|
|
|
if ($date_src < $date_max) $creer = true; |
|
|
|
|
if ($largeur != largeur($fichier_sprite) || $hauteur != hauteur ($fichier_sprite)) $creer = true; |
|
|
|
|
|
|
|
|
|
if (in_array($_GET['var_mode'], array('recalcul', 'debug'))) $creer = true; |
|
|
|
|
if ($date_src < $date_max) { |
|
|
|
|
$creer = true; |
|
|
|
|
} |
|
|
|
|
if ($largeur != largeur($fichier_sprite) || $hauteur != hauteur($fichier_sprite)) { |
|
|
|
|
$creer = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($creer) { |
|
|
|
|
if (!empty($_GET['var_mode']) |
|
|
|
|
and in_array($_GET['var_mode'], array('recalcul', 'debug'))) { |
|
|
|
|
$creer = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($creer) { |
|
|
|
|
include_spip('inc/filtres_images'); |
|
|
|
|
|
|
|
|
|
$im = imagecreatetruecolor($largeur, $hauteur); |
|
|
|
|
$im = imagecreatetruecolor($largeur, $hauteur); |
|
|
|
|
imagepalettetotruecolor($im); |
|
|
|
|
@imagealphablending($im, false); |
|
|
|
|
@imagesavealpha($im,true); |
|
|
|
|
$color_t = imagecolorallocatealpha( $im, 0, 0, 0 , 127 ); |
|
|
|
|
imagefill ($im, 0, 0, $color_t); |
|
|
|
|
@imagealphablending($im, false); |
|
|
|
|
@imagesavealpha($im, true); |
|
|
|
|
$color_t = imagecolorallocatealpha($im, 0, 0, 0, 127); |
|
|
|
|
imagefill($im, 0, 0, $color_t); |
|
|
|
|
|
|
|
|
|
$y_total = 0; |
|
|
|
|
foreach($sprite["fichiers"] as $img) { |
|
|
|
|
|
|
|
|
|
$f = "imagecreatefrom".str_replace("jpg","jpeg",creer_sprites_terminaison_fichier_image($img)); |
|
|
|
|
foreach ($sprite['fichiers'] as $img) { |
|
|
|
|
$f = 'imagecreatefrom'.str_replace('jpg', 'jpeg', creer_sprites_terminaison_fichier_image($img)); |
|
|
|
|
$im_tmp = $f($img); |
|
|
|
|
@imagepalettetotruecolor($im_tmp); |
|
|
|
|
|
|
|
|
@ -91,8 +100,8 @@ function creer_sprites($flux) {
|
|
|
|
|
_image_imagepng($im, "$nom_fichier_sprite.png"); |
|
|
|
|
|
|
|
|
|
$ext = creer_sprites_terminaison_fichier_image($fichier_sprite); |
|
|
|
|
if ($ext != "png") { |
|
|
|
|
$new = extraire_attribut( image_aplatir("$nom_fichier_sprite.png", $ext, "ffffff"), "src"); |
|
|
|
|
if ($ext != 'png') { |
|
|
|
|
$new = extraire_attribut(image_aplatir("$nom_fichier_sprite.png", $ext, 'ffffff'), 'src'); |
|
|
|
|
$ok = copy($new, $fichier_sprite); |
|
|
|
|
} |
|
|
|
|
imagedestroy($im); |
|
|
|
@ -102,27 +111,26 @@ function creer_sprites($flux) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Mettre les dates des fichiers en variable de chaque appel |
|
|
|
|
$page = preg_replace_callback(",spiprempdate\[([^\]]*)\],", "creer_sprites_remplacer_date", $page); |
|
|
|
|
$page = preg_replace_callback(',spiprempdate\[([^\]]*)\],', 'creer_sprites_remplacer_date', $page); |
|
|
|
|
|
|
|
|
|
$flux["data"]['texte'] = $page; |
|
|
|
|
$flux['data']['texte'] = $page; |
|
|
|
|
$GLOBALS['sprites'] = false; |
|
|
|
|
return $flux; |
|
|
|
|
return $flux; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function creer_sprites_remplacer_date($regs) { |
|
|
|
|
static $date_fichier=array(); |
|
|
|
|
$fichier = $regs[1]; |
|
|
|
|
static $date_fichier=array(); // AJOUT JLUC |
|
|
|
|
if ($date_fichier["$fichier"] > 0) { |
|
|
|
|
return $date_fichier["$fichier"]; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
} else { |
|
|
|
|
$date_fichier["$fichier"] = @filemtime($fichier); |
|
|
|
|
return $date_fichier["$fichier"]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function creer_sprites_recuperer_fond ($flux) { |
|
|
|
|
function creer_sprites_recuperer_fond($flux) { |
|
|
|
|
if (isset($flux['args']['fond']) |
|
|
|
|
and ($flux['args']['fond'] == 'modeles/logo' |
|
|
|
|
or ($flux['args']['fond'] == 'modeles/lesauteurs'))) { |
|
|
|
@ -130,4 +138,3 @@ function creer_sprites_recuperer_fond ($flux) {
|
|
|
|
|
} |
|
|
|
|
return creer_sprites($flux); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|