@@ -312,8 +312,7 @@ |
||
| 312 | 312 | ecrire_meta($casier, $serialized_store, null, $table); |
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | - } |
|
| 316 | - else { |
|
| 315 | + } else { |
|
| 317 | 316 | ecrire_meta($casier, $store, null, $table); |
| 318 | 317 | } |
| 319 | 318 | } |
@@ -303,9 +303,9 @@ |
||
| 303 | 303 | // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
| 304 | 304 | // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
| 305 | 305 | if ($has_planes) { |
| 306 | - $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 306 | + $check_store = sql_getfetsel('valeur', 'spip_'.$table, 'nom='.sql_quote($casier)); |
|
| 307 | 307 | if ($check_store !== $serialized_store) { |
| 308 | - array_walk_recursive($store, function (&$value, $key) { |
|
| 308 | + array_walk_recursive($store, function(&$value, $key) { |
|
| 309 | 309 | if (is_string($value)) { |
| 310 | 310 | $value = utf8_noplanes($value); |
| 311 | 311 | } |
@@ -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 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @return void |
| 29 | 29 | */ |
| 30 | 30 | function inc_config_dist() { |
| 31 | - actualise_metas(liste_metas()); |
|
| 31 | + actualise_metas(liste_metas()); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -45,34 +45,34 @@ discard block |
||
| 45 | 45 | * Liste (table, casier, sous_casier) |
| 46 | 46 | */ |
| 47 | 47 | function expliquer_config($cfg) { |
| 48 | - // par defaut, sur la table des meta |
|
| 49 | - $table = 'meta'; |
|
| 50 | - $casier = null; |
|
| 51 | - $sous_casier = []; |
|
| 52 | - $cfg = explode('/', $cfg); |
|
| 53 | - |
|
| 54 | - // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 55 | - if (!reset($cfg) and count($cfg) > 1) { |
|
| 56 | - array_shift($cfg); |
|
| 57 | - $table = array_shift($cfg); |
|
| 58 | - if (!isset($GLOBALS[$table])) { |
|
| 59 | - lire_metas($table); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 64 | - if (count($cfg)) { |
|
| 65 | - // pas sur un appel vide '' |
|
| 66 | - if ('' !== ($c = array_shift($cfg))) { |
|
| 67 | - $casier = $c; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if (count($cfg)) { |
|
| 72 | - $sous_casier = $cfg; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return [$table, $casier, $sous_casier]; |
|
| 48 | + // par defaut, sur la table des meta |
|
| 49 | + $table = 'meta'; |
|
| 50 | + $casier = null; |
|
| 51 | + $sous_casier = []; |
|
| 52 | + $cfg = explode('/', $cfg); |
|
| 53 | + |
|
| 54 | + // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 55 | + if (!reset($cfg) and count($cfg) > 1) { |
|
| 56 | + array_shift($cfg); |
|
| 57 | + $table = array_shift($cfg); |
|
| 58 | + if (!isset($GLOBALS[$table])) { |
|
| 59 | + lire_metas($table); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 64 | + if (count($cfg)) { |
|
| 65 | + // pas sur un appel vide '' |
|
| 66 | + if ('' !== ($c = array_shift($cfg))) { |
|
| 67 | + $casier = $c; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if (count($cfg)) { |
|
| 72 | + $sous_casier = $cfg; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return [$table, $casier, $sous_casier]; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -100,65 +100,65 @@ discard block |
||
| 100 | 100 | * Contenu de la configuration obtenue |
| 101 | 101 | */ |
| 102 | 102 | function lire_config($cfg = '', $def = null, $unserialize = true) { |
| 103 | - // lire le stockage sous la forme /table/valeur |
|
| 104 | - // ou valeur qui est en fait implicitement /meta/valeur |
|
| 105 | - // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 106 | - |
|
| 107 | - // traiter en priorite le cas simple et frequent |
|
| 108 | - // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 109 | - if ($cfg and strpbrk($cfg, '/:') === false) { |
|
| 110 | - $r = isset($GLOBALS['meta'][$cfg]) ? |
|
| 111 | - ((!$unserialize |
|
| 112 | - // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 113 | - or !is_string($GLOBALS['meta'][$cfg]) |
|
| 114 | - // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 115 | - or !str_contains($GLOBALS['meta'][$cfg], ':') |
|
| 116 | - or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t) |
|
| 117 | - : $def; |
|
| 118 | - |
|
| 119 | - return $r; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Brancher sur methodes externes si besoin |
|
| 123 | - if ($cfg and $p = strpos($cfg, '::')) { |
|
| 124 | - $methode = substr($cfg, 0, $p); |
|
| 125 | - $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 126 | - |
|
| 127 | - return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 131 | - |
|
| 132 | - if (!isset($GLOBALS[$table])) { |
|
| 133 | - return $def; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $r = $GLOBALS[$table]; |
|
| 137 | - |
|
| 138 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 139 | - if (!$casier) { |
|
| 140 | - return $unserialize ? $r : serialize($r); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // casier principal : |
|
| 144 | - // le deserializer si demande |
|
| 145 | - // ou si on a besoin |
|
| 146 | - // d'un sous casier |
|
| 147 | - $r = $r[$casier] ?? null; |
|
| 148 | - if (($unserialize or is_countable($sous_casier) ? count($sous_casier) : 0) and $r and is_string($r)) { |
|
| 149 | - $r = (($t = @unserialize($r)) === false ? $r : $t); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // aller chercher le sous_casier |
|
| 153 | - while (!is_null($r) and $casier = array_shift($sous_casier)) { |
|
| 154 | - $r = $r[$casier] ?? null; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (is_null($r)) { |
|
| 158 | - return $def; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $r; |
|
| 103 | + // lire le stockage sous la forme /table/valeur |
|
| 104 | + // ou valeur qui est en fait implicitement /meta/valeur |
|
| 105 | + // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 106 | + |
|
| 107 | + // traiter en priorite le cas simple et frequent |
|
| 108 | + // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 109 | + if ($cfg and strpbrk($cfg, '/:') === false) { |
|
| 110 | + $r = isset($GLOBALS['meta'][$cfg]) ? |
|
| 111 | + ((!$unserialize |
|
| 112 | + // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 113 | + or !is_string($GLOBALS['meta'][$cfg]) |
|
| 114 | + // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 115 | + or !str_contains($GLOBALS['meta'][$cfg], ':') |
|
| 116 | + or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t) |
|
| 117 | + : $def; |
|
| 118 | + |
|
| 119 | + return $r; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // Brancher sur methodes externes si besoin |
|
| 123 | + if ($cfg and $p = strpos($cfg, '::')) { |
|
| 124 | + $methode = substr($cfg, 0, $p); |
|
| 125 | + $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 126 | + |
|
| 127 | + return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 131 | + |
|
| 132 | + if (!isset($GLOBALS[$table])) { |
|
| 133 | + return $def; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $r = $GLOBALS[$table]; |
|
| 137 | + |
|
| 138 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 139 | + if (!$casier) { |
|
| 140 | + return $unserialize ? $r : serialize($r); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // casier principal : |
|
| 144 | + // le deserializer si demande |
|
| 145 | + // ou si on a besoin |
|
| 146 | + // d'un sous casier |
|
| 147 | + $r = $r[$casier] ?? null; |
|
| 148 | + if (($unserialize or is_countable($sous_casier) ? count($sous_casier) : 0) and $r and is_string($r)) { |
|
| 149 | + $r = (($t = @unserialize($r)) === false ? $r : $t); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // aller chercher le sous_casier |
|
| 153 | + while (!is_null($r) and $casier = array_shift($sous_casier)) { |
|
| 154 | + $r = $r[$casier] ?? null; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (is_null($r)) { |
|
| 158 | + return $def; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $r; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @return mixed |
| 173 | 173 | */ |
| 174 | 174 | function lire_config_metapack_dist($cfg = '', $def = null, $unserialize = true) { |
| 175 | - return lire_config($cfg, $def, $unserialize); |
|
| 175 | + return lire_config($cfg, $def, $unserialize); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -184,144 +184,144 @@ discard block |
||
| 184 | 184 | * @return bool |
| 185 | 185 | */ |
| 186 | 186 | function ecrire_config($cfg, $store) { |
| 187 | - // Brancher sur methodes externes si besoin |
|
| 188 | - if ($cfg and $p = strpos($cfg, '::')) { |
|
| 189 | - $methode = substr($cfg, 0, $p); |
|
| 190 | - $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 191 | - |
|
| 192 | - return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 196 | - // il faut au moins un casier pour ecrire |
|
| 197 | - if (!$casier) { |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // trouvons ou creons le pointeur sur le casier |
|
| 202 | - $st = $GLOBALS[$table][$casier] ?? null; |
|
| 203 | - if (!is_array($st) and ($sous_casier or is_array($store))) { |
|
| 204 | - if ($st === null) { |
|
| 205 | - // ne rien creer si c'est une demande d'effacement |
|
| 206 | - if ($store === null) { |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - $st = []; |
|
| 210 | - } else { |
|
| 211 | - $st = unserialize($st); |
|
| 212 | - if ($st === false) { |
|
| 213 | - // ne rien creer si c'est une demande d'effacement |
|
| 214 | - if ($store === null) { |
|
| 215 | - return false; |
|
| 216 | - } |
|
| 217 | - $st = []; |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $has_planes = false; |
|
| 223 | - // si on a affaire a un sous caiser |
|
| 224 | - // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 225 | - if ($c = $sous_casier) { |
|
| 226 | - $sc = &$st; |
|
| 227 | - $pointeurs = []; |
|
| 228 | - while (is_countable($c) ? count($c) : 0 and $cc = array_shift($c)) { |
|
| 229 | - // creer l'entree si elle n'existe pas |
|
| 230 | - if (!isset($sc[$cc])) { |
|
| 231 | - // si on essaye d'effacer une config qui n'existe pas |
|
| 232 | - // ne rien creer mais sortir |
|
| 233 | - if (is_null($store)) { |
|
| 234 | - return false; |
|
| 235 | - } |
|
| 236 | - $sc[$cc] = []; |
|
| 237 | - } |
|
| 238 | - $pointeurs[$cc] = &$sc; |
|
| 239 | - $sc = &$sc[$cc]; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // si c'est une demande d'effacement |
|
| 243 | - if (is_null($store)) { |
|
| 244 | - $c = $sous_casier; |
|
| 245 | - $sous = array_pop($c); |
|
| 246 | - // effacer, et remonter pour effacer les parents vides |
|
| 247 | - do { |
|
| 248 | - unset($pointeurs[$sous][$sous]); |
|
| 249 | - } while ($sous = array_pop($c) and !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0)); |
|
| 250 | - |
|
| 251 | - // si on a vide tous les sous casiers, |
|
| 252 | - // et que le casier est vide |
|
| 253 | - // vider aussi la meta |
|
| 254 | - if (!$sous and !(is_countable($st) ? count($st) : 0)) { |
|
| 255 | - $st = null; |
|
| 256 | - } |
|
| 257 | - } // dans tous les autres cas, on ecrase |
|
| 258 | - else { |
|
| 259 | - if ( |
|
| 260 | - defined('_MYSQL_NOPLANES') |
|
| 261 | - and _MYSQL_NOPLANES |
|
| 262 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 263 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 264 | - ) { |
|
| 265 | - // detecter si la valeur qu'on veut ecrire a des planes |
|
| 266 | - // @see utf8_noplanes |
|
| 267 | - $serialized_store = (is_string($store) ? $store : serialize($store)); |
|
| 268 | - // un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes |
|
| 269 | - if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) { |
|
| 270 | - if (!function_exists('utf8_noplanes')) { |
|
| 271 | - include_spip('inc/charsets'); |
|
| 272 | - } |
|
| 273 | - if ($serialized_store !== utf8_noplanes($serialized_store)) { |
|
| 274 | - $has_planes = true; |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $sc = $store; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // Maintenant que $st est modifiee |
|
| 283 | - // reprenons la comme valeur a stocker dans le casier principal |
|
| 284 | - $store = $st; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - if (is_null($store)) { |
|
| 288 | - if (is_null($st) and !$sous_casier) { |
|
| 289 | - return false; |
|
| 290 | - } // la config n'existait deja pas ! |
|
| 291 | - effacer_meta($casier, $table); |
|
| 292 | - supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 293 | - } // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 294 | - else { |
|
| 295 | - if (!isset($GLOBALS[$table])) { |
|
| 296 | - installer_table_meta($table); |
|
| 297 | - } |
|
| 298 | - // si ce n'est pas une chaine |
|
| 299 | - // il faut serializer |
|
| 300 | - if (!is_string($store)) { |
|
| 301 | - $serialized_store = serialize($store); |
|
| 302 | - ecrire_meta($casier, $serialized_store, null, $table); |
|
| 303 | - // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
|
| 304 | - // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
|
| 305 | - if ($has_planes) { |
|
| 306 | - $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 307 | - if ($check_store !== $serialized_store) { |
|
| 308 | - array_walk_recursive($store, function (&$value, $key) { |
|
| 309 | - if (is_string($value)) { |
|
| 310 | - $value = utf8_noplanes($value); |
|
| 311 | - } |
|
| 312 | - }); |
|
| 313 | - $serialized_store = serialize($store); |
|
| 314 | - ecrire_meta($casier, $serialized_store, null, $table); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - else { |
|
| 319 | - ecrire_meta($casier, $store, null, $table); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - // verifier que lire_config($cfg)==$store ? |
|
| 324 | - return true; |
|
| 187 | + // Brancher sur methodes externes si besoin |
|
| 188 | + if ($cfg and $p = strpos($cfg, '::')) { |
|
| 189 | + $methode = substr($cfg, 0, $p); |
|
| 190 | + $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 191 | + |
|
| 192 | + return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 196 | + // il faut au moins un casier pour ecrire |
|
| 197 | + if (!$casier) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // trouvons ou creons le pointeur sur le casier |
|
| 202 | + $st = $GLOBALS[$table][$casier] ?? null; |
|
| 203 | + if (!is_array($st) and ($sous_casier or is_array($store))) { |
|
| 204 | + if ($st === null) { |
|
| 205 | + // ne rien creer si c'est une demande d'effacement |
|
| 206 | + if ($store === null) { |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + $st = []; |
|
| 210 | + } else { |
|
| 211 | + $st = unserialize($st); |
|
| 212 | + if ($st === false) { |
|
| 213 | + // ne rien creer si c'est une demande d'effacement |
|
| 214 | + if ($store === null) { |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 217 | + $st = []; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $has_planes = false; |
|
| 223 | + // si on a affaire a un sous caiser |
|
| 224 | + // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 225 | + if ($c = $sous_casier) { |
|
| 226 | + $sc = &$st; |
|
| 227 | + $pointeurs = []; |
|
| 228 | + while (is_countable($c) ? count($c) : 0 and $cc = array_shift($c)) { |
|
| 229 | + // creer l'entree si elle n'existe pas |
|
| 230 | + if (!isset($sc[$cc])) { |
|
| 231 | + // si on essaye d'effacer une config qui n'existe pas |
|
| 232 | + // ne rien creer mais sortir |
|
| 233 | + if (is_null($store)) { |
|
| 234 | + return false; |
|
| 235 | + } |
|
| 236 | + $sc[$cc] = []; |
|
| 237 | + } |
|
| 238 | + $pointeurs[$cc] = &$sc; |
|
| 239 | + $sc = &$sc[$cc]; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // si c'est une demande d'effacement |
|
| 243 | + if (is_null($store)) { |
|
| 244 | + $c = $sous_casier; |
|
| 245 | + $sous = array_pop($c); |
|
| 246 | + // effacer, et remonter pour effacer les parents vides |
|
| 247 | + do { |
|
| 248 | + unset($pointeurs[$sous][$sous]); |
|
| 249 | + } while ($sous = array_pop($c) and !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0)); |
|
| 250 | + |
|
| 251 | + // si on a vide tous les sous casiers, |
|
| 252 | + // et que le casier est vide |
|
| 253 | + // vider aussi la meta |
|
| 254 | + if (!$sous and !(is_countable($st) ? count($st) : 0)) { |
|
| 255 | + $st = null; |
|
| 256 | + } |
|
| 257 | + } // dans tous les autres cas, on ecrase |
|
| 258 | + else { |
|
| 259 | + if ( |
|
| 260 | + defined('_MYSQL_NOPLANES') |
|
| 261 | + and _MYSQL_NOPLANES |
|
| 262 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 263 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 264 | + ) { |
|
| 265 | + // detecter si la valeur qu'on veut ecrire a des planes |
|
| 266 | + // @see utf8_noplanes |
|
| 267 | + $serialized_store = (is_string($store) ? $store : serialize($store)); |
|
| 268 | + // un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes |
|
| 269 | + if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) { |
|
| 270 | + if (!function_exists('utf8_noplanes')) { |
|
| 271 | + include_spip('inc/charsets'); |
|
| 272 | + } |
|
| 273 | + if ($serialized_store !== utf8_noplanes($serialized_store)) { |
|
| 274 | + $has_planes = true; |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $sc = $store; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // Maintenant que $st est modifiee |
|
| 283 | + // reprenons la comme valeur a stocker dans le casier principal |
|
| 284 | + $store = $st; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + if (is_null($store)) { |
|
| 288 | + if (is_null($st) and !$sous_casier) { |
|
| 289 | + return false; |
|
| 290 | + } // la config n'existait deja pas ! |
|
| 291 | + effacer_meta($casier, $table); |
|
| 292 | + supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 293 | + } // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 294 | + else { |
|
| 295 | + if (!isset($GLOBALS[$table])) { |
|
| 296 | + installer_table_meta($table); |
|
| 297 | + } |
|
| 298 | + // si ce n'est pas une chaine |
|
| 299 | + // il faut serializer |
|
| 300 | + if (!is_string($store)) { |
|
| 301 | + $serialized_store = serialize($store); |
|
| 302 | + ecrire_meta($casier, $serialized_store, null, $table); |
|
| 303 | + // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
|
| 304 | + // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
|
| 305 | + if ($has_planes) { |
|
| 306 | + $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 307 | + if ($check_store !== $serialized_store) { |
|
| 308 | + array_walk_recursive($store, function (&$value, $key) { |
|
| 309 | + if (is_string($value)) { |
|
| 310 | + $value = utf8_noplanes($value); |
|
| 311 | + } |
|
| 312 | + }); |
|
| 313 | + $serialized_store = serialize($store); |
|
| 314 | + ecrire_meta($casier, $serialized_store, null, $table); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + else { |
|
| 319 | + ecrire_meta($casier, $store, null, $table); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + // verifier que lire_config($cfg)==$store ? |
|
| 324 | + return true; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -335,14 +335,14 @@ discard block |
||
| 335 | 335 | * @return bool |
| 336 | 336 | */ |
| 337 | 337 | function ecrire_config_metapack_dist($cfg, $store) { |
| 338 | - // cas particulier en metapack:: |
|
| 339 | - // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 340 | - // intacte en sortie ... |
|
| 341 | - if (is_string($store) and strpos($store, ':') and unserialize($store)) { |
|
| 342 | - $store = serialize($store); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - return ecrire_config($cfg, $store); |
|
| 338 | + // cas particulier en metapack:: |
|
| 339 | + // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 340 | + // intacte en sortie ... |
|
| 341 | + if (is_string($store) and strpos($store, ':') and unserialize($store)) { |
|
| 342 | + $store = serialize($store); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + return ecrire_config($cfg, $store); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | /** |
@@ -352,9 +352,9 @@ discard block |
||
| 352 | 352 | * @return bool |
| 353 | 353 | */ |
| 354 | 354 | function effacer_config($cfg) { |
| 355 | - ecrire_config($cfg, null); |
|
| 355 | + ecrire_config($cfg, null); |
|
| 356 | 356 | |
| 357 | - return true; |
|
| 357 | + return true; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -371,58 +371,58 @@ discard block |
||
| 371 | 371 | * Couples nom de la `meta` => valeur par défaut |
| 372 | 372 | */ |
| 373 | 373 | function liste_metas() { |
| 374 | - return pipeline('configurer_liste_metas', [ |
|
| 375 | - 'nom_site' => _T('info_mon_site_spip'), |
|
| 376 | - 'slogan_site' => '', |
|
| 377 | - 'adresse_site' => preg_replace(',/$,', '', url_de_base()), |
|
| 378 | - 'descriptif_site' => '', |
|
| 379 | - 'activer_logos' => 'oui', |
|
| 380 | - 'activer_logos_survol' => 'non', |
|
| 381 | - 'articles_surtitre' => 'non', |
|
| 382 | - 'articles_soustitre' => 'non', |
|
| 383 | - 'articles_descriptif' => 'non', |
|
| 384 | - 'articles_chapeau' => 'non', |
|
| 385 | - 'articles_texte' => 'oui', |
|
| 386 | - 'articles_ps' => 'non', |
|
| 387 | - 'articles_redac' => 'non', |
|
| 388 | - 'post_dates' => 'non', |
|
| 389 | - 'articles_urlref' => 'non', |
|
| 390 | - 'articles_redirection' => 'non', |
|
| 391 | - 'creer_preview' => 'non', |
|
| 392 | - 'taille_preview' => 150, |
|
| 393 | - 'articles_modif' => 'non', |
|
| 394 | - |
|
| 395 | - 'rubriques_descriptif' => 'non', |
|
| 396 | - 'rubriques_texte' => 'oui', |
|
| 397 | - |
|
| 398 | - 'accepter_inscriptions' => 'non', |
|
| 399 | - 'accepter_visiteurs' => 'non', |
|
| 400 | - 'prevenir_auteurs' => 'non', |
|
| 401 | - 'suivi_edito' => 'non', |
|
| 402 | - 'adresse_suivi' => '', |
|
| 403 | - 'adresse_suivi_inscription' => '', |
|
| 404 | - 'adresse_neuf' => '', |
|
| 405 | - 'jours_neuf' => '', |
|
| 406 | - 'quoi_de_neuf' => 'non', |
|
| 407 | - 'preview' => ',0minirezo,1comite,', |
|
| 408 | - |
|
| 409 | - 'syndication_integrale' => 'oui', |
|
| 410 | - 'charset' => _DEFAULT_CHARSET, |
|
| 411 | - 'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)), |
|
| 412 | - |
|
| 413 | - 'multi_rubriques' => 'non', |
|
| 414 | - 'multi_secteurs' => 'non', |
|
| 415 | - 'gerer_trad' => 'non', |
|
| 416 | - 'langues_multilingue' => '', |
|
| 417 | - |
|
| 418 | - 'version_html_max' => 'html4', |
|
| 419 | - |
|
| 420 | - 'type_urls' => 'page', |
|
| 421 | - |
|
| 422 | - 'email_envoi' => '', |
|
| 423 | - 'email_webmaster' => '', |
|
| 424 | - 'auto_compress_http' => 'non', |
|
| 425 | - ]); |
|
| 374 | + return pipeline('configurer_liste_metas', [ |
|
| 375 | + 'nom_site' => _T('info_mon_site_spip'), |
|
| 376 | + 'slogan_site' => '', |
|
| 377 | + 'adresse_site' => preg_replace(',/$,', '', url_de_base()), |
|
| 378 | + 'descriptif_site' => '', |
|
| 379 | + 'activer_logos' => 'oui', |
|
| 380 | + 'activer_logos_survol' => 'non', |
|
| 381 | + 'articles_surtitre' => 'non', |
|
| 382 | + 'articles_soustitre' => 'non', |
|
| 383 | + 'articles_descriptif' => 'non', |
|
| 384 | + 'articles_chapeau' => 'non', |
|
| 385 | + 'articles_texte' => 'oui', |
|
| 386 | + 'articles_ps' => 'non', |
|
| 387 | + 'articles_redac' => 'non', |
|
| 388 | + 'post_dates' => 'non', |
|
| 389 | + 'articles_urlref' => 'non', |
|
| 390 | + 'articles_redirection' => 'non', |
|
| 391 | + 'creer_preview' => 'non', |
|
| 392 | + 'taille_preview' => 150, |
|
| 393 | + 'articles_modif' => 'non', |
|
| 394 | + |
|
| 395 | + 'rubriques_descriptif' => 'non', |
|
| 396 | + 'rubriques_texte' => 'oui', |
|
| 397 | + |
|
| 398 | + 'accepter_inscriptions' => 'non', |
|
| 399 | + 'accepter_visiteurs' => 'non', |
|
| 400 | + 'prevenir_auteurs' => 'non', |
|
| 401 | + 'suivi_edito' => 'non', |
|
| 402 | + 'adresse_suivi' => '', |
|
| 403 | + 'adresse_suivi_inscription' => '', |
|
| 404 | + 'adresse_neuf' => '', |
|
| 405 | + 'jours_neuf' => '', |
|
| 406 | + 'quoi_de_neuf' => 'non', |
|
| 407 | + 'preview' => ',0minirezo,1comite,', |
|
| 408 | + |
|
| 409 | + 'syndication_integrale' => 'oui', |
|
| 410 | + 'charset' => _DEFAULT_CHARSET, |
|
| 411 | + 'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)), |
|
| 412 | + |
|
| 413 | + 'multi_rubriques' => 'non', |
|
| 414 | + 'multi_secteurs' => 'non', |
|
| 415 | + 'gerer_trad' => 'non', |
|
| 416 | + 'langues_multilingue' => '', |
|
| 417 | + |
|
| 418 | + 'version_html_max' => 'html4', |
|
| 419 | + |
|
| 420 | + 'type_urls' => 'page', |
|
| 421 | + |
|
| 422 | + 'email_envoi' => '', |
|
| 423 | + 'email_webmaster' => '', |
|
| 424 | + 'auto_compress_http' => 'non', |
|
| 425 | + ]); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -433,43 +433,43 @@ discard block |
||
| 433 | 433 | * @return void |
| 434 | 434 | */ |
| 435 | 435 | function actualise_metas($liste_meta) { |
| 436 | - $meta_serveur = |
|
| 437 | - [ |
|
| 438 | - 'version_installee', |
|
| 439 | - 'adresse_site', |
|
| 440 | - 'alea_ephemere_ancien', |
|
| 441 | - 'alea_ephemere', |
|
| 442 | - 'alea_ephemere_date', |
|
| 443 | - 'langue_site', |
|
| 444 | - 'langues_proposees', |
|
| 445 | - 'date_calcul_rubriques', |
|
| 446 | - 'derniere_modif', |
|
| 447 | - 'optimiser_table', |
|
| 448 | - 'drapeau_edition', |
|
| 449 | - 'creer_preview', |
|
| 450 | - 'taille_preview', |
|
| 451 | - 'creer_htpasswd', |
|
| 452 | - 'creer_htaccess', |
|
| 453 | - 'gd_formats_read', |
|
| 454 | - 'gd_formats', |
|
| 455 | - 'netpbm_formats', |
|
| 456 | - 'formats_graphiques', |
|
| 457 | - 'image_process', |
|
| 458 | - 'plugin_header', |
|
| 459 | - 'plugin' |
|
| 460 | - ]; |
|
| 461 | - // verifier le impt=non |
|
| 462 | - sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur)); |
|
| 463 | - |
|
| 464 | - foreach ($liste_meta as $nom => $valeur) { |
|
| 465 | - if (empty($GLOBALS['meta'][$nom])) { |
|
| 466 | - ecrire_meta($nom, $valeur); |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - include_spip('inc/rubriques'); |
|
| 471 | - $langues = calculer_langues_utilisees(); |
|
| 472 | - ecrire_meta('langues_utilisees', $langues); |
|
| 436 | + $meta_serveur = |
|
| 437 | + [ |
|
| 438 | + 'version_installee', |
|
| 439 | + 'adresse_site', |
|
| 440 | + 'alea_ephemere_ancien', |
|
| 441 | + 'alea_ephemere', |
|
| 442 | + 'alea_ephemere_date', |
|
| 443 | + 'langue_site', |
|
| 444 | + 'langues_proposees', |
|
| 445 | + 'date_calcul_rubriques', |
|
| 446 | + 'derniere_modif', |
|
| 447 | + 'optimiser_table', |
|
| 448 | + 'drapeau_edition', |
|
| 449 | + 'creer_preview', |
|
| 450 | + 'taille_preview', |
|
| 451 | + 'creer_htpasswd', |
|
| 452 | + 'creer_htaccess', |
|
| 453 | + 'gd_formats_read', |
|
| 454 | + 'gd_formats', |
|
| 455 | + 'netpbm_formats', |
|
| 456 | + 'formats_graphiques', |
|
| 457 | + 'image_process', |
|
| 458 | + 'plugin_header', |
|
| 459 | + 'plugin' |
|
| 460 | + ]; |
|
| 461 | + // verifier le impt=non |
|
| 462 | + sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur)); |
|
| 463 | + |
|
| 464 | + foreach ($liste_meta as $nom => $valeur) { |
|
| 465 | + if (empty($GLOBALS['meta'][$nom])) { |
|
| 466 | + ecrire_meta($nom, $valeur); |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + include_spip('inc/rubriques'); |
|
| 471 | + $langues = calculer_langues_utilisees(); |
|
| 472 | + ecrire_meta('langues_utilisees', $langues); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | |
@@ -491,18 +491,18 @@ discard block |
||
| 491 | 491 | */ |
| 492 | 492 | function appliquer_modifs_config($purger_skel = false) { |
| 493 | 493 | |
| 494 | - foreach (liste_metas() as $i => $v) { |
|
| 495 | - if (($x = _request($i)) !== null) { |
|
| 496 | - ecrire_meta($i, $x); |
|
| 497 | - } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 498 | - ecrire_meta($i, $v); |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - if ($purger_skel) { |
|
| 503 | - include_spip('inc/invalideur'); |
|
| 504 | - purger_repertoire(_DIR_SKELS); |
|
| 505 | - } |
|
| 494 | + foreach (liste_metas() as $i => $v) { |
|
| 495 | + if (($x = _request($i)) !== null) { |
|
| 496 | + ecrire_meta($i, $x); |
|
| 497 | + } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 498 | + ecrire_meta($i, $v); |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + if ($purger_skel) { |
|
| 503 | + include_spip('inc/invalideur'); |
|
| 504 | + purger_repertoire(_DIR_SKELS); |
|
| 505 | + } |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -513,21 +513,21 @@ discard block |
||
| 513 | 513 | * @return string |
| 514 | 514 | */ |
| 515 | 515 | function appliquer_adresse_site($adresse_site) { |
| 516 | - if ($adresse_site !== null) { |
|
| 517 | - if (!strlen($adresse_site)) { |
|
| 518 | - $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; |
|
| 519 | - $adresse_site = url_de_base(); |
|
| 520 | - } |
|
| 521 | - $adresse_site = preg_replace(',/?\s*$,', '', $adresse_site); |
|
| 516 | + if ($adresse_site !== null) { |
|
| 517 | + if (!strlen($adresse_site)) { |
|
| 518 | + $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; |
|
| 519 | + $adresse_site = url_de_base(); |
|
| 520 | + } |
|
| 521 | + $adresse_site = preg_replace(',/?\s*$,', '', $adresse_site); |
|
| 522 | 522 | |
| 523 | - if (!tester_url_absolue($adresse_site)) { |
|
| 524 | - $adresse_site = "http://$adresse_site"; |
|
| 525 | - } |
|
| 523 | + if (!tester_url_absolue($adresse_site)) { |
|
| 524 | + $adresse_site = "http://$adresse_site"; |
|
| 525 | + } |
|
| 526 | 526 | |
| 527 | - $adresse_site = entites_html($adresse_site); |
|
| 527 | + $adresse_site = entites_html($adresse_site); |
|
| 528 | 528 | |
| 529 | - ecrire_meta('adresse_site', $adresse_site); |
|
| 530 | - } |
|
| 529 | + ecrire_meta('adresse_site', $adresse_site); |
|
| 530 | + } |
|
| 531 | 531 | |
| 532 | - return $adresse_site; |
|
| 532 | + return $adresse_site; |
|
| 533 | 533 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/config'); |
@@ -37,26 +37,26 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | function exec_admin_plugin_dist($retour = '') { |
| 39 | 39 | |
| 40 | - if (!autoriser('configurer', '_plugins')) { |
|
| 41 | - include_spip('inc/minipres'); |
|
| 42 | - echo minipres(); |
|
| 43 | - } else { |
|
| 44 | - // on fait la verif du path avant tout, |
|
| 45 | - // et l'installation des qu'on est dans la colonne principale |
|
| 46 | - // si jamais la liste des plugins actifs change, il faut faire un refresh du hit |
|
| 47 | - // pour etre sur que les bons fichiers seront charges lors de l'install |
|
| 48 | - $new = actualise_plugins_actifs(); |
|
| 49 | - if ($new and _request('actualise') < 2) { |
|
| 50 | - include_spip('inc/headers'); |
|
| 51 | - if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 52 | - // attendre eventuellement l'invalidation du cache opcode |
|
| 53 | - spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 54 | - } |
|
| 55 | - redirige_par_entete(parametre_url(self(), 'actualise', _request('actualise') + 1, '&')); |
|
| 56 | - } else { |
|
| 57 | - admin_plug_args(_request('voir'), _request('erreur'), _request('format')); |
|
| 58 | - } |
|
| 59 | - } |
|
| 40 | + if (!autoriser('configurer', '_plugins')) { |
|
| 41 | + include_spip('inc/minipres'); |
|
| 42 | + echo minipres(); |
|
| 43 | + } else { |
|
| 44 | + // on fait la verif du path avant tout, |
|
| 45 | + // et l'installation des qu'on est dans la colonne principale |
|
| 46 | + // si jamais la liste des plugins actifs change, il faut faire un refresh du hit |
|
| 47 | + // pour etre sur que les bons fichiers seront charges lors de l'install |
|
| 48 | + $new = actualise_plugins_actifs(); |
|
| 49 | + if ($new and _request('actualise') < 2) { |
|
| 50 | + include_spip('inc/headers'); |
|
| 51 | + if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 52 | + // attendre eventuellement l'invalidation du cache opcode |
|
| 53 | + spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 54 | + } |
|
| 55 | + redirige_par_entete(parametre_url(self(), 'actualise', _request('actualise') + 1, '&')); |
|
| 56 | + } else { |
|
| 57 | + admin_plug_args(_request('voir'), _request('erreur'), _request('format')); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -81,132 +81,132 @@ discard block |
||
| 81 | 81 | * Format d'affichage (liste ou arborescence) |
| 82 | 82 | **/ |
| 83 | 83 | function admin_plug_args($quoi, $erreur, $format) { |
| 84 | - $lpf = null; |
|
| 85 | - $lcpas = null; |
|
| 86 | - $lcpaffichesup = null; |
|
| 87 | - if (!$quoi) { |
|
| 88 | - $quoi = 'actifs'; |
|
| 89 | - } |
|
| 90 | - // empecher l'affichage des erreurs dans le bandeau, on le donne ensuite |
|
| 91 | - // format brut par plugin |
|
| 92 | - $GLOBALS['erreurs_activation_raw'] = plugin_donne_erreurs(true, false); |
|
| 93 | - // format resume mis en forme |
|
| 94 | - $erreur_activation = plugin_donne_erreurs(); |
|
| 95 | - $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 96 | - echo $commencer_page(_T('icone_admin_plugin'), 'configuration', 'plugin'); |
|
| 97 | - |
|
| 98 | - echo debut_gauche(); |
|
| 99 | - echo recuperer_fond('prive/squelettes/navigation/configurer', ['exec' => 'admin_plugin']); |
|
| 100 | - |
|
| 101 | - echo pipeline( |
|
| 102 | - 'affiche_gauche', |
|
| 103 | - [ |
|
| 104 | - 'args' => ['exec' => 'admin_plugin'], |
|
| 105 | - 'data' => afficher_librairies() |
|
| 106 | - ] |
|
| 107 | - ); |
|
| 108 | - |
|
| 109 | - echo debut_droite(); |
|
| 110 | - echo gros_titre(_T('icone_admin_plugin'), ''); |
|
| 111 | - |
|
| 112 | - // Barre d'onglets de premier niveau |
|
| 113 | - echo barre_onglets('plugins', 'plugins_actifs'); |
|
| 114 | - // Barre d'onglets de second niveau |
|
| 115 | - $onglet2 = $quoi == 'actifs' ? 'plugins_actifs' : 'admin_plugin'; |
|
| 116 | - echo debut_onglet('onglets_simple second'); |
|
| 117 | - echo onglet(_T('plugins_tous_liste'), generer_url_ecrire('admin_plugin', 'voir=tous'), 'admin_plugin', $onglet2); |
|
| 118 | - echo onglet(_T('plugins_actifs_liste'), generer_url_ecrire('admin_plugin'), 'plugins_actifs', $onglet2); |
|
| 119 | - echo fin_onglet(); |
|
| 120 | - |
|
| 121 | - // message d'erreur au retour d'une operation |
|
| 122 | - if ($erreur) { |
|
| 123 | - echo "<div class='error'>" . spip_htmlspecialchars($erreur) . '</div>'; |
|
| 124 | - } |
|
| 125 | - if ($erreur_activation) { |
|
| 126 | - echo "<div class='error'>$erreur_activation</div>"; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // la mise a jour de cette meta a ete faite par ecrire_plugin_actifs |
|
| 130 | - $actifs = (array) unserialize($GLOBALS['meta']['plugin']); |
|
| 131 | - $lcpa = $actifs + (array) unserialize($GLOBALS['meta']['plugin_attente']); |
|
| 132 | - |
|
| 133 | - // Les affichages se basent sur le repertoire, pas sur le nom |
|
| 134 | - $actifs = liste_chemin_plugin($actifs, ''); |
|
| 135 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 136 | - $lcpas = liste_chemin_plugin($lcpa, _DIR_PLUGINS_SUPPL); |
|
| 137 | - } |
|
| 138 | - $lcpa = liste_chemin_plugin($lcpa); |
|
| 139 | - |
|
| 140 | - // on installe les plugins maintenant, |
|
| 141 | - // cela permet aux scripts d'install de faire des affichages (moches...) |
|
| 142 | - plugin_installes_meta(); |
|
| 143 | - |
|
| 144 | - echo "<div class='liste-plugins formulaire_spip'>"; |
|
| 145 | - echo debut_cadre_trait_couleur('plugin-24.png', true, '', _T('plugins_liste'), 'plugins'); |
|
| 146 | - |
|
| 147 | - if ($quoi !== 'actifs') { |
|
| 148 | - $lpf = liste_plugin_files(); |
|
| 149 | - if ($lpf) { |
|
| 150 | - echo '<p>' . _T('texte_presente_plugin') . '</p>'; |
|
| 151 | - } else { |
|
| 152 | - if (!@is_dir(_DIR_PLUGINS)) { |
|
| 153 | - echo '<p>' . _T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)]) |
|
| 154 | - . ' — ' . _T('plugin_info_automatique_creer') . '</p>'; |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - $lcpaffiche = $lpf; |
|
| 158 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 159 | - $lcpaffichesup = liste_plugin_files(_DIR_PLUGINS_SUPPL); |
|
| 160 | - } |
|
| 161 | - } else { |
|
| 162 | - // la liste |
|
| 163 | - // $quoi=='actifs' |
|
| 164 | - $lcpaffiche = $lcpa; |
|
| 165 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 166 | - $lcpaffichesup = $lcpas; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if ($quoi == 'actifs' or $lpf) { |
|
| 171 | - $nb = is_countable($lcpa) ? count($lcpa) : 0; |
|
| 172 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 173 | - $nb += is_countable($lcpas) ? count($lcpas) : 0; |
|
| 174 | - } |
|
| 175 | - echo '<h3>' . sinon( |
|
| 176 | - singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'), |
|
| 177 | - _T('plugins_actif_aucun') |
|
| 178 | - ) . '</h3>'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if (empty($format)) { |
|
| 182 | - $format = 'liste'; |
|
| 183 | - } elseif (!in_array($format, ['liste', 'repertoires'])) { |
|
| 184 | - $format = 'repertoires'; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $afficher = charger_fonction("afficher_$format", 'plugins'); |
|
| 188 | - $corps = $afficher(self(), $lcpaffiche, $lcpa, $actifs); |
|
| 189 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 190 | - $corps .= $afficher(self(), $lcpaffichesup, $lcpas, $actifs, _DIR_PLUGINS_SUPPL); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - if ($corps) { |
|
| 194 | - $corps .= "\n<div class='boutons' style='display:none;'>" |
|
| 195 | - . "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer') |
|
| 196 | - . "' />" |
|
| 197 | - . '</div>'; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - echo redirige_action_post('activer_plugins', 'activer', 'admin_plugin', '', $corps); |
|
| 201 | - |
|
| 202 | - echo fin_cadre_trait_couleur(); |
|
| 203 | - |
|
| 204 | - if ($quoi == 'actifs') { |
|
| 205 | - echo affiche_les_plugins_verrouilles($actifs); |
|
| 206 | - } |
|
| 207 | - echo '</div>'; |
|
| 208 | - |
|
| 209 | - echo http_script(" |
|
| 84 | + $lpf = null; |
|
| 85 | + $lcpas = null; |
|
| 86 | + $lcpaffichesup = null; |
|
| 87 | + if (!$quoi) { |
|
| 88 | + $quoi = 'actifs'; |
|
| 89 | + } |
|
| 90 | + // empecher l'affichage des erreurs dans le bandeau, on le donne ensuite |
|
| 91 | + // format brut par plugin |
|
| 92 | + $GLOBALS['erreurs_activation_raw'] = plugin_donne_erreurs(true, false); |
|
| 93 | + // format resume mis en forme |
|
| 94 | + $erreur_activation = plugin_donne_erreurs(); |
|
| 95 | + $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 96 | + echo $commencer_page(_T('icone_admin_plugin'), 'configuration', 'plugin'); |
|
| 97 | + |
|
| 98 | + echo debut_gauche(); |
|
| 99 | + echo recuperer_fond('prive/squelettes/navigation/configurer', ['exec' => 'admin_plugin']); |
|
| 100 | + |
|
| 101 | + echo pipeline( |
|
| 102 | + 'affiche_gauche', |
|
| 103 | + [ |
|
| 104 | + 'args' => ['exec' => 'admin_plugin'], |
|
| 105 | + 'data' => afficher_librairies() |
|
| 106 | + ] |
|
| 107 | + ); |
|
| 108 | + |
|
| 109 | + echo debut_droite(); |
|
| 110 | + echo gros_titre(_T('icone_admin_plugin'), ''); |
|
| 111 | + |
|
| 112 | + // Barre d'onglets de premier niveau |
|
| 113 | + echo barre_onglets('plugins', 'plugins_actifs'); |
|
| 114 | + // Barre d'onglets de second niveau |
|
| 115 | + $onglet2 = $quoi == 'actifs' ? 'plugins_actifs' : 'admin_plugin'; |
|
| 116 | + echo debut_onglet('onglets_simple second'); |
|
| 117 | + echo onglet(_T('plugins_tous_liste'), generer_url_ecrire('admin_plugin', 'voir=tous'), 'admin_plugin', $onglet2); |
|
| 118 | + echo onglet(_T('plugins_actifs_liste'), generer_url_ecrire('admin_plugin'), 'plugins_actifs', $onglet2); |
|
| 119 | + echo fin_onglet(); |
|
| 120 | + |
|
| 121 | + // message d'erreur au retour d'une operation |
|
| 122 | + if ($erreur) { |
|
| 123 | + echo "<div class='error'>" . spip_htmlspecialchars($erreur) . '</div>'; |
|
| 124 | + } |
|
| 125 | + if ($erreur_activation) { |
|
| 126 | + echo "<div class='error'>$erreur_activation</div>"; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // la mise a jour de cette meta a ete faite par ecrire_plugin_actifs |
|
| 130 | + $actifs = (array) unserialize($GLOBALS['meta']['plugin']); |
|
| 131 | + $lcpa = $actifs + (array) unserialize($GLOBALS['meta']['plugin_attente']); |
|
| 132 | + |
|
| 133 | + // Les affichages se basent sur le repertoire, pas sur le nom |
|
| 134 | + $actifs = liste_chemin_plugin($actifs, ''); |
|
| 135 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 136 | + $lcpas = liste_chemin_plugin($lcpa, _DIR_PLUGINS_SUPPL); |
|
| 137 | + } |
|
| 138 | + $lcpa = liste_chemin_plugin($lcpa); |
|
| 139 | + |
|
| 140 | + // on installe les plugins maintenant, |
|
| 141 | + // cela permet aux scripts d'install de faire des affichages (moches...) |
|
| 142 | + plugin_installes_meta(); |
|
| 143 | + |
|
| 144 | + echo "<div class='liste-plugins formulaire_spip'>"; |
|
| 145 | + echo debut_cadre_trait_couleur('plugin-24.png', true, '', _T('plugins_liste'), 'plugins'); |
|
| 146 | + |
|
| 147 | + if ($quoi !== 'actifs') { |
|
| 148 | + $lpf = liste_plugin_files(); |
|
| 149 | + if ($lpf) { |
|
| 150 | + echo '<p>' . _T('texte_presente_plugin') . '</p>'; |
|
| 151 | + } else { |
|
| 152 | + if (!@is_dir(_DIR_PLUGINS)) { |
|
| 153 | + echo '<p>' . _T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)]) |
|
| 154 | + . ' — ' . _T('plugin_info_automatique_creer') . '</p>'; |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + $lcpaffiche = $lpf; |
|
| 158 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 159 | + $lcpaffichesup = liste_plugin_files(_DIR_PLUGINS_SUPPL); |
|
| 160 | + } |
|
| 161 | + } else { |
|
| 162 | + // la liste |
|
| 163 | + // $quoi=='actifs' |
|
| 164 | + $lcpaffiche = $lcpa; |
|
| 165 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 166 | + $lcpaffichesup = $lcpas; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + if ($quoi == 'actifs' or $lpf) { |
|
| 171 | + $nb = is_countable($lcpa) ? count($lcpa) : 0; |
|
| 172 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 173 | + $nb += is_countable($lcpas) ? count($lcpas) : 0; |
|
| 174 | + } |
|
| 175 | + echo '<h3>' . sinon( |
|
| 176 | + singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'), |
|
| 177 | + _T('plugins_actif_aucun') |
|
| 178 | + ) . '</h3>'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if (empty($format)) { |
|
| 182 | + $format = 'liste'; |
|
| 183 | + } elseif (!in_array($format, ['liste', 'repertoires'])) { |
|
| 184 | + $format = 'repertoires'; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $afficher = charger_fonction("afficher_$format", 'plugins'); |
|
| 188 | + $corps = $afficher(self(), $lcpaffiche, $lcpa, $actifs); |
|
| 189 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 190 | + $corps .= $afficher(self(), $lcpaffichesup, $lcpas, $actifs, _DIR_PLUGINS_SUPPL); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + if ($corps) { |
|
| 194 | + $corps .= "\n<div class='boutons' style='display:none;'>" |
|
| 195 | + . "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer') |
|
| 196 | + . "' />" |
|
| 197 | + . '</div>'; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + echo redirige_action_post('activer_plugins', 'activer', 'admin_plugin', '', $corps); |
|
| 201 | + |
|
| 202 | + echo fin_cadre_trait_couleur(); |
|
| 203 | + |
|
| 204 | + if ($quoi == 'actifs') { |
|
| 205 | + echo affiche_les_plugins_verrouilles($actifs); |
|
| 206 | + } |
|
| 207 | + echo '</div>'; |
|
| 208 | + |
|
| 209 | + echo http_script(" |
|
| 210 | 210 | jQuery(function(){ |
| 211 | 211 | jQuery('.plugins li.item a[rel=info]').click(function(){ |
| 212 | 212 | var li = jQuery(this).parents('li').eq(0); |
@@ -232,15 +232,15 @@ discard block |
||
| 232 | 232 | }); |
| 233 | 233 | "); |
| 234 | 234 | |
| 235 | - echo pipeline( |
|
| 236 | - 'affiche_milieu', |
|
| 237 | - [ |
|
| 238 | - 'args' => ['exec' => 'admin_plugin'], |
|
| 239 | - 'data' => '' |
|
| 240 | - ] |
|
| 241 | - ); |
|
| 235 | + echo pipeline( |
|
| 236 | + 'affiche_milieu', |
|
| 237 | + [ |
|
| 238 | + 'args' => ['exec' => 'admin_plugin'], |
|
| 239 | + 'data' => '' |
|
| 240 | + ] |
|
| 241 | + ); |
|
| 242 | 242 | |
| 243 | - echo fin_gauche(), fin_page(); |
|
| 243 | + echo fin_gauche(), fin_page(); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -254,23 +254,23 @@ discard block |
||
| 254 | 254 | * Code HTML |
| 255 | 255 | **/ |
| 256 | 256 | function affiche_les_plugins_verrouilles($actifs) { |
| 257 | - if ((!$liste = liste_plugin_files(_DIR_PLUGINS_DIST))) { |
|
| 258 | - return ''; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - $afficher = charger_fonction('afficher_liste', 'plugins'); |
|
| 262 | - $liste = $afficher(self(), $liste, [], $actifs, _DIR_PLUGINS_DIST); |
|
| 263 | - |
|
| 264 | - return |
|
| 265 | - "<div id='plugins_dist'>" |
|
| 266 | - . debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist') |
|
| 267 | - . '<p>' |
|
| 268 | - . _T('plugin_info_plugins_dist_1', ['plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST)]) |
|
| 269 | - . '<br />' . _T('plugin_info_plugins_dist_2') |
|
| 270 | - . '</p>' |
|
| 271 | - . $liste |
|
| 272 | - . fin_cadre_trait_couleur() |
|
| 273 | - . "</div>\n"; |
|
| 257 | + if ((!$liste = liste_plugin_files(_DIR_PLUGINS_DIST))) { |
|
| 258 | + return ''; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + $afficher = charger_fonction('afficher_liste', 'plugins'); |
|
| 262 | + $liste = $afficher(self(), $liste, [], $actifs, _DIR_PLUGINS_DIST); |
|
| 263 | + |
|
| 264 | + return |
|
| 265 | + "<div id='plugins_dist'>" |
|
| 266 | + . debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist') |
|
| 267 | + . '<p>' |
|
| 268 | + . _T('plugin_info_plugins_dist_1', ['plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST)]) |
|
| 269 | + . '<br />' . _T('plugin_info_plugins_dist_2') |
|
| 270 | + . '</p>' |
|
| 271 | + . $liste |
|
| 272 | + . fin_cadre_trait_couleur() |
|
| 273 | + . "</div>\n"; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -282,19 +282,19 @@ discard block |
||
| 282 | 282 | */ |
| 283 | 283 | function afficher_librairies() { |
| 284 | 284 | |
| 285 | - if (!$libs = liste_librairies()) { |
|
| 286 | - return ''; |
|
| 287 | - } |
|
| 288 | - ksort($libs); |
|
| 289 | - $res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees')); |
|
| 290 | - $res .= '<dl>'; |
|
| 291 | - foreach ($libs as $lib => $rep) { |
|
| 292 | - $res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n"; |
|
| 293 | - } |
|
| 294 | - $res .= '</dl>'; |
|
| 295 | - $res .= fin_cadre_enfonce(); |
|
| 296 | - |
|
| 297 | - return $res; |
|
| 285 | + if (!$libs = liste_librairies()) { |
|
| 286 | + return ''; |
|
| 287 | + } |
|
| 288 | + ksort($libs); |
|
| 289 | + $res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees')); |
|
| 290 | + $res .= '<dl>'; |
|
| 291 | + foreach ($libs as $lib => $rep) { |
|
| 292 | + $res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n"; |
|
| 293 | + } |
|
| 294 | + $res .= '</dl>'; |
|
| 295 | + $res .= fin_cadre_enfonce(); |
|
| 296 | + |
|
| 297 | + return $res; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
@@ -305,22 +305,22 @@ discard block |
||
| 305 | 305 | * Tableau (nom de la lib => repertoire , ...) |
| 306 | 306 | */ |
| 307 | 307 | function liste_librairies() { |
| 308 | - $libs = []; |
|
| 309 | - foreach (array_reverse(creer_chemin()) as $d) { |
|
| 310 | - if ( |
|
| 311 | - is_dir($dir = $d . 'lib/') |
|
| 312 | - and $t = opendir($dir) |
|
| 313 | - ) { |
|
| 314 | - while (($f = readdir($t)) !== false) { |
|
| 315 | - if ( |
|
| 316 | - $f[0] != '.' |
|
| 317 | - and is_dir("$dir/$f") |
|
| 318 | - ) { |
|
| 319 | - $libs[$f] = $dir; |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - return $libs; |
|
| 308 | + $libs = []; |
|
| 309 | + foreach (array_reverse(creer_chemin()) as $d) { |
|
| 310 | + if ( |
|
| 311 | + is_dir($dir = $d . 'lib/') |
|
| 312 | + and $t = opendir($dir) |
|
| 313 | + ) { |
|
| 314 | + while (($f = readdir($t)) !== false) { |
|
| 315 | + if ( |
|
| 316 | + $f[0] != '.' |
|
| 317 | + and is_dir("$dir/$f") |
|
| 318 | + ) { |
|
| 319 | + $libs[$f] = $dir; |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + return $libs; |
|
| 326 | 326 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | // message d'erreur au retour d'une operation |
| 122 | 122 | if ($erreur) { |
| 123 | - echo "<div class='error'>" . spip_htmlspecialchars($erreur) . '</div>'; |
|
| 123 | + echo "<div class='error'>".spip_htmlspecialchars($erreur).'</div>'; |
|
| 124 | 124 | } |
| 125 | 125 | if ($erreur_activation) { |
| 126 | 126 | echo "<div class='error'>$erreur_activation</div>"; |
@@ -147,11 +147,11 @@ discard block |
||
| 147 | 147 | if ($quoi !== 'actifs') { |
| 148 | 148 | $lpf = liste_plugin_files(); |
| 149 | 149 | if ($lpf) { |
| 150 | - echo '<p>' . _T('texte_presente_plugin') . '</p>'; |
|
| 150 | + echo '<p>'._T('texte_presente_plugin').'</p>'; |
|
| 151 | 151 | } else { |
| 152 | 152 | if (!@is_dir(_DIR_PLUGINS)) { |
| 153 | - echo '<p>' . _T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)]) |
|
| 154 | - . ' — ' . _T('plugin_info_automatique_creer') . '</p>'; |
|
| 153 | + echo '<p>'._T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)]) |
|
| 154 | + . ' — '._T('plugin_info_automatique_creer').'</p>'; |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | $lcpaffiche = $lpf; |
@@ -172,10 +172,10 @@ discard block |
||
| 172 | 172 | if (defined('_DIR_PLUGINS_SUPPL')) { |
| 173 | 173 | $nb += is_countable($lcpas) ? count($lcpas) : 0; |
| 174 | 174 | } |
| 175 | - echo '<h3>' . sinon( |
|
| 175 | + echo '<h3>'.sinon( |
|
| 176 | 176 | singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'), |
| 177 | 177 | _T('plugins_actif_aucun') |
| 178 | - ) . '</h3>'; |
|
| 178 | + ).'</h3>'; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | if (empty($format)) { |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | if ($corps) { |
| 194 | 194 | $corps .= "\n<div class='boutons' style='display:none;'>" |
| 195 | - . "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer') |
|
| 195 | + . "<input type='submit' class='submit save' value='"._T('bouton_enregistrer') |
|
| 196 | 196 | . "' />" |
| 197 | 197 | . '</div>'; |
| 198 | 198 | } |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | . debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist') |
| 267 | 267 | . '<p>' |
| 268 | 268 | . _T('plugin_info_plugins_dist_1', ['plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST)]) |
| 269 | - . '<br />' . _T('plugin_info_plugins_dist_2') |
|
| 269 | + . '<br />'._T('plugin_info_plugins_dist_2') |
|
| 270 | 270 | . '</p>' |
| 271 | 271 | . $liste |
| 272 | 272 | . fin_cadre_trait_couleur() |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | $res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees')); |
| 290 | 290 | $res .= '<dl>'; |
| 291 | 291 | foreach ($libs as $lib => $rep) { |
| 292 | - $res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n"; |
|
| 292 | + $res .= "<dt>$lib</dt><dd>".joli_repertoire($rep)."</dd>\n"; |
|
| 293 | 293 | } |
| 294 | 294 | $res .= '</dl>'; |
| 295 | 295 | $res .= fin_cadre_enfonce(); |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | $libs = []; |
| 309 | 309 | foreach (array_reverse(creer_chemin()) as $d) { |
| 310 | 310 | if ( |
| 311 | - is_dir($dir = $d . 'lib/') |
|
| 311 | + is_dir($dir = $d.'lib/') |
|
| 312 | 312 | and $t = opendir($dir) |
| 313 | 313 | ) { |
| 314 | 314 | while (($f = readdir($t)) !== false) { |
@@ -42,8 +42,7 @@ |
||
| 42 | 42 | if ((is_countable($logo) ? count($logo) : 0) < 6) { |
| 43 | 43 | spip_log('Supprimer ancien logo ' . json_encode($logo, JSON_THROW_ON_ERROR), 'logo'); |
| 44 | 44 | spip_unlink($logo[0]); |
| 45 | - } |
|
| 46 | - elseif ( |
|
| 45 | + } elseif ( |
|
| 47 | 46 | $doc = $logo[5] |
| 48 | 47 | and isset($doc['id_document']) |
| 49 | 48 | and $id_document = $doc['id_document'] |
@@ -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 | |
@@ -30,36 +30,36 @@ discard block |
||
| 30 | 30 | * `on` ou `off` |
| 31 | 31 | */ |
| 32 | 32 | function logo_supprimer($objet, $id_objet, $etat) { |
| 33 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 34 | - $objet = objet_type($objet); |
|
| 35 | - $primary = id_table_objet($objet); |
|
| 36 | - include_spip('inc/chercher_logo'); |
|
| 37 | - |
|
| 38 | - // existe-t-il deja un logo ? |
|
| 39 | - $logo = $chercher_logo($id_objet, $primary, $etat); |
|
| 40 | - if ($logo) { |
|
| 41 | - # TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base |
|
| 42 | - if ((is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 43 | - spip_log('Supprimer ancien logo ' . json_encode($logo, JSON_THROW_ON_ERROR), 'logo'); |
|
| 44 | - spip_unlink($logo[0]); |
|
| 45 | - } |
|
| 46 | - elseif ( |
|
| 47 | - $doc = $logo[5] |
|
| 48 | - and isset($doc['id_document']) |
|
| 49 | - and $id_document = $doc['id_document'] |
|
| 50 | - ) { |
|
| 51 | - include_spip('action/editer_liens'); |
|
| 52 | - // supprimer le lien dans la base |
|
| 53 | - objet_dissocier(['document' => $id_document], [$objet => $id_objet], ['role' => '*']); |
|
| 54 | - |
|
| 55 | - // verifier si il reste des liens avec d'autres objets et sinon supprimer |
|
| 56 | - $liens = objet_trouver_liens(['document' => $id_document], '*'); |
|
| 57 | - if (!count($liens)) { |
|
| 58 | - $supprimer_document = charger_fonction('supprimer_document', 'action'); |
|
| 59 | - $supprimer_document($doc['id_document']); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 33 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 34 | + $objet = objet_type($objet); |
|
| 35 | + $primary = id_table_objet($objet); |
|
| 36 | + include_spip('inc/chercher_logo'); |
|
| 37 | + |
|
| 38 | + // existe-t-il deja un logo ? |
|
| 39 | + $logo = $chercher_logo($id_objet, $primary, $etat); |
|
| 40 | + if ($logo) { |
|
| 41 | + # TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base |
|
| 42 | + if ((is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 43 | + spip_log('Supprimer ancien logo ' . json_encode($logo, JSON_THROW_ON_ERROR), 'logo'); |
|
| 44 | + spip_unlink($logo[0]); |
|
| 45 | + } |
|
| 46 | + elseif ( |
|
| 47 | + $doc = $logo[5] |
|
| 48 | + and isset($doc['id_document']) |
|
| 49 | + and $id_document = $doc['id_document'] |
|
| 50 | + ) { |
|
| 51 | + include_spip('action/editer_liens'); |
|
| 52 | + // supprimer le lien dans la base |
|
| 53 | + objet_dissocier(['document' => $id_document], [$objet => $id_objet], ['role' => '*']); |
|
| 54 | + |
|
| 55 | + // verifier si il reste des liens avec d'autres objets et sinon supprimer |
|
| 56 | + $liens = objet_trouver_liens(['document' => $id_document], '*'); |
|
| 57 | + if (!count($liens)) { |
|
| 58 | + $supprimer_document = charger_fonction('supprimer_document', 'action'); |
|
| 59 | + $supprimer_document($doc['id_document']); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -76,200 +76,200 @@ discard block |
||
| 76 | 76 | * Erreur, sinon '' |
| 77 | 77 | */ |
| 78 | 78 | function logo_modifier($objet, $id_objet, $etat, $source) { |
| 79 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 80 | - $objet = objet_type($objet); |
|
| 81 | - $primary = id_table_objet($objet); |
|
| 82 | - include_spip('inc/chercher_logo'); |
|
| 83 | - |
|
| 84 | - $mode = preg_replace(',\W,', '', $etat); |
|
| 85 | - if (!$mode) { |
|
| 86 | - spip_log("logo_modifier : etat $etat invalide", 'logo'); |
|
| 87 | - $erreur = 'etat invalide'; |
|
| 88 | - |
|
| 89 | - return $erreur; |
|
| 90 | - } |
|
| 91 | - // chercher dans la base |
|
| 92 | - $mode_document = 'logo' . $mode; |
|
| 93 | - |
|
| 94 | - include_spip('inc/documents'); |
|
| 95 | - $erreur = ''; |
|
| 96 | - |
|
| 97 | - if (!$source) { |
|
| 98 | - spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 99 | - $erreur = 'source inconnue'; |
|
| 100 | - |
|
| 101 | - return $erreur; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // fichier dans upload/ |
|
| 105 | - if (is_string($source)) { |
|
| 106 | - $tmp_name = false; |
|
| 107 | - if (file_exists($source)) { |
|
| 108 | - $tmp_name = $source; |
|
| 109 | - } elseif (file_exists($f = determine_upload() . $source)) { |
|
| 110 | - $tmp_name = $f; |
|
| 111 | - } |
|
| 112 | - if (!$tmp_name) { |
|
| 113 | - spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 114 | - $erreur = 'source inconnue'; |
|
| 115 | - |
|
| 116 | - return $erreur; |
|
| 117 | - } |
|
| 118 | - $source = [ |
|
| 119 | - 'tmp_name' => $tmp_name, |
|
| 120 | - 'name' => basename($tmp_name), |
|
| 121 | - ]; |
|
| 122 | - } elseif ($erreur = check_upload_error($source['error'], '', true)) { |
|
| 123 | - return $erreur; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // supprimer le logo eventueel existant |
|
| 127 | - // TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple) |
|
| 128 | - // mais de toute facon l'interface actuelle oblige a supprimer + reinserer |
|
| 129 | - if (empty($GLOBALS['logo_migrer_en_base'])) { |
|
| 130 | - logo_supprimer($objet, $id_objet, $etat); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - include_spip('inc/autoriser'); |
|
| 135 | - $source['mode'] = $mode_document; |
|
| 136 | - $ajouter_documents = charger_fonction('ajouter_documents', 'action'); |
|
| 137 | - autoriser_exception('associerdocuments', $objet, $id_objet); |
|
| 138 | - $ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document); |
|
| 139 | - autoriser_exception('associerdocuments', $objet, $id_objet, false); |
|
| 140 | - |
|
| 141 | - $id_document = reset($ajoutes); |
|
| 142 | - |
|
| 143 | - if (!is_numeric($id_document)) { |
|
| 144 | - $erreur = ($id_document ?: 'Erreur inconnue'); |
|
| 145 | - spip_log("Erreur ajout logo : $erreur pour source=" . json_encode($source, JSON_THROW_ON_ERROR), 'logo'); |
|
| 146 | - return $erreur; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return ''; // tout est bon, pas d'erreur |
|
| 79 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 80 | + $objet = objet_type($objet); |
|
| 81 | + $primary = id_table_objet($objet); |
|
| 82 | + include_spip('inc/chercher_logo'); |
|
| 83 | + |
|
| 84 | + $mode = preg_replace(',\W,', '', $etat); |
|
| 85 | + if (!$mode) { |
|
| 86 | + spip_log("logo_modifier : etat $etat invalide", 'logo'); |
|
| 87 | + $erreur = 'etat invalide'; |
|
| 88 | + |
|
| 89 | + return $erreur; |
|
| 90 | + } |
|
| 91 | + // chercher dans la base |
|
| 92 | + $mode_document = 'logo' . $mode; |
|
| 93 | + |
|
| 94 | + include_spip('inc/documents'); |
|
| 95 | + $erreur = ''; |
|
| 96 | + |
|
| 97 | + if (!$source) { |
|
| 98 | + spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 99 | + $erreur = 'source inconnue'; |
|
| 100 | + |
|
| 101 | + return $erreur; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // fichier dans upload/ |
|
| 105 | + if (is_string($source)) { |
|
| 106 | + $tmp_name = false; |
|
| 107 | + if (file_exists($source)) { |
|
| 108 | + $tmp_name = $source; |
|
| 109 | + } elseif (file_exists($f = determine_upload() . $source)) { |
|
| 110 | + $tmp_name = $f; |
|
| 111 | + } |
|
| 112 | + if (!$tmp_name) { |
|
| 113 | + spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 114 | + $erreur = 'source inconnue'; |
|
| 115 | + |
|
| 116 | + return $erreur; |
|
| 117 | + } |
|
| 118 | + $source = [ |
|
| 119 | + 'tmp_name' => $tmp_name, |
|
| 120 | + 'name' => basename($tmp_name), |
|
| 121 | + ]; |
|
| 122 | + } elseif ($erreur = check_upload_error($source['error'], '', true)) { |
|
| 123 | + return $erreur; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // supprimer le logo eventueel existant |
|
| 127 | + // TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple) |
|
| 128 | + // mais de toute facon l'interface actuelle oblige a supprimer + reinserer |
|
| 129 | + if (empty($GLOBALS['logo_migrer_en_base'])) { |
|
| 130 | + logo_supprimer($objet, $id_objet, $etat); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + include_spip('inc/autoriser'); |
|
| 135 | + $source['mode'] = $mode_document; |
|
| 136 | + $ajouter_documents = charger_fonction('ajouter_documents', 'action'); |
|
| 137 | + autoriser_exception('associerdocuments', $objet, $id_objet); |
|
| 138 | + $ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document); |
|
| 139 | + autoriser_exception('associerdocuments', $objet, $id_objet, false); |
|
| 140 | + |
|
| 141 | + $id_document = reset($ajoutes); |
|
| 142 | + |
|
| 143 | + if (!is_numeric($id_document)) { |
|
| 144 | + $erreur = ($id_document ?: 'Erreur inconnue'); |
|
| 145 | + spip_log("Erreur ajout logo : $erreur pour source=" . json_encode($source, JSON_THROW_ON_ERROR), 'logo'); |
|
| 146 | + return $erreur; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return ''; // tout est bon, pas d'erreur |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | function logo_migrer_en_base($objet, $time_limit) { |
| 153 | 153 | |
| 154 | - $dir_logos_erreurs = sous_repertoire(_DIR_IMG, 'logo_erreurs'); |
|
| 155 | - $dir_logos = sous_repertoire(_DIR_IMG, 'logo'); |
|
| 156 | - $formats_logos = ['jpg', 'png', 'svg', 'gif']; |
|
| 157 | - if (isset($GLOBALS['formats_logos'])) { |
|
| 158 | - $formats_logos = $GLOBALS['formats_logos']; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 163 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 164 | - include_spip('inc/chercher_logo'); |
|
| 165 | - $_id_objet = id_table_objet($objet); |
|
| 166 | - $table = table_objet_sql($objet); |
|
| 167 | - $type = type_du_logo($_id_objet); |
|
| 168 | - $desc = $trouver_table($table); |
|
| 169 | - |
|
| 170 | - // on desactive les revisions |
|
| 171 | - $liste_objets_versionnes = $GLOBALS['meta']['objets_versions'] ?? ''; |
|
| 172 | - unset($GLOBALS['meta']['objets_versions']); |
|
| 173 | - // et le signalement des editions |
|
| 174 | - $articles_modif = $GLOBALS['meta']['articles_modif'] ?? ''; |
|
| 175 | - $GLOBALS['meta']['articles_modif'] = 'non'; |
|
| 176 | - |
|
| 177 | - foreach (['on', 'off'] as $mode) { |
|
| 178 | - $nom_base = $type . $mode; |
|
| 179 | - $dir = (defined('_DIR_LOGOS') ? _DIR_LOGOS : _DIR_IMG); |
|
| 180 | - |
|
| 181 | - $files = glob($dir . $nom_base . '*'); |
|
| 182 | - // est-ce que c'est une nouvelle tentative de migration ? |
|
| 183 | - // dans ce cas les logos sont deja dans IMG/logo/ |
|
| 184 | - if (!(is_countable($files) ? count($files) : 0)) { |
|
| 185 | - $files = glob($dir_logos . $nom_base . '*'); |
|
| 186 | - if (is_countable($files) ? count($files) : 0) { |
|
| 187 | - // mais il faut verifier si ils ont pas deja ete migres pour tout ou partie |
|
| 188 | - $filescheck = []; |
|
| 189 | - foreach ($files as $file) { |
|
| 190 | - $short = basename(dirname($file)) . DIRECTORY_SEPARATOR . basename($file); |
|
| 191 | - $filescheck[$short] = $file; |
|
| 192 | - } |
|
| 193 | - // trouver ceux deja migres |
|
| 194 | - $deja = sql_allfetsel('fichier', 'spip_documents', sql_in('fichier', array_keys($filescheck)) . " AND mode LIKE 'logo%'"); |
|
| 195 | - if (is_countable($deja) ? count($deja) : 0) { |
|
| 196 | - $deja = array_column($deja, 'fichier'); |
|
| 197 | - $restant = array_diff(array_keys($filescheck), $deja); |
|
| 198 | - $files = []; |
|
| 199 | - if (count($restant)) { |
|
| 200 | - foreach ($restant as $r) { |
|
| 201 | - $files[] = $filescheck[$r]; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - // et si il en reste on peut y aller... |
|
| 206 | - // mais il faut modifier $dir qui sert de base dans la suite |
|
| 207 | - if (is_countable($files) ? count($files) : 0) { |
|
| 208 | - $dir = $dir_logos; |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $count = (is_countable($files) ? count($files) : 0); |
|
| 214 | - spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 215 | - |
|
| 216 | - $deja = []; |
|
| 217 | - foreach ($files as $file) { |
|
| 218 | - $logo = substr($file, strlen($dir . $nom_base)); |
|
| 219 | - $logo = explode('.', $logo); |
|
| 220 | - if ( |
|
| 221 | - is_numeric($logo[0]) |
|
| 222 | - and ($id_objet = intval($logo[0]) or in_array($objet, ['site', 'rubrique'])) |
|
| 223 | - ) { |
|
| 224 | - if (!isset($deja[$id_objet])) { |
|
| 225 | - $logo = $chercher_logo($id_objet, $_id_objet, $mode); |
|
| 226 | - // if no logo in base |
|
| 227 | - if (!$logo or (is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 228 | - foreach ($formats_logos as $format) { |
|
| 229 | - if (@file_exists($d = ($dir . ($nom = $nom_base . intval($id_objet) . '.' . $format)))) { |
|
| 230 | - if (isset($desc['field']['date_modif'])) { |
|
| 231 | - $date_modif = sql_getfetsel('date_modif', $table, "$_id_objet=$id_objet"); |
|
| 232 | - } else { |
|
| 233 | - $date_modif = null; |
|
| 234 | - } |
|
| 235 | - // s'assurer que le logo a les bon droits au passage (evite un echec en cas de sanitization d'un svg) |
|
| 236 | - @chmod($d, _SPIP_CHMOD & 0666); |
|
| 237 | - // logo_modifier commence par supprimer le logo existant, donc on le deplace pour pas le perdre |
|
| 238 | - @rename($d, $dir_logos . $nom); |
|
| 239 | - // et on le declare comme nouveau logo |
|
| 240 | - logo_modifier($objet, $id_objet, $mode, $dir_logos . $nom); |
|
| 241 | - if ($date_modif) { |
|
| 242 | - sql_updateq($table, ['date_modif' => $date_modif], "$_id_objet=$id_objet"); |
|
| 243 | - } |
|
| 244 | - break; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - $deja[$id_objet] = true; |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - // si le fichier est encore la on le move : rien a faire ici |
|
| 252 | - // (sauf si c'est une re-migration : il est deja dans logo/ donc il bouge pas) |
|
| 253 | - if ($dir !== $dir_logos and file_exists($file)) { |
|
| 254 | - @rename($file, $dir_logos_erreurs . basename($file)); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - $count--; |
|
| 258 | - if ($count % 250 === 0) { |
|
| 259 | - spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if ($time_limit and time() > $time_limit) { |
|
| 263 | - effacer_meta('drapeau_edition'); |
|
| 264 | - return; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - if ($liste_objets_versionnes) { |
|
| 270 | - $GLOBALS['meta']['objets_versions'] = $liste_objets_versionnes; |
|
| 271 | - } |
|
| 272 | - $GLOBALS['meta']['articles_modif'] = $articles_modif; |
|
| 273 | - |
|
| 274 | - effacer_meta('drapeau_edition'); |
|
| 154 | + $dir_logos_erreurs = sous_repertoire(_DIR_IMG, 'logo_erreurs'); |
|
| 155 | + $dir_logos = sous_repertoire(_DIR_IMG, 'logo'); |
|
| 156 | + $formats_logos = ['jpg', 'png', 'svg', 'gif']; |
|
| 157 | + if (isset($GLOBALS['formats_logos'])) { |
|
| 158 | + $formats_logos = $GLOBALS['formats_logos']; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 163 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 164 | + include_spip('inc/chercher_logo'); |
|
| 165 | + $_id_objet = id_table_objet($objet); |
|
| 166 | + $table = table_objet_sql($objet); |
|
| 167 | + $type = type_du_logo($_id_objet); |
|
| 168 | + $desc = $trouver_table($table); |
|
| 169 | + |
|
| 170 | + // on desactive les revisions |
|
| 171 | + $liste_objets_versionnes = $GLOBALS['meta']['objets_versions'] ?? ''; |
|
| 172 | + unset($GLOBALS['meta']['objets_versions']); |
|
| 173 | + // et le signalement des editions |
|
| 174 | + $articles_modif = $GLOBALS['meta']['articles_modif'] ?? ''; |
|
| 175 | + $GLOBALS['meta']['articles_modif'] = 'non'; |
|
| 176 | + |
|
| 177 | + foreach (['on', 'off'] as $mode) { |
|
| 178 | + $nom_base = $type . $mode; |
|
| 179 | + $dir = (defined('_DIR_LOGOS') ? _DIR_LOGOS : _DIR_IMG); |
|
| 180 | + |
|
| 181 | + $files = glob($dir . $nom_base . '*'); |
|
| 182 | + // est-ce que c'est une nouvelle tentative de migration ? |
|
| 183 | + // dans ce cas les logos sont deja dans IMG/logo/ |
|
| 184 | + if (!(is_countable($files) ? count($files) : 0)) { |
|
| 185 | + $files = glob($dir_logos . $nom_base . '*'); |
|
| 186 | + if (is_countable($files) ? count($files) : 0) { |
|
| 187 | + // mais il faut verifier si ils ont pas deja ete migres pour tout ou partie |
|
| 188 | + $filescheck = []; |
|
| 189 | + foreach ($files as $file) { |
|
| 190 | + $short = basename(dirname($file)) . DIRECTORY_SEPARATOR . basename($file); |
|
| 191 | + $filescheck[$short] = $file; |
|
| 192 | + } |
|
| 193 | + // trouver ceux deja migres |
|
| 194 | + $deja = sql_allfetsel('fichier', 'spip_documents', sql_in('fichier', array_keys($filescheck)) . " AND mode LIKE 'logo%'"); |
|
| 195 | + if (is_countable($deja) ? count($deja) : 0) { |
|
| 196 | + $deja = array_column($deja, 'fichier'); |
|
| 197 | + $restant = array_diff(array_keys($filescheck), $deja); |
|
| 198 | + $files = []; |
|
| 199 | + if (count($restant)) { |
|
| 200 | + foreach ($restant as $r) { |
|
| 201 | + $files[] = $filescheck[$r]; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + // et si il en reste on peut y aller... |
|
| 206 | + // mais il faut modifier $dir qui sert de base dans la suite |
|
| 207 | + if (is_countable($files) ? count($files) : 0) { |
|
| 208 | + $dir = $dir_logos; |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $count = (is_countable($files) ? count($files) : 0); |
|
| 214 | + spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 215 | + |
|
| 216 | + $deja = []; |
|
| 217 | + foreach ($files as $file) { |
|
| 218 | + $logo = substr($file, strlen($dir . $nom_base)); |
|
| 219 | + $logo = explode('.', $logo); |
|
| 220 | + if ( |
|
| 221 | + is_numeric($logo[0]) |
|
| 222 | + and ($id_objet = intval($logo[0]) or in_array($objet, ['site', 'rubrique'])) |
|
| 223 | + ) { |
|
| 224 | + if (!isset($deja[$id_objet])) { |
|
| 225 | + $logo = $chercher_logo($id_objet, $_id_objet, $mode); |
|
| 226 | + // if no logo in base |
|
| 227 | + if (!$logo or (is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 228 | + foreach ($formats_logos as $format) { |
|
| 229 | + if (@file_exists($d = ($dir . ($nom = $nom_base . intval($id_objet) . '.' . $format)))) { |
|
| 230 | + if (isset($desc['field']['date_modif'])) { |
|
| 231 | + $date_modif = sql_getfetsel('date_modif', $table, "$_id_objet=$id_objet"); |
|
| 232 | + } else { |
|
| 233 | + $date_modif = null; |
|
| 234 | + } |
|
| 235 | + // s'assurer que le logo a les bon droits au passage (evite un echec en cas de sanitization d'un svg) |
|
| 236 | + @chmod($d, _SPIP_CHMOD & 0666); |
|
| 237 | + // logo_modifier commence par supprimer le logo existant, donc on le deplace pour pas le perdre |
|
| 238 | + @rename($d, $dir_logos . $nom); |
|
| 239 | + // et on le declare comme nouveau logo |
|
| 240 | + logo_modifier($objet, $id_objet, $mode, $dir_logos . $nom); |
|
| 241 | + if ($date_modif) { |
|
| 242 | + sql_updateq($table, ['date_modif' => $date_modif], "$_id_objet=$id_objet"); |
|
| 243 | + } |
|
| 244 | + break; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + $deja[$id_objet] = true; |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + // si le fichier est encore la on le move : rien a faire ici |
|
| 252 | + // (sauf si c'est une re-migration : il est deja dans logo/ donc il bouge pas) |
|
| 253 | + if ($dir !== $dir_logos and file_exists($file)) { |
|
| 254 | + @rename($file, $dir_logos_erreurs . basename($file)); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + $count--; |
|
| 258 | + if ($count % 250 === 0) { |
|
| 259 | + spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if ($time_limit and time() > $time_limit) { |
|
| 263 | + effacer_meta('drapeau_edition'); |
|
| 264 | + return; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + if ($liste_objets_versionnes) { |
|
| 270 | + $GLOBALS['meta']['objets_versions'] = $liste_objets_versionnes; |
|
| 271 | + } |
|
| 272 | + $GLOBALS['meta']['articles_modif'] = $articles_modif; |
|
| 273 | + |
|
| 274 | + effacer_meta('drapeau_edition'); |
|
| 275 | 275 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | if ($logo) { |
| 41 | 41 | # TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base |
| 42 | 42 | if ((is_countable($logo) ? count($logo) : 0) < 6) { |
| 43 | - spip_log('Supprimer ancien logo ' . json_encode($logo, JSON_THROW_ON_ERROR), 'logo'); |
|
| 43 | + spip_log('Supprimer ancien logo '.json_encode($logo, JSON_THROW_ON_ERROR), 'logo'); |
|
| 44 | 44 | spip_unlink($logo[0]); |
| 45 | 45 | } |
| 46 | 46 | elseif ( |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | return $erreur; |
| 90 | 90 | } |
| 91 | 91 | // chercher dans la base |
| 92 | - $mode_document = 'logo' . $mode; |
|
| 92 | + $mode_document = 'logo'.$mode; |
|
| 93 | 93 | |
| 94 | 94 | include_spip('inc/documents'); |
| 95 | 95 | $erreur = ''; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $tmp_name = false; |
| 107 | 107 | if (file_exists($source)) { |
| 108 | 108 | $tmp_name = $source; |
| 109 | - } elseif (file_exists($f = determine_upload() . $source)) { |
|
| 109 | + } elseif (file_exists($f = determine_upload().$source)) { |
|
| 110 | 110 | $tmp_name = $f; |
| 111 | 111 | } |
| 112 | 112 | if (!$tmp_name) { |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | if (!is_numeric($id_document)) { |
| 144 | 144 | $erreur = ($id_document ?: 'Erreur inconnue'); |
| 145 | - spip_log("Erreur ajout logo : $erreur pour source=" . json_encode($source, JSON_THROW_ON_ERROR), 'logo'); |
|
| 145 | + spip_log("Erreur ajout logo : $erreur pour source=".json_encode($source, JSON_THROW_ON_ERROR), 'logo'); |
|
| 146 | 146 | return $erreur; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -175,23 +175,23 @@ discard block |
||
| 175 | 175 | $GLOBALS['meta']['articles_modif'] = 'non'; |
| 176 | 176 | |
| 177 | 177 | foreach (['on', 'off'] as $mode) { |
| 178 | - $nom_base = $type . $mode; |
|
| 178 | + $nom_base = $type.$mode; |
|
| 179 | 179 | $dir = (defined('_DIR_LOGOS') ? _DIR_LOGOS : _DIR_IMG); |
| 180 | 180 | |
| 181 | - $files = glob($dir . $nom_base . '*'); |
|
| 181 | + $files = glob($dir.$nom_base.'*'); |
|
| 182 | 182 | // est-ce que c'est une nouvelle tentative de migration ? |
| 183 | 183 | // dans ce cas les logos sont deja dans IMG/logo/ |
| 184 | 184 | if (!(is_countable($files) ? count($files) : 0)) { |
| 185 | - $files = glob($dir_logos . $nom_base . '*'); |
|
| 185 | + $files = glob($dir_logos.$nom_base.'*'); |
|
| 186 | 186 | if (is_countable($files) ? count($files) : 0) { |
| 187 | 187 | // mais il faut verifier si ils ont pas deja ete migres pour tout ou partie |
| 188 | 188 | $filescheck = []; |
| 189 | 189 | foreach ($files as $file) { |
| 190 | - $short = basename(dirname($file)) . DIRECTORY_SEPARATOR . basename($file); |
|
| 190 | + $short = basename(dirname($file)).DIRECTORY_SEPARATOR.basename($file); |
|
| 191 | 191 | $filescheck[$short] = $file; |
| 192 | 192 | } |
| 193 | 193 | // trouver ceux deja migres |
| 194 | - $deja = sql_allfetsel('fichier', 'spip_documents', sql_in('fichier', array_keys($filescheck)) . " AND mode LIKE 'logo%'"); |
|
| 194 | + $deja = sql_allfetsel('fichier', 'spip_documents', sql_in('fichier', array_keys($filescheck))." AND mode LIKE 'logo%'"); |
|
| 195 | 195 | if (is_countable($deja) ? count($deja) : 0) { |
| 196 | 196 | $deja = array_column($deja, 'fichier'); |
| 197 | 197 | $restant = array_diff(array_keys($filescheck), $deja); |
@@ -211,11 +211,11 @@ discard block |
||
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | $count = (is_countable($files) ? count($files) : 0); |
| 214 | - spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 214 | + spip_log("logo_migrer_en_base $objet $mode : ".$count.' logos restant', 'maj'._LOG_INFO_IMPORTANTE); |
|
| 215 | 215 | |
| 216 | 216 | $deja = []; |
| 217 | 217 | foreach ($files as $file) { |
| 218 | - $logo = substr($file, strlen($dir . $nom_base)); |
|
| 218 | + $logo = substr($file, strlen($dir.$nom_base)); |
|
| 219 | 219 | $logo = explode('.', $logo); |
| 220 | 220 | if ( |
| 221 | 221 | is_numeric($logo[0]) |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | // if no logo in base |
| 227 | 227 | if (!$logo or (is_countable($logo) ? count($logo) : 0) < 6) { |
| 228 | 228 | foreach ($formats_logos as $format) { |
| 229 | - if (@file_exists($d = ($dir . ($nom = $nom_base . intval($id_objet) . '.' . $format)))) { |
|
| 229 | + if (@file_exists($d = ($dir.($nom = $nom_base.intval($id_objet).'.'.$format)))) { |
|
| 230 | 230 | if (isset($desc['field']['date_modif'])) { |
| 231 | 231 | $date_modif = sql_getfetsel('date_modif', $table, "$_id_objet=$id_objet"); |
| 232 | 232 | } else { |
@@ -235,9 +235,9 @@ discard block |
||
| 235 | 235 | // s'assurer que le logo a les bon droits au passage (evite un echec en cas de sanitization d'un svg) |
| 236 | 236 | @chmod($d, _SPIP_CHMOD & 0666); |
| 237 | 237 | // logo_modifier commence par supprimer le logo existant, donc on le deplace pour pas le perdre |
| 238 | - @rename($d, $dir_logos . $nom); |
|
| 238 | + @rename($d, $dir_logos.$nom); |
|
| 239 | 239 | // et on le declare comme nouveau logo |
| 240 | - logo_modifier($objet, $id_objet, $mode, $dir_logos . $nom); |
|
| 240 | + logo_modifier($objet, $id_objet, $mode, $dir_logos.$nom); |
|
| 241 | 241 | if ($date_modif) { |
| 242 | 242 | sql_updateq($table, ['date_modif' => $date_modif], "$_id_objet=$id_objet"); |
| 243 | 243 | } |
@@ -251,12 +251,12 @@ discard block |
||
| 251 | 251 | // si le fichier est encore la on le move : rien a faire ici |
| 252 | 252 | // (sauf si c'est une re-migration : il est deja dans logo/ donc il bouge pas) |
| 253 | 253 | if ($dir !== $dir_logos and file_exists($file)) { |
| 254 | - @rename($file, $dir_logos_erreurs . basename($file)); |
|
| 254 | + @rename($file, $dir_logos_erreurs.basename($file)); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | $count--; |
| 258 | 258 | if ($count % 250 === 0) { |
| 259 | - spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 259 | + spip_log("logo_migrer_en_base $objet $mode : ".$count.' logos restant', 'maj'._LOG_INFO_IMPORTANTE); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | if ($time_limit and time() > $time_limit) { |
@@ -45,10 +45,10 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | if ($query) { |
| 48 | - $url .= '?' . $query; |
|
| 48 | + $url .= '?'.$query; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - return '/' . preg_replace(',^/,S', '', $url); |
|
| 51 | + return '/'.preg_replace(',^/,S', '', $url); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
| 79 | 79 | $r = array_pad($r, 3, ''); |
| 80 | 80 | |
| 81 | - return $r[1] . resolve_path($r[2]); |
|
| 81 | + return $r[1].resolve_path($r[2]); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | # L'url site spip est un lien absolu aussi |
@@ -99,13 +99,13 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | switch (substr($lien, 0, 1)) { |
| 101 | 101 | case '/': |
| 102 | - return $debut . resolve_path($lien); |
|
| 102 | + return $debut.resolve_path($lien); |
|
| 103 | 103 | case '#': |
| 104 | - return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 104 | + return $debut.resolve_path($dir.$mot.$get.$lien); |
|
| 105 | 105 | case '': |
| 106 | - return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 106 | + return $debut.resolve_path($dir.$mot.$get.$hash); |
|
| 107 | 107 | default: |
| 108 | - return $debut . resolve_path($dir . $lien); |
|
| 108 | + return $debut.resolve_path($dir.$lien); |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | return ''; |
| 134 | 134 | } |
| 135 | 135 | if (!$base) { |
| 136 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 136 | + $base = url_de_base().(_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | return suivre_lien($base, $url); |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * @param array $protocoles_autorises |
| 157 | 157 | * @return bool |
| 158 | 158 | */ |
| 159 | -function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
|
| 159 | +function protocole_verifier($url_absolue, $protocoles_autorises = ['http', 'https']) { |
|
| 160 | 160 | |
| 161 | 161 | if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
| 162 | 162 | $protocole = $m[1]; |
@@ -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 | |
@@ -35,20 +35,20 @@ discard block |
||
| 35 | 35 | * @return string URL nettoyée |
| 36 | 36 | **/ |
| 37 | 37 | function resolve_path($url) { |
| 38 | - [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | - while ( |
|
| 40 | - preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | - or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | - or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | - ) { |
|
| 44 | - $url = str_replace($regs[0], '/', $url); |
|
| 45 | - } |
|
| 38 | + [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | + while ( |
|
| 40 | + preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | + or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | + or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | + ) { |
|
| 44 | + $url = str_replace($regs[0], '/', $url); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - if ($query) { |
|
| 48 | - $url .= '?' . $query; |
|
| 49 | - } |
|
| 47 | + if ($query) { |
|
| 48 | + $url .= '?' . $query; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - return '/' . preg_replace(',^/,S', '', $url); |
|
| 51 | + return '/' . preg_replace(',^/,S', '', $url); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -69,44 +69,44 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function suivre_lien($url, $lien) { |
| 71 | 71 | |
| 72 | - $mot = null; |
|
| 73 | - $get = null; |
|
| 74 | - $hash = null; |
|
| 75 | - if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 76 | - return $lien; |
|
| 77 | - } |
|
| 78 | - if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 79 | - $r = array_pad($r, 3, ''); |
|
| 72 | + $mot = null; |
|
| 73 | + $get = null; |
|
| 74 | + $hash = null; |
|
| 75 | + if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 76 | + return $lien; |
|
| 77 | + } |
|
| 78 | + if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 79 | + $r = array_pad($r, 3, ''); |
|
| 80 | 80 | |
| 81 | - return $r[1] . resolve_path($r[2]); |
|
| 82 | - } |
|
| 81 | + return $r[1] . resolve_path($r[2]); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - # L'url site spip est un lien absolu aussi |
|
| 85 | - if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 86 | - return $lien; |
|
| 87 | - } |
|
| 84 | + # L'url site spip est un lien absolu aussi |
|
| 85 | + if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 86 | + return $lien; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - # lien relatif, il faut verifier l'url de base |
|
| 90 | - # commencer par virer la chaine de get de l'url de base |
|
| 91 | - $dir = '/'; |
|
| 92 | - $debut = ''; |
|
| 93 | - if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 94 | - $debut = $regs[1]; |
|
| 95 | - $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 96 | - $mot = $regs[3]; |
|
| 97 | - $get = $regs[4] ?? ''; |
|
| 98 | - $hash = $regs[5] ?? ''; |
|
| 99 | - } |
|
| 100 | - switch (substr($lien, 0, 1)) { |
|
| 101 | - case '/': |
|
| 102 | - return $debut . resolve_path($lien); |
|
| 103 | - case '#': |
|
| 104 | - return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 105 | - case '': |
|
| 106 | - return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 107 | - default: |
|
| 108 | - return $debut . resolve_path($dir . $lien); |
|
| 109 | - } |
|
| 89 | + # lien relatif, il faut verifier l'url de base |
|
| 90 | + # commencer par virer la chaine de get de l'url de base |
|
| 91 | + $dir = '/'; |
|
| 92 | + $debut = ''; |
|
| 93 | + if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 94 | + $debut = $regs[1]; |
|
| 95 | + $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 96 | + $mot = $regs[3]; |
|
| 97 | + $get = $regs[4] ?? ''; |
|
| 98 | + $hash = $regs[5] ?? ''; |
|
| 99 | + } |
|
| 100 | + switch (substr($lien, 0, 1)) { |
|
| 101 | + case '/': |
|
| 102 | + return $debut . resolve_path($lien); |
|
| 103 | + case '#': |
|
| 104 | + return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 105 | + case '': |
|
| 106 | + return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 107 | + default: |
|
| 108 | + return $debut . resolve_path($dir . $lien); |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -129,15 +129,15 @@ discard block |
||
| 129 | 129 | * @return string texte ou URL (en absolus) |
| 130 | 130 | **/ |
| 131 | 131 | function url_absolue($url, $base = '') { |
| 132 | - $url = trim((string) $url); |
|
| 133 | - if (strlen($url = trim($url)) == 0) { |
|
| 134 | - return ''; |
|
| 135 | - } |
|
| 136 | - if (!$base) { |
|
| 137 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 138 | - } |
|
| 132 | + $url = trim((string) $url); |
|
| 133 | + if (strlen($url = trim($url)) == 0) { |
|
| 134 | + return ''; |
|
| 135 | + } |
|
| 136 | + if (!$base) { |
|
| 137 | + $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - return suivre_lien($base, $url); |
|
| 140 | + return suivre_lien($base, $url); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * @return string |
| 149 | 149 | */ |
| 150 | 150 | function protocole_implicite($url_absolue) { |
| 151 | - return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 151 | + return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -159,16 +159,16 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
| 161 | 161 | |
| 162 | - if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 163 | - $protocole = $m[1]; |
|
| 164 | - if ( |
|
| 165 | - in_array($protocole, $protocoles_autorises) |
|
| 166 | - or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 167 | - ) { |
|
| 168 | - return true; |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - return false; |
|
| 162 | + if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 163 | + $protocole = $m[1]; |
|
| 164 | + if ( |
|
| 165 | + in_array($protocole, $protocoles_autorises) |
|
| 166 | + or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 167 | + ) { |
|
| 168 | + return true; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + return false; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -185,27 +185,27 @@ discard block |
||
| 185 | 185 | * @return string texte avec des URLs absolues |
| 186 | 186 | **/ |
| 187 | 187 | function liens_absolus($texte, $base = '') { |
| 188 | - if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 189 | - if (!function_exists('extraire_attribut')) { |
|
| 190 | - include_spip('inc/filtres'); |
|
| 191 | - } |
|
| 192 | - foreach ($liens as $lien) { |
|
| 193 | - foreach (['href', 'src'] as $attr) { |
|
| 194 | - $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 195 | - if (strlen($href) > 0) { |
|
| 196 | - if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 197 | - $abs = url_absolue($href, $base); |
|
| 198 | - if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 199 | - $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | - $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 188 | + if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 189 | + if (!function_exists('extraire_attribut')) { |
|
| 190 | + include_spip('inc/filtres'); |
|
| 191 | + } |
|
| 192 | + foreach ($liens as $lien) { |
|
| 193 | + foreach (['href', 'src'] as $attr) { |
|
| 194 | + $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 195 | + if (strlen($href) > 0) { |
|
| 196 | + if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 197 | + $abs = url_absolue($href, $base); |
|
| 198 | + if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 199 | + $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | + $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - return $texte; |
|
| 208 | + return $texte; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | * @return string texte ou URL (en absolus) |
| 222 | 222 | **/ |
| 223 | 223 | function abs_url($texte, $base = '') { |
| 224 | - if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 225 | - return url_absolue($texte, $base); |
|
| 226 | - } else { |
|
| 227 | - return liens_absolus($texte, $base); |
|
| 228 | - } |
|
| 224 | + if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 225 | + return url_absolue($texte, $base); |
|
| 226 | + } else { |
|
| 227 | + return liens_absolus($texte, $base); |
|
| 228 | + } |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | 240 | function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 241 | - if (is_null($flags)) { |
|
| 242 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 243 | - } |
|
| 241 | + if (is_null($flags)) { |
|
| 242 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 245 | + return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | 257 | function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 258 | - if (is_null($flags)) { |
|
| 259 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 260 | - } |
|
| 258 | + if (is_null($flags)) { |
|
| 259 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 262 | + return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 263 | 263 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @package SPIP\Core\Drapeaux\Edition |
| 31 | 31 | **/ |
| 32 | 32 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 33 | - return; |
|
| 33 | + return; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | |
@@ -45,46 +45,46 @@ discard block |
||
| 45 | 45 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 46 | 46 | **/ |
| 47 | 47 | function lire_tableau_edition() { |
| 48 | - $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 49 | - if (!$edition) { |
|
| 50 | - return []; |
|
| 51 | - } |
|
| 52 | - $changed = false; |
|
| 48 | + $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 49 | + if (!$edition) { |
|
| 50 | + return []; |
|
| 51 | + } |
|
| 52 | + $changed = false; |
|
| 53 | 53 | |
| 54 | - $bon_pour_le_service = time() - 3600; |
|
| 55 | - // parcourir le tableau et virer les vieux |
|
| 56 | - foreach ($edition as $objet => $data) { |
|
| 57 | - if (!is_array($data)) { |
|
| 58 | - unset($edition[$objet]); |
|
| 59 | - } // vieille version |
|
| 60 | - else { |
|
| 61 | - foreach ($data as $id => $tab) { |
|
| 62 | - if (!is_array($tab)) { |
|
| 63 | - unset($edition[$objet][$tab]); |
|
| 64 | - } // vieille version |
|
| 65 | - else { |
|
| 66 | - foreach ($tab as $n => $duo) { |
|
| 67 | - if (current($duo) < $bon_pour_le_service) { |
|
| 68 | - unset($edition[$objet][$id][$n]); |
|
| 69 | - $changed = true; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - if (!$edition[$objet][$id]) { |
|
| 74 | - unset($edition[$objet][$id]); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - if (!$edition[$objet]) { |
|
| 79 | - unset($edition[$objet]); |
|
| 80 | - } |
|
| 81 | - } |
|
| 54 | + $bon_pour_le_service = time() - 3600; |
|
| 55 | + // parcourir le tableau et virer les vieux |
|
| 56 | + foreach ($edition as $objet => $data) { |
|
| 57 | + if (!is_array($data)) { |
|
| 58 | + unset($edition[$objet]); |
|
| 59 | + } // vieille version |
|
| 60 | + else { |
|
| 61 | + foreach ($data as $id => $tab) { |
|
| 62 | + if (!is_array($tab)) { |
|
| 63 | + unset($edition[$objet][$tab]); |
|
| 64 | + } // vieille version |
|
| 65 | + else { |
|
| 66 | + foreach ($tab as $n => $duo) { |
|
| 67 | + if (current($duo) < $bon_pour_le_service) { |
|
| 68 | + unset($edition[$objet][$id][$n]); |
|
| 69 | + $changed = true; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + if (!$edition[$objet][$id]) { |
|
| 74 | + unset($edition[$objet][$id]); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + if (!$edition[$objet]) { |
|
| 79 | + unset($edition[$objet]); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - if ($changed) { |
|
| 84 | - ecrire_tableau_edition($edition); |
|
| 85 | - } |
|
| 83 | + if ($changed) { |
|
| 84 | + ecrire_tableau_edition($edition); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - return $edition; |
|
| 87 | + return $edition; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 98 | 98 | **/ |
| 99 | 99 | function ecrire_tableau_edition($edition) { |
| 100 | - ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 100 | + ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -117,22 +117,22 @@ discard block |
||
| 117 | 117 | * Type d'objet édité |
| 118 | 118 | */ |
| 119 | 119 | function signale_edition($id, $auteur, $type = 'article') { |
| 120 | - include_spip('base/objets'); |
|
| 121 | - include_spip('inc/filtres'); |
|
| 122 | - if (objet_info($type, 'editable') !== 'oui') { |
|
| 123 | - return; |
|
| 124 | - } |
|
| 120 | + include_spip('base/objets'); |
|
| 121 | + include_spip('inc/filtres'); |
|
| 122 | + if (objet_info($type, 'editable') !== 'oui') { |
|
| 123 | + return; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - $edition = lire_tableau_edition(); |
|
| 126 | + $edition = lire_tableau_edition(); |
|
| 127 | 127 | |
| 128 | - $nom = $auteur['nom'] ?? $GLOBALS['ip']; |
|
| 129 | - $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip']; |
|
| 128 | + $nom = $auteur['nom'] ?? $GLOBALS['ip']; |
|
| 129 | + $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip']; |
|
| 130 | 130 | |
| 131 | - if (!isset($edition[$type][$id]) or !is_array($edition[$type][$id])) { |
|
| 132 | - $edition[$type][$id] = []; |
|
| 133 | - } |
|
| 134 | - $edition[$type][$id][$id_a][$nom] = time(); |
|
| 135 | - ecrire_tableau_edition($edition); |
|
| 131 | + if (!isset($edition[$type][$id]) or !is_array($edition[$type][$id])) { |
|
| 132 | + $edition[$type][$id] = []; |
|
| 133 | + } |
|
| 134 | + $edition[$type][$id][$id_a][$nom] = time(); |
|
| 135 | + ecrire_tableau_edition($edition); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | function qui_edite($id, $type = 'article') { |
| 151 | 151 | |
| 152 | - $edition = lire_tableau_edition(); |
|
| 152 | + $edition = lire_tableau_edition(); |
|
| 153 | 153 | |
| 154 | - return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 154 | + return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -165,23 +165,23 @@ discard block |
||
| 165 | 165 | * Liste de tableaux `['nom_auteur_modif' => x|y|z, 'date_diff' => n]` |
| 166 | 166 | */ |
| 167 | 167 | function mention_qui_edite($id, $type = 'article'): array { |
| 168 | - $modif = qui_edite($id, $type); |
|
| 169 | - unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 168 | + $modif = qui_edite($id, $type); |
|
| 169 | + unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 170 | 170 | |
| 171 | - if ($modif) { |
|
| 172 | - $quand = 0; |
|
| 173 | - foreach ($modif as $duo) { |
|
| 174 | - $auteurs[] = typo(key($duo)); |
|
| 175 | - $quand = max($quand, current($duo)); |
|
| 176 | - } |
|
| 171 | + if ($modif) { |
|
| 172 | + $quand = 0; |
|
| 173 | + foreach ($modif as $duo) { |
|
| 174 | + $auteurs[] = typo(key($duo)); |
|
| 175 | + $quand = max($quand, current($duo)); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - // format lie a la chaine de langue 'avis_article_modifie' |
|
| 179 | - return [ |
|
| 180 | - 'nom_auteur_modif' => join(' | ', $auteurs), |
|
| 181 | - 'date_diff' => ceil((time() - $quand) / 60) |
|
| 182 | - ]; |
|
| 183 | - } |
|
| 184 | - return []; |
|
| 178 | + // format lie a la chaine de langue 'avis_article_modifie' |
|
| 179 | + return [ |
|
| 180 | + 'nom_auteur_modif' => join(' | ', $auteurs), |
|
| 181 | + 'date_diff' => ceil((time() - $quand) / 60) |
|
| 182 | + ]; |
|
| 183 | + } |
|
| 184 | + return []; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -195,25 +195,25 @@ discard block |
||
| 195 | 195 | * Liste de tableaux `['objet' => x, 'id_objet' => n]` |
| 196 | 196 | */ |
| 197 | 197 | function liste_drapeau_edition($id_auteur) { |
| 198 | - $edition = lire_tableau_edition(); |
|
| 199 | - $objets_ouverts = []; |
|
| 198 | + $edition = lire_tableau_edition(); |
|
| 199 | + $objets_ouverts = []; |
|
| 200 | 200 | |
| 201 | - foreach ($edition as $objet => $data) { |
|
| 202 | - foreach ($data as $id => $auteurs) { |
|
| 203 | - if ( |
|
| 204 | - isset($auteurs[$id_auteur]) |
|
| 205 | - and is_array($auteurs[$id_auteur]) // precaution |
|
| 206 | - and (array_pop($auteurs[$id_auteur]) > time() - 3600) |
|
| 207 | - ) { |
|
| 208 | - $objets_ouverts[] = [ |
|
| 209 | - 'objet' => $objet, |
|
| 210 | - 'id_objet' => $id, |
|
| 211 | - ]; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - } |
|
| 201 | + foreach ($edition as $objet => $data) { |
|
| 202 | + foreach ($data as $id => $auteurs) { |
|
| 203 | + if ( |
|
| 204 | + isset($auteurs[$id_auteur]) |
|
| 205 | + and is_array($auteurs[$id_auteur]) // precaution |
|
| 206 | + and (array_pop($auteurs[$id_auteur]) > time() - 3600) |
|
| 207 | + ) { |
|
| 208 | + $objets_ouverts[] = [ |
|
| 209 | + 'objet' => $objet, |
|
| 210 | + 'id_objet' => $id, |
|
| 211 | + ]; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - return $objets_ouverts; |
|
| 216 | + return $objets_ouverts; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -226,15 +226,15 @@ discard block |
||
| 226 | 226 | * @return void |
| 227 | 227 | */ |
| 228 | 228 | function debloquer_tous($id_auteur) { |
| 229 | - $edition = lire_tableau_edition(); |
|
| 230 | - foreach ($edition as $objet => $data) { |
|
| 231 | - foreach ($data as $id => $auteurs) { |
|
| 232 | - if (isset($auteurs[$id_auteur])) { |
|
| 233 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 234 | - ecrire_tableau_edition($edition); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 229 | + $edition = lire_tableau_edition(); |
|
| 230 | + foreach ($edition as $objet => $data) { |
|
| 231 | + foreach ($data as $id => $auteurs) { |
|
| 232 | + if (isset($auteurs[$id_auteur])) { |
|
| 233 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 234 | + ecrire_tableau_edition($edition); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -252,19 +252,19 @@ discard block |
||
| 252 | 252 | * @return void |
| 253 | 253 | */ |
| 254 | 254 | function debloquer_edition($id_auteur, $id_objet, $type = 'article') { |
| 255 | - $edition = lire_tableau_edition(); |
|
| 255 | + $edition = lire_tableau_edition(); |
|
| 256 | 256 | |
| 257 | - foreach ($edition as $objet => $data) { |
|
| 258 | - if ($objet == $type) { |
|
| 259 | - foreach ($data as $id => $auteurs) { |
|
| 260 | - if ( |
|
| 261 | - $id == $id_objet |
|
| 262 | - and isset($auteurs[$id_auteur]) |
|
| 263 | - ) { |
|
| 264 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 265 | - ecrire_tableau_edition($edition); |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 257 | + foreach ($edition as $objet => $data) { |
|
| 258 | + if ($objet == $type) { |
|
| 259 | + foreach ($data as $id => $auteurs) { |
|
| 260 | + if ( |
|
| 261 | + $id == $id_objet |
|
| 262 | + and isset($auteurs[$id_auteur]) |
|
| 263 | + ) { |
|
| 264 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 265 | + ecrire_tableau_edition($edition); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | // Appels incomplets (sans $c) |
| 115 | 115 | if (!is_array($c)) { |
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 116 | + spip_log('erreur appel objet_modifier_champs('.$objet.'), manque $c'); |
|
| 117 | 117 | |
| 118 | 118 | return _T('erreur_technique_enregistrement_impossible'); |
| 119 | 119 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | // N'accepter que les champs qui existent dans la table |
| 141 | 141 | $champs = array_intersect_key($c, $desc['field']); |
| 142 | 142 | // et dont la valeur n'est pas null |
| 143 | - $champs = array_filter($champs, static function ($var) { |
|
| 143 | + $champs = array_filter($champs, static function($var) { |
|
| 144 | 144 | return $var !== null; |
| 145 | 145 | }); |
| 146 | 146 | // TODO: ici aussi on peut valider les contenus |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $champs = array_map('corriger_caracteres', $champs); |
| 151 | 151 | |
| 152 | 152 | // On récupère l'état avant toute modification |
| 153 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 153 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet.'='.$id_objet); |
|
| 154 | 154 | |
| 155 | 155 | // Envoyer aux plugins |
| 156 | 156 | $champs = pipeline( |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $id_rubrique = 0; |
| 206 | 206 | if (isset($desc['field']['id_rubrique'])) { |
| 207 | 207 | $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
| 208 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 208 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=".intval($id_objet)); |
|
| 209 | 209 | } |
| 210 | 210 | $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
| 211 | 211 | $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
@@ -227,13 +227,13 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | // allez on commit la modif |
| 230 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 230 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=".intval($id_objet), [], $serveur); |
|
| 231 | 231 | |
| 232 | 232 | // on verifie si elle est bien passee |
| 233 | 233 | $moof = sql_fetsel( |
| 234 | 234 | array_keys($champs), |
| 235 | 235 | $spip_table_objet, |
| 236 | - "$id_table_objet=" . intval($id_objet), |
|
| 236 | + "$id_table_objet=".intval($id_objet), |
|
| 237 | 237 | [], |
| 238 | 238 | [], |
| 239 | 239 | '', |
@@ -269,13 +269,13 @@ discard block |
||
| 269 | 269 | // c'est un cas exceptionnel |
| 270 | 270 | if (count($liste)) { |
| 271 | 271 | spip_log( |
| 272 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 273 | - 'modifier.' . _LOG_CRITIQUE |
|
| 272 | + "Erreur enregistrement en base $objet/$id_objet champs :".var_export($conflits, true), |
|
| 273 | + 'modifier.'._LOG_CRITIQUE |
|
| 274 | 274 | ); |
| 275 | 275 | |
| 276 | 276 | return _T( |
| 277 | 277 | 'erreur_technique_enregistrement_champs', |
| 278 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 278 | + ['champs' => "<i>'".implode("'</i>,<i>'", $liste)."'</i>"] |
|
| 279 | 279 | ); |
| 280 | 280 | } |
| 281 | 281 | } |
@@ -317,18 +317,18 @@ discard block |
||
| 317 | 317 | include_spip('inc/filtres_mini'); |
| 318 | 318 | $qui = ''; |
| 319 | 319 | if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
| 320 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 320 | + $qui .= ' #id_auteur:'.$GLOBALS['visiteur_session']['id_auteur'].'#'; |
|
| 321 | 321 | } |
| 322 | 322 | if (!empty($GLOBALS['visiteur_session']['nom'])) { |
| 323 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 323 | + $qui .= ' #nom:'.$GLOBALS['visiteur_session']['nom'].'#'; |
|
| 324 | 324 | } |
| 325 | 325 | if ($qui == '') { |
| 326 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 326 | + $qui = '#ip:'.$GLOBALS['ip'].'#'; |
|
| 327 | 327 | } |
| 328 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 328 | + journal(_L($qui.' a édité '.$objet.' '.$id_objet.' ('.join( |
|
| 329 | 329 | '+', |
| 330 | 330 | array_diff(array_keys($champs), ['date_modif']) |
| 331 | - ) . ')'), [ |
|
| 331 | + ).')'), [ |
|
| 332 | 332 | 'faire' => 'modifier', |
| 333 | 333 | 'quoi' => $objet, |
| 334 | 334 | 'id' => $id_objet |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -38,28 +38,28 @@ discard block |
||
| 38 | 38 | * Tableau des champs et valeurs collectées |
| 39 | 39 | */ |
| 40 | 40 | function collecter_requests($include_list, $exclude_list = [], $set = null, $tous = false) { |
| 41 | - $c = $set; |
|
| 42 | - if (!$c) { |
|
| 43 | - $c = []; |
|
| 44 | - foreach ($include_list as $champ) { |
|
| 45 | - // on ne collecte que les champs reellement envoyes par defaut. |
|
| 46 | - // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 47 | - $val = _request($champ); |
|
| 48 | - if ($tous or $val !== null) { |
|
| 49 | - $c[$champ] = $val; |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - // on ajoute toujours la lang en saisie possible |
|
| 53 | - // meme si pas prevu au depart pour l'objet concerne |
|
| 54 | - if ($l = _request('changer_lang')) { |
|
| 55 | - $c['lang'] = $l; |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - foreach ($exclude_list as $champ) { |
|
| 59 | - unset($c[$champ]); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $c; |
|
| 41 | + $c = $set; |
|
| 42 | + if (!$c) { |
|
| 43 | + $c = []; |
|
| 44 | + foreach ($include_list as $champ) { |
|
| 45 | + // on ne collecte que les champs reellement envoyes par defaut. |
|
| 46 | + // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 47 | + $val = _request($champ); |
|
| 48 | + if ($tous or $val !== null) { |
|
| 49 | + $c[$champ] = $val; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + // on ajoute toujours la lang en saisie possible |
|
| 53 | + // meme si pas prevu au depart pour l'objet concerne |
|
| 54 | + if ($l = _request('changer_lang')) { |
|
| 55 | + $c['lang'] = $l; |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + foreach ($exclude_list as $champ) { |
|
| 59 | + unset($c[$champ]); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $c; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -96,262 +96,262 @@ discard block |
||
| 96 | 96 | * - chaîne : texte d'un message d'erreur |
| 97 | 97 | */ |
| 98 | 98 | function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') { |
| 99 | - if (!$id_objet = intval($id_objet)) { |
|
| 100 | - spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 101 | - |
|
| 102 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - include_spip('inc/filtres'); |
|
| 106 | - |
|
| 107 | - $table_objet = table_objet($objet, $serveur); |
|
| 108 | - $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 109 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 110 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 111 | - $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 112 | - |
|
| 113 | - // Appels incomplets (sans $c) |
|
| 114 | - if (!is_array($c)) { |
|
| 115 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 116 | - |
|
| 117 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 121 | - // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 122 | - // il faut passer par instituer_XX() |
|
| 123 | - // TODO: faut-il passer ces variables interdites |
|
| 124 | - // dans un fichier de description separe ? |
|
| 125 | - unset($c['statut']); |
|
| 126 | - unset($c['id_parent']); |
|
| 127 | - unset($c['id_rubrique']); |
|
| 128 | - unset($c['id_secteur']); |
|
| 129 | - |
|
| 130 | - // Gerer les champs non vides |
|
| 131 | - if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 132 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 133 | - if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 134 | - $c[$champ] = $sinon; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - // N'accepter que les champs qui existent dans la table |
|
| 140 | - $champs = array_intersect_key($c, $desc['field']); |
|
| 141 | - // et dont la valeur n'est pas null |
|
| 142 | - $champs = array_filter($champs, static function ($var) { |
|
| 143 | - return $var !== null; |
|
| 144 | - }); |
|
| 145 | - // TODO: ici aussi on peut valider les contenus |
|
| 146 | - // en fonction du type |
|
| 147 | - |
|
| 148 | - // Nettoyer les valeurs |
|
| 149 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 150 | - |
|
| 151 | - // On récupère l'état avant toute modification |
|
| 152 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 153 | - |
|
| 154 | - // Envoyer aux plugins |
|
| 155 | - $champs = pipeline( |
|
| 156 | - 'pre_edition', |
|
| 157 | - [ |
|
| 158 | - 'args' => [ |
|
| 159 | - 'table' => $spip_table_objet, // compatibilite |
|
| 160 | - 'table_objet' => $table_objet, |
|
| 161 | - 'spip_table_objet' => $spip_table_objet, |
|
| 162 | - 'desc' => $desc, |
|
| 163 | - 'type' => $objet, |
|
| 164 | - 'id_objet' => $id_objet, |
|
| 165 | - 'data' => $options['data'] ?? null, |
|
| 166 | - 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 167 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 168 | - 'serveur' => $serveur, |
|
| 169 | - 'action' => $options['action'] ?? 'modifier' |
|
| 170 | - ], |
|
| 171 | - 'data' => $champs |
|
| 172 | - ] |
|
| 173 | - ); |
|
| 174 | - |
|
| 175 | - if (!$champs) { |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - // marquer le fait que l'objet est travaille par toto a telle date |
|
| 181 | - include_spip('inc/config'); |
|
| 182 | - if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 183 | - include_spip('inc/drapeau_edition'); |
|
| 184 | - signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 188 | - include_spip('inc/editer'); |
|
| 189 | - if (!isset($options['data']) or is_null($options['data'])) { |
|
| 190 | - $options['data'] = &$_POST; |
|
| 191 | - } |
|
| 192 | - $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 193 | - // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 194 | - // et gere l'interface |
|
| 195 | - // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 196 | - if ($conflits) { |
|
| 197 | - return _T('titre_conflit_edition'); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($champs) { |
|
| 201 | - // cas particulier de la langue : passer par instituer_langue_objet |
|
| 202 | - if (isset($champs['lang'])) { |
|
| 203 | - if ($changer_lang = $champs['lang']) { |
|
| 204 | - $id_rubrique = 0; |
|
| 205 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 206 | - $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 207 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 208 | - } |
|
| 209 | - $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 210 | - $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 211 | - } |
|
| 212 | - // on laisse 'lang' dans $champs, |
|
| 213 | - // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 214 | - // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 215 | - // deja pris en compte |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // la modif peut avoir lieu |
|
| 219 | - |
|
| 220 | - // faut-il ajouter date_modif ? |
|
| 221 | - if ( |
|
| 222 | - !empty($options['date_modif']) |
|
| 223 | - and !isset($champs[$options['date_modif']]) |
|
| 224 | - ) { |
|
| 225 | - $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // allez on commit la modif |
|
| 229 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 230 | - |
|
| 231 | - // on verifie si elle est bien passee |
|
| 232 | - $moof = sql_fetsel( |
|
| 233 | - array_keys($champs), |
|
| 234 | - $spip_table_objet, |
|
| 235 | - "$id_table_objet=" . intval($id_objet), |
|
| 236 | - [], |
|
| 237 | - [], |
|
| 238 | - '', |
|
| 239 | - [], |
|
| 240 | - $serveur |
|
| 241 | - ); |
|
| 242 | - // si difference entre les champs, reperer les champs mal enregistres |
|
| 243 | - if ($moof != $champs) { |
|
| 244 | - $liste = []; |
|
| 245 | - foreach ($moof as $k => $v) { |
|
| 246 | - if ( |
|
| 247 | - $v !== $champs[$k] |
|
| 248 | - // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 249 | - and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 250 | - // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 251 | - and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 252 | - ) { |
|
| 253 | - $liste[] = $k; |
|
| 254 | - $conflits[$k]['post'] = $champs[$k]; |
|
| 255 | - $conflits[$k]['save'] = $v; |
|
| 256 | - |
|
| 257 | - // cas specifique MySQL+emoji : si l'un est la |
|
| 258 | - // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 259 | - if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 260 | - include_spip('inc/charsets'); |
|
| 261 | - if ($v == utf8_noplanes($champs[$k])) { |
|
| 262 | - array_pop($liste); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 268 | - // c'est un cas exceptionnel |
|
| 269 | - if (count($liste)) { |
|
| 270 | - spip_log( |
|
| 271 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 272 | - 'modifier.' . _LOG_CRITIQUE |
|
| 273 | - ); |
|
| 274 | - |
|
| 275 | - return _T( |
|
| 276 | - 'erreur_technique_enregistrement_champs', |
|
| 277 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 278 | - ); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // Invalider les caches |
|
| 283 | - if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 284 | - include_spip('inc/invalideur'); |
|
| 285 | - if (is_array($options['invalideur'])) { |
|
| 286 | - array_map('suivre_invalideur', $options['invalideur']); |
|
| 287 | - } else { |
|
| 288 | - suivre_invalideur($options['invalideur']); |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - // Notifications, gestion des revisions... |
|
| 293 | - // en standard, appelle |nouvelle_revision ci-dessous |
|
| 294 | - pipeline( |
|
| 295 | - 'post_edition', |
|
| 296 | - [ |
|
| 297 | - 'args' => [ |
|
| 298 | - 'table' => $spip_table_objet, |
|
| 299 | - 'table_objet' => $table_objet, |
|
| 300 | - 'spip_table_objet' => $spip_table_objet, |
|
| 301 | - 'desc' => $desc, |
|
| 302 | - 'type' => $objet, |
|
| 303 | - 'id_objet' => $id_objet, |
|
| 304 | - 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 305 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 306 | - 'serveur' => $serveur, |
|
| 307 | - 'action' => $options['action'] ?? 'modifier' |
|
| 308 | - ], |
|
| 309 | - 'data' => $champs |
|
| 310 | - ] |
|
| 311 | - ); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - // Appeler une notification |
|
| 315 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 316 | - $notifications( |
|
| 317 | - "{$objet}_modifier", |
|
| 318 | - $id_objet, |
|
| 319 | - [ |
|
| 320 | - 'champs' => $champs, |
|
| 321 | - ] |
|
| 322 | - ); |
|
| 323 | - $notifications( |
|
| 324 | - 'objet_modifier', |
|
| 325 | - $id_objet, |
|
| 326 | - [ |
|
| 327 | - 'objet' => $objet, |
|
| 328 | - 'id_objet' => $id_objet, |
|
| 329 | - 'champs' => $champs, |
|
| 330 | - ] |
|
| 331 | - ); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - // journaliser l'affaire |
|
| 335 | - // message a affiner :-) |
|
| 336 | - include_spip('inc/filtres_mini'); |
|
| 337 | - $qui = ''; |
|
| 338 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 339 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 340 | - } |
|
| 341 | - if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 342 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 343 | - } |
|
| 344 | - if ($qui == '') { |
|
| 345 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 346 | - } |
|
| 347 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 348 | - '+', |
|
| 349 | - array_diff(array_keys($champs), ['date_modif']) |
|
| 350 | - ) . ')'), [ |
|
| 351 | - 'faire' => 'modifier', |
|
| 352 | - 'quoi' => $objet, |
|
| 353 | - 'id' => $id_objet |
|
| 354 | - ]); |
|
| 355 | - |
|
| 356 | - return ''; |
|
| 99 | + if (!$id_objet = intval($id_objet)) { |
|
| 100 | + spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 101 | + |
|
| 102 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + include_spip('inc/filtres'); |
|
| 106 | + |
|
| 107 | + $table_objet = table_objet($objet, $serveur); |
|
| 108 | + $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 109 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 110 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 111 | + $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 112 | + |
|
| 113 | + // Appels incomplets (sans $c) |
|
| 114 | + if (!is_array($c)) { |
|
| 115 | + spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 116 | + |
|
| 117 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 121 | + // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 122 | + // il faut passer par instituer_XX() |
|
| 123 | + // TODO: faut-il passer ces variables interdites |
|
| 124 | + // dans un fichier de description separe ? |
|
| 125 | + unset($c['statut']); |
|
| 126 | + unset($c['id_parent']); |
|
| 127 | + unset($c['id_rubrique']); |
|
| 128 | + unset($c['id_secteur']); |
|
| 129 | + |
|
| 130 | + // Gerer les champs non vides |
|
| 131 | + if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 132 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 133 | + if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 134 | + $c[$champ] = $sinon; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + // N'accepter que les champs qui existent dans la table |
|
| 140 | + $champs = array_intersect_key($c, $desc['field']); |
|
| 141 | + // et dont la valeur n'est pas null |
|
| 142 | + $champs = array_filter($champs, static function ($var) { |
|
| 143 | + return $var !== null; |
|
| 144 | + }); |
|
| 145 | + // TODO: ici aussi on peut valider les contenus |
|
| 146 | + // en fonction du type |
|
| 147 | + |
|
| 148 | + // Nettoyer les valeurs |
|
| 149 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 150 | + |
|
| 151 | + // On récupère l'état avant toute modification |
|
| 152 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 153 | + |
|
| 154 | + // Envoyer aux plugins |
|
| 155 | + $champs = pipeline( |
|
| 156 | + 'pre_edition', |
|
| 157 | + [ |
|
| 158 | + 'args' => [ |
|
| 159 | + 'table' => $spip_table_objet, // compatibilite |
|
| 160 | + 'table_objet' => $table_objet, |
|
| 161 | + 'spip_table_objet' => $spip_table_objet, |
|
| 162 | + 'desc' => $desc, |
|
| 163 | + 'type' => $objet, |
|
| 164 | + 'id_objet' => $id_objet, |
|
| 165 | + 'data' => $options['data'] ?? null, |
|
| 166 | + 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 167 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 168 | + 'serveur' => $serveur, |
|
| 169 | + 'action' => $options['action'] ?? 'modifier' |
|
| 170 | + ], |
|
| 171 | + 'data' => $champs |
|
| 172 | + ] |
|
| 173 | + ); |
|
| 174 | + |
|
| 175 | + if (!$champs) { |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + // marquer le fait que l'objet est travaille par toto a telle date |
|
| 181 | + include_spip('inc/config'); |
|
| 182 | + if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 183 | + include_spip('inc/drapeau_edition'); |
|
| 184 | + signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 188 | + include_spip('inc/editer'); |
|
| 189 | + if (!isset($options['data']) or is_null($options['data'])) { |
|
| 190 | + $options['data'] = &$_POST; |
|
| 191 | + } |
|
| 192 | + $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 193 | + // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 194 | + // et gere l'interface |
|
| 195 | + // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 196 | + if ($conflits) { |
|
| 197 | + return _T('titre_conflit_edition'); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($champs) { |
|
| 201 | + // cas particulier de la langue : passer par instituer_langue_objet |
|
| 202 | + if (isset($champs['lang'])) { |
|
| 203 | + if ($changer_lang = $champs['lang']) { |
|
| 204 | + $id_rubrique = 0; |
|
| 205 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 206 | + $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 207 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 208 | + } |
|
| 209 | + $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 210 | + $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 211 | + } |
|
| 212 | + // on laisse 'lang' dans $champs, |
|
| 213 | + // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 214 | + // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 215 | + // deja pris en compte |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // la modif peut avoir lieu |
|
| 219 | + |
|
| 220 | + // faut-il ajouter date_modif ? |
|
| 221 | + if ( |
|
| 222 | + !empty($options['date_modif']) |
|
| 223 | + and !isset($champs[$options['date_modif']]) |
|
| 224 | + ) { |
|
| 225 | + $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // allez on commit la modif |
|
| 229 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 230 | + |
|
| 231 | + // on verifie si elle est bien passee |
|
| 232 | + $moof = sql_fetsel( |
|
| 233 | + array_keys($champs), |
|
| 234 | + $spip_table_objet, |
|
| 235 | + "$id_table_objet=" . intval($id_objet), |
|
| 236 | + [], |
|
| 237 | + [], |
|
| 238 | + '', |
|
| 239 | + [], |
|
| 240 | + $serveur |
|
| 241 | + ); |
|
| 242 | + // si difference entre les champs, reperer les champs mal enregistres |
|
| 243 | + if ($moof != $champs) { |
|
| 244 | + $liste = []; |
|
| 245 | + foreach ($moof as $k => $v) { |
|
| 246 | + if ( |
|
| 247 | + $v !== $champs[$k] |
|
| 248 | + // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 249 | + and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 250 | + // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 251 | + and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 252 | + ) { |
|
| 253 | + $liste[] = $k; |
|
| 254 | + $conflits[$k]['post'] = $champs[$k]; |
|
| 255 | + $conflits[$k]['save'] = $v; |
|
| 256 | + |
|
| 257 | + // cas specifique MySQL+emoji : si l'un est la |
|
| 258 | + // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 259 | + if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 260 | + include_spip('inc/charsets'); |
|
| 261 | + if ($v == utf8_noplanes($champs[$k])) { |
|
| 262 | + array_pop($liste); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 268 | + // c'est un cas exceptionnel |
|
| 269 | + if (count($liste)) { |
|
| 270 | + spip_log( |
|
| 271 | + "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 272 | + 'modifier.' . _LOG_CRITIQUE |
|
| 273 | + ); |
|
| 274 | + |
|
| 275 | + return _T( |
|
| 276 | + 'erreur_technique_enregistrement_champs', |
|
| 277 | + ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 278 | + ); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // Invalider les caches |
|
| 283 | + if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 284 | + include_spip('inc/invalideur'); |
|
| 285 | + if (is_array($options['invalideur'])) { |
|
| 286 | + array_map('suivre_invalideur', $options['invalideur']); |
|
| 287 | + } else { |
|
| 288 | + suivre_invalideur($options['invalideur']); |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + // Notifications, gestion des revisions... |
|
| 293 | + // en standard, appelle |nouvelle_revision ci-dessous |
|
| 294 | + pipeline( |
|
| 295 | + 'post_edition', |
|
| 296 | + [ |
|
| 297 | + 'args' => [ |
|
| 298 | + 'table' => $spip_table_objet, |
|
| 299 | + 'table_objet' => $table_objet, |
|
| 300 | + 'spip_table_objet' => $spip_table_objet, |
|
| 301 | + 'desc' => $desc, |
|
| 302 | + 'type' => $objet, |
|
| 303 | + 'id_objet' => $id_objet, |
|
| 304 | + 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 305 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 306 | + 'serveur' => $serveur, |
|
| 307 | + 'action' => $options['action'] ?? 'modifier' |
|
| 308 | + ], |
|
| 309 | + 'data' => $champs |
|
| 310 | + ] |
|
| 311 | + ); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + // Appeler une notification |
|
| 315 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 316 | + $notifications( |
|
| 317 | + "{$objet}_modifier", |
|
| 318 | + $id_objet, |
|
| 319 | + [ |
|
| 320 | + 'champs' => $champs, |
|
| 321 | + ] |
|
| 322 | + ); |
|
| 323 | + $notifications( |
|
| 324 | + 'objet_modifier', |
|
| 325 | + $id_objet, |
|
| 326 | + [ |
|
| 327 | + 'objet' => $objet, |
|
| 328 | + 'id_objet' => $id_objet, |
|
| 329 | + 'champs' => $champs, |
|
| 330 | + ] |
|
| 331 | + ); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + // journaliser l'affaire |
|
| 335 | + // message a affiner :-) |
|
| 336 | + include_spip('inc/filtres_mini'); |
|
| 337 | + $qui = ''; |
|
| 338 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 339 | + $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 340 | + } |
|
| 341 | + if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 342 | + $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 343 | + } |
|
| 344 | + if ($qui == '') { |
|
| 345 | + $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 346 | + } |
|
| 347 | + journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 348 | + '+', |
|
| 349 | + array_diff(array_keys($champs), ['date_modif']) |
|
| 350 | + ) . ')'), [ |
|
| 351 | + 'faire' => 'modifier', |
|
| 352 | + 'quoi' => $objet, |
|
| 353 | + 'id' => $id_objet |
|
| 354 | + ]); |
|
| 355 | + |
|
| 356 | + return ''; |
|
| 357 | 357 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $row = sql_fetsel( |
| 50 | 50 | '*', |
| 51 | 51 | 'spip_auteurs', |
| 52 | - 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 52 | + 'login='.sql_quote($login, $serveur, 'text')." AND statut<>'5poubelle'", |
|
| 53 | 53 | '', |
| 54 | 54 | '', |
| 55 | 55 | '', |
@@ -77,20 +77,20 @@ discard block |
||
| 77 | 77 | // legacy = md5 ou sha256 |
| 78 | 78 | case 32: |
| 79 | 79 | // tres anciens mots de passe encodes en md5(alea.pass) |
| 80 | - $hash = md5($row['alea_actuel'] . $pass); |
|
| 80 | + $hash = md5($row['alea_actuel'].$pass); |
|
| 81 | 81 | $methode = 'md5'; |
| 82 | 82 | case 64: |
| 83 | 83 | if (empty($hash)) { |
| 84 | 84 | // anciens mots de passe encodes en sha256(alea.pass) |
| 85 | 85 | include_spip('auth/sha256.inc'); |
| 86 | - $hash = spip_sha256($row['alea_actuel'] . $pass); |
|
| 86 | + $hash = spip_sha256($row['alea_actuel'].$pass); |
|
| 87 | 87 | $methode = 'sha256'; |
| 88 | 88 | } |
| 89 | 89 | if ($row['pass'] === $hash) { |
| 90 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 90 | + spip_log("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via $methode", 'auth'._LOG_DEBUG); |
|
| 91 | 91 | // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
| 92 | 92 | if (!empty($row['backup_cles'])) { |
| 93 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 93 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.intval($row['id_auteur'])); |
|
| 94 | 94 | } |
| 95 | 95 | break; |
| 96 | 96 | } |
@@ -108,19 +108,19 @@ discard block |
||
| 108 | 108 | and !empty($row['backup_cles']) |
| 109 | 109 | ) { |
| 110 | 110 | if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
| 111 | - spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 111 | + spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #'.$row['id_auteur'], 'auth'._LOG_INFO_IMPORTANTE); |
|
| 112 | 112 | if ($cles->save()) { |
| 113 | 113 | $secret = $cles->getSecretAuth(); |
| 114 | 114 | } |
| 115 | 115 | else { |
| 116 | - spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 116 | + spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth'._LOG_ERREUR); |
|
| 117 | 117 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 118 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 118 | + raler_fichier(_DIR_ETC.'cles.php'); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | else { |
| 122 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 123 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 122 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #'.$row['id_auteur']." n'est pas valide", 'auth'._LOG_ERREUR); |
|
| 123 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.intval($row['id_auteur'])); |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | unset($row); |
| 129 | 129 | } |
| 130 | 130 | else { |
| 131 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 131 | + spip_log("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via Password::verifier", 'auth'._LOG_DEBUG); |
|
| 132 | 132 | } |
| 133 | 133 | break; |
| 134 | 134 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | @sql_update( |
| 176 | 176 | 'spip_auteurs', |
| 177 | 177 | $set, |
| 178 | - 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 178 | + 'id_auteur='.intval($row['id_auteur']).' AND pass='.sql_quote( |
|
| 179 | 179 | $row['pass'], |
| 180 | 180 | $serveur, |
| 181 | 181 | 'text' |
@@ -223,24 +223,24 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | // si force, on ne verifie pas la presence d'un backup chez un webmestre |
| 225 | 225 | if ($force) { |
| 226 | - spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 226 | + spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth'._LOG_INFO_IMPORTANTE); |
|
| 227 | 227 | $secret = $cles->getSecretAuth(true); |
| 228 | 228 | return true; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 231 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut='.sql_quote('0minirezo').' AND webmestre='.sql_quote('oui')." AND backup_cles!=''"); |
|
| 232 | 232 | $has_backup = array_column($has_backup, 'id_auteur'); |
| 233 | 233 | if (empty($has_backup)) { |
| 234 | - spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 234 | + spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth'._LOG_INFO_IMPORTANTE); |
|
| 235 | 235 | if ($secret = $cles->getSecretAuth(true)) { |
| 236 | 236 | return true; |
| 237 | 237 | } |
| 238 | - spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 238 | + spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth'._LOG_ERREUR); |
|
| 239 | 239 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 240 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 240 | + raler_fichier(_DIR_ETC.'cles.php'); |
|
| 241 | 241 | } |
| 242 | 242 | else { |
| 243 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 243 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #'.implode(', #', $has_backup).' doit se connecter pour restaurer son backup des cles', 'auth'._LOG_ERREUR); |
|
| 244 | 244 | } |
| 245 | 245 | return false; |
| 246 | 246 | } |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | $flux['data'] .= |
| 258 | 258 | '<script type="text/javascript">/*<![CDATA[*/' |
| 259 | 259 | . "$js\n" |
| 260 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 261 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 260 | + . "var login_info={'login':'".$flux['args']['contexte']['var_login']."'," |
|
| 261 | + . "'page_auteur': '".generer_url_public('informer_auteur')."'," |
|
| 262 | 262 | . "'informe_auteur_en_cours':false," |
| 263 | 263 | . "'attente_informe':0};" |
| 264 | 264 | . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | } else { |
| 302 | 302 | $n = sql_countsel( |
| 303 | 303 | 'spip_auteurs', |
| 304 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 304 | + 'login='.sql_quote($new_login).' AND id_auteur!='.intval($id_auteur)." AND statut!='5poubelle'", |
|
| 305 | 305 | '', |
| 306 | 306 | '', |
| 307 | 307 | $serveur |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | } |
| 330 | 330 | if ( |
| 331 | 331 | !$id_auteur = intval($id_auteur) |
| 332 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 332 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur), '', '', '', '', $serveur) |
|
| 333 | 333 | ) { |
| 334 | 334 | return false; |
| 335 | 335 | } |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | $anciens = sql_allfetsel( |
| 345 | 345 | 'id_auteur', |
| 346 | 346 | 'spip_auteurs', |
| 347 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 347 | + 'login='.sql_quote($new_login, $serveur, 'text')." AND statut='5poubelle'", |
|
| 348 | 348 | '', |
| 349 | 349 | '', |
| 350 | 350 | '', |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | $r = sql_getfetsel( |
| 379 | 379 | 'login', |
| 380 | 380 | 'spip_auteurs', |
| 381 | - "statut<>'5poubelle'" . |
|
| 382 | - ' AND (length(pass)>0)' . |
|
| 381 | + "statut<>'5poubelle'". |
|
| 382 | + ' AND (length(pass)>0)'. |
|
| 383 | 383 | " AND (login=$l)", |
| 384 | 384 | '', |
| 385 | 385 | '', |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | return sql_getfetsel( |
| 399 | 399 | 'login', |
| 400 | 400 | 'spip_auteurs', |
| 401 | - "statut<>'5poubelle'" . |
|
| 402 | - ' AND (length(pass)>0)' . |
|
| 401 | + "statut<>'5poubelle'". |
|
| 402 | + ' AND (length(pass)>0)'. |
|
| 403 | 403 | " AND (login<>'' AND (nom=$l OR email=$l))", |
| 404 | 404 | '', |
| 405 | 405 | '', |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | |
| 469 | 469 | if ( |
| 470 | 470 | !$id_auteur = intval($id_auteur) |
| 471 | - or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 471 | + or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur='.intval($id_auteur), '', '', '', '', $serveur) |
|
| 472 | 472 | ) { |
| 473 | 473 | return false; |
| 474 | 474 | } |
@@ -529,8 +529,8 @@ discard block |
||
| 529 | 529 | or isset($champs['statut']) |
| 530 | 530 | or (isset($options['all']) and $options['all']) |
| 531 | 531 | ) { |
| 532 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 533 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 532 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 533 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 534 | 534 | |
| 535 | 535 | // Cette variable de configuration peut etre posee par un plugin |
| 536 | 536 | // par exemple acces_restreint ; |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | and !@file_exists($htaccess) |
| 541 | 541 | ) { |
| 542 | 542 | spip_unlink($htpasswd); |
| 543 | - spip_unlink($htpasswd . '-admin'); |
|
| 543 | + spip_unlink($htpasswd.'-admin'); |
|
| 544 | 544 | |
| 545 | 545 | return; |
| 546 | 546 | } |
@@ -558,16 +558,16 @@ discard block |
||
| 558 | 558 | ); |
| 559 | 559 | while ($t = sql_fetch($s)) { |
| 560 | 560 | if (strlen($t['login']) and strlen($t['htpass'])) { |
| 561 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 561 | + $p1 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 562 | 562 | if ($t['statut'] == '0minirezo') { |
| 563 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 563 | + $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | } |
| 567 | 567 | sql_free($s); |
| 568 | 568 | if ($p1) { |
| 569 | 569 | ecrire_fichier($htpasswd, $p1); |
| 570 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 570 | + ecrire_fichier($htpasswd.'-admin', $p2); |
|
| 571 | 571 | spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
| 572 | 572 | } |
| 573 | 573 | } |
@@ -111,14 +111,12 @@ discard block |
||
| 111 | 111 | spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
| 112 | 112 | if ($cles->save()) { |
| 113 | 113 | $secret = $cles->getSecretAuth(); |
| 114 | - } |
|
| 115 | - else { |
|
| 114 | + } else { |
|
| 116 | 115 | spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
| 117 | 116 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 118 | 117 | raler_fichier(_DIR_ETC . 'cles.php'); |
| 119 | 118 | } |
| 120 | - } |
|
| 121 | - else { |
|
| 119 | + } else { |
|
| 122 | 120 | spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
| 123 | 121 | sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
| 124 | 122 | } |
@@ -126,8 +124,7 @@ discard block |
||
| 126 | 124 | |
| 127 | 125 | if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) { |
| 128 | 126 | unset($row); |
| 129 | - } |
|
| 130 | - else { |
|
| 127 | + } else { |
|
| 131 | 128 | spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
| 132 | 129 | } |
| 133 | 130 | break; |
@@ -238,8 +235,7 @@ discard block |
||
| 238 | 235 | spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
| 239 | 236 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 240 | 237 | raler_fichier(_DIR_ETC . 'cles.php'); |
| 241 | - } |
|
| 242 | - else { |
|
| 238 | + } else { |
|
| 243 | 239 | spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
| 244 | 240 | } |
| 245 | 241 | return false; |
@@ -479,8 +475,7 @@ discard block |
||
| 479 | 475 | if (!$secret) { |
| 480 | 476 | if (auth_spip_initialiser_secret()) { |
| 481 | 477 | $secret = $cles->getSecretAuth(); |
| 482 | - } |
|
| 483 | - else { |
|
| 478 | + } else { |
|
| 484 | 479 | return false; |
| 485 | 480 | } |
| 486 | 481 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | use Spip\Chiffrer\SpipCles; |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -33,169 +33,169 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function auth_spip_dist($login, #[\SensitiveParameter] $pass, $serveur = '', $phpauth = false) { |
| 35 | 35 | |
| 36 | - // retrouver le login |
|
| 37 | - $login = auth_spip_retrouver_login($login); |
|
| 38 | - // login inconnu, n'allons pas plus loin |
|
| 39 | - if (!$login) { |
|
| 40 | - return []; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - $md5pass = ''; |
|
| 44 | - $shapass = $shanext = ''; |
|
| 45 | - $auteur_peut_sauver_cles = false; |
|
| 46 | - |
|
| 47 | - if ($pass) { |
|
| 48 | - $row = sql_fetsel( |
|
| 49 | - '*', |
|
| 50 | - 'spip_auteurs', |
|
| 51 | - 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 52 | - '', |
|
| 53 | - '', |
|
| 54 | - '', |
|
| 55 | - '', |
|
| 56 | - $serveur |
|
| 57 | - ); |
|
| 58 | - |
|
| 59 | - // lever un flag si cet auteur peut sauver les cles |
|
| 60 | - if ($row['statut'] === '0minirezo' and $row['webmestre'] === 'oui' and isset($row['backup_cles'])) { |
|
| 61 | - $auteur_peut_sauver_cles = true; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - // login inexistant ou mot de passe vide |
|
| 66 | - if (!$pass or !$row) { |
|
| 67 | - return []; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $cles = SpipCles::instance(); |
|
| 71 | - $secret = $cles->getSecretAuth(); |
|
| 72 | - |
|
| 73 | - $hash = null; |
|
| 74 | - switch (strlen($row['pass'])) { |
|
| 75 | - // legacy = md5 ou sha256 |
|
| 76 | - case 32: |
|
| 77 | - // tres anciens mots de passe encodes en md5(alea.pass) |
|
| 78 | - $hash = md5($row['alea_actuel'] . $pass); |
|
| 79 | - $methode = 'md5'; |
|
| 80 | - case 64: |
|
| 81 | - if (empty($hash)) { |
|
| 82 | - // anciens mots de passe encodes en sha256(alea.pass) |
|
| 83 | - include_spip('auth/sha256.inc'); |
|
| 84 | - $hash = spip_sha256($row['alea_actuel'] . $pass); |
|
| 85 | - $methode = 'sha256'; |
|
| 86 | - } |
|
| 87 | - if ($row['pass'] === $hash) { |
|
| 88 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 89 | - // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
|
| 90 | - if (!empty($row['backup_cles'])) { |
|
| 91 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 92 | - } |
|
| 93 | - break; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long |
|
| 97 | - |
|
| 98 | - case 60: |
|
| 99 | - case 98: |
|
| 100 | - default: |
|
| 101 | - // doit-on restaurer un backup des cles ? |
|
| 102 | - // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass |
|
| 103 | - if ( |
|
| 104 | - !$secret |
|
| 105 | - and $auteur_peut_sauver_cles |
|
| 106 | - and !empty($row['backup_cles']) |
|
| 107 | - ) { |
|
| 108 | - if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 109 | - spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 110 | - if ($cles->save()) { |
|
| 111 | - $secret = $cles->getSecretAuth(); |
|
| 112 | - } |
|
| 113 | - else { |
|
| 114 | - spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 115 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 116 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - else { |
|
| 120 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 121 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 126 | - unset($row); |
|
| 127 | - } |
|
| 128 | - else { |
|
| 129 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 130 | - } |
|
| 131 | - break; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // Migration depuis ancienne version : si on a pas encore de cle |
|
| 135 | - // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 136 | - // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 137 | - // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre |
|
| 138 | - if (!$secret and $auteur_peut_sauver_cles) { |
|
| 139 | - if (auth_spip_initialiser_secret()) { |
|
| 140 | - $secret = $cles->getSecretAuth(); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // login/mot de passe incorrect |
|
| 145 | - if (empty($row)) { |
|
| 146 | - return []; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // fait tourner le codage du pass dans la base |
|
| 150 | - // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 151 | - if (!$phpauth and $secret) { |
|
| 152 | - include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 153 | - $pass_hash_next = Password::hacher($pass, $secret); |
|
| 154 | - if ($pass_hash_next) { |
|
| 155 | - $set = [ |
|
| 156 | - 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 157 | - 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 158 | - 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 159 | - ]; |
|
| 160 | - |
|
| 161 | - // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 162 | - // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 163 | - $htpass = generer_htpass($pass); |
|
| 164 | - if (strlen($htpass) !== strlen($row['htpass'])) { |
|
| 165 | - $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 169 | - if ($auteur_peut_sauver_cles) { |
|
| 170 | - $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - @sql_update( |
|
| 174 | - 'spip_auteurs', |
|
| 175 | - $set, |
|
| 176 | - 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 177 | - $row['pass'], |
|
| 178 | - $serveur, |
|
| 179 | - 'text' |
|
| 180 | - ), |
|
| 181 | - [], |
|
| 182 | - $serveur |
|
| 183 | - ); |
|
| 184 | - |
|
| 185 | - // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 186 | - if (isset($set['htpass'])) { |
|
| 187 | - ecrire_acces(); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // En profiter pour verifier la securite de tmp/ |
|
| 192 | - // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 193 | - if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 194 | - return false; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - return $row; |
|
| 36 | + // retrouver le login |
|
| 37 | + $login = auth_spip_retrouver_login($login); |
|
| 38 | + // login inconnu, n'allons pas plus loin |
|
| 39 | + if (!$login) { |
|
| 40 | + return []; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + $md5pass = ''; |
|
| 44 | + $shapass = $shanext = ''; |
|
| 45 | + $auteur_peut_sauver_cles = false; |
|
| 46 | + |
|
| 47 | + if ($pass) { |
|
| 48 | + $row = sql_fetsel( |
|
| 49 | + '*', |
|
| 50 | + 'spip_auteurs', |
|
| 51 | + 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 52 | + '', |
|
| 53 | + '', |
|
| 54 | + '', |
|
| 55 | + '', |
|
| 56 | + $serveur |
|
| 57 | + ); |
|
| 58 | + |
|
| 59 | + // lever un flag si cet auteur peut sauver les cles |
|
| 60 | + if ($row['statut'] === '0minirezo' and $row['webmestre'] === 'oui' and isset($row['backup_cles'])) { |
|
| 61 | + $auteur_peut_sauver_cles = true; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // login inexistant ou mot de passe vide |
|
| 66 | + if (!$pass or !$row) { |
|
| 67 | + return []; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $cles = SpipCles::instance(); |
|
| 71 | + $secret = $cles->getSecretAuth(); |
|
| 72 | + |
|
| 73 | + $hash = null; |
|
| 74 | + switch (strlen($row['pass'])) { |
|
| 75 | + // legacy = md5 ou sha256 |
|
| 76 | + case 32: |
|
| 77 | + // tres anciens mots de passe encodes en md5(alea.pass) |
|
| 78 | + $hash = md5($row['alea_actuel'] . $pass); |
|
| 79 | + $methode = 'md5'; |
|
| 80 | + case 64: |
|
| 81 | + if (empty($hash)) { |
|
| 82 | + // anciens mots de passe encodes en sha256(alea.pass) |
|
| 83 | + include_spip('auth/sha256.inc'); |
|
| 84 | + $hash = spip_sha256($row['alea_actuel'] . $pass); |
|
| 85 | + $methode = 'sha256'; |
|
| 86 | + } |
|
| 87 | + if ($row['pass'] === $hash) { |
|
| 88 | + spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 89 | + // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
|
| 90 | + if (!empty($row['backup_cles'])) { |
|
| 91 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 92 | + } |
|
| 93 | + break; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long |
|
| 97 | + |
|
| 98 | + case 60: |
|
| 99 | + case 98: |
|
| 100 | + default: |
|
| 101 | + // doit-on restaurer un backup des cles ? |
|
| 102 | + // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass |
|
| 103 | + if ( |
|
| 104 | + !$secret |
|
| 105 | + and $auteur_peut_sauver_cles |
|
| 106 | + and !empty($row['backup_cles']) |
|
| 107 | + ) { |
|
| 108 | + if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 109 | + spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 110 | + if ($cles->save()) { |
|
| 111 | + $secret = $cles->getSecretAuth(); |
|
| 112 | + } |
|
| 113 | + else { |
|
| 114 | + spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 115 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 116 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + else { |
|
| 120 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 121 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 126 | + unset($row); |
|
| 127 | + } |
|
| 128 | + else { |
|
| 129 | + spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 130 | + } |
|
| 131 | + break; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // Migration depuis ancienne version : si on a pas encore de cle |
|
| 135 | + // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 136 | + // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 137 | + // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre |
|
| 138 | + if (!$secret and $auteur_peut_sauver_cles) { |
|
| 139 | + if (auth_spip_initialiser_secret()) { |
|
| 140 | + $secret = $cles->getSecretAuth(); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // login/mot de passe incorrect |
|
| 145 | + if (empty($row)) { |
|
| 146 | + return []; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // fait tourner le codage du pass dans la base |
|
| 150 | + // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 151 | + if (!$phpauth and $secret) { |
|
| 152 | + include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 153 | + $pass_hash_next = Password::hacher($pass, $secret); |
|
| 154 | + if ($pass_hash_next) { |
|
| 155 | + $set = [ |
|
| 156 | + 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 157 | + 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 158 | + 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 159 | + ]; |
|
| 160 | + |
|
| 161 | + // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 162 | + // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 163 | + $htpass = generer_htpass($pass); |
|
| 164 | + if (strlen($htpass) !== strlen($row['htpass'])) { |
|
| 165 | + $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 169 | + if ($auteur_peut_sauver_cles) { |
|
| 170 | + $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + @sql_update( |
|
| 174 | + 'spip_auteurs', |
|
| 175 | + $set, |
|
| 176 | + 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 177 | + $row['pass'], |
|
| 178 | + $serveur, |
|
| 179 | + 'text' |
|
| 180 | + ), |
|
| 181 | + [], |
|
| 182 | + $serveur |
|
| 183 | + ); |
|
| 184 | + |
|
| 185 | + // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 186 | + if (isset($set['htpass'])) { |
|
| 187 | + ecrire_acces(); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // En profiter pour verifier la securite de tmp/ |
|
| 192 | + // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 193 | + if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + return $row; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -210,36 +210,36 @@ discard block |
||
| 210 | 210 | * @return bool |
| 211 | 211 | */ |
| 212 | 212 | function auth_spip_initialiser_secret(bool $force = false): bool { |
| 213 | - $cles = SpipCles::instance(); |
|
| 214 | - $secret = $cles->getSecretAuth(); |
|
| 215 | - |
|
| 216 | - // on ne fait rien si on a un secret dispo |
|
| 217 | - if ($secret) { |
|
| 218 | - return false; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 222 | - if ($force) { |
|
| 223 | - spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 224 | - $secret = $cles->getSecretAuth(true); |
|
| 225 | - return true; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 229 | - $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 230 | - if (empty($has_backup)) { |
|
| 231 | - spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 232 | - if ($secret = $cles->getSecretAuth(true)) { |
|
| 233 | - return true; |
|
| 234 | - } |
|
| 235 | - spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 236 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 237 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 238 | - } |
|
| 239 | - else { |
|
| 240 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 241 | - } |
|
| 242 | - return false; |
|
| 213 | + $cles = SpipCles::instance(); |
|
| 214 | + $secret = $cles->getSecretAuth(); |
|
| 215 | + |
|
| 216 | + // on ne fait rien si on a un secret dispo |
|
| 217 | + if ($secret) { |
|
| 218 | + return false; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 222 | + if ($force) { |
|
| 223 | + spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 224 | + $secret = $cles->getSecretAuth(true); |
|
| 225 | + return true; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 229 | + $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 230 | + if (empty($has_backup)) { |
|
| 231 | + spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 232 | + if ($secret = $cles->getSecretAuth(true)) { |
|
| 233 | + return true; |
|
| 234 | + } |
|
| 235 | + spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 236 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 237 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 238 | + } |
|
| 239 | + else { |
|
| 240 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 241 | + } |
|
| 242 | + return false; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -249,19 +249,19 @@ discard block |
||
| 249 | 249 | * @return array |
| 250 | 250 | */ |
| 251 | 251 | function auth_spip_formulaire_login($flux) { |
| 252 | - // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 253 | - $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 254 | - $flux['data'] .= |
|
| 255 | - '<script type="text/javascript">/*<![CDATA[*/' |
|
| 256 | - . "$js\n" |
|
| 257 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 258 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 259 | - . "'informe_auteur_en_cours':false," |
|
| 260 | - . "'attente_informe':0};" |
|
| 261 | - . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 262 | - . '/*]]>*/</script>'; |
|
| 263 | - |
|
| 264 | - return $flux; |
|
| 252 | + // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 253 | + $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 254 | + $flux['data'] .= |
|
| 255 | + '<script type="text/javascript">/*<![CDATA[*/' |
|
| 256 | + . "$js\n" |
|
| 257 | + . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 258 | + . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 259 | + . "'informe_auteur_en_cours':false," |
|
| 260 | + . "'attente_informe':0};" |
|
| 261 | + . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 262 | + . '/*]]>*/</script>'; |
|
| 263 | + |
|
| 264 | + return $flux; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -273,11 +273,11 @@ discard block |
||
| 273 | 273 | * toujours true pour un auteur cree dans SPIP |
| 274 | 274 | */ |
| 275 | 275 | function auth_spip_autoriser_modifier_login(string $serveur = ''): bool { |
| 276 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 277 | - if (strlen($serveur)) { |
|
| 278 | - return false; |
|
| 279 | - } |
|
| 280 | - return true; |
|
| 276 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 277 | + if (strlen($serveur)) { |
|
| 278 | + return false; |
|
| 279 | + } |
|
| 280 | + return true; |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -291,25 +291,25 @@ discard block |
||
| 291 | 291 | * message d'erreur si login non valide, chaine vide sinon |
| 292 | 292 | */ |
| 293 | 293 | function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { |
| 294 | - // login et mot de passe |
|
| 295 | - if (strlen($new_login)) { |
|
| 296 | - if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 297 | - return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 298 | - } else { |
|
| 299 | - $n = sql_countsel( |
|
| 300 | - 'spip_auteurs', |
|
| 301 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 302 | - '', |
|
| 303 | - '', |
|
| 304 | - $serveur |
|
| 305 | - ); |
|
| 306 | - if ($n) { |
|
| 307 | - return _T('info_login_existant'); |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - return ''; |
|
| 294 | + // login et mot de passe |
|
| 295 | + if (strlen($new_login)) { |
|
| 296 | + if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 297 | + return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 298 | + } else { |
|
| 299 | + $n = sql_countsel( |
|
| 300 | + 'spip_auteurs', |
|
| 301 | + 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 302 | + '', |
|
| 303 | + '', |
|
| 304 | + $serveur |
|
| 305 | + ); |
|
| 306 | + if ($n) { |
|
| 307 | + return _T('info_login_existant'); |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + return ''; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /** |
@@ -321,41 +321,41 @@ discard block |
||
| 321 | 321 | * @return bool |
| 322 | 322 | */ |
| 323 | 323 | function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { |
| 324 | - if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 325 | - return false; |
|
| 326 | - } |
|
| 327 | - if ( |
|
| 328 | - !$id_auteur = intval($id_auteur) |
|
| 329 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 330 | - ) { |
|
| 331 | - return false; |
|
| 332 | - } |
|
| 333 | - if ($new_login == $auteur['login']) { |
|
| 334 | - return true; |
|
| 335 | - } // on a rien fait mais c'est bon ! |
|
| 336 | - |
|
| 337 | - include_spip('action/editer_auteur'); |
|
| 338 | - |
|
| 339 | - // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 340 | - if (strlen($new_login)) { |
|
| 341 | - $anciens = sql_allfetsel( |
|
| 342 | - 'id_auteur', |
|
| 343 | - 'spip_auteurs', |
|
| 344 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 345 | - '', |
|
| 346 | - '', |
|
| 347 | - '', |
|
| 348 | - '', |
|
| 349 | - $serveur |
|
| 350 | - ); |
|
| 351 | - while ($row = array_pop($anciens)) { |
|
| 352 | - auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 357 | - |
|
| 358 | - return true; |
|
| 324 | + if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 325 | + return false; |
|
| 326 | + } |
|
| 327 | + if ( |
|
| 328 | + !$id_auteur = intval($id_auteur) |
|
| 329 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 330 | + ) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 333 | + if ($new_login == $auteur['login']) { |
|
| 334 | + return true; |
|
| 335 | + } // on a rien fait mais c'est bon ! |
|
| 336 | + |
|
| 337 | + include_spip('action/editer_auteur'); |
|
| 338 | + |
|
| 339 | + // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 340 | + if (strlen($new_login)) { |
|
| 341 | + $anciens = sql_allfetsel( |
|
| 342 | + 'id_auteur', |
|
| 343 | + 'spip_auteurs', |
|
| 344 | + 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 345 | + '', |
|
| 346 | + '', |
|
| 347 | + '', |
|
| 348 | + '', |
|
| 349 | + $serveur |
|
| 350 | + ); |
|
| 351 | + while ($row = array_pop($anciens)) { |
|
| 352 | + auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 357 | + |
|
| 358 | + return true; |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
@@ -367,44 +367,44 @@ discard block |
||
| 367 | 367 | * @return string |
| 368 | 368 | */ |
| 369 | 369 | function auth_spip_retrouver_login($login, $serveur = '') { |
| 370 | - if (!strlen($login)) { |
|
| 371 | - return null; |
|
| 372 | - } // pas la peine de requeter |
|
| 373 | - $l = sql_quote($login, $serveur, 'text'); |
|
| 374 | - if ( |
|
| 375 | - $r = sql_getfetsel( |
|
| 376 | - 'login', |
|
| 377 | - 'spip_auteurs', |
|
| 378 | - "statut<>'5poubelle'" . |
|
| 379 | - ' AND (length(pass)>0)' . |
|
| 380 | - " AND (login=$l)", |
|
| 381 | - '', |
|
| 382 | - '', |
|
| 383 | - '', |
|
| 384 | - '', |
|
| 385 | - $serveur |
|
| 386 | - ) |
|
| 387 | - ) { |
|
| 388 | - return $r; |
|
| 389 | - } |
|
| 390 | - // Si pas d'auteur avec ce login |
|
| 391 | - // regarder s'il a saisi son nom ou son mail. |
|
| 392 | - // Ne pas fusionner avec la requete precedente |
|
| 393 | - // car un nom peut etre homonyme d'un autre login |
|
| 394 | - else { |
|
| 395 | - return sql_getfetsel( |
|
| 396 | - 'login', |
|
| 397 | - 'spip_auteurs', |
|
| 398 | - "statut<>'5poubelle'" . |
|
| 399 | - ' AND (length(pass)>0)' . |
|
| 400 | - " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 401 | - '', |
|
| 402 | - '', |
|
| 403 | - '', |
|
| 404 | - '', |
|
| 405 | - $serveur |
|
| 406 | - ); |
|
| 407 | - } |
|
| 370 | + if (!strlen($login)) { |
|
| 371 | + return null; |
|
| 372 | + } // pas la peine de requeter |
|
| 373 | + $l = sql_quote($login, $serveur, 'text'); |
|
| 374 | + if ( |
|
| 375 | + $r = sql_getfetsel( |
|
| 376 | + 'login', |
|
| 377 | + 'spip_auteurs', |
|
| 378 | + "statut<>'5poubelle'" . |
|
| 379 | + ' AND (length(pass)>0)' . |
|
| 380 | + " AND (login=$l)", |
|
| 381 | + '', |
|
| 382 | + '', |
|
| 383 | + '', |
|
| 384 | + '', |
|
| 385 | + $serveur |
|
| 386 | + ) |
|
| 387 | + ) { |
|
| 388 | + return $r; |
|
| 389 | + } |
|
| 390 | + // Si pas d'auteur avec ce login |
|
| 391 | + // regarder s'il a saisi son nom ou son mail. |
|
| 392 | + // Ne pas fusionner avec la requete precedente |
|
| 393 | + // car un nom peut etre homonyme d'un autre login |
|
| 394 | + else { |
|
| 395 | + return sql_getfetsel( |
|
| 396 | + 'login', |
|
| 397 | + 'spip_auteurs', |
|
| 398 | + "statut<>'5poubelle'" . |
|
| 399 | + ' AND (length(pass)>0)' . |
|
| 400 | + " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 401 | + '', |
|
| 402 | + '', |
|
| 403 | + '', |
|
| 404 | + '', |
|
| 405 | + $serveur |
|
| 406 | + ); |
|
| 407 | + } |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -415,11 +415,11 @@ discard block |
||
| 415 | 415 | * toujours true pour un auteur cree dans SPIP |
| 416 | 416 | */ |
| 417 | 417 | function auth_spip_autoriser_modifier_pass(string $serveur = ''): bool { |
| 418 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 419 | - if (strlen($serveur)) { |
|
| 420 | - return false; |
|
| 421 | - } |
|
| 422 | - return true; |
|
| 418 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 419 | + if (strlen($serveur)) { |
|
| 420 | + return false; |
|
| 421 | + } |
|
| 422 | + return true; |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | |
@@ -440,12 +440,12 @@ discard block |
||
| 440 | 440 | * message d'erreur si login non valide, chaine vide sinon |
| 441 | 441 | */ |
| 442 | 442 | function auth_spip_verifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') { |
| 443 | - // login et mot de passe |
|
| 444 | - if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 445 | - return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 446 | - } |
|
| 443 | + // login et mot de passe |
|
| 444 | + if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 445 | + return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | - return ''; |
|
| 448 | + return ''; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -459,47 +459,47 @@ discard block |
||
| 459 | 459 | * @return bool |
| 460 | 460 | */ |
| 461 | 461 | function auth_spip_modifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') { |
| 462 | - if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 463 | - return false; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - if ( |
|
| 467 | - !$id_auteur = intval($id_auteur) |
|
| 468 | - or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 469 | - ) { |
|
| 470 | - return false; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - $cles = SpipCles::instance(); |
|
| 474 | - $secret = $cles->getSecretAuth(); |
|
| 475 | - if (!$secret) { |
|
| 476 | - if (auth_spip_initialiser_secret()) { |
|
| 477 | - $secret = $cles->getSecretAuth(); |
|
| 478 | - } |
|
| 479 | - else { |
|
| 480 | - return false; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - include_spip('inc/acces'); |
|
| 486 | - $set = [ |
|
| 487 | - 'pass' => Password::hacher($new_pass, $secret), |
|
| 488 | - 'htpass' => generer_htpass($new_pass), |
|
| 489 | - 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 490 | - 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 491 | - 'low_sec' => '', |
|
| 492 | - ]; |
|
| 493 | - |
|
| 494 | - // si c'est un webmestre, on met a jour son backup des cles |
|
| 495 | - if ($auteur['statut'] === '0minirezo' and $auteur['webmestre'] === 'oui') { |
|
| 496 | - $set['backup_cles'] = $cles->backup($new_pass); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - include_spip('action/editer_auteur'); |
|
| 500 | - auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 501 | - |
|
| 502 | - return true; // on a bien modifie le pass |
|
| 462 | + if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 463 | + return false; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + if ( |
|
| 467 | + !$id_auteur = intval($id_auteur) |
|
| 468 | + or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 469 | + ) { |
|
| 470 | + return false; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + $cles = SpipCles::instance(); |
|
| 474 | + $secret = $cles->getSecretAuth(); |
|
| 475 | + if (!$secret) { |
|
| 476 | + if (auth_spip_initialiser_secret()) { |
|
| 477 | + $secret = $cles->getSecretAuth(); |
|
| 478 | + } |
|
| 479 | + else { |
|
| 480 | + return false; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + include_spip('inc/acces'); |
|
| 486 | + $set = [ |
|
| 487 | + 'pass' => Password::hacher($new_pass, $secret), |
|
| 488 | + 'htpass' => generer_htpass($new_pass), |
|
| 489 | + 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 490 | + 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 491 | + 'low_sec' => '', |
|
| 492 | + ]; |
|
| 493 | + |
|
| 494 | + // si c'est un webmestre, on met a jour son backup des cles |
|
| 495 | + if ($auteur['statut'] === '0minirezo' and $auteur['webmestre'] === 'oui') { |
|
| 496 | + $set['backup_cles'] = $cles->backup($new_pass); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + include_spip('action/editer_auteur'); |
|
| 500 | + auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 501 | + |
|
| 502 | + return true; // on a bien modifie le pass |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** |
@@ -513,58 +513,58 @@ discard block |
||
| 513 | 513 | * @return void |
| 514 | 514 | */ |
| 515 | 515 | function auth_spip_synchroniser_distant($id_auteur, $champs, $options = [], string $serveur = ''): void { |
| 516 | - // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 517 | - if (strlen($serveur)) { |
|
| 518 | - return; |
|
| 519 | - } |
|
| 520 | - // si un login, pass ou statut a ete modifie |
|
| 521 | - // regenerer les fichier htpass |
|
| 522 | - if ( |
|
| 523 | - isset($champs['login']) |
|
| 524 | - or isset($champs['pass']) |
|
| 525 | - or isset($champs['statut']) |
|
| 526 | - or (isset($options['all']) and $options['all']) |
|
| 527 | - ) { |
|
| 528 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 529 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 530 | - |
|
| 531 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 532 | - // par exemple acces_restreint ; |
|
| 533 | - // si .htaccess existe, outrepasser spip_meta |
|
| 534 | - if ( |
|
| 535 | - (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 536 | - and !@file_exists($htaccess) |
|
| 537 | - ) { |
|
| 538 | - spip_unlink($htpasswd); |
|
| 539 | - spip_unlink($htpasswd . '-admin'); |
|
| 540 | - |
|
| 541 | - return; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 545 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 546 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 547 | - |
|
| 548 | - $p1 = ''; // login:htpass pour tous |
|
| 549 | - $p2 = ''; // login:htpass pour les admins |
|
| 550 | - $s = sql_select( |
|
| 551 | - 'login, htpass, statut', |
|
| 552 | - 'spip_auteurs', |
|
| 553 | - sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 554 | - ); |
|
| 555 | - while ($t = sql_fetch($s)) { |
|
| 556 | - if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 557 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 558 | - if ($t['statut'] == '0minirezo') { |
|
| 559 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - sql_free($s); |
|
| 564 | - if ($p1) { |
|
| 565 | - ecrire_fichier($htpasswd, $p1); |
|
| 566 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 567 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 568 | - } |
|
| 569 | - } |
|
| 516 | + // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 517 | + if (strlen($serveur)) { |
|
| 518 | + return; |
|
| 519 | + } |
|
| 520 | + // si un login, pass ou statut a ete modifie |
|
| 521 | + // regenerer les fichier htpass |
|
| 522 | + if ( |
|
| 523 | + isset($champs['login']) |
|
| 524 | + or isset($champs['pass']) |
|
| 525 | + or isset($champs['statut']) |
|
| 526 | + or (isset($options['all']) and $options['all']) |
|
| 527 | + ) { |
|
| 528 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 529 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 530 | + |
|
| 531 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 532 | + // par exemple acces_restreint ; |
|
| 533 | + // si .htaccess existe, outrepasser spip_meta |
|
| 534 | + if ( |
|
| 535 | + (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 536 | + and !@file_exists($htaccess) |
|
| 537 | + ) { |
|
| 538 | + spip_unlink($htpasswd); |
|
| 539 | + spip_unlink($htpasswd . '-admin'); |
|
| 540 | + |
|
| 541 | + return; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 545 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 546 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 547 | + |
|
| 548 | + $p1 = ''; // login:htpass pour tous |
|
| 549 | + $p2 = ''; // login:htpass pour les admins |
|
| 550 | + $s = sql_select( |
|
| 551 | + 'login, htpass, statut', |
|
| 552 | + 'spip_auteurs', |
|
| 553 | + sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 554 | + ); |
|
| 555 | + while ($t = sql_fetch($s)) { |
|
| 556 | + if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 557 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 558 | + if ($t['statut'] == '0minirezo') { |
|
| 559 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + sql_free($s); |
|
| 564 | + if ($p1) { |
|
| 565 | + ecrire_fichier($htpasswd, $p1); |
|
| 566 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 567 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | 570 | } |
@@ -11,77 +11,77 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | # Les information d'une rubrique selectionnee dans le mini navigateur |
| 18 | 18 | |
| 19 | 19 | function inc_informer_dist($id, $col, $exclus, $rac, $type, $do = 'aff') { |
| 20 | - include_spip('inc/texte'); |
|
| 21 | - $titre = $descriptif = ''; |
|
| 22 | - if ($type === 'rubrique') { |
|
| 23 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 24 | - if ($row) { |
|
| 25 | - $titre = typo($row['titre']); |
|
| 26 | - $descriptif = propre($row['descriptif']); |
|
| 27 | - } else { |
|
| 28 | - $titre = _T('info_racine_site'); |
|
| 29 | - } |
|
| 30 | - } |
|
| 20 | + include_spip('inc/texte'); |
|
| 21 | + $titre = $descriptif = ''; |
|
| 22 | + if ($type === 'rubrique') { |
|
| 23 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 24 | + if ($row) { |
|
| 25 | + $titre = typo($row['titre']); |
|
| 26 | + $descriptif = propre($row['descriptif']); |
|
| 27 | + } else { |
|
| 28 | + $titre = _T('info_racine_site'); |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $res = ''; |
|
| 33 | - if ( |
|
| 34 | - $type === 'rubrique' |
|
| 35 | - and intval($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 36 | - and isset($GLOBALS['meta']['image_process']) |
|
| 37 | - ) { |
|
| 38 | - if ($GLOBALS['meta']['image_process'] !== 'non') { |
|
| 39 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 40 | - if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 41 | - [$fid, $dir, $nom, $format] = $res; |
|
| 42 | - include_spip('inc/filtres_images_mini'); |
|
| 43 | - $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 44 | - if ($res) { |
|
| 45 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - } |
|
| 32 | + $res = ''; |
|
| 33 | + if ( |
|
| 34 | + $type === 'rubrique' |
|
| 35 | + and intval($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 36 | + and isset($GLOBALS['meta']['image_process']) |
|
| 37 | + ) { |
|
| 38 | + if ($GLOBALS['meta']['image_process'] !== 'non') { |
|
| 39 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 40 | + if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 41 | + [$fid, $dir, $nom, $format] = $res; |
|
| 42 | + include_spip('inc/filtres_images_mini'); |
|
| 43 | + $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 44 | + if ($res) { |
|
| 45 | + $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 52 | - $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 53 | - $id = intval($id); |
|
| 51 | + $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 52 | + $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 53 | + $id = intval($id); |
|
| 54 | 54 | |
| 55 | 55 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 56 | 56 | # et l'affichage de son titre dans le bandeau |
| 57 | - $titre = strtr( |
|
| 58 | - str_replace( |
|
| 59 | - "'", |
|
| 60 | - '’', |
|
| 61 | - str_replace('"', '"', textebrut($titre)) |
|
| 62 | - ), |
|
| 63 | - "\n\r", |
|
| 64 | - ' ' |
|
| 65 | - ); |
|
| 57 | + $titre = strtr( |
|
| 58 | + str_replace( |
|
| 59 | + "'", |
|
| 60 | + '’', |
|
| 61 | + str_replace('"', '"', textebrut($titre)) |
|
| 62 | + ), |
|
| 63 | + "\n\r", |
|
| 64 | + ' ' |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | - $js_func = $do . '_selection_titre'; |
|
| 67 | + $js_func = $do . '_selection_titre'; |
|
| 68 | 68 | |
| 69 | - return "<div style='display: none;'>" |
|
| 70 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 71 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 72 | - . entites_html($titre) |
|
| 73 | - . '" />' |
|
| 74 | - . '</div>' |
|
| 75 | - . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 76 | - . '<div class="informer__item">' |
|
| 77 | - . (!$res ? '' : $res) |
|
| 78 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 79 | - . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 80 | - . '</div>' |
|
| 81 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 82 | - . "<input type='submit' class='fondo btn submit' value='" |
|
| 83 | - . _T('bouton_choisir') |
|
| 84 | - . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 85 | - . '</div>' |
|
| 86 | - . '</div>'; |
|
| 69 | + return "<div style='display: none;'>" |
|
| 70 | + . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 71 | + . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 72 | + . entites_html($titre) |
|
| 73 | + . '" />' |
|
| 74 | + . '</div>' |
|
| 75 | + . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 76 | + . '<div class="informer__item">' |
|
| 77 | + . (!$res ? '' : $res) |
|
| 78 | + . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 79 | + . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 80 | + . '</div>' |
|
| 81 | + . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 82 | + . "<input type='submit' class='fondo btn submit' value='" |
|
| 83 | + . _T('bouton_choisir') |
|
| 84 | + . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 85 | + . '</div>' |
|
| 86 | + . '</div>'; |
|
| 87 | 87 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | include_spip('inc/texte'); |
| 21 | 21 | $titre = $descriptif = ''; |
| 22 | 22 | if ($type === 'rubrique') { |
| 23 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 23 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = '.intval($id)); |
|
| 24 | 24 | if ($row) { |
| 25 | 25 | $titre = typo($row['titre']); |
| 26 | 26 | $descriptif = propre($row['descriptif']); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | include_spip('inc/filtres_images_mini'); |
| 43 | 43 | $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
| 44 | 44 | if ($res) { |
| 45 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | + $res = "<div class='informer__media' style='float: ".$GLOBALS['spip_lang_right'].'; margin-'.$GLOBALS['spip_lang_right'].": -5px; margin-top: -5px;'>$res</div>"; |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -64,21 +64,21 @@ discard block |
||
| 64 | 64 | ' ' |
| 65 | 65 | ); |
| 66 | 66 | |
| 67 | - $js_func = $do . '_selection_titre'; |
|
| 67 | + $js_func = $do.'_selection_titre'; |
|
| 68 | 68 | |
| 69 | 69 | return "<div style='display: none;'>" |
| 70 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 71 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 70 | + . "<input type='text' id='".$rac."_sel' value='$id' />" |
|
| 71 | + . "<input type='text' id='".$rac."_sel2' value=\"" |
|
| 72 | 72 | . entites_html($titre) |
| 73 | 73 | . '" />' |
| 74 | 74 | . '</div>' |
| 75 | 75 | . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
| 76 | 76 | . '<div class="informer__item">' |
| 77 | 77 | . (!$res ? '' : $res) |
| 78 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 79 | - . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 78 | + . "<p class='informer__titre'><b>".safehtml($titre).'</b></p>' |
|
| 79 | + . (!$descriptif ? '' : "<div class='informer__descriptif'>".safehtml($descriptif).'</div>') |
|
| 80 | 80 | . '</div>' |
| 81 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 81 | + . "<div class='informer__action' style='clear:both; text-align: ".$GLOBALS['spip_lang_right'].";'>" |
|
| 82 | 82 | . "<input type='submit' class='fondo btn submit' value='" |
| 83 | 83 | . _T('bouton_choisir') |
| 84 | 84 | . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $titre = '[' |
| 91 | 91 | . $nom_site_spip |
| 92 | 92 | . ']' |
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | + . ($titre ? ' '.textebrut(typo($titre)) : ''); |
|
| 94 | 94 | |
| 95 | 95 | return _DOCTYPE_ECRIRE |
| 96 | 96 | . html_lang_attributes() |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | 135 | $res = pipeline('body_prive', "<body class='" |
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | + . init_body_class().' '._request('exec')."'" |
|
| 137 | 137 | . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
| 138 | 138 | . '>'); |
| 139 | 139 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -42,25 +42,25 @@ discard block |
||
| 42 | 42 | * @return string Code HTML |
| 43 | 43 | **/ |
| 44 | 44 | function inc_commencer_page_dist( |
| 45 | - $titre = '', |
|
| 46 | - $rubrique = 'accueil', |
|
| 47 | - $sous_rubrique = 'accueil', |
|
| 48 | - $id_rubrique = '', |
|
| 49 | - $menu = true, |
|
| 50 | - $minipres = false, |
|
| 51 | - $alertes = true |
|
| 45 | + $titre = '', |
|
| 46 | + $rubrique = 'accueil', |
|
| 47 | + $sous_rubrique = 'accueil', |
|
| 48 | + $id_rubrique = '', |
|
| 49 | + $menu = true, |
|
| 50 | + $minipres = false, |
|
| 51 | + $alertes = true |
|
| 52 | 52 | ) { |
| 53 | 53 | |
| 54 | - include_spip('inc/headers'); |
|
| 54 | + include_spip('inc/headers'); |
|
| 55 | 55 | |
| 56 | - http_no_cache(); |
|
| 56 | + http_no_cache(); |
|
| 57 | 57 | |
| 58 | - return init_entete($titre, $id_rubrique, $minipres) |
|
| 59 | - . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 60 | - . "<div id='page'>" |
|
| 61 | - . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 62 | - . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 63 | - . '<div class="largeur">'; |
|
| 58 | + return init_entete($titre, $id_rubrique, $minipres) |
|
| 59 | + . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 60 | + . "<div id='page'>" |
|
| 61 | + . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 62 | + . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 63 | + . '<div class="largeur">'; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -81,21 +81,21 @@ discard block |
||
| 81 | 81 | * Entête du fichier HTML avec le DOCTYPE |
| 82 | 82 | */ |
| 83 | 83 | function init_entete($titre = '', $dummy = 0, $minipres = false) { |
| 84 | - include_spip('inc/texte'); |
|
| 85 | - if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 86 | - $nom_site_spip = _T('info_mon_site_spip'); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $titre = '[' |
|
| 90 | - . $nom_site_spip |
|
| 91 | - . ']' |
|
| 92 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | - |
|
| 94 | - return _DOCTYPE_ECRIRE |
|
| 95 | - . html_lang_attributes() |
|
| 96 | - . "<head>\n" |
|
| 97 | - . init_head($titre, $dummy, $minipres) |
|
| 98 | - . "</head>\n"; |
|
| 84 | + include_spip('inc/texte'); |
|
| 85 | + if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 86 | + $nom_site_spip = _T('info_mon_site_spip'); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $titre = '[' |
|
| 90 | + . $nom_site_spip |
|
| 91 | + . ']' |
|
| 92 | + . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | + |
|
| 94 | + return _DOCTYPE_ECRIRE |
|
| 95 | + . html_lang_attributes() |
|
| 96 | + . "<head>\n" |
|
| 97 | + . init_head($titre, $dummy, $minipres) |
|
| 98 | + . "</head>\n"; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | 111 | function init_head($titre = '', $dummy = 0, $minipres = false) { |
| 112 | - return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 112 | + return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -131,20 +131,20 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 133 | 133 | |
| 134 | - $res = pipeline('body_prive', "<body class='" |
|
| 135 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | - . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 137 | - . '>'); |
|
| 134 | + $res = pipeline('body_prive', "<body class='" |
|
| 135 | + . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | + . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 137 | + . '>'); |
|
| 138 | 138 | |
| 139 | - if (!$menu) { |
|
| 140 | - return $res; |
|
| 141 | - } |
|
| 139 | + if (!$menu) { |
|
| 140 | + return $res; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | |
| 144 | - $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 144 | + $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 145 | 145 | |
| 146 | - return $res |
|
| 147 | - . $bandeau(); |
|
| 146 | + return $res |
|
| 147 | + . $bandeau(); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -156,23 +156,23 @@ discard block |
||
| 156 | 156 | * @return string Classes CSS (séparées par des espaces) |
| 157 | 157 | */ |
| 158 | 158 | function init_body_class() { |
| 159 | - $display_modes = [ |
|
| 160 | - 0 => 'icones_img_texte' // défaut. |
|
| 161 | - /*init*/, |
|
| 162 | - 1 => 'icones_texte', |
|
| 163 | - 2 => 'icones_img_texte', |
|
| 164 | - 3 => 'icones_img' |
|
| 165 | - ]; |
|
| 159 | + $display_modes = [ |
|
| 160 | + 0 => 'icones_img_texte' // défaut. |
|
| 161 | + /*init*/, |
|
| 162 | + 1 => 'icones_texte', |
|
| 163 | + 2 => 'icones_img_texte', |
|
| 164 | + 3 => 'icones_img' |
|
| 165 | + ]; |
|
| 166 | 166 | |
| 167 | - $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 167 | + $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 168 | 168 | |
| 169 | - $display_mode = $display_modes[(int) ($prefs['display'] ?? 0)] ?? $display_modes[0]; |
|
| 170 | - $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 169 | + $display_mode = $display_modes[(int) ($prefs['display'] ?? 0)] ?? $display_modes[0]; |
|
| 170 | + $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 171 | 171 | |
| 172 | - $couleur = (int) ($prefs['couleur'] ?? 2); |
|
| 172 | + $couleur = (int) ($prefs['couleur'] ?? 2); |
|
| 173 | 173 | |
| 174 | - $classes = "spip-theme-colors-$couleur $spip_display_navigation $display_mode"; |
|
| 175 | - return spip_sanitize_classname($classes); |
|
| 174 | + $classes = "spip-theme-colors-$couleur $spip_display_navigation $display_mode"; |
|
| 175 | + return spip_sanitize_classname($classes); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -183,5 +183,5 @@ discard block |
||
| 183 | 183 | * @return string |
| 184 | 184 | */ |
| 185 | 185 | function auteurs_recemment_connectes($id_auteur) { |
| 186 | - return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 186 | + return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 187 | 187 | } |