@@ -311,7 +311,7 @@ |
||
| 311 | 311 | * peut etre utilise pour l'import depuis xml, |
| 312 | 312 | * ou la copie de base a base (mysql<->sqlite par exemple) |
| 313 | 313 | * |
| 314 | - * @param array $tables |
|
| 314 | + * @param string[] $tables |
|
| 315 | 315 | * @param array $exclure_tables |
| 316 | 316 | * @param string $serveur |
| 317 | 317 | */ |
@@ -326,14 +326,15 @@ |
||
| 326 | 326 | $connecte = false; |
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | - if ($connecte) |
|
| 330 | - # on ajoute les liaisons en premier |
|
| 329 | + if ($connecte) { |
|
| 330 | + # on ajoute les liaisons en premier |
|
| 331 | 331 | # si une restauration est interrompue, |
| 332 | 332 | # cela se verra mieux si il manque des objets |
| 333 | 333 | # que des liens |
| 334 | 334 | { |
| 335 | 335 | array_unshift($tables_for_dump, $link_table); |
| 336 | 336 | } |
| 337 | + } |
|
| 337 | 338 | } |
| 338 | 339 | |
| 339 | 340 | return array($tables_for_dump, $tables_for_link); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | define('_VERSION_ARCHIVE', '1.3'); |
@@ -29,13 +29,13 @@ discard block |
||
| 29 | 29 | // NB: Ce fichier peut ajouter des tables (old-style) |
| 30 | 30 | // donc il faut l'inclure "en globals" |
| 31 | 31 | if ($f = find_in_path('mes_fonctions.php')) { |
| 32 | - global $dossier_squelettes; |
|
| 33 | - @include_once(_ROOT_CWD . $f); |
|
| 32 | + global $dossier_squelettes; |
|
| 33 | + @include_once(_ROOT_CWD . $f); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | if (@is_readable(_CACHE_PLUGINS_FCT)) { |
| 37 | - // chargement optimise precompile |
|
| 38 | - include_once(_CACHE_PLUGINS_FCT); |
|
| 37 | + // chargement optimise precompile |
|
| 38 | + include_once(_CACHE_PLUGINS_FCT); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @return string |
| 49 | 49 | **/ |
| 50 | 50 | function base_dump_meta_name($rub) { |
| 51 | - return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 51 | + return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -63,15 +63,15 @@ discard block |
||
| 63 | 63 | * @return string |
| 64 | 64 | **/ |
| 65 | 65 | function base_dump_dir($meta) { |
| 66 | - include_spip('inc/documents'); |
|
| 67 | - // determine upload va aussi initialiser l'index "restreint" |
|
| 68 | - $maindir = determine_upload(); |
|
| 69 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 70 | - $maindir = _DIR_DUMP; |
|
| 71 | - } |
|
| 72 | - $dir = sous_repertoire($maindir, $meta); |
|
| 73 | - |
|
| 74 | - return $dir; |
|
| 66 | + include_spip('inc/documents'); |
|
| 67 | + // determine upload va aussi initialiser l'index "restreint" |
|
| 68 | + $maindir = determine_upload(); |
|
| 69 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 70 | + $maindir = _DIR_DUMP; |
|
| 71 | + } |
|
| 72 | + $dir = sous_repertoire($maindir, $meta); |
|
| 73 | + |
|
| 74 | + return $dir; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -85,28 +85,28 @@ discard block |
||
| 85 | 85 | * @return array |
| 86 | 86 | */ |
| 87 | 87 | function base_lister_toutes_tables( |
| 88 | - $serveur = '', |
|
| 89 | - $tables = array(), |
|
| 90 | - $exclude = array(), |
|
| 91 | - $affiche_vrai_prefixe = false |
|
| 88 | + $serveur = '', |
|
| 89 | + $tables = array(), |
|
| 90 | + $exclude = array(), |
|
| 91 | + $affiche_vrai_prefixe = false |
|
| 92 | 92 | ) { |
| 93 | - spip_connect($serveur); |
|
| 94 | - $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 95 | - $prefixe = $connexion['prefixe']; |
|
| 96 | - |
|
| 97 | - $p = '/^' . $prefixe . '/'; |
|
| 98 | - $res = $tables; |
|
| 99 | - foreach (sql_alltable(null, $serveur) as $t) { |
|
| 100 | - if (preg_match($p, $t)) { |
|
| 101 | - $t1 = preg_replace($p, 'spip', $t); |
|
| 102 | - if (!in_array($t1, $tables) and !in_array($t1, $exclude)) { |
|
| 103 | - $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - sort($res); |
|
| 108 | - |
|
| 109 | - return $res; |
|
| 93 | + spip_connect($serveur); |
|
| 94 | + $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 95 | + $prefixe = $connexion['prefixe']; |
|
| 96 | + |
|
| 97 | + $p = '/^' . $prefixe . '/'; |
|
| 98 | + $res = $tables; |
|
| 99 | + foreach (sql_alltable(null, $serveur) as $t) { |
|
| 100 | + if (preg_match($p, $t)) { |
|
| 101 | + $t1 = preg_replace($p, 'spip', $t); |
|
| 102 | + if (!in_array($t1, $tables) and !in_array($t1, $exclude)) { |
|
| 103 | + $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + sort($res); |
|
| 108 | + |
|
| 109 | + return $res; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -116,11 +116,11 @@ discard block |
||
| 116 | 116 | * @return string |
| 117 | 117 | */ |
| 118 | 118 | function base_prefixe_tables($serveur = '') { |
| 119 | - spip_connect($serveur); |
|
| 120 | - $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 121 | - $prefixe = $connexion['prefixe']; |
|
| 119 | + spip_connect($serveur); |
|
| 120 | + $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 121 | + $prefixe = $connexion['prefixe']; |
|
| 122 | 122 | |
| 123 | - return $prefixe; |
|
| 123 | + return $prefixe; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | |
@@ -135,29 +135,29 @@ discard block |
||
| 135 | 135 | * @return array |
| 136 | 136 | */ |
| 137 | 137 | function base_saisie_tables($name, $tables, $exclude = array(), $post = null, $serveur = '') { |
| 138 | - include_spip('inc/filtres'); |
|
| 139 | - $res = array(); |
|
| 140 | - foreach ($tables as $k => $t) { |
|
| 141 | - // par defaut tout est coche sauf les tables dans $exclude |
|
| 142 | - if (is_null($post)) { |
|
| 143 | - $check = (in_array($t, $exclude) ? false : true); |
|
| 144 | - } // mais si on a poste une selection, la reprendre |
|
| 145 | - else { |
|
| 146 | - $check = in_array($t, $post); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 150 | - . "[]' id='$name$k'" |
|
| 151 | - . ($check ? " checked='checked'" : '') |
|
| 152 | - . "/>\n" |
|
| 153 | - . "<label for='$name$k'>$t</label>" |
|
| 154 | - . " (" |
|
| 155 | - . sinon(singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 156 | - _T('dump:aucune_donnee')) |
|
| 157 | - . ")"; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - return $res; |
|
| 138 | + include_spip('inc/filtres'); |
|
| 139 | + $res = array(); |
|
| 140 | + foreach ($tables as $k => $t) { |
|
| 141 | + // par defaut tout est coche sauf les tables dans $exclude |
|
| 142 | + if (is_null($post)) { |
|
| 143 | + $check = (in_array($t, $exclude) ? false : true); |
|
| 144 | + } // mais si on a poste une selection, la reprendre |
|
| 145 | + else { |
|
| 146 | + $check = in_array($t, $post); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 150 | + . "[]' id='$name$k'" |
|
| 151 | + . ($check ? " checked='checked'" : '') |
|
| 152 | + . "/>\n" |
|
| 153 | + . "<label for='$name$k'>$t</label>" |
|
| 154 | + . " (" |
|
| 155 | + . sinon(singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 156 | + _T('dump:aucune_donnee')) |
|
| 157 | + . ")"; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + return $res; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
@@ -169,27 +169,27 @@ discard block |
||
| 169 | 169 | * @return array |
| 170 | 170 | */ |
| 171 | 171 | function lister_tables_noexport() { |
| 172 | - // par defaut tout est exporte sauf les tables ci-dessous |
|
| 173 | - static $EXPORT_tables_noexport = null; |
|
| 174 | - if (!is_null($EXPORT_tables_noexport)) { |
|
| 175 | - return $EXPORT_tables_noexport; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $EXPORT_tables_noexport = array( |
|
| 179 | - 'spip_caches', // plugin invalideur |
|
| 180 | - 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 181 | - 'spip_test', // c'est un test ! |
|
| 182 | - #'spip_referers', |
|
| 183 | - #'spip_referers_articles', |
|
| 184 | - #'spip_visites', |
|
| 185 | - #'spip_visites_articles', |
|
| 186 | - #'spip_versions', |
|
| 187 | - #'spip_versions_fragments' |
|
| 188 | - ); |
|
| 189 | - |
|
| 190 | - $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 191 | - |
|
| 192 | - return $EXPORT_tables_noexport; |
|
| 172 | + // par defaut tout est exporte sauf les tables ci-dessous |
|
| 173 | + static $EXPORT_tables_noexport = null; |
|
| 174 | + if (!is_null($EXPORT_tables_noexport)) { |
|
| 175 | + return $EXPORT_tables_noexport; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $EXPORT_tables_noexport = array( |
|
| 179 | + 'spip_caches', // plugin invalideur |
|
| 180 | + 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 181 | + 'spip_test', // c'est un test ! |
|
| 182 | + #'spip_referers', |
|
| 183 | + #'spip_referers_articles', |
|
| 184 | + #'spip_visites', |
|
| 185 | + #'spip_visites_articles', |
|
| 186 | + #'spip_versions', |
|
| 187 | + #'spip_versions_fragments' |
|
| 188 | + ); |
|
| 189 | + |
|
| 190 | + $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 191 | + |
|
| 192 | + return $EXPORT_tables_noexport; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -200,25 +200,25 @@ discard block |
||
| 200 | 200 | * @return array |
| 201 | 201 | */ |
| 202 | 202 | function lister_tables_noimport() { |
| 203 | - static $IMPORT_tables_noimport = null; |
|
| 204 | - if (!is_null($IMPORT_tables_noimport)) { |
|
| 205 | - return $IMPORT_tables_noimport; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $IMPORT_tables_noimport = array(); |
|
| 209 | - // par defaut tout est importe sauf les tables ci-dessous |
|
| 210 | - // possibiliter de definir cela tables via la meta |
|
| 211 | - // compatibilite |
|
| 212 | - if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 213 | - $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 214 | - if (!is_array($IMPORT_tables_noimport)) { |
|
| 215 | - include_spip('inc/meta'); |
|
| 216 | - effacer_meta('IMPORT_tables_noimport'); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 220 | - |
|
| 221 | - return $IMPORT_tables_noimport; |
|
| 203 | + static $IMPORT_tables_noimport = null; |
|
| 204 | + if (!is_null($IMPORT_tables_noimport)) { |
|
| 205 | + return $IMPORT_tables_noimport; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + $IMPORT_tables_noimport = array(); |
|
| 209 | + // par defaut tout est importe sauf les tables ci-dessous |
|
| 210 | + // possibiliter de definir cela tables via la meta |
|
| 211 | + // compatibilite |
|
| 212 | + if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 213 | + $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 214 | + if (!is_array($IMPORT_tables_noimport)) { |
|
| 215 | + include_spip('inc/meta'); |
|
| 216 | + effacer_meta('IMPORT_tables_noimport'); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 220 | + |
|
| 221 | + return $IMPORT_tables_noimport; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | |
@@ -230,23 +230,23 @@ discard block |
||
| 230 | 230 | * @return array |
| 231 | 231 | */ |
| 232 | 232 | function lister_tables_noerase() { |
| 233 | - static $IMPORT_tables_noerase = null; |
|
| 234 | - if (!is_null($IMPORT_tables_noerase)) { |
|
| 235 | - return $IMPORT_tables_noerase; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - $IMPORT_tables_noerase = array( |
|
| 239 | - 'spip_meta', |
|
| 240 | - // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 241 | - // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 242 | - 'spip_referers', |
|
| 243 | - 'spip_referers_articles', |
|
| 244 | - 'spip_visites', |
|
| 245 | - 'spip_visites_articles' |
|
| 246 | - ); |
|
| 247 | - $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 248 | - |
|
| 249 | - return $IMPORT_tables_noerase; |
|
| 233 | + static $IMPORT_tables_noerase = null; |
|
| 234 | + if (!is_null($IMPORT_tables_noerase)) { |
|
| 235 | + return $IMPORT_tables_noerase; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + $IMPORT_tables_noerase = array( |
|
| 239 | + 'spip_meta', |
|
| 240 | + // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 241 | + // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 242 | + 'spip_referers', |
|
| 243 | + 'spip_referers_articles', |
|
| 244 | + 'spip_visites', |
|
| 245 | + 'spip_visites_articles' |
|
| 246 | + ); |
|
| 247 | + $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 248 | + |
|
| 249 | + return $IMPORT_tables_noerase; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
@@ -260,83 +260,83 @@ discard block |
||
| 260 | 260 | * @return array |
| 261 | 261 | */ |
| 262 | 262 | function base_liste_table_for_dump($exclude_tables = array()) { |
| 263 | - $tables_for_dump = array(); |
|
| 264 | - $tables_pointees = array(); |
|
| 265 | - $tables = array(); |
|
| 266 | - $tables_principales = $GLOBALS['tables_principales']; |
|
| 267 | - $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 268 | - $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 269 | - |
|
| 270 | - if (include_spip('base/objets') |
|
| 271 | - and function_exists('lister_tables_objets_sql') |
|
| 272 | - ) { |
|
| 273 | - $tables = lister_tables_objets_sql(); |
|
| 274 | - foreach ($tables as $t => $infos) { |
|
| 275 | - if ($infos['principale'] and !isset($tables_principales[$t])) { |
|
| 276 | - $tables_principales[$t] = true; |
|
| 277 | - } |
|
| 278 | - if (!$infos['principale'] and !isset($tables_auxiliaires[$t])) { |
|
| 279 | - $tables_auxiliaires[$t] = true; |
|
| 280 | - } |
|
| 281 | - if (count($infos['tables_jointures'])) { |
|
| 282 | - $tables_jointures[$t] = array_merge(isset($tables_jointures[$t]) ? $tables_jointures[$t] : array(), |
|
| 283 | - $infos['tables_jointures']); |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - // on construit un index des tables de liens |
|
| 289 | - // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 290 | - $tables_for_link = array(); |
|
| 291 | - foreach ($tables_jointures as $table => $liste_relations) { |
|
| 292 | - if (is_array($liste_relations)) { |
|
| 293 | - $nom = $table; |
|
| 294 | - if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 295 | - $nom = "spip_$table"; |
|
| 296 | - } |
|
| 297 | - if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 298 | - foreach ($liste_relations as $link_table) { |
|
| 299 | - if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 300 | - $tables_for_link[$link_table][] = $nom; |
|
| 301 | - } else { |
|
| 302 | - if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 303 | - $tables_for_link["spip_$link_table"][] = $nom; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - $liste_tables = array_merge(array_keys($tables_principales), array_keys($tables_auxiliaires), array_keys($tables)); |
|
| 312 | - foreach ($liste_tables as $table) { |
|
| 313 | - // $name = preg_replace("{^spip_}","",$table); |
|
| 314 | - if (!isset($tables_pointees[$table]) |
|
| 315 | - && !in_array($table, $exclude_tables) |
|
| 316 | - && !isset($tables_for_link[$table]) |
|
| 317 | - ) { |
|
| 318 | - $tables_for_dump[] = $table; |
|
| 319 | - $tables_pointees[$table] = 1; |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - foreach ($tables_for_link as $link_table => $liste) { |
|
| 323 | - $connecte = true; |
|
| 324 | - foreach ($liste as $connect_table) { |
|
| 325 | - if (!in_array($connect_table, $tables_for_dump)) { |
|
| 326 | - $connecte = false; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - if ($connecte) |
|
| 330 | - # on ajoute les liaisons en premier |
|
| 331 | - # si une restauration est interrompue, |
|
| 332 | - # cela se verra mieux si il manque des objets |
|
| 333 | - # que des liens |
|
| 334 | - { |
|
| 335 | - array_unshift($tables_for_dump, $link_table); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - return array($tables_for_dump, $tables_for_link); |
|
| 263 | + $tables_for_dump = array(); |
|
| 264 | + $tables_pointees = array(); |
|
| 265 | + $tables = array(); |
|
| 266 | + $tables_principales = $GLOBALS['tables_principales']; |
|
| 267 | + $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 268 | + $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 269 | + |
|
| 270 | + if (include_spip('base/objets') |
|
| 271 | + and function_exists('lister_tables_objets_sql') |
|
| 272 | + ) { |
|
| 273 | + $tables = lister_tables_objets_sql(); |
|
| 274 | + foreach ($tables as $t => $infos) { |
|
| 275 | + if ($infos['principale'] and !isset($tables_principales[$t])) { |
|
| 276 | + $tables_principales[$t] = true; |
|
| 277 | + } |
|
| 278 | + if (!$infos['principale'] and !isset($tables_auxiliaires[$t])) { |
|
| 279 | + $tables_auxiliaires[$t] = true; |
|
| 280 | + } |
|
| 281 | + if (count($infos['tables_jointures'])) { |
|
| 282 | + $tables_jointures[$t] = array_merge(isset($tables_jointures[$t]) ? $tables_jointures[$t] : array(), |
|
| 283 | + $infos['tables_jointures']); |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + // on construit un index des tables de liens |
|
| 289 | + // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 290 | + $tables_for_link = array(); |
|
| 291 | + foreach ($tables_jointures as $table => $liste_relations) { |
|
| 292 | + if (is_array($liste_relations)) { |
|
| 293 | + $nom = $table; |
|
| 294 | + if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 295 | + $nom = "spip_$table"; |
|
| 296 | + } |
|
| 297 | + if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 298 | + foreach ($liste_relations as $link_table) { |
|
| 299 | + if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 300 | + $tables_for_link[$link_table][] = $nom; |
|
| 301 | + } else { |
|
| 302 | + if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 303 | + $tables_for_link["spip_$link_table"][] = $nom; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + $liste_tables = array_merge(array_keys($tables_principales), array_keys($tables_auxiliaires), array_keys($tables)); |
|
| 312 | + foreach ($liste_tables as $table) { |
|
| 313 | + // $name = preg_replace("{^spip_}","",$table); |
|
| 314 | + if (!isset($tables_pointees[$table]) |
|
| 315 | + && !in_array($table, $exclude_tables) |
|
| 316 | + && !isset($tables_for_link[$table]) |
|
| 317 | + ) { |
|
| 318 | + $tables_for_dump[] = $table; |
|
| 319 | + $tables_pointees[$table] = 1; |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + foreach ($tables_for_link as $link_table => $liste) { |
|
| 323 | + $connecte = true; |
|
| 324 | + foreach ($liste as $connect_table) { |
|
| 325 | + if (!in_array($connect_table, $tables_for_dump)) { |
|
| 326 | + $connecte = false; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + if ($connecte) |
|
| 330 | + # on ajoute les liaisons en premier |
|
| 331 | + # si une restauration est interrompue, |
|
| 332 | + # cela se verra mieux si il manque des objets |
|
| 333 | + # que des liens |
|
| 334 | + { |
|
| 335 | + array_unshift($tables_for_dump, $link_table); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + return array($tables_for_dump, $tables_for_link); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -351,34 +351,34 @@ discard block |
||
| 351 | 351 | * @param string $serveur |
| 352 | 352 | */ |
| 353 | 353 | function base_vider_tables_destination_copie($tables, $exclure_tables = array(), $serveur = '') { |
| 354 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | - |
|
| 356 | - spip_log('Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables), |
|
| 357 | - 'base.' . _LOG_INFO_IMPORTANTE); |
|
| 358 | - foreach ($tables as $table) { |
|
| 359 | - if (!in_array($table, $exclure_tables)) { |
|
| 360 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 361 | - if (($table != 'spip_auteurs') or $serveur != '') { |
|
| 362 | - // regarder si il y a au moins un champ impt='non' |
|
| 363 | - $desc = $trouver_table($table, $serveur); |
|
| 364 | - if (isset($desc['field']['impt'])) { |
|
| 365 | - sql_delete($table, "impt='oui'", $serveur); |
|
| 366 | - } else { |
|
| 367 | - sql_delete($table, "", $serveur); |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 374 | - // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 375 | - if ($serveur == '' |
|
| 376 | - and in_array('spip_auteurs', $tables) |
|
| 377 | - and !in_array('spip_auteurs', $exclure_tables) |
|
| 378 | - ) { |
|
| 379 | - base_conserver_copieur(true, $serveur); |
|
| 380 | - sql_delete("spip_auteurs", "id_auteur>0", $serveur); |
|
| 381 | - } |
|
| 354 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | + |
|
| 356 | + spip_log('Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables), |
|
| 357 | + 'base.' . _LOG_INFO_IMPORTANTE); |
|
| 358 | + foreach ($tables as $table) { |
|
| 359 | + if (!in_array($table, $exclure_tables)) { |
|
| 360 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 361 | + if (($table != 'spip_auteurs') or $serveur != '') { |
|
| 362 | + // regarder si il y a au moins un champ impt='non' |
|
| 363 | + $desc = $trouver_table($table, $serveur); |
|
| 364 | + if (isset($desc['field']['impt'])) { |
|
| 365 | + sql_delete($table, "impt='oui'", $serveur); |
|
| 366 | + } else { |
|
| 367 | + sql_delete($table, "", $serveur); |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 374 | + // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 375 | + if ($serveur == '' |
|
| 376 | + and in_array('spip_auteurs', $tables) |
|
| 377 | + and !in_array('spip_auteurs', $exclure_tables) |
|
| 378 | + ) { |
|
| 379 | + base_conserver_copieur(true, $serveur); |
|
| 380 | + sql_delete("spip_auteurs", "id_auteur>0", $serveur); |
|
| 381 | + } |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
@@ -389,21 +389,21 @@ discard block |
||
| 389 | 389 | * @return void |
| 390 | 390 | */ |
| 391 | 391 | function base_conserver_copieur($move = true, $serveur = '') { |
| 392 | - // s'asurer qu'on a pas deja fait la manip ! |
|
| 393 | - if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel("spip_auteurs", "id_auteur>0")) { |
|
| 394 | - spip_log('Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 395 | - 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 396 | - sql_delete("spip_auteurs", "id_auteur<0", $serveur); |
|
| 397 | - if ($move) { |
|
| 398 | - sql_updateq('spip_auteurs', array('id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']), |
|
| 399 | - "id_auteur=" . intval($GLOBALS['visiteur_session']['id_auteur']), array(), $serveur); |
|
| 400 | - } else { |
|
| 401 | - $row = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], '', '', '', '', |
|
| 402 | - $serveur); |
|
| 403 | - $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 404 | - sql_insertq('spip_auteurs', $row, array(), $serveur); |
|
| 405 | - } |
|
| 406 | - } |
|
| 392 | + // s'asurer qu'on a pas deja fait la manip ! |
|
| 393 | + if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel("spip_auteurs", "id_auteur>0")) { |
|
| 394 | + spip_log('Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 395 | + 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 396 | + sql_delete("spip_auteurs", "id_auteur<0", $serveur); |
|
| 397 | + if ($move) { |
|
| 398 | + sql_updateq('spip_auteurs', array('id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']), |
|
| 399 | + "id_auteur=" . intval($GLOBALS['visiteur_session']['id_auteur']), array(), $serveur); |
|
| 400 | + } else { |
|
| 401 | + $row = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], '', '', '', '', |
|
| 402 | + $serveur); |
|
| 403 | + $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 404 | + sql_insertq('spip_auteurs', $row, array(), $serveur); |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -418,19 +418,19 @@ discard block |
||
| 418 | 418 | * @param string $serveur |
| 419 | 419 | */ |
| 420 | 420 | function base_detruire_copieur_si_besoin($serveur = '') { |
| 421 | - // rien a faire si ce n'est pas le serveur principal ! |
|
| 422 | - if ($serveur == '') { |
|
| 423 | - if (sql_countsel("spip_auteurs", "id_auteur>0")) { |
|
| 424 | - spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 425 | - sql_delete("spip_auteurs", "id_auteur<0", $serveur); |
|
| 426 | - } else { |
|
| 427 | - spip_log("Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 428 | - 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 429 | - sql_update('spip_auteurs', array('id_auteur' => '-id_auteur'), "id_auteur<0"); |
|
| 430 | - } |
|
| 431 | - } else { |
|
| 432 | - spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 433 | - } |
|
| 421 | + // rien a faire si ce n'est pas le serveur principal ! |
|
| 422 | + if ($serveur == '') { |
|
| 423 | + if (sql_countsel("spip_auteurs", "id_auteur>0")) { |
|
| 424 | + spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 425 | + sql_delete("spip_auteurs", "id_auteur<0", $serveur); |
|
| 426 | + } else { |
|
| 427 | + spip_log("Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 428 | + 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 429 | + sql_update('spip_auteurs', array('id_auteur' => '-id_auteur'), "id_auteur<0"); |
|
| 430 | + } |
|
| 431 | + } else { |
|
| 432 | + spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 433 | + } |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -445,40 +445,40 @@ discard block |
||
| 445 | 445 | * @return array |
| 446 | 446 | */ |
| 447 | 447 | function base_preparer_table_dest($table, $desc, $serveur_dest, $init = false) { |
| 448 | - $upgrade = false; |
|
| 449 | - // si la table existe et qu'on est a l'init, la dropper |
|
| 450 | - if ($desc_dest = sql_showtable($table, true, $serveur_dest) and $init) { |
|
| 451 | - if ($serveur_dest == '' and in_array($table, array('spip_meta', 'spip_auteurs'))) { |
|
| 452 | - // ne pas dropper auteurs et meta sur le serveur principal |
|
| 453 | - // faire un simple upgrade a la place |
|
| 454 | - // pour ajouter les champs manquants |
|
| 455 | - $upgrade = true; |
|
| 456 | - // coherence avec le drop sur les autres tables |
|
| 457 | - base_vider_tables_destination_copie(array($table), array(), $serveur_dest); |
|
| 458 | - if ($table == 'spip_meta') { |
|
| 459 | - // virer les version base qui vont venir avec l'import |
|
| 460 | - sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 461 | - // hum casse la base si pas version_installee a l'import ... |
|
| 462 | - sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 463 | - } |
|
| 464 | - } else { |
|
| 465 | - sql_drop_table($table, '', $serveur_dest); |
|
| 466 | - spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 467 | - } |
|
| 468 | - $desc_dest = false; |
|
| 469 | - } |
|
| 470 | - // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 471 | - if (!$desc_dest) { |
|
| 472 | - spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 473 | - include_spip('base/create'); |
|
| 474 | - creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 475 | - $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 476 | - } |
|
| 477 | - if (!$desc_dest) { |
|
| 478 | - spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - return $desc_dest; |
|
| 448 | + $upgrade = false; |
|
| 449 | + // si la table existe et qu'on est a l'init, la dropper |
|
| 450 | + if ($desc_dest = sql_showtable($table, true, $serveur_dest) and $init) { |
|
| 451 | + if ($serveur_dest == '' and in_array($table, array('spip_meta', 'spip_auteurs'))) { |
|
| 452 | + // ne pas dropper auteurs et meta sur le serveur principal |
|
| 453 | + // faire un simple upgrade a la place |
|
| 454 | + // pour ajouter les champs manquants |
|
| 455 | + $upgrade = true; |
|
| 456 | + // coherence avec le drop sur les autres tables |
|
| 457 | + base_vider_tables_destination_copie(array($table), array(), $serveur_dest); |
|
| 458 | + if ($table == 'spip_meta') { |
|
| 459 | + // virer les version base qui vont venir avec l'import |
|
| 460 | + sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 461 | + // hum casse la base si pas version_installee a l'import ... |
|
| 462 | + sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 463 | + } |
|
| 464 | + } else { |
|
| 465 | + sql_drop_table($table, '', $serveur_dest); |
|
| 466 | + spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 467 | + } |
|
| 468 | + $desc_dest = false; |
|
| 469 | + } |
|
| 470 | + // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 471 | + if (!$desc_dest) { |
|
| 472 | + spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 473 | + include_spip('base/create'); |
|
| 474 | + creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 475 | + $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 476 | + } |
|
| 477 | + if (!$desc_dest) { |
|
| 478 | + spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + return $desc_dest; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | /** |
@@ -524,186 +524,186 @@ discard block |
||
| 524 | 524 | */ |
| 525 | 525 | function base_copier_tables($status_file, $tables, $serveur_source, $serveur_dest, $options = array()) { |
| 526 | 526 | |
| 527 | - $callback_progression = isset($options['callback_progression']) ? $options['callback_progression'] : ''; |
|
| 528 | - $max_time = isset($options['max_time']) ? $options['max_time'] : 0; |
|
| 529 | - $drop_source = isset($options['drop_source']) ? $options['drop_source'] : false; |
|
| 530 | - $no_erase_dest = isset($options['no_erase_dest']) ? $options['no_erase_dest'] : array(); |
|
| 531 | - $where = isset($options['where']) ? $options['where'] : array(); |
|
| 532 | - $fonction_base_inserer = isset($options['fonction_base_inserer']) ? $options['fonction_base_inserer'] : 'inserer_copie'; |
|
| 533 | - $desc_tables_dest = isset($options['desc_tables_dest']) ? $options['desc_tables_dest'] : array(); |
|
| 534 | - $racine_fonctions = (isset($options['racine_fonctions_dest']) ? $options['racine_fonctions_dest'] : 'base'); |
|
| 535 | - $data_pool = (isset($options['data_pool']) ? $options['data_pool'] : 50 * 1024); |
|
| 536 | - |
|
| 537 | - spip_log("Copier " . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 538 | - 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 539 | - |
|
| 540 | - if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 541 | - spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 542 | - |
|
| 543 | - return true; // echec mais on a fini, donc true |
|
| 544 | - } |
|
| 545 | - if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 546 | - spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 547 | - |
|
| 548 | - return true; // echec mais on a fini, donc true |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - if (!lire_fichier($status_file, $status) |
|
| 552 | - or !$status = unserialize($status) |
|
| 553 | - ) { |
|
| 554 | - $status = array(); |
|
| 555 | - } |
|
| 556 | - $status['etape'] = 'basecopie'; |
|
| 557 | - |
|
| 558 | - // puis relister les tables a importer |
|
| 559 | - // et les vider si besoin, au moment du premier passage ici |
|
| 560 | - $initialisation_copie = (!isset($status["dump_status_copie"])) ? 0 : $status["dump_status_copie"]; |
|
| 561 | - |
|
| 562 | - // si init pas encore faite, vider les tables du serveur destination |
|
| 563 | - if (!$initialisation_copie) { |
|
| 564 | - if (!$vider_tables_destination_copie = charger_fonction('vider_tables_destination_copie', $racine_fonctions, |
|
| 565 | - true) |
|
| 566 | - ) { |
|
| 567 | - spip_log("Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 568 | - 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 569 | - |
|
| 570 | - return true; // echec mais on a fini, donc true |
|
| 571 | - } |
|
| 572 | - $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 573 | - $status["dump_status_copie"] = 'ok'; |
|
| 574 | - ecrire_fichier($status_file, serialize($status)); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 578 | - if (in_array('spip_auteurs', $tables)) { |
|
| 579 | - $tables = array_diff($tables, array('spip_auteurs')); |
|
| 580 | - $tables[] = 'spip_auteurs'; |
|
| 581 | - } |
|
| 582 | - if (in_array('spip_meta', $tables)) { |
|
| 583 | - $tables = array_diff($tables, array('spip_meta')); |
|
| 584 | - $tables[] = 'spip_meta'; |
|
| 585 | - } |
|
| 586 | - spip_log("Tables a copier :" . implode(", ", $tables), 'dump.' . _LOG_INFO); |
|
| 587 | - |
|
| 588 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 589 | - |
|
| 590 | - foreach ($tables as $table) { |
|
| 591 | - // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 592 | - // sinon chercher la vraie table |
|
| 593 | - $desc_source = false; |
|
| 594 | - if (strncmp($table, "spip_", 5) == 0) { |
|
| 595 | - $desc_source = $trouver_table(preg_replace(",^spip_,", "", $table), $serveur_source, true); |
|
| 596 | - } |
|
| 597 | - if (!$desc_source or !isset($desc_source['exist']) or !$desc_source['exist']) { |
|
| 598 | - $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - // verifier que la table est presente dans la base source |
|
| 602 | - if ($desc_source) { |
|
| 603 | - // $status['tables_copiees'][$table] contient l'avancement |
|
| 604 | - // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 605 | - if (!isset($status['tables_copiees'][$table])) { |
|
| 606 | - $status['tables_copiees'][$table] = 0; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - if (is_numeric($status['tables_copiees'][$table]) |
|
| 610 | - and $status['tables_copiees'][$table] >= 0 |
|
| 611 | - and $desc_dest = $preparer_table_dest( |
|
| 612 | - $table, |
|
| 613 | - isset($desc_tables_dest[$table]) ? $desc_tables_dest[$table] : $desc_source, |
|
| 614 | - $serveur_dest, |
|
| 615 | - $status['tables_copiees'][$table] == 0) |
|
| 616 | - ) { |
|
| 617 | - if ($callback_progression) { |
|
| 618 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 619 | - } |
|
| 620 | - while (true) { |
|
| 621 | - $n = intval($status['tables_copiees'][$table]); |
|
| 622 | - // on copie par lot de 400 |
|
| 623 | - $res = sql_select('*', $table, isset($where[$table]) ? $where[$table] : '', '', '', "$n,400", '', |
|
| 624 | - $serveur_source); |
|
| 625 | - while ($row = sql_fetch($res, $serveur_source)) { |
|
| 626 | - $rows = array($row); |
|
| 627 | - // lire un groupe de donnees si demande en option |
|
| 628 | - // (permet un envoi par lot vers la destination) |
|
| 629 | - if ($data_pool > 0) { |
|
| 630 | - $s = strlen(serialize($row)); |
|
| 631 | - while ($s < $data_pool and $row = sql_fetch($res, $serveur_source)) { |
|
| 632 | - $s += strlen(serialize($row)); |
|
| 633 | - $rows[] = $row; |
|
| 634 | - } |
|
| 635 | - } |
|
| 636 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 637 | - // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 638 | - if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 639 | - // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 640 | - spip_log("Erreur fatale dans $inserer_copie table $table", "dump" . _LOG_ERREUR); |
|
| 641 | - $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 642 | - ecrire_fichier($status_file, serialize($status)); |
|
| 643 | - |
|
| 644 | - // copie finie |
|
| 645 | - return true; |
|
| 646 | - } |
|
| 647 | - $status['tables_copiees'][$table] += count($rows); |
|
| 648 | - if ($max_time and time() > $max_time) { |
|
| 649 | - break; |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - if ($n == $status['tables_copiees'][$table]) { |
|
| 653 | - break; |
|
| 654 | - } |
|
| 655 | - spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 656 | - if ($callback_progression) { |
|
| 657 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 658 | - } |
|
| 659 | - ecrire_fichier($status_file, serialize($status)); |
|
| 660 | - if ($max_time and time() > $max_time) { |
|
| 661 | - return false; |
|
| 662 | - } // on a pas fini, mais le temps imparti est ecoule |
|
| 663 | - } |
|
| 664 | - if ($drop_source) { |
|
| 665 | - sql_drop_table($table, '', $serveur_source); |
|
| 666 | - spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 667 | - } |
|
| 668 | - $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : "zero"); |
|
| 669 | - ecrire_fichier($status_file, serialize($status)); |
|
| 670 | - spip_log("tables_recopiees " . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 671 | - if ($callback_progression) { |
|
| 672 | - $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 673 | - } |
|
| 674 | - } else { |
|
| 675 | - if ($status['tables_copiees'][$table] < 0) { |
|
| 676 | - spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], "dump." . _LOG_INFO); |
|
| 677 | - } |
|
| 678 | - if ($callback_progression) { |
|
| 679 | - $callback_progression(0, $status['tables_copiees'][$table], |
|
| 680 | - "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? "[Echec]" : "")); |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - } else { |
|
| 684 | - $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 685 | - ecrire_fichier($status_file, serialize($status)); |
|
| 686 | - spip_log("Impossible de lire la description de la table $table", "dump." . _LOG_ERREUR); |
|
| 687 | - } |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 691 | - // abandonner |
|
| 692 | - if (count($status['tables_copiees']) < count($tables)) { |
|
| 693 | - spip_log("Nombre de tables copiees incorrect : " . count($status['tables_copiees']) . "/" . count($tables), |
|
| 694 | - "dump." . _LOG_ERREUR); |
|
| 695 | - $status['errors'][] = "Nombre de tables copiees incorrect : " . count($status['tables_copiees']) . "/" . count($tables); |
|
| 696 | - ecrire_fichier($status_file, serialize($status)); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 700 | - $detruire_copieur_si_besoin($serveur_dest); |
|
| 701 | - } else { |
|
| 702 | - spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - // OK, copie complete |
|
| 706 | - return true; |
|
| 527 | + $callback_progression = isset($options['callback_progression']) ? $options['callback_progression'] : ''; |
|
| 528 | + $max_time = isset($options['max_time']) ? $options['max_time'] : 0; |
|
| 529 | + $drop_source = isset($options['drop_source']) ? $options['drop_source'] : false; |
|
| 530 | + $no_erase_dest = isset($options['no_erase_dest']) ? $options['no_erase_dest'] : array(); |
|
| 531 | + $where = isset($options['where']) ? $options['where'] : array(); |
|
| 532 | + $fonction_base_inserer = isset($options['fonction_base_inserer']) ? $options['fonction_base_inserer'] : 'inserer_copie'; |
|
| 533 | + $desc_tables_dest = isset($options['desc_tables_dest']) ? $options['desc_tables_dest'] : array(); |
|
| 534 | + $racine_fonctions = (isset($options['racine_fonctions_dest']) ? $options['racine_fonctions_dest'] : 'base'); |
|
| 535 | + $data_pool = (isset($options['data_pool']) ? $options['data_pool'] : 50 * 1024); |
|
| 536 | + |
|
| 537 | + spip_log("Copier " . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 538 | + 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 539 | + |
|
| 540 | + if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 541 | + spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 542 | + |
|
| 543 | + return true; // echec mais on a fini, donc true |
|
| 544 | + } |
|
| 545 | + if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 546 | + spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 547 | + |
|
| 548 | + return true; // echec mais on a fini, donc true |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + if (!lire_fichier($status_file, $status) |
|
| 552 | + or !$status = unserialize($status) |
|
| 553 | + ) { |
|
| 554 | + $status = array(); |
|
| 555 | + } |
|
| 556 | + $status['etape'] = 'basecopie'; |
|
| 557 | + |
|
| 558 | + // puis relister les tables a importer |
|
| 559 | + // et les vider si besoin, au moment du premier passage ici |
|
| 560 | + $initialisation_copie = (!isset($status["dump_status_copie"])) ? 0 : $status["dump_status_copie"]; |
|
| 561 | + |
|
| 562 | + // si init pas encore faite, vider les tables du serveur destination |
|
| 563 | + if (!$initialisation_copie) { |
|
| 564 | + if (!$vider_tables_destination_copie = charger_fonction('vider_tables_destination_copie', $racine_fonctions, |
|
| 565 | + true) |
|
| 566 | + ) { |
|
| 567 | + spip_log("Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 568 | + 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 569 | + |
|
| 570 | + return true; // echec mais on a fini, donc true |
|
| 571 | + } |
|
| 572 | + $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 573 | + $status["dump_status_copie"] = 'ok'; |
|
| 574 | + ecrire_fichier($status_file, serialize($status)); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 578 | + if (in_array('spip_auteurs', $tables)) { |
|
| 579 | + $tables = array_diff($tables, array('spip_auteurs')); |
|
| 580 | + $tables[] = 'spip_auteurs'; |
|
| 581 | + } |
|
| 582 | + if (in_array('spip_meta', $tables)) { |
|
| 583 | + $tables = array_diff($tables, array('spip_meta')); |
|
| 584 | + $tables[] = 'spip_meta'; |
|
| 585 | + } |
|
| 586 | + spip_log("Tables a copier :" . implode(", ", $tables), 'dump.' . _LOG_INFO); |
|
| 587 | + |
|
| 588 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 589 | + |
|
| 590 | + foreach ($tables as $table) { |
|
| 591 | + // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 592 | + // sinon chercher la vraie table |
|
| 593 | + $desc_source = false; |
|
| 594 | + if (strncmp($table, "spip_", 5) == 0) { |
|
| 595 | + $desc_source = $trouver_table(preg_replace(",^spip_,", "", $table), $serveur_source, true); |
|
| 596 | + } |
|
| 597 | + if (!$desc_source or !isset($desc_source['exist']) or !$desc_source['exist']) { |
|
| 598 | + $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + // verifier que la table est presente dans la base source |
|
| 602 | + if ($desc_source) { |
|
| 603 | + // $status['tables_copiees'][$table] contient l'avancement |
|
| 604 | + // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 605 | + if (!isset($status['tables_copiees'][$table])) { |
|
| 606 | + $status['tables_copiees'][$table] = 0; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + if (is_numeric($status['tables_copiees'][$table]) |
|
| 610 | + and $status['tables_copiees'][$table] >= 0 |
|
| 611 | + and $desc_dest = $preparer_table_dest( |
|
| 612 | + $table, |
|
| 613 | + isset($desc_tables_dest[$table]) ? $desc_tables_dest[$table] : $desc_source, |
|
| 614 | + $serveur_dest, |
|
| 615 | + $status['tables_copiees'][$table] == 0) |
|
| 616 | + ) { |
|
| 617 | + if ($callback_progression) { |
|
| 618 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 619 | + } |
|
| 620 | + while (true) { |
|
| 621 | + $n = intval($status['tables_copiees'][$table]); |
|
| 622 | + // on copie par lot de 400 |
|
| 623 | + $res = sql_select('*', $table, isset($where[$table]) ? $where[$table] : '', '', '', "$n,400", '', |
|
| 624 | + $serveur_source); |
|
| 625 | + while ($row = sql_fetch($res, $serveur_source)) { |
|
| 626 | + $rows = array($row); |
|
| 627 | + // lire un groupe de donnees si demande en option |
|
| 628 | + // (permet un envoi par lot vers la destination) |
|
| 629 | + if ($data_pool > 0) { |
|
| 630 | + $s = strlen(serialize($row)); |
|
| 631 | + while ($s < $data_pool and $row = sql_fetch($res, $serveur_source)) { |
|
| 632 | + $s += strlen(serialize($row)); |
|
| 633 | + $rows[] = $row; |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 637 | + // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 638 | + if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 639 | + // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 640 | + spip_log("Erreur fatale dans $inserer_copie table $table", "dump" . _LOG_ERREUR); |
|
| 641 | + $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 642 | + ecrire_fichier($status_file, serialize($status)); |
|
| 643 | + |
|
| 644 | + // copie finie |
|
| 645 | + return true; |
|
| 646 | + } |
|
| 647 | + $status['tables_copiees'][$table] += count($rows); |
|
| 648 | + if ($max_time and time() > $max_time) { |
|
| 649 | + break; |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + if ($n == $status['tables_copiees'][$table]) { |
|
| 653 | + break; |
|
| 654 | + } |
|
| 655 | + spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 656 | + if ($callback_progression) { |
|
| 657 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 658 | + } |
|
| 659 | + ecrire_fichier($status_file, serialize($status)); |
|
| 660 | + if ($max_time and time() > $max_time) { |
|
| 661 | + return false; |
|
| 662 | + } // on a pas fini, mais le temps imparti est ecoule |
|
| 663 | + } |
|
| 664 | + if ($drop_source) { |
|
| 665 | + sql_drop_table($table, '', $serveur_source); |
|
| 666 | + spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 667 | + } |
|
| 668 | + $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : "zero"); |
|
| 669 | + ecrire_fichier($status_file, serialize($status)); |
|
| 670 | + spip_log("tables_recopiees " . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 671 | + if ($callback_progression) { |
|
| 672 | + $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 673 | + } |
|
| 674 | + } else { |
|
| 675 | + if ($status['tables_copiees'][$table] < 0) { |
|
| 676 | + spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], "dump." . _LOG_INFO); |
|
| 677 | + } |
|
| 678 | + if ($callback_progression) { |
|
| 679 | + $callback_progression(0, $status['tables_copiees'][$table], |
|
| 680 | + "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? "[Echec]" : "")); |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + } else { |
|
| 684 | + $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 685 | + ecrire_fichier($status_file, serialize($status)); |
|
| 686 | + spip_log("Impossible de lire la description de la table $table", "dump." . _LOG_ERREUR); |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 691 | + // abandonner |
|
| 692 | + if (count($status['tables_copiees']) < count($tables)) { |
|
| 693 | + spip_log("Nombre de tables copiees incorrect : " . count($status['tables_copiees']) . "/" . count($tables), |
|
| 694 | + "dump." . _LOG_ERREUR); |
|
| 695 | + $status['errors'][] = "Nombre de tables copiees incorrect : " . count($status['tables_copiees']) . "/" . count($tables); |
|
| 696 | + ecrire_fichier($status_file, serialize($status)); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 700 | + $detruire_copieur_si_besoin($serveur_dest); |
|
| 701 | + } else { |
|
| 702 | + spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + // OK, copie complete |
|
| 706 | + return true; |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
@@ -717,27 +717,27 @@ discard block |
||
| 717 | 717 | */ |
| 718 | 718 | function base_inserer_copie($table, $rows, $desc_dest, $serveur_dest) { |
| 719 | 719 | |
| 720 | - // verifier le nombre d'insertion |
|
| 721 | - $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 722 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 723 | - $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 724 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 725 | - if ($nb - $nb1 < count($rows)) { |
|
| 726 | - spip_log("base_inserer_copie : " . ($nb - $nb1) . " insertions au lieu de " . count($rows) . ". On retente 1 par 1", |
|
| 727 | - "dump" . _LOG_INFO_IMPORTANTE); |
|
| 728 | - foreach ($rows as $row) { |
|
| 729 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 730 | - $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 731 | - } |
|
| 732 | - // on reverifie le total |
|
| 733 | - $r = 0; |
|
| 734 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 735 | - if ($nb - $nb1 < count($rows)) { |
|
| 736 | - spip_log("base_inserer_copie : " . ($nb - $nb1) . " insertions au lieu de " . count($rows) . " apres insertion 1 par 1", |
|
| 737 | - "dump" . _LOG_ERREUR); |
|
| 738 | - $r = false; |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - return $r; |
|
| 720 | + // verifier le nombre d'insertion |
|
| 721 | + $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 722 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 723 | + $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 724 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 725 | + if ($nb - $nb1 < count($rows)) { |
|
| 726 | + spip_log("base_inserer_copie : " . ($nb - $nb1) . " insertions au lieu de " . count($rows) . ". On retente 1 par 1", |
|
| 727 | + "dump" . _LOG_INFO_IMPORTANTE); |
|
| 728 | + foreach ($rows as $row) { |
|
| 729 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 730 | + $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 731 | + } |
|
| 732 | + // on reverifie le total |
|
| 733 | + $r = 0; |
|
| 734 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 735 | + if ($nb - $nb1 < count($rows)) { |
|
| 736 | + spip_log("base_inserer_copie : " . ($nb - $nb1) . " insertions au lieu de " . count($rows) . " apres insertion 1 par 1", |
|
| 737 | + "dump" . _LOG_ERREUR); |
|
| 738 | + $r = false; |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + return $r; |
|
| 743 | 743 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | // donc il faut l'inclure "en globals" |
| 31 | 31 | if ($f = find_in_path('mes_fonctions.php')) { |
| 32 | 32 | global $dossier_squelettes; |
| 33 | - @include_once(_ROOT_CWD . $f); |
|
| 33 | + @include_once(_ROOT_CWD.$f); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | if (@is_readable(_CACHE_PLUGINS_FCT)) { |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @return string |
| 49 | 49 | **/ |
| 50 | 50 | function base_dump_meta_name($rub) { |
| 51 | - return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 51 | + return $meta = "status_dump_{$rub}_".abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
| 95 | 95 | $prefixe = $connexion['prefixe']; |
| 96 | 96 | |
| 97 | - $p = '/^' . $prefixe . '/'; |
|
| 97 | + $p = '/^'.$prefixe.'/'; |
|
| 98 | 98 | $res = $tables; |
| 99 | 99 | foreach (sql_alltable(null, $serveur) as $t) { |
| 100 | 100 | if (preg_match($p, $t)) { |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | function base_vider_tables_destination_copie($tables, $exclure_tables = array(), $serveur = '') { |
| 354 | 354 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 355 | 355 | |
| 356 | - spip_log('Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables), |
|
| 357 | - 'base.' . _LOG_INFO_IMPORTANTE); |
|
| 356 | + spip_log('Vider '.count($tables)." tables sur serveur '$serveur' : ".join(', ', $tables), |
|
| 357 | + 'base.'._LOG_INFO_IMPORTANTE); |
|
| 358 | 358 | foreach ($tables as $table) { |
| 359 | 359 | if (!in_array($table, $exclure_tables)) { |
| 360 | 360 | // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
@@ -391,14 +391,14 @@ discard block |
||
| 391 | 391 | function base_conserver_copieur($move = true, $serveur = '') { |
| 392 | 392 | // s'asurer qu'on a pas deja fait la manip ! |
| 393 | 393 | if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel("spip_auteurs", "id_auteur>0")) { |
| 394 | - spip_log('Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 395 | - 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 394 | + spip_log('Conserver copieur dans id_auteur='.$GLOBALS['visiteur_session']['id_auteur']." pour le serveur '$serveur'", |
|
| 395 | + 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 396 | 396 | sql_delete("spip_auteurs", "id_auteur<0", $serveur); |
| 397 | 397 | if ($move) { |
| 398 | 398 | sql_updateq('spip_auteurs', array('id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']), |
| 399 | - "id_auteur=" . intval($GLOBALS['visiteur_session']['id_auteur']), array(), $serveur); |
|
| 399 | + "id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur']), array(), $serveur); |
|
| 400 | 400 | } else { |
| 401 | - $row = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], '', '', '', '', |
|
| 401 | + $row = sql_fetsel('*', 'spip_auteurs', 'id_auteur='.$GLOBALS['visiteur_session']['id_auteur'], '', '', '', '', |
|
| 402 | 402 | $serveur); |
| 403 | 403 | $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
| 404 | 404 | sql_insertq('spip_auteurs', $row, array(), $serveur); |
@@ -421,15 +421,15 @@ discard block |
||
| 421 | 421 | // rien a faire si ce n'est pas le serveur principal ! |
| 422 | 422 | if ($serveur == '') { |
| 423 | 423 | if (sql_countsel("spip_auteurs", "id_auteur>0")) { |
| 424 | - spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 424 | + spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 425 | 425 | sql_delete("spip_auteurs", "id_auteur<0", $serveur); |
| 426 | 426 | } else { |
| 427 | 427 | spip_log("Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
| 428 | - 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 428 | + 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 429 | 429 | sql_update('spip_auteurs', array('id_auteur' => '-id_auteur'), "id_auteur<0"); |
| 430 | 430 | } |
| 431 | 431 | } else { |
| 432 | - spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 432 | + spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | |
@@ -463,19 +463,19 @@ discard block |
||
| 463 | 463 | } |
| 464 | 464 | } else { |
| 465 | 465 | sql_drop_table($table, '', $serveur_dest); |
| 466 | - spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 466 | + spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 467 | 467 | } |
| 468 | 468 | $desc_dest = false; |
| 469 | 469 | } |
| 470 | 470 | // si la table n'existe pas dans la destination, la creer a l'identique ! |
| 471 | 471 | if (!$desc_dest) { |
| 472 | - spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 472 | + spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 473 | 473 | include_spip('base/create'); |
| 474 | 474 | creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
| 475 | 475 | $desc_dest = sql_showtable($table, true, $serveur_dest); |
| 476 | 476 | } |
| 477 | 477 | if (!$desc_dest) { |
| 478 | - spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 478 | + spip_log("Erreur creation '$table' sur serveur '$serveur_dest'".var_export($desc, 1), 'dump.'._LOG_ERREUR); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | return $desc_dest; |
@@ -534,16 +534,16 @@ discard block |
||
| 534 | 534 | $racine_fonctions = (isset($options['racine_fonctions_dest']) ? $options['racine_fonctions_dest'] : 'base'); |
| 535 | 535 | $data_pool = (isset($options['data_pool']) ? $options['data_pool'] : 50 * 1024); |
| 536 | 536 | |
| 537 | - spip_log("Copier " . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 538 | - 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 537 | + spip_log("Copier ".count($tables)." tables de '$serveur_source' vers '$serveur_dest'", |
|
| 538 | + 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 539 | 539 | |
| 540 | 540 | if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
| 541 | - spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 541 | + spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 542 | 542 | |
| 543 | 543 | return true; // echec mais on a fini, donc true |
| 544 | 544 | } |
| 545 | 545 | if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
| 546 | - spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 546 | + spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 547 | 547 | |
| 548 | 548 | return true; // echec mais on a fini, donc true |
| 549 | 549 | } |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | true) |
| 566 | 566 | ) { |
| 567 | 567 | spip_log("Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
| 568 | - 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 568 | + 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 569 | 569 | |
| 570 | 570 | return true; // echec mais on a fini, donc true |
| 571 | 571 | } |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | $tables = array_diff($tables, array('spip_meta')); |
| 584 | 584 | $tables[] = 'spip_meta'; |
| 585 | 585 | } |
| 586 | - spip_log("Tables a copier :" . implode(", ", $tables), 'dump.' . _LOG_INFO); |
|
| 586 | + spip_log("Tables a copier :".implode(", ", $tables), 'dump.'._LOG_INFO); |
|
| 587 | 587 | |
| 588 | 588 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 589 | 589 | |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | // mais si ca renvoie false c'est une erreur fatale => abandon |
| 638 | 638 | if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
| 639 | 639 | // forcer la sortie, charge a l'appelant de gerer l'echec |
| 640 | - spip_log("Erreur fatale dans $inserer_copie table $table", "dump" . _LOG_ERREUR); |
|
| 640 | + spip_log("Erreur fatale dans $inserer_copie table $table", "dump"._LOG_ERREUR); |
|
| 641 | 641 | $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
| 642 | 642 | ecrire_fichier($status_file, serialize($status)); |
| 643 | 643 | |
@@ -652,7 +652,7 @@ discard block |
||
| 652 | 652 | if ($n == $status['tables_copiees'][$table]) { |
| 653 | 653 | break; |
| 654 | 654 | } |
| 655 | - spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 655 | + spip_log("recopie $table ".$status['tables_copiees'][$table], 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 656 | 656 | if ($callback_progression) { |
| 657 | 657 | $callback_progression($status['tables_copiees'][$table], 0, $table); |
| 658 | 658 | } |
@@ -663,43 +663,43 @@ discard block |
||
| 663 | 663 | } |
| 664 | 664 | if ($drop_source) { |
| 665 | 665 | sql_drop_table($table, '', $serveur_source); |
| 666 | - spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 666 | + spip_log("drop $table sur serveur source '$serveur_source'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 667 | 667 | } |
| 668 | 668 | $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : "zero"); |
| 669 | 669 | ecrire_fichier($status_file, serialize($status)); |
| 670 | - spip_log("tables_recopiees " . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 670 | + spip_log("tables_recopiees ".implode(',', array_keys($status['tables_copiees'])), 'dump.'._LOG_INFO); |
|
| 671 | 671 | if ($callback_progression) { |
| 672 | 672 | $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
| 673 | 673 | } |
| 674 | 674 | } else { |
| 675 | 675 | if ($status['tables_copiees'][$table] < 0) { |
| 676 | - spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], "dump." . _LOG_INFO); |
|
| 676 | + spip_log("Table $table deja copiee : ".$status['tables_copiees'][$table], "dump."._LOG_INFO); |
|
| 677 | 677 | } |
| 678 | 678 | if ($callback_progression) { |
| 679 | 679 | $callback_progression(0, $status['tables_copiees'][$table], |
| 680 | - "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? "[Echec]" : "")); |
|
| 680 | + "$table".((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? "[Echec]" : "")); |
|
| 681 | 681 | } |
| 682 | 682 | } |
| 683 | 683 | } else { |
| 684 | 684 | $status['errors'][] = "Impossible de lire la description de la table $table"; |
| 685 | 685 | ecrire_fichier($status_file, serialize($status)); |
| 686 | - spip_log("Impossible de lire la description de la table $table", "dump." . _LOG_ERREUR); |
|
| 686 | + spip_log("Impossible de lire la description de la table $table", "dump."._LOG_ERREUR); |
|
| 687 | 687 | } |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
| 691 | 691 | // abandonner |
| 692 | 692 | if (count($status['tables_copiees']) < count($tables)) { |
| 693 | - spip_log("Nombre de tables copiees incorrect : " . count($status['tables_copiees']) . "/" . count($tables), |
|
| 694 | - "dump." . _LOG_ERREUR); |
|
| 695 | - $status['errors'][] = "Nombre de tables copiees incorrect : " . count($status['tables_copiees']) . "/" . count($tables); |
|
| 693 | + spip_log("Nombre de tables copiees incorrect : ".count($status['tables_copiees'])."/".count($tables), |
|
| 694 | + "dump."._LOG_ERREUR); |
|
| 695 | + $status['errors'][] = "Nombre de tables copiees incorrect : ".count($status['tables_copiees'])."/".count($tables); |
|
| 696 | 696 | ecrire_fichier($status_file, serialize($status)); |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
| 700 | 700 | $detruire_copieur_si_besoin($serveur_dest); |
| 701 | 701 | } else { |
| 702 | - spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 702 | + spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | // OK, copie complete |
@@ -723,8 +723,8 @@ discard block |
||
| 723 | 723 | $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
| 724 | 724 | $nb = sql_countsel($table, '', '', '', $serveur_dest); |
| 725 | 725 | if ($nb - $nb1 < count($rows)) { |
| 726 | - spip_log("base_inserer_copie : " . ($nb - $nb1) . " insertions au lieu de " . count($rows) . ". On retente 1 par 1", |
|
| 727 | - "dump" . _LOG_INFO_IMPORTANTE); |
|
| 726 | + spip_log("base_inserer_copie : ".($nb - $nb1)." insertions au lieu de ".count($rows).". On retente 1 par 1", |
|
| 727 | + "dump"._LOG_INFO_IMPORTANTE); |
|
| 728 | 728 | foreach ($rows as $row) { |
| 729 | 729 | // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
| 730 | 730 | $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
@@ -733,8 +733,8 @@ discard block |
||
| 733 | 733 | $r = 0; |
| 734 | 734 | $nb = sql_countsel($table, '', '', '', $serveur_dest); |
| 735 | 735 | if ($nb - $nb1 < count($rows)) { |
| 736 | - spip_log("base_inserer_copie : " . ($nb - $nb1) . " insertions au lieu de " . count($rows) . " apres insertion 1 par 1", |
|
| 737 | - "dump" . _LOG_ERREUR); |
|
| 736 | + spip_log("base_inserer_copie : ".($nb - $nb1)." insertions au lieu de ".count($rows)." apres insertion 1 par 1", |
|
| 737 | + "dump"._LOG_ERREUR); |
|
| 738 | 738 | $r = false; |
| 739 | 739 | } |
| 740 | 740 | } |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | * Chemin sur lequel le cookie sera disponible |
| 36 | 36 | * @param string $domain |
| 37 | 37 | * Domaine à partir duquel le cookie est disponible |
| 38 | - * @param bool $secure |
|
| 38 | + * @param string|boolean $secure |
|
| 39 | 39 | * cookie sécurisé ou non ? |
| 40 | 40 | * @return bool |
| 41 | 41 | * true si le cookie a été posé, false sinon. |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -43,37 +43,37 @@ discard block |
||
| 43 | 43 | * true si le cookie a été posé, false sinon. |
| 44 | 44 | **/ |
| 45 | 45 | function spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') { |
| 46 | - // liste des cookies en httponly (a passer en define si besoin) |
|
| 47 | - $httponly = in_array($name, explode(' ', 'spip_session')); |
|
| 48 | - |
|
| 49 | - $name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'] . '_', $name); |
|
| 50 | - if ($path == 'AUTO') { |
|
| 51 | - $path = defined('_COOKIE_PATH') ? _COOKIE_PATH : preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 52 | - } |
|
| 53 | - if (!$domain and defined('_COOKIE_DOMAIN')) { |
|
| 54 | - $domain = _COOKIE_DOMAIN; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - #spip_log("cookie('$name', '$value', '$expire', '$path', '$domain', '$secure', '$httponly'"); |
|
| 58 | - |
|
| 59 | - $a = |
|
| 60 | - $httponly ? |
|
| 61 | - @setcookie($name, $value, $expire, $path, $domain, $secure, $httponly) |
|
| 62 | - : ($secure ? |
|
| 63 | - @setcookie($name, $value, $expire, $path, $domain, $secure) |
|
| 64 | - : ($domain ? |
|
| 65 | - @setcookie($name, $value, $expire, $path, $domain) |
|
| 66 | - : ($path ? |
|
| 67 | - @setcookie($name, $value, $expire, $path) |
|
| 68 | - : ($expire ? |
|
| 69 | - @setcookie($name, $value, $expire) |
|
| 70 | - : |
|
| 71 | - @setcookie($name, $value) |
|
| 72 | - )))); |
|
| 73 | - |
|
| 74 | - spip_cookie_envoye(true); |
|
| 75 | - |
|
| 76 | - return $a; |
|
| 46 | + // liste des cookies en httponly (a passer en define si besoin) |
|
| 47 | + $httponly = in_array($name, explode(' ', 'spip_session')); |
|
| 48 | + |
|
| 49 | + $name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'] . '_', $name); |
|
| 50 | + if ($path == 'AUTO') { |
|
| 51 | + $path = defined('_COOKIE_PATH') ? _COOKIE_PATH : preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 52 | + } |
|
| 53 | + if (!$domain and defined('_COOKIE_DOMAIN')) { |
|
| 54 | + $domain = _COOKIE_DOMAIN; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + #spip_log("cookie('$name', '$value', '$expire', '$path', '$domain', '$secure', '$httponly'"); |
|
| 58 | + |
|
| 59 | + $a = |
|
| 60 | + $httponly ? |
|
| 61 | + @setcookie($name, $value, $expire, $path, $domain, $secure, $httponly) |
|
| 62 | + : ($secure ? |
|
| 63 | + @setcookie($name, $value, $expire, $path, $domain, $secure) |
|
| 64 | + : ($domain ? |
|
| 65 | + @setcookie($name, $value, $expire, $path, $domain) |
|
| 66 | + : ($path ? |
|
| 67 | + @setcookie($name, $value, $expire, $path) |
|
| 68 | + : ($expire ? |
|
| 69 | + @setcookie($name, $value, $expire) |
|
| 70 | + : |
|
| 71 | + @setcookie($name, $value) |
|
| 72 | + )))); |
|
| 73 | + |
|
| 74 | + spip_cookie_envoye(true); |
|
| 75 | + |
|
| 76 | + return $a; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | * @return bool |
| 90 | 90 | **/ |
| 91 | 91 | function spip_cookie_envoye($set = '') { |
| 92 | - static $envoye = false; |
|
| 93 | - if ($set) { |
|
| 94 | - $envoye = true; |
|
| 95 | - } |
|
| 92 | + static $envoye = false; |
|
| 93 | + if ($set) { |
|
| 94 | + $envoye = true; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return $envoye; |
|
| 97 | + return $envoye; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -113,21 +113,21 @@ discard block |
||
| 113 | 113 | * Préfixe des cookies de SPIP |
| 114 | 114 | **/ |
| 115 | 115 | function recuperer_cookies_spip($cookie_prefix) { |
| 116 | - $prefix_long = strlen($cookie_prefix); |
|
| 117 | - |
|
| 118 | - foreach ($_COOKIE as $name => $value) { |
|
| 119 | - if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 120 | - unset($_COOKIE[$name]); |
|
| 121 | - unset($GLOBALS[$name]); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - foreach ($_COOKIE as $name => $value) { |
|
| 125 | - if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 126 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 127 | - $_COOKIE[$spipname] = $value; |
|
| 128 | - $GLOBALS[$spipname] = $value; |
|
| 129 | - } |
|
| 130 | - } |
|
| 116 | + $prefix_long = strlen($cookie_prefix); |
|
| 117 | + |
|
| 118 | + foreach ($_COOKIE as $name => $value) { |
|
| 119 | + if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 120 | + unset($_COOKIE[$name]); |
|
| 121 | + unset($GLOBALS[$name]); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + foreach ($_COOKIE as $name => $value) { |
|
| 125 | + if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 126 | + $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 127 | + $_COOKIE[$spipname] = $value; |
|
| 128 | + $GLOBALS[$spipname] = $value; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | 132 | } |
| 133 | 133 | |
@@ -147,18 +147,18 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | **/ |
| 149 | 149 | function exec_test_ajax_dist() { |
| 150 | - switch (_request('js')) { |
|
| 151 | - // on est appele par <noscript> |
|
| 152 | - case -1: |
|
| 153 | - spip_setcookie('spip_accepte_ajax', -1); |
|
| 154 | - include_spip('inc/headers'); |
|
| 155 | - redirige_par_entete(chemin_image('puce-orange-anim.gif')); |
|
| 156 | - break; |
|
| 157 | - |
|
| 158 | - // ou par ajax |
|
| 159 | - case 1: |
|
| 160 | - default: |
|
| 161 | - spip_setcookie('spip_accepte_ajax', 1); |
|
| 162 | - break; |
|
| 163 | - } |
|
| 150 | + switch (_request('js')) { |
|
| 151 | + // on est appele par <noscript> |
|
| 152 | + case -1: |
|
| 153 | + spip_setcookie('spip_accepte_ajax', -1); |
|
| 154 | + include_spip('inc/headers'); |
|
| 155 | + redirige_par_entete(chemin_image('puce-orange-anim.gif')); |
|
| 156 | + break; |
|
| 157 | + |
|
| 158 | + // ou par ajax |
|
| 159 | + case 1: |
|
| 160 | + default: |
|
| 161 | + spip_setcookie('spip_accepte_ajax', 1); |
|
| 162 | + break; |
|
| 163 | + } |
|
| 164 | 164 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | // liste des cookies en httponly (a passer en define si besoin) |
| 47 | 47 | $httponly = in_array($name, explode(' ', 'spip_session')); |
| 48 | 48 | |
| 49 | - $name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'] . '_', $name); |
|
| 49 | + $name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'].'_', $name); |
|
| 50 | 50 | if ($path == 'AUTO') { |
| 51 | 51 | $path = defined('_COOKIE_PATH') ? _COOKIE_PATH : preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
| 52 | 52 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | foreach ($_COOKIE as $name => $value) { |
| 125 | 125 | if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
| 126 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 126 | + $spipname = preg_replace('/^'.$cookie_prefix.'_/', 'spip_', $name); |
|
| 127 | 127 | $_COOKIE[$spipname] = $value; |
| 128 | 128 | $GLOBALS[$spipname] = $value; |
| 129 | 129 | } |
@@ -83,7 +83,7 @@ |
||
| 83 | 83 | * Couples champ/valeur à modifier |
| 84 | 84 | * @param string $serveur |
| 85 | 85 | * Nom du connecteur à la base de données |
| 86 | - * @return bool|string |
|
| 86 | + * @return string|false |
|
| 87 | 87 | * - false : Aucune modification, aucun champ n'est à modifier |
| 88 | 88 | * - chaîne vide : Vide si tout s'est bien passé |
| 89 | 89 | * - chaîne : Texte d'un message d'erreur |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -39,28 +39,28 @@ discard block |
||
| 39 | 39 | * Tableau des champs et valeurs collectées |
| 40 | 40 | */ |
| 41 | 41 | function collecter_requests($white_list, $black_list = array(), $set = null, $tous = false) { |
| 42 | - $c = $set; |
|
| 43 | - if (!$c) { |
|
| 44 | - $c = array(); |
|
| 45 | - foreach ($white_list as $champ) { |
|
| 46 | - // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | - // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | - $val = _request($champ); |
|
| 49 | - if ($tous or $val !== null) { |
|
| 50 | - $c[$champ] = $val; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - // on ajoute toujours la lang en saisie possible |
|
| 54 | - // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | - if ($l = _request('changer_lang')) { |
|
| 56 | - $c['lang'] = $l; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - foreach ($black_list as $champ) { |
|
| 60 | - unset($c[$champ]); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - return $c; |
|
| 42 | + $c = $set; |
|
| 43 | + if (!$c) { |
|
| 44 | + $c = array(); |
|
| 45 | + foreach ($white_list as $champ) { |
|
| 46 | + // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | + // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | + $val = _request($champ); |
|
| 49 | + if ($tous or $val !== null) { |
|
| 50 | + $c[$champ] = $val; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + // on ajoute toujours la lang en saisie possible |
|
| 54 | + // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | + if ($l = _request('changer_lang')) { |
|
| 56 | + $c['lang'] = $l; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + foreach ($black_list as $champ) { |
|
| 60 | + unset($c[$champ]); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + return $c; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -97,208 +97,208 @@ discard block |
||
| 97 | 97 | * - chaîne : Texte d'un message d'erreur |
| 98 | 98 | */ |
| 99 | 99 | function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') { |
| 100 | - if (!$id_objet = intval($id_objet)) { |
|
| 101 | - spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | - |
|
| 103 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/filtres'); |
|
| 107 | - |
|
| 108 | - $table_objet = table_objet($objet, $serveur); |
|
| 109 | - $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | - $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | - |
|
| 114 | - // Appels incomplets (sans $c) |
|
| 115 | - if (!is_array($c)) { |
|
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | - |
|
| 118 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | - // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | - // il faut passer par instituer_XX() |
|
| 124 | - // TODO: faut-il passer ces variables interdites |
|
| 125 | - // dans un fichier de description separe ? |
|
| 126 | - unset($c['statut']); |
|
| 127 | - unset($c['id_parent']); |
|
| 128 | - unset($c['id_rubrique']); |
|
| 129 | - unset($c['id_secteur']); |
|
| 130 | - |
|
| 131 | - // Gerer les champs non vides |
|
| 132 | - if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | - if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | - $c[$champ] = $sinon; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - // N'accepter que les champs qui existent |
|
| 142 | - // TODO: ici aussi on peut valider les contenus |
|
| 143 | - // en fonction du type |
|
| 144 | - $champs = array(); |
|
| 145 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 146 | - if (isset($c[$champ])) { |
|
| 147 | - $champs[$champ] = $c[$champ]; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // Nettoyer les valeurs |
|
| 152 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 153 | - |
|
| 154 | - // Envoyer aux plugins |
|
| 155 | - $champs = pipeline('pre_edition', |
|
| 156 | - array( |
|
| 157 | - 'args' => array( |
|
| 158 | - 'table' => $spip_table_objet, // compatibilite |
|
| 159 | - 'table_objet' => $table_objet, |
|
| 160 | - 'spip_table_objet' => $spip_table_objet, |
|
| 161 | - 'type' => $objet, |
|
| 162 | - 'id_objet' => $id_objet, |
|
| 163 | - 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ? |
|
| 164 | - 'serveur' => $serveur, |
|
| 165 | - 'action' => isset($options['action']) ? $options['action'] : 'modifier' |
|
| 166 | - ), |
|
| 167 | - 'data' => $champs |
|
| 168 | - ) |
|
| 169 | - ); |
|
| 170 | - |
|
| 171 | - if (!$champs) { |
|
| 172 | - return false; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - // marquer le fait que l'objet est travaille par toto a telle date |
|
| 177 | - if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 178 | - include_spip('inc/drapeau_edition'); |
|
| 179 | - signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 183 | - include_spip('inc/editer'); |
|
| 184 | - if (!isset($options['data']) or is_null($options['data'])){ |
|
| 185 | - $options['data'] = &$_POST; |
|
| 186 | - } |
|
| 187 | - $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 188 | - // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 189 | - // et gere l'interface |
|
| 190 | - // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 191 | - if ($conflits) { |
|
| 192 | - return _T('titre_conflit_edition'); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ($champs) { |
|
| 196 | - // cas particulier de la langue : passer par instituer_langue_objet |
|
| 197 | - if (isset($champs['lang'])) { |
|
| 198 | - if ($changer_lang = $champs['lang']) { |
|
| 199 | - $id_rubrique = 0; |
|
| 200 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 201 | - $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 202 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 203 | - } |
|
| 204 | - $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 205 | - $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 206 | - } |
|
| 207 | - // on laisse 'lang' dans $champs, |
|
| 208 | - // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 209 | - // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 210 | - // deja pris en compte |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - // la modif peut avoir lieu |
|
| 214 | - |
|
| 215 | - // faut-il ajouter date_modif ? |
|
| 216 | - if (isset($options['date_modif']) and $options['date_modif'] |
|
| 217 | - and !isset($champs[$options['date_modif']]) |
|
| 218 | - ) { |
|
| 219 | - $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // allez on commit la modif |
|
| 223 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur); |
|
| 224 | - |
|
| 225 | - // on verifie si elle est bien passee |
|
| 226 | - $moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=" . intval($id_objet), array(), array(), |
|
| 227 | - '', array(), $serveur); |
|
| 228 | - // si difference entre les champs, reperer les champs mal enregistres |
|
| 229 | - if ($moof != $champs) { |
|
| 230 | - $liste = array(); |
|
| 231 | - foreach ($moof as $k => $v) { |
|
| 232 | - if ($v !== $champs[$k] |
|
| 233 | - // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 234 | - and (!is_numeric($v) or intval($v) != intval($champs[$k])) |
|
| 235 | - ) { |
|
| 236 | - $liste[] = $k; |
|
| 237 | - $conflits[$k]['post'] = $champs[$k]; |
|
| 238 | - $conflits[$k]['save'] = $v; |
|
| 239 | - |
|
| 240 | - // cas specifique MySQL+emoji : si l'un est la |
|
| 241 | - // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 242 | - if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 243 | - include_spip('inc/charsets'); |
|
| 244 | - if ($v == utf8_noplanes($champs[$k])) { |
|
| 245 | - array_pop($liste); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 251 | - // c'est un cas exceptionnel |
|
| 252 | - if (count($liste)) { |
|
| 253 | - spip_log("Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 254 | - 'modifier.' . _LOG_CRITIQUE); |
|
| 255 | - |
|
| 256 | - return _T('erreur_technique_enregistrement_champs', |
|
| 257 | - array('champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>")); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // Invalider les caches |
|
| 262 | - if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 263 | - include_spip('inc/invalideur'); |
|
| 264 | - if (is_array($options['invalideur'])) { |
|
| 265 | - array_map('suivre_invalideur', $options['invalideur']); |
|
| 266 | - } else { |
|
| 267 | - suivre_invalideur($options['invalideur']); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Notifications, gestion des revisions... |
|
| 272 | - // en standard, appelle |nouvelle_revision ci-dessous |
|
| 273 | - pipeline('post_edition', |
|
| 274 | - array( |
|
| 275 | - 'args' => array( |
|
| 276 | - 'table' => $spip_table_objet, |
|
| 277 | - 'table_objet' => $table_objet, |
|
| 278 | - 'spip_table_objet' => $spip_table_objet, |
|
| 279 | - 'type' => $objet, |
|
| 280 | - 'id_objet' => $id_objet, |
|
| 281 | - 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] kesako ? |
|
| 282 | - 'serveur' => $serveur, |
|
| 283 | - 'action' => isset($options['action']) ? $options['action'] : 'modifier' |
|
| 284 | - ), |
|
| 285 | - 'data' => $champs |
|
| 286 | - ) |
|
| 287 | - ); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - // journaliser l'affaire |
|
| 291 | - // message a affiner :-) |
|
| 292 | - include_spip('inc/filtres_mini'); |
|
| 293 | - $qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip']; |
|
| 294 | - journal(_L($qui . ' a édité l’' . $objet . ' ' . $id_objet . ' (' . join('+', |
|
| 295 | - array_diff(array_keys($champs), array('date_modif'))) . ')'), array( |
|
| 296 | - 'faire' => 'modifier', |
|
| 297 | - 'quoi' => $objet, |
|
| 298 | - 'id' => $id_objet |
|
| 299 | - )); |
|
| 300 | - |
|
| 301 | - return ''; |
|
| 100 | + if (!$id_objet = intval($id_objet)) { |
|
| 101 | + spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | + |
|
| 103 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/filtres'); |
|
| 107 | + |
|
| 108 | + $table_objet = table_objet($objet, $serveur); |
|
| 109 | + $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | + $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | + |
|
| 114 | + // Appels incomplets (sans $c) |
|
| 115 | + if (!is_array($c)) { |
|
| 116 | + spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | + |
|
| 118 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | + // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | + // il faut passer par instituer_XX() |
|
| 124 | + // TODO: faut-il passer ces variables interdites |
|
| 125 | + // dans un fichier de description separe ? |
|
| 126 | + unset($c['statut']); |
|
| 127 | + unset($c['id_parent']); |
|
| 128 | + unset($c['id_rubrique']); |
|
| 129 | + unset($c['id_secteur']); |
|
| 130 | + |
|
| 131 | + // Gerer les champs non vides |
|
| 132 | + if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | + if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | + $c[$champ] = $sinon; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + // N'accepter que les champs qui existent |
|
| 142 | + // TODO: ici aussi on peut valider les contenus |
|
| 143 | + // en fonction du type |
|
| 144 | + $champs = array(); |
|
| 145 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 146 | + if (isset($c[$champ])) { |
|
| 147 | + $champs[$champ] = $c[$champ]; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // Nettoyer les valeurs |
|
| 152 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 153 | + |
|
| 154 | + // Envoyer aux plugins |
|
| 155 | + $champs = pipeline('pre_edition', |
|
| 156 | + array( |
|
| 157 | + 'args' => array( |
|
| 158 | + 'table' => $spip_table_objet, // compatibilite |
|
| 159 | + 'table_objet' => $table_objet, |
|
| 160 | + 'spip_table_objet' => $spip_table_objet, |
|
| 161 | + 'type' => $objet, |
|
| 162 | + 'id_objet' => $id_objet, |
|
| 163 | + 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ? |
|
| 164 | + 'serveur' => $serveur, |
|
| 165 | + 'action' => isset($options['action']) ? $options['action'] : 'modifier' |
|
| 166 | + ), |
|
| 167 | + 'data' => $champs |
|
| 168 | + ) |
|
| 169 | + ); |
|
| 170 | + |
|
| 171 | + if (!$champs) { |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + // marquer le fait que l'objet est travaille par toto a telle date |
|
| 177 | + if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 178 | + include_spip('inc/drapeau_edition'); |
|
| 179 | + signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 183 | + include_spip('inc/editer'); |
|
| 184 | + if (!isset($options['data']) or is_null($options['data'])){ |
|
| 185 | + $options['data'] = &$_POST; |
|
| 186 | + } |
|
| 187 | + $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 188 | + // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 189 | + // et gere l'interface |
|
| 190 | + // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 191 | + if ($conflits) { |
|
| 192 | + return _T('titre_conflit_edition'); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ($champs) { |
|
| 196 | + // cas particulier de la langue : passer par instituer_langue_objet |
|
| 197 | + if (isset($champs['lang'])) { |
|
| 198 | + if ($changer_lang = $champs['lang']) { |
|
| 199 | + $id_rubrique = 0; |
|
| 200 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 201 | + $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 202 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 203 | + } |
|
| 204 | + $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 205 | + $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 206 | + } |
|
| 207 | + // on laisse 'lang' dans $champs, |
|
| 208 | + // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 209 | + // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 210 | + // deja pris en compte |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + // la modif peut avoir lieu |
|
| 214 | + |
|
| 215 | + // faut-il ajouter date_modif ? |
|
| 216 | + if (isset($options['date_modif']) and $options['date_modif'] |
|
| 217 | + and !isset($champs[$options['date_modif']]) |
|
| 218 | + ) { |
|
| 219 | + $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // allez on commit la modif |
|
| 223 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur); |
|
| 224 | + |
|
| 225 | + // on verifie si elle est bien passee |
|
| 226 | + $moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=" . intval($id_objet), array(), array(), |
|
| 227 | + '', array(), $serveur); |
|
| 228 | + // si difference entre les champs, reperer les champs mal enregistres |
|
| 229 | + if ($moof != $champs) { |
|
| 230 | + $liste = array(); |
|
| 231 | + foreach ($moof as $k => $v) { |
|
| 232 | + if ($v !== $champs[$k] |
|
| 233 | + // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 234 | + and (!is_numeric($v) or intval($v) != intval($champs[$k])) |
|
| 235 | + ) { |
|
| 236 | + $liste[] = $k; |
|
| 237 | + $conflits[$k]['post'] = $champs[$k]; |
|
| 238 | + $conflits[$k]['save'] = $v; |
|
| 239 | + |
|
| 240 | + // cas specifique MySQL+emoji : si l'un est la |
|
| 241 | + // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 242 | + if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 243 | + include_spip('inc/charsets'); |
|
| 244 | + if ($v == utf8_noplanes($champs[$k])) { |
|
| 245 | + array_pop($liste); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 251 | + // c'est un cas exceptionnel |
|
| 252 | + if (count($liste)) { |
|
| 253 | + spip_log("Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 254 | + 'modifier.' . _LOG_CRITIQUE); |
|
| 255 | + |
|
| 256 | + return _T('erreur_technique_enregistrement_champs', |
|
| 257 | + array('champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>")); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + // Invalider les caches |
|
| 262 | + if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 263 | + include_spip('inc/invalideur'); |
|
| 264 | + if (is_array($options['invalideur'])) { |
|
| 265 | + array_map('suivre_invalideur', $options['invalideur']); |
|
| 266 | + } else { |
|
| 267 | + suivre_invalideur($options['invalideur']); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Notifications, gestion des revisions... |
|
| 272 | + // en standard, appelle |nouvelle_revision ci-dessous |
|
| 273 | + pipeline('post_edition', |
|
| 274 | + array( |
|
| 275 | + 'args' => array( |
|
| 276 | + 'table' => $spip_table_objet, |
|
| 277 | + 'table_objet' => $table_objet, |
|
| 278 | + 'spip_table_objet' => $spip_table_objet, |
|
| 279 | + 'type' => $objet, |
|
| 280 | + 'id_objet' => $id_objet, |
|
| 281 | + 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] kesako ? |
|
| 282 | + 'serveur' => $serveur, |
|
| 283 | + 'action' => isset($options['action']) ? $options['action'] : 'modifier' |
|
| 284 | + ), |
|
| 285 | + 'data' => $champs |
|
| 286 | + ) |
|
| 287 | + ); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + // journaliser l'affaire |
|
| 291 | + // message a affiner :-) |
|
| 292 | + include_spip('inc/filtres_mini'); |
|
| 293 | + $qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip']; |
|
| 294 | + journal(_L($qui . ' a édité l’' . $objet . ' ' . $id_objet . ' (' . join('+', |
|
| 295 | + array_diff(array_keys($champs), array('date_modif'))) . ')'), array( |
|
| 296 | + 'faire' => 'modifier', |
|
| 297 | + 'quoi' => $objet, |
|
| 298 | + 'id' => $id_objet |
|
| 299 | + )); |
|
| 300 | + |
|
| 301 | + return ''; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -323,9 +323,9 @@ discard block |
||
| 323 | 323 | * false sinon (erreur ou aucun champ modifié) |
| 324 | 324 | */ |
| 325 | 325 | function modifier_contenu($type, $id, $options, $c = null, $serveur = '') { |
| 326 | - $res = objet_modifier_champs($type, $id, $options, $c, $serveur); |
|
| 326 | + $res = objet_modifier_champs($type, $id, $options, $c, $serveur); |
|
| 327 | 327 | |
| 328 | - return ($res === '' ? true : false); |
|
| 328 | + return ($res === '' ? true : false); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /** |
@@ -346,8 +346,8 @@ discard block |
||
| 346 | 346 | * @return mixed|string |
| 347 | 347 | */ |
| 348 | 348 | function revision_objet($objet, $id_objet, $c = null) { |
| 349 | - $objet = objet_type($objet); // securite |
|
| 350 | - include_spip('action/editer_objet'); |
|
| 349 | + $objet = objet_type($objet); // securite |
|
| 350 | + include_spip('action/editer_objet'); |
|
| 351 | 351 | |
| 352 | - return objet_modifier($objet, $id_objet, $c); |
|
| 352 | + return objet_modifier($objet, $id_objet, $c); |
|
| 353 | 353 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | // Appels incomplets (sans $c) |
| 115 | 115 | if (!is_array($c)) { |
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 116 | + spip_log('erreur appel objet_modifier_champs('.$objet.'), manque $c'); |
|
| 117 | 117 | |
| 118 | 118 | return _T('erreur_technique_enregistrement_impossible'); |
| 119 | 119 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
| 183 | 183 | include_spip('inc/editer'); |
| 184 | - if (!isset($options['data']) or is_null($options['data'])){ |
|
| 184 | + if (!isset($options['data']) or is_null($options['data'])) { |
|
| 185 | 185 | $options['data'] = &$_POST; |
| 186 | 186 | } |
| 187 | 187 | $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | $id_rubrique = 0; |
| 200 | 200 | if (isset($desc['field']['id_rubrique'])) { |
| 201 | 201 | $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
| 202 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 202 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=".intval($id_objet)); |
|
| 203 | 203 | } |
| 204 | 204 | $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
| 205 | 205 | $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
@@ -220,10 +220,10 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // allez on commit la modif |
| 223 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur); |
|
| 223 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=".intval($id_objet), $serveur); |
|
| 224 | 224 | |
| 225 | 225 | // on verifie si elle est bien passee |
| 226 | - $moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=" . intval($id_objet), array(), array(), |
|
| 226 | + $moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=".intval($id_objet), array(), array(), |
|
| 227 | 227 | '', array(), $serveur); |
| 228 | 228 | // si difference entre les champs, reperer les champs mal enregistres |
| 229 | 229 | if ($moof != $champs) { |
@@ -250,11 +250,11 @@ discard block |
||
| 250 | 250 | // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
| 251 | 251 | // c'est un cas exceptionnel |
| 252 | 252 | if (count($liste)) { |
| 253 | - spip_log("Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 254 | - 'modifier.' . _LOG_CRITIQUE); |
|
| 253 | + spip_log("Erreur enregistrement en base $objet/$id_objet champs :".var_export($conflits, true), |
|
| 254 | + 'modifier.'._LOG_CRITIQUE); |
|
| 255 | 255 | |
| 256 | 256 | return _T('erreur_technique_enregistrement_champs', |
| 257 | - array('champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>")); |
|
| 257 | + array('champs' => "<i>'".implode("'</i>,<i>'", $liste)."'</i>")); |
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
@@ -291,8 +291,8 @@ discard block |
||
| 291 | 291 | // message a affiner :-) |
| 292 | 292 | include_spip('inc/filtres_mini'); |
| 293 | 293 | $qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip']; |
| 294 | - journal(_L($qui . ' a édité l’' . $objet . ' ' . $id_objet . ' (' . join('+', |
|
| 295 | - array_diff(array_keys($champs), array('date_modif'))) . ')'), array( |
|
| 294 | + journal(_L($qui.' a édité l’'.$objet.' '.$id_objet.' ('.join('+', |
|
| 295 | + array_diff(array_keys($champs), array('date_modif'))).')'), array( |
|
| 296 | 296 | 'faire' => 'modifier', |
| 297 | 297 | 'quoi' => $objet, |
| 298 | 298 | 'id' => $id_objet |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | |
| 329 | 329 | /** Array split |
| 330 | 330 | * |
| 331 | - * @param array $a |
|
| 331 | + * @param integer[] $a |
|
| 332 | 332 | * @param int $n |
| 333 | 333 | * @return array |
| 334 | 334 | **/ |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | /** |
| 353 | 353 | * Process and return the hash. |
| 354 | 354 | * |
| 355 | - * @param $str Input string to hash |
|
| 355 | + * @param string $str Input string to hash |
|
| 356 | 356 | * @param $ig_func Option param to ignore checking for php > 5.1.2 |
| 357 | 357 | * @return string Hexadecimal representation of the message digest |
| 358 | 358 | */ |
@@ -68,482 +68,482 @@ discard block |
||
| 68 | 68 | * @package SPIP\Core\Authentification\Sha256 |
| 69 | 69 | */ |
| 70 | 70 | if (!class_exists('nanoSha2')) { |
| 71 | - /** |
|
| 72 | - * Classe de calcul d'un SHA |
|
| 73 | - */ |
|
| 74 | - class nanoSha2 { |
|
| 75 | - // php 4 - 5 compatable class properties |
|
| 76 | - /** Le résultat doit être passé en majuscule ? |
|
| 77 | - * |
|
| 78 | - * @var bool |
|
| 79 | - */ |
|
| 80 | - var $toUpper; |
|
| 81 | - /** 32 ou 64 bits ? |
|
| 82 | - * |
|
| 83 | - * @var int |
|
| 84 | - */ |
|
| 85 | - var $platform; |
|
| 86 | - /** bytes par caractères */ |
|
| 87 | - var $bytesString = 16; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Constructor |
|
| 91 | - * |
|
| 92 | - * @param bool $toUpper |
|
| 93 | - */ |
|
| 94 | - function __construct($toUpper = false) { |
|
| 95 | - // Determine if the caller wants upper case or not. |
|
| 96 | - $this->toUpper = is_bool($toUpper) |
|
| 97 | - ? $toUpper |
|
| 98 | - : ((defined('_NANO_SHA2_UPPER')) ? true : false); |
|
| 99 | - |
|
| 100 | - // Deteremine if the system is 32 or 64 bit. |
|
| 101 | - $tmpInt = (int)4294967295; |
|
| 102 | - $this->platform = ($tmpInt > 0) ? 64 : 32; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Here are the bitwise and functions as defined in FIPS180-2 Standard |
|
| 107 | - * |
|
| 108 | - * @param int $x |
|
| 109 | - * @param int $y |
|
| 110 | - * @param int $n |
|
| 111 | - * @return int |
|
| 112 | - */ |
|
| 113 | - function addmod2n($x, $y, $n = 4294967296) // Z = (X + Y) mod 2^32 |
|
| 114 | - { |
|
| 115 | - $mask = 0x80000000; |
|
| 116 | - |
|
| 117 | - if ($x < 0) { |
|
| 118 | - $x &= 0x7FFFFFFF; |
|
| 119 | - $x = (float)$x+$mask; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - if ($y < 0) { |
|
| 123 | - $y &= 0x7FFFFFFF; |
|
| 124 | - $y = (float)$y+$mask; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - $r = $x+$y; |
|
| 128 | - |
|
| 129 | - if ($r >= $n) { |
|
| 130 | - while ($r >= $n) { |
|
| 131 | - $r -= $n; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return (int)$r; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Logical bitwise right shift (PHP default is arithmetic shift) |
|
| 140 | - * |
|
| 141 | - * @param int $x |
|
| 142 | - * @param int $n |
|
| 143 | - * return int |
|
| 144 | - */ |
|
| 145 | - function SHR($x, $n) // x >> n |
|
| 146 | - { |
|
| 147 | - if ($n >= 32) { // impose some limits to keep it 32-bit |
|
| 148 | - return (int)0; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if ($n <= 0) { |
|
| 152 | - return (int)$x; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - $mask = 0x40000000; |
|
| 156 | - |
|
| 157 | - if ($x < 0) { |
|
| 158 | - $x &= 0x7FFFFFFF; |
|
| 159 | - $mask = $mask >> ($n-1); |
|
| 160 | - |
|
| 161 | - return ($x >> $n) | $mask; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return (int)$x >> (int)$n; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** ROTR |
|
| 168 | - * |
|
| 169 | - * @param int $x |
|
| 170 | - * @param int $n |
|
| 171 | - * @return int |
|
| 172 | - */ |
|
| 173 | - function ROTR($x, $n) { return (int)(($this->SHR($x, $n) | ($x << (32-$n)) & 0xFFFFFFFF)); } |
|
| 174 | - |
|
| 175 | - /** Ch |
|
| 176 | - * |
|
| 177 | - * @param int $x |
|
| 178 | - * @param int $y |
|
| 179 | - * @param int $z |
|
| 180 | - * @return int |
|
| 181 | - */ |
|
| 182 | - function Ch($x, $y, $z) { return ($x & $y) ^ ((~$x) & $z); } |
|
| 183 | - |
|
| 184 | - /** Maj |
|
| 185 | - * |
|
| 186 | - * @param int $x |
|
| 187 | - * @param int $y |
|
| 188 | - * @param int $z |
|
| 189 | - * @return int |
|
| 190 | - */ |
|
| 191 | - function Maj($x, $y, $z) { return ($x & $y) ^ ($x & $z) ^ ($y & $z); } |
|
| 192 | - |
|
| 193 | - /** Sigma0 |
|
| 194 | - * |
|
| 195 | - * @param int $x |
|
| 196 | - * @return int |
|
| 197 | - */ |
|
| 198 | - function Sigma0($x) { return (int)($this->ROTR($x, 2) ^ $this->ROTR($x, 13) ^ $this->ROTR($x, 22)); } |
|
| 199 | - |
|
| 200 | - /** Sigma1 |
|
| 201 | - * |
|
| 202 | - * @param int $x |
|
| 203 | - * @return int |
|
| 204 | - */ |
|
| 205 | - function Sigma1($x) { return (int)($this->ROTR($x, 6) ^ $this->ROTR($x, 11) ^ $this->ROTR($x, 25)); } |
|
| 206 | - |
|
| 207 | - /** Sigma_0 |
|
| 208 | - * |
|
| 209 | - * @param int $x |
|
| 210 | - * @return int |
|
| 211 | - */ |
|
| 212 | - function sigma_0($x) { return (int)($this->ROTR($x, 7) ^ $this->ROTR($x, 18) ^ $this->SHR($x, 3)); } |
|
| 213 | - |
|
| 214 | - /** Sigma_1 |
|
| 215 | - * |
|
| 216 | - * @param int $x |
|
| 217 | - * @return int |
|
| 218 | - */ |
|
| 219 | - function sigma_1($x) { return (int)($this->ROTR($x, 17) ^ $this->ROTR($x, 19) ^ $this->SHR($x, 10)); } |
|
| 220 | - |
|
| 221 | - /** String 2 ord UTF8 |
|
| 222 | - * |
|
| 223 | - * @param string $s |
|
| 224 | - * @param int $byteSize |
|
| 225 | - * @return array |
|
| 226 | - **/ |
|
| 227 | - function string2ordUTF8($s, &$byteSize) { |
|
| 228 | - $chars = array(); |
|
| 229 | - // par defaut sur 8bits |
|
| 230 | - $byteSize = 8; |
|
| 231 | - $i = 0; |
|
| 232 | - while ($i < strlen($s)) { |
|
| 233 | - $chars[] = $this->ordUTF8($s, $i, $bytes); |
|
| 234 | - $i += $bytes; |
|
| 235 | - // mais si un char necessite 16bits, on passe tout sur 16 |
|
| 236 | - // sinon on ne concorde pas avec le lecture de la chaine en js |
|
| 237 | - // et le sha256 js |
|
| 238 | - if ($bytes > 1) { |
|
| 239 | - $byteSize = 16; |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - return $chars; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** Ord UTF8 |
|
| 247 | - * |
|
| 248 | - * @param string $c |
|
| 249 | - * @param int $index |
|
| 250 | - * @param int $bytes |
|
| 251 | - * @return unknown |
|
| 252 | - **/ |
|
| 253 | - function ordUTF8($c, $index = 0, &$bytes) { |
|
| 254 | - $len = strlen($c); |
|
| 255 | - $bytes = 0; |
|
| 256 | - |
|
| 257 | - if ($index >= $len) { |
|
| 258 | - return false; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - $h = ord($c{$index}); |
|
| 262 | - |
|
| 263 | - if ($h <= 0x7F) { |
|
| 264 | - $bytes = 1; |
|
| 265 | - |
|
| 266 | - return $h; |
|
| 267 | - } else { |
|
| 268 | - if ($h < 0xC2) { |
|
| 269 | - // pas utf mais renvoyer quand meme ce qu'on a |
|
| 270 | - $bytes = 1; |
|
| 271 | - |
|
| 272 | - return $h; |
|
| 273 | - } else { |
|
| 274 | - if ($h <= 0xDF && $index < $len-1) { |
|
| 275 | - $bytes = 2; |
|
| 276 | - |
|
| 277 | - return ($h & 0x1F) << 6 | (ord($c{$index+1}) & 0x3F); |
|
| 278 | - } else { |
|
| 279 | - if ($h <= 0xEF && $index < $len-2) { |
|
| 280 | - $bytes = 3; |
|
| 281 | - |
|
| 282 | - return ($h & 0x0F) << 12 | (ord($c{$index+1}) & 0x3F) << 6 |
|
| 283 | - | (ord($c{$index+2}) & 0x3F); |
|
| 284 | - } else { |
|
| 285 | - if ($h <= 0xF4 && $index < $len-3) { |
|
| 286 | - $bytes = 4; |
|
| 287 | - |
|
| 288 | - return ($h & 0x0F) << 18 | (ord($c{$index+1}) & 0x3F) << 12 |
|
| 289 | - | (ord($c{$index+2}) & 0x3F) << 6 |
|
| 290 | - | (ord($c{$index+3}) & 0x3F); |
|
| 291 | - } else { |
|
| 292 | - // pas utf mais renvoyer quand meme ce qu'on a |
|
| 293 | - $bytes = 1; |
|
| 294 | - |
|
| 295 | - return $h; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** String 2 bin int |
|
| 304 | - * |
|
| 305 | - * @param string $str |
|
| 306 | - * @param int $npad |
|
| 307 | - * @return int[] |
|
| 308 | - **/ |
|
| 309 | - function string2binint($str, $npad = 512) { |
|
| 310 | - $bin = array(); |
|
| 311 | - $ords = $this->string2ordUTF8($str, $this->bytesString); |
|
| 312 | - $npad = $npad/$this->bytesString; |
|
| 313 | - $length = count($ords); |
|
| 314 | - $ords[] = 0x80; // append the "1" bit followed by 7 0's |
|
| 315 | - $pad = ceil(($length+1+32/$this->bytesString)/$npad)*$npad-32/$this->bytesString; |
|
| 316 | - $ords = array_pad($ords, $pad, 0); |
|
| 317 | - $mask = (1 << $this->bytesString)-1; |
|
| 318 | - for ($i = 0; $i < count($ords)*$this->bytesString; $i += $this->bytesString) { |
|
| 319 | - if (!isset($bin[$i >> 5])) { |
|
| 320 | - $bin[$i >> 5] = 0; |
|
| 321 | - } // pour eviter des notices. |
|
| 322 | - $bin[$i >> 5] |= ($ords[$i/$this->bytesString] & $mask) << (24-$i%32); |
|
| 323 | - } |
|
| 324 | - $bin[] = $length*$this->bytesString; |
|
| 325 | - |
|
| 326 | - return $bin; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** Array split |
|
| 330 | - * |
|
| 331 | - * @param array $a |
|
| 332 | - * @param int $n |
|
| 333 | - * @return array |
|
| 334 | - **/ |
|
| 335 | - function array_split($a, $n) { |
|
| 336 | - $split = array(); |
|
| 337 | - while (count($a) > $n) { |
|
| 338 | - $s = array(); |
|
| 339 | - for ($i = 0; $i < $n; $i++) { |
|
| 340 | - $s[] = array_shift($a); |
|
| 341 | - } |
|
| 342 | - $split[] = $s; |
|
| 343 | - } |
|
| 344 | - if (count($a)) { |
|
| 345 | - $a = array_pad($a, $n, 0); |
|
| 346 | - $split[] = $a; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - return $split; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Process and return the hash. |
|
| 354 | - * |
|
| 355 | - * @param $str Input string to hash |
|
| 356 | - * @param $ig_func Option param to ignore checking for php > 5.1.2 |
|
| 357 | - * @return string Hexadecimal representation of the message digest |
|
| 358 | - */ |
|
| 359 | - function hash($str, $ig_func = true) { |
|
| 360 | - unset($binStr); // binary representation of input string |
|
| 361 | - unset($hexStr); // 256-bit message digest in readable hex format |
|
| 362 | - |
|
| 363 | - // check for php's internal sha256 function, ignore if ig_func==true |
|
| 364 | - if ($ig_func == false) { |
|
| 365 | - if (version_compare(PHP_VERSION, '5.1.2', '>=') AND !defined('_NO_HASH_DEFINED')) { |
|
| 366 | - return hash("sha256", $str, false); |
|
| 367 | - } else { |
|
| 368 | - if (function_exists('mhash') && defined('MHASH_SHA256')) { |
|
| 369 | - return base64_encode(bin2hex(mhash(MHASH_SHA256, $str))); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /* |
|
| 71 | + /** |
|
| 72 | + * Classe de calcul d'un SHA |
|
| 73 | + */ |
|
| 74 | + class nanoSha2 { |
|
| 75 | + // php 4 - 5 compatable class properties |
|
| 76 | + /** Le résultat doit être passé en majuscule ? |
|
| 77 | + * |
|
| 78 | + * @var bool |
|
| 79 | + */ |
|
| 80 | + var $toUpper; |
|
| 81 | + /** 32 ou 64 bits ? |
|
| 82 | + * |
|
| 83 | + * @var int |
|
| 84 | + */ |
|
| 85 | + var $platform; |
|
| 86 | + /** bytes par caractères */ |
|
| 87 | + var $bytesString = 16; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Constructor |
|
| 91 | + * |
|
| 92 | + * @param bool $toUpper |
|
| 93 | + */ |
|
| 94 | + function __construct($toUpper = false) { |
|
| 95 | + // Determine if the caller wants upper case or not. |
|
| 96 | + $this->toUpper = is_bool($toUpper) |
|
| 97 | + ? $toUpper |
|
| 98 | + : ((defined('_NANO_SHA2_UPPER')) ? true : false); |
|
| 99 | + |
|
| 100 | + // Deteremine if the system is 32 or 64 bit. |
|
| 101 | + $tmpInt = (int)4294967295; |
|
| 102 | + $this->platform = ($tmpInt > 0) ? 64 : 32; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Here are the bitwise and functions as defined in FIPS180-2 Standard |
|
| 107 | + * |
|
| 108 | + * @param int $x |
|
| 109 | + * @param int $y |
|
| 110 | + * @param int $n |
|
| 111 | + * @return int |
|
| 112 | + */ |
|
| 113 | + function addmod2n($x, $y, $n = 4294967296) // Z = (X + Y) mod 2^32 |
|
| 114 | + { |
|
| 115 | + $mask = 0x80000000; |
|
| 116 | + |
|
| 117 | + if ($x < 0) { |
|
| 118 | + $x &= 0x7FFFFFFF; |
|
| 119 | + $x = (float)$x+$mask; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + if ($y < 0) { |
|
| 123 | + $y &= 0x7FFFFFFF; |
|
| 124 | + $y = (float)$y+$mask; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + $r = $x+$y; |
|
| 128 | + |
|
| 129 | + if ($r >= $n) { |
|
| 130 | + while ($r >= $n) { |
|
| 131 | + $r -= $n; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return (int)$r; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Logical bitwise right shift (PHP default is arithmetic shift) |
|
| 140 | + * |
|
| 141 | + * @param int $x |
|
| 142 | + * @param int $n |
|
| 143 | + * return int |
|
| 144 | + */ |
|
| 145 | + function SHR($x, $n) // x >> n |
|
| 146 | + { |
|
| 147 | + if ($n >= 32) { // impose some limits to keep it 32-bit |
|
| 148 | + return (int)0; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + if ($n <= 0) { |
|
| 152 | + return (int)$x; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + $mask = 0x40000000; |
|
| 156 | + |
|
| 157 | + if ($x < 0) { |
|
| 158 | + $x &= 0x7FFFFFFF; |
|
| 159 | + $mask = $mask >> ($n-1); |
|
| 160 | + |
|
| 161 | + return ($x >> $n) | $mask; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return (int)$x >> (int)$n; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** ROTR |
|
| 168 | + * |
|
| 169 | + * @param int $x |
|
| 170 | + * @param int $n |
|
| 171 | + * @return int |
|
| 172 | + */ |
|
| 173 | + function ROTR($x, $n) { return (int)(($this->SHR($x, $n) | ($x << (32-$n)) & 0xFFFFFFFF)); } |
|
| 174 | + |
|
| 175 | + /** Ch |
|
| 176 | + * |
|
| 177 | + * @param int $x |
|
| 178 | + * @param int $y |
|
| 179 | + * @param int $z |
|
| 180 | + * @return int |
|
| 181 | + */ |
|
| 182 | + function Ch($x, $y, $z) { return ($x & $y) ^ ((~$x) & $z); } |
|
| 183 | + |
|
| 184 | + /** Maj |
|
| 185 | + * |
|
| 186 | + * @param int $x |
|
| 187 | + * @param int $y |
|
| 188 | + * @param int $z |
|
| 189 | + * @return int |
|
| 190 | + */ |
|
| 191 | + function Maj($x, $y, $z) { return ($x & $y) ^ ($x & $z) ^ ($y & $z); } |
|
| 192 | + |
|
| 193 | + /** Sigma0 |
|
| 194 | + * |
|
| 195 | + * @param int $x |
|
| 196 | + * @return int |
|
| 197 | + */ |
|
| 198 | + function Sigma0($x) { return (int)($this->ROTR($x, 2) ^ $this->ROTR($x, 13) ^ $this->ROTR($x, 22)); } |
|
| 199 | + |
|
| 200 | + /** Sigma1 |
|
| 201 | + * |
|
| 202 | + * @param int $x |
|
| 203 | + * @return int |
|
| 204 | + */ |
|
| 205 | + function Sigma1($x) { return (int)($this->ROTR($x, 6) ^ $this->ROTR($x, 11) ^ $this->ROTR($x, 25)); } |
|
| 206 | + |
|
| 207 | + /** Sigma_0 |
|
| 208 | + * |
|
| 209 | + * @param int $x |
|
| 210 | + * @return int |
|
| 211 | + */ |
|
| 212 | + function sigma_0($x) { return (int)($this->ROTR($x, 7) ^ $this->ROTR($x, 18) ^ $this->SHR($x, 3)); } |
|
| 213 | + |
|
| 214 | + /** Sigma_1 |
|
| 215 | + * |
|
| 216 | + * @param int $x |
|
| 217 | + * @return int |
|
| 218 | + */ |
|
| 219 | + function sigma_1($x) { return (int)($this->ROTR($x, 17) ^ $this->ROTR($x, 19) ^ $this->SHR($x, 10)); } |
|
| 220 | + |
|
| 221 | + /** String 2 ord UTF8 |
|
| 222 | + * |
|
| 223 | + * @param string $s |
|
| 224 | + * @param int $byteSize |
|
| 225 | + * @return array |
|
| 226 | + **/ |
|
| 227 | + function string2ordUTF8($s, &$byteSize) { |
|
| 228 | + $chars = array(); |
|
| 229 | + // par defaut sur 8bits |
|
| 230 | + $byteSize = 8; |
|
| 231 | + $i = 0; |
|
| 232 | + while ($i < strlen($s)) { |
|
| 233 | + $chars[] = $this->ordUTF8($s, $i, $bytes); |
|
| 234 | + $i += $bytes; |
|
| 235 | + // mais si un char necessite 16bits, on passe tout sur 16 |
|
| 236 | + // sinon on ne concorde pas avec le lecture de la chaine en js |
|
| 237 | + // et le sha256 js |
|
| 238 | + if ($bytes > 1) { |
|
| 239 | + $byteSize = 16; |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + return $chars; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** Ord UTF8 |
|
| 247 | + * |
|
| 248 | + * @param string $c |
|
| 249 | + * @param int $index |
|
| 250 | + * @param int $bytes |
|
| 251 | + * @return unknown |
|
| 252 | + **/ |
|
| 253 | + function ordUTF8($c, $index = 0, &$bytes) { |
|
| 254 | + $len = strlen($c); |
|
| 255 | + $bytes = 0; |
|
| 256 | + |
|
| 257 | + if ($index >= $len) { |
|
| 258 | + return false; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + $h = ord($c{$index}); |
|
| 262 | + |
|
| 263 | + if ($h <= 0x7F) { |
|
| 264 | + $bytes = 1; |
|
| 265 | + |
|
| 266 | + return $h; |
|
| 267 | + } else { |
|
| 268 | + if ($h < 0xC2) { |
|
| 269 | + // pas utf mais renvoyer quand meme ce qu'on a |
|
| 270 | + $bytes = 1; |
|
| 271 | + |
|
| 272 | + return $h; |
|
| 273 | + } else { |
|
| 274 | + if ($h <= 0xDF && $index < $len-1) { |
|
| 275 | + $bytes = 2; |
|
| 276 | + |
|
| 277 | + return ($h & 0x1F) << 6 | (ord($c{$index+1}) & 0x3F); |
|
| 278 | + } else { |
|
| 279 | + if ($h <= 0xEF && $index < $len-2) { |
|
| 280 | + $bytes = 3; |
|
| 281 | + |
|
| 282 | + return ($h & 0x0F) << 12 | (ord($c{$index+1}) & 0x3F) << 6 |
|
| 283 | + | (ord($c{$index+2}) & 0x3F); |
|
| 284 | + } else { |
|
| 285 | + if ($h <= 0xF4 && $index < $len-3) { |
|
| 286 | + $bytes = 4; |
|
| 287 | + |
|
| 288 | + return ($h & 0x0F) << 18 | (ord($c{$index+1}) & 0x3F) << 12 |
|
| 289 | + | (ord($c{$index+2}) & 0x3F) << 6 |
|
| 290 | + | (ord($c{$index+3}) & 0x3F); |
|
| 291 | + } else { |
|
| 292 | + // pas utf mais renvoyer quand meme ce qu'on a |
|
| 293 | + $bytes = 1; |
|
| 294 | + |
|
| 295 | + return $h; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** String 2 bin int |
|
| 304 | + * |
|
| 305 | + * @param string $str |
|
| 306 | + * @param int $npad |
|
| 307 | + * @return int[] |
|
| 308 | + **/ |
|
| 309 | + function string2binint($str, $npad = 512) { |
|
| 310 | + $bin = array(); |
|
| 311 | + $ords = $this->string2ordUTF8($str, $this->bytesString); |
|
| 312 | + $npad = $npad/$this->bytesString; |
|
| 313 | + $length = count($ords); |
|
| 314 | + $ords[] = 0x80; // append the "1" bit followed by 7 0's |
|
| 315 | + $pad = ceil(($length+1+32/$this->bytesString)/$npad)*$npad-32/$this->bytesString; |
|
| 316 | + $ords = array_pad($ords, $pad, 0); |
|
| 317 | + $mask = (1 << $this->bytesString)-1; |
|
| 318 | + for ($i = 0; $i < count($ords)*$this->bytesString; $i += $this->bytesString) { |
|
| 319 | + if (!isset($bin[$i >> 5])) { |
|
| 320 | + $bin[$i >> 5] = 0; |
|
| 321 | + } // pour eviter des notices. |
|
| 322 | + $bin[$i >> 5] |= ($ords[$i/$this->bytesString] & $mask) << (24-$i%32); |
|
| 323 | + } |
|
| 324 | + $bin[] = $length*$this->bytesString; |
|
| 325 | + |
|
| 326 | + return $bin; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** Array split |
|
| 330 | + * |
|
| 331 | + * @param array $a |
|
| 332 | + * @param int $n |
|
| 333 | + * @return array |
|
| 334 | + **/ |
|
| 335 | + function array_split($a, $n) { |
|
| 336 | + $split = array(); |
|
| 337 | + while (count($a) > $n) { |
|
| 338 | + $s = array(); |
|
| 339 | + for ($i = 0; $i < $n; $i++) { |
|
| 340 | + $s[] = array_shift($a); |
|
| 341 | + } |
|
| 342 | + $split[] = $s; |
|
| 343 | + } |
|
| 344 | + if (count($a)) { |
|
| 345 | + $a = array_pad($a, $n, 0); |
|
| 346 | + $split[] = $a; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + return $split; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Process and return the hash. |
|
| 354 | + * |
|
| 355 | + * @param $str Input string to hash |
|
| 356 | + * @param $ig_func Option param to ignore checking for php > 5.1.2 |
|
| 357 | + * @return string Hexadecimal representation of the message digest |
|
| 358 | + */ |
|
| 359 | + function hash($str, $ig_func = true) { |
|
| 360 | + unset($binStr); // binary representation of input string |
|
| 361 | + unset($hexStr); // 256-bit message digest in readable hex format |
|
| 362 | + |
|
| 363 | + // check for php's internal sha256 function, ignore if ig_func==true |
|
| 364 | + if ($ig_func == false) { |
|
| 365 | + if (version_compare(PHP_VERSION, '5.1.2', '>=') AND !defined('_NO_HASH_DEFINED')) { |
|
| 366 | + return hash("sha256", $str, false); |
|
| 367 | + } else { |
|
| 368 | + if (function_exists('mhash') && defined('MHASH_SHA256')) { |
|
| 369 | + return base64_encode(bin2hex(mhash(MHASH_SHA256, $str))); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /* |
|
| 375 | 375 | * SHA-256 Constants |
| 376 | 376 | * Sequence of sixty-four constant 32-bit words representing the |
| 377 | 377 | * first thirty-two bits of the fractional parts of the cube roots |
| 378 | 378 | * of the first sixtyfour prime numbers. |
| 379 | 379 | */ |
| 380 | - $K = array( |
|
| 381 | - (int)0x428a2f98, |
|
| 382 | - (int)0x71374491, |
|
| 383 | - (int)0xb5c0fbcf, |
|
| 384 | - (int)0xe9b5dba5, |
|
| 385 | - (int)0x3956c25b, |
|
| 386 | - (int)0x59f111f1, |
|
| 387 | - (int)0x923f82a4, |
|
| 388 | - (int)0xab1c5ed5, |
|
| 389 | - (int)0xd807aa98, |
|
| 390 | - (int)0x12835b01, |
|
| 391 | - (int)0x243185be, |
|
| 392 | - (int)0x550c7dc3, |
|
| 393 | - (int)0x72be5d74, |
|
| 394 | - (int)0x80deb1fe, |
|
| 395 | - (int)0x9bdc06a7, |
|
| 396 | - (int)0xc19bf174, |
|
| 397 | - (int)0xe49b69c1, |
|
| 398 | - (int)0xefbe4786, |
|
| 399 | - (int)0x0fc19dc6, |
|
| 400 | - (int)0x240ca1cc, |
|
| 401 | - (int)0x2de92c6f, |
|
| 402 | - (int)0x4a7484aa, |
|
| 403 | - (int)0x5cb0a9dc, |
|
| 404 | - (int)0x76f988da, |
|
| 405 | - (int)0x983e5152, |
|
| 406 | - (int)0xa831c66d, |
|
| 407 | - (int)0xb00327c8, |
|
| 408 | - (int)0xbf597fc7, |
|
| 409 | - (int)0xc6e00bf3, |
|
| 410 | - (int)0xd5a79147, |
|
| 411 | - (int)0x06ca6351, |
|
| 412 | - (int)0x14292967, |
|
| 413 | - (int)0x27b70a85, |
|
| 414 | - (int)0x2e1b2138, |
|
| 415 | - (int)0x4d2c6dfc, |
|
| 416 | - (int)0x53380d13, |
|
| 417 | - (int)0x650a7354, |
|
| 418 | - (int)0x766a0abb, |
|
| 419 | - (int)0x81c2c92e, |
|
| 420 | - (int)0x92722c85, |
|
| 421 | - (int)0xa2bfe8a1, |
|
| 422 | - (int)0xa81a664b, |
|
| 423 | - (int)0xc24b8b70, |
|
| 424 | - (int)0xc76c51a3, |
|
| 425 | - (int)0xd192e819, |
|
| 426 | - (int)0xd6990624, |
|
| 427 | - (int)0xf40e3585, |
|
| 428 | - (int)0x106aa070, |
|
| 429 | - (int)0x19a4c116, |
|
| 430 | - (int)0x1e376c08, |
|
| 431 | - (int)0x2748774c, |
|
| 432 | - (int)0x34b0bcb5, |
|
| 433 | - (int)0x391c0cb3, |
|
| 434 | - (int)0x4ed8aa4a, |
|
| 435 | - (int)0x5b9cca4f, |
|
| 436 | - (int)0x682e6ff3, |
|
| 437 | - (int)0x748f82ee, |
|
| 438 | - (int)0x78a5636f, |
|
| 439 | - (int)0x84c87814, |
|
| 440 | - (int)0x8cc70208, |
|
| 441 | - (int)0x90befffa, |
|
| 442 | - (int)0xa4506ceb, |
|
| 443 | - (int)0xbef9a3f7, |
|
| 444 | - (int)0xc67178f2 |
|
| 445 | - ); |
|
| 446 | - |
|
| 447 | - // Pre-processing: Padding the string |
|
| 448 | - $binStr = $this->string2binint($str, 512); |
|
| 449 | - |
|
| 450 | - // Parsing the Padded Message (Break into N 512-bit blocks) |
|
| 451 | - $M = $this->array_split($binStr, 16); |
|
| 452 | - |
|
| 453 | - // Set the initial hash values |
|
| 454 | - $h[0] = (int)0x6a09e667; |
|
| 455 | - $h[1] = (int)0xbb67ae85; |
|
| 456 | - $h[2] = (int)0x3c6ef372; |
|
| 457 | - $h[3] = (int)0xa54ff53a; |
|
| 458 | - $h[4] = (int)0x510e527f; |
|
| 459 | - $h[5] = (int)0x9b05688c; |
|
| 460 | - $h[6] = (int)0x1f83d9ab; |
|
| 461 | - $h[7] = (int)0x5be0cd19; |
|
| 462 | - |
|
| 463 | - // loop through message blocks and compute hash. ( For i=1 to N : ) |
|
| 464 | - $N = count($M); |
|
| 465 | - for ($i = 0; $i < $N; $i++) { |
|
| 466 | - // Break input block into 16 32bit words (message schedule prep) |
|
| 467 | - $MI = $M[$i]; |
|
| 468 | - |
|
| 469 | - // Initialize working variables |
|
| 470 | - $_a = (int)$h[0]; |
|
| 471 | - $_b = (int)$h[1]; |
|
| 472 | - $_c = (int)$h[2]; |
|
| 473 | - $_d = (int)$h[3]; |
|
| 474 | - $_e = (int)$h[4]; |
|
| 475 | - $_f = (int)$h[5]; |
|
| 476 | - $_g = (int)$h[6]; |
|
| 477 | - $_h = (int)$h[7]; |
|
| 478 | - unset($_s0); |
|
| 479 | - unset($_s1); |
|
| 480 | - unset($_T1); |
|
| 481 | - unset($_T2); |
|
| 482 | - $W = array(); |
|
| 483 | - |
|
| 484 | - // Compute the hash and update |
|
| 485 | - for ($t = 0; $t < 16; $t++) { |
|
| 486 | - // Prepare the first 16 message schedule values as we loop |
|
| 487 | - $W[$t] = $MI[$t]; |
|
| 488 | - |
|
| 489 | - // Compute hash |
|
| 490 | - $_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)), |
|
| 491 | - $this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t]); |
|
| 492 | - $_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c)); |
|
| 493 | - |
|
| 494 | - // Update working variables |
|
| 495 | - $_h = $_g; |
|
| 496 | - $_g = $_f; |
|
| 497 | - $_f = $_e; |
|
| 498 | - $_e = $this->addmod2n($_d, $_T1); |
|
| 499 | - $_d = $_c; |
|
| 500 | - $_c = $_b; |
|
| 501 | - $_b = $_a; |
|
| 502 | - $_a = $this->addmod2n($_T1, $_T2); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - for (; $t < 64; $t++) { |
|
| 506 | - // Continue building the message schedule as we loop |
|
| 507 | - $_s0 = $W[($t+1) & 0x0F]; |
|
| 508 | - $_s0 = $this->sigma_0($_s0); |
|
| 509 | - $_s1 = $W[($t+14) & 0x0F]; |
|
| 510 | - $_s1 = $this->sigma_1($_s1); |
|
| 511 | - |
|
| 512 | - $W[$t & 0xF] = $this->addmod2n($this->addmod2n($this->addmod2n($W[$t & 0xF], $_s0), $_s1), $W[($t+9) & 0x0F]); |
|
| 513 | - |
|
| 514 | - // Compute hash |
|
| 515 | - $_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)), |
|
| 516 | - $this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t & 0xF]); |
|
| 517 | - $_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c)); |
|
| 518 | - |
|
| 519 | - // Update working variables |
|
| 520 | - $_h = $_g; |
|
| 521 | - $_g = $_f; |
|
| 522 | - $_f = $_e; |
|
| 523 | - $_e = $this->addmod2n($_d, $_T1); |
|
| 524 | - $_d = $_c; |
|
| 525 | - $_c = $_b; |
|
| 526 | - $_b = $_a; |
|
| 527 | - $_a = $this->addmod2n($_T1, $_T2); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - $h[0] = $this->addmod2n($h[0], $_a); |
|
| 531 | - $h[1] = $this->addmod2n($h[1], $_b); |
|
| 532 | - $h[2] = $this->addmod2n($h[2], $_c); |
|
| 533 | - $h[3] = $this->addmod2n($h[3], $_d); |
|
| 534 | - $h[4] = $this->addmod2n($h[4], $_e); |
|
| 535 | - $h[5] = $this->addmod2n($h[5], $_f); |
|
| 536 | - $h[6] = $this->addmod2n($h[6], $_g); |
|
| 537 | - $h[7] = $this->addmod2n($h[7], $_h); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // Convert the 32-bit words into human readable hexadecimal format. |
|
| 541 | - $hexStr = sprintf("%08x%08x%08x%08x%08x%08x%08x%08x", $h[0], $h[1], $h[2], $h[3], $h[4], $h[5], $h[6], $h[7]); |
|
| 542 | - |
|
| 543 | - return ($this->toUpper) ? strtoupper($hexStr) : $hexStr; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - } |
|
| 380 | + $K = array( |
|
| 381 | + (int)0x428a2f98, |
|
| 382 | + (int)0x71374491, |
|
| 383 | + (int)0xb5c0fbcf, |
|
| 384 | + (int)0xe9b5dba5, |
|
| 385 | + (int)0x3956c25b, |
|
| 386 | + (int)0x59f111f1, |
|
| 387 | + (int)0x923f82a4, |
|
| 388 | + (int)0xab1c5ed5, |
|
| 389 | + (int)0xd807aa98, |
|
| 390 | + (int)0x12835b01, |
|
| 391 | + (int)0x243185be, |
|
| 392 | + (int)0x550c7dc3, |
|
| 393 | + (int)0x72be5d74, |
|
| 394 | + (int)0x80deb1fe, |
|
| 395 | + (int)0x9bdc06a7, |
|
| 396 | + (int)0xc19bf174, |
|
| 397 | + (int)0xe49b69c1, |
|
| 398 | + (int)0xefbe4786, |
|
| 399 | + (int)0x0fc19dc6, |
|
| 400 | + (int)0x240ca1cc, |
|
| 401 | + (int)0x2de92c6f, |
|
| 402 | + (int)0x4a7484aa, |
|
| 403 | + (int)0x5cb0a9dc, |
|
| 404 | + (int)0x76f988da, |
|
| 405 | + (int)0x983e5152, |
|
| 406 | + (int)0xa831c66d, |
|
| 407 | + (int)0xb00327c8, |
|
| 408 | + (int)0xbf597fc7, |
|
| 409 | + (int)0xc6e00bf3, |
|
| 410 | + (int)0xd5a79147, |
|
| 411 | + (int)0x06ca6351, |
|
| 412 | + (int)0x14292967, |
|
| 413 | + (int)0x27b70a85, |
|
| 414 | + (int)0x2e1b2138, |
|
| 415 | + (int)0x4d2c6dfc, |
|
| 416 | + (int)0x53380d13, |
|
| 417 | + (int)0x650a7354, |
|
| 418 | + (int)0x766a0abb, |
|
| 419 | + (int)0x81c2c92e, |
|
| 420 | + (int)0x92722c85, |
|
| 421 | + (int)0xa2bfe8a1, |
|
| 422 | + (int)0xa81a664b, |
|
| 423 | + (int)0xc24b8b70, |
|
| 424 | + (int)0xc76c51a3, |
|
| 425 | + (int)0xd192e819, |
|
| 426 | + (int)0xd6990624, |
|
| 427 | + (int)0xf40e3585, |
|
| 428 | + (int)0x106aa070, |
|
| 429 | + (int)0x19a4c116, |
|
| 430 | + (int)0x1e376c08, |
|
| 431 | + (int)0x2748774c, |
|
| 432 | + (int)0x34b0bcb5, |
|
| 433 | + (int)0x391c0cb3, |
|
| 434 | + (int)0x4ed8aa4a, |
|
| 435 | + (int)0x5b9cca4f, |
|
| 436 | + (int)0x682e6ff3, |
|
| 437 | + (int)0x748f82ee, |
|
| 438 | + (int)0x78a5636f, |
|
| 439 | + (int)0x84c87814, |
|
| 440 | + (int)0x8cc70208, |
|
| 441 | + (int)0x90befffa, |
|
| 442 | + (int)0xa4506ceb, |
|
| 443 | + (int)0xbef9a3f7, |
|
| 444 | + (int)0xc67178f2 |
|
| 445 | + ); |
|
| 446 | + |
|
| 447 | + // Pre-processing: Padding the string |
|
| 448 | + $binStr = $this->string2binint($str, 512); |
|
| 449 | + |
|
| 450 | + // Parsing the Padded Message (Break into N 512-bit blocks) |
|
| 451 | + $M = $this->array_split($binStr, 16); |
|
| 452 | + |
|
| 453 | + // Set the initial hash values |
|
| 454 | + $h[0] = (int)0x6a09e667; |
|
| 455 | + $h[1] = (int)0xbb67ae85; |
|
| 456 | + $h[2] = (int)0x3c6ef372; |
|
| 457 | + $h[3] = (int)0xa54ff53a; |
|
| 458 | + $h[4] = (int)0x510e527f; |
|
| 459 | + $h[5] = (int)0x9b05688c; |
|
| 460 | + $h[6] = (int)0x1f83d9ab; |
|
| 461 | + $h[7] = (int)0x5be0cd19; |
|
| 462 | + |
|
| 463 | + // loop through message blocks and compute hash. ( For i=1 to N : ) |
|
| 464 | + $N = count($M); |
|
| 465 | + for ($i = 0; $i < $N; $i++) { |
|
| 466 | + // Break input block into 16 32bit words (message schedule prep) |
|
| 467 | + $MI = $M[$i]; |
|
| 468 | + |
|
| 469 | + // Initialize working variables |
|
| 470 | + $_a = (int)$h[0]; |
|
| 471 | + $_b = (int)$h[1]; |
|
| 472 | + $_c = (int)$h[2]; |
|
| 473 | + $_d = (int)$h[3]; |
|
| 474 | + $_e = (int)$h[4]; |
|
| 475 | + $_f = (int)$h[5]; |
|
| 476 | + $_g = (int)$h[6]; |
|
| 477 | + $_h = (int)$h[7]; |
|
| 478 | + unset($_s0); |
|
| 479 | + unset($_s1); |
|
| 480 | + unset($_T1); |
|
| 481 | + unset($_T2); |
|
| 482 | + $W = array(); |
|
| 483 | + |
|
| 484 | + // Compute the hash and update |
|
| 485 | + for ($t = 0; $t < 16; $t++) { |
|
| 486 | + // Prepare the first 16 message schedule values as we loop |
|
| 487 | + $W[$t] = $MI[$t]; |
|
| 488 | + |
|
| 489 | + // Compute hash |
|
| 490 | + $_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)), |
|
| 491 | + $this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t]); |
|
| 492 | + $_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c)); |
|
| 493 | + |
|
| 494 | + // Update working variables |
|
| 495 | + $_h = $_g; |
|
| 496 | + $_g = $_f; |
|
| 497 | + $_f = $_e; |
|
| 498 | + $_e = $this->addmod2n($_d, $_T1); |
|
| 499 | + $_d = $_c; |
|
| 500 | + $_c = $_b; |
|
| 501 | + $_b = $_a; |
|
| 502 | + $_a = $this->addmod2n($_T1, $_T2); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + for (; $t < 64; $t++) { |
|
| 506 | + // Continue building the message schedule as we loop |
|
| 507 | + $_s0 = $W[($t+1) & 0x0F]; |
|
| 508 | + $_s0 = $this->sigma_0($_s0); |
|
| 509 | + $_s1 = $W[($t+14) & 0x0F]; |
|
| 510 | + $_s1 = $this->sigma_1($_s1); |
|
| 511 | + |
|
| 512 | + $W[$t & 0xF] = $this->addmod2n($this->addmod2n($this->addmod2n($W[$t & 0xF], $_s0), $_s1), $W[($t+9) & 0x0F]); |
|
| 513 | + |
|
| 514 | + // Compute hash |
|
| 515 | + $_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)), |
|
| 516 | + $this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t & 0xF]); |
|
| 517 | + $_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c)); |
|
| 518 | + |
|
| 519 | + // Update working variables |
|
| 520 | + $_h = $_g; |
|
| 521 | + $_g = $_f; |
|
| 522 | + $_f = $_e; |
|
| 523 | + $_e = $this->addmod2n($_d, $_T1); |
|
| 524 | + $_d = $_c; |
|
| 525 | + $_c = $_b; |
|
| 526 | + $_b = $_a; |
|
| 527 | + $_a = $this->addmod2n($_T1, $_T2); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + $h[0] = $this->addmod2n($h[0], $_a); |
|
| 531 | + $h[1] = $this->addmod2n($h[1], $_b); |
|
| 532 | + $h[2] = $this->addmod2n($h[2], $_c); |
|
| 533 | + $h[3] = $this->addmod2n($h[3], $_d); |
|
| 534 | + $h[4] = $this->addmod2n($h[4], $_e); |
|
| 535 | + $h[5] = $this->addmod2n($h[5], $_f); |
|
| 536 | + $h[6] = $this->addmod2n($h[6], $_g); |
|
| 537 | + $h[7] = $this->addmod2n($h[7], $_h); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // Convert the 32-bit words into human readable hexadecimal format. |
|
| 541 | + $hexStr = sprintf("%08x%08x%08x%08x%08x%08x%08x%08x", $h[0], $h[1], $h[2], $h[3], $h[4], $h[5], $h[6], $h[7]); |
|
| 542 | + |
|
| 543 | + return ($this->toUpper) ? strtoupper($hexStr) : $hexStr; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + } |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -562,42 +562,42 @@ discard block |
||
| 562 | 562 | * @return string Le SHA de la chaîne |
| 563 | 563 | */ |
| 564 | 564 | function _nano_sha256($str, $ig_func = true) { |
| 565 | - $obj = new nanoSha2((defined('_NANO_SHA2_UPPER')) ? true : false); |
|
| 565 | + $obj = new nanoSha2((defined('_NANO_SHA2_UPPER')) ? true : false); |
|
| 566 | 566 | |
| 567 | - return $obj->hash($str, $ig_func); |
|
| 567 | + return $obj->hash($str, $ig_func); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | // 2009-07-23: Added check for function as the Suhosin plugin adds this routine. |
| 571 | 571 | if (!function_exists('sha256')) { |
| 572 | - /** |
|
| 573 | - * Calcul du SHA256 |
|
| 574 | - * |
|
| 575 | - * @param string $str Chaîne dont on veut calculer le SHA |
|
| 576 | - * @param bool $ig_func |
|
| 577 | - * @return string Le SHA de la chaîne |
|
| 578 | - */ |
|
| 579 | - function sha256($str, $ig_func = true) { return _nano_sha256($str, $ig_func); } |
|
| 572 | + /** |
|
| 573 | + * Calcul du SHA256 |
|
| 574 | + * |
|
| 575 | + * @param string $str Chaîne dont on veut calculer le SHA |
|
| 576 | + * @param bool $ig_func |
|
| 577 | + * @return string Le SHA de la chaîne |
|
| 578 | + */ |
|
| 579 | + function sha256($str, $ig_func = true) { return _nano_sha256($str, $ig_func); } |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | // support to give php4 the hash() routine which abstracts this code. |
| 583 | 583 | if (!function_exists('hash')) { |
| 584 | - define('_NO_HASH_DEFINED', true); |
|
| 585 | - /** |
|
| 586 | - * Retourne le calcul d'un hachage d'une chaîne (pour PHP4) |
|
| 587 | - * |
|
| 588 | - * @param string $algo Nom de l'algorythme de hachage |
|
| 589 | - * @param string $data Chaîne à hacher |
|
| 590 | - * @return string|bool |
|
| 591 | - * Hash de la chaîne |
|
| 592 | - * False si pas d'algo trouvé |
|
| 593 | - */ |
|
| 594 | - function hash($algo, $data) { |
|
| 595 | - if (empty($algo) || !is_string($algo) || !is_string($data)) { |
|
| 596 | - return false; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - if (function_exists($algo)) { |
|
| 600 | - return $algo($data); |
|
| 601 | - } |
|
| 602 | - } |
|
| 584 | + define('_NO_HASH_DEFINED', true); |
|
| 585 | + /** |
|
| 586 | + * Retourne le calcul d'un hachage d'une chaîne (pour PHP4) |
|
| 587 | + * |
|
| 588 | + * @param string $algo Nom de l'algorythme de hachage |
|
| 589 | + * @param string $data Chaîne à hacher |
|
| 590 | + * @return string|bool |
|
| 591 | + * Hash de la chaîne |
|
| 592 | + * False si pas d'algo trouvé |
|
| 593 | + */ |
|
| 594 | + function hash($algo, $data) { |
|
| 595 | + if (empty($algo) || !is_string($algo) || !is_string($data)) { |
|
| 596 | + return false; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + if (function_exists($algo)) { |
|
| 600 | + return $algo($data); |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | 603 | } |
| 604 | 604 | \ No newline at end of file |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | : ((defined('_NANO_SHA2_UPPER')) ? true : false); |
| 99 | 99 | |
| 100 | 100 | // Deteremine if the system is 32 or 64 bit. |
| 101 | - $tmpInt = (int)4294967295; |
|
| 101 | + $tmpInt = (int) 4294967295; |
|
| 102 | 102 | $this->platform = ($tmpInt > 0) ? 64 : 32; |
| 103 | 103 | } |
| 104 | 104 | |
@@ -116,15 +116,15 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | if ($x < 0) { |
| 118 | 118 | $x &= 0x7FFFFFFF; |
| 119 | - $x = (float)$x+$mask; |
|
| 119 | + $x = (float) $x + $mask; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if ($y < 0) { |
| 123 | 123 | $y &= 0x7FFFFFFF; |
| 124 | - $y = (float)$y+$mask; |
|
| 124 | + $y = (float) $y + $mask; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - $r = $x+$y; |
|
| 127 | + $r = $x + $y; |
|
| 128 | 128 | |
| 129 | 129 | if ($r >= $n) { |
| 130 | 130 | while ($r >= $n) { |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - return (int)$r; |
|
| 135 | + return (int) $r; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -145,23 +145,23 @@ discard block |
||
| 145 | 145 | function SHR($x, $n) // x >> n |
| 146 | 146 | { |
| 147 | 147 | if ($n >= 32) { // impose some limits to keep it 32-bit |
| 148 | - return (int)0; |
|
| 148 | + return (int) 0; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | if ($n <= 0) { |
| 152 | - return (int)$x; |
|
| 152 | + return (int) $x; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | $mask = 0x40000000; |
| 156 | 156 | |
| 157 | 157 | if ($x < 0) { |
| 158 | 158 | $x &= 0x7FFFFFFF; |
| 159 | - $mask = $mask >> ($n-1); |
|
| 159 | + $mask = $mask >> ($n - 1); |
|
| 160 | 160 | |
| 161 | 161 | return ($x >> $n) | $mask; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - return (int)$x >> (int)$n; |
|
| 164 | + return (int) $x >> (int) $n; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** ROTR |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @param int $n |
| 171 | 171 | * @return int |
| 172 | 172 | */ |
| 173 | - function ROTR($x, $n) { return (int)(($this->SHR($x, $n) | ($x << (32-$n)) & 0xFFFFFFFF)); } |
|
| 173 | + function ROTR($x, $n) { return (int) (($this->SHR($x, $n) | ($x << (32 - $n)) & 0xFFFFFFFF)); } |
|
| 174 | 174 | |
| 175 | 175 | /** Ch |
| 176 | 176 | * |
@@ -195,28 +195,28 @@ discard block |
||
| 195 | 195 | * @param int $x |
| 196 | 196 | * @return int |
| 197 | 197 | */ |
| 198 | - function Sigma0($x) { return (int)($this->ROTR($x, 2) ^ $this->ROTR($x, 13) ^ $this->ROTR($x, 22)); } |
|
| 198 | + function Sigma0($x) { return (int) ($this->ROTR($x, 2) ^ $this->ROTR($x, 13) ^ $this->ROTR($x, 22)); } |
|
| 199 | 199 | |
| 200 | 200 | /** Sigma1 |
| 201 | 201 | * |
| 202 | 202 | * @param int $x |
| 203 | 203 | * @return int |
| 204 | 204 | */ |
| 205 | - function Sigma1($x) { return (int)($this->ROTR($x, 6) ^ $this->ROTR($x, 11) ^ $this->ROTR($x, 25)); } |
|
| 205 | + function Sigma1($x) { return (int) ($this->ROTR($x, 6) ^ $this->ROTR($x, 11) ^ $this->ROTR($x, 25)); } |
|
| 206 | 206 | |
| 207 | 207 | /** Sigma_0 |
| 208 | 208 | * |
| 209 | 209 | * @param int $x |
| 210 | 210 | * @return int |
| 211 | 211 | */ |
| 212 | - function sigma_0($x) { return (int)($this->ROTR($x, 7) ^ $this->ROTR($x, 18) ^ $this->SHR($x, 3)); } |
|
| 212 | + function sigma_0($x) { return (int) ($this->ROTR($x, 7) ^ $this->ROTR($x, 18) ^ $this->SHR($x, 3)); } |
|
| 213 | 213 | |
| 214 | 214 | /** Sigma_1 |
| 215 | 215 | * |
| 216 | 216 | * @param int $x |
| 217 | 217 | * @return int |
| 218 | 218 | */ |
| 219 | - function sigma_1($x) { return (int)($this->ROTR($x, 17) ^ $this->ROTR($x, 19) ^ $this->SHR($x, 10)); } |
|
| 219 | + function sigma_1($x) { return (int) ($this->ROTR($x, 17) ^ $this->ROTR($x, 19) ^ $this->SHR($x, 10)); } |
|
| 220 | 220 | |
| 221 | 221 | /** String 2 ord UTF8 |
| 222 | 222 | * |
@@ -271,23 +271,23 @@ discard block |
||
| 271 | 271 | |
| 272 | 272 | return $h; |
| 273 | 273 | } else { |
| 274 | - if ($h <= 0xDF && $index < $len-1) { |
|
| 274 | + if ($h <= 0xDF && $index < $len - 1) { |
|
| 275 | 275 | $bytes = 2; |
| 276 | 276 | |
| 277 | - return ($h & 0x1F) << 6 | (ord($c{$index+1}) & 0x3F); |
|
| 277 | + return ($h & 0x1F) << 6 | (ord($c{$index + 1}) & 0x3F); |
|
| 278 | 278 | } else { |
| 279 | - if ($h <= 0xEF && $index < $len-2) { |
|
| 279 | + if ($h <= 0xEF && $index < $len - 2) { |
|
| 280 | 280 | $bytes = 3; |
| 281 | 281 | |
| 282 | - return ($h & 0x0F) << 12 | (ord($c{$index+1}) & 0x3F) << 6 |
|
| 283 | - | (ord($c{$index+2}) & 0x3F); |
|
| 282 | + return ($h & 0x0F) << 12 | (ord($c{$index + 1}) & 0x3F) << 6 |
|
| 283 | + | (ord($c{$index + 2}) & 0x3F); |
|
| 284 | 284 | } else { |
| 285 | - if ($h <= 0xF4 && $index < $len-3) { |
|
| 285 | + if ($h <= 0xF4 && $index < $len - 3) { |
|
| 286 | 286 | $bytes = 4; |
| 287 | 287 | |
| 288 | - return ($h & 0x0F) << 18 | (ord($c{$index+1}) & 0x3F) << 12 |
|
| 289 | - | (ord($c{$index+2}) & 0x3F) << 6 |
|
| 290 | - | (ord($c{$index+3}) & 0x3F); |
|
| 288 | + return ($h & 0x0F) << 18 | (ord($c{$index + 1}) & 0x3F) << 12 |
|
| 289 | + | (ord($c{$index + 2}) & 0x3F) << 6 |
|
| 290 | + | (ord($c{$index + 3}) & 0x3F); |
|
| 291 | 291 | } else { |
| 292 | 292 | // pas utf mais renvoyer quand meme ce qu'on a |
| 293 | 293 | $bytes = 1; |
@@ -309,19 +309,19 @@ discard block |
||
| 309 | 309 | function string2binint($str, $npad = 512) { |
| 310 | 310 | $bin = array(); |
| 311 | 311 | $ords = $this->string2ordUTF8($str, $this->bytesString); |
| 312 | - $npad = $npad/$this->bytesString; |
|
| 312 | + $npad = $npad / $this->bytesString; |
|
| 313 | 313 | $length = count($ords); |
| 314 | 314 | $ords[] = 0x80; // append the "1" bit followed by 7 0's |
| 315 | - $pad = ceil(($length+1+32/$this->bytesString)/$npad)*$npad-32/$this->bytesString; |
|
| 315 | + $pad = ceil(($length + 1 + 32 / $this->bytesString) / $npad) * $npad - 32 / $this->bytesString; |
|
| 316 | 316 | $ords = array_pad($ords, $pad, 0); |
| 317 | - $mask = (1 << $this->bytesString)-1; |
|
| 318 | - for ($i = 0; $i < count($ords)*$this->bytesString; $i += $this->bytesString) { |
|
| 317 | + $mask = (1 << $this->bytesString) - 1; |
|
| 318 | + for ($i = 0; $i < count($ords) * $this->bytesString; $i += $this->bytesString) { |
|
| 319 | 319 | if (!isset($bin[$i >> 5])) { |
| 320 | 320 | $bin[$i >> 5] = 0; |
| 321 | 321 | } // pour eviter des notices. |
| 322 | - $bin[$i >> 5] |= ($ords[$i/$this->bytesString] & $mask) << (24-$i%32); |
|
| 322 | + $bin[$i >> 5] |= ($ords[$i / $this->bytesString] & $mask) << (24 - $i % 32); |
|
| 323 | 323 | } |
| 324 | - $bin[] = $length*$this->bytesString; |
|
| 324 | + $bin[] = $length * $this->bytesString; |
|
| 325 | 325 | |
| 326 | 326 | return $bin; |
| 327 | 327 | } |
@@ -357,8 +357,8 @@ discard block |
||
| 357 | 357 | * @return string Hexadecimal representation of the message digest |
| 358 | 358 | */ |
| 359 | 359 | function hash($str, $ig_func = true) { |
| 360 | - unset($binStr); // binary representation of input string |
|
| 361 | - unset($hexStr); // 256-bit message digest in readable hex format |
|
| 360 | + unset($binStr); // binary representation of input string |
|
| 361 | + unset($hexStr); // 256-bit message digest in readable hex format |
|
| 362 | 362 | |
| 363 | 363 | // check for php's internal sha256 function, ignore if ig_func==true |
| 364 | 364 | if ($ig_func == false) { |
@@ -378,70 +378,70 @@ discard block |
||
| 378 | 378 | * of the first sixtyfour prime numbers. |
| 379 | 379 | */ |
| 380 | 380 | $K = array( |
| 381 | - (int)0x428a2f98, |
|
| 382 | - (int)0x71374491, |
|
| 383 | - (int)0xb5c0fbcf, |
|
| 384 | - (int)0xe9b5dba5, |
|
| 385 | - (int)0x3956c25b, |
|
| 386 | - (int)0x59f111f1, |
|
| 387 | - (int)0x923f82a4, |
|
| 388 | - (int)0xab1c5ed5, |
|
| 389 | - (int)0xd807aa98, |
|
| 390 | - (int)0x12835b01, |
|
| 391 | - (int)0x243185be, |
|
| 392 | - (int)0x550c7dc3, |
|
| 393 | - (int)0x72be5d74, |
|
| 394 | - (int)0x80deb1fe, |
|
| 395 | - (int)0x9bdc06a7, |
|
| 396 | - (int)0xc19bf174, |
|
| 397 | - (int)0xe49b69c1, |
|
| 398 | - (int)0xefbe4786, |
|
| 399 | - (int)0x0fc19dc6, |
|
| 400 | - (int)0x240ca1cc, |
|
| 401 | - (int)0x2de92c6f, |
|
| 402 | - (int)0x4a7484aa, |
|
| 403 | - (int)0x5cb0a9dc, |
|
| 404 | - (int)0x76f988da, |
|
| 405 | - (int)0x983e5152, |
|
| 406 | - (int)0xa831c66d, |
|
| 407 | - (int)0xb00327c8, |
|
| 408 | - (int)0xbf597fc7, |
|
| 409 | - (int)0xc6e00bf3, |
|
| 410 | - (int)0xd5a79147, |
|
| 411 | - (int)0x06ca6351, |
|
| 412 | - (int)0x14292967, |
|
| 413 | - (int)0x27b70a85, |
|
| 414 | - (int)0x2e1b2138, |
|
| 415 | - (int)0x4d2c6dfc, |
|
| 416 | - (int)0x53380d13, |
|
| 417 | - (int)0x650a7354, |
|
| 418 | - (int)0x766a0abb, |
|
| 419 | - (int)0x81c2c92e, |
|
| 420 | - (int)0x92722c85, |
|
| 421 | - (int)0xa2bfe8a1, |
|
| 422 | - (int)0xa81a664b, |
|
| 423 | - (int)0xc24b8b70, |
|
| 424 | - (int)0xc76c51a3, |
|
| 425 | - (int)0xd192e819, |
|
| 426 | - (int)0xd6990624, |
|
| 427 | - (int)0xf40e3585, |
|
| 428 | - (int)0x106aa070, |
|
| 429 | - (int)0x19a4c116, |
|
| 430 | - (int)0x1e376c08, |
|
| 431 | - (int)0x2748774c, |
|
| 432 | - (int)0x34b0bcb5, |
|
| 433 | - (int)0x391c0cb3, |
|
| 434 | - (int)0x4ed8aa4a, |
|
| 435 | - (int)0x5b9cca4f, |
|
| 436 | - (int)0x682e6ff3, |
|
| 437 | - (int)0x748f82ee, |
|
| 438 | - (int)0x78a5636f, |
|
| 439 | - (int)0x84c87814, |
|
| 440 | - (int)0x8cc70208, |
|
| 441 | - (int)0x90befffa, |
|
| 442 | - (int)0xa4506ceb, |
|
| 443 | - (int)0xbef9a3f7, |
|
| 444 | - (int)0xc67178f2 |
|
| 381 | + (int) 0x428a2f98, |
|
| 382 | + (int) 0x71374491, |
|
| 383 | + (int) 0xb5c0fbcf, |
|
| 384 | + (int) 0xe9b5dba5, |
|
| 385 | + (int) 0x3956c25b, |
|
| 386 | + (int) 0x59f111f1, |
|
| 387 | + (int) 0x923f82a4, |
|
| 388 | + (int) 0xab1c5ed5, |
|
| 389 | + (int) 0xd807aa98, |
|
| 390 | + (int) 0x12835b01, |
|
| 391 | + (int) 0x243185be, |
|
| 392 | + (int) 0x550c7dc3, |
|
| 393 | + (int) 0x72be5d74, |
|
| 394 | + (int) 0x80deb1fe, |
|
| 395 | + (int) 0x9bdc06a7, |
|
| 396 | + (int) 0xc19bf174, |
|
| 397 | + (int) 0xe49b69c1, |
|
| 398 | + (int) 0xefbe4786, |
|
| 399 | + (int) 0x0fc19dc6, |
|
| 400 | + (int) 0x240ca1cc, |
|
| 401 | + (int) 0x2de92c6f, |
|
| 402 | + (int) 0x4a7484aa, |
|
| 403 | + (int) 0x5cb0a9dc, |
|
| 404 | + (int) 0x76f988da, |
|
| 405 | + (int) 0x983e5152, |
|
| 406 | + (int) 0xa831c66d, |
|
| 407 | + (int) 0xb00327c8, |
|
| 408 | + (int) 0xbf597fc7, |
|
| 409 | + (int) 0xc6e00bf3, |
|
| 410 | + (int) 0xd5a79147, |
|
| 411 | + (int) 0x06ca6351, |
|
| 412 | + (int) 0x14292967, |
|
| 413 | + (int) 0x27b70a85, |
|
| 414 | + (int) 0x2e1b2138, |
|
| 415 | + (int) 0x4d2c6dfc, |
|
| 416 | + (int) 0x53380d13, |
|
| 417 | + (int) 0x650a7354, |
|
| 418 | + (int) 0x766a0abb, |
|
| 419 | + (int) 0x81c2c92e, |
|
| 420 | + (int) 0x92722c85, |
|
| 421 | + (int) 0xa2bfe8a1, |
|
| 422 | + (int) 0xa81a664b, |
|
| 423 | + (int) 0xc24b8b70, |
|
| 424 | + (int) 0xc76c51a3, |
|
| 425 | + (int) 0xd192e819, |
|
| 426 | + (int) 0xd6990624, |
|
| 427 | + (int) 0xf40e3585, |
|
| 428 | + (int) 0x106aa070, |
|
| 429 | + (int) 0x19a4c116, |
|
| 430 | + (int) 0x1e376c08, |
|
| 431 | + (int) 0x2748774c, |
|
| 432 | + (int) 0x34b0bcb5, |
|
| 433 | + (int) 0x391c0cb3, |
|
| 434 | + (int) 0x4ed8aa4a, |
|
| 435 | + (int) 0x5b9cca4f, |
|
| 436 | + (int) 0x682e6ff3, |
|
| 437 | + (int) 0x748f82ee, |
|
| 438 | + (int) 0x78a5636f, |
|
| 439 | + (int) 0x84c87814, |
|
| 440 | + (int) 0x8cc70208, |
|
| 441 | + (int) 0x90befffa, |
|
| 442 | + (int) 0xa4506ceb, |
|
| 443 | + (int) 0xbef9a3f7, |
|
| 444 | + (int) 0xc67178f2 |
|
| 445 | 445 | ); |
| 446 | 446 | |
| 447 | 447 | // Pre-processing: Padding the string |
@@ -451,14 +451,14 @@ discard block |
||
| 451 | 451 | $M = $this->array_split($binStr, 16); |
| 452 | 452 | |
| 453 | 453 | // Set the initial hash values |
| 454 | - $h[0] = (int)0x6a09e667; |
|
| 455 | - $h[1] = (int)0xbb67ae85; |
|
| 456 | - $h[2] = (int)0x3c6ef372; |
|
| 457 | - $h[3] = (int)0xa54ff53a; |
|
| 458 | - $h[4] = (int)0x510e527f; |
|
| 459 | - $h[5] = (int)0x9b05688c; |
|
| 460 | - $h[6] = (int)0x1f83d9ab; |
|
| 461 | - $h[7] = (int)0x5be0cd19; |
|
| 454 | + $h[0] = (int) 0x6a09e667; |
|
| 455 | + $h[1] = (int) 0xbb67ae85; |
|
| 456 | + $h[2] = (int) 0x3c6ef372; |
|
| 457 | + $h[3] = (int) 0xa54ff53a; |
|
| 458 | + $h[4] = (int) 0x510e527f; |
|
| 459 | + $h[5] = (int) 0x9b05688c; |
|
| 460 | + $h[6] = (int) 0x1f83d9ab; |
|
| 461 | + $h[7] = (int) 0x5be0cd19; |
|
| 462 | 462 | |
| 463 | 463 | // loop through message blocks and compute hash. ( For i=1 to N : ) |
| 464 | 464 | $N = count($M); |
@@ -467,14 +467,14 @@ discard block |
||
| 467 | 467 | $MI = $M[$i]; |
| 468 | 468 | |
| 469 | 469 | // Initialize working variables |
| 470 | - $_a = (int)$h[0]; |
|
| 471 | - $_b = (int)$h[1]; |
|
| 472 | - $_c = (int)$h[2]; |
|
| 473 | - $_d = (int)$h[3]; |
|
| 474 | - $_e = (int)$h[4]; |
|
| 475 | - $_f = (int)$h[5]; |
|
| 476 | - $_g = (int)$h[6]; |
|
| 477 | - $_h = (int)$h[7]; |
|
| 470 | + $_a = (int) $h[0]; |
|
| 471 | + $_b = (int) $h[1]; |
|
| 472 | + $_c = (int) $h[2]; |
|
| 473 | + $_d = (int) $h[3]; |
|
| 474 | + $_e = (int) $h[4]; |
|
| 475 | + $_f = (int) $h[5]; |
|
| 476 | + $_g = (int) $h[6]; |
|
| 477 | + $_h = (int) $h[7]; |
|
| 478 | 478 | unset($_s0); |
| 479 | 479 | unset($_s1); |
| 480 | 480 | unset($_T1); |
@@ -504,12 +504,12 @@ discard block |
||
| 504 | 504 | |
| 505 | 505 | for (; $t < 64; $t++) { |
| 506 | 506 | // Continue building the message schedule as we loop |
| 507 | - $_s0 = $W[($t+1) & 0x0F]; |
|
| 507 | + $_s0 = $W[($t + 1) & 0x0F]; |
|
| 508 | 508 | $_s0 = $this->sigma_0($_s0); |
| 509 | - $_s1 = $W[($t+14) & 0x0F]; |
|
| 509 | + $_s1 = $W[($t + 14) & 0x0F]; |
|
| 510 | 510 | $_s1 = $this->sigma_1($_s1); |
| 511 | 511 | |
| 512 | - $W[$t & 0xF] = $this->addmod2n($this->addmod2n($this->addmod2n($W[$t & 0xF], $_s0), $_s1), $W[($t+9) & 0x0F]); |
|
| 512 | + $W[$t & 0xF] = $this->addmod2n($this->addmod2n($this->addmod2n($W[$t & 0xF], $_s0), $_s1), $W[($t + 9) & 0x0F]); |
|
| 513 | 513 | |
| 514 | 514 | // Compute hash |
| 515 | 515 | $_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)), |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @param bool|string $stat |
| 85 | 85 | * true, false ou le statut déjà défini si traitements enchaînés. |
| 86 | - * @return bool |
|
| 86 | + * @return false|null |
|
| 87 | 87 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 88 | 88 | */ |
| 89 | 89 | function statut_effacer_images_temporaires($stat) { |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | * |
| 555 | 555 | * @uses statut_effacer_images_temporaires() |
| 556 | 556 | * |
| 557 | - * @param ressource $img |
|
| 557 | + * @param resource $img |
|
| 558 | 558 | * Une ressource de type Image GD. |
| 559 | 559 | * @param array $valeurs |
| 560 | 560 | * Un tableau des informations (tailles, traitement, path...) accompagnant |
@@ -1400,7 +1400,7 @@ discard block |
||
| 1400 | 1400 | /** |
| 1401 | 1401 | * Transforme une ressource GD en image au format ICO |
| 1402 | 1402 | * |
| 1403 | - * @param array $gd_image_array |
|
| 1403 | + * @param Ressource[] $gd_image_array |
|
| 1404 | 1404 | * Tableau de ressources d'images GD |
| 1405 | 1405 | * @return string |
| 1406 | 1406 | * Image au format ICO |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | include_spip('inc/filtres'); // par precaution |
| 25 | 25 | include_spip('inc/filtres_images_mini'); // par precaution |
@@ -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,13 +63,13 @@ 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 = couleur_html_to_hex($couleur); |
|
| 67 | - $couleur = preg_replace(",^#,", "", $couleur); |
|
| 68 | - $retour["red"] = hexdec(substr($couleur, 0, 2)); |
|
| 69 | - $retour["green"] = hexdec(substr($couleur, 2, 2)); |
|
| 70 | - $retour["blue"] = hexdec(substr($couleur, 4, 2)); |
|
| 66 | + $couleur = couleur_html_to_hex($couleur); |
|
| 67 | + $couleur = preg_replace(",^#,", "", $couleur); |
|
| 68 | + $retour["red"] = hexdec(substr($couleur, 0, 2)); |
|
| 69 | + $retour["green"] = hexdec(substr($couleur, 2, 2)); |
|
| 70 | + $retour["blue"] = hexdec(substr($couleur, 4, 2)); |
|
| 71 | 71 | |
| 72 | - return $retour; |
|
| 72 | + return $retour; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 88 | 88 | */ |
| 89 | 89 | function statut_effacer_images_temporaires($stat) { |
| 90 | - static $statut = false; // par defaut on grave toute les images |
|
| 91 | - if ($stat === 'get') { |
|
| 92 | - return $statut; |
|
| 93 | - } |
|
| 94 | - $statut = $stat ? true : false; |
|
| 90 | + static $statut = false; // par defaut on grave toute les images |
|
| 91 | + if ($stat === 'get') { |
|
| 92 | + return $statut; |
|
| 93 | + } |
|
| 94 | + $statut = $stat ? true : false; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -137,224 +137,224 @@ discard block |
||
| 137 | 137 | * - array : tableau décrivant de l'image |
| 138 | 138 | */ |
| 139 | 139 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false) { |
| 140 | - static $images_recalcul = array(); |
|
| 141 | - if (strlen($img) == 0) { |
|
| 142 | - return false; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $source = trim(extraire_attribut($img, 'src')); |
|
| 146 | - if (strlen($source) < 1) { |
|
| 147 | - $source = $img; |
|
| 148 | - $img = "<img src='$source' />"; |
|
| 149 | - } # gerer img src="data:....base64" |
|
| 150 | - elseif (preg_match('@^data:image/(jpe?g|png|gif);base64,(.*)$@isS', $source, $regs)) { |
|
| 151 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . str_replace('jpeg', 'jpg', $regs[1]); |
|
| 152 | - if (!file_exists($local)) { |
|
| 153 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 154 | - } |
|
| 155 | - $source = $local; |
|
| 156 | - $img = inserer_attribut($img, 'src', $source); |
|
| 157 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 158 | - $img = inserer_attribut($img, 'width', ''); |
|
| 159 | - $img = inserer_attribut($img, 'height', ''); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // les protocoles web prennent au moins 3 lettres |
|
| 163 | - if (tester_url_absolue($source)) { |
|
| 164 | - include_spip('inc/distant'); |
|
| 165 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 166 | - if (!$fichier) { |
|
| 167 | - return ""; |
|
| 168 | - } |
|
| 169 | - } else { |
|
| 170 | - // enlever le timestamp eventuel |
|
| 171 | - if (strpos($source, "?") !== false) { |
|
| 172 | - $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 173 | - } |
|
| 174 | - if (strpos($source, "?") !== false |
|
| 175 | - and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 176 | - and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 177 | - ) { |
|
| 178 | - $source = $f; |
|
| 179 | - } |
|
| 180 | - $fichier = $source; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $terminaison = $terminaison_dest = ""; |
|
| 184 | - if (preg_match(",\.(gif|jpe?g|png)($|[?]),i", $fichier, $regs)) { |
|
| 185 | - $terminaison = strtolower($regs[1]); |
|
| 186 | - $terminaison_dest = $terminaison; |
|
| 187 | - |
|
| 188 | - if ($terminaison == "gif") { |
|
| 189 | - $terminaison_dest = "png"; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - if ($forcer_format !== false) { |
|
| 193 | - $terminaison_dest = $forcer_format; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (!$terminaison_dest) { |
|
| 197 | - return false; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $term_fonction = $terminaison; |
|
| 201 | - if ($term_fonction == "jpg") { |
|
| 202 | - $term_fonction = "jpeg"; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 206 | - $fichier_dest = $nom_fichier; |
|
| 207 | - if (($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 208 | - or @file_exists($f = $fichier) |
|
| 209 | - ) { |
|
| 210 | - // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 211 | - // au lieu de faire un acces disque sur le fichier |
|
| 212 | - list($ret["hauteur"], $ret["largeur"]) = taille_image($find_in_path ? $f : $img); |
|
| 213 | - $date_src = @filemtime($f); |
|
| 214 | - } elseif (@file_exists($f = "$fichier.src") |
|
| 215 | - and lire_fichier($f, $valeurs) |
|
| 216 | - and $valeurs = unserialize($valeurs) |
|
| 217 | - and isset($valeurs["hauteur_dest"]) |
|
| 218 | - and isset($valeurs["largeur_dest"]) |
|
| 219 | - ) { |
|
| 220 | - $ret["hauteur"] = $valeurs["hauteur_dest"]; |
|
| 221 | - $ret["largeur"] = $valeurs["largeur_dest"]; |
|
| 222 | - $date_src = $valeurs["date"]; |
|
| 223 | - } // pas de fichier source par la |
|
| 224 | - else { |
|
| 225 | - return false; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // pas de taille mesurable |
|
| 229 | - if (!($ret["hauteur"] or $ret["largeur"])) { |
|
| 230 | - return false; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // les images calculees dependent du chemin du fichier source |
|
| 234 | - // 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 |
|
| 235 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 236 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 237 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 238 | - // alors que ca concerne peu de site au final |
|
| 239 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 240 | - $identifiant = $fichier; |
|
| 241 | - |
|
| 242 | - // cas general : |
|
| 243 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 244 | - // cas particulier de reduire : |
|
| 245 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 246 | - $cache = "cache-gd2"; |
|
| 247 | - if (substr($effet, 0, 7) == 'reduire') { |
|
| 248 | - list(, $maxWidth, $maxHeight) = explode('-', $effet); |
|
| 249 | - list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 250 | - $ret['largeur_dest'] = $destWidth; |
|
| 251 | - $ret['hauteur_dest'] = $destHeight; |
|
| 252 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 253 | - $cache = "cache-vignettes"; |
|
| 254 | - $fichier_dest = basename($fichier_dest); |
|
| 255 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 256 | - // on garde la terminaison initiale car image simplement copiee |
|
| 257 | - // et on postfixe son nom avec un md5 du path |
|
| 258 | - $terminaison_dest = $terminaison; |
|
| 259 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 260 | - } else { |
|
| 261 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 262 | - } |
|
| 263 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 264 | - $cache = sous_repertoire($cache, $effet); |
|
| 265 | - # cherche un cache existant |
|
| 266 | - /*foreach (array('gif','jpg','png') as $fmt) |
|
| 140 | + static $images_recalcul = array(); |
|
| 141 | + if (strlen($img) == 0) { |
|
| 142 | + return false; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $source = trim(extraire_attribut($img, 'src')); |
|
| 146 | + if (strlen($source) < 1) { |
|
| 147 | + $source = $img; |
|
| 148 | + $img = "<img src='$source' />"; |
|
| 149 | + } # gerer img src="data:....base64" |
|
| 150 | + elseif (preg_match('@^data:image/(jpe?g|png|gif);base64,(.*)$@isS', $source, $regs)) { |
|
| 151 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . str_replace('jpeg', 'jpg', $regs[1]); |
|
| 152 | + if (!file_exists($local)) { |
|
| 153 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 154 | + } |
|
| 155 | + $source = $local; |
|
| 156 | + $img = inserer_attribut($img, 'src', $source); |
|
| 157 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 158 | + $img = inserer_attribut($img, 'width', ''); |
|
| 159 | + $img = inserer_attribut($img, 'height', ''); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // les protocoles web prennent au moins 3 lettres |
|
| 163 | + if (tester_url_absolue($source)) { |
|
| 164 | + include_spip('inc/distant'); |
|
| 165 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 166 | + if (!$fichier) { |
|
| 167 | + return ""; |
|
| 168 | + } |
|
| 169 | + } else { |
|
| 170 | + // enlever le timestamp eventuel |
|
| 171 | + if (strpos($source, "?") !== false) { |
|
| 172 | + $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 173 | + } |
|
| 174 | + if (strpos($source, "?") !== false |
|
| 175 | + and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 176 | + and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 177 | + ) { |
|
| 178 | + $source = $f; |
|
| 179 | + } |
|
| 180 | + $fichier = $source; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $terminaison = $terminaison_dest = ""; |
|
| 184 | + if (preg_match(",\.(gif|jpe?g|png)($|[?]),i", $fichier, $regs)) { |
|
| 185 | + $terminaison = strtolower($regs[1]); |
|
| 186 | + $terminaison_dest = $terminaison; |
|
| 187 | + |
|
| 188 | + if ($terminaison == "gif") { |
|
| 189 | + $terminaison_dest = "png"; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + if ($forcer_format !== false) { |
|
| 193 | + $terminaison_dest = $forcer_format; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (!$terminaison_dest) { |
|
| 197 | + return false; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $term_fonction = $terminaison; |
|
| 201 | + if ($term_fonction == "jpg") { |
|
| 202 | + $term_fonction = "jpeg"; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 206 | + $fichier_dest = $nom_fichier; |
|
| 207 | + if (($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 208 | + or @file_exists($f = $fichier) |
|
| 209 | + ) { |
|
| 210 | + // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 211 | + // au lieu de faire un acces disque sur le fichier |
|
| 212 | + list($ret["hauteur"], $ret["largeur"]) = taille_image($find_in_path ? $f : $img); |
|
| 213 | + $date_src = @filemtime($f); |
|
| 214 | + } elseif (@file_exists($f = "$fichier.src") |
|
| 215 | + and lire_fichier($f, $valeurs) |
|
| 216 | + and $valeurs = unserialize($valeurs) |
|
| 217 | + and isset($valeurs["hauteur_dest"]) |
|
| 218 | + and isset($valeurs["largeur_dest"]) |
|
| 219 | + ) { |
|
| 220 | + $ret["hauteur"] = $valeurs["hauteur_dest"]; |
|
| 221 | + $ret["largeur"] = $valeurs["largeur_dest"]; |
|
| 222 | + $date_src = $valeurs["date"]; |
|
| 223 | + } // pas de fichier source par la |
|
| 224 | + else { |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // pas de taille mesurable |
|
| 229 | + if (!($ret["hauteur"] or $ret["largeur"])) { |
|
| 230 | + return false; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // les images calculees dependent du chemin du fichier source |
|
| 234 | + // 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 |
|
| 235 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 236 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 237 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 238 | + // alors que ca concerne peu de site au final |
|
| 239 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 240 | + $identifiant = $fichier; |
|
| 241 | + |
|
| 242 | + // cas general : |
|
| 243 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 244 | + // cas particulier de reduire : |
|
| 245 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 246 | + $cache = "cache-gd2"; |
|
| 247 | + if (substr($effet, 0, 7) == 'reduire') { |
|
| 248 | + list(, $maxWidth, $maxHeight) = explode('-', $effet); |
|
| 249 | + list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 250 | + $ret['largeur_dest'] = $destWidth; |
|
| 251 | + $ret['hauteur_dest'] = $destHeight; |
|
| 252 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 253 | + $cache = "cache-vignettes"; |
|
| 254 | + $fichier_dest = basename($fichier_dest); |
|
| 255 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 256 | + // on garde la terminaison initiale car image simplement copiee |
|
| 257 | + // et on postfixe son nom avec un md5 du path |
|
| 258 | + $terminaison_dest = $terminaison; |
|
| 259 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 260 | + } else { |
|
| 261 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 262 | + } |
|
| 263 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 264 | + $cache = sous_repertoire($cache, $effet); |
|
| 265 | + # cherche un cache existant |
|
| 266 | + /*foreach (array('gif','jpg','png') as $fmt) |
|
| 267 | 267 | if (@file_exists($cache . $fichier_dest . '.' . $fmt)) { |
| 268 | 268 | $terminaison_dest = $fmt; |
| 269 | 269 | }*/ |
| 270 | - } else { |
|
| 271 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 272 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 273 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 274 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - $fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest; |
|
| 278 | - |
|
| 279 | - $GLOBALS["images_calculees"][] = $fichier_dest; |
|
| 280 | - |
|
| 281 | - $creer = true; |
|
| 282 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 283 | - if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 284 | - $images_recalcul[$fichier_dest] = true; |
|
| 285 | - } else { |
|
| 286 | - if (@file_exists($f = $fichier_dest)) { |
|
| 287 | - if (filemtime($f) >= $date_src) { |
|
| 288 | - $creer = false; |
|
| 289 | - } |
|
| 290 | - } else { |
|
| 291 | - if (@file_exists($f = "$fichier_dest.src") |
|
| 292 | - and lire_fichier($f, $valeurs) |
|
| 293 | - and $valeurs = unserialize($valeurs) |
|
| 294 | - and $valeurs["date"] >= $date_src |
|
| 295 | - ) { |
|
| 296 | - $creer = false; |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - if ($creer) { |
|
| 301 | - if (!@file_exists($fichier)) { |
|
| 302 | - if (!@file_exists("$fichier.src")) { |
|
| 303 | - spip_log("Image absente : $fichier"); |
|
| 304 | - |
|
| 305 | - return false; |
|
| 306 | - } |
|
| 307 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 308 | - reconstruire_image_intermediaire($fichier); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - if ($creer) { |
|
| 313 | - spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 314 | - "images" . _LOG_DEBUG); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - // TODO: si une image png est nommee .jpg, le reconnaitre avec le bon $f |
|
| 318 | - $ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction; |
|
| 319 | - $ret["fichier"] = $fichier; |
|
| 320 | - $ret["fonction_image"] = "_image_image" . $terminaison_dest; |
|
| 321 | - $ret["fichier_dest"] = $fichier_dest; |
|
| 322 | - $ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg'); |
|
| 323 | - $ret["format_dest"] = $terminaison_dest; |
|
| 324 | - $ret["date_src"] = $date_src; |
|
| 325 | - $ret["creer"] = $creer; |
|
| 326 | - $ret["class"] = extraire_attribut($img, 'class'); |
|
| 327 | - $ret["alt"] = extraire_attribut($img, 'alt'); |
|
| 328 | - $ret["style"] = extraire_attribut($img, 'style'); |
|
| 329 | - $ret["tag"] = $img; |
|
| 330 | - if ($fonction_creation) { |
|
| 331 | - $ret["reconstruction"] = $fonction_creation; |
|
| 332 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 333 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 334 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 335 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $ret = pipeline('image_preparer_filtre', array( |
|
| 339 | - 'args' => array( |
|
| 340 | - 'img' => $img, |
|
| 341 | - 'effet' => $effet, |
|
| 342 | - 'forcer_format' => $forcer_format, |
|
| 343 | - 'fonction_creation' => $fonction_creation, |
|
| 344 | - 'find_in_path' => $find_in_path, |
|
| 345 | - ), |
|
| 346 | - 'data' => $ret |
|
| 347 | - ) |
|
| 348 | - ); |
|
| 349 | - |
|
| 350 | - // une globale pour le debug en cas de crash memoire |
|
| 351 | - $GLOBALS["derniere_image_calculee"] = $ret; |
|
| 352 | - |
|
| 353 | - if (!function_exists($ret["fonction_imagecreatefrom"])) { |
|
| 354 | - return false; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - return $ret; |
|
| 270 | + } else { |
|
| 271 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 272 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 273 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 274 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + $fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest; |
|
| 278 | + |
|
| 279 | + $GLOBALS["images_calculees"][] = $fichier_dest; |
|
| 280 | + |
|
| 281 | + $creer = true; |
|
| 282 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 283 | + if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 284 | + $images_recalcul[$fichier_dest] = true; |
|
| 285 | + } else { |
|
| 286 | + if (@file_exists($f = $fichier_dest)) { |
|
| 287 | + if (filemtime($f) >= $date_src) { |
|
| 288 | + $creer = false; |
|
| 289 | + } |
|
| 290 | + } else { |
|
| 291 | + if (@file_exists($f = "$fichier_dest.src") |
|
| 292 | + and lire_fichier($f, $valeurs) |
|
| 293 | + and $valeurs = unserialize($valeurs) |
|
| 294 | + and $valeurs["date"] >= $date_src |
|
| 295 | + ) { |
|
| 296 | + $creer = false; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + if ($creer) { |
|
| 301 | + if (!@file_exists($fichier)) { |
|
| 302 | + if (!@file_exists("$fichier.src")) { |
|
| 303 | + spip_log("Image absente : $fichier"); |
|
| 304 | + |
|
| 305 | + return false; |
|
| 306 | + } |
|
| 307 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 308 | + reconstruire_image_intermediaire($fichier); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + if ($creer) { |
|
| 313 | + spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 314 | + "images" . _LOG_DEBUG); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + // TODO: si une image png est nommee .jpg, le reconnaitre avec le bon $f |
|
| 318 | + $ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction; |
|
| 319 | + $ret["fichier"] = $fichier; |
|
| 320 | + $ret["fonction_image"] = "_image_image" . $terminaison_dest; |
|
| 321 | + $ret["fichier_dest"] = $fichier_dest; |
|
| 322 | + $ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg'); |
|
| 323 | + $ret["format_dest"] = $terminaison_dest; |
|
| 324 | + $ret["date_src"] = $date_src; |
|
| 325 | + $ret["creer"] = $creer; |
|
| 326 | + $ret["class"] = extraire_attribut($img, 'class'); |
|
| 327 | + $ret["alt"] = extraire_attribut($img, 'alt'); |
|
| 328 | + $ret["style"] = extraire_attribut($img, 'style'); |
|
| 329 | + $ret["tag"] = $img; |
|
| 330 | + if ($fonction_creation) { |
|
| 331 | + $ret["reconstruction"] = $fonction_creation; |
|
| 332 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 333 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 334 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 335 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + $ret = pipeline('image_preparer_filtre', array( |
|
| 339 | + 'args' => array( |
|
| 340 | + 'img' => $img, |
|
| 341 | + 'effet' => $effet, |
|
| 342 | + 'forcer_format' => $forcer_format, |
|
| 343 | + 'fonction_creation' => $fonction_creation, |
|
| 344 | + 'find_in_path' => $find_in_path, |
|
| 345 | + ), |
|
| 346 | + 'data' => $ret |
|
| 347 | + ) |
|
| 348 | + ); |
|
| 349 | + |
|
| 350 | + // une globale pour le debug en cas de crash memoire |
|
| 351 | + $GLOBALS["derniere_image_calculee"] = $ret; |
|
| 352 | + |
|
| 353 | + if (!function_exists($ret["fonction_imagecreatefrom"])) { |
|
| 354 | + return false; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + return $ret; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -369,14 +369,14 @@ discard block |
||
| 369 | 369 | * Une ressource de type Image GD. |
| 370 | 370 | */ |
| 371 | 371 | function _imagecreatefromjpeg($filename) { |
| 372 | - $img = @imagecreatefromjpeg($filename); |
|
| 373 | - if (!$img) { |
|
| 374 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 375 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 376 | - $img = imagecreate(10, 10); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - return $img; |
|
| 372 | + $img = @imagecreatefromjpeg($filename); |
|
| 373 | + if (!$img) { |
|
| 374 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 375 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 376 | + $img = imagecreate(10, 10); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + return $img; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | /** |
@@ -391,14 +391,14 @@ discard block |
||
| 391 | 391 | * Une ressource de type Image GD. |
| 392 | 392 | */ |
| 393 | 393 | function _imagecreatefrompng($filename) { |
| 394 | - $img = @imagecreatefrompng($filename); |
|
| 395 | - if (!$img) { |
|
| 396 | - spip_log("Erreur lecture imagecreatefrompng $filename", _LOG_CRITIQUE); |
|
| 397 | - erreur_squelette("Erreur lecture imagecreatefrompng $filename"); |
|
| 398 | - $img = imagecreate(10, 10); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - return $img; |
|
| 394 | + $img = @imagecreatefrompng($filename); |
|
| 395 | + if (!$img) { |
|
| 396 | + spip_log("Erreur lecture imagecreatefrompng $filename", _LOG_CRITIQUE); |
|
| 397 | + erreur_squelette("Erreur lecture imagecreatefrompng $filename"); |
|
| 398 | + $img = imagecreate(10, 10); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + return $img; |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
@@ -413,14 +413,14 @@ discard block |
||
| 413 | 413 | * Une ressource de type Image GD. |
| 414 | 414 | */ |
| 415 | 415 | function _imagecreatefromgif($filename) { |
| 416 | - $img = @imagecreatefromgif($filename); |
|
| 417 | - if (!$img) { |
|
| 418 | - spip_log("Erreur lecture imagecreatefromgif $filename", _LOG_CRITIQUE); |
|
| 419 | - erreur_squelette("Erreur lecture imagecreatefromgif $filename"); |
|
| 420 | - $img = imagecreate(10, 10); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return $img; |
|
| 416 | + $img = @imagecreatefromgif($filename); |
|
| 417 | + if (!$img) { |
|
| 418 | + spip_log("Erreur lecture imagecreatefromgif $filename", _LOG_CRITIQUE); |
|
| 419 | + erreur_squelette("Erreur lecture imagecreatefromgif $filename"); |
|
| 420 | + $img = imagecreate(10, 10); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return $img; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -438,24 +438,24 @@ discard block |
||
| 438 | 438 | * - true si une image est bien retournée. |
| 439 | 439 | */ |
| 440 | 440 | function _image_imagepng($img, $fichier) { |
| 441 | - if (!function_exists('imagepng')) { |
|
| 442 | - return false; |
|
| 443 | - } |
|
| 444 | - $tmp = $fichier . ".tmp"; |
|
| 445 | - $ret = imagepng($img, $tmp); |
|
| 446 | - if (file_exists($tmp)) { |
|
| 447 | - $taille_test = getimagesize($tmp); |
|
| 448 | - if ($taille_test[0] < 1) { |
|
| 449 | - return false; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 453 | - @rename($tmp, $fichier); |
|
| 454 | - |
|
| 455 | - return $ret; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - return false; |
|
| 441 | + if (!function_exists('imagepng')) { |
|
| 442 | + return false; |
|
| 443 | + } |
|
| 444 | + $tmp = $fichier . ".tmp"; |
|
| 445 | + $ret = imagepng($img, $tmp); |
|
| 446 | + if (file_exists($tmp)) { |
|
| 447 | + $taille_test = getimagesize($tmp); |
|
| 448 | + if ($taille_test[0] < 1) { |
|
| 449 | + return false; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 453 | + @rename($tmp, $fichier); |
|
| 454 | + |
|
| 455 | + return $ret; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + return false; |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -473,24 +473,24 @@ discard block |
||
| 473 | 473 | * - true si une image est bien retournée. |
| 474 | 474 | */ |
| 475 | 475 | function _image_imagegif($img, $fichier) { |
| 476 | - if (!function_exists('imagegif')) { |
|
| 477 | - return false; |
|
| 478 | - } |
|
| 479 | - $tmp = $fichier . ".tmp"; |
|
| 480 | - $ret = imagegif($img, $tmp); |
|
| 481 | - if (file_exists($tmp)) { |
|
| 482 | - $taille_test = getimagesize($tmp); |
|
| 483 | - if ($taille_test[0] < 1) { |
|
| 484 | - return false; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 488 | - @rename($tmp, $fichier); |
|
| 489 | - |
|
| 490 | - return $ret; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - return false; |
|
| 476 | + if (!function_exists('imagegif')) { |
|
| 477 | + return false; |
|
| 478 | + } |
|
| 479 | + $tmp = $fichier . ".tmp"; |
|
| 480 | + $ret = imagegif($img, $tmp); |
|
| 481 | + if (file_exists($tmp)) { |
|
| 482 | + $taille_test = getimagesize($tmp); |
|
| 483 | + if ($taille_test[0] < 1) { |
|
| 484 | + return false; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 488 | + @rename($tmp, $fichier); |
|
| 489 | + |
|
| 490 | + return $ret; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + return false; |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /** |
@@ -513,29 +513,29 @@ discard block |
||
| 513 | 513 | * - true si une image est bien retournée. |
| 514 | 514 | */ |
| 515 | 515 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 516 | - if (!function_exists('imagejpeg')) { |
|
| 517 | - return false; |
|
| 518 | - } |
|
| 519 | - $tmp = $fichier . ".tmp"; |
|
| 516 | + if (!function_exists('imagejpeg')) { |
|
| 517 | + return false; |
|
| 518 | + } |
|
| 519 | + $tmp = $fichier . ".tmp"; |
|
| 520 | 520 | |
| 521 | - // Enable interlancing |
|
| 522 | - imageinterlace($img, true); |
|
| 521 | + // Enable interlancing |
|
| 522 | + imageinterlace($img, true); |
|
| 523 | 523 | |
| 524 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 524 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 525 | 525 | |
| 526 | - if (file_exists($tmp)) { |
|
| 527 | - $taille_test = getimagesize($tmp); |
|
| 528 | - if ($taille_test[0] < 1) { |
|
| 529 | - return false; |
|
| 530 | - } |
|
| 526 | + if (file_exists($tmp)) { |
|
| 527 | + $taille_test = getimagesize($tmp); |
|
| 528 | + if ($taille_test[0] < 1) { |
|
| 529 | + return false; |
|
| 530 | + } |
|
| 531 | 531 | |
| 532 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 533 | - @rename($tmp, $fichier); |
|
| 532 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 533 | + @rename($tmp, $fichier); |
|
| 534 | 534 | |
| 535 | - return $ret; |
|
| 536 | - } |
|
| 535 | + return $ret; |
|
| 536 | + } |
|
| 537 | 537 | |
| 538 | - return false; |
|
| 538 | + return false; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /** |
@@ -553,9 +553,9 @@ discard block |
||
| 553 | 553 | * true si le fichier a bien été créé ; false sinon. |
| 554 | 554 | */ |
| 555 | 555 | function _image_imageico($img, $fichier) { |
| 556 | - $gd_image_array = array($img); |
|
| 556 | + $gd_image_array = array($img); |
|
| 557 | 557 | |
| 558 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 558 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | /** |
@@ -582,27 +582,27 @@ discard block |
||
| 582 | 582 | * - false sinon. |
| 583 | 583 | */ |
| 584 | 584 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE) { |
| 585 | - $fonction = "_image_image" . $valeurs['format_dest']; |
|
| 586 | - $ret = false; |
|
| 587 | - #un flag pour reperer les images gravees |
|
| 588 | - $lock = |
|
| 589 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 590 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 591 | - if ( |
|
| 592 | - function_exists($fonction) |
|
| 593 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 594 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 595 | - && !$lock |
|
| 596 | - ) { |
|
| 597 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 598 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 599 | - list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']); |
|
| 600 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 601 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - return $ret; |
|
| 585 | + $fonction = "_image_image" . $valeurs['format_dest']; |
|
| 586 | + $ret = false; |
|
| 587 | + #un flag pour reperer les images gravees |
|
| 588 | + $lock = |
|
| 589 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 590 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 591 | + if ( |
|
| 592 | + function_exists($fonction) |
|
| 593 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 594 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 595 | + && !$lock |
|
| 596 | + ) { |
|
| 597 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 598 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 599 | + list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']); |
|
| 600 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 601 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + return $ret; |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | /** |
@@ -615,26 +615,26 @@ discard block |
||
| 615 | 615 | * Chemin vers le fichier manquant |
| 616 | 616 | **/ |
| 617 | 617 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 618 | - $reconstruire = array(); |
|
| 619 | - $fichier = $fichier_manquant; |
|
| 620 | - while (strpos($fichier,"://")===false |
|
| 621 | - and !@file_exists($fichier) |
|
| 622 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 623 | - and $valeurs = unserialize($source) |
|
| 624 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 625 | - ) { |
|
| 626 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 627 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 628 | - } |
|
| 629 | - while (count($reconstruire)) { |
|
| 630 | - $r = array_pop($reconstruire); |
|
| 631 | - $fonction = $r[0]; |
|
| 632 | - $args = $r[1]; |
|
| 633 | - call_user_func_array($fonction, $args); |
|
| 634 | - } |
|
| 635 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 636 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 637 | - ramasse_miettes($fichier_manquant); |
|
| 618 | + $reconstruire = array(); |
|
| 619 | + $fichier = $fichier_manquant; |
|
| 620 | + while (strpos($fichier,"://")===false |
|
| 621 | + and !@file_exists($fichier) |
|
| 622 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 623 | + and $valeurs = unserialize($source) |
|
| 624 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 625 | + ) { |
|
| 626 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 627 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 628 | + } |
|
| 629 | + while (count($reconstruire)) { |
|
| 630 | + $r = array_pop($reconstruire); |
|
| 631 | + $fonction = $r[0]; |
|
| 632 | + $args = $r[1]; |
|
| 633 | + call_user_func_array($fonction, $args); |
|
| 634 | + } |
|
| 635 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 636 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 637 | + ramasse_miettes($fichier_manquant); |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | /** |
@@ -654,25 +654,25 @@ discard block |
||
| 654 | 654 | * Chemin du fichier d'image calculé |
| 655 | 655 | **/ |
| 656 | 656 | function ramasse_miettes($fichier) { |
| 657 | - if (strpos($fichier,"://")!==false |
|
| 658 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 659 | - or !$valeurs = unserialize($source) |
|
| 660 | - ) { |
|
| 661 | - return; |
|
| 662 | - } |
|
| 663 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 664 | - while ( |
|
| 665 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 666 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 667 | - and (lire_fichier($src = "$fichier.src", |
|
| 668 | - $source)) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 669 | - and ($valeurs = unserialize($source)) # et valide |
|
| 670 | - ) { |
|
| 671 | - # on efface le fichier |
|
| 672 | - spip_unlink($fichier); |
|
| 673 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 674 | - #spip_unlink($src); |
|
| 675 | - } |
|
| 657 | + if (strpos($fichier,"://")!==false |
|
| 658 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 659 | + or !$valeurs = unserialize($source) |
|
| 660 | + ) { |
|
| 661 | + return; |
|
| 662 | + } |
|
| 663 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 664 | + while ( |
|
| 665 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 666 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 667 | + and (lire_fichier($src = "$fichier.src", |
|
| 668 | + $source)) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 669 | + and ($valeurs = unserialize($source)) # et valide |
|
| 670 | + ) { |
|
| 671 | + # on efface le fichier |
|
| 672 | + spip_unlink($fichier); |
|
| 673 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 674 | + #spip_unlink($src); |
|
| 675 | + } |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | |
@@ -697,71 +697,71 @@ discard block |
||
| 697 | 697 | * Code HTML de l'image |
| 698 | 698 | **/ |
| 699 | 699 | function image_graver($img) { |
| 700 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 701 | - // des traitements auto a la fin d'une serie de filtres |
|
| 702 | - $img = pipeline('post_image_filtrer', $img); |
|
| 703 | - |
|
| 704 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 705 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 706 | - $fichier = substr($fichier, 0, $p); |
|
| 707 | - } |
|
| 708 | - if (strlen($fichier) < 1) { |
|
| 709 | - $fichier = $img; |
|
| 710 | - } |
|
| 711 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 712 | - # et qu'il ne s'agit pas d'une URL |
|
| 713 | - if (strpos($fichier,"://")===false and !@file_exists($fichier)) { |
|
| 714 | - reconstruire_image_intermediaire($fichier); |
|
| 715 | - } |
|
| 716 | - ramasse_miettes($fichier); |
|
| 717 | - |
|
| 718 | - // ajouter le timestamp si besoin |
|
| 719 | - if (strpos($fichier_ori, "?") === false) { |
|
| 720 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 721 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - return $img; |
|
| 700 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 701 | + // des traitements auto a la fin d'une serie de filtres |
|
| 702 | + $img = pipeline('post_image_filtrer', $img); |
|
| 703 | + |
|
| 704 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 705 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 706 | + $fichier = substr($fichier, 0, $p); |
|
| 707 | + } |
|
| 708 | + if (strlen($fichier) < 1) { |
|
| 709 | + $fichier = $img; |
|
| 710 | + } |
|
| 711 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 712 | + # et qu'il ne s'agit pas d'une URL |
|
| 713 | + if (strpos($fichier,"://")===false and !@file_exists($fichier)) { |
|
| 714 | + reconstruire_image_intermediaire($fichier); |
|
| 715 | + } |
|
| 716 | + ramasse_miettes($fichier); |
|
| 717 | + |
|
| 718 | + // ajouter le timestamp si besoin |
|
| 719 | + if (strpos($fichier_ori, "?") === false) { |
|
| 720 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 721 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + return $img; |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | |
| 728 | 728 | if (!function_exists("imagepalettetotruecolor")) { |
| 729 | - /** |
|
| 730 | - * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 731 | - * |
|
| 732 | - * @note Pour compatibilité avec PHP < 5.5 |
|
| 733 | - * |
|
| 734 | - * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 735 | - * |
|
| 736 | - * @param ressource $img |
|
| 737 | - * @return bool |
|
| 738 | - * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 739 | - * - false si la transformation ne peut être faite. |
|
| 740 | - **/ |
|
| 741 | - function imagepalettetotruecolor(&$img) { |
|
| 742 | - if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 743 | - return false; |
|
| 744 | - } elseif (!imageistruecolor($img)) { |
|
| 745 | - $w = imagesx($img); |
|
| 746 | - $h = imagesy($img); |
|
| 747 | - $img1 = imagecreatetruecolor($w, $h); |
|
| 748 | - //Conserver la transparence si possible |
|
| 749 | - if (function_exists('ImageCopyResampled')) { |
|
| 750 | - if (function_exists("imageAntiAlias")) { |
|
| 751 | - imageAntiAlias($img1, true); |
|
| 752 | - } |
|
| 753 | - @imagealphablending($img1, false); |
|
| 754 | - @imagesavealpha($img1, true); |
|
| 755 | - @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 756 | - } else { |
|
| 757 | - imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - $img = $img1; |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - return true; |
|
| 764 | - } |
|
| 729 | + /** |
|
| 730 | + * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 731 | + * |
|
| 732 | + * @note Pour compatibilité avec PHP < 5.5 |
|
| 733 | + * |
|
| 734 | + * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 735 | + * |
|
| 736 | + * @param ressource $img |
|
| 737 | + * @return bool |
|
| 738 | + * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 739 | + * - false si la transformation ne peut être faite. |
|
| 740 | + **/ |
|
| 741 | + function imagepalettetotruecolor(&$img) { |
|
| 742 | + if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 743 | + return false; |
|
| 744 | + } elseif (!imageistruecolor($img)) { |
|
| 745 | + $w = imagesx($img); |
|
| 746 | + $h = imagesy($img); |
|
| 747 | + $img1 = imagecreatetruecolor($w, $h); |
|
| 748 | + //Conserver la transparence si possible |
|
| 749 | + if (function_exists('ImageCopyResampled')) { |
|
| 750 | + if (function_exists("imageAntiAlias")) { |
|
| 751 | + imageAntiAlias($img1, true); |
|
| 752 | + } |
|
| 753 | + @imagealphablending($img1, false); |
|
| 754 | + @imagesavealpha($img1, true); |
|
| 755 | + @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 756 | + } else { |
|
| 757 | + imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + $img = $img1; |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + return true; |
|
| 764 | + } |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /** |
@@ -788,32 +788,32 @@ discard block |
||
| 788 | 788 | * Code html modifié de la balise. |
| 789 | 789 | **/ |
| 790 | 790 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 791 | - if ($style === false) { |
|
| 792 | - $style = extraire_attribut($tag, 'style'); |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - // enlever le width et height du style |
|
| 796 | - $style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims", "", $style); |
|
| 797 | - if ($style and $style{0} == ';') { |
|
| 798 | - $style = substr($style, 1); |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - // mettre des attributs de width et height sur les images, |
|
| 802 | - // ca accelere le rendu du navigateur |
|
| 803 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 804 | - // quand on a desactive l'affichage des images. |
|
| 805 | - $tag = inserer_attribut($tag, 'width', $width); |
|
| 806 | - $tag = inserer_attribut($tag, 'height', $height); |
|
| 807 | - |
|
| 808 | - // attributs deprecies. Transformer en CSS |
|
| 809 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 810 | - $style = "margin:${espace}px;" . $style; |
|
| 811 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true); |
|
| 815 | - |
|
| 816 | - return $tag; |
|
| 791 | + if ($style === false) { |
|
| 792 | + $style = extraire_attribut($tag, 'style'); |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + // enlever le width et height du style |
|
| 796 | + $style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims", "", $style); |
|
| 797 | + if ($style and $style{0} == ';') { |
|
| 798 | + $style = substr($style, 1); |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + // mettre des attributs de width et height sur les images, |
|
| 802 | + // ca accelere le rendu du navigateur |
|
| 803 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 804 | + // quand on a desactive l'affichage des images. |
|
| 805 | + $tag = inserer_attribut($tag, 'width', $width); |
|
| 806 | + $tag = inserer_attribut($tag, 'height', $height); |
|
| 807 | + |
|
| 808 | + // attributs deprecies. Transformer en CSS |
|
| 809 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 810 | + $style = "margin:${espace}px;" . $style; |
|
| 811 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true); |
|
| 815 | + |
|
| 816 | + return $tag; |
|
| 817 | 817 | } |
| 818 | 818 | |
| 819 | 819 | |
@@ -839,71 +839,71 @@ discard block |
||
| 839 | 839 | * Retourne le code HTML de l'image |
| 840 | 840 | **/ |
| 841 | 841 | function _image_ecrire_tag($valeurs, $surcharge = array()) { |
| 842 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 843 | - |
|
| 844 | - // fermer les tags img pas bien fermes; |
|
| 845 | - $tag = str_replace(">", "/>", str_replace("/>", ">", $valeurs['tag'])); |
|
| 846 | - |
|
| 847 | - // le style |
|
| 848 | - $style = $valeurs['style']; |
|
| 849 | - if (isset($surcharge['style'])) { |
|
| 850 | - $style = $surcharge['style']; |
|
| 851 | - unset($surcharge['style']); |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - // traiter specifiquement la largeur et la hauteur |
|
| 855 | - $width = $valeurs['largeur']; |
|
| 856 | - if (isset($surcharge['width'])) { |
|
| 857 | - $width = $surcharge['width']; |
|
| 858 | - unset($surcharge['width']); |
|
| 859 | - } |
|
| 860 | - $height = $valeurs['hauteur']; |
|
| 861 | - if (isset($surcharge['height'])) { |
|
| 862 | - $height = $surcharge['height']; |
|
| 863 | - unset($surcharge['height']); |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 867 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 868 | - // on remplace toute les ref a src dans le tag |
|
| 869 | - $src = extraire_attribut($tag, 'src'); |
|
| 870 | - if (isset($surcharge['src'])) { |
|
| 871 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 872 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 873 | - // pas garanti comme methode, mais mieux que rien |
|
| 874 | - if (strpos($src, '&') !== false) { |
|
| 875 | - $tag = str_replace(str_replace("&", "&", $src), $surcharge['src'], $tag); |
|
| 876 | - } |
|
| 877 | - $src = $surcharge['src']; |
|
| 878 | - unset($surcharge['src']); |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - $class = $valeurs['class']; |
|
| 882 | - if (isset($surcharge['class'])) { |
|
| 883 | - $class = $surcharge['class']; |
|
| 884 | - unset($surcharge['class']); |
|
| 885 | - } |
|
| 886 | - if (strlen($class)) { |
|
| 887 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - if (count($surcharge)) { |
|
| 891 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 892 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 893 | - } |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - $tag = pipeline('image_ecrire_tag_finir', |
|
| 897 | - array( |
|
| 898 | - 'args' => array( |
|
| 899 | - 'valeurs' => $valeurs, |
|
| 900 | - 'surcharge' => $surcharge, |
|
| 901 | - ), |
|
| 902 | - 'data' => $tag |
|
| 903 | - ) |
|
| 904 | - ); |
|
| 905 | - |
|
| 906 | - return $tag; |
|
| 842 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 843 | + |
|
| 844 | + // fermer les tags img pas bien fermes; |
|
| 845 | + $tag = str_replace(">", "/>", str_replace("/>", ">", $valeurs['tag'])); |
|
| 846 | + |
|
| 847 | + // le style |
|
| 848 | + $style = $valeurs['style']; |
|
| 849 | + if (isset($surcharge['style'])) { |
|
| 850 | + $style = $surcharge['style']; |
|
| 851 | + unset($surcharge['style']); |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + // traiter specifiquement la largeur et la hauteur |
|
| 855 | + $width = $valeurs['largeur']; |
|
| 856 | + if (isset($surcharge['width'])) { |
|
| 857 | + $width = $surcharge['width']; |
|
| 858 | + unset($surcharge['width']); |
|
| 859 | + } |
|
| 860 | + $height = $valeurs['hauteur']; |
|
| 861 | + if (isset($surcharge['height'])) { |
|
| 862 | + $height = $surcharge['height']; |
|
| 863 | + unset($surcharge['height']); |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 867 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 868 | + // on remplace toute les ref a src dans le tag |
|
| 869 | + $src = extraire_attribut($tag, 'src'); |
|
| 870 | + if (isset($surcharge['src'])) { |
|
| 871 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 872 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 873 | + // pas garanti comme methode, mais mieux que rien |
|
| 874 | + if (strpos($src, '&') !== false) { |
|
| 875 | + $tag = str_replace(str_replace("&", "&", $src), $surcharge['src'], $tag); |
|
| 876 | + } |
|
| 877 | + $src = $surcharge['src']; |
|
| 878 | + unset($surcharge['src']); |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + $class = $valeurs['class']; |
|
| 882 | + if (isset($surcharge['class'])) { |
|
| 883 | + $class = $surcharge['class']; |
|
| 884 | + unset($surcharge['class']); |
|
| 885 | + } |
|
| 886 | + if (strlen($class)) { |
|
| 887 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + if (count($surcharge)) { |
|
| 891 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 892 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 893 | + } |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + $tag = pipeline('image_ecrire_tag_finir', |
|
| 897 | + array( |
|
| 898 | + 'args' => array( |
|
| 899 | + 'valeurs' => $valeurs, |
|
| 900 | + 'surcharge' => $surcharge, |
|
| 901 | + ), |
|
| 902 | + 'data' => $tag |
|
| 903 | + ) |
|
| 904 | + ); |
|
| 905 | + |
|
| 906 | + return $tag; |
|
| 907 | 907 | } |
| 908 | 908 | |
| 909 | 909 | /** |
@@ -926,236 +926,236 @@ discard block |
||
| 926 | 926 | * Description de l'image, sinon null. |
| 927 | 927 | **/ |
| 928 | 928 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 929 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 930 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 931 | - $image = $valeurs['fichier']; |
|
| 932 | - $format = $valeurs['format_source']; |
|
| 933 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 934 | - $destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]); |
|
| 935 | - |
|
| 936 | - $format_sortie = $valeurs['format_dest']; |
|
| 937 | - |
|
| 938 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 939 | - $process = $GLOBALS['meta']['image_process']; |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - // liste des formats qu'on sait lire |
|
| 943 | - $img = isset($GLOBALS['meta']['formats_graphiques']) |
|
| 944 | - ? (strpos($GLOBALS['meta']['formats_graphiques'], $format) !== false) |
|
| 945 | - : false; |
|
| 946 | - |
|
| 947 | - // si le doc n'est pas une image, refuser |
|
| 948 | - if (!$force and !$img) { |
|
| 949 | - return; |
|
| 950 | - } |
|
| 951 | - $destination = "$destdir/$destfile"; |
|
| 952 | - |
|
| 953 | - // calculer la taille |
|
| 954 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 955 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 956 | - list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight); |
|
| 957 | - } |
|
| 958 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 959 | - $destWidth = $maxWidth; |
|
| 960 | - $destHeight = $maxHeight; |
|
| 961 | - } else { |
|
| 962 | - spip_log("echec $process sur $image"); |
|
| 963 | - |
|
| 964 | - return; |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 968 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 969 | - $vignette = $destination . '.' . $format; |
|
| 970 | - @copy($image, $vignette); |
|
| 971 | - } // imagemagick en ligne de commande |
|
| 972 | - elseif ($process == 'convert') { |
|
| 973 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 974 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 975 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 976 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 977 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 978 | - } |
|
| 979 | - $vignette = $destination . "." . $format_sortie; |
|
| 980 | - $commande = str_replace( |
|
| 981 | - array('%x', '%y', '%src', '%dest'), |
|
| 982 | - array( |
|
| 983 | - $destWidth, |
|
| 984 | - $destHeight, |
|
| 985 | - escapeshellcmd($image), |
|
| 986 | - escapeshellcmd($vignette) |
|
| 987 | - ), |
|
| 988 | - _RESIZE_COMMAND); |
|
| 989 | - spip_log($commande); |
|
| 990 | - exec($commande); |
|
| 991 | - if (!@file_exists($vignette)) { |
|
| 992 | - spip_log("echec convert sur $vignette"); |
|
| 993 | - |
|
| 994 | - return; // echec commande |
|
| 995 | - } |
|
| 996 | - } // php5 imagemagick |
|
| 997 | - elseif ($process == 'imagick') { |
|
| 998 | - $vignette = "$destination." . $format_sortie; |
|
| 999 | - |
|
| 1000 | - if (!class_exists('Imagick')) { |
|
| 1001 | - spip_log("Classe Imagick absente !", _LOG_ERREUR); |
|
| 1002 | - |
|
| 1003 | - return; |
|
| 1004 | - } |
|
| 1005 | - $imagick = new Imagick(); |
|
| 1006 | - $imagick->readImage($image); |
|
| 1007 | - $imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS, |
|
| 1008 | - 1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1009 | - $imagick->writeImage($vignette); |
|
| 1010 | - |
|
| 1011 | - if (!@file_exists($vignette)) { |
|
| 1012 | - spip_log("echec imagick sur $vignette"); |
|
| 1013 | - |
|
| 1014 | - return; |
|
| 1015 | - } |
|
| 1016 | - } // netpbm |
|
| 1017 | - elseif ($process == "netpbm") { |
|
| 1018 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1019 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1020 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1021 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1022 | - return; |
|
| 1023 | - } |
|
| 1024 | - $vignette = $destination . "." . $format_sortie; |
|
| 1025 | - $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND); |
|
| 1026 | - if ($format == "jpg") { |
|
| 1027 | - |
|
| 1028 | - $jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND); |
|
| 1029 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1030 | - if (!($s = @filesize($vignette))) { |
|
| 1031 | - spip_unlink($vignette); |
|
| 1032 | - } |
|
| 1033 | - if (!@file_exists($vignette)) { |
|
| 1034 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1035 | - |
|
| 1036 | - return; |
|
| 1037 | - } |
|
| 1038 | - } else { |
|
| 1039 | - if ($format == "gif") { |
|
| 1040 | - $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND); |
|
| 1041 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1042 | - if (!($s = @filesize($vignette))) { |
|
| 1043 | - spip_unlink($vignette); |
|
| 1044 | - } |
|
| 1045 | - if (!@file_exists($vignette)) { |
|
| 1046 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1047 | - |
|
| 1048 | - return; |
|
| 1049 | - } |
|
| 1050 | - } else { |
|
| 1051 | - if ($format == "png") { |
|
| 1052 | - $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND); |
|
| 1053 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1054 | - if (!($s = @filesize($vignette))) { |
|
| 1055 | - spip_unlink($vignette); |
|
| 1056 | - } |
|
| 1057 | - if (!@file_exists($vignette)) { |
|
| 1058 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1059 | - |
|
| 1060 | - return; |
|
| 1061 | - } |
|
| 1062 | - } |
|
| 1063 | - } |
|
| 1064 | - } |
|
| 1065 | - } // gd ou gd2 |
|
| 1066 | - elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1067 | - if (!function_exists('gd_info')) { |
|
| 1068 | - spip_log("Librairie GD absente !", _LOG_ERREUR); |
|
| 1069 | - |
|
| 1070 | - return; |
|
| 1071 | - } |
|
| 1072 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1073 | - spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels"); |
|
| 1074 | - |
|
| 1075 | - return; |
|
| 1076 | - } |
|
| 1077 | - $destFormat = $format_sortie; |
|
| 1078 | - if (!$destFormat) { |
|
| 1079 | - spip_log("pas de format pour $image"); |
|
| 1080 | - |
|
| 1081 | - return; |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1085 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1086 | - return ''; |
|
| 1087 | - } |
|
| 1088 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1089 | - if (!$srcImage) { |
|
| 1090 | - spip_log("echec gd1/gd2"); |
|
| 1091 | - |
|
| 1092 | - return; |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - // Initialisation de l'image destination |
|
| 1096 | - $destImage = null; |
|
| 1097 | - if ($process == 'gd2' and $destFormat != "gif") { |
|
| 1098 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1099 | - } |
|
| 1100 | - if (!$destImage) { |
|
| 1101 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1105 | - $ok = false; |
|
| 1106 | - if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1107 | - if ($format == "gif") { |
|
| 1108 | - // Si un GIF est transparent, |
|
| 1109 | - // fabriquer un PNG transparent |
|
| 1110 | - $transp = imagecolortransparent($srcImage); |
|
| 1111 | - if ($transp > 0) { |
|
| 1112 | - $destFormat = "png"; |
|
| 1113 | - } |
|
| 1114 | - } |
|
| 1115 | - if ($destFormat == "png") { |
|
| 1116 | - // Conserver la transparence |
|
| 1117 | - if (function_exists("imageAntiAlias")) { |
|
| 1118 | - imageAntiAlias($destImage, true); |
|
| 1119 | - } |
|
| 1120 | - @imagealphablending($destImage, false); |
|
| 1121 | - @imagesavealpha($destImage, true); |
|
| 1122 | - } |
|
| 1123 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1124 | - } |
|
| 1125 | - if (!$ok) { |
|
| 1126 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - // Sauvegarde de l'image destination |
|
| 1130 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1131 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1132 | - _image_gd_output($destImage, $valeurs); |
|
| 1133 | - |
|
| 1134 | - if ($srcImage) { |
|
| 1135 | - ImageDestroy($srcImage); |
|
| 1136 | - } |
|
| 1137 | - ImageDestroy($destImage); |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - $size = @getimagesize($vignette); |
|
| 1141 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1142 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1143 | - if ($size[0] < 1) { |
|
| 1144 | - $size[0] = $destWidth; |
|
| 1145 | - } |
|
| 1146 | - if ($size[1] < 1) { |
|
| 1147 | - $size[1] = $destHeight; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - $retour['width'] = $largeur = $size[0]; |
|
| 1151 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1152 | - |
|
| 1153 | - $retour['fichier'] = $vignette; |
|
| 1154 | - $retour['format'] = $format; |
|
| 1155 | - $retour['date'] = @filemtime($vignette); |
|
| 1156 | - |
|
| 1157 | - // renvoyer l'image |
|
| 1158 | - return $retour; |
|
| 929 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 930 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 931 | + $image = $valeurs['fichier']; |
|
| 932 | + $format = $valeurs['format_source']; |
|
| 933 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 934 | + $destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]); |
|
| 935 | + |
|
| 936 | + $format_sortie = $valeurs['format_dest']; |
|
| 937 | + |
|
| 938 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 939 | + $process = $GLOBALS['meta']['image_process']; |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + // liste des formats qu'on sait lire |
|
| 943 | + $img = isset($GLOBALS['meta']['formats_graphiques']) |
|
| 944 | + ? (strpos($GLOBALS['meta']['formats_graphiques'], $format) !== false) |
|
| 945 | + : false; |
|
| 946 | + |
|
| 947 | + // si le doc n'est pas une image, refuser |
|
| 948 | + if (!$force and !$img) { |
|
| 949 | + return; |
|
| 950 | + } |
|
| 951 | + $destination = "$destdir/$destfile"; |
|
| 952 | + |
|
| 953 | + // calculer la taille |
|
| 954 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 955 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 956 | + list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight); |
|
| 957 | + } |
|
| 958 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 959 | + $destWidth = $maxWidth; |
|
| 960 | + $destHeight = $maxHeight; |
|
| 961 | + } else { |
|
| 962 | + spip_log("echec $process sur $image"); |
|
| 963 | + |
|
| 964 | + return; |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 968 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 969 | + $vignette = $destination . '.' . $format; |
|
| 970 | + @copy($image, $vignette); |
|
| 971 | + } // imagemagick en ligne de commande |
|
| 972 | + elseif ($process == 'convert') { |
|
| 973 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 974 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 975 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 976 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 977 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 978 | + } |
|
| 979 | + $vignette = $destination . "." . $format_sortie; |
|
| 980 | + $commande = str_replace( |
|
| 981 | + array('%x', '%y', '%src', '%dest'), |
|
| 982 | + array( |
|
| 983 | + $destWidth, |
|
| 984 | + $destHeight, |
|
| 985 | + escapeshellcmd($image), |
|
| 986 | + escapeshellcmd($vignette) |
|
| 987 | + ), |
|
| 988 | + _RESIZE_COMMAND); |
|
| 989 | + spip_log($commande); |
|
| 990 | + exec($commande); |
|
| 991 | + if (!@file_exists($vignette)) { |
|
| 992 | + spip_log("echec convert sur $vignette"); |
|
| 993 | + |
|
| 994 | + return; // echec commande |
|
| 995 | + } |
|
| 996 | + } // php5 imagemagick |
|
| 997 | + elseif ($process == 'imagick') { |
|
| 998 | + $vignette = "$destination." . $format_sortie; |
|
| 999 | + |
|
| 1000 | + if (!class_exists('Imagick')) { |
|
| 1001 | + spip_log("Classe Imagick absente !", _LOG_ERREUR); |
|
| 1002 | + |
|
| 1003 | + return; |
|
| 1004 | + } |
|
| 1005 | + $imagick = new Imagick(); |
|
| 1006 | + $imagick->readImage($image); |
|
| 1007 | + $imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS, |
|
| 1008 | + 1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1009 | + $imagick->writeImage($vignette); |
|
| 1010 | + |
|
| 1011 | + if (!@file_exists($vignette)) { |
|
| 1012 | + spip_log("echec imagick sur $vignette"); |
|
| 1013 | + |
|
| 1014 | + return; |
|
| 1015 | + } |
|
| 1016 | + } // netpbm |
|
| 1017 | + elseif ($process == "netpbm") { |
|
| 1018 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1019 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1020 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1021 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1022 | + return; |
|
| 1023 | + } |
|
| 1024 | + $vignette = $destination . "." . $format_sortie; |
|
| 1025 | + $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND); |
|
| 1026 | + if ($format == "jpg") { |
|
| 1027 | + |
|
| 1028 | + $jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND); |
|
| 1029 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1030 | + if (!($s = @filesize($vignette))) { |
|
| 1031 | + spip_unlink($vignette); |
|
| 1032 | + } |
|
| 1033 | + if (!@file_exists($vignette)) { |
|
| 1034 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1035 | + |
|
| 1036 | + return; |
|
| 1037 | + } |
|
| 1038 | + } else { |
|
| 1039 | + if ($format == "gif") { |
|
| 1040 | + $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND); |
|
| 1041 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1042 | + if (!($s = @filesize($vignette))) { |
|
| 1043 | + spip_unlink($vignette); |
|
| 1044 | + } |
|
| 1045 | + if (!@file_exists($vignette)) { |
|
| 1046 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1047 | + |
|
| 1048 | + return; |
|
| 1049 | + } |
|
| 1050 | + } else { |
|
| 1051 | + if ($format == "png") { |
|
| 1052 | + $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND); |
|
| 1053 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1054 | + if (!($s = @filesize($vignette))) { |
|
| 1055 | + spip_unlink($vignette); |
|
| 1056 | + } |
|
| 1057 | + if (!@file_exists($vignette)) { |
|
| 1058 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1059 | + |
|
| 1060 | + return; |
|
| 1061 | + } |
|
| 1062 | + } |
|
| 1063 | + } |
|
| 1064 | + } |
|
| 1065 | + } // gd ou gd2 |
|
| 1066 | + elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1067 | + if (!function_exists('gd_info')) { |
|
| 1068 | + spip_log("Librairie GD absente !", _LOG_ERREUR); |
|
| 1069 | + |
|
| 1070 | + return; |
|
| 1071 | + } |
|
| 1072 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1073 | + spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels"); |
|
| 1074 | + |
|
| 1075 | + return; |
|
| 1076 | + } |
|
| 1077 | + $destFormat = $format_sortie; |
|
| 1078 | + if (!$destFormat) { |
|
| 1079 | + spip_log("pas de format pour $image"); |
|
| 1080 | + |
|
| 1081 | + return; |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1085 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1086 | + return ''; |
|
| 1087 | + } |
|
| 1088 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1089 | + if (!$srcImage) { |
|
| 1090 | + spip_log("echec gd1/gd2"); |
|
| 1091 | + |
|
| 1092 | + return; |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + // Initialisation de l'image destination |
|
| 1096 | + $destImage = null; |
|
| 1097 | + if ($process == 'gd2' and $destFormat != "gif") { |
|
| 1098 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1099 | + } |
|
| 1100 | + if (!$destImage) { |
|
| 1101 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1105 | + $ok = false; |
|
| 1106 | + if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1107 | + if ($format == "gif") { |
|
| 1108 | + // Si un GIF est transparent, |
|
| 1109 | + // fabriquer un PNG transparent |
|
| 1110 | + $transp = imagecolortransparent($srcImage); |
|
| 1111 | + if ($transp > 0) { |
|
| 1112 | + $destFormat = "png"; |
|
| 1113 | + } |
|
| 1114 | + } |
|
| 1115 | + if ($destFormat == "png") { |
|
| 1116 | + // Conserver la transparence |
|
| 1117 | + if (function_exists("imageAntiAlias")) { |
|
| 1118 | + imageAntiAlias($destImage, true); |
|
| 1119 | + } |
|
| 1120 | + @imagealphablending($destImage, false); |
|
| 1121 | + @imagesavealpha($destImage, true); |
|
| 1122 | + } |
|
| 1123 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1124 | + } |
|
| 1125 | + if (!$ok) { |
|
| 1126 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + // Sauvegarde de l'image destination |
|
| 1130 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1131 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1132 | + _image_gd_output($destImage, $valeurs); |
|
| 1133 | + |
|
| 1134 | + if ($srcImage) { |
|
| 1135 | + ImageDestroy($srcImage); |
|
| 1136 | + } |
|
| 1137 | + ImageDestroy($destImage); |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + $size = @getimagesize($vignette); |
|
| 1141 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1142 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1143 | + if ($size[0] < 1) { |
|
| 1144 | + $size[0] = $destWidth; |
|
| 1145 | + } |
|
| 1146 | + if ($size[1] < 1) { |
|
| 1147 | + $size[1] = $destHeight; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + $retour['width'] = $largeur = $size[0]; |
|
| 1151 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1152 | + |
|
| 1153 | + $retour['fichier'] = $vignette; |
|
| 1154 | + $retour['format'] = $format; |
|
| 1155 | + $retour['date'] = @filemtime($vignette); |
|
| 1156 | + |
|
| 1157 | + // renvoyer l'image |
|
| 1158 | + return $retour; |
|
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | /** |
@@ -1175,25 +1175,25 @@ discard block |
||
| 1175 | 1175 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1176 | 1176 | **/ |
| 1177 | 1177 | function _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight) { |
| 1178 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1179 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1180 | - |
|
| 1181 | - if ($ratioWidth <= 1 and $ratioHeight <= 1) { |
|
| 1182 | - $destWidth = $srcWidth; |
|
| 1183 | - $destHeight = $srcHeight; |
|
| 1184 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1185 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1186 | - $destHeight = $maxHeight; |
|
| 1187 | - } else { |
|
| 1188 | - $destWidth = $maxWidth; |
|
| 1189 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - return array( |
|
| 1193 | - ceil($destWidth), |
|
| 1194 | - ceil($destHeight), |
|
| 1195 | - max($ratioWidth, $ratioHeight) |
|
| 1196 | - ); |
|
| 1178 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1179 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1180 | + |
|
| 1181 | + if ($ratioWidth <= 1 and $ratioHeight <= 1) { |
|
| 1182 | + $destWidth = $srcWidth; |
|
| 1183 | + $destHeight = $srcHeight; |
|
| 1184 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1185 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1186 | + $destHeight = $maxHeight; |
|
| 1187 | + } else { |
|
| 1188 | + $destWidth = $maxWidth; |
|
| 1189 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + return array( |
|
| 1193 | + ceil($destWidth), |
|
| 1194 | + ceil($destHeight), |
|
| 1195 | + max($ratioWidth, $ratioHeight) |
|
| 1196 | + ); |
|
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | /** |
@@ -1213,25 +1213,25 @@ discard block |
||
| 1213 | 1213 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1214 | 1214 | **/ |
| 1215 | 1215 | function ratio_passe_partout($srcWidth, $srcHeight, $maxWidth, $maxHeight) { |
| 1216 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1217 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1218 | - |
|
| 1219 | - if ($ratioWidth <= 1 and $ratioHeight <= 1) { |
|
| 1220 | - $destWidth = $srcWidth; |
|
| 1221 | - $destHeight = $srcHeight; |
|
| 1222 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1223 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1224 | - $destHeight = $maxHeight; |
|
| 1225 | - } else { |
|
| 1226 | - $destWidth = $maxWidth; |
|
| 1227 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - return array( |
|
| 1231 | - ceil($destWidth), |
|
| 1232 | - ceil($destHeight), |
|
| 1233 | - min($ratioWidth, $ratioHeight) |
|
| 1234 | - ); |
|
| 1216 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1217 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1218 | + |
|
| 1219 | + if ($ratioWidth <= 1 and $ratioHeight <= 1) { |
|
| 1220 | + $destWidth = $srcWidth; |
|
| 1221 | + $destHeight = $srcHeight; |
|
| 1222 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1223 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1224 | + $destHeight = $maxHeight; |
|
| 1225 | + } else { |
|
| 1226 | + $destWidth = $maxWidth; |
|
| 1227 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + return array( |
|
| 1231 | + ceil($destWidth), |
|
| 1232 | + ceil($destHeight), |
|
| 1233 | + min($ratioWidth, $ratioHeight) |
|
| 1234 | + ); |
|
| 1235 | 1235 | } |
| 1236 | 1236 | |
| 1237 | 1237 | |
@@ -1264,106 +1264,106 @@ discard block |
||
| 1264 | 1264 | * Code HTML de la balise img produite |
| 1265 | 1265 | **/ |
| 1266 | 1266 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1267 | - $image = false; |
|
| 1268 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1269 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1270 | - } |
|
| 1271 | - # determiner le format de sortie |
|
| 1272 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1273 | - if ($process == "netpbm") { |
|
| 1274 | - $format_sortie = "jpg"; |
|
| 1275 | - } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1276 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction); |
|
| 1277 | - |
|
| 1278 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1279 | - $gd_formats = explode(',', $GLOBALS['meta']["gd_formats"]); |
|
| 1280 | - if (is_array($image) |
|
| 1281 | - and (!in_array($image['format_dest'], $gd_formats) |
|
| 1282 | - or ($image['format_dest'] == 'gif' and !function_exists('ImageGif')) |
|
| 1283 | - ) |
|
| 1284 | - ) { |
|
| 1285 | - if ($image['format_source'] == 'jpg') { |
|
| 1286 | - $formats_sortie = array('jpg', 'png', 'gif'); |
|
| 1287 | - } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1288 | - { |
|
| 1289 | - $formats_sortie = array('png', 'jpg', 'gif'); |
|
| 1290 | - } |
|
| 1291 | - // Choisir le format destination |
|
| 1292 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1293 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1294 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1295 | - # pas *ecrire* |
|
| 1296 | - $format_sortie = ""; |
|
| 1297 | - foreach ($formats_sortie as $fmt) { |
|
| 1298 | - if (in_array($fmt, $gd_formats)) { |
|
| 1299 | - if ($fmt <> "gif" or function_exists('ImageGif')) { |
|
| 1300 | - $format_sortie = $fmt; |
|
| 1301 | - } |
|
| 1302 | - break; |
|
| 1303 | - } |
|
| 1304 | - } |
|
| 1305 | - $image = false; |
|
| 1306 | - } |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - if (!is_array($image)) { |
|
| 1310 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction); |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1314 | - spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1315 | - // on peut resizer en mode html si on dispose des elements |
|
| 1316 | - if ($srcw = extraire_attribut($img, 'width') |
|
| 1317 | - and $srch = extraire_attribut($img, 'height') |
|
| 1318 | - ) { |
|
| 1319 | - list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1320 | - |
|
| 1321 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1322 | - } |
|
| 1323 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1324 | - // sous la forme style='max-width: NNpx;' |
|
| 1325 | - return inserer_attribut($img, 'style', |
|
| 1326 | - "max-width: ${taille}px; max-height: ${taille_y}px"); |
|
| 1327 | - } |
|
| 1328 | - |
|
| 1329 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1330 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1331 | - if ($image['creer']) { |
|
| 1332 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1333 | - } |
|
| 1334 | - |
|
| 1335 | - return _image_ecrire_tag($image, array('src' => $image['fichier_dest'])); |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - if ($image['creer'] == false && !$force) { |
|
| 1339 | - return _image_ecrire_tag($image, |
|
| 1340 | - array('src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest'])); |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - if (in_array($image["format_source"], array('jpg', 'gif', 'png'))) { |
|
| 1344 | - $destWidth = $image['largeur_dest']; |
|
| 1345 | - $destHeight = $image['hauteur_dest']; |
|
| 1346 | - $logo = $image['fichier']; |
|
| 1347 | - $date = $image["date_src"]; |
|
| 1348 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1349 | - |
|
| 1350 | - if ($preview && $preview['fichier']) { |
|
| 1351 | - $logo = $preview['fichier']; |
|
| 1352 | - $destWidth = $preview['width']; |
|
| 1353 | - $destHeight = $preview['height']; |
|
| 1354 | - $date = $preview['date']; |
|
| 1355 | - } |
|
| 1356 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1357 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1358 | - // quand on fait supprimer/reuploader un logo |
|
| 1359 | - // (pas de filemtime si SAFE MODE) |
|
| 1360 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1361 | - |
|
| 1362 | - return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight)); |
|
| 1363 | - } else # SVG par exemple ? BMP, tiff ... les redacteurs osent tout! |
|
| 1364 | - { |
|
| 1365 | - return $img; |
|
| 1366 | - } |
|
| 1267 | + $image = false; |
|
| 1268 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1269 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1270 | + } |
|
| 1271 | + # determiner le format de sortie |
|
| 1272 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1273 | + if ($process == "netpbm") { |
|
| 1274 | + $format_sortie = "jpg"; |
|
| 1275 | + } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1276 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction); |
|
| 1277 | + |
|
| 1278 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1279 | + $gd_formats = explode(',', $GLOBALS['meta']["gd_formats"]); |
|
| 1280 | + if (is_array($image) |
|
| 1281 | + and (!in_array($image['format_dest'], $gd_formats) |
|
| 1282 | + or ($image['format_dest'] == 'gif' and !function_exists('ImageGif')) |
|
| 1283 | + ) |
|
| 1284 | + ) { |
|
| 1285 | + if ($image['format_source'] == 'jpg') { |
|
| 1286 | + $formats_sortie = array('jpg', 'png', 'gif'); |
|
| 1287 | + } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1288 | + { |
|
| 1289 | + $formats_sortie = array('png', 'jpg', 'gif'); |
|
| 1290 | + } |
|
| 1291 | + // Choisir le format destination |
|
| 1292 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1293 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1294 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1295 | + # pas *ecrire* |
|
| 1296 | + $format_sortie = ""; |
|
| 1297 | + foreach ($formats_sortie as $fmt) { |
|
| 1298 | + if (in_array($fmt, $gd_formats)) { |
|
| 1299 | + if ($fmt <> "gif" or function_exists('ImageGif')) { |
|
| 1300 | + $format_sortie = $fmt; |
|
| 1301 | + } |
|
| 1302 | + break; |
|
| 1303 | + } |
|
| 1304 | + } |
|
| 1305 | + $image = false; |
|
| 1306 | + } |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + if (!is_array($image)) { |
|
| 1310 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction); |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1314 | + spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1315 | + // on peut resizer en mode html si on dispose des elements |
|
| 1316 | + if ($srcw = extraire_attribut($img, 'width') |
|
| 1317 | + and $srch = extraire_attribut($img, 'height') |
|
| 1318 | + ) { |
|
| 1319 | + list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1320 | + |
|
| 1321 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1322 | + } |
|
| 1323 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1324 | + // sous la forme style='max-width: NNpx;' |
|
| 1325 | + return inserer_attribut($img, 'style', |
|
| 1326 | + "max-width: ${taille}px; max-height: ${taille_y}px"); |
|
| 1327 | + } |
|
| 1328 | + |
|
| 1329 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1330 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1331 | + if ($image['creer']) { |
|
| 1332 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1333 | + } |
|
| 1334 | + |
|
| 1335 | + return _image_ecrire_tag($image, array('src' => $image['fichier_dest'])); |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + if ($image['creer'] == false && !$force) { |
|
| 1339 | + return _image_ecrire_tag($image, |
|
| 1340 | + array('src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest'])); |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + if (in_array($image["format_source"], array('jpg', 'gif', 'png'))) { |
|
| 1344 | + $destWidth = $image['largeur_dest']; |
|
| 1345 | + $destHeight = $image['hauteur_dest']; |
|
| 1346 | + $logo = $image['fichier']; |
|
| 1347 | + $date = $image["date_src"]; |
|
| 1348 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1349 | + |
|
| 1350 | + if ($preview && $preview['fichier']) { |
|
| 1351 | + $logo = $preview['fichier']; |
|
| 1352 | + $destWidth = $preview['width']; |
|
| 1353 | + $destHeight = $preview['height']; |
|
| 1354 | + $date = $preview['date']; |
|
| 1355 | + } |
|
| 1356 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1357 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1358 | + // quand on fait supprimer/reuploader un logo |
|
| 1359 | + // (pas de filemtime si SAFE MODE) |
|
| 1360 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1361 | + |
|
| 1362 | + return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight)); |
|
| 1363 | + } else # SVG par exemple ? BMP, tiff ... les redacteurs osent tout! |
|
| 1364 | + { |
|
| 1365 | + return $img; |
|
| 1366 | + } |
|
| 1367 | 1367 | } |
| 1368 | 1368 | |
| 1369 | 1369 | /** |
@@ -1378,145 +1378,145 @@ discard block |
||
| 1378 | 1378 | */ |
| 1379 | 1379 | class phpthumb_functions { |
| 1380 | 1380 | |
| 1381 | - /** |
|
| 1382 | - * Retourne la couleur d'un pixel dans une image |
|
| 1383 | - * |
|
| 1384 | - * @param ressource $img |
|
| 1385 | - * @param int $x |
|
| 1386 | - * @param int $y |
|
| 1387 | - * @return array|bool |
|
| 1388 | - */ |
|
| 1389 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1390 | - if (!is_resource($img)) { |
|
| 1391 | - return false; |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1395 | - } |
|
| 1396 | - |
|
| 1397 | - /** |
|
| 1398 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1399 | - * |
|
| 1400 | - * @param int $number |
|
| 1401 | - * @param int $minbytes |
|
| 1402 | - * @return string |
|
| 1403 | - */ |
|
| 1404 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1405 | - $intstring = ''; |
|
| 1406 | - while ($number > 0) { |
|
| 1407 | - $intstring = $intstring . chr($number & 255); |
|
| 1408 | - $number >>= 8; |
|
| 1409 | - } |
|
| 1410 | - |
|
| 1411 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - /** |
|
| 1415 | - * Transforme une ressource GD en image au format ICO |
|
| 1416 | - * |
|
| 1417 | - * @param array $gd_image_array |
|
| 1418 | - * Tableau de ressources d'images GD |
|
| 1419 | - * @return string |
|
| 1420 | - * Image au format ICO |
|
| 1421 | - */ |
|
| 1422 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1423 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1424 | - |
|
| 1425 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1426 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1427 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1428 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1429 | - |
|
| 1430 | - $icXOR[$key] = ''; |
|
| 1431 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1432 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1433 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1434 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1435 | - $r = $argb['red']; |
|
| 1436 | - $g = $argb['green']; |
|
| 1437 | - $b = $argb['blue']; |
|
| 1438 | - |
|
| 1439 | - if ($bpp[$key] == 32) { |
|
| 1440 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1441 | - } elseif ($bpp[$key] == 24) { |
|
| 1442 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1443 | - } |
|
| 1444 | - |
|
| 1445 | - if ($a < 128) { |
|
| 1446 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1447 | - } else { |
|
| 1448 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1449 | - } |
|
| 1450 | - } |
|
| 1451 | - // mask bits are 32-bit aligned per scanline |
|
| 1452 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1453 | - $icANDmask[$key][$y] .= '0'; |
|
| 1454 | - } |
|
| 1455 | - } |
|
| 1456 | - $icAND[$key] = ''; |
|
| 1457 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1458 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1459 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1460 | - } |
|
| 1461 | - } |
|
| 1462 | - |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1466 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1467 | - |
|
| 1468 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1469 | - $BitmapInfoHeader[$key] = ''; |
|
| 1470 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1471 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1472 | - // The biHeight member specifies the combined |
|
| 1473 | - // height of the XOR and AND masks. |
|
| 1474 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1475 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1476 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1477 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1478 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1479 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1480 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1481 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1482 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - |
|
| 1486 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1487 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1488 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1489 | - |
|
| 1490 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1491 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1492 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1493 | - |
|
| 1494 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1495 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1496 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1497 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1498 | - |
|
| 1499 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1500 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1501 | - |
|
| 1502 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1503 | - $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, |
|
| 1504 | - 4); // dwBytesInRes; // How many bytes in this resource? |
|
| 1505 | - |
|
| 1506 | - $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, |
|
| 1507 | - 4); // dwImageOffset; // Where in the file is this image? |
|
| 1508 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1509 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 1510 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 1511 | - } |
|
| 1512 | - |
|
| 1513 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1514 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 1515 | - $icondata .= $icXOR[$key]; |
|
| 1516 | - $icondata .= $icAND[$key]; |
|
| 1517 | - } |
|
| 1518 | - |
|
| 1519 | - return $icondata; |
|
| 1520 | - } |
|
| 1381 | + /** |
|
| 1382 | + * Retourne la couleur d'un pixel dans une image |
|
| 1383 | + * |
|
| 1384 | + * @param ressource $img |
|
| 1385 | + * @param int $x |
|
| 1386 | + * @param int $y |
|
| 1387 | + * @return array|bool |
|
| 1388 | + */ |
|
| 1389 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1390 | + if (!is_resource($img)) { |
|
| 1391 | + return false; |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + /** |
|
| 1398 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1399 | + * |
|
| 1400 | + * @param int $number |
|
| 1401 | + * @param int $minbytes |
|
| 1402 | + * @return string |
|
| 1403 | + */ |
|
| 1404 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1405 | + $intstring = ''; |
|
| 1406 | + while ($number > 0) { |
|
| 1407 | + $intstring = $intstring . chr($number & 255); |
|
| 1408 | + $number >>= 8; |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + /** |
|
| 1415 | + * Transforme une ressource GD en image au format ICO |
|
| 1416 | + * |
|
| 1417 | + * @param array $gd_image_array |
|
| 1418 | + * Tableau de ressources d'images GD |
|
| 1419 | + * @return string |
|
| 1420 | + * Image au format ICO |
|
| 1421 | + */ |
|
| 1422 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1423 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1424 | + |
|
| 1425 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1426 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1427 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1428 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1429 | + |
|
| 1430 | + $icXOR[$key] = ''; |
|
| 1431 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1432 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1433 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1434 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1435 | + $r = $argb['red']; |
|
| 1436 | + $g = $argb['green']; |
|
| 1437 | + $b = $argb['blue']; |
|
| 1438 | + |
|
| 1439 | + if ($bpp[$key] == 32) { |
|
| 1440 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1441 | + } elseif ($bpp[$key] == 24) { |
|
| 1442 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1443 | + } |
|
| 1444 | + |
|
| 1445 | + if ($a < 128) { |
|
| 1446 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1447 | + } else { |
|
| 1448 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1449 | + } |
|
| 1450 | + } |
|
| 1451 | + // mask bits are 32-bit aligned per scanline |
|
| 1452 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1453 | + $icANDmask[$key][$y] .= '0'; |
|
| 1454 | + } |
|
| 1455 | + } |
|
| 1456 | + $icAND[$key] = ''; |
|
| 1457 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1458 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1459 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1460 | + } |
|
| 1461 | + } |
|
| 1462 | + |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1466 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1467 | + |
|
| 1468 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1469 | + $BitmapInfoHeader[$key] = ''; |
|
| 1470 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1471 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1472 | + // The biHeight member specifies the combined |
|
| 1473 | + // height of the XOR and AND masks. |
|
| 1474 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1475 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1476 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1477 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1478 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1479 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1480 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1481 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1482 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + |
|
| 1486 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1487 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1488 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1489 | + |
|
| 1490 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1491 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1492 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1493 | + |
|
| 1494 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1495 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1496 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1497 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1498 | + |
|
| 1499 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1500 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1501 | + |
|
| 1502 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1503 | + $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, |
|
| 1504 | + 4); // dwBytesInRes; // How many bytes in this resource? |
|
| 1505 | + |
|
| 1506 | + $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, |
|
| 1507 | + 4); // dwImageOffset; // Where in the file is this image? |
|
| 1508 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1509 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 1510 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 1511 | + } |
|
| 1512 | + |
|
| 1513 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1514 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 1515 | + $icondata .= $icXOR[$key]; |
|
| 1516 | + $icondata .= $icAND[$key]; |
|
| 1517 | + } |
|
| 1518 | + |
|
| 1519 | + return $icondata; |
|
| 1520 | + } |
|
| 1521 | 1521 | |
| 1522 | 1522 | } |
@@ -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"; |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | $img = "<img src='$source' />"; |
| 149 | 149 | } # gerer img src="data:....base64" |
| 150 | 150 | elseif (preg_match('@^data:image/(jpe?g|png|gif);base64,(.*)$@isS', $source, $regs)) { |
| 151 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . str_replace('jpeg', 'jpg', $regs[1]); |
|
| 151 | + $local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'.str_replace('jpeg', 'jpg', $regs[1]); |
|
| 152 | 152 | if (!file_exists($local)) { |
| 153 | 153 | ecrire_fichier($local, base64_decode($regs[2])); |
| 154 | 154 | } |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | // les protocoles web prennent au moins 3 lettres |
| 163 | 163 | if (tester_url_absolue($source)) { |
| 164 | 164 | include_spip('inc/distant'); |
| 165 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 165 | + $fichier = _DIR_RACINE.copie_locale($source); |
|
| 166 | 166 | if (!$fichier) { |
| 167 | 167 | return ""; |
| 168 | 168 | } |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | // on garde la terminaison initiale car image simplement copiee |
| 257 | 257 | // et on postfixe son nom avec un md5 du path |
| 258 | 258 | $terminaison_dest = $terminaison; |
| 259 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 259 | + $fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5); |
|
| 260 | 260 | } else { |
| 261 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 261 | + $fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5); |
|
| 262 | 262 | } |
| 263 | 263 | $cache = sous_repertoire(_DIR_VAR, $cache); |
| 264 | 264 | $cache = sous_repertoire($cache, $effet); |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | $fichier_dest = substr($fichier_dest, 2); |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - $fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest; |
|
| 277 | + $fichier_dest = $cache.$fichier_dest.".".$terminaison_dest; |
|
| 278 | 278 | |
| 279 | 279 | $GLOBALS["images_calculees"][] = $fichier_dest; |
| 280 | 280 | |
@@ -310,14 +310,14 @@ discard block |
||
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | if ($creer) { |
| 313 | - spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 314 | - "images" . _LOG_DEBUG); |
|
| 313 | + spip_log("filtre image ".($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier", |
|
| 314 | + "images"._LOG_DEBUG); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | // TODO: si une image png est nommee .jpg, le reconnaitre avec le bon $f |
| 318 | - $ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction; |
|
| 318 | + $ret["fonction_imagecreatefrom"] = "_imagecreatefrom".$term_fonction; |
|
| 319 | 319 | $ret["fichier"] = $fichier; |
| 320 | - $ret["fonction_image"] = "_image_image" . $terminaison_dest; |
|
| 320 | + $ret["fonction_image"] = "_image_image".$terminaison_dest; |
|
| 321 | 321 | $ret["fichier_dest"] = $fichier_dest; |
| 322 | 322 | $ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg'); |
| 323 | 323 | $ret["format_dest"] = $terminaison_dest; |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | if (!function_exists('imagepng')) { |
| 442 | 442 | return false; |
| 443 | 443 | } |
| 444 | - $tmp = $fichier . ".tmp"; |
|
| 444 | + $tmp = $fichier.".tmp"; |
|
| 445 | 445 | $ret = imagepng($img, $tmp); |
| 446 | 446 | if (file_exists($tmp)) { |
| 447 | 447 | $taille_test = getimagesize($tmp); |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | if (!function_exists('imagegif')) { |
| 477 | 477 | return false; |
| 478 | 478 | } |
| 479 | - $tmp = $fichier . ".tmp"; |
|
| 479 | + $tmp = $fichier.".tmp"; |
|
| 480 | 480 | $ret = imagegif($img, $tmp); |
| 481 | 481 | if (file_exists($tmp)) { |
| 482 | 482 | $taille_test = getimagesize($tmp); |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | if (!function_exists('imagejpeg')) { |
| 517 | 517 | return false; |
| 518 | 518 | } |
| 519 | - $tmp = $fichier . ".tmp"; |
|
| 519 | + $tmp = $fichier.".tmp"; |
|
| 520 | 520 | |
| 521 | 521 | // Enable interlancing |
| 522 | 522 | imageinterlace($img, true); |
@@ -582,12 +582,12 @@ discard block |
||
| 582 | 582 | * - false sinon. |
| 583 | 583 | */ |
| 584 | 584 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE) { |
| 585 | - $fonction = "_image_image" . $valeurs['format_dest']; |
|
| 585 | + $fonction = "_image_image".$valeurs['format_dest']; |
|
| 586 | 586 | $ret = false; |
| 587 | 587 | #un flag pour reperer les images gravees |
| 588 | 588 | $lock = |
| 589 | 589 | !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
| 590 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 590 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src')); |
|
| 591 | 591 | if ( |
| 592 | 592 | function_exists($fonction) |
| 593 | 593 | && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | // dans tous les cas mettre a jour la taille de l'image finale |
| 599 | 599 | list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']); |
| 600 | 600 | $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
| 601 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 601 | + ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true); |
|
| 602 | 602 | } |
| 603 | 603 | } |
| 604 | 604 | |
@@ -617,7 +617,7 @@ discard block |
||
| 617 | 617 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 618 | 618 | $reconstruire = array(); |
| 619 | 619 | $fichier = $fichier_manquant; |
| 620 | - while (strpos($fichier,"://")===false |
|
| 620 | + while (strpos($fichier, "://") === false |
|
| 621 | 621 | and !@file_exists($fichier) |
| 622 | 622 | and lire_fichier($src = "$fichier.src", $source) |
| 623 | 623 | and $valeurs = unserialize($source) |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | * Chemin du fichier d'image calculé |
| 655 | 655 | **/ |
| 656 | 656 | function ramasse_miettes($fichier) { |
| 657 | - if (strpos($fichier,"://")!==false |
|
| 657 | + if (strpos($fichier, "://") !== false |
|
| 658 | 658 | or !lire_fichier($src = "$fichier.src", $source) |
| 659 | 659 | or !$valeurs = unserialize($source) |
| 660 | 660 | ) { |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | } |
| 711 | 711 | # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
| 712 | 712 | # et qu'il ne s'agit pas d'une URL |
| 713 | - if (strpos($fichier,"://")===false and !@file_exists($fichier)) { |
|
| 713 | + if (strpos($fichier, "://") === false and !@file_exists($fichier)) { |
|
| 714 | 714 | reconstruire_image_intermediaire($fichier); |
| 715 | 715 | } |
| 716 | 716 | ramasse_miettes($fichier); |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | |
| 808 | 808 | // attributs deprecies. Transformer en CSS |
| 809 | 809 | if ($espace = extraire_attribut($tag, 'hspace')) { |
| 810 | - $style = "margin:${espace}px;" . $style; |
|
| 810 | + $style = "margin:${espace}px;".$style; |
|
| 811 | 811 | $tag = inserer_attribut($tag, 'hspace', ''); |
| 812 | 812 | } |
| 813 | 813 | |
@@ -931,7 +931,7 @@ discard block |
||
| 931 | 931 | $image = $valeurs['fichier']; |
| 932 | 932 | $format = $valeurs['format_source']; |
| 933 | 933 | $destdir = dirname($valeurs['fichier_dest']); |
| 934 | - $destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]); |
|
| 934 | + $destfile = basename($valeurs['fichier_dest'], ".".$valeurs["format_dest"]); |
|
| 935 | 935 | |
| 936 | 936 | $format_sortie = $valeurs['format_dest']; |
| 937 | 937 | |
@@ -966,7 +966,7 @@ discard block |
||
| 966 | 966 | |
| 967 | 967 | // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
| 968 | 968 | if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
| 969 | - $vignette = $destination . '.' . $format; |
|
| 969 | + $vignette = $destination.'.'.$format; |
|
| 970 | 970 | @copy($image, $vignette); |
| 971 | 971 | } // imagemagick en ligne de commande |
| 972 | 972 | elseif ($process == 'convert') { |
@@ -974,9 +974,9 @@ discard block |
||
| 974 | 974 | define('_CONVERT_COMMAND', 'convert'); |
| 975 | 975 | } // Securite : mes_options.php peut preciser le chemin absolu |
| 976 | 976 | if (!defined('_RESIZE_COMMAND')) { |
| 977 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 977 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest'); |
|
| 978 | 978 | } |
| 979 | - $vignette = $destination . "." . $format_sortie; |
|
| 979 | + $vignette = $destination.".".$format_sortie; |
|
| 980 | 980 | $commande = str_replace( |
| 981 | 981 | array('%x', '%y', '%src', '%dest'), |
| 982 | 982 | array( |
@@ -991,11 +991,11 @@ discard block |
||
| 991 | 991 | if (!@file_exists($vignette)) { |
| 992 | 992 | spip_log("echec convert sur $vignette"); |
| 993 | 993 | |
| 994 | - return; // echec commande |
|
| 994 | + return; // echec commande |
|
| 995 | 995 | } |
| 996 | 996 | } // php5 imagemagick |
| 997 | 997 | elseif ($process == 'imagick') { |
| 998 | - $vignette = "$destination." . $format_sortie; |
|
| 998 | + $vignette = "$destination.".$format_sortie; |
|
| 999 | 999 | |
| 1000 | 1000 | if (!class_exists('Imagick')) { |
| 1001 | 1001 | spip_log("Classe Imagick absente !", _LOG_ERREUR); |
@@ -1005,7 +1005,7 @@ discard block |
||
| 1005 | 1005 | $imagick = new Imagick(); |
| 1006 | 1006 | $imagick->readImage($image); |
| 1007 | 1007 | $imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS, |
| 1008 | - 1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1008 | + 1); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1009 | 1009 | $imagick->writeImage($vignette); |
| 1010 | 1010 | |
| 1011 | 1011 | if (!@file_exists($vignette)) { |
@@ -1021,12 +1021,12 @@ discard block |
||
| 1021 | 1021 | if (_PNMSCALE_COMMAND == '') { |
| 1022 | 1022 | return; |
| 1023 | 1023 | } |
| 1024 | - $vignette = $destination . "." . $format_sortie; |
|
| 1024 | + $vignette = $destination.".".$format_sortie; |
|
| 1025 | 1025 | $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND); |
| 1026 | 1026 | if ($format == "jpg") { |
| 1027 | 1027 | |
| 1028 | 1028 | $jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND); |
| 1029 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1029 | + exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1030 | 1030 | if (!($s = @filesize($vignette))) { |
| 1031 | 1031 | spip_unlink($vignette); |
| 1032 | 1032 | } |
@@ -1038,7 +1038,7 @@ discard block |
||
| 1038 | 1038 | } else { |
| 1039 | 1039 | if ($format == "gif") { |
| 1040 | 1040 | $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND); |
| 1041 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1041 | + exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1042 | 1042 | if (!($s = @filesize($vignette))) { |
| 1043 | 1043 | spip_unlink($vignette); |
| 1044 | 1044 | } |
@@ -1050,7 +1050,7 @@ discard block |
||
| 1050 | 1050 | } else { |
| 1051 | 1051 | if ($format == "png") { |
| 1052 | 1052 | $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND); |
| 1053 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1053 | + exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1054 | 1054 | if (!($s = @filesize($vignette))) { |
| 1055 | 1055 | spip_unlink($vignette); |
| 1056 | 1056 | } |
@@ -1070,7 +1070,7 @@ discard block |
||
| 1070 | 1070 | return; |
| 1071 | 1071 | } |
| 1072 | 1072 | if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
| 1073 | - spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels"); |
|
| 1073 | + spip_log("vignette gd1/gd2 impossible : ".$srcWidth * $srcHeight."pixels"); |
|
| 1074 | 1074 | |
| 1075 | 1075 | return; |
| 1076 | 1076 | } |
@@ -1357,7 +1357,7 @@ discard block |
||
| 1357 | 1357 | // de l'image, de facon a tromper le cache du navigateur |
| 1358 | 1358 | // quand on fait supprimer/reuploader un logo |
| 1359 | 1359 | // (pas de filemtime si SAFE MODE) |
| 1360 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1360 | + $date = test_espace_prive() ? ('?'.$date) : ''; |
|
| 1361 | 1361 | |
| 1362 | 1362 | return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight)); |
| 1363 | 1363 | } else # SVG par exemple ? BMP, tiff ... les redacteurs osent tout! |
@@ -1404,7 +1404,7 @@ discard block |
||
| 1404 | 1404 | public static function LittleEndian2String($number, $minbytes = 1) { |
| 1405 | 1405 | $intstring = ''; |
| 1406 | 1406 | while ($number > 0) { |
| 1407 | - $intstring = $intstring . chr($number & 255); |
|
| 1407 | + $intstring = $intstring.chr($number & 255); |
|
| 1408 | 1408 | $number >>= 8; |
| 1409 | 1409 | } |
| 1410 | 1410 | |
@@ -1437,9 +1437,9 @@ discard block |
||
| 1437 | 1437 | $b = $argb['blue']; |
| 1438 | 1438 | |
| 1439 | 1439 | if ($bpp[$key] == 32) { |
| 1440 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1440 | + $icXOR[$key] .= chr($b).chr($g).chr($r).chr($a); |
|
| 1441 | 1441 | } elseif ($bpp[$key] == 24) { |
| 1442 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1442 | + $icXOR[$key] .= chr($b).chr($g).chr($r); |
|
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | 1445 | if ($a < 128) { |
@@ -1467,44 +1467,44 @@ discard block |
||
| 1467 | 1467 | |
| 1468 | 1468 | // BITMAPINFOHEADER - 40 bytes |
| 1469 | 1469 | $BitmapInfoHeader[$key] = ''; |
| 1470 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1471 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1470 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1471 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1472 | 1472 | // The biHeight member specifies the combined |
| 1473 | 1473 | // height of the XOR and AND masks. |
| 1474 | 1474 | $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
| 1475 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1476 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1477 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1478 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1479 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1480 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1481 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1482 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1475 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1476 | + $BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount; |
|
| 1477 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1478 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1479 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1480 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1481 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1482 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | |
| 1486 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1487 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1488 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1486 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1487 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1488 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1489 | 1489 | |
| 1490 | 1490 | $dwImageOffset = 6 + (count($gd_image_array) * 16); |
| 1491 | 1491 | foreach ($gd_image_array as $key => $gd_image) { |
| 1492 | 1492 | // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
| 1493 | 1493 | |
| 1494 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1495 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1496 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1497 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1494 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1495 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1496 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1497 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1498 | 1498 | |
| 1499 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1500 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1499 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1500 | + $icondata .= chr($bpp[$key])."\x00"; // wBitCount; // Bits per pixel |
|
| 1501 | 1501 | |
| 1502 | 1502 | $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
| 1503 | 1503 | $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, |
| 1504 | - 4); // dwBytesInRes; // How many bytes in this resource? |
|
| 1504 | + 4); // dwBytesInRes; // How many bytes in this resource? |
|
| 1505 | 1505 | |
| 1506 | 1506 | $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, |
| 1507 | - 4); // dwImageOffset; // Where in the file is this image? |
|
| 1507 | + 4); // dwImageOffset; // Where in the file is this image? |
|
| 1508 | 1508 | $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
| 1509 | 1509 | $dwImageOffset += strlen($icXOR[$key]); |
| 1510 | 1510 | $dwImageOffset += strlen($icAND[$key]); |
@@ -122,7 +122,7 @@ |
||
| 122 | 122 | * @param int $height_max |
| 123 | 123 | * Hauteur minimale de l'image à traiter (10000 par défaut) |
| 124 | 124 | * @return |
| 125 | - * Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas |
|
| 125 | + string Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas |
|
| 126 | 126 | */ |
| 127 | 127 | function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) { |
| 128 | 128 | if (!$img) { |
@@ -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 | include_spip('inc/filtres_images_lib_mini'); // par precaution |
| 24 | 24 | |
@@ -31,161 +31,161 @@ discard block |
||
| 31 | 31 | * Le code hexadécimal de la couleur (sans le #) ou le code couleur textuel si non trouvé |
| 32 | 32 | */ |
| 33 | 33 | function couleur_html_to_hex($couleur) { |
| 34 | - $couleurs_html = array( |
|
| 35 | - 'aliceblue' => 'F0F8FF', |
|
| 36 | - 'antiquewhite' => 'FAEBD7', |
|
| 37 | - 'aqua' => '00FFFF', |
|
| 38 | - 'aquamarine' => '7FFFD4', |
|
| 39 | - 'azure' => 'F0FFFF', |
|
| 40 | - 'beige' => 'F5F5DC', |
|
| 41 | - 'bisque' => 'FFE4C4', |
|
| 42 | - 'black' => '000000', |
|
| 43 | - 'blanchedalmond' => 'FFEBCD', |
|
| 44 | - 'blue' => '0000FF', |
|
| 45 | - 'blueviolet' => '8A2BE2', |
|
| 46 | - 'brown' => 'A52A2A', |
|
| 47 | - 'burlywood' => 'DEB887', |
|
| 48 | - 'cadetblue' => '5F9EA0', |
|
| 49 | - 'chartreuse' => '7FFF00', |
|
| 50 | - 'chocolate' => 'D2691E', |
|
| 51 | - 'coral' => 'FF7F50', |
|
| 52 | - 'cornflowerblue' => '6495ED', |
|
| 53 | - 'cornsilk' => 'FFF8DC', |
|
| 54 | - 'crimson' => 'DC143C', |
|
| 55 | - 'cyan' => '00FFFF', |
|
| 56 | - 'darkblue' => '00008B', |
|
| 57 | - 'darkcyan' => '008B8B', |
|
| 58 | - 'darkgoldenrod' => 'B8860B', |
|
| 59 | - 'darkgray' => 'A9A9A9', |
|
| 60 | - 'darkgreen' => '006400', |
|
| 61 | - 'darkgrey' => 'A9A9A9', |
|
| 62 | - 'darkkhaki' => 'BDB76B', |
|
| 63 | - 'darkmagenta' => '8B008B', |
|
| 64 | - 'darkolivegreen' => '556B2F', |
|
| 65 | - 'darkorange' => 'FF8C00', |
|
| 66 | - 'darkorchid' => '9932CC', |
|
| 67 | - 'darkred' => '8B0000', |
|
| 68 | - 'darksalmon' => 'E9967A', |
|
| 69 | - 'darkseagreen' => '8FBC8F', |
|
| 70 | - 'darkslateblue' => '483D8B', |
|
| 71 | - 'darkslategray' => '2F4F4F', |
|
| 72 | - 'darkslategrey' => '2F4F4F', |
|
| 73 | - 'darkturquoise' => '00CED1', |
|
| 74 | - 'darkviolet' => '9400D3', |
|
| 75 | - 'deeppink' => 'FF1493', |
|
| 76 | - 'deepskyblue' => '00BFFF', |
|
| 77 | - 'dimgray' => '696969', |
|
| 78 | - 'dimgrey' => '696969', |
|
| 79 | - 'dodgerblue' => '1E90FF', |
|
| 80 | - 'firebrick' => 'B22222', |
|
| 81 | - 'floralwhite' => 'FFFAF0', |
|
| 82 | - 'forestgreen' => '228B22', |
|
| 83 | - 'fuchsia' => 'FF00FF', |
|
| 84 | - 'gainsboro' => 'DCDCDC', |
|
| 85 | - 'ghostwhite' => 'F8F8FF', |
|
| 86 | - 'gold' => 'FFD700', |
|
| 87 | - 'goldenrod' => 'DAA520', |
|
| 88 | - 'gray' => '808080', |
|
| 89 | - 'green' => '008000', |
|
| 90 | - 'greenyellow' => 'ADFF2F', |
|
| 91 | - 'grey' => '808080', |
|
| 92 | - 'honeydew' => 'F0FFF0', |
|
| 93 | - 'hotpink' => 'FF69B4', |
|
| 94 | - 'indianred' => 'CD5C5C', |
|
| 95 | - 'indigo' => '4B0082', |
|
| 96 | - 'ivory' => 'FFFFF0', |
|
| 97 | - 'khaki' => 'F0E68C', |
|
| 98 | - 'lavender' => 'E6E6FA', |
|
| 99 | - 'lavenderblush' => 'FFF0F5', |
|
| 100 | - 'lawngreen' => '7CFC00', |
|
| 101 | - 'lemonchiffon' => 'FFFACD', |
|
| 102 | - 'lightblue' => 'ADD8E6', |
|
| 103 | - 'lightcoral' => 'F08080', |
|
| 104 | - 'lightcyan' => 'E0FFFF', |
|
| 105 | - 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 106 | - 'lightgray' => 'D3D3D3', |
|
| 107 | - 'lightgreen' => '90EE90', |
|
| 108 | - 'lightgrey' => 'D3D3D3', |
|
| 109 | - 'lightpink' => 'FFB6C1', |
|
| 110 | - 'lightsalmon' => 'FFA07A', |
|
| 111 | - 'lightseagreen' => '20B2AA', |
|
| 112 | - 'lightskyblue' => '87CEFA', |
|
| 113 | - 'lightslategray' => '778899', |
|
| 114 | - 'lightslategrey' => '778899', |
|
| 115 | - 'lightsteelblue' => 'B0C4DE', |
|
| 116 | - 'lightyellow' => 'FFFFE0', |
|
| 117 | - 'lime' => '00FF00', |
|
| 118 | - 'limegreen' => '32CD32', |
|
| 119 | - 'linen' => 'FAF0E6', |
|
| 120 | - 'magenta' => 'FF00FF', |
|
| 121 | - 'maroon' => '800000', |
|
| 122 | - 'mediumaquamarine' => '66CDAA', |
|
| 123 | - 'mediumblue' => '0000CD', |
|
| 124 | - 'mediumorchid' => 'BA55D3', |
|
| 125 | - 'mediumpurple' => '9370DB', |
|
| 126 | - 'mediumseagreen' => '3CB371', |
|
| 127 | - 'mediumslateblue' => '7B68EE', |
|
| 128 | - 'mediumspringgreen' => '00FA9A', |
|
| 129 | - 'mediumturquoise' => '48D1CC', |
|
| 130 | - 'mediumvioletred' => 'C71585', |
|
| 131 | - 'midnightblue' => '191970', |
|
| 132 | - 'mintcream' => 'F5FFFA', |
|
| 133 | - 'mistyrose' => 'FFE4E1', |
|
| 134 | - 'moccasin' => 'FFE4B5', |
|
| 135 | - 'navajowhite' => 'FFDEAD', |
|
| 136 | - 'navy' => '000080', |
|
| 137 | - 'oldlace' => 'FDF5E6', |
|
| 138 | - 'olive' => '808000', |
|
| 139 | - 'olivedrab' => '6B8E23', |
|
| 140 | - 'orange' => 'FFA500', |
|
| 141 | - 'orangered' => 'FF4500', |
|
| 142 | - 'orchid' => 'DA70D6', |
|
| 143 | - 'palegoldenrod' => 'EEE8AA', |
|
| 144 | - 'palegreen' => '98FB98', |
|
| 145 | - 'paleturquoise' => 'AFEEEE', |
|
| 146 | - 'palevioletred' => 'DB7093', |
|
| 147 | - 'papayawhip' => 'FFEFD5', |
|
| 148 | - 'peachpuff' => 'FFDAB9', |
|
| 149 | - 'peru' => 'CD853F', |
|
| 150 | - 'pink' => 'FFC0CB', |
|
| 151 | - 'plum' => 'DDA0DD', |
|
| 152 | - 'powderblue' => 'B0E0E6', |
|
| 153 | - 'purple' => '800080', |
|
| 154 | - 'rebeccapurple' => '663399', |
|
| 155 | - 'red' => 'FF0000', |
|
| 156 | - 'rosybrown' => 'BC8F8F', |
|
| 157 | - 'royalblue' => '4169E1', |
|
| 158 | - 'saddlebrown' => '8B4513', |
|
| 159 | - 'salmon' => 'FA8072', |
|
| 160 | - 'sandybrown' => 'F4A460', |
|
| 161 | - 'seagreen' => '2E8B57', |
|
| 162 | - 'seashell' => 'FFF5EE', |
|
| 163 | - 'sienna' => 'A0522D', |
|
| 164 | - 'silver' => 'C0C0C0', |
|
| 165 | - 'skyblue' => '87CEEB', |
|
| 166 | - 'slateblue' => '6A5ACD', |
|
| 167 | - 'slategray' => '708090', |
|
| 168 | - 'slategrey' => '708090', |
|
| 169 | - 'snow' => 'FFFAFA', |
|
| 170 | - 'springgreen' => '00FF7F', |
|
| 171 | - 'steelblue' => '4682B4', |
|
| 172 | - 'tan' => 'D2B48C', |
|
| 173 | - 'teal' => '008080', |
|
| 174 | - 'thistle' => 'D8BFD8', |
|
| 175 | - 'tomato' => 'FF6347', |
|
| 176 | - 'turquoise' => '40E0D0', |
|
| 177 | - 'violet' => 'EE82EE', |
|
| 178 | - 'wheat' => 'F5DEB3', |
|
| 179 | - 'white' => 'FFFFFF', |
|
| 180 | - 'whitesmoke' => 'F5F5F5', |
|
| 181 | - 'yellow' => 'FFFF00', |
|
| 182 | - 'yellowgreen' => '9ACD32', |
|
| 183 | - ); |
|
| 184 | - if (isset($couleurs_html[$lc = strtolower($couleur)])) { |
|
| 185 | - return $couleurs_html[$lc]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $couleur; |
|
| 34 | + $couleurs_html = array( |
|
| 35 | + 'aliceblue' => 'F0F8FF', |
|
| 36 | + 'antiquewhite' => 'FAEBD7', |
|
| 37 | + 'aqua' => '00FFFF', |
|
| 38 | + 'aquamarine' => '7FFFD4', |
|
| 39 | + 'azure' => 'F0FFFF', |
|
| 40 | + 'beige' => 'F5F5DC', |
|
| 41 | + 'bisque' => 'FFE4C4', |
|
| 42 | + 'black' => '000000', |
|
| 43 | + 'blanchedalmond' => 'FFEBCD', |
|
| 44 | + 'blue' => '0000FF', |
|
| 45 | + 'blueviolet' => '8A2BE2', |
|
| 46 | + 'brown' => 'A52A2A', |
|
| 47 | + 'burlywood' => 'DEB887', |
|
| 48 | + 'cadetblue' => '5F9EA0', |
|
| 49 | + 'chartreuse' => '7FFF00', |
|
| 50 | + 'chocolate' => 'D2691E', |
|
| 51 | + 'coral' => 'FF7F50', |
|
| 52 | + 'cornflowerblue' => '6495ED', |
|
| 53 | + 'cornsilk' => 'FFF8DC', |
|
| 54 | + 'crimson' => 'DC143C', |
|
| 55 | + 'cyan' => '00FFFF', |
|
| 56 | + 'darkblue' => '00008B', |
|
| 57 | + 'darkcyan' => '008B8B', |
|
| 58 | + 'darkgoldenrod' => 'B8860B', |
|
| 59 | + 'darkgray' => 'A9A9A9', |
|
| 60 | + 'darkgreen' => '006400', |
|
| 61 | + 'darkgrey' => 'A9A9A9', |
|
| 62 | + 'darkkhaki' => 'BDB76B', |
|
| 63 | + 'darkmagenta' => '8B008B', |
|
| 64 | + 'darkolivegreen' => '556B2F', |
|
| 65 | + 'darkorange' => 'FF8C00', |
|
| 66 | + 'darkorchid' => '9932CC', |
|
| 67 | + 'darkred' => '8B0000', |
|
| 68 | + 'darksalmon' => 'E9967A', |
|
| 69 | + 'darkseagreen' => '8FBC8F', |
|
| 70 | + 'darkslateblue' => '483D8B', |
|
| 71 | + 'darkslategray' => '2F4F4F', |
|
| 72 | + 'darkslategrey' => '2F4F4F', |
|
| 73 | + 'darkturquoise' => '00CED1', |
|
| 74 | + 'darkviolet' => '9400D3', |
|
| 75 | + 'deeppink' => 'FF1493', |
|
| 76 | + 'deepskyblue' => '00BFFF', |
|
| 77 | + 'dimgray' => '696969', |
|
| 78 | + 'dimgrey' => '696969', |
|
| 79 | + 'dodgerblue' => '1E90FF', |
|
| 80 | + 'firebrick' => 'B22222', |
|
| 81 | + 'floralwhite' => 'FFFAF0', |
|
| 82 | + 'forestgreen' => '228B22', |
|
| 83 | + 'fuchsia' => 'FF00FF', |
|
| 84 | + 'gainsboro' => 'DCDCDC', |
|
| 85 | + 'ghostwhite' => 'F8F8FF', |
|
| 86 | + 'gold' => 'FFD700', |
|
| 87 | + 'goldenrod' => 'DAA520', |
|
| 88 | + 'gray' => '808080', |
|
| 89 | + 'green' => '008000', |
|
| 90 | + 'greenyellow' => 'ADFF2F', |
|
| 91 | + 'grey' => '808080', |
|
| 92 | + 'honeydew' => 'F0FFF0', |
|
| 93 | + 'hotpink' => 'FF69B4', |
|
| 94 | + 'indianred' => 'CD5C5C', |
|
| 95 | + 'indigo' => '4B0082', |
|
| 96 | + 'ivory' => 'FFFFF0', |
|
| 97 | + 'khaki' => 'F0E68C', |
|
| 98 | + 'lavender' => 'E6E6FA', |
|
| 99 | + 'lavenderblush' => 'FFF0F5', |
|
| 100 | + 'lawngreen' => '7CFC00', |
|
| 101 | + 'lemonchiffon' => 'FFFACD', |
|
| 102 | + 'lightblue' => 'ADD8E6', |
|
| 103 | + 'lightcoral' => 'F08080', |
|
| 104 | + 'lightcyan' => 'E0FFFF', |
|
| 105 | + 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 106 | + 'lightgray' => 'D3D3D3', |
|
| 107 | + 'lightgreen' => '90EE90', |
|
| 108 | + 'lightgrey' => 'D3D3D3', |
|
| 109 | + 'lightpink' => 'FFB6C1', |
|
| 110 | + 'lightsalmon' => 'FFA07A', |
|
| 111 | + 'lightseagreen' => '20B2AA', |
|
| 112 | + 'lightskyblue' => '87CEFA', |
|
| 113 | + 'lightslategray' => '778899', |
|
| 114 | + 'lightslategrey' => '778899', |
|
| 115 | + 'lightsteelblue' => 'B0C4DE', |
|
| 116 | + 'lightyellow' => 'FFFFE0', |
|
| 117 | + 'lime' => '00FF00', |
|
| 118 | + 'limegreen' => '32CD32', |
|
| 119 | + 'linen' => 'FAF0E6', |
|
| 120 | + 'magenta' => 'FF00FF', |
|
| 121 | + 'maroon' => '800000', |
|
| 122 | + 'mediumaquamarine' => '66CDAA', |
|
| 123 | + 'mediumblue' => '0000CD', |
|
| 124 | + 'mediumorchid' => 'BA55D3', |
|
| 125 | + 'mediumpurple' => '9370DB', |
|
| 126 | + 'mediumseagreen' => '3CB371', |
|
| 127 | + 'mediumslateblue' => '7B68EE', |
|
| 128 | + 'mediumspringgreen' => '00FA9A', |
|
| 129 | + 'mediumturquoise' => '48D1CC', |
|
| 130 | + 'mediumvioletred' => 'C71585', |
|
| 131 | + 'midnightblue' => '191970', |
|
| 132 | + 'mintcream' => 'F5FFFA', |
|
| 133 | + 'mistyrose' => 'FFE4E1', |
|
| 134 | + 'moccasin' => 'FFE4B5', |
|
| 135 | + 'navajowhite' => 'FFDEAD', |
|
| 136 | + 'navy' => '000080', |
|
| 137 | + 'oldlace' => 'FDF5E6', |
|
| 138 | + 'olive' => '808000', |
|
| 139 | + 'olivedrab' => '6B8E23', |
|
| 140 | + 'orange' => 'FFA500', |
|
| 141 | + 'orangered' => 'FF4500', |
|
| 142 | + 'orchid' => 'DA70D6', |
|
| 143 | + 'palegoldenrod' => 'EEE8AA', |
|
| 144 | + 'palegreen' => '98FB98', |
|
| 145 | + 'paleturquoise' => 'AFEEEE', |
|
| 146 | + 'palevioletred' => 'DB7093', |
|
| 147 | + 'papayawhip' => 'FFEFD5', |
|
| 148 | + 'peachpuff' => 'FFDAB9', |
|
| 149 | + 'peru' => 'CD853F', |
|
| 150 | + 'pink' => 'FFC0CB', |
|
| 151 | + 'plum' => 'DDA0DD', |
|
| 152 | + 'powderblue' => 'B0E0E6', |
|
| 153 | + 'purple' => '800080', |
|
| 154 | + 'rebeccapurple' => '663399', |
|
| 155 | + 'red' => 'FF0000', |
|
| 156 | + 'rosybrown' => 'BC8F8F', |
|
| 157 | + 'royalblue' => '4169E1', |
|
| 158 | + 'saddlebrown' => '8B4513', |
|
| 159 | + 'salmon' => 'FA8072', |
|
| 160 | + 'sandybrown' => 'F4A460', |
|
| 161 | + 'seagreen' => '2E8B57', |
|
| 162 | + 'seashell' => 'FFF5EE', |
|
| 163 | + 'sienna' => 'A0522D', |
|
| 164 | + 'silver' => 'C0C0C0', |
|
| 165 | + 'skyblue' => '87CEEB', |
|
| 166 | + 'slateblue' => '6A5ACD', |
|
| 167 | + 'slategray' => '708090', |
|
| 168 | + 'slategrey' => '708090', |
|
| 169 | + 'snow' => 'FFFAFA', |
|
| 170 | + 'springgreen' => '00FF7F', |
|
| 171 | + 'steelblue' => '4682B4', |
|
| 172 | + 'tan' => 'D2B48C', |
|
| 173 | + 'teal' => '008080', |
|
| 174 | + 'thistle' => 'D8BFD8', |
|
| 175 | + 'tomato' => 'FF6347', |
|
| 176 | + 'turquoise' => '40E0D0', |
|
| 177 | + 'violet' => 'EE82EE', |
|
| 178 | + 'wheat' => 'F5DEB3', |
|
| 179 | + 'white' => 'FFFFFF', |
|
| 180 | + 'whitesmoke' => 'F5F5F5', |
|
| 181 | + 'yellow' => 'FFFF00', |
|
| 182 | + 'yellowgreen' => '9ACD32', |
|
| 183 | + ); |
|
| 184 | + if (isset($couleurs_html[$lc = strtolower($couleur)])) { |
|
| 185 | + return $couleurs_html[$lc]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $couleur; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -201,15 +201,15 @@ discard block |
||
| 201 | 201 | * Code hexadécimal de la couleur plus foncée |
| 202 | 202 | */ |
| 203 | 203 | function couleur_foncer($couleur, $coeff = 0.5) { |
| 204 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 204 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 205 | 205 | |
| 206 | - $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 207 | - $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 208 | - $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 206 | + $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 207 | + $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 208 | + $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 209 | 209 | |
| 210 | - $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 210 | + $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 211 | 211 | |
| 212 | - return $couleur; |
|
| 212 | + return $couleur; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -225,15 +225,15 @@ discard block |
||
| 225 | 225 | * Code hexadécimal de la couleur éclaircie |
| 226 | 226 | */ |
| 227 | 227 | function couleur_eclaircir($couleur, $coeff = 0.5) { |
| 228 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 228 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 229 | 229 | |
| 230 | - $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 231 | - $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 232 | - $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 230 | + $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 231 | + $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 232 | + $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 233 | 233 | |
| 234 | - $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 234 | + $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 235 | 235 | |
| 236 | - return $couleur; |
|
| 236 | + return $couleur; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -256,28 +256,28 @@ discard block |
||
| 256 | 256 | * Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas |
| 257 | 257 | */ |
| 258 | 258 | function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) { |
| 259 | - if (!$img) { |
|
| 260 | - return $img; |
|
| 261 | - } |
|
| 262 | - list($h, $l) = taille_image($img); |
|
| 263 | - $select = true; |
|
| 264 | - if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) { |
|
| 265 | - $select = false; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - $class = extraire_attribut($img, 'class'); |
|
| 269 | - $p = strpos($class, 'filtre_inactif'); |
|
| 270 | - if (($select == false) and ($p === false)) { |
|
| 271 | - $class .= ' filtre_inactif'; |
|
| 272 | - $img = inserer_attribut($img, 'class', $class); |
|
| 273 | - } |
|
| 274 | - if (($select == true) and ($p !== false)) { |
|
| 275 | - // no_image_filtrer : historique, a virer |
|
| 276 | - $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 277 | - $img = inserer_attribut($img, 'class', $class); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - return $img; |
|
| 259 | + if (!$img) { |
|
| 260 | + return $img; |
|
| 261 | + } |
|
| 262 | + list($h, $l) = taille_image($img); |
|
| 263 | + $select = true; |
|
| 264 | + if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) { |
|
| 265 | + $select = false; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + $class = extraire_attribut($img, 'class'); |
|
| 269 | + $p = strpos($class, 'filtre_inactif'); |
|
| 270 | + if (($select == false) and ($p === false)) { |
|
| 271 | + $class .= ' filtre_inactif'; |
|
| 272 | + $img = inserer_attribut($img, 'class', $class); |
|
| 273 | + } |
|
| 274 | + if (($select == true) and ($p !== false)) { |
|
| 275 | + // no_image_filtrer : historique, a virer |
|
| 276 | + $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 277 | + $img = inserer_attribut($img, 'class', $class); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + return $img; |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -325,38 +325,38 @@ discard block |
||
| 325 | 325 | * Code HTML de l'image ou du texte. |
| 326 | 326 | **/ |
| 327 | 327 | function image_passe_partout( |
| 328 | - $img, |
|
| 329 | - $taille_x = -1, |
|
| 330 | - $taille_y = -1, |
|
| 331 | - $force = false, |
|
| 332 | - $cherche_image = false, |
|
| 333 | - $process = 'AUTO' |
|
| 328 | + $img, |
|
| 329 | + $taille_x = -1, |
|
| 330 | + $taille_y = -1, |
|
| 331 | + $force = false, |
|
| 332 | + $cherche_image = false, |
|
| 333 | + $process = 'AUTO' |
|
| 334 | 334 | ) { |
| 335 | - if (!$img) { |
|
| 336 | - return ''; |
|
| 337 | - } |
|
| 338 | - list($hauteur, $largeur) = taille_image($img); |
|
| 339 | - if ($taille_x == -1) { |
|
| 340 | - $taille_x = isset($GLOBALS['meta']['taille_preview']) ? $GLOBALS['meta']['taille_preview'] : 150; |
|
| 341 | - } |
|
| 342 | - if ($taille_y == -1) { |
|
| 343 | - $taille_y = $taille_x; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - if ($taille_x == 0 and $taille_y > 0) { |
|
| 347 | - $taille_x = 1; |
|
| 348 | - } # {0,300} -> c'est 300 qui compte |
|
| 349 | - elseif ($taille_x > 0 and $taille_y == 0) { |
|
| 350 | - $taille_y = 1; |
|
| 351 | - } # {300,0} -> c'est 300 qui compte |
|
| 352 | - elseif ($taille_x == 0 and $taille_y == 0) { |
|
| 353 | - return ''; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - list($destWidth, $destHeight, $ratio) = ratio_passe_partout($largeur, $hauteur, $taille_x, $taille_y); |
|
| 357 | - $fonction = array('image_passe_partout', func_get_args()); |
|
| 358 | - |
|
| 359 | - return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 335 | + if (!$img) { |
|
| 336 | + return ''; |
|
| 337 | + } |
|
| 338 | + list($hauteur, $largeur) = taille_image($img); |
|
| 339 | + if ($taille_x == -1) { |
|
| 340 | + $taille_x = isset($GLOBALS['meta']['taille_preview']) ? $GLOBALS['meta']['taille_preview'] : 150; |
|
| 341 | + } |
|
| 342 | + if ($taille_y == -1) { |
|
| 343 | + $taille_y = $taille_x; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + if ($taille_x == 0 and $taille_y > 0) { |
|
| 347 | + $taille_x = 1; |
|
| 348 | + } # {0,300} -> c'est 300 qui compte |
|
| 349 | + elseif ($taille_x > 0 and $taille_y == 0) { |
|
| 350 | + $taille_y = 1; |
|
| 351 | + } # {300,0} -> c'est 300 qui compte |
|
| 352 | + elseif ($taille_x == 0 and $taille_y == 0) { |
|
| 353 | + return ''; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + list($destWidth, $destHeight, $ratio) = ratio_passe_partout($largeur, $hauteur, $taille_x, $taille_y); |
|
| 357 | + $fonction = array('image_passe_partout', func_get_args()); |
|
| 358 | + |
|
| 359 | + return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -399,28 +399,28 @@ discard block |
||
| 399 | 399 | * Code HTML de l'image ou du texte. |
| 400 | 400 | **/ |
| 401 | 401 | function image_reduire($img, $taille = -1, $taille_y = -1, $force = false, $cherche_image = false, $process = 'AUTO') { |
| 402 | - // Determiner la taille x,y maxi |
|
| 403 | - // prendre le reglage de previsu par defaut |
|
| 404 | - if ($taille == -1) { |
|
| 405 | - $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) ? intval($GLOBALS['meta']['taille_preview']) : 150; |
|
| 406 | - } |
|
| 407 | - if ($taille_y == -1) { |
|
| 408 | - $taille_y = $taille; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - if ($taille == 0 and $taille_y > 0) { |
|
| 412 | - $taille = 10000; |
|
| 413 | - } # {0,300} -> c'est 300 qui compte |
|
| 414 | - elseif ($taille > 0 and $taille_y == 0) { |
|
| 415 | - $taille_y = 10000; |
|
| 416 | - } # {300,0} -> c'est 300 qui compte |
|
| 417 | - elseif ($taille == 0 and $taille_y == 0) { |
|
| 418 | - return ''; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - $fonction = array('image_reduire', func_get_args()); |
|
| 422 | - |
|
| 423 | - return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 402 | + // Determiner la taille x,y maxi |
|
| 403 | + // prendre le reglage de previsu par defaut |
|
| 404 | + if ($taille == -1) { |
|
| 405 | + $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) ? intval($GLOBALS['meta']['taille_preview']) : 150; |
|
| 406 | + } |
|
| 407 | + if ($taille_y == -1) { |
|
| 408 | + $taille_y = $taille; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + if ($taille == 0 and $taille_y > 0) { |
|
| 412 | + $taille = 10000; |
|
| 413 | + } # {0,300} -> c'est 300 qui compte |
|
| 414 | + elseif ($taille > 0 and $taille_y == 0) { |
|
| 415 | + $taille_y = 10000; |
|
| 416 | + } # {300,0} -> c'est 300 qui compte |
|
| 417 | + elseif ($taille == 0 and $taille_y == 0) { |
|
| 418 | + return ''; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + $fonction = array('image_reduire', func_get_args()); |
|
| 422 | + |
|
| 423 | + return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | |
@@ -439,20 +439,20 @@ discard block |
||
| 439 | 439 | * Code HTML de l'image ou du texte. |
| 440 | 440 | **/ |
| 441 | 441 | function image_reduire_par($img, $val = 1, $force = false) { |
| 442 | - list($hauteur, $largeur) = taille_image($img); |
|
| 442 | + list($hauteur, $largeur) = taille_image($img); |
|
| 443 | 443 | |
| 444 | - $l = round($largeur / $val); |
|
| 445 | - $h = round($hauteur / $val); |
|
| 444 | + $l = round($largeur / $val); |
|
| 445 | + $h = round($hauteur / $val); |
|
| 446 | 446 | |
| 447 | - if ($l > $h) { |
|
| 448 | - $h = 0; |
|
| 449 | - } else { |
|
| 450 | - $l = 0; |
|
| 451 | - } |
|
| 447 | + if ($l > $h) { |
|
| 448 | + $h = 0; |
|
| 449 | + } else { |
|
| 450 | + $l = 0; |
|
| 451 | + } |
|
| 452 | 452 | |
| 453 | - $img = image_reduire($img, $l, $h, $force); |
|
| 453 | + $img = image_reduire($img, $l, $h, $force); |
|
| 454 | 454 | |
| 455 | - return $img; |
|
| 455 | + return $img; |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | /** |
@@ -473,10 +473,10 @@ discard block |
||
| 473 | 473 | * Couleur en écriture hexadécimale. |
| 474 | 474 | **/ |
| 475 | 475 | function filtre_couleur_saturation_dist($couleur, $val) { |
| 476 | - if (function_exists('couleur_saturation')) { |
|
| 477 | - return couleur_saturation($couleur, $val); |
|
| 478 | - } |
|
| 479 | - return $couleur; |
|
| 476 | + if (function_exists('couleur_saturation')) { |
|
| 477 | + return couleur_saturation($couleur, $val); |
|
| 478 | + } |
|
| 479 | + return $couleur; |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | /** |
@@ -497,8 +497,8 @@ discard block |
||
| 497 | 497 | * Couleur en écriture hexadécimale. |
| 498 | 498 | **/ |
| 499 | 499 | function filtre_couleur_luminance_dist($couleur, $val) { |
| 500 | - if (function_exists('couleur_luminance')) { |
|
| 501 | - return couleur_luminance($couleur, $val); |
|
| 502 | - } |
|
| 503 | - return $couleur; |
|
| 500 | + if (function_exists('couleur_luminance')) { |
|
| 501 | + return couleur_luminance($couleur, $val); |
|
| 502 | + } |
|
| 503 | + return $couleur; |
|
| 504 | 504 | } |
@@ -644,7 +644,7 @@ |
||
| 644 | 644 | * |
| 645 | 645 | * @param string $dir |
| 646 | 646 | * Répertoire à parcourir |
| 647 | - * @param int|string $pattern |
|
| 647 | + * @param integer $pattern |
|
| 648 | 648 | * Expression régulière pour trouver des fichiers, tel que `[.]lock$` |
| 649 | 649 | * @param int $maxfiles |
| 650 | 650 | * Nombre de fichiers maximums retournés |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_TEST_FILE_EXISTS')) { |
| 24 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV["HTTP_HOST"]) ? $_ENV["HTTP_HOST"] : "")); |
|
| 24 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV["HTTP_HOST"]) ? $_ENV["HTTP_HOST"] : "")); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 31 | 31 | |
| 32 | 32 | if (_SPIP_LOCK_MODE == 2) { |
| 33 | - include_spip('inc/nfslock'); |
|
| 33 | + include_spip('inc/nfslock'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $GLOBALS['liste_verrous'] = array(); |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * Ressource sur le fichier ouvert, sinon false. |
| 54 | 54 | **/ |
| 55 | 55 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 56 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | - // verrou |
|
| 59 | - @flock($fl, $verrou); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $fl; |
|
| 63 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | - $GLOBALS['liste_verrous'][$fl] = array($fichier, $verrou); |
|
| 66 | - |
|
| 67 | - return $fl; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return @fopen($fichier, $mode); |
|
| 56 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | + // verrou |
|
| 59 | + @flock($fl, $verrou); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $fl; |
|
| 63 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | + $GLOBALS['liste_verrous'][$fl] = array($fichier, $verrou); |
|
| 66 | + |
|
| 67 | + return $fl; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return @fopen($fichier, $mode); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | * true si succès, false sinon. |
| 86 | 86 | **/ |
| 87 | 87 | function spip_fclose_unlock($handle) { |
| 88 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | - @flock($handle, LOCK_UN); |
|
| 90 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return @fclose($handle); |
|
| 88 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | + @flock($handle, LOCK_UN); |
|
| 90 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return @fclose($handle); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -106,23 +106,23 @@ discard block |
||
| 106 | 106 | * Contenu du fichier |
| 107 | 107 | **/ |
| 108 | 108 | function spip_file_get_contents($fichier) { |
| 109 | - if (substr($fichier, -3) != '.gz') { |
|
| 110 | - if (function_exists('file_get_contents')) { |
|
| 111 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | - // sinon on fait un file() pour avoir le coeur net |
|
| 114 | - $contenu = @file_get_contents($fichier); |
|
| 115 | - if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | - $contenu = @file($fichier); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $contenu = @file($fichier); |
|
| 120 | - } |
|
| 121 | - } else { |
|
| 122 | - $contenu = @gzfile($fichier); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 109 | + if (substr($fichier, -3) != '.gz') { |
|
| 110 | + if (function_exists('file_get_contents')) { |
|
| 111 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | + // sinon on fait un file() pour avoir le coeur net |
|
| 114 | + $contenu = @file_get_contents($fichier); |
|
| 115 | + if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | + $contenu = @file($fichier); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $contenu = @file($fichier); |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + $contenu = @gzfile($fichier); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -147,48 +147,48 @@ discard block |
||
| 147 | 147 | * true si l'opération a réussie, false sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function lire_fichier($fichier, &$contenu, $options = array()) { |
| 150 | - $contenu = ''; |
|
| 151 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | - if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - #spip_timer('lire_fichier'); |
|
| 158 | - |
|
| 159 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | - // lire le fichier avant tout |
|
| 162 | - $contenu = spip_file_get_contents($fichier); |
|
| 163 | - |
|
| 164 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | - // et eviter un acces disque |
|
| 168 | - if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | - spip_fclose_unlock($fl); |
|
| 170 | - |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // liberer le verrou |
|
| 175 | - spip_fclose_unlock($fl); |
|
| 176 | - |
|
| 177 | - // Verifications |
|
| 178 | - $ok = true; |
|
| 179 | - if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | - if (!$ok) { |
|
| 185 | - spip_log("echec lecture $fichier"); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $ok; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 150 | + $contenu = ''; |
|
| 151 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | + if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + #spip_timer('lire_fichier'); |
|
| 158 | + |
|
| 159 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | + // lire le fichier avant tout |
|
| 162 | + $contenu = spip_file_get_contents($fichier); |
|
| 163 | + |
|
| 164 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | + // et eviter un acces disque |
|
| 168 | + if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | + spip_fclose_unlock($fl); |
|
| 170 | + |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // liberer le verrou |
|
| 175 | + spip_fclose_unlock($fl); |
|
| 176 | + |
|
| 177 | + // Verifications |
|
| 178 | + $ok = true; |
|
| 179 | + if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | + if (!$ok) { |
|
| 185 | + spip_log("echec lecture $fichier"); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $ok; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -216,85 +216,85 @@ discard block |
||
| 216 | 216 | **/ |
| 217 | 217 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 218 | 218 | |
| 219 | - #spip_timer('ecrire_fichier'); |
|
| 220 | - |
|
| 221 | - // verrouiller le fichier destination |
|
| 222 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | - // ecrire les donnees, compressees le cas echeant |
|
| 224 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | - if (substr($fichier, -3) == '.gz') { |
|
| 227 | - $contenu = gzencode($contenu); |
|
| 228 | - } |
|
| 229 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | - // pour etre sur d'avoir une operation atomique |
|
| 231 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | - // sauf sous wintruc ou ca ne marche pas |
|
| 233 | - $ok = false; |
|
| 234 | - if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | - if (!function_exists('creer_uniqid')) { |
|
| 236 | - include_spip('inc/acces'); |
|
| 237 | - } |
|
| 238 | - $id = creer_uniqid(); |
|
| 239 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | - $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | - $ok = ($s == $a); |
|
| 243 | - spip_fclose_unlock($fp2); |
|
| 244 | - spip_fclose_unlock($fp); |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - // sinon ou si methode precedente a echoueee |
|
| 265 | - // on se rabat sur la methode ancienne |
|
| 266 | - if (!$ok) { |
|
| 267 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | - if ($truncate) { |
|
| 269 | - @ftruncate($fp, 0); |
|
| 270 | - } |
|
| 271 | - $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | - |
|
| 273 | - $ok = ($s == $a); |
|
| 274 | - spip_fclose_unlock($fp); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // liberer le verrou et fermer le fichier |
|
| 278 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | - if ($ok) { |
|
| 280 | - if (strpos($fichier, ".php") !== false) { |
|
| 281 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $ok; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if (!$ignorer_echec) { |
|
| 289 | - include_spip('inc/autoriser'); |
|
| 290 | - if (autoriser('chargerftp')) { |
|
| 291 | - raler_fichier($fichier); |
|
| 292 | - } |
|
| 293 | - spip_unlink($fichier); |
|
| 294 | - } |
|
| 295 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | - |
|
| 297 | - return false; |
|
| 219 | + #spip_timer('ecrire_fichier'); |
|
| 220 | + |
|
| 221 | + // verrouiller le fichier destination |
|
| 222 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | + // ecrire les donnees, compressees le cas echeant |
|
| 224 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | + if (substr($fichier, -3) == '.gz') { |
|
| 227 | + $contenu = gzencode($contenu); |
|
| 228 | + } |
|
| 229 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | + // pour etre sur d'avoir une operation atomique |
|
| 231 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | + // sauf sous wintruc ou ca ne marche pas |
|
| 233 | + $ok = false; |
|
| 234 | + if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | + if (!function_exists('creer_uniqid')) { |
|
| 236 | + include_spip('inc/acces'); |
|
| 237 | + } |
|
| 238 | + $id = creer_uniqid(); |
|
| 239 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | + $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | + $ok = ($s == $a); |
|
| 243 | + spip_fclose_unlock($fp2); |
|
| 244 | + spip_fclose_unlock($fp); |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + // sinon ou si methode precedente a echoueee |
|
| 265 | + // on se rabat sur la methode ancienne |
|
| 266 | + if (!$ok) { |
|
| 267 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | + if ($truncate) { |
|
| 269 | + @ftruncate($fp, 0); |
|
| 270 | + } |
|
| 271 | + $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | + |
|
| 273 | + $ok = ($s == $a); |
|
| 274 | + spip_fclose_unlock($fp); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // liberer le verrou et fermer le fichier |
|
| 278 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | + if ($ok) { |
|
| 280 | + if (strpos($fichier, ".php") !== false) { |
|
| 281 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $ok; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if (!$ignorer_echec) { |
|
| 289 | + include_spip('inc/autoriser'); |
|
| 290 | + if (autoriser('chargerftp')) { |
|
| 291 | + raler_fichier($fichier); |
|
| 292 | + } |
|
| 293 | + spip_unlink($fichier); |
|
| 294 | + } |
|
| 295 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | + |
|
| 297 | + return false; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | * Écriture avec troncation ? |
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | - if (substr($fichier, -4) !== '.php') { |
|
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | - } |
|
| 320 | - $contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 317 | + if (substr($fichier, -4) !== '.php') { |
|
| 318 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | + } |
|
| 320 | + $contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 321 | 321 | |
| 322 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 322 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -339,11 +339,11 @@ discard block |
||
| 339 | 339 | * true si l'opération a réussie, false sinon. |
| 340 | 340 | */ |
| 341 | 341 | function lire_fichier_securise($fichier, &$contenu, $options = array()) { |
| 342 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 343 | - $contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 344 | - } |
|
| 342 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 343 | + $contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | - return $res; |
|
| 346 | + return $res; |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -358,20 +358,20 @@ discard block |
||
| 358 | 358 | * Chemin du fichier |
| 359 | 359 | **/ |
| 360 | 360 | function raler_fichier($fichier) { |
| 361 | - include_spip('inc/minipres'); |
|
| 362 | - $dir = dirname($fichier); |
|
| 363 | - http_status(401); |
|
| 364 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 365 | - . _T('texte_inc_meta_1', array('fichier' => $fichier)) |
|
| 366 | - . " <a href='" |
|
| 367 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 368 | - . "'>" |
|
| 369 | - . _T('texte_inc_meta_2') |
|
| 370 | - . "</a> " |
|
| 371 | - . _T('texte_inc_meta_3', |
|
| 372 | - array('repertoire' => joli_repertoire($dir))) |
|
| 373 | - . "</h4>\n"); |
|
| 374 | - exit; |
|
| 361 | + include_spip('inc/minipres'); |
|
| 362 | + $dir = dirname($fichier); |
|
| 363 | + http_status(401); |
|
| 364 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 365 | + . _T('texte_inc_meta_1', array('fichier' => $fichier)) |
|
| 366 | + . " <a href='" |
|
| 367 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 368 | + . "'>" |
|
| 369 | + . _T('texte_inc_meta_2') |
|
| 370 | + . "</a> " |
|
| 371 | + . _T('texte_inc_meta_3', |
|
| 372 | + array('repertoire' => joli_repertoire($dir))) |
|
| 373 | + . "</h4>\n"); |
|
| 374 | + exit; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | |
@@ -386,14 +386,14 @@ discard block |
||
| 386 | 386 | * - true si récent, false sinon |
| 387 | 387 | */ |
| 388 | 388 | function jeune_fichier($fichier, $n) { |
| 389 | - if (!file_exists($fichier)) { |
|
| 390 | - return false; |
|
| 391 | - } |
|
| 392 | - if (!$c = @filemtime($fichier)) { |
|
| 393 | - return false; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - return (time() - $n <= $c); |
|
| 389 | + if (!file_exists($fichier)) { |
|
| 390 | + return false; |
|
| 391 | + } |
|
| 392 | + if (!$c = @filemtime($fichier)) { |
|
| 393 | + return false; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + return (time() - $n <= $c); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | /** |
@@ -409,22 +409,22 @@ discard block |
||
| 409 | 409 | * - void sinon |
| 410 | 410 | */ |
| 411 | 411 | function supprimer_fichier($fichier, $lock = true) { |
| 412 | - if (!@file_exists($fichier)) { |
|
| 413 | - return true; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - if ($lock) { |
|
| 417 | - // verrouiller le fichier destination |
|
| 418 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 419 | - return false; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - // liberer le verrou |
|
| 423 | - spip_fclose_unlock($fp); |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - // supprimer |
|
| 427 | - return @unlink($fichier); |
|
| 412 | + if (!@file_exists($fichier)) { |
|
| 413 | + return true; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + if ($lock) { |
|
| 417 | + // verrouiller le fichier destination |
|
| 418 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 419 | + return false; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + // liberer le verrou |
|
| 423 | + spip_fclose_unlock($fp); |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + // supprimer |
|
| 427 | + return @unlink($fichier); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | /** |
@@ -434,12 +434,12 @@ discard block |
||
| 434 | 434 | * Chemin du fichier |
| 435 | 435 | */ |
| 436 | 436 | function spip_unlink($f) { |
| 437 | - if (!is_dir($f)) { |
|
| 438 | - supprimer_fichier($f, false); |
|
| 439 | - } else { |
|
| 440 | - @unlink("$f/.ok"); |
|
| 441 | - @rmdir($f); |
|
| 442 | - } |
|
| 437 | + if (!is_dir($f)) { |
|
| 438 | + supprimer_fichier($f, false); |
|
| 439 | + } else { |
|
| 440 | + @unlink("$f/.ok"); |
|
| 441 | + @rmdir($f); |
|
| 442 | + } |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -453,23 +453,23 @@ discard block |
||
| 453 | 453 | * The absolute path of the PHP file to invalidate. |
| 454 | 454 | */ |
| 455 | 455 | function spip_clear_opcode_cache($filepath) { |
| 456 | - clearstatcache(true, $filepath); |
|
| 457 | - |
|
| 458 | - // Zend OPcache |
|
| 459 | - if (function_exists('opcache_invalidate')) { |
|
| 460 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 461 | - // si l'invalidation a echoue lever un flag |
|
| 462 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 463 | - define('_spip_attend_invalidation_opcode_cache',true); |
|
| 464 | - } |
|
| 465 | - } |
|
| 466 | - // APC. |
|
| 467 | - if (function_exists('apc_delete_file')) { |
|
| 468 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 469 | - // not compiled yet. |
|
| 470 | - // @see http://php.net/apc-delete-file |
|
| 471 | - @apc_delete_file($filepath); |
|
| 472 | - } |
|
| 456 | + clearstatcache(true, $filepath); |
|
| 457 | + |
|
| 458 | + // Zend OPcache |
|
| 459 | + if (function_exists('opcache_invalidate')) { |
|
| 460 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 461 | + // si l'invalidation a echoue lever un flag |
|
| 462 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 463 | + define('_spip_attend_invalidation_opcode_cache',true); |
|
| 464 | + } |
|
| 465 | + } |
|
| 466 | + // APC. |
|
| 467 | + if (function_exists('apc_delete_file')) { |
|
| 468 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 469 | + // not compiled yet. |
|
| 470 | + // @see http://php.net/apc-delete-file |
|
| 471 | + @apc_delete_file($filepath); |
|
| 472 | + } |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | /** |
@@ -492,24 +492,24 @@ discard block |
||
| 492 | 492 | * |
| 493 | 493 | */ |
| 494 | 494 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 495 | - if (function_exists('opcache_get_configuration') |
|
| 496 | - and @ini_get('opcache.enable') |
|
| 497 | - and @ini_get('opcache.validate_timestamps') |
|
| 498 | - and $duree = @ini_get('opcache.revalidate_freq') |
|
| 499 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 500 | - ) { |
|
| 501 | - $wait = $duree + 1; |
|
| 502 | - if ($timestamp) { |
|
| 503 | - $wait -= (time() - $timestamp); |
|
| 504 | - if ($wait<0) { |
|
| 505 | - $wait = 0; |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE); |
|
| 509 | - if ($wait) { |
|
| 510 | - sleep($duree + 1); |
|
| 511 | - } |
|
| 512 | - } |
|
| 495 | + if (function_exists('opcache_get_configuration') |
|
| 496 | + and @ini_get('opcache.enable') |
|
| 497 | + and @ini_get('opcache.validate_timestamps') |
|
| 498 | + and $duree = @ini_get('opcache.revalidate_freq') |
|
| 499 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 500 | + ) { |
|
| 501 | + $wait = $duree + 1; |
|
| 502 | + if ($timestamp) { |
|
| 503 | + $wait -= (time() - $timestamp); |
|
| 504 | + if ($wait<0) { |
|
| 505 | + $wait = 0; |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE); |
|
| 509 | + if ($wait) { |
|
| 510 | + sleep($duree + 1); |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | |
@@ -522,26 +522,26 @@ discard block |
||
| 522 | 522 | * @return bool Suppression reussie. |
| 523 | 523 | */ |
| 524 | 524 | function supprimer_repertoire($dir) { |
| 525 | - if (!file_exists($dir)) { |
|
| 526 | - return true; |
|
| 527 | - } |
|
| 528 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 529 | - return @unlink($dir); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - foreach (scandir($dir) as $item) { |
|
| 533 | - if ($item == '.' || $item == '..') { |
|
| 534 | - continue; |
|
| 535 | - } |
|
| 536 | - if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 537 | - @chmod($dir . "/" . $item, 0777); |
|
| 538 | - if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 539 | - return false; |
|
| 540 | - } |
|
| 541 | - }; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - return @rmdir($dir); |
|
| 525 | + if (!file_exists($dir)) { |
|
| 526 | + return true; |
|
| 527 | + } |
|
| 528 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 529 | + return @unlink($dir); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + foreach (scandir($dir) as $item) { |
|
| 533 | + if ($item == '.' || $item == '..') { |
|
| 534 | + continue; |
|
| 535 | + } |
|
| 536 | + if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 537 | + @chmod($dir . "/" . $item, 0777); |
|
| 538 | + if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 539 | + return false; |
|
| 540 | + } |
|
| 541 | + }; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + return @rmdir($dir); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -570,57 +570,57 @@ discard block |
||
| 570 | 570 | * Chemin du répertoire créé. |
| 571 | 571 | **/ |
| 572 | 572 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 573 | - static $dirs = array(); |
|
| 574 | - |
|
| 575 | - $base = str_replace("//", "/", $base); |
|
| 576 | - |
|
| 577 | - # suppr le dernier caractere si c'est un / |
|
| 578 | - $base = rtrim($base, '/'); |
|
| 579 | - |
|
| 580 | - if (!strlen($subdir)) { |
|
| 581 | - $n = strrpos($base, "/"); |
|
| 582 | - if ($n === false) { |
|
| 583 | - return $nobase ? '' : ($base . '/'); |
|
| 584 | - } |
|
| 585 | - $subdir = substr($base, $n + 1); |
|
| 586 | - $base = substr($base, 0, $n + 1); |
|
| 587 | - } else { |
|
| 588 | - $base .= '/'; |
|
| 589 | - $subdir = str_replace("/", "", $subdir); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - $baseaff = $nobase ? '' : $base; |
|
| 593 | - if (isset($dirs[$base . $subdir])) { |
|
| 594 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 598 | - |
|
| 599 | - if (file_exists("$path/.ok")) { |
|
| 600 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - @mkdir($path, _SPIP_CHMOD); |
|
| 604 | - @chmod($path, _SPIP_CHMOD); |
|
| 605 | - |
|
| 606 | - if (is_dir($path) && is_writable($path)) { |
|
| 607 | - @touch("$path/.ok"); |
|
| 608 | - spip_log("creation $base$subdir/"); |
|
| 609 | - |
|
| 610 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 614 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 615 | - spip_log("echec creation $base${subdir}"); |
|
| 616 | - if ($tantpis) { |
|
| 617 | - return ''; |
|
| 618 | - } |
|
| 619 | - if (!_DIR_RESTREINT) { |
|
| 620 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 621 | - } |
|
| 622 | - $base .= $subdir; |
|
| 623 | - raler_fichier($base . '/.ok'); |
|
| 573 | + static $dirs = array(); |
|
| 574 | + |
|
| 575 | + $base = str_replace("//", "/", $base); |
|
| 576 | + |
|
| 577 | + # suppr le dernier caractere si c'est un / |
|
| 578 | + $base = rtrim($base, '/'); |
|
| 579 | + |
|
| 580 | + if (!strlen($subdir)) { |
|
| 581 | + $n = strrpos($base, "/"); |
|
| 582 | + if ($n === false) { |
|
| 583 | + return $nobase ? '' : ($base . '/'); |
|
| 584 | + } |
|
| 585 | + $subdir = substr($base, $n + 1); |
|
| 586 | + $base = substr($base, 0, $n + 1); |
|
| 587 | + } else { |
|
| 588 | + $base .= '/'; |
|
| 589 | + $subdir = str_replace("/", "", $subdir); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + $baseaff = $nobase ? '' : $base; |
|
| 593 | + if (isset($dirs[$base . $subdir])) { |
|
| 594 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 598 | + |
|
| 599 | + if (file_exists("$path/.ok")) { |
|
| 600 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + @mkdir($path, _SPIP_CHMOD); |
|
| 604 | + @chmod($path, _SPIP_CHMOD); |
|
| 605 | + |
|
| 606 | + if (is_dir($path) && is_writable($path)) { |
|
| 607 | + @touch("$path/.ok"); |
|
| 608 | + spip_log("creation $base$subdir/"); |
|
| 609 | + |
|
| 610 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 614 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 615 | + spip_log("echec creation $base${subdir}"); |
|
| 616 | + if ($tantpis) { |
|
| 617 | + return ''; |
|
| 618 | + } |
|
| 619 | + if (!_DIR_RESTREINT) { |
|
| 620 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 621 | + } |
|
| 622 | + $base .= $subdir; |
|
| 623 | + raler_fichier($base . '/.ok'); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | |
@@ -653,51 +653,51 @@ discard block |
||
| 653 | 653 | * Chemins des fichiers trouvés. |
| 654 | 654 | **/ |
| 655 | 655 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = array()) { |
| 656 | - $nbfiles = 0; |
|
| 657 | - if ($pattern == -1) { |
|
| 658 | - $pattern = "^$dir"; |
|
| 659 | - } |
|
| 660 | - $fichiers = array(); |
|
| 661 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 662 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 663 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 664 | - if ($dir == '') { |
|
| 665 | - $dir = '.'; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 669 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 670 | - if ($f[0] != '.' # ignorer . .. .svn etc |
|
| 671 | - and $f != 'CVS' |
|
| 672 | - and $f != 'remove.txt' |
|
| 673 | - and is_readable($f = "$dir/$f") |
|
| 674 | - ) { |
|
| 675 | - if (is_file($f)) { |
|
| 676 | - if (preg_match(";$pattern;iS", $f)) { |
|
| 677 | - $fichiers[] = $f; |
|
| 678 | - $nbfiles++; |
|
| 679 | - } |
|
| 680 | - } else { |
|
| 681 | - if (is_dir($f) and is_array($recurs)) { |
|
| 682 | - $rp = @realpath($f); |
|
| 683 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 684 | - $rp = $f; |
|
| 685 | - } # realpath n'est peut etre pas autorise |
|
| 686 | - if (!isset($recurs[$rp])) { |
|
| 687 | - $recurs[$rp] = true; |
|
| 688 | - $beginning = $fichiers; |
|
| 689 | - $end = preg_files("$f/", $pattern, |
|
| 690 | - $maxfiles - $nbfiles, $recurs); |
|
| 691 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 692 | - $nbfiles = count($fichiers); |
|
| 693 | - } |
|
| 694 | - } |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - } |
|
| 698 | - closedir($d); |
|
| 699 | - } |
|
| 700 | - sort($fichiers); |
|
| 701 | - |
|
| 702 | - return $fichiers; |
|
| 656 | + $nbfiles = 0; |
|
| 657 | + if ($pattern == -1) { |
|
| 658 | + $pattern = "^$dir"; |
|
| 659 | + } |
|
| 660 | + $fichiers = array(); |
|
| 661 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 662 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 663 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 664 | + if ($dir == '') { |
|
| 665 | + $dir = '.'; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 669 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 670 | + if ($f[0] != '.' # ignorer . .. .svn etc |
|
| 671 | + and $f != 'CVS' |
|
| 672 | + and $f != 'remove.txt' |
|
| 673 | + and is_readable($f = "$dir/$f") |
|
| 674 | + ) { |
|
| 675 | + if (is_file($f)) { |
|
| 676 | + if (preg_match(";$pattern;iS", $f)) { |
|
| 677 | + $fichiers[] = $f; |
|
| 678 | + $nbfiles++; |
|
| 679 | + } |
|
| 680 | + } else { |
|
| 681 | + if (is_dir($f) and is_array($recurs)) { |
|
| 682 | + $rp = @realpath($f); |
|
| 683 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 684 | + $rp = $f; |
|
| 685 | + } # realpath n'est peut etre pas autorise |
|
| 686 | + if (!isset($recurs[$rp])) { |
|
| 687 | + $recurs[$rp] = true; |
|
| 688 | + $beginning = $fichiers; |
|
| 689 | + $end = preg_files("$f/", $pattern, |
|
| 690 | + $maxfiles - $nbfiles, $recurs); |
|
| 691 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 692 | + $nbfiles = count($fichiers); |
|
| 693 | + } |
|
| 694 | + } |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + } |
|
| 698 | + closedir($d); |
|
| 699 | + } |
|
| 700 | + sort($fichiers); |
|
| 701 | + |
|
| 702 | + return $fichiers; |
|
| 703 | 703 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | $contenu = @gzfile($fichier); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string) $contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -315,9 +315,9 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | 317 | if (substr($fichier, -4) !== '.php') { |
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 318 | + spip_log('Erreur de programmation: '.$fichier.' doit finir par .php'); |
|
| 319 | 319 | } |
| 320 | - $contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 320 | + $contenu = "<"."?php die ('Acces interdit'); ?".">\n".$contenu; |
|
| 321 | 321 | |
| 322 | 322 | return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
| 323 | 323 | } |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | */ |
| 341 | 341 | function lire_fichier_securise($fichier, &$contenu, $options = array()) { |
| 342 | 342 | if ($res = lire_fichier($fichier, $contenu, $options)) { |
| 343 | - $contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 343 | + $contenu = substr($contenu, strlen("<"."?php die ('Acces interdit'); ?".">\n")); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | return $res; |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | $invalidate = @opcache_invalidate($filepath, true); |
| 461 | 461 | // si l'invalidation a echoue lever un flag |
| 462 | 462 | if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
| 463 | - define('_spip_attend_invalidation_opcode_cache',true); |
|
| 463 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | // APC. |
@@ -501,11 +501,11 @@ discard block |
||
| 501 | 501 | $wait = $duree + 1; |
| 502 | 502 | if ($timestamp) { |
| 503 | 503 | $wait -= (time() - $timestamp); |
| 504 | - if ($wait<0) { |
|
| 504 | + if ($wait < 0) { |
|
| 505 | 505 | $wait = 0; |
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | - spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE); |
|
| 508 | + spip_log('Probleme de configuration opcache.revalidate_freq '.$duree.'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE); |
|
| 509 | 509 | if ($wait) { |
| 510 | 510 | sleep($duree + 1); |
| 511 | 511 | } |
@@ -533,9 +533,9 @@ discard block |
||
| 533 | 533 | if ($item == '.' || $item == '..') { |
| 534 | 534 | continue; |
| 535 | 535 | } |
| 536 | - if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 537 | - @chmod($dir . "/" . $item, 0777); |
|
| 538 | - if (!supprimer_repertoire($dir . "/" . $item)) { |
|
| 536 | + if (!supprimer_repertoire($dir."/".$item)) { |
|
| 537 | + @chmod($dir."/".$item, 0777); |
|
| 538 | + if (!supprimer_repertoire($dir."/".$item)) { |
|
| 539 | 539 | return false; |
| 540 | 540 | } |
| 541 | 541 | }; |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | if (!strlen($subdir)) { |
| 581 | 581 | $n = strrpos($base, "/"); |
| 582 | 582 | if ($n === false) { |
| 583 | - return $nobase ? '' : ($base . '/'); |
|
| 583 | + return $nobase ? '' : ($base.'/'); |
|
| 584 | 584 | } |
| 585 | 585 | $subdir = substr($base, $n + 1); |
| 586 | 586 | $base = substr($base, 0, $n + 1); |
@@ -590,14 +590,14 @@ discard block |
||
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | $baseaff = $nobase ? '' : $base; |
| 593 | - if (isset($dirs[$base . $subdir])) { |
|
| 594 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 593 | + if (isset($dirs[$base.$subdir])) { |
|
| 594 | + return $baseaff.$dirs[$base.$subdir]; |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 597 | + $path = $base.$subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 598 | 598 | |
| 599 | 599 | if (file_exists("$path/.ok")) { |
| 600 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 600 | + return $baseaff.($dirs[$base.$subdir] = "$subdir/"); |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | @mkdir($path, _SPIP_CHMOD); |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | @touch("$path/.ok"); |
| 608 | 608 | spip_log("creation $base$subdir/"); |
| 609 | 609 | |
| 610 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 610 | + return $baseaff.($dirs[$base.$subdir] = "$subdir/"); |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
@@ -617,10 +617,10 @@ discard block |
||
| 617 | 617 | return ''; |
| 618 | 618 | } |
| 619 | 619 | if (!_DIR_RESTREINT) { |
| 620 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 620 | + $base = preg_replace(',^'._DIR_RACINE.',', '', $base); |
|
| 621 | 621 | } |
| 622 | 622 | $base .= $subdir; |
| 623 | - raler_fichier($base . '/.ok'); |
|
| 623 | + raler_fichier($base.'/.ok'); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | $beginning = $fichiers; |
| 689 | 689 | $end = preg_files("$f/", $pattern, |
| 690 | 690 | $maxfiles - $nbfiles, $recurs); |
| 691 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 691 | + $fichiers = array_merge((array) $beginning, (array) $end); |
|
| 692 | 692 | $nbfiles = count($fichiers); |
| 693 | 693 | } |
| 694 | 694 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * Importer le charset d'une ligne |
| 33 | 33 | * |
| 34 | 34 | * @param string $texte |
| 35 | - * @return array |
|
| 35 | + * @return string |
|
| 36 | 36 | */ |
| 37 | 37 | function importer_csv_importcharset($texte) { |
| 38 | 38 | // le plus frequent, en particulier avec les trucs de ms@@@ |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @param string $delim |
| 67 | 67 | * @param string $enclos |
| 68 | 68 | * @param int $len |
| 69 | - * @return array |
|
| 69 | + * @return boolean |
|
| 70 | 70 | */ |
| 71 | 71 | function inc_importer_csv_dist($file, $head = false, $delim = ", ", $enclos = '"', $len = 10000) { |
| 72 | 72 | $return = false; |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/charsets'); |
@@ -35,14 +35,14 @@ discard block |
||
| 35 | 35 | * @return array |
| 36 | 36 | */ |
| 37 | 37 | function importer_csv_importcharset($texte) { |
| 38 | - // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 39 | - $charset_source = 'iso-8859-1'; |
|
| 40 | - // mais open-office sait faire mieux, donc mefiance ! |
|
| 41 | - if (is_utf8($texte)) { |
|
| 42 | - $charset_source = 'utf-8'; |
|
| 43 | - } |
|
| 38 | + // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 39 | + $charset_source = 'iso-8859-1'; |
|
| 40 | + // mais open-office sait faire mieux, donc mefiance ! |
|
| 41 | + if (is_utf8($texte)) { |
|
| 42 | + $charset_source = 'utf-8'; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - return importer_charset($texte, $charset_source); |
|
| 45 | + return importer_charset($texte, $charset_source); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return string |
| 54 | 54 | */ |
| 55 | 55 | function importer_csv_nettoie_key($key) { |
| 56 | - return translitteration($key); |
|
| 56 | + return translitteration($key); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -69,47 +69,47 @@ discard block |
||
| 69 | 69 | * @return array |
| 70 | 70 | */ |
| 71 | 71 | function inc_importer_csv_dist($file, $head = false, $delim = ", ", $enclos = '"', $len = 10000) { |
| 72 | - $return = false; |
|
| 73 | - if (@file_exists($file) |
|
| 74 | - and $handle = fopen($file, "r") |
|
| 75 | - ) { |
|
| 76 | - if ($head) { |
|
| 77 | - $header = fgetcsv($handle, $len, $delim, $enclos); |
|
| 78 | - if ($header) { |
|
| 79 | - $header = array_map('importer_csv_importcharset', $header); |
|
| 80 | - $header = array_map('importer_csv_nettoie_key', $header); |
|
| 81 | - $header_type = array(); |
|
| 82 | - foreach ($header as $heading) { |
|
| 83 | - if (!isset($header_type[$heading])) { |
|
| 84 | - $header_type[$heading] = "scalar"; |
|
| 85 | - } else { |
|
| 86 | - $header_type[$heading] = "array"; |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - while (($data = fgetcsv($handle, $len, $delim, $enclos)) !== false) { |
|
| 92 | - $data = array_map('importer_csv_importcharset', $data); |
|
| 93 | - if ($head and isset($header)) { |
|
| 94 | - $row = array(); |
|
| 95 | - foreach ($header as $key => $heading) { |
|
| 96 | - if ($header_type[$heading] == "array") { |
|
| 97 | - if (!isset($row[$heading])) { |
|
| 98 | - $row[$heading] = array(); |
|
| 99 | - } |
|
| 100 | - if (isset($data[$key]) and strlen($data[$key])) { |
|
| 101 | - $row[$heading][] = $data[$key]; |
|
| 102 | - } |
|
| 103 | - } else { |
|
| 104 | - $row[$heading] = (isset($data[$key])) ? $data[$key] : ''; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - $return[] = $row; |
|
| 108 | - } else { |
|
| 109 | - $return[] = $data; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - } |
|
| 72 | + $return = false; |
|
| 73 | + if (@file_exists($file) |
|
| 74 | + and $handle = fopen($file, "r") |
|
| 75 | + ) { |
|
| 76 | + if ($head) { |
|
| 77 | + $header = fgetcsv($handle, $len, $delim, $enclos); |
|
| 78 | + if ($header) { |
|
| 79 | + $header = array_map('importer_csv_importcharset', $header); |
|
| 80 | + $header = array_map('importer_csv_nettoie_key', $header); |
|
| 81 | + $header_type = array(); |
|
| 82 | + foreach ($header as $heading) { |
|
| 83 | + if (!isset($header_type[$heading])) { |
|
| 84 | + $header_type[$heading] = "scalar"; |
|
| 85 | + } else { |
|
| 86 | + $header_type[$heading] = "array"; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + while (($data = fgetcsv($handle, $len, $delim, $enclos)) !== false) { |
|
| 92 | + $data = array_map('importer_csv_importcharset', $data); |
|
| 93 | + if ($head and isset($header)) { |
|
| 94 | + $row = array(); |
|
| 95 | + foreach ($header as $key => $heading) { |
|
| 96 | + if ($header_type[$heading] == "array") { |
|
| 97 | + if (!isset($row[$heading])) { |
|
| 98 | + $row[$heading] = array(); |
|
| 99 | + } |
|
| 100 | + if (isset($data[$key]) and strlen($data[$key])) { |
|
| 101 | + $row[$heading][] = $data[$key]; |
|
| 102 | + } |
|
| 103 | + } else { |
|
| 104 | + $row[$heading] = (isset($data[$key])) ? $data[$key] : ''; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + $return[] = $row; |
|
| 108 | + } else { |
|
| 109 | + $return[] = $data; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - return $return; |
|
| 114 | + return $return; |
|
| 115 | 115 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @param string $lang |
| 33 | 33 | * La langue à utiliser |
| 34 | - * @return string|bool |
|
| 34 | + * @return false|string |
|
| 35 | 35 | * string : La langue qui a été utilisée si trouvée |
| 36 | 36 | * false : aucune langue ne correspondait à la demande |
| 37 | 37 | **/ |
@@ -80,6 +80,9 @@ discard block |
||
| 80 | 80 | // retourne son 2e argument si c'est un index du premier |
| 81 | 81 | // ou un index approchant sinon et si possible, |
| 82 | 82 | // la langue X etant consideree comme une approche de X_Y |
| 83 | +/** |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 83 | 86 | function approcher_langue($trads, $lang = '') { |
| 84 | 87 | |
| 85 | 88 | if (!$lang) { |
@@ -175,6 +178,9 @@ discard block |
||
| 175 | 178 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 176 | 179 | // |
| 177 | 180 | // http://code.spip.net/@menu_langues |
| 181 | +/** |
|
| 182 | + * @param string $nom_select |
|
| 183 | + */ |
|
| 178 | 184 | function menu_langues($nom_select, $default = '') { |
| 179 | 185 | include_spip('inc/actions'); |
| 180 | 186 | |
@@ -209,6 +215,10 @@ discard block |
||
| 209 | 215 | } |
| 210 | 216 | |
| 211 | 217 | // http://code.spip.net/@select_langues |
| 218 | +/** |
|
| 219 | + * @param string $change |
|
| 220 | + * @param string $options |
|
| 221 | + */ |
|
| 212 | 222 | function select_langues($nom_select, $change, $options, $label = "") { |
| 213 | 223 | static $cpt = 0; |
| 214 | 224 | $id = "menu_langues" . $cpt++; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Langue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -37,29 +37,29 @@ discard block |
||
| 37 | 37 | **/ |
| 38 | 38 | function changer_langue($lang) { |
| 39 | 39 | |
| 40 | - $liste_langues = ',' . @$GLOBALS['meta']['langues_proposees'] |
|
| 41 | - . ',' . @$GLOBALS['meta']['langues_multilingue'] . ','; |
|
| 42 | - |
|
| 43 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 44 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 45 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 46 | - if (!$lang) { |
|
| 47 | - return false; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (strpos($liste_langues, ",$lang,") !== false |
|
| 51 | - or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 52 | - and strpos($liste_langues, ",$lang,") !== false) |
|
| 53 | - ) { |
|
| 54 | - |
|
| 55 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 56 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 57 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 58 | - |
|
| 59 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 60 | - } else { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 40 | + $liste_langues = ',' . @$GLOBALS['meta']['langues_proposees'] |
|
| 41 | + . ',' . @$GLOBALS['meta']['langues_multilingue'] . ','; |
|
| 42 | + |
|
| 43 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 44 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 45 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 46 | + if (!$lang) { |
|
| 47 | + return false; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (strpos($liste_langues, ",$lang,") !== false |
|
| 51 | + or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 52 | + and strpos($liste_langues, ",$lang,") !== false) |
|
| 53 | + ) { |
|
| 54 | + |
|
| 55 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 56 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 57 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 58 | + |
|
| 59 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 60 | + } else { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | // |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 73 | 73 | |
| 74 | 74 | function choisir_traduction($trads, $lang = '') { |
| 75 | - $k = approcher_langue($trads, $lang); |
|
| 75 | + $k = approcher_langue($trads, $lang); |
|
| 76 | 76 | |
| 77 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 77 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // retourne son 2e argument si c'est un index du premier |
@@ -82,21 +82,21 @@ discard block |
||
| 82 | 82 | // la langue X etant consideree comme une approche de X_Y |
| 83 | 83 | function approcher_langue($trads, $lang = '') { |
| 84 | 84 | |
| 85 | - if (!$lang) { |
|
| 86 | - $lang = $GLOBALS['spip_lang']; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - if (isset($trads[$lang])) { |
|
| 90 | - return $lang; |
|
| 91 | - } // cas des langues xx_yy |
|
| 92 | - else { |
|
| 93 | - $r = explode('_', $lang); |
|
| 94 | - if (isset($trads[$r[0]])) { |
|
| 95 | - return $r[0]; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return ''; |
|
| 85 | + if (!$lang) { |
|
| 86 | + $lang = $GLOBALS['spip_lang']; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + if (isset($trads[$lang])) { |
|
| 90 | + return $lang; |
|
| 91 | + } // cas des langues xx_yy |
|
| 92 | + else { |
|
| 93 | + $r = explode('_', $lang); |
|
| 94 | + if (isset($trads[$r[0]])) { |
|
| 95 | + return $r[0]; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return ''; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -111,10 +111,10 @@ discard block |
||
| 111 | 111 | * Nom de la langue, sinon son code. |
| 112 | 112 | **/ |
| 113 | 113 | function traduire_nom_langue($lang) { |
| 114 | - include_spip('inc/lang_liste'); |
|
| 115 | - include_spip('inc/charsets'); |
|
| 114 | + include_spip('inc/lang_liste'); |
|
| 115 | + include_spip('inc/charsets'); |
|
| 116 | 116 | |
| 117 | - return html2unicode(isset($GLOBALS['codes_langues'][$lang]) ? $GLOBALS['codes_langues'][$lang] : $lang); |
|
| 117 | + return html2unicode(isset($GLOBALS['codes_langues'][$lang]) ? $GLOBALS['codes_langues'][$lang] : $lang); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 129 | 129 | // http://code.spip.net/@lang_dir |
| 130 | 130 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 131 | - static $lang_rtl = array('ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi'); |
|
| 131 | + static $lang_rtl = array('ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi'); |
|
| 132 | 132 | |
| 133 | - return in_array(($lang ? $lang : $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 134 | - $gaucher : $droitier; |
|
| 133 | + return in_array(($lang ? $lang : $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 134 | + $gaucher : $droitier; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // typo francaise ou anglaise ? |
@@ -141,31 +141,31 @@ discard block |
||
| 141 | 141 | |
| 142 | 142 | // http://code.spip.net/@lang_typo |
| 143 | 143 | function lang_typo($lang = '') { |
| 144 | - if (!$lang) { |
|
| 145 | - $lang = isset($GLOBALS['lang_objet']) |
|
| 146 | - ? $GLOBALS['lang_objet'] |
|
| 147 | - : $GLOBALS['spip_lang']; |
|
| 148 | - } |
|
| 149 | - if ($lang == 'eo' |
|
| 150 | - or $lang == 'fr' |
|
| 151 | - or strncmp($lang, 'fr_', 3) == 0 |
|
| 152 | - or $lang == 'cpf' |
|
| 153 | - ) { |
|
| 154 | - return 'fr'; |
|
| 155 | - } else { |
|
| 156 | - return 'en'; |
|
| 157 | - } |
|
| 144 | + if (!$lang) { |
|
| 145 | + $lang = isset($GLOBALS['lang_objet']) |
|
| 146 | + ? $GLOBALS['lang_objet'] |
|
| 147 | + : $GLOBALS['spip_lang']; |
|
| 148 | + } |
|
| 149 | + if ($lang == 'eo' |
|
| 150 | + or $lang == 'fr' |
|
| 151 | + or strncmp($lang, 'fr_', 3) == 0 |
|
| 152 | + or $lang == 'cpf' |
|
| 153 | + ) { |
|
| 154 | + return 'fr'; |
|
| 155 | + } else { |
|
| 156 | + return 'en'; |
|
| 157 | + } |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 161 | 161 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 162 | 162 | // http://code.spip.net/@changer_typo |
| 163 | 163 | function changer_typo($lang = '') { |
| 164 | - if ($lang) { |
|
| 165 | - $GLOBALS['lang_objet'] = $lang; |
|
| 166 | - } else { |
|
| 167 | - unset($GLOBALS['lang_objet']); |
|
| 168 | - } |
|
| 164 | + if ($lang) { |
|
| 165 | + $GLOBALS['lang_objet'] = $lang; |
|
| 166 | + } else { |
|
| 167 | + unset($GLOBALS['lang_objet']); |
|
| 168 | + } |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | // |
@@ -176,55 +176,55 @@ discard block |
||
| 176 | 176 | // |
| 177 | 177 | // http://code.spip.net/@menu_langues |
| 178 | 178 | function menu_langues($nom_select, $default = '') { |
| 179 | - include_spip('inc/actions'); |
|
| 180 | - |
|
| 181 | - $langues = liste_options_langues($nom_select); |
|
| 182 | - $ret = ""; |
|
| 183 | - if (!count($langues)) { |
|
| 184 | - return ''; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - if (!$default) { |
|
| 188 | - $default = $GLOBALS['spip_lang']; |
|
| 189 | - } |
|
| 190 | - foreach ($langues as $l) { |
|
| 191 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 192 | - $ret .= "<option value='$l'$selected>[" . $l . "] " . traduire_nom_langue($l) . "</option>\n"; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if (!test_espace_prive()) { |
|
| 196 | - $cible = self(); |
|
| 197 | - $base = ''; |
|
| 198 | - } else { |
|
| 199 | - $cible = self(); |
|
| 200 | - $base = spip_connect() ? 'base' : ''; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 204 | - |
|
| 205 | - return generer_action_auteur('converser', $base, $cible, |
|
| 206 | - (select_langues($nom_select, $change, $ret) |
|
| 207 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 208 | - " method='post'"); |
|
| 179 | + include_spip('inc/actions'); |
|
| 180 | + |
|
| 181 | + $langues = liste_options_langues($nom_select); |
|
| 182 | + $ret = ""; |
|
| 183 | + if (!count($langues)) { |
|
| 184 | + return ''; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + if (!$default) { |
|
| 188 | + $default = $GLOBALS['spip_lang']; |
|
| 189 | + } |
|
| 190 | + foreach ($langues as $l) { |
|
| 191 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 192 | + $ret .= "<option value='$l'$selected>[" . $l . "] " . traduire_nom_langue($l) . "</option>\n"; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if (!test_espace_prive()) { |
|
| 196 | + $cible = self(); |
|
| 197 | + $base = ''; |
|
| 198 | + } else { |
|
| 199 | + $cible = self(); |
|
| 200 | + $base = spip_connect() ? 'base' : ''; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 204 | + |
|
| 205 | + return generer_action_auteur('converser', $base, $cible, |
|
| 206 | + (select_langues($nom_select, $change, $ret) |
|
| 207 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 208 | + " method='post'"); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // http://code.spip.net/@select_langues |
| 212 | 212 | function select_langues($nom_select, $change, $options, $label = "") { |
| 213 | - static $cpt = 0; |
|
| 214 | - $id = "menu_langues" . $cpt++; |
|
| 215 | - |
|
| 216 | - return |
|
| 217 | - "<label for='$id'>" . ($label ? $label : _T('info_langues')) . "</label> " . |
|
| 218 | - "<select name='$nom_select' id='$id' " |
|
| 219 | - . ((!test_espace_prive()) ? |
|
| 220 | - ("class='forml menu_langues'") : |
|
| 221 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 222 | - ("class='lang_ecrire'") : |
|
| 223 | - "class='fondl'")) |
|
| 224 | - . $change |
|
| 225 | - . ">\n" |
|
| 226 | - . $options |
|
| 227 | - . "</select>"; |
|
| 213 | + static $cpt = 0; |
|
| 214 | + $id = "menu_langues" . $cpt++; |
|
| 215 | + |
|
| 216 | + return |
|
| 217 | + "<label for='$id'>" . ($label ? $label : _T('info_langues')) . "</label> " . |
|
| 218 | + "<select name='$nom_select' id='$id' " |
|
| 219 | + . ((!test_espace_prive()) ? |
|
| 220 | + ("class='forml menu_langues'") : |
|
| 221 | + (($nom_select == 'var_lang_ecrire') ? |
|
| 222 | + ("class='lang_ecrire'") : |
|
| 223 | + "class='fondl'")) |
|
| 224 | + . $change |
|
| 225 | + . ">\n" |
|
| 226 | + . $options |
|
| 227 | + . "</select>"; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -246,34 +246,34 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | function liste_options_langues($nom_select) { |
| 248 | 248 | |
| 249 | - switch ($nom_select) { |
|
| 250 | - # #MENU_LANG |
|
| 251 | - case 'var_lang': |
|
| 252 | - # menu de changement de la langue d'un article |
|
| 253 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 254 | - case 'changer_lang': |
|
| 255 | - $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 256 | - break; |
|
| 257 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 258 | - # les langues presentes sous forme de fichiers de langue |
|
| 259 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 260 | - case 'var_lang_ecrire': |
|
| 261 | - default: |
|
| 262 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 263 | - init_langues(); |
|
| 264 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 265 | - break; |
|
| 249 | + switch ($nom_select) { |
|
| 250 | + # #MENU_LANG |
|
| 251 | + case 'var_lang': |
|
| 252 | + # menu de changement de la langue d'un article |
|
| 253 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 254 | + case 'changer_lang': |
|
| 255 | + $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 256 | + break; |
|
| 257 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 258 | + # les langues presentes sous forme de fichiers de langue |
|
| 259 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 260 | + case 'var_lang_ecrire': |
|
| 261 | + default: |
|
| 262 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 263 | + init_langues(); |
|
| 264 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 265 | + break; |
|
| 266 | 266 | |
| 267 | 267 | # dernier choix possible : toutes les langues = langues_proposees |
| 268 | 268 | # + langues_multilingues ; mais, ne sert pas |
| 269 | 269 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 270 | - } |
|
| 271 | - if (count($langues) <= 1) { |
|
| 272 | - return array(); |
|
| 273 | - } |
|
| 274 | - sort($langues); |
|
| 270 | + } |
|
| 271 | + if (count($langues) <= 1) { |
|
| 272 | + return array(); |
|
| 273 | + } |
|
| 274 | + sort($langues); |
|
| 275 | 275 | |
| 276 | - return $langues; |
|
| 276 | + return $langues; |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | |
@@ -288,38 +288,38 @@ discard block |
||
| 288 | 288 | **/ |
| 289 | 289 | function verifier_lang_url() { |
| 290 | 290 | |
| 291 | - // quelle langue est demandee ? |
|
| 292 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 293 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 294 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 295 | - } |
|
| 296 | - if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 297 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 298 | - } |
|
| 299 | - if (isset($_GET['lang'])) { |
|
| 300 | - $lang_demandee = $_GET['lang']; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 304 | - if ($GLOBALS['spip_lang'] != $lang_demandee |
|
| 305 | - and changer_langue($lang_demandee) |
|
| 306 | - and $lang_demandee != @$_GET['lang'] |
|
| 307 | - ) { |
|
| 308 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 309 | - // ici on a besoin des var_truc |
|
| 310 | - foreach ($_GET as $var => $val) { |
|
| 311 | - if (!strncmp('var_', $var, 4)) { |
|
| 312 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - include_spip('inc/headers'); |
|
| 316 | - redirige_par_entete($destination); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 320 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 321 | - // (pour criteres {lang}). |
|
| 322 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 291 | + // quelle langue est demandee ? |
|
| 292 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 293 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 294 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 295 | + } |
|
| 296 | + if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 297 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 298 | + } |
|
| 299 | + if (isset($_GET['lang'])) { |
|
| 300 | + $lang_demandee = $_GET['lang']; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 304 | + if ($GLOBALS['spip_lang'] != $lang_demandee |
|
| 305 | + and changer_langue($lang_demandee) |
|
| 306 | + and $lang_demandee != @$_GET['lang'] |
|
| 307 | + ) { |
|
| 308 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 309 | + // ici on a besoin des var_truc |
|
| 310 | + foreach ($_GET as $var => $val) { |
|
| 311 | + if (!strncmp('var_', $var, 4)) { |
|
| 312 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + include_spip('inc/headers'); |
|
| 316 | + redirige_par_entete($destination); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 320 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 321 | + // (pour criteres {lang}). |
|
| 322 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -335,21 +335,21 @@ discard block |
||
| 335 | 335 | * La langue sélectionnée |
| 336 | 336 | **/ |
| 337 | 337 | function utiliser_langue_site() { |
| 338 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 339 | - if (isset($GLOBALS['meta']['langue_site']) |
|
| 340 | - // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 341 | - // ou qu'elle n'est pas identique à la langue du site |
|
| 342 | - and (!isset($GLOBALS['spip_lang']) |
|
| 343 | - or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 344 | - ) { |
|
| 345 | - return changer_langue($GLOBALS['meta']['langue_site']);//@:install |
|
| 346 | - } |
|
| 347 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 348 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 349 | - spip_log("La globale spip_lang est indéfinie dans utiliser_langue_site() !", _LOG_ERREUR); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - return $GLOBALS['spip_lang']; |
|
| 338 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 339 | + if (isset($GLOBALS['meta']['langue_site']) |
|
| 340 | + // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 341 | + // ou qu'elle n'est pas identique à la langue du site |
|
| 342 | + and (!isset($GLOBALS['spip_lang']) |
|
| 343 | + or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 344 | + ) { |
|
| 345 | + return changer_langue($GLOBALS['meta']['langue_site']);//@:install |
|
| 346 | + } |
|
| 347 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 348 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 349 | + spip_log("La globale spip_lang est indéfinie dans utiliser_langue_site() !", _LOG_ERREUR); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + return $GLOBALS['spip_lang']; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -366,30 +366,30 @@ discard block |
||
| 366 | 366 | **/ |
| 367 | 367 | function utiliser_langue_visiteur() { |
| 368 | 368 | |
| 369 | - $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 370 | - if (isset($_COOKIE[$l])) { |
|
| 371 | - if (changer_langue($l = $_COOKIE[$l])) { |
|
| 372 | - return $l; |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 377 | - if (changer_langue($l = $GLOBALS['visiteur_session']['lang'])) { |
|
| 378 | - return $l; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 383 | - foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 384 | - if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 385 | - if (changer_langue($l = strtolower($r[1]))) { |
|
| 386 | - return $l; |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return utiliser_langue_site(); |
|
| 369 | + $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 370 | + if (isset($_COOKIE[$l])) { |
|
| 371 | + if (changer_langue($l = $_COOKIE[$l])) { |
|
| 372 | + return $l; |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 377 | + if (changer_langue($l = $GLOBALS['visiteur_session']['lang'])) { |
|
| 378 | + return $l; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 383 | + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 384 | + if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 385 | + if (changer_langue($l = strtolower($r[1]))) { |
|
| 386 | + return $l; |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return utiliser_langue_site(); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | * @return int |
| 400 | 400 | */ |
| 401 | 401 | function match_langue($chaine) { |
| 402 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 402 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -417,36 +417,36 @@ discard block |
||
| 417 | 417 | **/ |
| 418 | 418 | function init_langues() { |
| 419 | 419 | |
| 420 | - // liste des langues dans les meta, sauf a l'install |
|
| 421 | - $all_langs = @$GLOBALS['meta']['langues_proposees']; |
|
| 422 | - |
|
| 423 | - $tout = array(); |
|
| 424 | - if (!$all_langs) { |
|
| 425 | - // trouver tous les modules lang/spip_xx.php |
|
| 426 | - $modules = find_all_in_path("lang/", "/spip_([a-z_]+)\.php$"); |
|
| 427 | - foreach ($modules as $name => $path) { |
|
| 428 | - if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 429 | - if (match_langue($regs[1])) { |
|
| 430 | - $tout[] = $regs[1]; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - sort($tout); |
|
| 435 | - $tout = join(',', $tout); |
|
| 436 | - // Si les langues n'ont pas change, ne rien faire |
|
| 437 | - if ($tout != $all_langs) { |
|
| 438 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 439 | - include_spip('inc/meta'); |
|
| 440 | - ecrire_meta('langues_proposees', $tout); |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 444 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 445 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 446 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', ",$all_langs,") !== false)) |
|
| 447 | - ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 448 | - ecrire_meta('langue_site', $tout); |
|
| 449 | - } |
|
| 420 | + // liste des langues dans les meta, sauf a l'install |
|
| 421 | + $all_langs = @$GLOBALS['meta']['langues_proposees']; |
|
| 422 | + |
|
| 423 | + $tout = array(); |
|
| 424 | + if (!$all_langs) { |
|
| 425 | + // trouver tous les modules lang/spip_xx.php |
|
| 426 | + $modules = find_all_in_path("lang/", "/spip_([a-z_]+)\.php$"); |
|
| 427 | + foreach ($modules as $name => $path) { |
|
| 428 | + if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 429 | + if (match_langue($regs[1])) { |
|
| 430 | + $tout[] = $regs[1]; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + sort($tout); |
|
| 435 | + $tout = join(',', $tout); |
|
| 436 | + // Si les langues n'ont pas change, ne rien faire |
|
| 437 | + if ($tout != $all_langs) { |
|
| 438 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 439 | + include_spip('inc/meta'); |
|
| 440 | + ecrire_meta('langues_proposees', $tout); |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 444 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 445 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 446 | + (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', ",$all_langs,") !== false)) |
|
| 447 | + ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 448 | + ecrire_meta('langue_site', $tout); |
|
| 449 | + } |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -460,10 +460,10 @@ discard block |
||
| 460 | 460 | * Code html de la balise <html> |
| 461 | 461 | **/ |
| 462 | 462 | function html_lang_attributes() { |
| 463 | - $lang = $GLOBALS['spip_lang']; |
|
| 464 | - $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 463 | + $lang = $GLOBALS['spip_lang']; |
|
| 464 | + $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 465 | 465 | |
| 466 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 466 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | * @return string |
| 478 | 478 | */ |
| 479 | 479 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 480 | - return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 480 | + return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | **/ |
| 38 | 38 | function changer_langue($lang) { |
| 39 | 39 | |
| 40 | - $liste_langues = ',' . @$GLOBALS['meta']['langues_proposees'] |
|
| 41 | - . ',' . @$GLOBALS['meta']['langues_multilingue'] . ','; |
|
| 40 | + $liste_langues = ','.@$GLOBALS['meta']['langues_proposees'] |
|
| 41 | + . ','.@$GLOBALS['meta']['langues_multilingue'].','; |
|
| 42 | 42 | |
| 43 | 43 | // Si la langue demandee n'existe pas, on essaie d'autres variantes |
| 44 | 44 | // Exemple : 'pt-br' => 'pt_br' => 'pt' |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | foreach ($langues as $l) { |
| 191 | 191 | $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
| 192 | - $ret .= "<option value='$l'$selected>[" . $l . "] " . traduire_nom_langue($l) . "</option>\n"; |
|
| 192 | + $ret .= "<option value='$l'$selected>[".$l."] ".traduire_nom_langue($l)."</option>\n"; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | if (!test_espace_prive()) { |
@@ -204,23 +204,21 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | return generer_action_auteur('converser', $base, $cible, |
| 206 | 206 | (select_langues($nom_select, $change, $ret) |
| 207 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 207 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='"._T('bouton_changer')."' /></div></noscript>"), |
|
| 208 | 208 | " method='post'"); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // http://code.spip.net/@select_langues |
| 212 | 212 | function select_langues($nom_select, $change, $options, $label = "") { |
| 213 | 213 | static $cpt = 0; |
| 214 | - $id = "menu_langues" . $cpt++; |
|
| 214 | + $id = "menu_langues".$cpt++; |
|
| 215 | 215 | |
| 216 | 216 | return |
| 217 | - "<label for='$id'>" . ($label ? $label : _T('info_langues')) . "</label> " . |
|
| 217 | + "<label for='$id'>".($label ? $label : _T('info_langues'))."</label> ". |
|
| 218 | 218 | "<select name='$nom_select' id='$id' " |
| 219 | 219 | . ((!test_espace_prive()) ? |
| 220 | - ("class='forml menu_langues'") : |
|
| 221 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 222 | - ("class='lang_ecrire'") : |
|
| 223 | - "class='fondl'")) |
|
| 220 | + ("class='forml menu_langues'") : (($nom_select == 'var_lang_ecrire') ? |
|
| 221 | + ("class='lang_ecrire'") : "class='fondl'")) |
|
| 224 | 222 | . $change |
| 225 | 223 | . ">\n" |
| 226 | 224 | . $options |
@@ -342,7 +340,7 @@ discard block |
||
| 342 | 340 | and (!isset($GLOBALS['spip_lang']) |
| 343 | 341 | or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
| 344 | 342 | ) { |
| 345 | - return changer_langue($GLOBALS['meta']['langue_site']);//@:install |
|
| 343 | + return changer_langue($GLOBALS['meta']['langue_site']); //@:install |
|
| 346 | 344 | } |
| 347 | 345 | // en theorie là, la globale est définie, sinon c'est un problème. |
| 348 | 346 | if (!isset($GLOBALS['spip_lang'])) { |
@@ -443,7 +441,7 @@ discard block |
||
| 443 | 441 | if (!isset($GLOBALS['meta']['langue_site'])) { |
| 444 | 442 | // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
| 445 | 443 | $GLOBALS['meta']['langue_site'] = $tout = |
| 446 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', ",$all_langs,") !== false)) |
|
| 444 | + (!$all_langs or (strpos(','._LANGUE_PAR_DEFAUT.',', ",$all_langs,") !== false)) |
|
| 447 | 445 | ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
| 448 | 446 | ecrire_meta('langue_site', $tout); |
| 449 | 447 | } |