@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\SQL\Tables |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | include_spip('base/objets'); |
| 22 | 22 | |
@@ -64,143 +64,143 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | **/ |
| 66 | 66 | function base_trouver_table_dist($nom, $serveur = '', $table_spip = true) { |
| 67 | - static $nom_cache_desc_sql = []; |
|
| 68 | - |
|
| 69 | - if ( |
|
| 70 | - !spip_connect($serveur) |
|
| 71 | - or !preg_match('/^[a-zA-Z0-9._-]*/', $nom) |
|
| 72 | - ) { |
|
| 73 | - return null; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 77 | - $objets_sql = lister_tables_objets_sql('::md5'); |
|
| 78 | - |
|
| 79 | - // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
|
| 80 | - // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
|
| 81 | - // de connexion, et tout risque d'ambiguite |
|
| 82 | - if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 83 | - $nom_cache_desc_sql[$serveur][$objets_sql] = |
|
| 84 | - _DIR_CACHE . 'sql_desc_' |
|
| 85 | - . ($serveur ? "{$serveur}_" : '') |
|
| 86 | - . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 87 | - . '.txt'; |
|
| 88 | - // nouveau nom de cache = nouvelle version en memoire |
|
| 89 | - unset($connexion['tables']); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
|
| 93 | - if (!$nom) { |
|
| 94 | - spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
|
| 95 | - $connexion['tables'] = []; |
|
| 96 | - |
|
| 97 | - return null; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $nom_sql = $nom; |
|
| 101 | - if (preg_match('/\.(.*)$/', $nom, $s)) { |
|
| 102 | - $nom_sql = $s[1]; |
|
| 103 | - } else { |
|
| 104 | - $nom_sql = $nom; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $fdesc = $desc = ''; |
|
| 108 | - $connexion = &$GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 109 | - |
|
| 110 | - // base sous SPIP: gerer les abreviations explicites des noms de table |
|
| 111 | - if ($connexion['spip_connect_version']) { |
|
| 112 | - if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 113 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 114 | - $nom_sql = 'spip_' . $nom; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // si c'est la premiere table qu'on cherche |
|
| 119 | - // et si on est pas explicitement en recalcul |
|
| 120 | - // on essaye de recharger le cache des decriptions de ce serveur |
|
| 121 | - // dans le fichier cache |
|
| 122 | - if ( |
|
| 123 | - !isset($connexion['tables'][$nom_sql]) |
|
| 124 | - and defined('_VAR_MODE') and _VAR_MODE !== 'recalcul' |
|
| 125 | - and (!isset($connexion['tables']) or !$connexion['tables']) |
|
| 126 | - ) { |
|
| 127 | - if ( |
|
| 128 | - lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 129 | - and $desc_cache = unserialize($desc_cache) |
|
| 130 | - ) { |
|
| 131 | - $connexion['tables'] = $desc_cache; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - if ($table_spip and !isset($connexion['tables'][$nom_sql])) { |
|
| 135 | - if (isset($GLOBALS['tables_principales'][$nom_sql])) { |
|
| 136 | - $fdesc = $GLOBALS['tables_principales'][$nom_sql]; |
|
| 137 | - } |
|
| 138 | - // meme si pas d'abreviation declaree, trouver la table spip_$nom |
|
| 139 | - // si c'est une table principale, |
|
| 140 | - // puisqu'on le fait aussi pour les tables auxiliaires |
|
| 141 | - elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 142 | - $nom_sql = 'spip_' . $nom; |
|
| 143 | - $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
|
| 144 | - } elseif ( |
|
| 145 | - isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
|
| 146 | - or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 147 | - ) { |
|
| 148 | - $nom_sql = $n; |
|
| 149 | - $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
|
| 150 | - } # table locale a cote de SPIP, comme non SPIP: |
|
| 151 | - } |
|
| 152 | - if (!isset($connexion['tables'][$nom_sql])) { |
|
| 153 | - // La *vraie* base a la priorite |
|
| 154 | - $desc = sql_showtable($nom_sql, $table_spip, $serveur); |
|
| 155 | - if (!$desc or !$desc['field']) { |
|
| 156 | - if (!$fdesc) { |
|
| 157 | - spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . _LOG_INFO_IMPORTANTE); |
|
| 158 | - |
|
| 159 | - return null; |
|
| 160 | - } |
|
| 161 | - // on ne sait pas lire la structure de la table : |
|
| 162 | - // on retombe sur la description donnee dans les fichiers spip |
|
| 163 | - $desc = $fdesc; |
|
| 164 | - $desc['exist'] = false; |
|
| 165 | - } else { |
|
| 166 | - $desc['exist'] = true; |
|
| 167 | - // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
|
| 168 | - // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
|
| 169 | - if (! $desc['key']) { |
|
| 170 | - spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
|
| 171 | - unset($desc['key']); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $desc['table'] = $desc['table_sql'] = $nom_sql; |
|
| 176 | - $desc['connexion'] = $serveur; |
|
| 177 | - |
|
| 178 | - // charger les infos declarees pour cette table |
|
| 179 | - // en lui passant les infos connues |
|
| 180 | - // $desc est prioritaire pour la description de la table |
|
| 181 | - $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 182 | - // s'assurer qu'on a toujours un 'key' |
|
| 183 | - if (!isset($desc['key']) && !empty($fdesc['key'])) { |
|
| 184 | - $desc['key'] = $fdesc['key']; |
|
| 185 | - } |
|
| 186 | - if (! isset($desc['key'])) { |
|
| 187 | - $desc['key'] = []; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // si tables_objets_sql est bien fini d'init, on peut cacher |
|
| 191 | - $connexion['tables'][$nom_sql] = $desc; |
|
| 192 | - $res = &$connexion['tables'][$nom_sql]; |
|
| 193 | - // une nouvelle table a ete decrite |
|
| 194 | - // mettons donc a jour le cache des descriptions de ce serveur |
|
| 195 | - if (is_writeable(_DIR_CACHE)) { |
|
| 196 | - ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 197 | - } |
|
| 198 | - } else { |
|
| 199 | - $res = &$connexion['tables'][$nom_sql]; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // toujours retourner $nom dans id_table |
|
| 203 | - $res['id_table'] = $nom; |
|
| 204 | - |
|
| 205 | - return $res; |
|
| 67 | + static $nom_cache_desc_sql = []; |
|
| 68 | + |
|
| 69 | + if ( |
|
| 70 | + !spip_connect($serveur) |
|
| 71 | + or !preg_match('/^[a-zA-Z0-9._-]*/', $nom) |
|
| 72 | + ) { |
|
| 73 | + return null; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 77 | + $objets_sql = lister_tables_objets_sql('::md5'); |
|
| 78 | + |
|
| 79 | + // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
|
| 80 | + // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
|
| 81 | + // de connexion, et tout risque d'ambiguite |
|
| 82 | + if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 83 | + $nom_cache_desc_sql[$serveur][$objets_sql] = |
|
| 84 | + _DIR_CACHE . 'sql_desc_' |
|
| 85 | + . ($serveur ? "{$serveur}_" : '') |
|
| 86 | + . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 87 | + . '.txt'; |
|
| 88 | + // nouveau nom de cache = nouvelle version en memoire |
|
| 89 | + unset($connexion['tables']); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
|
| 93 | + if (!$nom) { |
|
| 94 | + spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
|
| 95 | + $connexion['tables'] = []; |
|
| 96 | + |
|
| 97 | + return null; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $nom_sql = $nom; |
|
| 101 | + if (preg_match('/\.(.*)$/', $nom, $s)) { |
|
| 102 | + $nom_sql = $s[1]; |
|
| 103 | + } else { |
|
| 104 | + $nom_sql = $nom; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $fdesc = $desc = ''; |
|
| 108 | + $connexion = &$GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 109 | + |
|
| 110 | + // base sous SPIP: gerer les abreviations explicites des noms de table |
|
| 111 | + if ($connexion['spip_connect_version']) { |
|
| 112 | + if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 113 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 114 | + $nom_sql = 'spip_' . $nom; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // si c'est la premiere table qu'on cherche |
|
| 119 | + // et si on est pas explicitement en recalcul |
|
| 120 | + // on essaye de recharger le cache des decriptions de ce serveur |
|
| 121 | + // dans le fichier cache |
|
| 122 | + if ( |
|
| 123 | + !isset($connexion['tables'][$nom_sql]) |
|
| 124 | + and defined('_VAR_MODE') and _VAR_MODE !== 'recalcul' |
|
| 125 | + and (!isset($connexion['tables']) or !$connexion['tables']) |
|
| 126 | + ) { |
|
| 127 | + if ( |
|
| 128 | + lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 129 | + and $desc_cache = unserialize($desc_cache) |
|
| 130 | + ) { |
|
| 131 | + $connexion['tables'] = $desc_cache; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + if ($table_spip and !isset($connexion['tables'][$nom_sql])) { |
|
| 135 | + if (isset($GLOBALS['tables_principales'][$nom_sql])) { |
|
| 136 | + $fdesc = $GLOBALS['tables_principales'][$nom_sql]; |
|
| 137 | + } |
|
| 138 | + // meme si pas d'abreviation declaree, trouver la table spip_$nom |
|
| 139 | + // si c'est une table principale, |
|
| 140 | + // puisqu'on le fait aussi pour les tables auxiliaires |
|
| 141 | + elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 142 | + $nom_sql = 'spip_' . $nom; |
|
| 143 | + $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
|
| 144 | + } elseif ( |
|
| 145 | + isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
|
| 146 | + or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 147 | + ) { |
|
| 148 | + $nom_sql = $n; |
|
| 149 | + $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
|
| 150 | + } # table locale a cote de SPIP, comme non SPIP: |
|
| 151 | + } |
|
| 152 | + if (!isset($connexion['tables'][$nom_sql])) { |
|
| 153 | + // La *vraie* base a la priorite |
|
| 154 | + $desc = sql_showtable($nom_sql, $table_spip, $serveur); |
|
| 155 | + if (!$desc or !$desc['field']) { |
|
| 156 | + if (!$fdesc) { |
|
| 157 | + spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . _LOG_INFO_IMPORTANTE); |
|
| 158 | + |
|
| 159 | + return null; |
|
| 160 | + } |
|
| 161 | + // on ne sait pas lire la structure de la table : |
|
| 162 | + // on retombe sur la description donnee dans les fichiers spip |
|
| 163 | + $desc = $fdesc; |
|
| 164 | + $desc['exist'] = false; |
|
| 165 | + } else { |
|
| 166 | + $desc['exist'] = true; |
|
| 167 | + // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
|
| 168 | + // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
|
| 169 | + if (! $desc['key']) { |
|
| 170 | + spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
|
| 171 | + unset($desc['key']); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $desc['table'] = $desc['table_sql'] = $nom_sql; |
|
| 176 | + $desc['connexion'] = $serveur; |
|
| 177 | + |
|
| 178 | + // charger les infos declarees pour cette table |
|
| 179 | + // en lui passant les infos connues |
|
| 180 | + // $desc est prioritaire pour la description de la table |
|
| 181 | + $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 182 | + // s'assurer qu'on a toujours un 'key' |
|
| 183 | + if (!isset($desc['key']) && !empty($fdesc['key'])) { |
|
| 184 | + $desc['key'] = $fdesc['key']; |
|
| 185 | + } |
|
| 186 | + if (! isset($desc['key'])) { |
|
| 187 | + $desc['key'] = []; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // si tables_objets_sql est bien fini d'init, on peut cacher |
|
| 191 | + $connexion['tables'][$nom_sql] = $desc; |
|
| 192 | + $res = &$connexion['tables'][$nom_sql]; |
|
| 193 | + // une nouvelle table a ete decrite |
|
| 194 | + // mettons donc a jour le cache des descriptions de ce serveur |
|
| 195 | + if (is_writeable(_DIR_CACHE)) { |
|
| 196 | + ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 197 | + } |
|
| 198 | + } else { |
|
| 199 | + $res = &$connexion['tables'][$nom_sql]; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // toujours retourner $nom dans id_table |
|
| 203 | + $res['id_table'] = $nom; |
|
| 204 | + |
|
| 205 | + return $res; |
|
| 206 | 206 | } |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | // de connexion, et tout risque d'ambiguite |
| 82 | 82 | if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
| 83 | 83 | $nom_cache_desc_sql[$serveur][$objets_sql] = |
| 84 | - _DIR_CACHE . 'sql_desc_' |
|
| 84 | + _DIR_CACHE.'sql_desc_' |
|
| 85 | 85 | . ($serveur ? "{$serveur}_" : '') |
| 86 | - . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 86 | + . substr(md5($connexion['db'].':'.$connexion['prefixe'].":$objets_sql"), 0, 8) |
|
| 87 | 87 | . '.txt'; |
| 88 | 88 | // nouveau nom de cache = nouvelle version en memoire |
| 89 | 89 | unset($connexion['tables']); |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | if ($connexion['spip_connect_version']) { |
| 112 | 112 | if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
| 113 | 113 | $nom = $GLOBALS['table_des_tables'][$nom]; |
| 114 | - $nom_sql = 'spip_' . $nom; |
|
| 114 | + $nom_sql = 'spip_'.$nom; |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | // meme si pas d'abreviation declaree, trouver la table spip_$nom |
| 139 | 139 | // si c'est une table principale, |
| 140 | 140 | // puisqu'on le fait aussi pour les tables auxiliaires |
| 141 | - elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 142 | - $nom_sql = 'spip_' . $nom; |
|
| 141 | + elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_'.$nom])) { |
|
| 142 | + $nom_sql = 'spip_'.$nom; |
|
| 143 | 143 | $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
| 144 | 144 | } elseif ( |
| 145 | 145 | isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
| 146 | - or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 146 | + or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_'.$nom]) |
|
| 147 | 147 | ) { |
| 148 | 148 | $nom_sql = $n; |
| 149 | 149 | $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | $desc = sql_showtable($nom_sql, $table_spip, $serveur); |
| 155 | 155 | if (!$desc or !$desc['field']) { |
| 156 | 156 | if (!$fdesc) { |
| 157 | - spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . _LOG_INFO_IMPORTANTE); |
|
| 157 | + spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base'._LOG_INFO_IMPORTANTE); |
|
| 158 | 158 | |
| 159 | 159 | return null; |
| 160 | 160 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | $desc['exist'] = true; |
| 167 | 167 | // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
| 168 | 168 | // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
| 169 | - if (! $desc['key']) { |
|
| 169 | + if (!$desc['key']) { |
|
| 170 | 170 | spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
| 171 | 171 | unset($desc['key']); |
| 172 | 172 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | if (!isset($desc['key']) && !empty($fdesc['key'])) { |
| 184 | 184 | $desc['key'] = $fdesc['key']; |
| 185 | 185 | } |
| 186 | - if (! isset($desc['key'])) { |
|
| 186 | + if (!isset($desc['key'])) { |
|
| 187 | 187 | $desc['key'] = []; |
| 188 | 188 | } |
| 189 | 189 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | * @return void |
| 33 | 33 | **/ |
| 34 | 34 | function array_set_merge(&$table, $index, $valeur) { |
| 35 | - if (!isset($table[$index])) { |
|
| 36 | - $table[$index] = $valeur; |
|
| 37 | - } else { |
|
| 38 | - $table[$index] = array_merge($table[$index], $valeur); |
|
| 39 | - } |
|
| 35 | + if (!isset($table[$index])) { |
|
| 36 | + $table[$index] = $valeur; |
|
| 37 | + } else { |
|
| 38 | + $table[$index] = array_merge($table[$index], $valeur); |
|
| 39 | + } |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -53,440 +53,440 @@ discard block |
||
| 53 | 53 | * @return array|bool |
| 54 | 54 | */ |
| 55 | 55 | function lister_tables_objets_sql($table_sql = null, $desc = []) { |
| 56 | - static $deja_la = false; |
|
| 57 | - static $infos_tables = null; |
|
| 58 | - static $md5 = null; |
|
| 59 | - static $plugin_hash = null; |
|
| 60 | - |
|
| 61 | - // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 62 | - $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 63 | - |
|
| 64 | - // prealablement recuperer les tables_principales |
|
| 65 | - if (is_null($infos_tables) or $plugin_hash !== $_PLUGINS_HASH) { |
|
| 66 | - // pas de reentrance (cas base/serial) |
|
| 67 | - if ($deja_la) { |
|
| 68 | - spip_log('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 69 | - . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 70 | - |
|
| 71 | - return ($table_sql === '::md5' ? $md5 : []); |
|
| 72 | - } |
|
| 73 | - $deja_la = true; |
|
| 74 | - $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 75 | - |
|
| 76 | - // recuperer les declarations explicites ancienne mode |
|
| 77 | - // qui servent a completer declarer_tables_objets_sql |
|
| 78 | - base_serial($GLOBALS['tables_principales']); |
|
| 79 | - base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 80 | - $infos_tables = [ |
|
| 81 | - 'spip_articles' => [ |
|
| 82 | - 'page' => 'article', |
|
| 83 | - 'texte_retour' => 'icone_retour_article', |
|
| 84 | - 'texte_modifier' => 'icone_modifier_article', |
|
| 85 | - 'texte_creer' => 'icone_ecrire_article', |
|
| 86 | - 'texte_objets' => 'public:articles', |
|
| 87 | - 'texte_objet' => 'public:article', |
|
| 88 | - 'texte_signale_edition' => 'texte_travail_article', |
|
| 89 | - 'info_aucun_objet' => 'info_aucun_article', |
|
| 90 | - 'info_1_objet' => 'info_1_article', |
|
| 91 | - 'info_nb_objets' => 'info_nb_articles', |
|
| 92 | - 'texte_logo_objet' => 'logo_article', |
|
| 93 | - 'texte_langue_objet' => 'titre_langue_article', |
|
| 94 | - 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 95 | - 'titre' => 'titre, lang', |
|
| 96 | - 'date' => 'date', |
|
| 97 | - 'principale' => 'oui', |
|
| 98 | - 'introduction_longueur' => '500', |
|
| 99 | - 'champs_editables' => [ |
|
| 100 | - 'surtitre', |
|
| 101 | - 'titre', |
|
| 102 | - 'soustitre', |
|
| 103 | - 'descriptif', |
|
| 104 | - 'nom_site', |
|
| 105 | - 'url_site', |
|
| 106 | - 'chapo', |
|
| 107 | - 'texte', |
|
| 108 | - 'ps', |
|
| 109 | - 'virtuel' |
|
| 110 | - ], |
|
| 111 | - 'champs_versionnes' => [ |
|
| 112 | - 'id_rubrique', |
|
| 113 | - 'surtitre', |
|
| 114 | - 'titre', |
|
| 115 | - 'soustitre', |
|
| 116 | - 'jointure_auteurs', |
|
| 117 | - 'descriptif', |
|
| 118 | - 'nom_site', |
|
| 119 | - 'url_site', |
|
| 120 | - 'chapo', |
|
| 121 | - 'texte', |
|
| 122 | - 'ps' |
|
| 123 | - ], |
|
| 124 | - 'field' => [ |
|
| 125 | - 'id_article' => 'bigint(21) NOT NULL', |
|
| 126 | - 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 127 | - 'titre' => "text DEFAULT '' NOT NULL", |
|
| 128 | - 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 129 | - 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 130 | - 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 131 | - 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 132 | - 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 133 | - 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 134 | - 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 135 | - 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 136 | - 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 137 | - 'maj' => 'TIMESTAMP', |
|
| 138 | - 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 139 | - 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 140 | - 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 141 | - 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 142 | - 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 143 | - 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 144 | - 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 145 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 146 | - 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 147 | - 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 148 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 149 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 150 | - 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 151 | - ], |
|
| 152 | - 'key' => [ |
|
| 153 | - 'PRIMARY KEY' => 'id_article', |
|
| 154 | - 'KEY id_rubrique' => 'id_rubrique', |
|
| 155 | - 'KEY id_secteur' => 'id_secteur', |
|
| 156 | - 'KEY id_trad' => 'id_trad', |
|
| 157 | - 'KEY lang' => 'lang', |
|
| 158 | - 'KEY statut' => 'statut, date', |
|
| 159 | - ], |
|
| 160 | - 'join' => [ |
|
| 161 | - 'id_article' => 'id_article', |
|
| 162 | - 'id_rubrique' => 'id_rubrique' |
|
| 163 | - ], |
|
| 164 | - 'parent' => [ |
|
| 165 | - ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 166 | - ], |
|
| 167 | - 'rechercher_champs' => [ |
|
| 168 | - 'surtitre' => 5, |
|
| 169 | - 'titre' => 8, |
|
| 170 | - 'soustitre' => 5, |
|
| 171 | - 'chapo' => 3, |
|
| 172 | - 'texte' => 1, |
|
| 173 | - 'ps' => 1, |
|
| 174 | - 'nom_site' => 1, |
|
| 175 | - 'url_site' => 1, |
|
| 176 | - 'descriptif' => 4 |
|
| 177 | - ], |
|
| 178 | - 'rechercher_jointures' => [ |
|
| 179 | - 'auteur' => ['nom' => 10], |
|
| 180 | - ], |
|
| 181 | - 'statut' => [ |
|
| 182 | - [ |
|
| 183 | - 'champ' => 'statut', |
|
| 184 | - 'publie' => 'publie', |
|
| 185 | - 'previsu' => 'publie,prop,prepa/auteur', |
|
| 186 | - 'post_date' => 'date', |
|
| 187 | - 'exception' => ['statut', 'tout'] |
|
| 188 | - ] |
|
| 189 | - ], |
|
| 190 | - 'statut_titres' => [ |
|
| 191 | - 'prepa' => 'info_article_redaction', |
|
| 192 | - 'prop' => 'info_article_propose', |
|
| 193 | - 'publie' => 'info_article_publie', |
|
| 194 | - 'refuse' => 'info_article_refuse', |
|
| 195 | - 'poubelle' => 'info_article_supprime' |
|
| 196 | - ], |
|
| 197 | - 'statut_textes_instituer' => [ |
|
| 198 | - 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 199 | - 'prop' => 'texte_statut_propose_evaluation', |
|
| 200 | - 'publie' => 'texte_statut_publie', |
|
| 201 | - 'refuse' => 'texte_statut_refuse', |
|
| 202 | - 'poubelle' => 'texte_statut_poubelle', |
|
| 203 | - ], |
|
| 204 | - 'texte_changer_statut' => 'texte_article_statut', |
|
| 205 | - 'aide_changer_statut' => 'artstatut', |
|
| 206 | - 'tables_jointures' => [ |
|
| 207 | - 'profondeur' => 'rubriques', |
|
| 208 | - #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 209 | - ], |
|
| 210 | - ], |
|
| 211 | - 'spip_auteurs' => [ |
|
| 212 | - 'page' => 'auteur', |
|
| 213 | - 'texte_retour' => 'icone_retour', |
|
| 214 | - 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 215 | - 'texte_modifier' => 'admin_modifier_auteur', |
|
| 216 | - 'texte_objets' => 'icone_auteurs', |
|
| 217 | - 'texte_objet' => 'public:auteur', |
|
| 218 | - 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 219 | - 'info_1_objet' => 'info_1_auteur', |
|
| 220 | - 'info_nb_objets' => 'info_nb_auteurs', |
|
| 221 | - 'texte_logo_objet' => 'logo_auteur', |
|
| 222 | - 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 223 | - 'titre' => "nom AS titre, '' AS lang", |
|
| 224 | - 'date' => 'date', |
|
| 225 | - 'principale' => 'oui', |
|
| 226 | - 'champs_editables' => ['nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'], |
|
| 227 | - 'champs_versionnes' => ['nom', 'bio', 'email', 'nom_site', 'url_site', 'login'], |
|
| 228 | - 'field' => [ |
|
| 229 | - 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 230 | - 'nom' => "text DEFAULT '' NOT NULL", |
|
| 231 | - 'bio' => "text DEFAULT '' NOT NULL", |
|
| 232 | - 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 233 | - 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 234 | - 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 235 | - 'login' => 'VARCHAR(255) BINARY', |
|
| 236 | - 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 237 | - 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 238 | - 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 239 | - 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 240 | - 'maj' => 'TIMESTAMP', |
|
| 241 | - 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 242 | - 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 243 | - 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 244 | - 'alea_actuel' => 'tinytext', |
|
| 245 | - 'alea_futur' => 'tinytext', |
|
| 246 | - 'prefs' => 'text', |
|
| 247 | - 'cookie_oubli' => 'tinytext', |
|
| 248 | - 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 249 | - 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 250 | - 'imessage' => "VARCHAR(3) 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 ($all as $i => $v) { |
|
| 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' and isset($infos_tables[$t][$i]) and count($infos_tables[$t][$i])) { |
|
| 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 | - and is_numeric($k = array_search($d, $add)) |
|
| 414 | - ) { |
|
| 415 | - unset($add[$k]); |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - $infos_tables[$t][$i] = array_merge(isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : [], $add); |
|
| 420 | - } else { |
|
| 421 | - $infos_tables[$t][$i] = array_merge_recursive( |
|
| 422 | - isset($infos_tables[$t][$i]) ? $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 = (isset($GLOBALS[$principale_ou_auxiliaire][$table]) ? $GLOBALS[$principale_ou_auxiliaire][$table] : []); |
|
| 437 | - // l'ajouter au tableau |
|
| 438 | - $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 439 | - if (isset($infos['field']) and 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 (count($mem)) { |
|
| 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 and !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 isset($infos_tables[$table_sql]) ? $infos_tables[$table_sql] : []; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - return $infos_tables; |
|
| 56 | + static $deja_la = false; |
|
| 57 | + static $infos_tables = null; |
|
| 58 | + static $md5 = null; |
|
| 59 | + static $plugin_hash = null; |
|
| 60 | + |
|
| 61 | + // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé. |
|
| 62 | + $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT'; |
|
| 63 | + |
|
| 64 | + // prealablement recuperer les tables_principales |
|
| 65 | + if (is_null($infos_tables) or $plugin_hash !== $_PLUGINS_HASH) { |
|
| 66 | + // pas de reentrance (cas base/serial) |
|
| 67 | + if ($deja_la) { |
|
| 68 | + spip_log('Re-entrance anormale sur lister_tables_objets_sql : ' |
|
| 69 | + . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 70 | + |
|
| 71 | + return ($table_sql === '::md5' ? $md5 : []); |
|
| 72 | + } |
|
| 73 | + $deja_la = true; |
|
| 74 | + $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines |
|
| 75 | + |
|
| 76 | + // recuperer les declarations explicites ancienne mode |
|
| 77 | + // qui servent a completer declarer_tables_objets_sql |
|
| 78 | + base_serial($GLOBALS['tables_principales']); |
|
| 79 | + base_auxiliaires($GLOBALS['tables_auxiliaires']); |
|
| 80 | + $infos_tables = [ |
|
| 81 | + 'spip_articles' => [ |
|
| 82 | + 'page' => 'article', |
|
| 83 | + 'texte_retour' => 'icone_retour_article', |
|
| 84 | + 'texte_modifier' => 'icone_modifier_article', |
|
| 85 | + 'texte_creer' => 'icone_ecrire_article', |
|
| 86 | + 'texte_objets' => 'public:articles', |
|
| 87 | + 'texte_objet' => 'public:article', |
|
| 88 | + 'texte_signale_edition' => 'texte_travail_article', |
|
| 89 | + 'info_aucun_objet' => 'info_aucun_article', |
|
| 90 | + 'info_1_objet' => 'info_1_article', |
|
| 91 | + 'info_nb_objets' => 'info_nb_articles', |
|
| 92 | + 'texte_logo_objet' => 'logo_article', |
|
| 93 | + 'texte_langue_objet' => 'titre_langue_article', |
|
| 94 | + 'texte_definir_comme_traduction_objet' => 'trad_lier', |
|
| 95 | + 'titre' => 'titre, lang', |
|
| 96 | + 'date' => 'date', |
|
| 97 | + 'principale' => 'oui', |
|
| 98 | + 'introduction_longueur' => '500', |
|
| 99 | + 'champs_editables' => [ |
|
| 100 | + 'surtitre', |
|
| 101 | + 'titre', |
|
| 102 | + 'soustitre', |
|
| 103 | + 'descriptif', |
|
| 104 | + 'nom_site', |
|
| 105 | + 'url_site', |
|
| 106 | + 'chapo', |
|
| 107 | + 'texte', |
|
| 108 | + 'ps', |
|
| 109 | + 'virtuel' |
|
| 110 | + ], |
|
| 111 | + 'champs_versionnes' => [ |
|
| 112 | + 'id_rubrique', |
|
| 113 | + 'surtitre', |
|
| 114 | + 'titre', |
|
| 115 | + 'soustitre', |
|
| 116 | + 'jointure_auteurs', |
|
| 117 | + 'descriptif', |
|
| 118 | + 'nom_site', |
|
| 119 | + 'url_site', |
|
| 120 | + 'chapo', |
|
| 121 | + 'texte', |
|
| 122 | + 'ps' |
|
| 123 | + ], |
|
| 124 | + 'field' => [ |
|
| 125 | + 'id_article' => 'bigint(21) NOT NULL', |
|
| 126 | + 'surtitre' => "text DEFAULT '' NOT NULL", |
|
| 127 | + 'titre' => "text DEFAULT '' NOT NULL", |
|
| 128 | + 'soustitre' => "text DEFAULT '' NOT NULL", |
|
| 129 | + 'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 130 | + 'descriptif' => "text DEFAULT '' NOT NULL", |
|
| 131 | + 'chapo' => "mediumtext DEFAULT '' NOT NULL", |
|
| 132 | + 'texte' => "longtext DEFAULT '' NOT NULL", |
|
| 133 | + 'ps' => "mediumtext DEFAULT '' NOT NULL", |
|
| 134 | + 'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 135 | + 'statut' => "varchar(10) DEFAULT '0' NOT NULL", |
|
| 136 | + 'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 137 | + 'maj' => 'TIMESTAMP', |
|
| 138 | + 'export' => "VARCHAR(10) DEFAULT 'oui'", |
|
| 139 | + 'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 140 | + 'visites' => "integer DEFAULT '0' NOT NULL", |
|
| 141 | + 'referers' => "integer DEFAULT '0' NOT NULL", |
|
| 142 | + 'popularite' => "DOUBLE DEFAULT '0' NOT NULL", |
|
| 143 | + 'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL", |
|
| 144 | + 'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 145 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 146 | + 'langue_choisie' => "VARCHAR(3) DEFAULT 'non'", |
|
| 147 | + 'id_trad' => "bigint(21) DEFAULT '0' NOT NULL", |
|
| 148 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 149 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 150 | + 'virtuel' => "text DEFAULT '' NOT NULL", |
|
| 151 | + ], |
|
| 152 | + 'key' => [ |
|
| 153 | + 'PRIMARY KEY' => 'id_article', |
|
| 154 | + 'KEY id_rubrique' => 'id_rubrique', |
|
| 155 | + 'KEY id_secteur' => 'id_secteur', |
|
| 156 | + 'KEY id_trad' => 'id_trad', |
|
| 157 | + 'KEY lang' => 'lang', |
|
| 158 | + 'KEY statut' => 'statut, date', |
|
| 159 | + ], |
|
| 160 | + 'join' => [ |
|
| 161 | + 'id_article' => 'id_article', |
|
| 162 | + 'id_rubrique' => 'id_rubrique' |
|
| 163 | + ], |
|
| 164 | + 'parent' => [ |
|
| 165 | + ['type' => 'rubrique', 'champ' => 'id_rubrique'] |
|
| 166 | + ], |
|
| 167 | + 'rechercher_champs' => [ |
|
| 168 | + 'surtitre' => 5, |
|
| 169 | + 'titre' => 8, |
|
| 170 | + 'soustitre' => 5, |
|
| 171 | + 'chapo' => 3, |
|
| 172 | + 'texte' => 1, |
|
| 173 | + 'ps' => 1, |
|
| 174 | + 'nom_site' => 1, |
|
| 175 | + 'url_site' => 1, |
|
| 176 | + 'descriptif' => 4 |
|
| 177 | + ], |
|
| 178 | + 'rechercher_jointures' => [ |
|
| 179 | + 'auteur' => ['nom' => 10], |
|
| 180 | + ], |
|
| 181 | + 'statut' => [ |
|
| 182 | + [ |
|
| 183 | + 'champ' => 'statut', |
|
| 184 | + 'publie' => 'publie', |
|
| 185 | + 'previsu' => 'publie,prop,prepa/auteur', |
|
| 186 | + 'post_date' => 'date', |
|
| 187 | + 'exception' => ['statut', 'tout'] |
|
| 188 | + ] |
|
| 189 | + ], |
|
| 190 | + 'statut_titres' => [ |
|
| 191 | + 'prepa' => 'info_article_redaction', |
|
| 192 | + 'prop' => 'info_article_propose', |
|
| 193 | + 'publie' => 'info_article_publie', |
|
| 194 | + 'refuse' => 'info_article_refuse', |
|
| 195 | + 'poubelle' => 'info_article_supprime' |
|
| 196 | + ], |
|
| 197 | + 'statut_textes_instituer' => [ |
|
| 198 | + 'prepa' => 'texte_statut_en_cours_redaction', |
|
| 199 | + 'prop' => 'texte_statut_propose_evaluation', |
|
| 200 | + 'publie' => 'texte_statut_publie', |
|
| 201 | + 'refuse' => 'texte_statut_refuse', |
|
| 202 | + 'poubelle' => 'texte_statut_poubelle', |
|
| 203 | + ], |
|
| 204 | + 'texte_changer_statut' => 'texte_article_statut', |
|
| 205 | + 'aide_changer_statut' => 'artstatut', |
|
| 206 | + 'tables_jointures' => [ |
|
| 207 | + 'profondeur' => 'rubriques', |
|
| 208 | + #'id_auteur' => 'auteurs_liens' // declaration generique plus bas |
|
| 209 | + ], |
|
| 210 | + ], |
|
| 211 | + 'spip_auteurs' => [ |
|
| 212 | + 'page' => 'auteur', |
|
| 213 | + 'texte_retour' => 'icone_retour', |
|
| 214 | + 'texte_ajouter' => 'titre_ajouter_un_auteur', |
|
| 215 | + 'texte_modifier' => 'admin_modifier_auteur', |
|
| 216 | + 'texte_objets' => 'icone_auteurs', |
|
| 217 | + 'texte_objet' => 'public:auteur', |
|
| 218 | + 'info_aucun_objet' => 'info_aucun_auteur', |
|
| 219 | + 'info_1_objet' => 'info_1_auteur', |
|
| 220 | + 'info_nb_objets' => 'info_nb_auteurs', |
|
| 221 | + 'texte_logo_objet' => 'logo_auteur', |
|
| 222 | + 'texte_creer_associer' => 'creer_et_associer_un_auteur', |
|
| 223 | + 'titre' => "nom AS titre, '' AS lang", |
|
| 224 | + 'date' => 'date', |
|
| 225 | + 'principale' => 'oui', |
|
| 226 | + 'champs_editables' => ['nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'], |
|
| 227 | + 'champs_versionnes' => ['nom', 'bio', 'email', 'nom_site', 'url_site', 'login'], |
|
| 228 | + 'field' => [ |
|
| 229 | + 'id_auteur' => 'bigint(21) NOT NULL', |
|
| 230 | + 'nom' => "text DEFAULT '' NOT NULL", |
|
| 231 | + 'bio' => "text DEFAULT '' NOT NULL", |
|
| 232 | + 'email' => "tinytext DEFAULT '' NOT NULL", |
|
| 233 | + 'nom_site' => "tinytext DEFAULT '' NOT NULL", |
|
| 234 | + 'url_site' => "text DEFAULT '' NOT NULL", |
|
| 235 | + 'login' => 'VARCHAR(255) BINARY', |
|
| 236 | + 'pass' => "tinytext DEFAULT '' NOT NULL", |
|
| 237 | + 'low_sec' => "tinytext DEFAULT '' NOT NULL", |
|
| 238 | + 'statut' => "varchar(255) DEFAULT '0' NOT NULL", |
|
| 239 | + 'webmestre' => "varchar(3) DEFAULT 'non' NOT NULL", |
|
| 240 | + 'maj' => 'TIMESTAMP', |
|
| 241 | + 'pgp' => "TEXT DEFAULT '' NOT NULL", |
|
| 242 | + 'htpass' => "tinytext DEFAULT '' NOT NULL", |
|
| 243 | + 'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", |
|
| 244 | + 'alea_actuel' => 'tinytext', |
|
| 245 | + 'alea_futur' => 'tinytext', |
|
| 246 | + 'prefs' => 'text', |
|
| 247 | + 'cookie_oubli' => 'tinytext', |
|
| 248 | + 'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL", |
|
| 249 | + 'lang' => "VARCHAR(10) DEFAULT '' NOT NULL", |
|
| 250 | + 'imessage' => "VARCHAR(3) 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 ($all as $i => $v) { |
|
| 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' and isset($infos_tables[$t][$i]) and count($infos_tables[$t][$i])) { |
|
| 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 | + and is_numeric($k = array_search($d, $add)) |
|
| 414 | + ) { |
|
| 415 | + unset($add[$k]); |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + $infos_tables[$t][$i] = array_merge(isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : [], $add); |
|
| 420 | + } else { |
|
| 421 | + $infos_tables[$t][$i] = array_merge_recursive( |
|
| 422 | + isset($infos_tables[$t][$i]) ? $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 = (isset($GLOBALS[$principale_ou_auxiliaire][$table]) ? $GLOBALS[$principale_ou_auxiliaire][$table] : []); |
|
| 437 | + // l'ajouter au tableau |
|
| 438 | + $GLOBALS[$principale_ou_auxiliaire][$table] = []; |
|
| 439 | + if (isset($infos['field']) and 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 (count($mem)) { |
|
| 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 and !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 isset($infos_tables[$table_sql]) ? $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(',', $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'] and $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'] and $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(',', $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'] and $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'] and $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,32 +793,32 @@ 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']) and 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']) and 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 | - if (!isset($infos['statut'])) { |
|
| 812 | - $infos['statut'] = isset($GLOBALS['table_statut'][$table_sql]) ? $GLOBALS['table_statut'][$table_sql] : ''; |
|
| 813 | - } |
|
| 814 | - if (!isset($infos['tables_jointures'])) { |
|
| 815 | - $infos['tables_jointures'] = []; |
|
| 816 | - } |
|
| 817 | - if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 818 | - $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - return $infos; |
|
| 796 | + if (!isset($infos['titre'])) { |
|
| 797 | + if (isset($infos['table_objet']) and 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']) and 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 | + if (!isset($infos['statut'])) { |
|
| 812 | + $infos['statut'] = isset($GLOBALS['table_statut'][$table_sql]) ? $GLOBALS['table_statut'][$table_sql] : ''; |
|
| 813 | + } |
|
| 814 | + if (!isset($infos['tables_jointures'])) { |
|
| 815 | + $infos['tables_jointures'] = []; |
|
| 816 | + } |
|
| 817 | + if (isset($GLOBALS['tables_jointures'][$table_sql])) { |
|
| 818 | + $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + return $infos; |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | /** |
@@ -829,13 +829,13 @@ discard block |
||
| 829 | 829 | * Liste et descriptions des tables principales |
| 830 | 830 | **/ |
| 831 | 831 | function lister_tables_principales() { |
| 832 | - static $done = false; |
|
| 833 | - if (!$done or !count($GLOBALS['tables_principales'])) { |
|
| 834 | - lister_tables_objets_sql(); |
|
| 835 | - $done = true; |
|
| 836 | - } |
|
| 832 | + static $done = false; |
|
| 833 | + if (!$done or !count($GLOBALS['tables_principales'])) { |
|
| 834 | + lister_tables_objets_sql(); |
|
| 835 | + $done = true; |
|
| 836 | + } |
|
| 837 | 837 | |
| 838 | - return $GLOBALS['tables_principales']; |
|
| 838 | + return $GLOBALS['tables_principales']; |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | /** |
@@ -846,13 +846,13 @@ discard block |
||
| 846 | 846 | * Liste et descriptions des tables auxiliaires |
| 847 | 847 | **/ |
| 848 | 848 | function lister_tables_auxiliaires() { |
| 849 | - static $done = false; |
|
| 850 | - if (!$done or !count($GLOBALS['tables_auxiliaires'])) { |
|
| 851 | - lister_tables_objets_sql(); |
|
| 852 | - $done = true; |
|
| 853 | - } |
|
| 849 | + static $done = false; |
|
| 850 | + if (!$done or !count($GLOBALS['tables_auxiliaires'])) { |
|
| 851 | + lister_tables_objets_sql(); |
|
| 852 | + $done = true; |
|
| 853 | + } |
|
| 854 | 854 | |
| 855 | - return $GLOBALS['tables_auxiliaires']; |
|
| 855 | + return $GLOBALS['tables_auxiliaires']; |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | /** |
@@ -861,45 +861,45 @@ discard block |
||
| 861 | 861 | * @return array |
| 862 | 862 | */ |
| 863 | 863 | function lister_tables_objets_surnoms() { |
| 864 | - static $surnoms = null; |
|
| 865 | - static $md5 = null; |
|
| 866 | - if ( |
|
| 867 | - !$surnoms |
|
| 868 | - or $md5 != lister_tables_objets_sql('::md5') |
|
| 869 | - ) { |
|
| 870 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 871 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 872 | - // declarer_table_objets_sql |
|
| 873 | - $surnoms = pipeline( |
|
| 874 | - 'declarer_tables_objets_surnoms', |
|
| 875 | - [ |
|
| 876 | - # pour les modeles |
|
| 877 | - # a enlever ? |
|
| 878 | - 'doc' => 'documents', |
|
| 879 | - 'img' => 'documents', |
|
| 880 | - 'emb' => 'documents', |
|
| 881 | - ] |
|
| 882 | - ); |
|
| 883 | - $infos_tables = lister_tables_objets_sql(); |
|
| 884 | - foreach ($infos_tables as $t => $infos) { |
|
| 885 | - // cas de base type=>table |
|
| 886 | - // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 887 | - if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 888 | - // optimisations pour table_objet |
|
| 889 | - //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 890 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet']; |
|
| 891 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet']; |
|
| 892 | - if (is_array($infos['table_objet_surnoms']) and count($infos['table_objet_surnoms'])) { |
|
| 893 | - foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 894 | - $surnoms[$surnom] = $infos['table_objet']; |
|
| 895 | - } |
|
| 896 | - } |
|
| 897 | - } |
|
| 898 | - } |
|
| 899 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - return $surnoms; |
|
| 864 | + static $surnoms = null; |
|
| 865 | + static $md5 = null; |
|
| 866 | + if ( |
|
| 867 | + !$surnoms |
|
| 868 | + or $md5 != lister_tables_objets_sql('::md5') |
|
| 869 | + ) { |
|
| 870 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 871 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 872 | + // declarer_table_objets_sql |
|
| 873 | + $surnoms = pipeline( |
|
| 874 | + 'declarer_tables_objets_surnoms', |
|
| 875 | + [ |
|
| 876 | + # pour les modeles |
|
| 877 | + # a enlever ? |
|
| 878 | + 'doc' => 'documents', |
|
| 879 | + 'img' => 'documents', |
|
| 880 | + 'emb' => 'documents', |
|
| 881 | + ] |
|
| 882 | + ); |
|
| 883 | + $infos_tables = lister_tables_objets_sql(); |
|
| 884 | + foreach ($infos_tables as $t => $infos) { |
|
| 885 | + // cas de base type=>table |
|
| 886 | + // et preg_replace(',^spip_|^id_|s$,',table)=>table |
|
| 887 | + if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 888 | + // optimisations pour table_objet |
|
| 889 | + //$surnoms[$infos['type']] = $infos['table_objet']; |
|
| 890 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet']; |
|
| 891 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet']; |
|
| 892 | + if (is_array($infos['table_objet_surnoms']) and count($infos['table_objet_surnoms'])) { |
|
| 893 | + foreach ($infos['table_objet_surnoms'] as $surnom) { |
|
| 894 | + $surnoms[$surnom] = $infos['table_objet']; |
|
| 895 | + } |
|
| 896 | + } |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + return $surnoms; |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | /** |
@@ -908,35 +908,35 @@ discard block |
||
| 908 | 908 | * @return array |
| 909 | 909 | */ |
| 910 | 910 | function lister_types_surnoms() { |
| 911 | - static $surnoms = null; |
|
| 912 | - static $md5 = null; |
|
| 913 | - if ( |
|
| 914 | - !$surnoms |
|
| 915 | - or $md5 != lister_tables_objets_sql('::md5') |
|
| 916 | - ) { |
|
| 917 | - // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 918 | - // pour compatibilite, car il faut dorenavent utiliser |
|
| 919 | - // declarer_table_objets_sql |
|
| 920 | - $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']); |
|
| 921 | - $infos_tables = lister_tables_objets_sql(); |
|
| 922 | - foreach ($infos_tables as $t => $infos) { |
|
| 923 | - if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 924 | - // optimisations pour objet_type |
|
| 925 | - //$surnoms[$infos['type']] = $infos['type']; |
|
| 926 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type']; |
|
| 927 | - $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type']; |
|
| 928 | - // surnoms declares |
|
| 929 | - if (is_array($infos['type_surnoms']) and count($infos['type_surnoms'])) { |
|
| 930 | - foreach ($infos['type_surnoms'] as $surnom) { |
|
| 931 | - $surnoms[$surnom] = $infos['type']; |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - } |
|
| 936 | - $md5 = lister_tables_objets_sql('::md5'); |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - return $surnoms; |
|
| 911 | + static $surnoms = null; |
|
| 912 | + static $md5 = null; |
|
| 913 | + if ( |
|
| 914 | + !$surnoms |
|
| 915 | + or $md5 != lister_tables_objets_sql('::md5') |
|
| 916 | + ) { |
|
| 917 | + // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
|
| 918 | + // pour compatibilite, car il faut dorenavent utiliser |
|
| 919 | + // declarer_table_objets_sql |
|
| 920 | + $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']); |
|
| 921 | + $infos_tables = lister_tables_objets_sql(); |
|
| 922 | + foreach ($infos_tables as $t => $infos) { |
|
| 923 | + if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 924 | + // optimisations pour objet_type |
|
| 925 | + //$surnoms[$infos['type']] = $infos['type']; |
|
| 926 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type']; |
|
| 927 | + $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type']; |
|
| 928 | + // surnoms declares |
|
| 929 | + if (is_array($infos['type_surnoms']) and count($infos['type_surnoms'])) { |
|
| 930 | + foreach ($infos['type_surnoms'] as $surnom) { |
|
| 931 | + $surnoms[$surnom] = $infos['type']; |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + } |
|
| 936 | + $md5 = lister_tables_objets_sql('::md5'); |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + return $surnoms; |
|
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | /** |
@@ -950,22 +950,22 @@ discard block |
||
| 950 | 950 | * Couples (nom de la table SQL => même nom, sans 'spip_' devant) |
| 951 | 951 | **/ |
| 952 | 952 | function lister_tables_spip($serveur = '') { |
| 953 | - static $tables = []; |
|
| 954 | - if (!isset($tables[$serveur])) { |
|
| 955 | - $tables[$serveur] = []; |
|
| 956 | - if (!function_exists('sql_alltable')) { |
|
| 957 | - include_spip('base/abstract_sql'); |
|
| 958 | - } |
|
| 959 | - $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 960 | - $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 961 | - $spip = $connexion['prefixe'] . '_'; |
|
| 962 | - foreach ($ts as $t) { |
|
| 963 | - $t = substr($t, strlen($spip)); |
|
| 964 | - $tables[$serveur]["spip_$t"] = $t; |
|
| 965 | - } |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - return $tables[$serveur]; |
|
| 953 | + static $tables = []; |
|
| 954 | + if (!isset($tables[$serveur])) { |
|
| 955 | + $tables[$serveur] = []; |
|
| 956 | + if (!function_exists('sql_alltable')) { |
|
| 957 | + include_spip('base/abstract_sql'); |
|
| 958 | + } |
|
| 959 | + $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 960 | + $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 961 | + $spip = $connexion['prefixe'] . '_'; |
|
| 962 | + foreach ($ts as $t) { |
|
| 963 | + $t = substr($t, strlen($spip)); |
|
| 964 | + $tables[$serveur]["spip_$t"] = $t; |
|
| 965 | + } |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + return $tables[$serveur]; |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | |
@@ -980,18 +980,18 @@ discard block |
||
| 980 | 980 | * Couples (nom de la table SQL => même nom) |
| 981 | 981 | **/ |
| 982 | 982 | function lister_toutes_tables($serveur) { |
| 983 | - static $tables = []; |
|
| 984 | - if (!isset($tables[$serveur])) { |
|
| 985 | - $tables[$serveur] = []; |
|
| 986 | - if (!function_exists('sql_alltable')) { |
|
| 987 | - include_spip('base/abstract_sql'); |
|
| 988 | - } |
|
| 989 | - $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 990 | - foreach ($ts as $t) { |
|
| 991 | - $tables[$serveur][$t] = $t; |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - return $tables[$serveur]; |
|
| 983 | + static $tables = []; |
|
| 984 | + if (!isset($tables[$serveur])) { |
|
| 985 | + $tables[$serveur] = []; |
|
| 986 | + if (!function_exists('sql_alltable')) { |
|
| 987 | + include_spip('base/abstract_sql'); |
|
| 988 | + } |
|
| 989 | + $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 990 | + foreach ($ts as $t) { |
|
| 991 | + $tables[$serveur][$t] = $t; |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + return $tables[$serveur]; |
|
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | /** |
@@ -1011,36 +1011,36 @@ discard block |
||
| 1011 | 1011 | * Nom de l'objet |
| 1012 | 1012 | **/ |
| 1013 | 1013 | function table_objet($type, $serveur = '') { |
| 1014 | - $surnoms = lister_tables_objets_surnoms(); |
|
| 1015 | - $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1016 | - if (!$type) { |
|
| 1017 | - return; |
|
| 1018 | - } |
|
| 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]) or in_array($typetrim, $t)) |
|
| 1029 | - and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1030 | - ) { |
|
| 1031 | - return $desc['id_table']; |
|
| 1032 | - } elseif ( |
|
| 1033 | - (isset($t[$type]) or in_array($type, $t)) |
|
| 1034 | - and ($desc = $trouver_table($type, $serveur)) |
|
| 1035 | - ) { |
|
| 1036 | - return $desc['id_table']; |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1040 | - #spip_log(debug_backtrace(),'db'); |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1014 | + $surnoms = lister_tables_objets_surnoms(); |
|
| 1015 | + $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
|
| 1016 | + if (!$type) { |
|
| 1017 | + return; |
|
| 1018 | + } |
|
| 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]) or in_array($typetrim, $t)) |
|
| 1029 | + and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1030 | + ) { |
|
| 1031 | + return $desc['id_table']; |
|
| 1032 | + } elseif ( |
|
| 1033 | + (isset($t[$type]) or in_array($type, $t)) |
|
| 1034 | + and ($desc = $trouver_table($type, $serveur)) |
|
| 1035 | + ) { |
|
| 1036 | + return $desc['id_table']; |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1040 | + #spip_log(debug_backtrace(),'db'); |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | /** |
@@ -1061,30 +1061,30 @@ discard block |
||
| 1061 | 1061 | **/ |
| 1062 | 1062 | function table_objet_sql($type, $serveur = '') { |
| 1063 | 1063 | |
| 1064 | - $nom = table_objet($type, $serveur); |
|
| 1065 | - if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1066 | - // eviter de multiples inclusions |
|
| 1067 | - include_spip('public/interfaces'); |
|
| 1068 | - } |
|
| 1069 | - if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1070 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1071 | - $nom = "spip_$nom"; |
|
| 1072 | - } else { |
|
| 1073 | - $infos_tables = lister_tables_objets_sql(); |
|
| 1074 | - if (isset($infos_tables["spip_$nom"])) { |
|
| 1075 | - $nom = "spip_$nom"; |
|
| 1076 | - } elseif ($serveur !== false) { |
|
| 1077 | - $t = lister_tables_spip($serveur); |
|
| 1078 | - if (isset($t[$nom]) or in_array($nom, $t)) { |
|
| 1079 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1080 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1081 | - return $desc['table_sql']; |
|
| 1082 | - } |
|
| 1083 | - } |
|
| 1084 | - } |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - return $nom; |
|
| 1064 | + $nom = table_objet($type, $serveur); |
|
| 1065 | + if (!isset($GLOBALS['table_des_tables']['articles'])) { |
|
| 1066 | + // eviter de multiples inclusions |
|
| 1067 | + include_spip('public/interfaces'); |
|
| 1068 | + } |
|
| 1069 | + if (isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 1070 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 1071 | + $nom = "spip_$nom"; |
|
| 1072 | + } else { |
|
| 1073 | + $infos_tables = lister_tables_objets_sql(); |
|
| 1074 | + if (isset($infos_tables["spip_$nom"])) { |
|
| 1075 | + $nom = "spip_$nom"; |
|
| 1076 | + } elseif ($serveur !== false) { |
|
| 1077 | + $t = lister_tables_spip($serveur); |
|
| 1078 | + if (isset($t[$nom]) or in_array($nom, $t)) { |
|
| 1079 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1080 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1081 | + return $desc['table_sql']; |
|
| 1082 | + } |
|
| 1083 | + } |
|
| 1084 | + } |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + return $nom; |
|
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | 1090 | /** |
@@ -1103,35 +1103,35 @@ discard block |
||
| 1103 | 1103 | * Nom de la clé primaire |
| 1104 | 1104 | **/ |
| 1105 | 1105 | function id_table_objet($type, $serveur = '') { |
| 1106 | - static $trouver_table = null; |
|
| 1107 | - $type = objet_type($type, $serveur); |
|
| 1108 | - if (!$type) { |
|
| 1109 | - return; |
|
| 1110 | - } |
|
| 1111 | - $t = table_objet($type); |
|
| 1112 | - if (!$trouver_table) { |
|
| 1113 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1114 | - } |
|
| 1115 | - |
|
| 1116 | - $ts = lister_tables_spip($serveur); |
|
| 1117 | - if ( |
|
| 1118 | - in_array($t, $ts) |
|
| 1119 | - or 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 or 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"; |
|
| 1106 | + static $trouver_table = null; |
|
| 1107 | + $type = objet_type($type, $serveur); |
|
| 1108 | + if (!$type) { |
|
| 1109 | + return; |
|
| 1110 | + } |
|
| 1111 | + $t = table_objet($type); |
|
| 1112 | + if (!$trouver_table) { |
|
| 1113 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1114 | + } |
|
| 1115 | + |
|
| 1116 | + $ts = lister_tables_spip($serveur); |
|
| 1117 | + if ( |
|
| 1118 | + in_array($t, $ts) |
|
| 1119 | + or 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 or 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($table_objet, $serveur = '') { |
| 1153 | - if (!$table_objet) { |
|
| 1154 | - return; |
|
| 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 | - or (table_objet($type, $serveur) == $table_objet) |
|
| 1175 | - or (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 and 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 and 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; |
|
| 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 | + or (table_objet($type, $serveur) == $table_objet) |
|
| 1175 | + or (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 and 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 and 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,62 +1219,62 @@ 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 | - and isset($desc['statut']) |
|
| 1235 | - and $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 . '=' . intval($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 | - if (sql_fetch($res)) { |
|
| 1270 | - return true; |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - return false; |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1277 | - 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 | + and isset($desc['statut']) |
|
| 1235 | + and $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 . '=' . intval($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 | + if (sql_fetch($res)) { |
|
| 1270 | + return true; |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + return false; |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + // si pas d'info statut ni de fonction : l'objet est publie |
|
| 1277 | + return true; |
|
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | |
@@ -1309,124 +1309,124 @@ discard block |
||
| 1309 | 1309 | * Retourne un tableau décrivant les parents trouvés |
| 1310 | 1310 | */ |
| 1311 | 1311 | function objet_lister_parents($objet, $id_objet, $parent_direct_seulement = false) { |
| 1312 | - $parents = []; |
|
| 1313 | - |
|
| 1314 | - // Si on trouve une ou des méthodes de parent |
|
| 1315 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1316 | - // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1317 | - include_spip('base/abstract_sql'); |
|
| 1318 | - $table_objet = table_objet_sql($objet); |
|
| 1319 | - $cle_objet = id_table_objet($objet); |
|
| 1320 | - $id_objet = intval($id_objet); |
|
| 1321 | - |
|
| 1322 | - // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1323 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1324 | - // Champ identifiant le parent (id et éventuellement le type) |
|
| 1325 | - // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1326 | - // de celle de l'objet source |
|
| 1327 | - $select = []; |
|
| 1328 | - if (isset($parent_methode['champ'])) { |
|
| 1329 | - $select[] = $parent_methode['champ']; |
|
| 1330 | - } |
|
| 1331 | - if (isset($parent_methode['champ_type'])) { |
|
| 1332 | - $select[] = $parent_methode['champ_type']; |
|
| 1333 | - } |
|
| 1334 | - |
|
| 1335 | - // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1336 | - $condition_objet_invalide = false; |
|
| 1337 | - $where = []; |
|
| 1338 | - if (!isset($parent_methode['table'])) { |
|
| 1339 | - // Le parent est stocké dans la même table que l'objet source : |
|
| 1340 | - // -- toutes les conditions s'appliquent à la table source. |
|
| 1341 | - $table = $table_objet; |
|
| 1342 | - $where = ["$cle_objet = $id_objet"]; |
|
| 1343 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1344 | - if (isset($parent_methode['condition'])) { |
|
| 1345 | - $where[] = $parent_methode['condition']; |
|
| 1346 | - } |
|
| 1347 | - } elseif (!$parent_direct_seulement) { |
|
| 1348 | - // Le parent est stocké dans une table différente de l'objet source. |
|
| 1349 | - // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1350 | - // Si non, on peut arrêter le traitement. |
|
| 1351 | - if (isset($parent_methode['condition'])) { |
|
| 1352 | - $where = [ |
|
| 1353 | - "$cle_objet = $id_objet", |
|
| 1354 | - $parent_methode['condition'] |
|
| 1355 | - ]; |
|
| 1356 | - if (!sql_countsel($table_objet, $where)) { |
|
| 1357 | - $condition_objet_invalide = true; |
|
| 1358 | - } |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1362 | - // la requête sur la table qui accueille le parent. |
|
| 1363 | - if (!$condition_objet_invalide) { |
|
| 1364 | - $table = $parent_methode['table']; |
|
| 1365 | - // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1366 | - $where = []; |
|
| 1367 | - // -- 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 |
|
| 1368 | - // le même que celui de l'objet source. |
|
| 1369 | - $where[] = isset($parent_methode['source_champ']) |
|
| 1370 | - ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1371 | - : "${cle_objet} = $id_objet"; |
|
| 1372 | - if (isset($parent_methode['source_champ_type'])) { |
|
| 1373 | - $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1374 | - } |
|
| 1375 | - // -- Condition supplémentaire sur la détection du parent |
|
| 1376 | - if (isset($parent_methode['table_condition'])) { |
|
| 1377 | - $where[] = $parent_methode['table_condition']; |
|
| 1378 | - } |
|
| 1379 | - } |
|
| 1380 | - } |
|
| 1381 | - |
|
| 1382 | - // On lance la requête de récupération du parent |
|
| 1383 | - $is_table_lien = (strpos($table, '_liens') !== false and substr($table, -6) === '_liens'); |
|
| 1384 | - if ( |
|
| 1385 | - !$condition_objet_invalide |
|
| 1386 | - and $where |
|
| 1387 | - and ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where)) |
|
| 1388 | - ) { |
|
| 1389 | - foreach ($lignes as $ligne) { |
|
| 1390 | - // Si le type est fixe |
|
| 1391 | - if (isset($parent_methode['type'])) { |
|
| 1392 | - $parent = [ |
|
| 1393 | - 'objet' => $parent_methode['type'], |
|
| 1394 | - 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1395 | - 'champ' => $parent_methode['champ'], |
|
| 1396 | - 'table' => $table, |
|
| 1397 | - ]; |
|
| 1398 | - } |
|
| 1399 | - elseif (isset($parent_methode['champ_type'])) { |
|
| 1400 | - $parent = [ |
|
| 1401 | - 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1402 | - 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1403 | - 'champ' => $parent_methode['champ'], |
|
| 1404 | - 'champ_type' => $parent_methode['champ_type'], |
|
| 1405 | - 'table' => $table, |
|
| 1406 | - ]; |
|
| 1407 | - } |
|
| 1408 | - if ($is_table_lien) { |
|
| 1409 | - $parent['lien'] = $ligne; |
|
| 1410 | - } |
|
| 1411 | - $parents[] = $parent; |
|
| 1412 | - } |
|
| 1413 | - } |
|
| 1414 | - } |
|
| 1415 | - } |
|
| 1416 | - |
|
| 1417 | - // On passe par un pipeline avant de retourner |
|
| 1418 | - $parents = pipeline( |
|
| 1419 | - 'objet_lister_parents', |
|
| 1420 | - [ |
|
| 1421 | - 'args' => [ |
|
| 1422 | - 'objet' => $objet, |
|
| 1423 | - 'id_objet' => $id_objet, |
|
| 1424 | - ], |
|
| 1425 | - 'data' => $parents, |
|
| 1426 | - ] |
|
| 1427 | - ); |
|
| 1428 | - |
|
| 1429 | - return $parents; |
|
| 1312 | + $parents = []; |
|
| 1313 | + |
|
| 1314 | + // Si on trouve une ou des méthodes de parent |
|
| 1315 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet)) { |
|
| 1316 | + // On identifie les informations sur l'objet source dont on cherche le parent. |
|
| 1317 | + include_spip('base/abstract_sql'); |
|
| 1318 | + $table_objet = table_objet_sql($objet); |
|
| 1319 | + $cle_objet = id_table_objet($objet); |
|
| 1320 | + $id_objet = intval($id_objet); |
|
| 1321 | + |
|
| 1322 | + // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête |
|
| 1323 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1324 | + // Champ identifiant le parent (id et éventuellement le type) |
|
| 1325 | + // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente |
|
| 1326 | + // de celle de l'objet source |
|
| 1327 | + $select = []; |
|
| 1328 | + if (isset($parent_methode['champ'])) { |
|
| 1329 | + $select[] = $parent_methode['champ']; |
|
| 1330 | + } |
|
| 1331 | + if (isset($parent_methode['champ_type'])) { |
|
| 1332 | + $select[] = $parent_methode['champ_type']; |
|
| 1333 | + } |
|
| 1334 | + |
|
| 1335 | + // Détermination de la table du parent et des conditions sur l'objet source et le parent. |
|
| 1336 | + $condition_objet_invalide = false; |
|
| 1337 | + $where = []; |
|
| 1338 | + if (!isset($parent_methode['table'])) { |
|
| 1339 | + // Le parent est stocké dans la même table que l'objet source : |
|
| 1340 | + // -- toutes les conditions s'appliquent à la table source. |
|
| 1341 | + $table = $table_objet; |
|
| 1342 | + $where = ["$cle_objet = $id_objet"]; |
|
| 1343 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1344 | + if (isset($parent_methode['condition'])) { |
|
| 1345 | + $where[] = $parent_methode['condition']; |
|
| 1346 | + } |
|
| 1347 | + } elseif (!$parent_direct_seulement) { |
|
| 1348 | + // Le parent est stocké dans une table différente de l'objet source. |
|
| 1349 | + // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée |
|
| 1350 | + // Si non, on peut arrêter le traitement. |
|
| 1351 | + if (isset($parent_methode['condition'])) { |
|
| 1352 | + $where = [ |
|
| 1353 | + "$cle_objet = $id_objet", |
|
| 1354 | + $parent_methode['condition'] |
|
| 1355 | + ]; |
|
| 1356 | + if (!sql_countsel($table_objet, $where)) { |
|
| 1357 | + $condition_objet_invalide = true; |
|
| 1358 | + } |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire |
|
| 1362 | + // la requête sur la table qui accueille le parent. |
|
| 1363 | + if (!$condition_objet_invalide) { |
|
| 1364 | + $table = $parent_methode['table']; |
|
| 1365 | + // On construit les conditions en fonction de l'identification de l'objet source |
|
| 1366 | + $where = []; |
|
| 1367 | + // -- 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 |
|
| 1368 | + // le même que celui de l'objet source. |
|
| 1369 | + $where[] = isset($parent_methode['source_champ']) |
|
| 1370 | + ? "{$parent_methode['source_champ']} = $id_objet" |
|
| 1371 | + : "${cle_objet} = $id_objet"; |
|
| 1372 | + if (isset($parent_methode['source_champ_type'])) { |
|
| 1373 | + $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1374 | + } |
|
| 1375 | + // -- Condition supplémentaire sur la détection du parent |
|
| 1376 | + if (isset($parent_methode['table_condition'])) { |
|
| 1377 | + $where[] = $parent_methode['table_condition']; |
|
| 1378 | + } |
|
| 1379 | + } |
|
| 1380 | + } |
|
| 1381 | + |
|
| 1382 | + // On lance la requête de récupération du parent |
|
| 1383 | + $is_table_lien = (strpos($table, '_liens') !== false and substr($table, -6) === '_liens'); |
|
| 1384 | + if ( |
|
| 1385 | + !$condition_objet_invalide |
|
| 1386 | + and $where |
|
| 1387 | + and ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where)) |
|
| 1388 | + ) { |
|
| 1389 | + foreach ($lignes as $ligne) { |
|
| 1390 | + // Si le type est fixe |
|
| 1391 | + if (isset($parent_methode['type'])) { |
|
| 1392 | + $parent = [ |
|
| 1393 | + 'objet' => $parent_methode['type'], |
|
| 1394 | + 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1395 | + 'champ' => $parent_methode['champ'], |
|
| 1396 | + 'table' => $table, |
|
| 1397 | + ]; |
|
| 1398 | + } |
|
| 1399 | + elseif (isset($parent_methode['champ_type'])) { |
|
| 1400 | + $parent = [ |
|
| 1401 | + 'objet' => $ligne[$parent_methode['champ_type']], |
|
| 1402 | + 'id_objet' => intval($ligne[$parent_methode['champ']]), |
|
| 1403 | + 'champ' => $parent_methode['champ'], |
|
| 1404 | + 'champ_type' => $parent_methode['champ_type'], |
|
| 1405 | + 'table' => $table, |
|
| 1406 | + ]; |
|
| 1407 | + } |
|
| 1408 | + if ($is_table_lien) { |
|
| 1409 | + $parent['lien'] = $ligne; |
|
| 1410 | + } |
|
| 1411 | + $parents[] = $parent; |
|
| 1412 | + } |
|
| 1413 | + } |
|
| 1414 | + } |
|
| 1415 | + } |
|
| 1416 | + |
|
| 1417 | + // On passe par un pipeline avant de retourner |
|
| 1418 | + $parents = pipeline( |
|
| 1419 | + 'objet_lister_parents', |
|
| 1420 | + [ |
|
| 1421 | + 'args' => [ |
|
| 1422 | + 'objet' => $objet, |
|
| 1423 | + 'id_objet' => $id_objet, |
|
| 1424 | + ], |
|
| 1425 | + 'data' => $parents, |
|
| 1426 | + ] |
|
| 1427 | + ); |
|
| 1428 | + |
|
| 1429 | + return $parents; |
|
| 1430 | 1430 | } |
| 1431 | 1431 | |
| 1432 | 1432 | /** |
@@ -1438,17 +1438,17 @@ discard block |
||
| 1438 | 1438 | * @return array |
| 1439 | 1439 | */ |
| 1440 | 1440 | function objet_lister_parents_par_type($objet, $id_objet) { |
| 1441 | - $parents = objet_lister_parents($objet, $id_objet); |
|
| 1441 | + $parents = objet_lister_parents($objet, $id_objet); |
|
| 1442 | 1442 | |
| 1443 | - $parents_par_type = []; |
|
| 1444 | - foreach ($parents as $parent) { |
|
| 1445 | - if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1446 | - $parents_par_type[$parent['objet']] = []; |
|
| 1447 | - } |
|
| 1448 | - $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1449 | - } |
|
| 1443 | + $parents_par_type = []; |
|
| 1444 | + foreach ($parents as $parent) { |
|
| 1445 | + if (!isset($parents_par_type[$parent['objet']])) { |
|
| 1446 | + $parents_par_type[$parent['objet']] = []; |
|
| 1447 | + } |
|
| 1448 | + $parents_par_type[$parent['objet']][] = $parent['id_objet']; |
|
| 1449 | + } |
|
| 1450 | 1450 | |
| 1451 | - return $parents_par_type; |
|
| 1451 | + return $parents_par_type; |
|
| 1452 | 1452 | } |
| 1453 | 1453 | |
| 1454 | 1454 | |
@@ -1481,87 +1481,87 @@ discard block |
||
| 1481 | 1481 | * Retourne un tableau de tableaux, avec comme clés les types des objets, et dans chacun un tableau des identifiants trouvés |
| 1482 | 1482 | */ |
| 1483 | 1483 | function objet_lister_enfants($objet, $id_objet) { |
| 1484 | - $enfants = []; |
|
| 1485 | - |
|
| 1486 | - // Si on trouve des types d'enfants et leurs méthodes |
|
| 1487 | - if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1488 | - include_spip('base/abstract_sql'); |
|
| 1489 | - $id_objet = intval($id_objet); |
|
| 1490 | - |
|
| 1491 | - // On parcourt tous les types d'enfants trouvés |
|
| 1492 | - foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1493 | - // On construit les conditions d'identification du parent |
|
| 1494 | - $where = []; |
|
| 1495 | - // -- L'identifiant du parent |
|
| 1496 | - if (isset($_methode_parent['champ'])) { |
|
| 1497 | - $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1498 | - } |
|
| 1499 | - // -- Si le parent est variable |
|
| 1500 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1501 | - $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1502 | - } |
|
| 1503 | - |
|
| 1504 | - // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1505 | - if (!isset($_methode_parent['table'])) { |
|
| 1506 | - // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1507 | - $table_enfant = table_objet_sql($objet_enfant); |
|
| 1508 | - $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1509 | - |
|
| 1510 | - // S'il y a une condition supplémentaire |
|
| 1511 | - if (isset($_methode_parent['condition'])) { |
|
| 1512 | - $where[] = $_methode_parent['condition']; |
|
| 1513 | - } |
|
| 1514 | - } else { |
|
| 1515 | - // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1516 | - $table_enfant = $_methode_parent['table']; |
|
| 1517 | - $cle_objet_enfant = isset($_methode_parent['source_champ']) |
|
| 1518 | - ? $_methode_parent['source_champ'] |
|
| 1519 | - : id_table_objet($objet_enfant); |
|
| 1520 | - |
|
| 1521 | - // S'il y a une condition supplémentaire |
|
| 1522 | - if (isset($_methode_parent['table_condition'])) { |
|
| 1523 | - $where[] = $_methode_parent['table_condition']; |
|
| 1524 | - } |
|
| 1525 | - } |
|
| 1526 | - |
|
| 1527 | - // On lance la requête |
|
| 1528 | - $is_table_lien = (strpos($table_enfant, '_liens') !== false and substr($table_enfant, -6) === '_liens'); |
|
| 1529 | - if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1530 | - $enfant = [ |
|
| 1531 | - 'objet' => $objet_enfant, |
|
| 1532 | - 'id_objet' => 0, |
|
| 1533 | - 'table' => $table_enfant |
|
| 1534 | - ]; |
|
| 1535 | - if (isset($_methode_parent['champ'])) { |
|
| 1536 | - $enfant['champ'] = $_methode_parent['champ']; |
|
| 1537 | - } |
|
| 1538 | - if (isset($_methode_parent['champ_type'])) { |
|
| 1539 | - $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1540 | - } |
|
| 1541 | - foreach ($rows as $row) { |
|
| 1542 | - $enfant['id_objet'] = intval($row[$cle_objet_enfant]); |
|
| 1543 | - if ($is_table_lien) { |
|
| 1544 | - $enfant['lien'] = $row; |
|
| 1545 | - } |
|
| 1546 | - $enfants[] = $enfant; |
|
| 1547 | - } |
|
| 1548 | - } |
|
| 1549 | - } |
|
| 1550 | - } |
|
| 1551 | - |
|
| 1552 | - // On passe par un pipeline avant de retourner |
|
| 1553 | - $enfants = pipeline( |
|
| 1554 | - 'objet_lister_enfants', |
|
| 1555 | - [ |
|
| 1556 | - 'args' => [ |
|
| 1557 | - 'objet' => $objet, |
|
| 1558 | - 'id_objet' => $id_objet, |
|
| 1559 | - ], |
|
| 1560 | - 'data' => $enfants, |
|
| 1561 | - ] |
|
| 1562 | - ); |
|
| 1563 | - |
|
| 1564 | - return $enfants; |
|
| 1484 | + $enfants = []; |
|
| 1485 | + |
|
| 1486 | + // Si on trouve des types d'enfants et leurs méthodes |
|
| 1487 | + if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) { |
|
| 1488 | + include_spip('base/abstract_sql'); |
|
| 1489 | + $id_objet = intval($id_objet); |
|
| 1490 | + |
|
| 1491 | + // On parcourt tous les types d'enfants trouvés |
|
| 1492 | + foreach ($enfants_methodes as $objet_enfant => $_methode_parent) { |
|
| 1493 | + // On construit les conditions d'identification du parent |
|
| 1494 | + $where = []; |
|
| 1495 | + // -- L'identifiant du parent |
|
| 1496 | + if (isset($_methode_parent['champ'])) { |
|
| 1497 | + $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1498 | + } |
|
| 1499 | + // -- Si le parent est variable |
|
| 1500 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1501 | + $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1502 | + } |
|
| 1503 | + |
|
| 1504 | + // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
|
| 1505 | + if (!isset($_methode_parent['table'])) { |
|
| 1506 | + // Les enfants sont stockés dans la même table que l'objet parent : |
|
| 1507 | + $table_enfant = table_objet_sql($objet_enfant); |
|
| 1508 | + $cle_objet_enfant = id_table_objet($objet_enfant); |
|
| 1509 | + |
|
| 1510 | + // S'il y a une condition supplémentaire |
|
| 1511 | + if (isset($_methode_parent['condition'])) { |
|
| 1512 | + $where[] = $_methode_parent['condition']; |
|
| 1513 | + } |
|
| 1514 | + } else { |
|
| 1515 | + // Les enfants sont stockés dans une table différente de l'objet parent. |
|
| 1516 | + $table_enfant = $_methode_parent['table']; |
|
| 1517 | + $cle_objet_enfant = isset($_methode_parent['source_champ']) |
|
| 1518 | + ? $_methode_parent['source_champ'] |
|
| 1519 | + : id_table_objet($objet_enfant); |
|
| 1520 | + |
|
| 1521 | + // S'il y a une condition supplémentaire |
|
| 1522 | + if (isset($_methode_parent['table_condition'])) { |
|
| 1523 | + $where[] = $_methode_parent['table_condition']; |
|
| 1524 | + } |
|
| 1525 | + } |
|
| 1526 | + |
|
| 1527 | + // On lance la requête |
|
| 1528 | + $is_table_lien = (strpos($table_enfant, '_liens') !== false and substr($table_enfant, -6) === '_liens'); |
|
| 1529 | + if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) { |
|
| 1530 | + $enfant = [ |
|
| 1531 | + 'objet' => $objet_enfant, |
|
| 1532 | + 'id_objet' => 0, |
|
| 1533 | + 'table' => $table_enfant |
|
| 1534 | + ]; |
|
| 1535 | + if (isset($_methode_parent['champ'])) { |
|
| 1536 | + $enfant['champ'] = $_methode_parent['champ']; |
|
| 1537 | + } |
|
| 1538 | + if (isset($_methode_parent['champ_type'])) { |
|
| 1539 | + $enfant['champ_type'] = $_methode_parent['champ_type']; |
|
| 1540 | + } |
|
| 1541 | + foreach ($rows as $row) { |
|
| 1542 | + $enfant['id_objet'] = intval($row[$cle_objet_enfant]); |
|
| 1543 | + if ($is_table_lien) { |
|
| 1544 | + $enfant['lien'] = $row; |
|
| 1545 | + } |
|
| 1546 | + $enfants[] = $enfant; |
|
| 1547 | + } |
|
| 1548 | + } |
|
| 1549 | + } |
|
| 1550 | + } |
|
| 1551 | + |
|
| 1552 | + // On passe par un pipeline avant de retourner |
|
| 1553 | + $enfants = pipeline( |
|
| 1554 | + 'objet_lister_enfants', |
|
| 1555 | + [ |
|
| 1556 | + 'args' => [ |
|
| 1557 | + 'objet' => $objet, |
|
| 1558 | + 'id_objet' => $id_objet, |
|
| 1559 | + ], |
|
| 1560 | + 'data' => $enfants, |
|
| 1561 | + ] |
|
| 1562 | + ); |
|
| 1563 | + |
|
| 1564 | + return $enfants; |
|
| 1565 | 1565 | } |
| 1566 | 1566 | |
| 1567 | 1567 | /** |
@@ -1573,17 +1573,17 @@ discard block |
||
| 1573 | 1573 | * @return array |
| 1574 | 1574 | */ |
| 1575 | 1575 | function objet_lister_enfants_par_type($objet, $id_objet) { |
| 1576 | - $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1576 | + $enfants = objet_lister_enfants($objet, $id_objet); |
|
| 1577 | 1577 | |
| 1578 | - $enfants_par_type = []; |
|
| 1579 | - foreach ($enfants as $enfant) { |
|
| 1580 | - if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1581 | - $enfants_par_type[$enfant['objet']] = []; |
|
| 1582 | - } |
|
| 1583 | - $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1584 | - } |
|
| 1578 | + $enfants_par_type = []; |
|
| 1579 | + foreach ($enfants as $enfant) { |
|
| 1580 | + if (!isset($enfants_par_type[$enfant['objet']])) { |
|
| 1581 | + $enfants_par_type[$enfant['objet']] = []; |
|
| 1582 | + } |
|
| 1583 | + $enfants_par_type[$enfant['objet']][] = $enfant['id_objet']; |
|
| 1584 | + } |
|
| 1585 | 1585 | |
| 1586 | - return $enfants_par_type; |
|
| 1586 | + return $enfants_par_type; |
|
| 1587 | 1587 | } |
| 1588 | 1588 | |
| 1589 | 1589 | /** |
@@ -1595,35 +1595,35 @@ discard block |
||
| 1595 | 1595 | * Retourne un tableau de tableau contenant les informations de type et de champ pour trouver le parent ou false sinon |
| 1596 | 1596 | */ |
| 1597 | 1597 | function objet_type_decrire_infos_parents($objet) { |
| 1598 | - static $parents = []; |
|
| 1599 | - |
|
| 1600 | - // Si on ne l'a pas encore cherché pour cet objet |
|
| 1601 | - if (!isset($parents[$objet])) { |
|
| 1602 | - $parents[$objet] = false; |
|
| 1603 | - $table = table_objet_sql($objet); |
|
| 1604 | - |
|
| 1605 | - // Si on trouve bien la description de cet objet |
|
| 1606 | - if ($infos = lister_tables_objets_sql($table)) { |
|
| 1607 | - if (isset($infos['parent']) and is_array($infos['parent'])) { |
|
| 1608 | - // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1609 | - // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1610 | - // de description |
|
| 1611 | - if (!isset($infos['parent'][0])) { |
|
| 1612 | - $parents[$objet] = [$infos['parent']]; |
|
| 1613 | - } else { |
|
| 1614 | - $parents[$objet] = $infos['parent']; |
|
| 1615 | - } |
|
| 1616 | - } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1617 | - // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1618 | - $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']]; |
|
| 1619 | - } elseif (isset($infos['field']['id_parent'])) { |
|
| 1620 | - // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1621 | - $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']]; |
|
| 1622 | - } |
|
| 1623 | - } |
|
| 1624 | - } |
|
| 1625 | - |
|
| 1626 | - return $parents[$objet]; |
|
| 1598 | + static $parents = []; |
|
| 1599 | + |
|
| 1600 | + // Si on ne l'a pas encore cherché pour cet objet |
|
| 1601 | + if (!isset($parents[$objet])) { |
|
| 1602 | + $parents[$objet] = false; |
|
| 1603 | + $table = table_objet_sql($objet); |
|
| 1604 | + |
|
| 1605 | + // Si on trouve bien la description de cet objet |
|
| 1606 | + if ($infos = lister_tables_objets_sql($table)) { |
|
| 1607 | + if (isset($infos['parent']) and is_array($infos['parent'])) { |
|
| 1608 | + // S'il y a une description explicite de parent, c'est prioritaire |
|
| 1609 | + // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau |
|
| 1610 | + // de description |
|
| 1611 | + if (!isset($infos['parent'][0])) { |
|
| 1612 | + $parents[$objet] = [$infos['parent']]; |
|
| 1613 | + } else { |
|
| 1614 | + $parents[$objet] = $infos['parent']; |
|
| 1615 | + } |
|
| 1616 | + } elseif (isset($infos['field']['id_rubrique'])) { |
|
| 1617 | + // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique |
|
| 1618 | + $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']]; |
|
| 1619 | + } elseif (isset($infos['field']['id_parent'])) { |
|
| 1620 | + // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même |
|
| 1621 | + $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']]; |
|
| 1622 | + } |
|
| 1623 | + } |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + return $parents[$objet]; |
|
| 1627 | 1627 | } |
| 1628 | 1628 | |
| 1629 | 1629 | /** |
@@ -1635,36 +1635,36 @@ discard block |
||
| 1635 | 1635 | * Retourne un tableau de tableaux contenant chacun les informations d'un type d'enfant |
| 1636 | 1636 | */ |
| 1637 | 1637 | function objet_type_decrire_infos_enfants($objet) { |
| 1638 | - static $enfants = []; |
|
| 1639 | - |
|
| 1640 | - // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1641 | - if (!isset($enfants[$objet])) { |
|
| 1642 | - $enfants[$objet] = []; |
|
| 1643 | - $tables = lister_tables_objets_sql(); |
|
| 1644 | - |
|
| 1645 | - // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1646 | - foreach ($tables as $table => $infos) { |
|
| 1647 | - $objet_enfant = objet_type($table); |
|
| 1648 | - |
|
| 1649 | - // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1650 | - if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1651 | - // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1652 | - foreach ($parent_methodes as $parent_methode) { |
|
| 1653 | - // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1654 | - if (!isset($parent_methode['exclus']) or !in_array($objet, $parent_methode['exclus'])) { |
|
| 1655 | - // Si le type du parent est fixe et directement l'objet demandé |
|
| 1656 | - if (isset($parent_methode['type']) and isset($parent_methode['champ']) and $parent_methode['type'] == $objet) { |
|
| 1657 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1658 | - } |
|
| 1659 | - // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1660 | - elseif (isset($parent_methode['champ_type']) and isset($parent_methode['champ'])) { |
|
| 1661 | - $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1662 | - } |
|
| 1663 | - } |
|
| 1664 | - } |
|
| 1665 | - } |
|
| 1666 | - } |
|
| 1667 | - } |
|
| 1668 | - |
|
| 1669 | - return $enfants[$objet]; |
|
| 1638 | + static $enfants = []; |
|
| 1639 | + |
|
| 1640 | + // Si on a déjà fait la recherche pour ce type d'objet |
|
| 1641 | + if (!isset($enfants[$objet])) { |
|
| 1642 | + $enfants[$objet] = []; |
|
| 1643 | + $tables = lister_tables_objets_sql(); |
|
| 1644 | + |
|
| 1645 | + // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant |
|
| 1646 | + foreach ($tables as $table => $infos) { |
|
| 1647 | + $objet_enfant = objet_type($table); |
|
| 1648 | + |
|
| 1649 | + // On ne va pas refaire les tests des différents cas, on réutilise |
|
| 1650 | + if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) { |
|
| 1651 | + // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé |
|
| 1652 | + foreach ($parent_methodes as $parent_methode) { |
|
| 1653 | + // Si la méthode qu'on teste n'exclut pas le parent demandé |
|
| 1654 | + if (!isset($parent_methode['exclus']) or !in_array($objet, $parent_methode['exclus'])) { |
|
| 1655 | + // Si le type du parent est fixe et directement l'objet demandé |
|
| 1656 | + if (isset($parent_methode['type']) and isset($parent_methode['champ']) and $parent_methode['type'] == $objet) { |
|
| 1657 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1658 | + } |
|
| 1659 | + // Si le type est variable, alors l'objet demandé peut forcément être parent |
|
| 1660 | + elseif (isset($parent_methode['champ_type']) and isset($parent_methode['champ'])) { |
|
| 1661 | + $enfants[$objet][$objet_enfant] = $parent_methode; |
|
| 1662 | + } |
|
| 1663 | + } |
|
| 1664 | + } |
|
| 1665 | + } |
|
| 1666 | + } |
|
| 1667 | + } |
|
| 1668 | + |
|
| 1669 | + return $enfants[$objet]; |
|
| 1670 | 1670 | } |
@@ -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'])) { |
@@ -958,7 +958,7 @@ discard block |
||
| 958 | 958 | } |
| 959 | 959 | $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
| 960 | 960 | $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
| 961 | - $spip = $connexion['prefixe'] . '_'; |
|
| 961 | + $spip = $connexion['prefixe'].'_'; |
|
| 962 | 962 | foreach ($ts as $t) { |
| 963 | 963 | $t = substr($t, strlen($spip)); |
| 964 | 964 | $tables[$serveur]["spip_$t"] = $t; |
@@ -1023,10 +1023,10 @@ 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 | 1028 | (isset($t[$typetrim]) or in_array($typetrim, $t)) |
| 1029 | - and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur)) |
|
| 1029 | + and ($desc = $trouver_table(rtrim($type, 's').'s', $serveur)) |
|
| 1030 | 1030 | ) { |
| 1031 | 1031 | return $desc['id_table']; |
| 1032 | 1032 | } elseif ( |
@@ -1036,11 +1036,11 @@ discard block |
||
| 1036 | 1036 | return $desc['id_table']; |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | - spip_log('table_objet(' . $type . ') calculee sans verification'); |
|
| 1039 | + spip_log('table_objet('.$type.') calculee sans verification'); |
|
| 1040 | 1040 | #spip_log(debug_backtrace(),'db'); |
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | - return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1043 | + return rtrim($type, 's').'s'; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | /** |
@@ -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 . '=' . intval($id_objet); |
|
| 1246 | + $boucle->where[] = $id_table.'.'.$id_table_objet.'='.intval($id_objet); |
|
| 1247 | 1247 | |
| 1248 | 1248 | $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
| 1249 | 1249 | $boucle->descr['sourcefile'] = 'internal'; |
@@ -1370,7 +1370,7 @@ discard block |
||
| 1370 | 1370 | ? "{$parent_methode['source_champ']} = $id_objet" |
| 1371 | 1371 | : "${cle_objet} = $id_objet"; |
| 1372 | 1372 | if (isset($parent_methode['source_champ_type'])) { |
| 1373 | - $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet); |
|
| 1373 | + $where[] = "{$parent_methode['source_champ_type']} = ".sql_quote($objet); |
|
| 1374 | 1374 | } |
| 1375 | 1375 | // -- Condition supplémentaire sur la détection du parent |
| 1376 | 1376 | if (isset($parent_methode['table_condition'])) { |
@@ -1494,11 +1494,11 @@ discard block |
||
| 1494 | 1494 | $where = []; |
| 1495 | 1495 | // -- L'identifiant du parent |
| 1496 | 1496 | if (isset($_methode_parent['champ'])) { |
| 1497 | - $where[] = $_methode_parent['champ'] . ' = ' . $id_objet; |
|
| 1497 | + $where[] = $_methode_parent['champ'].' = '.$id_objet; |
|
| 1498 | 1498 | } |
| 1499 | 1499 | // -- Si le parent est variable |
| 1500 | 1500 | if (isset($_methode_parent['champ_type'])) { |
| 1501 | - $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet); |
|
| 1501 | + $where[] = $_methode_parent['champ_type'].' = '.sql_quote($objet); |
|
| 1502 | 1502 | } |
| 1503 | 1503 | |
| 1504 | 1504 | // On détermine la table, le champ id des enfants et on complète éventuellement les conditions |
@@ -1395,8 +1395,7 @@ |
||
| 1395 | 1395 | 'champ' => $parent_methode['champ'], |
| 1396 | 1396 | 'table' => $table, |
| 1397 | 1397 | ]; |
| 1398 | - } |
|
| 1399 | - elseif (isset($parent_methode['champ_type'])) { |
|
| 1398 | + } elseif (isset($parent_methode['champ_type'])) { |
|
| 1400 | 1399 | $parent = [ |
| 1401 | 1400 | 'objet' => $ligne[$parent_methode['champ_type']], |
| 1402 | 1401 | 'id_objet' => intval($ligne[$parent_methode['champ']]), |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | define('_VERSION_ARCHIVE', '1.3'); |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return string |
| 39 | 39 | **/ |
| 40 | 40 | function base_dump_meta_name($rub) { |
| 41 | - return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | + return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -53,15 +53,15 @@ discard block |
||
| 53 | 53 | * @return string |
| 54 | 54 | **/ |
| 55 | 55 | function base_dump_dir($meta) { |
| 56 | - include_spip('inc/documents'); |
|
| 57 | - // determine upload va aussi initialiser l'index "restreint" |
|
| 58 | - $maindir = determine_upload(); |
|
| 59 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 60 | - $maindir = _DIR_DUMP; |
|
| 61 | - } |
|
| 62 | - $dir = sous_repertoire($maindir, $meta); |
|
| 63 | - |
|
| 64 | - return $dir; |
|
| 56 | + include_spip('inc/documents'); |
|
| 57 | + // determine upload va aussi initialiser l'index "restreint" |
|
| 58 | + $maindir = determine_upload(); |
|
| 59 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 60 | + $maindir = _DIR_DUMP; |
|
| 61 | + } |
|
| 62 | + $dir = sous_repertoire($maindir, $meta); |
|
| 63 | + |
|
| 64 | + return $dir; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -75,28 +75,28 @@ discard block |
||
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | 77 | function base_lister_toutes_tables( |
| 78 | - $serveur = '', |
|
| 79 | - $tables = [], |
|
| 80 | - $exclude = [], |
|
| 81 | - $affiche_vrai_prefixe = false |
|
| 78 | + $serveur = '', |
|
| 79 | + $tables = [], |
|
| 80 | + $exclude = [], |
|
| 81 | + $affiche_vrai_prefixe = false |
|
| 82 | 82 | ) { |
| 83 | - spip_connect($serveur); |
|
| 84 | - $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 85 | - $prefixe = $connexion['prefixe']; |
|
| 86 | - |
|
| 87 | - $p = '/^' . $prefixe . '/'; |
|
| 88 | - $res = $tables; |
|
| 89 | - foreach (sql_alltable(null, $serveur) as $t) { |
|
| 90 | - if (preg_match($p, $t)) { |
|
| 91 | - $t1 = preg_replace($p, 'spip', $t); |
|
| 92 | - if (!in_array($t1, $tables) and !in_array($t1, $exclude)) { |
|
| 93 | - $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - sort($res); |
|
| 98 | - |
|
| 99 | - return $res; |
|
| 83 | + spip_connect($serveur); |
|
| 84 | + $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 85 | + $prefixe = $connexion['prefixe']; |
|
| 86 | + |
|
| 87 | + $p = '/^' . $prefixe . '/'; |
|
| 88 | + $res = $tables; |
|
| 89 | + foreach (sql_alltable(null, $serveur) as $t) { |
|
| 90 | + if (preg_match($p, $t)) { |
|
| 91 | + $t1 = preg_replace($p, 'spip', $t); |
|
| 92 | + if (!in_array($t1, $tables) and !in_array($t1, $exclude)) { |
|
| 93 | + $res[] = ($affiche_vrai_prefixe ? $t : $t1); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + sort($res); |
|
| 98 | + |
|
| 99 | + return $res; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | 108 | function base_prefixe_tables($serveur = '') { |
| 109 | - spip_connect($serveur); |
|
| 110 | - $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 111 | - $prefixe = $connexion['prefixe']; |
|
| 109 | + spip_connect($serveur); |
|
| 110 | + $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
|
| 111 | + $prefixe = $connexion['prefixe']; |
|
| 112 | 112 | |
| 113 | - return $prefixe; |
|
| 113 | + return $prefixe; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
@@ -125,31 +125,31 @@ discard block |
||
| 125 | 125 | * @return array |
| 126 | 126 | */ |
| 127 | 127 | function base_saisie_tables($name, $tables, $exclude = [], $post = null, $serveur = '') { |
| 128 | - include_spip('inc/filtres'); |
|
| 129 | - $res = []; |
|
| 130 | - foreach ($tables as $k => $t) { |
|
| 131 | - // par defaut tout est coche sauf les tables dans $exclude |
|
| 132 | - if (is_null($post)) { |
|
| 133 | - $check = (in_array($t, $exclude) ? false : true); |
|
| 134 | - } // mais si on a poste une selection, la reprendre |
|
| 135 | - else { |
|
| 136 | - $check = in_array($t, $post); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 140 | - . "[]' id='$name$k'" |
|
| 141 | - . ($check ? " checked='checked'" : '') |
|
| 142 | - . "/>\n" |
|
| 143 | - . "<label for='$name$k'>$t</label>" |
|
| 144 | - . ' (' |
|
| 145 | - . sinon( |
|
| 146 | - singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 147 | - _T('dump:aucune_donnee') |
|
| 148 | - ) |
|
| 149 | - . ')'; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $res; |
|
| 128 | + include_spip('inc/filtres'); |
|
| 129 | + $res = []; |
|
| 130 | + foreach ($tables as $k => $t) { |
|
| 131 | + // par defaut tout est coche sauf les tables dans $exclude |
|
| 132 | + if (is_null($post)) { |
|
| 133 | + $check = (in_array($t, $exclude) ? false : true); |
|
| 134 | + } // mais si on a poste une selection, la reprendre |
|
| 135 | + else { |
|
| 136 | + $check = in_array($t, $post); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $res[$k] = "<input type='checkbox' value='$t' name='$name" |
|
| 140 | + . "[]' id='$name$k'" |
|
| 141 | + . ($check ? " checked='checked'" : '') |
|
| 142 | + . "/>\n" |
|
| 143 | + . "<label for='$name$k'>$t</label>" |
|
| 144 | + . ' (' |
|
| 145 | + . sinon( |
|
| 146 | + singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'), |
|
| 147 | + _T('dump:aucune_donnee') |
|
| 148 | + ) |
|
| 149 | + . ')'; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $res; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -161,27 +161,27 @@ discard block |
||
| 161 | 161 | * @return array |
| 162 | 162 | */ |
| 163 | 163 | function lister_tables_noexport() { |
| 164 | - // par defaut tout est exporte sauf les tables ci-dessous |
|
| 165 | - static $EXPORT_tables_noexport = null; |
|
| 166 | - if (!is_null($EXPORT_tables_noexport)) { |
|
| 167 | - return $EXPORT_tables_noexport; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $EXPORT_tables_noexport = [ |
|
| 171 | - 'spip_caches', // plugin invalideur |
|
| 172 | - 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 173 | - 'spip_test', // c'est un test ! |
|
| 174 | - #'spip_referers', |
|
| 175 | - #'spip_referers_articles', |
|
| 176 | - #'spip_visites', |
|
| 177 | - #'spip_visites_articles', |
|
| 178 | - #'spip_versions', |
|
| 179 | - #'spip_versions_fragments' |
|
| 180 | - ]; |
|
| 181 | - |
|
| 182 | - $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 183 | - |
|
| 184 | - return $EXPORT_tables_noexport; |
|
| 164 | + // par defaut tout est exporte sauf les tables ci-dessous |
|
| 165 | + static $EXPORT_tables_noexport = null; |
|
| 166 | + if (!is_null($EXPORT_tables_noexport)) { |
|
| 167 | + return $EXPORT_tables_noexport; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $EXPORT_tables_noexport = [ |
|
| 171 | + 'spip_caches', // plugin invalideur |
|
| 172 | + 'spip_resultats', // resultats de recherche ... c'est un cache ! |
|
| 173 | + 'spip_test', // c'est un test ! |
|
| 174 | + #'spip_referers', |
|
| 175 | + #'spip_referers_articles', |
|
| 176 | + #'spip_visites', |
|
| 177 | + #'spip_visites_articles', |
|
| 178 | + #'spip_versions', |
|
| 179 | + #'spip_versions_fragments' |
|
| 180 | + ]; |
|
| 181 | + |
|
| 182 | + $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport); |
|
| 183 | + |
|
| 184 | + return $EXPORT_tables_noexport; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -192,25 +192,25 @@ discard block |
||
| 192 | 192 | * @return array |
| 193 | 193 | */ |
| 194 | 194 | function lister_tables_noimport() { |
| 195 | - static $IMPORT_tables_noimport = null; |
|
| 196 | - if (!is_null($IMPORT_tables_noimport)) { |
|
| 197 | - return $IMPORT_tables_noimport; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $IMPORT_tables_noimport = []; |
|
| 201 | - // par defaut tout est importe sauf les tables ci-dessous |
|
| 202 | - // possibiliter de definir cela tables via la meta |
|
| 203 | - // compatibilite |
|
| 204 | - if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 205 | - $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 206 | - if (!is_array($IMPORT_tables_noimport)) { |
|
| 207 | - include_spip('inc/meta'); |
|
| 208 | - effacer_meta('IMPORT_tables_noimport'); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 212 | - |
|
| 213 | - return $IMPORT_tables_noimport; |
|
| 195 | + static $IMPORT_tables_noimport = null; |
|
| 196 | + if (!is_null($IMPORT_tables_noimport)) { |
|
| 197 | + return $IMPORT_tables_noimport; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $IMPORT_tables_noimport = []; |
|
| 201 | + // par defaut tout est importe sauf les tables ci-dessous |
|
| 202 | + // possibiliter de definir cela tables via la meta |
|
| 203 | + // compatibilite |
|
| 204 | + if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) { |
|
| 205 | + $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']); |
|
| 206 | + if (!is_array($IMPORT_tables_noimport)) { |
|
| 207 | + include_spip('inc/meta'); |
|
| 208 | + effacer_meta('IMPORT_tables_noimport'); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport); |
|
| 212 | + |
|
| 213 | + return $IMPORT_tables_noimport; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | |
@@ -222,23 +222,23 @@ discard block |
||
| 222 | 222 | * @return array |
| 223 | 223 | */ |
| 224 | 224 | function lister_tables_noerase() { |
| 225 | - static $IMPORT_tables_noerase = null; |
|
| 226 | - if (!is_null($IMPORT_tables_noerase)) { |
|
| 227 | - return $IMPORT_tables_noerase; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $IMPORT_tables_noerase = [ |
|
| 231 | - 'spip_meta', |
|
| 232 | - // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 233 | - // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 234 | - 'spip_referers', |
|
| 235 | - 'spip_referers_articles', |
|
| 236 | - 'spip_visites', |
|
| 237 | - 'spip_visites_articles' |
|
| 238 | - ]; |
|
| 239 | - $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 240 | - |
|
| 241 | - return $IMPORT_tables_noerase; |
|
| 225 | + static $IMPORT_tables_noerase = null; |
|
| 226 | + if (!is_null($IMPORT_tables_noerase)) { |
|
| 227 | + return $IMPORT_tables_noerase; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $IMPORT_tables_noerase = [ |
|
| 231 | + 'spip_meta', |
|
| 232 | + // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump |
|
| 233 | + // et le cas echeant, un bouton dans l'admin permet de les vider a la main... |
|
| 234 | + 'spip_referers', |
|
| 235 | + 'spip_referers_articles', |
|
| 236 | + 'spip_visites', |
|
| 237 | + 'spip_visites_articles' |
|
| 238 | + ]; |
|
| 239 | + $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase); |
|
| 240 | + |
|
| 241 | + return $IMPORT_tables_noerase; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -252,86 +252,86 @@ discard block |
||
| 252 | 252 | * @return array |
| 253 | 253 | */ |
| 254 | 254 | function base_liste_table_for_dump($exclude_tables = []) { |
| 255 | - $tables_for_dump = []; |
|
| 256 | - $tables_pointees = []; |
|
| 257 | - $tables = []; |
|
| 258 | - $tables_principales = $GLOBALS['tables_principales']; |
|
| 259 | - $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 260 | - $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 261 | - |
|
| 262 | - if ( |
|
| 263 | - include_spip('base/objets') |
|
| 264 | - and function_exists('lister_tables_objets_sql') |
|
| 265 | - ) { |
|
| 266 | - $tables = lister_tables_objets_sql(); |
|
| 267 | - foreach ($tables as $t => $infos) { |
|
| 268 | - if ($infos['principale'] and !isset($tables_principales[$t])) { |
|
| 269 | - $tables_principales[$t] = true; |
|
| 270 | - } |
|
| 271 | - if (!$infos['principale'] and !isset($tables_auxiliaires[$t])) { |
|
| 272 | - $tables_auxiliaires[$t] = true; |
|
| 273 | - } |
|
| 274 | - if (count($infos['tables_jointures'])) { |
|
| 275 | - $tables_jointures[$t] = array_merge( |
|
| 276 | - isset($tables_jointures[$t]) ? $tables_jointures[$t] : [], |
|
| 277 | - $infos['tables_jointures'] |
|
| 278 | - ); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // on construit un index des tables de liens |
|
| 284 | - // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 285 | - $tables_for_link = []; |
|
| 286 | - foreach ($tables_jointures as $table => $liste_relations) { |
|
| 287 | - if (is_array($liste_relations)) { |
|
| 288 | - $nom = $table; |
|
| 289 | - if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 290 | - $nom = "spip_$table"; |
|
| 291 | - } |
|
| 292 | - if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 293 | - foreach ($liste_relations as $link_table) { |
|
| 294 | - if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 295 | - $tables_for_link[$link_table][] = $nom; |
|
| 296 | - } else { |
|
| 297 | - if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 298 | - $tables_for_link["spip_$link_table"][] = $nom; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - $liste_tables = array_merge(array_keys($tables_principales), array_keys($tables_auxiliaires), array_keys($tables)); |
|
| 307 | - foreach ($liste_tables as $table) { |
|
| 308 | - // $name = preg_replace("{^spip_}","",$table); |
|
| 309 | - if ( |
|
| 310 | - !isset($tables_pointees[$table]) |
|
| 311 | - && !in_array($table, $exclude_tables) |
|
| 312 | - && !isset($tables_for_link[$table]) |
|
| 313 | - ) { |
|
| 314 | - $tables_for_dump[] = $table; |
|
| 315 | - $tables_pointees[$table] = 1; |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - foreach ($tables_for_link as $link_table => $liste) { |
|
| 319 | - $connecte = true; |
|
| 320 | - foreach ($liste as $connect_table) { |
|
| 321 | - if (!in_array($connect_table, $tables_for_dump)) { |
|
| 322 | - $connecte = false; |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - if ($connecte) { |
|
| 326 | - # on ajoute les liaisons en premier |
|
| 327 | - # si une restauration est interrompue, |
|
| 328 | - # cela se verra mieux si il manque des objets |
|
| 329 | - # que des liens |
|
| 330 | - array_unshift($tables_for_dump, $link_table); |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - return [$tables_for_dump, $tables_for_link]; |
|
| 255 | + $tables_for_dump = []; |
|
| 256 | + $tables_pointees = []; |
|
| 257 | + $tables = []; |
|
| 258 | + $tables_principales = $GLOBALS['tables_principales']; |
|
| 259 | + $tables_auxiliaires = $GLOBALS['tables_auxiliaires']; |
|
| 260 | + $tables_jointures = $GLOBALS['tables_jointures']; |
|
| 261 | + |
|
| 262 | + if ( |
|
| 263 | + include_spip('base/objets') |
|
| 264 | + and function_exists('lister_tables_objets_sql') |
|
| 265 | + ) { |
|
| 266 | + $tables = lister_tables_objets_sql(); |
|
| 267 | + foreach ($tables as $t => $infos) { |
|
| 268 | + if ($infos['principale'] and !isset($tables_principales[$t])) { |
|
| 269 | + $tables_principales[$t] = true; |
|
| 270 | + } |
|
| 271 | + if (!$infos['principale'] and !isset($tables_auxiliaires[$t])) { |
|
| 272 | + $tables_auxiliaires[$t] = true; |
|
| 273 | + } |
|
| 274 | + if (count($infos['tables_jointures'])) { |
|
| 275 | + $tables_jointures[$t] = array_merge( |
|
| 276 | + isset($tables_jointures[$t]) ? $tables_jointures[$t] : [], |
|
| 277 | + $infos['tables_jointures'] |
|
| 278 | + ); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // on construit un index des tables de liens |
|
| 284 | + // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees |
|
| 285 | + $tables_for_link = []; |
|
| 286 | + foreach ($tables_jointures as $table => $liste_relations) { |
|
| 287 | + if (is_array($liste_relations)) { |
|
| 288 | + $nom = $table; |
|
| 289 | + if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) { |
|
| 290 | + $nom = "spip_$table"; |
|
| 291 | + } |
|
| 292 | + if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) { |
|
| 293 | + foreach ($liste_relations as $link_table) { |
|
| 294 | + if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) { |
|
| 295 | + $tables_for_link[$link_table][] = $nom; |
|
| 296 | + } else { |
|
| 297 | + if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) { |
|
| 298 | + $tables_for_link["spip_$link_table"][] = $nom; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + $liste_tables = array_merge(array_keys($tables_principales), array_keys($tables_auxiliaires), array_keys($tables)); |
|
| 307 | + foreach ($liste_tables as $table) { |
|
| 308 | + // $name = preg_replace("{^spip_}","",$table); |
|
| 309 | + if ( |
|
| 310 | + !isset($tables_pointees[$table]) |
|
| 311 | + && !in_array($table, $exclude_tables) |
|
| 312 | + && !isset($tables_for_link[$table]) |
|
| 313 | + ) { |
|
| 314 | + $tables_for_dump[] = $table; |
|
| 315 | + $tables_pointees[$table] = 1; |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + foreach ($tables_for_link as $link_table => $liste) { |
|
| 319 | + $connecte = true; |
|
| 320 | + foreach ($liste as $connect_table) { |
|
| 321 | + if (!in_array($connect_table, $tables_for_dump)) { |
|
| 322 | + $connecte = false; |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + if ($connecte) { |
|
| 326 | + # on ajoute les liaisons en premier |
|
| 327 | + # si une restauration est interrompue, |
|
| 328 | + # cela se verra mieux si il manque des objets |
|
| 329 | + # que des liens |
|
| 330 | + array_unshift($tables_for_dump, $link_table); |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + return [$tables_for_dump, $tables_for_link]; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -346,37 +346,37 @@ discard block |
||
| 346 | 346 | * @param string $serveur |
| 347 | 347 | */ |
| 348 | 348 | function base_vider_tables_destination_copie($tables, $exclure_tables = [], $serveur = '') { |
| 349 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 350 | - |
|
| 351 | - spip_log( |
|
| 352 | - 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables), |
|
| 353 | - 'base.' . _LOG_INFO_IMPORTANTE |
|
| 354 | - ); |
|
| 355 | - foreach ($tables as $table) { |
|
| 356 | - if (!in_array($table, $exclure_tables)) { |
|
| 357 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 358 | - if (($table != 'spip_auteurs') or $serveur != '') { |
|
| 359 | - // regarder si il y a au moins un champ impt='non' |
|
| 360 | - $desc = $trouver_table($table, $serveur); |
|
| 361 | - if (isset($desc['field']['impt'])) { |
|
| 362 | - sql_delete($table, "impt='oui'", $serveur); |
|
| 363 | - } elseif ($desc) { |
|
| 364 | - sql_delete($table, '', $serveur); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 371 | - // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 372 | - if ( |
|
| 373 | - $serveur == '' |
|
| 374 | - and in_array('spip_auteurs', $tables) |
|
| 375 | - and !in_array('spip_auteurs', $exclure_tables) |
|
| 376 | - ) { |
|
| 377 | - base_conserver_copieur(true, $serveur); |
|
| 378 | - sql_delete('spip_auteurs', 'id_auteur>0', $serveur); |
|
| 379 | - } |
|
| 349 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 350 | + |
|
| 351 | + spip_log( |
|
| 352 | + 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables), |
|
| 353 | + 'base.' . _LOG_INFO_IMPORTANTE |
|
| 354 | + ); |
|
| 355 | + foreach ($tables as $table) { |
|
| 356 | + if (!in_array($table, $exclure_tables)) { |
|
| 357 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 358 | + if (($table != 'spip_auteurs') or $serveur != '') { |
|
| 359 | + // regarder si il y a au moins un champ impt='non' |
|
| 360 | + $desc = $trouver_table($table, $serveur); |
|
| 361 | + if (isset($desc['field']['impt'])) { |
|
| 362 | + sql_delete($table, "impt='oui'", $serveur); |
|
| 363 | + } elseif ($desc) { |
|
| 364 | + sql_delete($table, '', $serveur); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // sur le serveur principal, il ne faut pas supprimer l'auteur loge ! |
|
| 371 | + // Bidouille pour garder l'acces admin actuel pendant toute la restauration |
|
| 372 | + if ( |
|
| 373 | + $serveur == '' |
|
| 374 | + and in_array('spip_auteurs', $tables) |
|
| 375 | + and !in_array('spip_auteurs', $exclure_tables) |
|
| 376 | + ) { |
|
| 377 | + base_conserver_copieur(true, $serveur); |
|
| 378 | + sql_delete('spip_auteurs', 'id_auteur>0', $serveur); |
|
| 379 | + } |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | /** |
@@ -387,36 +387,36 @@ discard block |
||
| 387 | 387 | * @return void |
| 388 | 388 | */ |
| 389 | 389 | function base_conserver_copieur($move = true, $serveur = '') { |
| 390 | - // s'asurer qu'on a pas deja fait la manip ! |
|
| 391 | - if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 392 | - spip_log( |
|
| 393 | - 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 394 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 395 | - ); |
|
| 396 | - sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 397 | - if ($move) { |
|
| 398 | - sql_updateq( |
|
| 399 | - 'spip_auteurs', |
|
| 400 | - ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
|
| 401 | - 'id_auteur=' . intval($GLOBALS['visiteur_session']['id_auteur']), |
|
| 402 | - [], |
|
| 403 | - $serveur |
|
| 404 | - ); |
|
| 405 | - } else { |
|
| 406 | - $row = sql_fetsel( |
|
| 407 | - '*', |
|
| 408 | - 'spip_auteurs', |
|
| 409 | - 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 410 | - '', |
|
| 411 | - '', |
|
| 412 | - '', |
|
| 413 | - '', |
|
| 414 | - $serveur |
|
| 415 | - ); |
|
| 416 | - $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 417 | - sql_insertq('spip_auteurs', $row, [], $serveur); |
|
| 418 | - } |
|
| 419 | - } |
|
| 390 | + // s'asurer qu'on a pas deja fait la manip ! |
|
| 391 | + if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 392 | + spip_log( |
|
| 393 | + 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 394 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 395 | + ); |
|
| 396 | + sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 397 | + if ($move) { |
|
| 398 | + sql_updateq( |
|
| 399 | + 'spip_auteurs', |
|
| 400 | + ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
|
| 401 | + 'id_auteur=' . intval($GLOBALS['visiteur_session']['id_auteur']), |
|
| 402 | + [], |
|
| 403 | + $serveur |
|
| 404 | + ); |
|
| 405 | + } else { |
|
| 406 | + $row = sql_fetsel( |
|
| 407 | + '*', |
|
| 408 | + 'spip_auteurs', |
|
| 409 | + 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 410 | + '', |
|
| 411 | + '', |
|
| 412 | + '', |
|
| 413 | + '', |
|
| 414 | + $serveur |
|
| 415 | + ); |
|
| 416 | + $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur']; |
|
| 417 | + sql_insertq('spip_auteurs', $row, [], $serveur); |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -431,21 +431,21 @@ discard block |
||
| 431 | 431 | * @param string $serveur |
| 432 | 432 | */ |
| 433 | 433 | function base_detruire_copieur_si_besoin($serveur = '') { |
| 434 | - // rien a faire si ce n'est pas le serveur principal ! |
|
| 435 | - if ($serveur == '') { |
|
| 436 | - if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 437 | - spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 438 | - sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 439 | - } else { |
|
| 440 | - spip_log( |
|
| 441 | - "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 442 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 443 | - ); |
|
| 444 | - sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
|
| 445 | - } |
|
| 446 | - } else { |
|
| 447 | - spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 448 | - } |
|
| 434 | + // rien a faire si ce n'est pas le serveur principal ! |
|
| 435 | + if ($serveur == '') { |
|
| 436 | + if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
|
| 437 | + spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 438 | + sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
|
| 439 | + } else { |
|
| 440 | + spip_log( |
|
| 441 | + "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
|
| 442 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 443 | + ); |
|
| 444 | + sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
|
| 445 | + } |
|
| 446 | + } else { |
|
| 447 | + spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 448 | + } |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -460,40 +460,40 @@ discard block |
||
| 460 | 460 | * @return array |
| 461 | 461 | */ |
| 462 | 462 | function base_preparer_table_dest($table, $desc, $serveur_dest, $init = false) { |
| 463 | - $upgrade = false; |
|
| 464 | - // si la table existe et qu'on est a l'init, la dropper |
|
| 465 | - if ($desc_dest = sql_showtable($table, true, $serveur_dest) and $init) { |
|
| 466 | - if ($serveur_dest == '' and in_array($table, ['spip_meta', 'spip_auteurs'])) { |
|
| 467 | - // ne pas dropper auteurs et meta sur le serveur principal |
|
| 468 | - // faire un simple upgrade a la place |
|
| 469 | - // pour ajouter les champs manquants |
|
| 470 | - $upgrade = true; |
|
| 471 | - // coherence avec le drop sur les autres tables |
|
| 472 | - base_vider_tables_destination_copie([$table], [], $serveur_dest); |
|
| 473 | - if ($table == 'spip_meta') { |
|
| 474 | - // virer les version base qui vont venir avec l'import |
|
| 475 | - sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 476 | - // hum casse la base si pas version_installee a l'import ... |
|
| 477 | - sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 478 | - } |
|
| 479 | - } else { |
|
| 480 | - sql_drop_table($table, '', $serveur_dest); |
|
| 481 | - spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 482 | - } |
|
| 483 | - $desc_dest = false; |
|
| 484 | - } |
|
| 485 | - // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 486 | - if (!$desc_dest) { |
|
| 487 | - spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 488 | - include_spip('base/create'); |
|
| 489 | - creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 490 | - $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 491 | - } |
|
| 492 | - if (!$desc_dest) { |
|
| 493 | - spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return $desc_dest; |
|
| 463 | + $upgrade = false; |
|
| 464 | + // si la table existe et qu'on est a l'init, la dropper |
|
| 465 | + if ($desc_dest = sql_showtable($table, true, $serveur_dest) and $init) { |
|
| 466 | + if ($serveur_dest == '' and in_array($table, ['spip_meta', 'spip_auteurs'])) { |
|
| 467 | + // ne pas dropper auteurs et meta sur le serveur principal |
|
| 468 | + // faire un simple upgrade a la place |
|
| 469 | + // pour ajouter les champs manquants |
|
| 470 | + $upgrade = true; |
|
| 471 | + // coherence avec le drop sur les autres tables |
|
| 472 | + base_vider_tables_destination_copie([$table], [], $serveur_dest); |
|
| 473 | + if ($table == 'spip_meta') { |
|
| 474 | + // virer les version base qui vont venir avec l'import |
|
| 475 | + sql_delete($table, "nom like '%_base_version'", $serveur_dest); |
|
| 476 | + // hum casse la base si pas version_installee a l'import ... |
|
| 477 | + sql_delete($table, "nom='version_installee'", $serveur_dest); |
|
| 478 | + } |
|
| 479 | + } else { |
|
| 480 | + sql_drop_table($table, '', $serveur_dest); |
|
| 481 | + spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 482 | + } |
|
| 483 | + $desc_dest = false; |
|
| 484 | + } |
|
| 485 | + // si la table n'existe pas dans la destination, la creer a l'identique ! |
|
| 486 | + if (!$desc_dest) { |
|
| 487 | + spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 488 | + include_spip('base/create'); |
|
| 489 | + creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
|
| 490 | + $desc_dest = sql_showtable($table, true, $serveur_dest); |
|
| 491 | + } |
|
| 492 | + if (!$desc_dest) { |
|
| 493 | + spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return $desc_dest; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | /** |
@@ -539,210 +539,210 @@ discard block |
||
| 539 | 539 | */ |
| 540 | 540 | function base_copier_tables($status_file, $tables, $serveur_source, $serveur_dest, $options = []) { |
| 541 | 541 | |
| 542 | - $callback_progression = isset($options['callback_progression']) ? $options['callback_progression'] : ''; |
|
| 543 | - $max_time = isset($options['max_time']) ? $options['max_time'] : 0; |
|
| 544 | - $drop_source = isset($options['drop_source']) ? $options['drop_source'] : false; |
|
| 545 | - $no_erase_dest = isset($options['no_erase_dest']) ? $options['no_erase_dest'] : []; |
|
| 546 | - $where = isset($options['where']) ? $options['where'] : []; |
|
| 547 | - $fonction_base_inserer = isset($options['fonction_base_inserer']) ? $options['fonction_base_inserer'] : 'inserer_copie'; |
|
| 548 | - $desc_tables_dest = isset($options['desc_tables_dest']) ? $options['desc_tables_dest'] : []; |
|
| 549 | - $racine_fonctions = (isset($options['racine_fonctions_dest']) ? $options['racine_fonctions_dest'] : 'base'); |
|
| 550 | - $data_pool = (isset($options['data_pool']) ? $options['data_pool'] : 50 * 1024); |
|
| 551 | - |
|
| 552 | - spip_log( |
|
| 553 | - 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 554 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 555 | - ); |
|
| 556 | - |
|
| 557 | - if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 558 | - spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 559 | - |
|
| 560 | - return true; // echec mais on a fini, donc true |
|
| 561 | - } |
|
| 562 | - if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 563 | - spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 564 | - |
|
| 565 | - return true; // echec mais on a fini, donc true |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - if ( |
|
| 569 | - !lire_fichier($status_file, $status) |
|
| 570 | - or !$status = unserialize($status) |
|
| 571 | - ) { |
|
| 572 | - $status = []; |
|
| 573 | - } |
|
| 574 | - $status['etape'] = 'basecopie'; |
|
| 575 | - |
|
| 576 | - // puis relister les tables a importer |
|
| 577 | - // et les vider si besoin, au moment du premier passage ici |
|
| 578 | - $initialisation_copie = (!isset($status['dump_status_copie'])) ? 0 : $status['dump_status_copie']; |
|
| 579 | - |
|
| 580 | - // si init pas encore faite, vider les tables du serveur destination |
|
| 581 | - if (!$initialisation_copie) { |
|
| 582 | - if ( |
|
| 583 | - !$vider_tables_destination_copie = charger_fonction( |
|
| 584 | - 'vider_tables_destination_copie', |
|
| 585 | - $racine_fonctions, |
|
| 586 | - true |
|
| 587 | - ) |
|
| 588 | - ) { |
|
| 589 | - spip_log( |
|
| 590 | - "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 591 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 592 | - ); |
|
| 593 | - |
|
| 594 | - return true; // echec mais on a fini, donc true |
|
| 595 | - } |
|
| 596 | - $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 597 | - $status['dump_status_copie'] = 'ok'; |
|
| 598 | - ecrire_fichier($status_file, serialize($status)); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 602 | - if (in_array('spip_auteurs', $tables)) { |
|
| 603 | - $tables = array_diff($tables, ['spip_auteurs']); |
|
| 604 | - $tables[] = 'spip_auteurs'; |
|
| 605 | - } |
|
| 606 | - if (in_array('spip_meta', $tables)) { |
|
| 607 | - $tables = array_diff($tables, ['spip_meta']); |
|
| 608 | - $tables[] = 'spip_meta'; |
|
| 609 | - } |
|
| 610 | - spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 611 | - |
|
| 612 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 613 | - |
|
| 614 | - foreach ($tables as $table) { |
|
| 615 | - // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 616 | - // sinon chercher la vraie table |
|
| 617 | - $desc_source = false; |
|
| 618 | - if (strncmp($table, 'spip_', 5) == 0) { |
|
| 619 | - $desc_source = $trouver_table(preg_replace(',^spip_,', '', $table), $serveur_source, true); |
|
| 620 | - } |
|
| 621 | - if (!$desc_source or !isset($desc_source['exist']) or !$desc_source['exist']) { |
|
| 622 | - $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - // verifier que la table est presente dans la base source |
|
| 626 | - if ($desc_source) { |
|
| 627 | - // $status['tables_copiees'][$table] contient l'avancement |
|
| 628 | - // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 629 | - if (!isset($status['tables_copiees'][$table])) { |
|
| 630 | - $status['tables_copiees'][$table] = 0; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - if ( |
|
| 634 | - is_numeric($status['tables_copiees'][$table]) |
|
| 635 | - and $status['tables_copiees'][$table] >= 0 |
|
| 636 | - and $desc_dest = $preparer_table_dest( |
|
| 637 | - $table, |
|
| 638 | - isset($desc_tables_dest[$table]) ? $desc_tables_dest[$table] : $desc_source, |
|
| 639 | - $serveur_dest, |
|
| 640 | - $status['tables_copiees'][$table] == 0 |
|
| 641 | - ) |
|
| 642 | - ) { |
|
| 643 | - if ($callback_progression) { |
|
| 644 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 645 | - } |
|
| 646 | - while (true) { |
|
| 647 | - $n = intval($status['tables_copiees'][$table]); |
|
| 648 | - // on copie par lot de 400 |
|
| 649 | - $res = sql_select( |
|
| 650 | - '*', |
|
| 651 | - $table, |
|
| 652 | - isset($where[$table]) ? $where[$table] : '', |
|
| 653 | - '', |
|
| 654 | - '', |
|
| 655 | - "$n,400", |
|
| 656 | - '', |
|
| 657 | - $serveur_source |
|
| 658 | - ); |
|
| 659 | - while ($row = sql_fetch($res, $serveur_source)) { |
|
| 660 | - $rows = [$row]; |
|
| 661 | - // lire un groupe de donnees si demande en option |
|
| 662 | - // (permet un envoi par lot vers la destination) |
|
| 663 | - if ($data_pool > 0) { |
|
| 664 | - $s = strlen(serialize($row)); |
|
| 665 | - while ($s < $data_pool and $row = sql_fetch($res, $serveur_source)) { |
|
| 666 | - $s += strlen(serialize($row)); |
|
| 667 | - $rows[] = $row; |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 671 | - // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 672 | - if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 673 | - // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 674 | - spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 675 | - $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 676 | - ecrire_fichier($status_file, serialize($status)); |
|
| 677 | - |
|
| 678 | - // copie finie |
|
| 679 | - return true; |
|
| 680 | - } |
|
| 681 | - $status['tables_copiees'][$table] += count($rows); |
|
| 682 | - if ($max_time and time() > $max_time) { |
|
| 683 | - break; |
|
| 684 | - } |
|
| 685 | - } |
|
| 686 | - if ($n == $status['tables_copiees'][$table]) { |
|
| 687 | - break; |
|
| 688 | - } |
|
| 689 | - spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 690 | - if ($callback_progression) { |
|
| 691 | - $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 692 | - } |
|
| 693 | - ecrire_fichier($status_file, serialize($status)); |
|
| 694 | - if ($max_time and time() > $max_time) { |
|
| 695 | - return false; |
|
| 696 | - } // on a pas fini, mais le temps imparti est ecoule |
|
| 697 | - } |
|
| 698 | - if ($drop_source) { |
|
| 699 | - sql_drop_table($table, '', $serveur_source); |
|
| 700 | - spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 701 | - } |
|
| 702 | - $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
|
| 703 | - ecrire_fichier($status_file, serialize($status)); |
|
| 704 | - spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 705 | - if ($callback_progression) { |
|
| 706 | - $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 707 | - } |
|
| 708 | - } else { |
|
| 709 | - if ($status['tables_copiees'][$table] < 0) { |
|
| 710 | - spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 711 | - } |
|
| 712 | - if ($callback_progression) { |
|
| 713 | - $callback_progression( |
|
| 714 | - 0, |
|
| 715 | - $status['tables_copiees'][$table], |
|
| 716 | - "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 717 | - ); |
|
| 718 | - } |
|
| 719 | - } |
|
| 720 | - } else { |
|
| 721 | - $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 722 | - ecrire_fichier($status_file, serialize($status)); |
|
| 723 | - spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 728 | - // abandonner |
|
| 729 | - if (count($status['tables_copiees']) < count($tables)) { |
|
| 730 | - spip_log( |
|
| 731 | - 'Nombre de tables copiees incorrect : ' . count($status['tables_copiees']) . '/' . count($tables), |
|
| 732 | - 'dump.' . _LOG_ERREUR |
|
| 733 | - ); |
|
| 734 | - $status['errors'][] = 'Nombre de tables copiees incorrect : ' . count($status['tables_copiees']) . '/' . count($tables); |
|
| 735 | - ecrire_fichier($status_file, serialize($status)); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 739 | - $detruire_copieur_si_besoin($serveur_dest); |
|
| 740 | - } else { |
|
| 741 | - spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - // OK, copie complete |
|
| 745 | - return true; |
|
| 542 | + $callback_progression = isset($options['callback_progression']) ? $options['callback_progression'] : ''; |
|
| 543 | + $max_time = isset($options['max_time']) ? $options['max_time'] : 0; |
|
| 544 | + $drop_source = isset($options['drop_source']) ? $options['drop_source'] : false; |
|
| 545 | + $no_erase_dest = isset($options['no_erase_dest']) ? $options['no_erase_dest'] : []; |
|
| 546 | + $where = isset($options['where']) ? $options['where'] : []; |
|
| 547 | + $fonction_base_inserer = isset($options['fonction_base_inserer']) ? $options['fonction_base_inserer'] : 'inserer_copie'; |
|
| 548 | + $desc_tables_dest = isset($options['desc_tables_dest']) ? $options['desc_tables_dest'] : []; |
|
| 549 | + $racine_fonctions = (isset($options['racine_fonctions_dest']) ? $options['racine_fonctions_dest'] : 'base'); |
|
| 550 | + $data_pool = (isset($options['data_pool']) ? $options['data_pool'] : 50 * 1024); |
|
| 551 | + |
|
| 552 | + spip_log( |
|
| 553 | + 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 554 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 555 | + ); |
|
| 556 | + |
|
| 557 | + if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
|
| 558 | + spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 559 | + |
|
| 560 | + return true; // echec mais on a fini, donc true |
|
| 561 | + } |
|
| 562 | + if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
|
| 563 | + spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 564 | + |
|
| 565 | + return true; // echec mais on a fini, donc true |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + if ( |
|
| 569 | + !lire_fichier($status_file, $status) |
|
| 570 | + or !$status = unserialize($status) |
|
| 571 | + ) { |
|
| 572 | + $status = []; |
|
| 573 | + } |
|
| 574 | + $status['etape'] = 'basecopie'; |
|
| 575 | + |
|
| 576 | + // puis relister les tables a importer |
|
| 577 | + // et les vider si besoin, au moment du premier passage ici |
|
| 578 | + $initialisation_copie = (!isset($status['dump_status_copie'])) ? 0 : $status['dump_status_copie']; |
|
| 579 | + |
|
| 580 | + // si init pas encore faite, vider les tables du serveur destination |
|
| 581 | + if (!$initialisation_copie) { |
|
| 582 | + if ( |
|
| 583 | + !$vider_tables_destination_copie = charger_fonction( |
|
| 584 | + 'vider_tables_destination_copie', |
|
| 585 | + $racine_fonctions, |
|
| 586 | + true |
|
| 587 | + ) |
|
| 588 | + ) { |
|
| 589 | + spip_log( |
|
| 590 | + "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
|
| 591 | + 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 592 | + ); |
|
| 593 | + |
|
| 594 | + return true; // echec mais on a fini, donc true |
|
| 595 | + } |
|
| 596 | + $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest); |
|
| 597 | + $status['dump_status_copie'] = 'ok'; |
|
| 598 | + ecrire_fichier($status_file, serialize($status)); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + // les tables auteurs et meta doivent etre copiees en dernier ! |
|
| 602 | + if (in_array('spip_auteurs', $tables)) { |
|
| 603 | + $tables = array_diff($tables, ['spip_auteurs']); |
|
| 604 | + $tables[] = 'spip_auteurs'; |
|
| 605 | + } |
|
| 606 | + if (in_array('spip_meta', $tables)) { |
|
| 607 | + $tables = array_diff($tables, ['spip_meta']); |
|
| 608 | + $tables[] = 'spip_meta'; |
|
| 609 | + } |
|
| 610 | + spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 611 | + |
|
| 612 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 613 | + |
|
| 614 | + foreach ($tables as $table) { |
|
| 615 | + // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin |
|
| 616 | + // sinon chercher la vraie table |
|
| 617 | + $desc_source = false; |
|
| 618 | + if (strncmp($table, 'spip_', 5) == 0) { |
|
| 619 | + $desc_source = $trouver_table(preg_replace(',^spip_,', '', $table), $serveur_source, true); |
|
| 620 | + } |
|
| 621 | + if (!$desc_source or !isset($desc_source['exist']) or !$desc_source['exist']) { |
|
| 622 | + $desc_source = $trouver_table($table, $serveur_source, false); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + // verifier que la table est presente dans la base source |
|
| 626 | + if ($desc_source) { |
|
| 627 | + // $status['tables_copiees'][$table] contient l'avancement |
|
| 628 | + // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...) |
|
| 629 | + if (!isset($status['tables_copiees'][$table])) { |
|
| 630 | + $status['tables_copiees'][$table] = 0; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + if ( |
|
| 634 | + is_numeric($status['tables_copiees'][$table]) |
|
| 635 | + and $status['tables_copiees'][$table] >= 0 |
|
| 636 | + and $desc_dest = $preparer_table_dest( |
|
| 637 | + $table, |
|
| 638 | + isset($desc_tables_dest[$table]) ? $desc_tables_dest[$table] : $desc_source, |
|
| 639 | + $serveur_dest, |
|
| 640 | + $status['tables_copiees'][$table] == 0 |
|
| 641 | + ) |
|
| 642 | + ) { |
|
| 643 | + if ($callback_progression) { |
|
| 644 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 645 | + } |
|
| 646 | + while (true) { |
|
| 647 | + $n = intval($status['tables_copiees'][$table]); |
|
| 648 | + // on copie par lot de 400 |
|
| 649 | + $res = sql_select( |
|
| 650 | + '*', |
|
| 651 | + $table, |
|
| 652 | + isset($where[$table]) ? $where[$table] : '', |
|
| 653 | + '', |
|
| 654 | + '', |
|
| 655 | + "$n,400", |
|
| 656 | + '', |
|
| 657 | + $serveur_source |
|
| 658 | + ); |
|
| 659 | + while ($row = sql_fetch($res, $serveur_source)) { |
|
| 660 | + $rows = [$row]; |
|
| 661 | + // lire un groupe de donnees si demande en option |
|
| 662 | + // (permet un envoi par lot vers la destination) |
|
| 663 | + if ($data_pool > 0) { |
|
| 664 | + $s = strlen(serialize($row)); |
|
| 665 | + while ($s < $data_pool and $row = sql_fetch($res, $serveur_source)) { |
|
| 666 | + $s += strlen(serialize($row)); |
|
| 667 | + $rows[] = $row; |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 671 | + // mais si ca renvoie false c'est une erreur fatale => abandon |
|
| 672 | + if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
|
| 673 | + // forcer la sortie, charge a l'appelant de gerer l'echec |
|
| 674 | + spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 675 | + $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
|
| 676 | + ecrire_fichier($status_file, serialize($status)); |
|
| 677 | + |
|
| 678 | + // copie finie |
|
| 679 | + return true; |
|
| 680 | + } |
|
| 681 | + $status['tables_copiees'][$table] += count($rows); |
|
| 682 | + if ($max_time and time() > $max_time) { |
|
| 683 | + break; |
|
| 684 | + } |
|
| 685 | + } |
|
| 686 | + if ($n == $status['tables_copiees'][$table]) { |
|
| 687 | + break; |
|
| 688 | + } |
|
| 689 | + spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 690 | + if ($callback_progression) { |
|
| 691 | + $callback_progression($status['tables_copiees'][$table], 0, $table); |
|
| 692 | + } |
|
| 693 | + ecrire_fichier($status_file, serialize($status)); |
|
| 694 | + if ($max_time and time() > $max_time) { |
|
| 695 | + return false; |
|
| 696 | + } // on a pas fini, mais le temps imparti est ecoule |
|
| 697 | + } |
|
| 698 | + if ($drop_source) { |
|
| 699 | + sql_drop_table($table, '', $serveur_source); |
|
| 700 | + spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 701 | + } |
|
| 702 | + $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
|
| 703 | + ecrire_fichier($status_file, serialize($status)); |
|
| 704 | + spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 705 | + if ($callback_progression) { |
|
| 706 | + $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
|
| 707 | + } |
|
| 708 | + } else { |
|
| 709 | + if ($status['tables_copiees'][$table] < 0) { |
|
| 710 | + spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 711 | + } |
|
| 712 | + if ($callback_progression) { |
|
| 713 | + $callback_progression( |
|
| 714 | + 0, |
|
| 715 | + $status['tables_copiees'][$table], |
|
| 716 | + "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 717 | + ); |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | + } else { |
|
| 721 | + $status['errors'][] = "Impossible de lire la description de la table $table"; |
|
| 722 | + ecrire_fichier($status_file, serialize($status)); |
|
| 723 | + spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees |
|
| 728 | + // abandonner |
|
| 729 | + if (count($status['tables_copiees']) < count($tables)) { |
|
| 730 | + spip_log( |
|
| 731 | + 'Nombre de tables copiees incorrect : ' . count($status['tables_copiees']) . '/' . count($tables), |
|
| 732 | + 'dump.' . _LOG_ERREUR |
|
| 733 | + ); |
|
| 734 | + $status['errors'][] = 'Nombre de tables copiees incorrect : ' . count($status['tables_copiees']) . '/' . count($tables); |
|
| 735 | + ecrire_fichier($status_file, serialize($status)); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
|
| 739 | + $detruire_copieur_si_besoin($serveur_dest); |
|
| 740 | + } else { |
|
| 741 | + spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + // OK, copie complete |
|
| 745 | + return true; |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | /** |
@@ -756,31 +756,31 @@ discard block |
||
| 756 | 756 | */ |
| 757 | 757 | function base_inserer_copie($table, $rows, $desc_dest, $serveur_dest) { |
| 758 | 758 | |
| 759 | - // verifier le nombre d'insertion |
|
| 760 | - $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 761 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 762 | - $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 763 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 764 | - if ($nb - $nb1 < count($rows)) { |
|
| 765 | - spip_log( |
|
| 766 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 767 | - 'dump' . _LOG_INFO_IMPORTANTE |
|
| 768 | - ); |
|
| 769 | - foreach ($rows as $row) { |
|
| 770 | - // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 771 | - $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 772 | - } |
|
| 773 | - // on reverifie le total |
|
| 774 | - $r = 0; |
|
| 775 | - $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 776 | - if ($nb - $nb1 < count($rows)) { |
|
| 777 | - spip_log( |
|
| 778 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 779 | - 'dump' . _LOG_ERREUR |
|
| 780 | - ); |
|
| 781 | - $r = false; |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - return $r; |
|
| 759 | + // verifier le nombre d'insertion |
|
| 760 | + $nb1 = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 761 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 762 | + $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest); |
|
| 763 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 764 | + if ($nb - $nb1 < count($rows)) { |
|
| 765 | + spip_log( |
|
| 766 | + 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 767 | + 'dump' . _LOG_INFO_IMPORTANTE |
|
| 768 | + ); |
|
| 769 | + foreach ($rows as $row) { |
|
| 770 | + // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
|
| 771 | + $r = sql_insertq($table, $row, $desc_dest, $serveur_dest); |
|
| 772 | + } |
|
| 773 | + // on reverifie le total |
|
| 774 | + $r = 0; |
|
| 775 | + $nb = sql_countsel($table, '', '', '', $serveur_dest); |
|
| 776 | + if ($nb - $nb1 < count($rows)) { |
|
| 777 | + spip_log( |
|
| 778 | + 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 779 | + 'dump' . _LOG_ERREUR |
|
| 780 | + ); |
|
| 781 | + $r = false; |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + return $r; |
|
| 786 | 786 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return string |
| 39 | 39 | **/ |
| 40 | 40 | function base_dump_meta_name($rub) { |
| 41 | - return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | + return $meta = "status_dump_{$rub}_".abs($GLOBALS['visiteur_session']['id_auteur']); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
| 85 | 85 | $prefixe = $connexion['prefixe']; |
| 86 | 86 | |
| 87 | - $p = '/^' . $prefixe . '/'; |
|
| 87 | + $p = '/^'.$prefixe.'/'; |
|
| 88 | 88 | $res = $tables; |
| 89 | 89 | foreach (sql_alltable(null, $serveur) as $t) { |
| 90 | 90 | if (preg_match($p, $t)) { |
@@ -349,8 +349,8 @@ discard block |
||
| 349 | 349 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 350 | 350 | |
| 351 | 351 | spip_log( |
| 352 | - 'Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables), |
|
| 353 | - 'base.' . _LOG_INFO_IMPORTANTE |
|
| 352 | + 'Vider '.count($tables)." tables sur serveur '$serveur' : ".join(', ', $tables), |
|
| 353 | + 'base.'._LOG_INFO_IMPORTANTE |
|
| 354 | 354 | ); |
| 355 | 355 | foreach ($tables as $table) { |
| 356 | 356 | if (!in_array($table, $exclure_tables)) { |
@@ -390,15 +390,15 @@ discard block |
||
| 390 | 390 | // s'asurer qu'on a pas deja fait la manip ! |
| 391 | 391 | if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel('spip_auteurs', 'id_auteur>0')) { |
| 392 | 392 | spip_log( |
| 393 | - 'Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'", |
|
| 394 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 393 | + 'Conserver copieur dans id_auteur='.$GLOBALS['visiteur_session']['id_auteur']." pour le serveur '$serveur'", |
|
| 394 | + 'dump.'._LOG_INFO_IMPORTANTE |
|
| 395 | 395 | ); |
| 396 | 396 | sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
| 397 | 397 | if ($move) { |
| 398 | 398 | sql_updateq( |
| 399 | 399 | 'spip_auteurs', |
| 400 | 400 | ['id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']], |
| 401 | - 'id_auteur=' . intval($GLOBALS['visiteur_session']['id_auteur']), |
|
| 401 | + 'id_auteur='.intval($GLOBALS['visiteur_session']['id_auteur']), |
|
| 402 | 402 | [], |
| 403 | 403 | $serveur |
| 404 | 404 | ); |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | $row = sql_fetsel( |
| 407 | 407 | '*', |
| 408 | 408 | 'spip_auteurs', |
| 409 | - 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], |
|
| 409 | + 'id_auteur='.$GLOBALS['visiteur_session']['id_auteur'], |
|
| 410 | 410 | '', |
| 411 | 411 | '', |
| 412 | 412 | '', |
@@ -434,17 +434,17 @@ discard block |
||
| 434 | 434 | // rien a faire si ce n'est pas le serveur principal ! |
| 435 | 435 | if ($serveur == '') { |
| 436 | 436 | if (sql_countsel('spip_auteurs', 'id_auteur>0')) { |
| 437 | - spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 437 | + spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 438 | 438 | sql_delete('spip_auteurs', 'id_auteur<0', $serveur); |
| 439 | 439 | } else { |
| 440 | 440 | spip_log( |
| 441 | 441 | "Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)", |
| 442 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 442 | + 'dump.'._LOG_INFO_IMPORTANTE |
|
| 443 | 443 | ); |
| 444 | 444 | sql_update('spip_auteurs', ['id_auteur' => '-id_auteur'], 'id_auteur<0'); |
| 445 | 445 | } |
| 446 | 446 | } else { |
| 447 | - spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 447 | + spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | |
@@ -478,19 +478,19 @@ discard block |
||
| 478 | 478 | } |
| 479 | 479 | } else { |
| 480 | 480 | sql_drop_table($table, '', $serveur_dest); |
| 481 | - spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 481 | + spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 482 | 482 | } |
| 483 | 483 | $desc_dest = false; |
| 484 | 484 | } |
| 485 | 485 | // si la table n'existe pas dans la destination, la creer a l'identique ! |
| 486 | 486 | if (!$desc_dest) { |
| 487 | - spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 487 | + spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 488 | 488 | include_spip('base/create'); |
| 489 | 489 | creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest); |
| 490 | 490 | $desc_dest = sql_showtable($table, true, $serveur_dest); |
| 491 | 491 | } |
| 492 | 492 | if (!$desc_dest) { |
| 493 | - spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR); |
|
| 493 | + spip_log("Erreur creation '$table' sur serveur '$serveur_dest'".var_export($desc, 1), 'dump.'._LOG_ERREUR); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | return $desc_dest; |
@@ -550,17 +550,17 @@ discard block |
||
| 550 | 550 | $data_pool = (isset($options['data_pool']) ? $options['data_pool'] : 50 * 1024); |
| 551 | 551 | |
| 552 | 552 | spip_log( |
| 553 | - 'Copier ' . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'", |
|
| 554 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 553 | + 'Copier '.count($tables)." tables de '$serveur_source' vers '$serveur_dest'", |
|
| 554 | + 'dump.'._LOG_INFO_IMPORTANTE |
|
| 555 | 555 | ); |
| 556 | 556 | |
| 557 | 557 | if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) { |
| 558 | - spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 558 | + spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 559 | 559 | |
| 560 | 560 | return true; // echec mais on a fini, donc true |
| 561 | 561 | } |
| 562 | 562 | if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) { |
| 563 | - spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 563 | + spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 564 | 564 | |
| 565 | 565 | return true; // echec mais on a fini, donc true |
| 566 | 566 | } |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | ) { |
| 589 | 589 | spip_log( |
| 590 | 590 | "Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon", |
| 591 | - 'dump.' . _LOG_INFO_IMPORTANTE |
|
| 591 | + 'dump.'._LOG_INFO_IMPORTANTE |
|
| 592 | 592 | ); |
| 593 | 593 | |
| 594 | 594 | return true; // echec mais on a fini, donc true |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | $tables = array_diff($tables, ['spip_meta']); |
| 608 | 608 | $tables[] = 'spip_meta'; |
| 609 | 609 | } |
| 610 | - spip_log('Tables a copier :' . implode(', ', $tables), 'dump.' . _LOG_INFO); |
|
| 610 | + spip_log('Tables a copier :'.implode(', ', $tables), 'dump.'._LOG_INFO); |
|
| 611 | 611 | |
| 612 | 612 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 613 | 613 | |
@@ -671,7 +671,7 @@ discard block |
||
| 671 | 671 | // mais si ca renvoie false c'est une erreur fatale => abandon |
| 672 | 672 | if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) { |
| 673 | 673 | // forcer la sortie, charge a l'appelant de gerer l'echec |
| 674 | - spip_log("Erreur fatale dans $inserer_copie table $table", 'dump' . _LOG_ERREUR); |
|
| 674 | + spip_log("Erreur fatale dans $inserer_copie table $table", 'dump'._LOG_ERREUR); |
|
| 675 | 675 | $status['errors'][] = "Erreur fatale lors de la copie de la table $table"; |
| 676 | 676 | ecrire_fichier($status_file, serialize($status)); |
| 677 | 677 | |
@@ -686,7 +686,7 @@ discard block |
||
| 686 | 686 | if ($n == $status['tables_copiees'][$table]) { |
| 687 | 687 | break; |
| 688 | 688 | } |
| 689 | - spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 689 | + spip_log("recopie $table ".$status['tables_copiees'][$table], 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 690 | 690 | if ($callback_progression) { |
| 691 | 691 | $callback_progression($status['tables_copiees'][$table], 0, $table); |
| 692 | 692 | } |
@@ -697,30 +697,30 @@ discard block |
||
| 697 | 697 | } |
| 698 | 698 | if ($drop_source) { |
| 699 | 699 | sql_drop_table($table, '', $serveur_source); |
| 700 | - spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 700 | + spip_log("drop $table sur serveur source '$serveur_source'", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 701 | 701 | } |
| 702 | 702 | $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : 'zero'); |
| 703 | 703 | ecrire_fichier($status_file, serialize($status)); |
| 704 | - spip_log('tables_recopiees ' . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO); |
|
| 704 | + spip_log('tables_recopiees '.implode(',', array_keys($status['tables_copiees'])), 'dump.'._LOG_INFO); |
|
| 705 | 705 | if ($callback_progression) { |
| 706 | 706 | $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table); |
| 707 | 707 | } |
| 708 | 708 | } else { |
| 709 | 709 | if ($status['tables_copiees'][$table] < 0) { |
| 710 | - spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO); |
|
| 710 | + spip_log("Table $table deja copiee : ".$status['tables_copiees'][$table], 'dump.'._LOG_INFO); |
|
| 711 | 711 | } |
| 712 | 712 | if ($callback_progression) { |
| 713 | 713 | $callback_progression( |
| 714 | 714 | 0, |
| 715 | 715 | $status['tables_copiees'][$table], |
| 716 | - "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 716 | + "$table".((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? '[Echec]' : '') |
|
| 717 | 717 | ); |
| 718 | 718 | } |
| 719 | 719 | } |
| 720 | 720 | } else { |
| 721 | 721 | $status['errors'][] = "Impossible de lire la description de la table $table"; |
| 722 | 722 | ecrire_fichier($status_file, serialize($status)); |
| 723 | - spip_log("Impossible de lire la description de la table $table", 'dump.' . _LOG_ERREUR); |
|
| 723 | + spip_log("Impossible de lire la description de la table $table", 'dump.'._LOG_ERREUR); |
|
| 724 | 724 | } |
| 725 | 725 | } |
| 726 | 726 | |
@@ -728,17 +728,17 @@ discard block |
||
| 728 | 728 | // abandonner |
| 729 | 729 | if (count($status['tables_copiees']) < count($tables)) { |
| 730 | 730 | spip_log( |
| 731 | - 'Nombre de tables copiees incorrect : ' . count($status['tables_copiees']) . '/' . count($tables), |
|
| 732 | - 'dump.' . _LOG_ERREUR |
|
| 731 | + 'Nombre de tables copiees incorrect : '.count($status['tables_copiees']).'/'.count($tables), |
|
| 732 | + 'dump.'._LOG_ERREUR |
|
| 733 | 733 | ); |
| 734 | - $status['errors'][] = 'Nombre de tables copiees incorrect : ' . count($status['tables_copiees']) . '/' . count($tables); |
|
| 734 | + $status['errors'][] = 'Nombre de tables copiees incorrect : '.count($status['tables_copiees']).'/'.count($tables); |
|
| 735 | 735 | ecrire_fichier($status_file, serialize($status)); |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) { |
| 739 | 739 | $detruire_copieur_si_besoin($serveur_dest); |
| 740 | 740 | } else { |
| 741 | - spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE); |
|
| 741 | + spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.'._LOG_INFO_IMPORTANTE); |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | // OK, copie complete |
@@ -763,8 +763,8 @@ discard block |
||
| 763 | 763 | $nb = sql_countsel($table, '', '', '', $serveur_dest); |
| 764 | 764 | if ($nb - $nb1 < count($rows)) { |
| 765 | 765 | spip_log( |
| 766 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . '. On retente 1 par 1', |
|
| 767 | - 'dump' . _LOG_INFO_IMPORTANTE |
|
| 766 | + 'base_inserer_copie : '.($nb - $nb1).' insertions au lieu de '.count($rows).'. On retente 1 par 1', |
|
| 767 | + 'dump'._LOG_INFO_IMPORTANTE |
|
| 768 | 768 | ); |
| 769 | 769 | foreach ($rows as $row) { |
| 770 | 770 | // si l'enregistrement est deja en base, ca fera un echec ou un doublon |
@@ -775,8 +775,8 @@ discard block |
||
| 775 | 775 | $nb = sql_countsel($table, '', '', '', $serveur_dest); |
| 776 | 776 | if ($nb - $nb1 < count($rows)) { |
| 777 | 777 | spip_log( |
| 778 | - 'base_inserer_copie : ' . ($nb - $nb1) . ' insertions au lieu de ' . count($rows) . ' apres insertion 1 par 1', |
|
| 779 | - 'dump' . _LOG_ERREUR |
|
| 778 | + 'base_inserer_copie : '.($nb - $nb1).' insertions au lieu de '.count($rows).' apres insertion 1 par 1', |
|
| 779 | + 'dump'._LOG_ERREUR |
|
| 780 | 780 | ); |
| 781 | 781 | $r = false; |
| 782 | 782 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -23,333 +23,333 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | class ValidateurXML { |
| 25 | 25 | |
| 26 | - // https://code.spip.net/@validerElement |
|
| 27 | - public function validerElement($phraseur, $name, $attrs) { |
|
| 28 | - if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 29 | - if ($p = strpos($name, ':')) { |
|
| 30 | - $name = substr($name, $p + 1); |
|
| 31 | - $p = isset($this->dtc->elements[$name]); |
|
| 32 | - } |
|
| 33 | - if (!$p) { |
|
| 34 | - coordonnees_erreur($this, " <b>$name</b> : " |
|
| 35 | - . _T('zxml_inconnu_balise')); |
|
| 36 | - |
|
| 37 | - return; |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - // controler les filles illegitimes, ca suffit |
|
| 41 | - $depth = $this->depth; |
|
| 42 | - $ouvrant = $this->ouvrant; |
|
| 43 | - #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 44 | - if (isset($ouvrant[$depth])) { |
|
| 45 | - if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 46 | - $pere = $r[1]; |
|
| 47 | - #spip_log("pere $pere"); |
|
| 48 | - if (isset($this->dtc->elements[$pere])) { |
|
| 49 | - $fils = $this->dtc->elements[$pere]; |
|
| 50 | - #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 51 | - if (!($p = @in_array($name, $fils))) { |
|
| 52 | - if ($p = strpos($name, ':')) { |
|
| 53 | - $p = substr($name, $p + 1); |
|
| 54 | - $p = @in_array($p, $fils); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - if (!$p) { |
|
| 58 | - $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 59 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 60 | - . _T('zxml_non_fils') |
|
| 61 | - . ' <b>' |
|
| 62 | - . $pere |
|
| 63 | - . '</b>' |
|
| 64 | - . (!$bons_peres ? '' |
|
| 65 | - : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 66 | - } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 67 | - $frat = substr($depth, 2); |
|
| 68 | - if (!isset($this->fratrie[$frat])) { |
|
| 69 | - $this->fratrie[$frat] = ''; |
|
| 70 | - } |
|
| 71 | - $this->fratrie[$frat] .= "$name "; |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - // Init de la suite des balises a memoriser si regle difficile |
|
| 77 | - if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 78 | - $this->fratrie[$depth] = ''; |
|
| 79 | - } |
|
| 80 | - if (isset($this->dtc->attributs[$name])) { |
|
| 81 | - foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 82 | - if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 83 | - coordonnees_erreur($this, " <b>$n</b>" |
|
| 84 | - . ' : ' |
|
| 85 | - . _T('zxml_obligatoire_attribut') |
|
| 86 | - . " <b>$name</b>"); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // https://code.spip.net/@validerAttribut |
|
| 93 | - public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 94 | - // Si la balise est inconnue, eviter d'insister |
|
| 95 | - if (!isset($this->dtc->attributs[$bal])) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $a = $this->dtc->attributs[$bal]; |
|
| 100 | - if (!isset($a[$name])) { |
|
| 101 | - $bons = join(', ', array_keys($a)); |
|
| 102 | - if ($bons) { |
|
| 103 | - $bons = " title=' " . |
|
| 104 | - _T('zxml_connus_attributs') . |
|
| 105 | - ' : ' . |
|
| 106 | - $bons . |
|
| 107 | - "'"; |
|
| 108 | - } |
|
| 109 | - $bons .= " style='font-weight: bold'"; |
|
| 110 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 111 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 112 | - . " <a$bons>$bal</a> (" |
|
| 113 | - . _T('zxml_survoler') |
|
| 114 | - . ')'); |
|
| 115 | - } else { |
|
| 116 | - $type = $a[$name][0]; |
|
| 117 | - if (!preg_match('/^\w+$/', $type)) { |
|
| 118 | - $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 119 | - } else { |
|
| 120 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 121 | - $this->$f($phraseur, $name, $val, $bal); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - # else spip_log("$type type d'attribut inconnu"); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 129 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 133 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // https://code.spip.net/@validerAttribut_ID |
|
| 137 | - public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 138 | - if (isset($this->ids[$val])) { |
|
| 139 | - list($l, $c) = $this->ids[$val]; |
|
| 140 | - coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 141 | - . _T('zxml_valeur_attribut') |
|
| 142 | - . " <b>$name</b> " |
|
| 143 | - . _T('zxml_de') |
|
| 144 | - . " <b>$bal</b> " |
|
| 145 | - . _T('zxml_vu') |
|
| 146 | - . " (L$l,C$c)"); |
|
| 147 | - } else { |
|
| 148 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 149 | - $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // https://code.spip.net/@validerAttribut_IDREF |
|
| 154 | - public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 155 | - $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // https://code.spip.net/@validerAttribut_IDREFS |
|
| 159 | - public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 160 | - $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // https://code.spip.net/@valider_motif |
|
| 164 | - public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 165 | - if (!preg_match($motif, $val)) { |
|
| 166 | - coordonnees_erreur($this, "<b>$val</b> " |
|
| 167 | - . _T('zxml_valeur_attribut') |
|
| 168 | - . " <b>$name</b> " |
|
| 169 | - . _T('zxml_de') |
|
| 170 | - . " <b>$bal</b> " |
|
| 171 | - . _T('zxml_non_conforme') |
|
| 172 | - . '</p><p>' |
|
| 173 | - . '<b>' . $motif . '</b>'); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - // https://code.spip.net/@valider_idref |
|
| 178 | - public function valider_idref($nom, $ligne, $col) { |
|
| 179 | - if (!isset($this->ids[$nom])) { |
|
| 180 | - $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // https://code.spip.net/@valider_passe2 |
|
| 185 | - public function valider_passe2() { |
|
| 186 | - if (!$this->err) { |
|
| 187 | - foreach ($this->idrefs as $idref) { |
|
| 188 | - list($nom, $ligne, $col) = $idref; |
|
| 189 | - $this->valider_idref($nom, $ligne, $col); |
|
| 190 | - } |
|
| 191 | - foreach ($this->idrefss as $idref) { |
|
| 192 | - list($noms, $ligne, $col) = $idref; |
|
| 193 | - foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 194 | - $this->valider_idref($nom, $ligne, $col); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // https://code.spip.net/@debutElement |
|
| 201 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 202 | - if ($this->dtc->elements) { |
|
| 203 | - $this->validerElement($phraseur, $name, $attrs); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($f = $this->process['debut']) { |
|
| 207 | - $f($this, $name, $attrs); |
|
| 208 | - } |
|
| 209 | - $depth = $this->depth; |
|
| 210 | - $this->debuts[$depth] = strlen($this->res); |
|
| 211 | - foreach ($attrs as $k => $v) { |
|
| 212 | - $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // https://code.spip.net/@finElement |
|
| 217 | - public function finElement($phraseur, $name) { |
|
| 218 | - $depth = $this->depth; |
|
| 219 | - $contenu = $this->contenu; |
|
| 220 | - |
|
| 221 | - $n = strlen($this->res); |
|
| 222 | - $c = strlen(trim($contenu[$depth])); |
|
| 223 | - $k = $this->debuts[$depth]; |
|
| 224 | - |
|
| 225 | - $regle = isset($this->dtc->regles[$name]) ? $this->dtc->regles[$name] : false; |
|
| 226 | - $vide = ($regle == 'EMPTY'); |
|
| 227 | - // controler que les balises devant etre vides le sont |
|
| 228 | - if ($vide) { |
|
| 229 | - if ($n <> ($k + $c)) { |
|
| 230 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 231 | - } |
|
| 232 | - // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 233 | - } elseif ($regle and ($regle != '*')) { |
|
| 234 | - if ($regle == '+') { |
|
| 235 | - // iteration de disjonction non vide: 1 balise au - |
|
| 236 | - if ($n == $k) { |
|
| 237 | - coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 238 | - . _T('zxml_vide_balise')); |
|
| 239 | - } |
|
| 240 | - } else { |
|
| 241 | - $f = isset($this->fratrie[substr($depth, 2)]) ? $this->fratrie[substr($depth, 2)] : null; |
|
| 242 | - if (is_null($f) or !preg_match($regle, $f)) { |
|
| 243 | - coordonnees_erreur( |
|
| 244 | - $this, |
|
| 245 | - " <p>\n<b>$name</b> " |
|
| 246 | - . _T('zxml_succession_fils_incorrecte') |
|
| 247 | - . ' : <b>' |
|
| 248 | - . $f |
|
| 249 | - . '</b>' |
|
| 250 | - ); |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - if ($f = $this->process['fin']) { |
|
| 255 | - $f($this, $name, $vide); |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - // https://code.spip.net/@textElement |
|
| 260 | - public function textElement($phraseur, $data) { |
|
| 261 | - if (trim($data)) { |
|
| 262 | - $d = $this->depth; |
|
| 263 | - $d = $this->ouvrant[$d]; |
|
| 264 | - preg_match('/^\s*(\S+)/', $d, $m); |
|
| 265 | - if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 266 | - coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 267 | - . _T('zxml_nonvide_balise')); // message a affiner |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - if ($f = $this->process['text']) { |
|
| 271 | - $f($this, $data); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - public function piElement($phraseur, $target, $data) { |
|
| 276 | - if ($f = $this->process['pi']) { |
|
| 277 | - $f($this, $target, $data); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - // Denonciation des entitees XML inconnues |
|
| 282 | - // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 283 | - // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 284 | - // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 285 | - // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 286 | - // le source de la page laisse legitimement supposer. |
|
| 287 | - |
|
| 288 | - // https://code.spip.net/@defautElement |
|
| 289 | - public function defaultElement($phraseur, $data) { |
|
| 290 | - if ( |
|
| 291 | - !preg_match('/^<!--/', $data) |
|
| 292 | - and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 293 | - ) { |
|
| 294 | - foreach ($r as $m) { |
|
| 295 | - list($t, $e) = $m; |
|
| 296 | - if (!isset($this->dtc->entites[$e])) { |
|
| 297 | - coordonnees_erreur($this, " <b>$e</b> " |
|
| 298 | - . _T('zxml_inconnu_entite') |
|
| 299 | - . ' '); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 304 | - $f($this, $data); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - // https://code.spip.net/@phraserTout |
|
| 309 | - public function phraserTout($phraseur, $data) { |
|
| 310 | - xml_parsestring($this, $data); |
|
| 311 | - |
|
| 312 | - if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 313 | - $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 314 | - } else { |
|
| 315 | - $this->valider_passe2($this); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Constructeur |
|
| 321 | - * |
|
| 322 | - * @param array $process ? |
|
| 323 | - **/ |
|
| 324 | - public function __construct($process = []) { |
|
| 325 | - if (is_array($process)) { |
|
| 326 | - $this->process = $process; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - public $ids = []; |
|
| 331 | - public $idrefs = []; |
|
| 332 | - public $idrefss = []; |
|
| 333 | - public $debuts = []; |
|
| 334 | - public $fratrie = []; |
|
| 335 | - |
|
| 336 | - public $dtc = null; |
|
| 337 | - public $sax = null; |
|
| 338 | - public $depth = ''; |
|
| 339 | - public $entete = ''; |
|
| 340 | - public $page = ''; |
|
| 341 | - public $res = ''; |
|
| 342 | - public $err = []; |
|
| 343 | - public $contenu = []; |
|
| 344 | - public $ouvrant = []; |
|
| 345 | - public $reperes = []; |
|
| 346 | - public $process = [ |
|
| 347 | - 'debut' => 'xml_debutElement', |
|
| 348 | - 'fin' => 'xml_finElement', |
|
| 349 | - 'text' => 'xml_textElement', |
|
| 350 | - 'pi' => 'xml_piElement', |
|
| 351 | - 'default' => 'xml_defaultElement' |
|
| 352 | - ]; |
|
| 26 | + // https://code.spip.net/@validerElement |
|
| 27 | + public function validerElement($phraseur, $name, $attrs) { |
|
| 28 | + if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 29 | + if ($p = strpos($name, ':')) { |
|
| 30 | + $name = substr($name, $p + 1); |
|
| 31 | + $p = isset($this->dtc->elements[$name]); |
|
| 32 | + } |
|
| 33 | + if (!$p) { |
|
| 34 | + coordonnees_erreur($this, " <b>$name</b> : " |
|
| 35 | + . _T('zxml_inconnu_balise')); |
|
| 36 | + |
|
| 37 | + return; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + // controler les filles illegitimes, ca suffit |
|
| 41 | + $depth = $this->depth; |
|
| 42 | + $ouvrant = $this->ouvrant; |
|
| 43 | + #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 44 | + if (isset($ouvrant[$depth])) { |
|
| 45 | + if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 46 | + $pere = $r[1]; |
|
| 47 | + #spip_log("pere $pere"); |
|
| 48 | + if (isset($this->dtc->elements[$pere])) { |
|
| 49 | + $fils = $this->dtc->elements[$pere]; |
|
| 50 | + #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 51 | + if (!($p = @in_array($name, $fils))) { |
|
| 52 | + if ($p = strpos($name, ':')) { |
|
| 53 | + $p = substr($name, $p + 1); |
|
| 54 | + $p = @in_array($p, $fils); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + if (!$p) { |
|
| 58 | + $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 59 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 60 | + . _T('zxml_non_fils') |
|
| 61 | + . ' <b>' |
|
| 62 | + . $pere |
|
| 63 | + . '</b>' |
|
| 64 | + . (!$bons_peres ? '' |
|
| 65 | + : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 66 | + } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 67 | + $frat = substr($depth, 2); |
|
| 68 | + if (!isset($this->fratrie[$frat])) { |
|
| 69 | + $this->fratrie[$frat] = ''; |
|
| 70 | + } |
|
| 71 | + $this->fratrie[$frat] .= "$name "; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + // Init de la suite des balises a memoriser si regle difficile |
|
| 77 | + if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 78 | + $this->fratrie[$depth] = ''; |
|
| 79 | + } |
|
| 80 | + if (isset($this->dtc->attributs[$name])) { |
|
| 81 | + foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 82 | + if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 83 | + coordonnees_erreur($this, " <b>$n</b>" |
|
| 84 | + . ' : ' |
|
| 85 | + . _T('zxml_obligatoire_attribut') |
|
| 86 | + . " <b>$name</b>"); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // https://code.spip.net/@validerAttribut |
|
| 93 | + public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 94 | + // Si la balise est inconnue, eviter d'insister |
|
| 95 | + if (!isset($this->dtc->attributs[$bal])) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $a = $this->dtc->attributs[$bal]; |
|
| 100 | + if (!isset($a[$name])) { |
|
| 101 | + $bons = join(', ', array_keys($a)); |
|
| 102 | + if ($bons) { |
|
| 103 | + $bons = " title=' " . |
|
| 104 | + _T('zxml_connus_attributs') . |
|
| 105 | + ' : ' . |
|
| 106 | + $bons . |
|
| 107 | + "'"; |
|
| 108 | + } |
|
| 109 | + $bons .= " style='font-weight: bold'"; |
|
| 110 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 111 | + . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 112 | + . " <a$bons>$bal</a> (" |
|
| 113 | + . _T('zxml_survoler') |
|
| 114 | + . ')'); |
|
| 115 | + } else { |
|
| 116 | + $type = $a[$name][0]; |
|
| 117 | + if (!preg_match('/^\w+$/', $type)) { |
|
| 118 | + $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 119 | + } else { |
|
| 120 | + if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 121 | + $this->$f($phraseur, $name, $val, $bal); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + # else spip_log("$type type d'attribut inconnu"); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 129 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 133 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // https://code.spip.net/@validerAttribut_ID |
|
| 137 | + public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 138 | + if (isset($this->ids[$val])) { |
|
| 139 | + list($l, $c) = $this->ids[$val]; |
|
| 140 | + coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 141 | + . _T('zxml_valeur_attribut') |
|
| 142 | + . " <b>$name</b> " |
|
| 143 | + . _T('zxml_de') |
|
| 144 | + . " <b>$bal</b> " |
|
| 145 | + . _T('zxml_vu') |
|
| 146 | + . " (L$l,C$c)"); |
|
| 147 | + } else { |
|
| 148 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 149 | + $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // https://code.spip.net/@validerAttribut_IDREF |
|
| 154 | + public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 155 | + $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // https://code.spip.net/@validerAttribut_IDREFS |
|
| 159 | + public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 160 | + $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // https://code.spip.net/@valider_motif |
|
| 164 | + public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 165 | + if (!preg_match($motif, $val)) { |
|
| 166 | + coordonnees_erreur($this, "<b>$val</b> " |
|
| 167 | + . _T('zxml_valeur_attribut') |
|
| 168 | + . " <b>$name</b> " |
|
| 169 | + . _T('zxml_de') |
|
| 170 | + . " <b>$bal</b> " |
|
| 171 | + . _T('zxml_non_conforme') |
|
| 172 | + . '</p><p>' |
|
| 173 | + . '<b>' . $motif . '</b>'); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + // https://code.spip.net/@valider_idref |
|
| 178 | + public function valider_idref($nom, $ligne, $col) { |
|
| 179 | + if (!isset($this->ids[$nom])) { |
|
| 180 | + $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // https://code.spip.net/@valider_passe2 |
|
| 185 | + public function valider_passe2() { |
|
| 186 | + if (!$this->err) { |
|
| 187 | + foreach ($this->idrefs as $idref) { |
|
| 188 | + list($nom, $ligne, $col) = $idref; |
|
| 189 | + $this->valider_idref($nom, $ligne, $col); |
|
| 190 | + } |
|
| 191 | + foreach ($this->idrefss as $idref) { |
|
| 192 | + list($noms, $ligne, $col) = $idref; |
|
| 193 | + foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 194 | + $this->valider_idref($nom, $ligne, $col); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // https://code.spip.net/@debutElement |
|
| 201 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 202 | + if ($this->dtc->elements) { |
|
| 203 | + $this->validerElement($phraseur, $name, $attrs); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($f = $this->process['debut']) { |
|
| 207 | + $f($this, $name, $attrs); |
|
| 208 | + } |
|
| 209 | + $depth = $this->depth; |
|
| 210 | + $this->debuts[$depth] = strlen($this->res); |
|
| 211 | + foreach ($attrs as $k => $v) { |
|
| 212 | + $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // https://code.spip.net/@finElement |
|
| 217 | + public function finElement($phraseur, $name) { |
|
| 218 | + $depth = $this->depth; |
|
| 219 | + $contenu = $this->contenu; |
|
| 220 | + |
|
| 221 | + $n = strlen($this->res); |
|
| 222 | + $c = strlen(trim($contenu[$depth])); |
|
| 223 | + $k = $this->debuts[$depth]; |
|
| 224 | + |
|
| 225 | + $regle = isset($this->dtc->regles[$name]) ? $this->dtc->regles[$name] : false; |
|
| 226 | + $vide = ($regle == 'EMPTY'); |
|
| 227 | + // controler que les balises devant etre vides le sont |
|
| 228 | + if ($vide) { |
|
| 229 | + if ($n <> ($k + $c)) { |
|
| 230 | + coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 231 | + } |
|
| 232 | + // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 233 | + } elseif ($regle and ($regle != '*')) { |
|
| 234 | + if ($regle == '+') { |
|
| 235 | + // iteration de disjonction non vide: 1 balise au - |
|
| 236 | + if ($n == $k) { |
|
| 237 | + coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 238 | + . _T('zxml_vide_balise')); |
|
| 239 | + } |
|
| 240 | + } else { |
|
| 241 | + $f = isset($this->fratrie[substr($depth, 2)]) ? $this->fratrie[substr($depth, 2)] : null; |
|
| 242 | + if (is_null($f) or !preg_match($regle, $f)) { |
|
| 243 | + coordonnees_erreur( |
|
| 244 | + $this, |
|
| 245 | + " <p>\n<b>$name</b> " |
|
| 246 | + . _T('zxml_succession_fils_incorrecte') |
|
| 247 | + . ' : <b>' |
|
| 248 | + . $f |
|
| 249 | + . '</b>' |
|
| 250 | + ); |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + if ($f = $this->process['fin']) { |
|
| 255 | + $f($this, $name, $vide); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + // https://code.spip.net/@textElement |
|
| 260 | + public function textElement($phraseur, $data) { |
|
| 261 | + if (trim($data)) { |
|
| 262 | + $d = $this->depth; |
|
| 263 | + $d = $this->ouvrant[$d]; |
|
| 264 | + preg_match('/^\s*(\S+)/', $d, $m); |
|
| 265 | + if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 266 | + coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 267 | + . _T('zxml_nonvide_balise')); // message a affiner |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + if ($f = $this->process['text']) { |
|
| 271 | + $f($this, $data); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + public function piElement($phraseur, $target, $data) { |
|
| 276 | + if ($f = $this->process['pi']) { |
|
| 277 | + $f($this, $target, $data); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + // Denonciation des entitees XML inconnues |
|
| 282 | + // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 283 | + // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 284 | + // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 285 | + // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 286 | + // le source de la page laisse legitimement supposer. |
|
| 287 | + |
|
| 288 | + // https://code.spip.net/@defautElement |
|
| 289 | + public function defaultElement($phraseur, $data) { |
|
| 290 | + if ( |
|
| 291 | + !preg_match('/^<!--/', $data) |
|
| 292 | + and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 293 | + ) { |
|
| 294 | + foreach ($r as $m) { |
|
| 295 | + list($t, $e) = $m; |
|
| 296 | + if (!isset($this->dtc->entites[$e])) { |
|
| 297 | + coordonnees_erreur($this, " <b>$e</b> " |
|
| 298 | + . _T('zxml_inconnu_entite') |
|
| 299 | + . ' '); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 304 | + $f($this, $data); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + // https://code.spip.net/@phraserTout |
|
| 309 | + public function phraserTout($phraseur, $data) { |
|
| 310 | + xml_parsestring($this, $data); |
|
| 311 | + |
|
| 312 | + if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 313 | + $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 314 | + } else { |
|
| 315 | + $this->valider_passe2($this); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Constructeur |
|
| 321 | + * |
|
| 322 | + * @param array $process ? |
|
| 323 | + **/ |
|
| 324 | + public function __construct($process = []) { |
|
| 325 | + if (is_array($process)) { |
|
| 326 | + $this->process = $process; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + public $ids = []; |
|
| 331 | + public $idrefs = []; |
|
| 332 | + public $idrefss = []; |
|
| 333 | + public $debuts = []; |
|
| 334 | + public $fratrie = []; |
|
| 335 | + |
|
| 336 | + public $dtc = null; |
|
| 337 | + public $sax = null; |
|
| 338 | + public $depth = ''; |
|
| 339 | + public $entete = ''; |
|
| 340 | + public $page = ''; |
|
| 341 | + public $res = ''; |
|
| 342 | + public $err = []; |
|
| 343 | + public $contenu = []; |
|
| 344 | + public $ouvrant = []; |
|
| 345 | + public $reperes = []; |
|
| 346 | + public $process = [ |
|
| 347 | + 'debut' => 'xml_debutElement', |
|
| 348 | + 'fin' => 'xml_finElement', |
|
| 349 | + 'text' => 'xml_textElement', |
|
| 350 | + 'pi' => 'xml_piElement', |
|
| 351 | + 'default' => 'xml_defaultElement' |
|
| 352 | + ]; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | |
@@ -359,8 +359,8 @@ discard block |
||
| 359 | 359 | * |
| 360 | 360 | **/ |
| 361 | 361 | function xml_valider_dist($page, $apply = false, $process = false, $doctype = '', $charset = null) { |
| 362 | - $f = new ValidateurXML($process); |
|
| 363 | - $sax = charger_fonction('sax', 'xml'); |
|
| 362 | + $f = new ValidateurXML($process); |
|
| 363 | + $sax = charger_fonction('sax', 'xml'); |
|
| 364 | 364 | |
| 365 | - return $sax($page, $apply, $f, $doctype, $charset); |
|
| 365 | + return $sax($page, $apply, $f, $doctype, $charset); |
|
| 366 | 366 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | . $pere |
| 63 | 63 | . '</b>' |
| 64 | 64 | . (!$bons_peres ? '' |
| 65 | - : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 65 | + : ('<p style="font-size: 80%"> '._T('zxml_mais_de').' <b>'.$bons_peres.'</b></p>'))); |
|
| 66 | 66 | } elseif ($this->dtc->regles[$pere][0] == '/') { |
| 67 | 67 | $frat = substr($depth, 2); |
| 68 | 68 | if (!isset($this->fratrie[$frat])) { |
@@ -100,15 +100,15 @@ discard block |
||
| 100 | 100 | if (!isset($a[$name])) { |
| 101 | 101 | $bons = join(', ', array_keys($a)); |
| 102 | 102 | if ($bons) { |
| 103 | - $bons = " title=' " . |
|
| 104 | - _T('zxml_connus_attributs') . |
|
| 105 | - ' : ' . |
|
| 106 | - $bons . |
|
| 103 | + $bons = " title=' ". |
|
| 104 | + _T('zxml_connus_attributs'). |
|
| 105 | + ' : '. |
|
| 106 | + $bons. |
|
| 107 | 107 | "'"; |
| 108 | 108 | } |
| 109 | 109 | $bons .= " style='font-weight: bold'"; |
| 110 | 110 | coordonnees_erreur($this, " <b>$name</b> " |
| 111 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 111 | + . _T('zxml_inconnu_attribut').' '._T('zxml_de') |
|
| 112 | 112 | . " <a$bons>$bal</a> (" |
| 113 | 113 | . _T('zxml_survoler') |
| 114 | 114 | . ')'); |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | if (!preg_match('/^\w+$/', $type)) { |
| 118 | 118 | $this->valider_motif($phraseur, $name, $val, $bal, $type); |
| 119 | 119 | } else { |
| 120 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 120 | + if (method_exists($this, $f = 'validerAttribut_'.$type)) { |
|
| 121 | 121 | $this->$f($phraseur, $name, $val, $bal); |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -170,14 +170,14 @@ discard block |
||
| 170 | 170 | . " <b>$bal</b> " |
| 171 | 171 | . _T('zxml_non_conforme') |
| 172 | 172 | . '</p><p>' |
| 173 | - . '<b>' . $motif . '</b>'); |
|
| 173 | + . '<b>'.$motif.'</b>'); |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | // https://code.spip.net/@valider_idref |
| 178 | 178 | public function valider_idref($nom, $ligne, $col) { |
| 179 | 179 | if (!isset($this->ids[$nom])) { |
| 180 | - $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 180 | + $this->err[] = [" <p><b>$nom</b> "._T('zxml_inconnu_id'), $ligne, $col]; |
|
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | // controler que les balises devant etre vides le sont |
| 228 | 228 | if ($vide) { |
| 229 | 229 | if ($n <> ($k + $c)) { |
| 230 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 230 | + coordonnees_erreur($this, " <p><b>$name</b> "._T('zxml_nonvide_balise')); |
|
| 231 | 231 | } |
| 232 | 232 | // pour les regles PCDATA ou iteration de disjonction, tout est fait |
| 233 | 233 | } elseif ($regle and ($regle != '*')) { |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | $d = $this->ouvrant[$d]; |
| 264 | 264 | preg_match('/^\s*(\S+)/', $d, $m); |
| 265 | 265 | if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
| 266 | - coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 266 | + coordonnees_erreur($this, ' <p><b>'.$m[1].'</b> ' |
|
| 267 | 267 | . _T('zxml_nonvide_balise')); // message a affiner |
| 268 | 268 | } |
| 269 | 269 | } |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | public function phraserTout($phraseur, $data) { |
| 310 | 310 | xml_parsestring($this, $data); |
| 311 | 311 | |
| 312 | - if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 312 | + if (!$this->dtc or preg_match(',^'._MESSAGE_DOCTYPE.',', $data)) { |
|
| 313 | 313 | $this->err[] = ['DOCTYPE ?', 0, 0]; |
| 314 | 314 | } else { |
| 315 | 315 | $this->valider_passe2($this); |
@@ -11,58 +11,58 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('xml/interfaces'); |
| 18 | 18 | |
| 19 | 19 | // https://code.spip.net/@charger_dtd |
| 20 | 20 | function charger_dtd($grammaire, $avail, $rotlvl) { |
| 21 | - static $dtd = []; # cache bien utile pour le validateur en boucle |
|
| 22 | - |
|
| 23 | - if (isset($dtd[$grammaire])) { |
|
| 24 | - return $dtd[$grammaire]; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - if ($avail == 'SYSTEM') { |
|
| 28 | - $grammaire = find_in_path($grammaire); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | - |
|
| 33 | - if (lire_fichier($file, $r)) { |
|
| 34 | - if (!$grammaire) { |
|
| 35 | - return []; |
|
| 36 | - } |
|
| 37 | - if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) { |
|
| 38 | - $r = false; |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - if ($r) { |
|
| 43 | - $dtc = unserialize($r); |
|
| 44 | - } else { |
|
| 45 | - spip_timer('dtd'); |
|
| 46 | - $dtc = new DTC(); |
|
| 47 | - // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 48 | - // Retourner vide en cas d'echec |
|
| 49 | - if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 50 | - $dtc = []; |
|
| 51 | - } else { |
|
| 52 | - // tri final pour presenter les suggestions de corrections |
|
| 53 | - foreach ($dtc->peres as $k => $v) { |
|
| 54 | - asort($v); |
|
| 55 | - $dtc->peres[$k] = $v; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . ' entites'); |
|
| 59 | - # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 60 | - ecrire_fichier($file, serialize($dtc), true); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - $dtd[$grammaire] = $dtc; |
|
| 64 | - |
|
| 65 | - return $dtc; |
|
| 21 | + static $dtd = []; # cache bien utile pour le validateur en boucle |
|
| 22 | + |
|
| 23 | + if (isset($dtd[$grammaire])) { |
|
| 24 | + return $dtd[$grammaire]; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + if ($avail == 'SYSTEM') { |
|
| 28 | + $grammaire = find_in_path($grammaire); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | + |
|
| 33 | + if (lire_fichier($file, $r)) { |
|
| 34 | + if (!$grammaire) { |
|
| 35 | + return []; |
|
| 36 | + } |
|
| 37 | + if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) { |
|
| 38 | + $r = false; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + if ($r) { |
|
| 43 | + $dtc = unserialize($r); |
|
| 44 | + } else { |
|
| 45 | + spip_timer('dtd'); |
|
| 46 | + $dtc = new DTC(); |
|
| 47 | + // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 48 | + // Retourner vide en cas d'echec |
|
| 49 | + if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 50 | + $dtc = []; |
|
| 51 | + } else { |
|
| 52 | + // tri final pour presenter les suggestions de corrections |
|
| 53 | + foreach ($dtc->peres as $k => $v) { |
|
| 54 | + asort($v); |
|
| 55 | + $dtc->peres[$k] = $v; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . ' entites'); |
|
| 59 | + # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 60 | + ecrire_fichier($file, serialize($dtc), true); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + $dtd[$grammaire] = $dtc; |
|
| 64 | + |
|
| 65 | + return $dtc; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Compiler une regle de production en une Regexp qu'on appliquera sur la |
@@ -75,157 +75,157 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | // https://code.spip.net/@compilerRegle |
| 77 | 77 | function compilerRegle($val) { |
| 78 | - $x = str_replace( |
|
| 79 | - '()', |
|
| 80 | - '', |
|
| 81 | - preg_replace( |
|
| 82 | - '/\s*,\s*/', |
|
| 83 | - '', |
|
| 84 | - preg_replace( |
|
| 85 | - '/(\w+)\s*/', |
|
| 86 | - '(?:\1 )', |
|
| 87 | - preg_replace( |
|
| 88 | - '/\s*\)/', |
|
| 89 | - ')', |
|
| 90 | - preg_replace( |
|
| 91 | - '/\s*([(+*|?])\s*/', |
|
| 92 | - '\1', |
|
| 93 | - preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val) |
|
| 94 | - ) |
|
| 95 | - ) |
|
| 96 | - ) |
|
| 97 | - ) |
|
| 98 | - ); |
|
| 99 | - |
|
| 100 | - return $x; |
|
| 78 | + $x = str_replace( |
|
| 79 | + '()', |
|
| 80 | + '', |
|
| 81 | + preg_replace( |
|
| 82 | + '/\s*,\s*/', |
|
| 83 | + '', |
|
| 84 | + preg_replace( |
|
| 85 | + '/(\w+)\s*/', |
|
| 86 | + '(?:\1 )', |
|
| 87 | + preg_replace( |
|
| 88 | + '/\s*\)/', |
|
| 89 | + ')', |
|
| 90 | + preg_replace( |
|
| 91 | + '/\s*([(+*|?])\s*/', |
|
| 92 | + '\1', |
|
| 93 | + preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val) |
|
| 94 | + ) |
|
| 95 | + ) |
|
| 96 | + ) |
|
| 97 | + ) |
|
| 98 | + ); |
|
| 99 | + |
|
| 100 | + return $x; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | |
| 104 | 104 | // https://code.spip.net/@analyser_dtd |
| 105 | 105 | function analyser_dtd($loc, $avail, &$dtc) { |
| 106 | - // creer le repertoire de cache si ce n'est fait |
|
| 107 | - // (utile aussi pour le resultat de la compil) |
|
| 108 | - $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 109 | - // si DTD locale, ignorer ce repertoire pour le moment |
|
| 110 | - if ($avail == 'SYSTEM') { |
|
| 111 | - $file = $loc; |
|
| 112 | - if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 113 | - $file = substr($file, strlen(_DIR_RACINE)); |
|
| 114 | - } |
|
| 115 | - $file = find_in_path($file); |
|
| 116 | - } else { |
|
| 117 | - $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $dtd = ''; |
|
| 121 | - if (@is_readable($file)) { |
|
| 122 | - lire_fichier($file, $dtd); |
|
| 123 | - } else { |
|
| 124 | - if ($avail == 'PUBLIC') { |
|
| 125 | - include_spip('inc/distant'); |
|
| 126 | - $dtd = recuperer_url($loc); |
|
| 127 | - $dtd = trim($dtd['page'] ?? ''); |
|
| 128 | - if ($dtd) { |
|
| 129 | - ecrire_fichier($file, $dtd, true); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - $dtd = ltrim($dtd); |
|
| 135 | - if (!$dtd) { |
|
| 136 | - spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 137 | - |
|
| 138 | - return false; |
|
| 139 | - } else { |
|
| 140 | - spip_log("analyse de la DTD $loc "); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - while ($dtd) { |
|
| 144 | - if ($dtd[0] != '<') { |
|
| 145 | - $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 146 | - } elseif ($dtd[1] != '!') { |
|
| 147 | - $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 148 | - } elseif ($dtd[2] == '[') { |
|
| 149 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 150 | - } else { |
|
| 151 | - switch ($dtd[3]) { |
|
| 152 | - case '%': |
|
| 153 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 154 | - break; |
|
| 155 | - case 'T': |
|
| 156 | - $r = analyser_dtd_attlist($dtd, $dtc, $loc); |
|
| 157 | - break; |
|
| 158 | - case 'L': |
|
| 159 | - $r = analyser_dtd_element($dtd, $dtc, $loc); |
|
| 160 | - break; |
|
| 161 | - case 'N': |
|
| 162 | - $r = analyser_dtd_entity($dtd, $dtc, $loc); |
|
| 163 | - break; |
|
| 164 | - case 'O': |
|
| 165 | - $r = analyser_dtd_notation($dtd, $dtc, $loc); |
|
| 166 | - break; |
|
| 167 | - case '-': |
|
| 168 | - $r = analyser_dtd_comment($dtd, $dtc, $loc); |
|
| 169 | - break; |
|
| 170 | - default: |
|
| 171 | - $r = -1; |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - if (!is_string($r)) { |
|
| 175 | - spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 176 | - |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - $dtd = $r; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return true; |
|
| 106 | + // creer le repertoire de cache si ce n'est fait |
|
| 107 | + // (utile aussi pour le resultat de la compil) |
|
| 108 | + $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 109 | + // si DTD locale, ignorer ce repertoire pour le moment |
|
| 110 | + if ($avail == 'SYSTEM') { |
|
| 111 | + $file = $loc; |
|
| 112 | + if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 113 | + $file = substr($file, strlen(_DIR_RACINE)); |
|
| 114 | + } |
|
| 115 | + $file = find_in_path($file); |
|
| 116 | + } else { |
|
| 117 | + $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $dtd = ''; |
|
| 121 | + if (@is_readable($file)) { |
|
| 122 | + lire_fichier($file, $dtd); |
|
| 123 | + } else { |
|
| 124 | + if ($avail == 'PUBLIC') { |
|
| 125 | + include_spip('inc/distant'); |
|
| 126 | + $dtd = recuperer_url($loc); |
|
| 127 | + $dtd = trim($dtd['page'] ?? ''); |
|
| 128 | + if ($dtd) { |
|
| 129 | + ecrire_fichier($file, $dtd, true); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + $dtd = ltrim($dtd); |
|
| 135 | + if (!$dtd) { |
|
| 136 | + spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 137 | + |
|
| 138 | + return false; |
|
| 139 | + } else { |
|
| 140 | + spip_log("analyse de la DTD $loc "); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + while ($dtd) { |
|
| 144 | + if ($dtd[0] != '<') { |
|
| 145 | + $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 146 | + } elseif ($dtd[1] != '!') { |
|
| 147 | + $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 148 | + } elseif ($dtd[2] == '[') { |
|
| 149 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 150 | + } else { |
|
| 151 | + switch ($dtd[3]) { |
|
| 152 | + case '%': |
|
| 153 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 154 | + break; |
|
| 155 | + case 'T': |
|
| 156 | + $r = analyser_dtd_attlist($dtd, $dtc, $loc); |
|
| 157 | + break; |
|
| 158 | + case 'L': |
|
| 159 | + $r = analyser_dtd_element($dtd, $dtc, $loc); |
|
| 160 | + break; |
|
| 161 | + case 'N': |
|
| 162 | + $r = analyser_dtd_entity($dtd, $dtc, $loc); |
|
| 163 | + break; |
|
| 164 | + case 'O': |
|
| 165 | + $r = analyser_dtd_notation($dtd, $dtc, $loc); |
|
| 166 | + break; |
|
| 167 | + case '-': |
|
| 168 | + $r = analyser_dtd_comment($dtd, $dtc, $loc); |
|
| 169 | + break; |
|
| 170 | + default: |
|
| 171 | + $r = -1; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + if (!is_string($r)) { |
|
| 175 | + spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 176 | + |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + $dtd = $r; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return true; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // https://code.spip.net/@analyser_dtd_comment |
| 186 | 186 | function analyser_dtd_comment($dtd, &$dtc, $grammaire) { |
| 187 | - // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 188 | - // Option /s car sur plusieurs lignes parfois |
|
| 187 | + // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 188 | + // Option /s car sur plusieurs lignes parfois |
|
| 189 | 189 | |
| 190 | - if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 191 | - return -6; |
|
| 192 | - } |
|
| 190 | + if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 191 | + return -6; |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - return $m[1]; |
|
| 194 | + return $m[1]; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | // https://code.spip.net/@analyser_dtd_pi |
| 198 | 198 | function analyser_dtd_pi($dtd, &$dtc, $grammaire) { |
| 199 | - if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 200 | - return -10; |
|
| 201 | - } |
|
| 199 | + if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 200 | + return -10; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - return $m[1]; |
|
| 203 | + return $m[1]; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | // https://code.spip.net/@analyser_dtd_lexeme |
| 207 | 207 | function analyser_dtd_lexeme($dtd, &$dtc, $grammaire) { |
| 208 | 208 | |
| 209 | - if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 210 | - return -9; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - list(, $s) = $m; |
|
| 214 | - $n = $dtc->macros[$s]; |
|
| 215 | - |
|
| 216 | - if (is_array($n)) { |
|
| 217 | - // en cas d'inclusion, l'espace de nom est le meme |
|
| 218 | - // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 219 | - if ( |
|
| 220 | - ($n[0] == 'PUBLIC') |
|
| 221 | - and !tester_url_absolue($n[1]) |
|
| 222 | - ) { |
|
| 223 | - $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 224 | - } |
|
| 225 | - analyser_dtd($n[1], $n[0], $dtc); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return ltrim(substr($dtd, strlen($m[0]))); |
|
| 209 | + if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 210 | + return -9; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + list(, $s) = $m; |
|
| 214 | + $n = $dtc->macros[$s]; |
|
| 215 | + |
|
| 216 | + if (is_array($n)) { |
|
| 217 | + // en cas d'inclusion, l'espace de nom est le meme |
|
| 218 | + // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 219 | + if ( |
|
| 220 | + ($n[0] == 'PUBLIC') |
|
| 221 | + and !tester_url_absolue($n[1]) |
|
| 222 | + ) { |
|
| 223 | + $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 224 | + } |
|
| 225 | + analyser_dtd($n[1], $n[0], $dtc); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return ltrim(substr($dtd, strlen($m[0]))); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // il faudrait gerer plus proprement les niveaux d'inclusion: |
@@ -234,85 +234,85 @@ discard block |
||
| 234 | 234 | // https://code.spip.net/@analyser_dtd_data |
| 235 | 235 | function analyser_dtd_data($dtd, &$dtc, $grammaire) { |
| 236 | 236 | |
| 237 | - if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 238 | - return -11; |
|
| 239 | - } |
|
| 240 | - if ( |
|
| 241 | - !preg_match( |
|
| 242 | - '/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', |
|
| 243 | - $m[2], |
|
| 244 | - $r |
|
| 245 | - ) |
|
| 246 | - ) { |
|
| 247 | - return -12; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - if ($dtc->macros[$m[1]] == 'INCLUDE') { |
|
| 251 | - $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 252 | - } else { |
|
| 253 | - $retour = substr($m[2], strlen($r[0])); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - return $retour; |
|
| 237 | + if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 238 | + return -11; |
|
| 239 | + } |
|
| 240 | + if ( |
|
| 241 | + !preg_match( |
|
| 242 | + '/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', |
|
| 243 | + $m[2], |
|
| 244 | + $r |
|
| 245 | + ) |
|
| 246 | + ) { |
|
| 247 | + return -12; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + if ($dtc->macros[$m[1]] == 'INCLUDE') { |
|
| 251 | + $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 252 | + } else { |
|
| 253 | + $retour = substr($m[2], strlen($r[0])); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + return $retour; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // https://code.spip.net/@analyser_dtd_notation |
| 260 | 260 | function analyser_dtd_notation($dtd, &$dtc, $grammaire) { |
| 261 | - if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 262 | - return -8; |
|
| 263 | - } |
|
| 264 | - spip_log('analyser_dtd_notation a ecrire'); |
|
| 261 | + if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 262 | + return -8; |
|
| 263 | + } |
|
| 264 | + spip_log('analyser_dtd_notation a ecrire'); |
|
| 265 | 265 | |
| 266 | - return $m[1]; |
|
| 266 | + return $m[1]; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // https://code.spip.net/@analyser_dtd_entity |
| 270 | 270 | function analyser_dtd_entity($dtd, &$dtc, $grammaire) { |
| 271 | - if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 272 | - return -2; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - list($t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd) = $m; |
|
| 276 | - |
|
| 277 | - if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) { |
|
| 278 | - return $dtd; |
|
| 279 | - } |
|
| 280 | - if (isset($dtc->entites[$nom])) { |
|
| 281 | - spip_log("redefinition de l'entite $nom"); |
|
| 282 | - } |
|
| 283 | - if ($k6) { |
|
| 284 | - return $k6 . $dtd; |
|
| 285 | - } // cas du synonyme complet |
|
| 286 | - $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 287 | - |
|
| 288 | - // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 289 | - if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 290 | - list($t, $type, $val, $q, $alt) = $r; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - if (!$term) { |
|
| 294 | - $dtc->entites[$nom] = $val; |
|
| 295 | - } elseif (!$type) { |
|
| 296 | - $dtc->macros[$nom] = $val; |
|
| 297 | - } else { |
|
| 298 | - if (($type == 'SYSTEM') and !$alt) { |
|
| 299 | - $alt = $val; |
|
| 300 | - } |
|
| 301 | - if (!$alt) { |
|
| 302 | - $dtc->macros[$nom] = $val; |
|
| 303 | - } else { |
|
| 304 | - if ( |
|
| 305 | - ($type == 'PUBLIC') |
|
| 306 | - and (strpos($alt, '/') === false) |
|
| 307 | - ) { |
|
| 308 | - $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 309 | - . $alt; |
|
| 310 | - } |
|
| 311 | - $dtc->macros[$nom] = [$type, $alt]; |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - return $dtd; |
|
| 271 | + if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 272 | + return -2; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + list($t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd) = $m; |
|
| 276 | + |
|
| 277 | + if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) { |
|
| 278 | + return $dtd; |
|
| 279 | + } |
|
| 280 | + if (isset($dtc->entites[$nom])) { |
|
| 281 | + spip_log("redefinition de l'entite $nom"); |
|
| 282 | + } |
|
| 283 | + if ($k6) { |
|
| 284 | + return $k6 . $dtd; |
|
| 285 | + } // cas du synonyme complet |
|
| 286 | + $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 287 | + |
|
| 288 | + // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 289 | + if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 290 | + list($t, $type, $val, $q, $alt) = $r; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + if (!$term) { |
|
| 294 | + $dtc->entites[$nom] = $val; |
|
| 295 | + } elseif (!$type) { |
|
| 296 | + $dtc->macros[$nom] = $val; |
|
| 297 | + } else { |
|
| 298 | + if (($type == 'SYSTEM') and !$alt) { |
|
| 299 | + $alt = $val; |
|
| 300 | + } |
|
| 301 | + if (!$alt) { |
|
| 302 | + $dtc->macros[$nom] = $val; |
|
| 303 | + } else { |
|
| 304 | + if ( |
|
| 305 | + ($type == 'PUBLIC') |
|
| 306 | + and (strpos($alt, '/') === false) |
|
| 307 | + ) { |
|
| 308 | + $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 309 | + . $alt; |
|
| 310 | + } |
|
| 311 | + $dtc->macros[$nom] = [$type, $alt]; |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + return $dtd; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // Dresser le tableau des filles potentielles de l'element |
@@ -326,77 +326,77 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | // https://code.spip.net/@analyser_dtd_element |
| 328 | 328 | function analyser_dtd_element($dtd, &$dtc, $grammaire) { |
| 329 | - if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 330 | - return -3; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - list(, $nom, $contenu, $dtd) = $m; |
|
| 334 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 335 | - |
|
| 336 | - if (isset($dtc->elements[$nom])) { |
|
| 337 | - spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 338 | - |
|
| 339 | - return -4; |
|
| 340 | - } |
|
| 341 | - $filles = []; |
|
| 342 | - $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 343 | - $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 344 | - if ($val == '(?:EMPTY )') { |
|
| 345 | - $dtc->regles[$nom] = 'EMPTY'; |
|
| 346 | - } elseif ($val == '(?:ANY )') { |
|
| 347 | - $dtc->regles[$nom] = 'ANY'; |
|
| 348 | - } else { |
|
| 349 | - $last = substr($val, -1); |
|
| 350 | - if ( |
|
| 351 | - preg_match('/ \w/', $val) |
|
| 352 | - or (!empty($last) and strpos('*+?', $last) === false) |
|
| 353 | - ) { |
|
| 354 | - $dtc->regles[$nom] = "/^$val$/"; |
|
| 355 | - } else { |
|
| 356 | - $dtc->regles[$nom] = $last; |
|
| 357 | - } |
|
| 358 | - $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 359 | - |
|
| 360 | - foreach ($filles as $k) { |
|
| 361 | - if (!isset($dtc->peres[$k])) { |
|
| 362 | - $dtc->peres[$k] = []; |
|
| 363 | - } |
|
| 364 | - if (!in_array($nom, $dtc->peres[$k])) { |
|
| 365 | - $dtc->peres[$k][] = $nom; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false); |
|
| 370 | - $dtc->elements[$nom] = $filles; |
|
| 371 | - |
|
| 372 | - return $dtd; |
|
| 329 | + if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 330 | + return -3; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + list(, $nom, $contenu, $dtd) = $m; |
|
| 334 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 335 | + |
|
| 336 | + if (isset($dtc->elements[$nom])) { |
|
| 337 | + spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 338 | + |
|
| 339 | + return -4; |
|
| 340 | + } |
|
| 341 | + $filles = []; |
|
| 342 | + $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 343 | + $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 344 | + if ($val == '(?:EMPTY )') { |
|
| 345 | + $dtc->regles[$nom] = 'EMPTY'; |
|
| 346 | + } elseif ($val == '(?:ANY )') { |
|
| 347 | + $dtc->regles[$nom] = 'ANY'; |
|
| 348 | + } else { |
|
| 349 | + $last = substr($val, -1); |
|
| 350 | + if ( |
|
| 351 | + preg_match('/ \w/', $val) |
|
| 352 | + or (!empty($last) and strpos('*+?', $last) === false) |
|
| 353 | + ) { |
|
| 354 | + $dtc->regles[$nom] = "/^$val$/"; |
|
| 355 | + } else { |
|
| 356 | + $dtc->regles[$nom] = $last; |
|
| 357 | + } |
|
| 358 | + $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 359 | + |
|
| 360 | + foreach ($filles as $k) { |
|
| 361 | + if (!isset($dtc->peres[$k])) { |
|
| 362 | + $dtc->peres[$k] = []; |
|
| 363 | + } |
|
| 364 | + if (!in_array($nom, $dtc->peres[$k])) { |
|
| 365 | + $dtc->peres[$k][] = $nom; |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false); |
|
| 370 | + $dtc->elements[$nom] = $filles; |
|
| 371 | + |
|
| 372 | + return $dtd; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | |
| 376 | 376 | // https://code.spip.net/@analyser_dtd_attlist |
| 377 | 377 | function analyser_dtd_attlist($dtd, &$dtc, $grammaire) { |
| 378 | - if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 379 | - return -5; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - list(, $nom, $val, $dtd) = $m; |
|
| 383 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 384 | - $val = expanserEntite($val, $dtc->macros); |
|
| 385 | - if (!isset($dtc->attributs[$nom])) { |
|
| 386 | - $dtc->attributs[$nom] = []; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 390 | - foreach ($r2 as $m2) { |
|
| 391 | - $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 392 | - : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 393 | - $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 394 | - $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 395 | - $dtc->attributs[$nom][$m21] = [$v, $m25]; |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - return $dtd; |
|
| 378 | + if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 379 | + return -5; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + list(, $nom, $val, $dtd) = $m; |
|
| 383 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 384 | + $val = expanserEntite($val, $dtc->macros); |
|
| 385 | + if (!isset($dtc->attributs[$nom])) { |
|
| 386 | + $dtc->attributs[$nom] = []; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 390 | + foreach ($r2 as $m2) { |
|
| 391 | + $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 392 | + : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 393 | + $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 394 | + $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 395 | + $dtc->attributs[$nom][$m21] = [$v, $m25]; |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + return $dtd; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | |
@@ -412,26 +412,26 @@ discard block |
||
| 412 | 412 | * @return string|array |
| 413 | 413 | **/ |
| 414 | 414 | function expanserEntite($val, $macros = []) { |
| 415 | - static $vu = []; |
|
| 416 | - if (!is_string($val)) { |
|
| 417 | - return $vu; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 421 | - foreach ($r as $m) { |
|
| 422 | - $ent = $m[1]; |
|
| 423 | - // il peut valoir "" |
|
| 424 | - if (!isset($macros[$ent])) { |
|
| 425 | - spip_log("Entite $ent inconnu"); |
|
| 426 | - } else { |
|
| 427 | - if (!isset($vu[$ent])) { |
|
| 428 | - $vu[$ent] = 0; |
|
| 429 | - } |
|
| 430 | - ++$vu[$ent]; |
|
| 431 | - $val = str_replace($m[0], $macros[$ent], $val); |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 415 | + static $vu = []; |
|
| 416 | + if (!is_string($val)) { |
|
| 417 | + return $vu; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 421 | + foreach ($r as $m) { |
|
| 422 | + $ent = $m[1]; |
|
| 423 | + // il peut valoir "" |
|
| 424 | + if (!isset($macros[$ent])) { |
|
| 425 | + spip_log("Entite $ent inconnu"); |
|
| 426 | + } else { |
|
| 427 | + if (!isset($vu[$ent])) { |
|
| 428 | + $vu[$ent] = 0; |
|
| 429 | + } |
|
| 430 | + ++$vu[$ent]; |
|
| 431 | + $val = str_replace($m[0], $macros[$ent], $val); |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 437 | 437 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | $grammaire = find_in_path($grammaire); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 31 | + $file = _DIR_CACHE_XML.preg_replace('/[^\w.]/', '_', $rotlvl).'.gz'; |
|
| 32 | 32 | |
| 33 | 33 | if (lire_fichier($file, $r)) { |
| 34 | 34 | if (!$grammaire) { |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $dtc->peres[$k] = $v; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . ' entites'); |
|
| 58 | + spip_log("Analyser DTD $avail $grammaire (".spip_timer('dtd').') '.count($dtc->macros).' macros, '.count($dtc->elements).' elements, '.count($dtc->attributs)." listes d'attributs, ".count($dtc->entites).' entites'); |
|
| 59 | 59 | # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
| 60 | 60 | ecrire_fichier($file, serialize($dtc), true); |
| 61 | 61 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | if (!is_string($r)) { |
| 175 | - spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 175 | + spip_log("erreur $r dans la DTD ".substr($dtd, 0, 80).'.....'); |
|
| 176 | 176 | |
| 177 | 177 | return false; |
| 178 | 178 | } |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | ($n[0] == 'PUBLIC') |
| 221 | 221 | and !tester_url_absolue($n[1]) |
| 222 | 222 | ) { |
| 223 | - $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 223 | + $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1).$n[1]; |
|
| 224 | 224 | } |
| 225 | 225 | analyser_dtd($n[1], $n[0], $dtc); |
| 226 | 226 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | if ($dtc->macros[$m[1]] == 'INCLUDE') { |
| 251 | - $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 251 | + $retour = $r[1].substr($m[2], strlen($r[0])); |
|
| 252 | 252 | } else { |
| 253 | 253 | $retour = substr($m[2], strlen($r[0])); |
| 254 | 254 | } |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | spip_log("redefinition de l'entite $nom"); |
| 282 | 282 | } |
| 283 | 283 | if ($k6) { |
| 284 | - return $k6 . $dtd; |
|
| 284 | + return $k6.$dtd; |
|
| 285 | 285 | } // cas du synonyme complet |
| 286 | 286 | $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
| 287 | 287 | |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
| 390 | 390 | foreach ($r2 as $m2) { |
| 391 | 391 | $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
| 392 | - : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 392 | + : ('/^'.preg_replace('/\s+/', '', $m2[2]).'$/'); |
|
| 393 | 393 | $m21 = expanserEntite($m2[1], $dtc->macros); |
| 394 | 394 | $m25 = expanserEntite($m2[5], $dtc->macros); |
| 395 | 395 | $dtc->attributs[$nom][$m21] = [$v, $m25]; |
@@ -11,61 +11,61 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | class IndenteurXML { |
| 18 | 18 | |
| 19 | - // https://code.spip.net/@debutElement |
|
| 20 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 21 | - xml_debutElement($this, $name, $attrs); |
|
| 22 | - } |
|
| 19 | + // https://code.spip.net/@debutElement |
|
| 20 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 21 | + xml_debutElement($this, $name, $attrs); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - // https://code.spip.net/@finElement |
|
| 25 | - public function finElement($phraseur, $name) { |
|
| 26 | - xml_finElement($this, $name); |
|
| 27 | - } |
|
| 24 | + // https://code.spip.net/@finElement |
|
| 25 | + public function finElement($phraseur, $name) { |
|
| 26 | + xml_finElement($this, $name); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - // https://code.spip.net/@textElement |
|
| 30 | - public function textElement($phraseur, $data) { |
|
| 31 | - xml_textElement($this, $data); |
|
| 32 | - } |
|
| 29 | + // https://code.spip.net/@textElement |
|
| 30 | + public function textElement($phraseur, $data) { |
|
| 31 | + xml_textElement($this, $data); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public function piElement($phraseur, $target, $data) { |
|
| 35 | - xml_PiElement($this, $target, $data); |
|
| 36 | - } |
|
| 34 | + public function piElement($phraseur, $target, $data) { |
|
| 35 | + xml_PiElement($this, $target, $data); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - // https://code.spip.net/@defautElement |
|
| 39 | - public function defaultElement($phraseur, $data) { |
|
| 40 | - xml_defaultElement($this, $data); |
|
| 41 | - } |
|
| 38 | + // https://code.spip.net/@defautElement |
|
| 39 | + public function defaultElement($phraseur, $data) { |
|
| 40 | + xml_defaultElement($this, $data); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - // https://code.spip.net/@phraserTout |
|
| 44 | - public function phraserTout($phraseur, $data) { |
|
| 45 | - xml_parsestring($this, $data); |
|
| 46 | - } |
|
| 43 | + // https://code.spip.net/@phraserTout |
|
| 44 | + public function phraserTout($phraseur, $data) { |
|
| 45 | + xml_parsestring($this, $data); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public $depth = ''; |
|
| 49 | - public $res = ''; |
|
| 50 | - public $err = []; |
|
| 51 | - public $contenu = []; |
|
| 52 | - public $ouvrant = []; |
|
| 53 | - public $reperes = []; |
|
| 54 | - public $entete = ''; |
|
| 55 | - public $page = ''; |
|
| 56 | - public $dtc = null; |
|
| 57 | - public $sax = null; |
|
| 48 | + public $depth = ''; |
|
| 49 | + public $res = ''; |
|
| 50 | + public $err = []; |
|
| 51 | + public $contenu = []; |
|
| 52 | + public $ouvrant = []; |
|
| 53 | + public $reperes = []; |
|
| 54 | + public $entete = ''; |
|
| 55 | + public $page = ''; |
|
| 56 | + public $dtc = null; |
|
| 57 | + public $sax = null; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | // https://code.spip.net/@xml_indenter_dist |
| 61 | 61 | function xml_indenter_dist($page, $apply = false) { |
| 62 | - $sax = charger_fonction('sax', 'xml'); |
|
| 63 | - $f = new IndenteurXML(); |
|
| 64 | - $sax($page, $apply, $f); |
|
| 65 | - if (!$f->err) { |
|
| 66 | - return $f->entete . $f->res; |
|
| 67 | - } |
|
| 68 | - spip_log('indentation impossible ' . count($f->err) . ' erreurs de validation'); |
|
| 62 | + $sax = charger_fonction('sax', 'xml'); |
|
| 63 | + $f = new IndenteurXML(); |
|
| 64 | + $sax($page, $apply, $f); |
|
| 65 | + if (!$f->err) { |
|
| 66 | + return $f->entete . $f->res; |
|
| 67 | + } |
|
| 68 | + spip_log('indentation impossible ' . count($f->err) . ' erreurs de validation'); |
|
| 69 | 69 | |
| 70 | - return $f->entete . $f->page; |
|
| 70 | + return $f->entete . $f->page; |
|
| 71 | 71 | } |
@@ -63,9 +63,9 @@ |
||
| 63 | 63 | $f = new IndenteurXML(); |
| 64 | 64 | $sax($page, $apply, $f); |
| 65 | 65 | if (!$f->err) { |
| 66 | - return $f->entete . $f->res; |
|
| 66 | + return $f->entete.$f->res; |
|
| 67 | 67 | } |
| 68 | - spip_log('indentation impossible ' . count($f->err) . ' erreurs de validation'); |
|
| 68 | + spip_log('indentation impossible '.count($f->err).' erreurs de validation'); |
|
| 69 | 69 | |
| 70 | - return $f->entete . $f->page; |
|
| 70 | + return $f->entete.$f->page; |
|
| 71 | 71 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/charsets'); |
@@ -24,229 +24,229 @@ discard block |
||
| 24 | 24 | * @return string |
| 25 | 25 | */ |
| 26 | 26 | function xml_entites_html($texte) { |
| 27 | - if ( |
|
| 28 | - !is_string($texte) or !$texte |
|
| 29 | - or strpbrk($texte, "&\"'<>") == false |
|
| 30 | - ) { |
|
| 31 | - return $texte; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - if (!function_exists('spip_htmlspecialchars')) { |
|
| 35 | - include_spip('inc/filtres_mini'); |
|
| 36 | - } |
|
| 37 | - $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 38 | - |
|
| 39 | - return $texte; |
|
| 27 | + if ( |
|
| 28 | + !is_string($texte) or !$texte |
|
| 29 | + or strpbrk($texte, "&\"'<>") == false |
|
| 30 | + ) { |
|
| 31 | + return $texte; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + if (!function_exists('spip_htmlspecialchars')) { |
|
| 35 | + include_spip('inc/filtres_mini'); |
|
| 36 | + } |
|
| 37 | + $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 38 | + |
|
| 39 | + return $texte; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // https://code.spip.net/@xml_debutElement |
| 43 | 43 | function xml_debutElement($phraseur, $name, $attrs) { |
| 44 | - $depth = $phraseur->depth; |
|
| 45 | - |
|
| 46 | - $t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' '; |
|
| 47 | - // espace initial signifie: deja integree au resultat |
|
| 48 | - if ($t[0] != ' ') { |
|
| 49 | - $phraseur->res .= '<' . $t . '>'; |
|
| 50 | - $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 51 | - } |
|
| 52 | - $t = $phraseur->contenu[$depth]; |
|
| 53 | - // n'indenter que s'il y a un separateur avant |
|
| 54 | - $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t); |
|
| 55 | - $phraseur->contenu[$depth] = ''; |
|
| 56 | - $att = ''; |
|
| 57 | - $sep = ' '; |
|
| 58 | - foreach ($attrs as $k => $v) { |
|
| 59 | - $delim = strpos($v, "'") === false ? "'" : '"'; |
|
| 60 | - $val = xml_entites_html($v); |
|
| 61 | - $att .= $sep . $k . '=' . $delim |
|
| 62 | - . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
|
| 63 | - . $delim; |
|
| 64 | - $sep = "\n $depth"; |
|
| 65 | - } |
|
| 66 | - $phraseur->depth .= ' '; |
|
| 67 | - $phraseur->contenu[$phraseur->depth] = ''; |
|
| 68 | - $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 69 | - $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
|
| 44 | + $depth = $phraseur->depth; |
|
| 45 | + |
|
| 46 | + $t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' '; |
|
| 47 | + // espace initial signifie: deja integree au resultat |
|
| 48 | + if ($t[0] != ' ') { |
|
| 49 | + $phraseur->res .= '<' . $t . '>'; |
|
| 50 | + $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 51 | + } |
|
| 52 | + $t = $phraseur->contenu[$depth]; |
|
| 53 | + // n'indenter que s'il y a un separateur avant |
|
| 54 | + $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t); |
|
| 55 | + $phraseur->contenu[$depth] = ''; |
|
| 56 | + $att = ''; |
|
| 57 | + $sep = ' '; |
|
| 58 | + foreach ($attrs as $k => $v) { |
|
| 59 | + $delim = strpos($v, "'") === false ? "'" : '"'; |
|
| 60 | + $val = xml_entites_html($v); |
|
| 61 | + $att .= $sep . $k . '=' . $delim |
|
| 62 | + . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
|
| 63 | + . $delim; |
|
| 64 | + $sep = "\n $depth"; |
|
| 65 | + } |
|
| 66 | + $phraseur->depth .= ' '; |
|
| 67 | + $phraseur->contenu[$phraseur->depth] = ''; |
|
| 68 | + $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 69 | + $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | // https://code.spip.net/@xml_finElement |
| 73 | 73 | function xml_finElement($phraseur, $name, $fusion_bal = false) { |
| 74 | - $ouv = $phraseur->ouvrant[$phraseur->depth]; |
|
| 75 | - |
|
| 76 | - if ($ouv[0] != ' ') { |
|
| 77 | - $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 78 | - } else { |
|
| 79 | - $ouv = ''; |
|
| 80 | - } |
|
| 81 | - $t = $phraseur->contenu[$phraseur->depth]; |
|
| 82 | - $phraseur->depth = substr($phraseur->depth, 2); |
|
| 83 | - $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 84 | - |
|
| 85 | - // fusion <balise></balise> en <balise />. |
|
| 86 | - // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
|
| 87 | - // en particulier pour les balises Script et A. |
|
| 88 | - // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
|
| 89 | - // (param fusion_bal) |
|
| 90 | - |
|
| 91 | - if ($t || (($ouv != $name) and !$fusion_bal)) { |
|
| 92 | - $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>'; |
|
| 93 | - } else { |
|
| 94 | - $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>')); |
|
| 95 | - } |
|
| 74 | + $ouv = $phraseur->ouvrant[$phraseur->depth]; |
|
| 75 | + |
|
| 76 | + if ($ouv[0] != ' ') { |
|
| 77 | + $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 78 | + } else { |
|
| 79 | + $ouv = ''; |
|
| 80 | + } |
|
| 81 | + $t = $phraseur->contenu[$phraseur->depth]; |
|
| 82 | + $phraseur->depth = substr($phraseur->depth, 2); |
|
| 83 | + $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 84 | + |
|
| 85 | + // fusion <balise></balise> en <balise />. |
|
| 86 | + // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
|
| 87 | + // en particulier pour les balises Script et A. |
|
| 88 | + // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
|
| 89 | + // (param fusion_bal) |
|
| 90 | + |
|
| 91 | + if ($t || (($ouv != $name) and !$fusion_bal)) { |
|
| 92 | + $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>'; |
|
| 93 | + } else { |
|
| 94 | + $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>')); |
|
| 95 | + } |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // https://code.spip.net/@xml_textElement |
| 99 | 99 | function xml_textElement($phraseur, $data) { |
| 100 | - $depth = $phraseur->depth; |
|
| 101 | - $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth]) |
|
| 102 | - ? $data |
|
| 103 | - : xml_entites_html($data); |
|
| 100 | + $depth = $phraseur->depth; |
|
| 101 | + $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth]) |
|
| 102 | + ? $data |
|
| 103 | + : xml_entites_html($data); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | function xml_piElement($phraseur, $target, $data) { |
| 107 | - $depth = $phraseur->depth; |
|
| 108 | - |
|
| 109 | - if (strtolower($target) != 'php') { |
|
| 110 | - $phraseur->contenu[$depth] .= $data; |
|
| 111 | - } else { |
|
| 112 | - ob_start(); |
|
| 113 | - eval($data); |
|
| 114 | - $data = ob_get_contents(); |
|
| 115 | - ob_end_clean(); |
|
| 116 | - $phraseur->contenu[$depth] .= $data; |
|
| 117 | - } |
|
| 107 | + $depth = $phraseur->depth; |
|
| 108 | + |
|
| 109 | + if (strtolower($target) != 'php') { |
|
| 110 | + $phraseur->contenu[$depth] .= $data; |
|
| 111 | + } else { |
|
| 112 | + ob_start(); |
|
| 113 | + eval($data); |
|
| 114 | + $data = ob_get_contents(); |
|
| 115 | + ob_end_clean(); |
|
| 116 | + $phraseur->contenu[$depth] .= $data; |
|
| 117 | + } |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
| 121 | 121 | // https://code.spip.net/@xml_defautElement |
| 122 | 122 | function xml_defaultElement($phraseur, $data) { |
| 123 | - $depth = $phraseur->depth; |
|
| 123 | + $depth = $phraseur->depth; |
|
| 124 | 124 | |
| 125 | - if (!isset($phraseur->contenu[$depth])) { |
|
| 126 | - $phraseur->contenu[$depth] = ''; |
|
| 127 | - } |
|
| 128 | - $phraseur->contenu[$depth] .= $data; |
|
| 125 | + if (!isset($phraseur->contenu[$depth])) { |
|
| 126 | + $phraseur->contenu[$depth] = ''; |
|
| 127 | + } |
|
| 128 | + $phraseur->contenu[$depth] .= $data; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // https://code.spip.net/@xml_parsestring |
| 132 | 132 | function xml_parsestring($phraseur, $data) { |
| 133 | - $phraseur->contenu[$phraseur->depth] = ''; |
|
| 134 | - |
|
| 135 | - if (!xml_parse($phraseur->sax, $data, true)) { |
|
| 136 | - coordonnees_erreur( |
|
| 137 | - $phraseur, |
|
| 138 | - xml_error_string(xml_get_error_code($phraseur->sax)) |
|
| 139 | - . "<br />\n" . |
|
| 140 | - (!$phraseur->depth ? '' : |
|
| 141 | - ('(' . |
|
| 142 | - _T('erreur_balise_non_fermee') . |
|
| 143 | - ' <tt>' . |
|
| 144 | - $phraseur->ouvrant[$phraseur->depth] . |
|
| 145 | - '</tt> ' . |
|
| 146 | - _T('ligne') . |
|
| 147 | - ' ' . |
|
| 148 | - $phraseur->reperes[$phraseur->depth] . |
|
| 149 | - ") <br />\n")) |
|
| 150 | - ); |
|
| 151 | - } |
|
| 133 | + $phraseur->contenu[$phraseur->depth] = ''; |
|
| 134 | + |
|
| 135 | + if (!xml_parse($phraseur->sax, $data, true)) { |
|
| 136 | + coordonnees_erreur( |
|
| 137 | + $phraseur, |
|
| 138 | + xml_error_string(xml_get_error_code($phraseur->sax)) |
|
| 139 | + . "<br />\n" . |
|
| 140 | + (!$phraseur->depth ? '' : |
|
| 141 | + ('(' . |
|
| 142 | + _T('erreur_balise_non_fermee') . |
|
| 143 | + ' <tt>' . |
|
| 144 | + $phraseur->ouvrant[$phraseur->depth] . |
|
| 145 | + '</tt> ' . |
|
| 146 | + _T('ligne') . |
|
| 147 | + ' ' . |
|
| 148 | + $phraseur->reperes[$phraseur->depth] . |
|
| 149 | + ") <br />\n")) |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // https://code.spip.net/@coordonnees_erreur |
| 155 | 155 | function coordonnees_erreur($phraseur, $msg) { |
| 156 | - $entete_length = substr_count($phraseur->entete, "\n"); |
|
| 157 | - $phraseur->err[] = [ |
|
| 158 | - $msg, |
|
| 159 | - xml_get_current_line_number($phraseur->sax) + $entete_length, |
|
| 160 | - xml_get_current_column_number($phraseur->sax) |
|
| 161 | - ]; |
|
| 156 | + $entete_length = substr_count($phraseur->entete, "\n"); |
|
| 157 | + $phraseur->err[] = [ |
|
| 158 | + $msg, |
|
| 159 | + xml_get_current_line_number($phraseur->sax) + $entete_length, |
|
| 160 | + xml_get_current_column_number($phraseur->sax) |
|
| 161 | + ]; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // https://code.spip.net/@xml_sax_dist |
| 165 | 165 | function xml_sax_dist($page, $apply = false, $phraseur = null, $doctype = '', $charset = null) { |
| 166 | - if (is_null($charset)) { |
|
| 167 | - $charset = $GLOBALS['meta']['charset']; |
|
| 168 | - } |
|
| 169 | - if ($apply) { |
|
| 170 | - ob_start(); |
|
| 171 | - if (is_array($apply)) { |
|
| 172 | - $r = call_user_func_array($page, $apply); |
|
| 173 | - } else { |
|
| 174 | - $r = $page(); |
|
| 175 | - } |
|
| 176 | - $page = ob_get_contents(); |
|
| 177 | - ob_end_clean(); |
|
| 178 | - // fonction sans aucun "echo", ca doit etre le resultat |
|
| 179 | - if (!$page) { |
|
| 180 | - $page = $r; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if (!$page) { |
|
| 185 | - return ''; |
|
| 186 | - } |
|
| 187 | - // charger la DTD et transcoder les entites, |
|
| 188 | - // et escamoter le doctype que sax mange en php5 mais pas en php4 |
|
| 189 | - if (!$doctype) { |
|
| 190 | - if (!$r = analyser_doctype($page)) { |
|
| 191 | - $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 192 | - . preg_replace(_REGEXP_DOCTYPE, '', $page); |
|
| 193 | - $r = analyser_doctype($page); |
|
| 194 | - } |
|
| 195 | - list($entete, $avail, $grammaire, $rotlvl) = array_pad($r, 4, null); |
|
| 196 | - $page = substr($page, strlen($entete)); |
|
| 197 | - } else { |
|
| 198 | - $avail = 'SYSTEM'; |
|
| 199 | - $grammaire = $doctype; |
|
| 200 | - $rotlvl = basename($grammaire); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - include_spip('xml/analyser_dtd'); |
|
| 204 | - $dtc = charger_dtd($grammaire, $avail, $rotlvl); |
|
| 205 | - $page = sax_bug($page, $dtc, $charset); |
|
| 206 | - |
|
| 207 | - // compatibilite Tidy espace public |
|
| 208 | - if (!$phraseur) { |
|
| 209 | - $indenter_xml = charger_fonction('indenter', 'xml'); |
|
| 210 | - |
|
| 211 | - return $indenter_xml($page, $apply); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $xml_parser = xml_parser_create($charset); |
|
| 215 | - |
|
| 216 | - xml_set_element_handler( |
|
| 217 | - $xml_parser, |
|
| 218 | - [$phraseur, 'debutElement'], |
|
| 219 | - [$phraseur, 'finElement'] |
|
| 220 | - ); |
|
| 221 | - |
|
| 222 | - xml_set_character_data_handler( |
|
| 223 | - $xml_parser, |
|
| 224 | - [$phraseur, 'textElement'] |
|
| 225 | - ); |
|
| 226 | - |
|
| 227 | - xml_set_processing_instruction_handler( |
|
| 228 | - $xml_parser, |
|
| 229 | - [$phraseur, 'piElement'] |
|
| 230 | - ); |
|
| 231 | - |
|
| 232 | - xml_set_default_handler( |
|
| 233 | - $xml_parser, |
|
| 234 | - [$phraseur, 'defaultElement'] |
|
| 235 | - ); |
|
| 236 | - |
|
| 237 | - xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 238 | - |
|
| 239 | - $phraseur->sax = $xml_parser; |
|
| 240 | - if (isset($entete)) { |
|
| 241 | - $phraseur->entete = $entete; |
|
| 242 | - } |
|
| 243 | - $phraseur->page = $page; |
|
| 244 | - $phraseur->dtc = $dtc; |
|
| 245 | - $phraseur->phraserTout($xml_parser, $page); |
|
| 246 | - xml_parser_free($xml_parser); |
|
| 247 | - $phraseur->sax = ''; |
|
| 248 | - |
|
| 249 | - return $phraseur; |
|
| 166 | + if (is_null($charset)) { |
|
| 167 | + $charset = $GLOBALS['meta']['charset']; |
|
| 168 | + } |
|
| 169 | + if ($apply) { |
|
| 170 | + ob_start(); |
|
| 171 | + if (is_array($apply)) { |
|
| 172 | + $r = call_user_func_array($page, $apply); |
|
| 173 | + } else { |
|
| 174 | + $r = $page(); |
|
| 175 | + } |
|
| 176 | + $page = ob_get_contents(); |
|
| 177 | + ob_end_clean(); |
|
| 178 | + // fonction sans aucun "echo", ca doit etre le resultat |
|
| 179 | + if (!$page) { |
|
| 180 | + $page = $r; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if (!$page) { |
|
| 185 | + return ''; |
|
| 186 | + } |
|
| 187 | + // charger la DTD et transcoder les entites, |
|
| 188 | + // et escamoter le doctype que sax mange en php5 mais pas en php4 |
|
| 189 | + if (!$doctype) { |
|
| 190 | + if (!$r = analyser_doctype($page)) { |
|
| 191 | + $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 192 | + . preg_replace(_REGEXP_DOCTYPE, '', $page); |
|
| 193 | + $r = analyser_doctype($page); |
|
| 194 | + } |
|
| 195 | + list($entete, $avail, $grammaire, $rotlvl) = array_pad($r, 4, null); |
|
| 196 | + $page = substr($page, strlen($entete)); |
|
| 197 | + } else { |
|
| 198 | + $avail = 'SYSTEM'; |
|
| 199 | + $grammaire = $doctype; |
|
| 200 | + $rotlvl = basename($grammaire); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + include_spip('xml/analyser_dtd'); |
|
| 204 | + $dtc = charger_dtd($grammaire, $avail, $rotlvl); |
|
| 205 | + $page = sax_bug($page, $dtc, $charset); |
|
| 206 | + |
|
| 207 | + // compatibilite Tidy espace public |
|
| 208 | + if (!$phraseur) { |
|
| 209 | + $indenter_xml = charger_fonction('indenter', 'xml'); |
|
| 210 | + |
|
| 211 | + return $indenter_xml($page, $apply); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $xml_parser = xml_parser_create($charset); |
|
| 215 | + |
|
| 216 | + xml_set_element_handler( |
|
| 217 | + $xml_parser, |
|
| 218 | + [$phraseur, 'debutElement'], |
|
| 219 | + [$phraseur, 'finElement'] |
|
| 220 | + ); |
|
| 221 | + |
|
| 222 | + xml_set_character_data_handler( |
|
| 223 | + $xml_parser, |
|
| 224 | + [$phraseur, 'textElement'] |
|
| 225 | + ); |
|
| 226 | + |
|
| 227 | + xml_set_processing_instruction_handler( |
|
| 228 | + $xml_parser, |
|
| 229 | + [$phraseur, 'piElement'] |
|
| 230 | + ); |
|
| 231 | + |
|
| 232 | + xml_set_default_handler( |
|
| 233 | + $xml_parser, |
|
| 234 | + [$phraseur, 'defaultElement'] |
|
| 235 | + ); |
|
| 236 | + |
|
| 237 | + xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 238 | + |
|
| 239 | + $phraseur->sax = $xml_parser; |
|
| 240 | + if (isset($entete)) { |
|
| 241 | + $phraseur->entete = $entete; |
|
| 242 | + } |
|
| 243 | + $phraseur->page = $page; |
|
| 244 | + $phraseur->dtc = $dtc; |
|
| 245 | + $phraseur->phraserTout($xml_parser, $page); |
|
| 246 | + xml_parser_free($xml_parser); |
|
| 247 | + $phraseur->sax = ''; |
|
| 248 | + |
|
| 249 | + return $phraseur; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | // SAX ne dit pas si une Entite est dans un attribut ou non. |
@@ -258,24 +258,24 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | // https://code.spip.net/@sax_bug |
| 260 | 260 | function sax_bug($data, $dtc, $charset = null) { |
| 261 | - if (is_null($charset)) { |
|
| 262 | - $charset = $GLOBALS['meta']['charset']; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - if ($dtc) { |
|
| 266 | - $trans = []; |
|
| 267 | - |
|
| 268 | - foreach ($dtc->entites as $k => $v) { |
|
| 269 | - if (!strpos(' amp lt gt quot ', $k)) { |
|
| 270 | - $trans["&$k;"] = $v; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - $data = strtr($data, $trans); |
|
| 274 | - } else { |
|
| 275 | - $data = html2unicode($data, true); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - return unicode2charset($data, $charset); |
|
| 261 | + if (is_null($charset)) { |
|
| 262 | + $charset = $GLOBALS['meta']['charset']; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + if ($dtc) { |
|
| 266 | + $trans = []; |
|
| 267 | + |
|
| 268 | + foreach ($dtc->entites as $k => $v) { |
|
| 269 | + if (!strpos(' amp lt gt quot ', $k)) { |
|
| 270 | + $trans["&$k;"] = $v; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + $data = strtr($data, $trans); |
|
| 274 | + } else { |
|
| 275 | + $data = html2unicode($data, true); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + return unicode2charset($data, $charset); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // Retirer < ? xml... ? > et autre PI, ainsi que les commentaires en debut |
@@ -286,52 +286,52 @@ discard block |
||
| 286 | 286 | // mais un XML Schema que SPIP ne fait pas encore lire. |
| 287 | 287 | // https://code.spip.net/@analyser_doctype |
| 288 | 288 | function analyser_doctype($data) { |
| 289 | - if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
|
| 290 | - if (preg_match(_REGEXP_XML, $data, $page)) { |
|
| 291 | - list(, $entete, $topelement) = $page; |
|
| 292 | - if ($topelement == 'rss') { |
|
| 293 | - return [ |
|
| 294 | - $entete, |
|
| 295 | - 'PUBLIC', |
|
| 296 | - _DOCTYPE_RSS, |
|
| 297 | - 'rss-0.91.dtd' |
|
| 298 | - ]; |
|
| 299 | - } else { |
|
| 300 | - $dtd = $topelement . '.dtd'; |
|
| 301 | - $f = find_in_path($dtd); |
|
| 302 | - if (file_exists($f)) { |
|
| 303 | - return [$entete, 'SYSTEM', $f, $dtd]; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - spip_log('Dtd pas vu pour ' . substr($data, 0, 100)); |
|
| 308 | - |
|
| 309 | - return []; |
|
| 310 | - } |
|
| 311 | - list($entete, , $topelement, $avail, $suite) = $page; |
|
| 312 | - |
|
| 313 | - if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
|
| 314 | - if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
|
| 315 | - return []; |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - list(, $rotlvl, $suite) = $r; |
|
| 319 | - |
|
| 320 | - if (!$suite) { |
|
| 321 | - if ($avail != 'SYSTEM') { |
|
| 322 | - return []; |
|
| 323 | - } |
|
| 324 | - $grammaire = $rotlvl; |
|
| 325 | - $rotlvl = ''; |
|
| 326 | - } else { |
|
| 327 | - if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) { |
|
| 328 | - if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) { |
|
| 329 | - return []; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - $grammaire = $r[1]; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - return [$entete, $avail, $grammaire, $rotlvl]; |
|
| 289 | + if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
|
| 290 | + if (preg_match(_REGEXP_XML, $data, $page)) { |
|
| 291 | + list(, $entete, $topelement) = $page; |
|
| 292 | + if ($topelement == 'rss') { |
|
| 293 | + return [ |
|
| 294 | + $entete, |
|
| 295 | + 'PUBLIC', |
|
| 296 | + _DOCTYPE_RSS, |
|
| 297 | + 'rss-0.91.dtd' |
|
| 298 | + ]; |
|
| 299 | + } else { |
|
| 300 | + $dtd = $topelement . '.dtd'; |
|
| 301 | + $f = find_in_path($dtd); |
|
| 302 | + if (file_exists($f)) { |
|
| 303 | + return [$entete, 'SYSTEM', $f, $dtd]; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + spip_log('Dtd pas vu pour ' . substr($data, 0, 100)); |
|
| 308 | + |
|
| 309 | + return []; |
|
| 310 | + } |
|
| 311 | + list($entete, , $topelement, $avail, $suite) = $page; |
|
| 312 | + |
|
| 313 | + if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
|
| 314 | + if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
|
| 315 | + return []; |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + list(, $rotlvl, $suite) = $r; |
|
| 319 | + |
|
| 320 | + if (!$suite) { |
|
| 321 | + if ($avail != 'SYSTEM') { |
|
| 322 | + return []; |
|
| 323 | + } |
|
| 324 | + $grammaire = $rotlvl; |
|
| 325 | + $rotlvl = ''; |
|
| 326 | + } else { |
|
| 327 | + if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) { |
|
| 328 | + if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) { |
|
| 329 | + return []; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + $grammaire = $r[1]; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + return [$entete, $avail, $grammaire, $rotlvl]; |
|
| 337 | 337 | } |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | $t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' '; |
| 47 | 47 | // espace initial signifie: deja integree au resultat |
| 48 | 48 | if ($t[0] != ' ') { |
| 49 | - $phraseur->res .= '<' . $t . '>'; |
|
| 50 | - $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 49 | + $phraseur->res .= '<'.$t.'>'; |
|
| 50 | + $phraseur->ouvrant[$depth] = ' '.$t; |
|
| 51 | 51 | } |
| 52 | 52 | $t = $phraseur->contenu[$depth]; |
| 53 | 53 | // n'indenter que s'il y a un separateur avant |
@@ -58,14 +58,14 @@ discard block |
||
| 58 | 58 | foreach ($attrs as $k => $v) { |
| 59 | 59 | $delim = strpos($v, "'") === false ? "'" : '"'; |
| 60 | 60 | $val = xml_entites_html($v); |
| 61 | - $att .= $sep . $k . '=' . $delim |
|
| 61 | + $att .= $sep.$k.'='.$delim |
|
| 62 | 62 | . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
| 63 | 63 | . $delim; |
| 64 | 64 | $sep = "\n $depth"; |
| 65 | 65 | } |
| 66 | 66 | $phraseur->depth .= ' '; |
| 67 | 67 | $phraseur->contenu[$phraseur->depth] = ''; |
| 68 | - $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 68 | + $phraseur->ouvrant[$phraseur->depth] = $name.$att; |
|
| 69 | 69 | $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | $ouv = $phraseur->ouvrant[$phraseur->depth]; |
| 75 | 75 | |
| 76 | 76 | if ($ouv[0] != ' ') { |
| 77 | - $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 77 | + $phraseur->ouvrant[$phraseur->depth] = ' '.$ouv; |
|
| 78 | 78 | } else { |
| 79 | 79 | $ouv = ''; |
| 80 | 80 | } |
| 81 | 81 | $t = $phraseur->contenu[$phraseur->depth]; |
| 82 | 82 | $phraseur->depth = substr($phraseur->depth, 2); |
| 83 | - $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 83 | + $t = preg_replace("/[\n\t ]+$/", "\n".$phraseur->depth, $t); |
|
| 84 | 84 | |
| 85 | 85 | // fusion <balise></balise> en <balise />. |
| 86 | 86 | // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | // (param fusion_bal) |
| 90 | 90 | |
| 91 | 91 | if ($t || (($ouv != $name) and !$fusion_bal)) { |
| 92 | - $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>'; |
|
| 92 | + $phraseur->res .= ($ouv ? ('<'.$ouv.'>') : '').$t.'</'.$name.'>'; |
|
| 93 | 93 | } else { |
| 94 | - $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>')); |
|
| 94 | + $phraseur->res .= ($ouv ? ('<'.$ouv.' />') : ('</'.$name.'>')); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
@@ -136,16 +136,15 @@ discard block |
||
| 136 | 136 | coordonnees_erreur( |
| 137 | 137 | $phraseur, |
| 138 | 138 | xml_error_string(xml_get_error_code($phraseur->sax)) |
| 139 | - . "<br />\n" . |
|
| 140 | - (!$phraseur->depth ? '' : |
|
| 141 | - ('(' . |
|
| 142 | - _T('erreur_balise_non_fermee') . |
|
| 143 | - ' <tt>' . |
|
| 144 | - $phraseur->ouvrant[$phraseur->depth] . |
|
| 145 | - '</tt> ' . |
|
| 146 | - _T('ligne') . |
|
| 147 | - ' ' . |
|
| 148 | - $phraseur->reperes[$phraseur->depth] . |
|
| 139 | + . "<br />\n". |
|
| 140 | + (!$phraseur->depth ? '' : ('('. |
|
| 141 | + _T('erreur_balise_non_fermee'). |
|
| 142 | + ' <tt>'. |
|
| 143 | + $phraseur->ouvrant[$phraseur->depth]. |
|
| 144 | + '</tt> '. |
|
| 145 | + _T('ligne'). |
|
| 146 | + ' '. |
|
| 147 | + $phraseur->reperes[$phraseur->depth]. |
|
| 149 | 148 | ") <br />\n")) |
| 150 | 149 | ); |
| 151 | 150 | } |
@@ -188,7 +187,7 @@ discard block |
||
| 188 | 187 | // et escamoter le doctype que sax mange en php5 mais pas en php4 |
| 189 | 188 | if (!$doctype) { |
| 190 | 189 | if (!$r = analyser_doctype($page)) { |
| 191 | - $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 190 | + $page = _MESSAGE_DOCTYPE._DOCTYPE_ECRIRE |
|
| 192 | 191 | . preg_replace(_REGEXP_DOCTYPE, '', $page); |
| 193 | 192 | $r = analyser_doctype($page); |
| 194 | 193 | } |
@@ -297,18 +296,18 @@ discard block |
||
| 297 | 296 | 'rss-0.91.dtd' |
| 298 | 297 | ]; |
| 299 | 298 | } else { |
| 300 | - $dtd = $topelement . '.dtd'; |
|
| 299 | + $dtd = $topelement.'.dtd'; |
|
| 301 | 300 | $f = find_in_path($dtd); |
| 302 | 301 | if (file_exists($f)) { |
| 303 | 302 | return [$entete, 'SYSTEM', $f, $dtd]; |
| 304 | 303 | } |
| 305 | 304 | } |
| 306 | 305 | } |
| 307 | - spip_log('Dtd pas vu pour ' . substr($data, 0, 100)); |
|
| 306 | + spip_log('Dtd pas vu pour '.substr($data, 0, 100)); |
|
| 308 | 307 | |
| 309 | 308 | return []; |
| 310 | 309 | } |
| 311 | - list($entete, , $topelement, $avail, $suite) = $page; |
|
| 310 | + list($entete,, $topelement, $avail, $suite) = $page; |
|
| 312 | 311 | |
| 313 | 312 | if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
| 314 | 313 | if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
@@ -19,14 +19,14 @@ discard block |
||
| 19 | 19 | /** Drapeau indiquant que l'on est dans l'espace privé */ |
| 20 | 20 | define('_ESPACE_PRIVE', true); |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - include 'inc_version.php'; |
|
| 22 | + include 'inc_version.php'; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | // Verification anti magic_quotes_sybase, pour qui addslashes("'") = "''" |
| 26 | 26 | // On prefere la faire ici plutot que dans inc_version, c'est moins souvent et |
| 27 | 27 | // si le reglage est modifie sur un site en prod, ca fait moins mal |
| 28 | 28 | if (addslashes("'") !== "\\'") { |
| 29 | - die('SPIP incompatible magic_quotes_sybase'); |
|
| 29 | + die('SPIP incompatible magic_quotes_sybase'); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | include_spip('inc/cookie'); |
@@ -42,18 +42,18 @@ discard block |
||
| 42 | 42 | // alors il faut blinder les variables d'URL |
| 43 | 43 | // |
| 44 | 44 | if (autoriser_sans_cookie($exec, false)) { |
| 45 | - if (!isset($reinstall)) { |
|
| 46 | - $reinstall = 'non'; |
|
| 47 | - } |
|
| 48 | - $var_auth = true; |
|
| 45 | + if (!isset($reinstall)) { |
|
| 46 | + $reinstall = 'non'; |
|
| 47 | + } |
|
| 48 | + $var_auth = true; |
|
| 49 | 49 | } else { |
| 50 | - // Authentification, redefinissable |
|
| 51 | - $auth = charger_fonction('auth', 'inc'); |
|
| 52 | - $var_auth = $auth(); |
|
| 53 | - if ($var_auth) { |
|
| 54 | - echo auth_echec($var_auth); |
|
| 55 | - exit; |
|
| 56 | - } |
|
| 50 | + // Authentification, redefinissable |
|
| 51 | + $auth = charger_fonction('auth', 'inc'); |
|
| 52 | + $var_auth = $auth(); |
|
| 53 | + if ($var_auth) { |
|
| 54 | + echo auth_echec($var_auth); |
|
| 55 | + exit; |
|
| 56 | + } |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // initialiser a la langue par defaut |
@@ -64,29 +64,29 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | if (_request('action') or _request('var_ajax') or _request('formulaire_action')) { |
| 67 | - if (!autoriser_sans_cookie($exec)) { |
|
| 68 | - // Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires |
|
| 69 | - include_spip('public/aiguiller'); |
|
| 70 | - if ( |
|
| 71 | - // cas des appels actions ?action=xxx |
|
| 72 | - traiter_appels_actions() |
|
| 73 | - or |
|
| 74 | - // cas des hits ajax sur les inclusions ajax |
|
| 75 | - traiter_appels_inclusions_ajax() |
|
| 76 | - or |
|
| 77 | - // cas des formulaires charger/verifier/traiter |
|
| 78 | - traiter_formulaires_dynamiques() |
|
| 79 | - ) { |
|
| 80 | - exit; |
|
| 81 | - } // le hit est fini ! |
|
| 82 | - } |
|
| 67 | + if (!autoriser_sans_cookie($exec)) { |
|
| 68 | + // Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires |
|
| 69 | + include_spip('public/aiguiller'); |
|
| 70 | + if ( |
|
| 71 | + // cas des appels actions ?action=xxx |
|
| 72 | + traiter_appels_actions() |
|
| 73 | + or |
|
| 74 | + // cas des hits ajax sur les inclusions ajax |
|
| 75 | + traiter_appels_inclusions_ajax() |
|
| 76 | + or |
|
| 77 | + // cas des formulaires charger/verifier/traiter |
|
| 78 | + traiter_formulaires_dynamiques() |
|
| 79 | + ) { |
|
| 80 | + exit; |
|
| 81 | + } // le hit est fini ! |
|
| 82 | + } |
|
| 83 | 83 | } |
| 84 | 84 | // securiser les redirect du back-office |
| 85 | 85 | if (_request('redirect')) { |
| 86 | - if (!function_exists('securiser_redirect_action')) { |
|
| 87 | - include_spip('public/aiguiller'); |
|
| 88 | - } |
|
| 89 | - set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 86 | + if (!function_exists('securiser_redirect_action')) { |
|
| 87 | + include_spip('public/aiguiller'); |
|
| 88 | + } |
|
| 89 | + set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
@@ -96,12 +96,12 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | // Controle de la version, sauf si on est deja en train de s'en occuper |
| 98 | 98 | if ( |
| 99 | - !$reinstall == 'oui' |
|
| 100 | - and !_AJAX |
|
| 101 | - and isset($GLOBALS['meta']['version_installee']) |
|
| 102 | - and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee']))) |
|
| 99 | + !$reinstall == 'oui' |
|
| 100 | + and !_AJAX |
|
| 101 | + and isset($GLOBALS['meta']['version_installee']) |
|
| 102 | + and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee']))) |
|
| 103 | 103 | ) { |
| 104 | - $exec = 'demande_mise_a_jour'; |
|
| 104 | + $exec = 'demande_mise_a_jour'; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // Quand une action d'administration est en cours (meta "admin"), |
@@ -111,45 +111,45 @@ discard block |
||
| 111 | 111 | // sinon c'est qu'elle a ete interrompue et il faut la reprendre |
| 112 | 112 | |
| 113 | 113 | elseif (isset($GLOBALS['meta']['admin'])) { |
| 114 | - if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l)) { |
|
| 115 | - list(, $var_f, $n) = $l; |
|
| 116 | - } |
|
| 117 | - if ( |
|
| 118 | - _AJAX |
|
| 119 | - or !( |
|
| 120 | - isset($_COOKIE['spip_admin']) |
|
| 121 | - or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo') |
|
| 122 | - ) |
|
| 123 | - ) { |
|
| 124 | - spip_log('Quand la meta admin vaut ' . |
|
| 125 | - $GLOBALS['meta']['admin'] . |
|
| 126 | - ' seul un admin peut se connecter et sans AJAX.' . |
|
| 127 | - ' En cas de probleme, detruire cette meta.'); |
|
| 128 | - die(_T('info_travaux_texte')); |
|
| 129 | - } |
|
| 130 | - if ($n) { |
|
| 131 | - list(, $var_f, $n) = $l; |
|
| 132 | - if (tester_url_ecrire("base_$var_f")) { |
|
| 133 | - $var_f = "base_$var_f"; |
|
| 134 | - } |
|
| 135 | - if ($var_f != $exec) { |
|
| 136 | - spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec"); |
|
| 137 | - $exec = $var_f; |
|
| 138 | - set_request('exec', $exec); |
|
| 139 | - } |
|
| 140 | - } |
|
| 114 | + if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l)) { |
|
| 115 | + list(, $var_f, $n) = $l; |
|
| 116 | + } |
|
| 117 | + if ( |
|
| 118 | + _AJAX |
|
| 119 | + or !( |
|
| 120 | + isset($_COOKIE['spip_admin']) |
|
| 121 | + or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo') |
|
| 122 | + ) |
|
| 123 | + ) { |
|
| 124 | + spip_log('Quand la meta admin vaut ' . |
|
| 125 | + $GLOBALS['meta']['admin'] . |
|
| 126 | + ' seul un admin peut se connecter et sans AJAX.' . |
|
| 127 | + ' En cas de probleme, detruire cette meta.'); |
|
| 128 | + die(_T('info_travaux_texte')); |
|
| 129 | + } |
|
| 130 | + if ($n) { |
|
| 131 | + list(, $var_f, $n) = $l; |
|
| 132 | + if (tester_url_ecrire("base_$var_f")) { |
|
| 133 | + $var_f = "base_$var_f"; |
|
| 134 | + } |
|
| 135 | + if ($var_f != $exec) { |
|
| 136 | + spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec"); |
|
| 137 | + $exec = $var_f; |
|
| 138 | + set_request('exec', $exec); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | } |
| 142 | 142 | // si nom pas plausible, prendre le script par defaut |
| 143 | 143 | // attention aux deux cas 404/403 qui commencent par un 4 ! |
| 144 | 144 | elseif (!preg_match(',^[a-z4_][0-9a-z_-]*$,i', $exec)) { |
| 145 | - $exec = 'accueil'; |
|
| 146 | - set_request('exec', $exec); |
|
| 145 | + $exec = 'accueil'; |
|
| 146 | + set_request('exec', $exec); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | // compatibilite ascendante : obsolete, ne plus utiliser |
| 150 | 150 | $GLOBALS['spip_display'] = isset($GLOBALS['visiteur_session']['prefs']['display']) |
| 151 | - ? (int) $GLOBALS['visiteur_session']['prefs']['display'] |
|
| 152 | - : 0; |
|
| 151 | + ? (int) $GLOBALS['visiteur_session']['prefs']['display'] |
|
| 152 | + : 0; |
|
| 153 | 153 | $GLOBALS['spip_ecran'] = isset($_COOKIE['spip_ecran']) ? preg_replace('/[^a-z0-9]/i', '', $_COOKIE['spip_ecran']) : 'etroit'; |
| 154 | 154 | |
| 155 | 155 | // si la langue est specifiee par cookie et ne correspond pas |
@@ -157,19 +157,19 @@ discard block |
||
| 157 | 157 | // on appelle directement la fonction, car un appel d'action peut conduire a une boucle infinie |
| 158 | 158 | // si le cookie n'est pas pose correctement dans l'action |
| 159 | 159 | if ( |
| 160 | - !$var_auth and isset($_COOKIE['spip_lang_ecrire']) |
|
| 161 | - and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang'] |
|
| 160 | + !$var_auth and isset($_COOKIE['spip_lang_ecrire']) |
|
| 161 | + and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang'] |
|
| 162 | 162 | ) { |
| 163 | - include_spip('action/converser'); |
|
| 164 | - action_converser_post($GLOBALS['visiteur_session']['lang'], true); |
|
| 163 | + include_spip('action/converser'); |
|
| 164 | + action_converser_post($GLOBALS['visiteur_session']['lang'], true); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | if ($var_f = tester_url_ecrire($exec)) { |
| 168 | - $var_f = charger_fonction($var_f); |
|
| 169 | - $var_f(); // at last |
|
| 168 | + $var_f = charger_fonction($var_f); |
|
| 169 | + $var_f(); // at last |
|
| 170 | 170 | } else { |
| 171 | - // Rien de connu: rerouter vers exec=404 au lieu d'echouer |
|
| 172 | - // ce qui permet de laisser la main a un plugin |
|
| 173 | - $var_f = charger_fonction('404'); |
|
| 174 | - $var_f($exec); |
|
| 171 | + // Rien de connu: rerouter vers exec=404 au lieu d'echouer |
|
| 172 | + // ce qui permet de laisser la main a un plugin |
|
| 173 | + $var_f = charger_fonction('404'); |
|
| 174 | + $var_f($exec); |
|
| 175 | 175 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | // Determiner l'action demandee |
| 36 | 36 | // |
| 37 | 37 | |
| 38 | -$exec = (string)_request('exec'); |
|
| 38 | +$exec = (string) _request('exec'); |
|
| 39 | 39 | $reinstall = (!is_null(_request('reinstall'))) ? _request('reinstall') : ($exec == 'install' ? 'oui' : null); |
| 40 | 40 | // |
| 41 | 41 | // Les scripts d'insallation n'authentifient pas, forcement, |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo') |
| 122 | 122 | ) |
| 123 | 123 | ) { |
| 124 | - spip_log('Quand la meta admin vaut ' . |
|
| 125 | - $GLOBALS['meta']['admin'] . |
|
| 126 | - ' seul un admin peut se connecter et sans AJAX.' . |
|
| 124 | + spip_log('Quand la meta admin vaut '. |
|
| 125 | + $GLOBALS['meta']['admin']. |
|
| 126 | + ' seul un admin peut se connecter et sans AJAX.'. |
|
| 127 | 127 | ' En cas de probleme, detruire cette meta.'); |
| 128 | 128 | die(_T('info_travaux_texte')); |
| 129 | 129 | } |
@@ -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 | /** |
@@ -36,15 +36,15 @@ discard block |
||
| 36 | 36 | define('_PHP_MIN', '7.3.0'); |
| 37 | 37 | |
| 38 | 38 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 39 | - /** le nom du repertoire ecrire/ */ |
|
| 40 | - define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 39 | + /** le nom du repertoire ecrire/ */ |
|
| 40 | + define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** Chemin relatif pour aller dans ecrire |
| 44 | 44 | * vide si on est dans ecrire, 'ecrire/' sinon */ |
| 45 | 45 | define( |
| 46 | - '_DIR_RESTREINT', |
|
| 47 | - (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS) |
|
| 46 | + '_DIR_RESTREINT', |
|
| 47 | + (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS) |
|
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | 50 | /** Chemin relatif pour aller à la racine */ |
@@ -59,8 +59,8 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | // Icones |
| 61 | 61 | if (!defined('_NOM_IMG_PACK')) { |
| 62 | - /** Nom du dossier images */ |
|
| 63 | - define('_NOM_IMG_PACK', 'images/'); |
|
| 62 | + /** Nom du dossier images */ |
|
| 63 | + define('_NOM_IMG_PACK', 'images/'); |
|
| 64 | 64 | } |
| 65 | 65 | /** le chemin http (relatif) vers les images standard */ |
| 66 | 66 | define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK)); |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | define('_ROOT_IMG_PACK', dirname(__DIR__) . '/prive/' . _NOM_IMG_PACK); |
| 70 | 70 | |
| 71 | 71 | if (!defined('_JAVASCRIPT')) { |
| 72 | - /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 73 | - define('_JAVASCRIPT', 'javascript/'); |
|
| 72 | + /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 73 | + define('_JAVASCRIPT', 'javascript/'); |
|
| 74 | 74 | } // utilisable avec #CHEMIN et find_in_path |
| 75 | 75 | /** le nom du repertoire des bibliotheques JavaScript du prive */ |
| 76 | 76 | define('_DIR_JAVASCRIPT', (_DIR_RACINE . 'prive/' . _JAVASCRIPT)); |
@@ -80,47 +80,47 @@ discard block |
||
| 80 | 80 | # mais on peut les mettre ailleurs et changer completement les noms |
| 81 | 81 | |
| 82 | 82 | if (!defined('_NOM_TEMPORAIRES_INACCESSIBLES')) { |
| 83 | - /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 84 | - define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 83 | + /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 84 | + define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 85 | 85 | } |
| 86 | 86 | if (!defined('_NOM_TEMPORAIRES_ACCESSIBLES')) { |
| 87 | - /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 88 | - define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 87 | + /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 88 | + define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 89 | 89 | } |
| 90 | 90 | if (!defined('_NOM_PERMANENTS_INACCESSIBLES')) { |
| 91 | - /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 92 | - define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 91 | + /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 92 | + define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 93 | 93 | } |
| 94 | 94 | if (!defined('_NOM_PERMANENTS_ACCESSIBLES')) { |
| 95 | - /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 96 | - define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 95 | + /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 96 | + define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | /** Le nom du fichier de personnalisation */ |
| 101 | 101 | if (!defined('_NOM_CONFIG')) { |
| 102 | - define('_NOM_CONFIG', 'mes_options'); |
|
| 102 | + define('_NOM_CONFIG', 'mes_options'); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Son emplacement absolu si on le trouve |
| 106 | 106 | if ( |
| 107 | - @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 108 | - or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 107 | + @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 108 | + or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 109 | 109 | ) { |
| 110 | - /** Emplacement absolu du fichier d'option */ |
|
| 111 | - define('_FILE_OPTIONS', $f); |
|
| 110 | + /** Emplacement absolu du fichier d'option */ |
|
| 111 | + define('_FILE_OPTIONS', $f); |
|
| 112 | 112 | } else { |
| 113 | - define('_FILE_OPTIONS', ''); |
|
| 113 | + define('_FILE_OPTIONS', ''); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | if (!defined('MODULES_IDIOMES')) { |
| 117 | - /** |
|
| 118 | - * Modules par défaut pour la traduction. |
|
| 119 | - * |
|
| 120 | - * Constante utilisée par le compilateur et le décompilateur |
|
| 121 | - * sa valeur etant traitée par inc_traduire_dist |
|
| 122 | - */ |
|
| 123 | - define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 117 | + /** |
|
| 118 | + * Modules par défaut pour la traduction. |
|
| 119 | + * |
|
| 120 | + * Constante utilisée par le compilateur et le décompilateur |
|
| 121 | + * sa valeur etant traitée par inc_traduire_dist |
|
| 122 | + */ |
|
| 123 | + define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // *** Fin des define *** // |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | // Inclure l'ecran de securite |
| 130 | 130 | if ( |
| 131 | - !defined('_ECRAN_SECURITE') |
|
| 132 | - and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 131 | + !defined('_ECRAN_SECURITE') |
|
| 132 | + and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 133 | 133 | ) { |
| 134 | - include $f; |
|
| 134 | + include $f; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
@@ -139,30 +139,30 @@ discard block |
||
| 139 | 139 | * Détecteur de robot d'indexation |
| 140 | 140 | */ |
| 141 | 141 | if (!defined('_IS_BOT')) { |
| 142 | - define( |
|
| 143 | - '_IS_BOT', |
|
| 144 | - isset($_SERVER['HTTP_USER_AGENT']) |
|
| 145 | - and preg_match( |
|
| 146 | - // mots generiques |
|
| 147 | - ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 148 | - // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 149 | - . 'MSIE 6\.0|' |
|
| 150 | - // UA plus cibles |
|
| 151 | - . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
|
| 152 | - . ',i', |
|
| 153 | - (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 154 | - ) |
|
| 155 | - ); |
|
| 142 | + define( |
|
| 143 | + '_IS_BOT', |
|
| 144 | + isset($_SERVER['HTTP_USER_AGENT']) |
|
| 145 | + and preg_match( |
|
| 146 | + // mots generiques |
|
| 147 | + ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 148 | + // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 149 | + . 'MSIE 6\.0|' |
|
| 150 | + // UA plus cibles |
|
| 151 | + . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
|
| 152 | + . ',i', |
|
| 153 | + (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 154 | + ) |
|
| 155 | + ); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | if (!defined('_IS_CLI')) { |
| 159 | - define( |
|
| 160 | - '_IS_CLI', |
|
| 161 | - !isset($_SERVER['HTTP_HOST']) |
|
| 162 | - and !strlen($_SERVER['DOCUMENT_ROOT']) |
|
| 163 | - and !empty($_SERVER['argv']) |
|
| 164 | - and empty($_SERVER['REQUEST_METHOD']) |
|
| 165 | - ); |
|
| 159 | + define( |
|
| 160 | + '_IS_CLI', |
|
| 161 | + !isset($_SERVER['HTTP_HOST']) |
|
| 162 | + and !strlen($_SERVER['DOCUMENT_ROOT']) |
|
| 163 | + and !empty($_SERVER['argv']) |
|
| 164 | + and empty($_SERVER['REQUEST_METHOD']) |
|
| 165 | + ); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // *** Parametrage par defaut de SPIP *** |
@@ -174,61 +174,61 @@ discard block |
||
| 174 | 174 | // Ne pas les rendre indefinies. |
| 175 | 175 | |
| 176 | 176 | global |
| 177 | - $nombre_de_logs, |
|
| 178 | - $taille_des_logs, |
|
| 179 | - $table_prefix, |
|
| 180 | - $cookie_prefix, |
|
| 181 | - $dossier_squelettes, |
|
| 182 | - $filtrer_javascript, |
|
| 183 | - $type_urls, |
|
| 184 | - $debut_date_publication, |
|
| 185 | - $ip, |
|
| 186 | - $mysql_rappel_connexion, |
|
| 187 | - $mysql_rappel_nom_base, |
|
| 188 | - $test_i18n, |
|
| 189 | - $ignore_auth_http, |
|
| 190 | - $ignore_remote_user, |
|
| 191 | - $derniere_modif_invalide, |
|
| 192 | - $home_server, |
|
| 193 | - $help_server, |
|
| 194 | - $url_glossaire_externe, |
|
| 195 | - $tex_server, |
|
| 196 | - $traiter_math, |
|
| 197 | - $xhtml, |
|
| 198 | - $xml_indent, |
|
| 199 | - $source_vignettes, |
|
| 200 | - $formats_logos, |
|
| 201 | - $controler_dates_rss, |
|
| 202 | - $spip_pipeline, |
|
| 203 | - $spip_matrice, |
|
| 204 | - $plugins, |
|
| 205 | - $surcharges, |
|
| 206 | - $exceptions_des_tables, |
|
| 207 | - $tables_principales, |
|
| 208 | - $table_des_tables, |
|
| 209 | - $tables_auxiliaires, |
|
| 210 | - $table_primary, |
|
| 211 | - $table_date, |
|
| 212 | - $table_titre, |
|
| 213 | - $tables_jointures, |
|
| 214 | - $liste_des_statuts, |
|
| 215 | - $liste_des_etats, |
|
| 216 | - $liste_des_authentifications, |
|
| 217 | - $spip_version_branche, |
|
| 218 | - $spip_version_code, |
|
| 219 | - $spip_version_base, |
|
| 220 | - $spip_sql_version, |
|
| 221 | - $spip_version_affichee, |
|
| 222 | - $visiteur_session, |
|
| 223 | - $auteur_session, |
|
| 224 | - $connect_statut, |
|
| 225 | - $connect_toutes_rubriques, |
|
| 226 | - $hash_recherche, |
|
| 227 | - $hash_recherche_strict, |
|
| 228 | - $ldap_present, |
|
| 229 | - $meta, |
|
| 230 | - $connect_id_rubrique, |
|
| 231 | - $puce; |
|
| 177 | + $nombre_de_logs, |
|
| 178 | + $taille_des_logs, |
|
| 179 | + $table_prefix, |
|
| 180 | + $cookie_prefix, |
|
| 181 | + $dossier_squelettes, |
|
| 182 | + $filtrer_javascript, |
|
| 183 | + $type_urls, |
|
| 184 | + $debut_date_publication, |
|
| 185 | + $ip, |
|
| 186 | + $mysql_rappel_connexion, |
|
| 187 | + $mysql_rappel_nom_base, |
|
| 188 | + $test_i18n, |
|
| 189 | + $ignore_auth_http, |
|
| 190 | + $ignore_remote_user, |
|
| 191 | + $derniere_modif_invalide, |
|
| 192 | + $home_server, |
|
| 193 | + $help_server, |
|
| 194 | + $url_glossaire_externe, |
|
| 195 | + $tex_server, |
|
| 196 | + $traiter_math, |
|
| 197 | + $xhtml, |
|
| 198 | + $xml_indent, |
|
| 199 | + $source_vignettes, |
|
| 200 | + $formats_logos, |
|
| 201 | + $controler_dates_rss, |
|
| 202 | + $spip_pipeline, |
|
| 203 | + $spip_matrice, |
|
| 204 | + $plugins, |
|
| 205 | + $surcharges, |
|
| 206 | + $exceptions_des_tables, |
|
| 207 | + $tables_principales, |
|
| 208 | + $table_des_tables, |
|
| 209 | + $tables_auxiliaires, |
|
| 210 | + $table_primary, |
|
| 211 | + $table_date, |
|
| 212 | + $table_titre, |
|
| 213 | + $tables_jointures, |
|
| 214 | + $liste_des_statuts, |
|
| 215 | + $liste_des_etats, |
|
| 216 | + $liste_des_authentifications, |
|
| 217 | + $spip_version_branche, |
|
| 218 | + $spip_version_code, |
|
| 219 | + $spip_version_base, |
|
| 220 | + $spip_sql_version, |
|
| 221 | + $spip_version_affichee, |
|
| 222 | + $visiteur_session, |
|
| 223 | + $auteur_session, |
|
| 224 | + $connect_statut, |
|
| 225 | + $connect_toutes_rubriques, |
|
| 226 | + $hash_recherche, |
|
| 227 | + $hash_recherche_strict, |
|
| 228 | + $ldap_present, |
|
| 229 | + $meta, |
|
| 230 | + $connect_id_rubrique, |
|
| 231 | + $puce; |
|
| 232 | 232 | |
| 233 | 233 | # comment on logge, defaut 4 tmp/spip.log de 100k, 0 ou 0 suppriment le log |
| 234 | 234 | $nombre_de_logs = 4; |
@@ -283,48 +283,48 @@ discard block |
||
| 283 | 283 | // Prendre en compte les entetes HTTP_X_FORWARDED_XX |
| 284 | 284 | // |
| 285 | 285 | if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
| 286 | - if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 287 | - $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 288 | - } |
|
| 289 | - if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 290 | - $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 291 | - } |
|
| 286 | + if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 287 | + $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 288 | + } |
|
| 289 | + if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 290 | + $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 291 | + } |
|
| 292 | 292 | } |
| 293 | 293 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 294 | - if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 295 | - $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 296 | - if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 297 | - $_SERVER['HTTPS'] = 'on'; |
|
| 298 | - if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 299 | - $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 304 | - if (strpos($host, ',') !== false) { |
|
| 305 | - $h = explode(',', $host); |
|
| 306 | - $host = trim(reset($h)); |
|
| 307 | - } |
|
| 308 | - // securite sur le contenu de l'entete |
|
| 309 | - $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 310 | - $_SERVER['HTTP_HOST'] = $host; |
|
| 294 | + if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 295 | + $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 296 | + if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 297 | + $_SERVER['HTTPS'] = 'on'; |
|
| 298 | + if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 299 | + $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 304 | + if (strpos($host, ',') !== false) { |
|
| 305 | + $h = explode(',', $host); |
|
| 306 | + $host = trim(reset($h)); |
|
| 307 | + } |
|
| 308 | + // securite sur le contenu de l'entete |
|
| 309 | + $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 310 | + $_SERVER['HTTP_HOST'] = $host; |
|
| 311 | 311 | } |
| 312 | 312 | // |
| 313 | 313 | // On note le numero IP du client dans la variable $ip |
| 314 | 314 | // |
| 315 | 315 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| 316 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 317 | - if (strpos($ip, ',') !== false) { |
|
| 318 | - $ip = explode(',', $ip); |
|
| 319 | - $ip = reset($ip); |
|
| 320 | - } |
|
| 321 | - // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 322 | - if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 323 | - $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 324 | - } |
|
| 316 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 317 | + if (strpos($ip, ',') !== false) { |
|
| 318 | + $ip = explode(',', $ip); |
|
| 319 | + $ip = reset($ip); |
|
| 320 | + } |
|
| 321 | + // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 322 | + if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 323 | + $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 324 | + } |
|
| 325 | 325 | } |
| 326 | 326 | if (isset($_SERVER['REMOTE_ADDR'])) { |
| 327 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 327 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | // Pour renforcer la privacy, decommentez la ligne ci-dessous (ou recopiez-la |
@@ -409,24 +409,24 @@ discard block |
||
| 409 | 409 | |
| 410 | 410 | // Liste des statuts. |
| 411 | 411 | $liste_des_statuts = [ |
| 412 | - 'info_administrateurs' => '0minirezo', |
|
| 413 | - 'info_redacteurs' => '1comite', |
|
| 414 | - 'info_visiteurs' => '6forum', |
|
| 415 | - 'texte_statut_poubelle' => '5poubelle' |
|
| 412 | + 'info_administrateurs' => '0minirezo', |
|
| 413 | + 'info_redacteurs' => '1comite', |
|
| 414 | + 'info_visiteurs' => '6forum', |
|
| 415 | + 'texte_statut_poubelle' => '5poubelle' |
|
| 416 | 416 | ]; |
| 417 | 417 | |
| 418 | 418 | $liste_des_etats = [ |
| 419 | - 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 420 | - 'texte_statut_propose_evaluation' => 'prop', |
|
| 421 | - 'texte_statut_publie' => 'publie', |
|
| 422 | - 'texte_statut_poubelle' => 'poubelle', |
|
| 423 | - 'texte_statut_refuse' => 'refuse' |
|
| 419 | + 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 420 | + 'texte_statut_propose_evaluation' => 'prop', |
|
| 421 | + 'texte_statut_publie' => 'publie', |
|
| 422 | + 'texte_statut_poubelle' => 'poubelle', |
|
| 423 | + 'texte_statut_refuse' => 'refuse' |
|
| 424 | 424 | ]; |
| 425 | 425 | |
| 426 | 426 | // liste des methodes d'authentifications |
| 427 | 427 | $liste_des_authentifications = [ |
| 428 | - 'spip' => 'spip', |
|
| 429 | - 'ldap' => 'ldap' |
|
| 428 | + 'spip' => 'spip', |
|
| 429 | + 'ldap' => 'ldap' |
|
| 430 | 430 | ]; |
| 431 | 431 | |
| 432 | 432 | // Experimental : pour supprimer systematiquement l'affichage des numeros |
@@ -476,12 +476,12 @@ discard block |
||
| 476 | 476 | // Definition personnelles eventuelles |
| 477 | 477 | |
| 478 | 478 | if (_FILE_OPTIONS) { |
| 479 | - include_once _FILE_OPTIONS; |
|
| 479 | + include_once _FILE_OPTIONS; |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | if (!defined('SPIP_ERREUR_REPORT')) { |
| 483 | - /** Masquer les warning */ |
|
| 484 | - define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 483 | + /** Masquer les warning */ |
|
| 484 | + define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 485 | 485 | } |
| 486 | 486 | error_reporting(SPIP_ERREUR_REPORT); |
| 487 | 487 | |
@@ -494,10 +494,10 @@ discard block |
||
| 494 | 494 | // ===> on execute en neutralisant les messages d'erreur |
| 495 | 495 | |
| 496 | 496 | spip_initialisation_core( |
| 497 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 498 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 499 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 500 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 497 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 498 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 499 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 500 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 501 | 501 | ); |
| 502 | 502 | |
| 503 | 503 | |
@@ -507,70 +507,70 @@ discard block |
||
| 507 | 507 | // donc il faut avoir tout fini ici avant de charger les plugins |
| 508 | 508 | |
| 509 | 509 | if (@is_readable(_CACHE_PLUGINS_OPT) and @is_readable(_CACHE_PLUGINS_PATH)) { |
| 510 | - // chargement optimise precompile |
|
| 511 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 510 | + // chargement optimise precompile |
|
| 511 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 512 | 512 | } else { |
| 513 | - spip_initialisation_suite(); |
|
| 514 | - include_spip('inc/plugin'); |
|
| 515 | - // generer les fichiers php precompiles |
|
| 516 | - // de chargement des plugins et des pipelines |
|
| 517 | - actualise_plugins_actifs(); |
|
| 513 | + spip_initialisation_suite(); |
|
| 514 | + include_spip('inc/plugin'); |
|
| 515 | + // generer les fichiers php precompiles |
|
| 516 | + // de chargement des plugins et des pipelines |
|
| 517 | + actualise_plugins_actifs(); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | // Initialisations non critiques surchargeables par les plugins |
| 521 | 521 | spip_initialisation_suite(); |
| 522 | 522 | |
| 523 | 523 | if (!defined('_LOG_FILTRE_GRAVITE')) { |
| 524 | - /** niveau maxi d'enregistrement des logs */ |
|
| 525 | - define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE); |
|
| 524 | + /** niveau maxi d'enregistrement des logs */ |
|
| 525 | + define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | if (!defined('_OUTILS_DEVELOPPEURS')) { |
| 529 | - /** Activer des outils pour développeurs ? */ |
|
| 530 | - define('_OUTILS_DEVELOPPEURS', false); |
|
| 529 | + /** Activer des outils pour développeurs ? */ |
|
| 530 | + define('_OUTILS_DEVELOPPEURS', false); |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | // charger systematiquement inc/autoriser dans l'espace restreint |
| 534 | 534 | if (test_espace_prive()) { |
| 535 | - include_spip('inc/autoriser'); |
|
| 535 | + include_spip('inc/autoriser'); |
|
| 536 | 536 | } |
| 537 | 537 | // |
| 538 | 538 | // Installer Spip si pas installe... sauf si justement on est en train |
| 539 | 539 | // |
| 540 | 540 | if ( |
| 541 | - !(_FILE_CONNECT |
|
| 542 | - or autoriser_sans_cookie(_request('exec')) |
|
| 543 | - or _request('action') == 'cookie' |
|
| 544 | - or _request('action') == 'converser' |
|
| 545 | - or _request('action') == 'test_dirs') |
|
| 541 | + !(_FILE_CONNECT |
|
| 542 | + or autoriser_sans_cookie(_request('exec')) |
|
| 543 | + or _request('action') == 'cookie' |
|
| 544 | + or _request('action') == 'converser' |
|
| 545 | + or _request('action') == 'test_dirs') |
|
| 546 | 546 | ) { |
| 547 | - // Si on peut installer, on lance illico |
|
| 548 | - if (test_espace_prive()) { |
|
| 549 | - include_spip('inc/headers'); |
|
| 550 | - redirige_url_ecrire('install'); |
|
| 551 | - } else { |
|
| 552 | - // Si on est dans le site public, dire que qq s'en occupe |
|
| 553 | - include_spip('inc/minipres'); |
|
| 554 | - utiliser_langue_visiteur(); |
|
| 555 | - echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 556 | - exit; |
|
| 557 | - } |
|
| 558 | - // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 547 | + // Si on peut installer, on lance illico |
|
| 548 | + if (test_espace_prive()) { |
|
| 549 | + include_spip('inc/headers'); |
|
| 550 | + redirige_url_ecrire('install'); |
|
| 551 | + } else { |
|
| 552 | + // Si on est dans le site public, dire que qq s'en occupe |
|
| 553 | + include_spip('inc/minipres'); |
|
| 554 | + utiliser_langue_visiteur(); |
|
| 555 | + echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 556 | + exit; |
|
| 557 | + } |
|
| 558 | + // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | // memoriser un tri sessionne eventuel |
| 562 | 562 | if ( |
| 563 | - isset($_REQUEST['var_memotri']) |
|
| 564 | - and $t = $_REQUEST['var_memotri'] |
|
| 565 | - and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0) |
|
| 563 | + isset($_REQUEST['var_memotri']) |
|
| 564 | + and $t = $_REQUEST['var_memotri'] |
|
| 565 | + and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0) |
|
| 566 | 566 | ) { |
| 567 | - if (!function_exists('session_set')) { |
|
| 568 | - include_spip('inc/session'); |
|
| 569 | - } |
|
| 570 | - $t = preg_replace(',\W,', '_', $t); |
|
| 571 | - if ($v = _request($t)) { |
|
| 572 | - session_set($t, $v); |
|
| 573 | - } |
|
| 567 | + if (!function_exists('session_set')) { |
|
| 568 | + include_spip('inc/session'); |
|
| 569 | + } |
|
| 570 | + $t = preg_replace(',\W,', '_', $t); |
|
| 571 | + if ($v = _request($t)) { |
|
| 572 | + session_set($t, $v); |
|
| 573 | + } |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -580,22 +580,22 @@ discard block |
||
| 580 | 580 | * La globale $spip_header_silencieux permet de rendre le header minimal pour raisons de securite |
| 581 | 581 | */ |
| 582 | 582 | if (!defined('_HEADER_COMPOSED_BY')) { |
| 583 | - define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 583 | + define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 584 | 584 | } |
| 585 | 585 | if (!headers_sent() and _HEADER_COMPOSED_BY) { |
| 586 | - if (!defined('_HEADER_VARY')) { |
|
| 587 | - define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 588 | - } |
|
| 589 | - if (_HEADER_VARY) { |
|
| 590 | - header(_HEADER_VARY); |
|
| 591 | - } |
|
| 592 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 593 | - include_spip('inc/filtres_mini'); |
|
| 594 | - header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 595 | - } else { |
|
| 596 | - // header minimal |
|
| 597 | - header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 598 | - } |
|
| 586 | + if (!defined('_HEADER_VARY')) { |
|
| 587 | + define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 588 | + } |
|
| 589 | + if (_HEADER_VARY) { |
|
| 590 | + header(_HEADER_VARY); |
|
| 591 | + } |
|
| 592 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 593 | + include_spip('inc/filtres_mini'); |
|
| 594 | + header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 595 | + } else { |
|
| 596 | + // header minimal |
|
| 597 | + header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 598 | + } |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | $methode = (isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : ((php_sapi_name() == 'cli') ? 'cli' : '')); |
@@ -51,11 +51,11 @@ discard block |
||
| 51 | 51 | define('_DIR_RACINE', _DIR_RESTREINT ? '' : '../'); |
| 52 | 52 | |
| 53 | 53 | /** chemin absolu vers la racine */ |
| 54 | -define('_ROOT_RACINE', dirname(__DIR__) . '/'); |
|
| 54 | +define('_ROOT_RACINE', dirname(__DIR__).'/'); |
|
| 55 | 55 | /** chemin absolu vers le repertoire de travail */ |
| 56 | -define('_ROOT_CWD', getcwd() . '/'); |
|
| 56 | +define('_ROOT_CWD', getcwd().'/'); |
|
| 57 | 57 | /** chemin absolu vers ecrire */ |
| 58 | -define('_ROOT_RESTREINT', _ROOT_CWD . _DIR_RESTREINT); |
|
| 58 | +define('_ROOT_RESTREINT', _ROOT_CWD._DIR_RESTREINT); |
|
| 59 | 59 | |
| 60 | 60 | // Icones |
| 61 | 61 | if (!defined('_NOM_IMG_PACK')) { |
@@ -63,17 +63,17 @@ discard block |
||
| 63 | 63 | define('_NOM_IMG_PACK', 'images/'); |
| 64 | 64 | } |
| 65 | 65 | /** le chemin http (relatif) vers les images standard */ |
| 66 | -define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK)); |
|
| 66 | +define('_DIR_IMG_PACK', (_DIR_RACINE.'prive/'._NOM_IMG_PACK)); |
|
| 67 | 67 | |
| 68 | 68 | /** le chemin php (absolu) vers les images standard (pour hebergement centralise) */ |
| 69 | -define('_ROOT_IMG_PACK', dirname(__DIR__) . '/prive/' . _NOM_IMG_PACK); |
|
| 69 | +define('_ROOT_IMG_PACK', dirname(__DIR__).'/prive/'._NOM_IMG_PACK); |
|
| 70 | 70 | |
| 71 | 71 | if (!defined('_JAVASCRIPT')) { |
| 72 | 72 | /** Nom du repertoire des bibliotheques JavaScript */ |
| 73 | 73 | define('_JAVASCRIPT', 'javascript/'); |
| 74 | 74 | } // utilisable avec #CHEMIN et find_in_path |
| 75 | 75 | /** le nom du repertoire des bibliotheques JavaScript du prive */ |
| 76 | -define('_DIR_JAVASCRIPT', (_DIR_RACINE . 'prive/' . _JAVASCRIPT)); |
|
| 76 | +define('_DIR_JAVASCRIPT', (_DIR_RACINE.'prive/'._JAVASCRIPT)); |
|
| 77 | 77 | |
| 78 | 78 | # Le nom des 4 repertoires modifiables par les scripts lances par httpd |
| 79 | 79 | # Par defaut ces 4 noms seront suffixes par _DIR_RACINE (cf plus bas) |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | // Son emplacement absolu si on le trouve |
| 106 | 106 | if ( |
| 107 | - @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 108 | - or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 107 | + @file_exists($f = _ROOT_RACINE._NOM_PERMANENTS_INACCESSIBLES._NOM_CONFIG.'.php') |
|
| 108 | + or (@file_exists($f = _ROOT_RESTREINT._NOM_CONFIG.'.php')) |
|
| 109 | 109 | ) { |
| 110 | 110 | /** Emplacement absolu du fichier d'option */ |
| 111 | 111 | define('_FILE_OPTIONS', $f); |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | // Inclure l'ecran de securite |
| 130 | 130 | if ( |
| 131 | 131 | !defined('_ECRAN_SECURITE') |
| 132 | - and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 132 | + and @file_exists($f = _ROOT_RACINE._NOM_PERMANENTS_INACCESSIBLES.'ecran_securite.php') |
|
| 133 | 133 | ) { |
| 134 | 134 | include $f; |
| 135 | 135 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | // UA plus cibles |
| 151 | 151 | . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
| 152 | 152 | . ',i', |
| 153 | - (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 153 | + (string) $_SERVER['HTTP_USER_AGENT'] |
|
| 154 | 154 | ) |
| 155 | 155 | ); |
| 156 | 156 | } |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | # la matrice standard (fichiers definissant les fonctions a inclure) |
| 393 | 393 | $spip_matrice = []; |
| 394 | 394 | # les plugins a activer |
| 395 | -$plugins = []; // voir le contenu du repertoire /plugins/ |
|
| 395 | +$plugins = []; // voir le contenu du repertoire /plugins/ |
|
| 396 | 396 | # les surcharges de include_spip() |
| 397 | 397 | $surcharges = []; // format 'inc_truc' => '/plugins/chose/inc_truc2.php' |
| 398 | 398 | |
@@ -470,8 +470,8 @@ discard block |
||
| 470 | 470 | // |
| 471 | 471 | // Charger les fonctions liees aux serveurs Http et Sql. |
| 472 | 472 | // |
| 473 | -require_once _ROOT_RESTREINT . 'inc/utils.php'; |
|
| 474 | -require_once _ROOT_RESTREINT . 'base/connect_sql.php'; |
|
| 473 | +require_once _ROOT_RESTREINT.'inc/utils.php'; |
|
| 474 | +require_once _ROOT_RESTREINT.'base/connect_sql.php'; |
|
| 475 | 475 | |
| 476 | 476 | // Definition personnelles eventuelles |
| 477 | 477 | |
@@ -494,10 +494,10 @@ discard block |
||
| 494 | 494 | // ===> on execute en neutralisant les messages d'erreur |
| 495 | 495 | |
| 496 | 496 | spip_initialisation_core( |
| 497 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 498 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 499 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 500 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 497 | + (_DIR_RACINE._NOM_PERMANENTS_INACCESSIBLES), |
|
| 498 | + (_DIR_RACINE._NOM_PERMANENTS_ACCESSIBLES), |
|
| 499 | + (_DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 500 | + (_DIR_RACINE._NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 501 | 501 | ); |
| 502 | 502 | |
| 503 | 503 | |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | // Si on est dans le site public, dire que qq s'en occupe |
| 553 | 553 | include_spip('inc/minipres'); |
| 554 | 554 | utiliser_langue_visiteur(); |
| 555 | - echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 555 | + echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>"._T('info_travaux_texte').'</p>', ['status' => 503]); |
|
| 556 | 556 | exit; |
| 557 | 557 | } |
| 558 | 558 | // autrement c'est une install ad hoc (spikini...), on sait pas faire |
@@ -591,12 +591,12 @@ discard block |
||
| 591 | 591 | } |
| 592 | 592 | if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
| 593 | 593 | include_spip('inc/filtres_mini'); |
| 594 | - header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 594 | + header(_HEADER_COMPOSED_BY." $spip_version_affichee @ www.spip.net + ".url_absolue(_DIR_VAR.'config.txt')); |
|
| 595 | 595 | } else { |
| 596 | 596 | // header minimal |
| 597 | - header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 597 | + header(_HEADER_COMPOSED_BY.' @ www.spip.net'); |
|
| 598 | 598 | } |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | $methode = (isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : ((php_sapi_name() == 'cli') ? 'cli' : '')); |
| 602 | -spip_log($methode . ' ' . self() . ' - ' . _FILE_CONNECT, _LOG_DEBUG); |
|
| 602 | +spip_log($methode.' '.self().' - '._FILE_CONNECT, _LOG_DEBUG); |
|