@@ -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/actions'); |
@@ -47,30 +47,30 @@ discard block |
||
| 47 | 47 | * Environnement du formulaire |
| 48 | 48 | **/ |
| 49 | 49 | function formulaires_editer_rubrique_charger_dist( |
| 50 | - $id_rubrique = 'new', |
|
| 51 | - $id_parent = 0, |
|
| 52 | - $retour = '', |
|
| 53 | - $lier_trad = 0, |
|
| 54 | - $config_fonc = 'rubriques_edit_config', |
|
| 55 | - $row = [], |
|
| 56 | - $hidden = '' |
|
| 50 | + $id_rubrique = 'new', |
|
| 51 | + $id_parent = 0, |
|
| 52 | + $retour = '', |
|
| 53 | + $lier_trad = 0, |
|
| 54 | + $config_fonc = 'rubriques_edit_config', |
|
| 55 | + $row = [], |
|
| 56 | + $hidden = '' |
|
| 57 | 57 | ) { |
| 58 | - $valeurs = formulaires_editer_objet_charger( |
|
| 59 | - 'rubrique', |
|
| 60 | - $id_rubrique, |
|
| 61 | - $id_parent, |
|
| 62 | - $lier_trad, |
|
| 63 | - $retour, |
|
| 64 | - $config_fonc, |
|
| 65 | - $row, |
|
| 66 | - $hidden |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - if (intval($id_rubrique) and !autoriser('modifier', 'rubrique', intval($id_rubrique))) { |
|
| 70 | - $valeurs['editable'] = ''; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return $valeurs; |
|
| 58 | + $valeurs = formulaires_editer_objet_charger( |
|
| 59 | + 'rubrique', |
|
| 60 | + $id_rubrique, |
|
| 61 | + $id_parent, |
|
| 62 | + $lier_trad, |
|
| 63 | + $retour, |
|
| 64 | + $config_fonc, |
|
| 65 | + $row, |
|
| 66 | + $hidden |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + if (intval($id_rubrique) and !autoriser('modifier', 'rubrique', intval($id_rubrique))) { |
|
| 70 | + $valeurs['editable'] = ''; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return $valeurs; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | function rubriques_edit_config(array $row): array { |
| 85 | 85 | |
| 86 | - $config = []; |
|
| 87 | - $config['lignes'] = 8; |
|
| 88 | - $config['langue'] = $GLOBALS['spip_lang']; |
|
| 89 | - $config['restreint'] = (!$GLOBALS['connect_toutes_rubriques']); |
|
| 86 | + $config = []; |
|
| 87 | + $config['lignes'] = 8; |
|
| 88 | + $config['langue'] = $GLOBALS['spip_lang']; |
|
| 89 | + $config['restreint'] = (!$GLOBALS['connect_toutes_rubriques']); |
|
| 90 | 90 | |
| 91 | - return $config; |
|
| 91 | + return $config; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -113,15 +113,15 @@ discard block |
||
| 113 | 113 | * Hash du formulaire |
| 114 | 114 | */ |
| 115 | 115 | function formulaires_editer_rubrique_identifier_dist( |
| 116 | - $id_rubrique = 'new', |
|
| 117 | - $id_parent = 0, |
|
| 118 | - $retour = '', |
|
| 119 | - $lier_trad = 0, |
|
| 120 | - $config_fonc = 'rubriques_edit_config', |
|
| 121 | - $row = [], |
|
| 122 | - $hidden = '' |
|
| 116 | + $id_rubrique = 'new', |
|
| 117 | + $id_parent = 0, |
|
| 118 | + $retour = '', |
|
| 119 | + $lier_trad = 0, |
|
| 120 | + $config_fonc = 'rubriques_edit_config', |
|
| 121 | + $row = [], |
|
| 122 | + $hidden = '' |
|
| 123 | 123 | ) { |
| 124 | - return serialize([intval($id_rubrique), $lier_trad]); |
|
| 124 | + return serialize([intval($id_rubrique), $lier_trad]); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -147,34 +147,34 @@ discard block |
||
| 147 | 147 | * Erreurs du formulaire |
| 148 | 148 | **/ |
| 149 | 149 | function formulaires_editer_rubrique_verifier_dist( |
| 150 | - $id_rubrique = 'new', |
|
| 151 | - $id_parent = 0, |
|
| 152 | - $retour = '', |
|
| 153 | - $lier_trad = 0, |
|
| 154 | - $config_fonc = 'rubriques_edit_config', |
|
| 155 | - $row = [], |
|
| 156 | - $hidden = '' |
|
| 150 | + $id_rubrique = 'new', |
|
| 151 | + $id_parent = 0, |
|
| 152 | + $retour = '', |
|
| 153 | + $lier_trad = 0, |
|
| 154 | + $config_fonc = 'rubriques_edit_config', |
|
| 155 | + $row = [], |
|
| 156 | + $hidden = '' |
|
| 157 | 157 | ) { |
| 158 | - // auto-renseigner le titre si il n'existe pas |
|
| 159 | - titre_automatique('titre', ['descriptif', 'texte']); |
|
| 160 | - // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_rubrique si vide |
|
| 161 | - $erreurs = formulaires_editer_objet_verifier('rubrique', $id_rubrique, []); |
|
| 162 | - |
|
| 163 | - // s'assurer qu'on ne s'auto-designe pas comme parent ! |
|
| 164 | - if ( |
|
| 165 | - intval($id_rubrique) |
|
| 166 | - and empty($erreurs['id_parent']) |
|
| 167 | - and $id_parent = _request('id_parent') |
|
| 168 | - ) { |
|
| 169 | - include_spip('inc/rubriques'); |
|
| 170 | - $branche = calcul_branche_in($id_rubrique); |
|
| 171 | - $branche = explode(',', $branche); |
|
| 172 | - if (in_array($id_parent, $branche)) { |
|
| 173 | - $erreurs['id_parent'] = _L('Impossible de déplacer une rubrique dans sa propre branche, on tourne en rond !'); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $erreurs; |
|
| 158 | + // auto-renseigner le titre si il n'existe pas |
|
| 159 | + titre_automatique('titre', ['descriptif', 'texte']); |
|
| 160 | + // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_rubrique si vide |
|
| 161 | + $erreurs = formulaires_editer_objet_verifier('rubrique', $id_rubrique, []); |
|
| 162 | + |
|
| 163 | + // s'assurer qu'on ne s'auto-designe pas comme parent ! |
|
| 164 | + if ( |
|
| 165 | + intval($id_rubrique) |
|
| 166 | + and empty($erreurs['id_parent']) |
|
| 167 | + and $id_parent = _request('id_parent') |
|
| 168 | + ) { |
|
| 169 | + include_spip('inc/rubriques'); |
|
| 170 | + $branche = calcul_branche_in($id_rubrique); |
|
| 171 | + $branche = explode(',', $branche); |
|
| 172 | + if (in_array($id_parent, $branche)) { |
|
| 173 | + $erreurs['id_parent'] = _L('Impossible de déplacer une rubrique dans sa propre branche, on tourne en rond !'); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $erreurs; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -200,22 +200,22 @@ discard block |
||
| 200 | 200 | * Retour des traitements |
| 201 | 201 | **/ |
| 202 | 202 | function formulaires_editer_rubrique_traiter_dist( |
| 203 | - $id_rubrique = 'new', |
|
| 204 | - $id_parent = 0, |
|
| 205 | - $retour = '', |
|
| 206 | - $lier_trad = 0, |
|
| 207 | - $config_fonc = 'rubriques_edit_config', |
|
| 208 | - $row = [], |
|
| 209 | - $hidden = '' |
|
| 203 | + $id_rubrique = 'new', |
|
| 204 | + $id_parent = 0, |
|
| 205 | + $retour = '', |
|
| 206 | + $lier_trad = 0, |
|
| 207 | + $config_fonc = 'rubriques_edit_config', |
|
| 208 | + $row = [], |
|
| 209 | + $hidden = '' |
|
| 210 | 210 | ) { |
| 211 | - return formulaires_editer_objet_traiter( |
|
| 212 | - 'rubrique', |
|
| 213 | - $id_rubrique, |
|
| 214 | - $id_parent, |
|
| 215 | - $lier_trad, |
|
| 216 | - $retour, |
|
| 217 | - $config_fonc, |
|
| 218 | - $row, |
|
| 219 | - $hidden |
|
| 220 | - ); |
|
| 211 | + return formulaires_editer_objet_traiter( |
|
| 212 | + 'rubrique', |
|
| 213 | + $id_rubrique, |
|
| 214 | + $id_parent, |
|
| 215 | + $lier_trad, |
|
| 216 | + $retour, |
|
| 217 | + $config_fonc, |
|
| 218 | + $row, |
|
| 219 | + $hidden |
|
| 220 | + ); |
|
| 221 | 221 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * Mot de passe |
| 32 | 32 | **/ |
| 33 | 33 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 34 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 34 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 35 | 35 | |
| 36 | 36 | mt_srand($seed); |
| 37 | 37 | $s = ''; |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | if (!$s) { |
| 43 | 43 | $s = random_int(0, mt_getrandmax()); |
| 44 | 44 | } |
| 45 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 45 | + $s = substr(md5(uniqid($s).$sel), 0, 16); |
|
| 46 | 46 | } |
| 47 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 47 | + $r = unpack('Cr', pack('H2', $s.$s)); |
|
| 48 | 48 | $x = $r['r'] & 63; |
| 49 | 49 | if ($x < 10) { |
| 50 | 50 | $x = chr($x + 48); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | static $seeded; |
| 83 | 83 | |
| 84 | 84 | if (!$seeded) { |
| 85 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 85 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 86 | 86 | mt_srand($seed); |
| 87 | 87 | $seeded = true; |
| 88 | 88 | } |
@@ -168,10 +168,10 @@ discard block |
||
| 168 | 168 | ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
| 169 | 169 | } |
| 170 | 170 | } else { |
| 171 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 171 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.intval($id_auteur)); |
|
| 172 | 172 | if (!$low_sec) { |
| 173 | 173 | $low_sec = creer_pass_aleatoire(); |
| 174 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 174 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = '.intval($id_auteur)); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 230 | 230 | $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
| 231 | 231 | $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
| 232 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 232 | + $path = "$id_auteur/$cle/$format/$fond".($path ? "/$path" : ''); |
|
| 233 | 233 | |
| 234 | 234 | return generer_url_api($script, $path, $args, $no_entities = false, $public); |
| 235 | 235 | } |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | foreach ($args as $val => $var) { |
| 254 | 254 | if ($var) { |
| 255 | 255 | if ($val <> 'statut') { |
| 256 | - $a .= ':' . $val . '-' . $var; |
|
| 256 | + $a .= ':'.$val.'-'.$var; |
|
| 257 | 257 | } |
| 258 | - $b .= $val . '=' . $var . '&'; |
|
| 258 | + $b .= $val.'='.$var.'&'; |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | $a = substr($a, 1); |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * Clé |
| 286 | 286 | **/ |
| 287 | 287 | function afficher_low_sec($id_auteur, $action = '') { |
| 288 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 288 | + return substr(md5($action.low_sec($id_auteur)), 0, 8); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | if (!$id_auteur = intval($id_auteur)) { |
| 317 | 317 | return; |
| 318 | 318 | } // jamais trop prudent ;) |
| 319 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 319 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = '.intval($id_auteur)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | * - void sinon. |
| 335 | 335 | **/ |
| 336 | 336 | function ecrire_acces() { |
| 337 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 338 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 337 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 338 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 339 | 339 | |
| 340 | 340 | // Cette variable de configuration peut etre posee par un plugin |
| 341 | 341 | // par exemple acces_restreint ; |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | and !@file_exists($htaccess) |
| 347 | 347 | ) { |
| 348 | 348 | spip_unlink($htpasswd); |
| 349 | - spip_unlink($htpasswd . '-admin'); |
|
| 349 | + spip_unlink($htpasswd.'-admin'); |
|
| 350 | 350 | return; |
| 351 | 351 | } |
| 352 | 352 | |
@@ -374,10 +374,10 @@ discard block |
||
| 374 | 374 | $pwd_all = ''; // login:htpass pour tous |
| 375 | 375 | $pwd_admin = ''; // login:htpass pour les admins |
| 376 | 376 | |
| 377 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 377 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND ".sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 378 | 378 | while ($row = sql_fetch($res)) { |
| 379 | 379 | if (strlen($row['login']) and strlen($row['htpass'])) { |
| 380 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 380 | + $ligne = $row['login'].':'.$row['htpass']."\n"; |
|
| 381 | 381 | $pwd_all .= $ligne; |
| 382 | 382 | if ($row['statut'] == '0minirezo') { |
| 383 | 383 | $pwd_admin .= $ligne; |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | * @return boolean |
| 421 | 421 | */ |
| 422 | 422 | function verifier_htaccess($rep, $force = false) { |
| 423 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 423 | + $htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME; |
|
| 424 | 424 | if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
| 425 | 425 | return true; |
| 426 | 426 | } |
@@ -449,17 +449,17 @@ discard block |
||
| 449 | 449 | fputs($ht, $deny); |
| 450 | 450 | fclose($ht); |
| 451 | 451 | @chmod($htaccess, _SPIP_CHMOD & 0666); |
| 452 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 452 | + $t = rtrim($rep, '/').'/.ok'; |
|
| 453 | 453 | if ($ht = @fopen($t, 'w')) { |
| 454 | 454 | @fclose($ht); |
| 455 | 455 | include_spip('inc/distant'); |
| 456 | 456 | $t = substr($t, strlen(_DIR_RACINE)); |
| 457 | - $t = url_de_base() . $t; |
|
| 457 | + $t = url_de_base().$t; |
|
| 458 | 458 | $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
| 459 | 459 | $ht = ($ht['status'] ?? null) === 403; |
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 462 | + spip_log("Creation de $htaccess ".($ht ? ' reussie' : ' manquee')); |
|
| 463 | 463 | |
| 464 | 464 | return $ht; |
| 465 | 465 | } |
@@ -485,11 +485,11 @@ discard block |
||
| 485 | 485 | $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
| 486 | 486 | $dirs[] = ['extension' => 'distant']; |
| 487 | 487 | foreach ($dirs as $e) { |
| 488 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 488 | + if (is_dir($dir = _DIR_IMG.$e['extension'])) { |
|
| 489 | 489 | if ($f) { |
| 490 | 490 | verifier_htaccess($dir); |
| 491 | 491 | } else { |
| 492 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 492 | + spip_unlink($dir.'/'._ACCESS_FILE_NAME); |
|
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | 495 | } |
@@ -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 | /** |
@@ -30,46 +30,46 @@ discard block |
||
| 30 | 30 | * Mot de passe |
| 31 | 31 | **/ |
| 32 | 32 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 33 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 34 | - |
|
| 35 | - mt_srand($seed); |
|
| 36 | - $s = ''; |
|
| 37 | - $pass = ''; |
|
| 38 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 39 | - if (!$s) { |
|
| 40 | - $s = random_int(0, mt_getrandmax()); |
|
| 41 | - if (!$s) { |
|
| 42 | - $s = random_int(0, mt_getrandmax()); |
|
| 43 | - } |
|
| 44 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 45 | - } |
|
| 46 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 47 | - $x = $r['r'] & 63; |
|
| 48 | - if ($x < 10) { |
|
| 49 | - $x = chr($x + 48); |
|
| 50 | - } else { |
|
| 51 | - if ($x < 36) { |
|
| 52 | - $x = chr($x + 55); |
|
| 53 | - } else { |
|
| 54 | - if ($x < 62) { |
|
| 55 | - $x = chr($x + 61); |
|
| 56 | - } else { |
|
| 57 | - if ($x == 63) { |
|
| 58 | - $x = '/'; |
|
| 59 | - } else { |
|
| 60 | - $x = '.'; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - $pass .= $x; |
|
| 66 | - $s = substr($s, 2); |
|
| 67 | - } |
|
| 68 | - $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 69 | - $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 70 | - $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 71 | - |
|
| 72 | - return $pass; |
|
| 33 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 34 | + |
|
| 35 | + mt_srand($seed); |
|
| 36 | + $s = ''; |
|
| 37 | + $pass = ''; |
|
| 38 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 39 | + if (!$s) { |
|
| 40 | + $s = random_int(0, mt_getrandmax()); |
|
| 41 | + if (!$s) { |
|
| 42 | + $s = random_int(0, mt_getrandmax()); |
|
| 43 | + } |
|
| 44 | + $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 45 | + } |
|
| 46 | + $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 47 | + $x = $r['r'] & 63; |
|
| 48 | + if ($x < 10) { |
|
| 49 | + $x = chr($x + 48); |
|
| 50 | + } else { |
|
| 51 | + if ($x < 36) { |
|
| 52 | + $x = chr($x + 55); |
|
| 53 | + } else { |
|
| 54 | + if ($x < 62) { |
|
| 55 | + $x = chr($x + 61); |
|
| 56 | + } else { |
|
| 57 | + if ($x == 63) { |
|
| 58 | + $x = '/'; |
|
| 59 | + } else { |
|
| 60 | + $x = '.'; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + $pass .= $x; |
|
| 66 | + $s = substr($s, 2); |
|
| 67 | + } |
|
| 68 | + $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 69 | + $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 70 | + $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 71 | + |
|
| 72 | + return $pass; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -78,20 +78,20 @@ discard block |
||
| 78 | 78 | * @return string Identifiant |
| 79 | 79 | */ |
| 80 | 80 | function creer_uniqid() { |
| 81 | - static $seeded; |
|
| 81 | + static $seeded; |
|
| 82 | 82 | |
| 83 | - if (!$seeded) { |
|
| 84 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 85 | - mt_srand($seed); |
|
| 86 | - $seeded = true; |
|
| 87 | - } |
|
| 83 | + if (!$seeded) { |
|
| 84 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 85 | + mt_srand($seed); |
|
| 86 | + $seeded = true; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - $s = random_int(0, mt_getrandmax()); |
|
| 90 | - if (!$s) { |
|
| 91 | - $s = random_int(0, mt_getrandmax()); |
|
| 92 | - } |
|
| 89 | + $s = random_int(0, mt_getrandmax()); |
|
| 90 | + if (!$s) { |
|
| 91 | + $s = random_int(0, mt_getrandmax()); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return uniqid($s, 1); |
|
| 94 | + return uniqid($s, 1); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -105,42 +105,42 @@ discard block |
||
| 105 | 105 | * @return string Retourne l'alea éphemère actuel au passage |
| 106 | 106 | */ |
| 107 | 107 | function charger_aleas() { |
| 108 | - if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 109 | - include_spip('base/abstract_sql'); |
|
| 110 | - $aleas = sql_allfetsel( |
|
| 111 | - ['nom', 'valeur'], |
|
| 112 | - 'spip_meta', |
|
| 113 | - sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 114 | - '', |
|
| 115 | - '', |
|
| 116 | - '', |
|
| 117 | - '', |
|
| 118 | - '', |
|
| 119 | - 'continue' |
|
| 120 | - ); |
|
| 121 | - if ($aleas) { |
|
| 122 | - foreach ($aleas as $a) { |
|
| 123 | - $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 124 | - } |
|
| 125 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 126 | - } else { |
|
| 127 | - spip_log('aleas indisponibles', 'session'); |
|
| 128 | - return ''; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 108 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 109 | + include_spip('base/abstract_sql'); |
|
| 110 | + $aleas = sql_allfetsel( |
|
| 111 | + ['nom', 'valeur'], |
|
| 112 | + 'spip_meta', |
|
| 113 | + sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 114 | + '', |
|
| 115 | + '', |
|
| 116 | + '', |
|
| 117 | + '', |
|
| 118 | + '', |
|
| 119 | + 'continue' |
|
| 120 | + ); |
|
| 121 | + if ($aleas) { |
|
| 122 | + foreach ($aleas as $a) { |
|
| 123 | + $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 124 | + } |
|
| 125 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 126 | + } else { |
|
| 127 | + spip_log('aleas indisponibles', 'session'); |
|
| 128 | + return ''; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | 135 | * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`) |
| 136 | 136 | **/ |
| 137 | 137 | function renouvelle_alea() { |
| 138 | - charger_aleas(); |
|
| 139 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 140 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 141 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 142 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 143 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 138 | + charger_aleas(); |
|
| 139 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 140 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 141 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 142 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 143 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | |
@@ -160,21 +160,21 @@ discard block |
||
| 160 | 160 | * Clé de sécurité. |
| 161 | 161 | **/ |
| 162 | 162 | function low_sec($id_auteur) { |
| 163 | - // Pas d'id_auteur : low_sec |
|
| 164 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 165 | - include_spip('inc/config'); |
|
| 166 | - if (!$low_sec = lire_config('low_sec')) { |
|
| 167 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 168 | - } |
|
| 169 | - } else { |
|
| 170 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 171 | - if (!$low_sec) { |
|
| 172 | - $low_sec = creer_pass_aleatoire(); |
|
| 173 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $low_sec; |
|
| 163 | + // Pas d'id_auteur : low_sec |
|
| 164 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 165 | + include_spip('inc/config'); |
|
| 166 | + if (!$low_sec = lire_config('low_sec')) { |
|
| 167 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 168 | + } |
|
| 169 | + } else { |
|
| 170 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 171 | + if (!$low_sec) { |
|
| 172 | + $low_sec = creer_pass_aleatoire(); |
|
| 173 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $low_sec; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -207,11 +207,11 @@ discard block |
||
| 207 | 207 | * @filtre |
| 208 | 208 | */ |
| 209 | 209 | function securiser_acces_low_sec($id_auteur, #[\SensitiveParameter] $cle, $dir, $op = '', $args = '') { |
| 210 | - if ($op) { |
|
| 211 | - $dir .= " $op $args"; |
|
| 212 | - } |
|
| 210 | + if ($op) { |
|
| 211 | + $dir .= " $op $args"; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 214 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -226,11 +226,11 @@ discard block |
||
| 226 | 226 | * @return string |
| 227 | 227 | */ |
| 228 | 228 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 229 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 230 | - $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 231 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 229 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 230 | + $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 231 | + $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 232 | 232 | |
| 233 | - return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 233 | + return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
@@ -248,27 +248,27 @@ discard block |
||
| 248 | 248 | * @deprecated 4.1 |
| 249 | 249 | */ |
| 250 | 250 | function param_low_sec($op, $args = [], $lang = '', $mime = 'rss') { |
| 251 | - $a = $b = ''; |
|
| 252 | - foreach ($args as $val => $var) { |
|
| 253 | - if ($var) { |
|
| 254 | - if ($val <> 'statut') { |
|
| 255 | - $a .= ':' . $val . '-' . $var; |
|
| 256 | - } |
|
| 257 | - $b .= $val . '=' . $var . '&'; |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - $a = substr($a, 1); |
|
| 261 | - $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 262 | - |
|
| 263 | - return $b |
|
| 264 | - . 'op=' |
|
| 265 | - . $op |
|
| 266 | - . '&id=' |
|
| 267 | - . $id |
|
| 268 | - . '&cle=' |
|
| 269 | - . afficher_low_sec($id, "$mime $op $a") |
|
| 270 | - . (!$a ? '' : "&args=$a") |
|
| 271 | - . (!$lang ? '' : "&lang=$lang"); |
|
| 251 | + $a = $b = ''; |
|
| 252 | + foreach ($args as $val => $var) { |
|
| 253 | + if ($var) { |
|
| 254 | + if ($val <> 'statut') { |
|
| 255 | + $a .= ':' . $val . '-' . $var; |
|
| 256 | + } |
|
| 257 | + $b .= $val . '=' . $var . '&'; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + $a = substr($a, 1); |
|
| 261 | + $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 262 | + |
|
| 263 | + return $b |
|
| 264 | + . 'op=' |
|
| 265 | + . $op |
|
| 266 | + . '&id=' |
|
| 267 | + . $id |
|
| 268 | + . '&cle=' |
|
| 269 | + . afficher_low_sec($id, "$mime $op $a") |
|
| 270 | + . (!$a ? '' : "&args=$a") |
|
| 271 | + . (!$lang ? '' : "&lang=$lang"); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | * Clé |
| 285 | 285 | **/ |
| 286 | 286 | function afficher_low_sec($id_auteur, $action = '') { |
| 287 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 287 | + return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * true si les clés corresponde, false sinon |
| 303 | 303 | **/ |
| 304 | 304 | function verifier_low_sec($id_auteur, #[\SensitiveParameter] $cle, $action = '') { |
| 305 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 305 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -312,10 +312,10 @@ discard block |
||
| 312 | 312 | * Identifiant de l'auteur |
| 313 | 313 | **/ |
| 314 | 314 | function effacer_low_sec($id_auteur) { |
| 315 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 316 | - return; |
|
| 317 | - } // jamais trop prudent ;) |
|
| 318 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 315 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 316 | + return; |
|
| 317 | + } // jamais trop prudent ;) |
|
| 318 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | |
@@ -333,31 +333,31 @@ discard block |
||
| 333 | 333 | * - void sinon. |
| 334 | 334 | **/ |
| 335 | 335 | function ecrire_acces() { |
| 336 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 337 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 338 | - |
|
| 339 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 340 | - // par exemple acces_restreint ; |
|
| 341 | - // si .htaccess existe, outrepasser spip_meta |
|
| 342 | - if ( |
|
| 343 | - (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 344 | - or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 345 | - and !@file_exists($htaccess) |
|
| 346 | - ) { |
|
| 347 | - spip_unlink($htpasswd); |
|
| 348 | - spip_unlink($htpasswd . '-admin'); |
|
| 349 | - return; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 353 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 354 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 355 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 356 | - if (include_spip('auth/ldap') and auth_ldap_connect()) { |
|
| 357 | - return; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 336 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 337 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 338 | + |
|
| 339 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 340 | + // par exemple acces_restreint ; |
|
| 341 | + // si .htaccess existe, outrepasser spip_meta |
|
| 342 | + if ( |
|
| 343 | + (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 344 | + or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 345 | + and !@file_exists($htaccess) |
|
| 346 | + ) { |
|
| 347 | + spip_unlink($htpasswd); |
|
| 348 | + spip_unlink($htpasswd . '-admin'); |
|
| 349 | + return; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 353 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 354 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 355 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 356 | + if (include_spip('auth/ldap') and auth_ldap_connect()) { |
|
| 357 | + return; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -366,29 +366,29 @@ discard block |
||
| 366 | 366 | * @param $htpasswd_admin |
| 367 | 367 | */ |
| 368 | 368 | function generer_htpasswd_files($htpasswd, $htpasswd_admin) { |
| 369 | - if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 370 | - $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - $pwd_all = ''; // login:htpass pour tous |
|
| 374 | - $pwd_admin = ''; // login:htpass pour les admins |
|
| 375 | - |
|
| 376 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 377 | - while ($row = sql_fetch($res)) { |
|
| 378 | - if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 379 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 380 | - $pwd_all .= $ligne; |
|
| 381 | - if ($row['statut'] == '0minirezo') { |
|
| 382 | - $pwd_admin .= $ligne; |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - if ($pwd_all) { |
|
| 388 | - ecrire_fichier($htpasswd, $pwd_all); |
|
| 389 | - ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 390 | - spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 391 | - } |
|
| 369 | + if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 370 | + $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + $pwd_all = ''; // login:htpass pour tous |
|
| 374 | + $pwd_admin = ''; // login:htpass pour les admins |
|
| 375 | + |
|
| 376 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 377 | + while ($row = sql_fetch($res)) { |
|
| 378 | + if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 379 | + $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 380 | + $pwd_all .= $ligne; |
|
| 381 | + if ($row['statut'] == '0minirezo') { |
|
| 382 | + $pwd_admin .= $ligne; |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + if ($pwd_all) { |
|
| 388 | + ecrire_fichier($htpasswd, $pwd_all); |
|
| 389 | + ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 390 | + spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 391 | + } |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -402,11 +402,11 @@ discard block |
||
| 402 | 402 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 403 | 403 | */ |
| 404 | 404 | function generer_htpass(#[\SensitiveParameter] $pass) { |
| 405 | - if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 406 | - return $generer_htpass($pass); |
|
| 407 | - } |
|
| 405 | + if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 406 | + return $generer_htpass($pass); |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | - return ''; |
|
| 409 | + return ''; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -419,14 +419,14 @@ discard block |
||
| 419 | 419 | * @return boolean |
| 420 | 420 | */ |
| 421 | 421 | function verifier_htaccess($rep, $force = false) { |
| 422 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 423 | - if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 424 | - return true; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - // directive deny compatible Apache 2.0+ |
|
| 428 | - $deny = |
|
| 429 | - '# Deny all requests from Apache 2.4+. |
|
| 422 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 423 | + if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 424 | + return true; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + // directive deny compatible Apache 2.0+ |
|
| 428 | + $deny = |
|
| 429 | + '# Deny all requests from Apache 2.4+. |
|
| 430 | 430 | <IfModule mod_authz_core.c> |
| 431 | 431 | Require all denied |
| 432 | 432 | </IfModule> |
@@ -435,32 +435,32 @@ discard block |
||
| 435 | 435 | Deny from all |
| 436 | 436 | </IfModule> |
| 437 | 437 | '; |
| 438 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 439 | - if ( |
|
| 440 | - function_exists('apache_get_version') |
|
| 441 | - and $v = apache_get_version() |
|
| 442 | - and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 443 | - ) { |
|
| 444 | - $deny = "deny from all\n"; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 448 | - fputs($ht, $deny); |
|
| 449 | - fclose($ht); |
|
| 450 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 451 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 452 | - if ($ht = @fopen($t, 'w')) { |
|
| 453 | - @fclose($ht); |
|
| 454 | - include_spip('inc/distant'); |
|
| 455 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 456 | - $t = url_de_base() . $t; |
|
| 457 | - $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 458 | - $ht = ($ht['status'] ?? null) === 403; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 462 | - |
|
| 463 | - return $ht; |
|
| 438 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 439 | + if ( |
|
| 440 | + function_exists('apache_get_version') |
|
| 441 | + and $v = apache_get_version() |
|
| 442 | + and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 443 | + ) { |
|
| 444 | + $deny = "deny from all\n"; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 448 | + fputs($ht, $deny); |
|
| 449 | + fclose($ht); |
|
| 450 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 451 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 452 | + if ($ht = @fopen($t, 'w')) { |
|
| 453 | + @fclose($ht); |
|
| 454 | + include_spip('inc/distant'); |
|
| 455 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 456 | + $t = url_de_base() . $t; |
|
| 457 | + $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 458 | + $ht = ($ht['status'] ?? null) === 403; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 462 | + |
|
| 463 | + return $ht; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |
@@ -478,20 +478,20 @@ discard block |
||
| 478 | 478 | * Valeur de la configuration `creer_htaccess` |
| 479 | 479 | */ |
| 480 | 480 | function gerer_htaccess() { |
| 481 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 482 | - // par exemple acces_restreint |
|
| 483 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 484 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 485 | - $dirs[] = ['extension' => 'distant']; |
|
| 486 | - foreach ($dirs as $e) { |
|
| 487 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 488 | - if ($f) { |
|
| 489 | - verifier_htaccess($dir); |
|
| 490 | - } else { |
|
| 491 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 481 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 482 | + // par exemple acces_restreint |
|
| 483 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 484 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 485 | + $dirs[] = ['extension' => 'distant']; |
|
| 486 | + foreach ($dirs as $e) { |
|
| 487 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 488 | + if ($f) { |
|
| 489 | + verifier_htaccess($dir); |
|
| 490 | + } else { |
|
| 491 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 497 | 497 | } |
@@ -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 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Fonctions |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -29,29 +29,29 @@ discard block |
||
| 29 | 29 | * @param bool $left |
| 30 | 30 | */ |
| 31 | 31 | function critere_compteur_articles_filtres_dist($idb, &$boucles, $crit, $left = false) { |
| 32 | - $boucle = &$boucles[$idb]; |
|
| 32 | + $boucle = &$boucles[$idb]; |
|
| 33 | 33 | |
| 34 | - $_statut = calculer_liste($crit->param[0], [], $boucles, $boucle->id_parent); |
|
| 34 | + $_statut = calculer_liste($crit->param[0], [], $boucles, $boucle->id_parent); |
|
| 35 | 35 | |
| 36 | - $not = ''; |
|
| 37 | - if ($crit->not) { |
|
| 38 | - $not = ", 'NOT'"; |
|
| 39 | - } |
|
| 40 | - $boucle->from['LAA'] = 'spip_auteurs_liens'; |
|
| 41 | - $boucle->from_type['LAA'] = 'left'; |
|
| 42 | - $boucle->join['LAA'] = ["'auteurs'", "'id_auteur'", "'id_auteur'", "'LAA.objet=\'article\''"]; |
|
| 36 | + $not = ''; |
|
| 37 | + if ($crit->not) { |
|
| 38 | + $not = ", 'NOT'"; |
|
| 39 | + } |
|
| 40 | + $boucle->from['LAA'] = 'spip_auteurs_liens'; |
|
| 41 | + $boucle->from_type['LAA'] = 'left'; |
|
| 42 | + $boucle->join['LAA'] = ["'auteurs'", "'id_auteur'", "'id_auteur'", "'LAA.objet=\'article\''"]; |
|
| 43 | 43 | |
| 44 | - $boucle->from['articles'] = 'spip_articles'; |
|
| 45 | - $boucle->from_type['articles'] = 'left'; |
|
| 46 | - $boucle->join['articles'] = [ |
|
| 47 | - "'LAA'", |
|
| 48 | - "'id_article'", |
|
| 49 | - "'id_objet'", |
|
| 50 | - "'(articles.statut IS NULL OR '.sql_in_quote('articles.statut',[$_statut]$not).')'" |
|
| 51 | - ]; |
|
| 44 | + $boucle->from['articles'] = 'spip_articles'; |
|
| 45 | + $boucle->from_type['articles'] = 'left'; |
|
| 46 | + $boucle->join['articles'] = [ |
|
| 47 | + "'LAA'", |
|
| 48 | + "'id_article'", |
|
| 49 | + "'id_objet'", |
|
| 50 | + "'(articles.statut IS NULL OR '.sql_in_quote('articles.statut',[$_statut]$not).')'" |
|
| 51 | + ]; |
|
| 52 | 52 | |
| 53 | - $boucle->select[] = 'COUNT(articles.id_article) AS compteur_articles'; |
|
| 54 | - $boucle->group[] = 'auteurs.id_auteur'; |
|
| 53 | + $boucle->select[] = 'COUNT(articles.id_article) AS compteur_articles'; |
|
| 54 | + $boucle->group[] = 'auteurs.id_auteur'; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * Pile complétée par le code à générer |
| 70 | 70 | */ |
| 71 | 71 | function balise_COMPTEUR_ARTICLES_dist($p) { |
| 72 | - return rindex_pile($p, 'compteur_articles', 'compteur_articles_filtres'); |
|
| 72 | + return rindex_pile($p, 'compteur_articles', 'compteur_articles_filtres'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -85,44 +85,44 @@ discard block |
||
| 85 | 85 | * @return string |
| 86 | 86 | */ |
| 87 | 87 | function afficher_initiale($url, $initiale, $compteur, $debut, $pas) { |
| 88 | - static $memo = null; |
|
| 89 | - static $res = []; |
|
| 90 | - $out = ''; |
|
| 91 | - if ( |
|
| 92 | - !$memo |
|
| 93 | - or (!$initiale and !$url) |
|
| 94 | - or ($initiale !== $memo['initiale']) |
|
| 95 | - ) { |
|
| 96 | - $newcompt = intval(floor(($compteur - 1) / $pas) * $pas); |
|
| 97 | - // si fin de la pagination et une seule entree, ne pas l'afficher, ca ne sert a rien |
|
| 98 | - if (!$initiale and !$url and !$memo['compteur']) { |
|
| 99 | - $memo = null; |
|
| 100 | - } |
|
| 101 | - if ($memo) { |
|
| 102 | - $on = (($memo['compteur'] <= $debut) |
|
| 103 | - and ( |
|
| 104 | - $newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur']) |
|
| 105 | - )); |
|
| 106 | - $res[] = "<li class='pagination-item'>" . lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination') . '</li>'; |
|
| 107 | - } |
|
| 108 | - if ($initiale) { |
|
| 109 | - $memo = [ |
|
| 110 | - 'entree' => isset($memo['entree']) ? $memo['entree'] + 1 : 0, |
|
| 111 | - 'initiale' => $initiale, |
|
| 112 | - 'url' => parametre_url($url, 'i', $initiale), |
|
| 113 | - 'compteur' => $newcompt |
|
| 114 | - ]; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - if (!$initiale and !$url) { |
|
| 118 | - if ((is_countable($res) ? count($res) : 0) > 1) { |
|
| 119 | - $out = "<ul class='pagination-items'>" . implode(' ', $res) . '</ul>'; |
|
| 120 | - } |
|
| 121 | - $memo = null; |
|
| 122 | - $res = []; |
|
| 123 | - } |
|
| 88 | + static $memo = null; |
|
| 89 | + static $res = []; |
|
| 90 | + $out = ''; |
|
| 91 | + if ( |
|
| 92 | + !$memo |
|
| 93 | + or (!$initiale and !$url) |
|
| 94 | + or ($initiale !== $memo['initiale']) |
|
| 95 | + ) { |
|
| 96 | + $newcompt = intval(floor(($compteur - 1) / $pas) * $pas); |
|
| 97 | + // si fin de la pagination et une seule entree, ne pas l'afficher, ca ne sert a rien |
|
| 98 | + if (!$initiale and !$url and !$memo['compteur']) { |
|
| 99 | + $memo = null; |
|
| 100 | + } |
|
| 101 | + if ($memo) { |
|
| 102 | + $on = (($memo['compteur'] <= $debut) |
|
| 103 | + and ( |
|
| 104 | + $newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur']) |
|
| 105 | + )); |
|
| 106 | + $res[] = "<li class='pagination-item'>" . lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination') . '</li>'; |
|
| 107 | + } |
|
| 108 | + if ($initiale) { |
|
| 109 | + $memo = [ |
|
| 110 | + 'entree' => isset($memo['entree']) ? $memo['entree'] + 1 : 0, |
|
| 111 | + 'initiale' => $initiale, |
|
| 112 | + 'url' => parametre_url($url, 'i', $initiale), |
|
| 113 | + 'compteur' => $newcompt |
|
| 114 | + ]; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + if (!$initiale and !$url) { |
|
| 118 | + if ((is_countable($res) ? count($res) : 0) > 1) { |
|
| 119 | + $out = "<ul class='pagination-items'>" . implode(' ', $res) . '</ul>'; |
|
| 120 | + } |
|
| 121 | + $memo = null; |
|
| 122 | + $res = []; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - return $out; |
|
| 125 | + return $out; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -141,24 +141,24 @@ discard block |
||
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | 143 | function auteur_lien_messagerie($id_auteur, $en_ligne, $statut, $imessage, $email = '') { |
| 144 | - static $time = null; |
|
| 145 | - if (!in_array($statut, ['0minirezo', '1comite'])) { |
|
| 146 | - return ''; |
|
| 147 | - } |
|
| 144 | + static $time = null; |
|
| 145 | + if (!in_array($statut, ['0minirezo', '1comite'])) { |
|
| 146 | + return ''; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - if (is_null($time)) { |
|
| 150 | - $time = time(); |
|
| 151 | - } |
|
| 152 | - $parti = (($time - strtotime($en_ligne)) > 15 * 60); |
|
| 149 | + if (is_null($time)) { |
|
| 150 | + $time = time(); |
|
| 151 | + } |
|
| 152 | + $parti = (($time - strtotime($en_ligne)) > 15 * 60); |
|
| 153 | 153 | |
| 154 | - if ( |
|
| 155 | - $imessage != 'non' and !$parti // historique : est-ce que ca a encore un sens de limiter vu qu'on a la notification par email ? |
|
| 156 | - and $GLOBALS['meta']['messagerie_agenda'] != 'non' |
|
| 157 | - ) { |
|
| 158 | - return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self()); |
|
| 159 | - } elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) { |
|
| 160 | - return 'mailto:' . $email; |
|
| 161 | - } else { |
|
| 162 | - return ''; |
|
| 163 | - } |
|
| 154 | + if ( |
|
| 155 | + $imessage != 'non' and !$parti // historique : est-ce que ca a encore un sens de limiter vu qu'on a la notification par email ? |
|
| 156 | + and $GLOBALS['meta']['messagerie_agenda'] != 'non' |
|
| 157 | + ) { |
|
| 158 | + return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self()); |
|
| 159 | + } elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) { |
|
| 160 | + return 'mailto:' . $email; |
|
| 161 | + } else { |
|
| 162 | + return ''; |
|
| 163 | + } |
|
| 164 | 164 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | and ( |
| 104 | 104 | $newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur']) |
| 105 | 105 | )); |
| 106 | - $res[] = "<li class='pagination-item'>" . lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination') . '</li>'; |
|
| 106 | + $res[] = "<li class='pagination-item'>".lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination').'</li>'; |
|
| 107 | 107 | } |
| 108 | 108 | if ($initiale) { |
| 109 | 109 | $memo = [ |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | if (!$initiale and !$url) { |
| 118 | 118 | if ((is_countable($res) ? count($res) : 0) > 1) { |
| 119 | - $out = "<ul class='pagination-items'>" . implode(' ', $res) . '</ul>'; |
|
| 119 | + $out = "<ul class='pagination-items'>".implode(' ', $res).'</ul>'; |
|
| 120 | 120 | } |
| 121 | 121 | $memo = null; |
| 122 | 122 | $res = []; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | ) { |
| 158 | 158 | return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self()); |
| 159 | 159 | } elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) { |
| 160 | - return 'mailto:' . $email; |
|
| 160 | + return 'mailto:'.$email; |
|
| 161 | 161 | } else { |
| 162 | 162 | return ''; |
| 163 | 163 | } |
@@ -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) { |
@@ -11,109 +11,109 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function inc_log_dist($message, $logname = null, $logdir = null, $logsuf = null) { |
| 18 | - static $test_repertoire = []; |
|
| 19 | - static $compteur = []; |
|
| 20 | - static $debugverb = ''; // pour ne pas le recalculer au reappel |
|
| 21 | - |
|
| 22 | - if (is_null($logname) or !is_string($logname)) { |
|
| 23 | - $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; |
|
| 24 | - } |
|
| 25 | - if (!isset($compteur[$logname])) { |
|
| 26 | - $compteur[$logname] = 0; |
|
| 27 | - } |
|
| 28 | - if ( |
|
| 29 | - $logname != 'maj' |
|
| 30 | - and defined('_MAX_LOG') |
|
| 31 | - and ( |
|
| 32 | - $compteur[$logname]++ > _MAX_LOG |
|
| 33 | - or !$GLOBALS['nombre_de_logs'] |
|
| 34 | - or !$GLOBALS['taille_des_logs'] |
|
| 35 | - ) |
|
| 36 | - ) { |
|
| 37 | - return; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
|
| 41 | - $logfile = |
|
| 42 | - ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 43 | - . $logname |
|
| 44 | - . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
|
| 45 | - |
|
| 46 | - if (!isset($test_repertoire[$d = dirname($logfile)])) { |
|
| 47 | - $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire |
|
| 48 | - $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire( |
|
| 49 | - $d, |
|
| 50 | - '', |
|
| 51 | - false, |
|
| 52 | - true |
|
| 53 | - ) : false)); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Si le repertoire défini n'existe pas, poser dans tmp/ |
|
| 57 | - if (!$test_repertoire[$d]) { |
|
| 58 | - $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $rotate = 0; |
|
| 62 | - $pid = '(pid ' . @getmypid() . ')'; |
|
| 63 | - |
|
| 64 | - // accepter spip_log( Array ) |
|
| 65 | - if (!is_string($message)) { |
|
| 66 | - $message = var_export($message, true); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) { |
|
| 70 | - $debug = debug_backtrace(); |
|
| 71 | - $l = $debug[1]['line']; |
|
| 72 | - $fi = $debug[1]['file']; |
|
| 73 | - if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) { |
|
| 74 | - $fi = substr($fi, strlen(_ROOT_RACINE)); |
|
| 75 | - } |
|
| 76 | - $fu = $debug[2]['function'] ?? ''; |
|
| 77 | - $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 81 | - //distinguer les logs prives et publics dans les grep |
|
| 82 | - . $debugverb |
|
| 83 | - . (test_espace_prive() ? ':Pri:' : ':Pub:') |
|
| 84 | - . preg_replace("/\n*$/", "\n", $message); |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - if ( |
|
| 88 | - @is_readable($logfile) |
|
| 89 | - and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024) |
|
| 90 | - ) { |
|
| 91 | - $rotate = $GLOBALS['nombre_de_logs']; |
|
| 92 | - $m .= "[-- rotate --]\n"; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $f = @fopen($logfile, 'ab'); |
|
| 96 | - if ($f) { |
|
| 97 | - fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '<', $m)); |
|
| 98 | - fclose($f); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if ( |
|
| 102 | - $rotate-- > 0 |
|
| 103 | - and function_exists('spip_unlink') |
|
| 104 | - ) { |
|
| 105 | - spip_unlink($logfile . '.' . $rotate); |
|
| 106 | - while ($rotate--) { |
|
| 107 | - @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Dupliquer les erreurs specifiques dans le log general |
|
| 112 | - if ( |
|
| 113 | - defined('_FILE_LOG') |
|
| 114 | - and ($logname !== _FILE_LOG) |
|
| 115 | - ) { |
|
| 116 | - inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message); |
|
| 117 | - } |
|
| 118 | - $debugverb = ''; |
|
| 18 | + static $test_repertoire = []; |
|
| 19 | + static $compteur = []; |
|
| 20 | + static $debugverb = ''; // pour ne pas le recalculer au reappel |
|
| 21 | + |
|
| 22 | + if (is_null($logname) or !is_string($logname)) { |
|
| 23 | + $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; |
|
| 24 | + } |
|
| 25 | + if (!isset($compteur[$logname])) { |
|
| 26 | + $compteur[$logname] = 0; |
|
| 27 | + } |
|
| 28 | + if ( |
|
| 29 | + $logname != 'maj' |
|
| 30 | + and defined('_MAX_LOG') |
|
| 31 | + and ( |
|
| 32 | + $compteur[$logname]++ > _MAX_LOG |
|
| 33 | + or !$GLOBALS['nombre_de_logs'] |
|
| 34 | + or !$GLOBALS['taille_des_logs'] |
|
| 35 | + ) |
|
| 36 | + ) { |
|
| 37 | + return; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
|
| 41 | + $logfile = |
|
| 42 | + ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 43 | + . $logname |
|
| 44 | + . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
|
| 45 | + |
|
| 46 | + if (!isset($test_repertoire[$d = dirname($logfile)])) { |
|
| 47 | + $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire |
|
| 48 | + $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire( |
|
| 49 | + $d, |
|
| 50 | + '', |
|
| 51 | + false, |
|
| 52 | + true |
|
| 53 | + ) : false)); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Si le repertoire défini n'existe pas, poser dans tmp/ |
|
| 57 | + if (!$test_repertoire[$d]) { |
|
| 58 | + $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $rotate = 0; |
|
| 62 | + $pid = '(pid ' . @getmypid() . ')'; |
|
| 63 | + |
|
| 64 | + // accepter spip_log( Array ) |
|
| 65 | + if (!is_string($message)) { |
|
| 66 | + $message = var_export($message, true); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) { |
|
| 70 | + $debug = debug_backtrace(); |
|
| 71 | + $l = $debug[1]['line']; |
|
| 72 | + $fi = $debug[1]['file']; |
|
| 73 | + if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) { |
|
| 74 | + $fi = substr($fi, strlen(_ROOT_RACINE)); |
|
| 75 | + } |
|
| 76 | + $fu = $debug[2]['function'] ?? ''; |
|
| 77 | + $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 81 | + //distinguer les logs prives et publics dans les grep |
|
| 82 | + . $debugverb |
|
| 83 | + . (test_espace_prive() ? ':Pri:' : ':Pub:') |
|
| 84 | + . preg_replace("/\n*$/", "\n", $message); |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + if ( |
|
| 88 | + @is_readable($logfile) |
|
| 89 | + and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024) |
|
| 90 | + ) { |
|
| 91 | + $rotate = $GLOBALS['nombre_de_logs']; |
|
| 92 | + $m .= "[-- rotate --]\n"; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $f = @fopen($logfile, 'ab'); |
|
| 96 | + if ($f) { |
|
| 97 | + fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '<', $m)); |
|
| 98 | + fclose($f); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if ( |
|
| 102 | + $rotate-- > 0 |
|
| 103 | + and function_exists('spip_unlink') |
|
| 104 | + ) { |
|
| 105 | + spip_unlink($logfile . '.' . $rotate); |
|
| 106 | + while ($rotate--) { |
|
| 107 | + @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // Dupliquer les erreurs specifiques dans le log general |
|
| 112 | + if ( |
|
| 113 | + defined('_FILE_LOG') |
|
| 114 | + and ($logname !== _FILE_LOG) |
|
| 115 | + ) { |
|
| 116 | + inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message); |
|
| 117 | + } |
|
| 118 | + $debugverb = ''; |
|
| 119 | 119 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
| 41 | 41 | $logfile = |
| 42 | - ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 42 | + ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 43 | 43 | . $logname |
| 44 | 44 | . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
| 45 | 45 | |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | // Si le repertoire défini n'existe pas, poser dans tmp/ |
| 57 | 57 | if (!$test_repertoire[$d]) { |
| 58 | - $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 58 | + $logfile = _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES.$logname.'.log'; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $rotate = 0; |
| 62 | - $pid = '(pid ' . @getmypid() . ')'; |
|
| 62 | + $pid = '(pid '.@getmypid().')'; |
|
| 63 | 63 | |
| 64 | 64 | // accepter spip_log( Array ) |
| 65 | 65 | if (!is_string($message)) { |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | $fi = substr($fi, strlen(_ROOT_RACINE)); |
| 75 | 75 | } |
| 76 | 76 | $fu = $debug[2]['function'] ?? ''; |
| 77 | - $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 77 | + $debugverb = "$fi:L$l:$fu".'():'; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 80 | + $m = date('Y-m-d H:i:s').' '.($GLOBALS['ip'] ?? '').' '.$pid.' ' |
|
| 81 | 81 | //distinguer les logs prives et publics dans les grep |
| 82 | 82 | . $debugverb |
| 83 | 83 | . (test_espace_prive() ? ':Pri:' : ':Pub:') |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | $rotate-- > 0 |
| 103 | 103 | and function_exists('spip_unlink') |
| 104 | 104 | ) { |
| 105 | - spip_unlink($logfile . '.' . $rotate); |
|
| 105 | + spip_unlink($logfile.'.'.$rotate); |
|
| 106 | 106 | while ($rotate--) { |
| 107 | - @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 107 | + @rename($logfile.($rotate ? '.'.$rotate : ''), $logfile.'.'.($rotate + 1)); |
|
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
@@ -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 | } |
@@ -19,78 +19,78 @@ |
||
| 19 | 19 | * @link https://www.php.net/manual/fr/book.sodium.php |
| 20 | 20 | */ |
| 21 | 21 | class Chiffrement { |
| 22 | - /** Chiffre un message en utilisant une clé ou un mot de passe */ |
|
| 23 | - public static function chiffrer( |
|
| 24 | - string $message, |
|
| 25 | - #[\SensitiveParameter] |
|
| 26 | - string $key |
|
| 27 | - ): ?string { |
|
| 28 | - // create a random salt for key derivation |
|
| 29 | - $salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES); |
|
| 30 | - $key = self::deriveKeyFromPassword($key, $salt); |
|
| 31 | - $nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 32 | - $padded_message = sodium_pad($message, 16); |
|
| 33 | - $encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key); |
|
| 34 | - $encoded = base64_encode($salt . $nonce . $encrypted); |
|
| 35 | - sodium_memzero($key); |
|
| 36 | - sodium_memzero($nonce); |
|
| 37 | - sodium_memzero($salt); |
|
| 38 | - #spip_log("chiffrer($message)=$encoded", 'chiffrer' . _LOG_DEBUG); |
|
| 39 | - return $encoded; |
|
| 40 | - } |
|
| 22 | + /** Chiffre un message en utilisant une clé ou un mot de passe */ |
|
| 23 | + public static function chiffrer( |
|
| 24 | + string $message, |
|
| 25 | + #[\SensitiveParameter] |
|
| 26 | + string $key |
|
| 27 | + ): ?string { |
|
| 28 | + // create a random salt for key derivation |
|
| 29 | + $salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES); |
|
| 30 | + $key = self::deriveKeyFromPassword($key, $salt); |
|
| 31 | + $nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 32 | + $padded_message = sodium_pad($message, 16); |
|
| 33 | + $encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key); |
|
| 34 | + $encoded = base64_encode($salt . $nonce . $encrypted); |
|
| 35 | + sodium_memzero($key); |
|
| 36 | + sodium_memzero($nonce); |
|
| 37 | + sodium_memzero($salt); |
|
| 38 | + #spip_log("chiffrer($message)=$encoded", 'chiffrer' . _LOG_DEBUG); |
|
| 39 | + return $encoded; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** Déchiffre un message en utilisant une clé ou un mot de passe */ |
|
| 43 | - public static function dechiffrer( |
|
| 44 | - string $encoded, |
|
| 45 | - #[\SensitiveParameter] |
|
| 46 | - string $key |
|
| 47 | - ): ?string { |
|
| 48 | - $decoded = base64_decode($encoded); |
|
| 49 | - $salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES); |
|
| 50 | - $nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 51 | - $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 52 | - $key = self::deriveKeyFromPassword($key, $salt); |
|
| 53 | - $padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key); |
|
| 54 | - sodium_memzero($key); |
|
| 55 | - sodium_memzero($nonce); |
|
| 56 | - sodium_memzero($salt); |
|
| 57 | - if ($padded_message === false) { |
|
| 58 | - spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG); |
|
| 59 | - return null; |
|
| 60 | - } |
|
| 61 | - $message = sodium_unpad($padded_message, 16); |
|
| 62 | - #spip_log("dechiffrer($encoded)=$message", 'chiffrer' . _LOG_DEBUG); |
|
| 63 | - return $message; |
|
| 64 | - } |
|
| 42 | + /** Déchiffre un message en utilisant une clé ou un mot de passe */ |
|
| 43 | + public static function dechiffrer( |
|
| 44 | + string $encoded, |
|
| 45 | + #[\SensitiveParameter] |
|
| 46 | + string $key |
|
| 47 | + ): ?string { |
|
| 48 | + $decoded = base64_decode($encoded); |
|
| 49 | + $salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES); |
|
| 50 | + $nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 51 | + $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 52 | + $key = self::deriveKeyFromPassword($key, $salt); |
|
| 53 | + $padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key); |
|
| 54 | + sodium_memzero($key); |
|
| 55 | + sodium_memzero($nonce); |
|
| 56 | + sodium_memzero($salt); |
|
| 57 | + if ($padded_message === false) { |
|
| 58 | + spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG); |
|
| 59 | + return null; |
|
| 60 | + } |
|
| 61 | + $message = sodium_unpad($padded_message, 16); |
|
| 62 | + #spip_log("dechiffrer($encoded)=$message", 'chiffrer' . _LOG_DEBUG); |
|
| 63 | + return $message; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** Génère une clé de la taille attendue pour le chiffrement */ |
|
| 67 | - public static function keygen(): string { |
|
| 68 | - return sodium_crypto_secretbox_keygen(); |
|
| 69 | - } |
|
| 66 | + /** Génère une clé de la taille attendue pour le chiffrement */ |
|
| 67 | + public static function keygen(): string { |
|
| 68 | + return sodium_crypto_secretbox_keygen(); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Retourne une clé de la taille attendue pour le chiffrement |
|
| 73 | - * |
|
| 74 | - * Notamment si on utilise un mot de passe comme clé, il faut le hacher |
|
| 75 | - * pour servir de clé à la taille correspondante. |
|
| 76 | - */ |
|
| 77 | - private static function deriveKeyFromPassword( |
|
| 78 | - #[\SensitiveParameter] |
|
| 79 | - string $password, |
|
| 80 | - string $salt |
|
| 81 | - ): string { |
|
| 82 | - if (strlen($password) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 83 | - return $password; |
|
| 84 | - } |
|
| 85 | - $key = sodium_crypto_pwhash( |
|
| 86 | - \SODIUM_CRYPTO_SECRETBOX_KEYBYTES, |
|
| 87 | - $password, |
|
| 88 | - $salt, |
|
| 89 | - \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, |
|
| 90 | - \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE |
|
| 91 | - ); |
|
| 92 | - sodium_memzero($password); |
|
| 71 | + /** |
|
| 72 | + * Retourne une clé de la taille attendue pour le chiffrement |
|
| 73 | + * |
|
| 74 | + * Notamment si on utilise un mot de passe comme clé, il faut le hacher |
|
| 75 | + * pour servir de clé à la taille correspondante. |
|
| 76 | + */ |
|
| 77 | + private static function deriveKeyFromPassword( |
|
| 78 | + #[\SensitiveParameter] |
|
| 79 | + string $password, |
|
| 80 | + string $salt |
|
| 81 | + ): string { |
|
| 82 | + if (strlen($password) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 83 | + return $password; |
|
| 84 | + } |
|
| 85 | + $key = sodium_crypto_pwhash( |
|
| 86 | + \SODIUM_CRYPTO_SECRETBOX_KEYBYTES, |
|
| 87 | + $password, |
|
| 88 | + $salt, |
|
| 89 | + \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, |
|
| 90 | + \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE |
|
| 91 | + ); |
|
| 92 | + sodium_memzero($password); |
|
| 93 | 93 | |
| 94 | - return $key; |
|
| 95 | - } |
|
| 94 | + return $key; |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
| 32 | 32 | $padded_message = sodium_pad($message, 16); |
| 33 | 33 | $encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key); |
| 34 | - $encoded = base64_encode($salt . $nonce . $encrypted); |
|
| 34 | + $encoded = base64_encode($salt.$nonce.$encrypted); |
|
| 35 | 35 | sodium_memzero($key); |
| 36 | 36 | sodium_memzero($nonce); |
| 37 | 37 | sodium_memzero($salt); |
@@ -48,14 +48,14 @@ discard block |
||
| 48 | 48 | $decoded = base64_decode($encoded); |
| 49 | 49 | $salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES); |
| 50 | 50 | $nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
| 51 | - $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 51 | + $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES +\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 52 | 52 | $key = self::deriveKeyFromPassword($key, $salt); |
| 53 | 53 | $padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key); |
| 54 | 54 | sodium_memzero($key); |
| 55 | 55 | sodium_memzero($nonce); |
| 56 | 56 | sodium_memzero($salt); |
| 57 | 57 | if ($padded_message === false) { |
| 58 | - spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG); |
|
| 58 | + spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer'._LOG_DEBUG); |
|
| 59 | 59 | return null; |
| 60 | 60 | } |
| 61 | 61 | $message = sodium_unpad($padded_message, 16); |