@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('base/serial'); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * en droit de l'éliminer |
| 27 | 27 | */ |
| 28 | 28 | if (!defined('_AGE_CACHE_ATIME')) { |
| 29 | - define('_AGE_CACHE_ATIME', 3600); |
|
| 29 | + define('_AGE_CACHE_ATIME', 3600); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | |
@@ -39,31 +39,31 @@ discard block |
||
| 39 | 39 | * @return int Taille approximative en octets |
| 40 | 40 | **/ |
| 41 | 41 | function taille_du_cache() { |
| 42 | - # check dirs until we reach > 500 files |
|
| 43 | - $t = 0; |
|
| 44 | - $n = 0; |
|
| 45 | - $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
|
| 46 | - for ($i = 0; $i < 256; $i++) { |
|
| 47 | - $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 48 | - if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 49 | - while (($f = readdir($d)) !== false) { |
|
| 50 | - if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) && ($a = stat("$dir/$f"))) { |
|
| 51 | - $n++; |
|
| 52 | - if ($a['mtime'] >= $time) { |
|
| 53 | - if ($a['blocks'] > 0) { |
|
| 54 | - $t += 512 * $a['blocks']; |
|
| 55 | - } else { |
|
| 56 | - $t += $a['size']; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - if ($n > 500) { |
|
| 63 | - return (int) (256 * $t / (1 + $i)); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - return $t; |
|
| 42 | + # check dirs until we reach > 500 files |
|
| 43 | + $t = 0; |
|
| 44 | + $n = 0; |
|
| 45 | + $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
|
| 46 | + for ($i = 0; $i < 256; $i++) { |
|
| 47 | + $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 48 | + if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
|
| 49 | + while (($f = readdir($d)) !== false) { |
|
| 50 | + if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) && ($a = stat("$dir/$f"))) { |
|
| 51 | + $n++; |
|
| 52 | + if ($a['mtime'] >= $time) { |
|
| 53 | + if ($a['blocks'] > 0) { |
|
| 54 | + $t += 512 * $a['blocks']; |
|
| 55 | + } else { |
|
| 56 | + $t += $a['size']; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + if ($n > 500) { |
|
| 63 | + return (int) (256 * $t / (1 + $i)); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + return $t; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | |
@@ -90,30 +90,30 @@ discard block |
||
| 90 | 90 | * Inutilisé |
| 91 | 91 | **/ |
| 92 | 92 | function inc_suivre_invalideur_dist($cond, $modif = true) { |
| 93 | - if (!$modif) { |
|
| 94 | - return; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // determiner l'objet modifie : forum, article, etc |
|
| 98 | - if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 99 | - $objet = objet_type($r[1]); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 103 | - if (isset($objet)) { |
|
| 104 | - ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 108 | - // n'affecter la meta que si un de ces objets est modifie |
|
| 109 | - if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 110 | - if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 111 | - ecrire_meta('derniere_modif', time()); |
|
| 112 | - } |
|
| 113 | - } // sinon, cas standard, toujours affecter la meta |
|
| 114 | - else { |
|
| 115 | - ecrire_meta('derniere_modif', time()); |
|
| 116 | - } |
|
| 93 | + if (!$modif) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // determiner l'objet modifie : forum, article, etc |
|
| 98 | + if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 99 | + $objet = objet_type($r[1]); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 103 | + if (isset($objet)) { |
|
| 104 | + ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 108 | + // n'affecter la meta que si un de ces objets est modifie |
|
| 109 | + if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 110 | + if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 111 | + ecrire_meta('derniere_modif', time()); |
|
| 112 | + } |
|
| 113 | + } // sinon, cas standard, toujours affecter la meta |
|
| 114 | + else { |
|
| 115 | + ecrire_meta('derniere_modif', time()); |
|
| 116 | + } |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | |
@@ -138,56 +138,56 @@ discard block |
||
| 138 | 138 | * Nombre de fichiers supprimés |
| 139 | 139 | **/ |
| 140 | 140 | function purger_repertoire($dir, $options = []) { |
| 141 | - if (!is_dir($dir) || !is_readable($dir)) { |
|
| 142 | - return 0; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
|
| 146 | - // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
|
| 147 | - if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 148 | - return 0; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - $handle = opendir($dir); |
|
| 152 | - if (!$handle) { |
|
| 153 | - return 0; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $total = 0; |
|
| 157 | - |
|
| 158 | - while (($fichier = @readdir($handle)) !== false) { |
|
| 159 | - // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 160 | - if ($fichier[0] == '.' || $fichier == 'CACHEDIR.TAG') { |
|
| 161 | - continue; |
|
| 162 | - } |
|
| 163 | - $chemin = "$dir/$fichier"; |
|
| 164 | - if (is_file($chemin)) { |
|
| 165 | - if ( |
|
| 166 | - (!isset($options['atime']) || @fileatime($chemin) < $options['atime']) && (!isset($options['mtime']) || @filemtime($chemin) < $options['mtime']) |
|
| 167 | - ) { |
|
| 168 | - supprimer_fichier($chemin); |
|
| 169 | - $total++; |
|
| 170 | - } |
|
| 171 | - } else { |
|
| 172 | - if (is_dir($chemin)) { |
|
| 173 | - $opts = $options; |
|
| 174 | - if (isset($options['limit'])) { |
|
| 175 | - $opts['limit'] = $options['limit'] - $total; |
|
| 176 | - } |
|
| 177 | - $total += purger_repertoire($chemin, $opts); |
|
| 178 | - if (isset($options['subdir']) && $options['subdir']) { |
|
| 179 | - spip_unlink($chemin); |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if (isset($options['limit']) && $total >= $options['limit']) { |
|
| 185 | - break; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - closedir($handle); |
|
| 189 | - |
|
| 190 | - return $total; |
|
| 141 | + if (!is_dir($dir) || !is_readable($dir)) { |
|
| 142 | + return 0; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
|
| 146 | + // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
|
| 147 | + if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 148 | + return 0; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + $handle = opendir($dir); |
|
| 152 | + if (!$handle) { |
|
| 153 | + return 0; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $total = 0; |
|
| 157 | + |
|
| 158 | + while (($fichier = @readdir($handle)) !== false) { |
|
| 159 | + // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 160 | + if ($fichier[0] == '.' || $fichier == 'CACHEDIR.TAG') { |
|
| 161 | + continue; |
|
| 162 | + } |
|
| 163 | + $chemin = "$dir/$fichier"; |
|
| 164 | + if (is_file($chemin)) { |
|
| 165 | + if ( |
|
| 166 | + (!isset($options['atime']) || @fileatime($chemin) < $options['atime']) && (!isset($options['mtime']) || @filemtime($chemin) < $options['mtime']) |
|
| 167 | + ) { |
|
| 168 | + supprimer_fichier($chemin); |
|
| 169 | + $total++; |
|
| 170 | + } |
|
| 171 | + } else { |
|
| 172 | + if (is_dir($chemin)) { |
|
| 173 | + $opts = $options; |
|
| 174 | + if (isset($options['limit'])) { |
|
| 175 | + $opts['limit'] = $options['limit'] - $total; |
|
| 176 | + } |
|
| 177 | + $total += purger_repertoire($chemin, $opts); |
|
| 178 | + if (isset($options['subdir']) && $options['subdir']) { |
|
| 179 | + spip_unlink($chemin); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if (isset($options['limit']) && $total >= $options['limit']) { |
|
| 185 | + break; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + closedir($handle); |
|
| 189 | + |
|
| 190 | + return $total; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -198,26 +198,26 @@ discard block |
||
| 198 | 198 | // Securite : est sur que c'est un cache |
| 199 | 199 | function retire_cache($cache) { |
| 200 | 200 | |
| 201 | - if ( |
|
| 202 | - preg_match( |
|
| 203 | - ',^([0-9a-f]/)?(\d+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 204 | - (string) $cache |
|
| 205 | - ) |
|
| 206 | - ) { |
|
| 207 | - // supprimer le fichier (de facon propre) |
|
| 208 | - supprimer_fichier(_DIR_CACHE . $cache); |
|
| 209 | - } else { |
|
| 210 | - spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 211 | - } |
|
| 201 | + if ( |
|
| 202 | + preg_match( |
|
| 203 | + ',^([0-9a-f]/)?(\d+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 204 | + (string) $cache |
|
| 205 | + ) |
|
| 206 | + ) { |
|
| 207 | + // supprimer le fichier (de facon propre) |
|
| 208 | + supprimer_fichier(_DIR_CACHE . $cache); |
|
| 209 | + } else { |
|
| 210 | + spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 211 | + } |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | // Supprimer les caches marques "x" |
| 215 | 215 | // A priori dans cette version la fonction ne sera pas appelee, car |
| 216 | 216 | // la meta est toujours false ; mais evitons un bug si elle est appellee |
| 217 | 217 | function inc_retire_caches_dist($chemin = '') { |
| 218 | - if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 219 | - effacer_meta('invalider_caches'); |
|
| 220 | - } # concurrence |
|
| 218 | + if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 219 | + effacer_meta('invalider_caches'); |
|
| 220 | + } # concurrence |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | ####################################################################### |
@@ -228,9 +228,9 @@ discard block |
||
| 228 | 228 | ## |
| 229 | 229 | |
| 230 | 230 | function retire_caches($chemin = '') { |
| 231 | - if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 232 | - return $retire_caches($chemin); |
|
| 233 | - } |
|
| 231 | + if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 232 | + return $retire_caches($chemin); |
|
| 233 | + } |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
@@ -238,10 +238,10 @@ discard block |
||
| 238 | 238 | // (note: si absente, n'est pas appellee) |
| 239 | 239 | |
| 240 | 240 | function calcul_invalideurs($corps, $primary, &$boucles, $id_boucle) { |
| 241 | - if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 242 | - return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 243 | - } |
|
| 244 | - return $corps; |
|
| 241 | + if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 242 | + return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 243 | + } |
|
| 244 | + return $corps; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
@@ -250,41 +250,41 @@ discard block |
||
| 250 | 250 | // invoquee quand on vide tout le cache en bloc (action/purger) |
| 251 | 251 | // |
| 252 | 252 | function supprime_invalideurs() { |
| 253 | - if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 254 | - return $supprime_invalideurs(); |
|
| 255 | - } |
|
| 253 | + if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 254 | + return $supprime_invalideurs(); |
|
| 255 | + } |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | |
| 259 | 259 | // Calcul des pages : noter dans la base les liens d'invalidation |
| 260 | 260 | function maj_invalideurs($fichier, &$page) { |
| 261 | - if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 262 | - return $maj_invalideurs($fichier, $page); |
|
| 263 | - } |
|
| 261 | + if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 262 | + return $maj_invalideurs($fichier, $page); |
|
| 263 | + } |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | |
| 267 | 267 | // les invalideurs sont de la forme "objet/id_objet" |
| 268 | 268 | function insere_invalideur($inval, $fichier) { |
| 269 | - if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 270 | - return $insere_invalideur($inval, $fichier); |
|
| 271 | - } |
|
| 269 | + if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 270 | + return $insere_invalideur($inval, $fichier); |
|
| 271 | + } |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // |
| 275 | 275 | // Marquer les fichiers caches invalides comme etant a supprimer |
| 276 | 276 | // |
| 277 | 277 | function applique_invalideur($depart) { |
| 278 | - if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 279 | - return $applique_invalideur($depart); |
|
| 280 | - } |
|
| 278 | + if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 279 | + return $applique_invalideur($depart); |
|
| 280 | + } |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // |
| 284 | 284 | // Invalider les caches liés à telle condition |
| 285 | 285 | // |
| 286 | 286 | function suivre_invalideur($cond, $modif = true) { |
| 287 | - if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 288 | - return $suivre_invalideur($cond, $modif); |
|
| 289 | - } |
|
| 287 | + if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 288 | + return $suivre_invalideur($cond, $modif); |
|
| 289 | + } |
|
| 290 | 290 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $n = 0; |
| 45 | 45 | $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
| 46 | 46 | for ($i = 0; $i < 256; $i++) { |
| 47 | - $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 47 | + $dir = _DIR_CACHE.sprintf('%02s', dechex($i)); |
|
| 48 | 48 | if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) { |
| 49 | 49 | while (($f = readdir($d)) !== false) { |
| 50 | 50 | if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) && ($a = stat("$dir/$f"))) { |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | // stocker la date_modif_$objet (ne sert a rien pour le moment) |
| 103 | 103 | if (isset($objet)) { |
| 104 | - ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 104 | + ecrire_meta('derniere_modif_'.$objet, time()); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // si $derniere_modif_invalide est un array('article', 'rubrique') |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
| 146 | 146 | // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
| 147 | - if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 147 | + if (file_exists(rtrim($dir, '/').'/inhib_purger_repertoire.txt')) { |
|
| 148 | 148 | return 0; |
| 149 | 149 | } |
| 150 | 150 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | ) |
| 206 | 206 | ) { |
| 207 | 207 | // supprimer le fichier (de facon propre) |
| 208 | - supprimer_fichier(_DIR_CACHE . $cache); |
|
| 208 | + supprimer_fichier(_DIR_CACHE.$cache); |
|
| 209 | 209 | } else { |
| 210 | 210 | spip_log("Nom de fichier cache incorrect : $cache"); |
| 211 | 211 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | // securité |
| 23 | 23 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // se faciliter la lecture du charset |
@@ -31,19 +31,19 @@ discard block |
||
| 31 | 31 | * Initialisation |
| 32 | 32 | */ |
| 33 | 33 | function init_charset(): void { |
| 34 | - // Initialisation |
|
| 35 | - $GLOBALS['CHARSET'] = []; |
|
| 36 | - |
|
| 37 | - // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u |
|
| 38 | - // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
|
| 39 | - // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
|
| 40 | - if ( |
|
| 41 | - !isset($GLOBALS['meta']['pcre_u']) |
|
| 42 | - || isset($_GET['var_mode']) && !isset($_GET['var_profile']) |
|
| 43 | - ) { |
|
| 44 | - include_spip('inc/meta'); |
|
| 45 | - ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : ''); |
|
| 46 | - } |
|
| 34 | + // Initialisation |
|
| 35 | + $GLOBALS['CHARSET'] = []; |
|
| 36 | + |
|
| 37 | + // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u |
|
| 38 | + // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
|
| 39 | + // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
|
| 40 | + if ( |
|
| 41 | + !isset($GLOBALS['meta']['pcre_u']) |
|
| 42 | + || isset($_GET['var_mode']) && !isset($_GET['var_profile']) |
|
| 43 | + ) { |
|
| 44 | + include_spip('inc/meta'); |
|
| 45 | + ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : ''); |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | // TODO: code d’exécution en dehors du fichier. |
@@ -64,39 +64,39 @@ discard block |
||
| 64 | 64 | * - false si le charset n'est pas décrit dans le répertoire charsets/ |
| 65 | 65 | **/ |
| 66 | 66 | function load_charset($charset = 'AUTO') { |
| 67 | - if ($charset == 'AUTO') { |
|
| 68 | - $charset = $GLOBALS['meta']['charset']; |
|
| 69 | - } |
|
| 70 | - $charset = trim(strtolower((string) $charset)); |
|
| 71 | - if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 72 | - return $charset; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - if ($charset == 'utf-8') { |
|
| 76 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 77 | - |
|
| 78 | - return $charset; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // Quelques synonymes |
|
| 82 | - if ($charset === '') { |
|
| 83 | - $charset = 'iso-8859-1'; |
|
| 84 | - } elseif ($charset === 'windows-1250') { |
|
| 85 | - $charset = 'cp1250'; |
|
| 86 | - } elseif ($charset === 'windows-1251') { |
|
| 87 | - $charset = 'cp1251'; |
|
| 88 | - } elseif ($charset === 'windows-1256') { |
|
| 89 | - $charset = 'cp1256'; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 93 | - return $charset; |
|
| 94 | - } else { |
|
| 95 | - spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 96 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 97 | - |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 67 | + if ($charset == 'AUTO') { |
|
| 68 | + $charset = $GLOBALS['meta']['charset']; |
|
| 69 | + } |
|
| 70 | + $charset = trim(strtolower((string) $charset)); |
|
| 71 | + if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 72 | + return $charset; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + if ($charset == 'utf-8') { |
|
| 76 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 77 | + |
|
| 78 | + return $charset; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // Quelques synonymes |
|
| 82 | + if ($charset === '') { |
|
| 83 | + $charset = 'iso-8859-1'; |
|
| 84 | + } elseif ($charset === 'windows-1250') { |
|
| 85 | + $charset = 'cp1250'; |
|
| 86 | + } elseif ($charset === 'windows-1251') { |
|
| 87 | + $charset = 'cp1251'; |
|
| 88 | + } elseif ($charset === 'windows-1256') { |
|
| 89 | + $charset = 'cp1256'; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 93 | + return $charset; |
|
| 94 | + } else { |
|
| 95 | + spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 96 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 97 | + |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
@@ -109,19 +109,19 @@ discard block |
||
| 109 | 109 | * true si notre charset est utilisable par mb_strsing |
| 110 | 110 | **/ |
| 111 | 111 | function init_mb_string(): bool { |
| 112 | - static $mb; |
|
| 113 | - |
|
| 114 | - // verifier que le charset interne est connu de mb_string |
|
| 115 | - if (!$mb) { |
|
| 116 | - if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) { |
|
| 117 | - mb_internal_encoding('utf-8'); |
|
| 118 | - $mb = 1; |
|
| 119 | - } else { |
|
| 120 | - $mb = -1; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return ($mb === 1); |
|
| 112 | + static $mb; |
|
| 113 | + |
|
| 114 | + // verifier que le charset interne est connu de mb_string |
|
| 115 | + if (!$mb) { |
|
| 116 | + if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) { |
|
| 117 | + mb_internal_encoding('utf-8'); |
|
| 118 | + $mb = 1; |
|
| 119 | + } else { |
|
| 120 | + $mb = -1; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return ($mb === 1); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -136,17 +136,17 @@ discard block |
||
| 136 | 136 | * true si iconv fonctionne correctement |
| 137 | 137 | **/ |
| 138 | 138 | function test_iconv(): bool { |
| 139 | - static $iconv_ok; |
|
| 139 | + static $iconv_ok; |
|
| 140 | 140 | |
| 141 | - if (!$iconv_ok) { |
|
| 142 | - if (!function_exists('iconv')) { |
|
| 143 | - $iconv_ok = -1; |
|
| 144 | - } else { |
|
| 145 | - $iconv_ok = utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test' ? 1 : -1; |
|
| 146 | - } |
|
| 147 | - } |
|
| 141 | + if (!$iconv_ok) { |
|
| 142 | + if (!function_exists('iconv')) { |
|
| 143 | + $iconv_ok = -1; |
|
| 144 | + } else { |
|
| 145 | + $iconv_ok = utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test' ? 1 : -1; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - return ($iconv_ok === 1); |
|
| 149 | + return ($iconv_ok === 1); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -166,75 +166,75 @@ discard block |
||
| 166 | 166 | * texte corrigé |
| 167 | 167 | **/ |
| 168 | 168 | function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') { |
| 169 | - static $trans; |
|
| 170 | - |
|
| 171 | - if (is_array($texte)) { |
|
| 172 | - return array_map('corriger_caracteres_windows', $texte); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if ($charset == 'AUTO') { |
|
| 176 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 177 | - } |
|
| 178 | - if ($charset == 'utf-8') { |
|
| 179 | - $p = chr(194); |
|
| 180 | - if (!str_contains($texte, $p)) { |
|
| 181 | - return $texte; |
|
| 182 | - } |
|
| 183 | - } else { |
|
| 184 | - if ($charset == 'iso-8859-1') { |
|
| 185 | - $p = ''; |
|
| 186 | - } else { |
|
| 187 | - return $texte; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - if (!isset($trans[$charset][$charset_cible])) { |
|
| 192 | - $trans[$charset][$charset_cible] = [ |
|
| 193 | - $p . chr(128) => '€', |
|
| 194 | - $p . chr(129) => ' ', # pas affecte |
|
| 195 | - $p . chr(130) => '‚', |
|
| 196 | - $p . chr(131) => 'ƒ', |
|
| 197 | - $p . chr(132) => '„', |
|
| 198 | - $p . chr(133) => '…', |
|
| 199 | - $p . chr(134) => '†', |
|
| 200 | - $p . chr(135) => '‡', |
|
| 201 | - $p . chr(136) => 'ˆ', |
|
| 202 | - $p . chr(137) => '‰', |
|
| 203 | - $p . chr(138) => 'Š', |
|
| 204 | - $p . chr(139) => '‹', |
|
| 205 | - $p . chr(140) => 'Œ', |
|
| 206 | - $p . chr(141) => ' ', # pas affecte |
|
| 207 | - $p . chr(142) => 'Ž', |
|
| 208 | - $p . chr(143) => ' ', # pas affecte |
|
| 209 | - $p . chr(144) => ' ', # pas affecte |
|
| 210 | - $p . chr(145) => '‘', |
|
| 211 | - $p . chr(146) => '’', |
|
| 212 | - $p . chr(147) => '“', |
|
| 213 | - $p . chr(148) => '”', |
|
| 214 | - $p . chr(149) => '•', |
|
| 215 | - $p . chr(150) => '–', |
|
| 216 | - $p . chr(151) => '—', |
|
| 217 | - $p . chr(152) => '˜', |
|
| 218 | - $p . chr(153) => '™', |
|
| 219 | - $p . chr(154) => 'š', |
|
| 220 | - $p . chr(155) => '›', |
|
| 221 | - $p . chr(156) => 'œ', |
|
| 222 | - $p . chr(157) => ' ', # pas affecte |
|
| 223 | - $p . chr(158) => 'ž', |
|
| 224 | - $p . chr(159) => 'Ÿ', |
|
| 225 | - ]; |
|
| 226 | - if ($charset_cible != 'unicode') { |
|
| 227 | - foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 228 | - $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - return @str_replace( |
|
| 234 | - array_keys($trans[$charset][$charset_cible]), |
|
| 235 | - array_values($trans[$charset][$charset_cible]), |
|
| 236 | - $texte |
|
| 237 | - ); |
|
| 169 | + static $trans; |
|
| 170 | + |
|
| 171 | + if (is_array($texte)) { |
|
| 172 | + return array_map('corriger_caracteres_windows', $texte); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if ($charset == 'AUTO') { |
|
| 176 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 177 | + } |
|
| 178 | + if ($charset == 'utf-8') { |
|
| 179 | + $p = chr(194); |
|
| 180 | + if (!str_contains($texte, $p)) { |
|
| 181 | + return $texte; |
|
| 182 | + } |
|
| 183 | + } else { |
|
| 184 | + if ($charset == 'iso-8859-1') { |
|
| 185 | + $p = ''; |
|
| 186 | + } else { |
|
| 187 | + return $texte; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if (!isset($trans[$charset][$charset_cible])) { |
|
| 192 | + $trans[$charset][$charset_cible] = [ |
|
| 193 | + $p . chr(128) => '€', |
|
| 194 | + $p . chr(129) => ' ', # pas affecte |
|
| 195 | + $p . chr(130) => '‚', |
|
| 196 | + $p . chr(131) => 'ƒ', |
|
| 197 | + $p . chr(132) => '„', |
|
| 198 | + $p . chr(133) => '…', |
|
| 199 | + $p . chr(134) => '†', |
|
| 200 | + $p . chr(135) => '‡', |
|
| 201 | + $p . chr(136) => 'ˆ', |
|
| 202 | + $p . chr(137) => '‰', |
|
| 203 | + $p . chr(138) => 'Š', |
|
| 204 | + $p . chr(139) => '‹', |
|
| 205 | + $p . chr(140) => 'Œ', |
|
| 206 | + $p . chr(141) => ' ', # pas affecte |
|
| 207 | + $p . chr(142) => 'Ž', |
|
| 208 | + $p . chr(143) => ' ', # pas affecte |
|
| 209 | + $p . chr(144) => ' ', # pas affecte |
|
| 210 | + $p . chr(145) => '‘', |
|
| 211 | + $p . chr(146) => '’', |
|
| 212 | + $p . chr(147) => '“', |
|
| 213 | + $p . chr(148) => '”', |
|
| 214 | + $p . chr(149) => '•', |
|
| 215 | + $p . chr(150) => '–', |
|
| 216 | + $p . chr(151) => '—', |
|
| 217 | + $p . chr(152) => '˜', |
|
| 218 | + $p . chr(153) => '™', |
|
| 219 | + $p . chr(154) => 'š', |
|
| 220 | + $p . chr(155) => '›', |
|
| 221 | + $p . chr(156) => 'œ', |
|
| 222 | + $p . chr(157) => ' ', # pas affecte |
|
| 223 | + $p . chr(158) => 'ž', |
|
| 224 | + $p . chr(159) => 'Ÿ', |
|
| 225 | + ]; |
|
| 226 | + if ($charset_cible != 'unicode') { |
|
| 227 | + foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 228 | + $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + return @str_replace( |
|
| 234 | + array_keys($trans[$charset][$charset_cible]), |
|
| 235 | + array_values($trans[$charset][$charset_cible]), |
|
| 236 | + $texte |
|
| 237 | + ); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | |
@@ -251,26 +251,26 @@ discard block |
||
| 251 | 251 | * texte converti |
| 252 | 252 | **/ |
| 253 | 253 | function html2unicode($texte, $secure = false) { |
| 254 | - if (!str_contains($texte, '&')) { |
|
| 255 | - return $texte; |
|
| 256 | - } |
|
| 257 | - static $trans = []; |
|
| 258 | - if (!$trans) { |
|
| 259 | - load_charset('html'); |
|
| 260 | - foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 261 | - $trans["&$key;"] = $val; |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - if ($secure) { |
|
| 266 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 267 | - } else { |
|
| 268 | - return str_replace( |
|
| 269 | - ['&', '"', '<', '>'], |
|
| 270 | - ['&', '"', '<', '>'], |
|
| 271 | - str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 272 | - ); |
|
| 273 | - } |
|
| 254 | + if (!str_contains($texte, '&')) { |
|
| 255 | + return $texte; |
|
| 256 | + } |
|
| 257 | + static $trans = []; |
|
| 258 | + if (!$trans) { |
|
| 259 | + load_charset('html'); |
|
| 260 | + foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 261 | + $trans["&$key;"] = $val; |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + if ($secure) { |
|
| 266 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 267 | + } else { |
|
| 268 | + return str_replace( |
|
| 269 | + ['&', '"', '<', '>'], |
|
| 270 | + ['&', '"', '<', '>'], |
|
| 271 | + str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 272 | + ); |
|
| 273 | + } |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -285,16 +285,16 @@ discard block |
||
| 285 | 285 | * texte converti |
| 286 | 286 | **/ |
| 287 | 287 | function mathml2unicode($texte) { |
| 288 | - static $trans; |
|
| 289 | - if (!$trans) { |
|
| 290 | - load_charset('mathml'); |
|
| 288 | + static $trans; |
|
| 289 | + if (!$trans) { |
|
| 290 | + load_charset('mathml'); |
|
| 291 | 291 | |
| 292 | - foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 293 | - $trans["&$key;"] = $val; |
|
| 294 | - } |
|
| 295 | - } |
|
| 292 | + foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 293 | + $trans["&$key;"] = $val; |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 297 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
@@ -316,70 +316,70 @@ discard block |
||
| 316 | 316 | * texte converti en unicode |
| 317 | 317 | **/ |
| 318 | 318 | function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) { |
| 319 | - static $trans; |
|
| 320 | - |
|
| 321 | - if ($charset === 'AUTO') { |
|
| 322 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - if ($charset === '') { |
|
| 326 | - $charset = 'iso-8859-1'; |
|
| 327 | - } |
|
| 328 | - $charset = strtolower((string) $charset); |
|
| 329 | - |
|
| 330 | - switch ($charset) { |
|
| 331 | - case 'utf-8': |
|
| 332 | - case 'utf8': |
|
| 333 | - return utf_8_to_unicode($texte); |
|
| 334 | - |
|
| 335 | - case 'iso-8859-1': |
|
| 336 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 337 | - // pas de break; ici, on suit sur default: |
|
| 338 | - |
|
| 339 | - default: |
|
| 340 | - // mbstring presente ? |
|
| 341 | - if (init_mb_string()) { |
|
| 342 | - $order = mb_detect_order(); |
|
| 343 | - try { |
|
| 344 | - # mb_string connait-il $charset? |
|
| 345 | - if ($order && mb_detect_order($charset)) { |
|
| 346 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 347 | - if ($s && $s != $texte) { |
|
| 348 | - return utf_8_to_unicode($s); |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - } catch (\Error) { |
|
| 352 | - // Le charset n'existe probablement pas |
|
| 353 | - } finally { |
|
| 354 | - mb_detect_order($order); # remettre comme precedemment |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 359 | - if (!isset($trans[$charset]) && (($cset = load_charset($charset)) && is_array($GLOBALS['CHARSET'][$cset]))) { |
|
| 360 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 361 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - if (isset($trans[$charset]) && (is_countable($trans[$charset]) ? count($trans[$charset]) : 0)) { |
|
| 365 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 369 | - // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 370 | - // surtout en utf-8, gere ci-dessus) |
|
| 371 | - if (test_iconv()) { |
|
| 372 | - $s = iconv($charset, 'utf-32le', $texte); |
|
| 373 | - if ($s) { |
|
| 374 | - return utf_32_to_unicode($s); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // Au pire ne rien faire |
|
| 379 | - spip_log("erreur charset '$charset' non supporte"); |
|
| 380 | - |
|
| 381 | - return $texte; |
|
| 382 | - } |
|
| 319 | + static $trans; |
|
| 320 | + |
|
| 321 | + if ($charset === 'AUTO') { |
|
| 322 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + if ($charset === '') { |
|
| 326 | + $charset = 'iso-8859-1'; |
|
| 327 | + } |
|
| 328 | + $charset = strtolower((string) $charset); |
|
| 329 | + |
|
| 330 | + switch ($charset) { |
|
| 331 | + case 'utf-8': |
|
| 332 | + case 'utf8': |
|
| 333 | + return utf_8_to_unicode($texte); |
|
| 334 | + |
|
| 335 | + case 'iso-8859-1': |
|
| 336 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 337 | + // pas de break; ici, on suit sur default: |
|
| 338 | + |
|
| 339 | + default: |
|
| 340 | + // mbstring presente ? |
|
| 341 | + if (init_mb_string()) { |
|
| 342 | + $order = mb_detect_order(); |
|
| 343 | + try { |
|
| 344 | + # mb_string connait-il $charset? |
|
| 345 | + if ($order && mb_detect_order($charset)) { |
|
| 346 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 347 | + if ($s && $s != $texte) { |
|
| 348 | + return utf_8_to_unicode($s); |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + } catch (\Error) { |
|
| 352 | + // Le charset n'existe probablement pas |
|
| 353 | + } finally { |
|
| 354 | + mb_detect_order($order); # remettre comme precedemment |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 359 | + if (!isset($trans[$charset]) && (($cset = load_charset($charset)) && is_array($GLOBALS['CHARSET'][$cset]))) { |
|
| 360 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 361 | + $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + if (isset($trans[$charset]) && (is_countable($trans[$charset]) ? count($trans[$charset]) : 0)) { |
|
| 365 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 369 | + // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 370 | + // surtout en utf-8, gere ci-dessus) |
|
| 371 | + if (test_iconv()) { |
|
| 372 | + $s = iconv($charset, 'utf-32le', $texte); |
|
| 373 | + if ($s) { |
|
| 374 | + return utf_32_to_unicode($s); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // Au pire ne rien faire |
|
| 379 | + spip_log("erreur charset '$charset' non supporte"); |
|
| 380 | + |
|
| 381 | + return $texte; |
|
| 382 | + } |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | |
@@ -398,42 +398,42 @@ discard block |
||
| 398 | 398 | * texte transformé dans le charset souhaité |
| 399 | 399 | **/ |
| 400 | 400 | function unicode2charset($texte, $charset = 'AUTO') { |
| 401 | - static $CHARSET_REVERSE = []; |
|
| 402 | - static $trans = []; |
|
| 403 | - |
|
| 404 | - if ($charset == 'AUTO') { |
|
| 405 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - switch ($charset) { |
|
| 409 | - case 'utf-8': |
|
| 410 | - return unicode_to_utf_8($texte); |
|
| 411 | - |
|
| 412 | - default: |
|
| 413 | - $charset = load_charset($charset); |
|
| 414 | - |
|
| 415 | - if (empty($CHARSET_REVERSE[$charset])) { |
|
| 416 | - $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - if (!isset($trans[$charset])) { |
|
| 420 | - $trans[$charset] = []; |
|
| 421 | - $t = &$trans[$charset]; |
|
| 422 | - for ($e = 128; $e < 255; $e++) { |
|
| 423 | - $h = dechex($e); |
|
| 424 | - if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 425 | - $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 426 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 427 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 428 | - } else { |
|
| 429 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 430 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 436 | - } |
|
| 401 | + static $CHARSET_REVERSE = []; |
|
| 402 | + static $trans = []; |
|
| 403 | + |
|
| 404 | + if ($charset == 'AUTO') { |
|
| 405 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + switch ($charset) { |
|
| 409 | + case 'utf-8': |
|
| 410 | + return unicode_to_utf_8($texte); |
|
| 411 | + |
|
| 412 | + default: |
|
| 413 | + $charset = load_charset($charset); |
|
| 414 | + |
|
| 415 | + if (empty($CHARSET_REVERSE[$charset])) { |
|
| 416 | + $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + if (!isset($trans[$charset])) { |
|
| 420 | + $trans[$charset] = []; |
|
| 421 | + $t = &$trans[$charset]; |
|
| 422 | + for ($e = 128; $e < 255; $e++) { |
|
| 423 | + $h = dechex($e); |
|
| 424 | + if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 425 | + $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 426 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 427 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 428 | + } else { |
|
| 429 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 430 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 436 | + } |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -451,39 +451,39 @@ discard block |
||
| 451 | 451 | * texte transformé dans le charset site |
| 452 | 452 | **/ |
| 453 | 453 | function importer_charset($texte, $charset = 'AUTO') { |
| 454 | - $s = null; |
|
| 455 | - static $trans = []; |
|
| 456 | - // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 457 | - if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 458 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 459 | - if (init_mb_string()) { |
|
| 460 | - if ( |
|
| 461 | - ($order = mb_detect_order()) |
|
| 462 | - && mb_detect_order($charset) |
|
| 463 | - ) { |
|
| 464 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 465 | - } |
|
| 466 | - mb_detect_order($order); # remettre comme precedemment |
|
| 467 | - return $s; |
|
| 468 | - } |
|
| 469 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 470 | - if ( |
|
| 471 | - !isset($trans[$charset]) |
|
| 472 | - && (($cset = load_charset($charset)) |
|
| 473 | - && is_array($GLOBALS['CHARSET'][$cset])) |
|
| 474 | - ) { |
|
| 475 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 476 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 480 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - return $texte; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return unicode2charset(charset2unicode($texte, $charset)); |
|
| 454 | + $s = null; |
|
| 455 | + static $trans = []; |
|
| 456 | + // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 457 | + if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 458 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 459 | + if (init_mb_string()) { |
|
| 460 | + if ( |
|
| 461 | + ($order = mb_detect_order()) |
|
| 462 | + && mb_detect_order($charset) |
|
| 463 | + ) { |
|
| 464 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 465 | + } |
|
| 466 | + mb_detect_order($order); # remettre comme precedemment |
|
| 467 | + return $s; |
|
| 468 | + } |
|
| 469 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 470 | + if ( |
|
| 471 | + !isset($trans[$charset]) |
|
| 472 | + && (($cset = load_charset($charset)) |
|
| 473 | + && is_array($GLOBALS['CHARSET'][$cset])) |
|
| 474 | + ) { |
|
| 475 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 476 | + $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 480 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + return $texte; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return unicode2charset(charset2unicode($texte, $charset)); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -499,92 +499,92 @@ discard block |
||
| 499 | 499 | **/ |
| 500 | 500 | function utf_8_to_unicode($source) { |
| 501 | 501 | |
| 502 | - // mb_string : methode rapide |
|
| 503 | - if (init_mb_string()) { |
|
| 504 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 505 | - |
|
| 506 | - return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - // Sinon methode pas a pas |
|
| 510 | - static $decrement; |
|
| 511 | - static $shift; |
|
| 512 | - |
|
| 513 | - // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 514 | - if (!is_array($decrement)) { |
|
| 515 | - // array used to figure what number to decrement from character order value |
|
| 516 | - // according to number of characters used to map unicode to ascii by utf-8 |
|
| 517 | - $decrement[4] = 240; |
|
| 518 | - $decrement[3] = 224; |
|
| 519 | - $decrement[2] = 192; |
|
| 520 | - $decrement[1] = 0; |
|
| 521 | - // the number of bits to shift each charNum by |
|
| 522 | - $shift[1][0] = 0; |
|
| 523 | - $shift[2][0] = 6; |
|
| 524 | - $shift[2][1] = 0; |
|
| 525 | - $shift[3][0] = 12; |
|
| 526 | - $shift[3][1] = 6; |
|
| 527 | - $shift[3][2] = 0; |
|
| 528 | - $shift[4][0] = 18; |
|
| 529 | - $shift[4][1] = 12; |
|
| 530 | - $shift[4][2] = 6; |
|
| 531 | - $shift[4][3] = 0; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - $pos = 0; |
|
| 535 | - $len = strlen($source); |
|
| 536 | - $encodedString = ''; |
|
| 537 | - while ($pos < $len) { |
|
| 538 | - $char = ''; |
|
| 539 | - $ischar = false; |
|
| 540 | - $asciiPos = ord(substr($source, $pos, 1)); |
|
| 541 | - if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 542 | - // 4 chars representing one unicode character |
|
| 543 | - $thisLetter = substr($source, $pos, 4); |
|
| 544 | - $pos += 4; |
|
| 545 | - } else { |
|
| 546 | - if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 547 | - // 3 chars representing one unicode character |
|
| 548 | - $thisLetter = substr($source, $pos, 3); |
|
| 549 | - $pos += 3; |
|
| 550 | - } else { |
|
| 551 | - if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 552 | - // 2 chars representing one unicode character |
|
| 553 | - $thisLetter = substr($source, $pos, 2); |
|
| 554 | - $pos += 2; |
|
| 555 | - } else { |
|
| 556 | - // 1 char (lower ascii) |
|
| 557 | - $thisLetter = substr($source, $pos, 1); |
|
| 558 | - $pos += 1; |
|
| 559 | - $char = $thisLetter; |
|
| 560 | - $ischar = true; |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - if ($ischar) { |
|
| 566 | - $encodedString .= $char; |
|
| 567 | - } else { // process the string representing the letter to a unicode entity |
|
| 568 | - $thisLen = strlen($thisLetter); |
|
| 569 | - $thisPos = 0; |
|
| 570 | - $decimalCode = 0; |
|
| 571 | - while ($thisPos < $thisLen) { |
|
| 572 | - $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 573 | - if ($thisPos == 0) { |
|
| 574 | - $charNum = (int) ($thisCharOrd - $decrement[$thisLen]); |
|
| 575 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 576 | - } else { |
|
| 577 | - $charNum = (int) ($thisCharOrd - 128); |
|
| 578 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 579 | - } |
|
| 580 | - $thisPos++; |
|
| 581 | - } |
|
| 582 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 583 | - $encodedString .= $encodedLetter; |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - return $encodedString; |
|
| 502 | + // mb_string : methode rapide |
|
| 503 | + if (init_mb_string()) { |
|
| 504 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 505 | + |
|
| 506 | + return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + // Sinon methode pas a pas |
|
| 510 | + static $decrement; |
|
| 511 | + static $shift; |
|
| 512 | + |
|
| 513 | + // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 514 | + if (!is_array($decrement)) { |
|
| 515 | + // array used to figure what number to decrement from character order value |
|
| 516 | + // according to number of characters used to map unicode to ascii by utf-8 |
|
| 517 | + $decrement[4] = 240; |
|
| 518 | + $decrement[3] = 224; |
|
| 519 | + $decrement[2] = 192; |
|
| 520 | + $decrement[1] = 0; |
|
| 521 | + // the number of bits to shift each charNum by |
|
| 522 | + $shift[1][0] = 0; |
|
| 523 | + $shift[2][0] = 6; |
|
| 524 | + $shift[2][1] = 0; |
|
| 525 | + $shift[3][0] = 12; |
|
| 526 | + $shift[3][1] = 6; |
|
| 527 | + $shift[3][2] = 0; |
|
| 528 | + $shift[4][0] = 18; |
|
| 529 | + $shift[4][1] = 12; |
|
| 530 | + $shift[4][2] = 6; |
|
| 531 | + $shift[4][3] = 0; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + $pos = 0; |
|
| 535 | + $len = strlen($source); |
|
| 536 | + $encodedString = ''; |
|
| 537 | + while ($pos < $len) { |
|
| 538 | + $char = ''; |
|
| 539 | + $ischar = false; |
|
| 540 | + $asciiPos = ord(substr($source, $pos, 1)); |
|
| 541 | + if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 542 | + // 4 chars representing one unicode character |
|
| 543 | + $thisLetter = substr($source, $pos, 4); |
|
| 544 | + $pos += 4; |
|
| 545 | + } else { |
|
| 546 | + if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 547 | + // 3 chars representing one unicode character |
|
| 548 | + $thisLetter = substr($source, $pos, 3); |
|
| 549 | + $pos += 3; |
|
| 550 | + } else { |
|
| 551 | + if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 552 | + // 2 chars representing one unicode character |
|
| 553 | + $thisLetter = substr($source, $pos, 2); |
|
| 554 | + $pos += 2; |
|
| 555 | + } else { |
|
| 556 | + // 1 char (lower ascii) |
|
| 557 | + $thisLetter = substr($source, $pos, 1); |
|
| 558 | + $pos += 1; |
|
| 559 | + $char = $thisLetter; |
|
| 560 | + $ischar = true; |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + if ($ischar) { |
|
| 566 | + $encodedString .= $char; |
|
| 567 | + } else { // process the string representing the letter to a unicode entity |
|
| 568 | + $thisLen = strlen($thisLetter); |
|
| 569 | + $thisPos = 0; |
|
| 570 | + $decimalCode = 0; |
|
| 571 | + while ($thisPos < $thisLen) { |
|
| 572 | + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 573 | + if ($thisPos == 0) { |
|
| 574 | + $charNum = (int) ($thisCharOrd - $decrement[$thisLen]); |
|
| 575 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 576 | + } else { |
|
| 577 | + $charNum = (int) ($thisCharOrd - 128); |
|
| 578 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 579 | + } |
|
| 580 | + $thisPos++; |
|
| 581 | + } |
|
| 582 | + $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 583 | + $encodedString .= $encodedLetter; |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + return $encodedString; |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -603,32 +603,32 @@ discard block |
||
| 603 | 603 | **/ |
| 604 | 604 | function utf_32_to_unicode($source) { |
| 605 | 605 | |
| 606 | - // mb_string : methode rapide |
|
| 607 | - if (init_mb_string()) { |
|
| 608 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 609 | - $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 610 | - |
|
| 611 | - return str_replace(chr(0), '', $source); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - // Sinon methode lente |
|
| 615 | - $texte = ''; |
|
| 616 | - while ($source) { |
|
| 617 | - $words = unpack('V*', substr($source, 0, 1024)); |
|
| 618 | - $source = substr($source, 1024); |
|
| 619 | - foreach ($words as $word) { |
|
| 620 | - if ($word < 128) { |
|
| 621 | - $texte .= chr($word); |
|
| 622 | - } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 623 | - else { |
|
| 624 | - if ($word != 65279) { |
|
| 625 | - $texte .= '&#' . $word . ';'; |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - return $texte; |
|
| 606 | + // mb_string : methode rapide |
|
| 607 | + if (init_mb_string()) { |
|
| 608 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 609 | + $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 610 | + |
|
| 611 | + return str_replace(chr(0), '', $source); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + // Sinon methode lente |
|
| 615 | + $texte = ''; |
|
| 616 | + while ($source) { |
|
| 617 | + $words = unpack('V*', substr($source, 0, 1024)); |
|
| 618 | + $source = substr($source, 1024); |
|
| 619 | + foreach ($words as $word) { |
|
| 620 | + if ($word < 128) { |
|
| 621 | + $texte .= chr($word); |
|
| 622 | + } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 623 | + else { |
|
| 624 | + if ($word != 65279) { |
|
| 625 | + $texte .= '&#' . $word . ';'; |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + return $texte; |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | |
@@ -645,21 +645,21 @@ discard block |
||
| 645 | 645 | * Caractère utf8 si trouvé, '' sinon |
| 646 | 646 | **/ |
| 647 | 647 | function caractere_utf_8($num) { |
| 648 | - $num = (int) $num; |
|
| 649 | - if ($num < 128) { |
|
| 650 | - return chr($num); |
|
| 651 | - } |
|
| 652 | - if ($num < 2048) { |
|
| 653 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 654 | - } |
|
| 655 | - if ($num < 65536) { |
|
| 656 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 657 | - } |
|
| 658 | - if ($num < 1_114_112) { |
|
| 659 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - return ''; |
|
| 648 | + $num = (int) $num; |
|
| 649 | + if ($num < 128) { |
|
| 650 | + return chr($num); |
|
| 651 | + } |
|
| 652 | + if ($num < 2048) { |
|
| 653 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 654 | + } |
|
| 655 | + if ($num < 65536) { |
|
| 656 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 657 | + } |
|
| 658 | + if ($num < 1_114_112) { |
|
| 659 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + return ''; |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | /** |
@@ -672,42 +672,42 @@ discard block |
||
| 672 | 672 | **/ |
| 673 | 673 | function unicode_to_utf_8($texte) { |
| 674 | 674 | |
| 675 | - // 1. Entites € et suivantes |
|
| 676 | - $vu = []; |
|
| 677 | - if ( |
|
| 678 | - preg_match_all( |
|
| 679 | - ',�*([1-9]\d\d+);,S', |
|
| 680 | - $texte, |
|
| 681 | - $regs, |
|
| 682 | - PREG_SET_ORDER |
|
| 683 | - ) |
|
| 684 | - ) { |
|
| 685 | - foreach ($regs as $reg) { |
|
| 686 | - if ($reg[1] > 127 && !isset($vu[$reg[0]])) { |
|
| 687 | - $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 692 | - |
|
| 693 | - // 2. Entites > ÿ |
|
| 694 | - //$vu = array(); |
|
| 695 | - if ( |
|
| 696 | - preg_match_all( |
|
| 697 | - ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 698 | - $texte, |
|
| 699 | - $regs, |
|
| 700 | - PREG_SET_ORDER |
|
| 701 | - ) |
|
| 702 | - ) { |
|
| 703 | - foreach ($regs as $reg) { |
|
| 704 | - if (!isset($vu[$reg[0]])) { |
|
| 705 | - $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 675 | + // 1. Entites € et suivantes |
|
| 676 | + $vu = []; |
|
| 677 | + if ( |
|
| 678 | + preg_match_all( |
|
| 679 | + ',�*([1-9]\d\d+);,S', |
|
| 680 | + $texte, |
|
| 681 | + $regs, |
|
| 682 | + PREG_SET_ORDER |
|
| 683 | + ) |
|
| 684 | + ) { |
|
| 685 | + foreach ($regs as $reg) { |
|
| 686 | + if ($reg[1] > 127 && !isset($vu[$reg[0]])) { |
|
| 687 | + $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 692 | + |
|
| 693 | + // 2. Entites > ÿ |
|
| 694 | + //$vu = array(); |
|
| 695 | + if ( |
|
| 696 | + preg_match_all( |
|
| 697 | + ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 698 | + $texte, |
|
| 699 | + $regs, |
|
| 700 | + PREG_SET_ORDER |
|
| 701 | + ) |
|
| 702 | + ) { |
|
| 703 | + foreach ($regs as $reg) { |
|
| 704 | + if (!isset($vu[$reg[0]])) { |
|
| 705 | + $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | /** |
@@ -719,15 +719,15 @@ discard block |
||
| 719 | 719 | * texte converti |
| 720 | 720 | **/ |
| 721 | 721 | function unicode_to_javascript($texte) { |
| 722 | - $vu = []; |
|
| 723 | - while (preg_match(',�*(\d+);,S', $texte, $regs) && !isset($vu[$regs[1]])) { |
|
| 724 | - $num = $regs[1]; |
|
| 725 | - $vu[$num] = true; |
|
| 726 | - $s = '\u' . sprintf('%04x', $num); |
|
| 727 | - $texte = str_replace($regs[0], $s, $texte); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - return $texte; |
|
| 722 | + $vu = []; |
|
| 723 | + while (preg_match(',�*(\d+);,S', $texte, $regs) && !isset($vu[$regs[1]])) { |
|
| 724 | + $num = $regs[1]; |
|
| 725 | + $vu[$num] = true; |
|
| 726 | + $s = '\u' . sprintf('%04x', $num); |
|
| 727 | + $texte = str_replace($regs[0], $s, $texte); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + return $texte; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -739,11 +739,11 @@ discard block |
||
| 739 | 739 | * texte converti |
| 740 | 740 | **/ |
| 741 | 741 | function javascript_to_unicode($texte) { |
| 742 | - while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 743 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 744 | - } |
|
| 742 | + while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 743 | + $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 744 | + } |
|
| 745 | 745 | |
| 746 | - return $texte; |
|
| 746 | + return $texte; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
@@ -755,11 +755,11 @@ discard block |
||
| 755 | 755 | * texte converti |
| 756 | 756 | **/ |
| 757 | 757 | function javascript_to_binary($texte) { |
| 758 | - while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 759 | - $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 760 | - } |
|
| 758 | + while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 759 | + $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | - return $texte; |
|
| 762 | + return $texte; |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | |
@@ -777,26 +777,26 @@ discard block |
||
| 777 | 777 | * @return string |
| 778 | 778 | */ |
| 779 | 779 | function translitteration_rapide($texte, $charset = 'AUTO', $complexe = ''): string { |
| 780 | - static $trans = []; |
|
| 781 | - if ($charset == 'AUTO') { |
|
| 782 | - $charset = $GLOBALS['meta']['charset']; |
|
| 783 | - } |
|
| 784 | - if (!strlen($texte)) { |
|
| 785 | - return $texte; |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - $table_translit = 'translit' . $complexe; |
|
| 789 | - |
|
| 790 | - // 2. Translitterer grace a la table predefinie |
|
| 791 | - if (!isset($trans[$complexe])) { |
|
| 792 | - $trans[$complexe] = []; |
|
| 793 | - load_charset($table_translit); |
|
| 794 | - foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 795 | - $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 796 | - } |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 780 | + static $trans = []; |
|
| 781 | + if ($charset == 'AUTO') { |
|
| 782 | + $charset = $GLOBALS['meta']['charset']; |
|
| 783 | + } |
|
| 784 | + if (!strlen($texte)) { |
|
| 785 | + return $texte; |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + $table_translit = 'translit' . $complexe; |
|
| 789 | + |
|
| 790 | + // 2. Translitterer grace a la table predefinie |
|
| 791 | + if (!isset($trans[$complexe])) { |
|
| 792 | + $trans[$complexe] = []; |
|
| 793 | + load_charset($table_translit); |
|
| 794 | + foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 795 | + $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -819,14 +819,14 @@ discard block |
||
| 819 | 819 | * @return string |
| 820 | 820 | */ |
| 821 | 821 | function translitteration($texte, $charset = 'AUTO', $complexe = ''): string { |
| 822 | - // 0. Supprimer les caracteres illegaux |
|
| 823 | - include_spip('inc/filtres'); |
|
| 824 | - $texte = corriger_caracteres($texte); |
|
| 822 | + // 0. Supprimer les caracteres illegaux |
|
| 823 | + include_spip('inc/filtres'); |
|
| 824 | + $texte = corriger_caracteres($texte); |
|
| 825 | 825 | |
| 826 | - // 1. Passer le charset et les é en utf-8 |
|
| 827 | - $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 826 | + // 1. Passer le charset et les é en utf-8 |
|
| 827 | + $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 828 | 828 | |
| 829 | - return translitteration_rapide($texte, $charset, $complexe); |
|
| 829 | + return translitteration_rapide($texte, $charset, $complexe); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | /** |
@@ -841,17 +841,17 @@ discard block |
||
| 841 | 841 | * @return string |
| 842 | 842 | */ |
| 843 | 843 | function translitteration_complexe($texte, $chiffres = false): string { |
| 844 | - $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 844 | + $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 845 | 845 | |
| 846 | - if ($chiffres) { |
|
| 847 | - $texte = preg_replace_callback( |
|
| 848 | - "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 849 | - fn($m) => translitteration_chiffree($m[0]), |
|
| 850 | - $texte |
|
| 851 | - ); |
|
| 852 | - } |
|
| 846 | + if ($chiffres) { |
|
| 847 | + $texte = preg_replace_callback( |
|
| 848 | + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 849 | + fn($m) => translitteration_chiffree($m[0]), |
|
| 850 | + $texte |
|
| 851 | + ); |
|
| 852 | + } |
|
| 853 | 853 | |
| 854 | - return $texte; |
|
| 854 | + return $texte; |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | /** |
@@ -863,7 +863,7 @@ discard block |
||
| 863 | 863 | * @return string |
| 864 | 864 | */ |
| 865 | 865 | function translitteration_chiffree($car): string { |
| 866 | - return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 866 | + return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | * true s'il a un BOM |
| 877 | 877 | **/ |
| 878 | 878 | function bom_utf8($texte): bool { |
| 879 | - return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 879 | + return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | /** |
@@ -893,21 +893,21 @@ discard block |
||
| 893 | 893 | * true si c'est le cas |
| 894 | 894 | **/ |
| 895 | 895 | function is_utf8($string): bool { |
| 896 | - return !strlen( |
|
| 897 | - preg_replace( |
|
| 898 | - ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 899 | - . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 900 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 901 | - . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 902 | - . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 903 | - . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 904 | - . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 905 | - . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 906 | - . ',sS', |
|
| 907 | - '', |
|
| 908 | - $string |
|
| 909 | - ) |
|
| 910 | - ); |
|
| 896 | + return !strlen( |
|
| 897 | + preg_replace( |
|
| 898 | + ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 899 | + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 900 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 901 | + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 902 | + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 903 | + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 904 | + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 905 | + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 906 | + . ',sS', |
|
| 907 | + '', |
|
| 908 | + $string |
|
| 909 | + ) |
|
| 910 | + ); |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | /** |
@@ -919,13 +919,13 @@ discard block |
||
| 919 | 919 | * true si c'est le cas |
| 920 | 920 | **/ |
| 921 | 921 | function is_ascii($string): bool { |
| 922 | - return !strlen( |
|
| 923 | - preg_replace( |
|
| 924 | - ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 925 | - '', |
|
| 926 | - $string |
|
| 927 | - ) |
|
| 928 | - ); |
|
| 922 | + return !strlen( |
|
| 923 | + preg_replace( |
|
| 924 | + ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 925 | + '', |
|
| 926 | + $string |
|
| 927 | + ) |
|
| 928 | + ); |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | /** |
@@ -944,50 +944,50 @@ discard block |
||
| 944 | 944 | **/ |
| 945 | 945 | function transcoder_page($texte, $headers = ''): string { |
| 946 | 946 | |
| 947 | - // Si tout est < 128 pas la peine d'aller plus loin |
|
| 948 | - if (is_ascii($texte)) { |
|
| 949 | - #spip_log('charset: ascii'); |
|
| 950 | - return $texte; |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - if (bom_utf8($texte)) { |
|
| 954 | - // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 955 | - $charset = 'utf-8'; |
|
| 956 | - $texte = substr($texte, 3); |
|
| 957 | - } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 958 | - // charset precise par le contenu (xml) |
|
| 959 | - $charset = trim(strtolower($regs[1])); |
|
| 960 | - } elseif ( |
|
| 961 | - // charset precise par le contenu (html) |
|
| 962 | - preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 963 | - # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 964 | - |
|
| 965 | - && !str_contains($regs[2], '#') |
|
| 966 | - && ($tmp = trim(strtolower($regs[2]))) |
|
| 967 | - ) { |
|
| 968 | - $charset = $tmp; |
|
| 969 | - } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 970 | - // charset de la reponse http |
|
| 971 | - $charset = trim(strtolower($regs[1])); |
|
| 972 | - } else { |
|
| 973 | - $charset = ''; |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - // normaliser les noms du shif-jis japonais |
|
| 978 | - if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 979 | - $charset = 'shift-jis'; |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - if ($charset) { |
|
| 983 | - spip_log("charset: $charset"); |
|
| 984 | - } else { |
|
| 985 | - // valeur par defaut |
|
| 986 | - $charset = is_utf8($texte) ? 'utf-8' : 'iso-8859-1'; |
|
| 987 | - spip_log("charset probable: $charset"); |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - return importer_charset($texte, $charset); |
|
| 947 | + // Si tout est < 128 pas la peine d'aller plus loin |
|
| 948 | + if (is_ascii($texte)) { |
|
| 949 | + #spip_log('charset: ascii'); |
|
| 950 | + return $texte; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + if (bom_utf8($texte)) { |
|
| 954 | + // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 955 | + $charset = 'utf-8'; |
|
| 956 | + $texte = substr($texte, 3); |
|
| 957 | + } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 958 | + // charset precise par le contenu (xml) |
|
| 959 | + $charset = trim(strtolower($regs[1])); |
|
| 960 | + } elseif ( |
|
| 961 | + // charset precise par le contenu (html) |
|
| 962 | + preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 963 | + # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 964 | + |
|
| 965 | + && !str_contains($regs[2], '#') |
|
| 966 | + && ($tmp = trim(strtolower($regs[2]))) |
|
| 967 | + ) { |
|
| 968 | + $charset = $tmp; |
|
| 969 | + } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 970 | + // charset de la reponse http |
|
| 971 | + $charset = trim(strtolower($regs[1])); |
|
| 972 | + } else { |
|
| 973 | + $charset = ''; |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + // normaliser les noms du shif-jis japonais |
|
| 978 | + if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 979 | + $charset = 'shift-jis'; |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + if ($charset) { |
|
| 983 | + spip_log("charset: $charset"); |
|
| 984 | + } else { |
|
| 985 | + // valeur par defaut |
|
| 986 | + $charset = is_utf8($texte) ? 'utf-8' : 'iso-8859-1'; |
|
| 987 | + spip_log("charset probable: $charset"); |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + return importer_charset($texte, $charset); |
|
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | |
@@ -1011,19 +1011,19 @@ discard block |
||
| 1011 | 1011 | * Le texte coupé |
| 1012 | 1012 | **/ |
| 1013 | 1013 | function spip_substr($c, $start = 0, $length = null) { |
| 1014 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1015 | - if ($length) { |
|
| 1016 | - return substr($c, $start, $length); |
|
| 1017 | - } else { |
|
| 1018 | - return substr($c, $start); |
|
| 1019 | - } |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - if ($length) { |
|
| 1023 | - return mb_substr($c, $start, $length); |
|
| 1024 | - } else { |
|
| 1025 | - return mb_substr($c, $start); |
|
| 1026 | - } |
|
| 1014 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1015 | + if ($length) { |
|
| 1016 | + return substr($c, $start, $length); |
|
| 1017 | + } else { |
|
| 1018 | + return substr($c, $start); |
|
| 1019 | + } |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + if ($length) { |
|
| 1023 | + return mb_substr($c, $start, $length); |
|
| 1024 | + } else { |
|
| 1025 | + return mb_substr($c, $start); |
|
| 1026 | + } |
|
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | 1029 | /** |
@@ -1037,13 +1037,13 @@ discard block |
||
| 1037 | 1037 | * La chaîne avec une majuscule sur le premier mot |
| 1038 | 1038 | */ |
| 1039 | 1039 | function spip_ucfirst($c) { |
| 1040 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1041 | - return ucfirst($c); |
|
| 1042 | - } |
|
| 1040 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1041 | + return ucfirst($c); |
|
| 1042 | + } |
|
| 1043 | 1043 | |
| 1044 | - $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1044 | + $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1045 | 1045 | |
| 1046 | - return $lettre1 . spip_substr($c, 1); |
|
| 1046 | + return $lettre1 . spip_substr($c, 1); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | /** |
@@ -1057,11 +1057,11 @@ discard block |
||
| 1057 | 1057 | * La chaîne en minuscules |
| 1058 | 1058 | */ |
| 1059 | 1059 | function spip_strtolower($c) { |
| 1060 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1061 | - return strtolower($c); |
|
| 1062 | - } |
|
| 1060 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1061 | + return strtolower($c); |
|
| 1062 | + } |
|
| 1063 | 1063 | |
| 1064 | - return mb_strtolower($c); |
|
| 1064 | + return mb_strtolower($c); |
|
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | 1067 | /** |
@@ -1075,15 +1075,15 @@ discard block |
||
| 1075 | 1075 | * Longueur de la chaîne |
| 1076 | 1076 | */ |
| 1077 | 1077 | function spip_strlen($c) { |
| 1078 | - // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1079 | - $c = str_replace("\r\n", "\n", $c); |
|
| 1078 | + // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1079 | + $c = str_replace("\r\n", "\n", $c); |
|
| 1080 | 1080 | |
| 1081 | - // Si ce n'est pas utf-8, utiliser strlen |
|
| 1082 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1083 | - return strlen($c); |
|
| 1084 | - } |
|
| 1081 | + // Si ce n'est pas utf-8, utiliser strlen |
|
| 1082 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1083 | + return strlen($c); |
|
| 1084 | + } |
|
| 1085 | 1085 | |
| 1086 | - return mb_strlen($c); |
|
| 1086 | + return mb_strlen($c); |
|
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | /** |
@@ -1098,17 +1098,17 @@ discard block |
||
| 1098 | 1098 | * en unicode : 💩 |
| 1099 | 1099 | */ |
| 1100 | 1100 | function utf8_noplanes($x): string { |
| 1101 | - $regexp_utf8_4bytes = '/( |
|
| 1101 | + $regexp_utf8_4bytes = '/( |
|
| 1102 | 1102 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1103 | 1103 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1104 | 1104 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1105 | 1105 | )/xS'; |
| 1106 | - if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1107 | - foreach ($z[0] as $k) { |
|
| 1108 | - $ku = utf_8_to_unicode($k); |
|
| 1109 | - $x = str_replace($k, $ku, $x); |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - return $x; |
|
| 1106 | + if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1107 | + foreach ($z[0] as $k) { |
|
| 1108 | + $ku = utf_8_to_unicode($k); |
|
| 1109 | + $x = str_replace($k, $ku, $x); |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + return $x; |
|
| 1114 | 1114 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $charset = 'cp1256'; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 92 | + if (find_in_path($charset.'.php', 'charsets/', true)) { |
|
| 93 | 93 | return $charset; |
| 94 | 94 | } else { |
| 95 | 95 | spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
@@ -190,38 +190,38 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | if (!isset($trans[$charset][$charset_cible])) { |
| 192 | 192 | $trans[$charset][$charset_cible] = [ |
| 193 | - $p . chr(128) => '€', |
|
| 194 | - $p . chr(129) => ' ', # pas affecte |
|
| 195 | - $p . chr(130) => '‚', |
|
| 196 | - $p . chr(131) => 'ƒ', |
|
| 197 | - $p . chr(132) => '„', |
|
| 198 | - $p . chr(133) => '…', |
|
| 199 | - $p . chr(134) => '†', |
|
| 200 | - $p . chr(135) => '‡', |
|
| 201 | - $p . chr(136) => 'ˆ', |
|
| 202 | - $p . chr(137) => '‰', |
|
| 203 | - $p . chr(138) => 'Š', |
|
| 204 | - $p . chr(139) => '‹', |
|
| 205 | - $p . chr(140) => 'Œ', |
|
| 206 | - $p . chr(141) => ' ', # pas affecte |
|
| 207 | - $p . chr(142) => 'Ž', |
|
| 208 | - $p . chr(143) => ' ', # pas affecte |
|
| 209 | - $p . chr(144) => ' ', # pas affecte |
|
| 210 | - $p . chr(145) => '‘', |
|
| 211 | - $p . chr(146) => '’', |
|
| 212 | - $p . chr(147) => '“', |
|
| 213 | - $p . chr(148) => '”', |
|
| 214 | - $p . chr(149) => '•', |
|
| 215 | - $p . chr(150) => '–', |
|
| 216 | - $p . chr(151) => '—', |
|
| 217 | - $p . chr(152) => '˜', |
|
| 218 | - $p . chr(153) => '™', |
|
| 219 | - $p . chr(154) => 'š', |
|
| 220 | - $p . chr(155) => '›', |
|
| 221 | - $p . chr(156) => 'œ', |
|
| 222 | - $p . chr(157) => ' ', # pas affecte |
|
| 223 | - $p . chr(158) => 'ž', |
|
| 224 | - $p . chr(159) => 'Ÿ', |
|
| 193 | + $p.chr(128) => '€', |
|
| 194 | + $p.chr(129) => ' ', # pas affecte |
|
| 195 | + $p.chr(130) => '‚', |
|
| 196 | + $p.chr(131) => 'ƒ', |
|
| 197 | + $p.chr(132) => '„', |
|
| 198 | + $p.chr(133) => '…', |
|
| 199 | + $p.chr(134) => '†', |
|
| 200 | + $p.chr(135) => '‡', |
|
| 201 | + $p.chr(136) => 'ˆ', |
|
| 202 | + $p.chr(137) => '‰', |
|
| 203 | + $p.chr(138) => 'Š', |
|
| 204 | + $p.chr(139) => '‹', |
|
| 205 | + $p.chr(140) => 'Œ', |
|
| 206 | + $p.chr(141) => ' ', # pas affecte |
|
| 207 | + $p.chr(142) => 'Ž', |
|
| 208 | + $p.chr(143) => ' ', # pas affecte |
|
| 209 | + $p.chr(144) => ' ', # pas affecte |
|
| 210 | + $p.chr(145) => '‘', |
|
| 211 | + $p.chr(146) => '’', |
|
| 212 | + $p.chr(147) => '“', |
|
| 213 | + $p.chr(148) => '”', |
|
| 214 | + $p.chr(149) => '•', |
|
| 215 | + $p.chr(150) => '–', |
|
| 216 | + $p.chr(151) => '—', |
|
| 217 | + $p.chr(152) => '˜', |
|
| 218 | + $p.chr(153) => '™', |
|
| 219 | + $p.chr(154) => 'š', |
|
| 220 | + $p.chr(155) => '›', |
|
| 221 | + $p.chr(156) => 'œ', |
|
| 222 | + $p.chr(157) => ' ', # pas affecte |
|
| 223 | + $p.chr(158) => 'ž', |
|
| 224 | + $p.chr(159) => 'Ÿ', |
|
| 225 | 225 | ]; |
| 226 | 226 | if ($charset_cible != 'unicode') { |
| 227 | 227 | foreach ($trans[$charset][$charset_cible] as $k => $c) { |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | // Sinon, peut-etre connaissons-nous ce charset ? |
| 359 | 359 | if (!isset($trans[$charset]) && (($cset = load_charset($charset)) && is_array($GLOBALS['CHARSET'][$cset]))) { |
| 360 | 360 | foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
| 361 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 361 | + $trans[$charset][chr($key)] = '&#'.$val.';'; |
|
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | if (isset($trans[$charset]) && (is_countable($trans[$charset]) ? count($trans[$charset]) : 0)) { |
@@ -423,11 +423,11 @@ discard block |
||
| 423 | 423 | $h = dechex($e); |
| 424 | 424 | if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
| 425 | 425 | $s = $CHARSET_REVERSE[$charset][$e]; |
| 426 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 427 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 426 | + $t['&#'.$e.';'] = $t['�'.$e.';'] = $t['�'.$e.';'] = chr($s); |
|
| 427 | + $t['&#x'.$h.';'] = $t['�'.$h.';'] = $t['�'.$h.';'] = chr($s); |
|
| 428 | 428 | } else { |
| 429 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 430 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 429 | + $t['&#'.$e.';'] = $t['�'.$e.';'] = $t['�'.$e.';'] = chr($e); |
|
| 430 | + $t['&#x'.$h.';'] = $t['�'.$h.';'] = $t['�'.$h.';'] = chr($e); |
|
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | } |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | && is_array($GLOBALS['CHARSET'][$cset])) |
| 474 | 474 | ) { |
| 475 | 475 | foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
| 476 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 476 | + $trans[$charset][chr($key)] = unicode2charset('&#'.$val.';'); |
|
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | 479 | if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | $thisPos++; |
| 581 | 581 | } |
| 582 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 582 | + $encodedLetter = '&#'.preg_replace('/^0+/', '', $decimalCode).';'; |
|
| 583 | 583 | $encodedString .= $encodedLetter; |
| 584 | 584 | } |
| 585 | 585 | } |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
| 623 | 623 | else { |
| 624 | 624 | if ($word != 65279) { |
| 625 | - $texte .= '&#' . $word . ';'; |
|
| 625 | + $texte .= '&#'.$word.';'; |
|
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | } |
@@ -650,13 +650,13 @@ discard block |
||
| 650 | 650 | return chr($num); |
| 651 | 651 | } |
| 652 | 652 | if ($num < 2048) { |
| 653 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 653 | + return chr(($num >> 6) + 192).chr(($num & 63) + 128); |
|
| 654 | 654 | } |
| 655 | 655 | if ($num < 65536) { |
| 656 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 656 | + return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); |
|
| 657 | 657 | } |
| 658 | 658 | if ($num < 1_114_112) { |
| 659 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 659 | + return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | return ''; |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | while (preg_match(',�*(\d+);,S', $texte, $regs) && !isset($vu[$regs[1]])) { |
| 724 | 724 | $num = $regs[1]; |
| 725 | 725 | $vu[$num] = true; |
| 726 | - $s = '\u' . sprintf('%04x', $num); |
|
| 726 | + $s = '\u'.sprintf('%04x', $num); |
|
| 727 | 727 | $texte = str_replace($regs[0], $s, $texte); |
| 728 | 728 | } |
| 729 | 729 | |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | **/ |
| 741 | 741 | function javascript_to_unicode($texte) { |
| 742 | 742 | while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
| 743 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 743 | + $texte = str_replace($regs[0], '&#'.hexdec($regs[1]).';', $texte); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | return $texte; |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | return $texte; |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | - $table_translit = 'translit' . $complexe; |
|
| 788 | + $table_translit = 'translit'.$complexe; |
|
| 789 | 789 | |
| 790 | 790 | // 2. Translitterer grace a la table predefinie |
| 791 | 791 | if (!isset($trans[$complexe])) { |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | * true s'il a un BOM |
| 877 | 877 | **/ |
| 878 | 878 | function bom_utf8($texte): bool { |
| 879 | - return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 879 | + return (substr($texte, 0, 3) === chr(0xEF).chr(0xBB).chr(0xBF)); |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | /** |
@@ -1043,7 +1043,7 @@ discard block |
||
| 1043 | 1043 | |
| 1044 | 1044 | $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
| 1045 | 1045 | |
| 1046 | - return $lettre1 . spip_substr($c, 1); |
|
| 1046 | + return $lettre1.spip_substr($c, 1); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | /** |
@@ -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 | /** |
@@ -42,22 +42,22 @@ discard block |
||
| 42 | 42 | * Pile complétée par le code à générer |
| 43 | 43 | */ |
| 44 | 44 | function balise_ALERTE_MESSAGE_dist($p) { |
| 45 | - $_texte = interprete_argument_balise(1, $p); |
|
| 46 | - $_titre = interprete_argument_balise(2, $p); |
|
| 47 | - $_class = interprete_argument_balise(3, $p); |
|
| 48 | - $_role = interprete_argument_balise(4, $p); |
|
| 49 | - $_id = interprete_argument_balise(5, $p); |
|
| 50 | - $_texte = ($_texte ?: "''"); |
|
| 51 | - $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 52 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 53 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 54 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 45 | + $_texte = interprete_argument_balise(1, $p); |
|
| 46 | + $_titre = interprete_argument_balise(2, $p); |
|
| 47 | + $_class = interprete_argument_balise(3, $p); |
|
| 48 | + $_role = interprete_argument_balise(4, $p); |
|
| 49 | + $_id = interprete_argument_balise(5, $p); |
|
| 50 | + $_texte = ($_texte ?: "''"); |
|
| 51 | + $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 52 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 53 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 54 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 55 | 55 | |
| 56 | - $f = chercher_filtre('message_alerte'); |
|
| 57 | - $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 58 | - $p->interdire_scripts = false; |
|
| 56 | + $f = chercher_filtre('message_alerte'); |
|
| 57 | + $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 58 | + $p->interdire_scripts = false; |
|
| 59 | 59 | |
| 60 | - return $p; |
|
| 60 | + return $p; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -85,20 +85,20 @@ discard block |
||
| 85 | 85 | * Pile complétée par le code à générer |
| 86 | 86 | */ |
| 87 | 87 | function balise_ALERTE_OUVRIR_dist($p) { |
| 88 | - $_titre = interprete_argument_balise(1, $p); |
|
| 89 | - $_class = interprete_argument_balise(2, $p); |
|
| 90 | - $_role = interprete_argument_balise(3, $p); |
|
| 91 | - $_id = interprete_argument_balise(4, $p); |
|
| 92 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 93 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 94 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 95 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 88 | + $_titre = interprete_argument_balise(1, $p); |
|
| 89 | + $_class = interprete_argument_balise(2, $p); |
|
| 90 | + $_role = interprete_argument_balise(3, $p); |
|
| 91 | + $_id = interprete_argument_balise(4, $p); |
|
| 92 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 93 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 94 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 95 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 96 | 96 | |
| 97 | - $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 98 | - $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 99 | - $p->interdire_scripts = false; |
|
| 97 | + $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 98 | + $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 99 | + $p->interdire_scripts = false; |
|
| 100 | 100 | |
| 101 | - return $p; |
|
| 101 | + return $p; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -120,11 +120,11 @@ discard block |
||
| 120 | 120 | * Pile complétée par le code à générer |
| 121 | 121 | */ |
| 122 | 122 | function balise_ALERTE_FERMER_dist($p) { |
| 123 | - $f = chercher_filtre('message_alerte_fermer'); |
|
| 124 | - $p->code = "$f()"; |
|
| 125 | - $p->interdire_scripts = false; |
|
| 123 | + $f = chercher_filtre('message_alerte_fermer'); |
|
| 124 | + $p->code = "$f()"; |
|
| 125 | + $p->interdire_scripts = false; |
|
| 126 | 126 | |
| 127 | - return $p; |
|
| 127 | + return $p; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -159,12 +159,12 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | function message_alerte(string $texte, ?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 161 | 161 | |
| 162 | - $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 163 | - $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 162 | + $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 163 | + $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 164 | 164 | |
| 165 | - return $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 166 | - $texte . |
|
| 167 | - $message_alerte_fermer(); |
|
| 165 | + return $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 166 | + $texte . |
|
| 167 | + $message_alerte_fermer(); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -195,53 +195,53 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | function message_alerte_ouvrir(?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 197 | 197 | |
| 198 | - $prive = test_espace_prive(); |
|
| 198 | + $prive = test_espace_prive(); |
|
| 199 | 199 | |
| 200 | - // Valeurs par défaut |
|
| 201 | - $titre = trim($titre ?? ''); |
|
| 202 | - $role ??= 'alert'; // fallback uniquement si null |
|
| 203 | - $class ??= 'notice'; // fallback uniquement si null |
|
| 200 | + // Valeurs par défaut |
|
| 201 | + $titre = trim($titre ?? ''); |
|
| 202 | + $role ??= 'alert'; // fallback uniquement si null |
|
| 203 | + $class ??= 'notice'; // fallback uniquement si null |
|
| 204 | 204 | |
| 205 | - // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 206 | - $types = [ |
|
| 207 | - 'notice', |
|
| 208 | - 'error', |
|
| 209 | - 'success', |
|
| 210 | - 'info', |
|
| 211 | - ]; |
|
| 212 | - $type = array_intersect(explode(' ', $class), $types); |
|
| 213 | - $type = reset($type); |
|
| 214 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 205 | + // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 206 | + $types = [ |
|
| 207 | + 'notice', |
|
| 208 | + 'error', |
|
| 209 | + 'success', |
|
| 210 | + 'info', |
|
| 211 | + ]; |
|
| 212 | + $type = array_intersect(explode(' ', $class), $types); |
|
| 213 | + $type = reset($type); |
|
| 214 | + $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 215 | 215 | |
| 216 | - // Classes |
|
| 217 | - $class_racine = 'msg-alert'; |
|
| 218 | - $clearfix = ($prive ? 'clearfix' : ''); |
|
| 219 | - $class_alerte = "$class_racine $class"; |
|
| 220 | - $class_texte = "{$class_racine}__text $clearfix"; |
|
| 221 | - $class_titre = "{$class_racine}__heading"; |
|
| 216 | + // Classes |
|
| 217 | + $class_racine = 'msg-alert'; |
|
| 218 | + $clearfix = ($prive ? 'clearfix' : ''); |
|
| 219 | + $class_alerte = "$class_racine $class"; |
|
| 220 | + $class_texte = "{$class_racine}__text $clearfix"; |
|
| 221 | + $class_titre = "{$class_racine}__heading"; |
|
| 222 | 222 | |
| 223 | - // Titre : markup |
|
| 224 | - $titre = trim($titre); |
|
| 225 | - if (strlen($titre)) { |
|
| 226 | - include_spip('inc/filtres'); |
|
| 227 | - // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 228 | - $cherche_tag = ($prive ? '<h' : '<'); |
|
| 229 | - $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 230 | - if (!str_starts_with($titre, $cherche_tag)) { |
|
| 231 | - $titre = wrap($titre, $wrap_tag); |
|
| 232 | - } |
|
| 233 | - // puis on ajoute la classe |
|
| 234 | - $titre = ajouter_class($titre, $class_titre); |
|
| 235 | - } |
|
| 223 | + // Titre : markup |
|
| 224 | + $titre = trim($titre); |
|
| 225 | + if (strlen($titre)) { |
|
| 226 | + include_spip('inc/filtres'); |
|
| 227 | + // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 228 | + $cherche_tag = ($prive ? '<h' : '<'); |
|
| 229 | + $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 230 | + if (!str_starts_with($titre, $cherche_tag)) { |
|
| 231 | + $titre = wrap($titre, $wrap_tag); |
|
| 232 | + } |
|
| 233 | + // puis on ajoute la classe |
|
| 234 | + $titre = ajouter_class($titre, $class_titre); |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - // Attributs |
|
| 238 | - $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 239 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 240 | - $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 237 | + // Attributs |
|
| 238 | + $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 239 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 240 | + $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 241 | 241 | |
| 242 | - return "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 243 | - . $titre |
|
| 244 | - . "<div class=\"$class_texte\">"; |
|
| 242 | + return "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 243 | + . $titre |
|
| 244 | + . "<div class=\"$class_texte\">"; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -255,5 +255,5 @@ discard block |
||
| 255 | 255 | * HTML de fin de l'alerte |
| 256 | 256 | */ |
| 257 | 257 | function message_alerte_fermer(): string { |
| 258 | - return '</div></div>'; |
|
| 258 | + return '</div></div>'; |
|
| 259 | 259 | } |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | $_texte = ($_texte ?: "''"); |
| 51 | 51 | $_titre = ($_titre ? ", $_titre" : ', null'); |
| 52 | 52 | $_class = ($_class ? ", $_class" : ', null'); |
| 53 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 54 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 53 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 54 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 55 | 55 | |
| 56 | 56 | $f = chercher_filtre('message_alerte'); |
| 57 | 57 | $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | $_class = interprete_argument_balise(2, $p); |
| 90 | 90 | $_role = interprete_argument_balise(3, $p); |
| 91 | 91 | $_id = interprete_argument_balise(4, $p); |
| 92 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 92 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 93 | 93 | $_class = ($_class ? ", $_class" : ', null'); |
| 94 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 95 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 94 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 95 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 96 | 96 | |
| 97 | 97 | $f = chercher_filtre('message_alerte_ouvrir'); |
| 98 | 98 | $p->code = "$f($_titre$_class$_role$_id)"; |
@@ -162,8 +162,8 @@ discard block |
||
| 162 | 162 | $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
| 163 | 163 | $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
| 164 | 164 | |
| 165 | - return $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 166 | - $texte . |
|
| 165 | + return $message_alerte_ouvrir($titre, $class, $role, $id). |
|
| 166 | + $texte. |
|
| 167 | 167 | $message_alerte_fermer(); |
| 168 | 168 | } |
| 169 | 169 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | ]; |
| 212 | 212 | $type = array_intersect(explode(' ', $class), $types); |
| 213 | 213 | $type = reset($type); |
| 214 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 214 | + $class = trim(str_replace($types, '', $class)." $type"); |
|
| 215 | 215 | |
| 216 | 216 | // Classes |
| 217 | 217 | $class_racine = 'msg-alert'; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | // Attributs |
| 238 | 238 | $attr_role = ($role ? "role=\"$role\"" : ''); |
| 239 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 239 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 240 | 240 | $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
| 241 | 241 | |
| 242 | 242 | return "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('inc/config'); |
@@ -31,31 +31,31 @@ discard block |
||
| 31 | 31 | * @return array|false |
| 32 | 32 | */ |
| 33 | 33 | function cvtconf_formulaire_charger($flux) { |
| 34 | - if ( |
|
| 35 | - ($form = $flux['args']['form']) |
|
| 36 | - && str_starts_with((string) $form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX |
|
| 37 | - ) { |
|
| 38 | - // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 39 | - include_spip('inc/autoriser'); |
|
| 40 | - if (!autoriser('configurer', '_' . substr((string) $form, 11))) { |
|
| 41 | - return false; |
|
| 42 | - } |
|
| 34 | + if ( |
|
| 35 | + ($form = $flux['args']['form']) |
|
| 36 | + && str_starts_with((string) $form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX |
|
| 37 | + ) { |
|
| 38 | + // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 39 | + include_spip('inc/autoriser'); |
|
| 40 | + if (!autoriser('configurer', '_' . substr((string) $form, 11))) { |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 45 | - if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 46 | - $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 47 | - $flux['data']['editable'] = true; |
|
| 48 | - if (_request('var_mode') == 'configurer' && autoriser('webmestre')) { |
|
| 49 | - if (!_AJAX) { |
|
| 50 | - var_dump($flux['data']); |
|
| 51 | - } |
|
| 52 | - // reinjecter pour la trace au traitement |
|
| 53 | - $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - } |
|
| 44 | + // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 45 | + if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 46 | + $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 47 | + $flux['data']['editable'] = true; |
|
| 48 | + if (_request('var_mode') == 'configurer' && autoriser('webmestre')) { |
|
| 49 | + if (!_AJAX) { |
|
| 50 | + var_dump($flux['data']); |
|
| 51 | + } |
|
| 52 | + // reinjecter pour la trace au traitement |
|
| 53 | + $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - return $flux; |
|
| 58 | + return $flux; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -65,16 +65,16 @@ discard block |
||
| 65 | 65 | * @return array |
| 66 | 66 | */ |
| 67 | 67 | function cvtconf_formulaire_traiter($flux) { |
| 68 | - if ( |
|
| 69 | - ($form = $flux['args']['form']) |
|
| 70 | - && str_starts_with((string) $form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX |
|
| 71 | - && !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 72 | - ) { |
|
| 73 | - $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 74 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 75 | - } |
|
| 68 | + if ( |
|
| 69 | + ($form = $flux['args']['form']) |
|
| 70 | + && str_starts_with((string) $form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX |
|
| 71 | + && !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 72 | + ) { |
|
| 73 | + $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 74 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - return $flux; |
|
| 77 | + return $flux; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -90,32 +90,32 @@ discard block |
||
| 90 | 90 | * @return string |
| 91 | 91 | */ |
| 92 | 92 | function cvtconf_formulaires_configurer_enregistre($form, $args) { |
| 93 | - $valeurs = []; |
|
| 94 | - // charger les valeurs |
|
| 95 | - // ce qui permet de prendre en charge une fonction charger() existante |
|
| 96 | - // qui prend alors la main sur l'auto detection |
|
| 97 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 98 | - $valeurs = $charger_valeurs(...$args); |
|
| 99 | - } |
|
| 100 | - $valeurs = pipeline( |
|
| 101 | - 'formulaire_charger', |
|
| 102 | - [ |
|
| 103 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 104 | - 'data' => $valeurs |
|
| 105 | - ] |
|
| 106 | - ); |
|
| 107 | - // ne pas stocker editable ! |
|
| 108 | - unset($valeurs['editable']); |
|
| 93 | + $valeurs = []; |
|
| 94 | + // charger les valeurs |
|
| 95 | + // ce qui permet de prendre en charge une fonction charger() existante |
|
| 96 | + // qui prend alors la main sur l'auto detection |
|
| 97 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 98 | + $valeurs = $charger_valeurs(...$args); |
|
| 99 | + } |
|
| 100 | + $valeurs = pipeline( |
|
| 101 | + 'formulaire_charger', |
|
| 102 | + [ |
|
| 103 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 104 | + 'data' => $valeurs |
|
| 105 | + ] |
|
| 106 | + ); |
|
| 107 | + // ne pas stocker editable ! |
|
| 108 | + unset($valeurs['editable']); |
|
| 109 | 109 | |
| 110 | - // recuperer les valeurs postees |
|
| 111 | - $store = []; |
|
| 112 | - foreach ($valeurs as $k => $v) { |
|
| 113 | - if (!str_starts_with((string) $k, '_')) { |
|
| 114 | - $store[$k] = _request($k); |
|
| 115 | - } |
|
| 116 | - } |
|
| 110 | + // recuperer les valeurs postees |
|
| 111 | + $store = []; |
|
| 112 | + foreach ($valeurs as $k => $v) { |
|
| 113 | + if (!str_starts_with((string) $k, '_')) { |
|
| 114 | + $store[$k] = _request($k); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 118 | + return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -131,31 +131,31 @@ discard block |
||
| 131 | 131 | * @return array |
| 132 | 132 | */ |
| 133 | 133 | function cvtconf_definir_configurer_conteneur($form, $valeurs) { |
| 134 | - // stocker en base |
|
| 135 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 136 | - $casier = substr($form, 11); |
|
| 137 | - $table = 'meta'; |
|
| 138 | - $prefixe = ''; |
|
| 139 | - $stockage = ''; |
|
| 134 | + // stocker en base |
|
| 135 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 136 | + $casier = substr($form, 11); |
|
| 137 | + $table = 'meta'; |
|
| 138 | + $prefixe = ''; |
|
| 139 | + $stockage = ''; |
|
| 140 | 140 | |
| 141 | - if (isset($valeurs['_meta_casier'])) { |
|
| 142 | - $casier = $valeurs['_meta_casier']; |
|
| 143 | - } |
|
| 144 | - if (isset($valeurs['_meta_prefixe'])) { |
|
| 145 | - $prefixe = $valeurs['_meta_prefixe']; |
|
| 146 | - } |
|
| 147 | - if (isset($valeurs['_meta_stockage'])) { |
|
| 148 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 149 | - } |
|
| 141 | + if (isset($valeurs['_meta_casier'])) { |
|
| 142 | + $casier = $valeurs['_meta_casier']; |
|
| 143 | + } |
|
| 144 | + if (isset($valeurs['_meta_prefixe'])) { |
|
| 145 | + $prefixe = $valeurs['_meta_prefixe']; |
|
| 146 | + } |
|
| 147 | + if (isset($valeurs['_meta_stockage'])) { |
|
| 148 | + $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - // si on indique juste une table, il faut vider les autres proprietes |
|
| 152 | - // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 153 | - if (isset($valeurs['_meta_table'])) { |
|
| 154 | - $table = $valeurs['_meta_table']; |
|
| 155 | - $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 156 | - } |
|
| 151 | + // si on indique juste une table, il faut vider les autres proprietes |
|
| 152 | + // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 153 | + if (isset($valeurs['_meta_table'])) { |
|
| 154 | + $table = $valeurs['_meta_table']; |
|
| 155 | + $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - return [$table, $casier, $prefixe, $stockage]; |
|
| 158 | + return [$table, $casier, $prefixe, $stockage]; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -166,49 +166,49 @@ discard block |
||
| 166 | 166 | * @return array |
| 167 | 167 | */ |
| 168 | 168 | function cvtconf_formulaires_configurer_recense($form) { |
| 169 | - $contenu = null; |
|
| 170 | - $valeurs = ['editable' => ' ']; |
|
| 169 | + $contenu = null; |
|
| 170 | + $valeurs = ['editable' => ' ']; |
|
| 171 | 171 | |
| 172 | - // sinon cas analyse du squelette |
|
| 173 | - if ( |
|
| 174 | - ($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/')) |
|
| 175 | - && lire_fichier($f, $contenu) |
|
| 176 | - ) { |
|
| 177 | - for ($i = 0; $i < 2; $i++) { |
|
| 178 | - // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | - // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | - if ($i == 1) { |
|
| 181 | - $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | - } |
|
| 172 | + // sinon cas analyse du squelette |
|
| 173 | + if ( |
|
| 174 | + ($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/')) |
|
| 175 | + && lire_fichier($f, $contenu) |
|
| 176 | + ) { |
|
| 177 | + for ($i = 0; $i < 2; $i++) { |
|
| 178 | + // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | + // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | + if ($i == 1) { |
|
| 181 | + $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - $balises = array_merge( |
|
| 185 | - extraire_balises($contenu, 'input'), |
|
| 186 | - extraire_balises($contenu, 'textarea'), |
|
| 187 | - extraire_balises($contenu, 'select') |
|
| 188 | - ); |
|
| 184 | + $balises = array_merge( |
|
| 185 | + extraire_balises($contenu, 'input'), |
|
| 186 | + extraire_balises($contenu, 'textarea'), |
|
| 187 | + extraire_balises($contenu, 'select') |
|
| 188 | + ); |
|
| 189 | 189 | |
| 190 | - foreach ($balises as $b) { |
|
| 191 | - if ( |
|
| 192 | - ($n = extraire_attribut($b, 'name')) |
|
| 193 | - && preg_match(',^([\w\-]+)(\[\w*\])?$,', (string) $n, $r) |
|
| 194 | - && !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | - && extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | - ) { |
|
| 197 | - $valeurs[$r[1]] = ''; |
|
| 198 | - // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | - // en input hidden dans le squelette |
|
| 200 | - if (str_starts_with($r[1], '_meta_')) { |
|
| 201 | - $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 190 | + foreach ($balises as $b) { |
|
| 191 | + if ( |
|
| 192 | + ($n = extraire_attribut($b, 'name')) |
|
| 193 | + && preg_match(',^([\w\-]+)(\[\w*\])?$,', (string) $n, $r) |
|
| 194 | + && !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | + && extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | + ) { |
|
| 197 | + $valeurs[$r[1]] = ''; |
|
| 198 | + // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | + // en input hidden dans le squelette |
|
| 200 | + if (str_starts_with($r[1], '_meta_')) { |
|
| 201 | + $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | |
| 209 | - cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 209 | + cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 210 | 210 | |
| 211 | - return $valeurs; |
|
| 211 | + return $valeurs; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -220,26 +220,26 @@ discard block |
||
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | 222 | function cvtconf_configurer_stocker($form, $valeurs, $store) { |
| 223 | - $trace = ''; |
|
| 224 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | - // stocker en base |
|
| 226 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | - if (!isset($GLOBALS[$table])) { |
|
| 228 | - lire_metas($table); |
|
| 229 | - } |
|
| 223 | + $trace = ''; |
|
| 224 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | + // stocker en base |
|
| 226 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | + if (!isset($GLOBALS[$table])) { |
|
| 228 | + lire_metas($table); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | - $table = ($table) ? "/$table/" : ''; |
|
| 233 | - $casier = ($casier) ? rtrim((string) $casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 231 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | + $table = ($table) ? "/$table/" : ''; |
|
| 233 | + $casier = ($casier) ? rtrim((string) $casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 234 | 234 | |
| 235 | - foreach ($store as $k => $v) { |
|
| 236 | - ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | - if (_request('var_mode') == 'configurer' && autoriser('webmestre')) { |
|
| 238 | - $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | - } |
|
| 240 | - } |
|
| 235 | + foreach ($store as $k => $v) { |
|
| 236 | + ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | + if (_request('var_mode') == 'configurer' && autoriser('webmestre')) { |
|
| 238 | + $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return $trace; |
|
| 242 | + return $trace; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * @param array $valeurs |
| 250 | 250 | */ |
| 251 | 251 | function cvtconf_configurer_lire_meta($form, &$valeurs) { |
| 252 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 252 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 253 | 253 | |
| 254 | - $table = ($table) ? "/$table/" : ''; |
|
| 255 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | - if ($casier) { |
|
| 257 | - $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | - $prefixe = ''; |
|
| 259 | - } else { |
|
| 260 | - $table = rtrim($table, '/'); |
|
| 261 | - $meta = lire_config("$stockage$table"); |
|
| 262 | - } |
|
| 254 | + $table = ($table) ? "/$table/" : ''; |
|
| 255 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | + if ($casier) { |
|
| 257 | + $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | + $prefixe = ''; |
|
| 259 | + } else { |
|
| 260 | + $table = rtrim($table, '/'); |
|
| 261 | + $meta = lire_config("$stockage$table"); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - foreach (array_keys($valeurs) as $k) { |
|
| 265 | - if (!str_starts_with($k, '_')) { |
|
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | - } |
|
| 268 | - } |
|
| 264 | + foreach (array_keys($valeurs) as $k) { |
|
| 265 | + if (!str_starts_with($k, '_')) { |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | ) { |
| 38 | 38 | // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
| 39 | 39 | include_spip('inc/autoriser'); |
| 40 | - if (!autoriser('configurer', '_' . substr((string) $form, 11))) { |
|
| 40 | + if (!autoriser('configurer', '_'.substr((string) $form, 11))) { |
|
| 41 | 41 | return false; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | && !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
| 72 | 72 | ) { |
| 73 | 73 | $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
| 74 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 74 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree').$trace, 'editable' => true]; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | return $flux; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $prefixe = $valeurs['_meta_prefixe']; |
| 146 | 146 | } |
| 147 | 147 | if (isset($valeurs['_meta_stockage'])) { |
| 148 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 148 | + $stockage = $valeurs['_meta_stockage'].'::'; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // si on indique juste une table, il faut vider les autres proprietes |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | // sinon cas analyse du squelette |
| 173 | 173 | if ( |
| 174 | - ($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/')) |
|
| 174 | + ($f = find_in_path($form.'.'._EXTENSION_SQUELETTES, 'formulaires/')) |
|
| 175 | 175 | && lire_fichier($f, $contenu) |
| 176 | 176 | ) { |
| 177 | 177 | for ($i = 0; $i < 2; $i++) { |
@@ -228,14 +228,14 @@ discard block |
||
| 228 | 228 | lire_metas($table); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 231 | + $prefixe = ($prefixe ? $prefixe.'_' : ''); |
|
| 232 | 232 | $table = ($table) ? "/$table/" : ''; |
| 233 | - $casier = ($casier) ? rtrim((string) $casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 233 | + $casier = ($casier) ? rtrim((string) $casier, '/').'/' : ''; // slash final, sinon rien |
|
| 234 | 234 | |
| 235 | 235 | foreach ($store as $k => $v) { |
| 236 | 236 | ecrire_config("$stockage$table$prefixe$casier$k", $v); |
| 237 | 237 | if (_request('var_mode') == 'configurer' && autoriser('webmestre')) { |
| 238 | - $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 238 | + $trace .= "<br />table $table : ".$prefixe.$k." = $v;"; |
|
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
| 253 | 253 | |
| 254 | 254 | $table = ($table) ? "/$table/" : ''; |
| 255 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 255 | + $prefixe = ($prefixe ? $prefixe.'_' : ''); |
|
| 256 | 256 | if ($casier) { |
| 257 | 257 | $meta = lire_config("$stockage$table$prefixe$casier"); |
| 258 | 258 | $prefixe = ''; |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | foreach (array_keys($valeurs) as $k) { |
| 265 | 265 | if (!str_starts_with($k, '_')) { |
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe.$k] ?? null); |
|
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -35,20 +35,20 @@ discard block |
||
| 35 | 35 | **/ |
| 36 | 36 | function base_repair_dist($titre = '', $reprise = '') { |
| 37 | 37 | |
| 38 | - $res = admin_repair_tables(); |
|
| 39 | - if (!$res) { |
|
| 40 | - $res = "<div class='error'>" . _T('avis_erreur_mysql') . ' ' . sql_errno() . ': ' . sql_error() . "</div>\n"; |
|
| 41 | - } else { |
|
| 42 | - include_spip('inc/rubriques'); |
|
| 43 | - calculer_rubriques(); |
|
| 44 | - propager_les_secteurs(); |
|
| 45 | - } |
|
| 46 | - include_spip('inc/minipres'); |
|
| 47 | - $res .= pipeline('base_admin_repair', $res); |
|
| 48 | - echo minipres( |
|
| 49 | - _T('texte_tentative_recuperation'), |
|
| 50 | - $res . generer_form_ecrire('accueil', '', '', _T('public:accueil_site')) |
|
| 51 | - ); |
|
| 38 | + $res = admin_repair_tables(); |
|
| 39 | + if (!$res) { |
|
| 40 | + $res = "<div class='error'>" . _T('avis_erreur_mysql') . ' ' . sql_errno() . ': ' . sql_error() . "</div>\n"; |
|
| 41 | + } else { |
|
| 42 | + include_spip('inc/rubriques'); |
|
| 43 | + calculer_rubriques(); |
|
| 44 | + propager_les_secteurs(); |
|
| 45 | + } |
|
| 46 | + include_spip('inc/minipres'); |
|
| 47 | + $res .= pipeline('base_admin_repair', $res); |
|
| 48 | + echo minipres( |
|
| 49 | + _T('texte_tentative_recuperation'), |
|
| 50 | + $res . generer_form_ecrire('accueil', '', '', _T('public:accueil_site')) |
|
| 51 | + ); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -62,60 +62,60 @@ discard block |
||
| 62 | 62 | **/ |
| 63 | 63 | function admin_repair_tables() { |
| 64 | 64 | |
| 65 | - $repair = sql_serveur('repair', '', true); |
|
| 65 | + $repair = sql_serveur('repair', '', true); |
|
| 66 | 66 | |
| 67 | - // recreer les tables manquantes eventuelles |
|
| 68 | - include_spip('base/create'); |
|
| 69 | - creer_base(); |
|
| 70 | - $tables = sql_alltable(); |
|
| 67 | + // recreer les tables manquantes eventuelles |
|
| 68 | + include_spip('base/create'); |
|
| 69 | + creer_base(); |
|
| 70 | + $tables = sql_alltable(); |
|
| 71 | 71 | |
| 72 | - $res = ''; |
|
| 73 | - foreach ($tables as $tab) { |
|
| 74 | - $class = ''; |
|
| 75 | - $m = "<strong>$tab</strong> "; |
|
| 76 | - spip_log("Repare $tab", _LOG_INFO_IMPORTANTE); |
|
| 77 | - // supprimer la meta avant de lancer la reparation |
|
| 78 | - // car le repair peut etre long ; on ne veut pas boucler |
|
| 79 | - effacer_meta('admin_repair'); |
|
| 80 | - if ($repair) { |
|
| 81 | - $result_repair = sql_repair($tab); |
|
| 82 | - if (!$result_repair) { |
|
| 83 | - return false; |
|
| 84 | - } |
|
| 85 | - } |
|
| 72 | + $res = ''; |
|
| 73 | + foreach ($tables as $tab) { |
|
| 74 | + $class = ''; |
|
| 75 | + $m = "<strong>$tab</strong> "; |
|
| 76 | + spip_log("Repare $tab", _LOG_INFO_IMPORTANTE); |
|
| 77 | + // supprimer la meta avant de lancer la reparation |
|
| 78 | + // car le repair peut etre long ; on ne veut pas boucler |
|
| 79 | + effacer_meta('admin_repair'); |
|
| 80 | + if ($repair) { |
|
| 81 | + $result_repair = sql_repair($tab); |
|
| 82 | + if (!$result_repair) { |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - // essayer de maj la table (creation de champs manquants) |
|
| 88 | - maj_tables($tab); |
|
| 87 | + // essayer de maj la table (creation de champs manquants) |
|
| 88 | + maj_tables($tab); |
|
| 89 | 89 | |
| 90 | - $count = sql_countsel($tab); |
|
| 90 | + $count = sql_countsel($tab); |
|
| 91 | 91 | |
| 92 | - if ($count > 1) { |
|
| 93 | - $m .= '(' . _T('texte_compte_elements', ['count' => $count]) . ")\n"; |
|
| 94 | - } else { |
|
| 95 | - if ($count == 1) { |
|
| 96 | - $m .= '(' . _T('texte_compte_element', ['count' => $count]) . ")\n"; |
|
| 97 | - } else { |
|
| 98 | - $m .= '(' . _T('texte_vide') . ")\n"; |
|
| 99 | - } |
|
| 100 | - } |
|
| 92 | + if ($count > 1) { |
|
| 93 | + $m .= '(' . _T('texte_compte_elements', ['count' => $count]) . ")\n"; |
|
| 94 | + } else { |
|
| 95 | + if ($count == 1) { |
|
| 96 | + $m .= '(' . _T('texte_compte_element', ['count' => $count]) . ")\n"; |
|
| 97 | + } else { |
|
| 98 | + $m .= '(' . _T('texte_vide') . ")\n"; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - if ( |
|
| 103 | - $repair |
|
| 104 | - && $result_repair |
|
| 105 | - && ($msg = implode( |
|
| 106 | - ' ', |
|
| 107 | - (is_resource($result_repair) || is_object($result_repair)) ? sql_fetch($result_repair) : $result_repair |
|
| 108 | - ) . ' ') |
|
| 109 | - && !str_contains($msg, ' OK ') |
|
| 110 | - ) { |
|
| 111 | - $class = " class='notice'"; |
|
| 112 | - $m .= '<br /><tt>' . spip_htmlentities($msg) . "</tt>\n"; |
|
| 113 | - } else { |
|
| 114 | - $m .= ' ' . _T('texte_table_ok'); |
|
| 115 | - } |
|
| 102 | + if ( |
|
| 103 | + $repair |
|
| 104 | + && $result_repair |
|
| 105 | + && ($msg = implode( |
|
| 106 | + ' ', |
|
| 107 | + (is_resource($result_repair) || is_object($result_repair)) ? sql_fetch($result_repair) : $result_repair |
|
| 108 | + ) . ' ') |
|
| 109 | + && !str_contains($msg, ' OK ') |
|
| 110 | + ) { |
|
| 111 | + $class = " class='notice'"; |
|
| 112 | + $m .= '<br /><tt>' . spip_htmlentities($msg) . "</tt>\n"; |
|
| 113 | + } else { |
|
| 114 | + $m .= ' ' . _T('texte_table_ok'); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - $res .= "<div$class>$m</div>"; |
|
| 118 | - } |
|
| 117 | + $res .= "<div$class>$m</div>"; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - return $res; |
|
| 120 | + return $res; |
|
| 121 | 121 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | $res = admin_repair_tables(); |
| 39 | 39 | if (!$res) { |
| 40 | - $res = "<div class='error'>" . _T('avis_erreur_mysql') . ' ' . sql_errno() . ': ' . sql_error() . "</div>\n"; |
|
| 40 | + $res = "<div class='error'>"._T('avis_erreur_mysql').' '.sql_errno().': '.sql_error()."</div>\n"; |
|
| 41 | 41 | } else { |
| 42 | 42 | include_spip('inc/rubriques'); |
| 43 | 43 | calculer_rubriques(); |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $res .= pipeline('base_admin_repair', $res); |
| 48 | 48 | echo minipres( |
| 49 | 49 | _T('texte_tentative_recuperation'), |
| 50 | - $res . generer_form_ecrire('accueil', '', '', _T('public:accueil_site')) |
|
| 50 | + $res.generer_form_ecrire('accueil', '', '', _T('public:accueil_site')) |
|
| 51 | 51 | ); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | $count = sql_countsel($tab); |
| 91 | 91 | |
| 92 | 92 | if ($count > 1) { |
| 93 | - $m .= '(' . _T('texte_compte_elements', ['count' => $count]) . ")\n"; |
|
| 93 | + $m .= '('._T('texte_compte_elements', ['count' => $count]).")\n"; |
|
| 94 | 94 | } else { |
| 95 | 95 | if ($count == 1) { |
| 96 | - $m .= '(' . _T('texte_compte_element', ['count' => $count]) . ")\n"; |
|
| 96 | + $m .= '('._T('texte_compte_element', ['count' => $count]).")\n"; |
|
| 97 | 97 | } else { |
| 98 | - $m .= '(' . _T('texte_vide') . ")\n"; |
|
| 98 | + $m .= '('._T('texte_vide').")\n"; |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
@@ -105,13 +105,13 @@ discard block |
||
| 105 | 105 | && ($msg = implode( |
| 106 | 106 | ' ', |
| 107 | 107 | (is_resource($result_repair) || is_object($result_repair)) ? sql_fetch($result_repair) : $result_repair |
| 108 | - ) . ' ') |
|
| 108 | + ).' ') |
|
| 109 | 109 | && !str_contains($msg, ' OK ') |
| 110 | 110 | ) { |
| 111 | 111 | $class = " class='notice'"; |
| 112 | - $m .= '<br /><tt>' . spip_htmlentities($msg) . "</tt>\n"; |
|
| 112 | + $m .= '<br /><tt>'.spip_htmlentities($msg)."</tt>\n"; |
|
| 113 | 113 | } else { |
| 114 | - $m .= ' ' . _T('texte_table_ok'); |
|
| 114 | + $m .= ' '._T('texte_table_ok'); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $res .= "<div$class>$m</div>"; |
@@ -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 | /** |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @return void |
| 34 | 34 | **/ |
| 35 | 35 | function array_set_merge(&$table, $index, $valeur) { |
| 36 | - $table[$index] = isset($table[$index]) ? array_merge($table[$index], $valeur) : $valeur; |
|
| 36 | + $table[$index] = isset($table[$index]) ? array_merge($table[$index], $valeur) : $valeur; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -52,441 +52,441 @@ discard block |
||
| 52 | 52 | * - string (interne) si table '::md5' retourne un hash |
| 53 | 53 | */ |
| 54 | 54 | function lister_tables_objets_sql(?string $table_sql = null, $desc = []) { |
| 55 | - static $deja_la = false; |
|
| 56 | - static $infos_tables = null; |
|
| 57 | - static $md5 = null; |
|
| 58 | - static $plugin_hash = null; |
|
| 59 | - |
|
| 60 | - // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 61 | - $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 62 | - |
|
| 63 | - // prealablement recuperer les tables_principales |
|
| 64 | - if (is_null($infos_tables) || $plugin_hash !== $_PLUGINS_HASH) { |
|
| 65 | - // pas de reentrance (cas base/serial) |
|
| 66 | - if ($deja_la) { |
|
| 67 | - spip_log('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 68 | - . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 69 | - |
|
| 70 | - return ($table_sql === '::md5' ? $md5 : []); |
|
| 71 | - } |
|
| 72 | - $deja_la = true; |
|
| 73 | - $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 74 | - |
|
| 75 | - // recuperer les declarations explicites ancienne mode |
|
| 76 | - // qui servent a completer declarer_tables_objets_sql |
|
| 77 | - base_serial($GLOBALS['tables_principales']); |
|
| 78 | - base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 79 | - $infos_tables = [ |
|
| 80 | - 'spip_articles' => [ |
|
| 81 | - 'page' => 'article', |
|
| 82 | - 'texte_retour' => 'icone_retour_article', |
|
| 83 | - 'texte_modifier' => 'icone_modifier_article', |
|
| 84 | - 'texte_creer' => 'icone_ecrire_article', |
|
| 85 | - 'texte_objets' => 'public:articles', |
|
| 86 | - 'texte_objet' => 'public:article', |
|
| 87 | - 'texte_signale_edition' => 'texte_travail_article', |
|
| 88 | - 'info_aucun_objet' => 'info_aucun_article', |
|
| 89 | - 'info_1_objet' => 'info_1_article', |
|
| 90 | - 'info_nb_objets' => 'info_nb_articles', |
|
| 91 | - 'texte_logo_objet' => 'logo_article', |
|
| 92 | - 'texte_langue_objet' => 'titre_langue_article', |
|
| 93 | - 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 94 | - 'titre' => 'titre, lang', |
|
| 95 | - 'date' => 'date', |
|
| 96 | - 'principale' => 'oui', |
|
| 97 | - 'introduction_longueur' => '500', |
|
| 98 | - 'champs_editables' => [ |
|
| 99 | - 'surtitre', |
|
| 100 | - 'titre', |
|
| 101 | - 'soustitre', |
|
| 102 | - 'descriptif', |
|
| 103 | - 'nom_site', |
|
| 104 | - 'url_site', |
|
| 105 | - 'chapo', |
|
| 106 | - 'texte', |
|
| 107 | - 'ps', |
|
| 108 | - 'virtuel' |
|
| 109 | - ], |
|
| 110 | - 'champs_versionnes' => [ |
|
| 111 | - 'id_rubrique', |
|
| 112 | - 'surtitre', |
|
| 113 | - 'titre', |
|
| 114 | - 'soustitre', |
|
| 115 | - 'jointure_auteurs', |
|
| 116 | - 'descriptif', |
|
| 117 | - 'nom_site', |
|
| 118 | - 'url_site', |
|
| 119 | - 'chapo', |
|
| 120 | - 'texte', |
|
| 121 | - 'ps' |
|
| 122 | - ], |
|
| 123 | - 'field' => [ |
|
| 124 | - 'id_article' => 'bigint(21) NOT NULL', |
|
| 125 | - 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 126 | - 'titre' => "text DEFAULT '' NOT NULL", |
|
| 127 | - 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 128 | - 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 129 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 130 | - 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 131 | - 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 132 | - 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 133 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 134 | - 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 135 | - 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 136 | - 'maj' => 'TIMESTAMP', |
|
| 137 | - 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 138 | - 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 139 | - 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 140 | - 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 141 | - 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 142 | - 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 143 | - 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 144 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 145 | - 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 146 | - 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 147 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 148 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 149 | - 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 150 | - ], |
|
| 151 | - 'key' => [ |
|
| 152 | - 'PRIMARY KEY' => 'id_article', |
|
| 153 | - 'KEY id_rubrique' => 'id_rubrique', |
|
| 154 | - 'KEY id_secteur' => 'id_secteur', |
|
| 155 | - 'KEY id_trad' => 'id_trad', |
|
| 156 | - 'KEY lang' => 'lang', |
|
| 157 | - 'KEY statut' => 'statut, date', |
|
| 158 | - ], |
|
| 159 | - 'join' => [ |
|
| 160 | - 'id_article' => 'id_article', |
|
| 161 | - 'id_rubrique' => 'id_rubrique' |
|
| 162 | - ], |
|
| 163 | - 'parent' => [ |
|
| 164 | - ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 165 | - ], |
|
| 166 | - 'rechercher_champs' => [ |
|
| 167 | - 'surtitre' => 5, |
|
| 168 | - 'titre' => 8, |
|
| 169 | - 'soustitre' => 5, |
|
| 170 | - 'chapo' => 3, |
|
| 171 | - 'texte' => 1, |
|
| 172 | - 'ps' => 1, |
|
| 173 | - 'nom_site' => 1, |
|
| 174 | - 'url_site' => 1, |
|
| 175 | - 'descriptif' => 4 |
|
| 176 | - ], |
|
| 177 | - 'rechercher_jointures' => [ |
|
| 178 | - 'auteur' => ['nom' => 10], |
|
| 179 | - ], |
|
| 180 | - 'statut' => [ |
|
| 181 | - [ |
|
| 182 | - 'champ' => 'statut', |
|
| 183 | - 'publie' => 'publie', |
|
| 184 | - 'previsu' => 'publie,prop,prepa/auteur', |
|
| 185 | - 'post_date' => 'date', |
|
| 186 | - 'exception' => ['statut', 'tout'] |
|
| 187 | - ] |
|
| 188 | - ], |
|
| 189 | - 'statut_titres' => [ |
|
| 190 | - 'prepa' => 'info_article_redaction', |
|
| 191 | - 'prop' => 'info_article_propose', |
|
| 192 | - 'publie' => 'info_article_publie', |
|
| 193 | - 'refuse' => 'info_article_refuse', |
|
| 194 | - 'poubelle' => 'info_article_supprime' |
|
| 195 | - ], |
|
| 196 | - 'statut_textes_instituer' => [ |
|
| 197 | - 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 198 | - 'prop' => 'texte_statut_propose_evaluation', |
|
| 199 | - 'publie' => 'texte_statut_publie', |
|
| 200 | - 'refuse' => 'texte_statut_refuse', |
|
| 201 | - 'poubelle' => 'texte_statut_poubelle', |
|
| 202 | - ], |
|
| 203 | - 'texte_changer_statut' => 'texte_article_statut', |
|
| 204 | - 'aide_changer_statut' => 'artstatut', |
|
| 205 | - 'tables_jointures' => [ |
|
| 206 | - 'profondeur' => 'rubriques', |
|
| 207 | - #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 208 | - ], |
|
| 209 | - ], |
|
| 210 | - 'spip_auteurs' => [ |
|
| 211 | - 'page' => 'auteur', |
|
| 212 | - 'texte_retour' => 'icone_retour', |
|
| 213 | - 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 214 | - 'texte_modifier' => 'admin_modifier_auteur', |
|
| 215 | - 'texte_objets' => 'icone_auteurs', |
|
| 216 | - 'texte_objet' => 'public:auteur', |
|
| 217 | - 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 218 | - 'info_1_objet' => 'info_1_auteur', |
|
| 219 | - 'info_nb_objets' => 'info_nb_auteurs', |
|
| 220 | - 'texte_logo_objet' => 'logo_auteur', |
|
| 221 | - 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 222 | - 'titre' => "nom AS titre, '' AS lang", |
|
| 223 | - 'date' => 'date', |
|
| 224 | - 'principale' => 'oui', |
|
| 225 | - 'champs_editables' => ['nom', 'email', 'lang', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'], |
|
| 226 | - 'champs_versionnes' => ['nom', 'bio', 'lang', 'email', 'nom_site', 'url_site', 'login'], |
|
| 227 | - 'field' => [ |
|
| 228 | - 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 229 | - 'nom' => "text DEFAULT '' NOT NULL", |
|
| 230 | - 'bio' => "text DEFAULT '' NOT NULL", |
|
| 231 | - 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 232 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 233 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 234 | - 'login' => 'VARCHAR(255) BINARY', |
|
| 235 | - 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 236 | - 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 237 | - 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 238 | - 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 239 | - 'maj' => 'TIMESTAMP', |
|
| 240 | - 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 241 | - 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 242 | - 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 243 | - 'alea_actuel' => 'tinytext', |
|
| 244 | - 'alea_futur' => 'tinytext', |
|
| 245 | - 'prefs' => 'text', |
|
| 246 | - 'cookie_oubli' => 'tinytext', |
|
| 247 | - 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 248 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 249 | - 'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL", |
|
| 250 | - 'backup_cles' => "mediumtext DEFAULT '' NOT NULL", |
|
| 251 | - ], |
|
| 252 | - 'key' => [ |
|
| 253 | - 'PRIMARY KEY' => 'id_auteur', |
|
| 254 | - 'KEY login' => 'login', |
|
| 255 | - 'KEY statut' => 'statut', |
|
| 256 | - 'KEY en_ligne' => 'en_ligne', |
|
| 257 | - ], |
|
| 258 | - 'join' => [ |
|
| 259 | - 'id_auteur' => 'id_auteur', |
|
| 260 | - 'login' => 'login' |
|
| 261 | - ], |
|
| 262 | - 'rechercher_champs' => [ |
|
| 263 | - 'nom' => 5, |
|
| 264 | - 'bio' => 1, |
|
| 265 | - 'email' => 1, |
|
| 266 | - 'nom_site' => 1, |
|
| 267 | - 'url_site' => 1, |
|
| 268 | - 'login' => 1 |
|
| 269 | - ], |
|
| 270 | - // 2 conditions pour les auteurs : statut!=poubelle, |
|
| 271 | - // et avoir des articles publies |
|
| 272 | - 'statut' => [ |
|
| 273 | - [ |
|
| 274 | - 'champ' => 'statut', |
|
| 275 | - 'publie' => '!5poubelle', |
|
| 276 | - 'previsu' => '!5poubelle', |
|
| 277 | - 'exception' => 'statut' |
|
| 278 | - ], |
|
| 279 | - [ |
|
| 280 | - 'champ' => [ |
|
| 281 | - ['spip_auteurs_liens', 'id_auteur'], |
|
| 282 | - [ |
|
| 283 | - 'spip_articles', |
|
| 284 | - ['id_objet', 'id_article', 'objet', 'article'] |
|
| 285 | - ], |
|
| 286 | - 'statut' |
|
| 287 | - ], |
|
| 288 | - 'publie' => 'publie', |
|
| 289 | - 'previsu' => '!', |
|
| 290 | - 'post_date' => 'date', |
|
| 291 | - 'exception' => ['statut', 'lien', 'tout'] |
|
| 292 | - ], |
|
| 293 | - ], |
|
| 294 | - 'statut_images' => [ |
|
| 295 | - 'auteur-6forum-16.png', |
|
| 296 | - '0minirezo' => 'auteur-0minirezo-16.png', |
|
| 297 | - '1comite' => 'auteur-1comite-16.png', |
|
| 298 | - '6forum' => 'auteur-6forum-16.png', |
|
| 299 | - '5poubelle' => 'auteur-5poubelle-16.png', |
|
| 300 | - 'nouveau' => '' |
|
| 301 | - ], |
|
| 302 | - 'statut_titres' => [ |
|
| 303 | - 'titre_image_visiteur', |
|
| 304 | - '0minirezo' => 'titre_image_administrateur', |
|
| 305 | - '1comite' => 'titre_image_redacteur_02', |
|
| 306 | - '6forum' => 'titre_image_visiteur', |
|
| 307 | - '5poubelle' => 'titre_image_auteur_supprime', |
|
| 308 | - ], |
|
| 309 | - 'tables_jointures' => [#'auteurs_liens' // declaration generique plus bas |
|
| 310 | - ], |
|
| 311 | - ], |
|
| 312 | - 'spip_rubriques' => [ |
|
| 313 | - 'page' => 'rubrique', |
|
| 314 | - 'url_voir' => 'rubrique', |
|
| 315 | - 'url_edit' => 'rubrique_edit', |
|
| 316 | - 'texte_retour' => 'icone_retour', |
|
| 317 | - 'texte_objets' => 'public:rubriques', |
|
| 318 | - 'texte_objet' => 'public:rubrique', |
|
| 319 | - 'texte_modifier' => 'icone_modifier_rubrique', |
|
| 320 | - 'texte_creer' => 'icone_creer_rubrique', |
|
| 321 | - 'texte_ajouter' => 'titre_ajouter_une_rubrique', |
|
| 322 | - 'texte_creer_associer' => 'creer_et_associer_une_rubrique', |
|
| 323 | - 'info_aucun_objet' => 'info_aucun_rubrique', |
|
| 324 | - 'info_1_objet' => 'info_1_rubrique', |
|
| 325 | - 'info_nb_objets' => 'info_nb_rubriques', |
|
| 326 | - 'texte_logo_objet' => 'logo_rubrique', |
|
| 327 | - 'texte_langue_objet' => 'titre_langue_rubrique', |
|
| 328 | - 'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique', |
|
| 329 | - 'titre' => 'titre, lang', |
|
| 330 | - 'date' => 'date', |
|
| 331 | - 'principale' => 'oui', |
|
| 332 | - 'introduction_longueur' => '600', |
|
| 333 | - 'champs_editables' => ['titre', 'texte', 'descriptif', 'extra'], |
|
| 334 | - 'champs_versionnes' => ['titre', 'descriptif', 'texte'], |
|
| 335 | - 'field' => [ |
|
| 336 | - 'id_rubrique' => 'bigint(21) NOT NULL', |
|
| 337 | - 'id_parent' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 338 | - 'titre' => "text DEFAULT '' NOT NULL", |
|
| 339 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 340 | - 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 341 | - 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 342 | - 'maj' => 'TIMESTAMP', |
|
| 343 | - 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 344 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 345 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 346 | - 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 347 | - 'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 348 | - 'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 349 | - 'profondeur' => "smallint(5) DEFAULT '0' NOT NULL" |
|
| 350 | - ], |
|
| 351 | - 'key' => [ |
|
| 352 | - 'PRIMARY KEY' => 'id_rubrique', |
|
| 353 | - 'KEY lang' => 'lang', |
|
| 354 | - 'KEY id_parent' => 'id_parent', |
|
| 355 | - ], |
|
| 356 | - 'parent' => [ |
|
| 357 | - ['type' => 'rubrique', 'champ' => 'id_parent'] |
|
| 358 | - ], |
|
| 359 | - 'rechercher_champs' => [ |
|
| 360 | - 'titre' => 8, |
|
| 361 | - 'descriptif' => 5, |
|
| 362 | - 'texte' => 1 |
|
| 363 | - ], |
|
| 364 | - 'statut' => [ |
|
| 365 | - [ |
|
| 366 | - 'champ' => 'statut', |
|
| 367 | - 'publie' => 'publie', |
|
| 368 | - 'previsu' => '!', |
|
| 369 | - 'exception' => ['statut', 'tout'] |
|
| 370 | - ], |
|
| 371 | - ], |
|
| 372 | - 'tables_jointures' => [#'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 373 | - ], |
|
| 374 | - ], |
|
| 375 | - // toutes les tables ont le droit a une jointure sur les auteurs |
|
| 376 | - ['tables_jointures' => ['id_auteur' => 'auteurs_liens']] |
|
| 377 | - ]; |
|
| 378 | - |
|
| 379 | - // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install |
|
| 380 | - // initialiser la signature |
|
| 381 | - $md5 = md5(serialize($infos_tables)); |
|
| 382 | - |
|
| 383 | - $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']); |
|
| 384 | - $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']); |
|
| 385 | - $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables); |
|
| 386 | - |
|
| 387 | - // completer les informations manquantes ou implicites |
|
| 388 | - $all = []; |
|
| 389 | - foreach (array_keys($infos_tables) as $t) { |
|
| 390 | - // les cles numeriques servent a declarer |
|
| 391 | - // les proprietes applicables a tous les objets |
|
| 392 | - // on les mets de cote |
|
| 393 | - if (is_numeric($t)) { |
|
| 394 | - $all = array_merge_recursive($all, $infos_tables[$t]); |
|
| 395 | - unset($infos_tables[$t]); |
|
| 396 | - } else { |
|
| 397 | - $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]); |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - // repercuter les proprietes generales communes a tous les objets |
|
| 402 | - foreach (array_keys($infos_tables) as $t) { |
|
| 403 | - foreach (array_keys($all) as $i) { |
|
| 404 | - if (in_array($i, ['tables_jointures', 'champs_versionnes'])) { |
|
| 405 | - $add = $all[$i]; |
|
| 406 | - // eviter les doublons de declaration de table jointure (ex des mots sur auteurs) |
|
| 407 | - // pour les declarations generiques avec cles numeriques |
|
| 408 | - if ($i == 'tables_jointures' && isset($infos_tables[$t][$i]) && (is_countable($infos_tables[$t][$i]) ? count($infos_tables[$t][$i]) : 0)) { |
|
| 409 | - $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 410 | - foreach ($doublons as $d) { |
|
| 411 | - if ( |
|
| 412 | - is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 413 | - && is_numeric($k = array_search($d, $add)) |
|
| 414 | - ) { |
|
| 415 | - unset($add[$k]); |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - $infos_tables[$t][$i] = array_merge($infos_tables[$t][$i] ?? [], $add); |
|
| 420 | - } else { |
|
| 421 | - $infos_tables[$t][$i] = array_merge_recursive( |
|
| 422 | - $infos_tables[$t][$i] ?? [], |
|
| 423 | - $all[$i] |
|
| 424 | - ); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // completer les tables principales et auxiliaires |
|
| 430 | - // avec celles declarees uniquement dans declarer_table_objets_sql |
|
| 431 | - // pour assurer la compat en transition |
|
| 432 | - foreach ($infos_tables as $table => $infos) { |
|
| 433 | - $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 434 | - // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
|
| 435 | - // qui a ete appelle avant |
|
| 436 | - $mem = ($GLOBALS[$principale_ou_auxiliaire][$table] ?? []); |
|
| 437 | - // l'ajouter au tableau |
|
| 438 | - $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 439 | - if (isset($infos['field']) && isset($infos['key'])) { |
|
| 440 | - foreach (['field', 'key', 'join'] as $k) { |
|
| 441 | - if (isset($infos_tables[$table][$k])) { |
|
| 442 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } else { |
|
| 446 | - // ici on ne renvoie que les declarations, donc RIEN |
|
| 447 | - // pour avoir la vrai description en base, il faut passer par trouver_table |
|
| 448 | - $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 449 | - } |
|
| 450 | - if (is_countable($mem) ? count($mem) : 0) { |
|
| 451 | - foreach (array_keys($mem) as $k) { |
|
| 452 | - if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) { |
|
| 453 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge( |
|
| 454 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k], |
|
| 455 | - $mem[$k] |
|
| 456 | - ); |
|
| 457 | - } else { |
|
| 458 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - // recuperer les interfaces (table_titre, table_date) |
|
| 465 | - // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
|
| 466 | - // dans le pipeline de declarer_tables_interfaces |
|
| 467 | - include_spip('public/interfaces'); |
|
| 468 | - foreach (array_keys($infos_tables) as $t) { |
|
| 469 | - $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - $deja_la = false; |
|
| 473 | - // signature |
|
| 474 | - $md5 = md5(serialize($infos_tables)); |
|
| 475 | - } |
|
| 476 | - if ($table_sql === '::md5') { |
|
| 477 | - return $md5; |
|
| 478 | - } |
|
| 479 | - if ($table_sql && !isset($infos_tables[$table_sql])) { |
|
| 480 | - #$desc = renseigner_table_objet_sql($table_sql,$desc); |
|
| 481 | - $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 482 | - |
|
| 483 | - return $desc; |
|
| 484 | - } |
|
| 485 | - if ($table_sql) { |
|
| 486 | - return $infos_tables[$table_sql] ?? []; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - return $infos_tables; |
|
| 55 | + static $deja_la = false; |
|
| 56 | + static $infos_tables = null; |
|
| 57 | + static $md5 = null; |
|
| 58 | + static $plugin_hash = null; |
|
| 59 | + |
|
| 60 | + // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 61 | + $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 62 | + |
|
| 63 | + // prealablement recuperer les tables_principales |
|
| 64 | + if (is_null($infos_tables) || $plugin_hash !== $_PLUGINS_HASH) { |
|
| 65 | + // pas de reentrance (cas base/serial) |
|
| 66 | + if ($deja_la) { |
|
| 67 | + spip_log('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 68 | + . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 69 | + |
|
| 70 | + return ($table_sql === '::md5' ? $md5 : []); |
|
| 71 | + } |
|
| 72 | + $deja_la = true; |
|
| 73 | + $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 74 | + |
|
| 75 | + // recuperer les declarations explicites ancienne mode |
|
| 76 | + // qui servent a completer declarer_tables_objets_sql |
|
| 77 | + base_serial($GLOBALS['tables_principales']); |
|
| 78 | + base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 79 | + $infos_tables = [ |
|
| 80 | + 'spip_articles' => [ |
|
| 81 | + 'page' => 'article', |
|
| 82 | + 'texte_retour' => 'icone_retour_article', |
|
| 83 | + 'texte_modifier' => 'icone_modifier_article', |
|
| 84 | + 'texte_creer' => 'icone_ecrire_article', |
|
| 85 | + 'texte_objets' => 'public:articles', |
|
| 86 | + 'texte_objet' => 'public:article', |
|
| 87 | + 'texte_signale_edition' => 'texte_travail_article', |
|
| 88 | + 'info_aucun_objet' => 'info_aucun_article', |
|
| 89 | + 'info_1_objet' => 'info_1_article', |
|
| 90 | + 'info_nb_objets' => 'info_nb_articles', |
|
| 91 | + 'texte_logo_objet' => 'logo_article', |
|
| 92 | + 'texte_langue_objet' => 'titre_langue_article', |
|
| 93 | + 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 94 | + 'titre' => 'titre, lang', |
|
| 95 | + 'date' => 'date', |
|
| 96 | + 'principale' => 'oui', |
|
| 97 | + 'introduction_longueur' => '500', |
|
| 98 | + 'champs_editables' => [ |
|
| 99 | + 'surtitre', |
|
| 100 | + 'titre', |
|
| 101 | + 'soustitre', |
|
| 102 | + 'descriptif', |
|
| 103 | + 'nom_site', |
|
| 104 | + 'url_site', |
|
| 105 | + 'chapo', |
|
| 106 | + 'texte', |
|
| 107 | + 'ps', |
|
| 108 | + 'virtuel' |
|
| 109 | + ], |
|
| 110 | + 'champs_versionnes' => [ |
|
| 111 | + 'id_rubrique', |
|
| 112 | + 'surtitre', |
|
| 113 | + 'titre', |
|
| 114 | + 'soustitre', |
|
| 115 | + 'jointure_auteurs', |
|
| 116 | + 'descriptif', |
|
| 117 | + 'nom_site', |
|
| 118 | + 'url_site', |
|
| 119 | + 'chapo', |
|
| 120 | + 'texte', |
|
| 121 | + 'ps' |
|
| 122 | + ], |
|
| 123 | + 'field' => [ |
|
| 124 | + 'id_article' => 'bigint(21) NOT NULL', |
|
| 125 | + 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 126 | + 'titre' => "text DEFAULT '' NOT NULL", |
|
| 127 | + 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 128 | + 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 129 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 130 | + 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 131 | + 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 132 | + 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 133 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 134 | + 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 135 | + 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 136 | + 'maj' => 'TIMESTAMP', |
|
| 137 | + 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 138 | + 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 139 | + 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 140 | + 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 141 | + 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 142 | + 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 143 | + 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 144 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 145 | + 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 146 | + 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 147 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 148 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 149 | + 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 150 | + ], |
|
| 151 | + 'key' => [ |
|
| 152 | + 'PRIMARY KEY' => 'id_article', |
|
| 153 | + 'KEY id_rubrique' => 'id_rubrique', |
|
| 154 | + 'KEY id_secteur' => 'id_secteur', |
|
| 155 | + 'KEY id_trad' => 'id_trad', |
|
| 156 | + 'KEY lang' => 'lang', |
|
| 157 | + 'KEY statut' => 'statut, date', |
|
| 158 | + ], |
|
| 159 | + 'join' => [ |
|
| 160 | + 'id_article' => 'id_article', |
|
| 161 | + 'id_rubrique' => 'id_rubrique' |
|
| 162 | + ], |
|
| 163 | + 'parent' => [ |
|
| 164 | + ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 165 | + ], |
|
| 166 | + 'rechercher_champs' => [ |
|
| 167 | + 'surtitre' => 5, |
|
| 168 | + 'titre' => 8, |
|
| 169 | + 'soustitre' => 5, |
|
| 170 | + 'chapo' => 3, |
|
| 171 | + 'texte' => 1, |
|
| 172 | + 'ps' => 1, |
|
| 173 | + 'nom_site' => 1, |
|
| 174 | + 'url_site' => 1, |
|
| 175 | + 'descriptif' => 4 |
|
| 176 | + ], |
|
| 177 | + 'rechercher_jointures' => [ |
|
| 178 | + 'auteur' => ['nom' => 10], |
|
| 179 | + ], |
|
| 180 | + 'statut' => [ |
|
| 181 | + [ |
|
| 182 | + 'champ' => 'statut', |
|
| 183 | + 'publie' => 'publie', |
|
| 184 | + 'previsu' => 'publie,prop,prepa/auteur', |
|
| 185 | + 'post_date' => 'date', |
|
| 186 | + 'exception' => ['statut', 'tout'] |
|
| 187 | + ] |
|
| 188 | + ], |
|
| 189 | + 'statut_titres' => [ |
|
| 190 | + 'prepa' => 'info_article_redaction', |
|
| 191 | + 'prop' => 'info_article_propose', |
|
| 192 | + 'publie' => 'info_article_publie', |
|
| 193 | + 'refuse' => 'info_article_refuse', |
|
| 194 | + 'poubelle' => 'info_article_supprime' |
|
| 195 | + ], |
|
| 196 | + 'statut_textes_instituer' => [ |
|
| 197 | + 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 198 | + 'prop' => 'texte_statut_propose_evaluation', |
|
| 199 | + 'publie' => 'texte_statut_publie', |
|
| 200 | + 'refuse' => 'texte_statut_refuse', |
|
| 201 | + 'poubelle' => 'texte_statut_poubelle', |
|
| 202 | + ], |
|
| 203 | + 'texte_changer_statut' => 'texte_article_statut', |
|
| 204 | + 'aide_changer_statut' => 'artstatut', |
|
| 205 | + 'tables_jointures' => [ |
|
| 206 | + 'profondeur' => 'rubriques', |
|
| 207 | + #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 208 | + ], |
|
| 209 | + ], |
|
| 210 | + 'spip_auteurs' => [ |
|
| 211 | + 'page' => 'auteur', |
|
| 212 | + 'texte_retour' => 'icone_retour', |
|
| 213 | + 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 214 | + 'texte_modifier' => 'admin_modifier_auteur', |
|
| 215 | + 'texte_objets' => 'icone_auteurs', |
|
| 216 | + 'texte_objet' => 'public:auteur', |
|
| 217 | + 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 218 | + 'info_1_objet' => 'info_1_auteur', |
|
| 219 | + 'info_nb_objets' => 'info_nb_auteurs', |
|
| 220 | + 'texte_logo_objet' => 'logo_auteur', |
|
| 221 | + 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 222 | + 'titre' => "nom AS titre, '' AS lang", |
|
| 223 | + 'date' => 'date', |
|
| 224 | + 'principale' => 'oui', |
|
| 225 | + 'champs_editables' => ['nom', 'email', 'lang', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'], |
|
| 226 | + 'champs_versionnes' => ['nom', 'bio', 'lang', 'email', 'nom_site', 'url_site', 'login'], |
|
| 227 | + 'field' => [ |
|
| 228 | + 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 229 | + 'nom' => "text DEFAULT '' NOT NULL", |
|
| 230 | + 'bio' => "text DEFAULT '' NOT NULL", |
|
| 231 | + 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 232 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 233 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 234 | + 'login' => 'VARCHAR(255) BINARY', |
|
| 235 | + 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 236 | + 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 237 | + 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 238 | + 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 239 | + 'maj' => 'TIMESTAMP', |
|
| 240 | + 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 241 | + 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 242 | + 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 243 | + 'alea_actuel' => 'tinytext', |
|
| 244 | + 'alea_futur' => 'tinytext', |
|
| 245 | + 'prefs' => 'text', |
|
| 246 | + 'cookie_oubli' => 'tinytext', |
|
| 247 | + 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 248 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 249 | + 'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL", |
|
| 250 | + 'backup_cles' => "mediumtext DEFAULT '' NOT NULL", |
|
| 251 | + ], |
|
| 252 | + 'key' => [ |
|
| 253 | + 'PRIMARY KEY' => 'id_auteur', |
|
| 254 | + 'KEY login' => 'login', |
|
| 255 | + 'KEY statut' => 'statut', |
|
| 256 | + 'KEY en_ligne' => 'en_ligne', |
|
| 257 | + ], |
|
| 258 | + 'join' => [ |
|
| 259 | + 'id_auteur' => 'id_auteur', |
|
| 260 | + 'login' => 'login' |
|
| 261 | + ], |
|
| 262 | + 'rechercher_champs' => [ |
|
| 263 | + 'nom' => 5, |
|
| 264 | + 'bio' => 1, |
|
| 265 | + 'email' => 1, |
|
| 266 | + 'nom_site' => 1, |
|
| 267 | + 'url_site' => 1, |
|
| 268 | + 'login' => 1 |
|
| 269 | + ], |
|
| 270 | + // 2 conditions pour les auteurs : statut!=poubelle, |
|
| 271 | + // et avoir des articles publies |
|
| 272 | + 'statut' => [ |
|
| 273 | + [ |
|
| 274 | + 'champ' => 'statut', |
|
| 275 | + 'publie' => '!5poubelle', |
|
| 276 | + 'previsu' => '!5poubelle', |
|
| 277 | + 'exception' => 'statut' |
|
| 278 | + ], |
|
| 279 | + [ |
|
| 280 | + 'champ' => [ |
|
| 281 | + ['spip_auteurs_liens', 'id_auteur'], |
|
| 282 | + [ |
|
| 283 | + 'spip_articles', |
|
| 284 | + ['id_objet', 'id_article', 'objet', 'article'] |
|
| 285 | + ], |
|
| 286 | + 'statut' |
|
| 287 | + ], |
|
| 288 | + 'publie' => 'publie', |
|
| 289 | + 'previsu' => '!', |
|
| 290 | + 'post_date' => 'date', |
|
| 291 | + 'exception' => ['statut', 'lien', 'tout'] |
|
| 292 | + ], |
|
| 293 | + ], |
|
| 294 | + 'statut_images' => [ |
|
| 295 | + 'auteur-6forum-16.png', |
|
| 296 | + '0minirezo' => 'auteur-0minirezo-16.png', |
|
| 297 | + '1comite' => 'auteur-1comite-16.png', |
|
| 298 | + '6forum' => 'auteur-6forum-16.png', |
|
| 299 | + '5poubelle' => 'auteur-5poubelle-16.png', |
|
| 300 | + 'nouveau' => '' |
|
| 301 | + ], |
|
| 302 | + 'statut_titres' => [ |
|
| 303 | + 'titre_image_visiteur', |
|
| 304 | + '0minirezo' => 'titre_image_administrateur', |
|
| 305 | + '1comite' => 'titre_image_redacteur_02', |
|
| 306 | + '6forum' => 'titre_image_visiteur', |
|
| 307 | + '5poubelle' => 'titre_image_auteur_supprime', |
|
| 308 | + ], |
|
| 309 | + 'tables_jointures' => [#'auteurs_liens' // declaration generique plus bas |
|
| 310 | + ], |
|
| 311 | + ], |
|
| 312 | + 'spip_rubriques' => [ |
|
| 313 | + 'page' => 'rubrique', |
|
| 314 | + 'url_voir' => 'rubrique', |
|
| 315 | + 'url_edit' => 'rubrique_edit', |
|
| 316 | + 'texte_retour' => 'icone_retour', |
|
| 317 | + 'texte_objets' => 'public:rubriques', |
|
| 318 | + 'texte_objet' => 'public:rubrique', |
|
| 319 | + 'texte_modifier' => 'icone_modifier_rubrique', |
|
| 320 | + 'texte_creer' => 'icone_creer_rubrique', |
|
| 321 | + 'texte_ajouter' => 'titre_ajouter_une_rubrique', |
|
| 322 | + 'texte_creer_associer' => 'creer_et_associer_une_rubrique', |
|
| 323 | + 'info_aucun_objet' => 'info_aucun_rubrique', |
|
| 324 | + 'info_1_objet' => 'info_1_rubrique', |
|
| 325 | + 'info_nb_objets' => 'info_nb_rubriques', |
|
| 326 | + 'texte_logo_objet' => 'logo_rubrique', |
|
| 327 | + 'texte_langue_objet' => 'titre_langue_rubrique', |
|
| 328 | + 'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique', |
|
| 329 | + 'titre' => 'titre, lang', |
|
| 330 | + 'date' => 'date', |
|
| 331 | + 'principale' => 'oui', |
|
| 332 | + 'introduction_longueur' => '600', |
|
| 333 | + 'champs_editables' => ['titre', 'texte', 'descriptif', 'extra'], |
|
| 334 | + 'champs_versionnes' => ['titre', 'descriptif', 'texte'], |
|
| 335 | + 'field' => [ |
|
| 336 | + 'id_rubrique' => 'bigint(21) NOT NULL', |
|
| 337 | + 'id_parent' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 338 | + 'titre' => "text DEFAULT '' NOT NULL", |
|
| 339 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 340 | + 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 341 | + 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 342 | + 'maj' => 'TIMESTAMP', |
|
| 343 | + 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 344 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 345 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 346 | + 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 347 | + 'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 348 | + 'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 349 | + 'profondeur' => "smallint(5) DEFAULT '0' NOT NULL" |
|
| 350 | + ], |
|
| 351 | + 'key' => [ |
|
| 352 | + 'PRIMARY KEY' => 'id_rubrique', |
|
| 353 | + 'KEY lang' => 'lang', |
|
| 354 | + 'KEY id_parent' => 'id_parent', |
|
| 355 | + ], |
|
| 356 | + 'parent' => [ |
|
| 357 | + ['type' => 'rubrique', 'champ' => 'id_parent'] |
|
| 358 | + ], |
|
| 359 | + 'rechercher_champs' => [ |
|
| 360 | + 'titre' => 8, |
|
| 361 | + 'descriptif' => 5, |
|
| 362 | + 'texte' => 1 |
|
| 363 | + ], |
|
| 364 | + 'statut' => [ |
|
| 365 | + [ |
|
| 366 | + 'champ' => 'statut', |
|
| 367 | + 'publie' => 'publie', |
|
| 368 | + 'previsu' => '!', |
|
| 369 | + 'exception' => ['statut', 'tout'] |
|
| 370 | + ], |
|
| 371 | + ], |
|
| 372 | + 'tables_jointures' => [#'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 373 | + ], |
|
| 374 | + ], |
|
| 375 | + // toutes les tables ont le droit a une jointure sur les auteurs |
|
| 376 | + ['tables_jointures' => ['id_auteur' => 'auteurs_liens']] |
|
| 377 | + ]; |
|
| 378 | + |
|
| 379 | + // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install |
|
| 380 | + // initialiser la signature |
|
| 381 | + $md5 = md5(serialize($infos_tables)); |
|
| 382 | + |
|
| 383 | + $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']); |
|
| 384 | + $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']); |
|
| 385 | + $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables); |
|
| 386 | + |
|
| 387 | + // completer les informations manquantes ou implicites |
|
| 388 | + $all = []; |
|
| 389 | + foreach (array_keys($infos_tables) as $t) { |
|
| 390 | + // les cles numeriques servent a declarer |
|
| 391 | + // les proprietes applicables a tous les objets |
|
| 392 | + // on les mets de cote |
|
| 393 | + if (is_numeric($t)) { |
|
| 394 | + $all = array_merge_recursive($all, $infos_tables[$t]); |
|
| 395 | + unset($infos_tables[$t]); |
|
| 396 | + } else { |
|
| 397 | + $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]); |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + // repercuter les proprietes generales communes a tous les objets |
|
| 402 | + foreach (array_keys($infos_tables) as $t) { |
|
| 403 | + foreach (array_keys($all) as $i) { |
|
| 404 | + if (in_array($i, ['tables_jointures', 'champs_versionnes'])) { |
|
| 405 | + $add = $all[$i]; |
|
| 406 | + // eviter les doublons de declaration de table jointure (ex des mots sur auteurs) |
|
| 407 | + // pour les declarations generiques avec cles numeriques |
|
| 408 | + if ($i == 'tables_jointures' && isset($infos_tables[$t][$i]) && (is_countable($infos_tables[$t][$i]) ? count($infos_tables[$t][$i]) : 0)) { |
|
| 409 | + $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 410 | + foreach ($doublons as $d) { |
|
| 411 | + if ( |
|
| 412 | + is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 413 | + && is_numeric($k = array_search($d, $add)) |
|
| 414 | + ) { |
|
| 415 | + unset($add[$k]); |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + $infos_tables[$t][$i] = array_merge($infos_tables[$t][$i] ?? [], $add); |
|
| 420 | + } else { |
|
| 421 | + $infos_tables[$t][$i] = array_merge_recursive( |
|
| 422 | + $infos_tables[$t][$i] ?? [], |
|
| 423 | + $all[$i] |
|
| 424 | + ); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // completer les tables principales et auxiliaires |
|
| 430 | + // avec celles declarees uniquement dans declarer_table_objets_sql |
|
| 431 | + // pour assurer la compat en transition |
|
| 432 | + foreach ($infos_tables as $table => $infos) { |
|
| 433 | + $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 434 | + // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
|
| 435 | + // qui a ete appelle avant |
|
| 436 | + $mem = ($GLOBALS[$principale_ou_auxiliaire][$table] ?? []); |
|
| 437 | + // l'ajouter au tableau |
|
| 438 | + $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 439 | + if (isset($infos['field']) && isset($infos['key'])) { |
|
| 440 | + foreach (['field', 'key', 'join'] as $k) { |
|
| 441 | + if (isset($infos_tables[$table][$k])) { |
|
| 442 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } else { |
|
| 446 | + // ici on ne renvoie que les declarations, donc RIEN |
|
| 447 | + // pour avoir la vrai description en base, il faut passer par trouver_table |
|
| 448 | + $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 449 | + } |
|
| 450 | + if (is_countable($mem) ? count($mem) : 0) { |
|
| 451 | + foreach (array_keys($mem) as $k) { |
|
| 452 | + if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) { |
|
| 453 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge( |
|
| 454 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k], |
|
| 455 | + $mem[$k] |
|
| 456 | + ); |
|
| 457 | + } else { |
|
| 458 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + // recuperer les interfaces (table_titre, table_date) |
|
| 465 | + // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
|
| 466 | + // dans le pipeline de declarer_tables_interfaces |
|
| 467 | + include_spip('public/interfaces'); |
|
| 468 | + foreach (array_keys($infos_tables) as $t) { |
|
| 469 | + $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + $deja_la = false; |
|
| 473 | + // signature |
|
| 474 | + $md5 = md5(serialize($infos_tables)); |
|
| 475 | + } |
|
| 476 | + if ($table_sql === '::md5') { |
|
| 477 | + return $md5; |
|
| 478 | + } |
|
| 479 | + if ($table_sql && !isset($infos_tables[$table_sql])) { |
|
| 480 | + #$desc = renseigner_table_objet_sql($table_sql,$desc); |
|
| 481 | + $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 482 | + |
|
| 483 | + return $desc; |
|
| 484 | + } |
|
| 485 | + if ($table_sql) { |
|
| 486 | + return $infos_tables[$table_sql] ?? []; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + return $infos_tables; |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | |
@@ -501,27 +501,27 @@ discard block |
||
| 501 | 501 | **/ |
| 502 | 502 | function base_serial(&$tables_principales) { |
| 503 | 503 | |
| 504 | - $spip_jobs = [ |
|
| 505 | - 'id_job' => 'bigint(21) NOT NULL', |
|
| 506 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 507 | - 'fonction' => 'varchar(255) NOT NULL', //nom de la fonction |
|
| 508 | - 'args' => "longblob DEFAULT '' NOT NULL", // arguments |
|
| 509 | - 'md5args' => "char(32) NOT NULL default ''", // signature des arguments |
|
| 510 | - 'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction |
|
| 511 | - 'priorite' => 'smallint(6) NOT NULL default 0', |
|
| 512 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot |
|
| 513 | - 'status' => 'tinyint NOT NULL default 1', |
|
| 514 | - ]; |
|
| 515 | - |
|
| 516 | - $spip_jobs_key = [ |
|
| 517 | - 'PRIMARY KEY' => 'id_job', |
|
| 518 | - 'KEY date' => 'date', |
|
| 519 | - 'KEY status' => 'status', |
|
| 520 | - ]; |
|
| 521 | - |
|
| 522 | - /// Attention: mes_fonctions peut avoir deja defini cette variable |
|
| 523 | - /// il faut donc rajouter, mais pas reinitialiser |
|
| 524 | - $tables_principales['spip_jobs'] = ['field' => &$spip_jobs, 'key' => &$spip_jobs_key]; |
|
| 504 | + $spip_jobs = [ |
|
| 505 | + 'id_job' => 'bigint(21) NOT NULL', |
|
| 506 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 507 | + 'fonction' => 'varchar(255) NOT NULL', //nom de la fonction |
|
| 508 | + 'args' => "longblob DEFAULT '' NOT NULL", // arguments |
|
| 509 | + 'md5args' => "char(32) NOT NULL default ''", // signature des arguments |
|
| 510 | + 'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction |
|
| 511 | + 'priorite' => 'smallint(6) NOT NULL default 0', |
|
| 512 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot |
|
| 513 | + 'status' => 'tinyint NOT NULL default 1', |
|
| 514 | + ]; |
|
| 515 | + |
|
| 516 | + $spip_jobs_key = [ |
|
| 517 | + 'PRIMARY KEY' => 'id_job', |
|
| 518 | + 'KEY date' => 'date', |
|
| 519 | + 'KEY status' => 'status', |
|
| 520 | + ]; |
|
| 521 | + |
|
| 522 | + /// Attention: mes_fonctions peut avoir deja defini cette variable |
|
| 523 | + /// il faut donc rajouter, mais pas reinitialiser |
|
| 524 | + $tables_principales['spip_jobs'] = ['field' => &$spip_jobs, 'key' => &$spip_jobs_key]; |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | |
@@ -533,71 +533,71 @@ discard block |
||
| 533 | 533 | * @return void |
| 534 | 534 | **/ |
| 535 | 535 | function base_auxiliaires(&$tables_auxiliaires) { |
| 536 | - $spip_resultats = [ |
|
| 537 | - 'recherche' => "char(16) DEFAULT '' NOT NULL", |
|
| 538 | - 'id' => 'INT UNSIGNED NOT NULL', |
|
| 539 | - 'points' => "INT UNSIGNED DEFAULT '0' NOT NULL", |
|
| 540 | - 'table_objet' => "varchar(30) DEFAULT '' NOT NULL", |
|
| 541 | - 'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal) |
|
| 542 | - 'maj' => 'TIMESTAMP' |
|
| 543 | - ]; |
|
| 544 | - |
|
| 545 | - $spip_resultats_key = [// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ... |
|
| 546 | - ]; |
|
| 547 | - |
|
| 548 | - $spip_auteurs_liens = [ |
|
| 549 | - 'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 550 | - 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 551 | - 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 552 | - 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" |
|
| 553 | - ]; |
|
| 554 | - |
|
| 555 | - $spip_auteurs_liens_key = [ |
|
| 556 | - 'PRIMARY KEY' => 'id_auteur,id_objet,objet', |
|
| 557 | - 'KEY id_auteur' => 'id_auteur', |
|
| 558 | - 'KEY id_objet' => 'id_objet', |
|
| 559 | - 'KEY objet' => 'objet', |
|
| 560 | - ]; |
|
| 561 | - |
|
| 562 | - $spip_meta = [ |
|
| 563 | - 'nom' => 'VARCHAR (255) NOT NULL', |
|
| 564 | - 'valeur' => "text DEFAULT ''", |
|
| 565 | - 'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL", |
|
| 566 | - 'maj' => 'TIMESTAMP' |
|
| 567 | - ]; |
|
| 568 | - |
|
| 569 | - $spip_meta_key = [ |
|
| 570 | - 'PRIMARY KEY' => 'nom' |
|
| 571 | - ]; |
|
| 572 | - |
|
| 573 | - $spip_jobs_liens = [ |
|
| 574 | - 'id_job' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 575 | - 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 576 | - 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 577 | - ]; |
|
| 578 | - |
|
| 579 | - $spip_jobs_liens_key = [ |
|
| 580 | - 'PRIMARY KEY' => 'id_job,id_objet,objet', |
|
| 581 | - 'KEY id_job' => 'id_job' |
|
| 582 | - ]; |
|
| 583 | - |
|
| 584 | - $tables_auxiliaires['spip_auteurs_liens'] = [ |
|
| 585 | - 'field' => &$spip_auteurs_liens, |
|
| 586 | - 'key' => &$spip_auteurs_liens_key |
|
| 587 | - ]; |
|
| 588 | - |
|
| 589 | - $tables_auxiliaires['spip_meta'] = [ |
|
| 590 | - 'field' => &$spip_meta, |
|
| 591 | - 'key' => &$spip_meta_key |
|
| 592 | - ]; |
|
| 593 | - $tables_auxiliaires['spip_resultats'] = [ |
|
| 594 | - 'field' => &$spip_resultats, |
|
| 595 | - 'key' => &$spip_resultats_key |
|
| 596 | - ]; |
|
| 597 | - $tables_auxiliaires['spip_jobs_liens'] = [ |
|
| 598 | - 'field' => &$spip_jobs_liens, |
|
| 599 | - 'key' => &$spip_jobs_liens_key |
|
| 600 | - ]; |
|
| 536 | + $spip_resultats = [ |
|
| 537 | + 'recherche' => "char(16) DEFAULT '' NOT NULL", |
|
| 538 | + 'id' => 'INT UNSIGNED NOT NULL', |
|
| 539 | + 'points' => "INT UNSIGNED DEFAULT '0' NOT NULL", |
|
| 540 | + 'table_objet' => "varchar(30) DEFAULT '' NOT NULL", |
|
| 541 | + 'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal) |
|
| 542 | + 'maj' => 'TIMESTAMP' |
|
| 543 | + ]; |
|
| 544 | + |
|
| 545 | + $spip_resultats_key = [// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ... |
|
| 546 | + ]; |
|
| 547 | + |
|
| 548 | + $spip_auteurs_liens = [ |
|
| 549 | + 'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 550 | + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 551 | + 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 552 | + 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" |
|
| 553 | + ]; |
|
| 554 | + |
|
| 555 | + $spip_auteurs_liens_key = [ |
|
| 556 | + 'PRIMARY KEY' => 'id_auteur,id_objet,objet', |
|
| 557 | + 'KEY id_auteur' => 'id_auteur', |
|
| 558 | + 'KEY id_objet' => 'id_objet', |
|
| 559 | + 'KEY objet' => 'objet', |
|
| 560 | + ]; |
|
| 561 | + |
|
| 562 | + $spip_meta = [ |
|
| 563 | + 'nom' => 'VARCHAR (255) NOT NULL', |
|
| 564 | + 'valeur' => "text DEFAULT ''", |
|
| 565 | + 'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL", |
|
| 566 | + 'maj' => 'TIMESTAMP' |
|
| 567 | + ]; |
|
| 568 | + |
|
| 569 | + $spip_meta_key = [ |
|
| 570 | + 'PRIMARY KEY' => 'nom' |
|
| 571 | + ]; |
|
| 572 | + |
|
| 573 | + $spip_jobs_liens = [ |
|
| 574 | + 'id_job' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 575 | + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 576 | + 'objet' => "VARCHAR (25) DEFAULT '' NOT NULL", |
|
| 577 | + ]; |
|
| 578 | + |
|
| 579 | + $spip_jobs_liens_key = [ |
|
| 580 | + 'PRIMARY KEY' => 'id_job,id_objet,objet', |
|
| 581 | + 'KEY id_job' => 'id_job' |
|
| 582 | + ]; |
|
| 583 | + |
|
| 584 | + $tables_auxiliaires['spip_auteurs_liens'] = [ |
|
| 585 | + 'field' => &$spip_auteurs_liens, |
|
| 586 | + 'key' => &$spip_auteurs_liens_key |
|
| 587 | + ]; |
|
| 588 | + |
|
| 589 | + $tables_auxiliaires['spip_meta'] = [ |
|
| 590 | + 'field' => &$spip_meta, |
|
| 591 | + 'key' => &$spip_meta_key |
|
| 592 | + ]; |
|
| 593 | + $tables_auxiliaires['spip_resultats'] = [ |
|
| 594 | + 'field' => &$spip_resultats, |
|
| 595 | + 'key' => &$spip_resultats_key |
|
| 596 | + ]; |
|
| 597 | + $tables_auxiliaires['spip_jobs_liens'] = [ |
|
| 598 | + 'field' => &$spip_jobs_liens, |
|
| 599 | + 'key' => &$spip_jobs_liens_key |
|
| 600 | + ]; |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | |
@@ -654,129 +654,129 @@ discard block |
||
| 654 | 654 | * @return array |
| 655 | 655 | */ |
| 656 | 656 | function renseigner_table_objet_sql($table_sql, &$infos) { |
| 657 | - if (!isset($infos['type'])) { |
|
| 658 | - // si on arrive de base/trouver_table, on a la cle primaire : |
|
| 659 | - // s'en servir pour extrapoler le type |
|
| 660 | - if (isset($infos['key']['PRIMARY KEY'])) { |
|
| 661 | - $primary = $infos['key']['PRIMARY KEY']; |
|
| 662 | - $primary = explode(',', (string) $primary); |
|
| 663 | - $primary = reset($primary); |
|
| 664 | - $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary); |
|
| 665 | - } else { |
|
| 666 | - $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql); |
|
| 667 | - } |
|
| 668 | - } |
|
| 669 | - if (!isset($infos['type_surnoms'])) { |
|
| 670 | - $infos['type_surnoms'] = []; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - if (!isset($infos['table_objet'])) { |
|
| 674 | - $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql); |
|
| 675 | - } |
|
| 676 | - if (!isset($infos['table_objet_surnoms'])) { |
|
| 677 | - $infos['table_objet_surnoms'] = []; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - if (!isset($infos['principale'])) { |
|
| 681 | - $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false); |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - // normaliser pour pouvoir tester en php $infos['principale']? |
|
| 685 | - // et dans une boucle {principale=oui} |
|
| 686 | - $infos['principale'] = (($infos['principale'] && $infos['principale'] != 'non') ? 'oui' : false); |
|
| 687 | - |
|
| 688 | - // declarer et normaliser pour pouvoir tester en php $infos['editable']? |
|
| 689 | - // et dans une boucle {editable=oui} |
|
| 690 | - if (!isset($infos['editable'])) { |
|
| 691 | - $infos['editable'] = 'oui'; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - $infos['editable'] = (($infos['editable'] && $infos['editable'] != 'non') ? 'oui' : false); |
|
| 695 | - |
|
| 696 | - // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres |
|
| 697 | - // seules les exceptions sont donc a declarer |
|
| 698 | - if (!isset($infos['page'])) { |
|
| 699 | - $infos['page'] = ($infos['principale'] ? $infos['type'] : ''); |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - if (!isset($infos['url_voir'])) { |
|
| 703 | - $infos['url_voir'] = $infos['type']; |
|
| 704 | - } |
|
| 705 | - if (!isset($infos['url_edit'])) { |
|
| 706 | - $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : ''); |
|
| 707 | - } |
|
| 708 | - if (!isset($infos['icone_objet'])) { |
|
| 709 | - $infos['icone_objet'] = $infos['type']; |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - // chaines de langue |
|
| 713 | - // par defaut : objet:icone_xxx_objet |
|
| 714 | - if (!isset($infos['texte_retour'])) { |
|
| 715 | - $infos['texte_retour'] = 'icone_retour'; |
|
| 716 | - } |
|
| 717 | - if (!isset($infos['texte_modifier'])) { |
|
| 718 | - $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type']; |
|
| 719 | - } |
|
| 720 | - if (!isset($infos['texte_creer'])) { |
|
| 721 | - $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type']; |
|
| 722 | - } |
|
| 723 | - if (!isset($infos['texte_creer_associer'])) { |
|
| 724 | - $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type']; |
|
| 725 | - } |
|
| 726 | - if (!isset($infos['texte_ajouter'])) { |
|
| 727 | - // Ajouter un X |
|
| 728 | - $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type']; |
|
| 729 | - } |
|
| 730 | - if (!isset($infos['texte_objets'])) { |
|
| 731 | - $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet']; |
|
| 732 | - } |
|
| 733 | - if (!isset($infos['texte_objet'])) { |
|
| 734 | - $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type']; |
|
| 735 | - } |
|
| 736 | - if (!isset($infos['texte_logo_objet'])) { |
|
| 737 | - // objet:titre_logo_objet "Logo de ce X" |
|
| 738 | - $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type']; |
|
| 739 | - } |
|
| 740 | - if (!isset($infos['texte_langue_objet'])) { |
|
| 741 | - // objet:texte_langue_objet "Langue de ce X" |
|
| 742 | - $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type']; |
|
| 743 | - } |
|
| 744 | - if (!isset($infos['texte_definir_comme_traduction_objet'])) { |
|
| 745 | - // "Ce X est une traduction du X numéro :" |
|
| 746 | - $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type']; |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - // objet:info_aucun_objet |
|
| 750 | - if (!isset($infos['info_aucun_objet'])) { |
|
| 751 | - $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type']; |
|
| 752 | - } |
|
| 753 | - // objet:info_1_objet |
|
| 754 | - if (!isset($infos['info_1_objet'])) { |
|
| 755 | - $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type']; |
|
| 756 | - } |
|
| 757 | - // objet:info_nb_objets |
|
| 758 | - if (!isset($infos['info_nb_objets'])) { |
|
| 759 | - $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet']; |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - if (!isset($infos['champs_editables'])) { |
|
| 763 | - $infos['champs_editables'] = []; |
|
| 764 | - } |
|
| 765 | - if (!isset($infos['champs_versionnes'])) { |
|
| 766 | - $infos['champs_versionnes'] = []; |
|
| 767 | - } |
|
| 768 | - if (!isset($infos['rechercher_champs'])) { |
|
| 769 | - $infos['rechercher_champs'] = []; |
|
| 770 | - } |
|
| 771 | - if (!isset($infos['rechercher_jointures'])) { |
|
| 772 | - $infos['rechercher_jointures'] = []; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - if (!isset($infos['modeles'])) { |
|
| 776 | - $infos['modeles'] = [$infos['type']]; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - return $infos; |
|
| 657 | + if (!isset($infos['type'])) { |
|
| 658 | + // si on arrive de base/trouver_table, on a la cle primaire : |
|
| 659 | + // s'en servir pour extrapoler le type |
|
| 660 | + if (isset($infos['key']['PRIMARY KEY'])) { |
|
| 661 | + $primary = $infos['key']['PRIMARY KEY']; |
|
| 662 | + $primary = explode(',', (string) $primary); |
|
| 663 | + $primary = reset($primary); |
|
| 664 | + $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary); |
|
| 665 | + } else { |
|
| 666 | + $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql); |
|
| 667 | + } |
|
| 668 | + } |
|
| 669 | + if (!isset($infos['type_surnoms'])) { |
|
| 670 | + $infos['type_surnoms'] = []; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + if (!isset($infos['table_objet'])) { |
|
| 674 | + $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql); |
|
| 675 | + } |
|
| 676 | + if (!isset($infos['table_objet_surnoms'])) { |
|
| 677 | + $infos['table_objet_surnoms'] = []; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + if (!isset($infos['principale'])) { |
|
| 681 | + $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false); |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + // normaliser pour pouvoir tester en php $infos['principale']? |
|
| 685 | + // et dans une boucle {principale=oui} |
|
| 686 | + $infos['principale'] = (($infos['principale'] && $infos['principale'] != 'non') ? 'oui' : false); |
|
| 687 | + |
|
| 688 | + // declarer et normaliser pour pouvoir tester en php $infos['editable']? |
|
| 689 | + // et dans une boucle {editable=oui} |
|
| 690 | + if (!isset($infos['editable'])) { |
|
| 691 | + $infos['editable'] = 'oui'; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + $infos['editable'] = (($infos['editable'] && $infos['editable'] != 'non') ? 'oui' : false); |
|
| 695 | + |
|
| 696 | + // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres |
|
| 697 | + // seules les exceptions sont donc a declarer |
|
| 698 | + if (!isset($infos['page'])) { |
|
| 699 | + $infos['page'] = ($infos['principale'] ? $infos['type'] : ''); |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + if (!isset($infos['url_voir'])) { |
|
| 703 | + $infos['url_voir'] = $infos['type']; |
|
| 704 | + } |
|
| 705 | + if (!isset($infos['url_edit'])) { |
|
| 706 | + $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : ''); |
|
| 707 | + } |
|
| 708 | + if (!isset($infos['icone_objet'])) { |
|
| 709 | + $infos['icone_objet'] = $infos['type']; |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + // chaines de langue |
|
| 713 | + // par defaut : objet:icone_xxx_objet |
|
| 714 | + if (!isset($infos['texte_retour'])) { |
|
| 715 | + $infos['texte_retour'] = 'icone_retour'; |
|
| 716 | + } |
|
| 717 | + if (!isset($infos['texte_modifier'])) { |
|
| 718 | + $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type']; |
|
| 719 | + } |
|
| 720 | + if (!isset($infos['texte_creer'])) { |
|
| 721 | + $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type']; |
|
| 722 | + } |
|
| 723 | + if (!isset($infos['texte_creer_associer'])) { |
|
| 724 | + $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type']; |
|
| 725 | + } |
|
| 726 | + if (!isset($infos['texte_ajouter'])) { |
|
| 727 | + // Ajouter un X |
|
| 728 | + $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type']; |
|
| 729 | + } |
|
| 730 | + if (!isset($infos['texte_objets'])) { |
|
| 731 | + $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet']; |
|
| 732 | + } |
|
| 733 | + if (!isset($infos['texte_objet'])) { |
|
| 734 | + $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type']; |
|
| 735 | + } |
|
| 736 | + if (!isset($infos['texte_logo_objet'])) { |
|
| 737 | + // objet:titre_logo_objet "Logo de ce X" |
|
| 738 | + $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type']; |
|
| 739 | + } |
|
| 740 | + if (!isset($infos['texte_langue_objet'])) { |
|
| 741 | + // objet:texte_langue_objet "Langue de ce X" |
|
| 742 | + $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type']; |
|
| 743 | + } |
|
| 744 | + if (!isset($infos['texte_definir_comme_traduction_objet'])) { |
|
| 745 | + // "Ce X est une traduction du X numéro :" |
|
| 746 | + $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type']; |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + // objet:info_aucun_objet |
|
| 750 | + if (!isset($infos['info_aucun_objet'])) { |
|
| 751 | + $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type']; |
|
| 752 | + } |
|
| 753 | + // objet:info_1_objet |
|
| 754 | + if (!isset($infos['info_1_objet'])) { |
|
| 755 | + $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type']; |
|
| 756 | + } |
|
| 757 | + // objet:info_nb_objets |
|
| 758 | + if (!isset($infos['info_nb_objets'])) { |
|
| 759 | + $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet']; |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + if (!isset($infos['champs_editables'])) { |
|
| 763 | + $infos['champs_editables'] = []; |
|
| 764 | + } |
|
| 765 | + if (!isset($infos['champs_versionnes'])) { |
|
| 766 | + $infos['champs_versionnes'] = []; |
|
| 767 | + } |
|
| 768 | + if (!isset($infos['rechercher_champs'])) { |
|
| 769 | + $infos['rechercher_champs'] = []; |
|
| 770 | + } |
|
| 771 | + if (!isset($infos['rechercher_jointures'])) { |
|
| 772 | + $infos['rechercher_jointures'] = []; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + if (!isset($infos['modeles'])) { |
|
| 776 | + $infos['modeles'] = [$infos['type']]; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + return $infos; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
@@ -793,30 +793,30 @@ discard block |
||
| 793 | 793 | * @return array |
| 794 | 794 | */ |
| 795 | 795 | function renseigner_table_objet_interfaces($table_sql, &$infos) { |
| 796 | - if (!isset($infos['titre'])) { |
|
| 797 | - if (isset($infos['table_objet']) && isset($GLOBALS['table_titre'][$infos['table_objet']])) { |
|
| 798 | - $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']]; |
|
| 799 | - } else { |
|
| 800 | - $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,"); |
|
| 801 | - $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang"); |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - if (!isset($infos['date'])) { |
|
| 805 | - if (isset($infos['table_objet']) && isset($GLOBALS['table_date'][$infos['table_objet']])) { |
|
| 806 | - $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']]; |
|
| 807 | - } else { |
|
| 808 | - $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : ''); |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - $infos['statut'] ??= $GLOBALS['table_statut'][$table_sql] ?? ''; |
|
| 813 | - $infos['tables_jointures'] ??= []; |
|
| 814 | - |
|
| 815 | - if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 816 | - $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - return $infos; |
|
| 796 | + if (!isset($infos['titre'])) { |
|
| 797 | + if (isset($infos['table_objet']) && isset($GLOBALS['table_titre'][$infos['table_objet']])) { |
|
| 798 | + $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']]; |
|
| 799 | + } else { |
|
| 800 | + $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,"); |
|
| 801 | + $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang"); |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + if (!isset($infos['date'])) { |
|
| 805 | + if (isset($infos['table_objet']) && isset($GLOBALS['table_date'][$infos['table_objet']])) { |
|
| 806 | + $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']]; |
|
| 807 | + } else { |
|
| 808 | + $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : ''); |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + $infos['statut'] ??= $GLOBALS['table_statut'][$table_sql] ?? ''; |
|
| 813 | + $infos['tables_jointures'] ??= []; |
|
| 814 | + |
|
| 815 | + if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 816 | + $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + return $infos; |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -827,13 +827,13 @@ discard block |
||
| 827 | 827 | * Liste et descriptions des tables principales |
| 828 | 828 | **/ |
| 829 | 829 | function lister_tables_principales() { |
| 830 | - static $done = false; |
|
| 831 | - if (!$done || !(is_countable($GLOBALS['tables_principales']) ? count($GLOBALS['tables_principales']) : 0)) { |
|
| 832 | - lister_tables_objets_sql(); |
|
| 833 | - $done = true; |
|
| 834 | - } |
|
| 830 | + static $done = false; |
|
| 831 | + if (!$done || !(is_countable($GLOBALS['tables_principales']) ? count($GLOBALS['tables_principales']) : 0)) { |
|
| 832 | + lister_tables_objets_sql(); |
|
| 833 | + $done = true; |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | - return $GLOBALS['tables_principales']; |
|
| 836 | + return $GLOBALS['tables_principales']; |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | /** |
@@ -844,13 +844,13 @@ discard block |
||
| 844 | 844 | * Liste et descriptions des tables auxiliaires |
| 845 | 845 | **/ |
| 846 | 846 | function lister_tables_auxiliaires() { |
| 847 | - static $done = false; |
|
| 848 | - if (!$done || !(is_countable($GLOBALS['tables_auxiliaires']) ? count($GLOBALS['tables_auxiliaires']) : 0)) { |
|
| 849 | - lister_tables_objets_sql(); |
|
| 850 | - $done = true; |
|
| 851 | - } |
|
| 847 | + static $done = false; |
|
| 848 | + if (!$done || !(is_countable($GLOBALS['tables_auxiliaires']) ? count($GLOBALS['tables_auxiliaires']) : 0)) { |
|
| 849 | + lister_tables_objets_sql(); |
|
| 850 | + $done = true; |
|
| 851 | + } |
|
| 852 | 852 | |
| 853 | - return $GLOBALS['tables_auxiliaires']; |
|
| 853 | + return $GLOBALS['tables_auxiliaires']; |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | /** |
@@ -859,44 +859,44 @@ discard block |
||
| 859 | 859 | * @return array |
| 860 | 860 | */ |
| 861 | 861 | function lister_tables_objets_surnoms() { |
| 862 | - static $surnoms = null; |
|
| 863 | - static $md5 = null; |
|
| 864 | - if ( |
|
| 865 | - !$surnoms || $md5 != lister_tables_objets_sql('::md5') |
|
| 866 | - ) { |
|
| 867 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 868 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 869 | - // declarer_table_objets_sql |
|
| 870 | - $surnoms = pipeline( |
|
| 871 | - 'declarer_tables_objets_surnoms', |
|
| 872 | - [ |
|
| 873 | - # pour les modeles |
|
| 874 | - # a enlever ? |
|
| 875 | - 'doc' => 'documents', |
|
| 876 | - 'img' => 'documents', |
|
| 877 | - 'emb' => 'documents', |
|
| 878 | - ] |
|
| 879 | - ); |
|
| 880 | - $infos_tables = lister_tables_objets_sql(); |
|
| 881 | - foreach ($infos_tables as $t => $infos) { |
|
| 882 | - // cas de base type=>table |
|
| 883 | - // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 884 | - if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 885 | - // optimisations pour table_objet |
|
| 886 | - //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 887 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['table_objet']; |
|
| 888 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['table_objet']; |
|
| 889 | - if (is_array($infos['table_objet_surnoms']) && count($infos['table_objet_surnoms'])) { |
|
| 890 | - foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 891 | - $surnoms[$surnom] = $infos['table_objet']; |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - return $surnoms; |
|
| 862 | + static $surnoms = null; |
|
| 863 | + static $md5 = null; |
|
| 864 | + if ( |
|
| 865 | + !$surnoms || $md5 != lister_tables_objets_sql('::md5') |
|
| 866 | + ) { |
|
| 867 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 868 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 869 | + // declarer_table_objets_sql |
|
| 870 | + $surnoms = pipeline( |
|
| 871 | + 'declarer_tables_objets_surnoms', |
|
| 872 | + [ |
|
| 873 | + # pour les modeles |
|
| 874 | + # a enlever ? |
|
| 875 | + 'doc' => 'documents', |
|
| 876 | + 'img' => 'documents', |
|
| 877 | + 'emb' => 'documents', |
|
| 878 | + ] |
|
| 879 | + ); |
|
| 880 | + $infos_tables = lister_tables_objets_sql(); |
|
| 881 | + foreach ($infos_tables as $t => $infos) { |
|
| 882 | + // cas de base type=>table |
|
| 883 | + // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 884 | + if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 885 | + // optimisations pour table_objet |
|
| 886 | + //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 887 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['table_objet']; |
|
| 888 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['table_objet']; |
|
| 889 | + if (is_array($infos['table_objet_surnoms']) && count($infos['table_objet_surnoms'])) { |
|
| 890 | + foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 891 | + $surnoms[$surnom] = $infos['table_objet']; |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + return $surnoms; |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | /** |
@@ -905,34 +905,34 @@ discard block |
||
| 905 | 905 | * @return array |
| 906 | 906 | */ |
| 907 | 907 | function lister_types_surnoms() { |
| 908 | - static $surnoms = null; |
|
| 909 | - static $md5 = null; |
|
| 910 | - if ( |
|
| 911 | - !$surnoms || $md5 != lister_tables_objets_sql('::md5') |
|
| 912 | - ) { |
|
| 913 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 914 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 915 | - // declarer_table_objets_sql |
|
| 916 | - $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']); |
|
| 917 | - $infos_tables = lister_tables_objets_sql(); |
|
| 918 | - foreach ($infos_tables as $t => $infos) { |
|
| 919 | - if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 920 | - // optimisations pour objet_type |
|
| 921 | - //$surnoms[$infos['type']] = $infos['type']; |
|
| 922 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['type']; |
|
| 923 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['type']; |
|
| 924 | - // surnoms declares |
|
| 925 | - if (is_array($infos['type_surnoms']) && count($infos['type_surnoms'])) { |
|
| 926 | - foreach ($infos['type_surnoms'] as $surnom) { |
|
| 927 | - $surnoms[$surnom] = $infos['type']; |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - return $surnoms; |
|
| 908 | + static $surnoms = null; |
|
| 909 | + static $md5 = null; |
|
| 910 | + if ( |
|
| 911 | + !$surnoms || $md5 != lister_tables_objets_sql('::md5') |
|
| 912 | + ) { |
|
| 913 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 914 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 915 | + // declarer_table_objets_sql |
|
| 916 | + $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']); |
|
| 917 | + $infos_tables = lister_tables_objets_sql(); |
|
| 918 | + foreach ($infos_tables as $t => $infos) { |
|
| 919 | + if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 920 | + // optimisations pour objet_type |
|
| 921 | + //$surnoms[$infos['type']] = $infos['type']; |
|
| 922 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['type']; |
|
| 923 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['type']; |
|
| 924 | + // surnoms declares |
|
| 925 | + if (is_array($infos['type_surnoms']) && count($infos['type_surnoms'])) { |
|
| 926 | + foreach ($infos['type_surnoms'] as $surnom) { |
|
| 927 | + $surnoms[$surnom] = $infos['type']; |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + return $surnoms; |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | /** |
@@ -946,22 +946,22 @@ discard block |
||
| 946 | 946 | * Couples (nom de la table SQL => même nom, sans 'spip_' devant) |
| 947 | 947 | **/ |
| 948 | 948 | function lister_tables_spip($serveur = '') { |
| 949 | - static $tables = []; |
|
| 950 | - if (!isset($tables[$serveur])) { |
|
| 951 | - $tables[$serveur] = []; |
|
| 952 | - if (!function_exists('sql_alltable')) { |
|
| 953 | - include_spip('base/abstract_sql'); |
|
| 954 | - } |
|
| 955 | - $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 956 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 957 | - $spip = $connexion['prefixe'] . '_'; |
|
| 958 | - foreach ($ts as $t) { |
|
| 959 | - $t = substr((string) $t, strlen($spip)); |
|
| 960 | - $tables[$serveur]["spip_$t"] = $t; |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - return $tables[$serveur]; |
|
| 949 | + static $tables = []; |
|
| 950 | + if (!isset($tables[$serveur])) { |
|
| 951 | + $tables[$serveur] = []; |
|
| 952 | + if (!function_exists('sql_alltable')) { |
|
| 953 | + include_spip('base/abstract_sql'); |
|
| 954 | + } |
|
| 955 | + $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 956 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 957 | + $spip = $connexion['prefixe'] . '_'; |
|
| 958 | + foreach ($ts as $t) { |
|
| 959 | + $t = substr((string) $t, strlen($spip)); |
|
| 960 | + $tables[$serveur]["spip_$t"] = $t; |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + return $tables[$serveur]; |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | |
@@ -976,18 +976,18 @@ discard block |
||
| 976 | 976 | * Couples (nom de la table SQL => même nom) |
| 977 | 977 | **/ |
| 978 | 978 | function lister_toutes_tables($serveur) { |
| 979 | - static $tables = []; |
|
| 980 | - if (!isset($tables[$serveur])) { |
|
| 981 | - $tables[$serveur] = []; |
|
| 982 | - if (!function_exists('sql_alltable')) { |
|
| 983 | - include_spip('base/abstract_sql'); |
|
| 984 | - } |
|
| 985 | - $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 986 | - foreach ($ts as $t) { |
|
| 987 | - $tables[$serveur][$t] = $t; |
|
| 988 | - } |
|
| 989 | - } |
|
| 990 | - return $tables[$serveur]; |
|
| 979 | + static $tables = []; |
|
| 980 | + if (!isset($tables[$serveur])) { |
|
| 981 | + $tables[$serveur] = []; |
|
| 982 | + if (!function_exists('sql_alltable')) { |
|
| 983 | + include_spip('base/abstract_sql'); |
|
| 984 | + } |
|
| 985 | + $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 986 | + foreach ($ts as $t) { |
|
| 987 | + $tables[$serveur][$t] = $t; |
|
| 988 | + } |
|
| 989 | + } |
|
| 990 | + return $tables[$serveur]; |
|
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | /** |
@@ -1008,37 +1008,37 @@ discard block |
||
| 1008 | 1008 | **/ |
| 1009 | 1009 | function table_objet(string $type, string $serveur = ''): string { |
| 1010 | 1010 | |
| 1011 | - if ($type) { |
|
| 1012 | - $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1013 | - } |
|
| 1014 | - if (!strlen($type)) { |
|
| 1015 | - return ''; |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - $surnoms = lister_tables_objets_surnoms(); |
|
| 1019 | - if (isset($surnoms[$type])) { |
|
| 1020 | - return $surnoms[$type]; |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - if ($serveur !== false) { |
|
| 1024 | - $t = lister_tables_spip($serveur); |
|
| 1025 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1026 | - $typetrim = rtrim($type, 's') . 's'; |
|
| 1027 | - if ( |
|
| 1028 | - (isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1029 | - ) { |
|
| 1030 | - return $desc['id_table']; |
|
| 1031 | - } elseif ( |
|
| 1032 | - (isset($t[$type]) || in_array($type, $t)) && ($desc = $trouver_table($type, $serveur)) |
|
| 1033 | - ) { |
|
| 1034 | - return $desc['id_table']; |
|
| 1035 | - } |
|
| 1036 | - |
|
| 1037 | - spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1038 | - #spip_log(debug_backtrace(),'db'); |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1011 | + if ($type) { |
|
| 1012 | + $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1013 | + } |
|
| 1014 | + if (!strlen($type)) { |
|
| 1015 | + return ''; |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + $surnoms = lister_tables_objets_surnoms(); |
|
| 1019 | + if (isset($surnoms[$type])) { |
|
| 1020 | + return $surnoms[$type]; |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + if ($serveur !== false) { |
|
| 1024 | + $t = lister_tables_spip($serveur); |
|
| 1025 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1026 | + $typetrim = rtrim($type, 's') . 's'; |
|
| 1027 | + if ( |
|
| 1028 | + (isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1029 | + ) { |
|
| 1030 | + return $desc['id_table']; |
|
| 1031 | + } elseif ( |
|
| 1032 | + (isset($t[$type]) || in_array($type, $t)) && ($desc = $trouver_table($type, $serveur)) |
|
| 1033 | + ) { |
|
| 1034 | + return $desc['id_table']; |
|
| 1035 | + } |
|
| 1036 | + |
|
| 1037 | + spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1038 | + #spip_log(debug_backtrace(),'db'); |
|
| 1039 | + } |
|
| 1040 | + |
|
| 1041 | + return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | /** |
@@ -1059,33 +1059,33 @@ discard block |
||
| 1059 | 1059 | **/ |
| 1060 | 1060 | function table_objet_sql(string $type, string $serveur = ''): string { |
| 1061 | 1061 | |
| 1062 | - $nom = table_objet($type, $serveur); |
|
| 1063 | - if (!strlen($nom)) { |
|
| 1064 | - return ''; |
|
| 1065 | - } |
|
| 1066 | - if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1067 | - // eviter de multiples inclusions |
|
| 1068 | - include_spip('public/interfaces'); |
|
| 1069 | - } |
|
| 1070 | - if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1071 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1072 | - $nom = "spip_$nom"; |
|
| 1073 | - } else { |
|
| 1074 | - $infos_tables = lister_tables_objets_sql(); |
|
| 1075 | - if (isset($infos_tables["spip_$nom"])) { |
|
| 1076 | - $nom = "spip_$nom"; |
|
| 1077 | - } elseif ($serveur !== false) { |
|
| 1078 | - $t = lister_tables_spip($serveur); |
|
| 1079 | - if (isset($t[$nom]) || in_array($nom, $t)) { |
|
| 1080 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1081 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1082 | - return $desc['table_sql']; |
|
| 1083 | - } |
|
| 1084 | - } |
|
| 1085 | - } |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - return $nom; |
|
| 1062 | + $nom = table_objet($type, $serveur); |
|
| 1063 | + if (!strlen($nom)) { |
|
| 1064 | + return ''; |
|
| 1065 | + } |
|
| 1066 | + if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1067 | + // eviter de multiples inclusions |
|
| 1068 | + include_spip('public/interfaces'); |
|
| 1069 | + } |
|
| 1070 | + if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1071 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1072 | + $nom = "spip_$nom"; |
|
| 1073 | + } else { |
|
| 1074 | + $infos_tables = lister_tables_objets_sql(); |
|
| 1075 | + if (isset($infos_tables["spip_$nom"])) { |
|
| 1076 | + $nom = "spip_$nom"; |
|
| 1077 | + } elseif ($serveur !== false) { |
|
| 1078 | + $t = lister_tables_spip($serveur); |
|
| 1079 | + if (isset($t[$nom]) || in_array($nom, $t)) { |
|
| 1080 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1081 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1082 | + return $desc['table_sql']; |
|
| 1083 | + } |
|
| 1084 | + } |
|
| 1085 | + } |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + return $nom; |
|
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | 1091 | /** |
@@ -1104,34 +1104,34 @@ discard block |
||
| 1104 | 1104 | * Nom de la clé primaire |
| 1105 | 1105 | **/ |
| 1106 | 1106 | function id_table_objet(string $type, string $serveur = ''): ?string { |
| 1107 | - static $trouver_table = null; |
|
| 1108 | - $type = objet_type($type, $serveur); |
|
| 1109 | - if (!$type) { |
|
| 1110 | - return null; |
|
| 1111 | - } |
|
| 1112 | - $t = table_objet($type); |
|
| 1113 | - if (!$trouver_table) { |
|
| 1114 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - $ts = lister_tables_spip($serveur); |
|
| 1118 | - if ( |
|
| 1119 | - in_array($t, $ts) || in_array($t, lister_toutes_tables($serveur)) |
|
| 1120 | - ) { |
|
| 1121 | - $desc = $trouver_table($t, $serveur); |
|
| 1122 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 1123 | - return $desc['key']['PRIMARY KEY']; |
|
| 1124 | - } |
|
| 1125 | - if (!$desc || isset($desc['field']["id_$type"])) { |
|
| 1126 | - return "id_$type"; |
|
| 1127 | - } |
|
| 1128 | - // sinon renvoyer le premier champ de la table... |
|
| 1129 | - $keys = array_keys($desc['field']); |
|
| 1130 | - |
|
| 1131 | - return array_shift($keys); |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - return "id_$type"; |
|
| 1107 | + static $trouver_table = null; |
|
| 1108 | + $type = objet_type($type, $serveur); |
|
| 1109 | + if (!$type) { |
|
| 1110 | + return null; |
|
| 1111 | + } |
|
| 1112 | + $t = table_objet($type); |
|
| 1113 | + if (!$trouver_table) { |
|
| 1114 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + $ts = lister_tables_spip($serveur); |
|
| 1118 | + if ( |
|
| 1119 | + in_array($t, $ts) || in_array($t, lister_toutes_tables($serveur)) |
|
| 1120 | + ) { |
|
| 1121 | + $desc = $trouver_table($t, $serveur); |
|
| 1122 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 1123 | + return $desc['key']['PRIMARY KEY']; |
|
| 1124 | + } |
|
| 1125 | + if (!$desc || isset($desc['field']["id_$type"])) { |
|
| 1126 | + return "id_$type"; |
|
| 1127 | + } |
|
| 1128 | + // sinon renvoyer le premier champ de la table... |
|
| 1129 | + $keys = array_keys($desc['field']); |
|
| 1130 | + |
|
| 1131 | + return array_shift($keys); |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + return "id_$type"; |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | /** |
@@ -1150,60 +1150,60 @@ discard block |
||
| 1150 | 1150 | * Type de l'objet |
| 1151 | 1151 | **/ |
| 1152 | 1152 | function objet_type(string $table_objet, string $serveur = ''): ?string { |
| 1153 | - if (!$table_objet) { |
|
| 1154 | - return null; |
|
| 1155 | - } |
|
| 1156 | - $surnoms = lister_types_surnoms(); |
|
| 1157 | - |
|
| 1158 | - // scenario de base |
|
| 1159 | - // le type est decline a partir du nom de la table en enlevant le prefixe eventuel |
|
| 1160 | - // et la marque du pluriel |
|
| 1161 | - // on accepte id_xx en entree aussi |
|
| 1162 | - $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet); |
|
| 1163 | - if (isset($surnoms[$type])) { |
|
| 1164 | - return $surnoms[$type]; |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - // securite : eliminer les caracteres non \w |
|
| 1168 | - $type = preg_replace(',[^\w-],', '', $type); |
|
| 1169 | - |
|
| 1170 | - // si le type redonne bien la table c'est bon |
|
| 1171 | - // oui si table_objet ressemblait deja a un type |
|
| 1172 | - if ( |
|
| 1173 | - $type == $table_objet |
|
| 1174 | - || table_objet($type, $serveur) === $table_objet |
|
| 1175 | - || table_objet_sql($type, $serveur) === $table_objet |
|
| 1176 | - ) { |
|
| 1177 | - return $type; |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - // si on ne veut pas chercher en base |
|
| 1181 | - if ($serveur === false) { |
|
| 1182 | - return $type; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - // sinon on passe par la cle primaire id_xx pour trouver le type |
|
| 1186 | - // car le s a la fin est incertain |
|
| 1187 | - // notamment en cas de pluriel derogatoire |
|
| 1188 | - // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux |
|
| 1189 | - // une declaration jeu => jeux, journal => journaux |
|
| 1190 | - // dans le pipeline declarer_tables_objets_surnoms |
|
| 1191 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1192 | - $ts = lister_tables_spip($serveur); |
|
| 1193 | - $desc = false; |
|
| 1194 | - if (in_array($table_objet, $ts)) { |
|
| 1195 | - $desc = $trouver_table($table_objet); |
|
| 1196 | - } |
|
| 1197 | - if (!$desc && in_array($table_objet = table_objet($type, $serveur), $ts)) { |
|
| 1198 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 1199 | - } |
|
| 1200 | - // si le type est declare : bingo ! |
|
| 1201 | - if ($desc && isset($desc['type'])) { |
|
| 1202 | - return $desc['type']; |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - // on a fait ce qu'on a pu |
|
| 1206 | - return $type; |
|
| 1153 | + if (!$table_objet) { |
|
| 1154 | + return null; |
|
| 1155 | + } |
|
| 1156 | + $surnoms = lister_types_surnoms(); |
|
| 1157 | + |
|
| 1158 | + // scenario de base |
|
| 1159 | + // le type est decline a partir du nom de la table en enlevant le prefixe eventuel |
|
| 1160 | + // et la marque du pluriel |
|
| 1161 | + // on accepte id_xx en entree aussi |
|
| 1162 | + $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet); |
|
| 1163 | + if (isset($surnoms[$type])) { |
|
| 1164 | + return $surnoms[$type]; |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + // securite : eliminer les caracteres non \w |
|
| 1168 | + $type = preg_replace(',[^\w-],', '', $type); |
|
| 1169 | + |
|
| 1170 | + // si le type redonne bien la table c'est bon |
|
| 1171 | + // oui si table_objet ressemblait deja a un type |
|
| 1172 | + if ( |
|
| 1173 | + $type == $table_objet |
|
| 1174 | + || table_objet($type, $serveur) === $table_objet |
|
| 1175 | + || table_objet_sql($type, $serveur) === $table_objet |
|
| 1176 | + ) { |
|
| 1177 | + return $type; |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + // si on ne veut pas chercher en base |
|
| 1181 | + if ($serveur === false) { |
|
| 1182 | + return $type; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + // sinon on passe par la cle primaire id_xx pour trouver le type |
|
| 1186 | + // car le s a la fin est incertain |
|
| 1187 | + // notamment en cas de pluriel derogatoire |
|
| 1188 | + // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux |
|
| 1189 | + // une declaration jeu => jeux, journal => journaux |
|
| 1190 | + // dans le pipeline declarer_tables_objets_surnoms |
|
| 1191 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1192 | + $ts = lister_tables_spip($serveur); |
|
| 1193 | + $desc = false; |
|
| 1194 | + if (in_array($table_objet, $ts)) { |
|
| 1195 | + $desc = $trouver_table($table_objet); |
|
| 1196 | + } |
|
| 1197 | + if (!$desc && in_array($table_objet = table_objet($type, $serveur), $ts)) { |
|
| 1198 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 1199 | + } |
|
| 1200 | + // si le type est declare : bingo ! |
|
| 1201 | + if ($desc && isset($desc['type'])) { |
|
| 1202 | + return $desc['type']; |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + // on a fait ce qu'on a pu |
|
| 1206 | + return $type; |
|
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | 1209 | /** |
@@ -1219,58 +1219,58 @@ discard block |
||
| 1219 | 1219 | * @return bool |
| 1220 | 1220 | */ |
| 1221 | 1221 | function objet_test_si_publie($objet, $id_objet, $serveur = '') { |
| 1222 | - // voir si une fonction est definie pour faire le boulot |
|
| 1223 | - // elle a la priorite dans ce cas |
|
| 1224 | - if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1225 | - return $f($objet, $id_objet, $serveur); |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - // sinon on se fie a la declaration de l'objet si presente |
|
| 1229 | - $id_table = $table_objet = table_objet($objet); |
|
| 1230 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 1231 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1232 | - if ( |
|
| 1233 | - ($desc = $trouver_table($table_objet, $serveur)) |
|
| 1234 | - && isset($desc['statut']) |
|
| 1235 | - && $desc['statut'] |
|
| 1236 | - ) { |
|
| 1237 | - $boucle = new Boucle(); |
|
| 1238 | - $boucle->show = $desc; |
|
| 1239 | - $boucle->nom = 'objet_test_si_publie'; |
|
| 1240 | - $boucle->id_boucle = $id_table; |
|
| 1241 | - $boucle->id_table = $id_table; |
|
| 1242 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 1243 | - $boucle->sql_serveur = $serveur; |
|
| 1244 | - $boucle->select[] = $id_table_objet; |
|
| 1245 | - $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
|
| 1246 | - $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . (int) $id_objet; |
|
| 1247 | - |
|
| 1248 | - $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 1249 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 1250 | - $boucle->descr['gram'] = 'html'; |
|
| 1251 | - |
|
| 1252 | - include_spip('public/compiler'); |
|
| 1253 | - include_spip('public/composer'); |
|
| 1254 | - instituer_boucle($boucle, false, true); |
|
| 1255 | - $res = calculer_select( |
|
| 1256 | - $boucle->select, |
|
| 1257 | - $boucle->from, |
|
| 1258 | - $boucle->from_type, |
|
| 1259 | - $boucle->where, |
|
| 1260 | - $boucle->join, |
|
| 1261 | - $boucle->group, |
|
| 1262 | - $boucle->order, |
|
| 1263 | - $boucle->limit, |
|
| 1264 | - $boucle->having, |
|
| 1265 | - $table_objet, |
|
| 1266 | - $id_table, |
|
| 1267 | - $serveur |
|
| 1268 | - ); |
|
| 1269 | - return (bool) sql_fetch($res); |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1273 | - return true; |
|
| 1222 | + // voir si une fonction est definie pour faire le boulot |
|
| 1223 | + // elle a la priorite dans ce cas |
|
| 1224 | + if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1225 | + return $f($objet, $id_objet, $serveur); |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + // sinon on se fie a la declaration de l'objet si presente |
|
| 1229 | + $id_table = $table_objet = table_objet($objet); |
|
| 1230 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 1231 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1232 | + if ( |
|
| 1233 | + ($desc = $trouver_table($table_objet, $serveur)) |
|
| 1234 | + && isset($desc['statut']) |
|
| 1235 | + && $desc['statut'] |
|
| 1236 | + ) { |
|
| 1237 | + $boucle = new Boucle(); |
|
| 1238 | + $boucle->show = $desc; |
|
| 1239 | + $boucle->nom = 'objet_test_si_publie'; |
|
| 1240 | + $boucle->id_boucle = $id_table; |
|
| 1241 | + $boucle->id_table = $id_table; |
|
| 1242 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 1243 | + $boucle->sql_serveur = $serveur; |
|
| 1244 | + $boucle->select[] = $id_table_objet; |
|
| 1245 | + $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
|
| 1246 | + $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . (int) $id_objet; |
|
| 1247 | + |
|
| 1248 | + $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 1249 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 1250 | + $boucle->descr['gram'] = 'html'; |
|
| 1251 | + |
|
| 1252 | + include_spip('public/compiler'); |
|
| 1253 | + include_spip('public/composer'); |
|
| 1254 | + instituer_boucle($boucle, false, true); |
|
| 1255 | + $res = calculer_select( |
|
| 1256 | + $boucle->select, |
|
| 1257 | + $boucle->from, |
|
| 1258 | + $boucle->from_type, |
|
| 1259 | + $boucle->where, |
|
| 1260 | + $boucle->join, |
|
| 1261 | + $boucle->group, |
|
| 1262 | + $boucle->order, |
|
| 1263 | + $boucle->limit, |
|
| 1264 | + $boucle->having, |
|
| 1265 | + $table_objet, |
|
| 1266 | + $id_table, |
|
| 1267 | + $serveur |
|
| 1268 | + ); |
|
| 1269 | + return (bool) sql_fetch($res); |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1273 | + return true; |
|
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | 1276 | |
@@ -1305,124 +1305,124 @@ discard block |
||
| 1305 | 1305 | * Retourne un tableau décrivant les parents trouvés |
| 1306 | 1306 | */ |
| 1307 | 1307 | function objet_lister_parents($objet, $id_objet, $parent_direct_seulement = false) { |
| 1308 | - $parents = []; |
|
| 1309 | - |
|
| 1310 | - // Si on trouve une ou des méthodes de parent |
|
| 1311 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1312 | - // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1313 | - include_spip('base/abstract_sql'); |
|
| 1314 | - $table_objet = table_objet_sql($objet); |
|
| 1315 | - $cle_objet = id_table_objet($objet); |
|
| 1316 | - $id_objet = (int) $id_objet; |
|
| 1317 | - |
|
| 1318 | - // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1319 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1320 | - // Champ identifiant le parent (id et éventuellement le type) |
|
| 1321 | - // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1322 | - // de celle de l'objet source |
|
| 1323 | - $select = []; |
|
| 1324 | - if (isset($parent_methode['champ'])) { |
|
| 1325 | - $select[] = $parent_methode['champ']; |
|
| 1326 | - } |
|
| 1327 | - if (isset($parent_methode['champ_type'])) { |
|
| 1328 | - $select[] = $parent_methode['champ_type']; |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1332 | - $condition_objet_invalide = false; |
|
| 1333 | - $where = []; |
|
| 1334 | - if (!isset($parent_methode['table'])) { |
|
| 1335 | - // Le parent est stocké dans la même table que l'objet source : |
|
| 1336 | - // -- toutes les conditions s'appliquent à la table source. |
|
| 1337 | - $table = $table_objet; |
|
| 1338 | - $where = ["$cle_objet = $id_objet"]; |
|
| 1339 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1340 | - if (isset($parent_methode['condition'])) { |
|
| 1341 | - $where[] = $parent_methode['condition']; |
|
| 1342 | - } |
|
| 1343 | - } elseif (!$parent_direct_seulement) { |
|
| 1344 | - // Le parent est stocké dans une table différente de l'objet source. |
|
| 1345 | - // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1346 | - // Si non, on peut arrêter le traitement. |
|
| 1347 | - if (isset($parent_methode['condition'])) { |
|
| 1348 | - $where = [ |
|
| 1349 | - "$cle_objet = $id_objet", |
|
| 1350 | - $parent_methode['condition'] |
|
| 1351 | - ]; |
|
| 1352 | - if (!sql_countsel($table_objet, $where)) { |
|
| 1353 | - $condition_objet_invalide = true; |
|
| 1354 | - } |
|
| 1355 | - } |
|
| 1356 | - |
|
| 1357 | - // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1358 | - // la requête sur la table qui accueille le parent. |
|
| 1359 | - if (!$condition_objet_invalide) { |
|
| 1360 | - $table = $parent_methode['table']; |
|
| 1361 | - // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1362 | - $where = []; |
|
| 1363 | - // -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est |
|
| 1364 | - // le même que celui de l'objet source. |
|
| 1365 | - $where[] = isset($parent_methode['source_champ']) |
|
| 1366 | - ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1367 | - : "$cle_objet = $id_objet"; |
|
| 1368 | - if (isset($parent_methode['source_champ_type'])) { |
|
| 1369 | - $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1370 | - } |
|
| 1371 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1372 | - if (isset($parent_methode['table_condition'])) { |
|
| 1373 | - $where[] = $parent_methode['table_condition']; |
|
| 1374 | - } |
|
| 1375 | - } |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - // On lance la requête de récupération du parent |
|
| 1379 | - $is_table_lien = (str_contains((string) $table, '_liens') && str_ends_with((string) $table, '_liens')); |
|
| 1380 | - if ( |
|
| 1381 | - !$condition_objet_invalide |
|
| 1382 | - && $where |
|
| 1383 | - && ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where)) |
|
| 1384 | - ) { |
|
| 1385 | - foreach ($lignes as $ligne) { |
|
| 1386 | - // Si le type est fixe |
|
| 1387 | - if (isset($parent_methode['type'])) { |
|
| 1388 | - $parent = [ |
|
| 1389 | - 'objet' => $parent_methode['type'], |
|
| 1390 | - 'id_objet' => (int) $ligne[$parent_methode['champ']], |
|
| 1391 | - 'champ' => $parent_methode['champ'], |
|
| 1392 | - 'table' => $table, |
|
| 1393 | - ]; |
|
| 1394 | - } |
|
| 1395 | - elseif (isset($parent_methode['champ_type'])) { |
|
| 1396 | - $parent = [ |
|
| 1397 | - 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1398 | - 'id_objet' => (int) $ligne[$parent_methode['champ']], |
|
| 1399 | - 'champ' => $parent_methode['champ'], |
|
| 1400 | - 'champ_type' => $parent_methode['champ_type'], |
|
| 1401 | - 'table' => $table, |
|
| 1402 | - ]; |
|
| 1403 | - } |
|
| 1404 | - if ($is_table_lien) { |
|
| 1405 | - $parent['lien'] = $ligne; |
|
| 1406 | - } |
|
| 1407 | - $parents[] = $parent; |
|
| 1408 | - } |
|
| 1409 | - } |
|
| 1410 | - } |
|
| 1411 | - } |
|
| 1412 | - |
|
| 1413 | - // On passe par un pipeline avant de retourner |
|
| 1414 | - $parents = pipeline( |
|
| 1415 | - 'objet_lister_parents', |
|
| 1416 | - [ |
|
| 1417 | - 'args' => [ |
|
| 1418 | - 'objet' => $objet, |
|
| 1419 | - 'id_objet' => $id_objet, |
|
| 1420 | - ], |
|
| 1421 | - 'data' => $parents, |
|
| 1422 | - ] |
|
| 1423 | - ); |
|
| 1424 | - |
|
| 1425 | - return $parents; |
|
| 1308 | + $parents = []; |
|
| 1309 | + |
|
| 1310 | + // Si on trouve une ou des méthodes de parent |
|
| 1311 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1312 | + // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1313 | + include_spip('base/abstract_sql'); |
|
| 1314 | + $table_objet = table_objet_sql($objet); |
|
| 1315 | + $cle_objet = id_table_objet($objet); |
|
| 1316 | + $id_objet = (int) $id_objet; |
|
| 1317 | + |
|
| 1318 | + // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1319 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1320 | + // Champ identifiant le parent (id et éventuellement le type) |
|
| 1321 | + // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1322 | + // de celle de l'objet source |
|
| 1323 | + $select = []; |
|
| 1324 | + if (isset($parent_methode['champ'])) { |
|
| 1325 | + $select[] = $parent_methode['champ']; |
|
| 1326 | + } |
|
| 1327 | + if (isset($parent_methode['champ_type'])) { |
|
| 1328 | + $select[] = $parent_methode['champ_type']; |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1332 | + $condition_objet_invalide = false; |
|
| 1333 | + $where = []; |
|
| 1334 | + if (!isset($parent_methode['table'])) { |
|
| 1335 | + // Le parent est stocké dans la même table que l'objet source : |
|
| 1336 | + // -- toutes les conditions s'appliquent à la table source. |
|
| 1337 | + $table = $table_objet; |
|
| 1338 | + $where = ["$cle_objet = $id_objet"]; |
|
| 1339 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1340 | + if (isset($parent_methode['condition'])) { |
|
| 1341 | + $where[] = $parent_methode['condition']; |
|
| 1342 | + } |
|
| 1343 | + } elseif (!$parent_direct_seulement) { |
|
| 1344 | + // Le parent est stocké dans une table différente de l'objet source. |
|
| 1345 | + // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1346 | + // Si non, on peut arrêter le traitement. |
|
| 1347 | + if (isset($parent_methode['condition'])) { |
|
| 1348 | + $where = [ |
|
| 1349 | + "$cle_objet = $id_objet", |
|
| 1350 | + $parent_methode['condition'] |
|
| 1351 | + ]; |
|
| 1352 | + if (!sql_countsel($table_objet, $where)) { |
|
| 1353 | + $condition_objet_invalide = true; |
|
| 1354 | + } |
|
| 1355 | + } |
|
| 1356 | + |
|
| 1357 | + // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1358 | + // la requête sur la table qui accueille le parent. |
|
| 1359 | + if (!$condition_objet_invalide) { |
|
| 1360 | + $table = $parent_methode['table']; |
|
| 1361 | + // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1362 | + $where = []; |
|
| 1363 | + // -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est |
|
| 1364 | + // le même que celui de l'objet source. |
|
| 1365 | + $where[] = isset($parent_methode['source_champ']) |
|
| 1366 | + ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1367 | + : "$cle_objet = $id_objet"; |
|
| 1368 | + if (isset($parent_methode['source_champ_type'])) { |
|
| 1369 | + $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1370 | + } |
|
| 1371 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1372 | + if (isset($parent_methode['table_condition'])) { |
|
| 1373 | + $where[] = $parent_methode['table_condition']; |
|
| 1374 | + } |
|
| 1375 | + } |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + // On lance la requête de récupération du parent |
|
| 1379 | + $is_table_lien = (str_contains((string) $table, '_liens') && str_ends_with((string) $table, '_liens')); |
|
| 1380 | + if ( |
|
| 1381 | + !$condition_objet_invalide |
|
| 1382 | + && $where |
|
| 1383 | + && ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where)) |
|
| 1384 | + ) { |
|
| 1385 | + foreach ($lignes as $ligne) { |
|
| 1386 | + // Si le type est fixe |
|
| 1387 | + if (isset($parent_methode['type'])) { |
|
| 1388 | + $parent = [ |
|
| 1389 | + 'objet' => $parent_methode['type'], |
|
| 1390 | + 'id_objet' => (int) $ligne[$parent_methode['champ']], |
|
| 1391 | + 'champ' => $parent_methode['champ'], |
|
| 1392 | + 'table' => $table, |
|
| 1393 | + ]; |
|
| 1394 | + } |
|
| 1395 | + elseif (isset($parent_methode['champ_type'])) { |
|
| 1396 | + $parent = [ |
|
| 1397 | + 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1398 | + 'id_objet' => (int) $ligne[$parent_methode['champ']], |
|
| 1399 | + 'champ' => $parent_methode['champ'], |
|
| 1400 | + 'champ_type' => $parent_methode['champ_type'], |
|
| 1401 | + 'table' => $table, |
|
| 1402 | + ]; |
|
| 1403 | + } |
|
| 1404 | + if ($is_table_lien) { |
|
| 1405 | + $parent['lien'] = $ligne; |
|
| 1406 | + } |
|
| 1407 | + $parents[] = $parent; |
|
| 1408 | + } |
|
| 1409 | + } |
|
| 1410 | + } |
|
| 1411 | + } |
|
| 1412 | + |
|
| 1413 | + // On passe par un pipeline avant de retourner |
|
| 1414 | + $parents = pipeline( |
|
| 1415 | + 'objet_lister_parents', |
|
| 1416 | + [ |
|
| 1417 | + 'args' => [ |
|
| 1418 | + 'objet' => $objet, |
|
| 1419 | + 'id_objet' => $id_objet, |
|
| 1420 | + ], |
|
| 1421 | + 'data' => $parents, |
|
| 1422 | + ] |
|
| 1423 | + ); |
|
| 1424 | + |
|
| 1425 | + return $parents; |
|
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | 1428 | /** |
@@ -1434,17 +1434,17 @@ discard block |
||
| 1434 | 1434 | * @return array |
| 1435 | 1435 | */ |
| 1436 | 1436 | function objet_lister_parents_par_type($objet, $id_objet) { |
| 1437 | - $parents = objet_lister_parents($objet, $id_objet); |
|
| 1437 | + $parents = objet_lister_parents($objet, $id_objet); |
|
| 1438 | 1438 | |
| 1439 | - $parents_par_type = []; |
|
| 1440 | - foreach ($parents as $parent) { |
|
| 1441 | - if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1442 | - $parents_par_type[$parent['objet']] = []; |
|
| 1443 | - } |
|
| 1444 | - $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1445 | - } |
|
| 1439 | + $parents_par_type = []; |
|
| 1440 | + foreach ($parents as $parent) { |
|
| 1441 | + if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1442 | + $parents_par_type[$parent['objet']] = []; |
|
| 1443 | + } |
|
| 1444 | + $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1445 | + } |
|
| 1446 | 1446 | |
| 1447 | - return $parents_par_type; |
|
| 1447 | + return $parents_par_type; |
|
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | 1450 | |
@@ -1477,85 +1477,85 @@ discard block |
||
| 1477 | 1477 | * Retourne un tableau de tableaux, avec comme clés les types des objets, et dans chacun un tableau des identifiants trouvés |
| 1478 | 1478 | */ |
| 1479 | 1479 | function objet_lister_enfants($objet, $id_objet) { |
| 1480 | - $enfants = []; |
|
| 1481 | - |
|
| 1482 | - // Si on trouve des types d'enfants et leurs méthodes |
|
| 1483 | - if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1484 | - include_spip('base/abstract_sql'); |
|
| 1485 | - $id_objet = (int) $id_objet; |
|
| 1486 | - |
|
| 1487 | - // On parcourt tous les types d'enfants trouvés |
|
| 1488 | - foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1489 | - // On construit les conditions d'identification du parent |
|
| 1490 | - $where = []; |
|
| 1491 | - // -- L'identifiant du parent |
|
| 1492 | - if (isset($_methode_parent['champ'])) { |
|
| 1493 | - $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1494 | - } |
|
| 1495 | - // -- Si le parent est variable |
|
| 1496 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1497 | - $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1498 | - } |
|
| 1499 | - |
|
| 1500 | - // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1501 | - if (!isset($_methode_parent['table'])) { |
|
| 1502 | - // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1503 | - $table_enfant = table_objet_sql($objet_enfant); |
|
| 1504 | - $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1505 | - |
|
| 1506 | - // S'il y a une condition supplémentaire |
|
| 1507 | - if (isset($_methode_parent['condition'])) { |
|
| 1508 | - $where[] = $_methode_parent['condition']; |
|
| 1509 | - } |
|
| 1510 | - } else { |
|
| 1511 | - // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1512 | - $table_enfant = $_methode_parent['table']; |
|
| 1513 | - $cle_objet_enfant = $_methode_parent['source_champ'] ?? id_table_objet($objet_enfant); |
|
| 1514 | - |
|
| 1515 | - // S'il y a une condition supplémentaire |
|
| 1516 | - if (isset($_methode_parent['table_condition'])) { |
|
| 1517 | - $where[] = $_methode_parent['table_condition']; |
|
| 1518 | - } |
|
| 1519 | - } |
|
| 1520 | - |
|
| 1521 | - // On lance la requête |
|
| 1522 | - $is_table_lien = (str_contains((string) $table_enfant, '_liens') && str_ends_with((string) $table_enfant, '_liens')); |
|
| 1523 | - if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1524 | - $enfant = [ |
|
| 1525 | - 'objet' => $objet_enfant, |
|
| 1526 | - 'id_objet' => 0, |
|
| 1527 | - 'table' => $table_enfant |
|
| 1528 | - ]; |
|
| 1529 | - if (isset($_methode_parent['champ'])) { |
|
| 1530 | - $enfant['champ'] = $_methode_parent['champ']; |
|
| 1531 | - } |
|
| 1532 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1533 | - $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1534 | - } |
|
| 1535 | - foreach ($rows as $row) { |
|
| 1536 | - $enfant['id_objet'] = (int) $row[$cle_objet_enfant]; |
|
| 1537 | - if ($is_table_lien) { |
|
| 1538 | - $enfant['lien'] = $row; |
|
| 1539 | - } |
|
| 1540 | - $enfants[] = $enfant; |
|
| 1541 | - } |
|
| 1542 | - } |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - |
|
| 1546 | - // On passe par un pipeline avant de retourner |
|
| 1547 | - $enfants = pipeline( |
|
| 1548 | - 'objet_lister_enfants', |
|
| 1549 | - [ |
|
| 1550 | - 'args' => [ |
|
| 1551 | - 'objet' => $objet, |
|
| 1552 | - 'id_objet' => $id_objet, |
|
| 1553 | - ], |
|
| 1554 | - 'data' => $enfants, |
|
| 1555 | - ] |
|
| 1556 | - ); |
|
| 1557 | - |
|
| 1558 | - return $enfants; |
|
| 1480 | + $enfants = []; |
|
| 1481 | + |
|
| 1482 | + // Si on trouve des types d'enfants et leurs méthodes |
|
| 1483 | + if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1484 | + include_spip('base/abstract_sql'); |
|
| 1485 | + $id_objet = (int) $id_objet; |
|
| 1486 | + |
|
| 1487 | + // On parcourt tous les types d'enfants trouvés |
|
| 1488 | + foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1489 | + // On construit les conditions d'identification du parent |
|
| 1490 | + $where = []; |
|
| 1491 | + // -- L'identifiant du parent |
|
| 1492 | + if (isset($_methode_parent['champ'])) { |
|
| 1493 | + $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1494 | + } |
|
| 1495 | + // -- Si le parent est variable |
|
| 1496 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1497 | + $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1498 | + } |
|
| 1499 | + |
|
| 1500 | + // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1501 | + if (!isset($_methode_parent['table'])) { |
|
| 1502 | + // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1503 | + $table_enfant = table_objet_sql($objet_enfant); |
|
| 1504 | + $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1505 | + |
|
| 1506 | + // S'il y a une condition supplémentaire |
|
| 1507 | + if (isset($_methode_parent['condition'])) { |
|
| 1508 | + $where[] = $_methode_parent['condition']; |
|
| 1509 | + } |
|
| 1510 | + } else { |
|
| 1511 | + // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1512 | + $table_enfant = $_methode_parent['table']; |
|
| 1513 | + $cle_objet_enfant = $_methode_parent['source_champ'] ?? id_table_objet($objet_enfant); |
|
| 1514 | + |
|
| 1515 | + // S'il y a une condition supplémentaire |
|
| 1516 | + if (isset($_methode_parent['table_condition'])) { |
|
| 1517 | + $where[] = $_methode_parent['table_condition']; |
|
| 1518 | + } |
|
| 1519 | + } |
|
| 1520 | + |
|
| 1521 | + // On lance la requête |
|
| 1522 | + $is_table_lien = (str_contains((string) $table_enfant, '_liens') && str_ends_with((string) $table_enfant, '_liens')); |
|
| 1523 | + if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1524 | + $enfant = [ |
|
| 1525 | + 'objet' => $objet_enfant, |
|
| 1526 | + 'id_objet' => 0, |
|
| 1527 | + 'table' => $table_enfant |
|
| 1528 | + ]; |
|
| 1529 | + if (isset($_methode_parent['champ'])) { |
|
| 1530 | + $enfant['champ'] = $_methode_parent['champ']; |
|
| 1531 | + } |
|
| 1532 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1533 | + $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1534 | + } |
|
| 1535 | + foreach ($rows as $row) { |
|
| 1536 | + $enfant['id_objet'] = (int) $row[$cle_objet_enfant]; |
|
| 1537 | + if ($is_table_lien) { |
|
| 1538 | + $enfant['lien'] = $row; |
|
| 1539 | + } |
|
| 1540 | + $enfants[] = $enfant; |
|
| 1541 | + } |
|
| 1542 | + } |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + // On passe par un pipeline avant de retourner |
|
| 1547 | + $enfants = pipeline( |
|
| 1548 | + 'objet_lister_enfants', |
|
| 1549 | + [ |
|
| 1550 | + 'args' => [ |
|
| 1551 | + 'objet' => $objet, |
|
| 1552 | + 'id_objet' => $id_objet, |
|
| 1553 | + ], |
|
| 1554 | + 'data' => $enfants, |
|
| 1555 | + ] |
|
| 1556 | + ); |
|
| 1557 | + |
|
| 1558 | + return $enfants; |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | /** |
@@ -1567,17 +1567,17 @@ discard block |
||
| 1567 | 1567 | * @return array |
| 1568 | 1568 | */ |
| 1569 | 1569 | function objet_lister_enfants_par_type($objet, $id_objet) { |
| 1570 | - $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1570 | + $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1571 | 1571 | |
| 1572 | - $enfants_par_type = []; |
|
| 1573 | - foreach ($enfants as $enfant) { |
|
| 1574 | - if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1575 | - $enfants_par_type[$enfant['objet']] = []; |
|
| 1576 | - } |
|
| 1577 | - $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1578 | - } |
|
| 1572 | + $enfants_par_type = []; |
|
| 1573 | + foreach ($enfants as $enfant) { |
|
| 1574 | + if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1575 | + $enfants_par_type[$enfant['objet']] = []; |
|
| 1576 | + } |
|
| 1577 | + $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1578 | + } |
|
| 1579 | 1579 | |
| 1580 | - return $enfants_par_type; |
|
| 1580 | + return $enfants_par_type; |
|
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | 1583 | /** |
@@ -1589,31 +1589,31 @@ discard block |
||
| 1589 | 1589 | * Retourne un tableau de tableau contenant les informations de type et de champ pour trouver le parent ou false sinon |
| 1590 | 1590 | */ |
| 1591 | 1591 | function objet_type_decrire_infos_parents($objet) { |
| 1592 | - static $parents = []; |
|
| 1593 | - |
|
| 1594 | - // Si on ne l'a pas encore cherché pour cet objet |
|
| 1595 | - if (!isset($parents[$objet])) { |
|
| 1596 | - $parents[$objet] = false; |
|
| 1597 | - $table = table_objet_sql($objet); |
|
| 1598 | - |
|
| 1599 | - // Si on trouve bien la description de cet objet |
|
| 1600 | - if ($infos = lister_tables_objets_sql($table)) { |
|
| 1601 | - if (isset($infos['parent']) && is_array($infos['parent'])) { |
|
| 1602 | - // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1603 | - // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1604 | - // de description |
|
| 1605 | - $parents[$objet] = isset($infos['parent'][0]) ? $infos['parent'] : [$infos['parent']]; |
|
| 1606 | - } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1607 | - // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1608 | - $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']]; |
|
| 1609 | - } elseif (isset($infos['field']['id_parent'])) { |
|
| 1610 | - // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1611 | - $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']]; |
|
| 1612 | - } |
|
| 1613 | - } |
|
| 1614 | - } |
|
| 1615 | - |
|
| 1616 | - return $parents[$objet]; |
|
| 1592 | + static $parents = []; |
|
| 1593 | + |
|
| 1594 | + // Si on ne l'a pas encore cherché pour cet objet |
|
| 1595 | + if (!isset($parents[$objet])) { |
|
| 1596 | + $parents[$objet] = false; |
|
| 1597 | + $table = table_objet_sql($objet); |
|
| 1598 | + |
|
| 1599 | + // Si on trouve bien la description de cet objet |
|
| 1600 | + if ($infos = lister_tables_objets_sql($table)) { |
|
| 1601 | + if (isset($infos['parent']) && is_array($infos['parent'])) { |
|
| 1602 | + // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1603 | + // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1604 | + // de description |
|
| 1605 | + $parents[$objet] = isset($infos['parent'][0]) ? $infos['parent'] : [$infos['parent']]; |
|
| 1606 | + } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1607 | + // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1608 | + $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']]; |
|
| 1609 | + } elseif (isset($infos['field']['id_parent'])) { |
|
| 1610 | + // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1611 | + $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']]; |
|
| 1612 | + } |
|
| 1613 | + } |
|
| 1614 | + } |
|
| 1615 | + |
|
| 1616 | + return $parents[$objet]; |
|
| 1617 | 1617 | } |
| 1618 | 1618 | |
| 1619 | 1619 | /** |
@@ -1625,36 +1625,36 @@ discard block |
||
| 1625 | 1625 | * Retourne un tableau de tableaux contenant chacun les informations d'un type d'enfant |
| 1626 | 1626 | */ |
| 1627 | 1627 | function objet_type_decrire_infos_enfants($objet) { |
| 1628 | - static $enfants = []; |
|
| 1629 | - |
|
| 1630 | - // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1631 | - if (!isset($enfants[$objet])) { |
|
| 1632 | - $enfants[$objet] = []; |
|
| 1633 | - $tables = lister_tables_objets_sql(); |
|
| 1634 | - |
|
| 1635 | - // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1636 | - foreach ($tables as $table => $infos) { |
|
| 1637 | - $objet_enfant = objet_type($table); |
|
| 1638 | - |
|
| 1639 | - // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1640 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1641 | - // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1642 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1643 | - // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1644 | - if (!isset($parent_methode['exclus']) || !in_array($objet, $parent_methode['exclus'])) { |
|
| 1645 | - // Si le type du parent est fixe et directement l'objet demandé |
|
| 1646 | - if (isset($parent_methode['type']) && isset($parent_methode['champ']) && $parent_methode['type'] == $objet) { |
|
| 1647 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1648 | - } |
|
| 1649 | - // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1650 | - elseif (isset($parent_methode['champ_type']) && isset($parent_methode['champ'])) { |
|
| 1651 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1652 | - } |
|
| 1653 | - } |
|
| 1654 | - } |
|
| 1655 | - } |
|
| 1656 | - } |
|
| 1657 | - } |
|
| 1658 | - |
|
| 1659 | - return $enfants[$objet]; |
|
| 1628 | + static $enfants = []; |
|
| 1629 | + |
|
| 1630 | + // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1631 | + if (!isset($enfants[$objet])) { |
|
| 1632 | + $enfants[$objet] = []; |
|
| 1633 | + $tables = lister_tables_objets_sql(); |
|
| 1634 | + |
|
| 1635 | + // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1636 | + foreach ($tables as $table => $infos) { |
|
| 1637 | + $objet_enfant = objet_type($table); |
|
| 1638 | + |
|
| 1639 | + // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1640 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1641 | + // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1642 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1643 | + // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1644 | + if (!isset($parent_methode['exclus']) || !in_array($objet, $parent_methode['exclus'])) { |
|
| 1645 | + // Si le type du parent est fixe et directement l'objet demandé |
|
| 1646 | + if (isset($parent_methode['type']) && isset($parent_methode['champ']) && $parent_methode['type'] == $objet) { |
|
| 1647 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1648 | + } |
|
| 1649 | + // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1650 | + elseif (isset($parent_methode['champ_type']) && isset($parent_methode['champ'])) { |
|
| 1651 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1652 | + } |
|
| 1653 | + } |
|
| 1654 | + } |
|
| 1655 | + } |
|
| 1656 | + } |
|
| 1657 | + } |
|
| 1658 | + |
|
| 1659 | + return $enfants[$objet]; |
|
| 1660 | 1660 | } |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | $infos['url_voir'] = $infos['type']; |
| 704 | 704 | } |
| 705 | 705 | if (!isset($infos['url_edit'])) { |
| 706 | - $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : ''); |
|
| 706 | + $infos['url_edit'] = $infos['url_voir'].($infos['editable'] ? '_edit' : ''); |
|
| 707 | 707 | } |
| 708 | 708 | if (!isset($infos['icone_objet'])) { |
| 709 | 709 | $infos['icone_objet'] = $infos['type']; |
@@ -715,48 +715,48 @@ discard block |
||
| 715 | 715 | $infos['texte_retour'] = 'icone_retour'; |
| 716 | 716 | } |
| 717 | 717 | if (!isset($infos['texte_modifier'])) { |
| 718 | - $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type']; |
|
| 718 | + $infos['texte_modifier'] = $infos['type'].':'.'icone_modifier_'.$infos['type']; |
|
| 719 | 719 | } |
| 720 | 720 | if (!isset($infos['texte_creer'])) { |
| 721 | - $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type']; |
|
| 721 | + $infos['texte_creer'] = $infos['type'].':'.'icone_creer_'.$infos['type']; |
|
| 722 | 722 | } |
| 723 | 723 | if (!isset($infos['texte_creer_associer'])) { |
| 724 | - $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type']; |
|
| 724 | + $infos['texte_creer_associer'] = $infos['type'].':'.'texte_creer_associer_'.$infos['type']; |
|
| 725 | 725 | } |
| 726 | 726 | if (!isset($infos['texte_ajouter'])) { |
| 727 | 727 | // Ajouter un X |
| 728 | - $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type']; |
|
| 728 | + $infos['texte_ajouter'] = $infos['type'].':'.'texte_ajouter_'.$infos['type']; |
|
| 729 | 729 | } |
| 730 | 730 | if (!isset($infos['texte_objets'])) { |
| 731 | - $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet']; |
|
| 731 | + $infos['texte_objets'] = $infos['type'].':'.'titre_'.$infos['table_objet']; |
|
| 732 | 732 | } |
| 733 | 733 | if (!isset($infos['texte_objet'])) { |
| 734 | - $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type']; |
|
| 734 | + $infos['texte_objet'] = $infos['type'].':'.'titre_'.$infos['type']; |
|
| 735 | 735 | } |
| 736 | 736 | if (!isset($infos['texte_logo_objet'])) { |
| 737 | 737 | // objet:titre_logo_objet "Logo de ce X" |
| 738 | - $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type']; |
|
| 738 | + $infos['texte_logo_objet'] = $infos['type'].':'.'titre_logo_'.$infos['type']; |
|
| 739 | 739 | } |
| 740 | 740 | if (!isset($infos['texte_langue_objet'])) { |
| 741 | 741 | // objet:texte_langue_objet "Langue de ce X" |
| 742 | - $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type']; |
|
| 742 | + $infos['texte_langue_objet'] = $infos['type'].':'.'titre_langue_'.$infos['type']; |
|
| 743 | 743 | } |
| 744 | 744 | if (!isset($infos['texte_definir_comme_traduction_objet'])) { |
| 745 | 745 | // "Ce X est une traduction du X numéro :" |
| 746 | - $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type']; |
|
| 746 | + $infos['texte_definir_comme_traduction_objet'] = $infos['type'].':'.'texte_definir_comme_traduction_'.$infos['type']; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | // objet:info_aucun_objet |
| 750 | 750 | if (!isset($infos['info_aucun_objet'])) { |
| 751 | - $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type']; |
|
| 751 | + $infos['info_aucun_objet'] = $infos['type'].':'.'info_aucun_'.$infos['type']; |
|
| 752 | 752 | } |
| 753 | 753 | // objet:info_1_objet |
| 754 | 754 | if (!isset($infos['info_1_objet'])) { |
| 755 | - $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type']; |
|
| 755 | + $infos['info_1_objet'] = $infos['type'].':'.'info_1_'.$infos['type']; |
|
| 756 | 756 | } |
| 757 | 757 | // objet:info_nb_objets |
| 758 | 758 | if (!isset($infos['info_nb_objets'])) { |
| 759 | - $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet']; |
|
| 759 | + $infos['info_nb_objets'] = $infos['type'].':'.'info_nb_'.$infos['table_objet']; |
|
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | if (!isset($infos['champs_editables'])) { |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | } |
| 955 | 955 | $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
| 956 | 956 | $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
| 957 | - $spip = $connexion['prefixe'] . '_'; |
|
| 957 | + $spip = $connexion['prefixe'].'_'; |
|
| 958 | 958 | foreach ($ts as $t) { |
| 959 | 959 | $t = substr((string) $t, strlen($spip)); |
| 960 | 960 | $tables[$serveur]["spip_$t"] = $t; |
@@ -1023,9 +1023,9 @@ discard block |
||
| 1023 | 1023 | if ($serveur !== false) { |
| 1024 | 1024 | $t = lister_tables_spip($serveur); |
| 1025 | 1025 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 1026 | - $typetrim = rtrim($type, 's') . 's'; |
|
| 1026 | + $typetrim = rtrim($type, 's').'s'; |
|
| 1027 | 1027 | if ( |
| 1028 | - (isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1028 | + (isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's').'s', $serveur)) |
|
| 1029 | 1029 | ) { |
| 1030 | 1030 | return $desc['id_table']; |
| 1031 | 1031 | } elseif ( |
@@ -1034,11 +1034,11 @@ discard block |
||
| 1034 | 1034 | return $desc['id_table']; |
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | - spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1037 | + spip_log('table_objet('.$type.') calculee sans verification'); |
|
| 1038 | 1038 | #spip_log(debug_backtrace(),'db'); |
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | - return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1041 | + return rtrim($type, 's').'s'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | /** |
@@ -1221,7 +1221,7 @@ discard block |
||
| 1221 | 1221 | function objet_test_si_publie($objet, $id_objet, $serveur = '') { |
| 1222 | 1222 | // voir si une fonction est definie pour faire le boulot |
| 1223 | 1223 | // elle a la priorite dans ce cas |
| 1224 | - if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) { |
|
| 1224 | + if ($f = charger_fonction($objet.'_test_si_publie', 'base', true)) { |
|
| 1225 | 1225 | return $f($objet, $id_objet, $serveur); |
| 1226 | 1226 | } |
| 1227 | 1227 | |
@@ -1243,7 +1243,7 @@ discard block |
||
| 1243 | 1243 | $boucle->sql_serveur = $serveur; |
| 1244 | 1244 | $boucle->select[] = $id_table_objet; |
| 1245 | 1245 | $boucle->from[$table_objet] = table_objet_sql($objet, $serveur); |
| 1246 | - $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . (int) $id_objet; |
|
| 1246 | + $boucle->where[] = $id_table.'.'.$id_table_objet.'='.(int) $id_objet; |
|
| 1247 | 1247 | |
| 1248 | 1248 | $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
| 1249 | 1249 | $boucle->descr['sourcefile'] = 'internal'; |
@@ -1366,7 +1366,7 @@ discard block |
||
| 1366 | 1366 | ? "{$parent_methode['source_champ']} = $id_objet" |
| 1367 | 1367 | : "$cle_objet = $id_objet"; |
| 1368 | 1368 | if (isset($parent_methode['source_champ_type'])) { |
| 1369 | - $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1369 | + $where[] = "{$parent_methode['source_champ_type']} = ".sql_quote($objet); |
|
| 1370 | 1370 | } |
| 1371 | 1371 | // -- Condition supplémentaire sur la détection du parent |
| 1372 | 1372 | if (isset($parent_methode['table_condition'])) { |
@@ -1490,11 +1490,11 @@ discard block |
||
| 1490 | 1490 | $where = []; |
| 1491 | 1491 | // -- L'identifiant du parent |
| 1492 | 1492 | if (isset($_methode_parent['champ'])) { |
| 1493 | - $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1493 | + $where[] = $_methode_parent['champ'].' = '.$id_objet; |
|
| 1494 | 1494 | } |
| 1495 | 1495 | // -- Si le parent est variable |
| 1496 | 1496 | if (isset($_methode_parent['champ_type'])) { |
| 1497 | - $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1497 | + $where[] = $_methode_parent['champ_type'].' = '.sql_quote($objet); |
|
| 1498 | 1498 | } |
| 1499 | 1499 | |
| 1500 | 1500 | // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
@@ -1391,8 +1391,7 @@ |
||
| 1391 | 1391 | 'champ' => $parent_methode['champ'], |
| 1392 | 1392 | 'table' => $table, |
| 1393 | 1393 | ]; |
| 1394 | - } |
|
| 1395 | - elseif (isset($parent_methode['champ_type'])) { |
|
| 1394 | + } elseif (isset($parent_methode['champ_type'])) { |
|
| 1396 | 1395 | $parent = [ |
| 1397 | 1396 | 'objet' => $ligne[$parent_methode['champ_type']], |
| 1398 | 1397 | 'id_objet' => (int) $ligne[$parent_methode['champ']], |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -28,27 +28,27 @@ discard block |
||
| 28 | 28 | * @param string $titre Inutilisé |
| 29 | 29 | **/ |
| 30 | 30 | function base_delete_all_dist($titre) { |
| 31 | - $delete = _request('delete'); |
|
| 32 | - $res = []; |
|
| 33 | - if (is_array($delete)) { |
|
| 34 | - foreach ($delete as $table) { |
|
| 35 | - if (sql_drop_table($table)) { |
|
| 36 | - $res[] = $table; |
|
| 37 | - } else { |
|
| 38 | - spip_log("SPIP n'a pas pu detruire $table.", _LOG_ERREUR); |
|
| 39 | - } |
|
| 40 | - } |
|
| 31 | + $delete = _request('delete'); |
|
| 32 | + $res = []; |
|
| 33 | + if (is_array($delete)) { |
|
| 34 | + foreach ($delete as $table) { |
|
| 35 | + if (sql_drop_table($table)) { |
|
| 36 | + $res[] = $table; |
|
| 37 | + } else { |
|
| 38 | + spip_log("SPIP n'a pas pu detruire $table.", _LOG_ERREUR); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - // un pipeline pour detruire les tables installees par les plugins |
|
| 43 | - pipeline('delete_tables', ''); |
|
| 42 | + // un pipeline pour detruire les tables installees par les plugins |
|
| 43 | + pipeline('delete_tables', ''); |
|
| 44 | 44 | |
| 45 | - spip_unlink(_FILE_CONNECT); |
|
| 46 | - spip_unlink(_FILE_CHMOD); |
|
| 47 | - spip_unlink(_FILE_META); |
|
| 48 | - spip_unlink(_ACCESS_FILE_NAME); |
|
| 49 | - spip_unlink(_CACHE_RUBRIQUES); |
|
| 50 | - } |
|
| 51 | - $d = is_countable($delete) ? count($delete) : 0; |
|
| 52 | - $r = count($res); |
|
| 53 | - spip_log("Tables detruites: $r sur $d: " . implode(', ', $res), _LOG_INFO_IMPORTANTE); |
|
| 45 | + spip_unlink(_FILE_CONNECT); |
|
| 46 | + spip_unlink(_FILE_CHMOD); |
|
| 47 | + spip_unlink(_FILE_META); |
|
| 48 | + spip_unlink(_ACCESS_FILE_NAME); |
|
| 49 | + spip_unlink(_CACHE_RUBRIQUES); |
|
| 50 | + } |
|
| 51 | + $d = is_countable($delete) ? count($delete) : 0; |
|
| 52 | + $r = count($res); |
|
| 53 | + spip_log("Tables detruites: $r sur $d: " . implode(', ', $res), _LOG_INFO_IMPORTANTE); |
|
| 54 | 54 | } |
@@ -50,5 +50,5 @@ |
||
| 50 | 50 | } |
| 51 | 51 | $d = is_countable($delete) ? count($delete) : 0; |
| 52 | 52 | $r = count($res); |
| 53 | - spip_log("Tables detruites: $r sur $d: " . implode(', ', $res), _LOG_INFO_IMPORTANTE); |
|
| 53 | + spip_log("Tables detruites: $r sur $d: ".implode(', ', $res), _LOG_INFO_IMPORTANTE); |
|
| 54 | 54 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | 26 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 27 | - return; |
|
| 27 | + return; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** Version de l'API SQL */ |
@@ -44,37 +44,37 @@ discard block |
||
| 44 | 44 | * contexte de l'erreur |
| 45 | 45 | **/ |
| 46 | 46 | function sql_error_backtrace($compil_info = false) { |
| 47 | - $trace = debug_backtrace(); |
|
| 48 | - $caller = array_shift($trace); |
|
| 49 | - while (count($trace) && (empty($trace[0]['file']) || $trace[0]['file'] === $caller['file'] || $trace[0]['file'] === __FILE__)) { |
|
| 50 | - array_shift($trace); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if ($compil_info) { |
|
| 54 | - return [ |
|
| 55 | - $trace[0]['file'],// sourcefile |
|
| 56 | - '', //nom |
|
| 57 | - (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 58 | - . $trace[0]['function'] . '();' |
|
| 59 | - . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
|
| 60 | - $trace[0]['line'], // ligne |
|
| 61 | - $GLOBALS['spip_lang'], // lang |
|
| 62 | - ]; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 66 | - $f = []; |
|
| 67 | - while (count($trace) && ($t = array_shift($trace))) { |
|
| 68 | - if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
|
| 69 | - break; |
|
| 70 | - } |
|
| 71 | - $f[] = $t['function']; |
|
| 72 | - } |
|
| 73 | - if ($f !== []) { |
|
| 74 | - $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - return $message; |
|
| 47 | + $trace = debug_backtrace(); |
|
| 48 | + $caller = array_shift($trace); |
|
| 49 | + while (count($trace) && (empty($trace[0]['file']) || $trace[0]['file'] === $caller['file'] || $trace[0]['file'] === __FILE__)) { |
|
| 50 | + array_shift($trace); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if ($compil_info) { |
|
| 54 | + return [ |
|
| 55 | + $trace[0]['file'],// sourcefile |
|
| 56 | + '', //nom |
|
| 57 | + (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 58 | + . $trace[0]['function'] . '();' |
|
| 59 | + . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
|
| 60 | + $trace[0]['line'], // ligne |
|
| 61 | + $GLOBALS['spip_lang'], // lang |
|
| 62 | + ]; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 66 | + $f = []; |
|
| 67 | + while (count($trace) && ($t = array_shift($trace))) { |
|
| 68 | + if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
|
| 69 | + break; |
|
| 70 | + } |
|
| 71 | + $f[] = $t['function']; |
|
| 72 | + } |
|
| 73 | + if ($f !== []) { |
|
| 74 | + $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + return $message; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | |
@@ -99,16 +99,16 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | **/ |
| 101 | 101 | function sql_serveur($ins_sql = '', $serveur = '', $continue = false) { |
| 102 | - static $sql_serveur = []; |
|
| 103 | - if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 104 | - $f = spip_connect_sql(\SQL_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 105 | - if (!is_string($f) || !$f) { |
|
| 106 | - return $f; |
|
| 107 | - } |
|
| 108 | - $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $sql_serveur[$serveur][$ins_sql]; |
|
| 102 | + static $sql_serveur = []; |
|
| 103 | + if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 104 | + $f = spip_connect_sql(\SQL_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 105 | + if (!is_string($f) || !$f) { |
|
| 106 | + return $f; |
|
| 107 | + } |
|
| 108 | + $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $sql_serveur[$serveur][$ins_sql]; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -130,23 +130,23 @@ discard block |
||
| 130 | 130 | * Retourne le nom du charset si effectivement trouvé, sinon false. |
| 131 | 131 | **/ |
| 132 | 132 | function sql_get_charset($charset, $serveur = '', $option = true) { |
| 133 | - // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 134 | - $desc = sql_serveur('', $serveur, true); |
|
| 135 | - $desc = $desc[\SQL_ABSTRACT_VERSION]; |
|
| 136 | - $c = $desc['charsets'][$charset]; |
|
| 137 | - if ( |
|
| 138 | - $c |
|
| 139 | - && function_exists($f = @$desc['get_charset']) |
|
| 140 | - && $f($c, $serveur, $option) |
|
| 141 | - ) { |
|
| 142 | - return $c; |
|
| 143 | - } |
|
| 144 | - spip_log( |
|
| 145 | - "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", |
|
| 146 | - _LOG_AVERTISSEMENT |
|
| 147 | - ); |
|
| 148 | - |
|
| 149 | - return false; |
|
| 133 | + // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 134 | + $desc = sql_serveur('', $serveur, true); |
|
| 135 | + $desc = $desc[\SQL_ABSTRACT_VERSION]; |
|
| 136 | + $c = $desc['charsets'][$charset]; |
|
| 137 | + if ( |
|
| 138 | + $c |
|
| 139 | + && function_exists($f = @$desc['get_charset']) |
|
| 140 | + && $f($c, $serveur, $option) |
|
| 141 | + ) { |
|
| 142 | + return $c; |
|
| 143 | + } |
|
| 144 | + spip_log( |
|
| 145 | + "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", |
|
| 146 | + _LOG_AVERTISSEMENT |
|
| 147 | + ); |
|
| 148 | + |
|
| 149 | + return false; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
@@ -172,12 +172,12 @@ discard block |
||
| 172 | 172 | * Retourne true si elle reussie. |
| 173 | 173 | **/ |
| 174 | 174 | function sql_set_charset($charset, $serveur = '', $option = true) { |
| 175 | - $f = sql_serveur('set_charset', $serveur, $option === 'continue' || $option === false); |
|
| 176 | - if (!is_string($f) || !$f) { |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 175 | + $f = sql_serveur('set_charset', $serveur, $option === 'continue' || $option === false); |
|
| 176 | + if (!is_string($f) || !$f) { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - return $f($charset, $serveur, $option !== false); |
|
| 180 | + return $f($charset, $serveur, $option !== false); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
@@ -228,59 +228,59 @@ discard block |
||
| 228 | 228 | * |
| 229 | 229 | **/ |
| 230 | 230 | function sql_select( |
| 231 | - $select = [], |
|
| 232 | - $from = [], |
|
| 233 | - $where = [], |
|
| 234 | - $groupby = [], |
|
| 235 | - $orderby = [], |
|
| 236 | - $limit = '', |
|
| 237 | - $having = [], |
|
| 238 | - $serveur = '', |
|
| 239 | - $option = true |
|
| 231 | + $select = [], |
|
| 232 | + $from = [], |
|
| 233 | + $where = [], |
|
| 234 | + $groupby = [], |
|
| 235 | + $orderby = [], |
|
| 236 | + $limit = '', |
|
| 237 | + $having = [], |
|
| 238 | + $serveur = '', |
|
| 239 | + $option = true |
|
| 240 | 240 | ) { |
| 241 | - $f = sql_serveur('select', $serveur, $option === 'continue' || $option === false); |
|
| 242 | - if (!is_string($f) || !$f) { |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 247 | - if ($option !== false && !$debug) { |
|
| 248 | - $res = $f( |
|
| 249 | - $select, |
|
| 250 | - $from, |
|
| 251 | - $where, |
|
| 252 | - $groupby, |
|
| 253 | - $orderby, |
|
| 254 | - $limit, |
|
| 255 | - $having, |
|
| 256 | - $serveur, |
|
| 257 | - is_array($option) ? true : $option |
|
| 258 | - ); |
|
| 259 | - } else { |
|
| 260 | - $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 261 | - if (!$option) { |
|
| 262 | - return $query; |
|
| 263 | - } |
|
| 264 | - // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 265 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 266 | - [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
|
| 267 | - $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 268 | - $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 269 | - } |
|
| 270 | - $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // en cas d'erreur |
|
| 274 | - if (!is_string($res)) { |
|
| 275 | - return $res; |
|
| 276 | - } |
|
| 277 | - // denoncer l'erreur SQL dans sa version brute |
|
| 278 | - spip_sql_erreur($serveur); |
|
| 279 | - // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 280 | - $contexte_compil = sql_error_backtrace(true); |
|
| 281 | - erreur_squelette([sql_errno($serveur), sql_error($serveur), $res], $contexte_compil); |
|
| 282 | - |
|
| 283 | - return false; |
|
| 241 | + $f = sql_serveur('select', $serveur, $option === 'continue' || $option === false); |
|
| 242 | + if (!is_string($f) || !$f) { |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 247 | + if ($option !== false && !$debug) { |
|
| 248 | + $res = $f( |
|
| 249 | + $select, |
|
| 250 | + $from, |
|
| 251 | + $where, |
|
| 252 | + $groupby, |
|
| 253 | + $orderby, |
|
| 254 | + $limit, |
|
| 255 | + $having, |
|
| 256 | + $serveur, |
|
| 257 | + is_array($option) ? true : $option |
|
| 258 | + ); |
|
| 259 | + } else { |
|
| 260 | + $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 261 | + if (!$option) { |
|
| 262 | + return $query; |
|
| 263 | + } |
|
| 264 | + // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 265 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 266 | + [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
|
| 267 | + $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 268 | + $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 269 | + } |
|
| 270 | + $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // en cas d'erreur |
|
| 274 | + if (!is_string($res)) { |
|
| 275 | + return $res; |
|
| 276 | + } |
|
| 277 | + // denoncer l'erreur SQL dans sa version brute |
|
| 278 | + spip_sql_erreur($serveur); |
|
| 279 | + // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 280 | + $contexte_compil = sql_error_backtrace(true); |
|
| 281 | + erreur_squelette([sql_errno($serveur), sql_error($serveur), $res], $contexte_compil); |
|
| 282 | + |
|
| 283 | + return false; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -317,16 +317,16 @@ discard block |
||
| 317 | 317 | * |
| 318 | 318 | **/ |
| 319 | 319 | function sql_get_select( |
| 320 | - $select = [], |
|
| 321 | - $from = [], |
|
| 322 | - $where = [], |
|
| 323 | - $groupby = [], |
|
| 324 | - $orderby = [], |
|
| 325 | - $limit = '', |
|
| 326 | - $having = [], |
|
| 327 | - $serveur = '' |
|
| 320 | + $select = [], |
|
| 321 | + $from = [], |
|
| 322 | + $where = [], |
|
| 323 | + $groupby = [], |
|
| 324 | + $orderby = [], |
|
| 325 | + $limit = '', |
|
| 326 | + $having = [], |
|
| 327 | + $serveur = '' |
|
| 328 | 328 | ) { |
| 329 | - return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 329 | + return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | |
@@ -370,23 +370,23 @@ discard block |
||
| 370 | 370 | * |
| 371 | 371 | **/ |
| 372 | 372 | function sql_countsel( |
| 373 | - $from = [], |
|
| 374 | - $where = [], |
|
| 375 | - $groupby = [], |
|
| 376 | - $having = [], |
|
| 377 | - $serveur = '', |
|
| 378 | - $option = true |
|
| 373 | + $from = [], |
|
| 374 | + $where = [], |
|
| 375 | + $groupby = [], |
|
| 376 | + $having = [], |
|
| 377 | + $serveur = '', |
|
| 378 | + $option = true |
|
| 379 | 379 | ) { |
| 380 | - $f = sql_serveur('countsel', $serveur, $option === 'continue' || $option === false); |
|
| 381 | - if (!is_string($f) || !$f) { |
|
| 382 | - return false; |
|
| 383 | - } |
|
| 384 | - $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 385 | - if ($r === false) { |
|
| 386 | - spip_sql_erreur($serveur); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - return $r; |
|
| 380 | + $f = sql_serveur('countsel', $serveur, $option === 'continue' || $option === false); |
|
| 381 | + if (!is_string($f) || !$f) { |
|
| 382 | + return false; |
|
| 383 | + } |
|
| 384 | + $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 385 | + if ($r === false) { |
|
| 386 | + spip_sql_erreur($serveur); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + return $r; |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | /** |
@@ -418,16 +418,16 @@ discard block |
||
| 418 | 418 | * Ce retour n'est pas pertinent pour savoir si l'opération est correctement réalisée. |
| 419 | 419 | **/ |
| 420 | 420 | function sql_alter($q, $serveur = '', $option = true) { |
| 421 | - $f = sql_serveur('alter', $serveur, $option === 'continue' || $option === false); |
|
| 422 | - if (!is_string($f) || !$f) { |
|
| 423 | - return false; |
|
| 424 | - } |
|
| 425 | - $r = $f($q, $serveur, $option !== false); |
|
| 426 | - if ($r === false) { |
|
| 427 | - spip_sql_erreur($serveur); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - return $r; |
|
| 421 | + $f = sql_serveur('alter', $serveur, $option === 'continue' || $option === false); |
|
| 422 | + if (!is_string($f) || !$f) { |
|
| 423 | + return false; |
|
| 424 | + } |
|
| 425 | + $r = $f($q, $serveur, $option !== false); |
|
| 426 | + if ($r === false) { |
|
| 427 | + spip_sql_erreur($serveur); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + return $r; |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -450,12 +450,12 @@ discard block |
||
| 450 | 450 | * presentant une ligne de resultat d'une selection |
| 451 | 451 | */ |
| 452 | 452 | function sql_fetch(mixed $res, $serveur = '', $option = true) { |
| 453 | - $f = sql_serveur('fetch', $serveur, $option === 'continue' || $option === false); |
|
| 454 | - if (!is_string($f) || !$f) { |
|
| 455 | - return false; |
|
| 456 | - } |
|
| 453 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' || $option === false); |
|
| 454 | + if (!is_string($f) || !$f) { |
|
| 455 | + return false; |
|
| 456 | + } |
|
| 457 | 457 | |
| 458 | - return $f($res, null, $serveur, $option !== false); |
|
| 458 | + return $f($res, null, $serveur, $option !== false); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | |
@@ -482,20 +482,20 @@ discard block |
||
| 482 | 482 | * presentant une ligne de resultat d'une selection |
| 483 | 483 | */ |
| 484 | 484 | function sql_fetch_all(mixed $res, $serveur = '', $option = true) { |
| 485 | - $rows = []; |
|
| 486 | - if (!$res) { |
|
| 487 | - return $rows; |
|
| 488 | - } |
|
| 489 | - $f = sql_serveur('fetch', $serveur, $option === 'continue' || $option === false); |
|
| 490 | - if (!is_string($f) || !$f) { |
|
| 491 | - return []; |
|
| 492 | - } |
|
| 493 | - while ($r = $f($res, null, $serveur, $option !== false)) { |
|
| 494 | - $rows[] = $r; |
|
| 495 | - } |
|
| 496 | - sql_free($res, $serveur); |
|
| 497 | - |
|
| 498 | - return $rows; |
|
| 485 | + $rows = []; |
|
| 486 | + if (!$res) { |
|
| 487 | + return $rows; |
|
| 488 | + } |
|
| 489 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' || $option === false); |
|
| 490 | + if (!is_string($f) || !$f) { |
|
| 491 | + return []; |
|
| 492 | + } |
|
| 493 | + while ($r = $f($res, null, $serveur, $option !== false)) { |
|
| 494 | + $rows[] = $r; |
|
| 495 | + } |
|
| 496 | + sql_free($res, $serveur); |
|
| 497 | + |
|
| 498 | + return $rows; |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | /** |
@@ -523,16 +523,16 @@ discard block |
||
| 523 | 523 | * Operation effectuée (true), sinon false. |
| 524 | 524 | **/ |
| 525 | 525 | function sql_seek(mixed $res, $row_number, $serveur = '', $option = true) { |
| 526 | - $f = sql_serveur('seek', $serveur, $option === 'continue' || $option === false); |
|
| 527 | - if (!is_string($f) || !$f) { |
|
| 528 | - return false; |
|
| 529 | - } |
|
| 530 | - $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 531 | - if ($r === false) { |
|
| 532 | - spip_sql_erreur($serveur); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - return $r; |
|
| 526 | + $f = sql_serveur('seek', $serveur, $option === 'continue' || $option === false); |
|
| 527 | + if (!is_string($f) || !$f) { |
|
| 528 | + return false; |
|
| 529 | + } |
|
| 530 | + $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 531 | + if ($r === false) { |
|
| 532 | + spip_sql_erreur($serveur); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + return $r; |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | |
@@ -557,16 +557,16 @@ discard block |
||
| 557 | 557 | * False en cas d'erreur. |
| 558 | 558 | **/ |
| 559 | 559 | function sql_listdbs($serveur = '', $option = true) { |
| 560 | - $f = sql_serveur('listdbs', $serveur, $option === 'continue' || $option === false); |
|
| 561 | - if (!is_string($f) || !$f) { |
|
| 562 | - return false; |
|
| 563 | - } |
|
| 564 | - $r = $f($serveur); |
|
| 565 | - if ($r === false) { |
|
| 566 | - spip_sql_erreur($serveur); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - return $r; |
|
| 560 | + $f = sql_serveur('listdbs', $serveur, $option === 'continue' || $option === false); |
|
| 561 | + if (!is_string($f) || !$f) { |
|
| 562 | + return false; |
|
| 563 | + } |
|
| 564 | + $r = $f($serveur); |
|
| 565 | + if ($r === false) { |
|
| 566 | + spip_sql_erreur($serveur); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + return $r; |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | |
@@ -589,16 +589,16 @@ discard block |
||
| 589 | 589 | * - False en cas d'erreur. |
| 590 | 590 | **/ |
| 591 | 591 | function sql_selectdb($nom, $serveur = '', $option = true) { |
| 592 | - $f = sql_serveur('selectdb', $serveur, $option === 'continue' || $option === false); |
|
| 593 | - if (!is_string($f) || !$f) { |
|
| 594 | - return false; |
|
| 595 | - } |
|
| 596 | - $r = $f($nom, $serveur, $option !== false); |
|
| 597 | - if ($r === false) { |
|
| 598 | - spip_sql_erreur($serveur); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - return $r; |
|
| 592 | + $f = sql_serveur('selectdb', $serveur, $option === 'continue' || $option === false); |
|
| 593 | + if (!is_string($f) || !$f) { |
|
| 594 | + return false; |
|
| 595 | + } |
|
| 596 | + $r = $f($nom, $serveur, $option !== false); |
|
| 597 | + if ($r === false) { |
|
| 598 | + spip_sql_erreur($serveur); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + return $r; |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | /** |
@@ -623,16 +623,16 @@ discard block |
||
| 623 | 623 | * - false en cas d'erreur. |
| 624 | 624 | **/ |
| 625 | 625 | function sql_count($res, $serveur = '', $option = true) { |
| 626 | - $f = sql_serveur('count', $serveur, $option === 'continue' || $option === false); |
|
| 627 | - if (!is_string($f) || !$f) { |
|
| 628 | - return false; |
|
| 629 | - } |
|
| 630 | - $r = $f($res, $serveur, $option !== false); |
|
| 631 | - if ($r === false) { |
|
| 632 | - spip_sql_erreur($serveur); |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - return $r; |
|
| 626 | + $f = sql_serveur('count', $serveur, $option === 'continue' || $option === false); |
|
| 627 | + if (!is_string($f) || !$f) { |
|
| 628 | + return false; |
|
| 629 | + } |
|
| 630 | + $r = $f($res, $serveur, $option !== false); |
|
| 631 | + if ($r === false) { |
|
| 632 | + spip_sql_erreur($serveur); |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + return $r; |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | /** |
@@ -654,12 +654,12 @@ discard block |
||
| 654 | 654 | * True si réussi |
| 655 | 655 | */ |
| 656 | 656 | function sql_free($res, $serveur = '', $option = true) { |
| 657 | - $f = sql_serveur('free', $serveur, $option === 'continue' || $option === false); |
|
| 658 | - if (!is_string($f) || !$f) { |
|
| 659 | - return false; |
|
| 660 | - } |
|
| 657 | + $f = sql_serveur('free', $serveur, $option === 'continue' || $option === false); |
|
| 658 | + if (!is_string($f) || !$f) { |
|
| 659 | + return false; |
|
| 660 | + } |
|
| 661 | 661 | |
| 662 | - return $f($res); |
|
| 662 | + return $f($res); |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | |
@@ -697,17 +697,17 @@ discard block |
||
| 697 | 697 | * - False en cas d'erreur. |
| 698 | 698 | **/ |
| 699 | 699 | function sql_insert($table, $noms, $valeurs, $desc = [], $serveur = '', $option = true) { |
| 700 | - $f = sql_serveur('insert', $serveur, $option === 'continue' || $option === false); |
|
| 701 | - if (!is_string($f) || !$f) { |
|
| 702 | - return false; |
|
| 703 | - } |
|
| 704 | - $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 705 | - if ($r === false || $r === null) { |
|
| 706 | - spip_sql_erreur($serveur); |
|
| 707 | - $r = false; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - return $r; |
|
| 700 | + $f = sql_serveur('insert', $serveur, $option === 'continue' || $option === false); |
|
| 701 | + if (!is_string($f) || !$f) { |
|
| 702 | + return false; |
|
| 703 | + } |
|
| 704 | + $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 705 | + if ($r === false || $r === null) { |
|
| 706 | + spip_sql_erreur($serveur); |
|
| 707 | + $r = false; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + return $r; |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | /** |
@@ -748,17 +748,17 @@ discard block |
||
| 748 | 748 | * - False en cas d'erreur. |
| 749 | 749 | **/ |
| 750 | 750 | function sql_insertq($table, $couples = [], $desc = [], $serveur = '', $option = true) { |
| 751 | - $f = sql_serveur('insertq', $serveur, $option === 'continue' || $option === false); |
|
| 752 | - if (!is_string($f) || !$f) { |
|
| 753 | - return false; |
|
| 754 | - } |
|
| 755 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 756 | - if ($r === false || $r === null) { |
|
| 757 | - spip_sql_erreur($serveur); |
|
| 758 | - $r = false; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - return $r; |
|
| 751 | + $f = sql_serveur('insertq', $serveur, $option === 'continue' || $option === false); |
|
| 752 | + if (!is_string($f) || !$f) { |
|
| 753 | + return false; |
|
| 754 | + } |
|
| 755 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 756 | + if ($r === false || $r === null) { |
|
| 757 | + spip_sql_erreur($serveur); |
|
| 758 | + $r = false; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + return $r; |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | /** |
@@ -793,17 +793,17 @@ discard block |
||
| 793 | 793 | * - false en cas d'erreur. |
| 794 | 794 | **/ |
| 795 | 795 | function sql_insertq_multi($table, $couples = [], $desc = [], $serveur = '', $option = true) { |
| 796 | - $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' || $option === false); |
|
| 797 | - if (!is_string($f) || !$f) { |
|
| 798 | - return false; |
|
| 799 | - } |
|
| 800 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 801 | - if ($r === false || $r === null) { |
|
| 802 | - spip_sql_erreur($serveur); |
|
| 803 | - $r = false; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - return $r; |
|
| 796 | + $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' || $option === false); |
|
| 797 | + if (!is_string($f) || !$f) { |
|
| 798 | + return false; |
|
| 799 | + } |
|
| 800 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 801 | + if ($r === false || $r === null) { |
|
| 802 | + spip_sql_erreur($serveur); |
|
| 803 | + $r = false; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + return $r; |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | /** |
@@ -843,16 +843,16 @@ discard block |
||
| 843 | 843 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 844 | 844 | */ |
| 845 | 845 | function sql_update($table, $exp, $where = '', $desc = [], $serveur = '', $option = true) { |
| 846 | - $f = sql_serveur('update', $serveur, $option === 'continue' || $option === false); |
|
| 847 | - if (!is_string($f) || !$f) { |
|
| 848 | - return false; |
|
| 849 | - } |
|
| 850 | - $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 851 | - if ($r === false) { |
|
| 852 | - spip_sql_erreur($serveur); |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - return $r; |
|
| 846 | + $f = sql_serveur('update', $serveur, $option === 'continue' || $option === false); |
|
| 847 | + if (!is_string($f) || !$f) { |
|
| 848 | + return false; |
|
| 849 | + } |
|
| 850 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 851 | + if ($r === false) { |
|
| 852 | + spip_sql_erreur($serveur); |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + return $r; |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | |
@@ -898,16 +898,16 @@ discard block |
||
| 898 | 898 | * - false en cas d'erreur. |
| 899 | 899 | **/ |
| 900 | 900 | function sql_updateq($table, $exp, $where = '', $desc = [], $serveur = '', $option = true) { |
| 901 | - $f = sql_serveur('updateq', $serveur, $option === 'continue' || $option === false); |
|
| 902 | - if (!is_string($f) || !$f) { |
|
| 903 | - return false; |
|
| 904 | - } |
|
| 905 | - $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 906 | - if ($r === false) { |
|
| 907 | - spip_sql_erreur($serveur); |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - return $r; |
|
| 901 | + $f = sql_serveur('updateq', $serveur, $option === 'continue' || $option === false); |
|
| 902 | + if (!is_string($f) || !$f) { |
|
| 903 | + return false; |
|
| 904 | + } |
|
| 905 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 906 | + if ($r === false) { |
|
| 907 | + spip_sql_erreur($serveur); |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + return $r; |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | /** |
@@ -938,16 +938,16 @@ discard block |
||
| 938 | 938 | * - false en cas d'erreur. |
| 939 | 939 | **/ |
| 940 | 940 | function sql_delete($table, $where = '', $serveur = '', $option = true) { |
| 941 | - $f = sql_serveur('delete', $serveur, $option === 'continue' || $option === false); |
|
| 942 | - if (!is_string($f) || !$f) { |
|
| 943 | - return false; |
|
| 944 | - } |
|
| 945 | - $r = $f($table, $where, $serveur, $option !== false); |
|
| 946 | - if ($r === false) { |
|
| 947 | - spip_sql_erreur($serveur); |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - return $r; |
|
| 941 | + $f = sql_serveur('delete', $serveur, $option === 'continue' || $option === false); |
|
| 942 | + if (!is_string($f) || !$f) { |
|
| 943 | + return false; |
|
| 944 | + } |
|
| 945 | + $r = $f($table, $where, $serveur, $option !== false); |
|
| 946 | + if ($r === false) { |
|
| 947 | + spip_sql_erreur($serveur); |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + return $r; |
|
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | /** |
@@ -983,16 +983,16 @@ discard block |
||
| 983 | 983 | * - false en cas d'erreur. |
| 984 | 984 | **/ |
| 985 | 985 | function sql_replace($table, $couples, $desc = [], $serveur = '', $option = true) { |
| 986 | - $f = sql_serveur('replace', $serveur, $option === 'continue' || $option === false); |
|
| 987 | - if (!is_string($f) || !$f) { |
|
| 988 | - return false; |
|
| 989 | - } |
|
| 990 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 991 | - if ($r === false) { |
|
| 992 | - spip_sql_erreur($serveur); |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - return $r; |
|
| 986 | + $f = sql_serveur('replace', $serveur, $option === 'continue' || $option === false); |
|
| 987 | + if (!is_string($f) || !$f) { |
|
| 988 | + return false; |
|
| 989 | + } |
|
| 990 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 991 | + if ($r === false) { |
|
| 992 | + spip_sql_erreur($serveur); |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + return $r; |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | |
@@ -1030,16 +1030,16 @@ discard block |
||
| 1030 | 1030 | * - false en cas d'erreur. |
| 1031 | 1031 | **/ |
| 1032 | 1032 | function sql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $option = true) { |
| 1033 | - $f = sql_serveur('replace_multi', $serveur, $option === 'continue' || $option === false); |
|
| 1034 | - if (!is_string($f) || !$f) { |
|
| 1035 | - return false; |
|
| 1036 | - } |
|
| 1037 | - $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 1038 | - if ($r === false) { |
|
| 1039 | - spip_sql_erreur($serveur); |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - return $r; |
|
| 1033 | + $f = sql_serveur('replace_multi', $serveur, $option === 'continue' || $option === false); |
|
| 1034 | + if (!is_string($f) || !$f) { |
|
| 1035 | + return false; |
|
| 1036 | + } |
|
| 1037 | + $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 1038 | + if ($r === false) { |
|
| 1039 | + spip_sql_erreur($serveur); |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + return $r; |
|
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | 1045 | /** |
@@ -1067,16 +1067,16 @@ discard block |
||
| 1067 | 1067 | * - false en cas d'erreur. |
| 1068 | 1068 | **/ |
| 1069 | 1069 | function sql_drop_table($table, $exist = '', $serveur = '', $option = true) { |
| 1070 | - $f = sql_serveur('drop_table', $serveur, $option === 'continue' || $option === false); |
|
| 1071 | - if (!is_string($f) || !$f) { |
|
| 1072 | - return false; |
|
| 1073 | - } |
|
| 1074 | - $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1075 | - if ($r === false) { |
|
| 1076 | - spip_sql_erreur($serveur); |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - return $r; |
|
| 1070 | + $f = sql_serveur('drop_table', $serveur, $option === 'continue' || $option === false); |
|
| 1071 | + if (!is_string($f) || !$f) { |
|
| 1072 | + return false; |
|
| 1073 | + } |
|
| 1074 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1075 | + if ($r === false) { |
|
| 1076 | + spip_sql_erreur($serveur); |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + return $r; |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | /** |
@@ -1100,16 +1100,16 @@ discard block |
||
| 1100 | 1100 | * - true si la requête a réussie, false sinon |
| 1101 | 1101 | */ |
| 1102 | 1102 | function sql_drop_view($table, $exist = '', $serveur = '', $option = true) { |
| 1103 | - $f = sql_serveur('drop_view', $serveur, $option === 'continue' || $option === false); |
|
| 1104 | - if (!is_string($f) || !$f) { |
|
| 1105 | - return false; |
|
| 1106 | - } |
|
| 1107 | - $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1108 | - if ($r === false) { |
|
| 1109 | - spip_sql_erreur($serveur); |
|
| 1110 | - } |
|
| 1111 | - |
|
| 1112 | - return $r; |
|
| 1103 | + $f = sql_serveur('drop_view', $serveur, $option === 'continue' || $option === false); |
|
| 1104 | + if (!is_string($f) || !$f) { |
|
| 1105 | + return false; |
|
| 1106 | + } |
|
| 1107 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1108 | + if ($r === false) { |
|
| 1109 | + spip_sql_erreur($serveur); |
|
| 1110 | + } |
|
| 1111 | + |
|
| 1112 | + return $r; |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | /** |
@@ -1133,18 +1133,18 @@ discard block |
||
| 1133 | 1133 | * Ressource à utiliser avec sql_fetch() |
| 1134 | 1134 | **/ |
| 1135 | 1135 | function sql_showbase($spip = null, $serveur = '', $option = true) { |
| 1136 | - $f = sql_serveur('showbase', $serveur, $option === 'continue' || $option === false); |
|
| 1137 | - if (!is_string($f) || !$f) { |
|
| 1138 | - return false; |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1142 | - if ($spip == null) { |
|
| 1143 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1144 | - $spip = $connexion['prefixe'] . '\_%'; |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - return $f($spip, $serveur, $option !== false); |
|
| 1136 | + $f = sql_serveur('showbase', $serveur, $option === 'continue' || $option === false); |
|
| 1137 | + if (!is_string($f) || !$f) { |
|
| 1138 | + return false; |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1142 | + if ($spip == null) { |
|
| 1143 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1144 | + $spip = $connexion['prefixe'] . '\_%'; |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + return $f($spip, $serveur, $option !== false); |
|
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | /** |
@@ -1167,15 +1167,15 @@ discard block |
||
| 1167 | 1167 | * Liste des tables SQL |
| 1168 | 1168 | **/ |
| 1169 | 1169 | function sql_alltable($spip = null, $serveur = '', $option = true) { |
| 1170 | - $q = sql_showbase($spip, $serveur, $option); |
|
| 1171 | - $r = []; |
|
| 1172 | - if ($q) { |
|
| 1173 | - while ($t = sql_fetch($q, $serveur)) { |
|
| 1174 | - $r[] = array_shift($t); |
|
| 1175 | - } |
|
| 1176 | - } |
|
| 1177 | - |
|
| 1178 | - return $r; |
|
| 1170 | + $q = sql_showbase($spip, $serveur, $option); |
|
| 1171 | + $r = []; |
|
| 1172 | + if ($q) { |
|
| 1173 | + while ($t = sql_fetch($q, $serveur)) { |
|
| 1174 | + $r[] = array_shift($t); |
|
| 1175 | + } |
|
| 1176 | + } |
|
| 1177 | + |
|
| 1178 | + return $r; |
|
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | 1181 | /** |
@@ -1208,31 +1208,31 @@ discard block |
||
| 1208 | 1208 | * - 'join' => array() // jointures, si déclarées. |
| 1209 | 1209 | **/ |
| 1210 | 1210 | function sql_showtable($table, $table_spip = false, $serveur = '', $option = true) { |
| 1211 | - $f = sql_serveur('showtable', $serveur, $option === 'continue' || $option === false); |
|
| 1212 | - if (!is_string($f) || !$f) { |
|
| 1213 | - return false; |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1217 | - if ($table_spip) { |
|
| 1218 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1219 | - $prefixe = $connexion['prefixe']; |
|
| 1220 | - $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1221 | - } else { |
|
| 1222 | - $vraie_table = $table; |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - $f = $f($vraie_table, $serveur, $option !== false); |
|
| 1226 | - if (!$f) { |
|
| 1227 | - return []; |
|
| 1228 | - } |
|
| 1229 | - if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 1230 | - $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 1231 | - } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 1232 | - $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - return $f; |
|
| 1211 | + $f = sql_serveur('showtable', $serveur, $option === 'continue' || $option === false); |
|
| 1212 | + if (!is_string($f) || !$f) { |
|
| 1213 | + return false; |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1217 | + if ($table_spip) { |
|
| 1218 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1219 | + $prefixe = $connexion['prefixe']; |
|
| 1220 | + $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1221 | + } else { |
|
| 1222 | + $vraie_table = $table; |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + $f = $f($vraie_table, $serveur, $option !== false); |
|
| 1226 | + if (!$f) { |
|
| 1227 | + return []; |
|
| 1228 | + } |
|
| 1229 | + if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 1230 | + $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 1231 | + } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 1232 | + $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + return $f; |
|
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | |
@@ -1259,21 +1259,21 @@ discard block |
||
| 1259 | 1259 | * - false en cas d'erreur. |
| 1260 | 1260 | **/ |
| 1261 | 1261 | function sql_table_exists(string $table, bool $table_spip = true, $serveur = '', $option = true) { |
| 1262 | - $f = sql_serveur('table_exists', $serveur, $option === 'continue' || $option === false); |
|
| 1263 | - if (!is_string($f) || !$f) { |
|
| 1264 | - return false; |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1268 | - if ($table_spip) { |
|
| 1269 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1270 | - $prefixe = $connexion['prefixe']; |
|
| 1271 | - $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1272 | - } else { |
|
| 1273 | - $vraie_table = $table; |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - return $f($vraie_table, $serveur, $option !== false); |
|
| 1262 | + $f = sql_serveur('table_exists', $serveur, $option === 'continue' || $option === false); |
|
| 1263 | + if (!is_string($f) || !$f) { |
|
| 1264 | + return false; |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1268 | + if ($table_spip) { |
|
| 1269 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1270 | + $prefixe = $connexion['prefixe']; |
|
| 1271 | + $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1272 | + } else { |
|
| 1273 | + $vraie_table = $table; |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + return $f($vraie_table, $serveur, $option !== false); |
|
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | 1279 | |
@@ -1319,24 +1319,24 @@ discard block |
||
| 1319 | 1319 | * true si succès, false en cas d'echec |
| 1320 | 1320 | **/ |
| 1321 | 1321 | function sql_create( |
| 1322 | - $nom, |
|
| 1323 | - $champs, |
|
| 1324 | - $cles = [], |
|
| 1325 | - $autoinc = false, |
|
| 1326 | - $temporary = false, |
|
| 1327 | - $serveur = '', |
|
| 1328 | - $option = true |
|
| 1322 | + $nom, |
|
| 1323 | + $champs, |
|
| 1324 | + $cles = [], |
|
| 1325 | + $autoinc = false, |
|
| 1326 | + $temporary = false, |
|
| 1327 | + $serveur = '', |
|
| 1328 | + $option = true |
|
| 1329 | 1329 | ) { |
| 1330 | - $f = sql_serveur('create', $serveur, $option === 'continue' || $option === false); |
|
| 1331 | - if (!is_string($f) || !$f) { |
|
| 1332 | - return false; |
|
| 1333 | - } |
|
| 1334 | - $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 1335 | - if ($r === false) { |
|
| 1336 | - spip_sql_erreur($serveur); |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - return $r; |
|
| 1330 | + $f = sql_serveur('create', $serveur, $option === 'continue' || $option === false); |
|
| 1331 | + if (!is_string($f) || !$f) { |
|
| 1332 | + return false; |
|
| 1333 | + } |
|
| 1334 | + $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 1335 | + if ($r === false) { |
|
| 1336 | + spip_sql_erreur($serveur); |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + return $r; |
|
| 1340 | 1340 | } |
| 1341 | 1341 | |
| 1342 | 1342 | /** |
@@ -1354,16 +1354,16 @@ discard block |
||
| 1354 | 1354 | * @return bool true si la base est créee. |
| 1355 | 1355 | **/ |
| 1356 | 1356 | function sql_create_base($nom, $serveur = '', $option = true) { |
| 1357 | - $f = sql_serveur('create_base', $serveur, $option === 'continue' || $option === false); |
|
| 1358 | - if (!is_string($f) || !$f) { |
|
| 1359 | - return false; |
|
| 1360 | - } |
|
| 1361 | - $r = $f($nom, $serveur, $option !== false); |
|
| 1362 | - if ($r === false) { |
|
| 1363 | - spip_sql_erreur($serveur); |
|
| 1364 | - } |
|
| 1365 | - |
|
| 1366 | - return $r; |
|
| 1357 | + $f = sql_serveur('create_base', $serveur, $option === 'continue' || $option === false); |
|
| 1358 | + if (!is_string($f) || !$f) { |
|
| 1359 | + return false; |
|
| 1360 | + } |
|
| 1361 | + $r = $f($nom, $serveur, $option !== false); |
|
| 1362 | + if ($r === false) { |
|
| 1363 | + spip_sql_erreur($serveur); |
|
| 1364 | + } |
|
| 1365 | + |
|
| 1366 | + return $r; |
|
| 1367 | 1367 | } |
| 1368 | 1368 | |
| 1369 | 1369 | |
@@ -1393,16 +1393,16 @@ discard block |
||
| 1393 | 1393 | * - false en cas d'échec. |
| 1394 | 1394 | **/ |
| 1395 | 1395 | function sql_create_view($nom, $select_query, $serveur = '', $option = true) { |
| 1396 | - $f = sql_serveur('create_view', $serveur, $option === 'continue' || $option === false); |
|
| 1397 | - if (!is_string($f) || !$f) { |
|
| 1398 | - return false; |
|
| 1399 | - } |
|
| 1400 | - $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 1401 | - if ($r === false) { |
|
| 1402 | - spip_sql_erreur($serveur); |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - return $r; |
|
| 1396 | + $f = sql_serveur('create_view', $serveur, $option === 'continue' || $option === false); |
|
| 1397 | + if (!is_string($f) || !$f) { |
|
| 1398 | + return false; |
|
| 1399 | + } |
|
| 1400 | + $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 1401 | + if ($r === false) { |
|
| 1402 | + spip_sql_erreur($serveur); |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + return $r; |
|
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | 1408 | /** |
@@ -1431,12 +1431,12 @@ discard block |
||
| 1431 | 1431 | * texte de sélection pour la requête |
| 1432 | 1432 | */ |
| 1433 | 1433 | function sql_multi($sel, $lang, $serveur = '', $option = true) { |
| 1434 | - $f = sql_serveur('multi', $serveur, $option === 'continue' || $option === false); |
|
| 1435 | - if (!is_string($f) || !$f) { |
|
| 1436 | - return false; |
|
| 1437 | - } |
|
| 1434 | + $f = sql_serveur('multi', $serveur, $option === 'continue' || $option === false); |
|
| 1435 | + if (!is_string($f) || !$f) { |
|
| 1436 | + return false; |
|
| 1437 | + } |
|
| 1438 | 1438 | |
| 1439 | - return $f($sel, $lang); |
|
| 1439 | + return $f($sel, $lang); |
|
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | 1442 | |
@@ -1451,12 +1451,12 @@ discard block |
||
| 1451 | 1451 | * False si le serveur est indisponible |
| 1452 | 1452 | */ |
| 1453 | 1453 | function sql_error($serveur = '') { |
| 1454 | - $f = sql_serveur('error', $serveur, true); |
|
| 1455 | - if (!is_string($f) || !$f) { |
|
| 1456 | - return false; |
|
| 1457 | - } |
|
| 1454 | + $f = sql_serveur('error', $serveur, true); |
|
| 1455 | + if (!is_string($f) || !$f) { |
|
| 1456 | + return false; |
|
| 1457 | + } |
|
| 1458 | 1458 | |
| 1459 | - return $f('query inconnue', $serveur); |
|
| 1459 | + return $f('query inconnue', $serveur); |
|
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | 1462 | /** |
@@ -1470,12 +1470,12 @@ discard block |
||
| 1470 | 1470 | * False si le serveur est indisponible |
| 1471 | 1471 | */ |
| 1472 | 1472 | function sql_errno($serveur = '') { |
| 1473 | - $f = sql_serveur('errno', $serveur, true); |
|
| 1474 | - if (!is_string($f) || !$f) { |
|
| 1475 | - return false; |
|
| 1476 | - } |
|
| 1473 | + $f = sql_serveur('errno', $serveur, true); |
|
| 1474 | + if (!is_string($f) || !$f) { |
|
| 1475 | + return false; |
|
| 1476 | + } |
|
| 1477 | 1477 | |
| 1478 | - return $f($serveur); |
|
| 1478 | + return $f($serveur); |
|
| 1479 | 1479 | } |
| 1480 | 1480 | |
| 1481 | 1481 | /** |
@@ -1493,16 +1493,16 @@ discard block |
||
| 1493 | 1493 | * @return array|false Tableau de l'explication |
| 1494 | 1494 | */ |
| 1495 | 1495 | function sql_explain($q, $serveur = '', $option = true) { |
| 1496 | - $f = sql_serveur('explain', $serveur, true); |
|
| 1497 | - if (!is_string($f) || !$f) { |
|
| 1498 | - return false; |
|
| 1499 | - } |
|
| 1500 | - $r = $f($q, $serveur, $option !== false); |
|
| 1501 | - if ($r === false) { |
|
| 1502 | - spip_sql_erreur($serveur); |
|
| 1503 | - } |
|
| 1504 | - |
|
| 1505 | - return $r; |
|
| 1496 | + $f = sql_serveur('explain', $serveur, true); |
|
| 1497 | + if (!is_string($f) || !$f) { |
|
| 1498 | + return false; |
|
| 1499 | + } |
|
| 1500 | + $r = $f($q, $serveur, $option !== false); |
|
| 1501 | + if ($r === false) { |
|
| 1502 | + spip_sql_erreur($serveur); |
|
| 1503 | + } |
|
| 1504 | + |
|
| 1505 | + return $r; |
|
| 1506 | 1506 | } |
| 1507 | 1507 | |
| 1508 | 1508 | /** |
@@ -1520,16 +1520,16 @@ discard block |
||
| 1520 | 1520 | * @return bool Toujours true |
| 1521 | 1521 | */ |
| 1522 | 1522 | function sql_optimize($table, $serveur = '', $option = true) { |
| 1523 | - $f = sql_serveur('optimize', $serveur, $option === 'continue' || $option === false); |
|
| 1524 | - if (!is_string($f) || !$f) { |
|
| 1525 | - return false; |
|
| 1526 | - } |
|
| 1527 | - $r = $f($table, $serveur, $option); |
|
| 1528 | - if ($r === false) { |
|
| 1529 | - spip_sql_erreur($serveur); |
|
| 1530 | - } |
|
| 1531 | - |
|
| 1532 | - return $r; |
|
| 1523 | + $f = sql_serveur('optimize', $serveur, $option === 'continue' || $option === false); |
|
| 1524 | + if (!is_string($f) || !$f) { |
|
| 1525 | + return false; |
|
| 1526 | + } |
|
| 1527 | + $r = $f($table, $serveur, $option); |
|
| 1528 | + if ($r === false) { |
|
| 1529 | + spip_sql_erreur($serveur); |
|
| 1530 | + } |
|
| 1531 | + |
|
| 1532 | + return $r; |
|
| 1533 | 1533 | } |
| 1534 | 1534 | |
| 1535 | 1535 | /** |
@@ -1549,16 +1549,16 @@ discard block |
||
| 1549 | 1549 | * - true si la requête a réussie, false sinon |
| 1550 | 1550 | */ |
| 1551 | 1551 | function sql_repair($table, $serveur = '', $option = true) { |
| 1552 | - $f = sql_serveur('repair', $serveur, $option === 'continue' || $option === false); |
|
| 1553 | - if (!is_string($f) || !$f) { |
|
| 1554 | - return false; |
|
| 1555 | - } |
|
| 1556 | - $r = $f($table, $serveur, $option !== false); |
|
| 1557 | - if ($r === false) { |
|
| 1558 | - spip_sql_erreur($serveur); |
|
| 1559 | - } |
|
| 1560 | - |
|
| 1561 | - return $r; |
|
| 1552 | + $f = sql_serveur('repair', $serveur, $option === 'continue' || $option === false); |
|
| 1553 | + if (!is_string($f) || !$f) { |
|
| 1554 | + return false; |
|
| 1555 | + } |
|
| 1556 | + $r = $f($table, $serveur, $option !== false); |
|
| 1557 | + if ($r === false) { |
|
| 1558 | + spip_sql_erreur($serveur); |
|
| 1559 | + } |
|
| 1560 | + |
|
| 1561 | + return $r; |
|
| 1562 | 1562 | } |
| 1563 | 1563 | |
| 1564 | 1564 | |
@@ -1583,16 +1583,16 @@ discard block |
||
| 1583 | 1583 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 1584 | 1584 | */ |
| 1585 | 1585 | function sql_query($ins, $serveur = '', $option = true) { |
| 1586 | - $f = sql_serveur('query', $serveur, $option === 'continue' || $option === false); |
|
| 1587 | - if (!is_string($f) || !$f) { |
|
| 1588 | - return false; |
|
| 1589 | - } |
|
| 1590 | - $r = $f($ins, $serveur, $option !== false); |
|
| 1591 | - if ($r === false) { |
|
| 1592 | - spip_sql_erreur($serveur); |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - return $r; |
|
| 1586 | + $f = sql_serveur('query', $serveur, $option === 'continue' || $option === false); |
|
| 1587 | + if (!is_string($f) || !$f) { |
|
| 1588 | + return false; |
|
| 1589 | + } |
|
| 1590 | + $r = $f($ins, $serveur, $option !== false); |
|
| 1591 | + if ($r === false) { |
|
| 1592 | + spip_sql_erreur($serveur); |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + return $r; |
|
| 1596 | 1596 | } |
| 1597 | 1597 | |
| 1598 | 1598 | /** |
@@ -1640,27 +1640,27 @@ discard block |
||
| 1640 | 1640 | * |
| 1641 | 1641 | **/ |
| 1642 | 1642 | function sql_fetsel( |
| 1643 | - $select = [], |
|
| 1644 | - $from = [], |
|
| 1645 | - $where = [], |
|
| 1646 | - $groupby = [], |
|
| 1647 | - $orderby = [], |
|
| 1648 | - $limit = '', |
|
| 1649 | - $having = [], |
|
| 1650 | - $serveur = '', |
|
| 1651 | - $option = true |
|
| 1643 | + $select = [], |
|
| 1644 | + $from = [], |
|
| 1645 | + $where = [], |
|
| 1646 | + $groupby = [], |
|
| 1647 | + $orderby = [], |
|
| 1648 | + $limit = '', |
|
| 1649 | + $having = [], |
|
| 1650 | + $serveur = '', |
|
| 1651 | + $option = true |
|
| 1652 | 1652 | ) { |
| 1653 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1654 | - if ($option === false) { |
|
| 1655 | - return $q; |
|
| 1656 | - } |
|
| 1657 | - if (!$q) { |
|
| 1658 | - return []; |
|
| 1659 | - } |
|
| 1660 | - $r = sql_fetch($q, $serveur, $option); |
|
| 1661 | - sql_free($q, $serveur, $option); |
|
| 1662 | - |
|
| 1663 | - return $r; |
|
| 1653 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1654 | + if ($option === false) { |
|
| 1655 | + return $q; |
|
| 1656 | + } |
|
| 1657 | + if (!$q) { |
|
| 1658 | + return []; |
|
| 1659 | + } |
|
| 1660 | + $r = sql_fetch($q, $serveur, $option); |
|
| 1661 | + sql_free($q, $serveur, $option); |
|
| 1662 | + |
|
| 1663 | + return $r; |
|
| 1664 | 1664 | } |
| 1665 | 1665 | |
| 1666 | 1666 | |
@@ -1717,22 +1717,22 @@ discard block |
||
| 1717 | 1717 | * |
| 1718 | 1718 | **/ |
| 1719 | 1719 | function sql_allfetsel( |
| 1720 | - $select = [], |
|
| 1721 | - $from = [], |
|
| 1722 | - $where = [], |
|
| 1723 | - $groupby = [], |
|
| 1724 | - $orderby = [], |
|
| 1725 | - $limit = '', |
|
| 1726 | - $having = [], |
|
| 1727 | - $serveur = '', |
|
| 1728 | - $option = true |
|
| 1720 | + $select = [], |
|
| 1721 | + $from = [], |
|
| 1722 | + $where = [], |
|
| 1723 | + $groupby = [], |
|
| 1724 | + $orderby = [], |
|
| 1725 | + $limit = '', |
|
| 1726 | + $having = [], |
|
| 1727 | + $serveur = '', |
|
| 1728 | + $option = true |
|
| 1729 | 1729 | ) { |
| 1730 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1731 | - if ($option === false) { |
|
| 1732 | - return $q; |
|
| 1733 | - } |
|
| 1730 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1731 | + if ($option === false) { |
|
| 1732 | + return $q; |
|
| 1733 | + } |
|
| 1734 | 1734 | |
| 1735 | - return sql_fetch_all($q, $serveur, $option); |
|
| 1735 | + return sql_fetch_all($q, $serveur, $option); |
|
| 1736 | 1736 | } |
| 1737 | 1737 | |
| 1738 | 1738 | |
@@ -1779,33 +1779,33 @@ discard block |
||
| 1779 | 1779 | * |
| 1780 | 1780 | **/ |
| 1781 | 1781 | function sql_getfetsel( |
| 1782 | - $select, |
|
| 1783 | - $from = [], |
|
| 1784 | - $where = [], |
|
| 1785 | - $groupby = [], |
|
| 1786 | - $orderby = [], |
|
| 1787 | - $limit = '', |
|
| 1788 | - $having = [], |
|
| 1789 | - $serveur = '', |
|
| 1790 | - $option = true |
|
| 1782 | + $select, |
|
| 1783 | + $from = [], |
|
| 1784 | + $where = [], |
|
| 1785 | + $groupby = [], |
|
| 1786 | + $orderby = [], |
|
| 1787 | + $limit = '', |
|
| 1788 | + $having = [], |
|
| 1789 | + $serveur = '', |
|
| 1790 | + $option = true |
|
| 1791 | 1791 | ) { |
| 1792 | - if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1793 | - $id = $c[1]; |
|
| 1794 | - } elseif (!preg_match('/\W/', $select)) { |
|
| 1795 | - $id = $select; |
|
| 1796 | - } else { |
|
| 1797 | - $id = 'n'; |
|
| 1798 | - $select .= ' AS n'; |
|
| 1799 | - } |
|
| 1800 | - $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1801 | - if ($option === false) { |
|
| 1802 | - return $r; |
|
| 1803 | - } |
|
| 1804 | - if (!$r) { |
|
| 1805 | - return null; |
|
| 1806 | - } |
|
| 1807 | - |
|
| 1808 | - return $r[$id]; |
|
| 1792 | + if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1793 | + $id = $c[1]; |
|
| 1794 | + } elseif (!preg_match('/\W/', $select)) { |
|
| 1795 | + $id = $select; |
|
| 1796 | + } else { |
|
| 1797 | + $id = 'n'; |
|
| 1798 | + $select .= ' AS n'; |
|
| 1799 | + } |
|
| 1800 | + $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1801 | + if ($option === false) { |
|
| 1802 | + return $r; |
|
| 1803 | + } |
|
| 1804 | + if (!$r) { |
|
| 1805 | + return null; |
|
| 1806 | + } |
|
| 1807 | + |
|
| 1808 | + return $r[$id]; |
|
| 1809 | 1809 | } |
| 1810 | 1810 | |
| 1811 | 1811 | /** |
@@ -1823,9 +1823,9 @@ discard block |
||
| 1823 | 1823 | * Numero de version du serveur SQL |
| 1824 | 1824 | **/ |
| 1825 | 1825 | function sql_version($serveur = '', $option = true) { |
| 1826 | - $row = sql_fetsel('version() AS n', '', '', '', '', '', '', $serveur); |
|
| 1826 | + $row = sql_fetsel('version() AS n', '', '', '', '', '', '', $serveur); |
|
| 1827 | 1827 | |
| 1828 | - return ($row['n']); |
|
| 1828 | + return ($row['n']); |
|
| 1829 | 1829 | } |
| 1830 | 1830 | |
| 1831 | 1831 | /** |
@@ -1861,16 +1861,16 @@ discard block |
||
| 1861 | 1861 | * Le serveur SQL prefere t'il des transactions pour les insertions multiples ? |
| 1862 | 1862 | **/ |
| 1863 | 1863 | function sql_preferer_transaction($serveur = '', $option = true) { |
| 1864 | - $f = sql_serveur('preferer_transaction', $serveur, true); |
|
| 1865 | - if (!is_string($f) || !$f) { |
|
| 1866 | - return false; |
|
| 1867 | - } |
|
| 1868 | - $r = $f($serveur, $option !== false); |
|
| 1869 | - if ($r === false) { |
|
| 1870 | - spip_sql_erreur($serveur); |
|
| 1871 | - } |
|
| 1872 | - |
|
| 1873 | - return $r; |
|
| 1864 | + $f = sql_serveur('preferer_transaction', $serveur, true); |
|
| 1865 | + if (!is_string($f) || !$f) { |
|
| 1866 | + return false; |
|
| 1867 | + } |
|
| 1868 | + $r = $f($serveur, $option !== false); |
|
| 1869 | + if ($r === false) { |
|
| 1870 | + spip_sql_erreur($serveur); |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + return $r; |
|
| 1874 | 1874 | } |
| 1875 | 1875 | |
| 1876 | 1876 | ; |
@@ -1895,16 +1895,16 @@ discard block |
||
| 1895 | 1895 | * false en cas d'erreur |
| 1896 | 1896 | **/ |
| 1897 | 1897 | function sql_demarrer_transaction($serveur = '', $option = true) { |
| 1898 | - $f = sql_serveur('demarrer_transaction', $serveur, true); |
|
| 1899 | - if (!is_string($f) || !$f) { |
|
| 1900 | - return false; |
|
| 1901 | - } |
|
| 1902 | - $r = $f($serveur, $option !== false); |
|
| 1903 | - if ($r === false) { |
|
| 1904 | - spip_sql_erreur($serveur); |
|
| 1905 | - } |
|
| 1906 | - |
|
| 1907 | - return $r; |
|
| 1898 | + $f = sql_serveur('demarrer_transaction', $serveur, true); |
|
| 1899 | + if (!is_string($f) || !$f) { |
|
| 1900 | + return false; |
|
| 1901 | + } |
|
| 1902 | + $r = $f($serveur, $option !== false); |
|
| 1903 | + if ($r === false) { |
|
| 1904 | + spip_sql_erreur($serveur); |
|
| 1905 | + } |
|
| 1906 | + |
|
| 1907 | + return $r; |
|
| 1908 | 1908 | } |
| 1909 | 1909 | |
| 1910 | 1910 | ; |
@@ -1929,16 +1929,16 @@ discard block |
||
| 1929 | 1929 | * false en cas d'erreur |
| 1930 | 1930 | **/ |
| 1931 | 1931 | function sql_terminer_transaction($serveur = '', $option = true) { |
| 1932 | - $f = sql_serveur('terminer_transaction', $serveur, true); |
|
| 1933 | - if (!is_string($f) || !$f) { |
|
| 1934 | - return false; |
|
| 1935 | - } |
|
| 1936 | - $r = $f($serveur, $option !== false); |
|
| 1937 | - if ($r === false) { |
|
| 1938 | - spip_sql_erreur($serveur); |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - return $r; |
|
| 1932 | + $f = sql_serveur('terminer_transaction', $serveur, true); |
|
| 1933 | + if (!is_string($f) || !$f) { |
|
| 1934 | + return false; |
|
| 1935 | + } |
|
| 1936 | + $r = $f($serveur, $option !== false); |
|
| 1937 | + if ($r === false) { |
|
| 1938 | + spip_sql_erreur($serveur); |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + return $r; |
|
| 1942 | 1942 | } |
| 1943 | 1943 | |
| 1944 | 1944 | ; |
@@ -1965,12 +1965,12 @@ discard block |
||
| 1965 | 1965 | * Valeur hexadécimale attendue par le serveur SQL |
| 1966 | 1966 | **/ |
| 1967 | 1967 | function sql_hex($val, $serveur = '', $option = true) { |
| 1968 | - $f = sql_serveur('hex', $serveur, $option === 'continue' || $option === false); |
|
| 1969 | - if (!is_string($f) || !$f) { |
|
| 1970 | - return false; |
|
| 1971 | - } |
|
| 1968 | + $f = sql_serveur('hex', $serveur, $option === 'continue' || $option === false); |
|
| 1969 | + if (!is_string($f) || !$f) { |
|
| 1970 | + return false; |
|
| 1971 | + } |
|
| 1972 | 1972 | |
| 1973 | - return $f($val); |
|
| 1973 | + return $f($val); |
|
| 1974 | 1974 | } |
| 1975 | 1975 | |
| 1976 | 1976 | /** |
@@ -1996,12 +1996,12 @@ discard block |
||
| 1996 | 1996 | * La chaine echappee |
| 1997 | 1997 | **/ |
| 1998 | 1998 | function sql_quote($val, $serveur = '', $type = '') { |
| 1999 | - $f = sql_serveur('quote', $serveur, true); |
|
| 2000 | - if (!is_string($f) || !$f) { |
|
| 2001 | - $f = '_q'; |
|
| 2002 | - } |
|
| 1999 | + $f = sql_serveur('quote', $serveur, true); |
|
| 2000 | + if (!is_string($f) || !$f) { |
|
| 2001 | + $f = '_q'; |
|
| 2002 | + } |
|
| 2003 | 2003 | |
| 2004 | - return $f($val, $type); |
|
| 2004 | + return $f($val, $type); |
|
| 2005 | 2005 | } |
| 2006 | 2006 | |
| 2007 | 2007 | /** |
@@ -2026,12 +2026,12 @@ discard block |
||
| 2026 | 2026 | * - false si le serveur SQL est indisponible |
| 2027 | 2027 | **/ |
| 2028 | 2028 | function sql_date_proche($champ, $interval, $unite, $serveur = '', $option = true) { |
| 2029 | - $f = sql_serveur('date_proche', $serveur, true); |
|
| 2030 | - if (!is_string($f) || !$f) { |
|
| 2031 | - return false; |
|
| 2032 | - } |
|
| 2029 | + $f = sql_serveur('date_proche', $serveur, true); |
|
| 2030 | + if (!is_string($f) || !$f) { |
|
| 2031 | + return false; |
|
| 2032 | + } |
|
| 2033 | 2033 | |
| 2034 | - return $f($champ, $interval, $unite); |
|
| 2034 | + return $f($champ, $interval, $unite); |
|
| 2035 | 2035 | } |
| 2036 | 2036 | |
| 2037 | 2037 | /** |
@@ -2067,26 +2067,26 @@ discard block |
||
| 2067 | 2067 | * Expression de requête SQL |
| 2068 | 2068 | **/ |
| 2069 | 2069 | function sql_in_quote($champ, $valeurs, $not = '', $serveur = '', $type = '', $option = true) { |
| 2070 | - $quote = sql_serveur('quote', $serveur, true); |
|
| 2071 | - if (!is_string($quote) || !$quote) { |
|
| 2072 | - return false; |
|
| 2073 | - } |
|
| 2074 | - |
|
| 2075 | - // sql_quote produit une chaine dans tous les cas |
|
| 2076 | - $valeurs = array_filter($valeurs, fn($v) => !is_array($v)); |
|
| 2077 | - $valeurs = array_unique($valeurs); |
|
| 2078 | - $valeurs = $quote($valeurs, $type); |
|
| 2079 | - |
|
| 2080 | - if (!strlen(trim((string) $valeurs))) { |
|
| 2081 | - return ($not ? '0=0' : '0=1'); |
|
| 2082 | - } |
|
| 2083 | - |
|
| 2084 | - $f = sql_serveur('in', $serveur, $option === 'continue' || $option === false); |
|
| 2085 | - if (!is_string($f) || !$f) { |
|
| 2086 | - return false; |
|
| 2087 | - } |
|
| 2088 | - |
|
| 2089 | - return $f($champ, $valeurs, $not ? 'NOT' : '', $serveur, $option !== false); |
|
| 2070 | + $quote = sql_serveur('quote', $serveur, true); |
|
| 2071 | + if (!is_string($quote) || !$quote) { |
|
| 2072 | + return false; |
|
| 2073 | + } |
|
| 2074 | + |
|
| 2075 | + // sql_quote produit une chaine dans tous les cas |
|
| 2076 | + $valeurs = array_filter($valeurs, fn($v) => !is_array($v)); |
|
| 2077 | + $valeurs = array_unique($valeurs); |
|
| 2078 | + $valeurs = $quote($valeurs, $type); |
|
| 2079 | + |
|
| 2080 | + if (!strlen(trim((string) $valeurs))) { |
|
| 2081 | + return ($not ? '0=0' : '0=1'); |
|
| 2082 | + } |
|
| 2083 | + |
|
| 2084 | + $f = sql_serveur('in', $serveur, $option === 'continue' || $option === false); |
|
| 2085 | + if (!is_string($f) || !$f) { |
|
| 2086 | + return false; |
|
| 2087 | + } |
|
| 2088 | + |
|
| 2089 | + return $f($champ, $valeurs, $not ? 'NOT' : '', $serveur, $option !== false); |
|
| 2090 | 2090 | } |
| 2091 | 2091 | |
| 2092 | 2092 | /** |
@@ -2103,19 +2103,19 @@ discard block |
||
| 2103 | 2103 | * @param bool $option |
| 2104 | 2104 | */ |
| 2105 | 2105 | function sql_in($champ, $valeurs, $not = '', $serveur = '', $option = true) { |
| 2106 | - $type = ''; |
|
| 2107 | - if (!is_array($valeurs)) { |
|
| 2108 | - $valeurs = (string) $valeurs; |
|
| 2109 | - if (isset($valeurs[0]) && $valeurs[0] === ',') { |
|
| 2110 | - $valeurs = substr($valeurs, 1); |
|
| 2111 | - } |
|
| 2112 | - // on explode en tableau pour pouvoir securiser le contenu |
|
| 2113 | - $valeurs = explode(',', $valeurs); |
|
| 2114 | - // et on force un cast de type int donc |
|
| 2115 | - $type = 'int'; |
|
| 2116 | - } |
|
| 2117 | - |
|
| 2118 | - return sql_in_quote($champ, $valeurs, $not, $serveur, $type, $option); |
|
| 2106 | + $type = ''; |
|
| 2107 | + if (!is_array($valeurs)) { |
|
| 2108 | + $valeurs = (string) $valeurs; |
|
| 2109 | + if (isset($valeurs[0]) && $valeurs[0] === ',') { |
|
| 2110 | + $valeurs = substr($valeurs, 1); |
|
| 2111 | + } |
|
| 2112 | + // on explode en tableau pour pouvoir securiser le contenu |
|
| 2113 | + $valeurs = explode(',', $valeurs); |
|
| 2114 | + // et on force un cast de type int donc |
|
| 2115 | + $type = 'int'; |
|
| 2116 | + } |
|
| 2117 | + |
|
| 2118 | + return sql_in_quote($champ, $valeurs, $not, $serveur, $type, $option); |
|
| 2119 | 2119 | } |
| 2120 | 2120 | |
| 2121 | 2121 | |
@@ -2156,24 +2156,24 @@ discard block |
||
| 2156 | 2156 | * Expression de requête SQL |
| 2157 | 2157 | **/ |
| 2158 | 2158 | function sql_in_select( |
| 2159 | - $in, |
|
| 2160 | - $select, |
|
| 2161 | - $from = [], |
|
| 2162 | - $where = [], |
|
| 2163 | - $groupby = [], |
|
| 2164 | - $orderby = [], |
|
| 2165 | - $limit = '', |
|
| 2166 | - $having = [], |
|
| 2167 | - $serveur = '' |
|
| 2159 | + $in, |
|
| 2160 | + $select, |
|
| 2161 | + $from = [], |
|
| 2162 | + $where = [], |
|
| 2163 | + $groupby = [], |
|
| 2164 | + $orderby = [], |
|
| 2165 | + $limit = '', |
|
| 2166 | + $having = [], |
|
| 2167 | + $serveur = '' |
|
| 2168 | 2168 | ) { |
| 2169 | - $liste = []; |
|
| 2170 | - $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 2171 | - while ($r = sql_fetch($res)) { |
|
| 2172 | - $liste[] = array_shift($r); |
|
| 2173 | - } |
|
| 2174 | - sql_free($res); |
|
| 2175 | - |
|
| 2176 | - return sql_in($in, $liste); |
|
| 2169 | + $liste = []; |
|
| 2170 | + $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 2171 | + while ($r = sql_fetch($res)) { |
|
| 2172 | + $liste[] = array_shift($r); |
|
| 2173 | + } |
|
| 2174 | + sql_free($res); |
|
| 2175 | + |
|
| 2176 | + return sql_in($in, $liste); |
|
| 2177 | 2177 | } |
| 2178 | 2178 | |
| 2179 | 2179 | /** |
@@ -2205,29 +2205,29 @@ discard block |
||
| 2205 | 2205 | * Position apres le saut. |
| 2206 | 2206 | */ |
| 2207 | 2207 | function sql_skip($res, $pos, $saut, $count, $serveur = '', $option = true) { |
| 2208 | - // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 2209 | - if (($saut = (int) $saut) <= 0) { |
|
| 2210 | - return $pos; |
|
| 2211 | - } |
|
| 2212 | - |
|
| 2213 | - $seek = $pos + $saut; |
|
| 2214 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 2215 | - // et on sort |
|
| 2216 | - if ($seek >= $count) { |
|
| 2217 | - sql_free($res, $serveur, $option); |
|
| 2218 | - |
|
| 2219 | - return $count; |
|
| 2220 | - } |
|
| 2221 | - |
|
| 2222 | - if (sql_seek($res, $seek)) { |
|
| 2223 | - $pos = $seek; |
|
| 2224 | - } else { |
|
| 2225 | - while ($pos < $seek && sql_fetch($res, $serveur, $option)) { |
|
| 2226 | - $pos++; |
|
| 2227 | - } |
|
| 2228 | - } |
|
| 2229 | - |
|
| 2230 | - return $pos; |
|
| 2208 | + // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 2209 | + if (($saut = (int) $saut) <= 0) { |
|
| 2210 | + return $pos; |
|
| 2211 | + } |
|
| 2212 | + |
|
| 2213 | + $seek = $pos + $saut; |
|
| 2214 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 2215 | + // et on sort |
|
| 2216 | + if ($seek >= $count) { |
|
| 2217 | + sql_free($res, $serveur, $option); |
|
| 2218 | + |
|
| 2219 | + return $count; |
|
| 2220 | + } |
|
| 2221 | + |
|
| 2222 | + if (sql_seek($res, $seek)) { |
|
| 2223 | + $pos = $seek; |
|
| 2224 | + } else { |
|
| 2225 | + while ($pos < $seek && sql_fetch($res, $serveur, $option)) { |
|
| 2226 | + $pos++; |
|
| 2227 | + } |
|
| 2228 | + } |
|
| 2229 | + |
|
| 2230 | + return $pos; |
|
| 2231 | 2231 | } |
| 2232 | 2232 | |
| 2233 | 2233 | |
@@ -2247,7 +2247,7 @@ discard block |
||
| 2247 | 2247 | * True si le champ est de type entier |
| 2248 | 2248 | */ |
| 2249 | 2249 | function sql_test_int($type, $serveur = '', $option = true) { |
| 2250 | - return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 2250 | + return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 2251 | 2251 | } |
| 2252 | 2252 | |
| 2253 | 2253 | /** |
@@ -2266,7 +2266,7 @@ discard block |
||
| 2266 | 2266 | * True si le champ est de type entier |
| 2267 | 2267 | */ |
| 2268 | 2268 | function sql_test_date($type, $serveur = '', $option = true) { |
| 2269 | - return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 2269 | + return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 2270 | 2270 | } |
| 2271 | 2271 | |
| 2272 | 2272 | /** |
@@ -2288,19 +2288,19 @@ discard block |
||
| 2288 | 2288 | * La date formatee |
| 2289 | 2289 | */ |
| 2290 | 2290 | function sql_format_date($annee = 0, $mois = 0, $jour = 0, $h = 0, $m = 0, $s = 0, $serveur = '') { |
| 2291 | - $annee = sprintf('%04s', $annee); |
|
| 2292 | - $mois = sprintf('%02s', $mois); |
|
| 2293 | - |
|
| 2294 | - if ($annee == '0000') { |
|
| 2295 | - $mois = 0; |
|
| 2296 | - } |
|
| 2297 | - if ($mois == '00') { |
|
| 2298 | - $jour = 0; |
|
| 2299 | - } |
|
| 2300 | - |
|
| 2301 | - return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2302 | - . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2303 | - . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2291 | + $annee = sprintf('%04s', $annee); |
|
| 2292 | + $mois = sprintf('%02s', $mois); |
|
| 2293 | + |
|
| 2294 | + if ($annee == '0000') { |
|
| 2295 | + $mois = 0; |
|
| 2296 | + } |
|
| 2297 | + if ($mois == '00') { |
|
| 2298 | + $jour = 0; |
|
| 2299 | + } |
|
| 2300 | + |
|
| 2301 | + return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2302 | + . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2303 | + . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2304 | 2304 | } |
| 2305 | 2305 | |
| 2306 | 2306 | |
@@ -2323,32 +2323,32 @@ discard block |
||
| 2323 | 2323 | **/ |
| 2324 | 2324 | function description_table($nom, $serveur = '') { |
| 2325 | 2325 | |
| 2326 | - static $trouver_table; |
|
| 2326 | + static $trouver_table; |
|
| 2327 | 2327 | |
| 2328 | - /* toujours utiliser trouver_table |
|
| 2328 | + /* toujours utiliser trouver_table |
|
| 2329 | 2329 | qui renverra la description theorique |
| 2330 | 2330 | car sinon on va se comporter differement selon que la table est declaree |
| 2331 | 2331 | ou non |
| 2332 | 2332 | */ |
| 2333 | - if (!$trouver_table) { |
|
| 2334 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2335 | - } |
|
| 2336 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 2337 | - return $desc; |
|
| 2338 | - } |
|
| 2339 | - |
|
| 2340 | - // sauf a l'installation : |
|
| 2341 | - include_spip('base/serial'); |
|
| 2342 | - if (isset($GLOBALS['tables_principales'][$nom])) { |
|
| 2343 | - return $GLOBALS['tables_principales'][$nom]; |
|
| 2344 | - } |
|
| 2345 | - |
|
| 2346 | - include_spip('base/auxiliaires'); |
|
| 2347 | - if (isset($GLOBALS['tables_auxiliaires'][$nom])) { |
|
| 2348 | - return $GLOBALS['tables_auxiliaires'][$nom]; |
|
| 2349 | - } |
|
| 2350 | - |
|
| 2351 | - return false; |
|
| 2333 | + if (!$trouver_table) { |
|
| 2334 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2335 | + } |
|
| 2336 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 2337 | + return $desc; |
|
| 2338 | + } |
|
| 2339 | + |
|
| 2340 | + // sauf a l'installation : |
|
| 2341 | + include_spip('base/serial'); |
|
| 2342 | + if (isset($GLOBALS['tables_principales'][$nom])) { |
|
| 2343 | + return $GLOBALS['tables_principales'][$nom]; |
|
| 2344 | + } |
|
| 2345 | + |
|
| 2346 | + include_spip('base/auxiliaires'); |
|
| 2347 | + if (isset($GLOBALS['tables_auxiliaires'][$nom])) { |
|
| 2348 | + return $GLOBALS['tables_auxiliaires'][$nom]; |
|
| 2349 | + } |
|
| 2350 | + |
|
| 2351 | + return false; |
|
| 2352 | 2352 | } |
| 2353 | 2353 | |
| 2354 | 2354 | /** |
@@ -2361,8 +2361,8 @@ discard block |
||
| 2361 | 2361 | * @return string Table sql éventuellement renommée |
| 2362 | 2362 | */ |
| 2363 | 2363 | function prefixer_table_spip($table, $prefixe) { |
| 2364 | - if ($prefixe) { |
|
| 2365 | - $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2366 | - } |
|
| 2367 | - return $table; |
|
| 2364 | + if ($prefixe) { |
|
| 2365 | + $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2366 | + } |
|
| 2367 | + return $table; |
|
| 2368 | 2368 | } |
@@ -52,17 +52,17 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | if ($compil_info) { |
| 54 | 54 | return [ |
| 55 | - $trace[0]['file'],// sourcefile |
|
| 55 | + $trace[0]['file'], // sourcefile |
|
| 56 | 56 | '', //nom |
| 57 | - (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 58 | - . $trace[0]['function'] . '();' |
|
| 57 | + (isset($trace[1]) ? $trace[1]['function']."(){\n" : '') |
|
| 58 | + . $trace[0]['function'].'();' |
|
| 59 | 59 | . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
| 60 | 60 | $trace[0]['line'], // ligne |
| 61 | 61 | $GLOBALS['spip_lang'], // lang |
| 62 | 62 | ]; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 65 | + $message = count($trace) ? $trace[0]['file'].' L'.$trace[0]['line'] : ''; |
|
| 66 | 66 | $f = []; |
| 67 | 67 | while (count($trace) && ($t = array_shift($trace))) { |
| 68 | 68 | if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | $f[] = $t['function']; |
| 72 | 72 | } |
| 73 | 73 | if ($f !== []) { |
| 74 | - $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 74 | + $message .= ' ['.implode('(),', $f).'()]'; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | return $message; |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | // le debug, c'est pour ce qui a ete produit par le compilateur |
| 265 | 265 | if (isset($GLOBALS['debug']['aucasou'])) { |
| 266 | 266 | [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
| 267 | - $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 267 | + $nom = $GLOBALS['debug_objets']['courant'].$id; |
|
| 268 | 268 | $GLOBALS['debug_objets']['requete'][$nom] = $query; |
| 269 | 269 | } |
| 270 | 270 | $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
@@ -1141,7 +1141,7 @@ discard block |
||
| 1141 | 1141 | // la globale n'est remplie qu'apres l'appel de sql_serveur. |
| 1142 | 1142 | if ($spip == null) { |
| 1143 | 1143 | $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 1144 | - $spip = $connexion['prefixe'] . '\_%'; |
|
| 1144 | + $spip = $connexion['prefixe'].'\_%'; |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | return $f($spip, $serveur, $option !== false); |
@@ -2298,9 +2298,9 @@ discard block |
||
| 2298 | 2298 | $jour = 0; |
| 2299 | 2299 | } |
| 2300 | 2300 | |
| 2301 | - return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2302 | - . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2303 | - . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2301 | + return sprintf('%04u', $annee).'-'.sprintf('%02u', $mois).'-' |
|
| 2302 | + . sprintf('%02u', $jour).' '.sprintf('%02u', $h).':' |
|
| 2303 | + . sprintf('%02u', $m).':'.sprintf('%02u', $s); |
|
| 2304 | 2304 | } |
| 2305 | 2305 | |
| 2306 | 2306 | |
@@ -2362,7 +2362,7 @@ discard block |
||
| 2362 | 2362 | */ |
| 2363 | 2363 | function prefixer_table_spip($table, $prefixe) { |
| 2364 | 2364 | if ($prefixe) { |
| 2365 | - $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2365 | + $table = preg_replace('/^spip_/', $prefixe.'_', $table); |
|
| 2366 | 2366 | } |
| 2367 | 2367 | return $table; |
| 2368 | 2368 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | define('_VERSION_ARCHIVE', '1.3'); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @return string |
| 38 | 38 | **/ |
| 39 | 39 | function base_dump_meta_name($rub) { |
| 40 | - return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 40 | + return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -52,14 +52,14 @@ discard block |
||
| 52 | 52 | * @return string |
| 53 | 53 | **/ |
| 54 | 54 | function base_dump_dir($meta) { |
| 55 | - include_spip('inc/documents'); |
|
| 56 | - // determine upload va aussi initialiser l'index "restreint" |
|
| 57 | - $maindir = determine_upload(); |
|
| 58 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 59 | - $maindir = _DIR_DUMP; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return sous_repertoire($maindir, $meta); |
|
| 55 | + include_spip('inc/documents'); |
|
| 56 | + // determine upload va aussi initialiser l'index "restreint" |
|
| 57 | + $maindir = determine_upload(); |
|
| 58 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 59 | + $maindir = _DIR_DUMP; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return sous_repertoire($maindir, $meta); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -73,28 +73,28 @@ discard block |
||
| 73 | 73 | * @return array |
| 74 | 74 | */ |
| 75 | 75 | function base_lister_toutes_tables( |
| 76 | - $serveur = '', |
|
| 77 | - $tables = [], |
|
| 78 | - $exclude = [], |
|
| 79 | - $affiche_vrai_prefixe = false |
|
| 76 | + $serveur = '', |
|
| 77 | + $tables = [], |
|
| 78 | + $exclude = [], |
|
| 79 | + $affiche_vrai_prefixe = false |
|
| 80 | 80 | ) { |
| 81 | - spip_connect($serveur); |
|
| 82 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 83 | - $prefixe = $connexion['prefixe']; |
|
| 84 | - |
|
| 85 | - $p = '/^' . $prefixe . '/'; |
|
| 86 | - $res = $tables; |
|
| 87 | - foreach (sql_alltable(null, $serveur) as $t) { |
|
| 88 | - if (preg_match($p, (string) $t)) { |
|
| 89 | - $t1 = preg_replace($p, 'spip', (string) $t); |
|
| 90 | - if (!in_array($t1, $tables) && !in_array($t1, $exclude)) { |
|
| 91 | - $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - sort($res); |
|
| 96 | - |
|
| 97 | - return $res; |
|
| 81 | + spip_connect($serveur); |
|
| 82 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 83 | + $prefixe = $connexion['prefixe']; |
|
| 84 | + |
|
| 85 | + $p = '/^' . $prefixe . '/'; |
|
| 86 | + $res = $tables; |
|
| 87 | + foreach (sql_alltable(null, $serveur) as $t) { |
|
| 88 | + if (preg_match($p, (string) $t)) { |
|
| 89 | + $t1 = preg_replace($p, 'spip', (string) $t); |
|
| 90 | + if (!in_array($t1, $tables) && !in_array($t1, $exclude)) { |
|
| 91 | + $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + sort($res); |
|
| 96 | + |
|
| 97 | + return $res; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | * @return string |
| 105 | 105 | */ |
| 106 | 106 | function base_prefixe_tables($serveur = '') { |
| 107 | - spip_connect($serveur); |
|
| 108 | - $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 107 | + spip_connect($serveur); |
|
| 108 | + $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
|
| 109 | 109 | |
| 110 | - return $connexion['prefixe']; |
|
| 110 | + return $connexion['prefixe']; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
@@ -122,26 +122,26 @@ discard block |
||
| 122 | 122 | * @return array |
| 123 | 123 | */ |
| 124 | 124 | function base_saisie_tables($name, $tables, $exclude = [], $post = null, $serveur = '') { |
| 125 | - include_spip('inc/filtres'); |
|
| 126 | - $res = []; |
|
| 127 | - foreach ($tables as $k => $t) { |
|
| 128 | - // par defaut tout est coche sauf les tables dans $exclude |
|
| 129 | - $check = is_null($post) ? !in_array($t, $exclude) : in_array($t, $post); |
|
| 130 | - |
|
| 131 | - $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 132 | - . "[]' id='$name$k'" |
|
| 133 | - . ($check ? " checked='checked'" : '') |
|
| 134 | - . "/>\n" |
|
| 135 | - . "<label for='$name$k'>$t</label>" |
|
| 136 | - . ' (' |
|
| 137 | - . sinon( |
|
| 138 | - singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 139 | - _T('dump:aucune_donnee') |
|
| 140 | - ) |
|
| 141 | - . ')'; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $res; |
|
| 125 | + include_spip('inc/filtres'); |
|
| 126 | + $res = []; |
|
| 127 | + foreach ($tables as $k => $t) { |
|
| 128 | + // par defaut tout est coche sauf les tables dans $exclude |
|
| 129 | + $check = is_null($post) ? !in_array($t, $exclude) : in_array($t, $post); |
|
| 130 | + |
|
| 131 | + $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 132 | + . "[]' id='$name$k'" |
|
| 133 | + . ($check ? " checked='checked'" : '') |
|
| 134 | + . "/>\n" |
|
| 135 | + . "<label for='$name$k'>$t</label>" |
|
| 136 | + . ' (' |
|
| 137 | + . sinon( |
|
| 138 | + singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 139 | + _T('dump:aucune_donnee') |
|
| 140 | + ) |
|
| 141 | + . ')'; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $res; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -153,27 +153,27 @@ discard block |
||
| 153 | 153 | * @return array |
| 154 | 154 | */ |
| 155 | 155 | function lister_tables_noexport() { |
| 156 | - // par defaut tout est exporte sauf les tables ci-dessous |
|
| 157 | - static $EXPORT_tables_noexport = null; |
|
| 158 | - if (!is_null($EXPORT_tables_noexport)) { |
|
| 159 | - return $EXPORT_tables_noexport; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $EXPORT_tables_noexport = [ |
|
| 163 | - 'spip_caches', // plugin invalideur |
|
| 164 | - 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 165 | - 'spip_test', // c'est un test ! |
|
| 166 | - #'spip_referers', |
|
| 167 | - #'spip_referers_articles', |
|
| 168 | - #'spip_visites', |
|
| 169 | - #'spip_visites_articles', |
|
| 170 | - #'spip_versions', |
|
| 171 | - #'spip_versions_fragments' |
|
| 172 | - ]; |
|
| 173 | - |
|
| 174 | - $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 175 | - |
|
| 176 | - return $EXPORT_tables_noexport; |
|
| 156 | + // par defaut tout est exporte sauf les tables ci-dessous |
|
| 157 | + static $EXPORT_tables_noexport = null; |
|
| 158 | + if (!is_null($EXPORT_tables_noexport)) { |
|
| 159 | + return $EXPORT_tables_noexport; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $EXPORT_tables_noexport = [ |
|
| 163 | + 'spip_caches', // plugin invalideur |
|
| 164 | + 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 165 | + 'spip_test', // c'est un test ! |
|
| 166 | + #'spip_referers', |
|
| 167 | + #'spip_referers_articles', |
|
| 168 | + #'spip_visites', |
|
| 169 | + #'spip_visites_articles', |
|
| 170 | + #'spip_versions', |
|
| 171 | + #'spip_versions_fragments' |
|
| 172 | + ]; |
|
| 173 | + |
|
| 174 | + $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 175 | + |
|
| 176 | + return $EXPORT_tables_noexport; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -184,25 +184,25 @@ discard block |
||
| 184 | 184 | * @return array |
| 185 | 185 | */ |
| 186 | 186 | function lister_tables_noimport() { |
| 187 | - static $IMPORT_tables_noimport = null; |
|
| 188 | - if (!is_null($IMPORT_tables_noimport)) { |
|
| 189 | - return $IMPORT_tables_noimport; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - $IMPORT_tables_noimport = []; |
|
| 193 | - // par defaut tout est importe sauf les tables ci-dessous |
|
| 194 | - // possibiliter de definir cela tables via la meta |
|
| 195 | - // compatibilite |
|
| 196 | - if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 197 | - $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 198 | - if (!is_array($IMPORT_tables_noimport)) { |
|
| 199 | - include_spip('inc/meta'); |
|
| 200 | - effacer_meta('IMPORT_tables_noimport'); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 204 | - |
|
| 205 | - return $IMPORT_tables_noimport; |
|
| 187 | + static $IMPORT_tables_noimport = null; |
|
| 188 | + if (!is_null($IMPORT_tables_noimport)) { |
|
| 189 | + return $IMPORT_tables_noimport; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + $IMPORT_tables_noimport = []; |
|
| 193 | + // par defaut tout est importe sauf les tables ci-dessous |
|
| 194 | + // possibiliter de definir cela tables via la meta |
|
| 195 | + // compatibilite |
|
| 196 | + if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 197 | + $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 198 | + if (!is_array($IMPORT_tables_noimport)) { |
|
| 199 | + include_spip('inc/meta'); |
|
| 200 | + effacer_meta('IMPORT_tables_noimport'); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 204 | + |
|
| 205 | + return $IMPORT_tables_noimport; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
@@ -214,23 +214,23 @@ discard block |
||
| 214 | 214 | * @return array |
| 215 | 215 | */ |
| 216 | 216 | function lister_tables_noerase() { |
| 217 | - static $IMPORT_tables_noerase = null; |
|
| 218 | - if (!is_null($IMPORT_tables_noerase)) { |
|
| 219 | - return $IMPORT_tables_noerase; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $IMPORT_tables_noerase = [ |
|
| 223 | - 'spip_meta', |
|
| 224 | - // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 225 | - // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 226 | - 'spip_referers', |
|
| 227 | - 'spip_referers_articles', |
|
| 228 | - 'spip_visites', |
|
| 229 | - 'spip_visites_articles' |
|
| 230 | - ]; |
|
| 231 | - $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 232 | - |
|
| 233 | - return $IMPORT_tables_noerase; |
|
| 217 | + static $IMPORT_tables_noerase = null; |
|
| 218 | + if (!is_null($IMPORT_tables_noerase)) { |
|
| 219 | + return $IMPORT_tables_noerase; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $IMPORT_tables_noerase = [ |
|
| 223 | + 'spip_meta', |
|
| 224 | + // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 225 | + // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 226 | + 'spip_referers', |
|
| 227 | + 'spip_referers_articles', |
|
| 228 | + 'spip_visites', |
|
| 229 | + 'spip_visites_articles' |
|
| 230 | + ]; |
|
| 231 | + $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 232 | + |
|
| 233 | + return $IMPORT_tables_noerase; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
@@ -244,86 +244,86 @@ discard block |
||
| 244 | 244 | * @return array |
| 245 | 245 | */ |
| 246 | 246 | function base_liste_table_for_dump($exclude_tables = []) { |
| 247 | - $tables_for_dump = []; |
|
| 248 | - $tables_pointees = []; |
|
| 249 | - $tables = []; |
|
| 250 | - $tables_principales = $GLOBALS['tables_principales']; |
|
| 251 | - $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 252 | - $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 253 | - |
|
| 254 | - if ( |
|
| 255 | - include_spip('base/objets') |
|
| 256 | - && function_exists('lister_tables_objets_sql') |
|
| 257 | - ) { |
|
| 258 | - $tables = lister_tables_objets_sql(); |
|
| 259 | - foreach ($tables as $t => $infos) { |
|
| 260 | - if ($infos['principale'] && !isset($tables_principales[$t])) { |
|
| 261 | - $tables_principales[$t] = true; |
|
| 262 | - } |
|
| 263 | - if (!$infos['principale'] && !isset($tables_auxiliaires[$t])) { |
|
| 264 | - $tables_auxiliaires[$t] = true; |
|
| 265 | - } |
|
| 266 | - if (is_countable($infos['tables_jointures']) ? count($infos['tables_jointures']) : 0) { |
|
| 267 | - $tables_jointures[$t] = array_merge( |
|
| 268 | - $tables_jointures[$t] ?? [], |
|
| 269 | - $infos['tables_jointures'] |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // on construit un index des tables de liens |
|
| 276 | - // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 277 | - $tables_for_link = []; |
|
| 278 | - foreach ($tables_jointures as $table => $liste_relations) { |
|
| 279 | - if (is_array($liste_relations)) { |
|
| 280 | - $nom = $table; |
|
| 281 | - if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 282 | - $nom = "spip_$table"; |
|
| 283 | - } |
|
| 284 | - if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 285 | - foreach ($liste_relations as $link_table) { |
|
| 286 | - if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 287 | - $tables_for_link[$link_table][] = $nom; |
|
| 288 | - } else { |
|
| 289 | - if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 290 | - $tables_for_link["spip_$link_table"][] = $nom; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $liste_tables = [...array_keys($tables_principales), ...array_keys($tables_auxiliaires), ...array_keys($tables)]; |
|
| 299 | - foreach ($liste_tables as $table) { |
|
| 300 | - // $name = preg_replace("{^spip_}","",$table); |
|
| 301 | - if ( |
|
| 302 | - !isset($tables_pointees[$table]) |
|
| 303 | - && !in_array($table, $exclude_tables) |
|
| 304 | - && !isset($tables_for_link[$table]) |
|
| 305 | - ) { |
|
| 306 | - $tables_for_dump[] = $table; |
|
| 307 | - $tables_pointees[$table] = 1; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - foreach ($tables_for_link as $link_table => $liste) { |
|
| 311 | - $connecte = true; |
|
| 312 | - foreach ($liste as $connect_table) { |
|
| 313 | - if (!in_array($connect_table, $tables_for_dump)) { |
|
| 314 | - $connecte = false; |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - if ($connecte) { |
|
| 318 | - # on ajoute les liaisons en premier |
|
| 319 | - # si une restauration est interrompue, |
|
| 320 | - # cela se verra mieux si il manque des objets |
|
| 321 | - # que des liens |
|
| 322 | - array_unshift($tables_for_dump, $link_table); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - return [$tables_for_dump, $tables_for_link]; |
|
| 247 | + $tables_for_dump = []; |
|
| 248 | + $tables_pointees = []; |
|
| 249 | + $tables = []; |
|
| 250 | + $tables_principales = $GLOBALS['tables_principales']; |
|
| 251 | + $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 252 | + $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 253 | + |
|
| 254 | + if ( |
|
| 255 | + include_spip('base/objets') |
|
| 256 | + && function_exists('lister_tables_objets_sql') |
|
| 257 | + ) { |
|
| 258 | + $tables = lister_tables_objets_sql(); |
|
| 259 | + foreach ($tables as $t => $infos) { |
|
| 260 | + if ($infos['principale'] && !isset($tables_principales[$t])) { |
|
| 261 | + $tables_principales[$t] = true; |
|
| 262 | + } |
|
| 263 | + if (!$infos['principale'] && !isset($tables_auxiliaires[$t])) { |
|
| 264 | + $tables_auxiliaires[$t] = true; |
|
| 265 | + } |
|
| 266 | + if (is_countable($infos['tables_jointures']) ? count($infos['tables_jointures']) : 0) { |
|
| 267 | + $tables_jointures[$t] = array_merge( |
|
| 268 | + $tables_jointures[$t] ?? [], |
|
| 269 | + $infos['tables_jointures'] |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // on construit un index des tables de liens |
|
| 276 | + // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 277 | + $tables_for_link = []; |
|
| 278 | + foreach ($tables_jointures as $table => $liste_relations) { |
|
| 279 | + if (is_array($liste_relations)) { |
|
| 280 | + $nom = $table; |
|
| 281 | + if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 282 | + $nom = "spip_$table"; |
|
| 283 | + } |
|
| 284 | + if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 285 | + foreach ($liste_relations as $link_table) { |
|
| 286 | + if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 287 | + $tables_for_link[$link_table][] = $nom; |
|
| 288 | + } else { |
|
| 289 | + if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 290 | + $tables_for_link["spip_$link_table"][] = $nom; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + $liste_tables = [...array_keys($tables_principales), ...array_keys($tables_auxiliaires), ...array_keys($tables)]; |
|
| 299 | + foreach ($liste_tables as $table) { |
|
| 300 | + // $name = preg_replace("{^spip_}","",$table); |
|
| 301 | + if ( |
|
| 302 | + !isset($tables_pointees[$table]) |
|
| 303 | + && !in_array($table, $exclude_tables) |
|
| 304 | + && !isset($tables_for_link[$table]) |
|
| 305 | + ) { |
|
| 306 | + $tables_for_dump[] = $table; |
|
| 307 | + $tables_pointees[$table] = 1; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + foreach ($tables_for_link as $link_table => $liste) { |
|
| 311 | + $connecte = true; |
|
| 312 | + foreach ($liste as $connect_table) { |
|
| 313 | + if (!in_array($connect_table, $tables_for_dump)) { |
|
| 314 | + $connecte = false; |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + if ($connecte) { |
|
| 318 | + # on ajoute les liaisons en premier |
|
| 319 | + # si une restauration est interrompue, |
|
| 320 | + # cela se verra mieux si il manque des objets |
|
| 321 | + # que des liens |
|
| 322 | + array_unshift($tables_for_dump, $link_table); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + return [$tables_for_dump, $tables_for_link]; |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
@@ -338,35 +338,35 @@ discard block |
||
| 338 | 338 | * @param string $serveur |
| 339 | 339 | */ |
| 340 | 340 | function base_vider_tables_destination_copie($tables, $exclure_tables = [], $serveur = '') { |
| 341 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 342 | - |
|
| 343 | - spip_log( |
|
| 344 | - 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . implode(', ', $tables), |
|
| 345 | - 'base.' . _LOG_INFO_IMPORTANTE |
|
| 346 | - ); |
|
| 347 | - foreach ($tables as $table) { |
|
| 348 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 349 | - if (!in_array($table, $exclure_tables) && ($table != 'spip_auteurs' || $serveur != '')) { |
|
| 350 | - // regarder si il y a au moins un champ impt='non' |
|
| 351 | - $desc = $trouver_table($table, $serveur); |
|
| 352 | - if (isset($desc['field']['impt'])) { |
|
| 353 | - sql_delete($table, "impt='oui'", $serveur); |
|
| 354 | - } elseif ($desc) { |
|
| 355 | - sql_delete($table, '', $serveur); |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 361 | - // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 362 | - if ( |
|
| 363 | - $serveur == '' |
|
| 364 | - && in_array('spip_auteurs', $tables) |
|
| 365 | - && !in_array('spip_auteurs', $exclure_tables) |
|
| 366 | - ) { |
|
| 367 | - base_conserver_copieur(true, $serveur); |
|
| 368 | - sql_delete('spip_auteurs', 'id_auteur>0', $serveur); |
|
| 369 | - } |
|
| 341 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 342 | + |
|
| 343 | + spip_log( |
|
| 344 | + 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . implode(', ', $tables), |
|
| 345 | + 'base.' . _LOG_INFO_IMPORTANTE |
|
| 346 | + ); |
|
| 347 | + foreach ($tables as $table) { |
|
| 348 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 349 | + if (!in_array($table, $exclure_tables) && ($table != 'spip_auteurs' || $serveur != '')) { |
|
| 350 | + // regarder si il y a au moins un champ impt='non' |
|
| 351 | + $desc = $trouver_table($table, $serveur); |
|
| 352 | + if (isset($desc['field']['impt'])) { |
|
| 353 | + sql_delete($table, "impt='oui'", $serveur); |
|
| 354 | + } elseif ($desc) { |
|
| 355 | + sql_delete($table, '', $serveur); |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 361 | + // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 362 | + if ( |
|
| 363 | + $serveur == '' |
|
| 364 | + && in_array('spip_auteurs', $tables) |
|
| 365 | + && !in_array('spip_auteurs', $exclure_tables) |
|
| 366 | + ) { |
|
| 367 | + base_conserver_copieur(true, $serveur); |
|
| 368 | + sql_delete('spip_auteurs', 'id_auteur>0', $serveur); |
|
| 369 | + } |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -377,36 +377,36 @@ discard block |
||
| 377 | 377 | * @return void |
| 378 | 378 | */ |
| 379 | 379 | function base_conserver_copieur($move = true, $serveur = '') { |
| 380 | - // s'asurer qu'on a pas deja fait la manip ! |
|
| 381 | - if ($GLOBALS['visiteur_session']['id_auteur'] > 0 && sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 382 | - spip_log( |
|
| 383 | - 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 384 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 385 | - ); |
|
| 386 | - sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 387 | - if ($move) { |
|
| 388 | - sql_updateq( |
|
| 389 | - 'spip_auteurs', |
|
| 390 | - ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
|
| 391 | - 'id_auteur=' . (int) $GLOBALS['visiteur_session']['id_auteur'], |
|
| 392 | - [], |
|
| 393 | - $serveur |
|
| 394 | - ); |
|
| 395 | - } else { |
|
| 396 | - $row = sql_fetsel( |
|
| 397 | - '*', |
|
| 398 | - 'spip_auteurs', |
|
| 399 | - 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 400 | - '', |
|
| 401 | - '', |
|
| 402 | - '', |
|
| 403 | - '', |
|
| 404 | - $serveur |
|
| 405 | - ); |
|
| 406 | - $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 407 | - sql_insertq('spip_auteurs', $row, [], $serveur); |
|
| 408 | - } |
|
| 409 | - } |
|
| 380 | + // s'asurer qu'on a pas deja fait la manip ! |
|
| 381 | + if ($GLOBALS['visiteur_session']['id_auteur'] > 0 && sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 382 | + spip_log( |
|
| 383 | + 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 384 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 385 | + ); |
|
| 386 | + sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 387 | + if ($move) { |
|
| 388 | + sql_updateq( |
|
| 389 | + 'spip_auteurs', |
|
| 390 | + ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
|
| 391 | + 'id_auteur=' . (int) $GLOBALS['visiteur_session']['id_auteur'], |
|
| 392 | + [], |
|
| 393 | + $serveur |
|
| 394 | + ); |
|
| 395 | + } else { |
|
| 396 | + $row = sql_fetsel( |
|
| 397 | + '*', |
|
| 398 | + 'spip_auteurs', |
|
| 399 | + 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 400 | + '', |
|
| 401 | + '', |
|
| 402 | + '', |
|
| 403 | + '', |
|
| 404 | + $serveur |
|
| 405 | + ); |
|
| 406 | + $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 407 | + sql_insertq('spip_auteurs', $row, [], $serveur); |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -421,21 +421,21 @@ discard block |
||
| 421 | 421 | * @param string $serveur |
| 422 | 422 | */ |
| 423 | 423 | function base_detruire_copieur_si_besoin($serveur = '') { |
| 424 | - // rien a faire si ce n'est pas le serveur principal ! |
|
| 425 | - if ($serveur == '') { |
|
| 426 | - if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 427 | - spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 428 | - sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 429 | - } else { |
|
| 430 | - spip_log( |
|
| 431 | - "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 432 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 433 | - ); |
|
| 434 | - sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
|
| 435 | - } |
|
| 436 | - } else { |
|
| 437 | - spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 438 | - } |
|
| 424 | + // rien a faire si ce n'est pas le serveur principal ! |
|
| 425 | + if ($serveur == '') { |
|
| 426 | + if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 427 | + spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 428 | + sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 429 | + } else { |
|
| 430 | + spip_log( |
|
| 431 | + "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 432 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 433 | + ); |
|
| 434 | + sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
|
| 435 | + } |
|
| 436 | + } else { |
|
| 437 | + spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 438 | + } |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | /** |
@@ -450,40 +450,40 @@ discard block |
||
| 450 | 450 | * @return array |
| 451 | 451 | */ |
| 452 | 452 | function base_preparer_table_dest($table, $desc, $serveur_dest, $init = false) { |
| 453 | - $upgrade = false; |
|
| 454 | - // si la table existe et qu'on est a l'init, la dropper |
|
| 455 | - if (($desc_dest = sql_showtable($table, true, $serveur_dest)) && $init) { |
|
| 456 | - if ($serveur_dest == '' && in_array($table, ['spip_meta', 'spip_auteurs'])) { |
|
| 457 | - // ne pas dropper auteurs et meta sur le serveur principal |
|
| 458 | - // faire un simple upgrade a la place |
|
| 459 | - // pour ajouter les champs manquants |
|
| 460 | - $upgrade = true; |
|
| 461 | - // coherence avec le drop sur les autres tables |
|
| 462 | - base_vider_tables_destination_copie([$table], [], $serveur_dest); |
|
| 463 | - if ($table == 'spip_meta') { |
|
| 464 | - // virer les version base qui vont venir avec l'import |
|
| 465 | - sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 466 | - // hum casse la base si pas version_installee a l'import ... |
|
| 467 | - sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 468 | - } |
|
| 469 | - } else { |
|
| 470 | - sql_drop_table($table, '', $serveur_dest); |
|
| 471 | - spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 472 | - } |
|
| 473 | - $desc_dest = false; |
|
| 474 | - } |
|
| 475 | - // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 476 | - if (!$desc_dest) { |
|
| 477 | - spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 478 | - include_spip('base/create'); |
|
| 479 | - creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 480 | - $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 481 | - } |
|
| 482 | - if (!$desc_dest) { |
|
| 483 | - spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return $desc_dest; |
|
| 453 | + $upgrade = false; |
|
| 454 | + // si la table existe et qu'on est a l'init, la dropper |
|
| 455 | + if (($desc_dest = sql_showtable($table, true, $serveur_dest)) && $init) { |
|
| 456 | + if ($serveur_dest == '' && in_array($table, ['spip_meta', 'spip_auteurs'])) { |
|
| 457 | + // ne pas dropper auteurs et meta sur le serveur principal |
|
| 458 | + // faire un simple upgrade a la place |
|
| 459 | + // pour ajouter les champs manquants |
|
| 460 | + $upgrade = true; |
|
| 461 | + // coherence avec le drop sur les autres tables |
|
| 462 | + base_vider_tables_destination_copie([$table], [], $serveur_dest); |
|
| 463 | + if ($table == 'spip_meta') { |
|
| 464 | + // virer les version base qui vont venir avec l'import |
|
| 465 | + sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 466 | + // hum casse la base si pas version_installee a l'import ... |
|
| 467 | + sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 468 | + } |
|
| 469 | + } else { |
|
| 470 | + sql_drop_table($table, '', $serveur_dest); |
|
| 471 | + spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 472 | + } |
|
| 473 | + $desc_dest = false; |
|
| 474 | + } |
|
| 475 | + // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 476 | + if (!$desc_dest) { |
|
| 477 | + spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 478 | + include_spip('base/create'); |
|
| 479 | + creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 480 | + $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 481 | + } |
|
| 482 | + if (!$desc_dest) { |
|
| 483 | + spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return $desc_dest; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -529,211 +529,211 @@ discard block |
||
| 529 | 529 | */ |
| 530 | 530 | function base_copier_tables($status_file, $tables, $serveur_source, $serveur_dest, $options = []) { |
| 531 | 531 | |
| 532 | - $status = []; |
|
| 533 | - $callback_progression = $options['callback_progression'] ?? ''; |
|
| 534 | - $max_time = $options['max_time'] ?? 0; |
|
| 535 | - $drop_source = $options['drop_source'] ?? false; |
|
| 536 | - $no_erase_dest = $options['no_erase_dest'] ?? []; |
|
| 537 | - $where = $options['where'] ?? []; |
|
| 538 | - $fonction_base_inserer = $options['fonction_base_inserer'] ?? 'inserer_copie'; |
|
| 539 | - $desc_tables_dest = $options['desc_tables_dest'] ?? []; |
|
| 540 | - $racine_fonctions = $options['racine_fonctions_dest'] ?? 'base'; |
|
| 541 | - $data_pool = $options['data_pool'] ?? 50 * 1024; |
|
| 542 | - |
|
| 543 | - spip_log( |
|
| 544 | - 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 545 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 546 | - ); |
|
| 547 | - |
|
| 548 | - if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 549 | - spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 550 | - |
|
| 551 | - return true; // echec mais on a fini, donc true |
|
| 552 | - } |
|
| 553 | - if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 554 | - spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 555 | - |
|
| 556 | - return true; // echec mais on a fini, donc true |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - if ( |
|
| 560 | - !lire_fichier($status_file, $status) |
|
| 561 | - || !($status = unserialize($status)) |
|
| 562 | - ) { |
|
| 563 | - $status = []; |
|
| 564 | - } |
|
| 565 | - $status['etape'] = 'basecopie'; |
|
| 566 | - |
|
| 567 | - // puis relister les tables a importer |
|
| 568 | - // et les vider si besoin, au moment du premier passage ici |
|
| 569 | - $initialisation_copie = $status['dump_status_copie'] ?? 0; |
|
| 570 | - |
|
| 571 | - // si init pas encore faite, vider les tables du serveur destination |
|
| 572 | - if (!$initialisation_copie) { |
|
| 573 | - if ( |
|
| 574 | - !$vider_tables_destination_copie = charger_fonction( |
|
| 575 | - 'vider_tables_destination_copie', |
|
| 576 | - $racine_fonctions, |
|
| 577 | - true |
|
| 578 | - ) |
|
| 579 | - ) { |
|
| 580 | - spip_log( |
|
| 581 | - "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 582 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 583 | - ); |
|
| 584 | - |
|
| 585 | - return true; // echec mais on a fini, donc true |
|
| 586 | - } |
|
| 587 | - $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 588 | - $status['dump_status_copie'] = 'ok'; |
|
| 589 | - ecrire_fichier($status_file, serialize($status)); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 593 | - if (in_array('spip_auteurs', $tables)) { |
|
| 594 | - $tables = array_diff($tables, ['spip_auteurs']); |
|
| 595 | - $tables[] = 'spip_auteurs'; |
|
| 596 | - } |
|
| 597 | - if (in_array('spip_meta', $tables)) { |
|
| 598 | - $tables = array_diff($tables, ['spip_meta']); |
|
| 599 | - $tables[] = 'spip_meta'; |
|
| 600 | - } |
|
| 601 | - spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 602 | - |
|
| 603 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 604 | - |
|
| 605 | - foreach ($tables as $table) { |
|
| 606 | - // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 607 | - // sinon chercher la vraie table |
|
| 608 | - $desc_source = false; |
|
| 609 | - if (str_starts_with((string) $table, 'spip_')) { |
|
| 610 | - $desc_source = $trouver_table(preg_replace(',^spip_,', '', (string) $table), $serveur_source, true); |
|
| 611 | - } |
|
| 612 | - if (!$desc_source || !isset($desc_source['exist']) || !$desc_source['exist']) { |
|
| 613 | - $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - // verifier que la table est presente dans la base source |
|
| 617 | - if ($desc_source) { |
|
| 618 | - // $status['tables_copiees'][$table] contient l'avancement |
|
| 619 | - // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 620 | - if (!isset($status['tables_copiees'][$table])) { |
|
| 621 | - $status['tables_copiees'][$table] = 0; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - if ( |
|
| 625 | - is_numeric($status['tables_copiees'][$table]) |
|
| 626 | - && $status['tables_copiees'][$table] >= 0 |
|
| 627 | - && ($desc_dest = $preparer_table_dest( |
|
| 628 | - $table, |
|
| 629 | - $desc_tables_dest[$table] ?? $desc_source, |
|
| 630 | - $serveur_dest, |
|
| 631 | - $status['tables_copiees'][$table] == 0 |
|
| 632 | - )) |
|
| 633 | - ) { |
|
| 634 | - if ($callback_progression) { |
|
| 635 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 636 | - } |
|
| 637 | - while (true) { |
|
| 638 | - $n = (int) $status['tables_copiees'][$table]; |
|
| 639 | - // on copie par lot de 400 |
|
| 640 | - $res = sql_select( |
|
| 641 | - '*', |
|
| 642 | - $table, |
|
| 643 | - $where[$table] ?? '', |
|
| 644 | - '', |
|
| 645 | - '', |
|
| 646 | - "$n,400", |
|
| 647 | - '', |
|
| 648 | - $serveur_source |
|
| 649 | - ); |
|
| 650 | - while ($row = sql_fetch($res, $serveur_source)) { |
|
| 651 | - $rows = [$row]; |
|
| 652 | - // lire un groupe de donnees si demande en option |
|
| 653 | - // (permet un envoi par lot vers la destination) |
|
| 654 | - if ($data_pool > 0) { |
|
| 655 | - $s = strlen(serialize($row)); |
|
| 656 | - while ($s < $data_pool && ($row = sql_fetch($res, $serveur_source))) { |
|
| 657 | - $s += strlen(serialize($row)); |
|
| 658 | - $rows[] = $row; |
|
| 659 | - } |
|
| 660 | - } |
|
| 661 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 662 | - // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 663 | - if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 664 | - // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 665 | - spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 666 | - $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 667 | - ecrire_fichier($status_file, serialize($status)); |
|
| 668 | - |
|
| 669 | - // copie finie |
|
| 670 | - return true; |
|
| 671 | - } |
|
| 672 | - $status['tables_copiees'][$table] += count($rows); |
|
| 673 | - if ($max_time && time() > $max_time) { |
|
| 674 | - break; |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - if ($n == $status['tables_copiees'][$table]) { |
|
| 678 | - break; |
|
| 679 | - } |
|
| 680 | - spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 681 | - if ($callback_progression) { |
|
| 682 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 683 | - } |
|
| 684 | - ecrire_fichier($status_file, serialize($status)); |
|
| 685 | - if ($max_time && time() > $max_time) { |
|
| 686 | - return false; |
|
| 687 | - } // on a pas fini, mais le temps imparti est ecoule |
|
| 688 | - } |
|
| 689 | - if ($drop_source) { |
|
| 690 | - sql_drop_table($table, '', $serveur_source); |
|
| 691 | - spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 692 | - } |
|
| 693 | - $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
|
| 694 | - ecrire_fichier($status_file, serialize($status)); |
|
| 695 | - spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 696 | - if ($callback_progression) { |
|
| 697 | - $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 698 | - } |
|
| 699 | - } else { |
|
| 700 | - if ($status['tables_copiees'][$table] < 0) { |
|
| 701 | - spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 702 | - } |
|
| 703 | - if ($callback_progression) { |
|
| 704 | - $callback_progression( |
|
| 705 | - 0, |
|
| 706 | - $status['tables_copiees'][$table], |
|
| 707 | - "$table" . ((is_numeric($status['tables_copiees'][$table]) && $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 708 | - ); |
|
| 709 | - } |
|
| 710 | - } |
|
| 711 | - } else { |
|
| 712 | - $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 713 | - ecrire_fichier($status_file, serialize($status)); |
|
| 714 | - spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 715 | - } |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 719 | - // abandonner |
|
| 720 | - if ((is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) < count($tables)) { |
|
| 721 | - spip_log( |
|
| 722 | - 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables), |
|
| 723 | - 'dump.' . _LOG_ERREUR |
|
| 724 | - ); |
|
| 725 | - $status['errors'][] = 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables); |
|
| 726 | - ecrire_fichier($status_file, serialize($status)); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 730 | - $detruire_copieur_si_besoin($serveur_dest); |
|
| 731 | - } else { |
|
| 732 | - spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - // OK, copie complete |
|
| 736 | - return true; |
|
| 532 | + $status = []; |
|
| 533 | + $callback_progression = $options['callback_progression'] ?? ''; |
|
| 534 | + $max_time = $options['max_time'] ?? 0; |
|
| 535 | + $drop_source = $options['drop_source'] ?? false; |
|
| 536 | + $no_erase_dest = $options['no_erase_dest'] ?? []; |
|
| 537 | + $where = $options['where'] ?? []; |
|
| 538 | + $fonction_base_inserer = $options['fonction_base_inserer'] ?? 'inserer_copie'; |
|
| 539 | + $desc_tables_dest = $options['desc_tables_dest'] ?? []; |
|
| 540 | + $racine_fonctions = $options['racine_fonctions_dest'] ?? 'base'; |
|
| 541 | + $data_pool = $options['data_pool'] ?? 50 * 1024; |
|
| 542 | + |
|
| 543 | + spip_log( |
|
| 544 | + 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 545 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 546 | + ); |
|
| 547 | + |
|
| 548 | + if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 549 | + spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 550 | + |
|
| 551 | + return true; // echec mais on a fini, donc true |
|
| 552 | + } |
|
| 553 | + if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 554 | + spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 555 | + |
|
| 556 | + return true; // echec mais on a fini, donc true |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + if ( |
|
| 560 | + !lire_fichier($status_file, $status) |
|
| 561 | + || !($status = unserialize($status)) |
|
| 562 | + ) { |
|
| 563 | + $status = []; |
|
| 564 | + } |
|
| 565 | + $status['etape'] = 'basecopie'; |
|
| 566 | + |
|
| 567 | + // puis relister les tables a importer |
|
| 568 | + // et les vider si besoin, au moment du premier passage ici |
|
| 569 | + $initialisation_copie = $status['dump_status_copie'] ?? 0; |
|
| 570 | + |
|
| 571 | + // si init pas encore faite, vider les tables du serveur destination |
|
| 572 | + if (!$initialisation_copie) { |
|
| 573 | + if ( |
|
| 574 | + !$vider_tables_destination_copie = charger_fonction( |
|
| 575 | + 'vider_tables_destination_copie', |
|
| 576 | + $racine_fonctions, |
|
| 577 | + true |
|
| 578 | + ) |
|
| 579 | + ) { |
|
| 580 | + spip_log( |
|
| 581 | + "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 582 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 583 | + ); |
|
| 584 | + |
|
| 585 | + return true; // echec mais on a fini, donc true |
|
| 586 | + } |
|
| 587 | + $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 588 | + $status['dump_status_copie'] = 'ok'; |
|
| 589 | + ecrire_fichier($status_file, serialize($status)); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 593 | + if (in_array('spip_auteurs', $tables)) { |
|
| 594 | + $tables = array_diff($tables, ['spip_auteurs']); |
|
| 595 | + $tables[] = 'spip_auteurs'; |
|
| 596 | + } |
|
| 597 | + if (in_array('spip_meta', $tables)) { |
|
| 598 | + $tables = array_diff($tables, ['spip_meta']); |
|
| 599 | + $tables[] = 'spip_meta'; |
|
| 600 | + } |
|
| 601 | + spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 602 | + |
|
| 603 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 604 | + |
|
| 605 | + foreach ($tables as $table) { |
|
| 606 | + // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 607 | + // sinon chercher la vraie table |
|
| 608 | + $desc_source = false; |
|
| 609 | + if (str_starts_with((string) $table, 'spip_')) { |
|
| 610 | + $desc_source = $trouver_table(preg_replace(',^spip_,', '', (string) $table), $serveur_source, true); |
|
| 611 | + } |
|
| 612 | + if (!$desc_source || !isset($desc_source['exist']) || !$desc_source['exist']) { |
|
| 613 | + $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + // verifier que la table est presente dans la base source |
|
| 617 | + if ($desc_source) { |
|
| 618 | + // $status['tables_copiees'][$table] contient l'avancement |
|
| 619 | + // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 620 | + if (!isset($status['tables_copiees'][$table])) { |
|
| 621 | + $status['tables_copiees'][$table] = 0; |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + if ( |
|
| 625 | + is_numeric($status['tables_copiees'][$table]) |
|
| 626 | + && $status['tables_copiees'][$table] >= 0 |
|
| 627 | + && ($desc_dest = $preparer_table_dest( |
|
| 628 | + $table, |
|
| 629 | + $desc_tables_dest[$table] ?? $desc_source, |
|
| 630 | + $serveur_dest, |
|
| 631 | + $status['tables_copiees'][$table] == 0 |
|
| 632 | + )) |
|
| 633 | + ) { |
|
| 634 | + if ($callback_progression) { |
|
| 635 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 636 | + } |
|
| 637 | + while (true) { |
|
| 638 | + $n = (int) $status['tables_copiees'][$table]; |
|
| 639 | + // on copie par lot de 400 |
|
| 640 | + $res = sql_select( |
|
| 641 | + '*', |
|
| 642 | + $table, |
|
| 643 | + $where[$table] ?? '', |
|
| 644 | + '', |
|
| 645 | + '', |
|
| 646 | + "$n,400", |
|
| 647 | + '', |
|
| 648 | + $serveur_source |
|
| 649 | + ); |
|
| 650 | + while ($row = sql_fetch($res, $serveur_source)) { |
|
| 651 | + $rows = [$row]; |
|
| 652 | + // lire un groupe de donnees si demande en option |
|
| 653 | + // (permet un envoi par lot vers la destination) |
|
| 654 | + if ($data_pool > 0) { |
|
| 655 | + $s = strlen(serialize($row)); |
|
| 656 | + while ($s < $data_pool && ($row = sql_fetch($res, $serveur_source))) { |
|
| 657 | + $s += strlen(serialize($row)); |
|
| 658 | + $rows[] = $row; |
|
| 659 | + } |
|
| 660 | + } |
|
| 661 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 662 | + // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 663 | + if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 664 | + // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 665 | + spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 666 | + $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 667 | + ecrire_fichier($status_file, serialize($status)); |
|
| 668 | + |
|
| 669 | + // copie finie |
|
| 670 | + return true; |
|
| 671 | + } |
|
| 672 | + $status['tables_copiees'][$table] += count($rows); |
|
| 673 | + if ($max_time && time() > $max_time) { |
|
| 674 | + break; |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + if ($n == $status['tables_copiees'][$table]) { |
|
| 678 | + break; |
|
| 679 | + } |
|
| 680 | + spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 681 | + if ($callback_progression) { |
|
| 682 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 683 | + } |
|
| 684 | + ecrire_fichier($status_file, serialize($status)); |
|
| 685 | + if ($max_time && time() > $max_time) { |
|
| 686 | + return false; |
|
| 687 | + } // on a pas fini, mais le temps imparti est ecoule |
|
| 688 | + } |
|
| 689 | + if ($drop_source) { |
|
| 690 | + sql_drop_table($table, '', $serveur_source); |
|
| 691 | + spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 692 | + } |
|
| 693 | + $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
|
| 694 | + ecrire_fichier($status_file, serialize($status)); |
|
| 695 | + spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 696 | + if ($callback_progression) { |
|
| 697 | + $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 698 | + } |
|
| 699 | + } else { |
|
| 700 | + if ($status['tables_copiees'][$table] < 0) { |
|
| 701 | + spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 702 | + } |
|
| 703 | + if ($callback_progression) { |
|
| 704 | + $callback_progression( |
|
| 705 | + 0, |
|
| 706 | + $status['tables_copiees'][$table], |
|
| 707 | + "$table" . ((is_numeric($status['tables_copiees'][$table]) && $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 708 | + ); |
|
| 709 | + } |
|
| 710 | + } |
|
| 711 | + } else { |
|
| 712 | + $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 713 | + ecrire_fichier($status_file, serialize($status)); |
|
| 714 | + spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 715 | + } |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 719 | + // abandonner |
|
| 720 | + if ((is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) < count($tables)) { |
|
| 721 | + spip_log( |
|
| 722 | + 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables), |
|
| 723 | + 'dump.' . _LOG_ERREUR |
|
| 724 | + ); |
|
| 725 | + $status['errors'][] = 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables); |
|
| 726 | + ecrire_fichier($status_file, serialize($status)); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 730 | + $detruire_copieur_si_besoin($serveur_dest); |
|
| 731 | + } else { |
|
| 732 | + spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + // OK, copie complete |
|
| 736 | + return true; |
|
| 737 | 737 | } |
| 738 | 738 | |
| 739 | 739 | /** |
@@ -747,31 +747,31 @@ discard block |
||
| 747 | 747 | */ |
| 748 | 748 | function base_inserer_copie($table, $rows, $desc_dest, $serveur_dest) { |
| 749 | 749 | |
| 750 | - // verifier le nombre d'insertion |
|
| 751 | - $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 752 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 753 | - $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 754 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 755 | - if ($nb - $nb1 < count($rows)) { |
|
| 756 | - spip_log( |
|
| 757 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 758 | - 'dump' . _LOG_INFO_IMPORTANTE |
|
| 759 | - ); |
|
| 760 | - foreach ($rows as $row) { |
|
| 761 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 762 | - $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 763 | - } |
|
| 764 | - // on reverifie le total |
|
| 765 | - $r = 0; |
|
| 766 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 767 | - if ($nb - $nb1 < count($rows)) { |
|
| 768 | - spip_log( |
|
| 769 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 770 | - 'dump' . _LOG_ERREUR |
|
| 771 | - ); |
|
| 772 | - $r = false; |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - return $r; |
|
| 750 | + // verifier le nombre d'insertion |
|
| 751 | + $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 752 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 753 | + $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 754 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 755 | + if ($nb - $nb1 < count($rows)) { |
|
| 756 | + spip_log( |
|
| 757 | + 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 758 | + 'dump' . _LOG_INFO_IMPORTANTE |
|
| 759 | + ); |
|
| 760 | + foreach ($rows as $row) { |
|
| 761 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 762 | + $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 763 | + } |
|
| 764 | + // on reverifie le total |
|
| 765 | + $r = 0; |
|
| 766 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 767 | + if ($nb - $nb1 < count($rows)) { |
|
| 768 | + spip_log( |
|
| 769 | + 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 770 | + 'dump' . _LOG_ERREUR |
|
| 771 | + ); |
|
| 772 | + $r = false; |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + return $r; |
|
| 777 | 777 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @return string |
| 38 | 38 | **/ |
| 39 | 39 | function base_dump_meta_name($rub) { |
| 40 | - return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 40 | + return $meta = "status_dump_{$rub}_".abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $connexion = $GLOBALS['connexions'][$serveur ?: 0]; |
| 83 | 83 | $prefixe = $connexion['prefixe']; |
| 84 | 84 | |
| 85 | - $p = '/^' . $prefixe . '/'; |
|
| 85 | + $p = '/^'.$prefixe.'/'; |
|
| 86 | 86 | $res = $tables; |
| 87 | 87 | foreach (sql_alltable(null, $serveur) as $t) { |
| 88 | 88 | if (preg_match($p, (string) $t)) { |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 342 | 342 | |
| 343 | 343 | spip_log( |
| 344 | - 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . implode(', ', $tables), |
|
| 345 | - 'base.' . _LOG_INFO_IMPORTANTE |
|
| 344 | + 'Vider '.count($tables)." tables sur serveur '$serveur' : ".implode(', ', $tables), |
|
| 345 | + 'base.'._LOG_INFO_IMPORTANTE |
|
| 346 | 346 | ); |
| 347 | 347 | foreach ($tables as $table) { |
| 348 | 348 | // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
@@ -380,15 +380,15 @@ discard block |
||
| 380 | 380 | // s'asurer qu'on a pas deja fait la manip ! |
| 381 | 381 | if ($GLOBALS['visiteur_session']['id_auteur'] > 0 && sql_countsel('spip_auteurs', 'id_auteur>0')) { |
| 382 | 382 | spip_log( |
| 383 | - 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 384 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 383 | + 'Conserver copieur dans id_auteur='.$GLOBALS['visiteur_session']['id_auteur']." pour le serveur '$serveur'", |
|
| 384 | + 'dump.'._LOG_INFO_IMPORTANTE |
|
| 385 | 385 | ); |
| 386 | 386 | sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
| 387 | 387 | if ($move) { |
| 388 | 388 | sql_updateq( |
| 389 | 389 | 'spip_auteurs', |
| 390 | 390 | ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
| 391 | - 'id_auteur=' . (int) $GLOBALS['visiteur_session']['id_auteur'], |
|
| 391 | + 'id_auteur='.(int) $GLOBALS['visiteur_session']['id_auteur'], |
|
| 392 | 392 | [], |
| 393 | 393 | $serveur |
| 394 | 394 | ); |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | $row = sql_fetsel( |
| 397 | 397 | '*', |
| 398 | 398 | 'spip_auteurs', |
| 399 | - 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 399 | + 'id_auteur='.$GLOBALS['visiteur_session']['id_auteur'], |
|
| 400 | 400 | '', |
| 401 | 401 | '', |
| 402 | 402 | '', |
@@ -424,17 +424,17 @@ discard block |
||
| 424 | 424 | // rien a faire si ce n'est pas le serveur principal ! |
| 425 | 425 | if ($serveur == '') { |
| 426 | 426 | if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
| 427 | - spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 427 | + spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 428 | 428 | sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
| 429 | 429 | } else { |
| 430 | 430 | spip_log( |
| 431 | 431 | "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
| 432 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 432 | + 'dump.'._LOG_INFO_IMPORTANTE |
|
| 433 | 433 | ); |
| 434 | 434 | sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
| 435 | 435 | } |
| 436 | 436 | } else { |
| 437 | - spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 437 | + spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | |
@@ -468,19 +468,19 @@ discard block |
||
| 468 | 468 | } |
| 469 | 469 | } else { |
| 470 | 470 | sql_drop_table($table, '', $serveur_dest); |
| 471 | - spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 471 | + spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 472 | 472 | } |
| 473 | 473 | $desc_dest = false; |
| 474 | 474 | } |
| 475 | 475 | // si la table n'existe pas dans la destination, la creer a l'identique ! |
| 476 | 476 | if (!$desc_dest) { |
| 477 | - spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 477 | + spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 478 | 478 | include_spip('base/create'); |
| 479 | 479 | creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
| 480 | 480 | $desc_dest = sql_showtable($table, true, $serveur_dest); |
| 481 | 481 | } |
| 482 | 482 | if (!$desc_dest) { |
| 483 | - spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 483 | + spip_log("Erreur creation '$table' sur serveur '$serveur_dest'".var_export($desc, 1), 'dump.'._LOG_ERREUR); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | return $desc_dest; |
@@ -541,17 +541,17 @@ discard block |
||
| 541 | 541 | $data_pool = $options['data_pool'] ?? 50 * 1024; |
| 542 | 542 | |
| 543 | 543 | spip_log( |
| 544 | - 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 545 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 544 | + 'Copier '.count($tables)." tables de '$serveur_source' vers '$serveur_dest'", |
|
| 545 | + 'dump.'._LOG_INFO_IMPORTANTE |
|
| 546 | 546 | ); |
| 547 | 547 | |
| 548 | 548 | if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
| 549 | - spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 549 | + spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 550 | 550 | |
| 551 | 551 | return true; // echec mais on a fini, donc true |
| 552 | 552 | } |
| 553 | 553 | if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
| 554 | - spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 554 | + spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 555 | 555 | |
| 556 | 556 | return true; // echec mais on a fini, donc true |
| 557 | 557 | } |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | ) { |
| 580 | 580 | spip_log( |
| 581 | 581 | "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
| 582 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 582 | + 'dump.'._LOG_INFO_IMPORTANTE |
|
| 583 | 583 | ); |
| 584 | 584 | |
| 585 | 585 | return true; // echec mais on a fini, donc true |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | $tables = array_diff($tables, ['spip_meta']); |
| 599 | 599 | $tables[] = 'spip_meta'; |
| 600 | 600 | } |
| 601 | - spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 601 | + spip_log('Tables a copier :'.implode(', ', $tables), 'dump.'._LOG_INFO); |
|
| 602 | 602 | |
| 603 | 603 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 604 | 604 | |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | // mais si ca renvoie false c'est une erreur fatale => abandon |
| 663 | 663 | if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
| 664 | 664 | // forcer la sortie, charge a l'appelant de gerer l'echec |
| 665 | - spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 665 | + spip_log("Erreur fatale dans $inserer_copie table $table", 'dump'._LOG_ERREUR); |
|
| 666 | 666 | $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
| 667 | 667 | ecrire_fichier($status_file, serialize($status)); |
| 668 | 668 | |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | if ($n == $status['tables_copiees'][$table]) { |
| 678 | 678 | break; |
| 679 | 679 | } |
| 680 | - spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 680 | + spip_log("recopie $table ".$status['tables_copiees'][$table], 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 681 | 681 | if ($callback_progression) { |
| 682 | 682 | $callback_progression($status['tables_copiees'][$table], 0, $table); |
| 683 | 683 | } |
@@ -688,30 +688,30 @@ discard block |
||
| 688 | 688 | } |
| 689 | 689 | if ($drop_source) { |
| 690 | 690 | sql_drop_table($table, '', $serveur_source); |
| 691 | - spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 691 | + spip_log("drop $table sur serveur source '$serveur_source'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 692 | 692 | } |
| 693 | 693 | $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
| 694 | 694 | ecrire_fichier($status_file, serialize($status)); |
| 695 | - spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 695 | + spip_log('tables_recopiees '.implode(',', array_keys($status['tables_copiees'])), 'dump.'._LOG_INFO); |
|
| 696 | 696 | if ($callback_progression) { |
| 697 | 697 | $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
| 698 | 698 | } |
| 699 | 699 | } else { |
| 700 | 700 | if ($status['tables_copiees'][$table] < 0) { |
| 701 | - spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 701 | + spip_log("Table $table deja copiee : ".$status['tables_copiees'][$table], 'dump.'._LOG_INFO); |
|
| 702 | 702 | } |
| 703 | 703 | if ($callback_progression) { |
| 704 | 704 | $callback_progression( |
| 705 | 705 | 0, |
| 706 | 706 | $status['tables_copiees'][$table], |
| 707 | - "$table" . ((is_numeric($status['tables_copiees'][$table]) && $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 707 | + "$table".((is_numeric($status['tables_copiees'][$table]) && $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 708 | 708 | ); |
| 709 | 709 | } |
| 710 | 710 | } |
| 711 | 711 | } else { |
| 712 | 712 | $status['errors'][] = "Impossible de lire la description de la table $table"; |
| 713 | 713 | ecrire_fichier($status_file, serialize($status)); |
| 714 | - spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 714 | + spip_log("Impossible de lire la description de la table $table", 'dump.'._LOG_ERREUR); |
|
| 715 | 715 | } |
| 716 | 716 | } |
| 717 | 717 | |
@@ -719,17 +719,17 @@ discard block |
||
| 719 | 719 | // abandonner |
| 720 | 720 | if ((is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) < count($tables)) { |
| 721 | 721 | spip_log( |
| 722 | - 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables), |
|
| 723 | - 'dump.' . _LOG_ERREUR |
|
| 722 | + 'Nombre de tables copiees incorrect : '.(is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0).'/'.count($tables), |
|
| 723 | + 'dump.'._LOG_ERREUR |
|
| 724 | 724 | ); |
| 725 | - $status['errors'][] = 'Nombre de tables copiees incorrect : ' . (is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0) . '/' . count($tables); |
|
| 725 | + $status['errors'][] = 'Nombre de tables copiees incorrect : '.(is_countable($status['tables_copiees']) ? count($status['tables_copiees']) : 0).'/'.count($tables); |
|
| 726 | 726 | ecrire_fichier($status_file, serialize($status)); |
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
| 730 | 730 | $detruire_copieur_si_besoin($serveur_dest); |
| 731 | 731 | } else { |
| 732 | - spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 732 | + spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | // OK, copie complete |
@@ -754,8 +754,8 @@ discard block |
||
| 754 | 754 | $nb = sql_countsel($table, '', '', '', $serveur_dest); |
| 755 | 755 | if ($nb - $nb1 < count($rows)) { |
| 756 | 756 | spip_log( |
| 757 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 758 | - 'dump' . _LOG_INFO_IMPORTANTE |
|
| 757 | + 'base_inserer_copie : '.($nb - $nb1).' insertions au lieu de '.count($rows).'. On retente 1 par 1', |
|
| 758 | + 'dump'._LOG_INFO_IMPORTANTE |
|
| 759 | 759 | ); |
| 760 | 760 | foreach ($rows as $row) { |
| 761 | 761 | // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
@@ -766,8 +766,8 @@ discard block |
||
| 766 | 766 | $nb = sql_countsel($table, '', '', '', $serveur_dest); |
| 767 | 767 | if ($nb - $nb1 < count($rows)) { |
| 768 | 768 | spip_log( |
| 769 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 770 | - 'dump' . _LOG_ERREUR |
|
| 769 | + 'base_inserer_copie : '.($nb - $nb1).' insertions au lieu de '.count($rows).' apres insertion 1 par 1', |
|
| 770 | + 'dump'._LOG_ERREUR |
|
| 771 | 771 | ); |
| 772 | 772 | $r = false; |
| 773 | 773 | } |