@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | include_spip('inc/filtres'); // par precaution |
| 25 | 25 | include_spip('inc/filtres_images_mini'); // par precaution |
@@ -39,21 +39,21 @@ discard block |
||
| 39 | 39 | * Le code de la couleur en hexadécimal. |
| 40 | 40 | */ |
| 41 | 41 | function _couleur_dec_to_hex($red, $green, $blue) { |
| 42 | - $red = dechex($red); |
|
| 43 | - $green = dechex($green); |
|
| 44 | - $blue = dechex($blue); |
|
| 45 | - |
|
| 46 | - if (strlen($red) == 1) { |
|
| 47 | - $red = "0" . $red; |
|
| 48 | - } |
|
| 49 | - if (strlen($green) == 1) { |
|
| 50 | - $green = "0" . $green; |
|
| 51 | - } |
|
| 52 | - if (strlen($blue) == 1) { |
|
| 53 | - $blue = "0" . $blue; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - return "$red$green$blue"; |
|
| 42 | + $red = dechex($red); |
|
| 43 | + $green = dechex($green); |
|
| 44 | + $blue = dechex($blue); |
|
| 45 | + |
|
| 46 | + if (strlen($red) == 1) { |
|
| 47 | + $red = "0" . $red; |
|
| 48 | + } |
|
| 49 | + if (strlen($green) == 1) { |
|
| 50 | + $green = "0" . $green; |
|
| 51 | + } |
|
| 52 | + if (strlen($blue) == 1) { |
|
| 53 | + $blue = "0" . $blue; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return "$red$green$blue"; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -65,16 +65,16 @@ discard block |
||
| 65 | 65 | * Un tableau des 3 éléments : rouge, vert, bleu. |
| 66 | 66 | */ |
| 67 | 67 | function _couleur_hex_to_dec($couleur) { |
| 68 | - $couleur = couleur_html_to_hex($couleur); |
|
| 69 | - $couleur = ltrim($couleur, '#'); |
|
| 70 | - if (strlen($couleur) === 3) { |
|
| 71 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 72 | - } |
|
| 73 | - $retour["red"] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | - $retour["green"] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | - $retour["blue"] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | - |
|
| 77 | - return $retour; |
|
| 68 | + $couleur = couleur_html_to_hex($couleur); |
|
| 69 | + $couleur = ltrim($couleur, '#'); |
|
| 70 | + if (strlen($couleur) === 3) { |
|
| 71 | + $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 72 | + } |
|
| 73 | + $retour["red"] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | + $retour["green"] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | + $retour["blue"] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | + |
|
| 77 | + return $retour; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 92 | 92 | */ |
| 93 | 93 | function statut_effacer_images_temporaires($stat) { |
| 94 | - static $statut = false; // par defaut on grave toute les images |
|
| 95 | - if ($stat === 'get') { |
|
| 96 | - return $statut; |
|
| 97 | - } |
|
| 98 | - $statut = $stat ? true : false; |
|
| 94 | + static $statut = false; // par defaut on grave toute les images |
|
| 95 | + if ($stat === 'get') { |
|
| 96 | + return $statut; |
|
| 97 | + } |
|
| 98 | + $statut = $stat ? true : false; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | |
@@ -145,226 +145,226 @@ discard block |
||
| 145 | 145 | * - array : tableau décrivant de l'image |
| 146 | 146 | */ |
| 147 | 147 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 148 | - static $images_recalcul = array(); |
|
| 149 | - if (strlen($img) == 0) { |
|
| 150 | - return false; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $source = trim(extraire_attribut($img, 'src')); |
|
| 154 | - if (strlen($source) < 1) { |
|
| 155 | - $source = $img; |
|
| 156 | - $img = "<img src='$source' />"; |
|
| 157 | - } # gerer img src="data:....base64" |
|
| 158 | - elseif (preg_match('@^data:image/(jpe?g|png|gif|svg+xml);base64,(.*)$@isS', $source, $regs)) { |
|
| 159 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . str_replace('jpeg', 'jpg', $regs[1]); |
|
| 160 | - if (!file_exists($local)) { |
|
| 161 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 162 | - } |
|
| 163 | - $source = $local; |
|
| 164 | - $img = inserer_attribut($img, 'src', $source); |
|
| 165 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 166 | - $img = inserer_attribut($img, 'width', ''); |
|
| 167 | - $img = inserer_attribut($img, 'height', ''); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // les protocoles web prennent au moins 3 lettres |
|
| 171 | - if (tester_url_absolue($source)) { |
|
| 172 | - include_spip('inc/distant'); |
|
| 173 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 174 | - if (!$fichier) { |
|
| 175 | - return ""; |
|
| 176 | - } |
|
| 177 | - } else { |
|
| 178 | - // enlever le timestamp eventuel |
|
| 179 | - if (strpos($source, "?") !== false) { |
|
| 180 | - $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 181 | - } |
|
| 182 | - if (strpos($source, "?") !== false |
|
| 183 | - and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 184 | - and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 185 | - ) { |
|
| 186 | - $source = $f; |
|
| 187 | - } |
|
| 188 | - $fichier = $source; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - $terminaison_dest = ""; |
|
| 192 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 193 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if ($forcer_format !== false |
|
| 197 | - // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 198 | - and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format,['png','gif','jpg']))) { |
|
| 199 | - $terminaison_dest = $forcer_format; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if (!$terminaison_dest) { |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 207 | - $fichier_dest = $nom_fichier; |
|
| 208 | - if (($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 209 | - or @file_exists($f = $fichier) |
|
| 210 | - ) { |
|
| 211 | - // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 212 | - // au lieu de faire un acces disque sur le fichier |
|
| 213 | - list($ret["hauteur"], $ret["largeur"]) = taille_image($find_in_path ? $f : $img); |
|
| 214 | - $date_src = @filemtime($f); |
|
| 215 | - } elseif (@file_exists($f = "$fichier.src") |
|
| 216 | - and lire_fichier($f, $valeurs) |
|
| 217 | - and $valeurs = unserialize($valeurs) |
|
| 218 | - and isset($valeurs["hauteur_dest"]) |
|
| 219 | - and isset($valeurs["largeur_dest"]) |
|
| 220 | - ) { |
|
| 221 | - $ret["hauteur"] = $valeurs["hauteur_dest"]; |
|
| 222 | - $ret["largeur"] = $valeurs["largeur_dest"]; |
|
| 223 | - $date_src = $valeurs["date"]; |
|
| 224 | - } // pas de fichier source par la |
|
| 225 | - else { |
|
| 226 | - return false; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // pas de taille mesurable |
|
| 230 | - if (!($ret["hauteur"] or $ret["largeur"])) { |
|
| 231 | - return false; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - // les images calculees dependent du chemin du fichier source |
|
| 235 | - // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 236 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 237 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 238 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 239 | - // alors que ca concerne peu de site au final |
|
| 240 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 241 | - $identifiant = $fichier; |
|
| 242 | - |
|
| 243 | - // cas general : |
|
| 244 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 245 | - // cas particulier de reduire : |
|
| 246 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 247 | - $cache = "cache-gd2"; |
|
| 248 | - if (substr($effet, 0, 7) == 'reduire') { |
|
| 249 | - list(, $maxWidth, $maxHeight) = explode('-', $effet); |
|
| 250 | - list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 251 | - $ret['largeur_dest'] = $destWidth; |
|
| 252 | - $ret['hauteur_dest'] = $destHeight; |
|
| 253 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 254 | - $cache = "cache-vignettes"; |
|
| 255 | - $fichier_dest = basename($fichier_dest); |
|
| 256 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 257 | - // on garde la terminaison initiale car image simplement copiee |
|
| 258 | - // et on postfixe son nom avec un md5 du path |
|
| 259 | - $terminaison_dest = $terminaison; |
|
| 260 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 261 | - } else { |
|
| 262 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 263 | - } |
|
| 264 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 265 | - $cache = sous_repertoire($cache, $effet); |
|
| 266 | - # cherche un cache existant |
|
| 267 | - /*foreach (array('gif','jpg','png') as $fmt) |
|
| 148 | + static $images_recalcul = array(); |
|
| 149 | + if (strlen($img) == 0) { |
|
| 150 | + return false; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $source = trim(extraire_attribut($img, 'src')); |
|
| 154 | + if (strlen($source) < 1) { |
|
| 155 | + $source = $img; |
|
| 156 | + $img = "<img src='$source' />"; |
|
| 157 | + } # gerer img src="data:....base64" |
|
| 158 | + elseif (preg_match('@^data:image/(jpe?g|png|gif|svg+xml);base64,(.*)$@isS', $source, $regs)) { |
|
| 159 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . str_replace('jpeg', 'jpg', $regs[1]); |
|
| 160 | + if (!file_exists($local)) { |
|
| 161 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 162 | + } |
|
| 163 | + $source = $local; |
|
| 164 | + $img = inserer_attribut($img, 'src', $source); |
|
| 165 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 166 | + $img = inserer_attribut($img, 'width', ''); |
|
| 167 | + $img = inserer_attribut($img, 'height', ''); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // les protocoles web prennent au moins 3 lettres |
|
| 171 | + if (tester_url_absolue($source)) { |
|
| 172 | + include_spip('inc/distant'); |
|
| 173 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 174 | + if (!$fichier) { |
|
| 175 | + return ""; |
|
| 176 | + } |
|
| 177 | + } else { |
|
| 178 | + // enlever le timestamp eventuel |
|
| 179 | + if (strpos($source, "?") !== false) { |
|
| 180 | + $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 181 | + } |
|
| 182 | + if (strpos($source, "?") !== false |
|
| 183 | + and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 184 | + and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 185 | + ) { |
|
| 186 | + $source = $f; |
|
| 187 | + } |
|
| 188 | + $fichier = $source; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + $terminaison_dest = ""; |
|
| 192 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 193 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if ($forcer_format !== false |
|
| 197 | + // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 198 | + and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format,['png','gif','jpg']))) { |
|
| 199 | + $terminaison_dest = $forcer_format; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if (!$terminaison_dest) { |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 207 | + $fichier_dest = $nom_fichier; |
|
| 208 | + if (($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 209 | + or @file_exists($f = $fichier) |
|
| 210 | + ) { |
|
| 211 | + // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 212 | + // au lieu de faire un acces disque sur le fichier |
|
| 213 | + list($ret["hauteur"], $ret["largeur"]) = taille_image($find_in_path ? $f : $img); |
|
| 214 | + $date_src = @filemtime($f); |
|
| 215 | + } elseif (@file_exists($f = "$fichier.src") |
|
| 216 | + and lire_fichier($f, $valeurs) |
|
| 217 | + and $valeurs = unserialize($valeurs) |
|
| 218 | + and isset($valeurs["hauteur_dest"]) |
|
| 219 | + and isset($valeurs["largeur_dest"]) |
|
| 220 | + ) { |
|
| 221 | + $ret["hauteur"] = $valeurs["hauteur_dest"]; |
|
| 222 | + $ret["largeur"] = $valeurs["largeur_dest"]; |
|
| 223 | + $date_src = $valeurs["date"]; |
|
| 224 | + } // pas de fichier source par la |
|
| 225 | + else { |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // pas de taille mesurable |
|
| 230 | + if (!($ret["hauteur"] or $ret["largeur"])) { |
|
| 231 | + return false; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + // les images calculees dependent du chemin du fichier source |
|
| 235 | + // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 236 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 237 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 238 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 239 | + // alors que ca concerne peu de site au final |
|
| 240 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 241 | + $identifiant = $fichier; |
|
| 242 | + |
|
| 243 | + // cas general : |
|
| 244 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 245 | + // cas particulier de reduire : |
|
| 246 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 247 | + $cache = "cache-gd2"; |
|
| 248 | + if (substr($effet, 0, 7) == 'reduire') { |
|
| 249 | + list(, $maxWidth, $maxHeight) = explode('-', $effet); |
|
| 250 | + list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 251 | + $ret['largeur_dest'] = $destWidth; |
|
| 252 | + $ret['hauteur_dest'] = $destHeight; |
|
| 253 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 254 | + $cache = "cache-vignettes"; |
|
| 255 | + $fichier_dest = basename($fichier_dest); |
|
| 256 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 257 | + // on garde la terminaison initiale car image simplement copiee |
|
| 258 | + // et on postfixe son nom avec un md5 du path |
|
| 259 | + $terminaison_dest = $terminaison; |
|
| 260 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 261 | + } else { |
|
| 262 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 263 | + } |
|
| 264 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 265 | + $cache = sous_repertoire($cache, $effet); |
|
| 266 | + # cherche un cache existant |
|
| 267 | + /*foreach (array('gif','jpg','png') as $fmt) |
|
| 268 | 268 | if (@file_exists($cache . $fichier_dest . '.' . $fmt)) { |
| 269 | 269 | $terminaison_dest = $fmt; |
| 270 | 270 | }*/ |
| 271 | - } else { |
|
| 272 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 273 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 274 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 275 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - $fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest; |
|
| 279 | - |
|
| 280 | - $GLOBALS["images_calculees"][] = $fichier_dest; |
|
| 281 | - |
|
| 282 | - $creer = true; |
|
| 283 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 284 | - if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 285 | - $images_recalcul[$fichier_dest] = true; |
|
| 286 | - } else { |
|
| 287 | - if (@file_exists($f = $fichier_dest)) { |
|
| 288 | - if (filemtime($f) >= $date_src) { |
|
| 289 | - $creer = false; |
|
| 290 | - } |
|
| 291 | - } else { |
|
| 292 | - if (@file_exists($f = "$fichier_dest.src") |
|
| 293 | - and lire_fichier($f, $valeurs) |
|
| 294 | - and $valeurs = unserialize($valeurs) |
|
| 295 | - and $valeurs["date"] >= $date_src |
|
| 296 | - ) { |
|
| 297 | - $creer = false; |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - if ($creer) { |
|
| 302 | - if (!@file_exists($fichier)) { |
|
| 303 | - if (!@file_exists("$fichier.src")) { |
|
| 304 | - spip_log("Image absente : $fichier"); |
|
| 305 | - |
|
| 306 | - return false; |
|
| 307 | - } |
|
| 308 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 309 | - reconstruire_image_intermediaire($fichier); |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - if ($creer) { |
|
| 314 | - spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 315 | - "images" . _LOG_DEBUG); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 319 | - $ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction; |
|
| 320 | - $ret["fichier"] = $fichier; |
|
| 321 | - $ret["fonction_image"] = "_image_image" . $terminaison_dest; |
|
| 322 | - $ret["fichier_dest"] = $fichier_dest; |
|
| 323 | - $ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg'); |
|
| 324 | - $ret["format_dest"] = $terminaison_dest; |
|
| 325 | - $ret["date_src"] = $date_src; |
|
| 326 | - $ret["creer"] = $creer; |
|
| 327 | - $ret["class"] = extraire_attribut($img, 'class'); |
|
| 328 | - $ret["alt"] = extraire_attribut($img, 'alt'); |
|
| 329 | - $ret["style"] = extraire_attribut($img, 'style'); |
|
| 330 | - $ret["tag"] = $img; |
|
| 331 | - if ($fonction_creation) { |
|
| 332 | - $ret["reconstruction"] = $fonction_creation; |
|
| 333 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 334 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 335 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 336 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - $ret = pipeline('image_preparer_filtre', array( |
|
| 340 | - 'args' => array( |
|
| 341 | - 'img' => $img, |
|
| 342 | - 'effet' => $effet, |
|
| 343 | - 'forcer_format' => $forcer_format, |
|
| 344 | - 'fonction_creation' => $fonction_creation, |
|
| 345 | - 'find_in_path' => $find_in_path, |
|
| 346 | - ), |
|
| 347 | - 'data' => $ret |
|
| 348 | - ) |
|
| 349 | - ); |
|
| 350 | - |
|
| 351 | - // une globale pour le debug en cas de crash memoire |
|
| 352 | - $GLOBALS["derniere_image_calculee"] = $ret; |
|
| 353 | - |
|
| 354 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 355 | - if ($term_fonction === 'svg') { |
|
| 356 | - if ($creer and !$support_svg) { |
|
| 357 | - process_image_svg_identite($ret); |
|
| 358 | - $ret['creer'] = false; |
|
| 359 | - } |
|
| 360 | - } |
|
| 361 | - else { |
|
| 362 | - if (!function_exists($ret["fonction_imagecreatefrom"])) { |
|
| 363 | - return false; |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - return $ret; |
|
| 271 | + } else { |
|
| 272 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 273 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 274 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 275 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + $fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest; |
|
| 279 | + |
|
| 280 | + $GLOBALS["images_calculees"][] = $fichier_dest; |
|
| 281 | + |
|
| 282 | + $creer = true; |
|
| 283 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 284 | + if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 285 | + $images_recalcul[$fichier_dest] = true; |
|
| 286 | + } else { |
|
| 287 | + if (@file_exists($f = $fichier_dest)) { |
|
| 288 | + if (filemtime($f) >= $date_src) { |
|
| 289 | + $creer = false; |
|
| 290 | + } |
|
| 291 | + } else { |
|
| 292 | + if (@file_exists($f = "$fichier_dest.src") |
|
| 293 | + and lire_fichier($f, $valeurs) |
|
| 294 | + and $valeurs = unserialize($valeurs) |
|
| 295 | + and $valeurs["date"] >= $date_src |
|
| 296 | + ) { |
|
| 297 | + $creer = false; |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + if ($creer) { |
|
| 302 | + if (!@file_exists($fichier)) { |
|
| 303 | + if (!@file_exists("$fichier.src")) { |
|
| 304 | + spip_log("Image absente : $fichier"); |
|
| 305 | + |
|
| 306 | + return false; |
|
| 307 | + } |
|
| 308 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 309 | + reconstruire_image_intermediaire($fichier); |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + if ($creer) { |
|
| 314 | + spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 315 | + "images" . _LOG_DEBUG); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 319 | + $ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction; |
|
| 320 | + $ret["fichier"] = $fichier; |
|
| 321 | + $ret["fonction_image"] = "_image_image" . $terminaison_dest; |
|
| 322 | + $ret["fichier_dest"] = $fichier_dest; |
|
| 323 | + $ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg'); |
|
| 324 | + $ret["format_dest"] = $terminaison_dest; |
|
| 325 | + $ret["date_src"] = $date_src; |
|
| 326 | + $ret["creer"] = $creer; |
|
| 327 | + $ret["class"] = extraire_attribut($img, 'class'); |
|
| 328 | + $ret["alt"] = extraire_attribut($img, 'alt'); |
|
| 329 | + $ret["style"] = extraire_attribut($img, 'style'); |
|
| 330 | + $ret["tag"] = $img; |
|
| 331 | + if ($fonction_creation) { |
|
| 332 | + $ret["reconstruction"] = $fonction_creation; |
|
| 333 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 334 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 335 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 336 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + $ret = pipeline('image_preparer_filtre', array( |
|
| 340 | + 'args' => array( |
|
| 341 | + 'img' => $img, |
|
| 342 | + 'effet' => $effet, |
|
| 343 | + 'forcer_format' => $forcer_format, |
|
| 344 | + 'fonction_creation' => $fonction_creation, |
|
| 345 | + 'find_in_path' => $find_in_path, |
|
| 346 | + ), |
|
| 347 | + 'data' => $ret |
|
| 348 | + ) |
|
| 349 | + ); |
|
| 350 | + |
|
| 351 | + // une globale pour le debug en cas de crash memoire |
|
| 352 | + $GLOBALS["derniere_image_calculee"] = $ret; |
|
| 353 | + |
|
| 354 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 355 | + if ($term_fonction === 'svg') { |
|
| 356 | + if ($creer and !$support_svg) { |
|
| 357 | + process_image_svg_identite($ret); |
|
| 358 | + $ret['creer'] = false; |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | + else { |
|
| 362 | + if (!function_exists($ret["fonction_imagecreatefrom"])) { |
|
| 363 | + return false; |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + return $ret; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -373,11 +373,11 @@ discard block |
||
| 373 | 373 | * @return string |
| 374 | 374 | */ |
| 375 | 375 | function _image_trouver_extension($path) { |
| 376 | - if (preg_match(",\.(gif|jpe?g|png|svg)($|[?]),i", $path, $regs)) { |
|
| 377 | - $terminaison = strtolower($regs[1]); |
|
| 378 | - return $terminaison; |
|
| 379 | - } |
|
| 380 | - return ''; |
|
| 376 | + if (preg_match(",\.(gif|jpe?g|png|svg)($|[?]),i", $path, $regs)) { |
|
| 377 | + $terminaison = strtolower($regs[1]); |
|
| 378 | + return $terminaison; |
|
| 379 | + } |
|
| 380 | + return ''; |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -388,60 +388,60 @@ discard block |
||
| 388 | 388 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 389 | 389 | */ |
| 390 | 390 | function _image_trouver_extension_pertinente($path) { |
| 391 | - $path = supprimer_timestamp($path); |
|
| 392 | - $terminaison = _image_trouver_extension($path); |
|
| 393 | - if ($terminaison == 'jpg') { |
|
| 394 | - $terminaison = 'jpeg'; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - if (!file_exists($path)) { |
|
| 398 | - return $terminaison; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - if (!$info = @spip_getimagesize($path)) { |
|
| 402 | - return $terminaison; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - if (isset($info['mime'])) { |
|
| 406 | - $mime = $info['mime']; |
|
| 407 | - } |
|
| 408 | - else { |
|
| 409 | - $mime = image_type_to_mime_type($info[2]); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - switch (strtolower($mime)) { |
|
| 413 | - case 'image/png': |
|
| 414 | - case 'image/x-png': |
|
| 415 | - $_terminaison = 'png'; |
|
| 416 | - break; |
|
| 417 | - |
|
| 418 | - case 'image/jpg': |
|
| 419 | - case 'image/jpeg': |
|
| 420 | - case 'image/pjpeg': |
|
| 421 | - $_terminaison = 'jpeg'; |
|
| 422 | - break; |
|
| 423 | - |
|
| 424 | - case 'image/gif': |
|
| 425 | - $_terminaison = 'gif'; |
|
| 426 | - break; |
|
| 427 | - |
|
| 428 | - case 'image/webp': |
|
| 429 | - case 'image/x-webp': |
|
| 430 | - $_terminaison = 'webp'; |
|
| 431 | - break; |
|
| 432 | - |
|
| 433 | - case 'image/svg+xml': |
|
| 434 | - $_terminaison = 'svg'; |
|
| 435 | - break; |
|
| 436 | - |
|
| 437 | - default: |
|
| 438 | - $_terminaison = ''; |
|
| 439 | - } |
|
| 440 | - if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 441 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", "images." . _LOG_INFO_IMPORTANTE); |
|
| 442 | - $terminaison = $_terminaison; |
|
| 443 | - } |
|
| 444 | - return $terminaison; |
|
| 391 | + $path = supprimer_timestamp($path); |
|
| 392 | + $terminaison = _image_trouver_extension($path); |
|
| 393 | + if ($terminaison == 'jpg') { |
|
| 394 | + $terminaison = 'jpeg'; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + if (!file_exists($path)) { |
|
| 398 | + return $terminaison; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + if (!$info = @spip_getimagesize($path)) { |
|
| 402 | + return $terminaison; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + if (isset($info['mime'])) { |
|
| 406 | + $mime = $info['mime']; |
|
| 407 | + } |
|
| 408 | + else { |
|
| 409 | + $mime = image_type_to_mime_type($info[2]); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + switch (strtolower($mime)) { |
|
| 413 | + case 'image/png': |
|
| 414 | + case 'image/x-png': |
|
| 415 | + $_terminaison = 'png'; |
|
| 416 | + break; |
|
| 417 | + |
|
| 418 | + case 'image/jpg': |
|
| 419 | + case 'image/jpeg': |
|
| 420 | + case 'image/pjpeg': |
|
| 421 | + $_terminaison = 'jpeg'; |
|
| 422 | + break; |
|
| 423 | + |
|
| 424 | + case 'image/gif': |
|
| 425 | + $_terminaison = 'gif'; |
|
| 426 | + break; |
|
| 427 | + |
|
| 428 | + case 'image/webp': |
|
| 429 | + case 'image/x-webp': |
|
| 430 | + $_terminaison = 'webp'; |
|
| 431 | + break; |
|
| 432 | + |
|
| 433 | + case 'image/svg+xml': |
|
| 434 | + $_terminaison = 'svg'; |
|
| 435 | + break; |
|
| 436 | + |
|
| 437 | + default: |
|
| 438 | + $_terminaison = ''; |
|
| 439 | + } |
|
| 440 | + if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 441 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", "images." . _LOG_INFO_IMPORTANTE); |
|
| 442 | + $terminaison = $_terminaison; |
|
| 443 | + } |
|
| 444 | + return $terminaison; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -456,14 +456,14 @@ discard block |
||
| 456 | 456 | * Une ressource de type Image GD. |
| 457 | 457 | */ |
| 458 | 458 | function _imagecreatefromjpeg($filename) { |
| 459 | - $img = @imagecreatefromjpeg($filename); |
|
| 460 | - if (!$img) { |
|
| 461 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 462 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 463 | - $img = imagecreate(10, 10); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - return $img; |
|
| 459 | + $img = @imagecreatefromjpeg($filename); |
|
| 460 | + if (!$img) { |
|
| 461 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 462 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 463 | + $img = imagecreate(10, 10); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + return $img; |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
@@ -478,14 +478,14 @@ discard block |
||
| 478 | 478 | * Une ressource de type Image GD. |
| 479 | 479 | */ |
| 480 | 480 | function _imagecreatefrompng($filename) { |
| 481 | - $img = @imagecreatefrompng($filename); |
|
| 482 | - if (!$img) { |
|
| 483 | - spip_log("Erreur lecture imagecreatefrompng $filename", _LOG_CRITIQUE); |
|
| 484 | - erreur_squelette("Erreur lecture imagecreatefrompng $filename"); |
|
| 485 | - $img = imagecreate(10, 10); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - return $img; |
|
| 481 | + $img = @imagecreatefrompng($filename); |
|
| 482 | + if (!$img) { |
|
| 483 | + spip_log("Erreur lecture imagecreatefrompng $filename", _LOG_CRITIQUE); |
|
| 484 | + erreur_squelette("Erreur lecture imagecreatefrompng $filename"); |
|
| 485 | + $img = imagecreate(10, 10); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + return $img; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | /** |
@@ -500,14 +500,14 @@ discard block |
||
| 500 | 500 | * Une ressource de type Image GD. |
| 501 | 501 | */ |
| 502 | 502 | function _imagecreatefromgif($filename) { |
| 503 | - $img = @imagecreatefromgif($filename); |
|
| 504 | - if (!$img) { |
|
| 505 | - spip_log("Erreur lecture imagecreatefromgif $filename", _LOG_CRITIQUE); |
|
| 506 | - erreur_squelette("Erreur lecture imagecreatefromgif $filename"); |
|
| 507 | - $img = imagecreate(10, 10); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - return $img; |
|
| 503 | + $img = @imagecreatefromgif($filename); |
|
| 504 | + if (!$img) { |
|
| 505 | + spip_log("Erreur lecture imagecreatefromgif $filename", _LOG_CRITIQUE); |
|
| 506 | + erreur_squelette("Erreur lecture imagecreatefromgif $filename"); |
|
| 507 | + $img = imagecreate(10, 10); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + return $img; |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | /** |
@@ -525,24 +525,24 @@ discard block |
||
| 525 | 525 | * - true si une image est bien retournée. |
| 526 | 526 | */ |
| 527 | 527 | function _image_imagepng($img, $fichier) { |
| 528 | - if (!function_exists('imagepng')) { |
|
| 529 | - return false; |
|
| 530 | - } |
|
| 531 | - $tmp = $fichier . ".tmp"; |
|
| 532 | - $ret = imagepng($img, $tmp); |
|
| 533 | - if (file_exists($tmp)) { |
|
| 534 | - $taille_test = getimagesize($tmp); |
|
| 535 | - if ($taille_test[0] < 1) { |
|
| 536 | - return false; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 540 | - @rename($tmp, $fichier); |
|
| 541 | - |
|
| 542 | - return $ret; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - return false; |
|
| 528 | + if (!function_exists('imagepng')) { |
|
| 529 | + return false; |
|
| 530 | + } |
|
| 531 | + $tmp = $fichier . ".tmp"; |
|
| 532 | + $ret = imagepng($img, $tmp); |
|
| 533 | + if (file_exists($tmp)) { |
|
| 534 | + $taille_test = getimagesize($tmp); |
|
| 535 | + if ($taille_test[0] < 1) { |
|
| 536 | + return false; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 540 | + @rename($tmp, $fichier); |
|
| 541 | + |
|
| 542 | + return $ret; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + return false; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -560,24 +560,24 @@ discard block |
||
| 560 | 560 | * - true si une image est bien retournée. |
| 561 | 561 | */ |
| 562 | 562 | function _image_imagegif($img, $fichier) { |
| 563 | - if (!function_exists('imagegif')) { |
|
| 564 | - return false; |
|
| 565 | - } |
|
| 566 | - $tmp = $fichier . ".tmp"; |
|
| 567 | - $ret = imagegif($img, $tmp); |
|
| 568 | - if (file_exists($tmp)) { |
|
| 569 | - $taille_test = getimagesize($tmp); |
|
| 570 | - if ($taille_test[0] < 1) { |
|
| 571 | - return false; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 575 | - @rename($tmp, $fichier); |
|
| 576 | - |
|
| 577 | - return $ret; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - return false; |
|
| 563 | + if (!function_exists('imagegif')) { |
|
| 564 | + return false; |
|
| 565 | + } |
|
| 566 | + $tmp = $fichier . ".tmp"; |
|
| 567 | + $ret = imagegif($img, $tmp); |
|
| 568 | + if (file_exists($tmp)) { |
|
| 569 | + $taille_test = getimagesize($tmp); |
|
| 570 | + if ($taille_test[0] < 1) { |
|
| 571 | + return false; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 575 | + @rename($tmp, $fichier); |
|
| 576 | + |
|
| 577 | + return $ret; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + return false; |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | /** |
@@ -600,29 +600,29 @@ discard block |
||
| 600 | 600 | * - true si une image est bien retournée. |
| 601 | 601 | */ |
| 602 | 602 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 603 | - if (!function_exists('imagejpeg')) { |
|
| 604 | - return false; |
|
| 605 | - } |
|
| 606 | - $tmp = $fichier . ".tmp"; |
|
| 603 | + if (!function_exists('imagejpeg')) { |
|
| 604 | + return false; |
|
| 605 | + } |
|
| 606 | + $tmp = $fichier . ".tmp"; |
|
| 607 | 607 | |
| 608 | - // Enable interlancing |
|
| 609 | - imageinterlace($img, true); |
|
| 608 | + // Enable interlancing |
|
| 609 | + imageinterlace($img, true); |
|
| 610 | 610 | |
| 611 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 611 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 612 | 612 | |
| 613 | - if (file_exists($tmp)) { |
|
| 614 | - $taille_test = getimagesize($tmp); |
|
| 615 | - if ($taille_test[0] < 1) { |
|
| 616 | - return false; |
|
| 617 | - } |
|
| 613 | + if (file_exists($tmp)) { |
|
| 614 | + $taille_test = getimagesize($tmp); |
|
| 615 | + if ($taille_test[0] < 1) { |
|
| 616 | + return false; |
|
| 617 | + } |
|
| 618 | 618 | |
| 619 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 620 | - @rename($tmp, $fichier); |
|
| 619 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 620 | + @rename($tmp, $fichier); |
|
| 621 | 621 | |
| 622 | - return $ret; |
|
| 623 | - } |
|
| 622 | + return $ret; |
|
| 623 | + } |
|
| 624 | 624 | |
| 625 | - return false; |
|
| 625 | + return false; |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | /** |
@@ -640,9 +640,9 @@ discard block |
||
| 640 | 640 | * true si le fichier a bien été créé ; false sinon. |
| 641 | 641 | */ |
| 642 | 642 | function _image_imageico($img, $fichier) { |
| 643 | - $gd_image_array = array($img); |
|
| 643 | + $gd_image_array = array($img); |
|
| 644 | 644 | |
| 645 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 645 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | |
@@ -663,35 +663,35 @@ discard block |
||
| 663 | 663 | */ |
| 664 | 664 | function _image_imagesvg($img, $fichier) { |
| 665 | 665 | |
| 666 | - $tmp = $fichier . ".tmp"; |
|
| 667 | - if (strpos($img, "<") === false) { |
|
| 668 | - $img = supprimer_timestamp($img); |
|
| 669 | - if (!file_exists($img)) { |
|
| 670 | - return false; |
|
| 671 | - } |
|
| 672 | - @copy($img, $tmp); |
|
| 673 | - if (filesize($tmp) == filesize($img)) { |
|
| 674 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 675 | - @rename($tmp, $fichier); |
|
| 676 | - return true; |
|
| 677 | - } |
|
| 678 | - return false; |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - file_put_contents($tmp, $img); |
|
| 682 | - if (file_exists($tmp)) { |
|
| 683 | - $taille_test = spip_getimagesize($tmp); |
|
| 684 | - if ($taille_test[0] < 1) { |
|
| 685 | - return false; |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 689 | - @rename($tmp, $fichier); |
|
| 690 | - |
|
| 691 | - return true; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - return false; |
|
| 666 | + $tmp = $fichier . ".tmp"; |
|
| 667 | + if (strpos($img, "<") === false) { |
|
| 668 | + $img = supprimer_timestamp($img); |
|
| 669 | + if (!file_exists($img)) { |
|
| 670 | + return false; |
|
| 671 | + } |
|
| 672 | + @copy($img, $tmp); |
|
| 673 | + if (filesize($tmp) == filesize($img)) { |
|
| 674 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 675 | + @rename($tmp, $fichier); |
|
| 676 | + return true; |
|
| 677 | + } |
|
| 678 | + return false; |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + file_put_contents($tmp, $img); |
|
| 682 | + if (file_exists($tmp)) { |
|
| 683 | + $taille_test = spip_getimagesize($tmp); |
|
| 684 | + if ($taille_test[0] < 1) { |
|
| 685 | + return false; |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 689 | + @rename($tmp, $fichier); |
|
| 690 | + |
|
| 691 | + return true; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + return false; |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | |
@@ -719,27 +719,27 @@ discard block |
||
| 719 | 719 | * - false sinon. |
| 720 | 720 | */ |
| 721 | 721 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE) { |
| 722 | - $fonction = "_image_image" . $valeurs['format_dest']; |
|
| 723 | - $ret = false; |
|
| 724 | - #un flag pour reperer les images gravees |
|
| 725 | - $lock = |
|
| 726 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 727 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 728 | - if ( |
|
| 729 | - function_exists($fonction) |
|
| 730 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 731 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 732 | - && !$lock |
|
| 733 | - ) { |
|
| 734 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 735 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 736 | - list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']); |
|
| 737 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 738 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - return $ret; |
|
| 722 | + $fonction = "_image_image" . $valeurs['format_dest']; |
|
| 723 | + $ret = false; |
|
| 724 | + #un flag pour reperer les images gravees |
|
| 725 | + $lock = |
|
| 726 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 727 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 728 | + if ( |
|
| 729 | + function_exists($fonction) |
|
| 730 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 731 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 732 | + && !$lock |
|
| 733 | + ) { |
|
| 734 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 735 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 736 | + list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']); |
|
| 737 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 738 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + return $ret; |
|
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | /** |
@@ -752,26 +752,26 @@ discard block |
||
| 752 | 752 | * Chemin vers le fichier manquant |
| 753 | 753 | **/ |
| 754 | 754 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 755 | - $reconstruire = array(); |
|
| 756 | - $fichier = $fichier_manquant; |
|
| 757 | - while (strpos($fichier,"://")===false |
|
| 758 | - and !@file_exists($fichier) |
|
| 759 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 760 | - and $valeurs = unserialize($source) |
|
| 761 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 762 | - ) { |
|
| 763 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 764 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 765 | - } |
|
| 766 | - while (count($reconstruire)) { |
|
| 767 | - $r = array_pop($reconstruire); |
|
| 768 | - $fonction = $r[0]; |
|
| 769 | - $args = $r[1]; |
|
| 770 | - call_user_func_array($fonction, $args); |
|
| 771 | - } |
|
| 772 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 773 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 774 | - ramasse_miettes($fichier_manquant); |
|
| 755 | + $reconstruire = array(); |
|
| 756 | + $fichier = $fichier_manquant; |
|
| 757 | + while (strpos($fichier,"://")===false |
|
| 758 | + and !@file_exists($fichier) |
|
| 759 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 760 | + and $valeurs = unserialize($source) |
|
| 761 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 762 | + ) { |
|
| 763 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 764 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 765 | + } |
|
| 766 | + while (count($reconstruire)) { |
|
| 767 | + $r = array_pop($reconstruire); |
|
| 768 | + $fonction = $r[0]; |
|
| 769 | + $args = $r[1]; |
|
| 770 | + call_user_func_array($fonction, $args); |
|
| 771 | + } |
|
| 772 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 773 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 774 | + ramasse_miettes($fichier_manquant); |
|
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | /** |
@@ -791,25 +791,25 @@ discard block |
||
| 791 | 791 | * Chemin du fichier d'image calculé |
| 792 | 792 | **/ |
| 793 | 793 | function ramasse_miettes($fichier) { |
| 794 | - if (strpos($fichier,"://")!==false |
|
| 795 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 796 | - or !$valeurs = unserialize($source) |
|
| 797 | - ) { |
|
| 798 | - return; |
|
| 799 | - } |
|
| 800 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 801 | - while ( |
|
| 802 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 803 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 804 | - and (lire_fichier($src = "$fichier.src", |
|
| 805 | - $source)) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 806 | - and ($valeurs = unserialize($source)) # et valide |
|
| 807 | - ) { |
|
| 808 | - # on efface le fichier |
|
| 809 | - spip_unlink($fichier); |
|
| 810 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 811 | - #spip_unlink($src); |
|
| 812 | - } |
|
| 794 | + if (strpos($fichier,"://")!==false |
|
| 795 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 796 | + or !$valeurs = unserialize($source) |
|
| 797 | + ) { |
|
| 798 | + return; |
|
| 799 | + } |
|
| 800 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 801 | + while ( |
|
| 802 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 803 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 804 | + and (lire_fichier($src = "$fichier.src", |
|
| 805 | + $source)) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 806 | + and ($valeurs = unserialize($source)) # et valide |
|
| 807 | + ) { |
|
| 808 | + # on efface le fichier |
|
| 809 | + spip_unlink($fichier); |
|
| 810 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 811 | + #spip_unlink($src); |
|
| 812 | + } |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | |
@@ -834,71 +834,71 @@ discard block |
||
| 834 | 834 | * Code HTML de l'image |
| 835 | 835 | **/ |
| 836 | 836 | function image_graver($img) { |
| 837 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 838 | - // des traitements auto a la fin d'une serie de filtres |
|
| 839 | - $img = pipeline('post_image_filtrer', $img); |
|
| 840 | - |
|
| 841 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 842 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 843 | - $fichier = substr($fichier, 0, $p); |
|
| 844 | - } |
|
| 845 | - if (strlen($fichier) < 1) { |
|
| 846 | - $fichier = $img; |
|
| 847 | - } |
|
| 848 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 849 | - # et qu'il ne s'agit pas d'une URL |
|
| 850 | - if (strpos($fichier,"://")===false and !@file_exists($fichier)) { |
|
| 851 | - reconstruire_image_intermediaire($fichier); |
|
| 852 | - } |
|
| 853 | - ramasse_miettes($fichier); |
|
| 854 | - |
|
| 855 | - // ajouter le timestamp si besoin |
|
| 856 | - if (strpos($fichier_ori, "?") === false) { |
|
| 857 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 858 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - return $img; |
|
| 837 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 838 | + // des traitements auto a la fin d'une serie de filtres |
|
| 839 | + $img = pipeline('post_image_filtrer', $img); |
|
| 840 | + |
|
| 841 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 842 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 843 | + $fichier = substr($fichier, 0, $p); |
|
| 844 | + } |
|
| 845 | + if (strlen($fichier) < 1) { |
|
| 846 | + $fichier = $img; |
|
| 847 | + } |
|
| 848 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 849 | + # et qu'il ne s'agit pas d'une URL |
|
| 850 | + if (strpos($fichier,"://")===false and !@file_exists($fichier)) { |
|
| 851 | + reconstruire_image_intermediaire($fichier); |
|
| 852 | + } |
|
| 853 | + ramasse_miettes($fichier); |
|
| 854 | + |
|
| 855 | + // ajouter le timestamp si besoin |
|
| 856 | + if (strpos($fichier_ori, "?") === false) { |
|
| 857 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 858 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + return $img; |
|
| 862 | 862 | } |
| 863 | 863 | |
| 864 | 864 | |
| 865 | 865 | if (!function_exists("imagepalettetotruecolor")) { |
| 866 | - /** |
|
| 867 | - * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 868 | - * |
|
| 869 | - * @note Pour compatibilité avec PHP < 5.5 |
|
| 870 | - * |
|
| 871 | - * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 872 | - * |
|
| 873 | - * @param ressource $img |
|
| 874 | - * @return bool |
|
| 875 | - * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 876 | - * - false si la transformation ne peut être faite. |
|
| 877 | - **/ |
|
| 878 | - function imagepalettetotruecolor(&$img) { |
|
| 879 | - if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 880 | - return false; |
|
| 881 | - } elseif (!imageistruecolor($img)) { |
|
| 882 | - $w = imagesx($img); |
|
| 883 | - $h = imagesy($img); |
|
| 884 | - $img1 = imagecreatetruecolor($w, $h); |
|
| 885 | - //Conserver la transparence si possible |
|
| 886 | - if (function_exists('ImageCopyResampled')) { |
|
| 887 | - if (function_exists("imageAntiAlias")) { |
|
| 888 | - imageAntiAlias($img1, true); |
|
| 889 | - } |
|
| 890 | - @imagealphablending($img1, false); |
|
| 891 | - @imagesavealpha($img1, true); |
|
| 892 | - @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 893 | - } else { |
|
| 894 | - imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - $img = $img1; |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - return true; |
|
| 901 | - } |
|
| 866 | + /** |
|
| 867 | + * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 868 | + * |
|
| 869 | + * @note Pour compatibilité avec PHP < 5.5 |
|
| 870 | + * |
|
| 871 | + * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 872 | + * |
|
| 873 | + * @param ressource $img |
|
| 874 | + * @return bool |
|
| 875 | + * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 876 | + * - false si la transformation ne peut être faite. |
|
| 877 | + **/ |
|
| 878 | + function imagepalettetotruecolor(&$img) { |
|
| 879 | + if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 880 | + return false; |
|
| 881 | + } elseif (!imageistruecolor($img)) { |
|
| 882 | + $w = imagesx($img); |
|
| 883 | + $h = imagesy($img); |
|
| 884 | + $img1 = imagecreatetruecolor($w, $h); |
|
| 885 | + //Conserver la transparence si possible |
|
| 886 | + if (function_exists('ImageCopyResampled')) { |
|
| 887 | + if (function_exists("imageAntiAlias")) { |
|
| 888 | + imageAntiAlias($img1, true); |
|
| 889 | + } |
|
| 890 | + @imagealphablending($img1, false); |
|
| 891 | + @imagesavealpha($img1, true); |
|
| 892 | + @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 893 | + } else { |
|
| 894 | + imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + $img = $img1; |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + return true; |
|
| 901 | + } |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | /** |
@@ -925,32 +925,32 @@ discard block |
||
| 925 | 925 | * Code html modifié de la balise. |
| 926 | 926 | **/ |
| 927 | 927 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 928 | - if ($style === false) { |
|
| 929 | - $style = extraire_attribut($tag, 'style'); |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - // enlever le width et height du style |
|
| 933 | - $style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims", "", $style); |
|
| 934 | - if ($style and $style[0] == ';') { |
|
| 935 | - $style = substr($style, 1); |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - // mettre des attributs de width et height sur les images, |
|
| 939 | - // ca accelere le rendu du navigateur |
|
| 940 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 941 | - // quand on a desactive l'affichage des images. |
|
| 942 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 943 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 944 | - |
|
| 945 | - // attributs deprecies. Transformer en CSS |
|
| 946 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 947 | - $style = "margin:${espace}px;" . $style; |
|
| 948 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true); |
|
| 952 | - |
|
| 953 | - return $tag; |
|
| 928 | + if ($style === false) { |
|
| 929 | + $style = extraire_attribut($tag, 'style'); |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + // enlever le width et height du style |
|
| 933 | + $style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims", "", $style); |
|
| 934 | + if ($style and $style[0] == ';') { |
|
| 935 | + $style = substr($style, 1); |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + // mettre des attributs de width et height sur les images, |
|
| 939 | + // ca accelere le rendu du navigateur |
|
| 940 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 941 | + // quand on a desactive l'affichage des images. |
|
| 942 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 943 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 944 | + |
|
| 945 | + // attributs deprecies. Transformer en CSS |
|
| 946 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 947 | + $style = "margin:${espace}px;" . $style; |
|
| 948 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true); |
|
| 952 | + |
|
| 953 | + return $tag; |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | |
@@ -976,71 +976,71 @@ discard block |
||
| 976 | 976 | * Retourne le code HTML de l'image |
| 977 | 977 | **/ |
| 978 | 978 | function _image_ecrire_tag($valeurs, $surcharge = array()) { |
| 979 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 980 | - |
|
| 981 | - // fermer les tags img pas bien fermes; |
|
| 982 | - $tag = str_replace(">", "/>", str_replace("/>", ">", $valeurs['tag'])); |
|
| 983 | - |
|
| 984 | - // le style |
|
| 985 | - $style = $valeurs['style']; |
|
| 986 | - if (isset($surcharge['style'])) { |
|
| 987 | - $style = $surcharge['style']; |
|
| 988 | - unset($surcharge['style']); |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - // traiter specifiquement la largeur et la hauteur |
|
| 992 | - $width = $valeurs['largeur']; |
|
| 993 | - if (isset($surcharge['width'])) { |
|
| 994 | - $width = $surcharge['width']; |
|
| 995 | - unset($surcharge['width']); |
|
| 996 | - } |
|
| 997 | - $height = $valeurs['hauteur']; |
|
| 998 | - if (isset($surcharge['height'])) { |
|
| 999 | - $height = $surcharge['height']; |
|
| 1000 | - unset($surcharge['height']); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1004 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1005 | - // on remplace toute les ref a src dans le tag |
|
| 1006 | - $src = extraire_attribut($tag, 'src'); |
|
| 1007 | - if (isset($surcharge['src'])) { |
|
| 1008 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1009 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1010 | - // pas garanti comme methode, mais mieux que rien |
|
| 1011 | - if (strpos($src, '&') !== false) { |
|
| 1012 | - $tag = str_replace(str_replace("&", "&", $src), $surcharge['src'], $tag); |
|
| 1013 | - } |
|
| 1014 | - $src = $surcharge['src']; |
|
| 1015 | - unset($surcharge['src']); |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - $class = $valeurs['class']; |
|
| 1019 | - if (isset($surcharge['class'])) { |
|
| 1020 | - $class = $surcharge['class']; |
|
| 1021 | - unset($surcharge['class']); |
|
| 1022 | - } |
|
| 1023 | - if (strlen($class)) { |
|
| 1024 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - if (count($surcharge)) { |
|
| 1028 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1029 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1030 | - } |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - $tag = pipeline('image_ecrire_tag_finir', |
|
| 1034 | - array( |
|
| 1035 | - 'args' => array( |
|
| 1036 | - 'valeurs' => $valeurs, |
|
| 1037 | - 'surcharge' => $surcharge, |
|
| 1038 | - ), |
|
| 1039 | - 'data' => $tag |
|
| 1040 | - ) |
|
| 1041 | - ); |
|
| 1042 | - |
|
| 1043 | - return $tag; |
|
| 979 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 980 | + |
|
| 981 | + // fermer les tags img pas bien fermes; |
|
| 982 | + $tag = str_replace(">", "/>", str_replace("/>", ">", $valeurs['tag'])); |
|
| 983 | + |
|
| 984 | + // le style |
|
| 985 | + $style = $valeurs['style']; |
|
| 986 | + if (isset($surcharge['style'])) { |
|
| 987 | + $style = $surcharge['style']; |
|
| 988 | + unset($surcharge['style']); |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + // traiter specifiquement la largeur et la hauteur |
|
| 992 | + $width = $valeurs['largeur']; |
|
| 993 | + if (isset($surcharge['width'])) { |
|
| 994 | + $width = $surcharge['width']; |
|
| 995 | + unset($surcharge['width']); |
|
| 996 | + } |
|
| 997 | + $height = $valeurs['hauteur']; |
|
| 998 | + if (isset($surcharge['height'])) { |
|
| 999 | + $height = $surcharge['height']; |
|
| 1000 | + unset($surcharge['height']); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1004 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1005 | + // on remplace toute les ref a src dans le tag |
|
| 1006 | + $src = extraire_attribut($tag, 'src'); |
|
| 1007 | + if (isset($surcharge['src'])) { |
|
| 1008 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1009 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1010 | + // pas garanti comme methode, mais mieux que rien |
|
| 1011 | + if (strpos($src, '&') !== false) { |
|
| 1012 | + $tag = str_replace(str_replace("&", "&", $src), $surcharge['src'], $tag); |
|
| 1013 | + } |
|
| 1014 | + $src = $surcharge['src']; |
|
| 1015 | + unset($surcharge['src']); |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + $class = $valeurs['class']; |
|
| 1019 | + if (isset($surcharge['class'])) { |
|
| 1020 | + $class = $surcharge['class']; |
|
| 1021 | + unset($surcharge['class']); |
|
| 1022 | + } |
|
| 1023 | + if (strlen($class)) { |
|
| 1024 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + if (count($surcharge)) { |
|
| 1028 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1029 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1030 | + } |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + $tag = pipeline('image_ecrire_tag_finir', |
|
| 1034 | + array( |
|
| 1035 | + 'args' => array( |
|
| 1036 | + 'valeurs' => $valeurs, |
|
| 1037 | + 'surcharge' => $surcharge, |
|
| 1038 | + ), |
|
| 1039 | + 'data' => $tag |
|
| 1040 | + ) |
|
| 1041 | + ); |
|
| 1042 | + |
|
| 1043 | + return $tag; |
|
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | /** |
@@ -1063,253 +1063,253 @@ discard block |
||
| 1063 | 1063 | * Description de l'image, sinon null. |
| 1064 | 1064 | **/ |
| 1065 | 1065 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1066 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1067 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1068 | - $image = $valeurs['fichier']; |
|
| 1069 | - $format = $valeurs['format_source']; |
|
| 1070 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1071 | - $destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]); |
|
| 1072 | - |
|
| 1073 | - $format_sortie = $valeurs['format_dest']; |
|
| 1074 | - |
|
| 1075 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1076 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - // si le doc n'est pas une image, refuser |
|
| 1080 | - if (!$force and !in_array($format, formats_image_acceptables())) { |
|
| 1081 | - return; |
|
| 1082 | - } |
|
| 1083 | - $destination = "$destdir/$destfile"; |
|
| 1084 | - |
|
| 1085 | - // calculer la taille |
|
| 1086 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1087 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1088 | - list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight); |
|
| 1089 | - } |
|
| 1090 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1091 | - $destWidth = $maxWidth; |
|
| 1092 | - $destHeight = $maxHeight; |
|
| 1093 | - } else { |
|
| 1094 | - spip_log("echec $process sur $image"); |
|
| 1095 | - |
|
| 1096 | - return; |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - $vignette = ''; |
|
| 1100 | - |
|
| 1101 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1102 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1103 | - $vignette = $destination . '.' . $format; |
|
| 1104 | - @copy($image, $vignette); |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - elseif ($valeurs["format_source"] === 'svg') { |
|
| 1108 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)){ |
|
| 1109 | - $format_sortie = 'svg'; |
|
| 1110 | - $vignette = $destination . "." . $format_sortie; |
|
| 1111 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1112 | - _image_gd_output($svg, $valeurs); |
|
| 1113 | - } |
|
| 1114 | - } |
|
| 1115 | - |
|
| 1116 | - // imagemagick en ligne de commande |
|
| 1117 | - elseif ($process == 'convert') { |
|
| 1118 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1119 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1120 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1121 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1122 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1123 | - } |
|
| 1124 | - $vignette = $destination . "." . $format_sortie; |
|
| 1125 | - $commande = str_replace( |
|
| 1126 | - array('%x', '%y', '%src', '%dest'), |
|
| 1127 | - array( |
|
| 1128 | - $destWidth, |
|
| 1129 | - $destHeight, |
|
| 1130 | - escapeshellcmd($image), |
|
| 1131 | - escapeshellcmd($vignette) |
|
| 1132 | - ), |
|
| 1133 | - _RESIZE_COMMAND); |
|
| 1134 | - spip_log($commande); |
|
| 1135 | - exec($commande); |
|
| 1136 | - if (!@file_exists($vignette)) { |
|
| 1137 | - spip_log("echec convert sur $vignette"); |
|
| 1138 | - |
|
| 1139 | - return; // echec commande |
|
| 1140 | - } |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - // php5 imagemagick |
|
| 1144 | - elseif ($process == 'imagick') { |
|
| 1145 | - $vignette = "$destination." . $format_sortie; |
|
| 1146 | - |
|
| 1147 | - if (!class_exists('Imagick')) { |
|
| 1148 | - spip_log("Classe Imagick absente !", _LOG_ERREUR); |
|
| 1149 | - |
|
| 1150 | - return; |
|
| 1151 | - } |
|
| 1152 | - $imagick = new Imagick(); |
|
| 1153 | - $imagick->readImage($image); |
|
| 1154 | - $imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS, |
|
| 1155 | - 1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1156 | - $imagick->writeImage($vignette); |
|
| 1157 | - |
|
| 1158 | - if (!@file_exists($vignette)) { |
|
| 1159 | - spip_log("echec imagick sur $vignette"); |
|
| 1160 | - |
|
| 1161 | - return; |
|
| 1162 | - } |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - // netpbm |
|
| 1166 | - elseif ($process == "netpbm") { |
|
| 1167 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1168 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1169 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1170 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1171 | - return; |
|
| 1172 | - } |
|
| 1173 | - $vignette = $destination . "." . $format_sortie; |
|
| 1174 | - $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND); |
|
| 1175 | - if ($format == "jpg") { |
|
| 1176 | - |
|
| 1177 | - $jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND); |
|
| 1178 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1179 | - if (!($s = @filesize($vignette))) { |
|
| 1180 | - spip_unlink($vignette); |
|
| 1181 | - } |
|
| 1182 | - if (!@file_exists($vignette)) { |
|
| 1183 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1184 | - |
|
| 1185 | - return; |
|
| 1186 | - } |
|
| 1187 | - } else { |
|
| 1188 | - if ($format == "gif") { |
|
| 1189 | - $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND); |
|
| 1190 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1191 | - if (!($s = @filesize($vignette))) { |
|
| 1192 | - spip_unlink($vignette); |
|
| 1193 | - } |
|
| 1194 | - if (!@file_exists($vignette)) { |
|
| 1195 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1196 | - |
|
| 1197 | - return; |
|
| 1198 | - } |
|
| 1199 | - } else { |
|
| 1200 | - if ($format == "png") { |
|
| 1201 | - $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND); |
|
| 1202 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1203 | - if (!($s = @filesize($vignette))) { |
|
| 1204 | - spip_unlink($vignette); |
|
| 1205 | - } |
|
| 1206 | - if (!@file_exists($vignette)) { |
|
| 1207 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1208 | - |
|
| 1209 | - return; |
|
| 1210 | - } |
|
| 1211 | - } |
|
| 1212 | - } |
|
| 1213 | - } |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - // gd ou gd2 |
|
| 1217 | - elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1218 | - if (!function_exists('gd_info')) { |
|
| 1219 | - spip_log("Librairie GD absente !", _LOG_ERREUR); |
|
| 1220 | - |
|
| 1221 | - return; |
|
| 1222 | - } |
|
| 1223 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1224 | - spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels"); |
|
| 1225 | - |
|
| 1226 | - return; |
|
| 1227 | - } |
|
| 1228 | - $destFormat = $format_sortie; |
|
| 1229 | - if (!$destFormat) { |
|
| 1230 | - spip_log("pas de format pour $image"); |
|
| 1231 | - |
|
| 1232 | - return; |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1236 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1237 | - return ''; |
|
| 1238 | - } |
|
| 1239 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1240 | - if (!$srcImage) { |
|
| 1241 | - spip_log("echec gd1/gd2"); |
|
| 1242 | - |
|
| 1243 | - return; |
|
| 1244 | - } |
|
| 1245 | - |
|
| 1246 | - // Initialisation de l'image destination |
|
| 1247 | - $destImage = null; |
|
| 1248 | - if ($process == 'gd2' and $destFormat != "gif") { |
|
| 1249 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1250 | - } |
|
| 1251 | - if (!$destImage) { |
|
| 1252 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1253 | - } |
|
| 1254 | - |
|
| 1255 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1256 | - $ok = false; |
|
| 1257 | - if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1258 | - if ($format == "gif") { |
|
| 1259 | - // Si un GIF est transparent, |
|
| 1260 | - // fabriquer un PNG transparent |
|
| 1261 | - $transp = imagecolortransparent($srcImage); |
|
| 1262 | - if ($transp > 0) { |
|
| 1263 | - $destFormat = "png"; |
|
| 1264 | - } |
|
| 1265 | - } |
|
| 1266 | - if ($destFormat == "png") { |
|
| 1267 | - // Conserver la transparence |
|
| 1268 | - if (function_exists("imageAntiAlias")) { |
|
| 1269 | - imageAntiAlias($destImage, true); |
|
| 1270 | - } |
|
| 1271 | - @imagealphablending($destImage, false); |
|
| 1272 | - @imagesavealpha($destImage, true); |
|
| 1273 | - } |
|
| 1274 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1275 | - } |
|
| 1276 | - if (!$ok) { |
|
| 1277 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - // Sauvegarde de l'image destination |
|
| 1281 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1282 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1283 | - _image_gd_output($destImage, $valeurs); |
|
| 1284 | - |
|
| 1285 | - if ($srcImage) { |
|
| 1286 | - ImageDestroy($srcImage); |
|
| 1287 | - } |
|
| 1288 | - ImageDestroy($destImage); |
|
| 1289 | - } |
|
| 1290 | - |
|
| 1291 | - if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1292 | - $size = array($destWidth, $destHeight); |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1296 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1297 | - if ($size[0] < 1) { |
|
| 1298 | - $size[0] = $destWidth; |
|
| 1299 | - } |
|
| 1300 | - if ($size[1] < 1) { |
|
| 1301 | - $size[1] = $destHeight; |
|
| 1302 | - } |
|
| 1303 | - |
|
| 1304 | - $retour['width'] = $largeur = $size[0]; |
|
| 1305 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1306 | - |
|
| 1307 | - $retour['fichier'] = $vignette; |
|
| 1308 | - $retour['format'] = $format; |
|
| 1309 | - $retour['date'] = @filemtime($vignette); |
|
| 1310 | - |
|
| 1311 | - // renvoyer l'image |
|
| 1312 | - return $retour; |
|
| 1066 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1067 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1068 | + $image = $valeurs['fichier']; |
|
| 1069 | + $format = $valeurs['format_source']; |
|
| 1070 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1071 | + $destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]); |
|
| 1072 | + |
|
| 1073 | + $format_sortie = $valeurs['format_dest']; |
|
| 1074 | + |
|
| 1075 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1076 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + // si le doc n'est pas une image, refuser |
|
| 1080 | + if (!$force and !in_array($format, formats_image_acceptables())) { |
|
| 1081 | + return; |
|
| 1082 | + } |
|
| 1083 | + $destination = "$destdir/$destfile"; |
|
| 1084 | + |
|
| 1085 | + // calculer la taille |
|
| 1086 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1087 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1088 | + list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight); |
|
| 1089 | + } |
|
| 1090 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1091 | + $destWidth = $maxWidth; |
|
| 1092 | + $destHeight = $maxHeight; |
|
| 1093 | + } else { |
|
| 1094 | + spip_log("echec $process sur $image"); |
|
| 1095 | + |
|
| 1096 | + return; |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + $vignette = ''; |
|
| 1100 | + |
|
| 1101 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1102 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1103 | + $vignette = $destination . '.' . $format; |
|
| 1104 | + @copy($image, $vignette); |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + elseif ($valeurs["format_source"] === 'svg') { |
|
| 1108 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)){ |
|
| 1109 | + $format_sortie = 'svg'; |
|
| 1110 | + $vignette = $destination . "." . $format_sortie; |
|
| 1111 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1112 | + _image_gd_output($svg, $valeurs); |
|
| 1113 | + } |
|
| 1114 | + } |
|
| 1115 | + |
|
| 1116 | + // imagemagick en ligne de commande |
|
| 1117 | + elseif ($process == 'convert') { |
|
| 1118 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1119 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1120 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1121 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1122 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1123 | + } |
|
| 1124 | + $vignette = $destination . "." . $format_sortie; |
|
| 1125 | + $commande = str_replace( |
|
| 1126 | + array('%x', '%y', '%src', '%dest'), |
|
| 1127 | + array( |
|
| 1128 | + $destWidth, |
|
| 1129 | + $destHeight, |
|
| 1130 | + escapeshellcmd($image), |
|
| 1131 | + escapeshellcmd($vignette) |
|
| 1132 | + ), |
|
| 1133 | + _RESIZE_COMMAND); |
|
| 1134 | + spip_log($commande); |
|
| 1135 | + exec($commande); |
|
| 1136 | + if (!@file_exists($vignette)) { |
|
| 1137 | + spip_log("echec convert sur $vignette"); |
|
| 1138 | + |
|
| 1139 | + return; // echec commande |
|
| 1140 | + } |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + // php5 imagemagick |
|
| 1144 | + elseif ($process == 'imagick') { |
|
| 1145 | + $vignette = "$destination." . $format_sortie; |
|
| 1146 | + |
|
| 1147 | + if (!class_exists('Imagick')) { |
|
| 1148 | + spip_log("Classe Imagick absente !", _LOG_ERREUR); |
|
| 1149 | + |
|
| 1150 | + return; |
|
| 1151 | + } |
|
| 1152 | + $imagick = new Imagick(); |
|
| 1153 | + $imagick->readImage($image); |
|
| 1154 | + $imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS, |
|
| 1155 | + 1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1156 | + $imagick->writeImage($vignette); |
|
| 1157 | + |
|
| 1158 | + if (!@file_exists($vignette)) { |
|
| 1159 | + spip_log("echec imagick sur $vignette"); |
|
| 1160 | + |
|
| 1161 | + return; |
|
| 1162 | + } |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + // netpbm |
|
| 1166 | + elseif ($process == "netpbm") { |
|
| 1167 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1168 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1169 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1170 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1171 | + return; |
|
| 1172 | + } |
|
| 1173 | + $vignette = $destination . "." . $format_sortie; |
|
| 1174 | + $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND); |
|
| 1175 | + if ($format == "jpg") { |
|
| 1176 | + |
|
| 1177 | + $jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND); |
|
| 1178 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1179 | + if (!($s = @filesize($vignette))) { |
|
| 1180 | + spip_unlink($vignette); |
|
| 1181 | + } |
|
| 1182 | + if (!@file_exists($vignette)) { |
|
| 1183 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1184 | + |
|
| 1185 | + return; |
|
| 1186 | + } |
|
| 1187 | + } else { |
|
| 1188 | + if ($format == "gif") { |
|
| 1189 | + $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND); |
|
| 1190 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1191 | + if (!($s = @filesize($vignette))) { |
|
| 1192 | + spip_unlink($vignette); |
|
| 1193 | + } |
|
| 1194 | + if (!@file_exists($vignette)) { |
|
| 1195 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1196 | + |
|
| 1197 | + return; |
|
| 1198 | + } |
|
| 1199 | + } else { |
|
| 1200 | + if ($format == "png") { |
|
| 1201 | + $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND); |
|
| 1202 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1203 | + if (!($s = @filesize($vignette))) { |
|
| 1204 | + spip_unlink($vignette); |
|
| 1205 | + } |
|
| 1206 | + if (!@file_exists($vignette)) { |
|
| 1207 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1208 | + |
|
| 1209 | + return; |
|
| 1210 | + } |
|
| 1211 | + } |
|
| 1212 | + } |
|
| 1213 | + } |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + // gd ou gd2 |
|
| 1217 | + elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1218 | + if (!function_exists('gd_info')) { |
|
| 1219 | + spip_log("Librairie GD absente !", _LOG_ERREUR); |
|
| 1220 | + |
|
| 1221 | + return; |
|
| 1222 | + } |
|
| 1223 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1224 | + spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels"); |
|
| 1225 | + |
|
| 1226 | + return; |
|
| 1227 | + } |
|
| 1228 | + $destFormat = $format_sortie; |
|
| 1229 | + if (!$destFormat) { |
|
| 1230 | + spip_log("pas de format pour $image"); |
|
| 1231 | + |
|
| 1232 | + return; |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1236 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1237 | + return ''; |
|
| 1238 | + } |
|
| 1239 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1240 | + if (!$srcImage) { |
|
| 1241 | + spip_log("echec gd1/gd2"); |
|
| 1242 | + |
|
| 1243 | + return; |
|
| 1244 | + } |
|
| 1245 | + |
|
| 1246 | + // Initialisation de l'image destination |
|
| 1247 | + $destImage = null; |
|
| 1248 | + if ($process == 'gd2' and $destFormat != "gif") { |
|
| 1249 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1250 | + } |
|
| 1251 | + if (!$destImage) { |
|
| 1252 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1253 | + } |
|
| 1254 | + |
|
| 1255 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1256 | + $ok = false; |
|
| 1257 | + if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1258 | + if ($format == "gif") { |
|
| 1259 | + // Si un GIF est transparent, |
|
| 1260 | + // fabriquer un PNG transparent |
|
| 1261 | + $transp = imagecolortransparent($srcImage); |
|
| 1262 | + if ($transp > 0) { |
|
| 1263 | + $destFormat = "png"; |
|
| 1264 | + } |
|
| 1265 | + } |
|
| 1266 | + if ($destFormat == "png") { |
|
| 1267 | + // Conserver la transparence |
|
| 1268 | + if (function_exists("imageAntiAlias")) { |
|
| 1269 | + imageAntiAlias($destImage, true); |
|
| 1270 | + } |
|
| 1271 | + @imagealphablending($destImage, false); |
|
| 1272 | + @imagesavealpha($destImage, true); |
|
| 1273 | + } |
|
| 1274 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1275 | + } |
|
| 1276 | + if (!$ok) { |
|
| 1277 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + // Sauvegarde de l'image destination |
|
| 1281 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1282 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1283 | + _image_gd_output($destImage, $valeurs); |
|
| 1284 | + |
|
| 1285 | + if ($srcImage) { |
|
| 1286 | + ImageDestroy($srcImage); |
|
| 1287 | + } |
|
| 1288 | + ImageDestroy($destImage); |
|
| 1289 | + } |
|
| 1290 | + |
|
| 1291 | + if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1292 | + $size = array($destWidth, $destHeight); |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1296 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1297 | + if ($size[0] < 1) { |
|
| 1298 | + $size[0] = $destWidth; |
|
| 1299 | + } |
|
| 1300 | + if ($size[1] < 1) { |
|
| 1301 | + $size[1] = $destHeight; |
|
| 1302 | + } |
|
| 1303 | + |
|
| 1304 | + $retour['width'] = $largeur = $size[0]; |
|
| 1305 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1306 | + |
|
| 1307 | + $retour['fichier'] = $vignette; |
|
| 1308 | + $retour['format'] = $format; |
|
| 1309 | + $retour['date'] = @filemtime($vignette); |
|
| 1310 | + |
|
| 1311 | + // renvoyer l'image |
|
| 1312 | + return $retour; |
|
| 1313 | 1313 | } |
| 1314 | 1314 | |
| 1315 | 1315 | /** |
@@ -1329,25 +1329,25 @@ discard block |
||
| 1329 | 1329 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1330 | 1330 | **/ |
| 1331 | 1331 | function _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight) { |
| 1332 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1333 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1334 | - |
|
| 1335 | - if ($ratioWidth <= 1 and $ratioHeight <= 1) { |
|
| 1336 | - $destWidth = $srcWidth; |
|
| 1337 | - $destHeight = $srcHeight; |
|
| 1338 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1339 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1340 | - $destHeight = $maxHeight; |
|
| 1341 | - } else { |
|
| 1342 | - $destWidth = $maxWidth; |
|
| 1343 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - return array( |
|
| 1347 | - ceil($destWidth), |
|
| 1348 | - ceil($destHeight), |
|
| 1349 | - max($ratioWidth, $ratioHeight) |
|
| 1350 | - ); |
|
| 1332 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1333 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1334 | + |
|
| 1335 | + if ($ratioWidth <= 1 and $ratioHeight <= 1) { |
|
| 1336 | + $destWidth = $srcWidth; |
|
| 1337 | + $destHeight = $srcHeight; |
|
| 1338 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1339 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1340 | + $destHeight = $maxHeight; |
|
| 1341 | + } else { |
|
| 1342 | + $destWidth = $maxWidth; |
|
| 1343 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + return array( |
|
| 1347 | + ceil($destWidth), |
|
| 1348 | + ceil($destHeight), |
|
| 1349 | + max($ratioWidth, $ratioHeight) |
|
| 1350 | + ); |
|
| 1351 | 1351 | } |
| 1352 | 1352 | |
| 1353 | 1353 | /** |
@@ -1367,25 +1367,25 @@ discard block |
||
| 1367 | 1367 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1368 | 1368 | **/ |
| 1369 | 1369 | function ratio_passe_partout($srcWidth, $srcHeight, $maxWidth, $maxHeight) { |
| 1370 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1371 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1372 | - |
|
| 1373 | - if ($ratioWidth <= 1 and $ratioHeight <= 1) { |
|
| 1374 | - $destWidth = $srcWidth; |
|
| 1375 | - $destHeight = $srcHeight; |
|
| 1376 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1377 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1378 | - $destHeight = $maxHeight; |
|
| 1379 | - } else { |
|
| 1380 | - $destWidth = $maxWidth; |
|
| 1381 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1382 | - } |
|
| 1383 | - |
|
| 1384 | - return array( |
|
| 1385 | - ceil($destWidth), |
|
| 1386 | - ceil($destHeight), |
|
| 1387 | - min($ratioWidth, $ratioHeight) |
|
| 1388 | - ); |
|
| 1370 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1371 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1372 | + |
|
| 1373 | + if ($ratioWidth <= 1 and $ratioHeight <= 1) { |
|
| 1374 | + $destWidth = $srcWidth; |
|
| 1375 | + $destHeight = $srcHeight; |
|
| 1376 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1377 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1378 | + $destHeight = $maxHeight; |
|
| 1379 | + } else { |
|
| 1380 | + $destWidth = $maxWidth; |
|
| 1381 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1382 | + } |
|
| 1383 | + |
|
| 1384 | + return array( |
|
| 1385 | + ceil($destWidth), |
|
| 1386 | + ceil($destHeight), |
|
| 1387 | + min($ratioWidth, $ratioHeight) |
|
| 1388 | + ); |
|
| 1389 | 1389 | } |
| 1390 | 1390 | |
| 1391 | 1391 | |
@@ -1398,12 +1398,12 @@ discard block |
||
| 1398 | 1398 | * @return string |
| 1399 | 1399 | */ |
| 1400 | 1400 | function process_image_svg_identite($image) { |
| 1401 | - if ($image['creer']) { |
|
| 1402 | - $source = $image['fichier']; |
|
| 1403 | - _image_gd_output($source, $image); |
|
| 1404 | - } |
|
| 1401 | + if ($image['creer']) { |
|
| 1402 | + $source = $image['fichier']; |
|
| 1403 | + _image_gd_output($source, $image); |
|
| 1404 | + } |
|
| 1405 | 1405 | |
| 1406 | - return _image_ecrire_tag($image, array('src' => $image['fichier_dest'])); |
|
| 1406 | + return _image_ecrire_tag($image, array('src' => $image['fichier_dest'])); |
|
| 1407 | 1407 | } |
| 1408 | 1408 | |
| 1409 | 1409 | |
@@ -1436,107 +1436,107 @@ discard block |
||
| 1436 | 1436 | * Code HTML de la balise img produite |
| 1437 | 1437 | **/ |
| 1438 | 1438 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1439 | - $image = false; |
|
| 1440 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1441 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1442 | - } |
|
| 1443 | - # determiner le format de sortie |
|
| 1444 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1445 | - if ($process == "netpbm") { |
|
| 1446 | - $format_sortie = "jpg"; |
|
| 1447 | - } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1448 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1449 | - |
|
| 1450 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1451 | - $gd_formats = formats_image_acceptables(true); |
|
| 1452 | - if (is_array($image) |
|
| 1453 | - and (!in_array($image['format_dest'], $gd_formats) |
|
| 1454 | - or ($image['format_dest'] == 'gif' and !function_exists('ImageGif')) |
|
| 1455 | - ) |
|
| 1456 | - ) { |
|
| 1457 | - if ($image['format_source'] == 'jpg') { |
|
| 1458 | - $formats_sortie = array('jpg', 'png', 'gif'); |
|
| 1459 | - } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1460 | - { |
|
| 1461 | - $formats_sortie = array('png', 'jpg', 'gif'); |
|
| 1462 | - } |
|
| 1463 | - // Choisir le format destination |
|
| 1464 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1465 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1466 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1467 | - # pas *ecrire* |
|
| 1468 | - $format_sortie = ""; |
|
| 1469 | - foreach ($formats_sortie as $fmt) { |
|
| 1470 | - if (in_array($fmt, $gd_formats)) { |
|
| 1471 | - if ($fmt <> "gif" or function_exists('ImageGif')) { |
|
| 1472 | - $format_sortie = $fmt; |
|
| 1473 | - } |
|
| 1474 | - break; |
|
| 1475 | - } |
|
| 1476 | - } |
|
| 1477 | - $image = false; |
|
| 1478 | - } |
|
| 1479 | - } |
|
| 1480 | - |
|
| 1481 | - if (!is_array($image)) { |
|
| 1482 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1486 | - spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1487 | - // on peut resizer en mode html si on dispose des elements |
|
| 1488 | - if ($srcw = extraire_attribut($img, 'width') |
|
| 1489 | - and $srch = extraire_attribut($img, 'height') |
|
| 1490 | - ) { |
|
| 1491 | - list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1492 | - |
|
| 1493 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1494 | - } |
|
| 1495 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1496 | - // sous la forme style='max-width: NNpx;' |
|
| 1497 | - return inserer_attribut($img, 'style', |
|
| 1498 | - "max-width: ${taille}px; max-height: ${taille_y}px"); |
|
| 1499 | - } |
|
| 1500 | - |
|
| 1501 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1502 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1503 | - if ($image['creer']) { |
|
| 1504 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1505 | - } |
|
| 1506 | - |
|
| 1507 | - return _image_ecrire_tag($image, array('src' => $image['fichier_dest'])); |
|
| 1508 | - } |
|
| 1509 | - |
|
| 1510 | - if ($image['creer'] == false && !$force) { |
|
| 1511 | - return _image_ecrire_tag($image, |
|
| 1512 | - array('src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest'])); |
|
| 1513 | - } |
|
| 1514 | - |
|
| 1515 | - if (in_array($image["format_source"], formats_image_acceptables())) { |
|
| 1516 | - $destWidth = $image['largeur_dest']; |
|
| 1517 | - $destHeight = $image['hauteur_dest']; |
|
| 1518 | - $logo = $image['fichier']; |
|
| 1519 | - $date = $image["date_src"]; |
|
| 1520 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1521 | - |
|
| 1522 | - if ($preview && $preview['fichier']) { |
|
| 1523 | - $logo = $preview['fichier']; |
|
| 1524 | - $destWidth = $preview['width']; |
|
| 1525 | - $destHeight = $preview['height']; |
|
| 1526 | - $date = $preview['date']; |
|
| 1527 | - } |
|
| 1528 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1529 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1530 | - // quand on fait supprimer/reuploader un logo |
|
| 1531 | - // (pas de filemtime si SAFE MODE) |
|
| 1532 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1533 | - |
|
| 1534 | - return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight)); |
|
| 1535 | - } |
|
| 1536 | - else { |
|
| 1537 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1538 | - return $img; |
|
| 1539 | - } |
|
| 1439 | + $image = false; |
|
| 1440 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1441 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1442 | + } |
|
| 1443 | + # determiner le format de sortie |
|
| 1444 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1445 | + if ($process == "netpbm") { |
|
| 1446 | + $format_sortie = "jpg"; |
|
| 1447 | + } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1448 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1449 | + |
|
| 1450 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1451 | + $gd_formats = formats_image_acceptables(true); |
|
| 1452 | + if (is_array($image) |
|
| 1453 | + and (!in_array($image['format_dest'], $gd_formats) |
|
| 1454 | + or ($image['format_dest'] == 'gif' and !function_exists('ImageGif')) |
|
| 1455 | + ) |
|
| 1456 | + ) { |
|
| 1457 | + if ($image['format_source'] == 'jpg') { |
|
| 1458 | + $formats_sortie = array('jpg', 'png', 'gif'); |
|
| 1459 | + } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1460 | + { |
|
| 1461 | + $formats_sortie = array('png', 'jpg', 'gif'); |
|
| 1462 | + } |
|
| 1463 | + // Choisir le format destination |
|
| 1464 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1465 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1466 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1467 | + # pas *ecrire* |
|
| 1468 | + $format_sortie = ""; |
|
| 1469 | + foreach ($formats_sortie as $fmt) { |
|
| 1470 | + if (in_array($fmt, $gd_formats)) { |
|
| 1471 | + if ($fmt <> "gif" or function_exists('ImageGif')) { |
|
| 1472 | + $format_sortie = $fmt; |
|
| 1473 | + } |
|
| 1474 | + break; |
|
| 1475 | + } |
|
| 1476 | + } |
|
| 1477 | + $image = false; |
|
| 1478 | + } |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + if (!is_array($image)) { |
|
| 1482 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1486 | + spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1487 | + // on peut resizer en mode html si on dispose des elements |
|
| 1488 | + if ($srcw = extraire_attribut($img, 'width') |
|
| 1489 | + and $srch = extraire_attribut($img, 'height') |
|
| 1490 | + ) { |
|
| 1491 | + list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1492 | + |
|
| 1493 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1494 | + } |
|
| 1495 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1496 | + // sous la forme style='max-width: NNpx;' |
|
| 1497 | + return inserer_attribut($img, 'style', |
|
| 1498 | + "max-width: ${taille}px; max-height: ${taille_y}px"); |
|
| 1499 | + } |
|
| 1500 | + |
|
| 1501 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1502 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1503 | + if ($image['creer']) { |
|
| 1504 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1505 | + } |
|
| 1506 | + |
|
| 1507 | + return _image_ecrire_tag($image, array('src' => $image['fichier_dest'])); |
|
| 1508 | + } |
|
| 1509 | + |
|
| 1510 | + if ($image['creer'] == false && !$force) { |
|
| 1511 | + return _image_ecrire_tag($image, |
|
| 1512 | + array('src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest'])); |
|
| 1513 | + } |
|
| 1514 | + |
|
| 1515 | + if (in_array($image["format_source"], formats_image_acceptables())) { |
|
| 1516 | + $destWidth = $image['largeur_dest']; |
|
| 1517 | + $destHeight = $image['hauteur_dest']; |
|
| 1518 | + $logo = $image['fichier']; |
|
| 1519 | + $date = $image["date_src"]; |
|
| 1520 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1521 | + |
|
| 1522 | + if ($preview && $preview['fichier']) { |
|
| 1523 | + $logo = $preview['fichier']; |
|
| 1524 | + $destWidth = $preview['width']; |
|
| 1525 | + $destHeight = $preview['height']; |
|
| 1526 | + $date = $preview['date']; |
|
| 1527 | + } |
|
| 1528 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1529 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1530 | + // quand on fait supprimer/reuploader un logo |
|
| 1531 | + // (pas de filemtime si SAFE MODE) |
|
| 1532 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1533 | + |
|
| 1534 | + return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight)); |
|
| 1535 | + } |
|
| 1536 | + else { |
|
| 1537 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1538 | + return $img; |
|
| 1539 | + } |
|
| 1540 | 1540 | } |
| 1541 | 1541 | |
| 1542 | 1542 | /** |
@@ -1551,145 +1551,145 @@ discard block |
||
| 1551 | 1551 | */ |
| 1552 | 1552 | class phpthumb_functions { |
| 1553 | 1553 | |
| 1554 | - /** |
|
| 1555 | - * Retourne la couleur d'un pixel dans une image |
|
| 1556 | - * |
|
| 1557 | - * @param ressource $img |
|
| 1558 | - * @param int $x |
|
| 1559 | - * @param int $y |
|
| 1560 | - * @return array|bool |
|
| 1561 | - */ |
|
| 1562 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1563 | - if (!is_resource($img)) { |
|
| 1564 | - return false; |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1568 | - } |
|
| 1569 | - |
|
| 1570 | - /** |
|
| 1571 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1572 | - * |
|
| 1573 | - * @param int $number |
|
| 1574 | - * @param int $minbytes |
|
| 1575 | - * @return string |
|
| 1576 | - */ |
|
| 1577 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1578 | - $intstring = ''; |
|
| 1579 | - while ($number > 0) { |
|
| 1580 | - $intstring = $intstring . chr($number & 255); |
|
| 1581 | - $number >>= 8; |
|
| 1582 | - } |
|
| 1583 | - |
|
| 1584 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - /** |
|
| 1588 | - * Transforme une ressource GD en image au format ICO |
|
| 1589 | - * |
|
| 1590 | - * @param array $gd_image_array |
|
| 1591 | - * Tableau de ressources d'images GD |
|
| 1592 | - * @return string |
|
| 1593 | - * Image au format ICO |
|
| 1594 | - */ |
|
| 1595 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1596 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1597 | - |
|
| 1598 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1599 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1600 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1601 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1602 | - |
|
| 1603 | - $icXOR[$key] = ''; |
|
| 1604 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1605 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1606 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1607 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1608 | - $r = $argb['red']; |
|
| 1609 | - $g = $argb['green']; |
|
| 1610 | - $b = $argb['blue']; |
|
| 1611 | - |
|
| 1612 | - if ($bpp[$key] == 32) { |
|
| 1613 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1614 | - } elseif ($bpp[$key] == 24) { |
|
| 1615 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1616 | - } |
|
| 1617 | - |
|
| 1618 | - if ($a < 128) { |
|
| 1619 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1620 | - } else { |
|
| 1621 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1622 | - } |
|
| 1623 | - } |
|
| 1624 | - // mask bits are 32-bit aligned per scanline |
|
| 1625 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1626 | - $icANDmask[$key][$y] .= '0'; |
|
| 1627 | - } |
|
| 1628 | - } |
|
| 1629 | - $icAND[$key] = ''; |
|
| 1630 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1631 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1632 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1633 | - } |
|
| 1634 | - } |
|
| 1635 | - |
|
| 1636 | - } |
|
| 1637 | - |
|
| 1638 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1639 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1640 | - |
|
| 1641 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1642 | - $BitmapInfoHeader[$key] = ''; |
|
| 1643 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1644 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1645 | - // The biHeight member specifies the combined |
|
| 1646 | - // height of the XOR and AND masks. |
|
| 1647 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1648 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1649 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1650 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1651 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1652 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1653 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1654 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1655 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1656 | - } |
|
| 1657 | - |
|
| 1658 | - |
|
| 1659 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1660 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1661 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1662 | - |
|
| 1663 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1664 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1665 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1666 | - |
|
| 1667 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1668 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1669 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1670 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1671 | - |
|
| 1672 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1673 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1674 | - |
|
| 1675 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1676 | - $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, |
|
| 1677 | - 4); // dwBytesInRes; // How many bytes in this resource? |
|
| 1678 | - |
|
| 1679 | - $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, |
|
| 1680 | - 4); // dwImageOffset; // Where in the file is this image? |
|
| 1681 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1682 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 1683 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 1684 | - } |
|
| 1685 | - |
|
| 1686 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1687 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 1688 | - $icondata .= $icXOR[$key]; |
|
| 1689 | - $icondata .= $icAND[$key]; |
|
| 1690 | - } |
|
| 1691 | - |
|
| 1692 | - return $icondata; |
|
| 1693 | - } |
|
| 1554 | + /** |
|
| 1555 | + * Retourne la couleur d'un pixel dans une image |
|
| 1556 | + * |
|
| 1557 | + * @param ressource $img |
|
| 1558 | + * @param int $x |
|
| 1559 | + * @param int $y |
|
| 1560 | + * @return array|bool |
|
| 1561 | + */ |
|
| 1562 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1563 | + if (!is_resource($img)) { |
|
| 1564 | + return false; |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1568 | + } |
|
| 1569 | + |
|
| 1570 | + /** |
|
| 1571 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1572 | + * |
|
| 1573 | + * @param int $number |
|
| 1574 | + * @param int $minbytes |
|
| 1575 | + * @return string |
|
| 1576 | + */ |
|
| 1577 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1578 | + $intstring = ''; |
|
| 1579 | + while ($number > 0) { |
|
| 1580 | + $intstring = $intstring . chr($number & 255); |
|
| 1581 | + $number >>= 8; |
|
| 1582 | + } |
|
| 1583 | + |
|
| 1584 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + /** |
|
| 1588 | + * Transforme une ressource GD en image au format ICO |
|
| 1589 | + * |
|
| 1590 | + * @param array $gd_image_array |
|
| 1591 | + * Tableau de ressources d'images GD |
|
| 1592 | + * @return string |
|
| 1593 | + * Image au format ICO |
|
| 1594 | + */ |
|
| 1595 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1596 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1597 | + |
|
| 1598 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1599 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1600 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1601 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1602 | + |
|
| 1603 | + $icXOR[$key] = ''; |
|
| 1604 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1605 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1606 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1607 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1608 | + $r = $argb['red']; |
|
| 1609 | + $g = $argb['green']; |
|
| 1610 | + $b = $argb['blue']; |
|
| 1611 | + |
|
| 1612 | + if ($bpp[$key] == 32) { |
|
| 1613 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1614 | + } elseif ($bpp[$key] == 24) { |
|
| 1615 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1616 | + } |
|
| 1617 | + |
|
| 1618 | + if ($a < 128) { |
|
| 1619 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1620 | + } else { |
|
| 1621 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1622 | + } |
|
| 1623 | + } |
|
| 1624 | + // mask bits are 32-bit aligned per scanline |
|
| 1625 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1626 | + $icANDmask[$key][$y] .= '0'; |
|
| 1627 | + } |
|
| 1628 | + } |
|
| 1629 | + $icAND[$key] = ''; |
|
| 1630 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1631 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1632 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1633 | + } |
|
| 1634 | + } |
|
| 1635 | + |
|
| 1636 | + } |
|
| 1637 | + |
|
| 1638 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1639 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1640 | + |
|
| 1641 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1642 | + $BitmapInfoHeader[$key] = ''; |
|
| 1643 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1644 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1645 | + // The biHeight member specifies the combined |
|
| 1646 | + // height of the XOR and AND masks. |
|
| 1647 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1648 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1649 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1650 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1651 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1652 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1653 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1654 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1655 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1656 | + } |
|
| 1657 | + |
|
| 1658 | + |
|
| 1659 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1660 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1661 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1662 | + |
|
| 1663 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1664 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1665 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1666 | + |
|
| 1667 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1668 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1669 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1670 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1671 | + |
|
| 1672 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1673 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1674 | + |
|
| 1675 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1676 | + $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, |
|
| 1677 | + 4); // dwBytesInRes; // How many bytes in this resource? |
|
| 1678 | + |
|
| 1679 | + $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, |
|
| 1680 | + 4); // dwImageOffset; // Where in the file is this image? |
|
| 1681 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1682 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 1683 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 1684 | + } |
|
| 1685 | + |
|
| 1686 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1687 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 1688 | + $icondata .= $icXOR[$key]; |
|
| 1689 | + $icondata .= $icAND[$key]; |
|
| 1690 | + } |
|
| 1691 | + |
|
| 1692 | + return $icondata; |
|
| 1693 | + } |
|
| 1694 | 1694 | |
| 1695 | 1695 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** l'adresse du repertoire de telechargement et de decompactage des plugins */ |
| 24 | 24 | if (!defined('_DIR_PLUGINS_AUTO')) { |
| 25 | - define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 25 | + define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins. |
@@ -47,26 +47,26 @@ discard block |
||
| 47 | 47 | * @return array |
| 48 | 48 | **/ |
| 49 | 49 | function liste_plugin_files($dir_plugins = null) { |
| 50 | - static $plugin_files = array(); |
|
| 51 | - if (is_null($dir_plugins)) { |
|
| 52 | - $dir_plugins = _DIR_PLUGINS; |
|
| 53 | - } |
|
| 54 | - if (!isset($plugin_files[$dir_plugins]) |
|
| 55 | - or count($plugin_files[$dir_plugins]) == 0 |
|
| 56 | - ) { |
|
| 57 | - $plugin_files[$dir_plugins] = array(); |
|
| 58 | - foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 59 | - $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - sort($plugin_files[$dir_plugins]); |
|
| 63 | - // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 64 | - // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 65 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 66 | - $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - return $plugin_files[$dir_plugins]; |
|
| 50 | + static $plugin_files = array(); |
|
| 51 | + if (is_null($dir_plugins)) { |
|
| 52 | + $dir_plugins = _DIR_PLUGINS; |
|
| 53 | + } |
|
| 54 | + if (!isset($plugin_files[$dir_plugins]) |
|
| 55 | + or count($plugin_files[$dir_plugins]) == 0 |
|
| 56 | + ) { |
|
| 57 | + $plugin_files[$dir_plugins] = array(); |
|
| 58 | + foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 59 | + $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + sort($plugin_files[$dir_plugins]); |
|
| 63 | + // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 64 | + // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 65 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 66 | + $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + return $plugin_files[$dir_plugins]; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -82,44 +82,44 @@ discard block |
||
| 82 | 82 | * Liste complète des répeertoires |
| 83 | 83 | **/ |
| 84 | 84 | function fast_find_plugin_dirs($dir, $max_prof = 100) { |
| 85 | - $fichiers = array(); |
|
| 86 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 87 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 88 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 89 | - if ($dir == '') { |
|
| 90 | - $dir = '.'; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - if (!is_dir($dir)) { |
|
| 94 | - return $fichiers; |
|
| 95 | - } |
|
| 96 | - if (is_plugin_dir($dir, '')) { |
|
| 97 | - $fichiers[] = $dir; |
|
| 98 | - |
|
| 99 | - return $fichiers; |
|
| 100 | - } |
|
| 101 | - if ($max_prof <= 0) { |
|
| 102 | - return $fichiers; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $subdirs = array(); |
|
| 106 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 107 | - while (($f = readdir($d)) !== false) { |
|
| 108 | - if ($f[0] != '.' # ignorer . .. .svn etc |
|
| 109 | - and $f != 'CVS' |
|
| 110 | - and is_dir($f = "$dir/$f") |
|
| 111 | - ) { |
|
| 112 | - $subdirs[] = $f; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - closedir($d); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - foreach ($subdirs as $d) { |
|
| 119 | - $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return $fichiers; |
|
| 85 | + $fichiers = array(); |
|
| 86 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 87 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 88 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 89 | + if ($dir == '') { |
|
| 90 | + $dir = '.'; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + if (!is_dir($dir)) { |
|
| 94 | + return $fichiers; |
|
| 95 | + } |
|
| 96 | + if (is_plugin_dir($dir, '')) { |
|
| 97 | + $fichiers[] = $dir; |
|
| 98 | + |
|
| 99 | + return $fichiers; |
|
| 100 | + } |
|
| 101 | + if ($max_prof <= 0) { |
|
| 102 | + return $fichiers; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $subdirs = array(); |
|
| 106 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 107 | + while (($f = readdir($d)) !== false) { |
|
| 108 | + if ($f[0] != '.' # ignorer . .. .svn etc |
|
| 109 | + and $f != 'CVS' |
|
| 110 | + and is_dir($f = "$dir/$f") |
|
| 111 | + ) { |
|
| 112 | + $subdirs[] = $f; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + closedir($d); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + foreach ($subdirs as $d) { |
|
| 119 | + $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return $fichiers; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -140,27 +140,27 @@ discard block |
||
| 140 | 140 | **/ |
| 141 | 141 | function is_plugin_dir($dir, $dir_plugins = null) { |
| 142 | 142 | |
| 143 | - if (is_array($dir)) { |
|
| 144 | - foreach ($dir as $k => $d) { |
|
| 145 | - if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 146 | - unset($dir[$k]); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $dir; |
|
| 151 | - } |
|
| 152 | - if (is_null($dir_plugins)) { |
|
| 153 | - $dir_plugins = _DIR_PLUGINS; |
|
| 154 | - } |
|
| 155 | - $search = array("$dir_plugins$dir/paquet.xml"); |
|
| 156 | - |
|
| 157 | - foreach ($search as $s) { |
|
| 158 | - if (file_exists($s)) { |
|
| 159 | - return $dir; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return ''; |
|
| 143 | + if (is_array($dir)) { |
|
| 144 | + foreach ($dir as $k => $d) { |
|
| 145 | + if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 146 | + unset($dir[$k]); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $dir; |
|
| 151 | + } |
|
| 152 | + if (is_null($dir_plugins)) { |
|
| 153 | + $dir_plugins = _DIR_PLUGINS; |
|
| 154 | + } |
|
| 155 | + $search = array("$dir_plugins$dir/paquet.xml"); |
|
| 156 | + |
|
| 157 | + foreach ($search as $s) { |
|
| 158 | + if (file_exists($s)) { |
|
| 159 | + return $dir; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return ''; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** Regexp d'extraction des informations d'un intervalle de compatibilité */ |
@@ -187,51 +187,51 @@ discard block |
||
| 187 | 187 | **/ |
| 188 | 188 | function plugin_version_compatible($intervalle, $version, $avec_quoi = '') { |
| 189 | 189 | |
| 190 | - if (!strlen($intervalle)) { |
|
| 191 | - return true; |
|
| 192 | - } |
|
| 193 | - if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 194 | - return false; |
|
| 195 | - } |
|
| 196 | - // Extraction des bornes et traitement de * pour la borne sup : |
|
| 197 | - // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 198 | - $minimum = $regs[1]; |
|
| 199 | - $maximum = $regs[2]; |
|
| 200 | - |
|
| 201 | - // si une version SPIP de compatibilité a été définie (dans |
|
| 202 | - // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 203 | - // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 204 | - // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 205 | - // entre plugins) |
|
| 206 | - if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 207 | - if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 208 | - return true; |
|
| 209 | - } |
|
| 210 | - // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 211 | - // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $minimum_inc = $intervalle[0] == "["; |
|
| 215 | - $maximum_inc = substr($intervalle, -1) == "]"; |
|
| 216 | - |
|
| 217 | - if (strlen($minimum)) { |
|
| 218 | - if ($minimum_inc and spip_version_compare($version, $minimum, '<')) { |
|
| 219 | - return false; |
|
| 220 | - } |
|
| 221 | - if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) { |
|
| 222 | - return false; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - if (strlen($maximum)) { |
|
| 226 | - if ($maximum_inc and spip_version_compare($version, $maximum, '>')) { |
|
| 227 | - return false; |
|
| 228 | - } |
|
| 229 | - if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) { |
|
| 230 | - return false; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - return true; |
|
| 190 | + if (!strlen($intervalle)) { |
|
| 191 | + return true; |
|
| 192 | + } |
|
| 193 | + if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + // Extraction des bornes et traitement de * pour la borne sup : |
|
| 197 | + // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 198 | + $minimum = $regs[1]; |
|
| 199 | + $maximum = $regs[2]; |
|
| 200 | + |
|
| 201 | + // si une version SPIP de compatibilité a été définie (dans |
|
| 202 | + // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 203 | + // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 204 | + // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 205 | + // entre plugins) |
|
| 206 | + if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 207 | + if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 208 | + return true; |
|
| 209 | + } |
|
| 210 | + // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 211 | + // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $minimum_inc = $intervalle[0] == "["; |
|
| 215 | + $maximum_inc = substr($intervalle, -1) == "]"; |
|
| 216 | + |
|
| 217 | + if (strlen($minimum)) { |
|
| 218 | + if ($minimum_inc and spip_version_compare($version, $minimum, '<')) { |
|
| 219 | + return false; |
|
| 220 | + } |
|
| 221 | + if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) { |
|
| 222 | + return false; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + if (strlen($maximum)) { |
|
| 226 | + if ($maximum_inc and spip_version_compare($version, $maximum, '>')) { |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | + if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) { |
|
| 230 | + return false; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + return true; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -248,62 +248,62 @@ discard block |
||
| 248 | 248 | * @return array |
| 249 | 249 | */ |
| 250 | 250 | function liste_plugin_valides($liste_plug, $force = false) { |
| 251 | - $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 252 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 253 | - $infos = array( |
|
| 254 | - // lister les extensions qui sont automatiquement actives |
|
| 255 | - '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 256 | - '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 257 | - ); |
|
| 258 | - |
|
| 259 | - // creer une premiere liste non ordonnee mais qui ne retient |
|
| 260 | - // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 261 | - $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 262 | - $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 263 | - $infos['_DIR_RESTREINT']['SPIP']['chemin'] = array(); |
|
| 264 | - $liste_non_classee = array( |
|
| 265 | - 'SPIP' => array( |
|
| 266 | - 'nom' => 'SPIP', |
|
| 267 | - 'etat' => 'stable', |
|
| 268 | - 'version' => $GLOBALS['spip_version_branche'], |
|
| 269 | - 'dir_type' => '_DIR_RESTREINT', |
|
| 270 | - 'dir' => '', |
|
| 271 | - ) |
|
| 272 | - ); |
|
| 273 | - |
|
| 274 | - $invalides = array(); |
|
| 275 | - foreach ($liste_ext as $plug) { |
|
| 276 | - if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 277 | - plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - foreach ($liste_plug as $plug) { |
|
| 281 | - if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 282 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 283 | - if (is_array($r)) { |
|
| 284 | - $invalides = array_merge($invalides, $r); |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) { |
|
| 290 | - $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 291 | - foreach ($liste_plug as $plug) { |
|
| 292 | - if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 293 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 294 | - if (is_array($r)) { |
|
| 295 | - $invalides = array_merge($invalides, $r); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - plugin_fixer_procure($liste_non_classee, $infos); |
|
| 302 | - |
|
| 303 | - // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 304 | - $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 305 | - |
|
| 306 | - return array($infos, $liste_non_classee, $invalides); |
|
| 251 | + $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 252 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 253 | + $infos = array( |
|
| 254 | + // lister les extensions qui sont automatiquement actives |
|
| 255 | + '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 256 | + '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 257 | + ); |
|
| 258 | + |
|
| 259 | + // creer une premiere liste non ordonnee mais qui ne retient |
|
| 260 | + // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 261 | + $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 262 | + $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 263 | + $infos['_DIR_RESTREINT']['SPIP']['chemin'] = array(); |
|
| 264 | + $liste_non_classee = array( |
|
| 265 | + 'SPIP' => array( |
|
| 266 | + 'nom' => 'SPIP', |
|
| 267 | + 'etat' => 'stable', |
|
| 268 | + 'version' => $GLOBALS['spip_version_branche'], |
|
| 269 | + 'dir_type' => '_DIR_RESTREINT', |
|
| 270 | + 'dir' => '', |
|
| 271 | + ) |
|
| 272 | + ); |
|
| 273 | + |
|
| 274 | + $invalides = array(); |
|
| 275 | + foreach ($liste_ext as $plug) { |
|
| 276 | + if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 277 | + plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + foreach ($liste_plug as $plug) { |
|
| 281 | + if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 282 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 283 | + if (is_array($r)) { |
|
| 284 | + $invalides = array_merge($invalides, $r); |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) { |
|
| 290 | + $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 291 | + foreach ($liste_plug as $plug) { |
|
| 292 | + if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 293 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 294 | + if (is_array($r)) { |
|
| 295 | + $invalides = array_merge($invalides, $r); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + plugin_fixer_procure($liste_non_classee, $infos); |
|
| 302 | + |
|
| 303 | + // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 304 | + $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 305 | + |
|
| 306 | + return array($infos, $liste_non_classee, $invalides); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -323,29 +323,29 @@ discard block |
||
| 323 | 323 | * array description short si on ne le retient pas (pour memorisation dans une table des erreurs) |
| 324 | 324 | */ |
| 325 | 325 | function plugin_valide_resume(&$liste, $plug, $infos, $dir_type) { |
| 326 | - $i = $infos[$dir_type][$plug]; |
|
| 327 | - $p = strtoupper($i['prefix']); |
|
| 328 | - $short_desc = array( |
|
| 329 | - 'nom' => $i['nom'], |
|
| 330 | - 'etat' => $i['etat'], |
|
| 331 | - 'version' => $i['version'], |
|
| 332 | - 'dir' => $plug, |
|
| 333 | - 'dir_type' => $dir_type |
|
| 334 | - ); |
|
| 335 | - if (isset($i['erreur']) and $i['erreur']) { |
|
| 336 | - $short_desc['erreur'] = $i['erreur']; |
|
| 337 | - return array($p=>$short_desc); |
|
| 338 | - } |
|
| 339 | - if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 340 | - return array($p=>$short_desc); |
|
| 341 | - } |
|
| 342 | - if (!isset($liste[$p]) |
|
| 343 | - or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 344 | - ) { |
|
| 345 | - $liste[$p] = $short_desc; |
|
| 346 | - } |
|
| 347 | - // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 348 | - return $p; |
|
| 326 | + $i = $infos[$dir_type][$plug]; |
|
| 327 | + $p = strtoupper($i['prefix']); |
|
| 328 | + $short_desc = array( |
|
| 329 | + 'nom' => $i['nom'], |
|
| 330 | + 'etat' => $i['etat'], |
|
| 331 | + 'version' => $i['version'], |
|
| 332 | + 'dir' => $plug, |
|
| 333 | + 'dir_type' => $dir_type |
|
| 334 | + ); |
|
| 335 | + if (isset($i['erreur']) and $i['erreur']) { |
|
| 336 | + $short_desc['erreur'] = $i['erreur']; |
|
| 337 | + return array($p=>$short_desc); |
|
| 338 | + } |
|
| 339 | + if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 340 | + return array($p=>$short_desc); |
|
| 341 | + } |
|
| 342 | + if (!isset($liste[$p]) |
|
| 343 | + or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 344 | + ) { |
|
| 345 | + $liste[$p] = $short_desc; |
|
| 346 | + } |
|
| 347 | + // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 348 | + return $p; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
@@ -361,46 +361,46 @@ discard block |
||
| 361 | 361 | * @param array $infos |
| 362 | 362 | */ |
| 363 | 363 | function plugin_fixer_procure(&$liste, &$infos) { |
| 364 | - foreach ($liste as $p => $resume) { |
|
| 365 | - $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 366 | - if (isset($i['procure']) and $i['procure']) { |
|
| 367 | - foreach ($i['procure'] as $procure) { |
|
| 368 | - $p = strtoupper($procure['nom']); |
|
| 369 | - $dir = $resume['dir']; |
|
| 370 | - if ($dir) { |
|
| 371 | - $dir .= "/"; |
|
| 372 | - } |
|
| 373 | - $dir .= "procure:" . $procure['nom']; |
|
| 374 | - |
|
| 375 | - $procure['etat'] = '?'; |
|
| 376 | - $procure['dir_type'] = $resume['dir_type']; |
|
| 377 | - $procure['dir'] = $dir; |
|
| 378 | - |
|
| 379 | - // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 380 | - // on ajoute cette version a la liste |
|
| 381 | - if (!isset($liste[$p]) |
|
| 382 | - or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 383 | - ) { |
|
| 384 | - $liste[$p] = $procure; |
|
| 385 | - |
|
| 386 | - // on fournit une information minimale pour ne pas perturber la compilation |
|
| 387 | - $infos[$resume['dir_type']][$dir] = array( |
|
| 388 | - 'prefix' => $procure['nom'], |
|
| 389 | - 'nom' => $procure['nom'], |
|
| 390 | - 'etat' => $procure['etat'], |
|
| 391 | - 'version' => $procure['version'], |
|
| 392 | - 'chemin' => array(), |
|
| 393 | - 'necessite' => array(), |
|
| 394 | - 'utilise' => array(), |
|
| 395 | - 'lib' => array(), |
|
| 396 | - 'menu' => array(), |
|
| 397 | - 'onglet' => array(), |
|
| 398 | - 'procure' => array(), |
|
| 399 | - ); |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - } |
|
| 364 | + foreach ($liste as $p => $resume) { |
|
| 365 | + $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 366 | + if (isset($i['procure']) and $i['procure']) { |
|
| 367 | + foreach ($i['procure'] as $procure) { |
|
| 368 | + $p = strtoupper($procure['nom']); |
|
| 369 | + $dir = $resume['dir']; |
|
| 370 | + if ($dir) { |
|
| 371 | + $dir .= "/"; |
|
| 372 | + } |
|
| 373 | + $dir .= "procure:" . $procure['nom']; |
|
| 374 | + |
|
| 375 | + $procure['etat'] = '?'; |
|
| 376 | + $procure['dir_type'] = $resume['dir_type']; |
|
| 377 | + $procure['dir'] = $dir; |
|
| 378 | + |
|
| 379 | + // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 380 | + // on ajoute cette version a la liste |
|
| 381 | + if (!isset($liste[$p]) |
|
| 382 | + or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 383 | + ) { |
|
| 384 | + $liste[$p] = $procure; |
|
| 385 | + |
|
| 386 | + // on fournit une information minimale pour ne pas perturber la compilation |
|
| 387 | + $infos[$resume['dir_type']][$dir] = array( |
|
| 388 | + 'prefix' => $procure['nom'], |
|
| 389 | + 'nom' => $procure['nom'], |
|
| 390 | + 'etat' => $procure['etat'], |
|
| 391 | + 'version' => $procure['version'], |
|
| 392 | + 'chemin' => array(), |
|
| 393 | + 'necessite' => array(), |
|
| 394 | + 'utilise' => array(), |
|
| 395 | + 'lib' => array(), |
|
| 396 | + 'menu' => array(), |
|
| 397 | + 'onglet' => array(), |
|
| 398 | + 'procure' => array(), |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | /** |
@@ -414,19 +414,19 @@ discard block |
||
| 414 | 414 | * @return array |
| 415 | 415 | */ |
| 416 | 416 | function liste_chemin_plugin($liste, $dir_plugins = _DIR_PLUGINS) { |
| 417 | - foreach ($liste as $prefix => $infos) { |
|
| 418 | - if (!$dir_plugins |
|
| 419 | - or ( |
|
| 420 | - defined($infos['dir_type']) |
|
| 421 | - and constant($infos['dir_type']) == $dir_plugins) |
|
| 422 | - ) { |
|
| 423 | - $liste[$prefix] = $infos['dir']; |
|
| 424 | - } else { |
|
| 425 | - unset($liste[$prefix]); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - return $liste; |
|
| 417 | + foreach ($liste as $prefix => $infos) { |
|
| 418 | + if (!$dir_plugins |
|
| 419 | + or ( |
|
| 420 | + defined($infos['dir_type']) |
|
| 421 | + and constant($infos['dir_type']) == $dir_plugins) |
|
| 422 | + ) { |
|
| 423 | + $liste[$prefix] = $infos['dir']; |
|
| 424 | + } else { |
|
| 425 | + unset($liste[$prefix]); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + return $liste; |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -441,9 +441,9 @@ discard block |
||
| 441 | 441 | * @return array |
| 442 | 442 | */ |
| 443 | 443 | function liste_chemin_plugin_actifs($dir_plugins = _DIR_PLUGINS) { |
| 444 | - include_spip('plugins/installer'); |
|
| 444 | + include_spip('plugins/installer'); |
|
| 445 | 445 | |
| 446 | - return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 446 | + return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
@@ -474,53 +474,53 @@ discard block |
||
| 474 | 474 | * qui n'ont pas satisfait leurs dépendances |
| 475 | 475 | **/ |
| 476 | 476 | function plugin_trier($infos, $liste_non_classee) { |
| 477 | - $toute_la_liste = $liste_non_classee; |
|
| 478 | - $liste = $ordre = array(); |
|
| 479 | - $count = 0; |
|
| 480 | - |
|
| 481 | - while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 482 | - #echo "tour::";var_dump($liste_non_classee); |
|
| 483 | - $count = $c; |
|
| 484 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 485 | - $plug = $resume['dir']; |
|
| 486 | - $dir_type = $resume['dir_type']; |
|
| 487 | - $info1 = $infos[$dir_type][$plug]; |
|
| 488 | - // si des plugins sont necessaires, |
|
| 489 | - // on ne peut inserer qu'apres eux |
|
| 490 | - foreach ($info1['necessite'] as $need) { |
|
| 491 | - $nom = strtoupper($need['nom']); |
|
| 492 | - $compat = isset($need['compatibilite']) ? $need['compatibilite'] : ''; |
|
| 493 | - if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 494 | - $info1 = false; |
|
| 495 | - break; |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - if (!$info1) { |
|
| 499 | - continue; |
|
| 500 | - } |
|
| 501 | - // idem si des plugins sont utiles, |
|
| 502 | - // sauf si ils sont de toute facon absents de la liste |
|
| 503 | - foreach ($info1['utilise'] as $need) { |
|
| 504 | - $nom = strtoupper($need['nom']); |
|
| 505 | - $compat = isset($need['compatibilite']) ? $need['compatibilite'] : ''; |
|
| 506 | - if (isset($toute_la_liste[$nom])) { |
|
| 507 | - if (!isset($liste[$nom]) or |
|
| 508 | - !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 509 | - ) { |
|
| 510 | - $info1 = false; |
|
| 511 | - break; |
|
| 512 | - } |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - if ($info1) { |
|
| 516 | - $ordre[$p] = $info1; |
|
| 517 | - $liste[$p] = $liste_non_classee[$p]; |
|
| 518 | - unset($liste_non_classee[$p]); |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - return array($liste, $ordre, $liste_non_classee); |
|
| 477 | + $toute_la_liste = $liste_non_classee; |
|
| 478 | + $liste = $ordre = array(); |
|
| 479 | + $count = 0; |
|
| 480 | + |
|
| 481 | + while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 482 | + #echo "tour::";var_dump($liste_non_classee); |
|
| 483 | + $count = $c; |
|
| 484 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 485 | + $plug = $resume['dir']; |
|
| 486 | + $dir_type = $resume['dir_type']; |
|
| 487 | + $info1 = $infos[$dir_type][$plug]; |
|
| 488 | + // si des plugins sont necessaires, |
|
| 489 | + // on ne peut inserer qu'apres eux |
|
| 490 | + foreach ($info1['necessite'] as $need) { |
|
| 491 | + $nom = strtoupper($need['nom']); |
|
| 492 | + $compat = isset($need['compatibilite']) ? $need['compatibilite'] : ''; |
|
| 493 | + if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 494 | + $info1 = false; |
|
| 495 | + break; |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + if (!$info1) { |
|
| 499 | + continue; |
|
| 500 | + } |
|
| 501 | + // idem si des plugins sont utiles, |
|
| 502 | + // sauf si ils sont de toute facon absents de la liste |
|
| 503 | + foreach ($info1['utilise'] as $need) { |
|
| 504 | + $nom = strtoupper($need['nom']); |
|
| 505 | + $compat = isset($need['compatibilite']) ? $need['compatibilite'] : ''; |
|
| 506 | + if (isset($toute_la_liste[$nom])) { |
|
| 507 | + if (!isset($liste[$nom]) or |
|
| 508 | + !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 509 | + ) { |
|
| 510 | + $info1 = false; |
|
| 511 | + break; |
|
| 512 | + } |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + if ($info1) { |
|
| 516 | + $ordre[$p] = $info1; |
|
| 517 | + $liste[$p] = $liste_non_classee[$p]; |
|
| 518 | + unset($liste_non_classee[$p]); |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + return array($liste, $ordre, $liste_non_classee); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | /** |
@@ -537,40 +537,40 @@ discard block |
||
| 537 | 537 | * Répertoire (plugins, plugins-dist, ...) => Couples (prefixes => infos completes) des plugins qu'ils contiennent |
| 538 | 538 | **/ |
| 539 | 539 | function plugins_erreurs($liste_non_classee, $liste, $infos, $msg = array()) { |
| 540 | - static $erreurs = array(); |
|
| 541 | - |
|
| 542 | - if (!is_array($liste)) { |
|
| 543 | - $liste = array(); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 547 | - $liste = array_diff_key($liste, $liste_non_classee); |
|
| 548 | - |
|
| 549 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 550 | - $dir_type = $resume['dir_type']; |
|
| 551 | - $plug = $resume['dir']; |
|
| 552 | - $k = $infos[$dir_type][$plug]; |
|
| 553 | - |
|
| 554 | - $plug = constant($dir_type) . $plug; |
|
| 555 | - if (!isset($msg[$p])) { |
|
| 556 | - if (isset($resume['erreur']) and $resume['erreur']) { |
|
| 557 | - $msg[$p] = array($resume['erreur']); |
|
| 558 | - } |
|
| 559 | - elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 560 | - $msg[$p] = array(plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')); |
|
| 561 | - } |
|
| 562 | - elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 563 | - $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 564 | - } |
|
| 565 | - } else { |
|
| 566 | - foreach ($msg[$p] as $c => $l) { |
|
| 567 | - $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - $erreurs[$plug] = $msg[$p]; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 540 | + static $erreurs = array(); |
|
| 541 | + |
|
| 542 | + if (!is_array($liste)) { |
|
| 543 | + $liste = array(); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 547 | + $liste = array_diff_key($liste, $liste_non_classee); |
|
| 548 | + |
|
| 549 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 550 | + $dir_type = $resume['dir_type']; |
|
| 551 | + $plug = $resume['dir']; |
|
| 552 | + $k = $infos[$dir_type][$plug]; |
|
| 553 | + |
|
| 554 | + $plug = constant($dir_type) . $plug; |
|
| 555 | + if (!isset($msg[$p])) { |
|
| 556 | + if (isset($resume['erreur']) and $resume['erreur']) { |
|
| 557 | + $msg[$p] = array($resume['erreur']); |
|
| 558 | + } |
|
| 559 | + elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 560 | + $msg[$p] = array(plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')); |
|
| 561 | + } |
|
| 562 | + elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 563 | + $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 564 | + } |
|
| 565 | + } else { |
|
| 566 | + foreach ($msg[$p] as $c => $l) { |
|
| 567 | + $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + $erreurs[$plug] = $msg[$p]; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -585,25 +585,25 @@ discard block |
||
| 585 | 585 | * - Liste des erreurs ou code HTML des erreurs |
| 586 | 586 | **/ |
| 587 | 587 | function plugin_donne_erreurs($raw = false, $raz = true) { |
| 588 | - if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 589 | - return $raw ? array() : ''; |
|
| 590 | - } |
|
| 591 | - $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 592 | - // Compat ancienne version |
|
| 593 | - if (!$list) { |
|
| 594 | - $list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 595 | - } elseif (!$raw) { |
|
| 596 | - foreach ($list as $plug => $msg) { |
|
| 597 | - $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug)) |
|
| 598 | - . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>"; |
|
| 599 | - } |
|
| 600 | - $list = "<ul>" . join("\n", $list) . "</ul>"; |
|
| 601 | - } |
|
| 602 | - if ($raz) { |
|
| 603 | - effacer_meta('plugin_erreur_activation'); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - return $list; |
|
| 588 | + if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 589 | + return $raw ? array() : ''; |
|
| 590 | + } |
|
| 591 | + $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 592 | + // Compat ancienne version |
|
| 593 | + if (!$list) { |
|
| 594 | + $list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 595 | + } elseif (!$raw) { |
|
| 596 | + foreach ($list as $plug => $msg) { |
|
| 597 | + $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug)) |
|
| 598 | + . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>"; |
|
| 599 | + } |
|
| 600 | + $list = "<ul>" . join("\n", $list) . "</ul>"; |
|
| 601 | + } |
|
| 602 | + if ($raz) { |
|
| 603 | + effacer_meta('plugin_erreur_activation'); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + return $list; |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | /** |
@@ -623,21 +623,21 @@ discard block |
||
| 623 | 623 | * |
| 624 | 624 | **/ |
| 625 | 625 | function plugin_necessite($n, $liste, $balise = 'necessite') { |
| 626 | - $msg = array(); |
|
| 627 | - foreach ($n as $need) { |
|
| 628 | - $id = strtoupper($need['nom']); |
|
| 629 | - $r = plugin_controler_necessite( |
|
| 630 | - $liste, |
|
| 631 | - $id, |
|
| 632 | - isset($need['compatibilite']) ? $need['compatibilite'] : '', |
|
| 633 | - $balise |
|
| 634 | - ); |
|
| 635 | - if ($r) { |
|
| 636 | - $msg[] = $r; |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - return $msg; |
|
| 626 | + $msg = array(); |
|
| 627 | + foreach ($n as $need) { |
|
| 628 | + $id = strtoupper($need['nom']); |
|
| 629 | + $r = plugin_controler_necessite( |
|
| 630 | + $liste, |
|
| 631 | + $id, |
|
| 632 | + isset($need['compatibilite']) ? $need['compatibilite'] : '', |
|
| 633 | + $balise |
|
| 634 | + ); |
|
| 635 | + if ($r) { |
|
| 636 | + $msg[] = $r; |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + return $msg; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | /** |
@@ -659,16 +659,16 @@ discard block |
||
| 659 | 659 | * Message d'erreur lorsque la dépendance est absente. |
| 660 | 660 | **/ |
| 661 | 661 | function plugin_controler_necessite($liste, $nom, $intervalle, $balise) { |
| 662 | - if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 663 | - return ''; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - return plugin_message_incompatibilite( |
|
| 667 | - $intervalle, |
|
| 668 | - (isset($liste[$nom]) ? $liste[$nom]['version'] : ""), |
|
| 669 | - $nom, |
|
| 670 | - $balise |
|
| 671 | - ); |
|
| 662 | + if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 663 | + return ''; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + return plugin_message_incompatibilite( |
|
| 667 | + $intervalle, |
|
| 668 | + (isset($liste[$nom]) ? $liste[$nom]['version'] : ""), |
|
| 669 | + $nom, |
|
| 670 | + $balise |
|
| 671 | + ); |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | /** |
@@ -685,70 +685,70 @@ discard block |
||
| 685 | 685 | */ |
| 686 | 686 | function plugin_message_incompatibilite($intervalle, $version, $nom, $balise) { |
| 687 | 687 | |
| 688 | - // prendre en compte les erreurs de dépendances à PHP |
|
| 689 | - // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 690 | - $type = 'plugin'; |
|
| 691 | - if ($nom === 'SPIP') { |
|
| 692 | - $type = 'spip'; |
|
| 693 | - } elseif ($nom === 'PHP') { |
|
| 694 | - $type = 'php'; |
|
| 695 | - } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 696 | - $type = 'extension_php'; |
|
| 697 | - list(,$nom) = explode(':', $nom, 2); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 701 | - $minimum = $regs[1]; |
|
| 702 | - $maximum = $regs[2]; |
|
| 703 | - |
|
| 704 | - $minimum_inclus = $intervalle[0] == "["; |
|
| 705 | - $maximum_inclus = substr($intervalle, -1) == "]"; |
|
| 706 | - |
|
| 707 | - if (strlen($minimum)) { |
|
| 708 | - if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 709 | - return _T("plugin_${balise}_${type}", array( |
|
| 710 | - 'plugin' => $nom, |
|
| 711 | - 'version' => ' ≥ ' . $minimum |
|
| 712 | - )); |
|
| 713 | - } |
|
| 714 | - if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 715 | - return _T("plugin_${balise}_${type}", array( |
|
| 716 | - 'plugin' => $nom, |
|
| 717 | - 'version' => ' > ' . $minimum |
|
| 718 | - )); |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - if (strlen($maximum)) { |
|
| 723 | - if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 724 | - return _T("plugin_${balise}_${type}", array( |
|
| 725 | - 'plugin' => $nom, |
|
| 726 | - 'version' => ' ≤ ' . $maximum |
|
| 727 | - )); |
|
| 728 | - } |
|
| 729 | - if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 730 | - return _T("plugin_${balise}_plugin", array( |
|
| 731 | - 'plugin' => $nom, |
|
| 732 | - 'version' => ' < ' . $maximum |
|
| 733 | - )); |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - // note : il ne peut pas y avoir d'erreur sur |
|
| 739 | - // - un 'utilise' sans version. |
|
| 740 | - // - un 'php' sans version. |
|
| 741 | - return _T("plugin_necessite_${type}_sans_version", array('plugin' => $nom)); |
|
| 688 | + // prendre en compte les erreurs de dépendances à PHP |
|
| 689 | + // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 690 | + $type = 'plugin'; |
|
| 691 | + if ($nom === 'SPIP') { |
|
| 692 | + $type = 'spip'; |
|
| 693 | + } elseif ($nom === 'PHP') { |
|
| 694 | + $type = 'php'; |
|
| 695 | + } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 696 | + $type = 'extension_php'; |
|
| 697 | + list(,$nom) = explode(':', $nom, 2); |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 701 | + $minimum = $regs[1]; |
|
| 702 | + $maximum = $regs[2]; |
|
| 703 | + |
|
| 704 | + $minimum_inclus = $intervalle[0] == "["; |
|
| 705 | + $maximum_inclus = substr($intervalle, -1) == "]"; |
|
| 706 | + |
|
| 707 | + if (strlen($minimum)) { |
|
| 708 | + if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 709 | + return _T("plugin_${balise}_${type}", array( |
|
| 710 | + 'plugin' => $nom, |
|
| 711 | + 'version' => ' ≥ ' . $minimum |
|
| 712 | + )); |
|
| 713 | + } |
|
| 714 | + if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 715 | + return _T("plugin_${balise}_${type}", array( |
|
| 716 | + 'plugin' => $nom, |
|
| 717 | + 'version' => ' > ' . $minimum |
|
| 718 | + )); |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + if (strlen($maximum)) { |
|
| 723 | + if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 724 | + return _T("plugin_${balise}_${type}", array( |
|
| 725 | + 'plugin' => $nom, |
|
| 726 | + 'version' => ' ≤ ' . $maximum |
|
| 727 | + )); |
|
| 728 | + } |
|
| 729 | + if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 730 | + return _T("plugin_${balise}_plugin", array( |
|
| 731 | + 'plugin' => $nom, |
|
| 732 | + 'version' => ' < ' . $maximum |
|
| 733 | + )); |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + // note : il ne peut pas y avoir d'erreur sur |
|
| 739 | + // - un 'utilise' sans version. |
|
| 740 | + // - un 'php' sans version. |
|
| 741 | + return _T("plugin_necessite_${type}_sans_version", array('plugin' => $nom)); |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | |
| 745 | 745 | function plugin_controler_lib($lib, $url) { |
| 746 | - /* Feature sortie du core, voir STP |
|
| 746 | + /* Feature sortie du core, voir STP |
|
| 747 | 747 | * if ($url) { |
| 748 | 748 | include_spip('inc/charger_plugin'); |
| 749 | 749 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 750 | 750 | }*/ |
| 751 | - return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>"; |
|
| 751 | + return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>"; |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | |
@@ -763,7 +763,7 @@ discard block |
||
| 763 | 763 | * true si il y a eu des modifications sur la liste des plugins actifs, false sinon |
| 764 | 764 | **/ |
| 765 | 765 | function actualise_plugins_actifs($pipe_recherche = false) { |
| 766 | - return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 766 | + return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | |
@@ -790,113 +790,113 @@ discard block |
||
| 790 | 790 | **/ |
| 791 | 791 | function ecrire_plugin_actifs($plugin, $pipe_recherche = false, $operation = 'raz') { |
| 792 | 792 | |
| 793 | - // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 794 | - $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 795 | - |
|
| 796 | - // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 797 | - if (!$cache and !spip_connect()) { |
|
| 798 | - return false; |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - if ($operation != 'raz') { |
|
| 802 | - $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 803 | - $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 804 | - if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 805 | - $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 806 | - $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 807 | - $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 808 | - } |
|
| 809 | - // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 810 | - // on les reinjecte ici |
|
| 811 | - if (isset($GLOBALS['meta']['plugin_attente']) |
|
| 812 | - and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 813 | - ) { |
|
| 814 | - $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - if ($operation == 'ajoute') { |
|
| 818 | - $plugin = array_merge($plugin_valides, $plugin); |
|
| 819 | - } elseif ($operation == 'enleve') { |
|
| 820 | - $plugin = array_diff($plugin_valides, $plugin); |
|
| 821 | - } else { |
|
| 822 | - $plugin = $plugin_valides; |
|
| 823 | - } |
|
| 824 | - } |
|
| 825 | - $actifs_avant = isset($GLOBALS['meta']['plugin']) ? $GLOBALS['meta']['plugin'] : ''; |
|
| 826 | - |
|
| 827 | - // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 828 | - if ($ajouter_dependances = charger_fonction("ajouter_dependances", "plugins", true)) { |
|
| 829 | - $plugin = $ajouter_dependances($plugin); |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - // recharger le xml des plugins a activer |
|
| 833 | - // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 834 | - // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 835 | - // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 836 | - // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 837 | - list($infos, $liste, $invalides) = liste_plugin_valides($plugin, true); |
|
| 838 | - // trouver l'ordre d'activation |
|
| 839 | - list($plugin_valides, $ordre, $reste) = plugin_trier($infos, $liste); |
|
| 840 | - if ($invalides or $reste) { |
|
| 841 | - plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - // Ignorer les plugins necessitant une lib absente |
|
| 845 | - // et preparer la meta d'entete Http |
|
| 846 | - $err = $msg = $header = array(); |
|
| 847 | - foreach ($plugin_valides as $p => $resume) { |
|
| 848 | - // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 849 | - if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
|
| 850 | - $header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : ""); |
|
| 851 | - } |
|
| 852 | - if ($resume['dir']) { |
|
| 853 | - foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 854 | - if (!find_in_path($l['nom'], 'lib/')) { |
|
| 855 | - $err[$p] = $resume; |
|
| 856 | - $msg[$p][] = $l; |
|
| 857 | - unset($plugin_valides[$p]); |
|
| 858 | - } |
|
| 859 | - } |
|
| 860 | - } |
|
| 861 | - } |
|
| 862 | - if ($err) { |
|
| 863 | - plugins_erreurs($err, '', $infos, $msg); |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 867 | - effacer_meta('message_crash_plugins'); |
|
| 868 | - } |
|
| 869 | - ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 870 | - $liste = array_diff_key($liste, $plugin_valides); |
|
| 871 | - ecrire_meta('plugin_attente', serialize($liste)); |
|
| 872 | - $header = strtolower(implode(",", $header)); |
|
| 873 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 874 | - ecrire_fichier(_DIR_VAR . "config.txt", |
|
| 875 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header); |
|
| 876 | - } else { |
|
| 877 | - @unlink(_DIR_VAR . "config.txt"); |
|
| 878 | - } |
|
| 879 | - // generer charger_plugins_chemin.php |
|
| 880 | - plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 881 | - // generer les fichiers |
|
| 882 | - // - charger_plugins_options.php |
|
| 883 | - // - charger_plugins_fonctions.php |
|
| 884 | - plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 885 | - // charger les chemins des plugins et les fichiers d'options |
|
| 886 | - // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 887 | - plugins_amorcer_plugins_actifs(); |
|
| 888 | - // mise a jour de la matrice des pipelines |
|
| 889 | - $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 890 | - // generer le fichier _CACHE_PIPELINE |
|
| 891 | - pipeline_precompile($prepend_code); |
|
| 892 | - |
|
| 893 | - if (spip_connect()) { |
|
| 894 | - // lancer et initialiser les nouveaux crons ! |
|
| 895 | - include_spip('inc/genie'); |
|
| 896 | - genie_queue_watch_dist(); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 793 | + // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 794 | + $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 795 | + |
|
| 796 | + // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 797 | + if (!$cache and !spip_connect()) { |
|
| 798 | + return false; |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + if ($operation != 'raz') { |
|
| 802 | + $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 803 | + $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 804 | + if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 805 | + $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 806 | + $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 807 | + $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 808 | + } |
|
| 809 | + // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 810 | + // on les reinjecte ici |
|
| 811 | + if (isset($GLOBALS['meta']['plugin_attente']) |
|
| 812 | + and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 813 | + ) { |
|
| 814 | + $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + if ($operation == 'ajoute') { |
|
| 818 | + $plugin = array_merge($plugin_valides, $plugin); |
|
| 819 | + } elseif ($operation == 'enleve') { |
|
| 820 | + $plugin = array_diff($plugin_valides, $plugin); |
|
| 821 | + } else { |
|
| 822 | + $plugin = $plugin_valides; |
|
| 823 | + } |
|
| 824 | + } |
|
| 825 | + $actifs_avant = isset($GLOBALS['meta']['plugin']) ? $GLOBALS['meta']['plugin'] : ''; |
|
| 826 | + |
|
| 827 | + // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 828 | + if ($ajouter_dependances = charger_fonction("ajouter_dependances", "plugins", true)) { |
|
| 829 | + $plugin = $ajouter_dependances($plugin); |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + // recharger le xml des plugins a activer |
|
| 833 | + // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 834 | + // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 835 | + // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 836 | + // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 837 | + list($infos, $liste, $invalides) = liste_plugin_valides($plugin, true); |
|
| 838 | + // trouver l'ordre d'activation |
|
| 839 | + list($plugin_valides, $ordre, $reste) = plugin_trier($infos, $liste); |
|
| 840 | + if ($invalides or $reste) { |
|
| 841 | + plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + // Ignorer les plugins necessitant une lib absente |
|
| 845 | + // et preparer la meta d'entete Http |
|
| 846 | + $err = $msg = $header = array(); |
|
| 847 | + foreach ($plugin_valides as $p => $resume) { |
|
| 848 | + // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 849 | + if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
|
| 850 | + $header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : ""); |
|
| 851 | + } |
|
| 852 | + if ($resume['dir']) { |
|
| 853 | + foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 854 | + if (!find_in_path($l['nom'], 'lib/')) { |
|
| 855 | + $err[$p] = $resume; |
|
| 856 | + $msg[$p][] = $l; |
|
| 857 | + unset($plugin_valides[$p]); |
|
| 858 | + } |
|
| 859 | + } |
|
| 860 | + } |
|
| 861 | + } |
|
| 862 | + if ($err) { |
|
| 863 | + plugins_erreurs($err, '', $infos, $msg); |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 867 | + effacer_meta('message_crash_plugins'); |
|
| 868 | + } |
|
| 869 | + ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 870 | + $liste = array_diff_key($liste, $plugin_valides); |
|
| 871 | + ecrire_meta('plugin_attente', serialize($liste)); |
|
| 872 | + $header = strtolower(implode(",", $header)); |
|
| 873 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 874 | + ecrire_fichier(_DIR_VAR . "config.txt", |
|
| 875 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header); |
|
| 876 | + } else { |
|
| 877 | + @unlink(_DIR_VAR . "config.txt"); |
|
| 878 | + } |
|
| 879 | + // generer charger_plugins_chemin.php |
|
| 880 | + plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 881 | + // generer les fichiers |
|
| 882 | + // - charger_plugins_options.php |
|
| 883 | + // - charger_plugins_fonctions.php |
|
| 884 | + plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 885 | + // charger les chemins des plugins et les fichiers d'options |
|
| 886 | + // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 887 | + plugins_amorcer_plugins_actifs(); |
|
| 888 | + // mise a jour de la matrice des pipelines |
|
| 889 | + $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 890 | + // generer le fichier _CACHE_PIPELINE |
|
| 891 | + pipeline_precompile($prepend_code); |
|
| 892 | + |
|
| 893 | + if (spip_connect()) { |
|
| 894 | + // lancer et initialiser les nouveaux crons ! |
|
| 895 | + include_spip('inc/genie'); |
|
| 896 | + genie_queue_watch_dist(); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | /** |
@@ -915,56 +915,56 @@ discard block |
||
| 915 | 915 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 916 | 916 | **/ |
| 917 | 917 | function plugins_precompile_chemin($plugin_valides, $ordre) { |
| 918 | - $chemins = array(); |
|
| 919 | - $contenu = ""; |
|
| 920 | - foreach ($ordre as $p => $info) { |
|
| 921 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 922 | - if (isset($plugin_valides[$p])) { |
|
| 923 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 924 | - $plug = $plugin_valides[$p]['dir']; |
|
| 925 | - // definir le plugin, donc le path avant l'include du fichier options |
|
| 926 | - // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 927 | - |
|
| 928 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 929 | - |
|
| 930 | - $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 931 | - if ( |
|
| 932 | - $prefix !== "SPIP" |
|
| 933 | - and strpos($dir, ":") === false // exclure le cas des procure: |
|
| 934 | - ) { |
|
| 935 | - $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 936 | - foreach ($info['chemin'] as $chemin) { |
|
| 937 | - if (!isset($chemin['version']) or plugin_version_compatible($chemin['version'], |
|
| 938 | - $GLOBALS['spip_version_branche'], 'spip') |
|
| 939 | - ) { |
|
| 940 | - $dir = $chemin['path']; |
|
| 941 | - if (strlen($dir) and $dir[0] == "/") { |
|
| 942 | - $dir = substr($dir, 1); |
|
| 943 | - } |
|
| 944 | - if (strlen($dir) and $dir == "./") { |
|
| 945 | - $dir = ''; |
|
| 946 | - } |
|
| 947 | - if (strlen($dir)) { |
|
| 948 | - $dir = rtrim($dir, '/') . '/'; |
|
| 949 | - } |
|
| 950 | - if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 951 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 952 | - } |
|
| 953 | - if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 954 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 955 | - } |
|
| 956 | - } |
|
| 957 | - } |
|
| 958 | - } |
|
| 959 | - } |
|
| 960 | - } |
|
| 961 | - if (count($chemins)) { |
|
| 962 | - $contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(" . implode(',', |
|
| 963 | - array_reverse($chemins['public'])) . ")));\n" |
|
| 964 | - . "else _chemin(implode(':',array(" . implode(',', array_reverse($chemins['prive'])) . ")));\n"; |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 918 | + $chemins = array(); |
|
| 919 | + $contenu = ""; |
|
| 920 | + foreach ($ordre as $p => $info) { |
|
| 921 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 922 | + if (isset($plugin_valides[$p])) { |
|
| 923 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 924 | + $plug = $plugin_valides[$p]['dir']; |
|
| 925 | + // definir le plugin, donc le path avant l'include du fichier options |
|
| 926 | + // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 927 | + |
|
| 928 | + $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 929 | + |
|
| 930 | + $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 931 | + if ( |
|
| 932 | + $prefix !== "SPIP" |
|
| 933 | + and strpos($dir, ":") === false // exclure le cas des procure: |
|
| 934 | + ) { |
|
| 935 | + $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 936 | + foreach ($info['chemin'] as $chemin) { |
|
| 937 | + if (!isset($chemin['version']) or plugin_version_compatible($chemin['version'], |
|
| 938 | + $GLOBALS['spip_version_branche'], 'spip') |
|
| 939 | + ) { |
|
| 940 | + $dir = $chemin['path']; |
|
| 941 | + if (strlen($dir) and $dir[0] == "/") { |
|
| 942 | + $dir = substr($dir, 1); |
|
| 943 | + } |
|
| 944 | + if (strlen($dir) and $dir == "./") { |
|
| 945 | + $dir = ''; |
|
| 946 | + } |
|
| 947 | + if (strlen($dir)) { |
|
| 948 | + $dir = rtrim($dir, '/') . '/'; |
|
| 949 | + } |
|
| 950 | + if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 951 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 952 | + } |
|
| 953 | + if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 954 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + } |
|
| 958 | + } |
|
| 959 | + } |
|
| 960 | + } |
|
| 961 | + if (count($chemins)) { |
|
| 962 | + $contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(" . implode(',', |
|
| 963 | + array_reverse($chemins['public'])) . ")));\n" |
|
| 964 | + . "else _chemin(implode(':',array(" . implode(',', array_reverse($chemins['prive'])) . ")));\n"; |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 968 | 968 | } |
| 969 | 969 | |
| 970 | 970 | /** |
@@ -982,65 +982,65 @@ discard block |
||
| 982 | 982 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 983 | 983 | **/ |
| 984 | 984 | function plugins_precompile_xxxtions($plugin_valides, $ordre) { |
| 985 | - $contenu = array('options' => '', 'fonctions' => ''); |
|
| 986 | - $boutons = array(); |
|
| 987 | - $onglets = array(); |
|
| 988 | - $sign = ""; |
|
| 989 | - |
|
| 990 | - foreach ($ordre as $p => $info) { |
|
| 991 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 992 | - if (isset($plugin_valides[$p])) { |
|
| 993 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 994 | - $plug = $plugin_valides[$p]['dir']; |
|
| 995 | - $dir = constant($dir_type); |
|
| 996 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 997 | - if ($info['menu']) { |
|
| 998 | - $boutons = array_merge($boutons, $info['menu']); |
|
| 999 | - } |
|
| 1000 | - if ($info['onglet']) { |
|
| 1001 | - $onglets = array_merge($onglets, $info['onglet']); |
|
| 1002 | - } |
|
| 1003 | - foreach ($contenu as $charge => $v) { |
|
| 1004 | - // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1005 | - // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1006 | - // donc ni sa relecture, ni sa detection |
|
| 1007 | - if (!isset($info[$charge]) |
|
| 1008 | - and $dir // exclure le cas du plugin "SPIP" |
|
| 1009 | - and strpos($dir, ":") === false // exclure le cas des procure: |
|
| 1010 | - and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1011 | - ) { |
|
| 1012 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) { |
|
| 1013 | - $info[$charge] = array($file); |
|
| 1014 | - } |
|
| 1015 | - } |
|
| 1016 | - if (isset($info[$charge])) { |
|
| 1017 | - $files = $info[$charge]; |
|
| 1018 | - foreach ($files as $k => $file) { |
|
| 1019 | - // on genere un if file_exists devant chaque include |
|
| 1020 | - // pour pouvoir garder le meme niveau d'erreur general |
|
| 1021 | - $file = trim($file); |
|
| 1022 | - if (!is_readable("$dir$plug/$file") |
|
| 1023 | - // uniquement pour les paquet.xml |
|
| 1024 | - and file_exists("$dir$plug/paquet.xml") |
|
| 1025 | - ) { |
|
| 1026 | - unset($info[$charge][$k]); |
|
| 1027 | - } else { |
|
| 1028 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1029 | - $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1030 | - } |
|
| 1031 | - } |
|
| 1032 | - } |
|
| 1033 | - } |
|
| 1034 | - $sign .= md5(serialize($info)); |
|
| 1035 | - } |
|
| 1036 | - } |
|
| 1037 | - |
|
| 1038 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1039 | - $contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons) |
|
| 1040 | - . plugin_ongletbouton("onglets_plugins", $onglets); |
|
| 1041 | - |
|
| 1042 | - ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1043 | - ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 985 | + $contenu = array('options' => '', 'fonctions' => ''); |
|
| 986 | + $boutons = array(); |
|
| 987 | + $onglets = array(); |
|
| 988 | + $sign = ""; |
|
| 989 | + |
|
| 990 | + foreach ($ordre as $p => $info) { |
|
| 991 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 992 | + if (isset($plugin_valides[$p])) { |
|
| 993 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 994 | + $plug = $plugin_valides[$p]['dir']; |
|
| 995 | + $dir = constant($dir_type); |
|
| 996 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 997 | + if ($info['menu']) { |
|
| 998 | + $boutons = array_merge($boutons, $info['menu']); |
|
| 999 | + } |
|
| 1000 | + if ($info['onglet']) { |
|
| 1001 | + $onglets = array_merge($onglets, $info['onglet']); |
|
| 1002 | + } |
|
| 1003 | + foreach ($contenu as $charge => $v) { |
|
| 1004 | + // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1005 | + // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1006 | + // donc ni sa relecture, ni sa detection |
|
| 1007 | + if (!isset($info[$charge]) |
|
| 1008 | + and $dir // exclure le cas du plugin "SPIP" |
|
| 1009 | + and strpos($dir, ":") === false // exclure le cas des procure: |
|
| 1010 | + and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1011 | + ) { |
|
| 1012 | + if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) { |
|
| 1013 | + $info[$charge] = array($file); |
|
| 1014 | + } |
|
| 1015 | + } |
|
| 1016 | + if (isset($info[$charge])) { |
|
| 1017 | + $files = $info[$charge]; |
|
| 1018 | + foreach ($files as $k => $file) { |
|
| 1019 | + // on genere un if file_exists devant chaque include |
|
| 1020 | + // pour pouvoir garder le meme niveau d'erreur general |
|
| 1021 | + $file = trim($file); |
|
| 1022 | + if (!is_readable("$dir$plug/$file") |
|
| 1023 | + // uniquement pour les paquet.xml |
|
| 1024 | + and file_exists("$dir$plug/paquet.xml") |
|
| 1025 | + ) { |
|
| 1026 | + unset($info[$charge][$k]); |
|
| 1027 | + } else { |
|
| 1028 | + $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1029 | + $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1030 | + } |
|
| 1031 | + } |
|
| 1032 | + } |
|
| 1033 | + } |
|
| 1034 | + $sign .= md5(serialize($info)); |
|
| 1035 | + } |
|
| 1036 | + } |
|
| 1037 | + |
|
| 1038 | + $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1039 | + $contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons) |
|
| 1040 | + . plugin_ongletbouton("onglets_plugins", $onglets); |
|
| 1041 | + |
|
| 1042 | + ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1043 | + ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | /** |
@@ -1059,24 +1059,24 @@ discard block |
||
| 1059 | 1059 | * @return string Code php |
| 1060 | 1060 | */ |
| 1061 | 1061 | function plugin_ongletbouton($nom, $val) { |
| 1062 | - if (!$val) { |
|
| 1063 | - $val = array(); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - $val = serialize($val); |
|
| 1067 | - $md5 = md5($val); |
|
| 1068 | - |
|
| 1069 | - if (!defined("_UPDATED_$nom")) { |
|
| 1070 | - define("_UPDATED_$nom", $val); |
|
| 1071 | - define("_UPDATED_md5_$nom", $md5); |
|
| 1072 | - } |
|
| 1073 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1074 | - |
|
| 1075 | - return |
|
| 1076 | - "if (!function_exists('$nom')) {\n" |
|
| 1077 | - . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1078 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1079 | - . "}\n"; |
|
| 1062 | + if (!$val) { |
|
| 1063 | + $val = array(); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + $val = serialize($val); |
|
| 1067 | + $md5 = md5($val); |
|
| 1068 | + |
|
| 1069 | + if (!defined("_UPDATED_$nom")) { |
|
| 1070 | + define("_UPDATED_$nom", $val); |
|
| 1071 | + define("_UPDATED_md5_$nom", $md5); |
|
| 1072 | + } |
|
| 1073 | + $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1074 | + |
|
| 1075 | + return |
|
| 1076 | + "if (!function_exists('$nom')) {\n" |
|
| 1077 | + . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1078 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1079 | + . "}\n"; |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | /** |
@@ -1091,15 +1091,15 @@ discard block |
||
| 1091 | 1091 | **/ |
| 1092 | 1092 | function plugins_amorcer_plugins_actifs() { |
| 1093 | 1093 | |
| 1094 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1095 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1096 | - } |
|
| 1094 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1095 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1096 | + } |
|
| 1097 | 1097 | |
| 1098 | - if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1099 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 1100 | - } else { |
|
| 1101 | - spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT); |
|
| 1102 | - } |
|
| 1098 | + if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1099 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 1100 | + } else { |
|
| 1101 | + spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT); |
|
| 1102 | + } |
|
| 1103 | 1103 | } |
| 1104 | 1104 | |
| 1105 | 1105 | /** |
@@ -1122,136 +1122,136 @@ discard block |
||
| 1122 | 1122 | * Couples (nom du pipeline => Code PHP à insérer au début du pipeline) |
| 1123 | 1123 | **/ |
| 1124 | 1124 | function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche) { |
| 1125 | - static $liste_pipe_manquants = array(); |
|
| 1126 | - if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1127 | - $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - $prepend_code = array(); |
|
| 1131 | - |
|
| 1132 | - foreach ($ordre as $p => $info) { |
|
| 1133 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1134 | - if (isset($plugin_valides[$p])) { |
|
| 1135 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1136 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1137 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1138 | - $prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_"); |
|
| 1139 | - if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1140 | - foreach ($info['pipeline'] as $pipe) { |
|
| 1141 | - $nom = $pipe['nom']; |
|
| 1142 | - if (isset($pipe['action'])) { |
|
| 1143 | - $action = $pipe['action']; |
|
| 1144 | - } else { |
|
| 1145 | - $action = $nom; |
|
| 1146 | - } |
|
| 1147 | - $nomlower = strtolower($nom); |
|
| 1148 | - if ($nomlower != $nom |
|
| 1149 | - and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1150 | - and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1151 | - ) { |
|
| 1152 | - $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1153 | - unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1154 | - } |
|
| 1155 | - $nom = $nomlower; |
|
| 1156 | - // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1157 | - if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel |
|
| 1158 | - { |
|
| 1159 | - $GLOBALS['spip_pipeline'][$nom] = ""; |
|
| 1160 | - } |
|
| 1161 | - if ($action) { |
|
| 1162 | - if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) { |
|
| 1163 | - $GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1", |
|
| 1164 | - $GLOBALS['spip_pipeline'][$nom], 1); |
|
| 1165 | - } |
|
| 1166 | - if (isset($pipe['inclure'])) { |
|
| 1167 | - $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1168 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1169 | - } |
|
| 1170 | - } |
|
| 1171 | - } |
|
| 1172 | - } |
|
| 1173 | - if (isset($info['genie']) and count($info['genie'])) { |
|
| 1174 | - if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1175 | - $prepend_code['taches_generales_cron'] = ""; |
|
| 1176 | - } |
|
| 1177 | - foreach ($info['genie'] as $genie) { |
|
| 1178 | - $nom = $prefix . $genie['nom']; |
|
| 1179 | - $periode = max(60, intval($genie['periode'])); |
|
| 1180 | - if (charger_fonction($nom, "genie", true)) { |
|
| 1181 | - $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1182 | - } else { |
|
| 1183 | - spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1184 | - } |
|
| 1185 | - } |
|
| 1186 | - } |
|
| 1187 | - if (isset($info['style']) and count($info['style'])) { |
|
| 1188 | - if (!isset($prepend_code['insert_head_css'])) { |
|
| 1189 | - $prepend_code['insert_head_css'] = ""; |
|
| 1190 | - } |
|
| 1191 | - if (!isset($prepend_code['header_prive_css'])) { |
|
| 1192 | - $prepend_code['header_prive_css'] = ""; |
|
| 1193 | - } |
|
| 1194 | - foreach ($info['style'] as $style) { |
|
| 1195 | - if (isset($style['path']) and $style['path']) { |
|
| 1196 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1197 | - } else { |
|
| 1198 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1199 | - } |
|
| 1200 | - $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1201 | - if (isset($style['media']) and strlen($style['media'])) { |
|
| 1202 | - $code .= " media=\"" . addslashes($style['media']) . "\""; |
|
| 1203 | - } |
|
| 1204 | - $code .= "/>';\n"; |
|
| 1205 | - if ($style['type'] != 'prive') { |
|
| 1206 | - $prepend_code['insert_head_css'] .= $code; |
|
| 1207 | - } |
|
| 1208 | - if ($style['type'] != 'public') { |
|
| 1209 | - $prepend_code['header_prive_css'] .= $code; |
|
| 1210 | - } |
|
| 1211 | - } |
|
| 1212 | - } |
|
| 1213 | - if (!isset($prepend_code['insert_head'])) { |
|
| 1214 | - $prepend_code['insert_head'] = ""; |
|
| 1215 | - } |
|
| 1216 | - if (!isset($prepend_code['header_prive'])) { |
|
| 1217 | - $prepend_code['header_prive'] = ""; |
|
| 1218 | - } |
|
| 1219 | - if (isset($info['script']) and count($info['script'])) { |
|
| 1220 | - foreach ($info['script'] as $script) { |
|
| 1221 | - if (isset($script['path']) and $script['path']) { |
|
| 1222 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1223 | - } else { |
|
| 1224 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1225 | - } |
|
| 1226 | - $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1227 | - if ($script['type'] != 'prive') { |
|
| 1228 | - $prepend_code['insert_head'] .= $code; |
|
| 1229 | - } |
|
| 1230 | - if ($script['type'] != 'public') { |
|
| 1231 | - $prepend_code['header_prive'] .= $code; |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - } |
|
| 1235 | - } |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - $prepend_code['insert_head'] = |
|
| 1239 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1240 | - . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1241 | - . $prepend_code['insert_head']; |
|
| 1242 | - $prepend_code['header_prive'] = |
|
| 1243 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1244 | - . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1245 | - . $prepend_code['header_prive']; |
|
| 1246 | - |
|
| 1247 | - // on ajoute les pipe qui ont ete recenses manquants |
|
| 1248 | - foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1249 | - if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1250 | - $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1251 | - } |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - return $prepend_code; |
|
| 1125 | + static $liste_pipe_manquants = array(); |
|
| 1126 | + if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1127 | + $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + $prepend_code = array(); |
|
| 1131 | + |
|
| 1132 | + foreach ($ordre as $p => $info) { |
|
| 1133 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1134 | + if (isset($plugin_valides[$p])) { |
|
| 1135 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1136 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1137 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1138 | + $prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_"); |
|
| 1139 | + if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1140 | + foreach ($info['pipeline'] as $pipe) { |
|
| 1141 | + $nom = $pipe['nom']; |
|
| 1142 | + if (isset($pipe['action'])) { |
|
| 1143 | + $action = $pipe['action']; |
|
| 1144 | + } else { |
|
| 1145 | + $action = $nom; |
|
| 1146 | + } |
|
| 1147 | + $nomlower = strtolower($nom); |
|
| 1148 | + if ($nomlower != $nom |
|
| 1149 | + and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1150 | + and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1151 | + ) { |
|
| 1152 | + $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1153 | + unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1154 | + } |
|
| 1155 | + $nom = $nomlower; |
|
| 1156 | + // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1157 | + if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel |
|
| 1158 | + { |
|
| 1159 | + $GLOBALS['spip_pipeline'][$nom] = ""; |
|
| 1160 | + } |
|
| 1161 | + if ($action) { |
|
| 1162 | + if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) { |
|
| 1163 | + $GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1", |
|
| 1164 | + $GLOBALS['spip_pipeline'][$nom], 1); |
|
| 1165 | + } |
|
| 1166 | + if (isset($pipe['inclure'])) { |
|
| 1167 | + $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1168 | + "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1169 | + } |
|
| 1170 | + } |
|
| 1171 | + } |
|
| 1172 | + } |
|
| 1173 | + if (isset($info['genie']) and count($info['genie'])) { |
|
| 1174 | + if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1175 | + $prepend_code['taches_generales_cron'] = ""; |
|
| 1176 | + } |
|
| 1177 | + foreach ($info['genie'] as $genie) { |
|
| 1178 | + $nom = $prefix . $genie['nom']; |
|
| 1179 | + $periode = max(60, intval($genie['periode'])); |
|
| 1180 | + if (charger_fonction($nom, "genie", true)) { |
|
| 1181 | + $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1182 | + } else { |
|
| 1183 | + spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1184 | + } |
|
| 1185 | + } |
|
| 1186 | + } |
|
| 1187 | + if (isset($info['style']) and count($info['style'])) { |
|
| 1188 | + if (!isset($prepend_code['insert_head_css'])) { |
|
| 1189 | + $prepend_code['insert_head_css'] = ""; |
|
| 1190 | + } |
|
| 1191 | + if (!isset($prepend_code['header_prive_css'])) { |
|
| 1192 | + $prepend_code['header_prive_css'] = ""; |
|
| 1193 | + } |
|
| 1194 | + foreach ($info['style'] as $style) { |
|
| 1195 | + if (isset($style['path']) and $style['path']) { |
|
| 1196 | + $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1197 | + } else { |
|
| 1198 | + $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1199 | + } |
|
| 1200 | + $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1201 | + if (isset($style['media']) and strlen($style['media'])) { |
|
| 1202 | + $code .= " media=\"" . addslashes($style['media']) . "\""; |
|
| 1203 | + } |
|
| 1204 | + $code .= "/>';\n"; |
|
| 1205 | + if ($style['type'] != 'prive') { |
|
| 1206 | + $prepend_code['insert_head_css'] .= $code; |
|
| 1207 | + } |
|
| 1208 | + if ($style['type'] != 'public') { |
|
| 1209 | + $prepend_code['header_prive_css'] .= $code; |
|
| 1210 | + } |
|
| 1211 | + } |
|
| 1212 | + } |
|
| 1213 | + if (!isset($prepend_code['insert_head'])) { |
|
| 1214 | + $prepend_code['insert_head'] = ""; |
|
| 1215 | + } |
|
| 1216 | + if (!isset($prepend_code['header_prive'])) { |
|
| 1217 | + $prepend_code['header_prive'] = ""; |
|
| 1218 | + } |
|
| 1219 | + if (isset($info['script']) and count($info['script'])) { |
|
| 1220 | + foreach ($info['script'] as $script) { |
|
| 1221 | + if (isset($script['path']) and $script['path']) { |
|
| 1222 | + $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1223 | + } else { |
|
| 1224 | + $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1225 | + } |
|
| 1226 | + $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1227 | + if ($script['type'] != 'prive') { |
|
| 1228 | + $prepend_code['insert_head'] .= $code; |
|
| 1229 | + } |
|
| 1230 | + if ($script['type'] != 'public') { |
|
| 1231 | + $prepend_code['header_prive'] .= $code; |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + } |
|
| 1235 | + } |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + $prepend_code['insert_head'] = |
|
| 1239 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1240 | + . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1241 | + . $prepend_code['insert_head']; |
|
| 1242 | + $prepend_code['header_prive'] = |
|
| 1243 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1244 | + . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1245 | + . $prepend_code['header_prive']; |
|
| 1246 | + |
|
| 1247 | + // on ajoute les pipe qui ont ete recenses manquants |
|
| 1248 | + foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1249 | + if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1250 | + $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1251 | + } |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + return $prepend_code; |
|
| 1255 | 1255 | } |
| 1256 | 1256 | |
| 1257 | 1257 | /** |
@@ -1278,44 +1278,44 @@ discard block |
||
| 1278 | 1278 | **/ |
| 1279 | 1279 | function pipeline_precompile($prepend_code = array()) { |
| 1280 | 1280 | |
| 1281 | - $content = ""; |
|
| 1282 | - foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1283 | - $s_inc = ""; |
|
| 1284 | - $s_call = ""; |
|
| 1285 | - $pipe = array_filter(explode('|', $pipeline)); |
|
| 1286 | - // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1287 | - foreach ($pipe as $fonc) { |
|
| 1288 | - $fonc = trim($fonc); |
|
| 1289 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1290 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1291 | - $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1292 | - $file = "'$file'"; |
|
| 1293 | - // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1294 | - if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums", $file, $regs)) { |
|
| 1295 | - $dir = $regs[1]; |
|
| 1296 | - $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1297 | - if (defined($root_dir)) { |
|
| 1298 | - $dir = $root_dir; |
|
| 1299 | - } |
|
| 1300 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1301 | - $file = str_replace("''.", "", $file); |
|
| 1302 | - $file = str_replace(constant($dir), '', $file); |
|
| 1303 | - } |
|
| 1304 | - $s_inc .= "include_once_check($file);\n"; |
|
| 1305 | - } |
|
| 1306 | - } |
|
| 1307 | - if (strlen($s_inc)) { |
|
| 1308 | - $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1309 | - } |
|
| 1310 | - $content .= "// Pipeline $action \n" |
|
| 1311 | - . "function execute_pipeline_$action(&\$val){\n" |
|
| 1312 | - . $s_inc |
|
| 1313 | - . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1314 | - . $s_call |
|
| 1315 | - . "return \$val;\n}\n"; |
|
| 1316 | - } |
|
| 1317 | - ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1318 | - clear_path_cache(); |
|
| 1281 | + $content = ""; |
|
| 1282 | + foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1283 | + $s_inc = ""; |
|
| 1284 | + $s_call = ""; |
|
| 1285 | + $pipe = array_filter(explode('|', $pipeline)); |
|
| 1286 | + // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1287 | + foreach ($pipe as $fonc) { |
|
| 1288 | + $fonc = trim($fonc); |
|
| 1289 | + $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1290 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1291 | + $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1292 | + $file = "'$file'"; |
|
| 1293 | + // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1294 | + if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums", $file, $regs)) { |
|
| 1295 | + $dir = $regs[1]; |
|
| 1296 | + $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1297 | + if (defined($root_dir)) { |
|
| 1298 | + $dir = $root_dir; |
|
| 1299 | + } |
|
| 1300 | + $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1301 | + $file = str_replace("''.", "", $file); |
|
| 1302 | + $file = str_replace(constant($dir), '', $file); |
|
| 1303 | + } |
|
| 1304 | + $s_inc .= "include_once_check($file);\n"; |
|
| 1305 | + } |
|
| 1306 | + } |
|
| 1307 | + if (strlen($s_inc)) { |
|
| 1308 | + $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1309 | + } |
|
| 1310 | + $content .= "// Pipeline $action \n" |
|
| 1311 | + . "function execute_pipeline_$action(&\$val){\n" |
|
| 1312 | + . $s_inc |
|
| 1313 | + . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1314 | + . $s_call |
|
| 1315 | + . "return \$val;\n}\n"; |
|
| 1316 | + } |
|
| 1317 | + ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1318 | + clear_path_cache(); |
|
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | 1321 | |
@@ -1328,12 +1328,12 @@ discard block |
||
| 1328 | 1328 | * true si le plugin est actif, false sinon |
| 1329 | 1329 | **/ |
| 1330 | 1330 | function plugin_est_installe($plug_path) { |
| 1331 | - $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : array(); |
|
| 1332 | - if (!$plugin_installes) { |
|
| 1333 | - return false; |
|
| 1334 | - } |
|
| 1331 | + $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : array(); |
|
| 1332 | + if (!$plugin_installes) { |
|
| 1333 | + return false; |
|
| 1334 | + } |
|
| 1335 | 1335 | |
| 1336 | - return in_array($plug_path, $plugin_installes); |
|
| 1336 | + return in_array($plug_path, $plugin_installes); |
|
| 1337 | 1337 | } |
| 1338 | 1338 | |
| 1339 | 1339 | |
@@ -1346,37 +1346,37 @@ discard block |
||
| 1346 | 1346 | * @uses plugins_installer_dist() |
| 1347 | 1347 | **/ |
| 1348 | 1348 | function plugin_installes_meta() { |
| 1349 | - if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1350 | - // attendre eventuellement l'invalidation du cache opcode |
|
| 1351 | - spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1352 | - } |
|
| 1353 | - |
|
| 1354 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1355 | - $meta_plug_installes = array(); |
|
| 1356 | - foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1357 | - if ($plug = $resume['dir']) { |
|
| 1358 | - $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1359 | - if ($infos) { |
|
| 1360 | - if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1361 | - $meta_plug_installes[] = $plug; |
|
| 1362 | - } |
|
| 1363 | - if (is_array($infos)) { |
|
| 1364 | - list($ok, $trace) = $infos['install_test']; |
|
| 1365 | - include_spip('inc/filtres_boites'); |
|
| 1366 | - echo "<div class='install-plugins svp_retour'>" |
|
| 1367 | - . boite_ouvrir(_T('plugin_titre_installation', array('plugin' => typo($infos['nom']))), |
|
| 1368 | - ($ok ? 'success' : 'error')) |
|
| 1369 | - . $trace |
|
| 1370 | - . "<div class='result'>" |
|
| 1371 | - . ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T("plugin_info_upgrade_ok") : _T("plugin_info_install_ok")) : _T("avis_operation_echec")) |
|
| 1372 | - . "</div>" |
|
| 1373 | - . boite_fermer() |
|
| 1374 | - . "</div>"; |
|
| 1375 | - } |
|
| 1376 | - } |
|
| 1377 | - } |
|
| 1378 | - } |
|
| 1379 | - ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1349 | + if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1350 | + // attendre eventuellement l'invalidation du cache opcode |
|
| 1351 | + spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1352 | + } |
|
| 1353 | + |
|
| 1354 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1355 | + $meta_plug_installes = array(); |
|
| 1356 | + foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1357 | + if ($plug = $resume['dir']) { |
|
| 1358 | + $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1359 | + if ($infos) { |
|
| 1360 | + if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1361 | + $meta_plug_installes[] = $plug; |
|
| 1362 | + } |
|
| 1363 | + if (is_array($infos)) { |
|
| 1364 | + list($ok, $trace) = $infos['install_test']; |
|
| 1365 | + include_spip('inc/filtres_boites'); |
|
| 1366 | + echo "<div class='install-plugins svp_retour'>" |
|
| 1367 | + . boite_ouvrir(_T('plugin_titre_installation', array('plugin' => typo($infos['nom']))), |
|
| 1368 | + ($ok ? 'success' : 'error')) |
|
| 1369 | + . $trace |
|
| 1370 | + . "<div class='result'>" |
|
| 1371 | + . ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T("plugin_info_upgrade_ok") : _T("plugin_info_install_ok")) : _T("avis_operation_echec")) |
|
| 1372 | + . "</div>" |
|
| 1373 | + . boite_fermer() |
|
| 1374 | + . "</div>"; |
|
| 1375 | + } |
|
| 1376 | + } |
|
| 1377 | + } |
|
| 1378 | + } |
|
| 1379 | + ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1380 | 1380 | } |
| 1381 | 1381 | |
| 1382 | 1382 | /** |
@@ -1390,29 +1390,29 @@ discard block |
||
| 1390 | 1390 | * Commentaire : code écrit en tout début de fichier, après la balise PHP ouvrante |
| 1391 | 1391 | **/ |
| 1392 | 1392 | function ecrire_fichier_php($nom, $contenu, $comment = '') { |
| 1393 | - if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1394 | - $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1395 | - } |
|
| 1396 | - |
|
| 1397 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1398 | - // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1399 | - // si pas de modif on ne touche pas au fichier initial |
|
| 1400 | - if (file_exists($nom)) { |
|
| 1401 | - if (substr($nom, -4) == '.php') { |
|
| 1402 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1403 | - } |
|
| 1404 | - else { |
|
| 1405 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1406 | - } |
|
| 1407 | - file_put_contents($fichier_tmp, $contenu); |
|
| 1408 | - if(md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1409 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1410 | - @unlink($fichier_tmp); |
|
| 1411 | - return; |
|
| 1412 | - } |
|
| 1413 | - @unlink($fichier_tmp); |
|
| 1414 | - } |
|
| 1415 | - ecrire_fichier($nom, $contenu); |
|
| 1416 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1417 | - spip_clear_opcode_cache(realpath($nom)); |
|
| 1393 | + if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1394 | + $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1398 | + // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1399 | + // si pas de modif on ne touche pas au fichier initial |
|
| 1400 | + if (file_exists($nom)) { |
|
| 1401 | + if (substr($nom, -4) == '.php') { |
|
| 1402 | + $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1403 | + } |
|
| 1404 | + else { |
|
| 1405 | + $fichier_tmp = $nom . '.tmp'; |
|
| 1406 | + } |
|
| 1407 | + file_put_contents($fichier_tmp, $contenu); |
|
| 1408 | + if(md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1409 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1410 | + @unlink($fichier_tmp); |
|
| 1411 | + return; |
|
| 1412 | + } |
|
| 1413 | + @unlink($fichier_tmp); |
|
| 1414 | + } |
|
| 1415 | + ecrire_fichier($nom, $contenu); |
|
| 1416 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1417 | + spip_clear_opcode_cache(realpath($nom)); |
|
| 1418 | 1418 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -47,23 +47,23 @@ discard block |
||
| 47 | 47 | * - false si l'arbre xml ne peut être créé ou est vide |
| 48 | 48 | **/ |
| 49 | 49 | function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1048576, $datas = '', $profondeur = -1) { |
| 50 | - $contenu = ""; |
|
| 51 | - if (tester_url_absolue($fichier)) { |
|
| 52 | - include_spip('inc/distant'); |
|
| 53 | - $contenu = recuperer_page($fichier, false, false, $taille_max, $datas); |
|
| 54 | - } else { |
|
| 55 | - lire_fichier($fichier, $contenu); |
|
| 56 | - } |
|
| 57 | - $arbre = array(); |
|
| 58 | - if ($contenu) { |
|
| 59 | - $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | - } |
|
| 50 | + $contenu = ""; |
|
| 51 | + if (tester_url_absolue($fichier)) { |
|
| 52 | + include_spip('inc/distant'); |
|
| 53 | + $contenu = recuperer_page($fichier, false, false, $taille_max, $datas); |
|
| 54 | + } else { |
|
| 55 | + lire_fichier($fichier, $contenu); |
|
| 56 | + } |
|
| 57 | + $arbre = array(); |
|
| 58 | + if ($contenu) { |
|
| 59 | + $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return count($arbre) ? $arbre : false; |
|
| 62 | + return count($arbre) ? $arbre : false; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | if (!defined('_SPIP_XML_TAG_SPLIT')) { |
| 66 | - define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS"); |
|
| 66 | + define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS"); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -82,151 +82,151 @@ discard block |
||
| 82 | 82 | * - false si l'arbre xml ne peut être créé ou est vide |
| 83 | 83 | **/ |
| 84 | 84 | function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) { |
| 85 | - $out = array(); |
|
| 86 | - // enlever les commentaires |
|
| 87 | - $charset = 'AUTO'; |
|
| 88 | - if ($clean === true) { |
|
| 89 | - if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | - $charset = $regs[2]; |
|
| 91 | - } |
|
| 92 | - $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | - $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | - include_spip('inc/charsets'); |
|
| 95 | - $clean = $charset; |
|
| 96 | - //$texte = importer_charset($texte,$charset); |
|
| 97 | - } |
|
| 98 | - if (is_string($clean)) { |
|
| 99 | - $charset = $clean; |
|
| 100 | - } |
|
| 101 | - $txt = $texte; |
|
| 85 | + $out = array(); |
|
| 86 | + // enlever les commentaires |
|
| 87 | + $charset = 'AUTO'; |
|
| 88 | + if ($clean === true) { |
|
| 89 | + if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | + $charset = $regs[2]; |
|
| 91 | + } |
|
| 92 | + $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | + $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | + include_spip('inc/charsets'); |
|
| 95 | + $clean = $charset; |
|
| 96 | + //$texte = importer_charset($texte,$charset); |
|
| 97 | + } |
|
| 98 | + if (is_string($clean)) { |
|
| 99 | + $charset = $clean; |
|
| 100 | + } |
|
| 101 | + $txt = $texte; |
|
| 102 | 102 | |
| 103 | - // tant qu'il y a des tags |
|
| 104 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | - while (count($chars) >= 2) { |
|
| 106 | - // tag ouvrant |
|
| 107 | - //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 103 | + // tant qu'il y a des tags |
|
| 104 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | + while (count($chars) >= 2) { |
|
| 106 | + // tag ouvrant |
|
| 107 | + //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 108 | 108 | |
| 109 | - // $before doit etre vide ou des espaces uniquements! |
|
| 110 | - $before = trim($chars[0]); |
|
| 109 | + // $before doit etre vide ou des espaces uniquements! |
|
| 110 | + $before = trim($chars[0]); |
|
| 111 | 111 | |
| 112 | - if (strlen($before) > 0) { |
|
| 113 | - return importer_charset($texte, $charset); |
|
| 114 | - }//$texte; // before non vide, donc on est dans du texte |
|
| 112 | + if (strlen($before) > 0) { |
|
| 113 | + return importer_charset($texte, $charset); |
|
| 114 | + }//$texte; // before non vide, donc on est dans du texte |
|
| 115 | 115 | |
| 116 | - $tag = rtrim($chars[1]); |
|
| 117 | - $txt = $chars[2]; |
|
| 116 | + $tag = rtrim($chars[1]); |
|
| 117 | + $txt = $chars[2]; |
|
| 118 | 118 | |
| 119 | - if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 120 | - return importer_charset($texte, $charset); |
|
| 121 | - }//$texte; |
|
| 122 | - if (substr($tag, -1) == '/') { // self closing tag |
|
| 123 | - $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | - $out[$tag][] = ""; |
|
| 125 | - } else { |
|
| 126 | - $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | - $closing_tag = reset($closing_tag); |
|
| 128 | - // tag fermant |
|
| 129 | - $ncclos = strlen("</$closing_tag>"); |
|
| 130 | - $p = strpos($txt, "</$closing_tag>"); |
|
| 131 | - if ($p !== false and (strpos($txt, "<") < $p)) { |
|
| 132 | - $nclose = 0; |
|
| 133 | - $nopen = 0; |
|
| 134 | - $d = 0; |
|
| 135 | - while ( |
|
| 136 | - $p !== false |
|
| 137 | - and ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | - and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 139 | - $matches, PREG_SET_ORDER)) > $nclose) |
|
| 140 | - ) { |
|
| 141 | - $nclose++; |
|
| 142 | - $d = $p + $ncclos; |
|
| 143 | - $p = strpos($txt, "</$closing_tag>", $d); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - if ($p === false) { |
|
| 147 | - if ($strict) { |
|
| 148 | - $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 119 | + if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 120 | + return importer_charset($texte, $charset); |
|
| 121 | + }//$texte; |
|
| 122 | + if (substr($tag, -1) == '/') { // self closing tag |
|
| 123 | + $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | + $out[$tag][] = ""; |
|
| 125 | + } else { |
|
| 126 | + $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | + $closing_tag = reset($closing_tag); |
|
| 128 | + // tag fermant |
|
| 129 | + $ncclos = strlen("</$closing_tag>"); |
|
| 130 | + $p = strpos($txt, "</$closing_tag>"); |
|
| 131 | + if ($p !== false and (strpos($txt, "<") < $p)) { |
|
| 132 | + $nclose = 0; |
|
| 133 | + $nopen = 0; |
|
| 134 | + $d = 0; |
|
| 135 | + while ( |
|
| 136 | + $p !== false |
|
| 137 | + and ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | + and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 139 | + $matches, PREG_SET_ORDER)) > $nclose) |
|
| 140 | + ) { |
|
| 141 | + $nclose++; |
|
| 142 | + $d = $p + $ncclos; |
|
| 143 | + $p = strpos($txt, "</$closing_tag>", $d); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + if ($p === false) { |
|
| 147 | + if ($strict) { |
|
| 148 | + $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 149 | 149 | |
| 150 | - return $out; |
|
| 151 | - } else { |
|
| 152 | - return importer_charset($texte, $charset); |
|
| 153 | - }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 154 | - } |
|
| 155 | - $content = substr($txt, 0, $p); |
|
| 156 | - $txt = substr($txt, $p + $ncclos); |
|
| 157 | - if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 158 | - { |
|
| 159 | - $out[$tag][] = importer_charset($content, $charset); |
|
| 160 | - }//$content; |
|
| 161 | - else { |
|
| 162 | - $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 166 | - } |
|
| 167 | - if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 168 | - return $out; |
|
| 169 | - } else { |
|
| 170 | - return importer_charset($texte, $charset); |
|
| 171 | - }//$texte; |
|
| 150 | + return $out; |
|
| 151 | + } else { |
|
| 152 | + return importer_charset($texte, $charset); |
|
| 153 | + }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 154 | + } |
|
| 155 | + $content = substr($txt, 0, $p); |
|
| 156 | + $txt = substr($txt, $p + $ncclos); |
|
| 157 | + if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 158 | + { |
|
| 159 | + $out[$tag][] = importer_charset($content, $charset); |
|
| 160 | + }//$content; |
|
| 161 | + else { |
|
| 162 | + $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 166 | + } |
|
| 167 | + if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 168 | + return $out; |
|
| 169 | + } else { |
|
| 170 | + return importer_charset($texte, $charset); |
|
| 171 | + }//$texte; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // http://code.spip.net/@spip_xml_aplatit |
| 175 | 175 | function spip_xml_aplatit($arbre, $separateur = " ") { |
| 176 | - $s = ""; |
|
| 177 | - if (is_array($arbre)) { |
|
| 178 | - foreach ($arbre as $tag => $feuille) { |
|
| 179 | - if (is_array($feuille)) { |
|
| 180 | - if ($tag !== intval($tag)) { |
|
| 181 | - $f = spip_xml_aplatit($feuille, $separateur); |
|
| 182 | - if (strlen($f)) { |
|
| 183 | - $tagf = explode(" ", $tag); |
|
| 184 | - $tagf = $tagf[0]; |
|
| 185 | - $s .= "<$tag>$f</$tagf>"; |
|
| 186 | - } else { |
|
| 187 | - $s .= "<$tag />"; |
|
| 188 | - } |
|
| 189 | - } else { |
|
| 190 | - $s .= spip_xml_aplatit($feuille); |
|
| 191 | - } |
|
| 192 | - $s .= $separateur; |
|
| 193 | - } else { |
|
| 194 | - $s .= "$feuille$separateur"; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 176 | + $s = ""; |
|
| 177 | + if (is_array($arbre)) { |
|
| 178 | + foreach ($arbre as $tag => $feuille) { |
|
| 179 | + if (is_array($feuille)) { |
|
| 180 | + if ($tag !== intval($tag)) { |
|
| 181 | + $f = spip_xml_aplatit($feuille, $separateur); |
|
| 182 | + if (strlen($f)) { |
|
| 183 | + $tagf = explode(" ", $tag); |
|
| 184 | + $tagf = $tagf[0]; |
|
| 185 | + $s .= "<$tag>$f</$tagf>"; |
|
| 186 | + } else { |
|
| 187 | + $s .= "<$tag />"; |
|
| 188 | + } |
|
| 189 | + } else { |
|
| 190 | + $s .= spip_xml_aplatit($feuille); |
|
| 191 | + } |
|
| 192 | + $s .= $separateur; |
|
| 193 | + } else { |
|
| 194 | + $s .= "$feuille$separateur"; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 199 | + return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // http://code.spip.net/@spip_xml_tagname |
| 203 | 203 | function spip_xml_tagname($tag) { |
| 204 | - if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 205 | - return $reg[1]; |
|
| 206 | - } |
|
| 204 | + if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 205 | + return $reg[1]; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - return ""; |
|
| 208 | + return ""; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // http://code.spip.net/@spip_xml_decompose_tag |
| 212 | 212 | function spip_xml_decompose_tag($tag) { |
| 213 | - $tagname = spip_xml_tagname($tag); |
|
| 214 | - $liste = array(); |
|
| 215 | - $p = strpos($tag, ' '); |
|
| 216 | - $tag = substr($tag, $p); |
|
| 217 | - $p = strpos($tag, '='); |
|
| 218 | - while ($p !== false) { |
|
| 219 | - $attr = trim(substr($tag, 0, $p)); |
|
| 220 | - $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | - $quote = $tag[0]; |
|
| 222 | - $p = strpos($tag, $quote, 1); |
|
| 223 | - $cont = substr($tag, 1, $p - 1); |
|
| 224 | - $liste[$attr] = $cont; |
|
| 225 | - $tag = substr($tag, $p + 1); |
|
| 226 | - $p = strpos($tag, '='); |
|
| 227 | - } |
|
| 213 | + $tagname = spip_xml_tagname($tag); |
|
| 214 | + $liste = array(); |
|
| 215 | + $p = strpos($tag, ' '); |
|
| 216 | + $tag = substr($tag, $p); |
|
| 217 | + $p = strpos($tag, '='); |
|
| 218 | + while ($p !== false) { |
|
| 219 | + $attr = trim(substr($tag, 0, $p)); |
|
| 220 | + $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | + $quote = $tag[0]; |
|
| 222 | + $p = strpos($tag, $quote, 1); |
|
| 223 | + $cont = substr($tag, 1, $p - 1); |
|
| 224 | + $liste[$attr] = $cont; |
|
| 225 | + $tag = substr($tag, $p + 1); |
|
| 226 | + $p = strpos($tag, '='); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - return array($tagname, $liste); |
|
| 229 | + return array($tagname, $liste); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 250 | 250 | **/ |
| 251 | 251 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
| 252 | - if ($init) { |
|
| 253 | - $matches = array(); |
|
| 254 | - } |
|
| 255 | - if (is_array($arbre) && count($arbre)) { |
|
| 256 | - foreach (array_keys($arbre) as $tag) { |
|
| 257 | - if (preg_match($regexp, $tag)) { |
|
| 258 | - $matches[$tag] = &$arbre[$tag]; |
|
| 259 | - } |
|
| 260 | - if (is_array($arbre[$tag])) { |
|
| 261 | - foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | - spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 252 | + if ($init) { |
|
| 253 | + $matches = array(); |
|
| 254 | + } |
|
| 255 | + if (is_array($arbre) && count($arbre)) { |
|
| 256 | + foreach (array_keys($arbre) as $tag) { |
|
| 257 | + if (preg_match($regexp, $tag)) { |
|
| 258 | + $matches[$tag] = &$arbre[$tag]; |
|
| 259 | + } |
|
| 260 | + if (is_array($arbre[$tag])) { |
|
| 261 | + foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | + spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - return (count($matches)); |
|
| 268 | + return (count($matches)); |
|
| 269 | 269 | } |