@@ -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'); |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return string |
| 39 | 39 | **/ |
| 40 | 40 | function base_dump_meta_name($rub) { |
| 41 | - return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | + return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -53,15 +53,15 @@ discard block |
||
| 53 | 53 | * @return string |
| 54 | 54 | **/ |
| 55 | 55 | function base_dump_dir($meta) { |
| 56 | - include_spip('inc/documents'); |
|
| 57 | - // determine upload va aussi initialiser l'index "restreint" |
|
| 58 | - $maindir = determine_upload(); |
|
| 59 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 60 | - $maindir = _DIR_DUMP; |
|
| 61 | - } |
|
| 62 | - $dir = sous_repertoire($maindir, $meta); |
|
| 63 | - |
|
| 64 | - return $dir; |
|
| 56 | + include_spip('inc/documents'); |
|
| 57 | + // determine upload va aussi initialiser l'index "restreint" |
|
| 58 | + $maindir = determine_upload(); |
|
| 59 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 60 | + $maindir = _DIR_DUMP; |
|
| 61 | + } |
|
| 62 | + $dir = sous_repertoire($maindir, $meta); |
|
| 63 | + |
|
| 64 | + return $dir; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -75,28 +75,28 @@ discard block |
||
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | 77 | function base_lister_toutes_tables( |
| 78 | - $serveur = '', |
|
| 79 | - $tables = [], |
|
| 80 | - $exclude = [], |
|
| 81 | - $affiche_vrai_prefixe = false |
|
| 78 | + $serveur = '', |
|
| 79 | + $tables = [], |
|
| 80 | + $exclude = [], |
|
| 81 | + $affiche_vrai_prefixe = false |
|
| 82 | 82 | ) { |
| 83 | - spip_connect($serveur); |
|
| 84 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 85 | - $prefixe = $connexion['prefixe']; |
|
| 86 | - |
|
| 87 | - $p = '/^' . $prefixe . '/'; |
|
| 88 | - $res = $tables; |
|
| 89 | - foreach (sql_alltable(null, $serveur) as $t) { |
|
| 90 | - if (preg_match($p, $t)) { |
|
| 91 | - $t1 = preg_replace($p, 'spip', $t); |
|
| 92 | - if (!in_array($t1, $tables) and !in_array($t1, $exclude)) { |
|
| 93 | - $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - sort($res); |
|
| 98 | - |
|
| 99 | - return $res; |
|
| 83 | + spip_connect($serveur); |
|
| 84 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 85 | + $prefixe = $connexion['prefixe']; |
|
| 86 | + |
|
| 87 | + $p = '/^' . $prefixe . '/'; |
|
| 88 | + $res = $tables; |
|
| 89 | + foreach (sql_alltable(null, $serveur) as $t) { |
|
| 90 | + if (preg_match($p, $t)) { |
|
| 91 | + $t1 = preg_replace($p, 'spip', $t); |
|
| 92 | + if (!in_array($t1, $tables) and !in_array($t1, $exclude)) { |
|
| 93 | + $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + sort($res); |
|
| 98 | + |
|
| 99 | + return $res; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | 108 | function base_prefixe_tables($serveur = '') { |
| 109 | - spip_connect($serveur); |
|
| 110 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 111 | - $prefixe = $connexion['prefixe']; |
|
| 109 | + spip_connect($serveur); |
|
| 110 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 111 | + $prefixe = $connexion['prefixe']; |
|
| 112 | 112 | |
| 113 | - return $prefixe; |
|
| 113 | + return $prefixe; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
@@ -125,31 +125,31 @@ discard block |
||
| 125 | 125 | * @return array |
| 126 | 126 | */ |
| 127 | 127 | function base_saisie_tables($name, $tables, $exclude = [], $post = null, $serveur = '') { |
| 128 | - include_spip('inc/filtres'); |
|
| 129 | - $res = []; |
|
| 130 | - foreach ($tables as $k => $t) { |
|
| 131 | - // par defaut tout est coche sauf les tables dans $exclude |
|
| 132 | - if (is_null($post)) { |
|
| 133 | - $check = (in_array($t, $exclude) ? false : true); |
|
| 134 | - } // mais si on a poste une selection, la reprendre |
|
| 135 | - else { |
|
| 136 | - $check = in_array($t, $post); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 140 | - . "[]' id='$name$k'" |
|
| 141 | - . ($check ? " checked='checked'" : '') |
|
| 142 | - . "/>\n" |
|
| 143 | - . "<label for='$name$k'>$t</label>" |
|
| 144 | - . ' (' |
|
| 145 | - . sinon( |
|
| 146 | - singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 147 | - _T('dump:aucune_donnee') |
|
| 148 | - ) |
|
| 149 | - . ')'; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $res; |
|
| 128 | + include_spip('inc/filtres'); |
|
| 129 | + $res = []; |
|
| 130 | + foreach ($tables as $k => $t) { |
|
| 131 | + // par defaut tout est coche sauf les tables dans $exclude |
|
| 132 | + if (is_null($post)) { |
|
| 133 | + $check = (in_array($t, $exclude) ? false : true); |
|
| 134 | + } // mais si on a poste une selection, la reprendre |
|
| 135 | + else { |
|
| 136 | + $check = in_array($t, $post); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 140 | + . "[]' id='$name$k'" |
|
| 141 | + . ($check ? " checked='checked'" : '') |
|
| 142 | + . "/>\n" |
|
| 143 | + . "<label for='$name$k'>$t</label>" |
|
| 144 | + . ' (' |
|
| 145 | + . sinon( |
|
| 146 | + singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 147 | + _T('dump:aucune_donnee') |
|
| 148 | + ) |
|
| 149 | + . ')'; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $res; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -161,27 +161,27 @@ discard block |
||
| 161 | 161 | * @return array |
| 162 | 162 | */ |
| 163 | 163 | function lister_tables_noexport() { |
| 164 | - // par defaut tout est exporte sauf les tables ci-dessous |
|
| 165 | - static $EXPORT_tables_noexport = null; |
|
| 166 | - if (!is_null($EXPORT_tables_noexport)) { |
|
| 167 | - return $EXPORT_tables_noexport; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $EXPORT_tables_noexport = [ |
|
| 171 | - 'spip_caches', // plugin invalideur |
|
| 172 | - 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 173 | - 'spip_test', // c'est un test ! |
|
| 174 | - #'spip_referers', |
|
| 175 | - #'spip_referers_articles', |
|
| 176 | - #'spip_visites', |
|
| 177 | - #'spip_visites_articles', |
|
| 178 | - #'spip_versions', |
|
| 179 | - #'spip_versions_fragments' |
|
| 180 | - ]; |
|
| 181 | - |
|
| 182 | - $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 183 | - |
|
| 184 | - return $EXPORT_tables_noexport; |
|
| 164 | + // par defaut tout est exporte sauf les tables ci-dessous |
|
| 165 | + static $EXPORT_tables_noexport = null; |
|
| 166 | + if (!is_null($EXPORT_tables_noexport)) { |
|
| 167 | + return $EXPORT_tables_noexport; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $EXPORT_tables_noexport = [ |
|
| 171 | + 'spip_caches', // plugin invalideur |
|
| 172 | + 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 173 | + 'spip_test', // c'est un test ! |
|
| 174 | + #'spip_referers', |
|
| 175 | + #'spip_referers_articles', |
|
| 176 | + #'spip_visites', |
|
| 177 | + #'spip_visites_articles', |
|
| 178 | + #'spip_versions', |
|
| 179 | + #'spip_versions_fragments' |
|
| 180 | + ]; |
|
| 181 | + |
|
| 182 | + $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 183 | + |
|
| 184 | + return $EXPORT_tables_noexport; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -192,25 +192,25 @@ discard block |
||
| 192 | 192 | * @return array |
| 193 | 193 | */ |
| 194 | 194 | function lister_tables_noimport() { |
| 195 | - static $IMPORT_tables_noimport = null; |
|
| 196 | - if (!is_null($IMPORT_tables_noimport)) { |
|
| 197 | - return $IMPORT_tables_noimport; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $IMPORT_tables_noimport = []; |
|
| 201 | - // par defaut tout est importe sauf les tables ci-dessous |
|
| 202 | - // possibiliter de definir cela tables via la meta |
|
| 203 | - // compatibilite |
|
| 204 | - if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 205 | - $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 206 | - if (!is_array($IMPORT_tables_noimport)) { |
|
| 207 | - include_spip('inc/meta'); |
|
| 208 | - effacer_meta('IMPORT_tables_noimport'); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 212 | - |
|
| 213 | - return $IMPORT_tables_noimport; |
|
| 195 | + static $IMPORT_tables_noimport = null; |
|
| 196 | + if (!is_null($IMPORT_tables_noimport)) { |
|
| 197 | + return $IMPORT_tables_noimport; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $IMPORT_tables_noimport = []; |
|
| 201 | + // par defaut tout est importe sauf les tables ci-dessous |
|
| 202 | + // possibiliter de definir cela tables via la meta |
|
| 203 | + // compatibilite |
|
| 204 | + if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 205 | + $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 206 | + if (!is_array($IMPORT_tables_noimport)) { |
|
| 207 | + include_spip('inc/meta'); |
|
| 208 | + effacer_meta('IMPORT_tables_noimport'); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 212 | + |
|
| 213 | + return $IMPORT_tables_noimport; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | |
@@ -222,23 +222,23 @@ discard block |
||
| 222 | 222 | * @return array |
| 223 | 223 | */ |
| 224 | 224 | function lister_tables_noerase() { |
| 225 | - static $IMPORT_tables_noerase = null; |
|
| 226 | - if (!is_null($IMPORT_tables_noerase)) { |
|
| 227 | - return $IMPORT_tables_noerase; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $IMPORT_tables_noerase = [ |
|
| 231 | - 'spip_meta', |
|
| 232 | - // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 233 | - // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 234 | - 'spip_referers', |
|
| 235 | - 'spip_referers_articles', |
|
| 236 | - 'spip_visites', |
|
| 237 | - 'spip_visites_articles' |
|
| 238 | - ]; |
|
| 239 | - $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 240 | - |
|
| 241 | - return $IMPORT_tables_noerase; |
|
| 225 | + static $IMPORT_tables_noerase = null; |
|
| 226 | + if (!is_null($IMPORT_tables_noerase)) { |
|
| 227 | + return $IMPORT_tables_noerase; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $IMPORT_tables_noerase = [ |
|
| 231 | + 'spip_meta', |
|
| 232 | + // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 233 | + // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 234 | + 'spip_referers', |
|
| 235 | + 'spip_referers_articles', |
|
| 236 | + 'spip_visites', |
|
| 237 | + 'spip_visites_articles' |
|
| 238 | + ]; |
|
| 239 | + $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 240 | + |
|
| 241 | + return $IMPORT_tables_noerase; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -252,86 +252,86 @@ discard block |
||
| 252 | 252 | * @return array |
| 253 | 253 | */ |
| 254 | 254 | function base_liste_table_for_dump($exclude_tables = []) { |
| 255 | - $tables_for_dump = []; |
|
| 256 | - $tables_pointees = []; |
|
| 257 | - $tables = []; |
|
| 258 | - $tables_principales = $GLOBALS['tables_principales']; |
|
| 259 | - $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 260 | - $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 261 | - |
|
| 262 | - if ( |
|
| 263 | - include_spip('base/objets') |
|
| 264 | - and function_exists('lister_tables_objets_sql') |
|
| 265 | - ) { |
|
| 266 | - $tables = lister_tables_objets_sql(); |
|
| 267 | - foreach ($tables as $t => $infos) { |
|
| 268 | - if ($infos['principale'] and !isset($tables_principales[$t])) { |
|
| 269 | - $tables_principales[$t] = true; |
|
| 270 | - } |
|
| 271 | - if (!$infos['principale'] and !isset($tables_auxiliaires[$t])) { |
|
| 272 | - $tables_auxiliaires[$t] = true; |
|
| 273 | - } |
|
| 274 | - if (is_countable($infos['tables_jointures']) ? count($infos['tables_jointures']) : 0) { |
|
| 275 | - $tables_jointures[$t] = array_merge( |
|
| 276 | - $tables_jointures[$t] ?? [], |
|
| 277 | - $infos['tables_jointures'] |
|
| 278 | - ); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // on construit un index des tables de liens |
|
| 284 | - // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 285 | - $tables_for_link = []; |
|
| 286 | - foreach ($tables_jointures as $table => $liste_relations) { |
|
| 287 | - if (is_array($liste_relations)) { |
|
| 288 | - $nom = $table; |
|
| 289 | - if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 290 | - $nom = "spip_$table"; |
|
| 291 | - } |
|
| 292 | - if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 293 | - foreach ($liste_relations as $link_table) { |
|
| 294 | - if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 295 | - $tables_for_link[$link_table][] = $nom; |
|
| 296 | - } else { |
|
| 297 | - if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 298 | - $tables_for_link["spip_$link_table"][] = $nom; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - $liste_tables = [...array_keys($tables_principales), ...array_keys($tables_auxiliaires), ...array_keys($tables)]; |
|
| 307 | - foreach ($liste_tables as $table) { |
|
| 308 | - // $name = preg_replace("{^spip_}","",$table); |
|
| 309 | - if ( |
|
| 310 | - !isset($tables_pointees[$table]) |
|
| 311 | - && !in_array($table, $exclude_tables) |
|
| 312 | - && !isset($tables_for_link[$table]) |
|
| 313 | - ) { |
|
| 314 | - $tables_for_dump[] = $table; |
|
| 315 | - $tables_pointees[$table] = 1; |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - foreach ($tables_for_link as $link_table => $liste) { |
|
| 319 | - $connecte = true; |
|
| 320 | - foreach ($liste as $connect_table) { |
|
| 321 | - if (!in_array($connect_table, $tables_for_dump)) { |
|
| 322 | - $connecte = false; |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - if ($connecte) { |
|
| 326 | - # on ajoute les liaisons en premier |
|
| 327 | - # si une restauration est interrompue, |
|
| 328 | - # cela se verra mieux si il manque des objets |
|
| 329 | - # que des liens |
|
| 330 | - array_unshift($tables_for_dump, $link_table); |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - return [$tables_for_dump, $tables_for_link]; |
|
| 255 | + $tables_for_dump = []; |
|
| 256 | + $tables_pointees = []; |
|
| 257 | + $tables = []; |
|
| 258 | + $tables_principales = $GLOBALS['tables_principales']; |
|
| 259 | + $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 260 | + $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 261 | + |
|
| 262 | + if ( |
|
| 263 | + include_spip('base/objets') |
|
| 264 | + and function_exists('lister_tables_objets_sql') |
|
| 265 | + ) { |
|
| 266 | + $tables = lister_tables_objets_sql(); |
|
| 267 | + foreach ($tables as $t => $infos) { |
|
| 268 | + if ($infos['principale'] and !isset($tables_principales[$t])) { |
|
| 269 | + $tables_principales[$t] = true; |
|
| 270 | + } |
|
| 271 | + if (!$infos['principale'] and !isset($tables_auxiliaires[$t])) { |
|
| 272 | + $tables_auxiliaires[$t] = true; |
|
| 273 | + } |
|
| 274 | + if (is_countable($infos['tables_jointures']) ? count($infos['tables_jointures']) : 0) { |
|
| 275 | + $tables_jointures[$t] = array_merge( |
|
| 276 | + $tables_jointures[$t] ?? [], |
|
| 277 | + $infos['tables_jointures'] |
|
| 278 | + ); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // on construit un index des tables de liens |
|
| 284 | + // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 285 | + $tables_for_link = []; |
|
| 286 | + foreach ($tables_jointures as $table => $liste_relations) { |
|
| 287 | + if (is_array($liste_relations)) { |
|
| 288 | + $nom = $table; |
|
| 289 | + if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 290 | + $nom = "spip_$table"; |
|
| 291 | + } |
|
| 292 | + if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 293 | + foreach ($liste_relations as $link_table) { |
|
| 294 | + if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 295 | + $tables_for_link[$link_table][] = $nom; |
|
| 296 | + } else { |
|
| 297 | + if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 298 | + $tables_for_link["spip_$link_table"][] = $nom; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + $liste_tables = [...array_keys($tables_principales), ...array_keys($tables_auxiliaires), ...array_keys($tables)]; |
|
| 307 | + foreach ($liste_tables as $table) { |
|
| 308 | + // $name = preg_replace("{^spip_}","",$table); |
|
| 309 | + if ( |
|
| 310 | + !isset($tables_pointees[$table]) |
|
| 311 | + && !in_array($table, $exclude_tables) |
|
| 312 | + && !isset($tables_for_link[$table]) |
|
| 313 | + ) { |
|
| 314 | + $tables_for_dump[] = $table; |
|
| 315 | + $tables_pointees[$table] = 1; |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + foreach ($tables_for_link as $link_table => $liste) { |
|
| 319 | + $connecte = true; |
|
| 320 | + foreach ($liste as $connect_table) { |
|
| 321 | + if (!in_array($connect_table, $tables_for_dump)) { |
|
| 322 | + $connecte = false; |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + if ($connecte) { |
|
| 326 | + # on ajoute les liaisons en premier |
|
| 327 | + # si une restauration est interrompue, |
|
| 328 | + # cela se verra mieux si il manque des objets |
|
| 329 | + # que des liens |
|
| 330 | + array_unshift($tables_for_dump, $link_table); |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + return [$tables_for_dump, $tables_for_link]; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -346,37 +346,37 @@ discard block |
||
| 346 | 346 | * @param string $serveur |
| 347 | 347 | */ |
| 348 | 348 | function base_vider_tables_destination_copie($tables, $exclure_tables = [], $serveur = '') { |
| 349 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 350 | - |
|
| 351 | - spip_log( |
|
| 352 | - 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables), |
|
| 353 | - 'base.' . _LOG_INFO_IMPORTANTE |
|
| 354 | - ); |
|
| 355 | - foreach ($tables as $table) { |
|
| 356 | - if (!in_array($table, $exclure_tables)) { |
|
| 357 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 358 | - if (($table != 'spip_auteurs') or $serveur != '') { |
|
| 359 | - // regarder si il y a au moins un champ impt='non' |
|
| 360 | - $desc = $trouver_table($table, $serveur); |
|
| 361 | - if (isset($desc['field']['impt'])) { |
|
| 362 | - sql_delete($table, "impt='oui'", $serveur); |
|
| 363 | - } elseif ($desc) { |
|
| 364 | - sql_delete($table, '', $serveur); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 371 | - // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 372 | - if ( |
|
| 373 | - $serveur == '' |
|
| 374 | - and in_array('spip_auteurs', $tables) |
|
| 375 | - and !in_array('spip_auteurs', $exclure_tables) |
|
| 376 | - ) { |
|
| 377 | - base_conserver_copieur(true, $serveur); |
|
| 378 | - sql_delete('spip_auteurs', 'id_auteur>0', $serveur); |
|
| 379 | - } |
|
| 349 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 350 | + |
|
| 351 | + spip_log( |
|
| 352 | + 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables), |
|
| 353 | + 'base.' . _LOG_INFO_IMPORTANTE |
|
| 354 | + ); |
|
| 355 | + foreach ($tables as $table) { |
|
| 356 | + if (!in_array($table, $exclure_tables)) { |
|
| 357 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 358 | + if (($table != 'spip_auteurs') or $serveur != '') { |
|
| 359 | + // regarder si il y a au moins un champ impt='non' |
|
| 360 | + $desc = $trouver_table($table, $serveur); |
|
| 361 | + if (isset($desc['field']['impt'])) { |
|
| 362 | + sql_delete($table, "impt='oui'", $serveur); |
|
| 363 | + } elseif ($desc) { |
|
| 364 | + sql_delete($table, '', $serveur); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 371 | + // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 372 | + if ( |
|
| 373 | + $serveur == '' |
|
| 374 | + and in_array('spip_auteurs', $tables) |
|
| 375 | + and !in_array('spip_auteurs', $exclure_tables) |
|
| 376 | + ) { |
|
| 377 | + base_conserver_copieur(true, $serveur); |
|
| 378 | + sql_delete('spip_auteurs', 'id_auteur>0', $serveur); |
|
| 379 | + } |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | /** |
@@ -387,36 +387,36 @@ discard block |
||
| 387 | 387 | * @return void |
| 388 | 388 | */ |
| 389 | 389 | function base_conserver_copieur($move = true, $serveur = '') { |
| 390 | - // s'asurer qu'on a pas deja fait la manip ! |
|
| 391 | - if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 392 | - spip_log( |
|
| 393 | - 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 394 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 395 | - ); |
|
| 396 | - sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 397 | - if ($move) { |
|
| 398 | - sql_updateq( |
|
| 399 | - 'spip_auteurs', |
|
| 400 | - ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
|
| 401 | - 'id_auteur=' . intval($GLOBALS['visiteur_session']['id_auteur']), |
|
| 402 | - [], |
|
| 403 | - $serveur |
|
| 404 | - ); |
|
| 405 | - } else { |
|
| 406 | - $row = sql_fetsel( |
|
| 407 | - '*', |
|
| 408 | - 'spip_auteurs', |
|
| 409 | - 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 410 | - '', |
|
| 411 | - '', |
|
| 412 | - '', |
|
| 413 | - '', |
|
| 414 | - $serveur |
|
| 415 | - ); |
|
| 416 | - $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 417 | - sql_insertq('spip_auteurs', $row, [], $serveur); |
|
| 418 | - } |
|
| 419 | - } |
|
| 390 | + // s'asurer qu'on a pas deja fait la manip ! |
|
| 391 | + if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 392 | + spip_log( |
|
| 393 | + 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 394 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 395 | + ); |
|
| 396 | + sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 397 | + if ($move) { |
|
| 398 | + sql_updateq( |
|
| 399 | + 'spip_auteurs', |
|
| 400 | + ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
|
| 401 | + 'id_auteur=' . intval($GLOBALS['visiteur_session']['id_auteur']), |
|
| 402 | + [], |
|
| 403 | + $serveur |
|
| 404 | + ); |
|
| 405 | + } else { |
|
| 406 | + $row = sql_fetsel( |
|
| 407 | + '*', |
|
| 408 | + 'spip_auteurs', |
|
| 409 | + 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 410 | + '', |
|
| 411 | + '', |
|
| 412 | + '', |
|
| 413 | + '', |
|
| 414 | + $serveur |
|
| 415 | + ); |
|
| 416 | + $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 417 | + sql_insertq('spip_auteurs', $row, [], $serveur); |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -431,21 +431,21 @@ discard block |
||
| 431 | 431 | * @param string $serveur |
| 432 | 432 | */ |
| 433 | 433 | function base_detruire_copieur_si_besoin($serveur = '') { |
| 434 | - // rien a faire si ce n'est pas le serveur principal ! |
|
| 435 | - if ($serveur == '') { |
|
| 436 | - if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 437 | - spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 438 | - sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 439 | - } else { |
|
| 440 | - spip_log( |
|
| 441 | - "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 442 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 443 | - ); |
|
| 444 | - sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
|
| 445 | - } |
|
| 446 | - } else { |
|
| 447 | - spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 448 | - } |
|
| 434 | + // rien a faire si ce n'est pas le serveur principal ! |
|
| 435 | + if ($serveur == '') { |
|
| 436 | + if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 437 | + spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 438 | + sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 439 | + } else { |
|
| 440 | + spip_log( |
|
| 441 | + "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 442 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 443 | + ); |
|
| 444 | + sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
|
| 445 | + } |
|
| 446 | + } else { |
|
| 447 | + spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 448 | + } |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -460,40 +460,40 @@ discard block |
||
| 460 | 460 | * @return array |
| 461 | 461 | */ |
| 462 | 462 | function base_preparer_table_dest($table, $desc, $serveur_dest, $init = false) { |
| 463 | - $upgrade = false; |
|
| 464 | - // si la table existe et qu'on est a l'init, la dropper |
|
| 465 | - if ($desc_dest = sql_showtable($table, true, $serveur_dest) and $init) { |
|
| 466 | - if ($serveur_dest == '' and in_array($table, ['spip_meta', 'spip_auteurs'])) { |
|
| 467 | - // ne pas dropper auteurs et meta sur le serveur principal |
|
| 468 | - // faire un simple upgrade a la place |
|
| 469 | - // pour ajouter les champs manquants |
|
| 470 | - $upgrade = true; |
|
| 471 | - // coherence avec le drop sur les autres tables |
|
| 472 | - base_vider_tables_destination_copie([$table], [], $serveur_dest); |
|
| 473 | - if ($table == 'spip_meta') { |
|
| 474 | - // virer les version base qui vont venir avec l'import |
|
| 475 | - sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 476 | - // hum casse la base si pas version_installee a l'import ... |
|
| 477 | - sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 478 | - } |
|
| 479 | - } else { |
|
| 480 | - sql_drop_table($table, '', $serveur_dest); |
|
| 481 | - spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 482 | - } |
|
| 483 | - $desc_dest = false; |
|
| 484 | - } |
|
| 485 | - // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 486 | - if (!$desc_dest) { |
|
| 487 | - spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 488 | - include_spip('base/create'); |
|
| 489 | - creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 490 | - $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 491 | - } |
|
| 492 | - if (!$desc_dest) { |
|
| 493 | - spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return $desc_dest; |
|
| 463 | + $upgrade = false; |
|
| 464 | + // si la table existe et qu'on est a l'init, la dropper |
|
| 465 | + if ($desc_dest = sql_showtable($table, true, $serveur_dest) and $init) { |
|
| 466 | + if ($serveur_dest == '' and in_array($table, ['spip_meta', 'spip_auteurs'])) { |
|
| 467 | + // ne pas dropper auteurs et meta sur le serveur principal |
|
| 468 | + // faire un simple upgrade a la place |
|
| 469 | + // pour ajouter les champs manquants |
|
| 470 | + $upgrade = true; |
|
| 471 | + // coherence avec le drop sur les autres tables |
|
| 472 | + base_vider_tables_destination_copie([$table], [], $serveur_dest); |
|
| 473 | + if ($table == 'spip_meta') { |
|
| 474 | + // virer les version base qui vont venir avec l'import |
|
| 475 | + sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 476 | + // hum casse la base si pas version_installee a l'import ... |
|
| 477 | + sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 478 | + } |
|
| 479 | + } else { |
|
| 480 | + sql_drop_table($table, '', $serveur_dest); |
|
| 481 | + spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 482 | + } |
|
| 483 | + $desc_dest = false; |
|
| 484 | + } |
|
| 485 | + // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 486 | + if (!$desc_dest) { |
|
| 487 | + spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 488 | + include_spip('base/create'); |
|
| 489 | + creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 490 | + $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 491 | + } |
|
| 492 | + if (!$desc_dest) { |
|
| 493 | + spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return $desc_dest; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | /** |
@@ -539,211 +539,211 @@ discard block |
||
| 539 | 539 | */ |
| 540 | 540 | function base_copier_tables($status_file, $tables, $serveur_source, $serveur_dest, $options = []) { |
| 541 | 541 | |
| 542 | - $status = []; |
|
| 543 | - $callback_progression = $options['callback_progression'] ?? ''; |
|
| 544 | - $max_time = $options['max_time'] ?? 0; |
|
| 545 | - $drop_source = $options['drop_source'] ?? false; |
|
| 546 | - $no_erase_dest = $options['no_erase_dest'] ?? []; |
|
| 547 | - $where = $options['where'] ?? []; |
|
| 548 | - $fonction_base_inserer = $options['fonction_base_inserer'] ?? 'inserer_copie'; |
|
| 549 | - $desc_tables_dest = $options['desc_tables_dest'] ?? []; |
|
| 550 | - $racine_fonctions = $options['racine_fonctions_dest'] ?? 'base'; |
|
| 551 | - $data_pool = $options['data_pool'] ?? 50 * 1024; |
|
| 552 | - |
|
| 553 | - spip_log( |
|
| 554 | - 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 555 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 556 | - ); |
|
| 557 | - |
|
| 558 | - if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 559 | - spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 560 | - |
|
| 561 | - return true; // echec mais on a fini, donc true |
|
| 562 | - } |
|
| 563 | - if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 564 | - spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 565 | - |
|
| 566 | - return true; // echec mais on a fini, donc true |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - if ( |
|
| 570 | - !lire_fichier($status_file, $status) |
|
| 571 | - or !$status = unserialize($status) |
|
| 572 | - ) { |
|
| 573 | - $status = []; |
|
| 574 | - } |
|
| 575 | - $status['etape'] = 'basecopie'; |
|
| 576 | - |
|
| 577 | - // puis relister les tables a importer |
|
| 578 | - // et les vider si besoin, au moment du premier passage ici |
|
| 579 | - $initialisation_copie = (!isset($status['dump_status_copie'])) ? 0 : $status['dump_status_copie']; |
|
| 580 | - |
|
| 581 | - // si init pas encore faite, vider les tables du serveur destination |
|
| 582 | - if (!$initialisation_copie) { |
|
| 583 | - if ( |
|
| 584 | - !$vider_tables_destination_copie = charger_fonction( |
|
| 585 | - 'vider_tables_destination_copie', |
|
| 586 | - $racine_fonctions, |
|
| 587 | - true |
|
| 588 | - ) |
|
| 589 | - ) { |
|
| 590 | - spip_log( |
|
| 591 | - "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 592 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 593 | - ); |
|
| 594 | - |
|
| 595 | - return true; // echec mais on a fini, donc true |
|
| 596 | - } |
|
| 597 | - $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 598 | - $status['dump_status_copie'] = 'ok'; |
|
| 599 | - ecrire_fichier($status_file, serialize($status)); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 603 | - if (in_array('spip_auteurs', $tables)) { |
|
| 604 | - $tables = array_diff($tables, ['spip_auteurs']); |
|
| 605 | - $tables[] = 'spip_auteurs'; |
|
| 606 | - } |
|
| 607 | - if (in_array('spip_meta', $tables)) { |
|
| 608 | - $tables = array_diff($tables, ['spip_meta']); |
|
| 609 | - $tables[] = 'spip_meta'; |
|
| 610 | - } |
|
| 611 | - spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 612 | - |
|
| 613 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 614 | - |
|
| 615 | - foreach ($tables as $table) { |
|
| 616 | - // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 617 | - // sinon chercher la vraie table |
|
| 618 | - $desc_source = false; |
|
| 619 | - if (strncmp($table, 'spip_', 5) == 0) { |
|
| 620 | - $desc_source = $trouver_table(preg_replace(',^spip_,', '', $table), $serveur_source, true); |
|
| 621 | - } |
|
| 622 | - if (!$desc_source or !isset($desc_source['exist']) or !$desc_source['exist']) { |
|
| 623 | - $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - // verifier que la table est presente dans la base source |
|
| 627 | - if ($desc_source) { |
|
| 628 | - // $status['tables_copiees'][$table] contient l'avancement |
|
| 629 | - // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 630 | - if (!isset($status['tables_copiees'][$table])) { |
|
| 631 | - $status['tables_copiees'][$table] = 0; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - if ( |
|
| 635 | - is_numeric($status['tables_copiees'][$table]) |
|
| 636 | - and $status['tables_copiees'][$table] >= 0 |
|
| 637 | - and $desc_dest = $preparer_table_dest( |
|
| 638 | - $table, |
|
| 639 | - $desc_tables_dest[$table] ?? $desc_source, |
|
| 640 | - $serveur_dest, |
|
| 641 | - $status['tables_copiees'][$table] == 0 |
|
| 642 | - ) |
|
| 643 | - ) { |
|
| 644 | - if ($callback_progression) { |
|
| 645 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 646 | - } |
|
| 647 | - while (true) { |
|
| 648 | - $n = intval($status['tables_copiees'][$table]); |
|
| 649 | - // on copie par lot de 400 |
|
| 650 | - $res = sql_select( |
|
| 651 | - '*', |
|
| 652 | - $table, |
|
| 653 | - $where[$table] ?? '', |
|
| 654 | - '', |
|
| 655 | - '', |
|
| 656 | - "$n,400", |
|
| 657 | - '', |
|
| 658 | - $serveur_source |
|
| 659 | - ); |
|
| 660 | - while ($row = sql_fetch($res, $serveur_source)) { |
|
| 661 | - $rows = [$row]; |
|
| 662 | - // lire un groupe de donnees si demande en option |
|
| 663 | - // (permet un envoi par lot vers la destination) |
|
| 664 | - if ($data_pool > 0) { |
|
| 665 | - $s = strlen(serialize($row)); |
|
| 666 | - while ($s < $data_pool and $row = sql_fetch($res, $serveur_source)) { |
|
| 667 | - $s += strlen(serialize($row)); |
|
| 668 | - $rows[] = $row; |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 672 | - // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 673 | - if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 674 | - // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 675 | - spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 676 | - $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 677 | - ecrire_fichier($status_file, serialize($status)); |
|
| 678 | - |
|
| 679 | - // copie finie |
|
| 680 | - return true; |
|
| 681 | - } |
|
| 682 | - $status['tables_copiees'][$table] += count($rows); |
|
| 683 | - if ($max_time and time() > $max_time) { |
|
| 684 | - break; |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - if ($n == $status['tables_copiees'][$table]) { |
|
| 688 | - break; |
|
| 689 | - } |
|
| 690 | - spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 691 | - if ($callback_progression) { |
|
| 692 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 693 | - } |
|
| 694 | - ecrire_fichier($status_file, serialize($status)); |
|
| 695 | - if ($max_time and time() > $max_time) { |
|
| 696 | - return false; |
|
| 697 | - } // on a pas fini, mais le temps imparti est ecoule |
|
| 698 | - } |
|
| 699 | - if ($drop_source) { |
|
| 700 | - sql_drop_table($table, '', $serveur_source); |
|
| 701 | - spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 702 | - } |
|
| 703 | - $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
|
| 704 | - ecrire_fichier($status_file, serialize($status)); |
|
| 705 | - spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 706 | - if ($callback_progression) { |
|
| 707 | - $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 708 | - } |
|
| 709 | - } else { |
|
| 710 | - if ($status['tables_copiees'][$table] < 0) { |
|
| 711 | - spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 712 | - } |
|
| 713 | - if ($callback_progression) { |
|
| 714 | - $callback_progression( |
|
| 715 | - 0, |
|
| 716 | - $status['tables_copiees'][$table], |
|
| 717 | - "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 718 | - ); |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - } else { |
|
| 722 | - $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 723 | - ecrire_fichier($status_file, serialize($status)); |
|
| 724 | - spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 729 | - // abandonner |
|
| 730 | - if ((is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) < count($tables)) { |
|
| 731 | - spip_log( |
|
| 732 | - 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables), |
|
| 733 | - 'dump.' . _LOG_ERREUR |
|
| 734 | - ); |
|
| 735 | - $status['errors'][] = 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables); |
|
| 736 | - ecrire_fichier($status_file, serialize($status)); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 740 | - $detruire_copieur_si_besoin($serveur_dest); |
|
| 741 | - } else { |
|
| 742 | - spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - // OK, copie complete |
|
| 746 | - return true; |
|
| 542 | + $status = []; |
|
| 543 | + $callback_progression = $options['callback_progression'] ?? ''; |
|
| 544 | + $max_time = $options['max_time'] ?? 0; |
|
| 545 | + $drop_source = $options['drop_source'] ?? false; |
|
| 546 | + $no_erase_dest = $options['no_erase_dest'] ?? []; |
|
| 547 | + $where = $options['where'] ?? []; |
|
| 548 | + $fonction_base_inserer = $options['fonction_base_inserer'] ?? 'inserer_copie'; |
|
| 549 | + $desc_tables_dest = $options['desc_tables_dest'] ?? []; |
|
| 550 | + $racine_fonctions = $options['racine_fonctions_dest'] ?? 'base'; |
|
| 551 | + $data_pool = $options['data_pool'] ?? 50 * 1024; |
|
| 552 | + |
|
| 553 | + spip_log( |
|
| 554 | + 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 555 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 556 | + ); |
|
| 557 | + |
|
| 558 | + if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 559 | + spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 560 | + |
|
| 561 | + return true; // echec mais on a fini, donc true |
|
| 562 | + } |
|
| 563 | + if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 564 | + spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 565 | + |
|
| 566 | + return true; // echec mais on a fini, donc true |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + if ( |
|
| 570 | + !lire_fichier($status_file, $status) |
|
| 571 | + or !$status = unserialize($status) |
|
| 572 | + ) { |
|
| 573 | + $status = []; |
|
| 574 | + } |
|
| 575 | + $status['etape'] = 'basecopie'; |
|
| 576 | + |
|
| 577 | + // puis relister les tables a importer |
|
| 578 | + // et les vider si besoin, au moment du premier passage ici |
|
| 579 | + $initialisation_copie = (!isset($status['dump_status_copie'])) ? 0 : $status['dump_status_copie']; |
|
| 580 | + |
|
| 581 | + // si init pas encore faite, vider les tables du serveur destination |
|
| 582 | + if (!$initialisation_copie) { |
|
| 583 | + if ( |
|
| 584 | + !$vider_tables_destination_copie = charger_fonction( |
|
| 585 | + 'vider_tables_destination_copie', |
|
| 586 | + $racine_fonctions, |
|
| 587 | + true |
|
| 588 | + ) |
|
| 589 | + ) { |
|
| 590 | + spip_log( |
|
| 591 | + "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 592 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 593 | + ); |
|
| 594 | + |
|
| 595 | + return true; // echec mais on a fini, donc true |
|
| 596 | + } |
|
| 597 | + $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 598 | + $status['dump_status_copie'] = 'ok'; |
|
| 599 | + ecrire_fichier($status_file, serialize($status)); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 603 | + if (in_array('spip_auteurs', $tables)) { |
|
| 604 | + $tables = array_diff($tables, ['spip_auteurs']); |
|
| 605 | + $tables[] = 'spip_auteurs'; |
|
| 606 | + } |
|
| 607 | + if (in_array('spip_meta', $tables)) { |
|
| 608 | + $tables = array_diff($tables, ['spip_meta']); |
|
| 609 | + $tables[] = 'spip_meta'; |
|
| 610 | + } |
|
| 611 | + spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 612 | + |
|
| 613 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 614 | + |
|
| 615 | + foreach ($tables as $table) { |
|
| 616 | + // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 617 | + // sinon chercher la vraie table |
|
| 618 | + $desc_source = false; |
|
| 619 | + if (strncmp($table, 'spip_', 5) == 0) { |
|
| 620 | + $desc_source = $trouver_table(preg_replace(',^spip_,', '', $table), $serveur_source, true); |
|
| 621 | + } |
|
| 622 | + if (!$desc_source or !isset($desc_source['exist']) or !$desc_source['exist']) { |
|
| 623 | + $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + // verifier que la table est presente dans la base source |
|
| 627 | + if ($desc_source) { |
|
| 628 | + // $status['tables_copiees'][$table] contient l'avancement |
|
| 629 | + // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 630 | + if (!isset($status['tables_copiees'][$table])) { |
|
| 631 | + $status['tables_copiees'][$table] = 0; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + if ( |
|
| 635 | + is_numeric($status['tables_copiees'][$table]) |
|
| 636 | + and $status['tables_copiees'][$table] >= 0 |
|
| 637 | + and $desc_dest = $preparer_table_dest( |
|
| 638 | + $table, |
|
| 639 | + $desc_tables_dest[$table] ?? $desc_source, |
|
| 640 | + $serveur_dest, |
|
| 641 | + $status['tables_copiees'][$table] == 0 |
|
| 642 | + ) |
|
| 643 | + ) { |
|
| 644 | + if ($callback_progression) { |
|
| 645 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 646 | + } |
|
| 647 | + while (true) { |
|
| 648 | + $n = intval($status['tables_copiees'][$table]); |
|
| 649 | + // on copie par lot de 400 |
|
| 650 | + $res = sql_select( |
|
| 651 | + '*', |
|
| 652 | + $table, |
|
| 653 | + $where[$table] ?? '', |
|
| 654 | + '', |
|
| 655 | + '', |
|
| 656 | + "$n,400", |
|
| 657 | + '', |
|
| 658 | + $serveur_source |
|
| 659 | + ); |
|
| 660 | + while ($row = sql_fetch($res, $serveur_source)) { |
|
| 661 | + $rows = [$row]; |
|
| 662 | + // lire un groupe de donnees si demande en option |
|
| 663 | + // (permet un envoi par lot vers la destination) |
|
| 664 | + if ($data_pool > 0) { |
|
| 665 | + $s = strlen(serialize($row)); |
|
| 666 | + while ($s < $data_pool and $row = sql_fetch($res, $serveur_source)) { |
|
| 667 | + $s += strlen(serialize($row)); |
|
| 668 | + $rows[] = $row; |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 672 | + // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 673 | + if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 674 | + // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 675 | + spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 676 | + $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 677 | + ecrire_fichier($status_file, serialize($status)); |
|
| 678 | + |
|
| 679 | + // copie finie |
|
| 680 | + return true; |
|
| 681 | + } |
|
| 682 | + $status['tables_copiees'][$table] += count($rows); |
|
| 683 | + if ($max_time and time() > $max_time) { |
|
| 684 | + break; |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + if ($n == $status['tables_copiees'][$table]) { |
|
| 688 | + break; |
|
| 689 | + } |
|
| 690 | + spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 691 | + if ($callback_progression) { |
|
| 692 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 693 | + } |
|
| 694 | + ecrire_fichier($status_file, serialize($status)); |
|
| 695 | + if ($max_time and time() > $max_time) { |
|
| 696 | + return false; |
|
| 697 | + } // on a pas fini, mais le temps imparti est ecoule |
|
| 698 | + } |
|
| 699 | + if ($drop_source) { |
|
| 700 | + sql_drop_table($table, '', $serveur_source); |
|
| 701 | + spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 702 | + } |
|
| 703 | + $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
|
| 704 | + ecrire_fichier($status_file, serialize($status)); |
|
| 705 | + spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 706 | + if ($callback_progression) { |
|
| 707 | + $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 708 | + } |
|
| 709 | + } else { |
|
| 710 | + if ($status['tables_copiees'][$table] < 0) { |
|
| 711 | + spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 712 | + } |
|
| 713 | + if ($callback_progression) { |
|
| 714 | + $callback_progression( |
|
| 715 | + 0, |
|
| 716 | + $status['tables_copiees'][$table], |
|
| 717 | + "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 718 | + ); |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + } else { |
|
| 722 | + $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 723 | + ecrire_fichier($status_file, serialize($status)); |
|
| 724 | + spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 729 | + // abandonner |
|
| 730 | + if ((is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) < count($tables)) { |
|
| 731 | + spip_log( |
|
| 732 | + 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables), |
|
| 733 | + 'dump.' . _LOG_ERREUR |
|
| 734 | + ); |
|
| 735 | + $status['errors'][] = 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables); |
|
| 736 | + ecrire_fichier($status_file, serialize($status)); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 740 | + $detruire_copieur_si_besoin($serveur_dest); |
|
| 741 | + } else { |
|
| 742 | + spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + // OK, copie complete |
|
| 746 | + return true; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
@@ -757,31 +757,31 @@ discard block |
||
| 757 | 757 | */ |
| 758 | 758 | function base_inserer_copie($table, $rows, $desc_dest, $serveur_dest) { |
| 759 | 759 | |
| 760 | - // verifier le nombre d'insertion |
|
| 761 | - $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 762 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 763 | - $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 764 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 765 | - if ($nb - $nb1 < count($rows)) { |
|
| 766 | - spip_log( |
|
| 767 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 768 | - 'dump' . _LOG_INFO_IMPORTANTE |
|
| 769 | - ); |
|
| 770 | - foreach ($rows as $row) { |
|
| 771 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 772 | - $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 773 | - } |
|
| 774 | - // on reverifie le total |
|
| 775 | - $r = 0; |
|
| 776 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 777 | - if ($nb - $nb1 < count($rows)) { |
|
| 778 | - spip_log( |
|
| 779 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 780 | - 'dump' . _LOG_ERREUR |
|
| 781 | - ); |
|
| 782 | - $r = false; |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - return $r; |
|
| 760 | + // verifier le nombre d'insertion |
|
| 761 | + $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 762 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 763 | + $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 764 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 765 | + if ($nb - $nb1 < count($rows)) { |
|
| 766 | + spip_log( |
|
| 767 | + 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 768 | + 'dump' . _LOG_INFO_IMPORTANTE |
|
| 769 | + ); |
|
| 770 | + foreach ($rows as $row) { |
|
| 771 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 772 | + $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 773 | + } |
|
| 774 | + // on reverifie le total |
|
| 775 | + $r = 0; |
|
| 776 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 777 | + if ($nb - $nb1 < count($rows)) { |
|
| 778 | + spip_log( |
|
| 779 | + 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 780 | + 'dump' . _LOG_ERREUR |
|
| 781 | + ); |
|
| 782 | + $r = false; |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + return $r; |
|
| 787 | 787 | } |
@@ -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 | /** |
@@ -32,35 +32,35 @@ discard block |
||
| 32 | 32 | * @return int |
| 33 | 33 | */ |
| 34 | 34 | function genie_mail_dist($t) { |
| 35 | - $adresse_neuf = $GLOBALS['meta']['adresse_neuf']; |
|
| 36 | - $jours_neuf = $GLOBALS['meta']['jours_neuf']; |
|
| 35 | + $adresse_neuf = $GLOBALS['meta']['adresse_neuf']; |
|
| 36 | + $jours_neuf = $GLOBALS['meta']['jours_neuf']; |
|
| 37 | 37 | |
| 38 | - $now = time(); |
|
| 39 | - if (!isset($GLOBALS['meta']['dernier_envoi_neuf'])) { |
|
| 40 | - ecrire_meta('dernier_envoi_neuf', date('Y-m-d H:i:s', $now - (3600 * 24 * $jours_neuf))); |
|
| 41 | - } |
|
| 38 | + $now = time(); |
|
| 39 | + if (!isset($GLOBALS['meta']['dernier_envoi_neuf'])) { |
|
| 40 | + ecrire_meta('dernier_envoi_neuf', date('Y-m-d H:i:s', $now - (3600 * 24 * $jours_neuf))); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $page = recuperer_fond( |
|
| 44 | - 'nouveautes', |
|
| 45 | - ['date' => $GLOBALS['meta']['dernier_envoi_neuf'], 'jours_neuf' => $jours_neuf], |
|
| 46 | - ['raw' => true] |
|
| 47 | - ); |
|
| 43 | + $page = recuperer_fond( |
|
| 44 | + 'nouveautes', |
|
| 45 | + ['date' => $GLOBALS['meta']['dernier_envoi_neuf'], 'jours_neuf' => $jours_neuf], |
|
| 46 | + ['raw' => true] |
|
| 47 | + ); |
|
| 48 | 48 | |
| 49 | - if (strlen(trim($page['texte']))) { |
|
| 50 | - // recuperer les entetes envoyes par #HTTP_HEADER |
|
| 51 | - $headers = ''; |
|
| 52 | - if (isset($page['entetes']) and is_countable($page['entetes']) ? count($page['entetes']) : 0) { |
|
| 53 | - foreach ($page['entetes'] as $k => $v) { |
|
| 54 | - $headers .= (strlen($v) ? "$k: $v" : $k) . "\n"; |
|
| 55 | - } |
|
| 56 | - } |
|
| 49 | + if (strlen(trim($page['texte']))) { |
|
| 50 | + // recuperer les entetes envoyes par #HTTP_HEADER |
|
| 51 | + $headers = ''; |
|
| 52 | + if (isset($page['entetes']) and is_countable($page['entetes']) ? count($page['entetes']) : 0) { |
|
| 53 | + foreach ($page['entetes'] as $k => $v) { |
|
| 54 | + $headers .= (strlen($v) ? "$k: $v" : $k) . "\n"; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - include_spip('inc/notifications'); |
|
| 59 | - notifications_envoyer_mails($adresse_neuf, $page['texte'], '', '', $headers); |
|
| 60 | - ecrire_meta('dernier_envoi_neuf', date('Y-m-d H:i:s', $now)); |
|
| 61 | - } else { |
|
| 62 | - spip_log("mail nouveautes : rien de neuf depuis $jours_neuf jours"); |
|
| 63 | - } |
|
| 58 | + include_spip('inc/notifications'); |
|
| 59 | + notifications_envoyer_mails($adresse_neuf, $page['texte'], '', '', $headers); |
|
| 60 | + ecrire_meta('dernier_envoi_neuf', date('Y-m-d H:i:s', $now)); |
|
| 61 | + } else { |
|
| 62 | + spip_log("mail nouveautes : rien de neuf depuis $jours_neuf jours"); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return 1; |
|
| 65 | + return 1; |
|
| 66 | 66 | } |
@@ -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 | include_spip('inc/editer'); |
@@ -32,17 +32,17 @@ discard block |
||
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | 34 | function lister_statuts_proposes($desc, $publiable = true) { |
| 35 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 36 | - return false; |
|
| 37 | - } |
|
| 35 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 36 | + return false; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - $l = $desc['statut_textes_instituer']; |
|
| 40 | - if (!$publiable) { |
|
| 41 | - unset($l['publie']); |
|
| 42 | - unset($l['refuse']); |
|
| 43 | - } |
|
| 39 | + $l = $desc['statut_textes_instituer']; |
|
| 40 | + if (!$publiable) { |
|
| 41 | + unset($l['publie']); |
|
| 42 | + unset($l['refuse']); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - return $l; |
|
| 45 | + return $l; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -64,54 +64,54 @@ discard block |
||
| 64 | 64 | * Environnement du formulaire ou false si aucun affichage à faire. |
| 65 | 65 | */ |
| 66 | 66 | function formulaires_instituer_objet_charger_dist($objet, $id_objet, $retour = '', $editable = true) { |
| 67 | - $editable = ($editable ? true : false); |
|
| 68 | - |
|
| 69 | - $table = table_objet_sql($objet); |
|
| 70 | - $desc = lister_tables_objets_sql($table); |
|
| 71 | - |
|
| 72 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 73 | - return false; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (!autoriser('modifier', $objet, $id_objet)) { |
|
| 77 | - $editable = false; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // charger le contenu de l'objet |
|
| 81 | - // dont son champ statut |
|
| 82 | - $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', ''); |
|
| 83 | - |
|
| 84 | - $publiable = true; |
|
| 85 | - $statuts = lister_statuts_proposes($desc); |
|
| 86 | - // tester si on a le droit de publier, si un statut publie existe |
|
| 87 | - if (isset($statuts['publie'])) { |
|
| 88 | - if (!autoriser('instituer', $objet, $id_objet, null, ['statut' => 'publie'])) { |
|
| 89 | - if ($v['statut'] == 'publie') { |
|
| 90 | - $editable = false; |
|
| 91 | - } else { |
|
| 92 | - $publiable = false; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - $statuts = lister_statuts_proposes($desc, $editable ? $publiable : true); |
|
| 97 | - if (count($statuts) == 1 and isset($statuts[$v['statut']])) { |
|
| 98 | - $editable = false; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $valeurs = [ |
|
| 102 | - 'editable' => $editable, |
|
| 103 | - 'statut' => $v['statut'], |
|
| 104 | - '_objet' => $objet, |
|
| 105 | - '_id_objet' => $id_objet, |
|
| 106 | - '_statuts' => $statuts, |
|
| 107 | - '_publiable' => $publiable, |
|
| 108 | - '_label' => $desc['texte_changer_statut'] ?? 'texte_article_statut', |
|
| 109 | - '_aide' => $desc['aide_changer_statut'] ?? '', |
|
| 110 | - '_hidden' => "<input type='hidden' name='statut_old' value='" . $v['statut'] . "' />", |
|
| 111 | - ]; |
|
| 112 | - |
|
| 113 | - #if (!count($valeurs['statuts'])) |
|
| 114 | - return $valeurs; |
|
| 67 | + $editable = ($editable ? true : false); |
|
| 68 | + |
|
| 69 | + $table = table_objet_sql($objet); |
|
| 70 | + $desc = lister_tables_objets_sql($table); |
|
| 71 | + |
|
| 72 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 73 | + return false; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (!autoriser('modifier', $objet, $id_objet)) { |
|
| 77 | + $editable = false; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // charger le contenu de l'objet |
|
| 81 | + // dont son champ statut |
|
| 82 | + $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', ''); |
|
| 83 | + |
|
| 84 | + $publiable = true; |
|
| 85 | + $statuts = lister_statuts_proposes($desc); |
|
| 86 | + // tester si on a le droit de publier, si un statut publie existe |
|
| 87 | + if (isset($statuts['publie'])) { |
|
| 88 | + if (!autoriser('instituer', $objet, $id_objet, null, ['statut' => 'publie'])) { |
|
| 89 | + if ($v['statut'] == 'publie') { |
|
| 90 | + $editable = false; |
|
| 91 | + } else { |
|
| 92 | + $publiable = false; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + $statuts = lister_statuts_proposes($desc, $editable ? $publiable : true); |
|
| 97 | + if (count($statuts) == 1 and isset($statuts[$v['statut']])) { |
|
| 98 | + $editable = false; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $valeurs = [ |
|
| 102 | + 'editable' => $editable, |
|
| 103 | + 'statut' => $v['statut'], |
|
| 104 | + '_objet' => $objet, |
|
| 105 | + '_id_objet' => $id_objet, |
|
| 106 | + '_statuts' => $statuts, |
|
| 107 | + '_publiable' => $publiable, |
|
| 108 | + '_label' => $desc['texte_changer_statut'] ?? 'texte_article_statut', |
|
| 109 | + '_aide' => $desc['aide_changer_statut'] ?? '', |
|
| 110 | + '_hidden' => "<input type='hidden' name='statut_old' value='" . $v['statut'] . "' />", |
|
| 111 | + ]; |
|
| 112 | + |
|
| 113 | + #if (!count($valeurs['statuts'])) |
|
| 114 | + return $valeurs; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -131,35 +131,35 @@ discard block |
||
| 131 | 131 | * Tableau des erreurs |
| 132 | 132 | */ |
| 133 | 133 | function formulaires_instituer_objet_verifier_dist($objet, $id_objet, $retour = '', $editable = true) { |
| 134 | - $erreurs = []; |
|
| 135 | - // charger le contenu de l'objet |
|
| 136 | - // dont son champ statut |
|
| 137 | - $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', ''); |
|
| 138 | - |
|
| 139 | - if ($v['statut'] !== _request('statut_old')) { |
|
| 140 | - $erreurs['statut'] = _T('instituer_erreur_statut_a_change'); |
|
| 141 | - } else { |
|
| 142 | - $table = table_objet_sql($objet); |
|
| 143 | - $desc = lister_tables_objets_sql($table); |
|
| 144 | - |
|
| 145 | - $publiable = true; |
|
| 146 | - if ( |
|
| 147 | - isset($v['id_rubrique']) |
|
| 148 | - and !autoriser('publierdans', 'rubrique', $v['id_rubrique']) |
|
| 149 | - ) { |
|
| 150 | - $publiable = false; |
|
| 151 | - } |
|
| 152 | - $l = lister_statuts_proposes($desc, $publiable); |
|
| 153 | - $statut = _request('statut'); |
|
| 154 | - if ( |
|
| 155 | - !isset($l[$statut]) |
|
| 156 | - or !autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 157 | - ) { |
|
| 158 | - $erreurs['statut'] = _T('instituer_erreur_statut_non_autorise'); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - return $erreurs; |
|
| 134 | + $erreurs = []; |
|
| 135 | + // charger le contenu de l'objet |
|
| 136 | + // dont son champ statut |
|
| 137 | + $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', ''); |
|
| 138 | + |
|
| 139 | + if ($v['statut'] !== _request('statut_old')) { |
|
| 140 | + $erreurs['statut'] = _T('instituer_erreur_statut_a_change'); |
|
| 141 | + } else { |
|
| 142 | + $table = table_objet_sql($objet); |
|
| 143 | + $desc = lister_tables_objets_sql($table); |
|
| 144 | + |
|
| 145 | + $publiable = true; |
|
| 146 | + if ( |
|
| 147 | + isset($v['id_rubrique']) |
|
| 148 | + and !autoriser('publierdans', 'rubrique', $v['id_rubrique']) |
|
| 149 | + ) { |
|
| 150 | + $publiable = false; |
|
| 151 | + } |
|
| 152 | + $l = lister_statuts_proposes($desc, $publiable); |
|
| 153 | + $statut = _request('statut'); |
|
| 154 | + if ( |
|
| 155 | + !isset($l[$statut]) |
|
| 156 | + or !autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 157 | + ) { |
|
| 158 | + $erreurs['statut'] = _T('instituer_erreur_statut_non_autorise'); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return $erreurs; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -178,25 +178,25 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | function formulaires_instituer_objet_traiter_dist($objet, $id_objet, $retour = '', $editable = true) { |
| 180 | 180 | |
| 181 | - $c = ['statut' => _request('statut')]; |
|
| 182 | - // si on a envoye une 'date_posterieure', l'enregistrer |
|
| 183 | - // todo dans le HTML |
|
| 184 | - if ($d = _request('date_posterieure')) { |
|
| 185 | - $c['date'] = $d; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - include_spip('action/editer_objet'); |
|
| 190 | - if ($err = objet_instituer($objet, $id_objet, $c)) { |
|
| 191 | - $res = ['message_erreur' => $err]; |
|
| 192 | - } else { |
|
| 193 | - $res = ['message_ok' => _T('info_modification_enregistree')]; |
|
| 194 | - if ($retour) { |
|
| 195 | - $res['redirect'] = $retour; |
|
| 196 | - } |
|
| 197 | - set_request('statut'); |
|
| 198 | - set_request('date_posterieure'); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $res; |
|
| 181 | + $c = ['statut' => _request('statut')]; |
|
| 182 | + // si on a envoye une 'date_posterieure', l'enregistrer |
|
| 183 | + // todo dans le HTML |
|
| 184 | + if ($d = _request('date_posterieure')) { |
|
| 185 | + $c['date'] = $d; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + include_spip('action/editer_objet'); |
|
| 190 | + if ($err = objet_instituer($objet, $id_objet, $c)) { |
|
| 191 | + $res = ['message_erreur' => $err]; |
|
| 192 | + } else { |
|
| 193 | + $res = ['message_ok' => _T('info_modification_enregistree')]; |
|
| 194 | + if ($retour) { |
|
| 195 | + $res['redirect'] = $retour; |
|
| 196 | + } |
|
| 197 | + set_request('statut'); |
|
| 198 | + set_request('date_posterieure'); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $res; |
|
| 202 | 202 | } |
@@ -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 | /** |
@@ -33,19 +33,19 @@ discard block |
||
| 33 | 33 | * @return array Environnement du formulaire |
| 34 | 34 | **/ |
| 35 | 35 | function formulaires_recherche_ecrire_charger_dist($action = '', $class = '') { |
| 36 | - if ($GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 37 | - $lang = $GLOBALS['spip_lang']; |
|
| 38 | - } else { |
|
| 39 | - $lang = ''; |
|
| 40 | - } |
|
| 36 | + if ($GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 37 | + $lang = $GLOBALS['spip_lang']; |
|
| 38 | + } else { |
|
| 39 | + $lang = ''; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - return |
|
| 43 | - [ |
|
| 44 | - 'action' => ($action ?: generer_url_ecrire('recherche')), |
|
| 45 | - # action specifique, ne passe pas par Verifier, ni Traiter |
|
| 46 | - 'recherche' => _request('recherche'), |
|
| 47 | - 'lang' => $lang, |
|
| 48 | - 'class' => $class, |
|
| 49 | - '_id_champ' => 'rechercher_' . substr(md5($action . $class), 0, 4), |
|
| 50 | - ]; |
|
| 42 | + return |
|
| 43 | + [ |
|
| 44 | + 'action' => ($action ?: generer_url_ecrire('recherche')), |
|
| 45 | + # action specifique, ne passe pas par Verifier, ni Traiter |
|
| 46 | + 'recherche' => _request('recherche'), |
|
| 47 | + 'lang' => $lang, |
|
| 48 | + 'class' => $class, |
|
| 49 | + '_id_champ' => 'rechercher_' . substr(md5($action . $class), 0, 4), |
|
| 50 | + ]; |
|
| 51 | 51 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -28,24 +28,24 @@ discard block |
||
| 28 | 28 | * Environnement du formulaire |
| 29 | 29 | **/ |
| 30 | 30 | function formulaires_configurer_reducteur_charger_dist() { |
| 31 | - $valeurs = []; |
|
| 32 | - foreach ( |
|
| 33 | - [ |
|
| 34 | - 'image_process', |
|
| 35 | - 'formats_graphiques', |
|
| 36 | - 'creer_preview', |
|
| 37 | - 'taille_preview', |
|
| 38 | - ] as $m |
|
| 39 | - ) { |
|
| 40 | - $valeurs[$m] = $GLOBALS['meta'][$m] ?? null; |
|
| 41 | - } |
|
| 31 | + $valeurs = []; |
|
| 32 | + foreach ( |
|
| 33 | + [ |
|
| 34 | + 'image_process', |
|
| 35 | + 'formats_graphiques', |
|
| 36 | + 'creer_preview', |
|
| 37 | + 'taille_preview', |
|
| 38 | + ] as $m |
|
| 39 | + ) { |
|
| 40 | + $valeurs[$m] = $GLOBALS['meta'][$m] ?? null; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $valeurs['taille_preview'] = intval($valeurs['taille_preview']); |
|
| 44 | - if ($valeurs['taille_preview'] < 10) { |
|
| 45 | - $valeurs['taille_preview'] = 120; |
|
| 46 | - } |
|
| 43 | + $valeurs['taille_preview'] = intval($valeurs['taille_preview']); |
|
| 44 | + if ($valeurs['taille_preview'] < 10) { |
|
| 45 | + $valeurs['taille_preview'] = 120; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - return $valeurs; |
|
| 48 | + return $valeurs; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | |
@@ -56,53 +56,53 @@ discard block |
||
| 56 | 56 | * Retours des traitements |
| 57 | 57 | **/ |
| 58 | 58 | function formulaires_configurer_reducteur_traiter_dist() { |
| 59 | - $res = ['editable' => true]; |
|
| 59 | + $res = ['editable' => true]; |
|
| 60 | 60 | |
| 61 | - if (is_array($image_process = _request('image_process_'))) { |
|
| 62 | - $image_process = array_keys($image_process); |
|
| 63 | - $image_process = reset($image_process); |
|
| 61 | + if (is_array($image_process = _request('image_process_'))) { |
|
| 62 | + $image_process = array_keys($image_process); |
|
| 63 | + $image_process = reset($image_process); |
|
| 64 | 64 | |
| 65 | - // application du choix de vignette |
|
| 66 | - if ($image_process) { |
|
| 67 | - // mettre a jour les formats graphiques lisibles |
|
| 68 | - switch ($image_process) { |
|
| 69 | - case 'gd1': |
|
| 70 | - case 'gd2': |
|
| 71 | - $formats_graphiques = $GLOBALS['meta']['gd_formats_read']; |
|
| 72 | - break; |
|
| 73 | - case 'netpbm': |
|
| 74 | - $formats_graphiques = $GLOBALS['meta']['netpbm_formats']; |
|
| 75 | - break; |
|
| 76 | - case 'convert': |
|
| 77 | - case 'imagick': |
|
| 78 | - $formats_graphiques = 'gif,jpg,png,webp'; |
|
| 79 | - break; |
|
| 80 | - default: #debug |
|
| 81 | - $formats_graphiques = ''; |
|
| 82 | - $image_process = 'non'; |
|
| 83 | - break; |
|
| 84 | - } |
|
| 85 | - ecrire_meta('formats_graphiques', $formats_graphiques, 'non'); |
|
| 86 | - ecrire_meta('image_process', $image_process, 'non'); |
|
| 87 | - } |
|
| 88 | - } |
|
| 65 | + // application du choix de vignette |
|
| 66 | + if ($image_process) { |
|
| 67 | + // mettre a jour les formats graphiques lisibles |
|
| 68 | + switch ($image_process) { |
|
| 69 | + case 'gd1': |
|
| 70 | + case 'gd2': |
|
| 71 | + $formats_graphiques = $GLOBALS['meta']['gd_formats_read']; |
|
| 72 | + break; |
|
| 73 | + case 'netpbm': |
|
| 74 | + $formats_graphiques = $GLOBALS['meta']['netpbm_formats']; |
|
| 75 | + break; |
|
| 76 | + case 'convert': |
|
| 77 | + case 'imagick': |
|
| 78 | + $formats_graphiques = 'gif,jpg,png,webp'; |
|
| 79 | + break; |
|
| 80 | + default: #debug |
|
| 81 | + $formats_graphiques = ''; |
|
| 82 | + $image_process = 'non'; |
|
| 83 | + break; |
|
| 84 | + } |
|
| 85 | + ecrire_meta('formats_graphiques', $formats_graphiques, 'non'); |
|
| 86 | + ecrire_meta('image_process', $image_process, 'non'); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - foreach ( |
|
| 91 | - [ |
|
| 92 | - 'creer_preview' |
|
| 93 | - ] as $m |
|
| 94 | - ) { |
|
| 95 | - if (!is_null($v = _request($m))) { |
|
| 96 | - ecrire_meta($m, $v == 'oui' ? 'oui' : 'non'); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - if (!is_null($v = _request('taille_preview'))) { |
|
| 100 | - ecrire_meta('taille_preview', intval($v)); |
|
| 101 | - } |
|
| 90 | + foreach ( |
|
| 91 | + [ |
|
| 92 | + 'creer_preview' |
|
| 93 | + ] as $m |
|
| 94 | + ) { |
|
| 95 | + if (!is_null($v = _request($m))) { |
|
| 96 | + ecrire_meta($m, $v == 'oui' ? 'oui' : 'non'); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + if (!is_null($v = _request('taille_preview'))) { |
|
| 100 | + ecrire_meta('taille_preview', intval($v)); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - $res['message_ok'] = _T('config_info_enregistree'); |
|
| 103 | + $res['message_ok'] = _T('config_info_enregistree'); |
|
| 104 | 104 | |
| 105 | - return $res; |
|
| 105 | + return $res; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -115,37 +115,37 @@ discard block |
||
| 115 | 115 | * URL d'action pour tester la librairie graphique en créant une vignette |
| 116 | 116 | **/ |
| 117 | 117 | function url_vignette_choix($process) { |
| 118 | - switch ($process) { |
|
| 119 | - case 'gd2': |
|
| 120 | - if (!function_exists('ImageCreateTrueColor')) { |
|
| 121 | - return ''; |
|
| 122 | - } |
|
| 123 | - break; |
|
| 124 | - case 'gd1': |
|
| 125 | - if ( |
|
| 126 | - !function_exists('ImageGif') |
|
| 127 | - and !function_exists('ImageJpeg') |
|
| 128 | - and !function_exists('ImagePng') |
|
| 129 | - ) { |
|
| 130 | - return ''; |
|
| 131 | - } |
|
| 132 | - break; |
|
| 133 | - case 'netpbm': |
|
| 134 | - if (defined('_PNMSCALE_COMMAND') and _PNMSCALE_COMMAND == '') { |
|
| 135 | - return ''; |
|
| 136 | - } |
|
| 137 | - break; |
|
| 138 | - case 'imagick': |
|
| 139 | - if (!method_exists(\Imagick::class, 'readImage')) { |
|
| 140 | - return ''; |
|
| 141 | - } |
|
| 142 | - break; |
|
| 143 | - case 'convert': |
|
| 144 | - if (defined('_CONVERT_COMMAND') and _CONVERT_COMMAND == '') { |
|
| 145 | - return ''; |
|
| 146 | - } |
|
| 147 | - break; |
|
| 148 | - } |
|
| 118 | + switch ($process) { |
|
| 119 | + case 'gd2': |
|
| 120 | + if (!function_exists('ImageCreateTrueColor')) { |
|
| 121 | + return ''; |
|
| 122 | + } |
|
| 123 | + break; |
|
| 124 | + case 'gd1': |
|
| 125 | + if ( |
|
| 126 | + !function_exists('ImageGif') |
|
| 127 | + and !function_exists('ImageJpeg') |
|
| 128 | + and !function_exists('ImagePng') |
|
| 129 | + ) { |
|
| 130 | + return ''; |
|
| 131 | + } |
|
| 132 | + break; |
|
| 133 | + case 'netpbm': |
|
| 134 | + if (defined('_PNMSCALE_COMMAND') and _PNMSCALE_COMMAND == '') { |
|
| 135 | + return ''; |
|
| 136 | + } |
|
| 137 | + break; |
|
| 138 | + case 'imagick': |
|
| 139 | + if (!method_exists(\Imagick::class, 'readImage')) { |
|
| 140 | + return ''; |
|
| 141 | + } |
|
| 142 | + break; |
|
| 143 | + case 'convert': |
|
| 144 | + if (defined('_CONVERT_COMMAND') and _CONVERT_COMMAND == '') { |
|
| 145 | + return ''; |
|
| 146 | + } |
|
| 147 | + break; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - return generer_url_action('tester', "arg=$process&time=" . time()); |
|
| 150 | + return generer_url_action('tester', "arg=$process&time=" . time()); |
|
| 151 | 151 | } |
@@ -11,56 +11,56 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function formulaires_configurer_identite_charger_dist() { |
| 18 | - // travailler sur des meta fraiches |
|
| 19 | - include_spip('inc/meta'); |
|
| 20 | - lire_metas(); |
|
| 18 | + // travailler sur des meta fraiches |
|
| 19 | + include_spip('inc/meta'); |
|
| 20 | + lire_metas(); |
|
| 21 | 21 | |
| 22 | - $valeurs = []; |
|
| 23 | - foreach (['nom_site', 'adresse_site', 'slogan_site', 'descriptif_site', 'email_webmaster'] as $k) { |
|
| 24 | - $valeurs[$k] = $GLOBALS['meta'][$k] ?? ''; |
|
| 25 | - } |
|
| 22 | + $valeurs = []; |
|
| 23 | + foreach (['nom_site', 'adresse_site', 'slogan_site', 'descriptif_site', 'email_webmaster'] as $k) { |
|
| 24 | + $valeurs[$k] = $GLOBALS['meta'][$k] ?? ''; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - return $valeurs; |
|
| 27 | + return $valeurs; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | function formulaires_configurer_identite_verifier_dist() { |
| 31 | - $erreurs = []; |
|
| 31 | + $erreurs = []; |
|
| 32 | 32 | |
| 33 | - // adresse_site est obligatoire mais rempli automatiquement si absent ! |
|
| 34 | - foreach (['nom_site'/*,'adresse_site'*/] as $obli) { |
|
| 35 | - if (!_request($obli)) { |
|
| 36 | - $erreurs[$obli] = _T('info_obligatoire'); |
|
| 37 | - } |
|
| 38 | - } |
|
| 33 | + // adresse_site est obligatoire mais rempli automatiquement si absent ! |
|
| 34 | + foreach (['nom_site'/*,'adresse_site'*/] as $obli) { |
|
| 35 | + if (!_request($obli)) { |
|
| 36 | + $erreurs[$obli] = _T('info_obligatoire'); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - if ($email = _request('email_webmaster') and !email_valide($email)) { |
|
| 41 | - $erreurs['email_webmaster'] = _T('info_email_invalide'); |
|
| 42 | - } |
|
| 40 | + if ($email = _request('email_webmaster') and !email_valide($email)) { |
|
| 41 | + $erreurs['email_webmaster'] = _T('info_email_invalide'); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - return $erreurs; |
|
| 44 | + return $erreurs; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | function formulaires_configurer_identite_traiter_dist() { |
| 48 | - include_spip('inc/config'); |
|
| 49 | - $adresse_site = $GLOBALS['meta']['adresse_site'] ?? ''; |
|
| 50 | - if (_request('adresse_site') != $adresse_site) { |
|
| 51 | - refuser_traiter_formulaire_ajax(); |
|
| 52 | - } |
|
| 48 | + include_spip('inc/config'); |
|
| 49 | + $adresse_site = $GLOBALS['meta']['adresse_site'] ?? ''; |
|
| 50 | + if (_request('adresse_site') != $adresse_site) { |
|
| 51 | + refuser_traiter_formulaire_ajax(); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - set_request('adresse_site', appliquer_adresse_site(_request('adresse_site'))); |
|
| 54 | + set_request('adresse_site', appliquer_adresse_site(_request('adresse_site'))); |
|
| 55 | 55 | |
| 56 | - include_spip('inc/meta'); |
|
| 57 | - foreach (['nom_site', 'slogan_site', 'descriptif_site', 'email_webmaster'] as $k) { |
|
| 58 | - ecrire_meta($k, _request($k)); |
|
| 59 | - } |
|
| 56 | + include_spip('inc/meta'); |
|
| 57 | + foreach (['nom_site', 'slogan_site', 'descriptif_site', 'email_webmaster'] as $k) { |
|
| 58 | + ecrire_meta($k, _request($k)); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - include_spip('inc/texte_mini'); |
|
| 62 | - $reload = texte_script(couper(_request('nom_site'), 35)); |
|
| 63 | - $reload = "<script type='text/javascript'>if (window.jQuery) jQuery('#bando_identite .nom_site_spip .nom').html('$reload');</script>"; |
|
| 61 | + include_spip('inc/texte_mini'); |
|
| 62 | + $reload = texte_script(couper(_request('nom_site'), 35)); |
|
| 63 | + $reload = "<script type='text/javascript'>if (window.jQuery) jQuery('#bando_identite .nom_site_spip .nom').html('$reload');</script>"; |
|
| 64 | 64 | |
| 65 | - return ['message_ok' => _T('config_info_enregistree') . $reload, 'editable' => true]; |
|
| 65 | + return ['message_ok' => _T('config_info_enregistree') . $reload, 'editable' => true]; |
|
| 66 | 66 | } |
@@ -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 | |
@@ -45,136 +45,136 @@ discard block |
||
| 45 | 45 | **/ |
| 46 | 46 | function formulaires_dater_charger_dist($objet, $id_objet, $retour = '', $options = []) { |
| 47 | 47 | |
| 48 | - $jour = null; |
|
| 49 | - $mois = null; |
|
| 50 | - $annee = null; |
|
| 51 | - $heure = null; |
|
| 52 | - $minute = null; |
|
| 53 | - $objet = objet_type($objet); |
|
| 54 | - if (!$objet or !intval($id_objet)) { |
|
| 55 | - return false; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if (!is_array($options)) { |
|
| 59 | - $options = unserialize($options); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - $_id_objet = id_table_objet($objet); |
|
| 63 | - $table = table_objet($objet); |
|
| 64 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | - $desc = $trouver_table($table); |
|
| 66 | - |
|
| 67 | - if (!$desc) { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $champ_date = $desc['date'] ?: 'date'; |
|
| 72 | - if (isset($options['champ_date']) and $options['champ_date']) { |
|
| 73 | - $champ_date = $options['champ_date']; |
|
| 74 | - } |
|
| 75 | - if (!isset($desc['field'][$champ_date])) { |
|
| 76 | - return false; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - $valeurs = [ |
|
| 80 | - 'objet' => $objet, |
|
| 81 | - 'id_objet' => $id_objet, |
|
| 82 | - 'id' => $id_objet, |
|
| 83 | - ]; |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - $select = "$champ_date as date"; |
|
| 87 | - $champ_date_redac = 'date_redac'; |
|
| 88 | - if (isset($options['champ_date_redac']) and $options['champ_date_redac']) { |
|
| 89 | - $champ_date_redac = $options['champ_date_redac']; |
|
| 90 | - } |
|
| 91 | - if (isset($desc['field'][$champ_date_redac])) { |
|
| 92 | - $select .= ",$champ_date_redac as date_redac"; |
|
| 93 | - } |
|
| 94 | - if (isset($desc['field']['statut'])) { |
|
| 95 | - $select .= ',statut'; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - $row = sql_fetsel($select, $desc['table'], "$_id_objet=" . intval($id_objet)); |
|
| 100 | - $statut = $row['statut'] ?? 'publie'; // pas de statut => publie |
|
| 101 | - |
|
| 102 | - $valeurs['editable'] = autoriser('dater', $objet, $id_objet, null, ['statut' => $statut]); |
|
| 103 | - |
|
| 104 | - $possedeDateRedac = false; |
|
| 105 | - |
|
| 106 | - if ( |
|
| 107 | - isset($row['date_redac']) and |
|
| 108 | - $regs = recup_date($row['date_redac'], false) |
|
| 109 | - ) { |
|
| 110 | - $annee_redac = $regs[0]; |
|
| 111 | - $mois_redac = $regs[1]; |
|
| 112 | - $jour_redac = $regs[2]; |
|
| 113 | - $heure_redac = $regs[3]; |
|
| 114 | - $minute_redac = $regs[4]; |
|
| 115 | - $possedeDateRedac = true; |
|
| 116 | - // attention : les vrai dates de l'annee 1 sont stockee avec +9000 => 9001 |
|
| 117 | - // mais reviennent ici en annee 1 par recup_date |
|
| 118 | - // on verifie donc que le intval($row['date_redac']) qui ressort l'annee |
|
| 119 | - // est bien lui aussi <=1 : dans ce cas c'est une date sql 'nulle' ou presque, selon |
|
| 120 | - // le gestionnnaire sql utilise (0001-01-01 pour PG par exemple) |
|
| 121 | - if (intval($row['date_redac']) <= 1 and ($annee_redac <= 1) and ($mois_redac <= 1) and ($jour_redac <= 1)) { |
|
| 122 | - $possedeDateRedac = false; |
|
| 123 | - } |
|
| 124 | - } else { |
|
| 125 | - $annee_redac = $mois_redac = $jour_redac = $heure_redac = $minute_redac = 0; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if ($regs = recup_date($row['date'], false)) { |
|
| 129 | - $annee = $regs[0]; |
|
| 130 | - $mois = $regs[1]; |
|
| 131 | - $jour = $regs[2]; |
|
| 132 | - $heure = $regs[3]; |
|
| 133 | - $minute = $regs[4]; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // attention, si la variable s'appelle date ou date_redac, le compilo va |
|
| 137 | - // la normaliser, ce qu'on ne veut pas ici. |
|
| 138 | - $valeurs['afficher_date_redac'] = ($possedeDateRedac ? $row['date_redac'] : ''); |
|
| 139 | - $valeurs['date_redac_jour'] = dater_formater_saisie_jour($jour_redac, $mois_redac, $annee_redac); |
|
| 140 | - $valeurs['date_redac_heure'] = "$heure_redac:$minute_redac"; |
|
| 141 | - |
|
| 142 | - $valeurs['afficher_date'] = $row['date']; |
|
| 143 | - $valeurs['date_jour'] = dater_formater_saisie_jour($jour, $mois, $annee); |
|
| 144 | - $valeurs['date_heure'] = "$heure:$minute"; |
|
| 145 | - |
|
| 146 | - $valeurs['sans_redac'] = !$possedeDateRedac; |
|
| 147 | - |
|
| 148 | - if (isset($options['date_redac'])) { |
|
| 149 | - $valeurs['_editer_date_anterieure'] = $options['date_redac']; |
|
| 150 | - } else { |
|
| 151 | - $valeurs['_editer_date_anterieure'] = ($objet == 'article' and ($GLOBALS['meta']['articles_redac'] != 'non' or $possedeDateRedac)); |
|
| 152 | - } |
|
| 153 | - $valeurs['_label_date'] = (($statut == 'publie') ? |
|
| 154 | - _T('texte_date_publication_objet') : _T('texte_date_creation_objet')); |
|
| 155 | - if (isset($options['label_date']) and $options['label_date']) { |
|
| 156 | - $valeurs['_label_date'] = $options['label_date']; |
|
| 157 | - } |
|
| 158 | - if (isset($options['label_date_redac']) and $options['label_date_redac']) { |
|
| 159 | - $valeurs['_label_date_redac'] = $options['label_date_redac']; |
|
| 160 | - } |
|
| 161 | - if (isset($options['texte_sans_date_redac']) and $options['texte_sans_date_redac']) { |
|
| 162 | - $valeurs['_texte_sans_date_redac'] = $options['texte_sans_date_redac']; |
|
| 163 | - } |
|
| 164 | - if (isset($options['class']) and $options['class']) { |
|
| 165 | - $valeurs['_class'] = $options['class']; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $valeurs['_saisie_en_cours'] = (_request('_saisie_en_cours') !== null or _request('date_jour') !== null); |
|
| 169 | - |
|
| 170 | - // cas ou l'on ne peut pas dater mais on peut modifier la date de redac anterieure |
|
| 171 | - // https://core.spip.net/issues/3494 |
|
| 172 | - $valeurs['_editer_date'] = $valeurs['editable']; |
|
| 173 | - if ($valeurs['_editer_date_anterieure'] and !$valeurs['editable']) { |
|
| 174 | - $valeurs['editable'] = autoriser('modifier', $objet, $id_objet); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $valeurs; |
|
| 48 | + $jour = null; |
|
| 49 | + $mois = null; |
|
| 50 | + $annee = null; |
|
| 51 | + $heure = null; |
|
| 52 | + $minute = null; |
|
| 53 | + $objet = objet_type($objet); |
|
| 54 | + if (!$objet or !intval($id_objet)) { |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if (!is_array($options)) { |
|
| 59 | + $options = unserialize($options); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + $_id_objet = id_table_objet($objet); |
|
| 63 | + $table = table_objet($objet); |
|
| 64 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | + $desc = $trouver_table($table); |
|
| 66 | + |
|
| 67 | + if (!$desc) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $champ_date = $desc['date'] ?: 'date'; |
|
| 72 | + if (isset($options['champ_date']) and $options['champ_date']) { |
|
| 73 | + $champ_date = $options['champ_date']; |
|
| 74 | + } |
|
| 75 | + if (!isset($desc['field'][$champ_date])) { |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + $valeurs = [ |
|
| 80 | + 'objet' => $objet, |
|
| 81 | + 'id_objet' => $id_objet, |
|
| 82 | + 'id' => $id_objet, |
|
| 83 | + ]; |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + $select = "$champ_date as date"; |
|
| 87 | + $champ_date_redac = 'date_redac'; |
|
| 88 | + if (isset($options['champ_date_redac']) and $options['champ_date_redac']) { |
|
| 89 | + $champ_date_redac = $options['champ_date_redac']; |
|
| 90 | + } |
|
| 91 | + if (isset($desc['field'][$champ_date_redac])) { |
|
| 92 | + $select .= ",$champ_date_redac as date_redac"; |
|
| 93 | + } |
|
| 94 | + if (isset($desc['field']['statut'])) { |
|
| 95 | + $select .= ',statut'; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + $row = sql_fetsel($select, $desc['table'], "$_id_objet=" . intval($id_objet)); |
|
| 100 | + $statut = $row['statut'] ?? 'publie'; // pas de statut => publie |
|
| 101 | + |
|
| 102 | + $valeurs['editable'] = autoriser('dater', $objet, $id_objet, null, ['statut' => $statut]); |
|
| 103 | + |
|
| 104 | + $possedeDateRedac = false; |
|
| 105 | + |
|
| 106 | + if ( |
|
| 107 | + isset($row['date_redac']) and |
|
| 108 | + $regs = recup_date($row['date_redac'], false) |
|
| 109 | + ) { |
|
| 110 | + $annee_redac = $regs[0]; |
|
| 111 | + $mois_redac = $regs[1]; |
|
| 112 | + $jour_redac = $regs[2]; |
|
| 113 | + $heure_redac = $regs[3]; |
|
| 114 | + $minute_redac = $regs[4]; |
|
| 115 | + $possedeDateRedac = true; |
|
| 116 | + // attention : les vrai dates de l'annee 1 sont stockee avec +9000 => 9001 |
|
| 117 | + // mais reviennent ici en annee 1 par recup_date |
|
| 118 | + // on verifie donc que le intval($row['date_redac']) qui ressort l'annee |
|
| 119 | + // est bien lui aussi <=1 : dans ce cas c'est une date sql 'nulle' ou presque, selon |
|
| 120 | + // le gestionnnaire sql utilise (0001-01-01 pour PG par exemple) |
|
| 121 | + if (intval($row['date_redac']) <= 1 and ($annee_redac <= 1) and ($mois_redac <= 1) and ($jour_redac <= 1)) { |
|
| 122 | + $possedeDateRedac = false; |
|
| 123 | + } |
|
| 124 | + } else { |
|
| 125 | + $annee_redac = $mois_redac = $jour_redac = $heure_redac = $minute_redac = 0; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if ($regs = recup_date($row['date'], false)) { |
|
| 129 | + $annee = $regs[0]; |
|
| 130 | + $mois = $regs[1]; |
|
| 131 | + $jour = $regs[2]; |
|
| 132 | + $heure = $regs[3]; |
|
| 133 | + $minute = $regs[4]; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // attention, si la variable s'appelle date ou date_redac, le compilo va |
|
| 137 | + // la normaliser, ce qu'on ne veut pas ici. |
|
| 138 | + $valeurs['afficher_date_redac'] = ($possedeDateRedac ? $row['date_redac'] : ''); |
|
| 139 | + $valeurs['date_redac_jour'] = dater_formater_saisie_jour($jour_redac, $mois_redac, $annee_redac); |
|
| 140 | + $valeurs['date_redac_heure'] = "$heure_redac:$minute_redac"; |
|
| 141 | + |
|
| 142 | + $valeurs['afficher_date'] = $row['date']; |
|
| 143 | + $valeurs['date_jour'] = dater_formater_saisie_jour($jour, $mois, $annee); |
|
| 144 | + $valeurs['date_heure'] = "$heure:$minute"; |
|
| 145 | + |
|
| 146 | + $valeurs['sans_redac'] = !$possedeDateRedac; |
|
| 147 | + |
|
| 148 | + if (isset($options['date_redac'])) { |
|
| 149 | + $valeurs['_editer_date_anterieure'] = $options['date_redac']; |
|
| 150 | + } else { |
|
| 151 | + $valeurs['_editer_date_anterieure'] = ($objet == 'article' and ($GLOBALS['meta']['articles_redac'] != 'non' or $possedeDateRedac)); |
|
| 152 | + } |
|
| 153 | + $valeurs['_label_date'] = (($statut == 'publie') ? |
|
| 154 | + _T('texte_date_publication_objet') : _T('texte_date_creation_objet')); |
|
| 155 | + if (isset($options['label_date']) and $options['label_date']) { |
|
| 156 | + $valeurs['_label_date'] = $options['label_date']; |
|
| 157 | + } |
|
| 158 | + if (isset($options['label_date_redac']) and $options['label_date_redac']) { |
|
| 159 | + $valeurs['_label_date_redac'] = $options['label_date_redac']; |
|
| 160 | + } |
|
| 161 | + if (isset($options['texte_sans_date_redac']) and $options['texte_sans_date_redac']) { |
|
| 162 | + $valeurs['_texte_sans_date_redac'] = $options['texte_sans_date_redac']; |
|
| 163 | + } |
|
| 164 | + if (isset($options['class']) and $options['class']) { |
|
| 165 | + $valeurs['_class'] = $options['class']; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $valeurs['_saisie_en_cours'] = (_request('_saisie_en_cours') !== null or _request('date_jour') !== null); |
|
| 169 | + |
|
| 170 | + // cas ou l'on ne peut pas dater mais on peut modifier la date de redac anterieure |
|
| 171 | + // https://core.spip.net/issues/3494 |
|
| 172 | + $valeurs['_editer_date'] = $valeurs['editable']; |
|
| 173 | + if ($valeurs['_editer_date_anterieure'] and !$valeurs['editable']) { |
|
| 174 | + $valeurs['editable'] = autoriser('modifier', $objet, $id_objet); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $valeurs; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -192,20 +192,20 @@ discard block |
||
| 192 | 192 | * Date formatée tel que `02/10/2012` |
| 193 | 193 | **/ |
| 194 | 194 | function dater_formater_saisie_jour($jour, $mois, $annee, $sep = '/') { |
| 195 | - $annee = str_pad($annee, 4, '0', STR_PAD_LEFT); |
|
| 196 | - if (intval($jour)) { |
|
| 197 | - $jour = str_pad($jour, 2, '0', STR_PAD_LEFT); |
|
| 198 | - $mois = str_pad($mois, 2, '0', STR_PAD_LEFT); |
|
| 195 | + $annee = str_pad($annee, 4, '0', STR_PAD_LEFT); |
|
| 196 | + if (intval($jour)) { |
|
| 197 | + $jour = str_pad($jour, 2, '0', STR_PAD_LEFT); |
|
| 198 | + $mois = str_pad($mois, 2, '0', STR_PAD_LEFT); |
|
| 199 | 199 | |
| 200 | - return "$jour$sep$mois$sep$annee"; |
|
| 201 | - } |
|
| 202 | - if (intval($mois)) { |
|
| 203 | - $mois = str_pad($mois, 2, '0', STR_PAD_LEFT); |
|
| 200 | + return "$jour$sep$mois$sep$annee"; |
|
| 201 | + } |
|
| 202 | + if (intval($mois)) { |
|
| 203 | + $mois = str_pad($mois, 2, '0', STR_PAD_LEFT); |
|
| 204 | 204 | |
| 205 | - return "$mois$sep$annee"; |
|
| 206 | - } |
|
| 205 | + return "$mois$sep$annee"; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - return $annee; |
|
| 208 | + return $annee; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * Hash du formulaire |
| 225 | 225 | **/ |
| 226 | 226 | function formulaires_dater_identifier_dist($objet, $id_objet, $retour = '', $options = []) { |
| 227 | - return serialize([$objet, $id_objet]); |
|
| 227 | + return serialize([$objet, $id_objet]); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -242,30 +242,30 @@ discard block |
||
| 242 | 242 | * Tableau des erreurs |
| 243 | 243 | */ |
| 244 | 244 | function formulaires_dater_verifier_dist($objet, $id_objet, $retour = '', $options = []) { |
| 245 | - $erreurs = []; |
|
| 246 | - |
|
| 247 | - // ouvrir le formulaire en edition ? |
|
| 248 | - if (_request('_saisie_en_cours')) { |
|
| 249 | - $erreurs['message_erreur'] = ''; |
|
| 250 | - |
|
| 251 | - return $erreurs; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - if (_request('changer')) { |
|
| 255 | - foreach (['date', 'date_redac'] as $k) { |
|
| 256 | - if ($v = _request($k . '_jour') and !dater_recuperer_date_saisie($v, $k)) { |
|
| 257 | - $erreurs[$k] = _T('format_date_incorrecte'); |
|
| 258 | - } elseif ($v = _request($k . '_heure') and !dater_recuperer_heure_saisie($v)) { |
|
| 259 | - $erreurs[$k] = _T('format_heure_incorrecte'); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if (!_request('date_jour')) { |
|
| 264 | - $erreurs['date'] = _T('info_obligatoire'); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - return $erreurs; |
|
| 245 | + $erreurs = []; |
|
| 246 | + |
|
| 247 | + // ouvrir le formulaire en edition ? |
|
| 248 | + if (_request('_saisie_en_cours')) { |
|
| 249 | + $erreurs['message_erreur'] = ''; |
|
| 250 | + |
|
| 251 | + return $erreurs; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + if (_request('changer')) { |
|
| 255 | + foreach (['date', 'date_redac'] as $k) { |
|
| 256 | + if ($v = _request($k . '_jour') and !dater_recuperer_date_saisie($v, $k)) { |
|
| 257 | + $erreurs[$k] = _T('format_date_incorrecte'); |
|
| 258 | + } elseif ($v = _request($k . '_heure') and !dater_recuperer_heure_saisie($v)) { |
|
| 259 | + $erreurs[$k] = _T('format_heure_incorrecte'); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if (!_request('date_jour')) { |
|
| 264 | + $erreurs['date'] = _T('info_obligatoire'); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + return $erreurs; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -283,79 +283,79 @@ discard block |
||
| 283 | 283 | * Retours des traitements |
| 284 | 284 | */ |
| 285 | 285 | function formulaires_dater_traiter_dist($objet, $id_objet, $retour = '', $options = []) { |
| 286 | - $res = ['editable' => ' ']; |
|
| 287 | - |
|
| 288 | - if (_request('changer')) { |
|
| 289 | - $table = table_objet($objet); |
|
| 290 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 291 | - $desc = $trouver_table($table); |
|
| 292 | - |
|
| 293 | - if (!$desc) { |
|
| 294 | - return ['message_erreur' => _L('erreur')]; |
|
| 295 | - } #impossible en principe |
|
| 296 | - |
|
| 297 | - $champ_date = $desc['date'] ?: 'date'; |
|
| 298 | - if (isset($options['champ_date']) and $options['champ_date']) { |
|
| 299 | - $champ_date = $options['champ_date']; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $set = []; |
|
| 303 | - |
|
| 304 | - $charger = charger_fonction('charger', 'formulaires/dater/'); |
|
| 305 | - $v = $charger($objet, $id_objet, $retour, $options); |
|
| 306 | - |
|
| 307 | - if ($v['_editer_date']) { |
|
| 308 | - if (!$d = dater_recuperer_date_saisie(_request('date_jour'))) { |
|
| 309 | - $d = [date('Y'), date('m'), date('d')]; |
|
| 310 | - } |
|
| 311 | - if (!$h = dater_recuperer_heure_saisie(_request('date_heure'))) { |
|
| 312 | - $h = [0, 0]; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $set[$champ_date] = sql_format_date($d[0], $d[1], $d[2], $h[0], $h[1]); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $champ_date_redac = 'date_redac'; |
|
| 319 | - if (isset($options['champ_date_redac']) and $options['champ_date_redac']) { |
|
| 320 | - $champ_date_redac = $options['champ_date_redac']; |
|
| 321 | - } |
|
| 322 | - if (isset($desc['field'][$champ_date_redac]) and $v['_editer_date_anterieure']) { |
|
| 323 | - if (!_request('date_redac_jour') or _request('sans_redac')) { |
|
| 324 | - $set[$champ_date_redac] = sql_format_date(0, 0, 0, 0, 0, 0); |
|
| 325 | - } else { |
|
| 326 | - if (!$d = dater_recuperer_date_saisie(_request('date_redac_jour'), 'date_redac')) { |
|
| 327 | - $d = [date('Y'), date('m'), date('d')]; |
|
| 328 | - } |
|
| 329 | - if (!$h = dater_recuperer_heure_saisie(_request('date_redac_heure'))) { |
|
| 330 | - $h = [0, 0]; |
|
| 331 | - } |
|
| 332 | - $set[$champ_date_redac] = sql_format_date($d[0], $d[1], $d[2], $h[0], $h[1]); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - if (count($set)) { |
|
| 337 | - $publie_avant = objet_test_si_publie($objet, $id_objet); |
|
| 338 | - include_spip('action/editer_objet'); |
|
| 339 | - objet_modifier($objet, $id_objet, $set); |
|
| 340 | - $publie_apres = objet_test_si_publie($objet, $id_objet); |
|
| 341 | - if ($publie_avant !== $publie_apres) { |
|
| 342 | - // on refuse ajax pour forcer le rechargement de la page ici |
|
| 343 | - // on refera traiter une 2eme fois, mais c'est sans consequence |
|
| 344 | - refuser_traiter_formulaire_ajax(); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if ($retour) { |
|
| 350 | - $res['redirect'] = $retour; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - set_request('date_jour'); |
|
| 354 | - set_request('date_redac_jour'); |
|
| 355 | - set_request('date_heure'); |
|
| 356 | - set_request('date_redac_heure'); |
|
| 357 | - |
|
| 358 | - return $res; |
|
| 286 | + $res = ['editable' => ' ']; |
|
| 287 | + |
|
| 288 | + if (_request('changer')) { |
|
| 289 | + $table = table_objet($objet); |
|
| 290 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 291 | + $desc = $trouver_table($table); |
|
| 292 | + |
|
| 293 | + if (!$desc) { |
|
| 294 | + return ['message_erreur' => _L('erreur')]; |
|
| 295 | + } #impossible en principe |
|
| 296 | + |
|
| 297 | + $champ_date = $desc['date'] ?: 'date'; |
|
| 298 | + if (isset($options['champ_date']) and $options['champ_date']) { |
|
| 299 | + $champ_date = $options['champ_date']; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $set = []; |
|
| 303 | + |
|
| 304 | + $charger = charger_fonction('charger', 'formulaires/dater/'); |
|
| 305 | + $v = $charger($objet, $id_objet, $retour, $options); |
|
| 306 | + |
|
| 307 | + if ($v['_editer_date']) { |
|
| 308 | + if (!$d = dater_recuperer_date_saisie(_request('date_jour'))) { |
|
| 309 | + $d = [date('Y'), date('m'), date('d')]; |
|
| 310 | + } |
|
| 311 | + if (!$h = dater_recuperer_heure_saisie(_request('date_heure'))) { |
|
| 312 | + $h = [0, 0]; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $set[$champ_date] = sql_format_date($d[0], $d[1], $d[2], $h[0], $h[1]); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $champ_date_redac = 'date_redac'; |
|
| 319 | + if (isset($options['champ_date_redac']) and $options['champ_date_redac']) { |
|
| 320 | + $champ_date_redac = $options['champ_date_redac']; |
|
| 321 | + } |
|
| 322 | + if (isset($desc['field'][$champ_date_redac]) and $v['_editer_date_anterieure']) { |
|
| 323 | + if (!_request('date_redac_jour') or _request('sans_redac')) { |
|
| 324 | + $set[$champ_date_redac] = sql_format_date(0, 0, 0, 0, 0, 0); |
|
| 325 | + } else { |
|
| 326 | + if (!$d = dater_recuperer_date_saisie(_request('date_redac_jour'), 'date_redac')) { |
|
| 327 | + $d = [date('Y'), date('m'), date('d')]; |
|
| 328 | + } |
|
| 329 | + if (!$h = dater_recuperer_heure_saisie(_request('date_redac_heure'))) { |
|
| 330 | + $h = [0, 0]; |
|
| 331 | + } |
|
| 332 | + $set[$champ_date_redac] = sql_format_date($d[0], $d[1], $d[2], $h[0], $h[1]); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + if (count($set)) { |
|
| 337 | + $publie_avant = objet_test_si_publie($objet, $id_objet); |
|
| 338 | + include_spip('action/editer_objet'); |
|
| 339 | + objet_modifier($objet, $id_objet, $set); |
|
| 340 | + $publie_apres = objet_test_si_publie($objet, $id_objet); |
|
| 341 | + if ($publie_avant !== $publie_apres) { |
|
| 342 | + // on refuse ajax pour forcer le rechargement de la page ici |
|
| 343 | + // on refera traiter une 2eme fois, mais c'est sans consequence |
|
| 344 | + refuser_traiter_formulaire_ajax(); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if ($retour) { |
|
| 350 | + $res['redirect'] = $retour; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + set_request('date_jour'); |
|
| 354 | + set_request('date_redac_jour'); |
|
| 355 | + set_request('date_heure'); |
|
| 356 | + set_request('date_redac_heure'); |
|
| 357 | + |
|
| 358 | + return $res; |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
@@ -366,24 +366,24 @@ discard block |
||
| 366 | 366 | * @return array|string Chaîne vide si date invalide, tableau (année, mois, jour) sinon. |
| 367 | 367 | */ |
| 368 | 368 | function dater_recuperer_date_saisie($post, $quoi = 'date') { |
| 369 | - if (!preg_match('#^(?:(?:([0-9]{1,2})[/-])?([0-9]{1,2})[/-])?([0-9]{4}|[0-9]{1,2})#', $post, $regs)) { |
|
| 370 | - return ''; |
|
| 371 | - } |
|
| 372 | - if ($quoi == 'date_redac') { |
|
| 373 | - if ($regs[3] <> '' and $regs[3] < 1001) { |
|
| 374 | - $regs[3] += 9000; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - return [$regs[3], $regs[2], $regs[1]]; |
|
| 378 | - } else { |
|
| 379 | - if ( |
|
| 380 | - checkdate(intval($regs[2]), intval($regs[1]), intval($regs[3])) |
|
| 381 | - and $t = mktime(0, 0, 0, $regs[2], $regs[1], $regs[3]) |
|
| 382 | - ) { |
|
| 383 | - return [date('Y', $t), date('m', $t), date('d', $t)]; |
|
| 384 | - } |
|
| 385 | - return ''; |
|
| 386 | - } |
|
| 369 | + if (!preg_match('#^(?:(?:([0-9]{1,2})[/-])?([0-9]{1,2})[/-])?([0-9]{4}|[0-9]{1,2})#', $post, $regs)) { |
|
| 370 | + return ''; |
|
| 371 | + } |
|
| 372 | + if ($quoi == 'date_redac') { |
|
| 373 | + if ($regs[3] <> '' and $regs[3] < 1001) { |
|
| 374 | + $regs[3] += 9000; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + return [$regs[3], $regs[2], $regs[1]]; |
|
| 378 | + } else { |
|
| 379 | + if ( |
|
| 380 | + checkdate(intval($regs[2]), intval($regs[1]), intval($regs[3])) |
|
| 381 | + and $t = mktime(0, 0, 0, $regs[2], $regs[1], $regs[3]) |
|
| 382 | + ) { |
|
| 383 | + return [date('Y', $t), date('m', $t), date('d', $t)]; |
|
| 384 | + } |
|
| 385 | + return ''; |
|
| 386 | + } |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -393,12 +393,12 @@ discard block |
||
| 393 | 393 | * @return array |
| 394 | 394 | */ |
| 395 | 395 | function dater_recuperer_heure_saisie($post) { |
| 396 | - if (!preg_match('#([0-9]{1,2})(?:[h:](?:([0-9]{1,2}))?)?#', $post, $regs)) { |
|
| 397 | - return ''; |
|
| 398 | - } |
|
| 399 | - if ($regs[1] > 23 or $regs[2] > 59) { |
|
| 400 | - return ''; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - return [$regs[1], $regs[2]]; |
|
| 396 | + if (!preg_match('#([0-9]{1,2})(?:[h:](?:([0-9]{1,2}))?)?#', $post, $regs)) { |
|
| 397 | + return ''; |
|
| 398 | + } |
|
| 399 | + if ($regs[1] > 23 or $regs[2] > 59) { |
|
| 400 | + return ''; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + return [$regs[1], $regs[2]]; |
|
| 404 | 404 | } |
@@ -11,53 +11,53 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function formulaires_configurer_multilinguisme_charger_dist() { |
| 18 | - $valeurs = []; |
|
| 19 | - $valeurs['multi_secteurs'] = $GLOBALS['meta']['multi_secteurs']; |
|
| 20 | - foreach (['multi_objets', 'gerer_trad_objets'] as $m) { |
|
| 21 | - $valeurs[$m] = explode(',', $GLOBALS['meta'][$m] ?? ''); |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - if ( |
|
| 25 | - is_countable($valeurs['multi_objets']) ? count($valeurs['multi_objets']) : 0 |
|
| 26 | - or count(explode(',', $GLOBALS['meta']['langues_utilisees'])) > 1 |
|
| 27 | - ) { |
|
| 28 | - $selection = (is_null(_request('multi_objets')) ? |
|
| 29 | - explode(',', $GLOBALS['meta']['langues_multilingue']) : _request('langues_auth')); |
|
| 30 | - $valeurs['_langues'] = saisie_langues_utiles('langues_auth', $selection ?: []); |
|
| 31 | - $valeurs['_nb_langues_selection'] = is_countable($selection) ? count($selection) : 0; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - return $valeurs; |
|
| 18 | + $valeurs = []; |
|
| 19 | + $valeurs['multi_secteurs'] = $GLOBALS['meta']['multi_secteurs']; |
|
| 20 | + foreach (['multi_objets', 'gerer_trad_objets'] as $m) { |
|
| 21 | + $valeurs[$m] = explode(',', $GLOBALS['meta'][$m] ?? ''); |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + if ( |
|
| 25 | + is_countable($valeurs['multi_objets']) ? count($valeurs['multi_objets']) : 0 |
|
| 26 | + or count(explode(',', $GLOBALS['meta']['langues_utilisees'])) > 1 |
|
| 27 | + ) { |
|
| 28 | + $selection = (is_null(_request('multi_objets')) ? |
|
| 29 | + explode(',', $GLOBALS['meta']['langues_multilingue']) : _request('langues_auth')); |
|
| 30 | + $valeurs['_langues'] = saisie_langues_utiles('langues_auth', $selection ?: []); |
|
| 31 | + $valeurs['_nb_langues_selection'] = is_countable($selection) ? count($selection) : 0; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + return $valeurs; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | function formulaires_configurer_multilinguisme_traiter_dist() { |
| 39 | - $res = ['editable' => true]; |
|
| 40 | - // un checkbox seul de name X non coche n'est pas poste. |
|
| 41 | - // on verifie le champ X_check qui indique que la checkbox etait presente dans le formulaire. |
|
| 42 | - foreach (['multi_secteurs'] as $m) { |
|
| 43 | - if (!is_null(_request($m . '_check'))) { |
|
| 44 | - ecrire_meta($m, _request($m) ? 'oui' : 'non'); |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - foreach (['multi_objets', 'gerer_trad_objets'] as $m) { |
|
| 48 | - if (!is_null($v = _request($m))) { |
|
| 49 | - // join et enlever la valeur vide '' |
|
| 50 | - ecrire_meta($m, implode(',', array_diff($v, ['']))); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if ($i = _request('langues_auth') and is_array($i)) { |
|
| 55 | - $i = array_unique(array_merge($i, explode(',', $GLOBALS['meta']['langues_utilisees']))); |
|
| 56 | - ecrire_meta('langues_multilingue', implode(',', $i)); |
|
| 57 | - } |
|
| 58 | - $res['message_ok'] = _T('config_info_enregistree'); |
|
| 59 | - |
|
| 60 | - return $res; |
|
| 39 | + $res = ['editable' => true]; |
|
| 40 | + // un checkbox seul de name X non coche n'est pas poste. |
|
| 41 | + // on verifie le champ X_check qui indique que la checkbox etait presente dans le formulaire. |
|
| 42 | + foreach (['multi_secteurs'] as $m) { |
|
| 43 | + if (!is_null(_request($m . '_check'))) { |
|
| 44 | + ecrire_meta($m, _request($m) ? 'oui' : 'non'); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + foreach (['multi_objets', 'gerer_trad_objets'] as $m) { |
|
| 48 | + if (!is_null($v = _request($m))) { |
|
| 49 | + // join et enlever la valeur vide '' |
|
| 50 | + ecrire_meta($m, implode(',', array_diff($v, ['']))); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if ($i = _request('langues_auth') and is_array($i)) { |
|
| 55 | + $i = array_unique(array_merge($i, explode(',', $GLOBALS['meta']['langues_utilisees']))); |
|
| 56 | + ecrire_meta('langues_multilingue', implode(',', $i)); |
|
| 57 | + } |
|
| 58 | + $res['message_ok'] = _T('config_info_enregistree'); |
|
| 59 | + |
|
| 60 | + return $res; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | * @return string |
| 68 | 68 | */ |
| 69 | 69 | function table_supporte_lang($table_sql) { |
| 70 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 71 | - $desc = $trouver_table($table_sql); |
|
| 72 | - if (!$desc or !isset($desc['field']['lang'])) { |
|
| 73 | - return ''; |
|
| 74 | - } |
|
| 70 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 71 | + $desc = $trouver_table($table_sql); |
|
| 72 | + if (!$desc or !isset($desc['field']['lang'])) { |
|
| 73 | + return ''; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return ' '; |
|
| 76 | + return ' '; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -83,67 +83,67 @@ discard block |
||
| 83 | 83 | * @return string |
| 84 | 84 | */ |
| 85 | 85 | function table_supporte_trad($table_sql) { |
| 86 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 87 | - $desc = $trouver_table($table_sql); |
|
| 88 | - if (!$desc or !isset($desc['field']['id_trad'])) { |
|
| 89 | - return ''; |
|
| 90 | - } |
|
| 86 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 87 | + $desc = $trouver_table($table_sql); |
|
| 88 | + if (!$desc or !isset($desc['field']['id_trad'])) { |
|
| 89 | + return ''; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return ' '; |
|
| 92 | + return ' '; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
| 96 | 96 | function saisie_langues_utiles($name, $selection) { |
| 97 | - include_spip('inc/lang_liste'); |
|
| 98 | - $langues = $GLOBALS['codes_langues']; |
|
| 99 | - |
|
| 100 | - $langues_installees = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 101 | - $langues_trad = array_flip($langues_installees); |
|
| 102 | - |
|
| 103 | - $langues_bloquees = explode(',', $GLOBALS['meta']['langues_utilisees']); |
|
| 104 | - |
|
| 105 | - $res = ''; |
|
| 106 | - |
|
| 107 | - $i = 0; |
|
| 108 | - foreach ($langues_bloquees as $code_langue) { |
|
| 109 | - $nom_langue = $langues[$code_langue]; |
|
| 110 | - $res .= "<li class='choix " |
|
| 111 | - . alterner(++$i, 'odd', 'even') |
|
| 112 | - . (isset($langues_trad[$code_langue]) ? ' traduite' : '') |
|
| 113 | - . "'>" |
|
| 114 | - . "<input type='hidden' name='{$name}[]' value='$code_langue'>" // necessaire ... |
|
| 115 | - . "<input type='checkbox' name='{$name}[]' id='{$name}_$code_langue' value='$code_langue' checked='checked' disabled='disabled' />" |
|
| 116 | - . "<label for='{$name}_$code_langue'>" . $nom_langue . " <span class='code_langue'>[$code_langue]</span></label>" |
|
| 117 | - . '</li>'; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if ($res) { |
|
| 121 | - $res = "<ul id='langues_bloquees'>" . $res . "</ul><div class='nettoyeur'></div>"; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $res .= "<ul id='langues_proposees'>"; |
|
| 125 | - |
|
| 126 | - $i = 0; |
|
| 127 | - $langues_bloquees = array_flip($langues_bloquees); |
|
| 128 | - foreach ($langues as $code_langue => $nom_langue) { |
|
| 129 | - if (!isset($langues_bloquees[$code_langue])) { |
|
| 130 | - $checked = (in_array($code_langue, $selection) ? ' checked="checked"' : ''); |
|
| 131 | - $res .= "<li class='choix " |
|
| 132 | - . alterner(++$i, 'odd', 'even') |
|
| 133 | - . (isset($langues_trad[$code_langue]) ? ' traduite' : '') |
|
| 134 | - . "'>" |
|
| 135 | - . "<input type='checkbox' name='{$name}[]' id='{$name}_$code_langue' value='$code_langue'" |
|
| 136 | - . $checked |
|
| 137 | - . '/>' |
|
| 138 | - . "<label for='{$name}_$code_langue'" |
|
| 139 | - . ($checked ? " class='on'" : '') |
|
| 140 | - . '>' |
|
| 141 | - . $nom_langue . " <span class='code_langue'>[$code_langue]</span></label>" |
|
| 142 | - . '</li>'; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $res .= "</ul><div class='nettoyeur'></div>"; |
|
| 147 | - |
|
| 148 | - return $res; |
|
| 97 | + include_spip('inc/lang_liste'); |
|
| 98 | + $langues = $GLOBALS['codes_langues']; |
|
| 99 | + |
|
| 100 | + $langues_installees = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 101 | + $langues_trad = array_flip($langues_installees); |
|
| 102 | + |
|
| 103 | + $langues_bloquees = explode(',', $GLOBALS['meta']['langues_utilisees']); |
|
| 104 | + |
|
| 105 | + $res = ''; |
|
| 106 | + |
|
| 107 | + $i = 0; |
|
| 108 | + foreach ($langues_bloquees as $code_langue) { |
|
| 109 | + $nom_langue = $langues[$code_langue]; |
|
| 110 | + $res .= "<li class='choix " |
|
| 111 | + . alterner(++$i, 'odd', 'even') |
|
| 112 | + . (isset($langues_trad[$code_langue]) ? ' traduite' : '') |
|
| 113 | + . "'>" |
|
| 114 | + . "<input type='hidden' name='{$name}[]' value='$code_langue'>" // necessaire ... |
|
| 115 | + . "<input type='checkbox' name='{$name}[]' id='{$name}_$code_langue' value='$code_langue' checked='checked' disabled='disabled' />" |
|
| 116 | + . "<label for='{$name}_$code_langue'>" . $nom_langue . " <span class='code_langue'>[$code_langue]</span></label>" |
|
| 117 | + . '</li>'; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if ($res) { |
|
| 121 | + $res = "<ul id='langues_bloquees'>" . $res . "</ul><div class='nettoyeur'></div>"; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $res .= "<ul id='langues_proposees'>"; |
|
| 125 | + |
|
| 126 | + $i = 0; |
|
| 127 | + $langues_bloquees = array_flip($langues_bloquees); |
|
| 128 | + foreach ($langues as $code_langue => $nom_langue) { |
|
| 129 | + if (!isset($langues_bloquees[$code_langue])) { |
|
| 130 | + $checked = (in_array($code_langue, $selection) ? ' checked="checked"' : ''); |
|
| 131 | + $res .= "<li class='choix " |
|
| 132 | + . alterner(++$i, 'odd', 'even') |
|
| 133 | + . (isset($langues_trad[$code_langue]) ? ' traduite' : '') |
|
| 134 | + . "'>" |
|
| 135 | + . "<input type='checkbox' name='{$name}[]' id='{$name}_$code_langue' value='$code_langue'" |
|
| 136 | + . $checked |
|
| 137 | + . '/>' |
|
| 138 | + . "<label for='{$name}_$code_langue'" |
|
| 139 | + . ($checked ? " class='on'" : '') |
|
| 140 | + . '>' |
|
| 141 | + . $nom_langue . " <span class='code_langue'>[$code_langue]</span></label>" |
|
| 142 | + . '</li>'; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $res .= "</ul><div class='nettoyeur'></div>"; |
|
| 147 | + |
|
| 148 | + return $res; |
|
| 149 | 149 | } |
@@ -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 | include_spip('inc/rechercher'); |
| 24 | 24 | if (!defined('_DELAI_CACHE_resultats')) { |
| 25 | - define('_DELAI_CACHE_resultats', 600); |
|
| 25 | + define('_DELAI_CACHE_resultats', 600); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -49,129 +49,129 @@ discard block |
||
| 49 | 49 | * @return array |
| 50 | 50 | */ |
| 51 | 51 | function inc_prepare_recherche_dist( |
| 52 | - $recherche, |
|
| 53 | - $table = 'articles', |
|
| 54 | - $cond = false, |
|
| 55 | - $serveur = '', |
|
| 56 | - $modificateurs = [], |
|
| 57 | - $primary = '' |
|
| 52 | + $recherche, |
|
| 53 | + $table = 'articles', |
|
| 54 | + $cond = false, |
|
| 55 | + $serveur = '', |
|
| 56 | + $modificateurs = [], |
|
| 57 | + $primary = '' |
|
| 58 | 58 | ) { |
| 59 | - $where = null; |
|
| 60 | - $rows = null; |
|
| 61 | - static $cache = []; |
|
| 62 | - $delai_fraicheur = min( |
|
| 63 | - \_DELAI_CACHE_resultats, |
|
| 64 | - time() - ($GLOBALS['meta']['derniere_modif'] ?? 0) |
|
| 65 | - ); |
|
| 66 | - |
|
| 67 | - // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 68 | - // ca permet de faire des inclure simple. |
|
| 69 | - if (!isset($recherche) and isset($GLOBALS['recherche'])) { |
|
| 70 | - $recherche = $GLOBALS['recherche']; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // traiter le cas {recherche?} |
|
| 74 | - if ($cond and !strlen($recherche)) { |
|
| 75 | - return [ |
|
| 76 | - '0 as points' /* as points */, /* where */ |
|
| 77 | - '' |
|
| 78 | - ]; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - $rechercher = false; |
|
| 83 | - |
|
| 84 | - $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND'); |
|
| 85 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 86 | - $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 87 | - $hash = substr(md5($recherche . $table), 0, 16); |
|
| 88 | - $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 89 | - $row = sql_fetsel( |
|
| 90 | - 'recherche', |
|
| 91 | - 'spip_resultats AS resultats', |
|
| 92 | - $where . " AND $where_resultat_recent", |
|
| 93 | - '', |
|
| 94 | - '', |
|
| 95 | - '0,1' |
|
| 96 | - ); |
|
| 97 | - if ( |
|
| 98 | - !$row |
|
| 99 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 100 | - ) { |
|
| 101 | - $rechercher = true; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 106 | - if ($rechercher) { |
|
| 107 | - //$tables = liste_des_champs(); |
|
| 108 | - $x = objet_type($table); |
|
| 109 | - $points = recherche_en_base( |
|
| 110 | - $recherche, |
|
| 111 | - $x, |
|
| 112 | - [ |
|
| 113 | - 'score' => true, |
|
| 114 | - 'toutvoir' => true, |
|
| 115 | - 'jointures' => true |
|
| 116 | - ], |
|
| 117 | - $serveur |
|
| 118 | - ); |
|
| 119 | - // pas de résultat, pas de point |
|
| 120 | - $points = $points[$x] ?? []; |
|
| 121 | - |
|
| 122 | - // permettre aux plugins de modifier le resultat |
|
| 123 | - $points = pipeline('prepare_recherche', [ |
|
| 124 | - 'args' => [ |
|
| 125 | - 'type' => $x, |
|
| 126 | - 'recherche' => $recherche, |
|
| 127 | - 'serveur' => $serveur, |
|
| 128 | - 'modificateurs' => $modificateurs |
|
| 129 | - ], |
|
| 130 | - 'data' => $points |
|
| 131 | - ]); |
|
| 132 | - |
|
| 133 | - // supprimer les anciens resultats de cette recherche |
|
| 134 | - // et les resultats trop vieux avec une marge |
|
| 135 | - // pas de AS resultats dans un delete (mysql) |
|
| 136 | - $whered = str_replace( |
|
| 137 | - ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'], |
|
| 138 | - ['recherche', 'table_objet', 'serveur'], |
|
| 139 | - $where |
|
| 140 | - ); |
|
| 141 | - |
|
| 142 | - sql_delete( |
|
| 143 | - 'spip_resultats', |
|
| 144 | - "NOT($where_resultat_recent) OR ($whered)" |
|
| 145 | - ); |
|
| 146 | - |
|
| 147 | - // inserer les resultats dans la table de cache des resultats |
|
| 148 | - if (is_countable($points) ? count($points) : 0) { |
|
| 149 | - $tab_couples = []; |
|
| 150 | - foreach ($points as $id => $p) { |
|
| 151 | - $tab_couples[] = [ |
|
| 152 | - 'recherche' => $hash, |
|
| 153 | - 'id' => $id, |
|
| 154 | - 'points' => $p['score'], |
|
| 155 | - 'table_objet' => $table, |
|
| 156 | - 'serveur' => $hash_serv, |
|
| 157 | - ]; |
|
| 158 | - } |
|
| 159 | - sql_insertq_multi('spip_resultats', $tab_couples, []); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 164 | - if (!$serveur) { |
|
| 165 | - $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where]; |
|
| 166 | - } else { |
|
| 167 | - if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 168 | - $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 169 | - } |
|
| 170 | - $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - return $cache[$serveur][$table][$recherche]; |
|
| 59 | + $where = null; |
|
| 60 | + $rows = null; |
|
| 61 | + static $cache = []; |
|
| 62 | + $delai_fraicheur = min( |
|
| 63 | + \_DELAI_CACHE_resultats, |
|
| 64 | + time() - ($GLOBALS['meta']['derniere_modif'] ?? 0) |
|
| 65 | + ); |
|
| 66 | + |
|
| 67 | + // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 68 | + // ca permet de faire des inclure simple. |
|
| 69 | + if (!isset($recherche) and isset($GLOBALS['recherche'])) { |
|
| 70 | + $recherche = $GLOBALS['recherche']; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // traiter le cas {recherche?} |
|
| 74 | + if ($cond and !strlen($recherche)) { |
|
| 75 | + return [ |
|
| 76 | + '0 as points' /* as points */, /* where */ |
|
| 77 | + '' |
|
| 78 | + ]; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + $rechercher = false; |
|
| 83 | + |
|
| 84 | + $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND'); |
|
| 85 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 86 | + $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 87 | + $hash = substr(md5($recherche . $table), 0, 16); |
|
| 88 | + $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 89 | + $row = sql_fetsel( |
|
| 90 | + 'recherche', |
|
| 91 | + 'spip_resultats AS resultats', |
|
| 92 | + $where . " AND $where_resultat_recent", |
|
| 93 | + '', |
|
| 94 | + '', |
|
| 95 | + '0,1' |
|
| 96 | + ); |
|
| 97 | + if ( |
|
| 98 | + !$row |
|
| 99 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 100 | + ) { |
|
| 101 | + $rechercher = true; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 106 | + if ($rechercher) { |
|
| 107 | + //$tables = liste_des_champs(); |
|
| 108 | + $x = objet_type($table); |
|
| 109 | + $points = recherche_en_base( |
|
| 110 | + $recherche, |
|
| 111 | + $x, |
|
| 112 | + [ |
|
| 113 | + 'score' => true, |
|
| 114 | + 'toutvoir' => true, |
|
| 115 | + 'jointures' => true |
|
| 116 | + ], |
|
| 117 | + $serveur |
|
| 118 | + ); |
|
| 119 | + // pas de résultat, pas de point |
|
| 120 | + $points = $points[$x] ?? []; |
|
| 121 | + |
|
| 122 | + // permettre aux plugins de modifier le resultat |
|
| 123 | + $points = pipeline('prepare_recherche', [ |
|
| 124 | + 'args' => [ |
|
| 125 | + 'type' => $x, |
|
| 126 | + 'recherche' => $recherche, |
|
| 127 | + 'serveur' => $serveur, |
|
| 128 | + 'modificateurs' => $modificateurs |
|
| 129 | + ], |
|
| 130 | + 'data' => $points |
|
| 131 | + ]); |
|
| 132 | + |
|
| 133 | + // supprimer les anciens resultats de cette recherche |
|
| 134 | + // et les resultats trop vieux avec une marge |
|
| 135 | + // pas de AS resultats dans un delete (mysql) |
|
| 136 | + $whered = str_replace( |
|
| 137 | + ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'], |
|
| 138 | + ['recherche', 'table_objet', 'serveur'], |
|
| 139 | + $where |
|
| 140 | + ); |
|
| 141 | + |
|
| 142 | + sql_delete( |
|
| 143 | + 'spip_resultats', |
|
| 144 | + "NOT($where_resultat_recent) OR ($whered)" |
|
| 145 | + ); |
|
| 146 | + |
|
| 147 | + // inserer les resultats dans la table de cache des resultats |
|
| 148 | + if (is_countable($points) ? count($points) : 0) { |
|
| 149 | + $tab_couples = []; |
|
| 150 | + foreach ($points as $id => $p) { |
|
| 151 | + $tab_couples[] = [ |
|
| 152 | + 'recherche' => $hash, |
|
| 153 | + 'id' => $id, |
|
| 154 | + 'points' => $p['score'], |
|
| 155 | + 'table_objet' => $table, |
|
| 156 | + 'serveur' => $hash_serv, |
|
| 157 | + ]; |
|
| 158 | + } |
|
| 159 | + sql_insertq_multi('spip_resultats', $tab_couples, []); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 164 | + if (!$serveur) { |
|
| 165 | + $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where]; |
|
| 166 | + } else { |
|
| 167 | + if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 168 | + $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 169 | + } |
|
| 170 | + $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + return $cache[$serveur][$table][$recherche]; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | |
@@ -187,22 +187,22 @@ discard block |
||
| 187 | 187 | * @return array |
| 188 | 188 | */ |
| 189 | 189 | function generer_select_where_explicites($table, $primary, $rows, $serveur) { |
| 190 | - # calculer le {id_article IN()} et le {... as points} |
|
| 191 | - if (!count($rows)) { |
|
| 192 | - return ["''", '0=1']; |
|
| 193 | - } else { |
|
| 194 | - $listes_ids = []; |
|
| 195 | - $select = '0'; |
|
| 196 | - foreach ($rows as $r) { |
|
| 197 | - $listes_ids[$r['points']][] = $r['id']; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - foreach ($listes_ids as $p => $ids) { |
|
| 201 | - $select .= "+$p*(" . |
|
| 202 | - sql_in("$table.$primary", $ids, '', $serveur) |
|
| 203 | - . ') '; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)]; |
|
| 207 | - } |
|
| 190 | + # calculer le {id_article IN()} et le {... as points} |
|
| 191 | + if (!count($rows)) { |
|
| 192 | + return ["''", '0=1']; |
|
| 193 | + } else { |
|
| 194 | + $listes_ids = []; |
|
| 195 | + $select = '0'; |
|
| 196 | + foreach ($rows as $r) { |
|
| 197 | + $listes_ids[$r['points']][] = $r['id']; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + foreach ($listes_ids as $p => $ids) { |
|
| 201 | + $select .= "+$p*(" . |
|
| 202 | + sql_in("$table.$primary", $ids, '', $serveur) |
|
| 203 | + . ') '; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)]; |
|
| 207 | + } |
|
| 208 | 208 | } |