@@ -17,18 +17,18 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_ACTIVER_PUCE_RAPIDE')) { |
| 24 | - /** |
|
| 25 | - * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 26 | - * |
|
| 27 | - * Peut ralentir un site sur des listes très longues. |
|
| 28 | - * |
|
| 29 | - * @var bool |
|
| 30 | - **/ |
|
| 31 | - define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 24 | + /** |
|
| 25 | + * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 26 | + * |
|
| 27 | + * Peut ralentir un site sur des listes très longues. |
|
| 28 | + * |
|
| 29 | + * @var bool |
|
| 30 | + **/ |
|
| 31 | + define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -56,31 +56,31 @@ discard block |
||
| 56 | 56 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 57 | 57 | */ |
| 58 | 58 | function inc_puce_statut_dist( |
| 59 | - $id_objet, |
|
| 60 | - $statut, |
|
| 61 | - $id_parent, |
|
| 62 | - $type, |
|
| 63 | - $ajax = false, |
|
| 64 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 59 | + $id_objet, |
|
| 60 | + $statut, |
|
| 61 | + $id_parent, |
|
| 62 | + $type, |
|
| 63 | + $ajax = false, |
|
| 64 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 65 | 65 | ) { |
| 66 | - static $f_puce_statut = []; |
|
| 67 | - $type = objet_type($type); |
|
| 68 | - // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 69 | - if (!isset($f_puce_statut[$type]) || is_null($f_puce_statut[$type])) { |
|
| 70 | - $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 71 | - } |
|
| 72 | - if ($f_puce_statut[$type]) { |
|
| 73 | - return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 77 | - // composer une puce, avec si possible changement rapide |
|
| 78 | - elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 79 | - return $puce; |
|
| 80 | - } // sinon fausse puce avec le type de l'image |
|
| 81 | - else { |
|
| 82 | - return http_img_pack("$type-16.png", ''); |
|
| 83 | - } |
|
| 66 | + static $f_puce_statut = []; |
|
| 67 | + $type = objet_type($type); |
|
| 68 | + // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 69 | + if (!isset($f_puce_statut[$type]) || is_null($f_puce_statut[$type])) { |
|
| 70 | + $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 71 | + } |
|
| 72 | + if ($f_puce_statut[$type]) { |
|
| 73 | + return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 77 | + // composer une puce, avec si possible changement rapide |
|
| 78 | + elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 79 | + return $puce; |
|
| 80 | + } // sinon fausse puce avec le type de l'image |
|
| 81 | + else { |
|
| 82 | + return http_img_pack("$type-16.png", ''); |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -109,41 +109,41 @@ discard block |
||
| 109 | 109 | * null si pas capable de déterminer l'image |
| 110 | 110 | */ |
| 111 | 111 | function statut_image($objet, $statut) { |
| 112 | - $src = null; |
|
| 113 | - $table = table_objet_sql($objet); |
|
| 114 | - $desc = lister_tables_objets_sql($table); |
|
| 115 | - if (isset($desc['statut_images'])) { |
|
| 116 | - // si une declaration statut_images |
|
| 117 | - // mais rien pour le statut demande, ne rien afficher |
|
| 118 | - $src = ''; |
|
| 119 | - if (isset($desc['statut_images'][$statut])) { |
|
| 120 | - $src = $desc['statut_images'][$statut]; |
|
| 121 | - } // sinon image par defaut ? |
|
| 122 | - elseif (isset($desc['statut_images'][0])) { |
|
| 123 | - $src = $desc['statut_images'][0]; |
|
| 124 | - } |
|
| 125 | - } else { |
|
| 126 | - switch ($statut) { |
|
| 127 | - case 'prepa': |
|
| 128 | - $src = 'puce-preparer-xx.svg?12px'; |
|
| 129 | - break; |
|
| 130 | - case 'prop': |
|
| 131 | - $src = 'puce-proposer-xx.svg?12px'; |
|
| 132 | - break; |
|
| 133 | - case 'publie': |
|
| 134 | - $src = 'puce-publier-xx.svg?12px'; |
|
| 135 | - break; |
|
| 136 | - case 'refuse': |
|
| 137 | - $src = 'puce-refuser-xx.svg?12px'; |
|
| 138 | - break; |
|
| 139 | - case 'poubelle': |
|
| 140 | - case 'poub': |
|
| 141 | - $src = 'puce-supprimer-xx.svg?12px'; |
|
| 142 | - break; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $src; |
|
| 112 | + $src = null; |
|
| 113 | + $table = table_objet_sql($objet); |
|
| 114 | + $desc = lister_tables_objets_sql($table); |
|
| 115 | + if (isset($desc['statut_images'])) { |
|
| 116 | + // si une declaration statut_images |
|
| 117 | + // mais rien pour le statut demande, ne rien afficher |
|
| 118 | + $src = ''; |
|
| 119 | + if (isset($desc['statut_images'][$statut])) { |
|
| 120 | + $src = $desc['statut_images'][$statut]; |
|
| 121 | + } // sinon image par defaut ? |
|
| 122 | + elseif (isset($desc['statut_images'][0])) { |
|
| 123 | + $src = $desc['statut_images'][0]; |
|
| 124 | + } |
|
| 125 | + } else { |
|
| 126 | + switch ($statut) { |
|
| 127 | + case 'prepa': |
|
| 128 | + $src = 'puce-preparer-xx.svg?12px'; |
|
| 129 | + break; |
|
| 130 | + case 'prop': |
|
| 131 | + $src = 'puce-proposer-xx.svg?12px'; |
|
| 132 | + break; |
|
| 133 | + case 'publie': |
|
| 134 | + $src = 'puce-publier-xx.svg?12px'; |
|
| 135 | + break; |
|
| 136 | + case 'refuse': |
|
| 137 | + $src = 'puce-refuser-xx.svg?12px'; |
|
| 138 | + break; |
|
| 139 | + case 'poubelle': |
|
| 140 | + case 'poub': |
|
| 141 | + $src = 'puce-supprimer-xx.svg?12px'; |
|
| 142 | + break; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $src; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -171,40 +171,40 @@ discard block |
||
| 171 | 171 | * @return string |
| 172 | 172 | */ |
| 173 | 173 | function statut_titre($objet, $statut) { |
| 174 | - $titre = ''; |
|
| 175 | - $table = table_objet_sql($objet); |
|
| 176 | - $desc = lister_tables_objets_sql($table); |
|
| 177 | - if (isset($desc['statut_titres'])) { |
|
| 178 | - // si une declaration statut_titres |
|
| 179 | - // mais rien pour le statut demande, ne rien afficher |
|
| 180 | - if (isset($desc['statut_titres'][$statut])) { |
|
| 181 | - $titre = $desc['statut_titres'][$statut]; |
|
| 182 | - } // sinon image par defaut ? |
|
| 183 | - elseif (isset($desc['statut_titres'][0])) { |
|
| 184 | - $titre = $desc['statut_titres'][0]; |
|
| 185 | - } |
|
| 186 | - } else { |
|
| 187 | - switch ($statut) { |
|
| 188 | - case 'prepa': |
|
| 189 | - $titre = 'texte_statut_en_cours_redaction'; |
|
| 190 | - break; |
|
| 191 | - case 'prop': |
|
| 192 | - $titre = 'texte_statut_propose_evaluation'; |
|
| 193 | - break; |
|
| 194 | - case 'publie': |
|
| 195 | - $titre = 'texte_statut_publie'; |
|
| 196 | - break; |
|
| 197 | - case 'refuse': |
|
| 198 | - $titre = 'texte_statut_refuse'; |
|
| 199 | - break; |
|
| 200 | - case 'poubelle': |
|
| 201 | - case 'poub': |
|
| 202 | - $titre = 'texte_statut_poubelle'; |
|
| 203 | - break; |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - return $titre ? _T($titre) : ''; |
|
| 174 | + $titre = ''; |
|
| 175 | + $table = table_objet_sql($objet); |
|
| 176 | + $desc = lister_tables_objets_sql($table); |
|
| 177 | + if (isset($desc['statut_titres'])) { |
|
| 178 | + // si une declaration statut_titres |
|
| 179 | + // mais rien pour le statut demande, ne rien afficher |
|
| 180 | + if (isset($desc['statut_titres'][$statut])) { |
|
| 181 | + $titre = $desc['statut_titres'][$statut]; |
|
| 182 | + } // sinon image par defaut ? |
|
| 183 | + elseif (isset($desc['statut_titres'][0])) { |
|
| 184 | + $titre = $desc['statut_titres'][0]; |
|
| 185 | + } |
|
| 186 | + } else { |
|
| 187 | + switch ($statut) { |
|
| 188 | + case 'prepa': |
|
| 189 | + $titre = 'texte_statut_en_cours_redaction'; |
|
| 190 | + break; |
|
| 191 | + case 'prop': |
|
| 192 | + $titre = 'texte_statut_propose_evaluation'; |
|
| 193 | + break; |
|
| 194 | + case 'publie': |
|
| 195 | + $titre = 'texte_statut_publie'; |
|
| 196 | + break; |
|
| 197 | + case 'refuse': |
|
| 198 | + $titre = 'texte_statut_refuse'; |
|
| 199 | + break; |
|
| 200 | + case 'poubelle': |
|
| 201 | + case 'poub': |
|
| 202 | + $titre = 'texte_statut_poubelle'; |
|
| 203 | + break; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + return $titre ? _T($titre) : ''; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
@@ -224,37 +224,37 @@ discard block |
||
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | 226 | function statut_texte_instituer($objet, $statut) { |
| 227 | - $texte = ''; |
|
| 228 | - $table = table_objet_sql($objet); |
|
| 229 | - $desc = lister_tables_objets_sql($table); |
|
| 230 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 231 | - // si une declaration statut_titres |
|
| 232 | - // mais rien pour le statut demande, ne rien afficher |
|
| 233 | - if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 234 | - $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 235 | - } |
|
| 236 | - } else { |
|
| 237 | - switch ($statut) { |
|
| 238 | - case 'prepa': |
|
| 239 | - $texte = 'texte_statut_en_cours_redaction'; |
|
| 240 | - break; |
|
| 241 | - case 'prop': |
|
| 242 | - $texte = 'texte_statut_propose_evaluation'; |
|
| 243 | - break; |
|
| 244 | - case 'publie': |
|
| 245 | - $texte = 'texte_statut_publie'; |
|
| 246 | - break; |
|
| 247 | - case 'refuse': |
|
| 248 | - $texte = 'texte_statut_refuse'; |
|
| 249 | - break; |
|
| 250 | - case 'poubelle': |
|
| 251 | - case 'poub': |
|
| 252 | - $texte = 'texte_statut_poubelle'; |
|
| 253 | - break; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - return $texte ? _T($texte) : ''; |
|
| 227 | + $texte = ''; |
|
| 228 | + $table = table_objet_sql($objet); |
|
| 229 | + $desc = lister_tables_objets_sql($table); |
|
| 230 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 231 | + // si une declaration statut_titres |
|
| 232 | + // mais rien pour le statut demande, ne rien afficher |
|
| 233 | + if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 234 | + $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 235 | + } |
|
| 236 | + } else { |
|
| 237 | + switch ($statut) { |
|
| 238 | + case 'prepa': |
|
| 239 | + $texte = 'texte_statut_en_cours_redaction'; |
|
| 240 | + break; |
|
| 241 | + case 'prop': |
|
| 242 | + $texte = 'texte_statut_propose_evaluation'; |
|
| 243 | + break; |
|
| 244 | + case 'publie': |
|
| 245 | + $texte = 'texte_statut_publie'; |
|
| 246 | + break; |
|
| 247 | + case 'refuse': |
|
| 248 | + $texte = 'texte_statut_refuse'; |
|
| 249 | + break; |
|
| 250 | + case 'poubelle': |
|
| 251 | + case 'poub': |
|
| 252 | + $texte = 'texte_statut_poubelle'; |
|
| 253 | + break; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + return $texte ? _T($texte) : ''; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -274,16 +274,16 @@ discard block |
||
| 274 | 274 | * @return string |
| 275 | 275 | */ |
| 276 | 276 | function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 277 | - $img = statut_image('auteur', $statut); |
|
| 278 | - if (!$img) { |
|
| 279 | - return ''; |
|
| 280 | - } |
|
| 281 | - $alt = statut_titre('auteur', $statut); |
|
| 277 | + $img = statut_image('auteur', $statut); |
|
| 278 | + if (!$img) { |
|
| 279 | + return ''; |
|
| 280 | + } |
|
| 281 | + $alt = statut_titre('auteur', $statut); |
|
| 282 | 282 | |
| 283 | - $fond = ''; |
|
| 284 | - $titre = ''; |
|
| 283 | + $fond = ''; |
|
| 284 | + $titre = ''; |
|
| 285 | 285 | |
| 286 | - /* |
|
| 286 | + /* |
|
| 287 | 287 | if ($type != 'auteur') { |
| 288 | 288 | $img2 = chemin_image('del-16.png'); |
| 289 | 289 | $titre = _T('titre_image_redacteur'); |
@@ -293,12 +293,12 @@ discard block |
||
| 293 | 293 | } |
| 294 | 294 | */ |
| 295 | 295 | |
| 296 | - return http_img_pack($img, $alt, $fond, $alt); |
|
| 296 | + return http_img_pack($img, $alt, $fond, $alt); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
| 300 | 300 | function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 301 | - return http_img_pack('rubrique-16.png', ''); |
|
| 301 | + return http_img_pack('rubrique-16.png', ''); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -322,101 +322,101 @@ discard block |
||
| 322 | 322 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 323 | 323 | **/ |
| 324 | 324 | function puce_statut_changement_rapide( |
| 325 | - $id, |
|
| 326 | - $statut, |
|
| 327 | - $id_rubrique, |
|
| 328 | - $type = 'article', |
|
| 329 | - $ajax = false, |
|
| 330 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 325 | + $id, |
|
| 326 | + $statut, |
|
| 327 | + $id_rubrique, |
|
| 328 | + $type = 'article', |
|
| 329 | + $ajax = false, |
|
| 330 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 331 | 331 | ) { |
| 332 | - $src = statut_image($type, $statut); |
|
| 333 | - if (!$src) { |
|
| 334 | - return $src; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - $ajax_node = (!$id || !_SPIP_AJAX || !$menu_rapide) ? '' : " class='imgstatut$type$id'"; |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - $t = statut_titre($type, $statut); |
|
| 341 | - $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 342 | - |
|
| 343 | - if (!$ajax_node) { |
|
| 344 | - return $inser_puce; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - $table = table_objet_sql($type); |
|
| 348 | - $desc = lister_tables_objets_sql($table); |
|
| 349 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 350 | - return $inser_puce; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if (!function_exists('autoriser')) { |
|
| 354 | - include_spip('inc/autoriser'); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 358 | - if ($id_rubrique) { |
|
| 359 | - if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 360 | - return $inser_puce; |
|
| 361 | - } |
|
| 362 | - } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 363 | - else { |
|
| 364 | - if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 365 | - return $inser_puce; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 370 | - if (!isset($coord[$statut])) { |
|
| 371 | - return $inser_puce; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 375 | - ; |
|
| 376 | - $margin = 0; /* marge a gauche + droite */ |
|
| 377 | - $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 378 | - ; |
|
| 379 | - $clip = $zero + ($unit * $coord[$statut]); |
|
| 380 | - |
|
| 381 | - if ($ajax) { |
|
| 382 | - $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin; |
|
| 383 | - $out = "<span class='puce_objet_fixe $type'>" |
|
| 384 | - . $inser_puce |
|
| 385 | - . '</span>' |
|
| 386 | - . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 387 | - $i = 0; |
|
| 388 | - foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 389 | - $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $out . '</span>'; |
|
| 393 | - } else { |
|
| 394 | - $nom = 'puce_statut_'; |
|
| 395 | - $action = generer_url_ecrire('puce_statut', '', true); |
|
| 396 | - $lang_dir = lang_dir(lang_typo()); |
|
| 397 | - |
|
| 398 | - return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 399 | - . $inser_puce |
|
| 400 | - . '</span>'; |
|
| 401 | - } |
|
| 332 | + $src = statut_image($type, $statut); |
|
| 333 | + if (!$src) { |
|
| 334 | + return $src; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + $ajax_node = (!$id || !_SPIP_AJAX || !$menu_rapide) ? '' : " class='imgstatut$type$id'"; |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + $t = statut_titre($type, $statut); |
|
| 341 | + $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 342 | + |
|
| 343 | + if (!$ajax_node) { |
|
| 344 | + return $inser_puce; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + $table = table_objet_sql($type); |
|
| 348 | + $desc = lister_tables_objets_sql($table); |
|
| 349 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 350 | + return $inser_puce; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if (!function_exists('autoriser')) { |
|
| 354 | + include_spip('inc/autoriser'); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 358 | + if ($id_rubrique) { |
|
| 359 | + if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 360 | + return $inser_puce; |
|
| 361 | + } |
|
| 362 | + } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 363 | + else { |
|
| 364 | + if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 365 | + return $inser_puce; |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 370 | + if (!isset($coord[$statut])) { |
|
| 371 | + return $inser_puce; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 375 | + ; |
|
| 376 | + $margin = 0; /* marge a gauche + droite */ |
|
| 377 | + $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 378 | + ; |
|
| 379 | + $clip = $zero + ($unit * $coord[$statut]); |
|
| 380 | + |
|
| 381 | + if ($ajax) { |
|
| 382 | + $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin; |
|
| 383 | + $out = "<span class='puce_objet_fixe $type'>" |
|
| 384 | + . $inser_puce |
|
| 385 | + . '</span>' |
|
| 386 | + . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 387 | + $i = 0; |
|
| 388 | + foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 389 | + $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $out . '</span>'; |
|
| 393 | + } else { |
|
| 394 | + $nom = 'puce_statut_'; |
|
| 395 | + $action = generer_url_ecrire('puce_statut', '', true); |
|
| 396 | + $lang_dir = lang_dir(lang_typo()); |
|
| 397 | + |
|
| 398 | + return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 399 | + . $inser_puce |
|
| 400 | + . '</span>'; |
|
| 401 | + } |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | |
| 405 | 405 | function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') { |
| 406 | - $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 407 | - $t = supprimer_tags($titre); |
|
| 406 | + $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 407 | + $t = supprimer_tags($titre); |
|
| 408 | 408 | |
| 409 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 409 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | // compat |
| 413 | 413 | // La couleur du statut |
| 414 | 414 | |
| 415 | 415 | function puce_statut($statut, $atts = '') { |
| 416 | - $src = statut_image('article', $statut); |
|
| 417 | - if (!$src) { |
|
| 418 | - return ''; |
|
| 419 | - } |
|
| 416 | + $src = statut_image('article', $statut); |
|
| 417 | + if (!$src) { |
|
| 418 | + return ''; |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 421 | + return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 422 | 422 | } |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - return $out . '</span>'; |
|
| 392 | + return $out.'</span>'; |
|
| 393 | 393 | } else { |
| 394 | 394 | $nom = 'puce_statut_'; |
| 395 | 395 | $action = generer_url_ecrire('puce_statut', '', true); |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
| 407 | 407 | $t = supprimer_tags($titre); |
| 408 | 408 | |
| 409 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 409 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>".http_img_pack($img, $t).'</a>'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | // compat |
@@ -537,8 +537,7 @@ discard block |
||
| 537 | 537 | process_image_svg_identite($ret); |
| 538 | 538 | $ret['creer'] = false; |
| 539 | 539 | } |
| 540 | - } |
|
| 541 | - else { |
|
| 540 | + } else { |
|
| 542 | 541 | if (!function_exists($ret['fonction_imagecreatefrom'])) { |
| 543 | 542 | return false; |
| 544 | 543 | } |
@@ -1356,9 +1355,7 @@ discard block |
||
| 1356 | 1355 | if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
| 1357 | 1356 | $vignette = $destination . '.' . $format; |
| 1358 | 1357 | @copy($image, $vignette); |
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1358 | + } elseif ($valeurs['format_source'] === 'svg') { |
|
| 1362 | 1359 | include_spip('inc/svg'); |
| 1363 | 1360 | if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
| 1364 | 1361 | $format_sortie = 'svg'; |
@@ -1793,8 +1790,7 @@ discard block |
||
| 1793 | 1790 | $date = test_espace_prive() ? ('?' . $date) : ''; |
| 1794 | 1791 | |
| 1795 | 1792 | return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
| 1796 | - } |
|
| 1797 | - else { |
|
| 1793 | + } else { |
|
| 1798 | 1794 | # BMP, tiff ... les redacteurs osent tout! |
| 1799 | 1795 | return $img; |
| 1800 | 1796 | } |
@@ -42,13 +42,13 @@ discard block |
||
| 42 | 42 | $blue = dechex($blue); |
| 43 | 43 | |
| 44 | 44 | if (strlen($red) == 1) { |
| 45 | - $red = '0' . $red; |
|
| 45 | + $red = '0'.$red; |
|
| 46 | 46 | } |
| 47 | 47 | if (strlen($green) == 1) { |
| 48 | - $green = '0' . $green; |
|
| 48 | + $green = '0'.$green; |
|
| 49 | 49 | } |
| 50 | 50 | if (strlen($blue) == 1) { |
| 51 | - $blue = '0' . $blue; |
|
| 51 | + $blue = '0'.$blue; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | return "$red$green$blue"; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $couleur = couleur_html_to_hex($couleur); |
| 68 | 68 | $couleur = ltrim($couleur, '#'); |
| 69 | 69 | if (strlen($couleur) === 3) { |
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 70 | + $couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2]; |
|
| 71 | 71 | } |
| 72 | 72 | $retour = []; |
| 73 | 73 | $retour['red'] = hexdec(substr($couleur, 0, 2)); |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | $var_G = ($G / 255); |
| 126 | 126 | $var_B = ($B / 255); |
| 127 | 127 | |
| 128 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 128 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | 131 | |
| 132 | 132 | $L = ($var_Max + $var_Min) / 2; |
| 133 | 133 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 187 | 187 | // helper |
| 188 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 188 | + $hue_2_rgb = function($v1, $v2, $vH) { |
|
| 189 | 189 | if ($vH < 0) { |
| 190 | 190 | $vH += 1; |
| 191 | 191 | } |
@@ -319,11 +319,11 @@ discard block |
||
| 319 | 319 | } |
| 320 | 320 | } elseif ( |
| 321 | 321 | preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
| 322 | - && ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])) |
|
| 322 | + && ($extension = _image_trouver_extension_depuis_mime('image/'.$regs[1])) |
|
| 323 | 323 | && in_array($extension, _image_extensions_acceptees_en_entree()) |
| 324 | 324 | ) { |
| 325 | 325 | # gerer img src="data:....base64" |
| 326 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 326 | + $local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension); |
|
| 327 | 327 | if (!file_exists($local)) { |
| 328 | 328 | ecrire_fichier($local, base64_decode($regs[2])); |
| 329 | 329 | } |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | // les protocoles web prennent au moins 3 lettres |
| 341 | 341 | if (tester_url_absolue($source)) { |
| 342 | 342 | include_spip('inc/distant'); |
| 343 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 343 | + $fichier = _DIR_RACINE.copie_locale($source); |
|
| 344 | 344 | if (!$fichier) { |
| 345 | 345 | return ''; |
| 346 | 346 | } |
@@ -442,9 +442,9 @@ discard block |
||
| 442 | 442 | // on garde la terminaison initiale car image simplement copiee |
| 443 | 443 | // et on postfixe son nom avec un md5 du path |
| 444 | 444 | $terminaison_dest = $terminaison; |
| 445 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 445 | + $fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5); |
|
| 446 | 446 | } else { |
| 447 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 447 | + $fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5); |
|
| 448 | 448 | } |
| 449 | 449 | $cache = sous_repertoire(_DIR_VAR, $cache); |
| 450 | 450 | $cache = sous_repertoire($cache, $effet); |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | $fichier_dest = substr($fichier_dest, 2); |
| 456 | 456 | } |
| 457 | 457 | |
| 458 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 458 | + $fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest; |
|
| 459 | 459 | |
| 460 | 460 | $GLOBALS['images_calculees'][] = $fichier_dest; |
| 461 | 461 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | } |
| 482 | 482 | if ($creer && !@file_exists($fichier)) { |
| 483 | 483 | if (!@file_exists("$fichier.src")) { |
| 484 | - spip_log("Image absente : $fichier", 'images' . _LOG_ERREUR); |
|
| 484 | + spip_log("Image absente : $fichier", 'images'._LOG_ERREUR); |
|
| 485 | 485 | |
| 486 | 486 | return false; |
| 487 | 487 | } |
@@ -491,15 +491,15 @@ discard block |
||
| 491 | 491 | |
| 492 | 492 | if ($creer) { |
| 493 | 493 | spip_log( |
| 494 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 495 | - 'images' . _LOG_DEBUG |
|
| 494 | + 'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier", |
|
| 495 | + 'images'._LOG_DEBUG |
|
| 496 | 496 | ); |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | $term_fonction = _image_trouver_extension_pertinente($fichier); |
| 500 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 500 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction; |
|
| 501 | 501 | $ret['fichier'] = $fichier; |
| 502 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 502 | + $ret['fonction_image'] = '_image_image'.$terminaison_dest; |
|
| 503 | 503 | $ret['fichier_dest'] = $fichier_dest; |
| 504 | 504 | $ret['format_source'] = _image_extension_normalisee($terminaison); |
| 505 | 505 | $ret['format_dest'] = $terminaison_dest; |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | |
| 643 | 643 | $_terminaison = _image_trouver_extension_depuis_mime($mime); |
| 644 | 644 | if ($_terminaison && $_terminaison !== $terminaison) { |
| 645 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 645 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE); |
|
| 646 | 646 | $terminaison = $_terminaison; |
| 647 | 647 | } |
| 648 | 648 | return $terminaison; |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | if (!function_exists('imagepng')) { |
| 778 | 778 | return false; |
| 779 | 779 | } |
| 780 | - $tmp = $fichier . '.tmp'; |
|
| 780 | + $tmp = $fichier.'.tmp'; |
|
| 781 | 781 | $ret = imagepng($img, $tmp); |
| 782 | 782 | if (file_exists($tmp)) { |
| 783 | 783 | $taille_test = @getimagesize($tmp); |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | if (!function_exists('imagegif')) { |
| 813 | 813 | return false; |
| 814 | 814 | } |
| 815 | - $tmp = $fichier . '.tmp'; |
|
| 815 | + $tmp = $fichier.'.tmp'; |
|
| 816 | 816 | $ret = imagegif($img, $tmp); |
| 817 | 817 | if (file_exists($tmp)) { |
| 818 | 818 | $taille_test = @getimagesize($tmp); |
@@ -852,7 +852,7 @@ discard block |
||
| 852 | 852 | if (!function_exists('imagejpeg')) { |
| 853 | 853 | return false; |
| 854 | 854 | } |
| 855 | - $tmp = $fichier . '.tmp'; |
|
| 855 | + $tmp = $fichier.'.tmp'; |
|
| 856 | 856 | |
| 857 | 857 | // Enable interlancing |
| 858 | 858 | imageinterlace($img, true); |
@@ -913,7 +913,7 @@ discard block |
||
| 913 | 913 | if (!function_exists('imagewebp')) { |
| 914 | 914 | return false; |
| 915 | 915 | } |
| 916 | - $tmp = $fichier . '.tmp'; |
|
| 916 | + $tmp = $fichier.'.tmp'; |
|
| 917 | 917 | $ret = imagewebp($img, $tmp, $qualite); |
| 918 | 918 | if (file_exists($tmp)) { |
| 919 | 919 | $taille_test = @getimagesize($tmp); |
@@ -947,7 +947,7 @@ discard block |
||
| 947 | 947 | */ |
| 948 | 948 | function _image_imagesvg($img, $fichier) { |
| 949 | 949 | |
| 950 | - $tmp = $fichier . '.tmp'; |
|
| 950 | + $tmp = $fichier.'.tmp'; |
|
| 951 | 951 | if (!str_contains($img, '<')) { |
| 952 | 952 | $img = supprimer_timestamp($img); |
| 953 | 953 | if (!file_exists($img)) { |
@@ -1004,14 +1004,14 @@ discard block |
||
| 1004 | 1004 | */ |
| 1005 | 1005 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1006 | 1006 | if (is_null($fonction)) { |
| 1007 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1007 | + $fonction = '_image_image'.$valeurs['format_dest']; |
|
| 1008 | 1008 | } |
| 1009 | 1009 | $ret = false; |
| 1010 | 1010 | #un flag pour reperer les images gravees |
| 1011 | 1011 | $lock = ( |
| 1012 | 1012 | !statut_effacer_images_temporaires('get') |
| 1013 | 1013 | || @file_exists($valeurs['fichier_dest']) |
| 1014 | - && !@file_exists($valeurs['fichier_dest'] . '.src') |
|
| 1014 | + && !@file_exists($valeurs['fichier_dest'].'.src') |
|
| 1015 | 1015 | ); |
| 1016 | 1016 | if ( |
| 1017 | 1017 | function_exists($fonction) |
@@ -1023,7 +1023,7 @@ discard block |
||
| 1023 | 1023 | [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
| 1024 | 1024 | $valeurs['date'] = @filemtime($valeurs['fichier_dest']); |
| 1025 | 1025 | // pour la retrouver apres disparition |
| 1026 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1026 | + ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true); |
|
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | 1029 | return $ret; |
@@ -1198,7 +1198,7 @@ discard block |
||
| 1198 | 1198 | |
| 1199 | 1199 | // attributs deprecies. Transformer en CSS |
| 1200 | 1200 | if ($espace = extraire_attribut($tag, 'hspace')) { |
| 1201 | - $style = "margin:{$espace}px;" . $style; |
|
| 1201 | + $style = "margin:{$espace}px;".$style; |
|
| 1202 | 1202 | $tag = inserer_attribut($tag, 'hspace', ''); |
| 1203 | 1203 | } |
| 1204 | 1204 | |
@@ -1321,7 +1321,7 @@ discard block |
||
| 1321 | 1321 | $image = $valeurs['fichier']; |
| 1322 | 1322 | $format = $valeurs['format_source']; |
| 1323 | 1323 | $destdir = dirname((string) $valeurs['fichier_dest']); |
| 1324 | - $destfile = basename((string) $valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1324 | + $destfile = basename((string) $valeurs['fichier_dest'], '.'.$valeurs['format_dest']); |
|
| 1325 | 1325 | |
| 1326 | 1326 | $format_sortie = $valeurs['format_dest']; |
| 1327 | 1327 | |
@@ -1353,7 +1353,7 @@ discard block |
||
| 1353 | 1353 | |
| 1354 | 1354 | // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
| 1355 | 1355 | if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
| 1356 | - $vignette = $destination . '.' . $format; |
|
| 1356 | + $vignette = $destination.'.'.$format; |
|
| 1357 | 1357 | @copy($image, $vignette); |
| 1358 | 1358 | } |
| 1359 | 1359 | |
@@ -1361,7 +1361,7 @@ discard block |
||
| 1361 | 1361 | include_spip('inc/svg'); |
| 1362 | 1362 | if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
| 1363 | 1363 | $format_sortie = 'svg'; |
| 1364 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1364 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1365 | 1365 | $valeurs['fichier_dest'] = $vignette; |
| 1366 | 1366 | _image_gd_output($svg, $valeurs); |
| 1367 | 1367 | } |
@@ -1373,9 +1373,9 @@ discard block |
||
| 1373 | 1373 | define('_CONVERT_COMMAND', 'convert'); |
| 1374 | 1374 | } // Securite : mes_options.php peut preciser le chemin absolu |
| 1375 | 1375 | if (!defined('_RESIZE_COMMAND')) { |
| 1376 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest'); |
|
| 1376 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -orient Undefined -resize %xx%y! %src %dest'); |
|
| 1377 | 1377 | } |
| 1378 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1378 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1379 | 1379 | $commande = str_replace( |
| 1380 | 1380 | ['%x', '%y', '%src', '%dest'], |
| 1381 | 1381 | [ |
@@ -1391,7 +1391,7 @@ discard block |
||
| 1391 | 1391 | if (!@file_exists($vignette)) { |
| 1392 | 1392 | spip_log("echec convert sur $vignette"); |
| 1393 | 1393 | |
| 1394 | - return; // echec commande |
|
| 1394 | + return; // echec commande |
|
| 1395 | 1395 | } |
| 1396 | 1396 | } |
| 1397 | 1397 | |
@@ -1408,7 +1408,7 @@ discard block |
||
| 1408 | 1408 | if (!$output) { |
| 1409 | 1409 | return; |
| 1410 | 1410 | } |
| 1411 | - $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1411 | + $vignette = $output.DIRECTORY_SEPARATOR.basename($destination).'.'.$format_sortie; |
|
| 1412 | 1412 | |
| 1413 | 1413 | $imagick = new Imagick(); |
| 1414 | 1414 | $imagick->readImage(realpath($image)); |
@@ -1417,7 +1417,7 @@ discard block |
||
| 1417 | 1417 | $destHeight, |
| 1418 | 1418 | Imagick::FILTER_LANCZOS, |
| 1419 | 1419 | 1 |
| 1420 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1420 | + ); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1421 | 1421 | $imagick->writeImage($vignette); |
| 1422 | 1422 | |
| 1423 | 1423 | if (!@file_exists($vignette)) { |
@@ -1426,7 +1426,7 @@ discard block |
||
| 1426 | 1426 | return; |
| 1427 | 1427 | } |
| 1428 | 1428 | // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
| 1429 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1429 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1430 | 1430 | } |
| 1431 | 1431 | |
| 1432 | 1432 | // netpbm |
@@ -1437,11 +1437,11 @@ discard block |
||
| 1437 | 1437 | if (_PNMSCALE_COMMAND == '') { |
| 1438 | 1438 | return; |
| 1439 | 1439 | } |
| 1440 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1440 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1441 | 1441 | $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', (string) _PNMSCALE_COMMAND); |
| 1442 | 1442 | if ($format == 'jpg') { |
| 1443 | 1443 | $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', (string) _PNMSCALE_COMMAND); |
| 1444 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1444 | + exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1445 | 1445 | if (!($s = @filesize($vignette))) { |
| 1446 | 1446 | spip_unlink($vignette); |
| 1447 | 1447 | } |
@@ -1453,7 +1453,7 @@ discard block |
||
| 1453 | 1453 | } else { |
| 1454 | 1454 | if ($format == 'gif') { |
| 1455 | 1455 | $giftopnm_command = str_replace('pnmscale', 'giftopnm', (string) _PNMSCALE_COMMAND); |
| 1456 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1456 | + exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1457 | 1457 | if (!($s = @filesize($vignette))) { |
| 1458 | 1458 | spip_unlink($vignette); |
| 1459 | 1459 | } |
@@ -1465,7 +1465,7 @@ discard block |
||
| 1465 | 1465 | } else { |
| 1466 | 1466 | if ($format == 'png') { |
| 1467 | 1467 | $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', (string) _PNMSCALE_COMMAND); |
| 1468 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1468 | + exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1469 | 1469 | if (!($s = @filesize($vignette))) { |
| 1470 | 1470 | spip_unlink($vignette); |
| 1471 | 1471 | } |
@@ -1487,7 +1487,7 @@ discard block |
||
| 1487 | 1487 | return; |
| 1488 | 1488 | } |
| 1489 | 1489 | if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
| 1490 | - spip_log('vignette gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1490 | + spip_log('vignette gd2 impossible : '.$srcWidth * $srcHeight.'pixels'); |
|
| 1491 | 1491 | |
| 1492 | 1492 | return; |
| 1493 | 1493 | } |
@@ -1790,7 +1790,7 @@ discard block |
||
| 1790 | 1790 | // de l'image, de facon a tromper le cache du navigateur |
| 1791 | 1791 | // quand on fait supprimer/reuploader un logo |
| 1792 | 1792 | // (pas de filemtime si SAFE MODE) |
| 1793 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1793 | + $date = test_espace_prive() ? ('?'.$date) : ''; |
|
| 1794 | 1794 | |
| 1795 | 1795 | return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
| 1796 | 1796 | } |
@@ -1868,9 +1868,9 @@ discard block |
||
| 1868 | 1868 | $b = $argb['blue']; |
| 1869 | 1869 | |
| 1870 | 1870 | if ($bpp[$key] == 32) { |
| 1871 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1871 | + $icXOR[$key] .= chr($b).chr($g).chr($r).chr($a); |
|
| 1872 | 1872 | } elseif ($bpp[$key] === 24) { |
| 1873 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1873 | + $icXOR[$key] .= chr($b).chr($g).chr($r); |
|
| 1874 | 1874 | } |
| 1875 | 1875 | |
| 1876 | 1876 | if ($a < 128) { |
@@ -1897,48 +1897,48 @@ discard block |
||
| 1897 | 1897 | |
| 1898 | 1898 | // BITMAPINFOHEADER - 40 bytes |
| 1899 | 1899 | $BitmapInfoHeader[$key] = ''; |
| 1900 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1901 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1900 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1901 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1902 | 1902 | // The biHeight member specifies the combined |
| 1903 | 1903 | // height of the XOR and AND masks. |
| 1904 | 1904 | $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
| 1905 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1906 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1907 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1908 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1909 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1910 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1911 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1912 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1905 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1906 | + $BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount; |
|
| 1907 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1908 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1909 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1910 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1911 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1912 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1913 | 1913 | } |
| 1914 | 1914 | |
| 1915 | 1915 | |
| 1916 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1917 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1918 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1916 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1917 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1918 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1919 | 1919 | |
| 1920 | 1920 | $dwImageOffset = 6 + (count($gd_image_array) * 16); |
| 1921 | 1921 | foreach (array_keys($gd_image_array) as $key) { |
| 1922 | 1922 | // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
| 1923 | 1923 | |
| 1924 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1925 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1926 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1927 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1924 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1925 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1926 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1927 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1928 | 1928 | |
| 1929 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1930 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1929 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1930 | + $icondata .= chr($bpp[$key])."\x00"; // wBitCount; // Bits per pixel |
|
| 1931 | 1931 | |
| 1932 | 1932 | $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
| 1933 | 1933 | $icondata .= phpthumb_functions::LittleEndian2String( |
| 1934 | 1934 | $dwBytesInRes, |
| 1935 | 1935 | 4 |
| 1936 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1936 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1937 | 1937 | |
| 1938 | 1938 | $icondata .= phpthumb_functions::LittleEndian2String( |
| 1939 | 1939 | $dwImageOffset, |
| 1940 | 1940 | 4 |
| 1941 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1941 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1942 | 1942 | $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
| 1943 | 1943 | $dwImageOffset += strlen($icXOR[$key]); |
| 1944 | 1944 | $dwImageOffset += strlen($icAND[$key]); |
@@ -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 | include_spip('inc/filtres'); // par precaution |
| 23 | 23 | include_spip('inc/filtres_images_mini'); // par precaution |
@@ -37,21 +37,21 @@ discard block |
||
| 37 | 37 | * Le code de la couleur en hexadécimal. |
| 38 | 38 | */ |
| 39 | 39 | function _couleur_dec_to_hex($red, $green, $blue) { |
| 40 | - $red = dechex($red); |
|
| 41 | - $green = dechex($green); |
|
| 42 | - $blue = dechex($blue); |
|
| 43 | - |
|
| 44 | - if (strlen($red) == 1) { |
|
| 45 | - $red = '0' . $red; |
|
| 46 | - } |
|
| 47 | - if (strlen($green) == 1) { |
|
| 48 | - $green = '0' . $green; |
|
| 49 | - } |
|
| 50 | - if (strlen($blue) == 1) { |
|
| 51 | - $blue = '0' . $blue; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - return "$red$green$blue"; |
|
| 40 | + $red = dechex($red); |
|
| 41 | + $green = dechex($green); |
|
| 42 | + $blue = dechex($blue); |
|
| 43 | + |
|
| 44 | + if (strlen($red) == 1) { |
|
| 45 | + $red = '0' . $red; |
|
| 46 | + } |
|
| 47 | + if (strlen($green) == 1) { |
|
| 48 | + $green = '0' . $green; |
|
| 49 | + } |
|
| 50 | + if (strlen($blue) == 1) { |
|
| 51 | + $blue = '0' . $blue; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + return "$red$green$blue"; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -63,18 +63,18 @@ discard block |
||
| 63 | 63 | * Un tableau des 3 éléments : rouge, vert, bleu. |
| 64 | 64 | */ |
| 65 | 65 | function _couleur_hex_to_dec($couleur) { |
| 66 | - $couleur ??= ''; |
|
| 67 | - $couleur = couleur_html_to_hex($couleur); |
|
| 68 | - $couleur = ltrim($couleur, '#'); |
|
| 69 | - if (strlen($couleur) === 3) { |
|
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | - } |
|
| 72 | - $retour = []; |
|
| 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; |
|
| 66 | + $couleur ??= ''; |
|
| 67 | + $couleur = couleur_html_to_hex($couleur); |
|
| 68 | + $couleur = ltrim($couleur, '#'); |
|
| 69 | + if (strlen($couleur) === 3) { |
|
| 70 | + $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | + } |
|
| 72 | + $retour = []; |
|
| 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,8 +91,8 @@ discard block |
||
| 91 | 91 | * Le code de la couleur en hexadécimal. |
| 92 | 92 | */ |
| 93 | 93 | function _couleur_hsl_to_hex($hue, $saturation, $lightness) { |
| 94 | - $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | - return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 94 | + $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | + return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * Un tableau des 3 éléments : teinte, saturation, luminosité. |
| 105 | 105 | */ |
| 106 | 106 | function _couleur_hex_to_hsl($couleur) { |
| 107 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | - return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 107 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | + return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -120,55 +120,55 @@ discard block |
||
| 120 | 120 | * @return array |
| 121 | 121 | */ |
| 122 | 122 | function _couleur_rgb_to_hsl($R, $G, $B) { |
| 123 | - $H = null; |
|
| 124 | - $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 125 | - $var_G = ($G / 255); |
|
| 126 | - $var_B = ($B / 255); |
|
| 127 | - |
|
| 128 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | - |
|
| 132 | - $L = ($var_Max + $var_Min) / 2; |
|
| 133 | - |
|
| 134 | - if ($del_Max == 0) { |
|
| 135 | - //This is a gray, no chroma... |
|
| 136 | - $H = 0; //HSL results = 0 ÷ 1 |
|
| 137 | - $S = 0; |
|
| 138 | - } else { |
|
| 139 | - // Chromatic data... |
|
| 140 | - $S = $L < 0.5 ? $del_Max / ($var_Max + $var_Min) : $del_Max / (2 - $var_Max - $var_Min); |
|
| 141 | - |
|
| 142 | - $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 143 | - $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 144 | - $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 145 | - |
|
| 146 | - if ($var_R === $var_Max) { |
|
| 147 | - $H = $del_B - $del_G; |
|
| 148 | - } else { |
|
| 149 | - if ($var_G === $var_Max) { |
|
| 150 | - $H = (1 / 3) + $del_R - $del_B; |
|
| 151 | - } else { |
|
| 152 | - if ($var_B === $var_Max) { |
|
| 153 | - $H = (2 / 3) + $del_G - $del_R; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if ($H < 0) { |
|
| 159 | - $H += 1; |
|
| 160 | - } |
|
| 161 | - if ($H > 1) { |
|
| 162 | - $H -= 1; |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $ret = []; |
|
| 167 | - $ret['h'] = $H; |
|
| 168 | - $ret['s'] = $S; |
|
| 169 | - $ret['l'] = $L; |
|
| 170 | - |
|
| 171 | - return $ret; |
|
| 123 | + $H = null; |
|
| 124 | + $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 125 | + $var_G = ($G / 255); |
|
| 126 | + $var_B = ($B / 255); |
|
| 127 | + |
|
| 128 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | + |
|
| 132 | + $L = ($var_Max + $var_Min) / 2; |
|
| 133 | + |
|
| 134 | + if ($del_Max == 0) { |
|
| 135 | + //This is a gray, no chroma... |
|
| 136 | + $H = 0; //HSL results = 0 ÷ 1 |
|
| 137 | + $S = 0; |
|
| 138 | + } else { |
|
| 139 | + // Chromatic data... |
|
| 140 | + $S = $L < 0.5 ? $del_Max / ($var_Max + $var_Min) : $del_Max / (2 - $var_Max - $var_Min); |
|
| 141 | + |
|
| 142 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 143 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 144 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 145 | + |
|
| 146 | + if ($var_R === $var_Max) { |
|
| 147 | + $H = $del_B - $del_G; |
|
| 148 | + } else { |
|
| 149 | + if ($var_G === $var_Max) { |
|
| 150 | + $H = (1 / 3) + $del_R - $del_B; |
|
| 151 | + } else { |
|
| 152 | + if ($var_B === $var_Max) { |
|
| 153 | + $H = (2 / 3) + $del_G - $del_R; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if ($H < 0) { |
|
| 159 | + $H += 1; |
|
| 160 | + } |
|
| 161 | + if ($H > 1) { |
|
| 162 | + $H -= 1; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $ret = []; |
|
| 167 | + $ret['h'] = $H; |
|
| 168 | + $ret['s'] = $S; |
|
| 169 | + $ret['l'] = $L; |
|
| 170 | + |
|
| 171 | + return $ret; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | |
@@ -184,48 +184,48 @@ discard block |
||
| 184 | 184 | * @return array |
| 185 | 185 | */ |
| 186 | 186 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 187 | - // helper |
|
| 188 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 189 | - if ($vH < 0) { |
|
| 190 | - $vH += 1; |
|
| 191 | - } |
|
| 192 | - if ($vH > 1) { |
|
| 193 | - $vH -= 1; |
|
| 194 | - } |
|
| 195 | - if ((6 * $vH) < 1) { |
|
| 196 | - return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 197 | - } |
|
| 198 | - if ((2 * $vH) < 1) { |
|
| 199 | - return ($v2); |
|
| 200 | - } |
|
| 201 | - if ((3 * $vH) < 2) { |
|
| 202 | - return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return ($v1); |
|
| 206 | - }; |
|
| 207 | - |
|
| 208 | - if ($S == 0) { |
|
| 209 | - // HSV values = 0 -> 1 |
|
| 210 | - $R = $L * 255; |
|
| 211 | - $G = $L * 255; |
|
| 212 | - $B = $L * 255; |
|
| 213 | - } else { |
|
| 214 | - $var_2 = $L < 0.5 ? $L * (1 + $S) : ($L + $S) - ($S * $L); |
|
| 215 | - |
|
| 216 | - $var_1 = 2 * $L - $var_2; |
|
| 217 | - |
|
| 218 | - $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 219 | - $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 220 | - $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $ret = []; |
|
| 224 | - $ret['r'] = floor($R); |
|
| 225 | - $ret['g'] = floor($G); |
|
| 226 | - $ret['b'] = floor($B); |
|
| 227 | - |
|
| 228 | - return $ret; |
|
| 187 | + // helper |
|
| 188 | + $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 189 | + if ($vH < 0) { |
|
| 190 | + $vH += 1; |
|
| 191 | + } |
|
| 192 | + if ($vH > 1) { |
|
| 193 | + $vH -= 1; |
|
| 194 | + } |
|
| 195 | + if ((6 * $vH) < 1) { |
|
| 196 | + return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 197 | + } |
|
| 198 | + if ((2 * $vH) < 1) { |
|
| 199 | + return ($v2); |
|
| 200 | + } |
|
| 201 | + if ((3 * $vH) < 2) { |
|
| 202 | + return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return ($v1); |
|
| 206 | + }; |
|
| 207 | + |
|
| 208 | + if ($S == 0) { |
|
| 209 | + // HSV values = 0 -> 1 |
|
| 210 | + $R = $L * 255; |
|
| 211 | + $G = $L * 255; |
|
| 212 | + $B = $L * 255; |
|
| 213 | + } else { |
|
| 214 | + $var_2 = $L < 0.5 ? $L * (1 + $S) : ($L + $S) - ($S * $L); |
|
| 215 | + |
|
| 216 | + $var_1 = 2 * $L - $var_2; |
|
| 217 | + |
|
| 218 | + $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 219 | + $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 220 | + $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $ret = []; |
|
| 224 | + $ret['r'] = floor($R); |
|
| 225 | + $ret['g'] = floor($G); |
|
| 226 | + $ret['b'] = floor($B); |
|
| 227 | + |
|
| 228 | + return $ret; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -243,11 +243,11 @@ discard block |
||
| 243 | 243 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 244 | 244 | */ |
| 245 | 245 | function statut_effacer_images_temporaires($stat) { |
| 246 | - static $statut = false; // par defaut on grave toute les images |
|
| 247 | - if ($stat === 'get') { |
|
| 248 | - return $statut; |
|
| 249 | - } |
|
| 250 | - $statut = (bool) $stat; |
|
| 246 | + static $statut = false; // par defaut on grave toute les images |
|
| 247 | + if ($stat === 'get') { |
|
| 248 | + return $statut; |
|
| 249 | + } |
|
| 250 | + $statut = (bool) $stat; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -300,251 +300,251 @@ discard block |
||
| 300 | 300 | * - array : tableau décrivant de l'image |
| 301 | 301 | */ |
| 302 | 302 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 303 | - $valeurs = []; |
|
| 304 | - $ret = []; |
|
| 305 | - $f = null; |
|
| 306 | - static $images_recalcul = []; |
|
| 307 | - if (strlen($img) == 0) { |
|
| 308 | - return false; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 312 | - if (strlen($source) < 1) { |
|
| 313 | - if (!str_starts_with($img, '<img ')) { |
|
| 314 | - $source = $img; |
|
| 315 | - $img = "<img src='$source' />"; |
|
| 316 | - } else { |
|
| 317 | - // pas d'attribut src sur cette balise <img../> |
|
| 318 | - return false; |
|
| 319 | - } |
|
| 320 | - } elseif ( |
|
| 321 | - preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 322 | - && ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])) |
|
| 323 | - && in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 324 | - ) { |
|
| 325 | - # gerer img src="data:....base64" |
|
| 326 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 327 | - if (!file_exists($local)) { |
|
| 328 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 329 | - } |
|
| 330 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 331 | - $sanitizer($local); |
|
| 332 | - } |
|
| 333 | - $source = $local; |
|
| 334 | - $img = inserer_attribut($img, 'src', $source); |
|
| 335 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 336 | - $img = inserer_attribut($img, 'width', ''); |
|
| 337 | - $img = inserer_attribut($img, 'height', ''); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - // les protocoles web prennent au moins 3 lettres |
|
| 341 | - if (tester_url_absolue($source)) { |
|
| 342 | - include_spip('inc/distant'); |
|
| 343 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 344 | - if (!$fichier) { |
|
| 345 | - return ''; |
|
| 346 | - } |
|
| 347 | - if ( |
|
| 348 | - ($extension = _image_trouver_extension($fichier)) |
|
| 349 | - && ($sanitizer = charger_fonction($extension, 'sanitizer', true)) |
|
| 350 | - ) { |
|
| 351 | - $sanitizer($fichier); |
|
| 352 | - } |
|
| 353 | - } else { |
|
| 354 | - // enlever le timestamp eventuel |
|
| 355 | - if (str_contains($source, '?')) { |
|
| 356 | - $source = preg_replace(',[?]\d+$,', '', $source); |
|
| 357 | - } |
|
| 358 | - if ( |
|
| 359 | - str_contains($source, '?') |
|
| 360 | - && str_starts_with($source, (string) _DIR_IMG) |
|
| 361 | - && file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 362 | - ) { |
|
| 363 | - $source = $f; |
|
| 364 | - } |
|
| 365 | - $fichier = $source; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - $terminaison_dest = ''; |
|
| 369 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 370 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - if ( |
|
| 374 | - $forcer_format !== false |
|
| 375 | - && ($terminaison_dest !== 'svg' || $support_svg || !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 376 | - ) { |
|
| 377 | - $terminaison_dest = $forcer_format; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - if (!$terminaison_dest) { |
|
| 381 | - return false; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 385 | - $fichier_dest = $nom_fichier; |
|
| 386 | - if ( |
|
| 387 | - $find_in_path && ($f = find_in_path($fichier)) && ($fichier = $f) |
|
| 388 | - || @file_exists($f = $fichier) |
|
| 389 | - ) { |
|
| 390 | - // on ne passe jamais la balise img qui est peut-être en x2 et à laquelle on ne peut pas faire confiance |
|
| 391 | - // on lit directement les infos du fichier |
|
| 392 | - [$ret['hauteur'], $ret['largeur']] = taille_image($f); |
|
| 393 | - $date_src = @filemtime($f); |
|
| 394 | - } elseif ( |
|
| 395 | - @file_exists($f = "$fichier.src") |
|
| 396 | - && lire_fichier($f, $valeurs) |
|
| 397 | - && ($valeurs = unserialize($valeurs)) |
|
| 398 | - && isset($valeurs['hauteur_dest']) |
|
| 399 | - && isset($valeurs['largeur_dest']) |
|
| 400 | - ) { |
|
| 401 | - $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 402 | - $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 403 | - $date_src = $valeurs['date']; |
|
| 404 | - } // pas de fichier source par la |
|
| 405 | - else { |
|
| 406 | - return false; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - // pas de taille mesurable ? |
|
| 410 | - if ( |
|
| 411 | - !$ret['hauteur'] |
|
| 412 | - || !($ret['hauteur'] = (int) round($ret['hauteur'])) |
|
| 413 | - || !$ret['largeur'] |
|
| 414 | - || !($ret['largeur'] = (int) round($ret['largeur'])) |
|
| 415 | - ) { |
|
| 416 | - return false; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - // les images calculees dependent du chemin du fichier source |
|
| 420 | - // 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 |
|
| 421 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 422 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 423 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 424 | - // alors que ca concerne peu de site au final |
|
| 425 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 426 | - $identifiant = $fichier; |
|
| 427 | - |
|
| 428 | - // cas general : |
|
| 429 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 430 | - // cas particulier de reduire : |
|
| 431 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 432 | - $cache = 'cache-gd2'; |
|
| 433 | - if (str_starts_with($effet, 'reduire')) { |
|
| 434 | - [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 435 | - [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 436 | - $ret['largeur_dest'] = $destWidth; |
|
| 437 | - $ret['hauteur_dest'] = $destHeight; |
|
| 438 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 439 | - $cache = 'cache-vignettes'; |
|
| 440 | - $fichier_dest = basename($fichier_dest); |
|
| 441 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 442 | - // on garde la terminaison initiale car image simplement copiee |
|
| 443 | - // et on postfixe son nom avec un md5 du path |
|
| 444 | - $terminaison_dest = $terminaison; |
|
| 445 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 446 | - } else { |
|
| 447 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 448 | - } |
|
| 449 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 450 | - $cache = sous_repertoire($cache, $effet); |
|
| 451 | - } else { |
|
| 452 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 453 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 454 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 455 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 459 | - |
|
| 460 | - $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 461 | - |
|
| 462 | - $creer = true; |
|
| 463 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 464 | - if (defined('_VAR_IMAGES') && _VAR_IMAGES && !isset($images_recalcul[$fichier_dest])) { |
|
| 465 | - $images_recalcul[$fichier_dest] = true; |
|
| 466 | - } else { |
|
| 467 | - if (@file_exists($f = $fichier_dest)) { |
|
| 468 | - if (filemtime($f) >= $date_src) { |
|
| 469 | - $creer = false; |
|
| 470 | - } |
|
| 471 | - } else { |
|
| 472 | - if ( |
|
| 473 | - @file_exists($f = "$fichier_dest.src") |
|
| 474 | - && lire_fichier($f, $valeurs) |
|
| 475 | - && ($valeurs = unserialize($valeurs)) |
|
| 476 | - && $valeurs['date'] >= $date_src |
|
| 477 | - ) { |
|
| 478 | - $creer = false; |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - if ($creer && !@file_exists($fichier)) { |
|
| 483 | - if (!@file_exists("$fichier.src")) { |
|
| 484 | - spip_log("Image absente : $fichier", 'images' . _LOG_ERREUR); |
|
| 485 | - |
|
| 486 | - return false; |
|
| 487 | - } |
|
| 488 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 489 | - reconstruire_image_intermediaire($fichier); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - if ($creer) { |
|
| 493 | - spip_log( |
|
| 494 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 495 | - 'images' . _LOG_DEBUG |
|
| 496 | - ); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 500 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 501 | - $ret['fichier'] = $fichier; |
|
| 502 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 503 | - $ret['fichier_dest'] = $fichier_dest; |
|
| 504 | - $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 505 | - $ret['format_dest'] = $terminaison_dest; |
|
| 506 | - $ret['date_src'] = $date_src; |
|
| 507 | - $ret['creer'] = $creer; |
|
| 508 | - $ret['class'] = extraire_attribut($img, 'class'); |
|
| 509 | - $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 510 | - $ret['style'] = extraire_attribut($img, 'style'); |
|
| 511 | - $ret['tag'] = $img; |
|
| 512 | - if ($fonction_creation) { |
|
| 513 | - $ret['reconstruction'] = $fonction_creation; |
|
| 514 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 515 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 516 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 517 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - $ret = pipeline('image_preparer_filtre', [ |
|
| 521 | - 'args' => [ |
|
| 522 | - 'img' => $img, |
|
| 523 | - 'effet' => $effet, |
|
| 524 | - 'forcer_format' => $forcer_format, |
|
| 525 | - 'fonction_creation' => $fonction_creation, |
|
| 526 | - 'find_in_path' => $find_in_path, |
|
| 527 | - ], |
|
| 528 | - 'data' => $ret |
|
| 529 | - ]); |
|
| 530 | - |
|
| 531 | - // une globale pour le debug en cas de crash memoire |
|
| 532 | - $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 533 | - |
|
| 534 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 535 | - if ($term_fonction === 'svg') { |
|
| 536 | - if ($creer && !$support_svg) { |
|
| 537 | - process_image_svg_identite($ret); |
|
| 538 | - $ret['creer'] = false; |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - else { |
|
| 542 | - if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 543 | - return false; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - return $ret; |
|
| 303 | + $valeurs = []; |
|
| 304 | + $ret = []; |
|
| 305 | + $f = null; |
|
| 306 | + static $images_recalcul = []; |
|
| 307 | + if (strlen($img) == 0) { |
|
| 308 | + return false; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 312 | + if (strlen($source) < 1) { |
|
| 313 | + if (!str_starts_with($img, '<img ')) { |
|
| 314 | + $source = $img; |
|
| 315 | + $img = "<img src='$source' />"; |
|
| 316 | + } else { |
|
| 317 | + // pas d'attribut src sur cette balise <img../> |
|
| 318 | + return false; |
|
| 319 | + } |
|
| 320 | + } elseif ( |
|
| 321 | + preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 322 | + && ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])) |
|
| 323 | + && in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 324 | + ) { |
|
| 325 | + # gerer img src="data:....base64" |
|
| 326 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 327 | + if (!file_exists($local)) { |
|
| 328 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 329 | + } |
|
| 330 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 331 | + $sanitizer($local); |
|
| 332 | + } |
|
| 333 | + $source = $local; |
|
| 334 | + $img = inserer_attribut($img, 'src', $source); |
|
| 335 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 336 | + $img = inserer_attribut($img, 'width', ''); |
|
| 337 | + $img = inserer_attribut($img, 'height', ''); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + // les protocoles web prennent au moins 3 lettres |
|
| 341 | + if (tester_url_absolue($source)) { |
|
| 342 | + include_spip('inc/distant'); |
|
| 343 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 344 | + if (!$fichier) { |
|
| 345 | + return ''; |
|
| 346 | + } |
|
| 347 | + if ( |
|
| 348 | + ($extension = _image_trouver_extension($fichier)) |
|
| 349 | + && ($sanitizer = charger_fonction($extension, 'sanitizer', true)) |
|
| 350 | + ) { |
|
| 351 | + $sanitizer($fichier); |
|
| 352 | + } |
|
| 353 | + } else { |
|
| 354 | + // enlever le timestamp eventuel |
|
| 355 | + if (str_contains($source, '?')) { |
|
| 356 | + $source = preg_replace(',[?]\d+$,', '', $source); |
|
| 357 | + } |
|
| 358 | + if ( |
|
| 359 | + str_contains($source, '?') |
|
| 360 | + && str_starts_with($source, (string) _DIR_IMG) |
|
| 361 | + && file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 362 | + ) { |
|
| 363 | + $source = $f; |
|
| 364 | + } |
|
| 365 | + $fichier = $source; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + $terminaison_dest = ''; |
|
| 369 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 370 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + if ( |
|
| 374 | + $forcer_format !== false |
|
| 375 | + && ($terminaison_dest !== 'svg' || $support_svg || !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 376 | + ) { |
|
| 377 | + $terminaison_dest = $forcer_format; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + if (!$terminaison_dest) { |
|
| 381 | + return false; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 385 | + $fichier_dest = $nom_fichier; |
|
| 386 | + if ( |
|
| 387 | + $find_in_path && ($f = find_in_path($fichier)) && ($fichier = $f) |
|
| 388 | + || @file_exists($f = $fichier) |
|
| 389 | + ) { |
|
| 390 | + // on ne passe jamais la balise img qui est peut-être en x2 et à laquelle on ne peut pas faire confiance |
|
| 391 | + // on lit directement les infos du fichier |
|
| 392 | + [$ret['hauteur'], $ret['largeur']] = taille_image($f); |
|
| 393 | + $date_src = @filemtime($f); |
|
| 394 | + } elseif ( |
|
| 395 | + @file_exists($f = "$fichier.src") |
|
| 396 | + && lire_fichier($f, $valeurs) |
|
| 397 | + && ($valeurs = unserialize($valeurs)) |
|
| 398 | + && isset($valeurs['hauteur_dest']) |
|
| 399 | + && isset($valeurs['largeur_dest']) |
|
| 400 | + ) { |
|
| 401 | + $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 402 | + $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 403 | + $date_src = $valeurs['date']; |
|
| 404 | + } // pas de fichier source par la |
|
| 405 | + else { |
|
| 406 | + return false; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + // pas de taille mesurable ? |
|
| 410 | + if ( |
|
| 411 | + !$ret['hauteur'] |
|
| 412 | + || !($ret['hauteur'] = (int) round($ret['hauteur'])) |
|
| 413 | + || !$ret['largeur'] |
|
| 414 | + || !($ret['largeur'] = (int) round($ret['largeur'])) |
|
| 415 | + ) { |
|
| 416 | + return false; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + // les images calculees dependent du chemin du fichier source |
|
| 420 | + // 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 |
|
| 421 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 422 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 423 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 424 | + // alors que ca concerne peu de site au final |
|
| 425 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 426 | + $identifiant = $fichier; |
|
| 427 | + |
|
| 428 | + // cas general : |
|
| 429 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 430 | + // cas particulier de reduire : |
|
| 431 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 432 | + $cache = 'cache-gd2'; |
|
| 433 | + if (str_starts_with($effet, 'reduire')) { |
|
| 434 | + [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 435 | + [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 436 | + $ret['largeur_dest'] = $destWidth; |
|
| 437 | + $ret['hauteur_dest'] = $destHeight; |
|
| 438 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 439 | + $cache = 'cache-vignettes'; |
|
| 440 | + $fichier_dest = basename($fichier_dest); |
|
| 441 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 442 | + // on garde la terminaison initiale car image simplement copiee |
|
| 443 | + // et on postfixe son nom avec un md5 du path |
|
| 444 | + $terminaison_dest = $terminaison; |
|
| 445 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 446 | + } else { |
|
| 447 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 448 | + } |
|
| 449 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 450 | + $cache = sous_repertoire($cache, $effet); |
|
| 451 | + } else { |
|
| 452 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 453 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 454 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 455 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 459 | + |
|
| 460 | + $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 461 | + |
|
| 462 | + $creer = true; |
|
| 463 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 464 | + if (defined('_VAR_IMAGES') && _VAR_IMAGES && !isset($images_recalcul[$fichier_dest])) { |
|
| 465 | + $images_recalcul[$fichier_dest] = true; |
|
| 466 | + } else { |
|
| 467 | + if (@file_exists($f = $fichier_dest)) { |
|
| 468 | + if (filemtime($f) >= $date_src) { |
|
| 469 | + $creer = false; |
|
| 470 | + } |
|
| 471 | + } else { |
|
| 472 | + if ( |
|
| 473 | + @file_exists($f = "$fichier_dest.src") |
|
| 474 | + && lire_fichier($f, $valeurs) |
|
| 475 | + && ($valeurs = unserialize($valeurs)) |
|
| 476 | + && $valeurs['date'] >= $date_src |
|
| 477 | + ) { |
|
| 478 | + $creer = false; |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + if ($creer && !@file_exists($fichier)) { |
|
| 483 | + if (!@file_exists("$fichier.src")) { |
|
| 484 | + spip_log("Image absente : $fichier", 'images' . _LOG_ERREUR); |
|
| 485 | + |
|
| 486 | + return false; |
|
| 487 | + } |
|
| 488 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 489 | + reconstruire_image_intermediaire($fichier); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + if ($creer) { |
|
| 493 | + spip_log( |
|
| 494 | + 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 495 | + 'images' . _LOG_DEBUG |
|
| 496 | + ); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 500 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 501 | + $ret['fichier'] = $fichier; |
|
| 502 | + $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 503 | + $ret['fichier_dest'] = $fichier_dest; |
|
| 504 | + $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 505 | + $ret['format_dest'] = $terminaison_dest; |
|
| 506 | + $ret['date_src'] = $date_src; |
|
| 507 | + $ret['creer'] = $creer; |
|
| 508 | + $ret['class'] = extraire_attribut($img, 'class'); |
|
| 509 | + $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 510 | + $ret['style'] = extraire_attribut($img, 'style'); |
|
| 511 | + $ret['tag'] = $img; |
|
| 512 | + if ($fonction_creation) { |
|
| 513 | + $ret['reconstruction'] = $fonction_creation; |
|
| 514 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 515 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 516 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 517 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + $ret = pipeline('image_preparer_filtre', [ |
|
| 521 | + 'args' => [ |
|
| 522 | + 'img' => $img, |
|
| 523 | + 'effet' => $effet, |
|
| 524 | + 'forcer_format' => $forcer_format, |
|
| 525 | + 'fonction_creation' => $fonction_creation, |
|
| 526 | + 'find_in_path' => $find_in_path, |
|
| 527 | + ], |
|
| 528 | + 'data' => $ret |
|
| 529 | + ]); |
|
| 530 | + |
|
| 531 | + // une globale pour le debug en cas de crash memoire |
|
| 532 | + $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 533 | + |
|
| 534 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 535 | + if ($term_fonction === 'svg') { |
|
| 536 | + if ($creer && !$support_svg) { |
|
| 537 | + process_image_svg_identite($ret); |
|
| 538 | + $ret['creer'] = false; |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + else { |
|
| 542 | + if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 543 | + return false; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + return $ret; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | |
@@ -552,54 +552,54 @@ discard block |
||
| 552 | 552 | * Extensions d’images acceptées en entrée |
| 553 | 553 | */ |
| 554 | 554 | function _image_extensions_acceptees_en_entree(): array { |
| 555 | - static $extensions = null; |
|
| 556 | - if (empty($extensions)) { |
|
| 557 | - $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 558 | - if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 559 | - // action=tester renseigne gd_formats et detecte le support de webp |
|
| 560 | - $extensions = array_merge(explode(',', (string) $GLOBALS['meta']['gd_formats'])); |
|
| 561 | - $extensions = array_map('trim', $extensions); |
|
| 562 | - $extensions = array_filter($extensions); |
|
| 563 | - if (in_array('jpg', $extensions)) { |
|
| 564 | - $extensions[] = 'jpeg'; |
|
| 565 | - } |
|
| 566 | - $extensions = array_unique($extensions); |
|
| 567 | - } |
|
| 568 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - return $extensions; |
|
| 555 | + static $extensions = null; |
|
| 556 | + if (empty($extensions)) { |
|
| 557 | + $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 558 | + if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 559 | + // action=tester renseigne gd_formats et detecte le support de webp |
|
| 560 | + $extensions = array_merge(explode(',', (string) $GLOBALS['meta']['gd_formats'])); |
|
| 561 | + $extensions = array_map('trim', $extensions); |
|
| 562 | + $extensions = array_filter($extensions); |
|
| 563 | + if (in_array('jpg', $extensions)) { |
|
| 564 | + $extensions[] = 'jpeg'; |
|
| 565 | + } |
|
| 566 | + $extensions = array_unique($extensions); |
|
| 567 | + } |
|
| 568 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + return $extensions; |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
| 575 | 575 | * Extensions d’images acceptées en sortie |
| 576 | 576 | */ |
| 577 | 577 | function _image_extensions_acceptees_en_sortie(): array { |
| 578 | - static $extensions = null; |
|
| 579 | - if (empty($extensions)) { |
|
| 580 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 581 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 582 | - if (in_array('gif', $extensions) && !function_exists('imagegif')) { |
|
| 583 | - $extensions = array_diff($extensions, ['gif']); |
|
| 584 | - } |
|
| 585 | - if (in_array('webp', $extensions) && !function_exists('imagewebp')) { |
|
| 586 | - $extensions = array_diff($extensions, ['webp']); |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - return $extensions; |
|
| 578 | + static $extensions = null; |
|
| 579 | + if (empty($extensions)) { |
|
| 580 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 581 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 582 | + if (in_array('gif', $extensions) && !function_exists('imagegif')) { |
|
| 583 | + $extensions = array_diff($extensions, ['gif']); |
|
| 584 | + } |
|
| 585 | + if (in_array('webp', $extensions) && !function_exists('imagewebp')) { |
|
| 586 | + $extensions = array_diff($extensions, ['webp']); |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + return $extensions; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | function _image_extension_normalisee($extension) { |
| 594 | - $extension = strtolower((string) $extension); |
|
| 595 | - if ($extension === 'jpeg') { |
|
| 596 | - $extension = 'jpg'; |
|
| 597 | - } |
|
| 598 | - return $extension; |
|
| 594 | + $extension = strtolower((string) $extension); |
|
| 595 | + if ($extension === 'jpeg') { |
|
| 596 | + $extension = 'jpg'; |
|
| 597 | + } |
|
| 598 | + return $extension; |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | function _image_extensions_conservent_transparence() { |
| 602 | - return ['png', 'webp']; |
|
| 602 | + return ['png', 'webp']; |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | |
@@ -609,11 +609,11 @@ discard block |
||
| 609 | 609 | * @return string |
| 610 | 610 | */ |
| 611 | 611 | function _image_trouver_extension($path) { |
| 612 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 613 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 614 | - return strtolower($regs[1]); |
|
| 615 | - } |
|
| 616 | - return ''; |
|
| 612 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 613 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 614 | + return strtolower($regs[1]); |
|
| 615 | + } |
|
| 616 | + return ''; |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | /** |
@@ -624,42 +624,42 @@ discard block |
||
| 624 | 624 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 625 | 625 | */ |
| 626 | 626 | function _image_trouver_extension_pertinente($path) { |
| 627 | - $path = supprimer_timestamp($path); |
|
| 628 | - $terminaison = _image_trouver_extension($path); |
|
| 629 | - if ($terminaison == 'jpg') { |
|
| 630 | - $terminaison = 'jpeg'; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - if (!file_exists($path)) { |
|
| 634 | - return $terminaison; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - if (!$info = @spip_getimagesize($path)) { |
|
| 638 | - return $terminaison; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - $mime = $info['mime'] ?? image_type_to_mime_type($info[2]); |
|
| 642 | - |
|
| 643 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 644 | - if ($_terminaison && $_terminaison !== $terminaison) { |
|
| 645 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 646 | - $terminaison = $_terminaison; |
|
| 647 | - } |
|
| 648 | - return $terminaison; |
|
| 627 | + $path = supprimer_timestamp($path); |
|
| 628 | + $terminaison = _image_trouver_extension($path); |
|
| 629 | + if ($terminaison == 'jpg') { |
|
| 630 | + $terminaison = 'jpeg'; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + if (!file_exists($path)) { |
|
| 634 | + return $terminaison; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + if (!$info = @spip_getimagesize($path)) { |
|
| 638 | + return $terminaison; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + $mime = $info['mime'] ?? image_type_to_mime_type($info[2]); |
|
| 642 | + |
|
| 643 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 644 | + if ($_terminaison && $_terminaison !== $terminaison) { |
|
| 645 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 646 | + $terminaison = $_terminaison; |
|
| 647 | + } |
|
| 648 | + return $terminaison; |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | /** |
| 652 | 652 | * Retourne une extension d’image depuis un mime-type |
| 653 | 653 | */ |
| 654 | 654 | function _image_trouver_extension_depuis_mime(string $mime): string { |
| 655 | - return match (strtolower($mime)) { |
|
| 656 | - 'image/png', 'image/x-png' => 'png', |
|
| 657 | - 'image/jpg', 'image/jpeg', 'image/pjpeg' => 'jpeg', |
|
| 658 | - 'image/gif' => 'gif', |
|
| 659 | - 'image/webp', 'image/x-webp' => 'webp', |
|
| 660 | - 'image/svg+xml' => 'svg', |
|
| 661 | - default => '', |
|
| 662 | - }; |
|
| 655 | + return match (strtolower($mime)) { |
|
| 656 | + 'image/png', 'image/x-png' => 'png', |
|
| 657 | + 'image/jpg', 'image/jpeg', 'image/pjpeg' => 'jpeg', |
|
| 658 | + 'image/gif' => 'gif', |
|
| 659 | + 'image/webp', 'image/x-webp' => 'webp', |
|
| 660 | + 'image/svg+xml' => 'svg', |
|
| 661 | + default => '', |
|
| 662 | + }; |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | |
@@ -679,18 +679,18 @@ discard block |
||
| 679 | 679 | * Une ressource de type Image GD. |
| 680 | 680 | */ |
| 681 | 681 | function _imagecreatefrom_func(string $func, string $filename) { |
| 682 | - if (!function_exists($func)) { |
|
| 683 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 684 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 685 | - return null; |
|
| 686 | - } |
|
| 687 | - $img = @$func($filename); |
|
| 688 | - if (!$img) { |
|
| 689 | - spip_log("Erreur lecture $func $filename", _LOG_CRITIQUE); |
|
| 690 | - erreur_squelette("Erreur lecture $func $filename"); |
|
| 691 | - $img = imagecreate(10, 10); |
|
| 692 | - } |
|
| 693 | - return $img; |
|
| 682 | + if (!function_exists($func)) { |
|
| 683 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 684 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 685 | + return null; |
|
| 686 | + } |
|
| 687 | + $img = @$func($filename); |
|
| 688 | + if (!$img) { |
|
| 689 | + spip_log("Erreur lecture $func $filename", _LOG_CRITIQUE); |
|
| 690 | + erreur_squelette("Erreur lecture $func $filename"); |
|
| 691 | + $img = imagecreate(10, 10); |
|
| 692 | + } |
|
| 693 | + return $img; |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | /** |
@@ -706,7 +706,7 @@ discard block |
||
| 706 | 706 | * Une ressource de type Image GD. |
| 707 | 707 | */ |
| 708 | 708 | function _imagecreatefromjpeg($filename) { |
| 709 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 709 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | * Une ressource de type Image GD. |
| 723 | 723 | */ |
| 724 | 724 | function _imagecreatefrompng($filename) { |
| 725 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 725 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | /** |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | * Une ressource de type Image GD. |
| 739 | 739 | */ |
| 740 | 740 | function _imagecreatefromgif($filename) { |
| 741 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 741 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | |
@@ -755,7 +755,7 @@ discard block |
||
| 755 | 755 | * Une ressource de type Image GD. |
| 756 | 756 | */ |
| 757 | 757 | function _imagecreatefromwebp($filename) { |
| 758 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 758 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | /** |
@@ -773,24 +773,24 @@ discard block |
||
| 773 | 773 | * - true si une image est bien retournée. |
| 774 | 774 | */ |
| 775 | 775 | function _image_imagepng($img, $fichier) { |
| 776 | - if (!function_exists('imagepng')) { |
|
| 777 | - return false; |
|
| 778 | - } |
|
| 779 | - $tmp = $fichier . '.tmp'; |
|
| 780 | - $ret = imagepng($img, $tmp); |
|
| 781 | - if (file_exists($tmp)) { |
|
| 782 | - $taille_test = @getimagesize($tmp); |
|
| 783 | - if (empty($taille_test[0])) { |
|
| 784 | - return false; |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 788 | - @rename($tmp, $fichier); |
|
| 789 | - |
|
| 790 | - return $ret; |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - return false; |
|
| 776 | + if (!function_exists('imagepng')) { |
|
| 777 | + return false; |
|
| 778 | + } |
|
| 779 | + $tmp = $fichier . '.tmp'; |
|
| 780 | + $ret = imagepng($img, $tmp); |
|
| 781 | + if (file_exists($tmp)) { |
|
| 782 | + $taille_test = @getimagesize($tmp); |
|
| 783 | + if (empty($taille_test[0])) { |
|
| 784 | + return false; |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 788 | + @rename($tmp, $fichier); |
|
| 789 | + |
|
| 790 | + return $ret; |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + return false; |
|
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | /** |
@@ -808,24 +808,24 @@ discard block |
||
| 808 | 808 | * - true si une image est bien retournée. |
| 809 | 809 | */ |
| 810 | 810 | function _image_imagegif($img, $fichier) { |
| 811 | - if (!function_exists('imagegif')) { |
|
| 812 | - return false; |
|
| 813 | - } |
|
| 814 | - $tmp = $fichier . '.tmp'; |
|
| 815 | - $ret = imagegif($img, $tmp); |
|
| 816 | - if (file_exists($tmp)) { |
|
| 817 | - $taille_test = @getimagesize($tmp); |
|
| 818 | - if (empty($taille_test[0])) { |
|
| 819 | - return false; |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 823 | - @rename($tmp, $fichier); |
|
| 824 | - |
|
| 825 | - return $ret; |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - return false; |
|
| 811 | + if (!function_exists('imagegif')) { |
|
| 812 | + return false; |
|
| 813 | + } |
|
| 814 | + $tmp = $fichier . '.tmp'; |
|
| 815 | + $ret = imagegif($img, $tmp); |
|
| 816 | + if (file_exists($tmp)) { |
|
| 817 | + $taille_test = @getimagesize($tmp); |
|
| 818 | + if (empty($taille_test[0])) { |
|
| 819 | + return false; |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 823 | + @rename($tmp, $fichier); |
|
| 824 | + |
|
| 825 | + return $ret; |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + return false; |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | /** |
@@ -848,29 +848,29 @@ discard block |
||
| 848 | 848 | * - true si une image est bien retournée. |
| 849 | 849 | */ |
| 850 | 850 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 851 | - if (!function_exists('imagejpeg')) { |
|
| 852 | - return false; |
|
| 853 | - } |
|
| 854 | - $tmp = $fichier . '.tmp'; |
|
| 851 | + if (!function_exists('imagejpeg')) { |
|
| 852 | + return false; |
|
| 853 | + } |
|
| 854 | + $tmp = $fichier . '.tmp'; |
|
| 855 | 855 | |
| 856 | - // Enable interlancing |
|
| 857 | - imageinterlace($img, true); |
|
| 856 | + // Enable interlancing |
|
| 857 | + imageinterlace($img, true); |
|
| 858 | 858 | |
| 859 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 859 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 860 | 860 | |
| 861 | - if (file_exists($tmp)) { |
|
| 862 | - $taille_test = @getimagesize($tmp); |
|
| 863 | - if (empty($taille_test[0])) { |
|
| 864 | - return false; |
|
| 865 | - } |
|
| 861 | + if (file_exists($tmp)) { |
|
| 862 | + $taille_test = @getimagesize($tmp); |
|
| 863 | + if (empty($taille_test[0])) { |
|
| 864 | + return false; |
|
| 865 | + } |
|
| 866 | 866 | |
| 867 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 868 | - @rename($tmp, $fichier); |
|
| 867 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 868 | + @rename($tmp, $fichier); |
|
| 869 | 869 | |
| 870 | - return $ret; |
|
| 871 | - } |
|
| 870 | + return $ret; |
|
| 871 | + } |
|
| 872 | 872 | |
| 873 | - return false; |
|
| 873 | + return false; |
|
| 874 | 874 | } |
| 875 | 875 | |
| 876 | 876 | /** |
@@ -888,9 +888,9 @@ discard block |
||
| 888 | 888 | * true si le fichier a bien été créé ; false sinon. |
| 889 | 889 | */ |
| 890 | 890 | function _image_imageico($img, $fichier) { |
| 891 | - $gd_image_array = [$img]; |
|
| 891 | + $gd_image_array = [$img]; |
|
| 892 | 892 | |
| 893 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 893 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | |
@@ -909,24 +909,24 @@ discard block |
||
| 909 | 909 | * - true si une image est bien retournée. |
| 910 | 910 | */ |
| 911 | 911 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 912 | - if (!function_exists('imagewebp')) { |
|
| 913 | - return false; |
|
| 914 | - } |
|
| 915 | - $tmp = $fichier . '.tmp'; |
|
| 916 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 917 | - if (file_exists($tmp)) { |
|
| 918 | - $taille_test = @getimagesize($tmp); |
|
| 919 | - if (empty($taille_test[0])) { |
|
| 920 | - return false; |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 924 | - @rename($tmp, $fichier); |
|
| 925 | - |
|
| 926 | - return $ret; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - return false; |
|
| 912 | + if (!function_exists('imagewebp')) { |
|
| 913 | + return false; |
|
| 914 | + } |
|
| 915 | + $tmp = $fichier . '.tmp'; |
|
| 916 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 917 | + if (file_exists($tmp)) { |
|
| 918 | + $taille_test = @getimagesize($tmp); |
|
| 919 | + if (empty($taille_test[0])) { |
|
| 920 | + return false; |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 924 | + @rename($tmp, $fichier); |
|
| 925 | + |
|
| 926 | + return $ret; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + return false; |
|
| 930 | 930 | } |
| 931 | 931 | |
| 932 | 932 | /** |
@@ -946,35 +946,35 @@ discard block |
||
| 946 | 946 | */ |
| 947 | 947 | function _image_imagesvg($img, $fichier) { |
| 948 | 948 | |
| 949 | - $tmp = $fichier . '.tmp'; |
|
| 950 | - if (!str_contains($img, '<')) { |
|
| 951 | - $img = supprimer_timestamp($img); |
|
| 952 | - if (!file_exists($img)) { |
|
| 953 | - return false; |
|
| 954 | - } |
|
| 955 | - @copy($img, $tmp); |
|
| 956 | - if (filesize($tmp) === filesize($img)) { |
|
| 957 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 958 | - @rename($tmp, $fichier); |
|
| 959 | - return true; |
|
| 960 | - } |
|
| 961 | - return false; |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - file_put_contents($tmp, $img); |
|
| 965 | - if (file_exists($tmp)) { |
|
| 966 | - $taille_test = spip_getimagesize($tmp); |
|
| 967 | - if (empty($taille_test[0])) { |
|
| 968 | - return false; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 972 | - @rename($tmp, $fichier); |
|
| 973 | - |
|
| 974 | - return true; |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - return false; |
|
| 949 | + $tmp = $fichier . '.tmp'; |
|
| 950 | + if (!str_contains($img, '<')) { |
|
| 951 | + $img = supprimer_timestamp($img); |
|
| 952 | + if (!file_exists($img)) { |
|
| 953 | + return false; |
|
| 954 | + } |
|
| 955 | + @copy($img, $tmp); |
|
| 956 | + if (filesize($tmp) === filesize($img)) { |
|
| 957 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 958 | + @rename($tmp, $fichier); |
|
| 959 | + return true; |
|
| 960 | + } |
|
| 961 | + return false; |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + file_put_contents($tmp, $img); |
|
| 965 | + if (file_exists($tmp)) { |
|
| 966 | + $taille_test = spip_getimagesize($tmp); |
|
| 967 | + if (empty($taille_test[0])) { |
|
| 968 | + return false; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 972 | + @rename($tmp, $fichier); |
|
| 973 | + |
|
| 974 | + return true; |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + return false; |
|
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | |
@@ -1002,30 +1002,30 @@ discard block |
||
| 1002 | 1002 | * - false sinon. |
| 1003 | 1003 | */ |
| 1004 | 1004 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1005 | - if (is_null($fonction)) { |
|
| 1006 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1007 | - } |
|
| 1008 | - $ret = false; |
|
| 1009 | - #un flag pour reperer les images gravees |
|
| 1010 | - $lock = ( |
|
| 1011 | - !statut_effacer_images_temporaires('get') |
|
| 1012 | - || @file_exists($valeurs['fichier_dest']) |
|
| 1013 | - && !@file_exists($valeurs['fichier_dest'] . '.src') |
|
| 1014 | - ); |
|
| 1015 | - if ( |
|
| 1016 | - function_exists($fonction) |
|
| 1017 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1018 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1019 | - && !$lock && @file_exists($valeurs['fichier_dest']) |
|
| 1020 | - ) { |
|
| 1021 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1022 | - [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1023 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); |
|
| 1024 | - // pour la retrouver apres disparition |
|
| 1025 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - return $ret; |
|
| 1005 | + if (is_null($fonction)) { |
|
| 1006 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1007 | + } |
|
| 1008 | + $ret = false; |
|
| 1009 | + #un flag pour reperer les images gravees |
|
| 1010 | + $lock = ( |
|
| 1011 | + !statut_effacer_images_temporaires('get') |
|
| 1012 | + || @file_exists($valeurs['fichier_dest']) |
|
| 1013 | + && !@file_exists($valeurs['fichier_dest'] . '.src') |
|
| 1014 | + ); |
|
| 1015 | + if ( |
|
| 1016 | + function_exists($fonction) |
|
| 1017 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1018 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1019 | + && !$lock && @file_exists($valeurs['fichier_dest']) |
|
| 1020 | + ) { |
|
| 1021 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1022 | + [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1023 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); |
|
| 1024 | + // pour la retrouver apres disparition |
|
| 1025 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + return $ret; |
|
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | 1031 | /** |
@@ -1038,28 +1038,28 @@ discard block |
||
| 1038 | 1038 | * Chemin vers le fichier manquant |
| 1039 | 1039 | **/ |
| 1040 | 1040 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1041 | - $source = null; |
|
| 1042 | - $reconstruire = []; |
|
| 1043 | - $fichier = $fichier_manquant; |
|
| 1044 | - while ( |
|
| 1045 | - !str_contains((string) $fichier, '://') |
|
| 1046 | - && !@file_exists($fichier) |
|
| 1047 | - && lire_fichier($src = "$fichier.src", $source) |
|
| 1048 | - && ($valeurs = unserialize($source)) |
|
| 1049 | - && ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1050 | - ) { |
|
| 1051 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1052 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1053 | - } |
|
| 1054 | - while (count($reconstruire)) { |
|
| 1055 | - $r = array_pop($reconstruire); |
|
| 1056 | - $fonction = $r[0]; |
|
| 1057 | - $args = $r[1]; |
|
| 1058 | - $fonction(...$args); |
|
| 1059 | - } |
|
| 1060 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1061 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1062 | - ramasse_miettes($fichier_manquant); |
|
| 1041 | + $source = null; |
|
| 1042 | + $reconstruire = []; |
|
| 1043 | + $fichier = $fichier_manquant; |
|
| 1044 | + while ( |
|
| 1045 | + !str_contains((string) $fichier, '://') |
|
| 1046 | + && !@file_exists($fichier) |
|
| 1047 | + && lire_fichier($src = "$fichier.src", $source) |
|
| 1048 | + && ($valeurs = unserialize($source)) |
|
| 1049 | + && ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1050 | + ) { |
|
| 1051 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1052 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1053 | + } |
|
| 1054 | + while (count($reconstruire)) { |
|
| 1055 | + $r = array_pop($reconstruire); |
|
| 1056 | + $fonction = $r[0]; |
|
| 1057 | + $args = $r[1]; |
|
| 1058 | + $fonction(...$args); |
|
| 1059 | + } |
|
| 1060 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1061 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1062 | + ramasse_miettes($fichier_manquant); |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | /** |
@@ -1079,26 +1079,26 @@ discard block |
||
| 1079 | 1079 | * Chemin du fichier d'image calculé |
| 1080 | 1080 | **/ |
| 1081 | 1081 | function ramasse_miettes($fichier) { |
| 1082 | - $source = null; |
|
| 1083 | - if ( |
|
| 1084 | - str_contains($fichier, '://') |
|
| 1085 | - || !lire_fichier($src = "$fichier.src", $source) |
|
| 1086 | - || !$valeurs = unserialize($source) |
|
| 1087 | - ) { |
|
| 1088 | - return; |
|
| 1089 | - } |
|
| 1090 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1091 | - while ( |
|
| 1092 | - ($fichier = $valeurs['fichier']) |
|
| 1093 | - && str_starts_with((string) $fichier, (string) _DIR_VAR) |
|
| 1094 | - && lire_fichier($src = "$fichier.src", $source) |
|
| 1095 | - && ($valeurs = unserialize($source)) # et valide |
|
| 1096 | - ) { |
|
| 1097 | - # on efface le fichier |
|
| 1098 | - spip_unlink($fichier); |
|
| 1099 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1100 | - #spip_unlink($src); |
|
| 1101 | - } |
|
| 1082 | + $source = null; |
|
| 1083 | + if ( |
|
| 1084 | + str_contains($fichier, '://') |
|
| 1085 | + || !lire_fichier($src = "$fichier.src", $source) |
|
| 1086 | + || !$valeurs = unserialize($source) |
|
| 1087 | + ) { |
|
| 1088 | + return; |
|
| 1089 | + } |
|
| 1090 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1091 | + while ( |
|
| 1092 | + ($fichier = $valeurs['fichier']) |
|
| 1093 | + && str_starts_with((string) $fichier, (string) _DIR_VAR) |
|
| 1094 | + && lire_fichier($src = "$fichier.src", $source) |
|
| 1095 | + && ($valeurs = unserialize($source)) # et valide |
|
| 1096 | + ) { |
|
| 1097 | + # on efface le fichier |
|
| 1098 | + spip_unlink($fichier); |
|
| 1099 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1100 | + #spip_unlink($src); |
|
| 1101 | + } |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | |
@@ -1123,33 +1123,33 @@ discard block |
||
| 1123 | 1123 | * Code HTML de l'image |
| 1124 | 1124 | **/ |
| 1125 | 1125 | function image_graver($img) { |
| 1126 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1127 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1128 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1129 | - |
|
| 1130 | - $fichier_ori = $fichier = (extraire_attribut($img, 'src') ?? ''); |
|
| 1131 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1132 | - $fichier = substr($fichier, 0, $p); |
|
| 1133 | - } |
|
| 1134 | - if (strlen($fichier) < 1 && !str_starts_with((string) $img, '<img ')) { |
|
| 1135 | - $fichier = $img; |
|
| 1136 | - } |
|
| 1137 | - if (strlen((string) $fichier)) { |
|
| 1138 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1139 | - # et qu'il ne s'agit pas d'une URL |
|
| 1140 | - if (!str_contains((string) $fichier, '://') && !@file_exists($fichier)) { |
|
| 1141 | - reconstruire_image_intermediaire($fichier); |
|
| 1142 | - } |
|
| 1143 | - ramasse_miettes($fichier); |
|
| 1144 | - |
|
| 1145 | - // ajouter le timestamp si besoin |
|
| 1146 | - if (!str_contains($fichier_ori, '?')) { |
|
| 1147 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1148 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), (string) $img); |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - return $img; |
|
| 1126 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1127 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1128 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1129 | + |
|
| 1130 | + $fichier_ori = $fichier = (extraire_attribut($img, 'src') ?? ''); |
|
| 1131 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1132 | + $fichier = substr($fichier, 0, $p); |
|
| 1133 | + } |
|
| 1134 | + if (strlen($fichier) < 1 && !str_starts_with((string) $img, '<img ')) { |
|
| 1135 | + $fichier = $img; |
|
| 1136 | + } |
|
| 1137 | + if (strlen((string) $fichier)) { |
|
| 1138 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1139 | + # et qu'il ne s'agit pas d'une URL |
|
| 1140 | + if (!str_contains((string) $fichier, '://') && !@file_exists($fichier)) { |
|
| 1141 | + reconstruire_image_intermediaire($fichier); |
|
| 1142 | + } |
|
| 1143 | + ramasse_miettes($fichier); |
|
| 1144 | + |
|
| 1145 | + // ajouter le timestamp si besoin |
|
| 1146 | + if (!str_contains($fichier_ori, '?')) { |
|
| 1147 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1148 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), (string) $img); |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + return $img; |
|
| 1153 | 1153 | } |
| 1154 | 1154 | |
| 1155 | 1155 | /** |
@@ -1176,32 +1176,32 @@ discard block |
||
| 1176 | 1176 | * Code html modifié de la balise. |
| 1177 | 1177 | **/ |
| 1178 | 1178 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1179 | - if ($style === false) { |
|
| 1180 | - $style = extraire_attribut($tag, 'style'); |
|
| 1181 | - } |
|
| 1182 | - |
|
| 1183 | - // enlever le width et height du style |
|
| 1184 | - if ($style) { |
|
| 1185 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1186 | - } |
|
| 1187 | - if ($style && $style[0] === ';') { |
|
| 1188 | - $style = substr($style, 1); |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - // mettre des attributs de width et height sur les images, |
|
| 1192 | - // ca accelere le rendu du navigateur |
|
| 1193 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1194 | - // quand on a desactive l'affichage des images. |
|
| 1195 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1196 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1197 | - |
|
| 1198 | - // attributs deprecies. Transformer en CSS |
|
| 1199 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1200 | - $style = "margin:{$espace}px;" . $style; |
|
| 1201 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - return inserer_attribut($tag, 'style', (string) $style, true, !(bool) $style); |
|
| 1179 | + if ($style === false) { |
|
| 1180 | + $style = extraire_attribut($tag, 'style'); |
|
| 1181 | + } |
|
| 1182 | + |
|
| 1183 | + // enlever le width et height du style |
|
| 1184 | + if ($style) { |
|
| 1185 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1186 | + } |
|
| 1187 | + if ($style && $style[0] === ';') { |
|
| 1188 | + $style = substr($style, 1); |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + // mettre des attributs de width et height sur les images, |
|
| 1192 | + // ca accelere le rendu du navigateur |
|
| 1193 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1194 | + // quand on a desactive l'affichage des images. |
|
| 1195 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1196 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1197 | + |
|
| 1198 | + // attributs deprecies. Transformer en CSS |
|
| 1199 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1200 | + $style = "margin:{$espace}px;" . $style; |
|
| 1201 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + return inserer_attribut($tag, 'style', (string) $style, true, !(bool) $style); |
|
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | 1207 | |
@@ -1227,70 +1227,70 @@ discard block |
||
| 1227 | 1227 | * Retourne le code HTML de l'image |
| 1228 | 1228 | **/ |
| 1229 | 1229 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1230 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1231 | - |
|
| 1232 | - // fermer les tags img pas bien fermes; |
|
| 1233 | - $tag = str_replace('>', '/>', str_replace('/>', '>', (string) $valeurs['tag'])); |
|
| 1234 | - |
|
| 1235 | - // le style |
|
| 1236 | - $style = $valeurs['style']; |
|
| 1237 | - if (isset($surcharge['style'])) { |
|
| 1238 | - $style = $surcharge['style']; |
|
| 1239 | - unset($surcharge['style']); |
|
| 1240 | - } |
|
| 1241 | - |
|
| 1242 | - // traiter specifiquement la largeur et la hauteur |
|
| 1243 | - $width = $valeurs['largeur']; |
|
| 1244 | - if (isset($surcharge['width'])) { |
|
| 1245 | - $width = $surcharge['width']; |
|
| 1246 | - unset($surcharge['width']); |
|
| 1247 | - } |
|
| 1248 | - $height = $valeurs['hauteur']; |
|
| 1249 | - if (isset($surcharge['height'])) { |
|
| 1250 | - $height = $surcharge['height']; |
|
| 1251 | - unset($surcharge['height']); |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1255 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1256 | - // on remplace toute les ref a src dans le tag |
|
| 1257 | - $src = extraire_attribut($tag, 'src'); |
|
| 1258 | - if (isset($surcharge['src'])) { |
|
| 1259 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1260 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1261 | - // pas garanti comme methode, mais mieux que rien |
|
| 1262 | - if (str_contains($src, '&')) { |
|
| 1263 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1264 | - } |
|
| 1265 | - $src = $surcharge['src']; |
|
| 1266 | - unset($surcharge['src']); |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - $class = $valeurs['class']; |
|
| 1270 | - if (isset($surcharge['class'])) { |
|
| 1271 | - $class = $surcharge['class']; |
|
| 1272 | - unset($surcharge['class']); |
|
| 1273 | - } |
|
| 1274 | - if (is_scalar($class) && strlen($class)) { |
|
| 1275 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - if ($surcharge !== []) { |
|
| 1279 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1280 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - return pipeline( |
|
| 1285 | - 'image_ecrire_tag_finir', |
|
| 1286 | - [ |
|
| 1287 | - 'args' => [ |
|
| 1288 | - 'valeurs' => $valeurs, |
|
| 1289 | - 'surcharge' => $surcharge, |
|
| 1290 | - ], |
|
| 1291 | - 'data' => $tag |
|
| 1292 | - ] |
|
| 1293 | - ); |
|
| 1230 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1231 | + |
|
| 1232 | + // fermer les tags img pas bien fermes; |
|
| 1233 | + $tag = str_replace('>', '/>', str_replace('/>', '>', (string) $valeurs['tag'])); |
|
| 1234 | + |
|
| 1235 | + // le style |
|
| 1236 | + $style = $valeurs['style']; |
|
| 1237 | + if (isset($surcharge['style'])) { |
|
| 1238 | + $style = $surcharge['style']; |
|
| 1239 | + unset($surcharge['style']); |
|
| 1240 | + } |
|
| 1241 | + |
|
| 1242 | + // traiter specifiquement la largeur et la hauteur |
|
| 1243 | + $width = $valeurs['largeur']; |
|
| 1244 | + if (isset($surcharge['width'])) { |
|
| 1245 | + $width = $surcharge['width']; |
|
| 1246 | + unset($surcharge['width']); |
|
| 1247 | + } |
|
| 1248 | + $height = $valeurs['hauteur']; |
|
| 1249 | + if (isset($surcharge['height'])) { |
|
| 1250 | + $height = $surcharge['height']; |
|
| 1251 | + unset($surcharge['height']); |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1255 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1256 | + // on remplace toute les ref a src dans le tag |
|
| 1257 | + $src = extraire_attribut($tag, 'src'); |
|
| 1258 | + if (isset($surcharge['src'])) { |
|
| 1259 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1260 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1261 | + // pas garanti comme methode, mais mieux que rien |
|
| 1262 | + if (str_contains($src, '&')) { |
|
| 1263 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1264 | + } |
|
| 1265 | + $src = $surcharge['src']; |
|
| 1266 | + unset($surcharge['src']); |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + $class = $valeurs['class']; |
|
| 1270 | + if (isset($surcharge['class'])) { |
|
| 1271 | + $class = $surcharge['class']; |
|
| 1272 | + unset($surcharge['class']); |
|
| 1273 | + } |
|
| 1274 | + if (is_scalar($class) && strlen($class)) { |
|
| 1275 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + if ($surcharge !== []) { |
|
| 1279 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1280 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + return pipeline( |
|
| 1285 | + 'image_ecrire_tag_finir', |
|
| 1286 | + [ |
|
| 1287 | + 'args' => [ |
|
| 1288 | + 'valeurs' => $valeurs, |
|
| 1289 | + 'surcharge' => $surcharge, |
|
| 1290 | + ], |
|
| 1291 | + 'data' => $tag |
|
| 1292 | + ] |
|
| 1293 | + ); |
|
| 1294 | 1294 | } |
| 1295 | 1295 | |
| 1296 | 1296 | /** |
@@ -1313,268 +1313,268 @@ discard block |
||
| 1313 | 1313 | * Description de l'image, sinon null. |
| 1314 | 1314 | **/ |
| 1315 | 1315 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1316 | - $srcHeight = null; |
|
| 1317 | - $retour = []; |
|
| 1318 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1319 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1320 | - $image = $valeurs['fichier']; |
|
| 1321 | - $format = $valeurs['format_source']; |
|
| 1322 | - $destdir = dirname((string) $valeurs['fichier_dest']); |
|
| 1323 | - $destfile = basename((string) $valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1324 | - |
|
| 1325 | - $format_sortie = $valeurs['format_dest']; |
|
| 1326 | - |
|
| 1327 | - if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) { |
|
| 1328 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1332 | - if (!$force && !in_array($format, formats_image_acceptables($process === 'gd2'))) { |
|
| 1333 | - return; |
|
| 1334 | - } |
|
| 1335 | - $destination = "$destdir/$destfile"; |
|
| 1336 | - |
|
| 1337 | - // calculer la taille |
|
| 1338 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1339 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1340 | - [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1341 | - } |
|
| 1342 | - } elseif ($process == 'convert' || $process == 'imagick') { |
|
| 1343 | - $destWidth = $maxWidth; |
|
| 1344 | - $destHeight = $maxHeight; |
|
| 1345 | - } else { |
|
| 1346 | - spip_log("echec $process sur $image"); |
|
| 1347 | - |
|
| 1348 | - return; |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - $vignette = ''; |
|
| 1352 | - |
|
| 1353 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1354 | - if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
|
| 1355 | - $vignette = $destination . '.' . $format; |
|
| 1356 | - @copy($image, $vignette); |
|
| 1357 | - } |
|
| 1358 | - |
|
| 1359 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1360 | - include_spip('inc/svg'); |
|
| 1361 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1362 | - $format_sortie = 'svg'; |
|
| 1363 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1364 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1365 | - _image_gd_output($svg, $valeurs); |
|
| 1366 | - } |
|
| 1367 | - } |
|
| 1368 | - |
|
| 1369 | - // imagemagick en ligne de commande |
|
| 1370 | - elseif ($process == 'convert') { |
|
| 1371 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1372 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1373 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1374 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1375 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest'); |
|
| 1376 | - } |
|
| 1377 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1378 | - $commande = str_replace( |
|
| 1379 | - ['%x', '%y', '%src', '%dest'], |
|
| 1380 | - [ |
|
| 1381 | - $destWidth, |
|
| 1382 | - $destHeight, |
|
| 1383 | - escapeshellcmd($image), |
|
| 1384 | - escapeshellcmd($vignette) |
|
| 1385 | - ], |
|
| 1386 | - (string) _RESIZE_COMMAND |
|
| 1387 | - ); |
|
| 1388 | - spip_log($commande); |
|
| 1389 | - exec($commande); |
|
| 1390 | - if (!@file_exists($vignette)) { |
|
| 1391 | - spip_log("echec convert sur $vignette"); |
|
| 1392 | - |
|
| 1393 | - return; // echec commande |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - |
|
| 1397 | - // php5 imagemagick |
|
| 1398 | - elseif ($process == 'imagick') { |
|
| 1399 | - if (!class_exists(\Imagick::class)) { |
|
| 1400 | - spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1401 | - |
|
| 1402 | - return; |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - // chemin compatible Windows |
|
| 1406 | - $output = realpath(dirname($destination)); |
|
| 1407 | - if (!$output) { |
|
| 1408 | - return; |
|
| 1409 | - } |
|
| 1410 | - $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1411 | - |
|
| 1412 | - $imagick = new Imagick(); |
|
| 1413 | - $imagick->readImage(realpath($image)); |
|
| 1414 | - $imagick->resizeImage( |
|
| 1415 | - $destWidth, |
|
| 1416 | - $destHeight, |
|
| 1417 | - Imagick::FILTER_LANCZOS, |
|
| 1418 | - 1 |
|
| 1419 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1420 | - $imagick->writeImage($vignette); |
|
| 1421 | - |
|
| 1422 | - if (!@file_exists($vignette)) { |
|
| 1423 | - spip_log("echec imagick sur $vignette"); |
|
| 1424 | - |
|
| 1425 | - return; |
|
| 1426 | - } |
|
| 1427 | - // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1428 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1429 | - } |
|
| 1430 | - |
|
| 1431 | - // netpbm |
|
| 1432 | - elseif ($process == 'netpbm') { |
|
| 1433 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1434 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1435 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1436 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1437 | - return; |
|
| 1438 | - } |
|
| 1439 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1440 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', (string) _PNMSCALE_COMMAND); |
|
| 1441 | - if ($format == 'jpg') { |
|
| 1442 | - $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', (string) _PNMSCALE_COMMAND); |
|
| 1443 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1444 | - if (!($s = @filesize($vignette))) { |
|
| 1445 | - spip_unlink($vignette); |
|
| 1446 | - } |
|
| 1447 | - if (!@file_exists($vignette)) { |
|
| 1448 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1449 | - |
|
| 1450 | - return; |
|
| 1451 | - } |
|
| 1452 | - } else { |
|
| 1453 | - if ($format == 'gif') { |
|
| 1454 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', (string) _PNMSCALE_COMMAND); |
|
| 1455 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1456 | - if (!($s = @filesize($vignette))) { |
|
| 1457 | - spip_unlink($vignette); |
|
| 1458 | - } |
|
| 1459 | - if (!@file_exists($vignette)) { |
|
| 1460 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1461 | - |
|
| 1462 | - return; |
|
| 1463 | - } |
|
| 1464 | - } else { |
|
| 1465 | - if ($format == 'png') { |
|
| 1466 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', (string) _PNMSCALE_COMMAND); |
|
| 1467 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1468 | - if (!($s = @filesize($vignette))) { |
|
| 1469 | - spip_unlink($vignette); |
|
| 1470 | - } |
|
| 1471 | - if (!@file_exists($vignette)) { |
|
| 1472 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1473 | - |
|
| 1474 | - return; |
|
| 1475 | - } |
|
| 1476 | - } |
|
| 1477 | - } |
|
| 1478 | - } |
|
| 1479 | - } |
|
| 1480 | - |
|
| 1481 | - // gd ou gd2 |
|
| 1482 | - elseif ($process === 'gd2') { |
|
| 1483 | - if (!function_exists('gd_info')) { |
|
| 1484 | - spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1485 | - |
|
| 1486 | - return; |
|
| 1487 | - } |
|
| 1488 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1489 | - spip_log('vignette gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1490 | - |
|
| 1491 | - return; |
|
| 1492 | - } |
|
| 1493 | - $destFormat = $format_sortie; |
|
| 1494 | - if (!$destFormat) { |
|
| 1495 | - spip_log("pas de format pour $image"); |
|
| 1496 | - |
|
| 1497 | - return; |
|
| 1498 | - } |
|
| 1499 | - |
|
| 1500 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1501 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1502 | - return; |
|
| 1503 | - } |
|
| 1504 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1505 | - if (!$srcImage) { |
|
| 1506 | - spip_log('echec gd2'); |
|
| 1507 | - |
|
| 1508 | - return; |
|
| 1509 | - } |
|
| 1510 | - |
|
| 1511 | - // Initialisation de l'image destination |
|
| 1512 | - $destImage = null; |
|
| 1513 | - if ($process == 'gd2' && $destFormat != 'gif') { |
|
| 1514 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1515 | - } |
|
| 1516 | - if (!$destImage) { |
|
| 1517 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1521 | - $ok = false; |
|
| 1522 | - if ($process == 'gd2' && function_exists('ImageCopyResampled')) { |
|
| 1523 | - if ($format == 'gif') { |
|
| 1524 | - // Si un GIF est transparent, |
|
| 1525 | - // fabriquer un PNG transparent |
|
| 1526 | - $transp = imagecolortransparent($srcImage); |
|
| 1527 | - if ($transp > 0) { |
|
| 1528 | - $destFormat = 'png'; |
|
| 1529 | - } |
|
| 1530 | - } |
|
| 1531 | - if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1532 | - // Conserver la transparence |
|
| 1533 | - if (function_exists('imageAntiAlias')) { |
|
| 1534 | - imageAntiAlias($destImage, true); |
|
| 1535 | - } |
|
| 1536 | - @imagealphablending($destImage, false); |
|
| 1537 | - @imagesavealpha($destImage, true); |
|
| 1538 | - } |
|
| 1539 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1540 | - } |
|
| 1541 | - if (!$ok) { |
|
| 1542 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1543 | - } |
|
| 1544 | - |
|
| 1545 | - // Sauvegarde de l'image destination |
|
| 1546 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1547 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1548 | - _image_gd_output($destImage, $valeurs); |
|
| 1549 | - |
|
| 1550 | - if ($srcImage) { |
|
| 1551 | - ImageDestroy($srcImage); |
|
| 1552 | - } |
|
| 1553 | - ImageDestroy($destImage); |
|
| 1554 | - } |
|
| 1555 | - |
|
| 1556 | - if (!$vignette || !$size = @spip_getimagesize($vignette)) { |
|
| 1557 | - $size = [$destWidth, $destHeight]; |
|
| 1558 | - } |
|
| 1559 | - |
|
| 1560 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1561 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1562 | - if ($size[0] < 1) { |
|
| 1563 | - $size[0] = $destWidth; |
|
| 1564 | - } |
|
| 1565 | - if ($size[1] < 1) { |
|
| 1566 | - $size[1] = $destHeight; |
|
| 1567 | - } |
|
| 1568 | - |
|
| 1569 | - $retour['width'] = $largeur = $size[0]; |
|
| 1570 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1571 | - |
|
| 1572 | - $retour['fichier'] = $vignette; |
|
| 1573 | - $retour['format'] = $format; |
|
| 1574 | - $retour['date'] = @filemtime($vignette); |
|
| 1575 | - |
|
| 1576 | - // renvoyer l'image |
|
| 1577 | - return $retour; |
|
| 1316 | + $srcHeight = null; |
|
| 1317 | + $retour = []; |
|
| 1318 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1319 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1320 | + $image = $valeurs['fichier']; |
|
| 1321 | + $format = $valeurs['format_source']; |
|
| 1322 | + $destdir = dirname((string) $valeurs['fichier_dest']); |
|
| 1323 | + $destfile = basename((string) $valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1324 | + |
|
| 1325 | + $format_sortie = $valeurs['format_dest']; |
|
| 1326 | + |
|
| 1327 | + if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) { |
|
| 1328 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1332 | + if (!$force && !in_array($format, formats_image_acceptables($process === 'gd2'))) { |
|
| 1333 | + return; |
|
| 1334 | + } |
|
| 1335 | + $destination = "$destdir/$destfile"; |
|
| 1336 | + |
|
| 1337 | + // calculer la taille |
|
| 1338 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1339 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1340 | + [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1341 | + } |
|
| 1342 | + } elseif ($process == 'convert' || $process == 'imagick') { |
|
| 1343 | + $destWidth = $maxWidth; |
|
| 1344 | + $destHeight = $maxHeight; |
|
| 1345 | + } else { |
|
| 1346 | + spip_log("echec $process sur $image"); |
|
| 1347 | + |
|
| 1348 | + return; |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + $vignette = ''; |
|
| 1352 | + |
|
| 1353 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1354 | + if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
|
| 1355 | + $vignette = $destination . '.' . $format; |
|
| 1356 | + @copy($image, $vignette); |
|
| 1357 | + } |
|
| 1358 | + |
|
| 1359 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1360 | + include_spip('inc/svg'); |
|
| 1361 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1362 | + $format_sortie = 'svg'; |
|
| 1363 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1364 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1365 | + _image_gd_output($svg, $valeurs); |
|
| 1366 | + } |
|
| 1367 | + } |
|
| 1368 | + |
|
| 1369 | + // imagemagick en ligne de commande |
|
| 1370 | + elseif ($process == 'convert') { |
|
| 1371 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1372 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1373 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1374 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1375 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest'); |
|
| 1376 | + } |
|
| 1377 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1378 | + $commande = str_replace( |
|
| 1379 | + ['%x', '%y', '%src', '%dest'], |
|
| 1380 | + [ |
|
| 1381 | + $destWidth, |
|
| 1382 | + $destHeight, |
|
| 1383 | + escapeshellcmd($image), |
|
| 1384 | + escapeshellcmd($vignette) |
|
| 1385 | + ], |
|
| 1386 | + (string) _RESIZE_COMMAND |
|
| 1387 | + ); |
|
| 1388 | + spip_log($commande); |
|
| 1389 | + exec($commande); |
|
| 1390 | + if (!@file_exists($vignette)) { |
|
| 1391 | + spip_log("echec convert sur $vignette"); |
|
| 1392 | + |
|
| 1393 | + return; // echec commande |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + // php5 imagemagick |
|
| 1398 | + elseif ($process == 'imagick') { |
|
| 1399 | + if (!class_exists(\Imagick::class)) { |
|
| 1400 | + spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1401 | + |
|
| 1402 | + return; |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + // chemin compatible Windows |
|
| 1406 | + $output = realpath(dirname($destination)); |
|
| 1407 | + if (!$output) { |
|
| 1408 | + return; |
|
| 1409 | + } |
|
| 1410 | + $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1411 | + |
|
| 1412 | + $imagick = new Imagick(); |
|
| 1413 | + $imagick->readImage(realpath($image)); |
|
| 1414 | + $imagick->resizeImage( |
|
| 1415 | + $destWidth, |
|
| 1416 | + $destHeight, |
|
| 1417 | + Imagick::FILTER_LANCZOS, |
|
| 1418 | + 1 |
|
| 1419 | + );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1420 | + $imagick->writeImage($vignette); |
|
| 1421 | + |
|
| 1422 | + if (!@file_exists($vignette)) { |
|
| 1423 | + spip_log("echec imagick sur $vignette"); |
|
| 1424 | + |
|
| 1425 | + return; |
|
| 1426 | + } |
|
| 1427 | + // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1428 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1429 | + } |
|
| 1430 | + |
|
| 1431 | + // netpbm |
|
| 1432 | + elseif ($process == 'netpbm') { |
|
| 1433 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1434 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1435 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1436 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1437 | + return; |
|
| 1438 | + } |
|
| 1439 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1440 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', (string) _PNMSCALE_COMMAND); |
|
| 1441 | + if ($format == 'jpg') { |
|
| 1442 | + $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', (string) _PNMSCALE_COMMAND); |
|
| 1443 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1444 | + if (!($s = @filesize($vignette))) { |
|
| 1445 | + spip_unlink($vignette); |
|
| 1446 | + } |
|
| 1447 | + if (!@file_exists($vignette)) { |
|
| 1448 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1449 | + |
|
| 1450 | + return; |
|
| 1451 | + } |
|
| 1452 | + } else { |
|
| 1453 | + if ($format == 'gif') { |
|
| 1454 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', (string) _PNMSCALE_COMMAND); |
|
| 1455 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1456 | + if (!($s = @filesize($vignette))) { |
|
| 1457 | + spip_unlink($vignette); |
|
| 1458 | + } |
|
| 1459 | + if (!@file_exists($vignette)) { |
|
| 1460 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1461 | + |
|
| 1462 | + return; |
|
| 1463 | + } |
|
| 1464 | + } else { |
|
| 1465 | + if ($format == 'png') { |
|
| 1466 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', (string) _PNMSCALE_COMMAND); |
|
| 1467 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1468 | + if (!($s = @filesize($vignette))) { |
|
| 1469 | + spip_unlink($vignette); |
|
| 1470 | + } |
|
| 1471 | + if (!@file_exists($vignette)) { |
|
| 1472 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1473 | + |
|
| 1474 | + return; |
|
| 1475 | + } |
|
| 1476 | + } |
|
| 1477 | + } |
|
| 1478 | + } |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + // gd ou gd2 |
|
| 1482 | + elseif ($process === 'gd2') { |
|
| 1483 | + if (!function_exists('gd_info')) { |
|
| 1484 | + spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1485 | + |
|
| 1486 | + return; |
|
| 1487 | + } |
|
| 1488 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1489 | + spip_log('vignette gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1490 | + |
|
| 1491 | + return; |
|
| 1492 | + } |
|
| 1493 | + $destFormat = $format_sortie; |
|
| 1494 | + if (!$destFormat) { |
|
| 1495 | + spip_log("pas de format pour $image"); |
|
| 1496 | + |
|
| 1497 | + return; |
|
| 1498 | + } |
|
| 1499 | + |
|
| 1500 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1501 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1502 | + return; |
|
| 1503 | + } |
|
| 1504 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1505 | + if (!$srcImage) { |
|
| 1506 | + spip_log('echec gd2'); |
|
| 1507 | + |
|
| 1508 | + return; |
|
| 1509 | + } |
|
| 1510 | + |
|
| 1511 | + // Initialisation de l'image destination |
|
| 1512 | + $destImage = null; |
|
| 1513 | + if ($process == 'gd2' && $destFormat != 'gif') { |
|
| 1514 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1515 | + } |
|
| 1516 | + if (!$destImage) { |
|
| 1517 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1521 | + $ok = false; |
|
| 1522 | + if ($process == 'gd2' && function_exists('ImageCopyResampled')) { |
|
| 1523 | + if ($format == 'gif') { |
|
| 1524 | + // Si un GIF est transparent, |
|
| 1525 | + // fabriquer un PNG transparent |
|
| 1526 | + $transp = imagecolortransparent($srcImage); |
|
| 1527 | + if ($transp > 0) { |
|
| 1528 | + $destFormat = 'png'; |
|
| 1529 | + } |
|
| 1530 | + } |
|
| 1531 | + if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1532 | + // Conserver la transparence |
|
| 1533 | + if (function_exists('imageAntiAlias')) { |
|
| 1534 | + imageAntiAlias($destImage, true); |
|
| 1535 | + } |
|
| 1536 | + @imagealphablending($destImage, false); |
|
| 1537 | + @imagesavealpha($destImage, true); |
|
| 1538 | + } |
|
| 1539 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1540 | + } |
|
| 1541 | + if (!$ok) { |
|
| 1542 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1543 | + } |
|
| 1544 | + |
|
| 1545 | + // Sauvegarde de l'image destination |
|
| 1546 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1547 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1548 | + _image_gd_output($destImage, $valeurs); |
|
| 1549 | + |
|
| 1550 | + if ($srcImage) { |
|
| 1551 | + ImageDestroy($srcImage); |
|
| 1552 | + } |
|
| 1553 | + ImageDestroy($destImage); |
|
| 1554 | + } |
|
| 1555 | + |
|
| 1556 | + if (!$vignette || !$size = @spip_getimagesize($vignette)) { |
|
| 1557 | + $size = [$destWidth, $destHeight]; |
|
| 1558 | + } |
|
| 1559 | + |
|
| 1560 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1561 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1562 | + if ($size[0] < 1) { |
|
| 1563 | + $size[0] = $destWidth; |
|
| 1564 | + } |
|
| 1565 | + if ($size[1] < 1) { |
|
| 1566 | + $size[1] = $destHeight; |
|
| 1567 | + } |
|
| 1568 | + |
|
| 1569 | + $retour['width'] = $largeur = $size[0]; |
|
| 1570 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1571 | + |
|
| 1572 | + $retour['fichier'] = $vignette; |
|
| 1573 | + $retour['format'] = $format; |
|
| 1574 | + $retour['date'] = @filemtime($vignette); |
|
| 1575 | + |
|
| 1576 | + // renvoyer l'image |
|
| 1577 | + return $retour; |
|
| 1578 | 1578 | } |
| 1579 | 1579 | |
| 1580 | 1580 | /** |
@@ -1594,25 +1594,25 @@ discard block |
||
| 1594 | 1594 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1595 | 1595 | **/ |
| 1596 | 1596 | function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1597 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1598 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1599 | - |
|
| 1600 | - if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
|
| 1601 | - $destWidth = $srcWidth; |
|
| 1602 | - $destHeight = $srcHeight; |
|
| 1603 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1604 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1605 | - $destHeight = $maxHeight; |
|
| 1606 | - } else { |
|
| 1607 | - $destWidth = $maxWidth; |
|
| 1608 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1609 | - } |
|
| 1610 | - |
|
| 1611 | - return [ |
|
| 1612 | - (int) round($destWidth), |
|
| 1613 | - (int) round($destHeight), |
|
| 1614 | - max($ratioWidth, $ratioHeight) |
|
| 1615 | - ]; |
|
| 1597 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1598 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1599 | + |
|
| 1600 | + if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
|
| 1601 | + $destWidth = $srcWidth; |
|
| 1602 | + $destHeight = $srcHeight; |
|
| 1603 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1604 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1605 | + $destHeight = $maxHeight; |
|
| 1606 | + } else { |
|
| 1607 | + $destWidth = $maxWidth; |
|
| 1608 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1609 | + } |
|
| 1610 | + |
|
| 1611 | + return [ |
|
| 1612 | + (int) round($destWidth), |
|
| 1613 | + (int) round($destHeight), |
|
| 1614 | + max($ratioWidth, $ratioHeight) |
|
| 1615 | + ]; |
|
| 1616 | 1616 | } |
| 1617 | 1617 | |
| 1618 | 1618 | /** |
@@ -1632,25 +1632,25 @@ discard block |
||
| 1632 | 1632 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1633 | 1633 | **/ |
| 1634 | 1634 | function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1635 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1636 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1637 | - |
|
| 1638 | - if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
|
| 1639 | - $destWidth = $srcWidth; |
|
| 1640 | - $destHeight = $srcHeight; |
|
| 1641 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1642 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1643 | - $destHeight = $maxHeight; |
|
| 1644 | - } else { |
|
| 1645 | - $destWidth = $maxWidth; |
|
| 1646 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - return [ |
|
| 1650 | - (int) round($destWidth), |
|
| 1651 | - (int) round($destHeight), |
|
| 1652 | - min($ratioWidth, $ratioHeight) |
|
| 1653 | - ]; |
|
| 1635 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1636 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1637 | + |
|
| 1638 | + if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
|
| 1639 | + $destWidth = $srcWidth; |
|
| 1640 | + $destHeight = $srcHeight; |
|
| 1641 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1642 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1643 | + $destHeight = $maxHeight; |
|
| 1644 | + } else { |
|
| 1645 | + $destWidth = $maxWidth; |
|
| 1646 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1647 | + } |
|
| 1648 | + |
|
| 1649 | + return [ |
|
| 1650 | + (int) round($destWidth), |
|
| 1651 | + (int) round($destHeight), |
|
| 1652 | + min($ratioWidth, $ratioHeight) |
|
| 1653 | + ]; |
|
| 1654 | 1654 | } |
| 1655 | 1655 | |
| 1656 | 1656 | |
@@ -1663,12 +1663,12 @@ discard block |
||
| 1663 | 1663 | * @return string |
| 1664 | 1664 | */ |
| 1665 | 1665 | function process_image_svg_identite($image) { |
| 1666 | - if ($image['creer']) { |
|
| 1667 | - $source = $image['fichier']; |
|
| 1668 | - _image_gd_output($source, $image); |
|
| 1669 | - } |
|
| 1666 | + if ($image['creer']) { |
|
| 1667 | + $source = $image['fichier']; |
|
| 1668 | + _image_gd_output($source, $image); |
|
| 1669 | + } |
|
| 1670 | 1670 | |
| 1671 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1671 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1672 | 1672 | } |
| 1673 | 1673 | |
| 1674 | 1674 | |
@@ -1701,102 +1701,102 @@ discard block |
||
| 1701 | 1701 | * Code HTML de la balise img produite |
| 1702 | 1702 | **/ |
| 1703 | 1703 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1704 | - $image = false; |
|
| 1705 | - if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) { |
|
| 1706 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1707 | - } |
|
| 1708 | - # determiner le format de sortie |
|
| 1709 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1710 | - if ($process === 'netpbm') { |
|
| 1711 | - $format_sortie = 'jpg'; |
|
| 1712 | - } elseif ($process === 'gd2') { |
|
| 1713 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1714 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1715 | - $gd_formats = formats_image_acceptables(true); |
|
| 1716 | - if ( |
|
| 1717 | - is_array($image) |
|
| 1718 | - && (!in_array($image['format_dest'], $gd_formats) || !in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1719 | - ) { |
|
| 1720 | - $formats_sortie = $image['format_source'] == 'jpg' ? ['jpg', 'png', 'gif'] : ['png', 'jpg', 'gif']; |
|
| 1721 | - // Choisir le format destination |
|
| 1722 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1723 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1724 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1725 | - # pas *ecrire* |
|
| 1726 | - $format_sortie = ''; |
|
| 1727 | - foreach ($formats_sortie as $fmt) { |
|
| 1728 | - if (in_array($fmt, $gd_formats) && in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1729 | - $format_sortie = $fmt; |
|
| 1730 | - break; |
|
| 1731 | - } |
|
| 1732 | - } |
|
| 1733 | - $image = false; |
|
| 1734 | - } |
|
| 1735 | - } |
|
| 1736 | - |
|
| 1737 | - if (!is_array($image)) { |
|
| 1738 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1739 | - } |
|
| 1740 | - |
|
| 1741 | - if (!is_array($image) || !$image['largeur'] || !$image['hauteur']) { |
|
| 1742 | - spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge"); |
|
| 1743 | - // on peut resizer en mode html si on dispose des elements |
|
| 1744 | - [$srcw, $srch] = taille_image($img); |
|
| 1745 | - if ($srcw && $srch) { |
|
| 1746 | - [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1747 | - |
|
| 1748 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1749 | - } |
|
| 1750 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1751 | - // sous la forme style='max-width: NNpx;' |
|
| 1752 | - return inserer_attribut( |
|
| 1753 | - $img, |
|
| 1754 | - 'style', |
|
| 1755 | - "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px" |
|
| 1756 | - ); |
|
| 1757 | - } |
|
| 1758 | - |
|
| 1759 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1760 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1761 | - if ($image['creer']) { |
|
| 1762 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1763 | - } |
|
| 1764 | - |
|
| 1765 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1766 | - } |
|
| 1767 | - |
|
| 1768 | - if ($image['creer'] == false && !$force) { |
|
| 1769 | - return _image_ecrire_tag( |
|
| 1770 | - $image, |
|
| 1771 | - ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1772 | - ); |
|
| 1773 | - } |
|
| 1774 | - |
|
| 1775 | - if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1776 | - $destWidth = $image['largeur_dest']; |
|
| 1777 | - $destHeight = $image['hauteur_dest']; |
|
| 1778 | - $logo = $image['fichier']; |
|
| 1779 | - $date = $image['date_src']; |
|
| 1780 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1781 | - |
|
| 1782 | - if ($preview && $preview['fichier']) { |
|
| 1783 | - $logo = $preview['fichier']; |
|
| 1784 | - $destWidth = $preview['width']; |
|
| 1785 | - $destHeight = $preview['height']; |
|
| 1786 | - $date = $preview['date']; |
|
| 1787 | - } |
|
| 1788 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1789 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1790 | - // quand on fait supprimer/reuploader un logo |
|
| 1791 | - // (pas de filemtime si SAFE MODE) |
|
| 1792 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1793 | - |
|
| 1794 | - return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1795 | - } |
|
| 1796 | - else { |
|
| 1797 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1798 | - return $img; |
|
| 1799 | - } |
|
| 1704 | + $image = false; |
|
| 1705 | + if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) { |
|
| 1706 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1707 | + } |
|
| 1708 | + # determiner le format de sortie |
|
| 1709 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1710 | + if ($process === 'netpbm') { |
|
| 1711 | + $format_sortie = 'jpg'; |
|
| 1712 | + } elseif ($process === 'gd2') { |
|
| 1713 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1714 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1715 | + $gd_formats = formats_image_acceptables(true); |
|
| 1716 | + if ( |
|
| 1717 | + is_array($image) |
|
| 1718 | + && (!in_array($image['format_dest'], $gd_formats) || !in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1719 | + ) { |
|
| 1720 | + $formats_sortie = $image['format_source'] == 'jpg' ? ['jpg', 'png', 'gif'] : ['png', 'jpg', 'gif']; |
|
| 1721 | + // Choisir le format destination |
|
| 1722 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1723 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1724 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1725 | + # pas *ecrire* |
|
| 1726 | + $format_sortie = ''; |
|
| 1727 | + foreach ($formats_sortie as $fmt) { |
|
| 1728 | + if (in_array($fmt, $gd_formats) && in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1729 | + $format_sortie = $fmt; |
|
| 1730 | + break; |
|
| 1731 | + } |
|
| 1732 | + } |
|
| 1733 | + $image = false; |
|
| 1734 | + } |
|
| 1735 | + } |
|
| 1736 | + |
|
| 1737 | + if (!is_array($image)) { |
|
| 1738 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1739 | + } |
|
| 1740 | + |
|
| 1741 | + if (!is_array($image) || !$image['largeur'] || !$image['hauteur']) { |
|
| 1742 | + spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge"); |
|
| 1743 | + // on peut resizer en mode html si on dispose des elements |
|
| 1744 | + [$srcw, $srch] = taille_image($img); |
|
| 1745 | + if ($srcw && $srch) { |
|
| 1746 | + [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1747 | + |
|
| 1748 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1749 | + } |
|
| 1750 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1751 | + // sous la forme style='max-width: NNpx;' |
|
| 1752 | + return inserer_attribut( |
|
| 1753 | + $img, |
|
| 1754 | + 'style', |
|
| 1755 | + "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px" |
|
| 1756 | + ); |
|
| 1757 | + } |
|
| 1758 | + |
|
| 1759 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1760 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1761 | + if ($image['creer']) { |
|
| 1762 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1766 | + } |
|
| 1767 | + |
|
| 1768 | + if ($image['creer'] == false && !$force) { |
|
| 1769 | + return _image_ecrire_tag( |
|
| 1770 | + $image, |
|
| 1771 | + ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1772 | + ); |
|
| 1773 | + } |
|
| 1774 | + |
|
| 1775 | + if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1776 | + $destWidth = $image['largeur_dest']; |
|
| 1777 | + $destHeight = $image['hauteur_dest']; |
|
| 1778 | + $logo = $image['fichier']; |
|
| 1779 | + $date = $image['date_src']; |
|
| 1780 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1781 | + |
|
| 1782 | + if ($preview && $preview['fichier']) { |
|
| 1783 | + $logo = $preview['fichier']; |
|
| 1784 | + $destWidth = $preview['width']; |
|
| 1785 | + $destHeight = $preview['height']; |
|
| 1786 | + $date = $preview['date']; |
|
| 1787 | + } |
|
| 1788 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1789 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1790 | + // quand on fait supprimer/reuploader un logo |
|
| 1791 | + // (pas de filemtime si SAFE MODE) |
|
| 1792 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1793 | + |
|
| 1794 | + return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1795 | + } |
|
| 1796 | + else { |
|
| 1797 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1798 | + return $img; |
|
| 1799 | + } |
|
| 1800 | 1800 | } |
| 1801 | 1801 | |
| 1802 | 1802 | /** |
@@ -1810,145 +1810,145 @@ discard block |
||
| 1810 | 1810 | * Class phpthumb_functions |
| 1811 | 1811 | */ |
| 1812 | 1812 | class phpthumb_functions { |
| 1813 | - /** |
|
| 1814 | - * Retourne la couleur d'un pixel dans une image |
|
| 1815 | - * |
|
| 1816 | - * @param GdImage $img |
|
| 1817 | - * @param int $x |
|
| 1818 | - * @param int $y |
|
| 1819 | - * @return array|bool |
|
| 1820 | - */ |
|
| 1821 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1822 | - if ($img instanceof \GdImage) { |
|
| 1823 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1824 | - } |
|
| 1825 | - return false; |
|
| 1826 | - } |
|
| 1827 | - |
|
| 1828 | - /** |
|
| 1829 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1830 | - * |
|
| 1831 | - * @param int $number |
|
| 1832 | - * @param int $minbytes |
|
| 1833 | - * @return string |
|
| 1834 | - */ |
|
| 1835 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1836 | - $intstring = ''; |
|
| 1837 | - while ($number > 0) { |
|
| 1838 | - $intstring .= chr($number & 255); |
|
| 1839 | - $number >>= 8; |
|
| 1840 | - } |
|
| 1841 | - |
|
| 1842 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1843 | - } |
|
| 1844 | - |
|
| 1845 | - /** |
|
| 1846 | - * Transforme une ressource GD en image au format ICO |
|
| 1847 | - * |
|
| 1848 | - * @param array $gd_image_array |
|
| 1849 | - * Tableau de ressources d'images GD |
|
| 1850 | - * @return string |
|
| 1851 | - * Image au format ICO |
|
| 1852 | - */ |
|
| 1853 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1854 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1855 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1856 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1857 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1858 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1859 | - |
|
| 1860 | - $icXOR[$key] = ''; |
|
| 1861 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1862 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1863 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1864 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1865 | - $r = $argb['red']; |
|
| 1866 | - $g = $argb['green']; |
|
| 1867 | - $b = $argb['blue']; |
|
| 1868 | - |
|
| 1869 | - if ($bpp[$key] == 32) { |
|
| 1870 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1871 | - } elseif ($bpp[$key] === 24) { |
|
| 1872 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1873 | - } |
|
| 1874 | - |
|
| 1875 | - if ($a < 128) { |
|
| 1876 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1877 | - } else { |
|
| 1878 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1879 | - } |
|
| 1880 | - } |
|
| 1881 | - // mask bits are 32-bit aligned per scanline |
|
| 1882 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1883 | - $icANDmask[$key][$y] .= '0'; |
|
| 1884 | - } |
|
| 1885 | - } |
|
| 1886 | - $icAND[$key] = ''; |
|
| 1887 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1888 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1889 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1890 | - } |
|
| 1891 | - } |
|
| 1892 | - } |
|
| 1893 | - |
|
| 1894 | - foreach (array_keys($gd_image_array) as $key) { |
|
| 1895 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1896 | - |
|
| 1897 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1898 | - $BitmapInfoHeader[$key] = ''; |
|
| 1899 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1900 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1901 | - // The biHeight member specifies the combined |
|
| 1902 | - // height of the XOR and AND masks. |
|
| 1903 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1904 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1905 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1906 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1907 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1908 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1909 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1910 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1911 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1912 | - } |
|
| 1913 | - |
|
| 1914 | - |
|
| 1915 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1916 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1917 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1918 | - |
|
| 1919 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1920 | - foreach (array_keys($gd_image_array) as $key) { |
|
| 1921 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1922 | - |
|
| 1923 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1924 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1925 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1926 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1927 | - |
|
| 1928 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1929 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1930 | - |
|
| 1931 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1932 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1933 | - $dwBytesInRes, |
|
| 1934 | - 4 |
|
| 1935 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1936 | - |
|
| 1937 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1938 | - $dwImageOffset, |
|
| 1939 | - 4 |
|
| 1940 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1941 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1942 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 1943 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 1944 | - } |
|
| 1945 | - |
|
| 1946 | - foreach (array_keys($gd_image_array) as $key) { |
|
| 1947 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 1948 | - $icondata .= $icXOR[$key]; |
|
| 1949 | - $icondata .= $icAND[$key]; |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - return $icondata; |
|
| 1953 | - } |
|
| 1813 | + /** |
|
| 1814 | + * Retourne la couleur d'un pixel dans une image |
|
| 1815 | + * |
|
| 1816 | + * @param GdImage $img |
|
| 1817 | + * @param int $x |
|
| 1818 | + * @param int $y |
|
| 1819 | + * @return array|bool |
|
| 1820 | + */ |
|
| 1821 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1822 | + if ($img instanceof \GdImage) { |
|
| 1823 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1824 | + } |
|
| 1825 | + return false; |
|
| 1826 | + } |
|
| 1827 | + |
|
| 1828 | + /** |
|
| 1829 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1830 | + * |
|
| 1831 | + * @param int $number |
|
| 1832 | + * @param int $minbytes |
|
| 1833 | + * @return string |
|
| 1834 | + */ |
|
| 1835 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1836 | + $intstring = ''; |
|
| 1837 | + while ($number > 0) { |
|
| 1838 | + $intstring .= chr($number & 255); |
|
| 1839 | + $number >>= 8; |
|
| 1840 | + } |
|
| 1841 | + |
|
| 1842 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1843 | + } |
|
| 1844 | + |
|
| 1845 | + /** |
|
| 1846 | + * Transforme une ressource GD en image au format ICO |
|
| 1847 | + * |
|
| 1848 | + * @param array $gd_image_array |
|
| 1849 | + * Tableau de ressources d'images GD |
|
| 1850 | + * @return string |
|
| 1851 | + * Image au format ICO |
|
| 1852 | + */ |
|
| 1853 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1854 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1855 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1856 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1857 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1858 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1859 | + |
|
| 1860 | + $icXOR[$key] = ''; |
|
| 1861 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1862 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1863 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1864 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1865 | + $r = $argb['red']; |
|
| 1866 | + $g = $argb['green']; |
|
| 1867 | + $b = $argb['blue']; |
|
| 1868 | + |
|
| 1869 | + if ($bpp[$key] == 32) { |
|
| 1870 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1871 | + } elseif ($bpp[$key] === 24) { |
|
| 1872 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1873 | + } |
|
| 1874 | + |
|
| 1875 | + if ($a < 128) { |
|
| 1876 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1877 | + } else { |
|
| 1878 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1879 | + } |
|
| 1880 | + } |
|
| 1881 | + // mask bits are 32-bit aligned per scanline |
|
| 1882 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1883 | + $icANDmask[$key][$y] .= '0'; |
|
| 1884 | + } |
|
| 1885 | + } |
|
| 1886 | + $icAND[$key] = ''; |
|
| 1887 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1888 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1889 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1890 | + } |
|
| 1891 | + } |
|
| 1892 | + } |
|
| 1893 | + |
|
| 1894 | + foreach (array_keys($gd_image_array) as $key) { |
|
| 1895 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1896 | + |
|
| 1897 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1898 | + $BitmapInfoHeader[$key] = ''; |
|
| 1899 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1900 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1901 | + // The biHeight member specifies the combined |
|
| 1902 | + // height of the XOR and AND masks. |
|
| 1903 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1904 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1905 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1906 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1907 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1908 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1909 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1910 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1911 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1912 | + } |
|
| 1913 | + |
|
| 1914 | + |
|
| 1915 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1916 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1917 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1918 | + |
|
| 1919 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1920 | + foreach (array_keys($gd_image_array) as $key) { |
|
| 1921 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1922 | + |
|
| 1923 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1924 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1925 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1926 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1927 | + |
|
| 1928 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1929 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1930 | + |
|
| 1931 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1932 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1933 | + $dwBytesInRes, |
|
| 1934 | + 4 |
|
| 1935 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1936 | + |
|
| 1937 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1938 | + $dwImageOffset, |
|
| 1939 | + 4 |
|
| 1940 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1941 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1942 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 1943 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 1944 | + } |
|
| 1945 | + |
|
| 1946 | + foreach (array_keys($gd_image_array) as $key) { |
|
| 1947 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 1948 | + $icondata .= $icXOR[$key]; |
|
| 1949 | + $icondata .= $icAND[$key]; |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + return $icondata; |
|
| 1953 | + } |
|
| 1954 | 1954 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | static $dirs = []; |
| 43 | 43 | $liste = []; |
| 44 | 44 | foreach (creer_chemin() as $dir) { |
| 45 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 45 | + if (!isset($dirs[$a = $dir.$dirname])) { |
|
| 46 | 46 | $dirs[$a] = (is_dir($a) || !$a); |
| 47 | 47 | } |
| 48 | 48 | if ($dirs[$a] && is_readable($a .= $file)) { |
@@ -66,21 +66,21 @@ discard block |
||
| 66 | 66 | **/ |
| 67 | 67 | function chercher_module_lang($module, $lang = '') { |
| 68 | 68 | if ($lang) { |
| 69 | - $lang = '_' . $lang; |
|
| 69 | + $lang = '_'.$lang; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
| 73 | 73 | if ( |
| 74 | 74 | $f = ($module == 'local' |
| 75 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 76 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 75 | + ? find_in_path($module.$lang.'.php', 'lang/') |
|
| 76 | + : find_langs_in_path($module.$lang.'.php', 'lang/')) |
|
| 77 | 77 | ) { |
| 78 | 78 | return is_array($f) ? $f : [$f]; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // 2) directement dans le chemin (old style, uniquement pour local) |
| 82 | 82 | return ($module == 'local' || strpos($module, '/')) |
| 83 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 83 | + ? (($f = find_in_path($module.$lang.'.php')) ? [$f] : false) |
|
| 84 | 84 | : false; |
| 85 | 85 | } |
| 86 | 86 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | **/ |
| 105 | 105 | function charger_langue($lang, $module = 'spip') { |
| 106 | 106 | static $langs = []; |
| 107 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 107 | + $var = 'i18n_'.$module.'_'.$lang; |
|
| 108 | 108 | if (!isset($langs[$lang])) { |
| 109 | 109 | $langs[$lang] = []; |
| 110 | 110 | if ($lang) { |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | foreach ($langs[$lang] as $l) { |
| 121 | 121 | if ($fichiers_lang = chercher_module_lang($module, $l)) { |
| 122 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 122 | + $GLOBALS['idx_lang'] = 'i18n_'.$module.'_'.$l; |
|
| 123 | 123 | $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
| 124 | 124 | surcharger_langue($fichiers_lang); |
| 125 | 125 | if ($l !== $lang) { |
| 126 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 126 | + $GLOBALS[$var] = &$GLOBALS['i18n_'.$module.'_'.$l]; |
|
| 127 | 127 | } |
| 128 | - $GLOBALS['lang_' . $var] = $l; |
|
| 128 | + $GLOBALS['lang_'.$var] = $l; |
|
| 129 | 129 | #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
| 130 | 130 | break; |
| 131 | 131 | } |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | function lire_fichier_langue(string $fichier): array { |
| 145 | 145 | $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
| 146 | - $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 146 | + $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang').'@temporaire'; |
|
| 147 | 147 | $GLOBALS['idx_lang'] = $idx_lang_tmp; |
| 148 | 148 | $idx_lang = include $fichier; |
| 149 | 149 | $GLOBALS['idx_lang'] = $idx_lang_before; |
@@ -254,27 +254,27 @@ discard block |
||
| 254 | 254 | } else { |
| 255 | 255 | $modules = ['spip', 'ecrire']; |
| 256 | 256 | $code = $ori; |
| 257 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 257 | + $ori_complet = implode('|', $modules).':'.$ori; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | $desc = new Description(); |
| 261 | 261 | |
| 262 | 262 | // parcourir tous les modules jusqu'a ce qu'on trouve |
| 263 | 263 | foreach ($modules as $module) { |
| 264 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 264 | + $var = 'i18n_'.$module.'_'.$lang; |
|
| 265 | 265 | |
| 266 | 266 | if (empty($GLOBALS[$var])) { |
| 267 | 267 | charger_langue($lang, $module); |
| 268 | 268 | // surcharges persos -- on cherche |
| 269 | 269 | // (lang/)local_xx.php et/ou (lang/)local.php ... |
| 270 | - if (!isset($local['local_' . $lang])) { |
|
| 270 | + if (!isset($local['local_'.$lang])) { |
|
| 271 | 271 | // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
| 272 | 272 | $GLOBALS['idx_lang'] = $var; |
| 273 | 273 | // ... (lang/)local_xx.php |
| 274 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 274 | + $local['local_'.$lang] = chercher_module_lang('local', $lang); |
|
| 275 | 275 | } |
| 276 | - if ($local['local_' . $lang]) { |
|
| 277 | - surcharger_langue($local['local_' . $lang]); |
|
| 276 | + if ($local['local_'.$lang]) { |
|
| 277 | + surcharger_langue($local['local_'.$lang]); |
|
| 278 | 278 | } |
| 279 | 279 | // ... puis (lang/)local.php |
| 280 | 280 | if (!isset($local['local'])) { |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | if (isset($GLOBALS[$var][$code])) { |
| 289 | 289 | $desc->code = $code; |
| 290 | 290 | $desc->module = $module; |
| 291 | - $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 291 | + $desc->langue = $GLOBALS['lang_'.$var] ?? $lang; |
|
| 292 | 292 | $desc->texte = $GLOBALS[$var][$code]; |
| 293 | 293 | break; |
| 294 | 294 | } |
@@ -346,13 +346,13 @@ discard block |
||
| 346 | 346 | if (!$desc->mode && $desc->texte) { |
| 347 | 347 | // ne pas modifier 2 fois l'affichage |
| 348 | 348 | $desc->mode = 'traduction'; |
| 349 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 349 | + $classe = 'debug-traduction'.($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 350 | 350 | $desc->texte = '<span ' |
| 351 | - . 'lang=' . $desc->langue |
|
| 352 | - . ' class=' . $classe |
|
| 353 | - . ' data-module=' . $desc->module |
|
| 354 | - . ' data-code=' . $desc->code |
|
| 355 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 351 | + . 'lang='.$desc->langue |
|
| 352 | + . ' class='.$classe |
|
| 353 | + . ' data-module='.$desc->module |
|
| 354 | + . ' data-code='.$desc->code |
|
| 355 | + . ' title='.$modules.'('.$desc->langue.')>' |
|
| 356 | 356 | . $desc->texte |
| 357 | 357 | . '</span>'; |
| 358 | 358 | $desc->texte = str_replace( |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -39,18 +39,18 @@ discard block |
||
| 39 | 39 | * Liste des fichiers de langue trouvés, dans l'ordre des chemins |
| 40 | 40 | */ |
| 41 | 41 | function find_langs_in_path($file, $dirname = 'lang') { |
| 42 | - static $dirs = []; |
|
| 43 | - $liste = []; |
|
| 44 | - foreach (creer_chemin() as $dir) { |
|
| 45 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 46 | - $dirs[$a] = (is_dir($a) || !$a); |
|
| 47 | - } |
|
| 48 | - if ($dirs[$a] && is_readable($a .= $file)) { |
|
| 49 | - $liste[] = $a; |
|
| 50 | - } |
|
| 51 | - } |
|
| 42 | + static $dirs = []; |
|
| 43 | + $liste = []; |
|
| 44 | + foreach (creer_chemin() as $dir) { |
|
| 45 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 46 | + $dirs[$a] = (is_dir($a) || !$a); |
|
| 47 | + } |
|
| 48 | + if ($dirs[$a] && is_readable($a .= $file)) { |
|
| 49 | + $liste[] = $a; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - return array_reverse($liste); |
|
| 53 | + return array_reverse($liste); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -65,23 +65,23 @@ discard block |
||
| 65 | 65 | * Liste des fichiers touvés pour ce module et cette langue. |
| 66 | 66 | **/ |
| 67 | 67 | function chercher_module_lang($module, $lang = '') { |
| 68 | - if ($lang) { |
|
| 69 | - $lang = '_' . $lang; |
|
| 70 | - } |
|
| 68 | + if ($lang) { |
|
| 69 | + $lang = '_' . $lang; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 73 | - if ( |
|
| 74 | - $f = ($module == 'local' |
|
| 75 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 76 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 77 | - ) { |
|
| 78 | - return is_array($f) ? $f : [$f]; |
|
| 79 | - } |
|
| 72 | + // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 73 | + if ( |
|
| 74 | + $f = ($module == 'local' |
|
| 75 | + ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 76 | + : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 77 | + ) { |
|
| 78 | + return is_array($f) ? $f : [$f]; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 82 | - return ($module == 'local' || strpos($module, '/')) |
|
| 83 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 84 | - : false; |
|
| 81 | + // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 82 | + return ($module == 'local' || strpos($module, '/')) |
|
| 83 | + ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 84 | + : false; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -103,33 +103,33 @@ discard block |
||
| 103 | 103 | * @return void |
| 104 | 104 | **/ |
| 105 | 105 | function charger_langue($lang, $module = 'spip') { |
| 106 | - static $langs = []; |
|
| 107 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 108 | - if (!isset($langs[$lang])) { |
|
| 109 | - $langs[$lang] = []; |
|
| 110 | - if ($lang) { |
|
| 111 | - $langs[$lang][] = $lang; |
|
| 112 | - if (str_contains($lang, '_')) { |
|
| 113 | - $l = explode('_', $lang); |
|
| 114 | - $langs[$lang][] = reset($l); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 118 | - $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 119 | - } |
|
| 120 | - foreach ($langs[$lang] as $l) { |
|
| 121 | - if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 122 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 123 | - $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 124 | - surcharger_langue($fichiers_lang); |
|
| 125 | - if ($l !== $lang) { |
|
| 126 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 127 | - } |
|
| 128 | - $GLOBALS['lang_' . $var] = $l; |
|
| 129 | - #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 130 | - break; |
|
| 131 | - } |
|
| 132 | - } |
|
| 106 | + static $langs = []; |
|
| 107 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 108 | + if (!isset($langs[$lang])) { |
|
| 109 | + $langs[$lang] = []; |
|
| 110 | + if ($lang) { |
|
| 111 | + $langs[$lang][] = $lang; |
|
| 112 | + if (str_contains($lang, '_')) { |
|
| 113 | + $l = explode('_', $lang); |
|
| 114 | + $langs[$lang][] = reset($l); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 118 | + $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 119 | + } |
|
| 120 | + foreach ($langs[$lang] as $l) { |
|
| 121 | + if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 122 | + $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 123 | + $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 124 | + surcharger_langue($fichiers_lang); |
|
| 125 | + if ($l !== $lang) { |
|
| 126 | + $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 127 | + } |
|
| 128 | + $GLOBALS['lang_' . $var] = $l; |
|
| 129 | + #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 130 | + break; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -142,22 +142,22 @@ discard block |
||
| 142 | 142 | * @return array<string, string> |
| 143 | 143 | */ |
| 144 | 144 | function lire_fichier_langue(string $fichier): array { |
| 145 | - $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 146 | - $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 147 | - $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 148 | - $idx_lang = include $fichier; |
|
| 149 | - $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 150 | - if (!is_array($idx_lang)) { |
|
| 151 | - if (isset($GLOBALS[$idx_lang_tmp]) && is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 152 | - trigger_deprecation('spip', '5.0', sprintf('Lang file "%s" populating a GLOBALS is deprecated. Return an array instead.', $fichier)); |
|
| 153 | - $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 154 | - } else { |
|
| 155 | - $idx_lang = []; |
|
| 156 | - spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 157 | - } |
|
| 158 | - unset($GLOBALS[$idx_lang_tmp]); |
|
| 159 | - } |
|
| 160 | - return $idx_lang; |
|
| 145 | + $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 146 | + $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 147 | + $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 148 | + $idx_lang = include $fichier; |
|
| 149 | + $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 150 | + if (!is_array($idx_lang)) { |
|
| 151 | + if (isset($GLOBALS[$idx_lang_tmp]) && is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 152 | + trigger_deprecation('spip', '5.0', sprintf('Lang file "%s" populating a GLOBALS is deprecated. Return an array instead.', $fichier)); |
|
| 153 | + $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 154 | + } else { |
|
| 155 | + $idx_lang = []; |
|
| 156 | + spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 157 | + } |
|
| 158 | + unset($GLOBALS[$idx_lang_tmp]); |
|
| 159 | + } |
|
| 160 | + return $idx_lang; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -177,29 +177,29 @@ discard block |
||
| 177 | 177 | * Liste des chemins de fichiers de langue à surcharger. |
| 178 | 178 | **/ |
| 179 | 179 | function surcharger_langue($fichiers) { |
| 180 | - static $surcharges = []; |
|
| 181 | - if (!isset($GLOBALS['idx_lang'])) { |
|
| 182 | - return; |
|
| 183 | - } |
|
| 180 | + static $surcharges = []; |
|
| 181 | + if (!isset($GLOBALS['idx_lang'])) { |
|
| 182 | + return; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - if (!is_array($fichiers)) { |
|
| 186 | - $fichiers = [$fichiers]; |
|
| 187 | - } |
|
| 188 | - if ($fichiers === []) { |
|
| 189 | - return; |
|
| 190 | - } |
|
| 191 | - foreach ($fichiers as $fichier) { |
|
| 192 | - if (!isset($surcharges[$fichier])) { |
|
| 193 | - $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 194 | - } |
|
| 195 | - if (is_array($surcharges[$fichier])) { |
|
| 196 | - $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 197 | - $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 198 | - $GLOBALS[$GLOBALS['idx_lang']], |
|
| 199 | - $surcharges[$fichier] |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - } |
|
| 185 | + if (!is_array($fichiers)) { |
|
| 186 | + $fichiers = [$fichiers]; |
|
| 187 | + } |
|
| 188 | + if ($fichiers === []) { |
|
| 189 | + return; |
|
| 190 | + } |
|
| 191 | + foreach ($fichiers as $fichier) { |
|
| 192 | + if (!isset($surcharges[$fichier])) { |
|
| 193 | + $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 194 | + } |
|
| 195 | + if (is_array($surcharges[$fichier])) { |
|
| 196 | + $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 197 | + $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 198 | + $GLOBALS[$GLOBALS['idx_lang']], |
|
| 199 | + $surcharges[$fichier] |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -240,99 +240,99 @@ discard block |
||
| 240 | 240 | * - Description : traduction et description (texte, module, langue) |
| 241 | 241 | **/ |
| 242 | 242 | function inc_traduire_dist($ori, $lang, $raw = false) { |
| 243 | - static $deja_vu = []; |
|
| 244 | - static $local = []; |
|
| 243 | + static $deja_vu = []; |
|
| 244 | + static $local = []; |
|
| 245 | 245 | |
| 246 | - if (isset($deja_vu[$lang][$ori]) && _request('var_mode') != 'traduction') { |
|
| 247 | - return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 248 | - } |
|
| 246 | + if (isset($deja_vu[$lang][$ori]) && _request('var_mode') != 'traduction') { |
|
| 247 | + return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 251 | - if (strpos($ori, ':')) { |
|
| 252 | - [$modules, $code] = explode(':', $ori, 2); |
|
| 253 | - $modules = explode('|', $modules); |
|
| 254 | - $ori_complet = $ori; |
|
| 255 | - } else { |
|
| 256 | - $modules = ['spip', 'ecrire']; |
|
| 257 | - $code = $ori; |
|
| 258 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 259 | - } |
|
| 250 | + // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 251 | + if (strpos($ori, ':')) { |
|
| 252 | + [$modules, $code] = explode(':', $ori, 2); |
|
| 253 | + $modules = explode('|', $modules); |
|
| 254 | + $ori_complet = $ori; |
|
| 255 | + } else { |
|
| 256 | + $modules = ['spip', 'ecrire']; |
|
| 257 | + $code = $ori; |
|
| 258 | + $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - $desc = new Description(); |
|
| 261 | + $desc = new Description(); |
|
| 262 | 262 | |
| 263 | - // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 264 | - foreach ($modules as $module) { |
|
| 265 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 263 | + // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 264 | + foreach ($modules as $module) { |
|
| 265 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 266 | 266 | |
| 267 | - if (empty($GLOBALS[$var])) { |
|
| 268 | - charger_langue($lang, $module); |
|
| 269 | - // surcharges persos -- on cherche |
|
| 270 | - // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 271 | - if (!isset($local['local_' . $lang])) { |
|
| 272 | - // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 273 | - $GLOBALS['idx_lang'] = $var; |
|
| 274 | - // ... (lang/)local_xx.php |
|
| 275 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 276 | - } |
|
| 277 | - if ($local['local_' . $lang]) { |
|
| 278 | - surcharger_langue($local['local_' . $lang]); |
|
| 279 | - } |
|
| 280 | - // ... puis (lang/)local.php |
|
| 281 | - if (!isset($local['local'])) { |
|
| 282 | - $local['local'] = chercher_module_lang('local'); |
|
| 283 | - } |
|
| 284 | - if ($local['local']) { |
|
| 285 | - surcharger_langue($local['local']); |
|
| 286 | - } |
|
| 287 | - } |
|
| 267 | + if (empty($GLOBALS[$var])) { |
|
| 268 | + charger_langue($lang, $module); |
|
| 269 | + // surcharges persos -- on cherche |
|
| 270 | + // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 271 | + if (!isset($local['local_' . $lang])) { |
|
| 272 | + // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 273 | + $GLOBALS['idx_lang'] = $var; |
|
| 274 | + // ... (lang/)local_xx.php |
|
| 275 | + $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 276 | + } |
|
| 277 | + if ($local['local_' . $lang]) { |
|
| 278 | + surcharger_langue($local['local_' . $lang]); |
|
| 279 | + } |
|
| 280 | + // ... puis (lang/)local.php |
|
| 281 | + if (!isset($local['local'])) { |
|
| 282 | + $local['local'] = chercher_module_lang('local'); |
|
| 283 | + } |
|
| 284 | + if ($local['local']) { |
|
| 285 | + surcharger_langue($local['local']); |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - if (isset($GLOBALS[$var][$code])) { |
|
| 290 | - $desc->code = $code; |
|
| 291 | - $desc->module = $module; |
|
| 292 | - $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 293 | - $desc->texte = $GLOBALS[$var][$code]; |
|
| 294 | - break; |
|
| 295 | - } |
|
| 296 | - } |
|
| 289 | + if (isset($GLOBALS[$var][$code])) { |
|
| 290 | + $desc->code = $code; |
|
| 291 | + $desc->module = $module; |
|
| 292 | + $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 293 | + $desc->texte = $GLOBALS[$var][$code]; |
|
| 294 | + break; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - if (!$desc->corrections) { |
|
| 299 | - $desc->corrections = true; |
|
| 300 | - // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 301 | - // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 302 | - if ( |
|
| 303 | - ($desc->texte === null || !strlen($desc->texte)) |
|
| 304 | - && $lang !== _LANGUE_PAR_DEFAUT |
|
| 305 | - ) { |
|
| 306 | - if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 307 | - $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 308 | - } else { |
|
| 309 | - $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 310 | - } |
|
| 311 | - } |
|
| 298 | + if (!$desc->corrections) { |
|
| 299 | + $desc->corrections = true; |
|
| 300 | + // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 301 | + // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 302 | + if ( |
|
| 303 | + ($desc->texte === null || !strlen($desc->texte)) |
|
| 304 | + && $lang !== _LANGUE_PAR_DEFAUT |
|
| 305 | + ) { |
|
| 306 | + if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 307 | + $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 308 | + } else { |
|
| 309 | + $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - // Supprimer la mention <NEW> ou <MODIF> |
|
| 314 | - if ($desc->texte && str_starts_with($desc->texte, '<')) { |
|
| 315 | - $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 316 | - } |
|
| 313 | + // Supprimer la mention <NEW> ou <MODIF> |
|
| 314 | + if ($desc->texte && str_starts_with($desc->texte, '<')) { |
|
| 315 | + $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 319 | - // le cas echeant on la convertit en entites html &#xxx; |
|
| 320 | - if ( |
|
| 321 | - (!isset($GLOBALS['meta']['charset']) || $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 322 | - && preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 323 | - ) { |
|
| 324 | - include_spip('inc/charsets'); |
|
| 325 | - $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 326 | - } |
|
| 327 | - } |
|
| 318 | + // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 319 | + // le cas echeant on la convertit en entites html &#xxx; |
|
| 320 | + if ( |
|
| 321 | + (!isset($GLOBALS['meta']['charset']) || $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 322 | + && preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 323 | + ) { |
|
| 324 | + include_spip('inc/charsets'); |
|
| 325 | + $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - if (_request('var_mode') == 'traduction') { |
|
| 330 | - $desc = definir_details_traduction($desc, $ori_complet); |
|
| 331 | - } else { |
|
| 332 | - $deja_vu[$lang][$ori] = $desc; |
|
| 333 | - } |
|
| 329 | + if (_request('var_mode') == 'traduction') { |
|
| 330 | + $desc = definir_details_traduction($desc, $ori_complet); |
|
| 331 | + } else { |
|
| 332 | + $deja_vu[$lang][$ori] = $desc; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - return $raw ? $desc : $desc->texte; |
|
| 335 | + return $raw ? $desc : $desc->texte; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /** |
@@ -344,23 +344,23 @@ discard block |
||
| 344 | 344 | * @return Description |
| 345 | 345 | */ |
| 346 | 346 | function definir_details_traduction($desc, $modules) { |
| 347 | - if (!$desc->mode && $desc->texte) { |
|
| 348 | - // ne pas modifier 2 fois l'affichage |
|
| 349 | - $desc->mode = 'traduction'; |
|
| 350 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 351 | - $desc->texte = '<span ' |
|
| 352 | - . 'lang=' . $desc->langue |
|
| 353 | - . ' class=' . $classe |
|
| 354 | - . ' data-module=' . $desc->module |
|
| 355 | - . ' data-code=' . $desc->code |
|
| 356 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 357 | - . $desc->texte |
|
| 358 | - . '</span>'; |
|
| 359 | - $desc->texte = str_replace( |
|
| 360 | - ["$desc->module:", "$desc->module|"], |
|
| 361 | - ["*$desc->module*:", "*$desc->module*|"], |
|
| 362 | - $desc->texte |
|
| 363 | - ); |
|
| 364 | - } |
|
| 365 | - return $desc; |
|
| 347 | + if (!$desc->mode && $desc->texte) { |
|
| 348 | + // ne pas modifier 2 fois l'affichage |
|
| 349 | + $desc->mode = 'traduction'; |
|
| 350 | + $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 351 | + $desc->texte = '<span ' |
|
| 352 | + . 'lang=' . $desc->langue |
|
| 353 | + . ' class=' . $classe |
|
| 354 | + . ' data-module=' . $desc->module |
|
| 355 | + . ' data-code=' . $desc->code |
|
| 356 | + . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 357 | + . $desc->texte |
|
| 358 | + . '</span>'; |
|
| 359 | + $desc->texte = str_replace( |
|
| 360 | + ["$desc->module:", "$desc->module|"], |
|
| 361 | + ["*$desc->module*:", "*$desc->module*|"], |
|
| 362 | + $desc->texte |
|
| 363 | + ); |
|
| 364 | + } |
|
| 365 | + return $desc; |
|
| 366 | 366 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $_id = $e['id_table_objet']; |
| 52 | 52 | if (isset($contexte[$_id]) && ($id = (int) $contexte[$_id])) { |
| 53 | 53 | $table = $e['table_objet_sql']; |
| 54 | - $row = sql_fetsel('*', $table, "$_id=" . (int) $id); |
|
| 54 | + $row = sql_fetsel('*', $table, "$_id=".(int) $id); |
|
| 55 | 55 | if (isset($row['id_rubrique'])) { |
| 56 | 56 | $contexte['id_rubrique'] = $row['id_rubrique']; |
| 57 | 57 | if (isset($row['id_secteur'])) { |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
| 116 | 116 | + [ |
| 117 | 117 | $id => new Bouton( |
| 118 | - ($icones && !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 119 | - $infos['titre'], // titre |
|
| 118 | + ($icones && !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 119 | + $infos['titre'], // titre |
|
| 120 | 120 | (isset($infos['action']) && $infos['action']) ? $infos['action'] : null, |
| 121 | 121 | (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null |
| 122 | 122 | ) |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | $boutons_admin = array_slice($boutons_admin, 0, $position) |
| 134 | 134 | + [ |
| 135 | 135 | $id => new Bouton( |
| 136 | - ($icones && isset($infos['icone']) && $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 137 | - $infos['titre'], // titre |
|
| 136 | + ($icones && isset($infos['icone']) && $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 137 | + $infos['titre'], // titre |
|
| 138 | 138 | (isset($infos['action']) && $infos['action']) ? $infos['action'] : null, |
| 139 | 139 | (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null |
| 140 | 140 | ) |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $url = str_replace('&', '&', $url); |
| 222 | 222 | while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
| 223 | 223 | if ($matches[2] == 'id_secteur' && !isset($contexte['id_secteur']) && isset($contexte['id_rubrique'])) { |
| 224 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $contexte['id_rubrique']); |
|
| 224 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.(int) $contexte['id_rubrique']); |
|
| 225 | 225 | } |
| 226 | 226 | $val = _request($matches[2], $contexte); |
| 227 | 227 | $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/boutons'); |
@@ -38,33 +38,33 @@ discard block |
||
| 38 | 38 | * contexte |
| 39 | 39 | **/ |
| 40 | 40 | function definir_barre_contexte($contexte = null) { |
| 41 | - if (is_null($contexte)) { |
|
| 42 | - $contexte = $_GET; |
|
| 43 | - } elseif (is_string($contexte)) { |
|
| 44 | - $contexte = unserialize($contexte); |
|
| 45 | - } |
|
| 46 | - if (!isset($contexte['id_rubrique']) && isset($contexte['exec'])) { |
|
| 47 | - if (!function_exists('trouver_objet_exec')) { |
|
| 48 | - include_spip('inc/pipelines_ecrire'); |
|
| 49 | - } |
|
| 50 | - if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 51 | - $_id = $e['id_table_objet']; |
|
| 52 | - if (isset($contexte[$_id]) && ($id = (int) $contexte[$_id])) { |
|
| 53 | - $table = $e['table_objet_sql']; |
|
| 54 | - $row = sql_fetsel('*', $table, "$_id=" . (int) $id); |
|
| 55 | - if (isset($row['id_rubrique'])) { |
|
| 56 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 57 | - if (isset($row['id_secteur'])) { |
|
| 58 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 59 | - } |
|
| 60 | - } elseif (isset($row['id_groupe'])) { |
|
| 61 | - // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 62 | - $contexte['id_groupe'] = $row['id_groupe']; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - return $contexte; |
|
| 41 | + if (is_null($contexte)) { |
|
| 42 | + $contexte = $_GET; |
|
| 43 | + } elseif (is_string($contexte)) { |
|
| 44 | + $contexte = unserialize($contexte); |
|
| 45 | + } |
|
| 46 | + if (!isset($contexte['id_rubrique']) && isset($contexte['exec'])) { |
|
| 47 | + if (!function_exists('trouver_objet_exec')) { |
|
| 48 | + include_spip('inc/pipelines_ecrire'); |
|
| 49 | + } |
|
| 50 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 51 | + $_id = $e['id_table_objet']; |
|
| 52 | + if (isset($contexte[$_id]) && ($id = (int) $contexte[$_id])) { |
|
| 53 | + $table = $e['table_objet_sql']; |
|
| 54 | + $row = sql_fetsel('*', $table, "$_id=" . (int) $id); |
|
| 55 | + if (isset($row['id_rubrique'])) { |
|
| 56 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 57 | + if (isset($row['id_secteur'])) { |
|
| 58 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 59 | + } |
|
| 60 | + } elseif (isset($row['id_groupe'])) { |
|
| 61 | + // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 62 | + $contexte['id_groupe'] = $row['id_groupe']; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + return $contexte; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -80,89 +80,89 @@ discard block |
||
| 80 | 80 | * @return array |
| 81 | 81 | */ |
| 82 | 82 | function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) { |
| 83 | - include_spip('inc/autoriser'); |
|
| 84 | - $boutons_admin = []; |
|
| 83 | + include_spip('inc/autoriser'); |
|
| 84 | + $boutons_admin = []; |
|
| 85 | 85 | |
| 86 | - // les boutons du core, issus de ecrire/paquet.xml |
|
| 87 | - $liste_boutons = []; |
|
| 86 | + // les boutons du core, issus de ecrire/paquet.xml |
|
| 87 | + $liste_boutons = []; |
|
| 88 | 88 | |
| 89 | - // ajouter les boutons issus des plugin via paquet.xml |
|
| 90 | - if ( |
|
| 91 | - function_exists('boutons_plugins') |
|
| 92 | - && is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 93 | - ) { |
|
| 94 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 95 | - } |
|
| 89 | + // ajouter les boutons issus des plugin via paquet.xml |
|
| 90 | + if ( |
|
| 91 | + function_exists('boutons_plugins') |
|
| 92 | + && is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 93 | + ) { |
|
| 94 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - foreach ($liste_boutons as $id => $infos) { |
|
| 98 | - $parent = ''; |
|
| 99 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 100 | - if ( |
|
| 101 | - !isset($infos['parent']) |
|
| 102 | - || !($parent = $infos['parent']) |
|
| 103 | - || !$autorise |
|
| 104 | - || autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 105 | - ) { |
|
| 106 | - if ( |
|
| 107 | - $parent |
|
| 108 | - && ($parent = preg_replace(',^bando_,', 'menu_', (string) $parent)) |
|
| 109 | - && isset($boutons_admin[$parent]) |
|
| 110 | - ) { |
|
| 111 | - $position = (isset($infos['position']) && strlen((string) $infos['position'])) ? (int) $infos['position'] : count($boutons_admin[$parent]->sousmenu); |
|
| 112 | - if ($position < 0) { |
|
| 113 | - $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 114 | - } |
|
| 115 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 116 | - + [ |
|
| 117 | - $id => new Bouton( |
|
| 118 | - ($icones && !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 119 | - $infos['titre'], // titre |
|
| 120 | - (isset($infos['action']) && $infos['action']) ? $infos['action'] : null, |
|
| 121 | - (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null |
|
| 122 | - ) |
|
| 123 | - ] |
|
| 124 | - + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 125 | - } |
|
| 126 | - if ( |
|
| 127 | - !$parent |
|
| 128 | - // provisoire, eviter les vieux boutons |
|
| 129 | - && !in_array($id, ['forum', 'statistiques_visites']) |
|
| 130 | - && (!$autorise || autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 131 | - ) { |
|
| 132 | - $position = (isset($infos['position']) && $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 133 | - $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 134 | - + [ |
|
| 135 | - $id => new Bouton( |
|
| 136 | - ($icones && isset($infos['icone']) && $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 137 | - $infos['titre'], // titre |
|
| 138 | - (isset($infos['action']) && $infos['action']) ? $infos['action'] : null, |
|
| 139 | - (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null |
|
| 140 | - ) |
|
| 141 | - ] |
|
| 142 | - + array_slice($boutons_admin, $position, 100); |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 97 | + foreach ($liste_boutons as $id => $infos) { |
|
| 98 | + $parent = ''; |
|
| 99 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 100 | + if ( |
|
| 101 | + !isset($infos['parent']) |
|
| 102 | + || !($parent = $infos['parent']) |
|
| 103 | + || !$autorise |
|
| 104 | + || autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 105 | + ) { |
|
| 106 | + if ( |
|
| 107 | + $parent |
|
| 108 | + && ($parent = preg_replace(',^bando_,', 'menu_', (string) $parent)) |
|
| 109 | + && isset($boutons_admin[$parent]) |
|
| 110 | + ) { |
|
| 111 | + $position = (isset($infos['position']) && strlen((string) $infos['position'])) ? (int) $infos['position'] : count($boutons_admin[$parent]->sousmenu); |
|
| 112 | + if ($position < 0) { |
|
| 113 | + $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 114 | + } |
|
| 115 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 116 | + + [ |
|
| 117 | + $id => new Bouton( |
|
| 118 | + ($icones && !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 119 | + $infos['titre'], // titre |
|
| 120 | + (isset($infos['action']) && $infos['action']) ? $infos['action'] : null, |
|
| 121 | + (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null |
|
| 122 | + ) |
|
| 123 | + ] |
|
| 124 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 125 | + } |
|
| 126 | + if ( |
|
| 127 | + !$parent |
|
| 128 | + // provisoire, eviter les vieux boutons |
|
| 129 | + && !in_array($id, ['forum', 'statistiques_visites']) |
|
| 130 | + && (!$autorise || autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 131 | + ) { |
|
| 132 | + $position = (isset($infos['position']) && $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 133 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 134 | + + [ |
|
| 135 | + $id => new Bouton( |
|
| 136 | + ($icones && isset($infos['icone']) && $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 137 | + $infos['titre'], // titre |
|
| 138 | + (isset($infos['action']) && $infos['action']) ? $infos['action'] : null, |
|
| 139 | + (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null |
|
| 140 | + ) |
|
| 141 | + ] |
|
| 142 | + + array_slice($boutons_admin, $position, 100); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 147 | 147 | |
| 148 | - // définir les favoris et positions d’origine |
|
| 149 | - if ($boutons_admin) { |
|
| 150 | - $menus_favoris = obtenir_menus_favoris(); |
|
| 151 | - $i = 1; |
|
| 152 | - foreach ($boutons_admin as $key => $menu) { |
|
| 153 | - $menu->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 154 | - $menu->position = $i++; |
|
| 155 | - if ($menu->sousmenu) { |
|
| 156 | - $j = 1; |
|
| 157 | - foreach ($menu->sousmenu as $key => $bouton) { |
|
| 158 | - $bouton->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 159 | - $bouton->position = $j++; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 148 | + // définir les favoris et positions d’origine |
|
| 149 | + if ($boutons_admin) { |
|
| 150 | + $menus_favoris = obtenir_menus_favoris(); |
|
| 151 | + $i = 1; |
|
| 152 | + foreach ($boutons_admin as $key => $menu) { |
|
| 153 | + $menu->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 154 | + $menu->position = $i++; |
|
| 155 | + if ($menu->sousmenu) { |
|
| 156 | + $j = 1; |
|
| 157 | + foreach ($menu->sousmenu as $key => $bouton) { |
|
| 158 | + $bouton->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 159 | + $bouton->position = $j++; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - return $boutons_admin; |
|
| 165 | + return $boutons_admin; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -174,22 +174,22 @@ discard block |
||
| 174 | 174 | * @return Bouton[] |
| 175 | 175 | */ |
| 176 | 176 | function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) { |
| 177 | - foreach ($menus as $menu) { |
|
| 178 | - if ($menu->sousmenu) { |
|
| 179 | - $libelles = $isfavoris = $favoris = []; |
|
| 180 | - foreach ($menu->sousmenu as $key => $item) { |
|
| 181 | - $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 182 | - $isfavoris[$key] = (bool) $item->favori; |
|
| 183 | - $favoris[$key] = $item->favori; |
|
| 184 | - } |
|
| 185 | - if ($avec_favoris) { |
|
| 186 | - array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 187 | - } else { |
|
| 188 | - array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - return $menus; |
|
| 177 | + foreach ($menus as $menu) { |
|
| 178 | + if ($menu->sousmenu) { |
|
| 179 | + $libelles = $isfavoris = $favoris = []; |
|
| 180 | + foreach ($menu->sousmenu as $key => $item) { |
|
| 181 | + $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 182 | + $isfavoris[$key] = (bool) $item->favori; |
|
| 183 | + $favoris[$key] = $item->favori; |
|
| 184 | + } |
|
| 185 | + if ($avec_favoris) { |
|
| 186 | + array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 187 | + } else { |
|
| 188 | + array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + return $menus; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * @return Bouton[] |
| 201 | 201 | */ |
| 202 | 202 | function trier_boutons_enfants_par_favoris_alpha($menus) { |
| 203 | - return trier_boutons_enfants_par_alpha($menus, true); |
|
| 203 | + return trier_boutons_enfants_par_alpha($menus, true); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | |
@@ -213,23 +213,23 @@ discard block |
||
| 213 | 213 | * @return string |
| 214 | 214 | */ |
| 215 | 215 | function bandeau_creer_url($url, $args = '', $contexte = null) { |
| 216 | - if (!preg_match(',[\/\?],', $url)) { |
|
| 217 | - $url = generer_url_ecrire($url, $args, true); |
|
| 218 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 219 | - // &truc=@machin@ |
|
| 220 | - // @machin@ etant remplace par _request('machin') |
|
| 221 | - $url = str_replace('&', '&', $url); |
|
| 222 | - while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 223 | - if ($matches[2] == 'id_secteur' && !isset($contexte['id_secteur']) && isset($contexte['id_rubrique'])) { |
|
| 224 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $contexte['id_rubrique']); |
|
| 225 | - } |
|
| 226 | - $val = _request($matches[2], $contexte); |
|
| 227 | - $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 228 | - } |
|
| 229 | - $url = str_replace('&', '&', $url); |
|
| 230 | - } |
|
| 216 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 217 | + $url = generer_url_ecrire($url, $args, true); |
|
| 218 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 219 | + // &truc=@machin@ |
|
| 220 | + // @machin@ etant remplace par _request('machin') |
|
| 221 | + $url = str_replace('&', '&', $url); |
|
| 222 | + while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 223 | + if ($matches[2] == 'id_secteur' && !isset($contexte['id_secteur']) && isset($contexte['id_rubrique'])) { |
|
| 224 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $contexte['id_rubrique']); |
|
| 225 | + } |
|
| 226 | + $val = _request($matches[2], $contexte); |
|
| 227 | + $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 228 | + } |
|
| 229 | + $url = str_replace('&', '&', $url); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - return $url; |
|
| 232 | + return $url; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * Code HTML du bandeau |
| 240 | 240 | */ |
| 241 | 241 | function inc_bandeau_dist() { |
| 242 | - return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 242 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | |
@@ -248,13 +248,13 @@ discard block |
||
| 248 | 248 | * @return array |
| 249 | 249 | */ |
| 250 | 250 | function obtenir_menus_favoris() { |
| 251 | - if ( |
|
| 252 | - isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 253 | - && is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 254 | - && $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 255 | - ) { |
|
| 256 | - return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 257 | - } |
|
| 258 | - $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 259 | - return $definir_menus_favoris(); |
|
| 251 | + if ( |
|
| 252 | + isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 253 | + && is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 254 | + && $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 255 | + ) { |
|
| 256 | + return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 257 | + } |
|
| 258 | + $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 259 | + return $definir_menus_favoris(); |
|
| 260 | 260 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | if ($aff_racine) { |
| 55 | 55 | $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
| 56 | - $idom3 = $idom . '_selection'; |
|
| 56 | + $idom3 = $idom.'_selection'; |
|
| 57 | 57 | |
| 58 | 58 | $onClick = "jQuery(this).parent().addClass('on');jQuery('#choix_parent_principal .on').removeClass('on'); aff_selection(0, '$idom3', '$info', event);return false;"; |
| 59 | 59 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | ' ' |
| 72 | 72 | ); |
| 73 | 73 | |
| 74 | - $js_func = $do . '_selection_titre'; |
|
| 74 | + $js_func = $do.'_selection_titre'; |
|
| 75 | 75 | $ondbClick = "$js_func('$ondbClick',0,'selection_rubrique','id_parent');"; |
| 76 | 76 | |
| 77 | 77 | $aff_racine = "<div class='petit-item petite-racine item'>" |
@@ -112,12 +112,12 @@ discard block |
||
| 112 | 112 | **/ |
| 113 | 113 | function construire_selectionner_hierarchie($idom, $liste, $racine, $url, $name, $url_init = '') { |
| 114 | 114 | |
| 115 | - $idom1 = $idom . '_champ_recherche'; |
|
| 116 | - $idom2 = $idom . '_principal'; |
|
| 117 | - $idom3 = $idom . '_selection'; |
|
| 118 | - $idom4 = $idom . '_col_1'; |
|
| 119 | - $idom5 = 'img_' . $idom4; |
|
| 120 | - $idom6 = $idom . '_fonc'; |
|
| 115 | + $idom1 = $idom.'_champ_recherche'; |
|
| 116 | + $idom2 = $idom.'_principal'; |
|
| 117 | + $idom3 = $idom.'_selection'; |
|
| 118 | + $idom4 = $idom.'_col_1'; |
|
| 119 | + $idom5 = 'img_'.$idom4; |
|
| 120 | + $idom6 = $idom.'_fonc'; |
|
| 121 | 121 | |
| 122 | 122 | return "<div id='$idom'>" |
| 123 | 123 | . "<a id='$idom6' style='visibility: hidden;'" |
@@ -127,10 +127,10 @@ discard block |
||
| 127 | 127 | . http_img_pack( |
| 128 | 128 | 'loader.svg', |
| 129 | 129 | '', |
| 130 | - "class='loader' style='visibility: hidden;float:" . $GLOBALS['spip_lang_right'] . "' id='$idom5'" |
|
| 130 | + "class='loader' style='visibility: hidden;float:".$GLOBALS['spip_lang_right']."' id='$idom5'" |
|
| 131 | 131 | ) |
| 132 | 132 | . '' |
| 133 | - . "<input style='width: 10em;float:" . $GLOBALS['spip_lang_right'] . ";' type='text' class='text search' id='$idom1' placeholder='" . _T('info_rechercher') . "'" |
|
| 133 | + . "<input style='width: 10em;float:".$GLOBALS['spip_lang_right'].";' type='text' class='text search' id='$idom1' placeholder='"._T('info_rechercher')."'" |
|
| 134 | 134 | // eliminer Return car il provoque la soumission (balise unique) |
| 135 | 135 | // et eliminer Tab pour la navigation au clavier |
| 136 | 136 | // ce serait encore mieux de ne le faire que s'il y a encore plusieurs |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | $liste = $id_rubrique; |
| 179 | 179 | $id_rubrique = (int) $id_rubrique; |
| 180 | - while ($id_rubrique = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique = ' . $id_rubrique)) { |
|
| 181 | - $liste = $id_rubrique . ",$liste"; |
|
| 180 | + while ($id_rubrique = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique = '.$id_rubrique)) { |
|
| 181 | + $liste = $id_rubrique.",$liste"; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | return explode(',', "0,$liste"); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/filtres'); |
@@ -45,56 +45,56 @@ discard block |
||
| 45 | 45 | **/ |
| 46 | 46 | function inc_selectionner_dist($sel, $idom = '', $exclus = 0, $aff_racine = false, $recur = true, $do = 'aff') { |
| 47 | 47 | |
| 48 | - if ($recur) { |
|
| 49 | - $recur = mini_hier($sel); |
|
| 50 | - } else { |
|
| 51 | - $sel = 0; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if ($aff_racine) { |
|
| 55 | - $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
|
| 56 | - $idom3 = $idom . '_selection'; |
|
| 57 | - |
|
| 58 | - $onClick = "jQuery(this).parent().addClass('on');jQuery('#choix_parent_principal .on').removeClass('on'); aff_selection(0, '$idom3', '$info', event);return false;"; |
|
| 59 | - |
|
| 60 | - $ondbClick = strtr( |
|
| 61 | - str_replace( |
|
| 62 | - "'", |
|
| 63 | - '’', |
|
| 64 | - str_replace( |
|
| 65 | - '"', |
|
| 66 | - '"', |
|
| 67 | - (string) textebrut(_T('info_racine_site')) |
|
| 68 | - ) |
|
| 69 | - ), |
|
| 70 | - "\n\r", |
|
| 71 | - ' ' |
|
| 72 | - ); |
|
| 73 | - |
|
| 74 | - $js_func = $do . '_selection_titre'; |
|
| 75 | - $ondbClick = "$js_func('$ondbClick',0,'selection_rubrique','id_parent');"; |
|
| 76 | - |
|
| 77 | - $aff_racine = "<div class='petit-item petite-racine item'>" |
|
| 78 | - . "<a href='#'" |
|
| 79 | - . 'onclick="' |
|
| 80 | - . $onClick |
|
| 81 | - . "\"\nondbclick=\"" |
|
| 82 | - . $ondbClick |
|
| 83 | - . $onClick |
|
| 84 | - . '">' |
|
| 85 | - . _T('info_racine_site') |
|
| 86 | - . '</a></div>'; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $url_init = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclus&id=0&col=1&do=$do"); |
|
| 90 | - |
|
| 91 | - $plonger = charger_fonction('plonger', 'inc'); |
|
| 92 | - $plonger_r = $plonger($sel, $idom, $recur, 1, $exclus, $do); |
|
| 93 | - |
|
| 94 | - // url completee par la fonction JS onkeypress_rechercher |
|
| 95 | - $url = generer_url_ecrire('rechercher', "exclus=$exclus&rac=$idom&do=$do&type="); |
|
| 96 | - |
|
| 97 | - return construire_selectionner_hierarchie($idom, $plonger_r, $aff_racine, $url, 'id_parent', $url_init); |
|
| 48 | + if ($recur) { |
|
| 49 | + $recur = mini_hier($sel); |
|
| 50 | + } else { |
|
| 51 | + $sel = 0; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if ($aff_racine) { |
|
| 55 | + $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
|
| 56 | + $idom3 = $idom . '_selection'; |
|
| 57 | + |
|
| 58 | + $onClick = "jQuery(this).parent().addClass('on');jQuery('#choix_parent_principal .on').removeClass('on'); aff_selection(0, '$idom3', '$info', event);return false;"; |
|
| 59 | + |
|
| 60 | + $ondbClick = strtr( |
|
| 61 | + str_replace( |
|
| 62 | + "'", |
|
| 63 | + '’', |
|
| 64 | + str_replace( |
|
| 65 | + '"', |
|
| 66 | + '"', |
|
| 67 | + (string) textebrut(_T('info_racine_site')) |
|
| 68 | + ) |
|
| 69 | + ), |
|
| 70 | + "\n\r", |
|
| 71 | + ' ' |
|
| 72 | + ); |
|
| 73 | + |
|
| 74 | + $js_func = $do . '_selection_titre'; |
|
| 75 | + $ondbClick = "$js_func('$ondbClick',0,'selection_rubrique','id_parent');"; |
|
| 76 | + |
|
| 77 | + $aff_racine = "<div class='petit-item petite-racine item'>" |
|
| 78 | + . "<a href='#'" |
|
| 79 | + . 'onclick="' |
|
| 80 | + . $onClick |
|
| 81 | + . "\"\nondbclick=\"" |
|
| 82 | + . $ondbClick |
|
| 83 | + . $onClick |
|
| 84 | + . '">' |
|
| 85 | + . _T('info_racine_site') |
|
| 86 | + . '</a></div>'; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $url_init = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclus&id=0&col=1&do=$do"); |
|
| 90 | + |
|
| 91 | + $plonger = charger_fonction('plonger', 'inc'); |
|
| 92 | + $plonger_r = $plonger($sel, $idom, $recur, 1, $exclus, $do); |
|
| 93 | + |
|
| 94 | + // url completee par la fonction JS onkeypress_rechercher |
|
| 95 | + $url = generer_url_ecrire('rechercher', "exclus=$exclus&rac=$idom&do=$do&type="); |
|
| 96 | + |
|
| 97 | + return construire_selectionner_hierarchie($idom, $plonger_r, $aff_racine, $url, 'id_parent', $url_init); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -112,58 +112,58 @@ discard block |
||
| 112 | 112 | **/ |
| 113 | 113 | function construire_selectionner_hierarchie($idom, $liste, $racine, $url, $name, $url_init = '') { |
| 114 | 114 | |
| 115 | - $idom1 = $idom . '_champ_recherche'; |
|
| 116 | - $idom2 = $idom . '_principal'; |
|
| 117 | - $idom3 = $idom . '_selection'; |
|
| 118 | - $idom4 = $idom . '_col_1'; |
|
| 119 | - $idom5 = 'img_' . $idom4; |
|
| 120 | - $idom6 = $idom . '_fonc'; |
|
| 121 | - |
|
| 122 | - return "<div id='$idom'>" |
|
| 123 | - . "<a id='$idom6' style='visibility: hidden;'" |
|
| 124 | - . ($url_init ? "\nhref='$url_init'" : '') |
|
| 125 | - . '></a>' |
|
| 126 | - . "<div class='recherche_rapide_parent formulaire_recherche'>" |
|
| 127 | - . http_img_pack( |
|
| 128 | - 'loader.svg', |
|
| 129 | - '', |
|
| 130 | - "class='loader' style='visibility: hidden;float:" . $GLOBALS['spip_lang_right'] . "' id='$idom5'" |
|
| 131 | - ) |
|
| 132 | - . '' |
|
| 133 | - . "<input style='width: 10em;float:" . $GLOBALS['spip_lang_right'] . ";' type='text' class='text search' id='$idom1' placeholder='" . _T('info_rechercher') . "'" |
|
| 134 | - // eliminer Return car il provoque la soumission (balise unique) |
|
| 135 | - // et eliminer Tab pour la navigation au clavier |
|
| 136 | - // ce serait encore mieux de ne le faire que s'il y a encore plusieurs |
|
| 137 | - // resultats retournes par la recherche |
|
| 138 | - . "\nonkeypress=\"k=event.keyCode;if (k==13 || k==3 || k==9){return false;}\"" |
|
| 139 | - // lancer la recherche apres le filtrage ci-dessus sauf sur le tab (navigation au clavier) |
|
| 140 | - . "\nonkeyup=\"if(event.keyCode==9){return false;};return onkey_rechercher(this.value," |
|
| 141 | - // la destination de la recherche |
|
| 142 | - . "'$idom4'" |
|
| 115 | + $idom1 = $idom . '_champ_recherche'; |
|
| 116 | + $idom2 = $idom . '_principal'; |
|
| 117 | + $idom3 = $idom . '_selection'; |
|
| 118 | + $idom4 = $idom . '_col_1'; |
|
| 119 | + $idom5 = 'img_' . $idom4; |
|
| 120 | + $idom6 = $idom . '_fonc'; |
|
| 121 | + |
|
| 122 | + return "<div id='$idom'>" |
|
| 123 | + . "<a id='$idom6' style='visibility: hidden;'" |
|
| 124 | + . ($url_init ? "\nhref='$url_init'" : '') |
|
| 125 | + . '></a>' |
|
| 126 | + . "<div class='recherche_rapide_parent formulaire_recherche'>" |
|
| 127 | + . http_img_pack( |
|
| 128 | + 'loader.svg', |
|
| 129 | + '', |
|
| 130 | + "class='loader' style='visibility: hidden;float:" . $GLOBALS['spip_lang_right'] . "' id='$idom5'" |
|
| 131 | + ) |
|
| 132 | + . '' |
|
| 133 | + . "<input style='width: 10em;float:" . $GLOBALS['spip_lang_right'] . ";' type='text' class='text search' id='$idom1' placeholder='" . _T('info_rechercher') . "'" |
|
| 134 | + // eliminer Return car il provoque la soumission (balise unique) |
|
| 135 | + // et eliminer Tab pour la navigation au clavier |
|
| 136 | + // ce serait encore mieux de ne le faire que s'il y a encore plusieurs |
|
| 137 | + // resultats retournes par la recherche |
|
| 138 | + . "\nonkeypress=\"k=event.keyCode;if (k==13 || k==3 || k==9){return false;}\"" |
|
| 139 | + // lancer la recherche apres le filtrage ci-dessus sauf sur le tab (navigation au clavier) |
|
| 140 | + . "\nonkeyup=\"if(event.keyCode==9){return false;};return onkey_rechercher(this.value," |
|
| 141 | + // la destination de la recherche |
|
| 142 | + . "'$idom4'" |
|
| 143 | 143 | # . "this.parentNode.parentNode.parentNode.parentNode.nextSibling.firstChild.id" |
| 144 | - . ",'" |
|
| 145 | - // l'url effectuant la recherche |
|
| 146 | - . $url |
|
| 147 | - . "'," |
|
| 148 | - // le noeud contenant un gif anime |
|
| 149 | - // . "'idom5'" |
|
| 150 | - . 'this.parentNode.previousSibling.firstChild' |
|
| 151 | - . ",'" |
|
| 152 | - // la valeur de l'attribut Name a remplir |
|
| 153 | - . $name |
|
| 154 | - . "','" |
|
| 155 | - // noeud invisible memorisant l'URL initiale (pour re-initialisation) |
|
| 156 | - . $idom6 |
|
| 157 | - . "')\"" |
|
| 158 | - . ' />' |
|
| 159 | - . "\n</div>" |
|
| 160 | - . ($racine ? "<div>$racine</div>" : '') |
|
| 161 | - . "<div id='" |
|
| 162 | - . $idom2 |
|
| 163 | - . "'><div id='$idom4'" |
|
| 164 | - . " class=''>" |
|
| 165 | - . $liste |
|
| 166 | - . "</div></div>\n<div id='$idom3'></div></div>\n"; |
|
| 144 | + . ",'" |
|
| 145 | + // l'url effectuant la recherche |
|
| 146 | + . $url |
|
| 147 | + . "'," |
|
| 148 | + // le noeud contenant un gif anime |
|
| 149 | + // . "'idom5'" |
|
| 150 | + . 'this.parentNode.previousSibling.firstChild' |
|
| 151 | + . ",'" |
|
| 152 | + // la valeur de l'attribut Name a remplir |
|
| 153 | + . $name |
|
| 154 | + . "','" |
|
| 155 | + // noeud invisible memorisant l'URL initiale (pour re-initialisation) |
|
| 156 | + . $idom6 |
|
| 157 | + . "')\"" |
|
| 158 | + . ' />' |
|
| 159 | + . "\n</div>" |
|
| 160 | + . ($racine ? "<div>$racine</div>" : '') |
|
| 161 | + . "<div id='" |
|
| 162 | + . $idom2 |
|
| 163 | + . "'><div id='$idom4'" |
|
| 164 | + . " class=''>" |
|
| 165 | + . $liste |
|
| 166 | + . "</div></div>\n<div id='$idom3'></div></div>\n"; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -175,11 +175,11 @@ discard block |
||
| 175 | 175 | **/ |
| 176 | 176 | function mini_hier($id_rubrique) { |
| 177 | 177 | |
| 178 | - $liste = $id_rubrique; |
|
| 179 | - $id_rubrique = (int) $id_rubrique; |
|
| 180 | - while ($id_rubrique = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique = ' . $id_rubrique)) { |
|
| 181 | - $liste = $id_rubrique . ",$liste"; |
|
| 182 | - } |
|
| 178 | + $liste = $id_rubrique; |
|
| 179 | + $id_rubrique = (int) $id_rubrique; |
|
| 180 | + while ($id_rubrique = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique = ' . $id_rubrique)) { |
|
| 181 | + $liste = $id_rubrique . ",$liste"; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - return explode(',', "0,$liste"); |
|
| 184 | + return explode(',', "0,$liste"); |
|
| 185 | 185 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -28,51 +28,51 @@ discard block |
||
| 28 | 28 | * @return string Erreur éventuelle |
| 29 | 29 | */ |
| 30 | 30 | function inc_completer_traduction_dist($objet, $id_objet, $id_trad) { |
| 31 | - // dupliquer tous les liens sauf les auteurs : le nouvel auteur est celui qui traduit |
|
| 32 | - // cf API editer_liens |
|
| 33 | - include_spip('action/editer_liens'); |
|
| 34 | - objet_dupliquer_liens($objet, $id_trad, $id_objet, null, ['auteur']); |
|
| 35 | - $_id_table = id_table_objet($objet); |
|
| 31 | + // dupliquer tous les liens sauf les auteurs : le nouvel auteur est celui qui traduit |
|
| 32 | + // cf API editer_liens |
|
| 33 | + include_spip('action/editer_liens'); |
|
| 34 | + objet_dupliquer_liens($objet, $id_trad, $id_objet, null, ['auteur']); |
|
| 35 | + $_id_table = id_table_objet($objet); |
|
| 36 | 36 | |
| 37 | - // recuperer le logo |
|
| 38 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 39 | - include_spip('action/editer_logo'); |
|
| 40 | - foreach (['on', 'off'] as $etat) { |
|
| 41 | - $logo = $chercher_logo($id_trad, $_id_table, $etat); |
|
| 42 | - if ($logo && ($file = reset($logo))) { |
|
| 43 | - logo_modifier($objet, $id_objet, $etat, $file); |
|
| 44 | - } |
|
| 45 | - } |
|
| 37 | + // recuperer le logo |
|
| 38 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 39 | + include_spip('action/editer_logo'); |
|
| 40 | + foreach (['on', 'off'] as $etat) { |
|
| 41 | + $logo = $chercher_logo($id_trad, $_id_table, $etat); |
|
| 42 | + if ($logo && ($file = reset($logo))) { |
|
| 43 | + logo_modifier($objet, $id_objet, $etat, $file); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - // dupliquer certains champs |
|
| 48 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 49 | - $desc = $trouver_table(table_objet_sql($objet)); |
|
| 50 | - $champs = $set = []; |
|
| 47 | + // dupliquer certains champs |
|
| 48 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 49 | + $desc = $trouver_table(table_objet_sql($objet)); |
|
| 50 | + $champs = $set = []; |
|
| 51 | 51 | |
| 52 | - // un éventuel champ 'virtuel' (redirections) |
|
| 53 | - if (!empty($desc['field']['virtuel'])) { |
|
| 54 | - $champs[] = 'virtuel'; |
|
| 55 | - } |
|
| 52 | + // un éventuel champ 'virtuel' (redirections) |
|
| 53 | + if (!empty($desc['field']['virtuel'])) { |
|
| 54 | + $champs[] = 'virtuel'; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $data = sql_fetsel('*', $desc['table'], $_id_table . '=' . (int) $id_trad); |
|
| 57 | + $data = sql_fetsel('*', $desc['table'], $_id_table . '=' . (int) $id_trad); |
|
| 58 | 58 | |
| 59 | - foreach ($champs as $c) { |
|
| 60 | - $set[$c] = $data[$c]; |
|
| 61 | - } |
|
| 59 | + foreach ($champs as $c) { |
|
| 60 | + $set[$c] = $data[$c]; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /* |
|
| 63 | + /* |
|
| 64 | 64 | * Le pipeline 'pre_edition' sera appelé avec l'action 'completer_traduction'. |
| 65 | 65 | * Des plugins pourront ainsi compléter les champs d'un objet traduit lors d'une nouvelle traduction. |
| 66 | 66 | */ |
| 67 | - $err = objet_modifier_champs( |
|
| 68 | - $objet, |
|
| 69 | - $id_objet, |
|
| 70 | - [ |
|
| 71 | - 'data' => $data, |
|
| 72 | - 'action' => 'completer_traduction', |
|
| 73 | - ], |
|
| 74 | - $set |
|
| 75 | - ); |
|
| 67 | + $err = objet_modifier_champs( |
|
| 68 | + $objet, |
|
| 69 | + $id_objet, |
|
| 70 | + [ |
|
| 71 | + 'data' => $data, |
|
| 72 | + 'action' => 'completer_traduction', |
|
| 73 | + ], |
|
| 74 | + $set |
|
| 75 | + ); |
|
| 76 | 76 | |
| 77 | - return $err; |
|
| 77 | + return $err; |
|
| 78 | 78 | } |
@@ -54,7 +54,7 @@ |
||
| 54 | 54 | $champs[] = 'virtuel'; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $data = sql_fetsel('*', $desc['table'], $_id_table . '=' . (int) $id_trad); |
|
| 57 | + $data = sql_fetsel('*', $desc['table'], $_id_table.'='.(int) $id_trad); |
|
| 58 | 58 | |
| 59 | 59 | foreach ($champs as $c) { |
| 60 | 60 | $set[$c] = $data[$c]; |
@@ -10,101 +10,101 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function inc_log_dist($message, $logname = null, $logdir = null, $logsuf = null) { |
| 17 | - static $test_repertoire = []; |
|
| 18 | - static $compteur = []; |
|
| 19 | - static $debugverb = ''; // pour ne pas le recalculer au reappel |
|
| 20 | - |
|
| 21 | - if (is_null($logname) || !is_string($logname)) { |
|
| 22 | - $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; |
|
| 23 | - } |
|
| 24 | - if (!isset($compteur[$logname])) { |
|
| 25 | - $compteur[$logname] = 0; |
|
| 26 | - } |
|
| 27 | - if ( |
|
| 28 | - $logname != 'maj' |
|
| 29 | - && defined('_MAX_LOG') |
|
| 30 | - && ($compteur[$logname]++ > _MAX_LOG || !$GLOBALS['nombre_de_logs'] || !$GLOBALS['taille_des_logs']) |
|
| 31 | - ) { |
|
| 32 | - return; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
|
| 36 | - $logfile = |
|
| 37 | - ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 38 | - . $logname |
|
| 39 | - . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
|
| 40 | - |
|
| 41 | - if (!isset($test_repertoire[$d = dirname($logfile)])) { |
|
| 42 | - $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire |
|
| 43 | - $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire( |
|
| 44 | - $d, |
|
| 45 | - '', |
|
| 46 | - false, |
|
| 47 | - true |
|
| 48 | - ) : false)); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - // Si le repertoire défini n'existe pas, poser dans tmp/ |
|
| 52 | - if (!$test_repertoire[$d]) { |
|
| 53 | - $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $rotate = 0; |
|
| 57 | - $pid = '(pid ' . @getmypid() . ')'; |
|
| 58 | - |
|
| 59 | - // accepter spip_log( Array ) |
|
| 60 | - if (!is_string($message)) { |
|
| 61 | - $message = var_export($message, true); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - if (!$debugverb && defined('_LOG_FILELINE') && _LOG_FILELINE) { |
|
| 65 | - $debug = debug_backtrace(); |
|
| 66 | - $l = $debug[1]['line']; |
|
| 67 | - $fi = $debug[1]['file']; |
|
| 68 | - if (str_starts_with($fi, _ROOT_RACINE)) { |
|
| 69 | - $fi = substr($fi, strlen(_ROOT_RACINE)); |
|
| 70 | - } |
|
| 71 | - $fu = $debug[2]['function'] ?? ''; |
|
| 72 | - $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 76 | - //distinguer les logs prives et publics dans les grep |
|
| 77 | - . $debugverb |
|
| 78 | - . (test_espace_prive() ? ':Pri:' : ':Pub:') |
|
| 79 | - . preg_replace("/\n*$/", "\n", $message); |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - if ( |
|
| 83 | - @is_readable($logfile) |
|
| 84 | - && ((!$s = @filesize($logfile)) || $s > $GLOBALS['taille_des_logs'] * 1024) |
|
| 85 | - ) { |
|
| 86 | - $rotate = $GLOBALS['nombre_de_logs']; |
|
| 87 | - $m .= "[-- rotate --]\n"; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $f = @fopen($logfile, 'ab'); |
|
| 91 | - if ($f) { |
|
| 92 | - fwrite($f, (defined('_LOG_BRUT') && _LOG_BRUT) ? $m : str_replace('<', '<', $m)); |
|
| 93 | - fclose($f); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if ( |
|
| 97 | - $rotate-- > 0 && function_exists('spip_unlink') |
|
| 98 | - ) { |
|
| 99 | - spip_unlink($logfile . '.' . $rotate); |
|
| 100 | - while ($rotate--) { |
|
| 101 | - @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // Dupliquer les erreurs specifiques dans le log general |
|
| 106 | - if (defined('_FILE_LOG') && $logname !== _FILE_LOG) { |
|
| 107 | - inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message); |
|
| 108 | - } |
|
| 109 | - $debugverb = ''; |
|
| 17 | + static $test_repertoire = []; |
|
| 18 | + static $compteur = []; |
|
| 19 | + static $debugverb = ''; // pour ne pas le recalculer au reappel |
|
| 20 | + |
|
| 21 | + if (is_null($logname) || !is_string($logname)) { |
|
| 22 | + $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; |
|
| 23 | + } |
|
| 24 | + if (!isset($compteur[$logname])) { |
|
| 25 | + $compteur[$logname] = 0; |
|
| 26 | + } |
|
| 27 | + if ( |
|
| 28 | + $logname != 'maj' |
|
| 29 | + && defined('_MAX_LOG') |
|
| 30 | + && ($compteur[$logname]++ > _MAX_LOG || !$GLOBALS['nombre_de_logs'] || !$GLOBALS['taille_des_logs']) |
|
| 31 | + ) { |
|
| 32 | + return; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
|
| 36 | + $logfile = |
|
| 37 | + ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 38 | + . $logname |
|
| 39 | + . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
|
| 40 | + |
|
| 41 | + if (!isset($test_repertoire[$d = dirname($logfile)])) { |
|
| 42 | + $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire |
|
| 43 | + $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire( |
|
| 44 | + $d, |
|
| 45 | + '', |
|
| 46 | + false, |
|
| 47 | + true |
|
| 48 | + ) : false)); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + // Si le repertoire défini n'existe pas, poser dans tmp/ |
|
| 52 | + if (!$test_repertoire[$d]) { |
|
| 53 | + $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $rotate = 0; |
|
| 57 | + $pid = '(pid ' . @getmypid() . ')'; |
|
| 58 | + |
|
| 59 | + // accepter spip_log( Array ) |
|
| 60 | + if (!is_string($message)) { |
|
| 61 | + $message = var_export($message, true); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + if (!$debugverb && defined('_LOG_FILELINE') && _LOG_FILELINE) { |
|
| 65 | + $debug = debug_backtrace(); |
|
| 66 | + $l = $debug[1]['line']; |
|
| 67 | + $fi = $debug[1]['file']; |
|
| 68 | + if (str_starts_with($fi, _ROOT_RACINE)) { |
|
| 69 | + $fi = substr($fi, strlen(_ROOT_RACINE)); |
|
| 70 | + } |
|
| 71 | + $fu = $debug[2]['function'] ?? ''; |
|
| 72 | + $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 76 | + //distinguer les logs prives et publics dans les grep |
|
| 77 | + . $debugverb |
|
| 78 | + . (test_espace_prive() ? ':Pri:' : ':Pub:') |
|
| 79 | + . preg_replace("/\n*$/", "\n", $message); |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + if ( |
|
| 83 | + @is_readable($logfile) |
|
| 84 | + && ((!$s = @filesize($logfile)) || $s > $GLOBALS['taille_des_logs'] * 1024) |
|
| 85 | + ) { |
|
| 86 | + $rotate = $GLOBALS['nombre_de_logs']; |
|
| 87 | + $m .= "[-- rotate --]\n"; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $f = @fopen($logfile, 'ab'); |
|
| 91 | + if ($f) { |
|
| 92 | + fwrite($f, (defined('_LOG_BRUT') && _LOG_BRUT) ? $m : str_replace('<', '<', $m)); |
|
| 93 | + fclose($f); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if ( |
|
| 97 | + $rotate-- > 0 && function_exists('spip_unlink') |
|
| 98 | + ) { |
|
| 99 | + spip_unlink($logfile . '.' . $rotate); |
|
| 100 | + while ($rotate--) { |
|
| 101 | + @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // Dupliquer les erreurs specifiques dans le log general |
|
| 106 | + if (defined('_FILE_LOG') && $logname !== _FILE_LOG) { |
|
| 107 | + inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message); |
|
| 108 | + } |
|
| 109 | + $debugverb = ''; |
|
| 110 | 110 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
| 36 | 36 | $logfile = |
| 37 | - ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 37 | + ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 38 | 38 | . $logname |
| 39 | 39 | . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
| 40 | 40 | |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | // Si le repertoire défini n'existe pas, poser dans tmp/ |
| 52 | 52 | if (!$test_repertoire[$d]) { |
| 53 | - $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 53 | + $logfile = _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES.$logname.'.log'; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $rotate = 0; |
| 57 | - $pid = '(pid ' . @getmypid() . ')'; |
|
| 57 | + $pid = '(pid '.@getmypid().')'; |
|
| 58 | 58 | |
| 59 | 59 | // accepter spip_log( Array ) |
| 60 | 60 | if (!is_string($message)) { |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | $fi = substr($fi, strlen(_ROOT_RACINE)); |
| 70 | 70 | } |
| 71 | 71 | $fu = $debug[2]['function'] ?? ''; |
| 72 | - $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 72 | + $debugverb = "$fi:L$l:$fu".'():'; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 75 | + $m = date('Y-m-d H:i:s').' '.($GLOBALS['ip'] ?? '').' '.$pid.' ' |
|
| 76 | 76 | //distinguer les logs prives et publics dans les grep |
| 77 | 77 | . $debugverb |
| 78 | 78 | . (test_espace_prive() ? ':Pri:' : ':Pub:') |
@@ -96,9 +96,9 @@ discard block |
||
| 96 | 96 | if ( |
| 97 | 97 | $rotate-- > 0 && function_exists('spip_unlink') |
| 98 | 98 | ) { |
| 99 | - spip_unlink($logfile . '.' . $rotate); |
|
| 99 | + spip_unlink($logfile.'.'.$rotate); |
|
| 100 | 100 | while ($rotate--) { |
| 101 | - @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 101 | + @rename($logfile.($rotate ? '.'.$rotate : ''), $logfile.'.'.($rotate + 1)); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
@@ -164,8 +164,7 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | if ($start === false || $start === 'end') { |
| 166 | 166 | $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
| 167 | - } |
|
| 168 | - else { |
|
| 167 | + } else { |
|
| 169 | 168 | $p = stripos($svg, '<svg'); |
| 170 | 169 | $p = strpos($svg, '>', $p); |
| 171 | 170 | $svg = substr_replace($svg, $shapes, $p + 1, 0); |
@@ -224,8 +223,7 @@ discard block |
||
| 224 | 223 | if (str_starts_with($couleur, 'rgb(')) { |
| 225 | 224 | $c = explode(',', substr($couleur, 4)); |
| 226 | 225 | $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]); |
| 227 | - } |
|
| 228 | - else { |
|
| 226 | + } else { |
|
| 229 | 227 | $couleur = couleur_html_to_hex($couleur); |
| 230 | 228 | } |
| 231 | 229 | return '#' . ltrim($couleur, '#'); |
@@ -281,17 +279,14 @@ discard block |
||
| 281 | 279 | // si pas de height valide, on suppose l'image carree |
| 282 | 280 | $viewBox[3] = $width; |
| 283 | 281 | } |
| 284 | - } |
|
| 285 | - else { |
|
| 282 | + } else { |
|
| 286 | 283 | // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
| 287 | 284 | $width = $viewBox[2]; |
| 288 | 285 | if ($width < 1) { |
| 289 | 286 | $coeff = max($coeff, 1000); |
| 290 | - } |
|
| 291 | - elseif ($width < 10) { |
|
| 287 | + } elseif ($width < 10) { |
|
| 292 | 288 | $coeff = max($coeff, 100); |
| 293 | - } |
|
| 294 | - elseif ($width < 100) { |
|
| 289 | + } elseif ($width < 100) { |
|
| 295 | 290 | $coeff = max($coeff, 10); |
| 296 | 291 | } |
| 297 | 292 | } |
@@ -304,16 +299,13 @@ discard block |
||
| 304 | 299 | if (empty($attributs['viewBox'])) { |
| 305 | 300 | $viewBox[3] = $height; |
| 306 | 301 | } |
| 307 | - } |
|
| 308 | - else { |
|
| 302 | + } else { |
|
| 309 | 303 | $height = $viewBox[3]; |
| 310 | 304 | if ($height < 1) { |
| 311 | 305 | $coeff = max($coeff, 1000); |
| 312 | - } |
|
| 313 | - elseif ($height < 10) { |
|
| 306 | + } elseif ($height < 10) { |
|
| 314 | 307 | $coeff = max($coeff, 100); |
| 315 | - } |
|
| 316 | - elseif ($height < 100) { |
|
| 308 | + } elseif ($height < 100) { |
|
| 317 | 309 | $coeff = max($coeff, 10); |
| 318 | 310 | } |
| 319 | 311 | } |
@@ -454,8 +446,7 @@ discard block |
||
| 454 | 446 | if (isset($attributs['viewBox'])) { |
| 455 | 447 | $viewBox = explode(' ', $attributs['viewBox']); |
| 456 | 448 | $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
| 457 | - } |
|
| 458 | - else { |
|
| 449 | + } else { |
|
| 459 | 450 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
| 460 | 451 | } |
| 461 | 452 | $svg = svg_insert_shapes($svg, $rect); |
@@ -484,8 +475,7 @@ discard block |
||
| 484 | 475 | if (isset($attributs['viewBox'])) { |
| 485 | 476 | $viewBox = explode(' ', $attributs['viewBox']); |
| 486 | 477 | $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
| 487 | - } |
|
| 488 | - else { |
|
| 478 | + } else { |
|
| 489 | 479 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
| 490 | 480 | } |
| 491 | 481 | $svg = svg_insert_shapes($svg, $rect, false); |
@@ -606,8 +596,7 @@ discard block |
||
| 606 | 596 | $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2); |
| 607 | 597 | $mx = -$x; |
| 608 | 598 | $transform = "translate($x, 0) $transform translate($mx, 0)"; |
| 609 | - } |
|
| 610 | - else { |
|
| 599 | + } else { |
|
| 611 | 600 | $transform = 'scale(1,-1)'; |
| 612 | 601 | |
| 613 | 602 | $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2); |
@@ -666,8 +655,7 @@ discard block |
||
| 666 | 655 | $c = array_shift($colors); |
| 667 | 656 | if (strlen($c) == 4) { |
| 668 | 657 | $short[] = $c; |
| 669 | - } |
|
| 670 | - else { |
|
| 658 | + } else { |
|
| 671 | 659 | $long[] = $c; |
| 672 | 660 | } |
| 673 | 661 | } |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('IMG_SVG')) { |
| 23 | - // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 24 | - define('IMG_SVG', 128); |
|
| 25 | - define('IMAGETYPE_SVG', 19); |
|
| 23 | + // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 24 | + define('IMG_SVG', 128); |
|
| 25 | + define('IMAGETYPE_SVG', 19); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -38,35 +38,35 @@ discard block |
||
| 38 | 38 | * false si on a pas pu charger l'image |
| 39 | 39 | */ |
| 40 | 40 | function svg_charger($fichier, $maxlen = null) { |
| 41 | - if (str_starts_with($fichier, 'data:image/svg+xml')) { |
|
| 42 | - $image = explode(';', $fichier, 2); |
|
| 43 | - $image = end($image); |
|
| 44 | - if (str_starts_with($image, 'base64,')) { |
|
| 45 | - $image = base64_decode(substr($image, 7)); |
|
| 46 | - } |
|
| 47 | - if (str_contains($image, '<svg')) { |
|
| 48 | - return $image; |
|
| 49 | - } |
|
| 50 | - // encodage inconnu ou autre format d'image ? |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 53 | - // c'est peut etre deja une image svg ? |
|
| 54 | - if (str_contains($fichier, '<svg')) { |
|
| 55 | - return $fichier; |
|
| 56 | - } |
|
| 57 | - if (!file_exists($fichier)) { |
|
| 58 | - include_spip('inc/filtres'); |
|
| 59 | - $fichier = supprimer_timestamp($fichier); |
|
| 60 | - if (!file_exists($fichier)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - $image = is_null($maxlen) ? file_get_contents($fichier) : file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 65 | - // est-ce bien une image svg ? |
|
| 66 | - if (str_contains($image, '<svg')) { |
|
| 67 | - return $image; |
|
| 68 | - } |
|
| 69 | - return false; |
|
| 41 | + if (str_starts_with($fichier, 'data:image/svg+xml')) { |
|
| 42 | + $image = explode(';', $fichier, 2); |
|
| 43 | + $image = end($image); |
|
| 44 | + if (str_starts_with($image, 'base64,')) { |
|
| 45 | + $image = base64_decode(substr($image, 7)); |
|
| 46 | + } |
|
| 47 | + if (str_contains($image, '<svg')) { |
|
| 48 | + return $image; |
|
| 49 | + } |
|
| 50 | + // encodage inconnu ou autre format d'image ? |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | + // c'est peut etre deja une image svg ? |
|
| 54 | + if (str_contains($fichier, '<svg')) { |
|
| 55 | + return $fichier; |
|
| 56 | + } |
|
| 57 | + if (!file_exists($fichier)) { |
|
| 58 | + include_spip('inc/filtres'); |
|
| 59 | + $fichier = supprimer_timestamp($fichier); |
|
| 60 | + if (!file_exists($fichier)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + $image = is_null($maxlen) ? file_get_contents($fichier) : file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 65 | + // est-ce bien une image svg ? |
|
| 66 | + if (str_contains($image, '<svg')) { |
|
| 67 | + return $image; |
|
| 68 | + } |
|
| 69 | + return false; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -75,28 +75,28 @@ discard block |
||
| 75 | 75 | * @return array|bool |
| 76 | 76 | */ |
| 77 | 77 | function svg_lire_balise_svg($fichier) { |
| 78 | - if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 79 | - return false; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 83 | - $pe = stripos($debut_fichier, '>', $ps); |
|
| 84 | - $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 85 | - |
|
| 86 | - if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 87 | - if (!function_exists('extraire_attribut')) { |
|
| 88 | - include_spip('inc/filtres'); |
|
| 89 | - } |
|
| 90 | - $attributs = []; |
|
| 91 | - foreach ($matches[1] as $att) { |
|
| 92 | - $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return [$balise_svg, $attributs]; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return false; |
|
| 78 | + if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 79 | + return false; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 83 | + $pe = stripos($debut_fichier, '>', $ps); |
|
| 84 | + $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 85 | + |
|
| 86 | + if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 87 | + if (!function_exists('extraire_attribut')) { |
|
| 88 | + include_spip('inc/filtres'); |
|
| 89 | + } |
|
| 90 | + $attributs = []; |
|
| 91 | + foreach ($matches[1] as $att) { |
|
| 92 | + $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return [$balise_svg, $attributs]; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return false; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -106,12 +106,12 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | function svg_lire_attributs($img) { |
| 108 | 108 | |
| 109 | - if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 110 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 111 | - return $attributs; |
|
| 112 | - } |
|
| 109 | + if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 110 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 111 | + return $attributs; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - return false; |
|
| 114 | + return false; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -121,19 +121,19 @@ discard block |
||
| 121 | 121 | * @return bool|float|int |
| 122 | 122 | */ |
| 123 | 123 | function svg_dimension_to_pixels($dimension, $precision = 2) { |
| 124 | - if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 125 | - return match (strtolower($m[2])) { |
|
| 126 | - '%' => false, |
|
| 127 | - 'em' => round($m[1] * 16, $precision), |
|
| 128 | - 'ex' => round($m[1] * 16, $precision), |
|
| 129 | - 'pc' => round($m[1] * 16, $precision), |
|
| 130 | - 'cm' => round($m[1] * 96 / 2.54, $precision), |
|
| 131 | - 'mm' => round($m[1] * 96 / 25.4, $precision), |
|
| 132 | - 'in' => round($m[1] * 96, $precision), |
|
| 133 | - default => $m[1], |
|
| 134 | - }; |
|
| 135 | - } |
|
| 136 | - return false; |
|
| 124 | + if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 125 | + return match (strtolower($m[2])) { |
|
| 126 | + '%' => false, |
|
| 127 | + 'em' => round($m[1] * 16, $precision), |
|
| 128 | + 'ex' => round($m[1] * 16, $precision), |
|
| 129 | + 'pc' => round($m[1] * 16, $precision), |
|
| 130 | + 'cm' => round($m[1] * 96 / 2.54, $precision), |
|
| 131 | + 'mm' => round($m[1] * 96 / 25.4, $precision), |
|
| 132 | + 'in' => round($m[1] * 96, $precision), |
|
| 133 | + default => $m[1], |
|
| 134 | + }; |
|
| 135 | + } |
|
| 136 | + return false; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -144,14 +144,14 @@ discard block |
||
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | 146 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 147 | - $new_balise_svg = '<svg'; |
|
| 148 | - foreach ($attributs as $k => $v) { |
|
| 149 | - $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 150 | - } |
|
| 151 | - $new_balise_svg .= '>'; |
|
| 152 | - |
|
| 153 | - $p = strpos($svg, $old_balise_svg); |
|
| 154 | - return substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 147 | + $new_balise_svg = '<svg'; |
|
| 148 | + foreach ($attributs as $k => $v) { |
|
| 149 | + $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 150 | + } |
|
| 151 | + $new_balise_svg .= '>'; |
|
| 152 | + |
|
| 153 | + $p = strpos($svg, $old_balise_svg); |
|
| 154 | + return substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -163,15 +163,15 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | function svg_insert_shapes($svg, $shapes, $start = true) { |
| 165 | 165 | |
| 166 | - if ($start === false || $start === 'end') { |
|
| 167 | - $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 168 | - } |
|
| 169 | - else { |
|
| 170 | - $p = stripos($svg, '<svg'); |
|
| 171 | - $p = strpos($svg, '>', $p); |
|
| 172 | - $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 173 | - } |
|
| 174 | - return $svg; |
|
| 166 | + if ($start === false || $start === 'end') { |
|
| 167 | + $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 168 | + } |
|
| 169 | + else { |
|
| 170 | + $p = stripos($svg, '<svg'); |
|
| 171 | + $p = strpos($svg, '>', $p); |
|
| 172 | + $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 173 | + } |
|
| 174 | + return $svg; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -184,12 +184,12 @@ discard block |
||
| 184 | 184 | * @return string |
| 185 | 185 | */ |
| 186 | 186 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 187 | - $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 188 | - $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 189 | - $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 190 | - $g = "<g clip-path=\"url(#$id)\">"; |
|
| 191 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 192 | - return svg_insert_shapes($svg, '</g>', false); |
|
| 187 | + $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 188 | + $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 189 | + $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 190 | + $g = "<g clip-path=\"url(#$id)\">"; |
|
| 191 | + $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 192 | + return svg_insert_shapes($svg, '</g>', false); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -200,20 +200,20 @@ discard block |
||
| 200 | 200 | * @return bool|string |
| 201 | 201 | */ |
| 202 | 202 | function svg_redimensionner($img, $new_width, $new_height) { |
| 203 | - if ( |
|
| 204 | - ($svg = svg_charger($img)) |
|
| 205 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 206 | - ) { |
|
| 207 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 208 | - if (!isset($attributs['viewBox'])) { |
|
| 209 | - $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 210 | - } |
|
| 211 | - $attributs['width'] = (string) $new_width; |
|
| 212 | - $attributs['height'] = (string) $new_height; |
|
| 213 | - return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - return $img; |
|
| 203 | + if ( |
|
| 204 | + ($svg = svg_charger($img)) |
|
| 205 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 206 | + ) { |
|
| 207 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 208 | + if (!isset($attributs['viewBox'])) { |
|
| 209 | + $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 210 | + } |
|
| 211 | + $attributs['width'] = (string) $new_width; |
|
| 212 | + $attributs['height'] = (string) $new_height; |
|
| 213 | + return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + return $img; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -222,14 +222,14 @@ discard block |
||
| 222 | 222 | * @return string |
| 223 | 223 | */ |
| 224 | 224 | function svg_couleur_to_hexa($couleur) { |
| 225 | - if (str_starts_with($couleur, 'rgb(')) { |
|
| 226 | - $c = explode(',', substr($couleur, 4)); |
|
| 227 | - $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]); |
|
| 228 | - } |
|
| 229 | - else { |
|
| 230 | - $couleur = couleur_html_to_hex($couleur); |
|
| 231 | - } |
|
| 232 | - return '#' . ltrim($couleur, '#'); |
|
| 225 | + if (str_starts_with($couleur, 'rgb(')) { |
|
| 226 | + $c = explode(',', substr($couleur, 4)); |
|
| 227 | + $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]); |
|
| 228 | + } |
|
| 229 | + else { |
|
| 230 | + $couleur = couleur_html_to_hex($couleur); |
|
| 231 | + } |
|
| 232 | + return '#' . ltrim($couleur, '#'); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | * @return array |
| 239 | 239 | */ |
| 240 | 240 | function svg_couleur_to_rgb($couleur) { |
| 241 | - if (str_starts_with($couleur, 'rgb(')) { |
|
| 242 | - $c = explode(',', substr($couleur, 4)); |
|
| 243 | - return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]]; |
|
| 244 | - } |
|
| 245 | - return _couleur_hex_to_dec($couleur); |
|
| 241 | + if (str_starts_with($couleur, 'rgb(')) { |
|
| 242 | + $c = explode(',', substr($couleur, 4)); |
|
| 243 | + return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]]; |
|
| 244 | + } |
|
| 245 | + return _couleur_hex_to_dec($couleur); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -252,80 +252,80 @@ discard block |
||
| 252 | 252 | * @return array |
| 253 | 253 | */ |
| 254 | 254 | function svg_getimagesize_from_attr($attributs) { |
| 255 | - $width = 350; // default width |
|
| 256 | - $height = 150; // default height |
|
| 257 | - |
|
| 258 | - $viewBox = "0 0 $width $height"; |
|
| 259 | - if (isset($attributs['viewBox'])) { |
|
| 260 | - $viewBox = $attributs['viewBox']; |
|
| 261 | - $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 262 | - } |
|
| 263 | - // et on la convertit en px |
|
| 264 | - $viewBox = explode(' ', $viewBox); |
|
| 265 | - $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 266 | - if (!$viewBox[2]) { |
|
| 267 | - $viewBox[2] = $width; |
|
| 268 | - } |
|
| 269 | - if (!$viewBox[3]) { |
|
| 270 | - $viewBox[3] = $height; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - $coeff = 1; |
|
| 274 | - if ( |
|
| 275 | - isset($attributs['width']) |
|
| 276 | - && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 277 | - ) { |
|
| 278 | - $width = $w; |
|
| 279 | - // si on avait pas de viewBox, la construire a partir de ce width |
|
| 280 | - if (empty($attributs['viewBox'])) { |
|
| 281 | - $viewBox[2] = $width; |
|
| 282 | - // si pas de height valide, on suppose l'image carree |
|
| 283 | - $viewBox[3] = $width; |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - else { |
|
| 287 | - // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 288 | - $width = $viewBox[2]; |
|
| 289 | - if ($width < 1) { |
|
| 290 | - $coeff = max($coeff, 1000); |
|
| 291 | - } |
|
| 292 | - elseif ($width < 10) { |
|
| 293 | - $coeff = max($coeff, 100); |
|
| 294 | - } |
|
| 295 | - elseif ($width < 100) { |
|
| 296 | - $coeff = max($coeff, 10); |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - if ( |
|
| 300 | - isset($attributs['height']) |
|
| 301 | - && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 302 | - ) { |
|
| 303 | - $height = $h; |
|
| 304 | - // si on avait pas de viewBox, la construire a partir de ce height |
|
| 305 | - if (empty($attributs['viewBox'])) { |
|
| 306 | - $viewBox[3] = $height; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - else { |
|
| 310 | - $height = $viewBox[3]; |
|
| 311 | - if ($height < 1) { |
|
| 312 | - $coeff = max($coeff, 1000); |
|
| 313 | - } |
|
| 314 | - elseif ($height < 10) { |
|
| 315 | - $coeff = max($coeff, 100); |
|
| 316 | - } |
|
| 317 | - elseif ($height < 100) { |
|
| 318 | - $coeff = max($coeff, 10); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - // arrondir le width et height en pixel in fine |
|
| 323 | - $width = round($coeff * $width); |
|
| 324 | - $height = round($coeff * $height); |
|
| 325 | - |
|
| 326 | - $viewBox = implode(' ', $viewBox); |
|
| 327 | - |
|
| 328 | - return [$width, $height, $viewBox]; |
|
| 255 | + $width = 350; // default width |
|
| 256 | + $height = 150; // default height |
|
| 257 | + |
|
| 258 | + $viewBox = "0 0 $width $height"; |
|
| 259 | + if (isset($attributs['viewBox'])) { |
|
| 260 | + $viewBox = $attributs['viewBox']; |
|
| 261 | + $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 262 | + } |
|
| 263 | + // et on la convertit en px |
|
| 264 | + $viewBox = explode(' ', $viewBox); |
|
| 265 | + $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 266 | + if (!$viewBox[2]) { |
|
| 267 | + $viewBox[2] = $width; |
|
| 268 | + } |
|
| 269 | + if (!$viewBox[3]) { |
|
| 270 | + $viewBox[3] = $height; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + $coeff = 1; |
|
| 274 | + if ( |
|
| 275 | + isset($attributs['width']) |
|
| 276 | + && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 277 | + ) { |
|
| 278 | + $width = $w; |
|
| 279 | + // si on avait pas de viewBox, la construire a partir de ce width |
|
| 280 | + if (empty($attributs['viewBox'])) { |
|
| 281 | + $viewBox[2] = $width; |
|
| 282 | + // si pas de height valide, on suppose l'image carree |
|
| 283 | + $viewBox[3] = $width; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + else { |
|
| 287 | + // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 288 | + $width = $viewBox[2]; |
|
| 289 | + if ($width < 1) { |
|
| 290 | + $coeff = max($coeff, 1000); |
|
| 291 | + } |
|
| 292 | + elseif ($width < 10) { |
|
| 293 | + $coeff = max($coeff, 100); |
|
| 294 | + } |
|
| 295 | + elseif ($width < 100) { |
|
| 296 | + $coeff = max($coeff, 10); |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + if ( |
|
| 300 | + isset($attributs['height']) |
|
| 301 | + && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 302 | + ) { |
|
| 303 | + $height = $h; |
|
| 304 | + // si on avait pas de viewBox, la construire a partir de ce height |
|
| 305 | + if (empty($attributs['viewBox'])) { |
|
| 306 | + $viewBox[3] = $height; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + else { |
|
| 310 | + $height = $viewBox[3]; |
|
| 311 | + if ($height < 1) { |
|
| 312 | + $coeff = max($coeff, 1000); |
|
| 313 | + } |
|
| 314 | + elseif ($height < 10) { |
|
| 315 | + $coeff = max($coeff, 100); |
|
| 316 | + } |
|
| 317 | + elseif ($height < 100) { |
|
| 318 | + $coeff = max($coeff, 10); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + // arrondir le width et height en pixel in fine |
|
| 323 | + $width = round($coeff * $width); |
|
| 324 | + $height = round($coeff * $height); |
|
| 325 | + |
|
| 326 | + $viewBox = implode(' ', $viewBox); |
|
| 327 | + |
|
| 328 | + return [$width, $height, $viewBox]; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /** |
@@ -341,23 +341,23 @@ discard block |
||
| 341 | 341 | * @return string |
| 342 | 342 | */ |
| 343 | 343 | function svg_force_viewBox_px($img, $force_width_and_height = false) { |
| 344 | - if ( |
|
| 345 | - ($svg = svg_charger($img)) |
|
| 346 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 347 | - ) { |
|
| 348 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 349 | - |
|
| 350 | - [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 351 | - |
|
| 352 | - if ($force_width_and_height) { |
|
| 353 | - $attributs['width'] = $width; |
|
| 354 | - $attributs['height'] = $height; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - $attributs['viewBox'] = $viewBox; |
|
| 358 | - return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 359 | - } |
|
| 360 | - return $img; |
|
| 344 | + if ( |
|
| 345 | + ($svg = svg_charger($img)) |
|
| 346 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 347 | + ) { |
|
| 348 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 349 | + |
|
| 350 | + [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 351 | + |
|
| 352 | + if ($force_width_and_height) { |
|
| 353 | + $attributs['width'] = $width; |
|
| 354 | + $attributs['height'] = $height; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + $attributs['viewBox'] = $viewBox; |
|
| 358 | + return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 359 | + } |
|
| 360 | + return $img; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -366,13 +366,13 @@ discard block |
||
| 366 | 366 | * @return array|mixed |
| 367 | 367 | */ |
| 368 | 368 | function svg_extract_couleurs($img) { |
| 369 | - if ( |
|
| 370 | - ($svg = svg_charger($img)) |
|
| 371 | - && preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches) |
|
| 372 | - ) { |
|
| 373 | - return $matches[0]; |
|
| 374 | - } |
|
| 375 | - return []; |
|
| 369 | + if ( |
|
| 370 | + ($svg = svg_charger($img)) |
|
| 371 | + && preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches) |
|
| 372 | + ) { |
|
| 373 | + return $matches[0]; |
|
| 374 | + } |
|
| 375 | + return []; |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /** |
@@ -383,58 +383,58 @@ discard block |
||
| 383 | 383 | * @return bool|string |
| 384 | 384 | */ |
| 385 | 385 | function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') { |
| 386 | - if ( |
|
| 387 | - ($svg = svg_force_viewBox_px($img)) |
|
| 388 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 389 | - ) { |
|
| 390 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 391 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 392 | - |
|
| 393 | - $viewport_w = $new_width; |
|
| 394 | - $viewport_h = $new_height; |
|
| 395 | - $viewport_ox = $offset_width; |
|
| 396 | - $viewport_oy = $offset_height; |
|
| 397 | - |
|
| 398 | - // si on a un width/height qui rescale, il faut rescaler |
|
| 399 | - if ( |
|
| 400 | - isset($attributs['width']) |
|
| 401 | - && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 402 | - && isset($attributs['height']) |
|
| 403 | - && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 404 | - ) { |
|
| 405 | - $xscale = $viewBox[2] / $w; |
|
| 406 | - $viewport_w = round($viewport_w * $xscale, 2); |
|
| 407 | - $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 408 | - $yscale = $viewBox[3] / $h; |
|
| 409 | - $viewport_h = round($viewport_h * $yscale, 2); |
|
| 410 | - $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - if ($viewport_w > $viewBox[2] || $viewport_h > $viewBox[3]) { |
|
| 414 | - $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - // maintenant on redefinit la viewBox |
|
| 418 | - $viewBox[0] += $viewport_ox; |
|
| 419 | - $viewBox[1] += $viewport_oy; |
|
| 420 | - $viewBox[2] = $viewport_w; |
|
| 421 | - $viewBox[3] = $viewport_h; |
|
| 422 | - |
|
| 423 | - $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 424 | - $attributs['width'] = (string) $new_width; |
|
| 425 | - $attributs['height'] = (string) $new_height; |
|
| 426 | - |
|
| 427 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 428 | - |
|
| 429 | - // ajouter un background |
|
| 430 | - if ($background_color && $background_color !== 'transparent') { |
|
| 431 | - $svg = svg_ajouter_background($svg, $background_color); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - return $svg; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - return $img; |
|
| 386 | + if ( |
|
| 387 | + ($svg = svg_force_viewBox_px($img)) |
|
| 388 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 389 | + ) { |
|
| 390 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 391 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 392 | + |
|
| 393 | + $viewport_w = $new_width; |
|
| 394 | + $viewport_h = $new_height; |
|
| 395 | + $viewport_ox = $offset_width; |
|
| 396 | + $viewport_oy = $offset_height; |
|
| 397 | + |
|
| 398 | + // si on a un width/height qui rescale, il faut rescaler |
|
| 399 | + if ( |
|
| 400 | + isset($attributs['width']) |
|
| 401 | + && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 402 | + && isset($attributs['height']) |
|
| 403 | + && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 404 | + ) { |
|
| 405 | + $xscale = $viewBox[2] / $w; |
|
| 406 | + $viewport_w = round($viewport_w * $xscale, 2); |
|
| 407 | + $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 408 | + $yscale = $viewBox[3] / $h; |
|
| 409 | + $viewport_h = round($viewport_h * $yscale, 2); |
|
| 410 | + $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + if ($viewport_w > $viewBox[2] || $viewport_h > $viewBox[3]) { |
|
| 414 | + $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + // maintenant on redefinit la viewBox |
|
| 418 | + $viewBox[0] += $viewport_ox; |
|
| 419 | + $viewBox[1] += $viewport_oy; |
|
| 420 | + $viewBox[2] = $viewport_w; |
|
| 421 | + $viewBox[3] = $viewport_h; |
|
| 422 | + |
|
| 423 | + $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 424 | + $attributs['width'] = (string) $new_width; |
|
| 425 | + $attributs['height'] = (string) $new_height; |
|
| 426 | + |
|
| 427 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 428 | + |
|
| 429 | + // ajouter un background |
|
| 430 | + if ($background_color && $background_color !== 'transparent') { |
|
| 431 | + $svg = svg_ajouter_background($svg, $background_color); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + return $svg; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + return $img; |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | /** |
@@ -444,26 +444,26 @@ discard block |
||
| 444 | 444 | * @return bool|string |
| 445 | 445 | */ |
| 446 | 446 | function svg_ajouter_background($img, $background_color) { |
| 447 | - if ( |
|
| 448 | - ($svg = svg_charger($img)) |
|
| 449 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 450 | - ) { |
|
| 451 | - if ($background_color && $background_color !== 'transparent') { |
|
| 452 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 453 | - |
|
| 454 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 455 | - if (isset($attributs['viewBox'])) { |
|
| 456 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 457 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 458 | - } |
|
| 459 | - else { |
|
| 460 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 461 | - } |
|
| 462 | - $svg = svg_insert_shapes($svg, $rect); |
|
| 463 | - } |
|
| 464 | - return $svg; |
|
| 465 | - } |
|
| 466 | - return $img; |
|
| 447 | + if ( |
|
| 448 | + ($svg = svg_charger($img)) |
|
| 449 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 450 | + ) { |
|
| 451 | + if ($background_color && $background_color !== 'transparent') { |
|
| 452 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 453 | + |
|
| 454 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 455 | + if (isset($attributs['viewBox'])) { |
|
| 456 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 457 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 458 | + } |
|
| 459 | + else { |
|
| 460 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 461 | + } |
|
| 462 | + $svg = svg_insert_shapes($svg, $rect); |
|
| 463 | + } |
|
| 464 | + return $svg; |
|
| 465 | + } |
|
| 466 | + return $img; |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
@@ -474,26 +474,26 @@ discard block |
||
| 474 | 474 | * @return bool|string |
| 475 | 475 | */ |
| 476 | 476 | function svg_ajouter_voile($img, $background_color, $opacity) { |
| 477 | - if ( |
|
| 478 | - ($svg = svg_charger($img)) |
|
| 479 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 480 | - ) { |
|
| 481 | - if ($background_color && $background_color !== 'transparent') { |
|
| 482 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 483 | - |
|
| 484 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 485 | - if (isset($attributs['viewBox'])) { |
|
| 486 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 487 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 488 | - } |
|
| 489 | - else { |
|
| 490 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 491 | - } |
|
| 492 | - $svg = svg_insert_shapes($svg, $rect, false); |
|
| 493 | - } |
|
| 494 | - return $svg; |
|
| 495 | - } |
|
| 496 | - return $img; |
|
| 477 | + if ( |
|
| 478 | + ($svg = svg_charger($img)) |
|
| 479 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 480 | + ) { |
|
| 481 | + if ($background_color && $background_color !== 'transparent') { |
|
| 482 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 483 | + |
|
| 484 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 485 | + if (isset($attributs['viewBox'])) { |
|
| 486 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 487 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 488 | + } |
|
| 489 | + else { |
|
| 490 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 491 | + } |
|
| 492 | + $svg = svg_insert_shapes($svg, $rect, false); |
|
| 493 | + } |
|
| 494 | + return $svg; |
|
| 495 | + } |
|
| 496 | + return $img; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | |
@@ -504,27 +504,27 @@ discard block |
||
| 504 | 504 | * @return bool|string |
| 505 | 505 | */ |
| 506 | 506 | function svg_transformer($img, $attributs) { |
| 507 | - if ( |
|
| 508 | - ($svg = svg_charger($img)) |
|
| 509 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 510 | - ) { |
|
| 511 | - if ($attributs) { |
|
| 512 | - [$balise_svg, ] = $svg_infos; |
|
| 513 | - $g = '<g'; |
|
| 514 | - foreach ($attributs as $k => $v) { |
|
| 515 | - if (strlen($v)) { |
|
| 516 | - $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - if (strlen($g) > 2) { |
|
| 520 | - $g .= '>'; |
|
| 521 | - $svg = svg_insert_shapes($svg, $g); |
|
| 522 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - return $svg; |
|
| 526 | - } |
|
| 527 | - return $img; |
|
| 507 | + if ( |
|
| 508 | + ($svg = svg_charger($img)) |
|
| 509 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 510 | + ) { |
|
| 511 | + if ($attributs) { |
|
| 512 | + [$balise_svg, ] = $svg_infos; |
|
| 513 | + $g = '<g'; |
|
| 514 | + foreach ($attributs as $k => $v) { |
|
| 515 | + if (strlen($v)) { |
|
| 516 | + $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + if (strlen($g) > 2) { |
|
| 520 | + $g .= '>'; |
|
| 521 | + $svg = svg_insert_shapes($svg, $g); |
|
| 522 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + return $svg; |
|
| 526 | + } |
|
| 527 | + return $img; |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -535,21 +535,21 @@ discard block |
||
| 535 | 535 | * @return bool|string |
| 536 | 536 | */ |
| 537 | 537 | function svg_apply_filter($img, $filter_def) { |
| 538 | - if ( |
|
| 539 | - ($svg = svg_charger($img)) |
|
| 540 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 541 | - ) { |
|
| 542 | - if ($filter_def) { |
|
| 543 | - [$balise_svg, ] = $svg_infos; |
|
| 544 | - $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 545 | - $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 546 | - $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 547 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 548 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 549 | - } |
|
| 550 | - return $svg; |
|
| 551 | - } |
|
| 552 | - return $img; |
|
| 538 | + if ( |
|
| 539 | + ($svg = svg_charger($img)) |
|
| 540 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 541 | + ) { |
|
| 542 | + if ($filter_def) { |
|
| 543 | + [$balise_svg, ] = $svg_infos; |
|
| 544 | + $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 545 | + $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 546 | + $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 547 | + $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 548 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 549 | + } |
|
| 550 | + return $svg; |
|
| 551 | + } |
|
| 552 | + return $img; |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | /** |
@@ -559,8 +559,8 @@ discard block |
||
| 559 | 559 | * @return string |
| 560 | 560 | */ |
| 561 | 561 | function svg_filter_blur($img, $blur_width) { |
| 562 | - $blur_width = (int) $blur_width; |
|
| 563 | - return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 562 | + $blur_width = (int) $blur_width; |
|
| 563 | + return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -570,10 +570,10 @@ discard block |
||
| 570 | 570 | * @return bool|string |
| 571 | 571 | */ |
| 572 | 572 | function svg_filter_grayscale($img, $intensity) { |
| 573 | - $value = round(1.0 - $intensity, 2); |
|
| 574 | - //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 575 | - $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 576 | - return svg_apply_filter($img, $filter); |
|
| 573 | + $value = round(1.0 - $intensity, 2); |
|
| 574 | + //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 575 | + $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 576 | + return svg_apply_filter($img, $filter); |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
@@ -586,8 +586,8 @@ discard block |
||
| 586 | 586 | * @return bool|string |
| 587 | 587 | */ |
| 588 | 588 | function svg_filter_sepia($img, $intensity) { |
| 589 | - $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 590 | - return svg_apply_filter($img, $filter); |
|
| 589 | + $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 590 | + return svg_apply_filter($img, $filter); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -597,30 +597,30 @@ discard block |
||
| 597 | 597 | * @return bool|string |
| 598 | 598 | */ |
| 599 | 599 | function svg_flip($img, $HorV) { |
| 600 | - if ( |
|
| 601 | - ($svg = svg_force_viewBox_px($img)) |
|
| 602 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 603 | - ) { |
|
| 604 | - [$balise_svg, $atts] = $svg_infos; |
|
| 605 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 606 | - |
|
| 607 | - if (!in_array($HorV, ['h', 'H'])) { |
|
| 608 | - $transform = 'scale(-1,1)'; |
|
| 609 | - |
|
| 610 | - $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2); |
|
| 611 | - $mx = -$x; |
|
| 612 | - $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 613 | - } |
|
| 614 | - else { |
|
| 615 | - $transform = 'scale(1,-1)'; |
|
| 616 | - |
|
| 617 | - $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2); |
|
| 618 | - $my = -$y; |
|
| 619 | - $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 620 | - } |
|
| 621 | - return svg_transformer($svg, ['transform' => $transform]); |
|
| 622 | - } |
|
| 623 | - return $img; |
|
| 600 | + if ( |
|
| 601 | + ($svg = svg_force_viewBox_px($img)) |
|
| 602 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 603 | + ) { |
|
| 604 | + [$balise_svg, $atts] = $svg_infos; |
|
| 605 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 606 | + |
|
| 607 | + if (!in_array($HorV, ['h', 'H'])) { |
|
| 608 | + $transform = 'scale(-1,1)'; |
|
| 609 | + |
|
| 610 | + $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2); |
|
| 611 | + $mx = -$x; |
|
| 612 | + $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 613 | + } |
|
| 614 | + else { |
|
| 615 | + $transform = 'scale(1,-1)'; |
|
| 616 | + |
|
| 617 | + $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2); |
|
| 618 | + $my = -$y; |
|
| 619 | + $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 620 | + } |
|
| 621 | + return svg_transformer($svg, ['transform' => $transform]); |
|
| 622 | + } |
|
| 623 | + return $img; |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | /** |
@@ -634,19 +634,19 @@ discard block |
||
| 634 | 634 | * @return bool|string |
| 635 | 635 | */ |
| 636 | 636 | function svg_rotate($img, $angle, $center_x, $center_y) { |
| 637 | - if ( |
|
| 638 | - ($svg = svg_force_viewBox_px($img)) |
|
| 639 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 640 | - ) { |
|
| 641 | - [$balise_svg, $atts] = $svg_infos; |
|
| 642 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 643 | - |
|
| 644 | - $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 645 | - $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 646 | - |
|
| 647 | - return svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 648 | - } |
|
| 649 | - return $img; |
|
| 637 | + if ( |
|
| 638 | + ($svg = svg_force_viewBox_px($img)) |
|
| 639 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 640 | + ) { |
|
| 641 | + [$balise_svg, $atts] = $svg_infos; |
|
| 642 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 643 | + |
|
| 644 | + $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 645 | + $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 646 | + |
|
| 647 | + return svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 648 | + } |
|
| 649 | + return $img; |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | /** |
@@ -658,40 +658,40 @@ discard block |
||
| 658 | 658 | * @return bool|mixed|string |
| 659 | 659 | */ |
| 660 | 660 | function svg_filtrer_couleurs($img, $callback_filter) { |
| 661 | - if ( |
|
| 662 | - ($svg = svg_force_viewBox_px($img)) |
|
| 663 | - && ($colors = svg_extract_couleurs($svg)) |
|
| 664 | - ) { |
|
| 665 | - $colors = array_unique($colors); |
|
| 666 | - |
|
| 667 | - $short = []; |
|
| 668 | - $long = []; |
|
| 669 | - while (count($colors)) { |
|
| 670 | - $c = array_shift($colors); |
|
| 671 | - if (strlen($c) == 4) { |
|
| 672 | - $short[] = $c; |
|
| 673 | - } |
|
| 674 | - else { |
|
| 675 | - $long[] = $c; |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - $colors = [...$long, ...$short]; |
|
| 680 | - $new_colors = []; |
|
| 681 | - $colors = array_flip($colors); |
|
| 682 | - foreach ($colors as $c => $k) { |
|
| 683 | - $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - |
|
| 687 | - foreach ($colors as $original => $replace) { |
|
| 688 | - $new = svg_couleur_to_hexa($original); |
|
| 689 | - $new_colors[$replace] = $callback_filter($new); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 693 | - |
|
| 694 | - return str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 695 | - } |
|
| 696 | - return $img; |
|
| 661 | + if ( |
|
| 662 | + ($svg = svg_force_viewBox_px($img)) |
|
| 663 | + && ($colors = svg_extract_couleurs($svg)) |
|
| 664 | + ) { |
|
| 665 | + $colors = array_unique($colors); |
|
| 666 | + |
|
| 667 | + $short = []; |
|
| 668 | + $long = []; |
|
| 669 | + while (count($colors)) { |
|
| 670 | + $c = array_shift($colors); |
|
| 671 | + if (strlen($c) == 4) { |
|
| 672 | + $short[] = $c; |
|
| 673 | + } |
|
| 674 | + else { |
|
| 675 | + $long[] = $c; |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + $colors = [...$long, ...$short]; |
|
| 680 | + $new_colors = []; |
|
| 681 | + $colors = array_flip($colors); |
|
| 682 | + foreach ($colors as $c => $k) { |
|
| 683 | + $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + |
|
| 687 | + foreach ($colors as $original => $replace) { |
|
| 688 | + $new = svg_couleur_to_hexa($original); |
|
| 689 | + $new_colors[$replace] = $callback_filter($new); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 693 | + |
|
| 694 | + return str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 695 | + } |
|
| 696 | + return $img; |
|
| 697 | 697 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | if (!file_exists($fichier)) { |
| 58 | 58 | include_spip('inc/filtres'); |
| 59 | - $fichier = supprimer_timestamp($fichier); |
|
| 59 | + $fichier = supprimer_timestamp($fichier); |
|
| 60 | 60 | if (!file_exists($fichier)) { |
| 61 | 61 | return false; |
| 62 | 62 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 147 | 147 | $new_balise_svg = '<svg'; |
| 148 | 148 | foreach ($attributs as $k => $v) { |
| 149 | - $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 149 | + $new_balise_svg .= " $k=\"".entites_html($v).'"'; |
|
| 150 | 150 | } |
| 151 | 151 | $new_balise_svg .= '>'; |
| 152 | 152 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | function svg_insert_shapes($svg, $shapes, $start = true) { |
| 165 | 165 | |
| 166 | 166 | if ($start === false || $start === 'end') { |
| 167 | - $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 167 | + $svg = str_replace('</svg>', $shapes.'</svg>', $svg); |
|
| 168 | 168 | } |
| 169 | 169 | else { |
| 170 | 170 | $p = stripos($svg, '<svg'); |
@@ -185,10 +185,10 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 187 | 187 | $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
| 188 | - $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 188 | + $id = 'clip-'.substr(md5($rect.strlen($svg)), 0, 8); |
|
| 189 | 189 | $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
| 190 | 190 | $g = "<g clip-path=\"url(#$id)\">"; |
| 191 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 191 | + $svg = svg_insert_shapes($svg, $clippath.$g); |
|
| 192 | 192 | return svg_insert_shapes($svg, '</g>', false); |
| 193 | 193 | } |
| 194 | 194 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | ) { |
| 207 | 207 | [$balise_svg, $attributs] = $svg_infos; |
| 208 | 208 | if (!isset($attributs['viewBox'])) { |
| 209 | - $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 209 | + $attributs['viewBox'] = '0 0 '.$attributs['width'].' '.$attributs['height']; |
|
| 210 | 210 | } |
| 211 | 211 | $attributs['width'] = (string) $new_width; |
| 212 | 212 | $attributs['height'] = (string) $new_height; |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | else { |
| 230 | 230 | $couleur = couleur_html_to_hex($couleur); |
| 231 | 231 | } |
| 232 | - return '#' . ltrim($couleur, '#'); |
|
| 232 | + return '#'.ltrim($couleur, '#'); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | function svg_couleur_to_rgb($couleur) { |
| 241 | 241 | if (str_starts_with($couleur, 'rgb(')) { |
| 242 | 242 | $c = explode(',', substr($couleur, 4)); |
| 243 | - return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]]; |
|
| 243 | + return ['red' => (int) $c[0], 'green' => (int) $c[1], 'blue' => (int) $c[2]]; |
|
| 244 | 244 | } |
| 245 | 245 | return _couleur_hex_to_dec($couleur); |
| 246 | 246 | } |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | $background_color = svg_couleur_to_hexa($background_color); |
| 455 | 455 | if (isset($attributs['viewBox'])) { |
| 456 | 456 | $viewBox = explode(' ', $attributs['viewBox']); |
| 457 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 457 | + $rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\"/>"; |
|
| 458 | 458 | } |
| 459 | 459 | else { |
| 460 | 460 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | $background_color = svg_couleur_to_hexa($background_color); |
| 485 | 485 | if (isset($attributs['viewBox'])) { |
| 486 | 486 | $viewBox = explode(' ', $attributs['viewBox']); |
| 487 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 487 | + $rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 488 | 488 | } |
| 489 | 489 | else { |
| 490 | 490 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | $g = '<g'; |
| 514 | 514 | foreach ($attributs as $k => $v) { |
| 515 | 515 | if (strlen($v)) { |
| 516 | - $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 516 | + $g .= " $k=\"".attribut_html($v).'"'; |
|
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | if (strlen($g) > 2) { |
@@ -541,10 +541,10 @@ discard block |
||
| 541 | 541 | ) { |
| 542 | 542 | if ($filter_def) { |
| 543 | 543 | [$balise_svg, ] = $svg_infos; |
| 544 | - $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 544 | + $filter_id = 'filter-'.substr(md5($filter_def.strlen($svg)), 0, 8); |
|
| 545 | 545 | $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
| 546 | 546 | $g = "<g filter=\"url(#$filter_id)\">"; |
| 547 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 547 | + $svg = svg_insert_shapes($svg, $filter.$g); |
|
| 548 | 548 | $svg = svg_insert_shapes($svg, '</g>', false); |
| 549 | 549 | } |
| 550 | 550 | return $svg; |
@@ -15,22 +15,22 @@ |
||
| 15 | 15 | * Présentation des pages simplifiées pour installer SPIP |
| 16 | 16 | **/ |
| 17 | 17 | class Installation extends Admin { |
| 18 | - public const TYPE = 'installation'; |
|
| 18 | + public const TYPE = 'installation'; |
|
| 19 | 19 | |
| 20 | - protected function setOptions(array $options) { |
|
| 21 | - $options['titre'] ??= ''; |
|
| 22 | - if (!$options['titre'] || $options['titre'] === 'AUTO') { |
|
| 23 | - $options['titre'] = _T('info_installation_systeme_publication'); |
|
| 24 | - } |
|
| 25 | - $options = parent::setOptions($options); |
|
| 26 | - $options['couleur_fond'] = '#a1124d'; |
|
| 27 | - $options['css_files'][] = find_in_theme('installation.css'); |
|
| 28 | - $options['footer'] = ''; |
|
| 29 | - return $options; |
|
| 30 | - } |
|
| 20 | + protected function setOptions(array $options) { |
|
| 21 | + $options['titre'] ??= ''; |
|
| 22 | + if (!$options['titre'] || $options['titre'] === 'AUTO') { |
|
| 23 | + $options['titre'] = _T('info_installation_systeme_publication'); |
|
| 24 | + } |
|
| 25 | + $options = parent::setOptions($options); |
|
| 26 | + $options['couleur_fond'] = '#a1124d'; |
|
| 27 | + $options['css_files'][] = find_in_theme('installation.css'); |
|
| 28 | + $options['footer'] = ''; |
|
| 29 | + return $options; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function page($corps = '', $options = []) { |
|
| 33 | - $options['titre'] ??= 'AUTO'; |
|
| 34 | - return parent::page($corps, $options); |
|
| 35 | - } |
|
| 32 | + public function page($corps = '', $options = []) { |
|
| 33 | + $options['titre'] ??= 'AUTO'; |
|
| 34 | + return parent::page($corps, $options); |
|
| 35 | + } |
|
| 36 | 36 | } |