@@ -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 |
@@ -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 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @param $function |
| 34 | 34 | * The function name to call. |
| 35 | - * @param $description |
|
| 35 | + * @param string $description |
|
| 36 | 36 | * A human-readable description of the queued job. |
| 37 | 37 | * @param $arguments |
| 38 | 38 | * Optional array of arguments to pass to the function. |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * |
| 163 | 163 | * @param int $id_job |
| 164 | 164 | * id de la tache a retirer |
| 165 | - * @return bool |
|
| 165 | + * @return boolean|string |
|
| 166 | 166 | */ |
| 167 | 167 | function queue_remove_job($id_job) { |
| 168 | 168 | include_spip('base/abstract_sql'); |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | * Nom de la fonction de tâche |
| 467 | 467 | * @param string $inclure |
| 468 | 468 | * Nom de l'inclusion contenant la fonction |
| 469 | - * @return bool|int |
|
| 469 | + * @return integer |
|
| 470 | 470 | * Périodicité de la tâche en secondes, si tâche périodique, sinon false. |
| 471 | 471 | */ |
| 472 | 472 | function queue_is_cron_job($function, $inclure) { |
@@ -429,9 +429,11 @@ |
||
| 429 | 429 | if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
| 430 | 430 | // relancer avec les nouveaux arguments de temps |
| 431 | 431 | include_spip('inc/genie'); |
| 432 | - if ($result < 0) // relancer tout de suite, mais en baissant la priorite |
|
| 432 | + if ($result < 0) { |
|
| 433 | + // relancer tout de suite, mais en baissant la priorite |
|
| 433 | 434 | { |
| 434 | 435 | queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
| 436 | + } |
|
| 435 | 437 | } else // relancer avec la periode prevue |
| 436 | 438 | { |
| 437 | 439 | queue_genie_replan_job($row['fonction'], $periode, $time); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Queue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined("_ECRIRE_INC_VERSION")) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | define('_JQ_SCHEDULED', 1); |
@@ -50,98 +50,98 @@ discard block |
||
| 50 | 50 | * id of job |
| 51 | 51 | */ |
| 52 | 52 | function queue_add_job( |
| 53 | - $function, |
|
| 54 | - $description, |
|
| 55 | - $arguments = array(), |
|
| 56 | - $file = '', |
|
| 57 | - $no_duplicate = false, |
|
| 58 | - $time = 0, |
|
| 59 | - $priority = 0 |
|
| 53 | + $function, |
|
| 54 | + $description, |
|
| 55 | + $arguments = array(), |
|
| 56 | + $file = '', |
|
| 57 | + $no_duplicate = false, |
|
| 58 | + $time = 0, |
|
| 59 | + $priority = 0 |
|
| 60 | 60 | ) { |
| 61 | - include_spip('base/abstract_sql'); |
|
| 62 | - |
|
| 63 | - // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 64 | - if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 65 | - $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // serialiser les arguments |
|
| 69 | - $arguments = serialize($arguments); |
|
| 70 | - $md5args = md5($arguments); |
|
| 71 | - |
|
| 72 | - // si pas de date programee, des que possible |
|
| 73 | - $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 74 | - if (!$time) { |
|
| 75 | - $time = time(); |
|
| 76 | - $duplicate_where = ""; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 77 | - } |
|
| 78 | - $date = date('Y-m-d H:i:s', $time); |
|
| 79 | - |
|
| 80 | - $set_job = array( |
|
| 81 | - 'fonction' => $function, |
|
| 82 | - 'descriptif' => $description, |
|
| 83 | - 'args' => $arguments, |
|
| 84 | - 'md5args' => $md5args, |
|
| 85 | - 'inclure' => $file, |
|
| 86 | - 'priorite' => max(-10, min(10, intval($priority))), |
|
| 87 | - 'date' => $date, |
|
| 88 | - 'status' => _JQ_SCHEDULED, |
|
| 89 | - ); |
|
| 90 | - // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 91 | - // avec les memes args et file |
|
| 92 | - if ( |
|
| 93 | - $no_duplicate |
|
| 94 | - and |
|
| 95 | - $id_job = sql_getfetsel('id_job', 'spip_jobs', |
|
| 96 | - $duplicate_where = |
|
| 97 | - $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 98 | - . (($no_duplicate === 'function_only') ? '' : |
|
| 99 | - ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))) |
|
| 100 | - ) { |
|
| 101 | - return $id_job; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 105 | - // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 106 | - // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 107 | - // doit s'effacer |
|
| 108 | - if ( |
|
| 109 | - $no_duplicate |
|
| 110 | - and |
|
| 111 | - $id_prev = sql_getfetsel('id_job', 'spip_jobs', "id_job<" . intval($id_job) . " AND $duplicate_where") |
|
| 112 | - ) { |
|
| 113 | - sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 114 | - |
|
| 115 | - return $id_prev; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 119 | - // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 120 | - |
|
| 121 | - // une option de debug pour verifier que les arguments en base sont bons |
|
| 122 | - // ie cas d'un char non acceptables sur certains type de champs |
|
| 123 | - // qui coupe la valeur |
|
| 124 | - if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
|
| 125 | - $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 126 | - if ($args !== $arguments) { |
|
| 127 | - spip_log('arguments job errones / longueur ' . strlen($args) . " vs " . strlen($arguments) . ' / valeur : ' . var_export($arguments, |
|
| 128 | - true), 'queue'); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if ($id_job) { |
|
| 133 | - queue_update_next_job_time($time); |
|
| 134 | - } |
|
| 135 | - // si la mise en file d'attente du job echoue, |
|
| 136 | - // il ne faut pas perdre l'execution de la fonction |
|
| 137 | - // on la lance immediatement, c'est un fallback |
|
| 138 | - // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 139 | - elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 140 | - $set_job['id_job'] = 0; |
|
| 141 | - queue_start_job($set_job); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $id_job; |
|
| 61 | + include_spip('base/abstract_sql'); |
|
| 62 | + |
|
| 63 | + // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 64 | + if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 65 | + $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // serialiser les arguments |
|
| 69 | + $arguments = serialize($arguments); |
|
| 70 | + $md5args = md5($arguments); |
|
| 71 | + |
|
| 72 | + // si pas de date programee, des que possible |
|
| 73 | + $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 74 | + if (!$time) { |
|
| 75 | + $time = time(); |
|
| 76 | + $duplicate_where = ""; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 77 | + } |
|
| 78 | + $date = date('Y-m-d H:i:s', $time); |
|
| 79 | + |
|
| 80 | + $set_job = array( |
|
| 81 | + 'fonction' => $function, |
|
| 82 | + 'descriptif' => $description, |
|
| 83 | + 'args' => $arguments, |
|
| 84 | + 'md5args' => $md5args, |
|
| 85 | + 'inclure' => $file, |
|
| 86 | + 'priorite' => max(-10, min(10, intval($priority))), |
|
| 87 | + 'date' => $date, |
|
| 88 | + 'status' => _JQ_SCHEDULED, |
|
| 89 | + ); |
|
| 90 | + // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 91 | + // avec les memes args et file |
|
| 92 | + if ( |
|
| 93 | + $no_duplicate |
|
| 94 | + and |
|
| 95 | + $id_job = sql_getfetsel('id_job', 'spip_jobs', |
|
| 96 | + $duplicate_where = |
|
| 97 | + $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 98 | + . (($no_duplicate === 'function_only') ? '' : |
|
| 99 | + ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))) |
|
| 100 | + ) { |
|
| 101 | + return $id_job; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 105 | + // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 106 | + // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 107 | + // doit s'effacer |
|
| 108 | + if ( |
|
| 109 | + $no_duplicate |
|
| 110 | + and |
|
| 111 | + $id_prev = sql_getfetsel('id_job', 'spip_jobs', "id_job<" . intval($id_job) . " AND $duplicate_where") |
|
| 112 | + ) { |
|
| 113 | + sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 114 | + |
|
| 115 | + return $id_prev; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 119 | + // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 120 | + |
|
| 121 | + // une option de debug pour verifier que les arguments en base sont bons |
|
| 122 | + // ie cas d'un char non acceptables sur certains type de champs |
|
| 123 | + // qui coupe la valeur |
|
| 124 | + if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
|
| 125 | + $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 126 | + if ($args !== $arguments) { |
|
| 127 | + spip_log('arguments job errones / longueur ' . strlen($args) . " vs " . strlen($arguments) . ' / valeur : ' . var_export($arguments, |
|
| 128 | + true), 'queue'); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if ($id_job) { |
|
| 133 | + queue_update_next_job_time($time); |
|
| 134 | + } |
|
| 135 | + // si la mise en file d'attente du job echoue, |
|
| 136 | + // il ne faut pas perdre l'execution de la fonction |
|
| 137 | + // on la lance immediatement, c'est un fallback |
|
| 138 | + // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 139 | + elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 140 | + $set_job['id_job'] = 0; |
|
| 141 | + queue_start_job($set_job); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $id_job; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -150,11 +150,11 @@ discard block |
||
| 150 | 150 | * @return void |
| 151 | 151 | */ |
| 152 | 152 | function queue_purger() { |
| 153 | - include_spip('base/abstract_sql'); |
|
| 154 | - sql_delete('spip_jobs'); |
|
| 155 | - sql_delete("spip_jobs_liens", "id_job NOT IN (" . sql_get_select("id_job", "spip_jobs") . ")"); |
|
| 156 | - include_spip('inc/genie'); |
|
| 157 | - genie_queue_watch_dist(); |
|
| 153 | + include_spip('base/abstract_sql'); |
|
| 154 | + sql_delete('spip_jobs'); |
|
| 155 | + sql_delete("spip_jobs_liens", "id_job NOT IN (" . sql_get_select("id_job", "spip_jobs") . ")"); |
|
| 156 | + include_spip('inc/genie'); |
|
| 157 | + genie_queue_watch_dist(); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -165,23 +165,23 @@ discard block |
||
| 165 | 165 | * @return bool |
| 166 | 166 | */ |
| 167 | 167 | function queue_remove_job($id_job) { |
| 168 | - include_spip('base/abstract_sql'); |
|
| 169 | - |
|
| 170 | - if ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 171 | - and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 172 | - ) { |
|
| 173 | - queue_unlink_job($id_job); |
|
| 174 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 175 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 176 | - // relancer avec les nouveaux arguments de temps |
|
| 177 | - include_spip('inc/genie'); |
|
| 178 | - // relancer avec la periode prevue |
|
| 179 | - queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 180 | - } |
|
| 181 | - queue_update_next_job_time(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return $res; |
|
| 168 | + include_spip('base/abstract_sql'); |
|
| 169 | + |
|
| 170 | + if ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 171 | + and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 172 | + ) { |
|
| 173 | + queue_unlink_job($id_job); |
|
| 174 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 175 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 176 | + // relancer avec les nouveaux arguments de temps |
|
| 177 | + include_spip('inc/genie'); |
|
| 178 | + // relancer avec la periode prevue |
|
| 179 | + queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 180 | + } |
|
| 181 | + queue_update_next_job_time(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return $res; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -194,18 +194,18 @@ discard block |
||
| 194 | 194 | * ou un tableau composé de tableaux simples pour lieur plusieurs objets en une fois |
| 195 | 195 | */ |
| 196 | 196 | function queue_link_job($id_job, $objets) { |
| 197 | - include_spip('base/abstract_sql'); |
|
| 198 | - |
|
| 199 | - if (is_array($objets) and count($objets)) { |
|
| 200 | - if (is_array(reset($objets))) { |
|
| 201 | - foreach ($objets as $k => $o) { |
|
| 202 | - $objets[$k]['id_job'] = $id_job; |
|
| 203 | - } |
|
| 204 | - sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 205 | - } else { |
|
| 206 | - sql_insertq('spip_jobs_liens', array_merge(array('id_job' => $id_job), $objets)); |
|
| 207 | - } |
|
| 208 | - } |
|
| 197 | + include_spip('base/abstract_sql'); |
|
| 198 | + |
|
| 199 | + if (is_array($objets) and count($objets)) { |
|
| 200 | + if (is_array(reset($objets))) { |
|
| 201 | + foreach ($objets as $k => $o) { |
|
| 202 | + $objets[$k]['id_job'] = $id_job; |
|
| 203 | + } |
|
| 204 | + sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 205 | + } else { |
|
| 206 | + sql_insertq('spip_jobs_liens', array_merge(array('id_job' => $id_job), $objets)); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * resultat du sql_delete |
| 218 | 218 | */ |
| 219 | 219 | function queue_unlink_job($id_job) { |
| 220 | - return sql_delete("spip_jobs_liens", "id_job=" . intval($id_job)); |
|
| 220 | + return sql_delete("spip_jobs_liens", "id_job=" . intval($id_job)); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -230,74 +230,74 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | function queue_start_job($row) { |
| 232 | 232 | |
| 233 | - // deserialiser les arguments |
|
| 234 | - $args = unserialize($row['args']); |
|
| 235 | - if ($args === false) { |
|
| 236 | - spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 237 | - $args = array(); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - $fonction = $row['fonction']; |
|
| 241 | - if (strlen($inclure = trim($row['inclure']))) { |
|
| 242 | - if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction |
|
| 243 | - $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 244 | - if ($f) { |
|
| 245 | - $fonction = $f; |
|
| 246 | - } |
|
| 247 | - } else { |
|
| 248 | - include_spip($inclure); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - if (!function_exists($fonction)) { |
|
| 253 | - spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 254 | - |
|
| 255 | - return false; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - spip_log("queue [" . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 259 | - switch (count($args)) { |
|
| 260 | - case 0: |
|
| 261 | - $res = $fonction(); |
|
| 262 | - break; |
|
| 263 | - case 1: |
|
| 264 | - $res = $fonction($args[0]); |
|
| 265 | - break; |
|
| 266 | - case 2: |
|
| 267 | - $res = $fonction($args[0], $args[1]); |
|
| 268 | - break; |
|
| 269 | - case 3: |
|
| 270 | - $res = $fonction($args[0], $args[1], $args[2]); |
|
| 271 | - break; |
|
| 272 | - case 4: |
|
| 273 | - $res = $fonction($args[0], $args[1], $args[2], $args[3]); |
|
| 274 | - break; |
|
| 275 | - case 5: |
|
| 276 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]); |
|
| 277 | - break; |
|
| 278 | - case 6: |
|
| 279 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); |
|
| 280 | - break; |
|
| 281 | - case 7: |
|
| 282 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); |
|
| 283 | - break; |
|
| 284 | - case 8: |
|
| 285 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); |
|
| 286 | - break; |
|
| 287 | - case 9: |
|
| 288 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); |
|
| 289 | - break; |
|
| 290 | - case 10: |
|
| 291 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], |
|
| 292 | - $args[9]); |
|
| 293 | - break; |
|
| 294 | - default: |
|
| 295 | - # plus lent mais completement generique |
|
| 296 | - $res = call_user_func_array($fonction, $args); |
|
| 297 | - } |
|
| 298 | - spip_log("queue [" . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 299 | - |
|
| 300 | - return $res; |
|
| 233 | + // deserialiser les arguments |
|
| 234 | + $args = unserialize($row['args']); |
|
| 235 | + if ($args === false) { |
|
| 236 | + spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 237 | + $args = array(); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + $fonction = $row['fonction']; |
|
| 241 | + if (strlen($inclure = trim($row['inclure']))) { |
|
| 242 | + if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction |
|
| 243 | + $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 244 | + if ($f) { |
|
| 245 | + $fonction = $f; |
|
| 246 | + } |
|
| 247 | + } else { |
|
| 248 | + include_spip($inclure); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + if (!function_exists($fonction)) { |
|
| 253 | + spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 254 | + |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + spip_log("queue [" . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 259 | + switch (count($args)) { |
|
| 260 | + case 0: |
|
| 261 | + $res = $fonction(); |
|
| 262 | + break; |
|
| 263 | + case 1: |
|
| 264 | + $res = $fonction($args[0]); |
|
| 265 | + break; |
|
| 266 | + case 2: |
|
| 267 | + $res = $fonction($args[0], $args[1]); |
|
| 268 | + break; |
|
| 269 | + case 3: |
|
| 270 | + $res = $fonction($args[0], $args[1], $args[2]); |
|
| 271 | + break; |
|
| 272 | + case 4: |
|
| 273 | + $res = $fonction($args[0], $args[1], $args[2], $args[3]); |
|
| 274 | + break; |
|
| 275 | + case 5: |
|
| 276 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]); |
|
| 277 | + break; |
|
| 278 | + case 6: |
|
| 279 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); |
|
| 280 | + break; |
|
| 281 | + case 7: |
|
| 282 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); |
|
| 283 | + break; |
|
| 284 | + case 8: |
|
| 285 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); |
|
| 286 | + break; |
|
| 287 | + case 9: |
|
| 288 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); |
|
| 289 | + break; |
|
| 290 | + case 10: |
|
| 291 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], |
|
| 292 | + $args[9]); |
|
| 293 | + break; |
|
| 294 | + default: |
|
| 295 | + # plus lent mais completement generique |
|
| 296 | + $res = call_user_func_array($fonction, $args); |
|
| 297 | + } |
|
| 298 | + spip_log("queue [" . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 299 | + |
|
| 300 | + return $res; |
|
| 301 | 301 | |
| 302 | 302 | } |
| 303 | 303 | |
@@ -325,89 +325,89 @@ discard block |
||
| 325 | 325 | * - true : une planification a été faite. |
| 326 | 326 | */ |
| 327 | 327 | function queue_schedule($force_jobs = null) { |
| 328 | - $time = time(); |
|
| 329 | - if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 330 | - spip_log("_DEBUG_BLOCK_QUEUE : schedule stop", 'jq' . _LOG_DEBUG); |
|
| 331 | - |
|
| 332 | - return; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // rien a faire si le prochain job est encore dans le futur |
|
| 336 | - if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
|
| 337 | - spip_log("queue_sleep_time_to_next_job", 'jq' . _LOG_DEBUG); |
|
| 338 | - |
|
| 339 | - return; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - include_spip('base/abstract_sql'); |
|
| 343 | - // on ne peut rien faire si pas de connexion SQL |
|
| 344 | - if (!spip_connect()) { |
|
| 345 | - return false; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 349 | - $max_time = ini_get('max_execution_time') / 2; |
|
| 350 | - // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 351 | - if (!$max_time) { |
|
| 352 | - $max_time = 5; |
|
| 353 | - } |
|
| 354 | - define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 355 | - } |
|
| 356 | - $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 357 | - |
|
| 358 | - spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 359 | - |
|
| 360 | - if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 361 | - define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 362 | - } |
|
| 363 | - $nbj = 0; |
|
| 364 | - // attraper les jobs |
|
| 365 | - // dont la date est passee (echus en attente), |
|
| 366 | - // par ordre : |
|
| 367 | - // - de priorite |
|
| 368 | - // - de date |
|
| 369 | - // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 370 | - // pour qu'il ne bloque pas les autres jobs en attente |
|
| 371 | - if (is_array($force_jobs) and count($force_jobs)) { |
|
| 372 | - $cond = "status=" . intval(_JQ_SCHEDULED) . " AND " . sql_in("id_job", $force_jobs); |
|
| 373 | - } else { |
|
| 374 | - $now = date('Y-m-d H:i:s', $time); |
|
| 375 | - $cond = "status=" . intval(_JQ_SCHEDULED) . " AND date<=" . sql_quote($now); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 379 | - $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 380 | - do { |
|
| 381 | - if ($row = array_shift($res)) { |
|
| 382 | - $nbj++; |
|
| 383 | - // il faut un verrou, a base de sql_delete |
|
| 384 | - if (sql_delete('spip_jobs', "id_job=" . intval($row['id_job']) . " AND status=" . intval(_JQ_SCHEDULED))) { |
|
| 385 | - #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 386 | - // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 387 | - $row['status'] = _JQ_PENDING; |
|
| 388 | - $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 389 | - sql_insertq('spip_jobs', $row); |
|
| 390 | - |
|
| 391 | - // on a la main sur le job : |
|
| 392 | - // l'executer |
|
| 393 | - $result = queue_start_job($row); |
|
| 394 | - |
|
| 395 | - $time = time(); |
|
| 396 | - queue_close_job($row, $time, $result); |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - spip_log("JQ schedule job end time " . $time, 'jq' . _LOG_DEBUG); |
|
| 400 | - } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
|
| 401 | - spip_log("JQ schedule end time " . time(), 'jq' . _LOG_DEBUG); |
|
| 402 | - |
|
| 403 | - if ($row = array_shift($res)) { |
|
| 404 | - queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 405 | - spip_log("JQ encore !", 'jq' . _LOG_DEBUG); |
|
| 406 | - } else { |
|
| 407 | - queue_update_next_job_time(); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - return true; |
|
| 328 | + $time = time(); |
|
| 329 | + if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 330 | + spip_log("_DEBUG_BLOCK_QUEUE : schedule stop", 'jq' . _LOG_DEBUG); |
|
| 331 | + |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // rien a faire si le prochain job est encore dans le futur |
|
| 336 | + if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
|
| 337 | + spip_log("queue_sleep_time_to_next_job", 'jq' . _LOG_DEBUG); |
|
| 338 | + |
|
| 339 | + return; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + include_spip('base/abstract_sql'); |
|
| 343 | + // on ne peut rien faire si pas de connexion SQL |
|
| 344 | + if (!spip_connect()) { |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 349 | + $max_time = ini_get('max_execution_time') / 2; |
|
| 350 | + // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 351 | + if (!$max_time) { |
|
| 352 | + $max_time = 5; |
|
| 353 | + } |
|
| 354 | + define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 355 | + } |
|
| 356 | + $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 357 | + |
|
| 358 | + spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 359 | + |
|
| 360 | + if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 361 | + define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 362 | + } |
|
| 363 | + $nbj = 0; |
|
| 364 | + // attraper les jobs |
|
| 365 | + // dont la date est passee (echus en attente), |
|
| 366 | + // par ordre : |
|
| 367 | + // - de priorite |
|
| 368 | + // - de date |
|
| 369 | + // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 370 | + // pour qu'il ne bloque pas les autres jobs en attente |
|
| 371 | + if (is_array($force_jobs) and count($force_jobs)) { |
|
| 372 | + $cond = "status=" . intval(_JQ_SCHEDULED) . " AND " . sql_in("id_job", $force_jobs); |
|
| 373 | + } else { |
|
| 374 | + $now = date('Y-m-d H:i:s', $time); |
|
| 375 | + $cond = "status=" . intval(_JQ_SCHEDULED) . " AND date<=" . sql_quote($now); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 379 | + $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 380 | + do { |
|
| 381 | + if ($row = array_shift($res)) { |
|
| 382 | + $nbj++; |
|
| 383 | + // il faut un verrou, a base de sql_delete |
|
| 384 | + if (sql_delete('spip_jobs', "id_job=" . intval($row['id_job']) . " AND status=" . intval(_JQ_SCHEDULED))) { |
|
| 385 | + #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 386 | + // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 387 | + $row['status'] = _JQ_PENDING; |
|
| 388 | + $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 389 | + sql_insertq('spip_jobs', $row); |
|
| 390 | + |
|
| 391 | + // on a la main sur le job : |
|
| 392 | + // l'executer |
|
| 393 | + $result = queue_start_job($row); |
|
| 394 | + |
|
| 395 | + $time = time(); |
|
| 396 | + queue_close_job($row, $time, $result); |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + spip_log("JQ schedule job end time " . $time, 'jq' . _LOG_DEBUG); |
|
| 400 | + } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
|
| 401 | + spip_log("JQ schedule end time " . time(), 'jq' . _LOG_DEBUG); |
|
| 402 | + |
|
| 403 | + if ($row = array_shift($res)) { |
|
| 404 | + queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 405 | + spip_log("JQ encore !", 'jq' . _LOG_DEBUG); |
|
| 406 | + } else { |
|
| 407 | + queue_update_next_job_time(); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + return true; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -425,22 +425,22 @@ discard block |
||
| 425 | 425 | * @param int $result |
| 426 | 426 | */ |
| 427 | 427 | function queue_close_job(&$row, $time, $result = 0) { |
| 428 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 429 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 430 | - // relancer avec les nouveaux arguments de temps |
|
| 431 | - include_spip('inc/genie'); |
|
| 432 | - if ($result < 0) // relancer tout de suite, mais en baissant la priorite |
|
| 433 | - { |
|
| 434 | - queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 435 | - } else // relancer avec la periode prevue |
|
| 436 | - { |
|
| 437 | - queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - // purger ses liens eventuels avec des objets |
|
| 441 | - sql_delete("spip_jobs_liens", "id_job=" . intval($row['id_job'])); |
|
| 442 | - // supprimer le job fini |
|
| 443 | - sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 428 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 429 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 430 | + // relancer avec les nouveaux arguments de temps |
|
| 431 | + include_spip('inc/genie'); |
|
| 432 | + if ($result < 0) // relancer tout de suite, mais en baissant la priorite |
|
| 433 | + { |
|
| 434 | + queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 435 | + } else // relancer avec la periode prevue |
|
| 436 | + { |
|
| 437 | + queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + // purger ses liens eventuels avec des objets |
|
| 441 | + sql_delete("spip_jobs_liens", "id_job=" . intval($row['id_job'])); |
|
| 442 | + // supprimer le job fini |
|
| 443 | + sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | /** |
@@ -450,10 +450,10 @@ discard block |
||
| 450 | 450 | * @uses queue_update_next_job_time() |
| 451 | 451 | */ |
| 452 | 452 | function queue_error_handler() { |
| 453 | - // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 454 | - chdir(_ROOT_CWD); |
|
| 453 | + // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 454 | + chdir(_ROOT_CWD); |
|
| 455 | 455 | |
| 456 | - queue_update_next_job_time(); |
|
| 456 | + queue_update_next_job_time(); |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | |
@@ -470,18 +470,18 @@ discard block |
||
| 470 | 470 | * Périodicité de la tâche en secondes, si tâche périodique, sinon false. |
| 471 | 471 | */ |
| 472 | 472 | function queue_is_cron_job($function, $inclure) { |
| 473 | - static $taches = null; |
|
| 474 | - if (strncmp($inclure, 'genie/', 6) == 0) { |
|
| 475 | - if (is_null($taches)) { |
|
| 476 | - include_spip('inc/genie'); |
|
| 477 | - $taches = taches_generales(); |
|
| 478 | - } |
|
| 479 | - if (isset($taches[$function])) { |
|
| 480 | - return $taches[$function]; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - return false; |
|
| 473 | + static $taches = null; |
|
| 474 | + if (strncmp($inclure, 'genie/', 6) == 0) { |
|
| 475 | + if (is_null($taches)) { |
|
| 476 | + include_spip('inc/genie'); |
|
| 477 | + $taches = taches_generales(); |
|
| 478 | + } |
|
| 479 | + if (isset($taches[$function])) { |
|
| 480 | + return $taches[$function]; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + return false; |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -495,57 +495,57 @@ discard block |
||
| 495 | 495 | * temps de la tache ajoutee ou 0 pour ASAP |
| 496 | 496 | */ |
| 497 | 497 | function queue_update_next_job_time($next_time = null) { |
| 498 | - static $nb_jobs_scheduled = null; |
|
| 499 | - static $deja_la = false; |
|
| 500 | - // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 501 | - static $next = null; |
|
| 502 | - // queue_close_job peut etre reentrant ici |
|
| 503 | - if ($deja_la) { |
|
| 504 | - return; |
|
| 505 | - } |
|
| 506 | - $deja_la = true; |
|
| 507 | - |
|
| 508 | - include_spip('base/abstract_sql'); |
|
| 509 | - $time = time(); |
|
| 510 | - |
|
| 511 | - // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 512 | - // pour cause de timeout ou autre erreur fatale |
|
| 513 | - $res = sql_allfetsel("*", "spip_jobs", |
|
| 514 | - "status=" . intval(_JQ_PENDING) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time - 180))); |
|
| 515 | - if (is_array($res)) { |
|
| 516 | - foreach ($res as $row) { |
|
| 517 | - queue_close_job($row, $time); |
|
| 518 | - spip_log ("queue_close_job car _JQ_PENDING depuis +180s : ".print_r($row,1), "job_mort"._LOG_ERREUR); |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - // chercher la date du prochain job si pas connu |
|
| 523 | - if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
|
| 524 | - $date = sql_getfetsel('date', 'spip_jobs', "status=" . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 525 | - $next = strtotime($date); |
|
| 526 | - } |
|
| 527 | - if (!is_null($next_time)) { |
|
| 528 | - if (is_null($next) or $next > $next_time) { |
|
| 529 | - $next = $next_time; |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - if ($next) { |
|
| 534 | - if (is_null($nb_jobs_scheduled)) { |
|
| 535 | - $nb_jobs_scheduled = sql_countsel('spip_jobs', |
|
| 536 | - "status=" . intval(_JQ_SCHEDULED) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time))); |
|
| 537 | - } elseif ($next <= $time) { |
|
| 538 | - $nb_jobs_scheduled++; |
|
| 539 | - } |
|
| 540 | - // si trop de jobs en attente, on force la purge en fin de hit |
|
| 541 | - // pour assurer le coup |
|
| 542 | - if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 543 | - define('_DIRECT_CRON_FORCE', true); |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - queue_set_next_job_time($next); |
|
| 548 | - $deja_la = false; |
|
| 498 | + static $nb_jobs_scheduled = null; |
|
| 499 | + static $deja_la = false; |
|
| 500 | + // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 501 | + static $next = null; |
|
| 502 | + // queue_close_job peut etre reentrant ici |
|
| 503 | + if ($deja_la) { |
|
| 504 | + return; |
|
| 505 | + } |
|
| 506 | + $deja_la = true; |
|
| 507 | + |
|
| 508 | + include_spip('base/abstract_sql'); |
|
| 509 | + $time = time(); |
|
| 510 | + |
|
| 511 | + // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 512 | + // pour cause de timeout ou autre erreur fatale |
|
| 513 | + $res = sql_allfetsel("*", "spip_jobs", |
|
| 514 | + "status=" . intval(_JQ_PENDING) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time - 180))); |
|
| 515 | + if (is_array($res)) { |
|
| 516 | + foreach ($res as $row) { |
|
| 517 | + queue_close_job($row, $time); |
|
| 518 | + spip_log ("queue_close_job car _JQ_PENDING depuis +180s : ".print_r($row,1), "job_mort"._LOG_ERREUR); |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + // chercher la date du prochain job si pas connu |
|
| 523 | + if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
|
| 524 | + $date = sql_getfetsel('date', 'spip_jobs', "status=" . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 525 | + $next = strtotime($date); |
|
| 526 | + } |
|
| 527 | + if (!is_null($next_time)) { |
|
| 528 | + if (is_null($next) or $next > $next_time) { |
|
| 529 | + $next = $next_time; |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + if ($next) { |
|
| 534 | + if (is_null($nb_jobs_scheduled)) { |
|
| 535 | + $nb_jobs_scheduled = sql_countsel('spip_jobs', |
|
| 536 | + "status=" . intval(_JQ_SCHEDULED) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time))); |
|
| 537 | + } elseif ($next <= $time) { |
|
| 538 | + $nb_jobs_scheduled++; |
|
| 539 | + } |
|
| 540 | + // si trop de jobs en attente, on force la purge en fin de hit |
|
| 541 | + // pour assurer le coup |
|
| 542 | + if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 543 | + define('_DIRECT_CRON_FORCE', true); |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + queue_set_next_job_time($next); |
|
| 548 | + $deja_la = false; |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | |
@@ -556,26 +556,26 @@ discard block |
||
| 556 | 556 | */ |
| 557 | 557 | function queue_set_next_job_time($next) { |
| 558 | 558 | |
| 559 | - // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 560 | - $time = time(); |
|
| 561 | - |
|
| 562 | - // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 563 | - // et ne mettre a jour que si il y a un interet a le faire |
|
| 564 | - // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 565 | - $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 566 | - if ( |
|
| 567 | - ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 568 | - or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 569 | - ) { |
|
| 570 | - if (function_exists("cache_set") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 571 | - cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 572 | - } else { |
|
| 573 | - ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 574 | - } |
|
| 575 | - queue_sleep_time_to_next_job($next); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - return queue_sleep_time_to_next_job(); |
|
| 559 | + // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 560 | + $time = time(); |
|
| 561 | + |
|
| 562 | + // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 563 | + // et ne mettre a jour que si il y a un interet a le faire |
|
| 564 | + // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 565 | + $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 566 | + if ( |
|
| 567 | + ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 568 | + or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 569 | + ) { |
|
| 570 | + if (function_exists("cache_set") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 571 | + cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 572 | + } else { |
|
| 573 | + ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 574 | + } |
|
| 575 | + queue_sleep_time_to_next_job($next); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + return queue_sleep_time_to_next_job(); |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | /** |
@@ -592,121 +592,121 @@ discard block |
||
| 592 | 592 | * @return string |
| 593 | 593 | */ |
| 594 | 594 | function queue_affichage_cron() { |
| 595 | - $texte = ""; |
|
| 596 | - |
|
| 597 | - $time_to_next = queue_sleep_time_to_next_job(); |
|
| 598 | - // rien a faire si le prochain job est encore dans le futur |
|
| 599 | - if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 600 | - return $texte; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 604 | - if (file_exists($lock = _DIR_TMP . "cron.lock") and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 605 | - return $texte; |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - @touch($lock); |
|
| 609 | - |
|
| 610 | - // il y a des taches en attentes |
|
| 611 | - // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 612 | - // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 613 | - $urgent = false; |
|
| 614 | - if ($time_to_next < -300) { |
|
| 615 | - $urgent = true; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - $url_cron = generer_url_action('cron', '', false, true); |
|
| 619 | - |
|
| 620 | - if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) { |
|
| 621 | - |
|
| 622 | - // methode la plus rapide : |
|
| 623 | - // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 624 | - // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 625 | - // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 626 | - // on passe direct a la methode background-image |
|
| 627 | - if (function_exists('fsockopen')) { |
|
| 628 | - $parts = parse_url($url_cron); |
|
| 629 | - |
|
| 630 | - switch ($parts['scheme']) { |
|
| 631 | - case 'https': |
|
| 632 | - $scheme = 'ssl://'; |
|
| 633 | - $port = 443; |
|
| 634 | - break; |
|
| 635 | - case 'http': |
|
| 636 | - default: |
|
| 637 | - $scheme = ''; |
|
| 638 | - $port = 80; |
|
| 639 | - } |
|
| 640 | - $fp = @fsockopen($scheme . $parts['host'], |
|
| 641 | - isset($parts['port']) ? $parts['port'] : $port, |
|
| 642 | - $errno, $errstr, 1); |
|
| 643 | - |
|
| 644 | - if ($fp) { |
|
| 645 | - $host_sent = $parts['host']; |
|
| 646 | - if (isset($parts['port']) and $parts['port'] !== $port) { |
|
| 647 | - $host_sent .= ':' . $parts['port']; |
|
| 648 | - } |
|
| 649 | - $timeout = 200; // ms |
|
| 650 | - stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 651 | - $query = $parts['path'] . ($parts['query'] ? "?" . $parts['query'] : ""); |
|
| 652 | - $out = "GET " . $query . " HTTP/1.1\r\n"; |
|
| 653 | - $out .= "Host: " . $host_sent . "\r\n"; |
|
| 654 | - $out .= "Connection: Close\r\n\r\n"; |
|
| 655 | - fwrite($fp, $out); |
|
| 656 | - spip_timer('read'); |
|
| 657 | - $t = 0; |
|
| 658 | - // on lit la reponse si possible pour fermer proprement la connexion |
|
| 659 | - // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 660 | - while (!feof($fp) and $t < $timeout) { |
|
| 661 | - @fgets($fp, 1024); |
|
| 662 | - $t += spip_timer('read', true); |
|
| 663 | - spip_timer('read'); |
|
| 664 | - } |
|
| 665 | - fclose($fp); |
|
| 666 | - if (!$urgent) { |
|
| 667 | - return $texte; |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - // si fsockopen n'est pas dispo on essaye cURL : |
|
| 672 | - // lancer le cron par un cURL asynchrone si cURL est present |
|
| 673 | - elseif (function_exists("curl_init")) { |
|
| 674 | - //setting the curl parameters. |
|
| 675 | - $ch = curl_init($url_cron); |
|
| 676 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 677 | - // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 678 | - curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 679 | - // valeur mini pour que la requete soit lancee |
|
| 680 | - curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 681 | - // lancer |
|
| 682 | - curl_exec($ch); |
|
| 683 | - // fermer |
|
| 684 | - curl_close($ch); |
|
| 685 | - if (!$urgent) { |
|
| 686 | - return $texte; |
|
| 687 | - } |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - // si deja force, on retourne sans rien |
|
| 692 | - if (defined('_DIRECT_CRON_FORCE')) { |
|
| 693 | - return $texte; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - // si c'est un bot |
|
| 697 | - // inutile de faire un appel par image background, |
|
| 698 | - // on force un appel direct en fin de hit |
|
| 699 | - if ((defined('_IS_BOT') and _IS_BOT)) { |
|
| 700 | - define('_DIRECT_CRON_FORCE', true); |
|
| 701 | - |
|
| 702 | - return $texte; |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 706 | - $url_cron = generer_url_action('cron'); |
|
| 707 | - $texte = '<!-- SPIP-CRON -->' |
|
| 708 | - . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 709 | - . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 710 | - |
|
| 711 | - return $texte; |
|
| 595 | + $texte = ""; |
|
| 596 | + |
|
| 597 | + $time_to_next = queue_sleep_time_to_next_job(); |
|
| 598 | + // rien a faire si le prochain job est encore dans le futur |
|
| 599 | + if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 600 | + return $texte; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 604 | + if (file_exists($lock = _DIR_TMP . "cron.lock") and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 605 | + return $texte; |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + @touch($lock); |
|
| 609 | + |
|
| 610 | + // il y a des taches en attentes |
|
| 611 | + // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 612 | + // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 613 | + $urgent = false; |
|
| 614 | + if ($time_to_next < -300) { |
|
| 615 | + $urgent = true; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + $url_cron = generer_url_action('cron', '', false, true); |
|
| 619 | + |
|
| 620 | + if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) { |
|
| 621 | + |
|
| 622 | + // methode la plus rapide : |
|
| 623 | + // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 624 | + // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 625 | + // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 626 | + // on passe direct a la methode background-image |
|
| 627 | + if (function_exists('fsockopen')) { |
|
| 628 | + $parts = parse_url($url_cron); |
|
| 629 | + |
|
| 630 | + switch ($parts['scheme']) { |
|
| 631 | + case 'https': |
|
| 632 | + $scheme = 'ssl://'; |
|
| 633 | + $port = 443; |
|
| 634 | + break; |
|
| 635 | + case 'http': |
|
| 636 | + default: |
|
| 637 | + $scheme = ''; |
|
| 638 | + $port = 80; |
|
| 639 | + } |
|
| 640 | + $fp = @fsockopen($scheme . $parts['host'], |
|
| 641 | + isset($parts['port']) ? $parts['port'] : $port, |
|
| 642 | + $errno, $errstr, 1); |
|
| 643 | + |
|
| 644 | + if ($fp) { |
|
| 645 | + $host_sent = $parts['host']; |
|
| 646 | + if (isset($parts['port']) and $parts['port'] !== $port) { |
|
| 647 | + $host_sent .= ':' . $parts['port']; |
|
| 648 | + } |
|
| 649 | + $timeout = 200; // ms |
|
| 650 | + stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 651 | + $query = $parts['path'] . ($parts['query'] ? "?" . $parts['query'] : ""); |
|
| 652 | + $out = "GET " . $query . " HTTP/1.1\r\n"; |
|
| 653 | + $out .= "Host: " . $host_sent . "\r\n"; |
|
| 654 | + $out .= "Connection: Close\r\n\r\n"; |
|
| 655 | + fwrite($fp, $out); |
|
| 656 | + spip_timer('read'); |
|
| 657 | + $t = 0; |
|
| 658 | + // on lit la reponse si possible pour fermer proprement la connexion |
|
| 659 | + // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 660 | + while (!feof($fp) and $t < $timeout) { |
|
| 661 | + @fgets($fp, 1024); |
|
| 662 | + $t += spip_timer('read', true); |
|
| 663 | + spip_timer('read'); |
|
| 664 | + } |
|
| 665 | + fclose($fp); |
|
| 666 | + if (!$urgent) { |
|
| 667 | + return $texte; |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + // si fsockopen n'est pas dispo on essaye cURL : |
|
| 672 | + // lancer le cron par un cURL asynchrone si cURL est present |
|
| 673 | + elseif (function_exists("curl_init")) { |
|
| 674 | + //setting the curl parameters. |
|
| 675 | + $ch = curl_init($url_cron); |
|
| 676 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 677 | + // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 678 | + curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 679 | + // valeur mini pour que la requete soit lancee |
|
| 680 | + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 681 | + // lancer |
|
| 682 | + curl_exec($ch); |
|
| 683 | + // fermer |
|
| 684 | + curl_close($ch); |
|
| 685 | + if (!$urgent) { |
|
| 686 | + return $texte; |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + // si deja force, on retourne sans rien |
|
| 692 | + if (defined('_DIRECT_CRON_FORCE')) { |
|
| 693 | + return $texte; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + // si c'est un bot |
|
| 697 | + // inutile de faire un appel par image background, |
|
| 698 | + // on force un appel direct en fin de hit |
|
| 699 | + if ((defined('_IS_BOT') and _IS_BOT)) { |
|
| 700 | + define('_DIRECT_CRON_FORCE', true); |
|
| 701 | + |
|
| 702 | + return $texte; |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 706 | + $url_cron = generer_url_action('cron'); |
|
| 707 | + $texte = '<!-- SPIP-CRON -->' |
|
| 708 | + . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 709 | + . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 710 | + |
|
| 711 | + return $texte; |
|
| 712 | 712 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $md5args = md5($arguments); |
| 71 | 71 | |
| 72 | 72 | // si pas de date programee, des que possible |
| 73 | - $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 73 | + $duplicate_where = 'status='.intval(_JQ_SCHEDULED).' AND '; |
|
| 74 | 74 | if (!$time) { |
| 75 | 75 | $time = time(); |
| 76 | 76 | $duplicate_where = ""; // ne pas dupliquer si deja le meme job en cours d'execution |
@@ -94,9 +94,8 @@ discard block |
||
| 94 | 94 | and |
| 95 | 95 | $id_job = sql_getfetsel('id_job', 'spip_jobs', |
| 96 | 96 | $duplicate_where = |
| 97 | - $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 98 | - . (($no_duplicate === 'function_only') ? '' : |
|
| 99 | - ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))) |
|
| 97 | + $duplicate_where.'fonction='.sql_quote($function) |
|
| 98 | + . (($no_duplicate === 'function_only') ? '' : ' AND md5args='.sql_quote($md5args).' AND inclure='.sql_quote($file))) |
|
| 100 | 99 | ) { |
| 101 | 100 | return $id_job; |
| 102 | 101 | } |
@@ -108,9 +107,9 @@ discard block |
||
| 108 | 107 | if ( |
| 109 | 108 | $no_duplicate |
| 110 | 109 | and |
| 111 | - $id_prev = sql_getfetsel('id_job', 'spip_jobs', "id_job<" . intval($id_job) . " AND $duplicate_where") |
|
| 110 | + $id_prev = sql_getfetsel('id_job', 'spip_jobs', "id_job<".intval($id_job)." AND $duplicate_where") |
|
| 112 | 111 | ) { |
| 113 | - sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 112 | + sql_delete('spip_jobs', 'id_job='.intval($id_job)); |
|
| 114 | 113 | |
| 115 | 114 | return $id_prev; |
| 116 | 115 | } |
@@ -122,9 +121,9 @@ discard block |
||
| 122 | 121 | // ie cas d'un char non acceptables sur certains type de champs |
| 123 | 122 | // qui coupe la valeur |
| 124 | 123 | if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
| 125 | - $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 124 | + $args = sql_getfetsel('args', 'spip_jobs', 'id_job='.intval($id_job)); |
|
| 126 | 125 | if ($args !== $arguments) { |
| 127 | - spip_log('arguments job errones / longueur ' . strlen($args) . " vs " . strlen($arguments) . ' / valeur : ' . var_export($arguments, |
|
| 126 | + spip_log('arguments job errones / longueur '.strlen($args)." vs ".strlen($arguments).' / valeur : '.var_export($arguments, |
|
| 128 | 127 | true), 'queue'); |
| 129 | 128 | } |
| 130 | 129 | } |
@@ -152,7 +151,7 @@ discard block |
||
| 152 | 151 | function queue_purger() { |
| 153 | 152 | include_spip('base/abstract_sql'); |
| 154 | 153 | sql_delete('spip_jobs'); |
| 155 | - sql_delete("spip_jobs_liens", "id_job NOT IN (" . sql_get_select("id_job", "spip_jobs") . ")"); |
|
| 154 | + sql_delete("spip_jobs_liens", "id_job NOT IN (".sql_get_select("id_job", "spip_jobs").")"); |
|
| 156 | 155 | include_spip('inc/genie'); |
| 157 | 156 | genie_queue_watch_dist(); |
| 158 | 157 | } |
@@ -167,8 +166,8 @@ discard block |
||
| 167 | 166 | function queue_remove_job($id_job) { |
| 168 | 167 | include_spip('base/abstract_sql'); |
| 169 | 168 | |
| 170 | - if ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 171 | - and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 169 | + if ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job='.intval($id_job)) |
|
| 170 | + and $res = sql_delete('spip_jobs', 'id_job='.intval($id_job)) |
|
| 172 | 171 | ) { |
| 173 | 172 | queue_unlink_job($id_job); |
| 174 | 173 | // est-ce une tache cron qu'il faut relancer ? |
@@ -217,7 +216,7 @@ discard block |
||
| 217 | 216 | * resultat du sql_delete |
| 218 | 217 | */ |
| 219 | 218 | function queue_unlink_job($id_job) { |
| 220 | - return sql_delete("spip_jobs_liens", "id_job=" . intval($id_job)); |
|
| 219 | + return sql_delete("spip_jobs_liens", "id_job=".intval($id_job)); |
|
| 221 | 220 | } |
| 222 | 221 | |
| 223 | 222 | /** |
@@ -233,7 +232,7 @@ discard block |
||
| 233 | 232 | // deserialiser les arguments |
| 234 | 233 | $args = unserialize($row['args']); |
| 235 | 234 | if ($args === false) { |
| 236 | - spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 235 | + spip_log('arguments job errones '.var_export($row, true), 'queue'); |
|
| 237 | 236 | $args = array(); |
| 238 | 237 | } |
| 239 | 238 | |
@@ -250,12 +249,12 @@ discard block |
||
| 250 | 249 | } |
| 251 | 250 | |
| 252 | 251 | if (!function_exists($fonction)) { |
| 253 | - spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 252 | + spip_log("fonction $fonction ($inclure) inexistante ".var_export($row, true), 'queue'); |
|
| 254 | 253 | |
| 255 | 254 | return false; |
| 256 | 255 | } |
| 257 | 256 | |
| 258 | - spip_log("queue [" . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 257 | + spip_log("queue [".$row['id_job']."]: $fonction() start", 'queue'); |
|
| 259 | 258 | switch (count($args)) { |
| 260 | 259 | case 0: |
| 261 | 260 | $res = $fonction(); |
@@ -295,7 +294,7 @@ discard block |
||
| 295 | 294 | # plus lent mais completement generique |
| 296 | 295 | $res = call_user_func_array($fonction, $args); |
| 297 | 296 | } |
| 298 | - spip_log("queue [" . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 297 | + spip_log("queue [".$row['id_job']."]: $fonction() end", 'queue'); |
|
| 299 | 298 | |
| 300 | 299 | return $res; |
| 301 | 300 | |
@@ -327,14 +326,14 @@ discard block |
||
| 327 | 326 | function queue_schedule($force_jobs = null) { |
| 328 | 327 | $time = time(); |
| 329 | 328 | if (defined('_DEBUG_BLOCK_QUEUE')) { |
| 330 | - spip_log("_DEBUG_BLOCK_QUEUE : schedule stop", 'jq' . _LOG_DEBUG); |
|
| 329 | + spip_log("_DEBUG_BLOCK_QUEUE : schedule stop", 'jq'._LOG_DEBUG); |
|
| 331 | 330 | |
| 332 | 331 | return; |
| 333 | 332 | } |
| 334 | 333 | |
| 335 | 334 | // rien a faire si le prochain job est encore dans le futur |
| 336 | 335 | if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
| 337 | - spip_log("queue_sleep_time_to_next_job", 'jq' . _LOG_DEBUG); |
|
| 336 | + spip_log("queue_sleep_time_to_next_job", 'jq'._LOG_DEBUG); |
|
| 338 | 337 | |
| 339 | 338 | return; |
| 340 | 339 | } |
@@ -355,7 +354,7 @@ discard block |
||
| 355 | 354 | } |
| 356 | 355 | $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
| 357 | 356 | |
| 358 | - spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 357 | + spip_log("JQ schedule $time / $end_time", 'jq'._LOG_DEBUG); |
|
| 359 | 358 | |
| 360 | 359 | if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
| 361 | 360 | define('_JQ_MAX_JOBS_EXECUTE', 200); |
@@ -369,19 +368,19 @@ discard block |
||
| 369 | 368 | // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
| 370 | 369 | // pour qu'il ne bloque pas les autres jobs en attente |
| 371 | 370 | if (is_array($force_jobs) and count($force_jobs)) { |
| 372 | - $cond = "status=" . intval(_JQ_SCHEDULED) . " AND " . sql_in("id_job", $force_jobs); |
|
| 371 | + $cond = "status=".intval(_JQ_SCHEDULED)." AND ".sql_in("id_job", $force_jobs); |
|
| 373 | 372 | } else { |
| 374 | 373 | $now = date('Y-m-d H:i:s', $time); |
| 375 | - $cond = "status=" . intval(_JQ_SCHEDULED) . " AND date<=" . sql_quote($now); |
|
| 374 | + $cond = "status=".intval(_JQ_SCHEDULED)." AND date<=".sql_quote($now); |
|
| 376 | 375 | } |
| 377 | 376 | |
| 378 | 377 | register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
| 379 | - $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 378 | + $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,'.(_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 380 | 379 | do { |
| 381 | 380 | if ($row = array_shift($res)) { |
| 382 | 381 | $nbj++; |
| 383 | 382 | // il faut un verrou, a base de sql_delete |
| 384 | - if (sql_delete('spip_jobs', "id_job=" . intval($row['id_job']) . " AND status=" . intval(_JQ_SCHEDULED))) { |
|
| 383 | + if (sql_delete('spip_jobs', "id_job=".intval($row['id_job'])." AND status=".intval(_JQ_SCHEDULED))) { |
|
| 385 | 384 | #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
| 386 | 385 | // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
| 387 | 386 | $row['status'] = _JQ_PENDING; |
@@ -396,13 +395,13 @@ discard block |
||
| 396 | 395 | queue_close_job($row, $time, $result); |
| 397 | 396 | } |
| 398 | 397 | } |
| 399 | - spip_log("JQ schedule job end time " . $time, 'jq' . _LOG_DEBUG); |
|
| 398 | + spip_log("JQ schedule job end time ".$time, 'jq'._LOG_DEBUG); |
|
| 400 | 399 | } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
| 401 | - spip_log("JQ schedule end time " . time(), 'jq' . _LOG_DEBUG); |
|
| 400 | + spip_log("JQ schedule end time ".time(), 'jq'._LOG_DEBUG); |
|
| 402 | 401 | |
| 403 | 402 | if ($row = array_shift($res)) { |
| 404 | 403 | queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
| 405 | - spip_log("JQ encore !", 'jq' . _LOG_DEBUG); |
|
| 404 | + spip_log("JQ encore !", 'jq'._LOG_DEBUG); |
|
| 406 | 405 | } else { |
| 407 | 406 | queue_update_next_job_time(); |
| 408 | 407 | } |
@@ -438,9 +437,9 @@ discard block |
||
| 438 | 437 | } |
| 439 | 438 | } |
| 440 | 439 | // purger ses liens eventuels avec des objets |
| 441 | - sql_delete("spip_jobs_liens", "id_job=" . intval($row['id_job'])); |
|
| 440 | + sql_delete("spip_jobs_liens", "id_job=".intval($row['id_job'])); |
|
| 442 | 441 | // supprimer le job fini |
| 443 | - sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 442 | + sql_delete('spip_jobs', 'id_job='.intval($row['id_job'])); |
|
| 444 | 443 | } |
| 445 | 444 | |
| 446 | 445 | /** |
@@ -511,17 +510,17 @@ discard block |
||
| 511 | 510 | // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
| 512 | 511 | // pour cause de timeout ou autre erreur fatale |
| 513 | 512 | $res = sql_allfetsel("*", "spip_jobs", |
| 514 | - "status=" . intval(_JQ_PENDING) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time - 180))); |
|
| 513 | + "status=".intval(_JQ_PENDING)." AND date<".sql_quote(date('Y-m-d H:i:s', $time - 180))); |
|
| 515 | 514 | if (is_array($res)) { |
| 516 | 515 | foreach ($res as $row) { |
| 517 | 516 | queue_close_job($row, $time); |
| 518 | - spip_log ("queue_close_job car _JQ_PENDING depuis +180s : ".print_r($row,1), "job_mort"._LOG_ERREUR); |
|
| 517 | + spip_log("queue_close_job car _JQ_PENDING depuis +180s : ".print_r($row, 1), "job_mort"._LOG_ERREUR); |
|
| 519 | 518 | } |
| 520 | 519 | } |
| 521 | 520 | |
| 522 | 521 | // chercher la date du prochain job si pas connu |
| 523 | 522 | if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
| 524 | - $date = sql_getfetsel('date', 'spip_jobs', "status=" . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 523 | + $date = sql_getfetsel('date', 'spip_jobs', "status=".intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 525 | 524 | $next = strtotime($date); |
| 526 | 525 | } |
| 527 | 526 | if (!is_null($next_time)) { |
@@ -533,7 +532,7 @@ discard block |
||
| 533 | 532 | if ($next) { |
| 534 | 533 | if (is_null($nb_jobs_scheduled)) { |
| 535 | 534 | $nb_jobs_scheduled = sql_countsel('spip_jobs', |
| 536 | - "status=" . intval(_JQ_SCHEDULED) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time))); |
|
| 535 | + "status=".intval(_JQ_SCHEDULED)." AND date<".sql_quote(date('Y-m-d H:i:s', $time))); |
|
| 537 | 536 | } elseif ($next <= $time) { |
| 538 | 537 | $nb_jobs_scheduled++; |
| 539 | 538 | } |
@@ -601,7 +600,7 @@ discard block |
||
| 601 | 600 | } |
| 602 | 601 | |
| 603 | 602 | // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
| 604 | - if (file_exists($lock = _DIR_TMP . "cron.lock") and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 603 | + if (file_exists($lock = _DIR_TMP."cron.lock") and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 605 | 604 | return $texte; |
| 606 | 605 | } |
| 607 | 606 | |
@@ -637,20 +636,20 @@ discard block |
||
| 637 | 636 | $scheme = ''; |
| 638 | 637 | $port = 80; |
| 639 | 638 | } |
| 640 | - $fp = @fsockopen($scheme . $parts['host'], |
|
| 639 | + $fp = @fsockopen($scheme.$parts['host'], |
|
| 641 | 640 | isset($parts['port']) ? $parts['port'] : $port, |
| 642 | 641 | $errno, $errstr, 1); |
| 643 | 642 | |
| 644 | 643 | if ($fp) { |
| 645 | 644 | $host_sent = $parts['host']; |
| 646 | 645 | if (isset($parts['port']) and $parts['port'] !== $port) { |
| 647 | - $host_sent .= ':' . $parts['port']; |
|
| 646 | + $host_sent .= ':'.$parts['port']; |
|
| 648 | 647 | } |
| 649 | 648 | $timeout = 200; // ms |
| 650 | 649 | stream_set_timeout($fp, 0, $timeout * 1000); |
| 651 | - $query = $parts['path'] . ($parts['query'] ? "?" . $parts['query'] : ""); |
|
| 652 | - $out = "GET " . $query . " HTTP/1.1\r\n"; |
|
| 653 | - $out .= "Host: " . $host_sent . "\r\n"; |
|
| 650 | + $query = $parts['path'].($parts['query'] ? "?".$parts['query'] : ""); |
|
| 651 | + $out = "GET ".$query." HTTP/1.1\r\n"; |
|
| 652 | + $out .= "Host: ".$host_sent."\r\n"; |
|
| 654 | 653 | $out .= "Connection: Close\r\n\r\n"; |
| 655 | 654 | fwrite($fp, $out); |
| 656 | 655 | spip_timer('read'); |
@@ -80,6 +80,9 @@ discard block |
||
| 80 | 80 | // une $source differente ; le script detecte automagiquement si ce qu'on |
| 81 | 81 | // echappe est un div ou un span |
| 82 | 82 | // http://code.spip.net/@code_echappement |
| 83 | +/** |
|
| 84 | + * @param string $mode |
|
| 85 | + */ |
|
| 83 | 86 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 84 | 87 | if (!strlen($rempl)) { |
| 85 | 88 | return ''; |
@@ -284,6 +287,9 @@ discard block |
||
| 284 | 287 | // Reinserer le javascript de confiance (venant des modeles) |
| 285 | 288 | |
| 286 | 289 | // http://code.spip.net/@echappe_retour_modeles |
| 290 | +/** |
|
| 291 | + * @param string $letexte |
|
| 292 | + */ |
|
| 287 | 293 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 288 | 294 | $letexte = echappe_retour($letexte); |
| 289 | 295 | |
@@ -433,6 +439,9 @@ discard block |
||
| 433 | 439 | } |
| 434 | 440 | |
| 435 | 441 | |
| 442 | +/** |
|
| 443 | + * @param string $letexte |
|
| 444 | + */ |
|
| 436 | 445 | function echapper_faux_tags($letexte) { |
| 437 | 446 | if (strpos($letexte, '<') === false) { |
| 438 | 447 | return $letexte; |
@@ -384,10 +384,12 @@ |
||
| 384 | 384 | $texte = $court; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - if (strpos($texte, "\n")) // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 387 | + if (strpos($texte, "\n")) { |
|
| 388 | + // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 388 | 389 | { |
| 389 | 390 | $points = ''; |
| 390 | 391 | } |
| 392 | + } |
|
| 391 | 393 | |
| 392 | 394 | // remettre les paragraphes |
| 393 | 395 | $texte = preg_replace("/\r+/", "\n\n", $texte); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('inc/filtres'); |
| 23 | 23 | include_spip('inc/lang'); |
@@ -39,21 +39,21 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function definir_puce() { |
| 41 | 41 | |
| 42 | - // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | - // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | - // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | - $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 42 | + // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | + // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | + // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | + $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 46 | 46 | |
| 47 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | - if ($dir == 'rtl') { |
|
| 49 | - $p .= '_rtl'; |
|
| 50 | - } |
|
| 47 | + $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | + if ($dir == 'rtl') { |
|
| 49 | + $p .= '_rtl'; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - if (!isset($GLOBALS[$p])) { |
|
| 53 | - $GLOBALS[$p] = '<span class="spip-puce '.$dir.'"><b>–</b></span>'; |
|
| 54 | - } |
|
| 52 | + if (!isset($GLOBALS[$p])) { |
|
| 53 | + $GLOBALS[$p] = '<span class="spip-puce '.$dir.'"><b>–</b></span>'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $GLOBALS[$p]; |
|
| 56 | + return $GLOBALS[$p]; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -61,13 +61,13 @@ discard block |
||
| 61 | 61 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 62 | 62 | |
| 63 | 63 | if (!defined('_BALISES_BLOCS')) { |
| 64 | - define('_BALISES_BLOCS', |
|
| 65 | - 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 66 | - ); |
|
| 64 | + define('_BALISES_BLOCS', |
|
| 65 | + 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 66 | + ); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 70 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 70 | + define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // |
@@ -79,26 +79,26 @@ discard block |
||
| 79 | 79 | // echappe est un div ou un span |
| 80 | 80 | // http://code.spip.net/@code_echappement |
| 81 | 81 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 82 | - if (!strlen($rempl)) { |
|
| 83 | - return ''; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Tester si on echappe en span ou en div |
|
| 87 | - if (is_null($mode) or !in_array($mode, array('div', 'span'))) { |
|
| 88 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 92 | - $taille = 30000; |
|
| 93 | - $return = ""; |
|
| 94 | - for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 95 | - // Convertir en base64 et cacher dans un attribut |
|
| 96 | - // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 97 | - $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 98 | - $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $return; |
|
| 82 | + if (!strlen($rempl)) { |
|
| 83 | + return ''; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Tester si on echappe en span ou en div |
|
| 87 | + if (is_null($mode) or !in_array($mode, array('div', 'span'))) { |
|
| 88 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 92 | + $taille = 30000; |
|
| 93 | + $return = ""; |
|
| 94 | + for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 95 | + // Convertir en base64 et cacher dans un attribut |
|
| 96 | + // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 97 | + $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 98 | + $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $return; |
|
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |
@@ -106,64 +106,64 @@ discard block |
||
| 106 | 106 | // Echapper les <html>...</ html> |
| 107 | 107 | // http://code.spip.net/@traiter_echap_html_dist |
| 108 | 108 | function traiter_echap_html_dist($regs) { |
| 109 | - return $regs[3]; |
|
| 109 | + return $regs[3]; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // Echapper les <code>...</ code> |
| 113 | 113 | // http://code.spip.net/@traiter_echap_code_dist |
| 114 | 114 | function traiter_echap_code_dist($regs) { |
| 115 | - list(, , $att, $corps) = $regs; |
|
| 116 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 117 | - |
|
| 118 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 119 | - if (is_int(strpos($echap, "\n"))) { |
|
| 120 | - // supprimer les sauts de ligne debut/fin |
|
| 121 | - // (mais pas les espaces => ascii art). |
|
| 122 | - $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", "", $echap); |
|
| 123 | - $echap = nl2br($echap); |
|
| 124 | - $echap = "<div style='text-align: left;' " |
|
| 125 | - . "class='spip_code' dir='ltr'><code$att>" |
|
| 126 | - . $echap . "</code></div>"; |
|
| 127 | - } else { |
|
| 128 | - $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . "</code>"; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $echap = str_replace("\t", " ", $echap); |
|
| 132 | - $echap = str_replace(" ", " ", $echap); |
|
| 133 | - |
|
| 134 | - return $echap; |
|
| 115 | + list(, , $att, $corps) = $regs; |
|
| 116 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 117 | + |
|
| 118 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 119 | + if (is_int(strpos($echap, "\n"))) { |
|
| 120 | + // supprimer les sauts de ligne debut/fin |
|
| 121 | + // (mais pas les espaces => ascii art). |
|
| 122 | + $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", "", $echap); |
|
| 123 | + $echap = nl2br($echap); |
|
| 124 | + $echap = "<div style='text-align: left;' " |
|
| 125 | + . "class='spip_code' dir='ltr'><code$att>" |
|
| 126 | + . $echap . "</code></div>"; |
|
| 127 | + } else { |
|
| 128 | + $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . "</code>"; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $echap = str_replace("\t", " ", $echap); |
|
| 132 | + $echap = str_replace(" ", " ", $echap); |
|
| 133 | + |
|
| 134 | + return $echap; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 138 | 138 | // http://code.spip.net/@traiter_echap_cadre_dist |
| 139 | 139 | function traiter_echap_cadre_dist($regs) { |
| 140 | - $echap = trim(entites_html($regs[3])); |
|
| 141 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 142 | - $lignes = explode("\n", trim($echap)); |
|
| 143 | - $n = 0; |
|
| 144 | - foreach ($lignes as $l) { |
|
| 145 | - $n += floor(strlen($l) / 60) + 1; |
|
| 146 | - } |
|
| 147 | - $n = max($n, 2); |
|
| 148 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 149 | - |
|
| 150 | - return $echap; |
|
| 140 | + $echap = trim(entites_html($regs[3])); |
|
| 141 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 142 | + $lignes = explode("\n", trim($echap)); |
|
| 143 | + $n = 0; |
|
| 144 | + foreach ($lignes as $l) { |
|
| 145 | + $n += floor(strlen($l) / 60) + 1; |
|
| 146 | + } |
|
| 147 | + $n = max($n, 2); |
|
| 148 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 149 | + |
|
| 150 | + return $echap; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // http://code.spip.net/@traiter_echap_frame_dist |
| 154 | 154 | function traiter_echap_frame_dist($regs) { |
| 155 | - return traiter_echap_cadre_dist($regs); |
|
| 155 | + return traiter_echap_cadre_dist($regs); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // http://code.spip.net/@traiter_echap_script_dist |
| 159 | 159 | function traiter_echap_script_dist($regs) { |
| 160 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 161 | - if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 162 | - return highlight_string($regs[0], true); |
|
| 163 | - } |
|
| 160 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 161 | + if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 162 | + return highlight_string($regs[0], true); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - // Cas normal : le script passe tel quel |
|
| 166 | - return $regs[0]; |
|
| 165 | + // Cas normal : le script passe tel quel |
|
| 166 | + return $regs[0]; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | define('_PROTEGE_BLOCS', ',<(html|code|cadre|frame|script|style)(\s[^>]*)?>(.*)</\1>,UimsS'); |
@@ -172,71 +172,71 @@ discard block |
||
| 172 | 172 | // - pour $no_transform voir le filtre post_autobr dans inc/filtres |
| 173 | 173 | // http://code.spip.net/@echappe_html |
| 174 | 174 | function echappe_html( |
| 175 | - $letexte, |
|
| 176 | - $source = '', |
|
| 177 | - $no_transform = false, |
|
| 178 | - $preg = '' |
|
| 175 | + $letexte, |
|
| 176 | + $source = '', |
|
| 177 | + $no_transform = false, |
|
| 178 | + $preg = '' |
|
| 179 | 179 | ) { |
| 180 | - if (!is_string($letexte) or !strlen($letexte)) { |
|
| 181 | - return $letexte; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // si le texte recu est long PCRE risque d'exploser, on |
|
| 185 | - // fait donc un mic-mac pour augmenter pcre.backtrack_limit |
|
| 186 | - if (($len = strlen($letexte)) > 100000) { |
|
| 187 | - if (!$old = @ini_get('pcre.backtrack_limit')) { |
|
| 188 | - $old = 100000; |
|
| 189 | - } |
|
| 190 | - if ($len > $old) { |
|
| 191 | - $a = @ini_set('pcre.backtrack_limit', $len); |
|
| 192 | - spip_log("ini_set pcre.backtrack_limit=$len ($old)"); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (($preg or strpos($letexte, "<") !== false) |
|
| 197 | - and preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 198 | - ) { |
|
| 199 | - foreach ($matches as $regs) { |
|
| 200 | - // echappements tels quels ? |
|
| 201 | - if ($no_transform) { |
|
| 202 | - $echap = $regs[0]; |
|
| 203 | - } // sinon les traiter selon le cas |
|
| 204 | - else { |
|
| 205 | - if (function_exists($f = 'traiter_echap_' . strtolower($regs[1]))) { |
|
| 206 | - $echap = $f($regs); |
|
| 207 | - } else { |
|
| 208 | - if (function_exists($f = $f . '_dist')) { |
|
| 209 | - $echap = $f($regs); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $p = strpos($letexte, $regs[0]); |
|
| 215 | - $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - if ($no_transform) { |
|
| 220 | - return $letexte; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 224 | - // seulement si on a echappe les <script> |
|
| 225 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 226 | - // dans une callback autonommee |
|
| 227 | - if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'script') !== false) { |
|
| 228 | - if (strpos($letexte, "<" . "?") !== false and preg_match_all(',<[?].*($|[?]>),UisS', |
|
| 229 | - $letexte, $matches, PREG_SET_ORDER) |
|
| 230 | - ) { |
|
| 231 | - foreach ($matches as $regs) { |
|
| 232 | - $letexte = str_replace($regs[0], |
|
| 233 | - code_echappement(highlight_string($regs[0], true), $source), |
|
| 234 | - $letexte); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $letexte; |
|
| 180 | + if (!is_string($letexte) or !strlen($letexte)) { |
|
| 181 | + return $letexte; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // si le texte recu est long PCRE risque d'exploser, on |
|
| 185 | + // fait donc un mic-mac pour augmenter pcre.backtrack_limit |
|
| 186 | + if (($len = strlen($letexte)) > 100000) { |
|
| 187 | + if (!$old = @ini_get('pcre.backtrack_limit')) { |
|
| 188 | + $old = 100000; |
|
| 189 | + } |
|
| 190 | + if ($len > $old) { |
|
| 191 | + $a = @ini_set('pcre.backtrack_limit', $len); |
|
| 192 | + spip_log("ini_set pcre.backtrack_limit=$len ($old)"); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (($preg or strpos($letexte, "<") !== false) |
|
| 197 | + and preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 198 | + ) { |
|
| 199 | + foreach ($matches as $regs) { |
|
| 200 | + // echappements tels quels ? |
|
| 201 | + if ($no_transform) { |
|
| 202 | + $echap = $regs[0]; |
|
| 203 | + } // sinon les traiter selon le cas |
|
| 204 | + else { |
|
| 205 | + if (function_exists($f = 'traiter_echap_' . strtolower($regs[1]))) { |
|
| 206 | + $echap = $f($regs); |
|
| 207 | + } else { |
|
| 208 | + if (function_exists($f = $f . '_dist')) { |
|
| 209 | + $echap = $f($regs); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $p = strpos($letexte, $regs[0]); |
|
| 215 | + $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + if ($no_transform) { |
|
| 220 | + return $letexte; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 224 | + // seulement si on a echappe les <script> |
|
| 225 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 226 | + // dans une callback autonommee |
|
| 227 | + if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'script') !== false) { |
|
| 228 | + if (strpos($letexte, "<" . "?") !== false and preg_match_all(',<[?].*($|[?]>),UisS', |
|
| 229 | + $letexte, $matches, PREG_SET_ORDER) |
|
| 230 | + ) { |
|
| 231 | + foreach ($matches as $regs) { |
|
| 232 | + $letexte = str_replace($regs[0], |
|
| 233 | + code_echappement(highlight_string($regs[0], true), $source), |
|
| 234 | + $letexte); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $letexte; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // |
@@ -245,52 +245,52 @@ discard block |
||
| 245 | 245 | // par propre() : exemple dans multi et dans typo() |
| 246 | 246 | // http://code.spip.net/@echappe_retour |
| 247 | 247 | function echappe_retour($letexte, $source = '', $filtre = "") { |
| 248 | - if (strpos($letexte, "base64$source")) { |
|
| 249 | - # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 250 | - $max_prof = 5; |
|
| 251 | - while (strpos($letexte, "<") !== false |
|
| 252 | - and |
|
| 253 | - preg_match_all(',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 254 | - $letexte, $regs, PREG_SET_ORDER) |
|
| 255 | - and $max_prof--) { |
|
| 256 | - foreach ($regs as $reg) { |
|
| 257 | - $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 258 | - // recherche d'attributs supplementaires |
|
| 259 | - $at = array(); |
|
| 260 | - foreach (array('lang', 'dir') as $attr) { |
|
| 261 | - if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 262 | - $at[$attr] = $a; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - if ($at) { |
|
| 266 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 267 | - foreach ($at as $attr => $a) { |
|
| 268 | - $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - if ($filtre) { |
|
| 272 | - $rempl = $filtre($rempl); |
|
| 273 | - } |
|
| 274 | - $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return $letexte; |
|
| 248 | + if (strpos($letexte, "base64$source")) { |
|
| 249 | + # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 250 | + $max_prof = 5; |
|
| 251 | + while (strpos($letexte, "<") !== false |
|
| 252 | + and |
|
| 253 | + preg_match_all(',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 254 | + $letexte, $regs, PREG_SET_ORDER) |
|
| 255 | + and $max_prof--) { |
|
| 256 | + foreach ($regs as $reg) { |
|
| 257 | + $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 258 | + // recherche d'attributs supplementaires |
|
| 259 | + $at = array(); |
|
| 260 | + foreach (array('lang', 'dir') as $attr) { |
|
| 261 | + if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 262 | + $at[$attr] = $a; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + if ($at) { |
|
| 266 | + $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 267 | + foreach ($at as $attr => $a) { |
|
| 268 | + $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + if ($filtre) { |
|
| 272 | + $rempl = $filtre($rempl); |
|
| 273 | + } |
|
| 274 | + $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return $letexte; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | // Reinserer le javascript de confiance (venant des modeles) |
| 283 | 283 | |
| 284 | 284 | // http://code.spip.net/@echappe_retour_modeles |
| 285 | 285 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 286 | - $letexte = echappe_retour($letexte); |
|
| 286 | + $letexte = echappe_retour($letexte); |
|
| 287 | 287 | |
| 288 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 289 | - if ($interdire_scripts) { |
|
| 290 | - $letexte = interdire_scripts($letexte); |
|
| 291 | - } |
|
| 288 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 289 | + if ($interdire_scripts) { |
|
| 290 | + $letexte = interdire_scripts($letexte); |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - return trim($letexte); |
|
| 293 | + return trim($letexte); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
@@ -318,130 +318,130 @@ discard block |
||
| 318 | 318 | * Texte coupé |
| 319 | 319 | **/ |
| 320 | 320 | function couper($texte, $taille = 50, $suite = null) { |
| 321 | - if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 322 | - return ''; |
|
| 323 | - } |
|
| 324 | - $offset = 400 + 2 * $taille; |
|
| 325 | - while ($offset < $length |
|
| 326 | - and strlen(preg_replace(",<(!--|\w|/)[^>]+>,Uims", "", substr($texte, 0, $offset))) < $taille) { |
|
| 327 | - $offset = 2 * $offset; |
|
| 328 | - } |
|
| 329 | - if ($offset < $length |
|
| 330 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 331 | - ) { |
|
| 332 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 333 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 334 | - $offset = $p_tag_fermant + 1; |
|
| 335 | - } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 336 | - } |
|
| 337 | - $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 338 | - |
|
| 339 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 340 | - include_spip('inc/lien'); |
|
| 341 | - } |
|
| 342 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 343 | - |
|
| 344 | - // balises de sauts de ligne et paragraphe |
|
| 345 | - $texte = preg_replace("/<p( [^>]*)?" . ">/", "\r", $texte); |
|
| 346 | - $texte = preg_replace("/<br( [^>]*)?" . ">/", "\n", $texte); |
|
| 347 | - |
|
| 348 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 349 | - $texte = str_replace("\n\n", "\r", $texte); |
|
| 350 | - |
|
| 351 | - // supprimer les tags |
|
| 352 | - $texte = supprimer_tags($texte); |
|
| 353 | - $texte = trim(str_replace("\n", " ", $texte)); |
|
| 354 | - $texte .= "\n"; // marquer la fin |
|
| 355 | - |
|
| 356 | - // corriger la longueur de coupe |
|
| 357 | - // en fonction de la presence de caracteres utf |
|
| 358 | - if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 359 | - $long = charset2unicode($texte); |
|
| 360 | - $long = spip_substr($long, 0, max($taille, 1)); |
|
| 361 | - $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 362 | - $taille += $nbcharutf; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - // couper au mot precedent |
|
| 367 | - $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 368 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 369 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 370 | - if (is_null($suite)) { |
|
| 371 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 372 | - } |
|
| 373 | - $points = $suite; |
|
| 374 | - |
|
| 375 | - // trop court ? ne pas faire de (...) |
|
| 376 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 377 | - $points = ''; |
|
| 378 | - $long = spip_substr($texte, 0, $taille); |
|
| 379 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 380 | - // encore trop court ? couper au caractere |
|
| 381 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 382 | - $texte = $long; |
|
| 383 | - } |
|
| 384 | - } else { |
|
| 385 | - $texte = $court; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if (strpos($texte, "\n")) // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 389 | - { |
|
| 390 | - $points = ''; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - // remettre les paragraphes |
|
| 394 | - $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 395 | - |
|
| 396 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 397 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 398 | - |
|
| 399 | - return quote_amp(trim($texte)) . $points; |
|
| 321 | + if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 322 | + return ''; |
|
| 323 | + } |
|
| 324 | + $offset = 400 + 2 * $taille; |
|
| 325 | + while ($offset < $length |
|
| 326 | + and strlen(preg_replace(",<(!--|\w|/)[^>]+>,Uims", "", substr($texte, 0, $offset))) < $taille) { |
|
| 327 | + $offset = 2 * $offset; |
|
| 328 | + } |
|
| 329 | + if ($offset < $length |
|
| 330 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 331 | + ) { |
|
| 332 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 333 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 334 | + $offset = $p_tag_fermant + 1; |
|
| 335 | + } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 336 | + } |
|
| 337 | + $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 338 | + |
|
| 339 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 340 | + include_spip('inc/lien'); |
|
| 341 | + } |
|
| 342 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 343 | + |
|
| 344 | + // balises de sauts de ligne et paragraphe |
|
| 345 | + $texte = preg_replace("/<p( [^>]*)?" . ">/", "\r", $texte); |
|
| 346 | + $texte = preg_replace("/<br( [^>]*)?" . ">/", "\n", $texte); |
|
| 347 | + |
|
| 348 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 349 | + $texte = str_replace("\n\n", "\r", $texte); |
|
| 350 | + |
|
| 351 | + // supprimer les tags |
|
| 352 | + $texte = supprimer_tags($texte); |
|
| 353 | + $texte = trim(str_replace("\n", " ", $texte)); |
|
| 354 | + $texte .= "\n"; // marquer la fin |
|
| 355 | + |
|
| 356 | + // corriger la longueur de coupe |
|
| 357 | + // en fonction de la presence de caracteres utf |
|
| 358 | + if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 359 | + $long = charset2unicode($texte); |
|
| 360 | + $long = spip_substr($long, 0, max($taille, 1)); |
|
| 361 | + $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 362 | + $taille += $nbcharutf; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + // couper au mot precedent |
|
| 367 | + $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 368 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 369 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 370 | + if (is_null($suite)) { |
|
| 371 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 372 | + } |
|
| 373 | + $points = $suite; |
|
| 374 | + |
|
| 375 | + // trop court ? ne pas faire de (...) |
|
| 376 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 377 | + $points = ''; |
|
| 378 | + $long = spip_substr($texte, 0, $taille); |
|
| 379 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 380 | + // encore trop court ? couper au caractere |
|
| 381 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 382 | + $texte = $long; |
|
| 383 | + } |
|
| 384 | + } else { |
|
| 385 | + $texte = $court; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if (strpos($texte, "\n")) // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 389 | + { |
|
| 390 | + $points = ''; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + // remettre les paragraphes |
|
| 394 | + $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 395 | + |
|
| 396 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 397 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 398 | + |
|
| 399 | + return quote_amp(trim($texte)) . $points; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | |
| 403 | 403 | // http://code.spip.net/@protege_js_modeles |
| 404 | 404 | function protege_js_modeles($t) { |
| 405 | - if (isset($GLOBALS['visiteur_session'])) { |
|
| 406 | - if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 407 | - if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 408 | - include_spip('inc/acces'); |
|
| 409 | - define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 410 | - } |
|
| 411 | - foreach ($r as $regs) { |
|
| 412 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 416 | - if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 417 | - include_spip('inc/acces'); |
|
| 418 | - define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 419 | - } |
|
| 420 | - foreach ($r as $regs) { |
|
| 421 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - return $t; |
|
| 405 | + if (isset($GLOBALS['visiteur_session'])) { |
|
| 406 | + if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 407 | + if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 408 | + include_spip('inc/acces'); |
|
| 409 | + define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 410 | + } |
|
| 411 | + foreach ($r as $regs) { |
|
| 412 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 416 | + if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 417 | + include_spip('inc/acces'); |
|
| 418 | + define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 419 | + } |
|
| 420 | + foreach ($r as $regs) { |
|
| 421 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + return $t; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | |
| 430 | 430 | function echapper_faux_tags($letexte) { |
| 431 | - if (strpos($letexte, '<') === false) { |
|
| 432 | - return $letexte; |
|
| 433 | - } |
|
| 434 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, null, PREG_SPLIT_DELIM_CAPTURE); |
|
| 435 | - |
|
| 436 | - $letexte = ""; |
|
| 437 | - while (count($textMatches)) { |
|
| 438 | - // un texte a echapper |
|
| 439 | - $letexte .= str_replace("<", '<', array_shift($textMatches)); |
|
| 440 | - // un tag html qui a servit a faite le split |
|
| 441 | - $letexte .= array_shift($textMatches); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - return $letexte; |
|
| 431 | + if (strpos($letexte, '<') === false) { |
|
| 432 | + return $letexte; |
|
| 433 | + } |
|
| 434 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, null, PREG_SPLIT_DELIM_CAPTURE); |
|
| 435 | + |
|
| 436 | + $letexte = ""; |
|
| 437 | + while (count($textMatches)) { |
|
| 438 | + // un texte a echapper |
|
| 439 | + $letexte .= str_replace("<", '<', array_shift($textMatches)); |
|
| 440 | + // un tag html qui a servit a faite le split |
|
| 441 | + $letexte .= array_shift($textMatches); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + return $letexte; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -454,44 +454,44 @@ discard block |
||
| 454 | 454 | * @return string |
| 455 | 455 | */ |
| 456 | 456 | function echapper_html_suspect($texte, $strict=true) { |
| 457 | - static $echapper_html_suspect; |
|
| 458 | - if (!$texte or !is_string($texte)) { |
|
| 459 | - return $texte; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - if (!isset($echapper_html_suspect)) { |
|
| 463 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 464 | - } |
|
| 465 | - // si fonction personalisee, on delegue |
|
| 466 | - if ($echapper_html_suspect) { |
|
| 467 | - return $echapper_html_suspect($texte, $strict); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - if (strpos($texte, '<') === false |
|
| 471 | - or strpos($texte, '=') === false) { |
|
| 472 | - return $texte; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 476 | - // car sinon on declenche sur les modeles ou ressources |
|
| 477 | - if (!$strict and |
|
| 478 | - (strpos($texte,'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 479 | - ){ |
|
| 480 | - return $texte; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 484 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 485 | - // donc un test d'egalite est trop strict |
|
| 486 | - if (strlen(safehtml($texte)) !== strlen($texte)) { |
|
| 487 | - $texte = str_replace("<", "<", $texte); |
|
| 488 | - if (!function_exists('attribut_html')) { |
|
| 489 | - include_spip('inc/filtres'); |
|
| 490 | - } |
|
| 491 | - $texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return $texte; |
|
| 457 | + static $echapper_html_suspect; |
|
| 458 | + if (!$texte or !is_string($texte)) { |
|
| 459 | + return $texte; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + if (!isset($echapper_html_suspect)) { |
|
| 463 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 464 | + } |
|
| 465 | + // si fonction personalisee, on delegue |
|
| 466 | + if ($echapper_html_suspect) { |
|
| 467 | + return $echapper_html_suspect($texte, $strict); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + if (strpos($texte, '<') === false |
|
| 471 | + or strpos($texte, '=') === false) { |
|
| 472 | + return $texte; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 476 | + // car sinon on declenche sur les modeles ou ressources |
|
| 477 | + if (!$strict and |
|
| 478 | + (strpos($texte,'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 479 | + ){ |
|
| 480 | + return $texte; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 484 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 485 | + // donc un test d'egalite est trop strict |
|
| 486 | + if (strlen(safehtml($texte)) !== strlen($texte)) { |
|
| 487 | + $texte = str_replace("<", "<", $texte); |
|
| 488 | + if (!function_exists('attribut_html')) { |
|
| 489 | + include_spip('inc/filtres'); |
|
| 490 | + } |
|
| 491 | + $texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return $texte; |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | |
@@ -512,27 +512,27 @@ discard block |
||
| 512 | 512 | * Texte sécurisé |
| 513 | 513 | **/ |
| 514 | 514 | function safehtml($t) { |
| 515 | - static $safehtml; |
|
| 516 | - |
|
| 517 | - if (!$t or !is_string($t)) { |
|
| 518 | - return $t; |
|
| 519 | - } |
|
| 520 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 521 | - if (strpos($t, '<') === false) { |
|
| 522 | - return str_replace("\x00", '', $t); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $t = interdire_scripts($t); // jolifier le php |
|
| 526 | - $t = echappe_js($t); |
|
| 527 | - |
|
| 528 | - if (!isset($safehtml)) { |
|
| 529 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 530 | - } |
|
| 531 | - if ($safehtml) { |
|
| 532 | - $t = $safehtml($t); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 515 | + static $safehtml; |
|
| 516 | + |
|
| 517 | + if (!$t or !is_string($t)) { |
|
| 518 | + return $t; |
|
| 519 | + } |
|
| 520 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 521 | + if (strpos($t, '<') === false) { |
|
| 522 | + return str_replace("\x00", '', $t); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $t = interdire_scripts($t); // jolifier le php |
|
| 526 | + $t = echappe_js($t); |
|
| 527 | + |
|
| 528 | + if (!isset($safehtml)) { |
|
| 529 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 530 | + } |
|
| 531 | + if ($safehtml) { |
|
| 532 | + $t = $safehtml($t); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | |
@@ -554,10 +554,10 @@ discard block |
||
| 554 | 554 | * Texte sans les modèles d'image |
| 555 | 555 | **/ |
| 556 | 556 | function supprime_img($letexte, $message = null) { |
| 557 | - if ($message === null) { |
|
| 558 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 559 | - } |
|
| 557 | + if ($message === null) { |
|
| 558 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 559 | + } |
|
| 560 | 560 | |
| 561 | - return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 562 | - $message, $letexte); |
|
| 561 | + return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 562 | + $message, $letexte); |
|
| 563 | 563 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | // celle du texte) et public (spip_lang est la langue du texte) |
| 45 | 45 | $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
| 46 | 46 | |
| 47 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 47 | + $p = 'puce'.(test_espace_prive() ? '_prive' : ''); |
|
| 48 | 48 | if ($dir == 'rtl') { |
| 49 | 49 | $p .= '_rtl'; |
| 50 | 50 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 70 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 70 | + define('_BALISES_BLOCS_REGEXP', ',</?('._BALISES_BLOCS.')[>[:space:]],iS'); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | // Tester si on echappe en span ou en div |
| 87 | 87 | if (is_null($mode) or !in_array($mode, array('div', 'span'))) { |
| 88 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 88 | + $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | // Echapper les <code>...</ code> |
| 113 | 113 | // http://code.spip.net/@traiter_echap_code_dist |
| 114 | 114 | function traiter_echap_code_dist($regs) { |
| 115 | - list(, , $att, $corps) = $regs; |
|
| 115 | + list(,, $att, $corps) = $regs; |
|
| 116 | 116 | $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
| 117 | 117 | |
| 118 | 118 | // ne pas mettre le <div...> s'il n'y a qu'une ligne |
@@ -123,9 +123,9 @@ discard block |
||
| 123 | 123 | $echap = nl2br($echap); |
| 124 | 124 | $echap = "<div style='text-align: left;' " |
| 125 | 125 | . "class='spip_code' dir='ltr'><code$att>" |
| 126 | - . $echap . "</code></div>"; |
|
| 126 | + . $echap."</code></div>"; |
|
| 127 | 127 | } else { |
| 128 | - $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . "</code>"; |
|
| 128 | + $echap = "<code$att class='spip_code' dir='ltr'>".$echap."</code>"; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | $echap = str_replace("\t", " ", $echap); |
@@ -202,10 +202,10 @@ discard block |
||
| 202 | 202 | $echap = $regs[0]; |
| 203 | 203 | } // sinon les traiter selon le cas |
| 204 | 204 | else { |
| 205 | - if (function_exists($f = 'traiter_echap_' . strtolower($regs[1]))) { |
|
| 205 | + if (function_exists($f = 'traiter_echap_'.strtolower($regs[1]))) { |
|
| 206 | 206 | $echap = $f($regs); |
| 207 | 207 | } else { |
| 208 | - if (function_exists($f = $f . '_dist')) { |
|
| 208 | + if (function_exists($f = $f.'_dist')) { |
|
| 209 | 209 | $echap = $f($regs); |
| 210 | 210 | } |
| 211 | 211 | } |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | // (derogatoire car on ne peut pas faire passer < ? ... ? > |
| 226 | 226 | // dans une callback autonommee |
| 227 | 227 | if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'script') !== false) { |
| 228 | - if (strpos($letexte, "<" . "?") !== false and preg_match_all(',<[?].*($|[?]>),UisS', |
|
| 228 | + if (strpos($letexte, "<"."?") !== false and preg_match_all(',<[?].*($|[?]>),UisS', |
|
| 229 | 229 | $letexte, $matches, PREG_SET_ORDER) |
| 230 | 230 | ) { |
| 231 | 231 | foreach ($matches as $regs) { |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | $max_prof = 5; |
| 251 | 251 | while (strpos($letexte, "<") !== false |
| 252 | 252 | and |
| 253 | - preg_match_all(',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 253 | + preg_match_all(',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 254 | 254 | $letexte, $regs, PREG_SET_ORDER) |
| 255 | 255 | and $max_prof--) { |
| 256 | 256 | foreach ($regs as $reg) { |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | if ($at) { |
| 266 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 266 | + $rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>'; |
|
| 267 | 267 | foreach ($at as $attr => $a) { |
| 268 | 268 | $rempl = inserer_attribut($rempl, $attr, $a); |
| 269 | 269 | } |
@@ -342,8 +342,8 @@ discard block |
||
| 342 | 342 | $texte = nettoyer_raccourcis_typo($texte); |
| 343 | 343 | |
| 344 | 344 | // balises de sauts de ligne et paragraphe |
| 345 | - $texte = preg_replace("/<p( [^>]*)?" . ">/", "\r", $texte); |
|
| 346 | - $texte = preg_replace("/<br( [^>]*)?" . ">/", "\n", $texte); |
|
| 345 | + $texte = preg_replace("/<p( [^>]*)?".">/", "\r", $texte); |
|
| 346 | + $texte = preg_replace("/<br( [^>]*)?".">/", "\n", $texte); |
|
| 347 | 347 | |
| 348 | 348 | // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
| 349 | 349 | $texte = str_replace("\n\n", "\r", $texte); |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | // supprimer les tags |
| 352 | 352 | $texte = supprimer_tags($texte); |
| 353 | 353 | $texte = trim(str_replace("\n", " ", $texte)); |
| 354 | - $texte .= "\n"; // marquer la fin |
|
| 354 | + $texte .= "\n"; // marquer la fin |
|
| 355 | 355 | |
| 356 | 356 | // corriger la longueur de coupe |
| 357 | 357 | // en fonction de la presence de caracteres utf |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | // couper au mot precedent |
| 367 | 367 | $long = spip_substr($texte, 0, max($taille - 4, 1)); |
| 368 | 368 | $u = $GLOBALS['meta']['pcre_u']; |
| 369 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 369 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long); |
|
| 370 | 370 | if (is_null($suite)) { |
| 371 | 371 | $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
| 372 | 372 | } |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
| 377 | 377 | $points = ''; |
| 378 | 378 | $long = spip_substr($texte, 0, $taille); |
| 379 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 379 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long); |
|
| 380 | 380 | // encore trop court ? couper au caractere |
| 381 | 381 | if (spip_strlen($texte) < 0.75 * $taille) { |
| 382 | 382 | $texte = $long; |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | // supprimer l'eventuelle entite finale mal coupee |
| 397 | 397 | $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
| 398 | 398 | |
| 399 | - return quote_amp(trim($texte)) . $points; |
|
| 399 | + return quote_amp(trim($texte)).$points; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | |
@@ -409,16 +409,16 @@ discard block |
||
| 409 | 409 | define('_PROTEGE_JS_MODELES', creer_uniqid()); |
| 410 | 410 | } |
| 411 | 411 | foreach ($r as $regs) { |
| 412 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 412 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript'._PROTEGE_JS_MODELES), $t); |
|
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 415 | + if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 416 | 416 | if (!defined('_PROTEGE_PHP_MODELES')) { |
| 417 | 417 | include_spip('inc/acces'); |
| 418 | 418 | define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
| 419 | 419 | } |
| 420 | 420 | foreach ($r as $regs) { |
| 421 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 421 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php'._PROTEGE_PHP_MODELES), $t); |
|
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | } |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | * @param bool $strict |
| 454 | 454 | * @return string |
| 455 | 455 | */ |
| 456 | -function echapper_html_suspect($texte, $strict=true) { |
|
| 456 | +function echapper_html_suspect($texte, $strict = true) { |
|
| 457 | 457 | static $echapper_html_suspect; |
| 458 | 458 | if (!$texte or !is_string($texte)) { |
| 459 | 459 | return $texte; |
@@ -475,8 +475,8 @@ discard block |
||
| 475 | 475 | // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
| 476 | 476 | // car sinon on declenche sur les modeles ou ressources |
| 477 | 477 | if (!$strict and |
| 478 | - (strpos($texte,'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 479 | - ){ |
|
| 478 | + (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 479 | + ) { |
|
| 480 | 480 | return $texte; |
| 481 | 481 | } |
| 482 | 482 | |
@@ -555,9 +555,9 @@ discard block |
||
| 555 | 555 | **/ |
| 556 | 556 | function supprime_img($letexte, $message = null) { |
| 557 | 557 | if ($message === null) { |
| 558 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 558 | + $message = '('._T('img_indisponible').')'; |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 561 | + return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i', |
|
| 562 | 562 | $message, $letexte); |
| 563 | 563 | } |