@@ -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 | /** |
@@ -44,29 +44,29 @@ discard block |
||
| 44 | 44 | * sinon code HTML de la page après le traitement effectué. |
| 45 | 45 | **/ |
| 46 | 46 | function inc_admin_dist($script, $titre, $comment = '', $anonymous = false) { |
| 47 | - $reprise = true; |
|
| 48 | - if ( |
|
| 49 | - !isset($GLOBALS['meta'][$script]) |
|
| 50 | - || !isset($GLOBALS['meta']['admin']) |
|
| 51 | - ) { |
|
| 52 | - $reprise = false; |
|
| 53 | - $res = debut_admin($script, $titre, $comment); |
|
| 54 | - if ($res) { |
|
| 55 | - return $res; |
|
| 56 | - } |
|
| 57 | - spip_log("meta: $script " . print_r($_POST, true)); |
|
| 58 | - ecrire_meta($script, serialize($_POST)); |
|
| 59 | - } |
|
| 47 | + $reprise = true; |
|
| 48 | + if ( |
|
| 49 | + !isset($GLOBALS['meta'][$script]) |
|
| 50 | + || !isset($GLOBALS['meta']['admin']) |
|
| 51 | + ) { |
|
| 52 | + $reprise = false; |
|
| 53 | + $res = debut_admin($script, $titre, $comment); |
|
| 54 | + if ($res) { |
|
| 55 | + return $res; |
|
| 56 | + } |
|
| 57 | + spip_log("meta: $script " . print_r($_POST, true)); |
|
| 58 | + ecrire_meta($script, serialize($_POST)); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $res = admin_verifie_session($script, $anonymous); |
|
| 62 | - if ($res) { |
|
| 63 | - return $res; |
|
| 64 | - } |
|
| 65 | - $base = charger_fonction($script, 'base'); |
|
| 66 | - $base($titre, $reprise); |
|
| 67 | - fin_admin($script); |
|
| 61 | + $res = admin_verifie_session($script, $anonymous); |
|
| 62 | + if ($res) { |
|
| 63 | + return $res; |
|
| 64 | + } |
|
| 65 | + $base = charger_fonction($script, 'base'); |
|
| 66 | + $base($titre, $reprise); |
|
| 67 | + fin_admin($script); |
|
| 68 | 68 | |
| 69 | - return ''; |
|
| 69 | + return ''; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -97,36 +97,36 @@ discard block |
||
| 97 | 97 | * Code HTML si message d'erreur, '' sinon; |
| 98 | 98 | */ |
| 99 | 99 | function admin_verifie_session($script, $anonymous = false) { |
| 100 | - include_spip('base/abstract_sql'); |
|
| 101 | - $pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 102 | - $signal = fichier_admin($script, "$script$pref"); |
|
| 103 | - $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'"); |
|
| 104 | - if ($valeur === null) { |
|
| 105 | - ecrire_meta('admin', $signal, 'non'); |
|
| 106 | - } else { |
|
| 107 | - if ( |
|
| 108 | - !$anonymous |
|
| 109 | - && $valeur != $signal |
|
| 110 | - && ( |
|
| 111 | - !preg_match('/^(.*)_(\d+)_/', (string) $GLOBALS['meta']['admin'], $l) |
|
| 112 | - || (int) $l[2] != $GLOBALS['visiteur_session']['id_auteur'] |
|
| 113 | - ) |
|
| 114 | - ) { |
|
| 115 | - include_spip('inc/minipres'); |
|
| 116 | - spip_log("refus de lancer $script, priorite a $valeur"); |
|
| 117 | - return minipres(_T('info_travaux_texte'), '', ['status' => 503]); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - $journal = 'spip'; |
|
| 121 | - if (autoriser('configurer')) { |
|
| 122 | - // c'est une action webmestre, soit par ftp soit par statut webmestre |
|
| 123 | - $journal = 'webmestre'; |
|
| 124 | - } |
|
| 125 | - // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
|
| 100 | + include_spip('base/abstract_sql'); |
|
| 101 | + $pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 102 | + $signal = fichier_admin($script, "$script$pref"); |
|
| 103 | + $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'"); |
|
| 104 | + if ($valeur === null) { |
|
| 105 | + ecrire_meta('admin', $signal, 'non'); |
|
| 106 | + } else { |
|
| 107 | + if ( |
|
| 108 | + !$anonymous |
|
| 109 | + && $valeur != $signal |
|
| 110 | + && ( |
|
| 111 | + !preg_match('/^(.*)_(\d+)_/', (string) $GLOBALS['meta']['admin'], $l) |
|
| 112 | + || (int) $l[2] != $GLOBALS['visiteur_session']['id_auteur'] |
|
| 113 | + ) |
|
| 114 | + ) { |
|
| 115 | + include_spip('inc/minipres'); |
|
| 116 | + spip_log("refus de lancer $script, priorite a $valeur"); |
|
| 117 | + return minipres(_T('info_travaux_texte'), '', ['status' => 503]); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + $journal = 'spip'; |
|
| 121 | + if (autoriser('configurer')) { |
|
| 122 | + // c'est une action webmestre, soit par ftp soit par statut webmestre |
|
| 123 | + $journal = 'webmestre'; |
|
| 124 | + } |
|
| 125 | + // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
|
| 126 | 126 | |
| 127 | - spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 127 | + spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 128 | 128 | |
| 129 | - return ''; |
|
| 129 | + return ''; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | * Chemin du répertoire. |
| 140 | 140 | **/ |
| 141 | 141 | function dir_admin() { |
| 142 | - if (autoriser('configurer')) { |
|
| 143 | - return _DIR_TMP; |
|
| 144 | - } else { |
|
| 145 | - return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 146 | - } |
|
| 142 | + if (autoriser('configurer')) { |
|
| 143 | + return _DIR_TMP; |
|
| 144 | + } else { |
|
| 145 | + return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 146 | + } |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | * Nom du fichier |
| 161 | 161 | **/ |
| 162 | 162 | function fichier_admin($action, $pref = 'admin_') { |
| 163 | - return $pref . |
|
| 164 | - substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 163 | + return $pref . |
|
| 164 | + substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -187,76 +187,76 @@ discard block |
||
| 187 | 187 | * sinon chaîne vide si déjà fait. |
| 188 | 188 | **/ |
| 189 | 189 | function debut_admin($script, $action = '', $corps = '') { |
| 190 | - if ( |
|
| 191 | - !$action |
|
| 192 | - || !autoriser('webmestre') && !autoriser('chargerftp') |
|
| 193 | - ) { |
|
| 194 | - include_spip('inc/minipres'); |
|
| 190 | + if ( |
|
| 191 | + !$action |
|
| 192 | + || !autoriser('webmestre') && !autoriser('chargerftp') |
|
| 193 | + ) { |
|
| 194 | + include_spip('inc/minipres'); |
|
| 195 | 195 | |
| 196 | - return minipres(); |
|
| 197 | - } else { |
|
| 198 | - $dir = dir_admin(); |
|
| 199 | - $signal = fichier_admin($script); |
|
| 200 | - if (@file_exists($dir . $signal)) { |
|
| 201 | - spip_log("Action admin: $action"); |
|
| 196 | + return minipres(); |
|
| 197 | + } else { |
|
| 198 | + $dir = dir_admin(); |
|
| 199 | + $signal = fichier_admin($script); |
|
| 200 | + if (@file_exists($dir . $signal)) { |
|
| 201 | + spip_log("Action admin: $action"); |
|
| 202 | 202 | |
| 203 | - return ''; |
|
| 204 | - } |
|
| 205 | - include_spip('inc/minipres'); |
|
| 203 | + return ''; |
|
| 204 | + } |
|
| 205 | + include_spip('inc/minipres'); |
|
| 206 | 206 | |
| 207 | - // Si on est un super-admin, un bouton de validation suffit |
|
| 208 | - // sauf dans les cas destroy |
|
| 209 | - if ( |
|
| 210 | - (autoriser('webmestre') || $script === 'repair') |
|
| 211 | - && $script != 'delete_all' |
|
| 212 | - ) { |
|
| 213 | - if (_request('validation_admin') == $signal) { |
|
| 214 | - spip_log("Action super-admin: $action"); |
|
| 207 | + // Si on est un super-admin, un bouton de validation suffit |
|
| 208 | + // sauf dans les cas destroy |
|
| 209 | + if ( |
|
| 210 | + (autoriser('webmestre') || $script === 'repair') |
|
| 211 | + && $script != 'delete_all' |
|
| 212 | + ) { |
|
| 213 | + if (_request('validation_admin') == $signal) { |
|
| 214 | + spip_log("Action super-admin: $action"); |
|
| 215 | 215 | |
| 216 | - return ''; |
|
| 217 | - } |
|
| 218 | - $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 219 | - $suivant = _T('bouton_valider'); |
|
| 220 | - $js = ''; |
|
| 221 | - } else { |
|
| 222 | - // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj) |
|
| 223 | - // l'insertion du script a cet endroit n'est pas xhtml licite |
|
| 224 | - // mais evite de l'embarquer dans toutes les pages minipres |
|
| 225 | - $corps .= http_script('', 'spip_barre.js'); |
|
| 216 | + return ''; |
|
| 217 | + } |
|
| 218 | + $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 219 | + $suivant = _T('bouton_valider'); |
|
| 220 | + $js = ''; |
|
| 221 | + } else { |
|
| 222 | + // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj) |
|
| 223 | + // l'insertion du script a cet endroit n'est pas xhtml licite |
|
| 224 | + // mais evite de l'embarquer dans toutes les pages minipres |
|
| 225 | + $corps .= http_script('', 'spip_barre.js'); |
|
| 226 | 226 | |
| 227 | - $corps .= '<fieldset><legend>' |
|
| 228 | - . _T('info_authentification_ftp') |
|
| 229 | - . aider('ftp_auth') |
|
| 230 | - . "</legend>\n<label for='fichier'>" |
|
| 231 | - . _T('info_creer_repertoire') |
|
| 232 | - . "</label>\n" |
|
| 233 | - . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 234 | - . "<input type='hidden' id='fichier' name='fichier' value='" |
|
| 235 | - . $signal |
|
| 236 | - . "' />" |
|
| 237 | - . _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)]) |
|
| 238 | - . '</fieldset>'; |
|
| 227 | + $corps .= '<fieldset><legend>' |
|
| 228 | + . _T('info_authentification_ftp') |
|
| 229 | + . aider('ftp_auth') |
|
| 230 | + . "</legend>\n<label for='fichier'>" |
|
| 231 | + . _T('info_creer_repertoire') |
|
| 232 | + . "</label>\n" |
|
| 233 | + . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 234 | + . "<input type='hidden' id='fichier' name='fichier' value='" |
|
| 235 | + . $signal |
|
| 236 | + . "' />" |
|
| 237 | + . _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)]) |
|
| 238 | + . '</fieldset>'; |
|
| 239 | 239 | |
| 240 | - $suivant = _T('bouton_recharger_page'); |
|
| 240 | + $suivant = _T('bouton_recharger_page'); |
|
| 241 | 241 | |
| 242 | - // code volontairement tordu: |
|
| 243 | - // provoquer la copie dans le presse papier du nom du repertoire |
|
| 244 | - // en remettant a vide le champ pour que ca marche aussi en cas |
|
| 245 | - // de JavaScript inactif. |
|
| 246 | - $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'"; |
|
| 247 | - } |
|
| 242 | + // code volontairement tordu: |
|
| 243 | + // provoquer la copie dans le presse papier du nom du repertoire |
|
| 244 | + // en remettant a vide le champ pour que ca marche aussi en cas |
|
| 245 | + // de JavaScript inactif. |
|
| 246 | + $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'"; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - // admin/xxx correspond |
|
| 250 | - // a exec/base_xxx de preference |
|
| 251 | - // et exec/xxx sinon (compat) |
|
| 252 | - if (tester_url_ecrire("base_$script")) { |
|
| 253 | - $script = "base_$script"; |
|
| 254 | - } |
|
| 255 | - $form = copy_request($script, $corps, $suivant); |
|
| 256 | - $info_action = _T('info_action', ['action' => "$action"]); |
|
| 249 | + // admin/xxx correspond |
|
| 250 | + // a exec/base_xxx de preference |
|
| 251 | + // et exec/xxx sinon (compat) |
|
| 252 | + if (tester_url_ecrire("base_$script")) { |
|
| 253 | + $script = "base_$script"; |
|
| 254 | + } |
|
| 255 | + $form = copy_request($script, $corps, $suivant); |
|
| 256 | + $info_action = _T('info_action', ['action' => "$action"]); |
|
| 257 | 257 | |
| 258 | - return minipres($info_action, $form, ['onload' => $js]); |
|
| 259 | - } |
|
| 258 | + return minipres($info_action, $form, ['onload' => $js]); |
|
| 259 | + } |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | * Nom de l'action (en base) qui a été exécutée |
| 268 | 268 | **/ |
| 269 | 269 | function fin_admin($action) { |
| 270 | - $signal = dir_admin() . fichier_admin($action); |
|
| 271 | - spip_unlink($signal); |
|
| 272 | - if ($action != 'delete_all') { |
|
| 273 | - effacer_meta($action); |
|
| 274 | - effacer_meta('admin'); |
|
| 275 | - spip_log("efface les meta admin et $action "); |
|
| 276 | - } |
|
| 270 | + $signal = dir_admin() . fichier_admin($action); |
|
| 271 | + spip_unlink($signal); |
|
| 272 | + if ($action != 'delete_all') { |
|
| 273 | + effacer_meta($action); |
|
| 274 | + effacer_meta('admin'); |
|
| 275 | + spip_log("efface les meta admin et $action "); |
|
| 276 | + } |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -292,14 +292,14 @@ discard block |
||
| 292 | 292 | * Code HTML du formulaire |
| 293 | 293 | **/ |
| 294 | 294 | function copy_request($script, $suite, $submit = '') { |
| 295 | - include_spip('inc/filtres'); |
|
| 296 | - foreach ([...$_POST, ...$_GET] as $n => $c) { |
|
| 297 | - if (!in_array($n, ['fichier', 'exec', 'validation_admin']) && !is_array($c)) { |
|
| 298 | - $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 299 | - entites_html($c) . |
|
| 300 | - "' />"; |
|
| 301 | - } |
|
| 302 | - } |
|
| 295 | + include_spip('inc/filtres'); |
|
| 296 | + foreach ([...$_POST, ...$_GET] as $n => $c) { |
|
| 297 | + if (!in_array($n, ['fichier', 'exec', 'validation_admin']) && !is_array($c)) { |
|
| 298 | + $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 299 | + entites_html($c) . |
|
| 300 | + "' />"; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - return generer_form_ecrire($script, $suite, '', $submit); |
|
| 304 | + return generer_form_ecrire($script, $suite, '', $submit); |
|
| 305 | 305 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | if ($res) { |
| 55 | 55 | return $res; |
| 56 | 56 | } |
| 57 | - spip_log("meta: $script " . print_r($_POST, true)); |
|
| 57 | + spip_log("meta: $script ".print_r($_POST, true)); |
|
| 58 | 58 | ecrire_meta($script, serialize($_POST)); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
| 126 | 126 | |
| 127 | - spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 127 | + spip_log("admin $pref".($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 128 | 128 | |
| 129 | 129 | return ''; |
| 130 | 130 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if (autoriser('configurer')) { |
| 143 | 143 | return _DIR_TMP; |
| 144 | 144 | } else { |
| 145 | - return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 145 | + return _DIR_TRANSFERT.$GLOBALS['visiteur_session']['login'].'/'; |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | * Nom du fichier |
| 161 | 161 | **/ |
| 162 | 162 | function fichier_admin($action, $pref = 'admin_') { |
| 163 | - return $pref . |
|
| 164 | - substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 163 | + return $pref. |
|
| 164 | + substr(md5($action.(time() & ~2047).$GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | } else { |
| 198 | 198 | $dir = dir_admin(); |
| 199 | 199 | $signal = fichier_admin($script); |
| 200 | - if (@file_exists($dir . $signal)) { |
|
| 200 | + if (@file_exists($dir.$signal)) { |
|
| 201 | 201 | spip_log("Action admin: $action"); |
| 202 | 202 | |
| 203 | 203 | return ''; |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | |
| 216 | 216 | return ''; |
| 217 | 217 | } |
| 218 | - $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 218 | + $corps .= '<input type="hidden" name="validation_admin" value="'.$signal.'" />'; |
|
| 219 | 219 | $suivant = _T('bouton_valider'); |
| 220 | 220 | $js = ''; |
| 221 | 221 | } else { |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | . "</legend>\n<label for='fichier'>" |
| 231 | 231 | . _T('info_creer_repertoire') |
| 232 | 232 | . "</label>\n" |
| 233 | - . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 233 | + . "<span id='signal' class='formo'>".$signal.'</span>' |
|
| 234 | 234 | . "<input type='hidden' id='fichier' name='fichier' value='" |
| 235 | 235 | . $signal |
| 236 | 236 | . "' />" |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * Nom de l'action (en base) qui a été exécutée |
| 268 | 268 | **/ |
| 269 | 269 | function fin_admin($action) { |
| 270 | - $signal = dir_admin() . fichier_admin($action); |
|
| 270 | + $signal = dir_admin().fichier_admin($action); |
|
| 271 | 271 | spip_unlink($signal); |
| 272 | 272 | if ($action != 'delete_all') { |
| 273 | 273 | effacer_meta($action); |
@@ -295,8 +295,8 @@ discard block |
||
| 295 | 295 | include_spip('inc/filtres'); |
| 296 | 296 | foreach ([...$_POST, ...$_GET] as $n => $c) { |
| 297 | 297 | if (!in_array($n, ['fichier', 'exec', 'validation_admin']) && !is_array($c)) { |
| 298 | - $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 299 | - entites_html($c) . |
|
| 298 | + $suite .= "\n<input type='hidden' name='".spip_htmlspecialchars($n)."' value='". |
|
| 299 | + entites_html($c). |
|
| 300 | 300 | "' />"; |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -336,8 +336,7 @@ |
||
| 336 | 336 | if (!autoriser('modifier', $type, (int) $id)) { |
| 337 | 337 | $contexte['editable'] = ''; |
| 338 | 338 | } |
| 339 | - } |
|
| 340 | - else { |
|
| 339 | + } else { |
|
| 341 | 340 | if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
| 342 | 341 | $contexte['editable'] = ''; |
| 343 | 342 | } |
@@ -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 | include_spip('base/abstract_sql'); |
| 22 | 22 | |
@@ -58,56 +58,56 @@ discard block |
||
| 58 | 58 | * Retour des traitements. |
| 59 | 59 | **/ |
| 60 | 60 | function formulaires_editer_objet_traiter( |
| 61 | - $type, |
|
| 62 | - $id = 'new', |
|
| 63 | - $id_parent = 0, |
|
| 64 | - $lier_trad = 0, |
|
| 65 | - $retour = '', |
|
| 66 | - $config_fonc = 'articles_edit_config', |
|
| 67 | - $row = [], |
|
| 68 | - $hidden = '' |
|
| 61 | + $type, |
|
| 62 | + $id = 'new', |
|
| 63 | + $id_parent = 0, |
|
| 64 | + $lier_trad = 0, |
|
| 65 | + $retour = '', |
|
| 66 | + $config_fonc = 'articles_edit_config', |
|
| 67 | + $row = [], |
|
| 68 | + $hidden = '' |
|
| 69 | 69 | ) { |
| 70 | 70 | |
| 71 | - $res = []; |
|
| 72 | - // eviter la redirection forcee par l'action... |
|
| 73 | - set_request('redirect'); |
|
| 74 | - if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 75 | - [$id, $err] = $action_editer($id); |
|
| 76 | - } else { |
|
| 77 | - $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 78 | - [$id, $err] = $action_editer($id, $type); |
|
| 79 | - } |
|
| 80 | - $id_table_objet = id_table_objet($type); |
|
| 81 | - $res[$id_table_objet] = $id; |
|
| 82 | - if ($err || !$id) { |
|
| 83 | - $res['message_erreur'] = ($err ?: _T('erreur')); |
|
| 84 | - } else { |
|
| 85 | - // Un lien de trad a prendre en compte |
|
| 86 | - if ($lier_trad) { |
|
| 87 | - // referencer la traduction |
|
| 88 | - $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 89 | - $referencer_traduction($type, $id, $lier_trad); |
|
| 90 | - // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 91 | - $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 92 | - $err = $completer_traduction($type, $id, $lier_trad); |
|
| 93 | - if ($err) { |
|
| 94 | - $res['message_erreur'] = $err; |
|
| 95 | - return $res; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 100 | - if ($retour) { |
|
| 101 | - if (str_starts_with($retour, 'javascript:')) { |
|
| 102 | - $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 103 | - $res['editable'] = true; |
|
| 104 | - } else { |
|
| 105 | - $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return $res; |
|
| 71 | + $res = []; |
|
| 72 | + // eviter la redirection forcee par l'action... |
|
| 73 | + set_request('redirect'); |
|
| 74 | + if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 75 | + [$id, $err] = $action_editer($id); |
|
| 76 | + } else { |
|
| 77 | + $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 78 | + [$id, $err] = $action_editer($id, $type); |
|
| 79 | + } |
|
| 80 | + $id_table_objet = id_table_objet($type); |
|
| 81 | + $res[$id_table_objet] = $id; |
|
| 82 | + if ($err || !$id) { |
|
| 83 | + $res['message_erreur'] = ($err ?: _T('erreur')); |
|
| 84 | + } else { |
|
| 85 | + // Un lien de trad a prendre en compte |
|
| 86 | + if ($lier_trad) { |
|
| 87 | + // referencer la traduction |
|
| 88 | + $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 89 | + $referencer_traduction($type, $id, $lier_trad); |
|
| 90 | + // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 91 | + $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 92 | + $err = $completer_traduction($type, $id, $lier_trad); |
|
| 93 | + if ($err) { |
|
| 94 | + $res['message_erreur'] = $err; |
|
| 95 | + return $res; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 100 | + if ($retour) { |
|
| 101 | + if (str_starts_with($retour, 'javascript:')) { |
|
| 102 | + $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 103 | + $res['editable'] = true; |
|
| 104 | + } else { |
|
| 105 | + $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return $res; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -131,29 +131,29 @@ discard block |
||
| 131 | 131 | * Tableau des erreurs |
| 132 | 132 | **/ |
| 133 | 133 | function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = []) { |
| 134 | - $erreurs = []; |
|
| 135 | - if ((int) $id) { |
|
| 136 | - $conflits = controler_contenu($type, $id); |
|
| 137 | - if ($conflits && (is_countable($conflits) ? count($conflits) : 0)) { |
|
| 138 | - foreach ($conflits as $champ => $conflit) { |
|
| 139 | - if (!isset($erreurs[$champ])) { |
|
| 140 | - $erreurs[$champ] = ''; |
|
| 141 | - } |
|
| 142 | - $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - foreach ($oblis as $obli) { |
|
| 147 | - $value = _request($obli); |
|
| 148 | - if (is_null($value) || !(is_array($value) ? count($value) : strlen((string) $value))) { |
|
| 149 | - if (!isset($erreurs[$obli])) { |
|
| 150 | - $erreurs[$obli] = ''; |
|
| 151 | - } |
|
| 152 | - $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return $erreurs; |
|
| 134 | + $erreurs = []; |
|
| 135 | + if ((int) $id) { |
|
| 136 | + $conflits = controler_contenu($type, $id); |
|
| 137 | + if ($conflits && (is_countable($conflits) ? count($conflits) : 0)) { |
|
| 138 | + foreach ($conflits as $champ => $conflit) { |
|
| 139 | + if (!isset($erreurs[$champ])) { |
|
| 140 | + $erreurs[$champ] = ''; |
|
| 141 | + } |
|
| 142 | + $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + foreach ($oblis as $obli) { |
|
| 147 | + $value = _request($obli); |
|
| 148 | + if (is_null($value) || !(is_array($value) ? count($value) : strlen((string) $value))) { |
|
| 149 | + if (!isset($erreurs[$obli])) { |
|
| 150 | + $erreurs[$obli] = ''; |
|
| 151 | + } |
|
| 152 | + $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return $erreurs; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -198,151 +198,151 @@ discard block |
||
| 198 | 198 | * Environnement du formulaire. |
| 199 | 199 | **/ |
| 200 | 200 | function formulaires_editer_objet_charger( |
| 201 | - $type, |
|
| 202 | - $id = 'new', |
|
| 203 | - $id_parent = 0, |
|
| 204 | - $lier_trad = 0, |
|
| 205 | - $retour = '', |
|
| 206 | - $config_fonc = 'articles_edit_config', |
|
| 207 | - $row = [], |
|
| 208 | - $hidden = '' |
|
| 201 | + $type, |
|
| 202 | + $id = 'new', |
|
| 203 | + $id_parent = 0, |
|
| 204 | + $lier_trad = 0, |
|
| 205 | + $retour = '', |
|
| 206 | + $config_fonc = 'articles_edit_config', |
|
| 207 | + $row = [], |
|
| 208 | + $hidden = '' |
|
| 209 | 209 | ) { |
| 210 | 210 | |
| 211 | - $table_objet = table_objet($type); |
|
| 212 | - $table_objet_sql = table_objet_sql($type); |
|
| 213 | - $id_table_objet = id_table_objet($type); |
|
| 214 | - if (!is_array($row)) { |
|
| 215 | - $row = []; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // on accepte pas une fonction de config inconnue si elle vient d'un modele |
|
| 219 | - if ( |
|
| 220 | - $config_fonc |
|
| 221 | - && !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
|
| 222 | - && $config_fonc !== $table_objet . '_edit_config' |
|
| 223 | - && ($args = test_formulaire_inclus_par_modele()) |
|
| 224 | - && in_array($config_fonc, $args) |
|
| 225 | - ) { |
|
| 226 | - $config_fonc = ''; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $new = !is_numeric($id); |
|
| 230 | - $lang_default = ''; |
|
| 231 | - // Appel direct dans un squelette |
|
| 232 | - if (!$row) { |
|
| 233 | - if (!$new || $lier_trad) { |
|
| 234 | - if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 235 | - $row = $select($id, $id_parent, $lier_trad); |
|
| 236 | - // si on a une fonction precharger, elle pu faire un reglage de langue |
|
| 237 | - $lang_default = (empty($row['lang']) ? null : $row['lang']); |
|
| 238 | - } else { |
|
| 239 | - $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id); |
|
| 240 | - } |
|
| 241 | - if (!$new) { |
|
| 242 | - $md5 = controles_md5($row ?: []); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - if (!$row) { |
|
| 246 | - $row = []; |
|
| 247 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 248 | - if ($desc = $trouver_table($table_objet)) { |
|
| 249 | - foreach ($desc['field'] as $k => $v) { |
|
| 250 | - $row[$k] = ''; |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 257 | - // (et donc: pas de lien de traduction) |
|
| 258 | - $id = ($new || $lier_trad) |
|
| 259 | - ? 'oui' |
|
| 260 | - : $row[$id_table_objet]; |
|
| 261 | - $row[$id_table_objet] = $id; |
|
| 262 | - |
|
| 263 | - $contexte = $row; |
|
| 264 | - if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) || $new)) { |
|
| 265 | - if (!isset($contexte['id_parent'])) { |
|
| 266 | - unset($contexte['id_rubrique']); |
|
| 267 | - } |
|
| 268 | - $contexte['id_parent'] = $id_parent; |
|
| 269 | - } elseif (!isset($contexte['id_parent'])) { |
|
| 270 | - // id_rubrique dans id_parent si possible |
|
| 271 | - if (isset($contexte['id_rubrique'])) { |
|
| 272 | - $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 273 | - unset($contexte['id_rubrique']); |
|
| 274 | - } else { |
|
| 275 | - $contexte['id_parent'] = ''; |
|
| 276 | - } |
|
| 277 | - if ( |
|
| 278 | - !$contexte['id_parent'] |
|
| 279 | - && ($preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)) |
|
| 280 | - ) { |
|
| 281 | - $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $config = []; |
|
| 286 | - if ($config_fonc) { |
|
| 287 | - $contexte['config'] = $config = $config_fonc($contexte); |
|
| 288 | - if (!$lang_default) { |
|
| 289 | - include_spip('inc/session'); |
|
| 290 | - $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - $config += [ |
|
| 294 | - 'lignes' => 0, |
|
| 295 | - 'langue' => '', |
|
| 296 | - ]; |
|
| 297 | - |
|
| 298 | - $att_text = " class='textarea' " |
|
| 299 | - . " rows='" |
|
| 300 | - . ($config['lignes'] + 15) |
|
| 301 | - . "' cols='40'"; |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - // on veut conserver la langue de l'interface ; |
|
| 305 | - // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 306 | - // voudrait l'exploiter |
|
| 307 | - if (isset($contexte['lang'])) { |
|
| 308 | - $contexte['langue'] = $contexte['lang']; |
|
| 309 | - unset($contexte['lang']); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 313 | - ($lier_trad |
|
| 314 | - ? "\n<input type='hidden' name='lier_trad' value='" . |
|
| 315 | - $lier_trad . |
|
| 316 | - "' />" . |
|
| 317 | - "\n<input type='hidden' name='changer_lang' value='" . |
|
| 318 | - $lang_default . |
|
| 319 | - "' />" |
|
| 320 | - : '') |
|
| 321 | - . $hidden |
|
| 322 | - . ($md5 ?? ''); |
|
| 323 | - |
|
| 324 | - // preciser que le formulaire doit passer dans un pipeline |
|
| 325 | - $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]]; |
|
| 326 | - |
|
| 327 | - // preciser que le formulaire doit etre securise auteur/action |
|
| 328 | - // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 329 | - // on le garde pour compat |
|
| 330 | - $contexte['_action'] = ["editer_$type", $id]; |
|
| 331 | - |
|
| 332 | - // et in fine placer l'autorisation |
|
| 333 | - include_spip('inc/autoriser'); |
|
| 334 | - if ((int) $id) { |
|
| 335 | - if (!autoriser('modifier', $type, (int) $id)) { |
|
| 336 | - $contexte['editable'] = ''; |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - else { |
|
| 340 | - if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
|
| 341 | - $contexte['editable'] = ''; |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - return $contexte; |
|
| 211 | + $table_objet = table_objet($type); |
|
| 212 | + $table_objet_sql = table_objet_sql($type); |
|
| 213 | + $id_table_objet = id_table_objet($type); |
|
| 214 | + if (!is_array($row)) { |
|
| 215 | + $row = []; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // on accepte pas une fonction de config inconnue si elle vient d'un modele |
|
| 219 | + if ( |
|
| 220 | + $config_fonc |
|
| 221 | + && !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
|
| 222 | + && $config_fonc !== $table_objet . '_edit_config' |
|
| 223 | + && ($args = test_formulaire_inclus_par_modele()) |
|
| 224 | + && in_array($config_fonc, $args) |
|
| 225 | + ) { |
|
| 226 | + $config_fonc = ''; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $new = !is_numeric($id); |
|
| 230 | + $lang_default = ''; |
|
| 231 | + // Appel direct dans un squelette |
|
| 232 | + if (!$row) { |
|
| 233 | + if (!$new || $lier_trad) { |
|
| 234 | + if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 235 | + $row = $select($id, $id_parent, $lier_trad); |
|
| 236 | + // si on a une fonction precharger, elle pu faire un reglage de langue |
|
| 237 | + $lang_default = (empty($row['lang']) ? null : $row['lang']); |
|
| 238 | + } else { |
|
| 239 | + $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id); |
|
| 240 | + } |
|
| 241 | + if (!$new) { |
|
| 242 | + $md5 = controles_md5($row ?: []); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + if (!$row) { |
|
| 246 | + $row = []; |
|
| 247 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 248 | + if ($desc = $trouver_table($table_objet)) { |
|
| 249 | + foreach ($desc['field'] as $k => $v) { |
|
| 250 | + $row[$k] = ''; |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 257 | + // (et donc: pas de lien de traduction) |
|
| 258 | + $id = ($new || $lier_trad) |
|
| 259 | + ? 'oui' |
|
| 260 | + : $row[$id_table_objet]; |
|
| 261 | + $row[$id_table_objet] = $id; |
|
| 262 | + |
|
| 263 | + $contexte = $row; |
|
| 264 | + if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) || $new)) { |
|
| 265 | + if (!isset($contexte['id_parent'])) { |
|
| 266 | + unset($contexte['id_rubrique']); |
|
| 267 | + } |
|
| 268 | + $contexte['id_parent'] = $id_parent; |
|
| 269 | + } elseif (!isset($contexte['id_parent'])) { |
|
| 270 | + // id_rubrique dans id_parent si possible |
|
| 271 | + if (isset($contexte['id_rubrique'])) { |
|
| 272 | + $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 273 | + unset($contexte['id_rubrique']); |
|
| 274 | + } else { |
|
| 275 | + $contexte['id_parent'] = ''; |
|
| 276 | + } |
|
| 277 | + if ( |
|
| 278 | + !$contexte['id_parent'] |
|
| 279 | + && ($preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)) |
|
| 280 | + ) { |
|
| 281 | + $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $config = []; |
|
| 286 | + if ($config_fonc) { |
|
| 287 | + $contexte['config'] = $config = $config_fonc($contexte); |
|
| 288 | + if (!$lang_default) { |
|
| 289 | + include_spip('inc/session'); |
|
| 290 | + $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + $config += [ |
|
| 294 | + 'lignes' => 0, |
|
| 295 | + 'langue' => '', |
|
| 296 | + ]; |
|
| 297 | + |
|
| 298 | + $att_text = " class='textarea' " |
|
| 299 | + . " rows='" |
|
| 300 | + . ($config['lignes'] + 15) |
|
| 301 | + . "' cols='40'"; |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + // on veut conserver la langue de l'interface ; |
|
| 305 | + // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 306 | + // voudrait l'exploiter |
|
| 307 | + if (isset($contexte['lang'])) { |
|
| 308 | + $contexte['langue'] = $contexte['lang']; |
|
| 309 | + unset($contexte['lang']); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 313 | + ($lier_trad |
|
| 314 | + ? "\n<input type='hidden' name='lier_trad' value='" . |
|
| 315 | + $lier_trad . |
|
| 316 | + "' />" . |
|
| 317 | + "\n<input type='hidden' name='changer_lang' value='" . |
|
| 318 | + $lang_default . |
|
| 319 | + "' />" |
|
| 320 | + : '') |
|
| 321 | + . $hidden |
|
| 322 | + . ($md5 ?? ''); |
|
| 323 | + |
|
| 324 | + // preciser que le formulaire doit passer dans un pipeline |
|
| 325 | + $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]]; |
|
| 326 | + |
|
| 327 | + // preciser que le formulaire doit etre securise auteur/action |
|
| 328 | + // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 329 | + // on le garde pour compat |
|
| 330 | + $contexte['_action'] = ["editer_$type", $id]; |
|
| 331 | + |
|
| 332 | + // et in fine placer l'autorisation |
|
| 333 | + include_spip('inc/autoriser'); |
|
| 334 | + if ((int) $id) { |
|
| 335 | + if (!autoriser('modifier', $type, (int) $id)) { |
|
| 336 | + $contexte['editable'] = ''; |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + else { |
|
| 340 | + if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
|
| 341 | + $contexte['editable'] = ''; |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + return $contexte; |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | /** |
@@ -353,29 +353,29 @@ discard block |
||
| 353 | 353 | * @return array |
| 354 | 354 | */ |
| 355 | 355 | function coupe_trop_long($texte) { |
| 356 | - $aider = charger_fonction('aider', 'inc'); |
|
| 357 | - if (strlen($texte) > 28 * 1024) { |
|
| 358 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 359 | - $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 360 | - if ($pos > 0 && $pos < 32 * 1024) { |
|
| 361 | - $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 362 | - $suite = substr($texte, $pos + 2); |
|
| 363 | - } else { |
|
| 364 | - $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 365 | - if (!($pos > 0 && $pos < 32 * 1024)) { |
|
| 366 | - $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 367 | - $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 368 | - } else { |
|
| 369 | - $decalage = 1; |
|
| 370 | - } |
|
| 371 | - $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 372 | - $suite = substr($texte, $pos + $decalage); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return ([$debut, $suite]); |
|
| 376 | - } else { |
|
| 377 | - return ([$texte, '']); |
|
| 378 | - } |
|
| 356 | + $aider = charger_fonction('aider', 'inc'); |
|
| 357 | + if (strlen($texte) > 28 * 1024) { |
|
| 358 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 359 | + $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 360 | + if ($pos > 0 && $pos < 32 * 1024) { |
|
| 361 | + $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 362 | + $suite = substr($texte, $pos + 2); |
|
| 363 | + } else { |
|
| 364 | + $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 365 | + if (!($pos > 0 && $pos < 32 * 1024)) { |
|
| 366 | + $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 367 | + $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 368 | + } else { |
|
| 369 | + $decalage = 1; |
|
| 370 | + } |
|
| 371 | + $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 372 | + $suite = substr($texte, $pos + $decalage); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return ([$debut, $suite]); |
|
| 376 | + } else { |
|
| 377 | + return ([$texte, '']); |
|
| 378 | + } |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -386,13 +386,13 @@ discard block |
||
| 386 | 386 | * @param int $longueur |
| 387 | 387 | */ |
| 388 | 388 | function titre_automatique($champ_titre, $champs_contenu, $longueur = null) { |
| 389 | - if (!_request($champ_titre)) { |
|
| 390 | - $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 391 | - $t = is_null($longueur) ? $titrer_contenu($champs_contenu) : $titrer_contenu($champs_contenu, null, $longueur); |
|
| 392 | - if ($t) { |
|
| 393 | - set_request($champ_titre, $t); |
|
| 394 | - } |
|
| 395 | - } |
|
| 389 | + if (!_request($champ_titre)) { |
|
| 390 | + $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 391 | + $t = is_null($longueur) ? $titrer_contenu($champs_contenu) : $titrer_contenu($champs_contenu, null, $longueur); |
|
| 392 | + if ($t) { |
|
| 393 | + set_request($champ_titre, $t); |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -412,20 +412,20 @@ discard block |
||
| 412 | 412 | * @return string |
| 413 | 413 | */ |
| 414 | 414 | function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) { |
| 415 | - // trouver un champ texte non vide |
|
| 416 | - $t = ''; |
|
| 417 | - foreach ($champs_contenu as $champ) { |
|
| 418 | - if ($t = _request($champ, $c)) { |
|
| 419 | - break; |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if ($t) { |
|
| 424 | - include_spip('inc/texte_mini'); |
|
| 425 | - $t = couper($t, $longueur, '...'); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - return $t; |
|
| 415 | + // trouver un champ texte non vide |
|
| 416 | + $t = ''; |
|
| 417 | + foreach ($champs_contenu as $champ) { |
|
| 418 | + if ($t = _request($champ, $c)) { |
|
| 419 | + break; |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if ($t) { |
|
| 424 | + include_spip('inc/texte_mini'); |
|
| 425 | + $t = couper($t, $longueur, '...'); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + return $t; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -447,22 +447,22 @@ discard block |
||
| 447 | 447 | * - array sinon couples ('$prefixe$colonne => md5) |
| 448 | 448 | **/ |
| 449 | 449 | function controles_md5(array $data, string $prefixe = 'ctr_', string $format = 'html') { |
| 450 | - $ctr = []; |
|
| 451 | - foreach ($data as $key => $val) { |
|
| 452 | - $m = md5($val ?? ''); |
|
| 453 | - $k = $prefixe . $key; |
|
| 454 | - |
|
| 455 | - $ctr[$k] = match ($format) { |
|
| 456 | - 'html' => "<input type='hidden' value='$m' name='$k' />", |
|
| 457 | - default => $m, |
|
| 458 | - }; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - if ($format === 'html') { |
|
| 462 | - return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n"; |
|
| 463 | - } else { |
|
| 464 | - return $ctr; |
|
| 465 | - } |
|
| 450 | + $ctr = []; |
|
| 451 | + foreach ($data as $key => $val) { |
|
| 452 | + $m = md5($val ?? ''); |
|
| 453 | + $k = $prefixe . $key; |
|
| 454 | + |
|
| 455 | + $ctr[$k] = match ($format) { |
|
| 456 | + 'html' => "<input type='hidden' value='$m' name='$k' />", |
|
| 457 | + default => $m, |
|
| 458 | + }; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + if ($format === 'html') { |
|
| 462 | + return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n"; |
|
| 463 | + } else { |
|
| 464 | + return $ctr; |
|
| 465 | + } |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -501,80 +501,80 @@ discard block |
||
| 501 | 501 | * - post : le contenu posté |
| 502 | 502 | **/ |
| 503 | 503 | function controler_contenu($type, $id, $options = [], $c = false, $serveur = '') { |
| 504 | - include_spip('inc/filtres'); |
|
| 505 | - |
|
| 506 | - $table_objet = table_objet($type); |
|
| 507 | - $spip_table_objet = table_objet_sql($type); |
|
| 508 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 509 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 510 | - |
|
| 511 | - // Appels incomplets (sans $c) |
|
| 512 | - if (!is_array($c)) { |
|
| 513 | - $c = []; |
|
| 514 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 515 | - if (_request($champ)) { |
|
| 516 | - $c[$champ] = _request($champ); |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 522 | - // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 523 | - // il faut passer par instituer_XX() |
|
| 524 | - // TODO: faut-il passer ces variables interdites |
|
| 525 | - // dans un fichier de description separe ? |
|
| 526 | - unset($c['statut']); |
|
| 527 | - unset($c['id_parent']); |
|
| 528 | - unset($c['id_rubrique']); |
|
| 529 | - unset($c['id_secteur']); |
|
| 530 | - |
|
| 531 | - // Gerer les champs non vides |
|
| 532 | - if (isset($options['nonvide']) && is_array($options['nonvide'])) { |
|
| 533 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 534 | - if ($c[$champ] === '') { |
|
| 535 | - $c[$champ] = $sinon; |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // N'accepter que les champs qui existent |
|
| 541 | - // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 542 | - $champs = []; |
|
| 543 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 544 | - if (isset($c[$champ])) { |
|
| 545 | - $champs[$champ] = $c[$champ]; |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - // Nettoyer les valeurs |
|
| 550 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 551 | - |
|
| 552 | - // Envoyer aux plugins |
|
| 553 | - $champs = pipeline( |
|
| 554 | - 'pre_edition', |
|
| 555 | - [ |
|
| 556 | - 'args' => [ |
|
| 557 | - 'table' => $spip_table_objet, // compatibilite |
|
| 558 | - 'table_objet' => $table_objet, |
|
| 559 | - 'spip_table_objet' => $spip_table_objet, |
|
| 560 | - 'type' => $type, |
|
| 561 | - 'id_objet' => $id, |
|
| 562 | - 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 563 | - 'action' => 'controler', |
|
| 564 | - 'serveur' => $serveur, |
|
| 565 | - ], |
|
| 566 | - 'data' => $champs |
|
| 567 | - ] |
|
| 568 | - ); |
|
| 569 | - |
|
| 570 | - if (!$champs) { |
|
| 571 | - return false; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 575 | - $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, $options['prefix'] ?? 'ctr_'); |
|
| 576 | - |
|
| 577 | - return $conflits; |
|
| 504 | + include_spip('inc/filtres'); |
|
| 505 | + |
|
| 506 | + $table_objet = table_objet($type); |
|
| 507 | + $spip_table_objet = table_objet_sql($type); |
|
| 508 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 509 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 510 | + |
|
| 511 | + // Appels incomplets (sans $c) |
|
| 512 | + if (!is_array($c)) { |
|
| 513 | + $c = []; |
|
| 514 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 515 | + if (_request($champ)) { |
|
| 516 | + $c[$champ] = _request($champ); |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 522 | + // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 523 | + // il faut passer par instituer_XX() |
|
| 524 | + // TODO: faut-il passer ces variables interdites |
|
| 525 | + // dans un fichier de description separe ? |
|
| 526 | + unset($c['statut']); |
|
| 527 | + unset($c['id_parent']); |
|
| 528 | + unset($c['id_rubrique']); |
|
| 529 | + unset($c['id_secteur']); |
|
| 530 | + |
|
| 531 | + // Gerer les champs non vides |
|
| 532 | + if (isset($options['nonvide']) && is_array($options['nonvide'])) { |
|
| 533 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 534 | + if ($c[$champ] === '') { |
|
| 535 | + $c[$champ] = $sinon; |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // N'accepter que les champs qui existent |
|
| 541 | + // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 542 | + $champs = []; |
|
| 543 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 544 | + if (isset($c[$champ])) { |
|
| 545 | + $champs[$champ] = $c[$champ]; |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + // Nettoyer les valeurs |
|
| 550 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 551 | + |
|
| 552 | + // Envoyer aux plugins |
|
| 553 | + $champs = pipeline( |
|
| 554 | + 'pre_edition', |
|
| 555 | + [ |
|
| 556 | + 'args' => [ |
|
| 557 | + 'table' => $spip_table_objet, // compatibilite |
|
| 558 | + 'table_objet' => $table_objet, |
|
| 559 | + 'spip_table_objet' => $spip_table_objet, |
|
| 560 | + 'type' => $type, |
|
| 561 | + 'id_objet' => $id, |
|
| 562 | + 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 563 | + 'action' => 'controler', |
|
| 564 | + 'serveur' => $serveur, |
|
| 565 | + ], |
|
| 566 | + 'data' => $champs |
|
| 567 | + ] |
|
| 568 | + ); |
|
| 569 | + |
|
| 570 | + if (!$champs) { |
|
| 571 | + return false; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 575 | + $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, $options['prefix'] ?? 'ctr_'); |
|
| 576 | + |
|
| 577 | + return $conflits; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | |
@@ -604,66 +604,66 @@ discard block |
||
| 604 | 604 | * - post : le contenu posté |
| 605 | 605 | **/ |
| 606 | 606 | function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') { |
| 607 | - $spip_table_objet = table_objet_sql($type); |
|
| 608 | - $id_table_objet = id_table_objet($type); |
|
| 609 | - |
|
| 610 | - // Controle des MD5 envoyes |
|
| 611 | - // On elimine les donnees non modifiees par le formulaire (mais |
|
| 612 | - // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 613 | - foreach ($champs as $key => $val) { |
|
| 614 | - if ( |
|
| 615 | - isset($ctr[$prefix . $key]) |
|
| 616 | - && ($m = $ctr[$prefix . $key]) |
|
| 617 | - && (is_scalar($val) && $m == md5($val)) |
|
| 618 | - ) { |
|
| 619 | - unset($champs[$key]); |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - if (!$champs) { |
|
| 623 | - return; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - // On veut savoir si notre modif va avoir un impact |
|
| 627 | - // par rapport aux donnees contenues dans la base |
|
| 628 | - // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 629 | - $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 630 | - $intact = true; |
|
| 631 | - foreach ($champs as $ch => $val) { |
|
| 632 | - $intact &= ($s[$ch] == $val); |
|
| 633 | - } |
|
| 634 | - if ($intact) { |
|
| 635 | - return; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - // Detection de conflits : |
|
| 639 | - // On verifie si notre modif ne provient pas d'un formulaire |
|
| 640 | - // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 641 | - // on compare a ce qui est dans la base, et on bloque en cas |
|
| 642 | - // de conflit. |
|
| 643 | - $ctrh = $ctrq = $conflits = []; |
|
| 644 | - foreach (array_keys($champs) as $key) { |
|
| 645 | - if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) { |
|
| 646 | - $ctrh[$key] = $m; |
|
| 647 | - $ctrq[] = $key; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - if ($ctrq) { |
|
| 651 | - $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 652 | - foreach ($ctrh as $key => $m) { |
|
| 653 | - if ( |
|
| 654 | - $m != md5((string) $ctrq[$key]) |
|
| 655 | - && $champs[$key] !== $ctrq[$key] |
|
| 656 | - ) { |
|
| 657 | - $conflits[$key] = [ |
|
| 658 | - 'base' => $ctrq[$key], |
|
| 659 | - 'post' => $champs[$key] |
|
| 660 | - ]; |
|
| 661 | - unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - return $conflits; |
|
| 607 | + $spip_table_objet = table_objet_sql($type); |
|
| 608 | + $id_table_objet = id_table_objet($type); |
|
| 609 | + |
|
| 610 | + // Controle des MD5 envoyes |
|
| 611 | + // On elimine les donnees non modifiees par le formulaire (mais |
|
| 612 | + // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 613 | + foreach ($champs as $key => $val) { |
|
| 614 | + if ( |
|
| 615 | + isset($ctr[$prefix . $key]) |
|
| 616 | + && ($m = $ctr[$prefix . $key]) |
|
| 617 | + && (is_scalar($val) && $m == md5($val)) |
|
| 618 | + ) { |
|
| 619 | + unset($champs[$key]); |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + if (!$champs) { |
|
| 623 | + return; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + // On veut savoir si notre modif va avoir un impact |
|
| 627 | + // par rapport aux donnees contenues dans la base |
|
| 628 | + // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 629 | + $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 630 | + $intact = true; |
|
| 631 | + foreach ($champs as $ch => $val) { |
|
| 632 | + $intact &= ($s[$ch] == $val); |
|
| 633 | + } |
|
| 634 | + if ($intact) { |
|
| 635 | + return; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + // Detection de conflits : |
|
| 639 | + // On verifie si notre modif ne provient pas d'un formulaire |
|
| 640 | + // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 641 | + // on compare a ce qui est dans la base, et on bloque en cas |
|
| 642 | + // de conflit. |
|
| 643 | + $ctrh = $ctrq = $conflits = []; |
|
| 644 | + foreach (array_keys($champs) as $key) { |
|
| 645 | + if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) { |
|
| 646 | + $ctrh[$key] = $m; |
|
| 647 | + $ctrq[] = $key; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + if ($ctrq) { |
|
| 651 | + $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 652 | + foreach ($ctrh as $key => $m) { |
|
| 653 | + if ( |
|
| 654 | + $m != md5((string) $ctrq[$key]) |
|
| 655 | + && $champs[$key] !== $ctrq[$key] |
|
| 656 | + ) { |
|
| 657 | + $conflits[$key] = [ |
|
| 658 | + 'base' => $ctrq[$key], |
|
| 659 | + 'post' => $champs[$key] |
|
| 660 | + ]; |
|
| 661 | + unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + return $conflits; |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | /** |
@@ -675,9 +675,9 @@ discard block |
||
| 675 | 675 | * @return string |
| 676 | 676 | */ |
| 677 | 677 | function display_conflit_champ($x) { |
| 678 | - if (strstr($x, "\n") || strlen($x) > 80) { |
|
| 679 | - return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 680 | - } else { |
|
| 681 | - return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 682 | - } |
|
| 678 | + if (strstr($x, "\n") || strlen($x) > 80) { |
|
| 679 | + return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 680 | + } else { |
|
| 681 | + return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 682 | + } |
|
| 683 | 683 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | $res['message_ok'] = _T('info_modification_enregistree'); |
| 100 | 100 | if ($retour) { |
| 101 | 101 | if (str_starts_with($retour, 'javascript:')) { |
| 102 | - $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 102 | + $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour, 11).'/*]]>*/</script>'; |
|
| 103 | 103 | $res['editable'] = true; |
| 104 | 104 | } else { |
| 105 | 105 | $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | if (!isset($erreurs[$champ])) { |
| 140 | 140 | $erreurs[$champ] = ''; |
| 141 | 141 | } |
| 142 | - $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 142 | + $erreurs[$champ] .= _T('alerte_modif_info_concourante')."<br /><textarea readonly='readonly' class='forml'>".entites_html($conflit['base']).'</textarea>'; |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | if ( |
| 220 | 220 | $config_fonc |
| 221 | 221 | && !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
| 222 | - && $config_fonc !== $table_objet . '_edit_config' |
|
| 222 | + && $config_fonc !== $table_objet.'_edit_config' |
|
| 223 | 223 | && ($args = test_formulaire_inclus_par_modele()) |
| 224 | 224 | && in_array($config_fonc, $args) |
| 225 | 225 | ) { |
@@ -231,12 +231,12 @@ discard block |
||
| 231 | 231 | // Appel direct dans un squelette |
| 232 | 232 | if (!$row) { |
| 233 | 233 | if (!$new || $lier_trad) { |
| 234 | - if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 234 | + if ($select = charger_fonction('precharger_'.$type, 'inc', true)) { |
|
| 235 | 235 | $row = $select($id, $id_parent, $lier_trad); |
| 236 | 236 | // si on a une fonction precharger, elle pu faire un reglage de langue |
| 237 | 237 | $lang_default = (empty($row['lang']) ? null : $row['lang']); |
| 238 | 238 | } else { |
| 239 | - $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id); |
|
| 239 | + $row = sql_fetsel('*', $table_objet_sql, $id_table_objet.'='.(int) $id); |
|
| 240 | 240 | } |
| 241 | 241 | if (!$new) { |
| 242 | 242 | $md5 = controles_md5($row ?: []); |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | $contexte['config'] = $config = $config_fonc($contexte); |
| 288 | 288 | if (!$lang_default) { |
| 289 | 289 | include_spip('inc/session'); |
| 290 | - $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 290 | + $lang_default = $config['langue'] ?? session_get('lang'); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | $config += [ |
@@ -309,13 +309,13 @@ discard block |
||
| 309 | 309 | unset($contexte['lang']); |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 312 | + $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n". |
|
| 313 | 313 | ($lier_trad |
| 314 | - ? "\n<input type='hidden' name='lier_trad' value='" . |
|
| 315 | - $lier_trad . |
|
| 316 | - "' />" . |
|
| 317 | - "\n<input type='hidden' name='changer_lang' value='" . |
|
| 318 | - $lang_default . |
|
| 314 | + ? "\n<input type='hidden' name='lier_trad' value='". |
|
| 315 | + $lier_trad. |
|
| 316 | + "' />". |
|
| 317 | + "\n<input type='hidden' name='changer_lang' value='". |
|
| 318 | + $lang_default. |
|
| 319 | 319 | "' />" |
| 320 | 320 | : '') |
| 321 | 321 | . $hidden |
@@ -356,14 +356,14 @@ discard block |
||
| 356 | 356 | $aider = charger_fonction('aider', 'inc'); |
| 357 | 357 | if (strlen($texte) > 28 * 1024) { |
| 358 | 358 | $texte = str_replace("\r\n", "\n", $texte); |
| 359 | - $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 359 | + $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 360 | 360 | if ($pos > 0 && $pos < 32 * 1024) { |
| 361 | - $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 361 | + $debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n"; |
|
| 362 | 362 | $suite = substr($texte, $pos + 2); |
| 363 | 363 | } else { |
| 364 | - $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 364 | + $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 365 | 365 | if (!($pos > 0 && $pos < 32 * 1024)) { |
| 366 | - $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 366 | + $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 367 | 367 | $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
| 368 | 368 | } else { |
| 369 | 369 | $decalage = 1; |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | $ctr = []; |
| 451 | 451 | foreach ($data as $key => $val) { |
| 452 | 452 | $m = md5($val ?? ''); |
| 453 | - $k = $prefixe . $key; |
|
| 453 | + $k = $prefixe.$key; |
|
| 454 | 454 | |
| 455 | 455 | $ctr[$k] = match ($format) { |
| 456 | 456 | 'html' => "<input type='hidden' value='$m' name='$k' />", |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | if ($format === 'html') { |
| 462 | - return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n"; |
|
| 462 | + return "\n\n<!-- controles md5 -->\n".implode("\n", $ctr)."\n\n"; |
|
| 463 | 463 | } else { |
| 464 | 464 | return $ctr; |
| 465 | 465 | } |
@@ -612,8 +612,8 @@ discard block |
||
| 612 | 612 | // potentiellement modifiees entre temps par un autre utilisateur) |
| 613 | 613 | foreach ($champs as $key => $val) { |
| 614 | 614 | if ( |
| 615 | - isset($ctr[$prefix . $key]) |
|
| 616 | - && ($m = $ctr[$prefix . $key]) |
|
| 615 | + isset($ctr[$prefix.$key]) |
|
| 616 | + && ($m = $ctr[$prefix.$key]) |
|
| 617 | 617 | && (is_scalar($val) && $m == md5($val)) |
| 618 | 618 | ) { |
| 619 | 619 | unset($champs[$key]); |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | // de conflit. |
| 643 | 643 | $ctrh = $ctrq = $conflits = []; |
| 644 | 644 | foreach (array_keys($champs) as $key) { |
| 645 | - if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) { |
|
| 645 | + if (isset($ctr[$prefix.$key]) && ($m = $ctr[$prefix.$key])) { |
|
| 646 | 646 | $ctrh[$key] = $m; |
| 647 | 647 | $ctrq[] = $key; |
| 648 | 648 | } |
@@ -676,8 +676,8 @@ discard block |
||
| 676 | 676 | */ |
| 677 | 677 | function display_conflit_champ($x) { |
| 678 | 678 | if (strstr($x, "\n") || strlen($x) > 80) { |
| 679 | - return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 679 | + return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n"; |
|
| 680 | 680 | } else { |
| 681 | - return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 681 | + return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n"; |
|
| 682 | 682 | } |
| 683 | 683 | } |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | if ($query) { |
| 47 | - $url .= '?' . $query; |
|
| 47 | + $url .= '?'.$query; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - return '/' . preg_replace(',^/,S', '', (string) $url); |
|
| 50 | + return '/'.preg_replace(',^/,S', '', (string) $url); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
| 78 | 78 | $r = array_pad($r, 3, ''); |
| 79 | 79 | |
| 80 | - return $r[1] . resolve_path($r[2]); |
|
| 80 | + return $r[1].resolve_path($r[2]); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | # L'url site spip est un lien absolu aussi |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | $hash = $regs[5] ?? ''; |
| 98 | 98 | } |
| 99 | 99 | return match (substr($lien, 0, 1)) { |
| 100 | - '/' => $debut . resolve_path($lien), |
|
| 101 | - '#' => $debut . resolve_path($dir . $mot . $get . $lien), |
|
| 102 | - '' => $debut . resolve_path($dir . $mot . $get . $hash), |
|
| 103 | - default => $debut . resolve_path($dir . $lien), |
|
| 100 | + '/' => $debut.resolve_path($lien), |
|
| 101 | + '#' => $debut.resolve_path($dir.$mot.$get.$lien), |
|
| 102 | + '' => $debut.resolve_path($dir.$mot.$get.$hash), |
|
| 103 | + default => $debut.resolve_path($dir.$lien), |
|
| 104 | 104 | }; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | return ''; |
| 130 | 130 | } |
| 131 | 131 | if (!$base) { |
| 132 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 132 | + $base = url_de_base().(_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | return suivre_lien($base, $url); |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @param array $protocoles_autorises |
| 153 | 153 | * @return bool |
| 154 | 154 | */ |
| 155 | -function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
|
| 155 | +function protocole_verifier($url_absolue, $protocoles_autorises = ['http', 'https']) { |
|
| 156 | 156 | |
| 157 | 157 | if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
| 158 | 158 | $protocole = $m[1]; |
@@ -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 | |
@@ -34,20 +34,20 @@ discard block |
||
| 34 | 34 | * @return string URL nettoyée |
| 35 | 35 | **/ |
| 36 | 36 | function resolve_path($url) { |
| 37 | - [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 38 | - while ( |
|
| 39 | - preg_match(',/\.?/,', (string) $url, $regs) # supprime // et /./ |
|
| 40 | - || preg_match(',/[^/]*/\.\./,S', (string) $url, $regs) # supprime /toto/../ |
|
| 41 | - || preg_match(',^/\.\./,S', (string) $url, $regs) # supprime les /../ du haut |
|
| 42 | - ) { |
|
| 43 | - $url = str_replace($regs[0], '/', (string) $url); |
|
| 44 | - } |
|
| 37 | + [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 38 | + while ( |
|
| 39 | + preg_match(',/\.?/,', (string) $url, $regs) # supprime // et /./ |
|
| 40 | + || preg_match(',/[^/]*/\.\./,S', (string) $url, $regs) # supprime /toto/../ |
|
| 41 | + || preg_match(',^/\.\./,S', (string) $url, $regs) # supprime les /../ du haut |
|
| 42 | + ) { |
|
| 43 | + $url = str_replace($regs[0], '/', (string) $url); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if ($query) { |
|
| 47 | - $url .= '?' . $query; |
|
| 48 | - } |
|
| 46 | + if ($query) { |
|
| 47 | + $url .= '?' . $query; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return '/' . preg_replace(',^/,S', '', (string) $url); |
|
| 50 | + return '/' . preg_replace(',^/,S', '', (string) $url); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -68,40 +68,40 @@ discard block |
||
| 68 | 68 | **/ |
| 69 | 69 | function suivre_lien($url, $lien) { |
| 70 | 70 | |
| 71 | - $mot = null; |
|
| 72 | - $get = null; |
|
| 73 | - $hash = null; |
|
| 74 | - if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 75 | - return $lien; |
|
| 76 | - } |
|
| 77 | - if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 78 | - $r = array_pad($r, 3, ''); |
|
| 71 | + $mot = null; |
|
| 72 | + $get = null; |
|
| 73 | + $hash = null; |
|
| 74 | + if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 75 | + return $lien; |
|
| 76 | + } |
|
| 77 | + if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 78 | + $r = array_pad($r, 3, ''); |
|
| 79 | 79 | |
| 80 | - return $r[1] . resolve_path($r[2]); |
|
| 81 | - } |
|
| 80 | + return $r[1] . resolve_path($r[2]); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - # L'url site spip est un lien absolu aussi |
|
| 84 | - if (isset($GLOBALS['meta']['adresse_site']) && $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 85 | - return $lien; |
|
| 86 | - } |
|
| 83 | + # L'url site spip est un lien absolu aussi |
|
| 84 | + if (isset($GLOBALS['meta']['adresse_site']) && $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 85 | + return $lien; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - # lien relatif, il faut verifier l'url de base |
|
| 89 | - # commencer par virer la chaine de get de l'url de base |
|
| 90 | - $dir = '/'; |
|
| 91 | - $debut = ''; |
|
| 92 | - if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 93 | - $debut = $regs[1]; |
|
| 94 | - $dir = strlen($regs[2]) ? $regs[2] : '/'; |
|
| 95 | - $mot = $regs[3]; |
|
| 96 | - $get = $regs[4] ?? ''; |
|
| 97 | - $hash = $regs[5] ?? ''; |
|
| 98 | - } |
|
| 99 | - return match (substr($lien, 0, 1)) { |
|
| 100 | - '/' => $debut . resolve_path($lien), |
|
| 101 | - '#' => $debut . resolve_path($dir . $mot . $get . $lien), |
|
| 102 | - '' => $debut . resolve_path($dir . $mot . $get . $hash), |
|
| 103 | - default => $debut . resolve_path($dir . $lien), |
|
| 104 | - }; |
|
| 88 | + # lien relatif, il faut verifier l'url de base |
|
| 89 | + # commencer par virer la chaine de get de l'url de base |
|
| 90 | + $dir = '/'; |
|
| 91 | + $debut = ''; |
|
| 92 | + if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 93 | + $debut = $regs[1]; |
|
| 94 | + $dir = strlen($regs[2]) ? $regs[2] : '/'; |
|
| 95 | + $mot = $regs[3]; |
|
| 96 | + $get = $regs[4] ?? ''; |
|
| 97 | + $hash = $regs[5] ?? ''; |
|
| 98 | + } |
|
| 99 | + return match (substr($lien, 0, 1)) { |
|
| 100 | + '/' => $debut . resolve_path($lien), |
|
| 101 | + '#' => $debut . resolve_path($dir . $mot . $get . $lien), |
|
| 102 | + '' => $debut . resolve_path($dir . $mot . $get . $hash), |
|
| 103 | + default => $debut . resolve_path($dir . $lien), |
|
| 104 | + }; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | |
@@ -124,15 +124,15 @@ discard block |
||
| 124 | 124 | * @return string texte ou URL (en absolus) |
| 125 | 125 | **/ |
| 126 | 126 | function url_absolue($url, $base = '') { |
| 127 | - $url = trim((string) $url); |
|
| 128 | - if (strlen($url = trim($url)) == 0) { |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 131 | - if (!$base) { |
|
| 132 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 133 | - } |
|
| 127 | + $url = trim((string) $url); |
|
| 128 | + if (strlen($url = trim($url)) == 0) { |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | + if (!$base) { |
|
| 132 | + $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - return suivre_lien($base, $url); |
|
| 135 | + return suivre_lien($base, $url); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | 145 | function protocole_implicite($url_absolue) { |
| 146 | - return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 146 | + return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,16 +154,16 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
| 156 | 156 | |
| 157 | - if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 158 | - $protocole = $m[1]; |
|
| 159 | - if ( |
|
| 160 | - in_array($protocole, $protocoles_autorises) |
|
| 161 | - || in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 162 | - ) { |
|
| 163 | - return true; |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - return false; |
|
| 157 | + if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 158 | + $protocole = $m[1]; |
|
| 159 | + if ( |
|
| 160 | + in_array($protocole, $protocoles_autorises) |
|
| 161 | + || in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 162 | + ) { |
|
| 163 | + return true; |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + return false; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -180,31 +180,31 @@ discard block |
||
| 180 | 180 | * @return string texte avec des URLs absolues |
| 181 | 181 | **/ |
| 182 | 182 | function liens_absolus($texte, $base = '') { |
| 183 | - if ($texte === null || $texte === '') { |
|
| 184 | - return ''; |
|
| 185 | - } |
|
| 186 | - if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 187 | - if (!function_exists('extraire_attribut')) { |
|
| 188 | - include_spip('inc/filtres'); |
|
| 189 | - } |
|
| 190 | - foreach ($liens as $lien) { |
|
| 191 | - foreach (['href', 'src'] as $attr) { |
|
| 192 | - $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 193 | - if ( |
|
| 194 | - strlen((string) $href) > 0 |
|
| 195 | - && !preg_match(';^((?:[a-z]{3,7}:)?//);iS', (string) $href) |
|
| 196 | - ) { |
|
| 197 | - $abs = url_absolue($href, $base); |
|
| 198 | - if (rtrim((string) $href, '/') !== rtrim($abs, '/') && !preg_match('/^#/', (string) $href)) { |
|
| 199 | - $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | - $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 183 | + if ($texte === null || $texte === '') { |
|
| 184 | + return ''; |
|
| 185 | + } |
|
| 186 | + if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 187 | + if (!function_exists('extraire_attribut')) { |
|
| 188 | + include_spip('inc/filtres'); |
|
| 189 | + } |
|
| 190 | + foreach ($liens as $lien) { |
|
| 191 | + foreach (['href', 'src'] as $attr) { |
|
| 192 | + $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 193 | + if ( |
|
| 194 | + strlen((string) $href) > 0 |
|
| 195 | + && !preg_match(';^((?:[a-z]{3,7}:)?//);iS', (string) $href) |
|
| 196 | + ) { |
|
| 197 | + $abs = url_absolue($href, $base); |
|
| 198 | + if (rtrim((string) $href, '/') !== rtrim($abs, '/') && !preg_match('/^#/', (string) $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 | 206 | |
| 207 | - return $texte; |
|
| 207 | + return $texte; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
@@ -222,12 +222,12 @@ discard block |
||
| 222 | 222 | * @return string texte ou URL (en absolus) |
| 223 | 223 | **/ |
| 224 | 224 | function abs_url($texte, $base = '') { |
| 225 | - trigger_deprecation('spip', '5.0', sprintf('Using "%s" is deprecated. Use "%s" or "%s"', __FUNCTION__, 'url_absolue', 'liens_absolus')); |
|
| 226 | - if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 227 | - return url_absolue($texte, $base); |
|
| 228 | - } else { |
|
| 229 | - return liens_absolus($texte, $base); |
|
| 230 | - } |
|
| 225 | + trigger_deprecation('spip', '5.0', sprintf('Using "%s" is deprecated. Use "%s" or "%s"', __FUNCTION__, 'url_absolue', 'liens_absolus')); |
|
| 226 | + if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 227 | + return url_absolue($texte, $base); |
|
| 228 | + } else { |
|
| 229 | + return liens_absolus($texte, $base); |
|
| 230 | + } |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | * @return string |
| 241 | 241 | */ |
| 242 | 242 | function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 243 | - if (is_null($flags)) { |
|
| 244 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 245 | - } |
|
| 243 | + if (is_null($flags)) { |
|
| 244 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 247 | + return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | * @return string |
| 258 | 258 | */ |
| 259 | 259 | function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 260 | - if (is_null($flags)) { |
|
| 261 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 262 | - } |
|
| 260 | + if (is_null($flags)) { |
|
| 261 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 264 | + return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 265 | 265 | } |
@@ -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 | |
@@ -46,24 +46,24 @@ discard block |
||
| 46 | 46 | * - false si l'arbre xml ne peut être créé ou est vide |
| 47 | 47 | **/ |
| 48 | 48 | function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1_048_576, $datas = '', $profondeur = -1) { |
| 49 | - $contenu = ''; |
|
| 50 | - if (tester_url_absolue($fichier)) { |
|
| 51 | - include_spip('inc/distant'); |
|
| 52 | - $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 53 | - $contenu = $contenu['page'] ?? ''; |
|
| 54 | - } else { |
|
| 55 | - lire_fichier($fichier, $contenu); |
|
| 56 | - } |
|
| 57 | - $arbre = []; |
|
| 58 | - if ($contenu) { |
|
| 59 | - $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | - } |
|
| 49 | + $contenu = ''; |
|
| 50 | + if (tester_url_absolue($fichier)) { |
|
| 51 | + include_spip('inc/distant'); |
|
| 52 | + $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 53 | + $contenu = $contenu['page'] ?? ''; |
|
| 54 | + } else { |
|
| 55 | + lire_fichier($fichier, $contenu); |
|
| 56 | + } |
|
| 57 | + $arbre = []; |
|
| 58 | + if ($contenu) { |
|
| 59 | + $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return count($arbre) ? $arbre : false; |
|
| 62 | + return count($arbre) ? $arbre : false; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | if (!defined('_SPIP_XML_TAG_SPLIT')) { |
| 66 | - define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS'); |
|
| 66 | + define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS'); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -82,150 +82,150 @@ discard block |
||
| 82 | 82 | * - false si l'arbre xml ne peut être créé ou est vide |
| 83 | 83 | **/ |
| 84 | 84 | function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) { |
| 85 | - $out = []; |
|
| 86 | - // enlever les commentaires |
|
| 87 | - $charset = 'AUTO'; |
|
| 88 | - if ($clean) { |
|
| 89 | - if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | - $charset = $regs[2]; |
|
| 91 | - } |
|
| 92 | - $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | - $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | - include_spip('inc/charsets'); |
|
| 95 | - $clean = $charset; |
|
| 96 | - //$texte = importer_charset($texte,$charset); |
|
| 97 | - } |
|
| 98 | - if (is_string($clean)) { |
|
| 99 | - $charset = $clean; |
|
| 100 | - } |
|
| 101 | - $txt = $texte; |
|
| 85 | + $out = []; |
|
| 86 | + // enlever les commentaires |
|
| 87 | + $charset = 'AUTO'; |
|
| 88 | + if ($clean) { |
|
| 89 | + if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | + $charset = $regs[2]; |
|
| 91 | + } |
|
| 92 | + $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | + $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | + include_spip('inc/charsets'); |
|
| 95 | + $clean = $charset; |
|
| 96 | + //$texte = importer_charset($texte,$charset); |
|
| 97 | + } |
|
| 98 | + if (is_string($clean)) { |
|
| 99 | + $charset = $clean; |
|
| 100 | + } |
|
| 101 | + $txt = $texte; |
|
| 102 | 102 | |
| 103 | - // tant qu'il y a des tags |
|
| 104 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | - while ((is_countable($chars) ? count($chars) : 0) >= 2) { |
|
| 106 | - // tag ouvrant |
|
| 107 | - //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 103 | + // tant qu'il y a des tags |
|
| 104 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | + while ((is_countable($chars) ? count($chars) : 0) >= 2) { |
|
| 106 | + // tag ouvrant |
|
| 107 | + //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 108 | 108 | |
| 109 | - // $before doit etre vide ou des espaces uniquements! |
|
| 110 | - $before = trim($chars[0]); |
|
| 109 | + // $before doit etre vide ou des espaces uniquements! |
|
| 110 | + $before = trim($chars[0]); |
|
| 111 | 111 | |
| 112 | - if (strlen($before) > 0) { |
|
| 113 | - return importer_charset($texte, $charset); |
|
| 114 | - }//$texte; // before non vide, donc on est dans du texte |
|
| 112 | + if (strlen($before) > 0) { |
|
| 113 | + return importer_charset($texte, $charset); |
|
| 114 | + }//$texte; // before non vide, donc on est dans du texte |
|
| 115 | 115 | |
| 116 | - $tag = rtrim($chars[1]); |
|
| 117 | - $txt = $chars[2]; |
|
| 116 | + $tag = rtrim($chars[1]); |
|
| 117 | + $txt = $chars[2]; |
|
| 118 | 118 | |
| 119 | - if (str_starts_with($tag, '![CDATA[')) { |
|
| 120 | - return importer_charset($texte, $charset); |
|
| 121 | - }//$texte; |
|
| 122 | - if (str_ends_with($tag, '/')) { // self closing tag |
|
| 123 | - $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | - $out[$tag][] = ''; |
|
| 125 | - } else { |
|
| 126 | - $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | - $closing_tag = reset($closing_tag); |
|
| 128 | - // tag fermant |
|
| 129 | - $ncclos = strlen("</$closing_tag>"); |
|
| 130 | - $p = strpos($txt, (string) "</$closing_tag>"); |
|
| 131 | - if ($p !== false && strpos($txt, '<') < $p) { |
|
| 132 | - $nclose = 0; |
|
| 133 | - $nopen = 0; |
|
| 134 | - $d = 0; |
|
| 135 | - while ( |
|
| 136 | - $p !== false |
|
| 137 | - && ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | - && ($nopen += preg_match_all( |
|
| 139 | - '{<' . preg_quote((string) $closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 140 | - $morceau, |
|
| 141 | - $matches, |
|
| 142 | - PREG_SET_ORDER |
|
| 143 | - )) > $nclose |
|
| 144 | - ) { |
|
| 145 | - $nclose++; |
|
| 146 | - $d = $p + $ncclos; |
|
| 147 | - $p = strpos($txt, (string) "</$closing_tag>", $d); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - if ($p === false) { |
|
| 151 | - if ($strict) { |
|
| 152 | - $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 119 | + if (str_starts_with($tag, '![CDATA[')) { |
|
| 120 | + return importer_charset($texte, $charset); |
|
| 121 | + }//$texte; |
|
| 122 | + if (str_ends_with($tag, '/')) { // self closing tag |
|
| 123 | + $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | + $out[$tag][] = ''; |
|
| 125 | + } else { |
|
| 126 | + $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | + $closing_tag = reset($closing_tag); |
|
| 128 | + // tag fermant |
|
| 129 | + $ncclos = strlen("</$closing_tag>"); |
|
| 130 | + $p = strpos($txt, (string) "</$closing_tag>"); |
|
| 131 | + if ($p !== false && strpos($txt, '<') < $p) { |
|
| 132 | + $nclose = 0; |
|
| 133 | + $nopen = 0; |
|
| 134 | + $d = 0; |
|
| 135 | + while ( |
|
| 136 | + $p !== false |
|
| 137 | + && ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | + && ($nopen += preg_match_all( |
|
| 139 | + '{<' . preg_quote((string) $closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 140 | + $morceau, |
|
| 141 | + $matches, |
|
| 142 | + PREG_SET_ORDER |
|
| 143 | + )) > $nclose |
|
| 144 | + ) { |
|
| 145 | + $nclose++; |
|
| 146 | + $d = $p + $ncclos; |
|
| 147 | + $p = strpos($txt, (string) "</$closing_tag>", $d); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + if ($p === false) { |
|
| 151 | + if ($strict) { |
|
| 152 | + $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 153 | 153 | |
| 154 | - return $out; |
|
| 155 | - } else { |
|
| 156 | - return importer_charset($texte, $charset); |
|
| 157 | - }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 158 | - } |
|
| 159 | - $content = substr($txt, 0, $p); |
|
| 160 | - $txt = substr($txt, $p + $ncclos); |
|
| 161 | - if ($profondeur == 0 || !str_contains($content, '<')) { // eviter une recursion si pas utile |
|
| 162 | - $out[$tag][] = importer_charset($content, $charset); |
|
| 163 | - }//$content; |
|
| 164 | - else { |
|
| 165 | - $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 169 | - } |
|
| 170 | - if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 171 | - return $out; |
|
| 172 | - } else { |
|
| 173 | - return importer_charset($texte, $charset); |
|
| 174 | - }//$texte; |
|
| 154 | + return $out; |
|
| 155 | + } else { |
|
| 156 | + return importer_charset($texte, $charset); |
|
| 157 | + }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 158 | + } |
|
| 159 | + $content = substr($txt, 0, $p); |
|
| 160 | + $txt = substr($txt, $p + $ncclos); |
|
| 161 | + if ($profondeur == 0 || !str_contains($content, '<')) { // eviter une recursion si pas utile |
|
| 162 | + $out[$tag][] = importer_charset($content, $charset); |
|
| 163 | + }//$content; |
|
| 164 | + else { |
|
| 165 | + $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 169 | + } |
|
| 170 | + if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 171 | + return $out; |
|
| 172 | + } else { |
|
| 173 | + return importer_charset($texte, $charset); |
|
| 174 | + }//$texte; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | function spip_xml_aplatit($arbre, $separateur = ' ') { |
| 178 | - $s = ''; |
|
| 179 | - if (is_array($arbre)) { |
|
| 180 | - foreach ($arbre as $tag => $feuille) { |
|
| 181 | - if (is_array($feuille)) { |
|
| 182 | - if ($tag !== (int) $tag) { |
|
| 183 | - $f = spip_xml_aplatit($feuille, $separateur); |
|
| 184 | - if (strlen((string) $f)) { |
|
| 185 | - $tagf = explode(' ', $tag); |
|
| 186 | - $tagf = $tagf[0]; |
|
| 187 | - $s .= "<$tag>$f</$tagf>"; |
|
| 188 | - } else { |
|
| 189 | - $s .= "<$tag />"; |
|
| 190 | - } |
|
| 191 | - } else { |
|
| 192 | - $s .= spip_xml_aplatit($feuille); |
|
| 193 | - } |
|
| 194 | - $s .= $separateur; |
|
| 195 | - } else { |
|
| 196 | - $s .= "$feuille$separateur"; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 178 | + $s = ''; |
|
| 179 | + if (is_array($arbre)) { |
|
| 180 | + foreach ($arbre as $tag => $feuille) { |
|
| 181 | + if (is_array($feuille)) { |
|
| 182 | + if ($tag !== (int) $tag) { |
|
| 183 | + $f = spip_xml_aplatit($feuille, $separateur); |
|
| 184 | + if (strlen((string) $f)) { |
|
| 185 | + $tagf = explode(' ', $tag); |
|
| 186 | + $tagf = $tagf[0]; |
|
| 187 | + $s .= "<$tag>$f</$tagf>"; |
|
| 188 | + } else { |
|
| 189 | + $s .= "<$tag />"; |
|
| 190 | + } |
|
| 191 | + } else { |
|
| 192 | + $s .= spip_xml_aplatit($feuille); |
|
| 193 | + } |
|
| 194 | + $s .= $separateur; |
|
| 195 | + } else { |
|
| 196 | + $s .= "$feuille$separateur"; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - return strlen((string) $separateur) ? substr($s, 0, -strlen((string) $separateur)) : $s; |
|
| 201 | + return strlen((string) $separateur) ? substr($s, 0, -strlen((string) $separateur)) : $s; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | function spip_xml_tagname($tag) { |
| 205 | - if (preg_match(',^([a-z][\w:]*),i', (string) $tag, $reg)) { |
|
| 206 | - return $reg[1]; |
|
| 207 | - } |
|
| 205 | + if (preg_match(',^([a-z][\w:]*),i', (string) $tag, $reg)) { |
|
| 206 | + return $reg[1]; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - return ''; |
|
| 209 | + return ''; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function spip_xml_decompose_tag($tag) { |
| 213 | - $tagname = spip_xml_tagname($tag); |
|
| 214 | - $liste = []; |
|
| 215 | - $tag = ltrim(strpbrk((string) $tag, " \n\t")); |
|
| 216 | - $p = strpos($tag, '='); |
|
| 217 | - while ($p !== false) { |
|
| 218 | - $attr = trim(substr($tag, 0, $p)); |
|
| 219 | - $tag = ltrim(substr($tag, $p + 1)); |
|
| 220 | - $quote = $tag[0]; |
|
| 221 | - $p = strpos($tag, $quote, 1); |
|
| 222 | - $cont = substr($tag, 1, $p - 1); |
|
| 223 | - $liste[$attr] = $cont; |
|
| 224 | - $tag = substr($tag, $p + 1); |
|
| 225 | - $p = strpos($tag, '='); |
|
| 226 | - } |
|
| 213 | + $tagname = spip_xml_tagname($tag); |
|
| 214 | + $liste = []; |
|
| 215 | + $tag = ltrim(strpbrk((string) $tag, " \n\t")); |
|
| 216 | + $p = strpos($tag, '='); |
|
| 217 | + while ($p !== false) { |
|
| 218 | + $attr = trim(substr($tag, 0, $p)); |
|
| 219 | + $tag = ltrim(substr($tag, $p + 1)); |
|
| 220 | + $quote = $tag[0]; |
|
| 221 | + $p = strpos($tag, $quote, 1); |
|
| 222 | + $cont = substr($tag, 1, $p - 1); |
|
| 223 | + $liste[$attr] = $cont; |
|
| 224 | + $tag = substr($tag, $p + 1); |
|
| 225 | + $p = strpos($tag, '='); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - return [$tagname, $liste]; |
|
| 228 | + return [$tagname, $liste]; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -248,21 +248,21 @@ discard block |
||
| 248 | 248 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 249 | 249 | **/ |
| 250 | 250 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
| 251 | - if ($init) { |
|
| 252 | - $matches = []; |
|
| 253 | - } |
|
| 254 | - if (is_array($arbre) && count($arbre)) { |
|
| 255 | - foreach (array_keys($arbre) as $tag) { |
|
| 256 | - if (preg_match($regexp, $tag)) { |
|
| 257 | - $matches[$tag] = &$arbre[$tag]; |
|
| 258 | - } |
|
| 259 | - if (is_array($arbre[$tag])) { |
|
| 260 | - foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 261 | - spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 251 | + if ($init) { |
|
| 252 | + $matches = []; |
|
| 253 | + } |
|
| 254 | + if (is_array($arbre) && count($arbre)) { |
|
| 255 | + foreach (array_keys($arbre) as $tag) { |
|
| 256 | + if (preg_match($regexp, $tag)) { |
|
| 257 | + $matches[$tag] = &$arbre[$tag]; |
|
| 258 | + } |
|
| 259 | + if (is_array($arbre[$tag])) { |
|
| 260 | + foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 261 | + spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - return (is_countable($matches) ? count($matches) : 0); |
|
| 267 | + return (is_countable($matches) ? count($matches) : 0); |
|
| 268 | 268 | } |
@@ -136,7 +136,7 @@ |
||
| 136 | 136 | $p !== false |
| 137 | 137 | && ($morceau = substr($txt, $d, $p - $d)) |
| 138 | 138 | && ($nopen += preg_match_all( |
| 139 | - '{<' . preg_quote((string) $closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 139 | + '{<'.preg_quote((string) $closing_tag).'(\s*>|\s[^>]*[^/>]>)}is', |
|
| 140 | 140 | $morceau, |
| 141 | 141 | $matches, |
| 142 | 142 | PREG_SET_ORDER |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | use Spip\Texte\Collecteur\Modeles; |
| 14 | 14 | |
| 15 | 15 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 16 | - return; |
|
| 16 | + return; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function traiter_modeles($texte, $doublons = false, $echap = '', string $connect = '', ?Liens $collecteurLiens = null, $env = []) { |
| 28 | 28 | |
| 29 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 30 | - include_spip('src/Texte/Collecteur/Modeles'); |
|
| 31 | - $collecteurModeles = new Modeles(); |
|
| 29 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 30 | + include_spip('src/Texte/Collecteur/Modeles'); |
|
| 31 | + $collecteurModeles = new Modeles(); |
|
| 32 | 32 | |
| 33 | - $options = [ |
|
| 34 | - 'doublons' => $doublons, |
|
| 35 | - 'echap' => $echap, |
|
| 36 | - 'connect' => $connect, |
|
| 37 | - 'collecteurLiens' => $collecteurLiens, |
|
| 38 | - 'env' => $env |
|
| 39 | - ]; |
|
| 40 | - return $collecteurModeles->traiter($texte ?? '', $options); |
|
| 33 | + $options = [ |
|
| 34 | + 'doublons' => $doublons, |
|
| 35 | + 'echap' => $echap, |
|
| 36 | + 'connect' => $connect, |
|
| 37 | + 'collecteurLiens' => $collecteurLiens, |
|
| 38 | + 'env' => $env |
|
| 39 | + ]; |
|
| 40 | + return $collecteurModeles->traiter($texte ?? '', $options); |
|
| 41 | 41 | } |
@@ -10,76 +10,76 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | # Les information d'une rubrique selectionnee dans le mini navigateur |
| 17 | 17 | |
| 18 | 18 | function inc_informer_dist($id, $col, $exclus, $rac, $type, $do = 'aff') { |
| 19 | - include_spip('inc/texte'); |
|
| 20 | - $titre = $descriptif = ''; |
|
| 21 | - if ($type === 'rubrique') { |
|
| 22 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . (int) $id); |
|
| 23 | - if ($row) { |
|
| 24 | - $titre = typo($row['titre']); |
|
| 25 | - $descriptif = propre($row['descriptif']); |
|
| 26 | - } else { |
|
| 27 | - $titre = _T('info_racine_site'); |
|
| 28 | - } |
|
| 29 | - } |
|
| 19 | + include_spip('inc/texte'); |
|
| 20 | + $titre = $descriptif = ''; |
|
| 21 | + if ($type === 'rubrique') { |
|
| 22 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . (int) $id); |
|
| 23 | + if ($row) { |
|
| 24 | + $titre = typo($row['titre']); |
|
| 25 | + $descriptif = propre($row['descriptif']); |
|
| 26 | + } else { |
|
| 27 | + $titre = _T('info_racine_site'); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - $res = ''; |
|
| 32 | - if ( |
|
| 33 | - $type === 'rubrique' |
|
| 34 | - && (int) ($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 35 | - && isset($GLOBALS['meta']['image_process']) |
|
| 36 | - && $GLOBALS['meta']['image_process'] !== 'non' |
|
| 37 | - ) { |
|
| 38 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 39 | - if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 40 | - [$fid, $dir, $nom, $format] = $res; |
|
| 41 | - include_spip('inc/filtres_images_mini'); |
|
| 42 | - $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 43 | - if ($res) { |
|
| 44 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 31 | + $res = ''; |
|
| 32 | + if ( |
|
| 33 | + $type === 'rubrique' |
|
| 34 | + && (int) ($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 35 | + && isset($GLOBALS['meta']['image_process']) |
|
| 36 | + && $GLOBALS['meta']['image_process'] !== 'non' |
|
| 37 | + ) { |
|
| 38 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 39 | + if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 40 | + [$fid, $dir, $nom, $format] = $res; |
|
| 41 | + include_spip('inc/filtres_images_mini'); |
|
| 42 | + $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 43 | + if ($res) { |
|
| 44 | + $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 50 | - $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 51 | - $id = (int) $id; |
|
| 49 | + $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 50 | + $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 51 | + $id = (int) $id; |
|
| 52 | 52 | |
| 53 | 53 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 54 | 54 | # et l'affichage de son titre dans le bandeau |
| 55 | - $titre = strtr( |
|
| 56 | - str_replace( |
|
| 57 | - "'", |
|
| 58 | - '’', |
|
| 59 | - str_replace('"', '"', (string) textebrut($titre)) |
|
| 60 | - ), |
|
| 61 | - "\n\r", |
|
| 62 | - ' ' |
|
| 63 | - ); |
|
| 55 | + $titre = strtr( |
|
| 56 | + str_replace( |
|
| 57 | + "'", |
|
| 58 | + '’', |
|
| 59 | + str_replace('"', '"', (string) textebrut($titre)) |
|
| 60 | + ), |
|
| 61 | + "\n\r", |
|
| 62 | + ' ' |
|
| 63 | + ); |
|
| 64 | 64 | |
| 65 | - $js_func = $do . '_selection_titre'; |
|
| 65 | + $js_func = $do . '_selection_titre'; |
|
| 66 | 66 | |
| 67 | - return "<div style='display: none;'>" |
|
| 68 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 69 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 70 | - . entites_html($titre) |
|
| 71 | - . '" />' |
|
| 72 | - . '</div>' |
|
| 73 | - . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 74 | - . '<div class="informer__item">' |
|
| 75 | - . ($res ?: '') |
|
| 76 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 77 | - . ($descriptif ? "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>' : '') |
|
| 78 | - . '</div>' |
|
| 79 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 80 | - . "<input type='submit' class='fondo btn submit' value='" |
|
| 81 | - . _T('bouton_choisir') |
|
| 82 | - . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 83 | - . '</div>' |
|
| 84 | - . '</div>'; |
|
| 67 | + return "<div style='display: none;'>" |
|
| 68 | + . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 69 | + . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 70 | + . entites_html($titre) |
|
| 71 | + . '" />' |
|
| 72 | + . '</div>' |
|
| 73 | + . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 74 | + . '<div class="informer__item">' |
|
| 75 | + . ($res ?: '') |
|
| 76 | + . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 77 | + . ($descriptif ? "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>' : '') |
|
| 78 | + . '</div>' |
|
| 79 | + . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 80 | + . "<input type='submit' class='fondo btn submit' value='" |
|
| 81 | + . _T('bouton_choisir') |
|
| 82 | + . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 83 | + . '</div>' |
|
| 84 | + . '</div>'; |
|
| 85 | 85 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | include_spip('inc/texte'); |
| 20 | 20 | $titre = $descriptif = ''; |
| 21 | 21 | if ($type === 'rubrique') { |
| 22 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . (int) $id); |
|
| 22 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = '.(int) $id); |
|
| 23 | 23 | if ($row) { |
| 24 | 24 | $titre = typo($row['titre']); |
| 25 | 25 | $descriptif = propre($row['descriptif']); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | include_spip('inc/filtres_images_mini'); |
| 42 | 42 | $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
| 43 | 43 | if ($res) { |
| 44 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 44 | + $res = "<div class='informer__media' style='float: ".$GLOBALS['spip_lang_right'].'; margin-'.$GLOBALS['spip_lang_right'].": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | } |
@@ -62,21 +62,21 @@ discard block |
||
| 62 | 62 | ' ' |
| 63 | 63 | ); |
| 64 | 64 | |
| 65 | - $js_func = $do . '_selection_titre'; |
|
| 65 | + $js_func = $do.'_selection_titre'; |
|
| 66 | 66 | |
| 67 | 67 | return "<div style='display: none;'>" |
| 68 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 69 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 68 | + . "<input type='text' id='".$rac."_sel' value='$id' />" |
|
| 69 | + . "<input type='text' id='".$rac."_sel2' value=\"" |
|
| 70 | 70 | . entites_html($titre) |
| 71 | 71 | . '" />' |
| 72 | 72 | . '</div>' |
| 73 | 73 | . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
| 74 | 74 | . '<div class="informer__item">' |
| 75 | 75 | . ($res ?: '') |
| 76 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 77 | - . ($descriptif ? "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>' : '') |
|
| 76 | + . "<p class='informer__titre'><b>".safehtml($titre).'</b></p>' |
|
| 77 | + . ($descriptif ? "<div class='informer__descriptif'>".safehtml($descriptif).'</div>' : '') |
|
| 78 | 78 | . '</div>' |
| 79 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 79 | + . "<div class='informer__action' style='clear:both; text-align: ".$GLOBALS['spip_lang_right'].";'>" |
|
| 80 | 80 | . "<input type='submit' class='fondo btn submit' value='" |
| 81 | 81 | . _T('bouton_choisir') |
| 82 | 82 | . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
@@ -17,16 +17,16 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_SPIP_SELECT_RUBRIQUES')) { |
| 24 | - /** |
|
| 25 | - * @var int Nombre de rubriques maximum du sélecteur de rubriques. |
|
| 26 | - * Au delà, on bascule sur un sélecteur ajax. |
|
| 27 | - * mettre 100000 pour desactiver ajax |
|
| 28 | - */ |
|
| 29 | - define('_SPIP_SELECT_RUBRIQUES', 20); |
|
| 24 | + /** |
|
| 25 | + * @var int Nombre de rubriques maximum du sélecteur de rubriques. |
|
| 26 | + * Au delà, on bascule sur un sélecteur ajax. |
|
| 27 | + * mettre 100000 pour desactiver ajax |
|
| 28 | + */ |
|
| 29 | + define('_SPIP_SELECT_RUBRIQUES', 20); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -54,22 +54,22 @@ discard block |
||
| 54 | 54 | * Code HTML du sélecteur |
| 55 | 55 | **/ |
| 56 | 56 | function inc_chercher_rubrique_dist($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') { |
| 57 | - if (sql_countsel('spip_rubriques') < 1) { |
|
| 58 | - return ''; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // Mode sans Ajax : |
|
| 62 | - // - soit parce que le cookie ajax n'est pas la |
|
| 63 | - // - soit parce qu'il y a peu de rubriques |
|
| 64 | - if ( |
|
| 65 | - _SPIP_AJAX < 1 |
|
| 66 | - || $type == 'breve' |
|
| 67 | - || sql_countsel('spip_rubriques') < _SPIP_SELECT_RUBRIQUES |
|
| 68 | - ) { |
|
| 69 | - return selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem); |
|
| 70 | - } else { |
|
| 71 | - return selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem, $do); |
|
| 72 | - } |
|
| 57 | + if (sql_countsel('spip_rubriques') < 1) { |
|
| 58 | + return ''; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // Mode sans Ajax : |
|
| 62 | + // - soit parce que le cookie ajax n'est pas la |
|
| 63 | + // - soit parce qu'il y a peu de rubriques |
|
| 64 | + if ( |
|
| 65 | + _SPIP_AJAX < 1 |
|
| 66 | + || $type == 'breve' |
|
| 67 | + || sql_countsel('spip_rubriques') < _SPIP_SELECT_RUBRIQUES |
|
| 68 | + ) { |
|
| 69 | + return selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem); |
|
| 70 | + } else { |
|
| 71 | + return selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem, $do); |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // compatibilite pour extensions qui utilisaient l'ancien nom |
@@ -86,17 +86,17 @@ discard block |
||
| 86 | 86 | **/ |
| 87 | 87 | function style_menu_rubriques($i) { |
| 88 | 88 | |
| 89 | - $espace = ''; |
|
| 90 | - $style = ''; |
|
| 91 | - for ($count = 1; $count <= $i; $count++) { |
|
| 92 | - $espace .= ' '; |
|
| 93 | - } |
|
| 94 | - if ($i == 1) { |
|
| 95 | - $espace = ''; |
|
| 96 | - } |
|
| 97 | - $class = "niveau_$i"; |
|
| 98 | - |
|
| 99 | - return [$class, $style, $espace]; |
|
| 89 | + $espace = ''; |
|
| 90 | + $style = ''; |
|
| 91 | + for ($count = 1; $count <= $i; $count++) { |
|
| 92 | + $espace .= ' '; |
|
| 93 | + } |
|
| 94 | + if ($i == 1) { |
|
| 95 | + $espace = ''; |
|
| 96 | + } |
|
| 97 | + $class = "niveau_$i"; |
|
| 98 | + |
|
| 99 | + return [$class, $style, $espace]; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -120,57 +120,57 @@ discard block |
||
| 120 | 120 | * Code HTML du sélecteur |
| 121 | 121 | **/ |
| 122 | 122 | function sous_menu_rubriques($id_rubrique, $root, $niv, &$data, &$enfants, $exclus, $restreint, $type) { |
| 123 | - static $decalage_secteur; |
|
| 124 | - |
|
| 125 | - // Si on a demande l'exclusion ne pas descendre dans la rubrique courante |
|
| 126 | - if ($exclus > 0 && $root == $exclus) { |
|
| 127 | - return ''; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // en fonction du niveau faire un affichage plus ou moins kikoo |
|
| 131 | - |
|
| 132 | - // selected ? |
|
| 133 | - $selected = ($root == $id_rubrique) ? ' selected="selected"' : ''; |
|
| 134 | - |
|
| 135 | - // le style en fonction de la profondeur |
|
| 136 | - [$class, $style, $espace] = style_menu_rubriques($niv); |
|
| 137 | - |
|
| 138 | - $class .= ' selec_rub'; |
|
| 139 | - |
|
| 140 | - // creer l'<option> pour la rubrique $root |
|
| 141 | - |
|
| 142 | - if (isset($data[$root])) { # pas de racine sauf pour les rubriques |
|
| 143 | - $r = "<option$selected value='$root' class='$class' style='$style'>$espace" |
|
| 144 | - . $data[$root] |
|
| 145 | - . '</option>' . "\n"; |
|
| 146 | - } else { |
|
| 147 | - $r = ''; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // et le sous-menu pour ses enfants |
|
| 151 | - $sous = ''; |
|
| 152 | - if (isset($enfants[$root])) { |
|
| 153 | - foreach ($enfants[$root] as $sousrub) { |
|
| 154 | - $sous .= sous_menu_rubriques( |
|
| 155 | - $id_rubrique, |
|
| 156 | - $sousrub, |
|
| 157 | - $niv + 1, |
|
| 158 | - $data, |
|
| 159 | - $enfants, |
|
| 160 | - $exclus, |
|
| 161 | - $restreint, |
|
| 162 | - $type |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // si l'objet a deplacer est publie, verifier qu'on a acces aux rubriques |
|
| 168 | - if ($restreint && $root != $id_rubrique && !autoriser('publierdans', 'rubrique', $root)) { |
|
| 169 | - return $sous; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // et voila le travail |
|
| 173 | - return $r . $sous; |
|
| 123 | + static $decalage_secteur; |
|
| 124 | + |
|
| 125 | + // Si on a demande l'exclusion ne pas descendre dans la rubrique courante |
|
| 126 | + if ($exclus > 0 && $root == $exclus) { |
|
| 127 | + return ''; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // en fonction du niveau faire un affichage plus ou moins kikoo |
|
| 131 | + |
|
| 132 | + // selected ? |
|
| 133 | + $selected = ($root == $id_rubrique) ? ' selected="selected"' : ''; |
|
| 134 | + |
|
| 135 | + // le style en fonction de la profondeur |
|
| 136 | + [$class, $style, $espace] = style_menu_rubriques($niv); |
|
| 137 | + |
|
| 138 | + $class .= ' selec_rub'; |
|
| 139 | + |
|
| 140 | + // creer l'<option> pour la rubrique $root |
|
| 141 | + |
|
| 142 | + if (isset($data[$root])) { # pas de racine sauf pour les rubriques |
|
| 143 | + $r = "<option$selected value='$root' class='$class' style='$style'>$espace" |
|
| 144 | + . $data[$root] |
|
| 145 | + . '</option>' . "\n"; |
|
| 146 | + } else { |
|
| 147 | + $r = ''; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // et le sous-menu pour ses enfants |
|
| 151 | + $sous = ''; |
|
| 152 | + if (isset($enfants[$root])) { |
|
| 153 | + foreach ($enfants[$root] as $sousrub) { |
|
| 154 | + $sous .= sous_menu_rubriques( |
|
| 155 | + $id_rubrique, |
|
| 156 | + $sousrub, |
|
| 157 | + $niv + 1, |
|
| 158 | + $data, |
|
| 159 | + $enfants, |
|
| 160 | + $exclus, |
|
| 161 | + $restreint, |
|
| 162 | + $type |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // si l'objet a deplacer est publie, verifier qu'on a acces aux rubriques |
|
| 168 | + if ($restreint && $root != $id_rubrique && !autoriser('publierdans', 'rubrique', $root)) { |
|
| 169 | + return $sous; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // et voila le travail |
|
| 173 | + return $r . $sous; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -191,75 +191,75 @@ discard block |
||
| 191 | 191 | * Code HTML du sélecteur |
| 192 | 192 | **/ |
| 193 | 193 | function selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem = 0) { |
| 194 | - $enfants = []; |
|
| 195 | - $data = []; |
|
| 196 | - if ($type == 'rubrique' && autoriser('publierdans', 'rubrique', 0)) { |
|
| 197 | - $data[0] = _T('info_racine_site'); |
|
| 198 | - } |
|
| 199 | - # premier choix = neant |
|
| 200 | - # si auteur (rubriques restreintes) |
|
| 201 | - # ou si creation avec id_rubrique=0 |
|
| 202 | - elseif ($type == 'auteur' || !$id_rubrique) { |
|
| 203 | - $data[0] = ' '; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // |
|
| 207 | - // creer une structure contenant toute l'arborescence |
|
| 208 | - // |
|
| 209 | - |
|
| 210 | - include_spip('base/abstract_sql'); |
|
| 211 | - $q = sql_select( |
|
| 212 | - 'id_rubrique, id_parent, titre, statut, lang, langue_choisie', |
|
| 213 | - 'spip_rubriques', |
|
| 214 | - ($type == 'breve' ? ' id_parent=0 ' : ''), |
|
| 215 | - '', |
|
| 216 | - '0+titre,titre' |
|
| 217 | - ); |
|
| 218 | - while ($r = sql_fetch($q)) { |
|
| 219 | - if (autoriser('voir', 'rubrique', $r['id_rubrique'])) { |
|
| 220 | - // titre largeur maxi a 50 |
|
| 221 | - $titre = couper(supprimer_tags(typo($r['titre'])) . ' ', 50); |
|
| 222 | - if ( |
|
| 223 | - $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 224 | - && ($r['langue_choisie'] == 'oui' || $r['id_parent'] == 0) |
|
| 225 | - ) { |
|
| 226 | - $titre .= ' [' . traduire_nom_langue($r['lang']) . ']'; |
|
| 227 | - } |
|
| 228 | - $data[$r['id_rubrique']] = $titre; |
|
| 229 | - $enfants[$r['id_parent']][] = $r['id_rubrique']; |
|
| 230 | - if ($id_rubrique == $r['id_rubrique']) { |
|
| 231 | - $id_parent = $r['id_parent']; |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // si une seule rubrique comme choix possible, |
|
| 237 | - // inutile de mettre le selecteur sur un choix vide par defaut |
|
| 238 | - // sauf si le selecteur s'adresse a une rubrique puisque on peut la mettre a la racine dans ce cas |
|
| 239 | - if ( |
|
| 240 | - count($data) == 2 |
|
| 241 | - && isset($data[0]) |
|
| 242 | - && !in_array($type, ['auteur', 'rubrique']) |
|
| 243 | - && !$id_rubrique |
|
| 244 | - ) { |
|
| 245 | - unset($data[0]); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - $opt = sous_menu_rubriques($id_rubrique, 0, 0, $data, $enfants, $idem, $restreint, $type); |
|
| 250 | - $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'"; |
|
| 251 | - |
|
| 252 | - if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) { |
|
| 253 | - $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2]; |
|
| 254 | - } else { |
|
| 255 | - $r = '<select' . $att . " size='1'>\n$opt</select>\n"; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - # message pour neuneus (a supprimer ?) |
|
| 194 | + $enfants = []; |
|
| 195 | + $data = []; |
|
| 196 | + if ($type == 'rubrique' && autoriser('publierdans', 'rubrique', 0)) { |
|
| 197 | + $data[0] = _T('info_racine_site'); |
|
| 198 | + } |
|
| 199 | + # premier choix = neant |
|
| 200 | + # si auteur (rubriques restreintes) |
|
| 201 | + # ou si creation avec id_rubrique=0 |
|
| 202 | + elseif ($type == 'auteur' || !$id_rubrique) { |
|
| 203 | + $data[0] = ' '; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // |
|
| 207 | + // creer une structure contenant toute l'arborescence |
|
| 208 | + // |
|
| 209 | + |
|
| 210 | + include_spip('base/abstract_sql'); |
|
| 211 | + $q = sql_select( |
|
| 212 | + 'id_rubrique, id_parent, titre, statut, lang, langue_choisie', |
|
| 213 | + 'spip_rubriques', |
|
| 214 | + ($type == 'breve' ? ' id_parent=0 ' : ''), |
|
| 215 | + '', |
|
| 216 | + '0+titre,titre' |
|
| 217 | + ); |
|
| 218 | + while ($r = sql_fetch($q)) { |
|
| 219 | + if (autoriser('voir', 'rubrique', $r['id_rubrique'])) { |
|
| 220 | + // titre largeur maxi a 50 |
|
| 221 | + $titre = couper(supprimer_tags(typo($r['titre'])) . ' ', 50); |
|
| 222 | + if ( |
|
| 223 | + $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 224 | + && ($r['langue_choisie'] == 'oui' || $r['id_parent'] == 0) |
|
| 225 | + ) { |
|
| 226 | + $titre .= ' [' . traduire_nom_langue($r['lang']) . ']'; |
|
| 227 | + } |
|
| 228 | + $data[$r['id_rubrique']] = $titre; |
|
| 229 | + $enfants[$r['id_parent']][] = $r['id_rubrique']; |
|
| 230 | + if ($id_rubrique == $r['id_rubrique']) { |
|
| 231 | + $id_parent = $r['id_parent']; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // si une seule rubrique comme choix possible, |
|
| 237 | + // inutile de mettre le selecteur sur un choix vide par defaut |
|
| 238 | + // sauf si le selecteur s'adresse a une rubrique puisque on peut la mettre a la racine dans ce cas |
|
| 239 | + if ( |
|
| 240 | + count($data) == 2 |
|
| 241 | + && isset($data[0]) |
|
| 242 | + && !in_array($type, ['auteur', 'rubrique']) |
|
| 243 | + && !$id_rubrique |
|
| 244 | + ) { |
|
| 245 | + unset($data[0]); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + $opt = sous_menu_rubriques($id_rubrique, 0, 0, $data, $enfants, $idem, $restreint, $type); |
|
| 250 | + $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'"; |
|
| 251 | + |
|
| 252 | + if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) { |
|
| 253 | + $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2]; |
|
| 254 | + } else { |
|
| 255 | + $r = '<select' . $att . " size='1'>\n$opt</select>\n"; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + # message pour neuneus (a supprimer ?) |
|
| 259 | 259 | # if ($type != 'auteur' AND $type != 'breve') |
| 260 | 260 | # $r .= "\n<br />"._T('texte_rappel_selection_champs'); |
| 261 | 261 | |
| 262 | - return $r; |
|
| 262 | + return $r; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -293,22 +293,22 @@ discard block |
||
| 293 | 293 | */ |
| 294 | 294 | function selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') { |
| 295 | 295 | |
| 296 | - if ($id_rubrique) { |
|
| 297 | - $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 298 | - } else { |
|
| 299 | - $titre = $type == 'auteur' ? ' ' : _T('info_racine_site'); |
|
| 300 | - } |
|
| 296 | + if ($id_rubrique) { |
|
| 297 | + $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 298 | + } else { |
|
| 299 | + $titre = $type == 'auteur' ? ' ' : _T('info_racine_site'); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - $titre = str_replace('&', '&', (string) entites_html(textebrut(typo($titre)))); |
|
| 303 | - $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'"; |
|
| 302 | + $titre = str_replace('&', '&', (string) entites_html(textebrut(typo($titre)))); |
|
| 303 | + $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'"; |
|
| 304 | 304 | |
| 305 | - $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do" |
|
| 306 | - . ($idem ? "&exclus=$idem" : '') |
|
| 307 | - . ($restreint ? '' : '&racine=oui') |
|
| 308 | - . (isset($GLOBALS['var_profile']) ? '&var_profile=1' : '')); |
|
| 305 | + $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do" |
|
| 306 | + . ($idem ? "&exclus=$idem" : '') |
|
| 307 | + . ($restreint ? '' : '&racine=oui') |
|
| 308 | + . (isset($GLOBALS['var_profile']) ? '&var_profile=1' : '')); |
|
| 309 | 309 | |
| 310 | 310 | |
| 311 | - return construire_selecteur($url, '', 'selection_rubrique', 'id_parent', $init, $id_rubrique); |
|
| 311 | + return construire_selecteur($url, '', 'selection_rubrique', 'id_parent', $init, $id_rubrique); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -338,30 +338,30 @@ discard block |
||
| 338 | 338 | * Code HTML du sélecteur de rubrique AJAX |
| 339 | 339 | **/ |
| 340 | 340 | function construire_selecteur($url, $js, $idom, $name, $init = '', $id = 0) { |
| 341 | - $icone = (str_contains($idom, 'auteur')) ? 'auteur-24.png' : 'rechercher-20.png'; |
|
| 342 | - // si icone de recherche on embed le svg |
|
| 343 | - $balise = ($icone === 'rechercher-20.png' ? chercher_filtre('balise_svg') : chercher_filtre('balise_img')); |
|
| 344 | - $img_icone = $balise(chemin_image($icone), _T('titre_image_selecteur')); |
|
| 345 | - |
|
| 346 | - return |
|
| 347 | - "<div class='rubrique_actuelle'><a href='#' class='rubrique-search' role='button' style='display:inline-flex;vertical-align:middle;' onclick=\"" |
|
| 348 | - . $js |
|
| 349 | - . " jQuery(this).toggleClass('toggled'); " |
|
| 350 | - . "return charger_node_url_si_vide('" |
|
| 351 | - . $url |
|
| 352 | - . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'>" |
|
| 353 | - . $img_icone |
|
| 354 | - . "</a><img src='" |
|
| 355 | - . chemin_image('loader.svg') |
|
| 356 | - . "' class='loader' id='img_" |
|
| 357 | - . $idom |
|
| 358 | - . "'\nstyle='visibility: hidden;' alt='*' />" |
|
| 359 | - . "<input id='titreparent' name='titreparent' class='text'" |
|
| 360 | - . $init |
|
| 361 | - . ' />' |
|
| 362 | - . "<input type='hidden' id='$name' name='$name' value='" |
|
| 363 | - . $id |
|
| 364 | - . "' /><div class='nettoyeur'></div></div><div id='" |
|
| 365 | - . $idom |
|
| 366 | - . "'\nstyle='display: none;'></div>"; |
|
| 341 | + $icone = (str_contains($idom, 'auteur')) ? 'auteur-24.png' : 'rechercher-20.png'; |
|
| 342 | + // si icone de recherche on embed le svg |
|
| 343 | + $balise = ($icone === 'rechercher-20.png' ? chercher_filtre('balise_svg') : chercher_filtre('balise_img')); |
|
| 344 | + $img_icone = $balise(chemin_image($icone), _T('titre_image_selecteur')); |
|
| 345 | + |
|
| 346 | + return |
|
| 347 | + "<div class='rubrique_actuelle'><a href='#' class='rubrique-search' role='button' style='display:inline-flex;vertical-align:middle;' onclick=\"" |
|
| 348 | + . $js |
|
| 349 | + . " jQuery(this).toggleClass('toggled'); " |
|
| 350 | + . "return charger_node_url_si_vide('" |
|
| 351 | + . $url |
|
| 352 | + . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'>" |
|
| 353 | + . $img_icone |
|
| 354 | + . "</a><img src='" |
|
| 355 | + . chemin_image('loader.svg') |
|
| 356 | + . "' class='loader' id='img_" |
|
| 357 | + . $idom |
|
| 358 | + . "'\nstyle='visibility: hidden;' alt='*' />" |
|
| 359 | + . "<input id='titreparent' name='titreparent' class='text'" |
|
| 360 | + . $init |
|
| 361 | + . ' />' |
|
| 362 | + . "<input type='hidden' id='$name' name='$name' value='" |
|
| 363 | + . $id |
|
| 364 | + . "' /><div class='nettoyeur'></div></div><div id='" |
|
| 365 | + . $idom |
|
| 366 | + . "'\nstyle='display: none;'></div>"; |
|
| 367 | 367 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if (isset($data[$root])) { # pas de racine sauf pour les rubriques |
| 143 | 143 | $r = "<option$selected value='$root' class='$class' style='$style'>$espace" |
| 144 | 144 | . $data[$root] |
| 145 | - . '</option>' . "\n"; |
|
| 145 | + . '</option>'."\n"; |
|
| 146 | 146 | } else { |
| 147 | 147 | $r = ''; |
| 148 | 148 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // et voila le travail |
| 173 | - return $r . $sous; |
|
| 173 | + return $r.$sous; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -218,12 +218,12 @@ discard block |
||
| 218 | 218 | while ($r = sql_fetch($q)) { |
| 219 | 219 | if (autoriser('voir', 'rubrique', $r['id_rubrique'])) { |
| 220 | 220 | // titre largeur maxi a 50 |
| 221 | - $titre = couper(supprimer_tags(typo($r['titre'])) . ' ', 50); |
|
| 221 | + $titre = couper(supprimer_tags(typo($r['titre'])).' ', 50); |
|
| 222 | 222 | if ( |
| 223 | 223 | $GLOBALS['meta']['multi_rubriques'] == 'oui' |
| 224 | 224 | && ($r['langue_choisie'] == 'oui' || $r['id_parent'] == 0) |
| 225 | 225 | ) { |
| 226 | - $titre .= ' [' . traduire_nom_langue($r['lang']) . ']'; |
|
| 226 | + $titre .= ' ['.traduire_nom_langue($r['lang']).']'; |
|
| 227 | 227 | } |
| 228 | 228 | $data[$r['id_rubrique']] = $titre; |
| 229 | 229 | $enfants[$r['id_parent']][] = $r['id_rubrique']; |
@@ -250,9 +250,9 @@ discard block |
||
| 250 | 250 | $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'"; |
| 251 | 251 | |
| 252 | 252 | if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) { |
| 253 | - $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2]; |
|
| 253 | + $r = "<input$att type='hidden' value='".$r[1]."' />".$r[2]; |
|
| 254 | 254 | } else { |
| 255 | - $r = '<select' . $att . " size='1'>\n$opt</select>\n"; |
|
| 255 | + $r = '<select'.$att." size='1'>\n$opt</select>\n"; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | # message pour neuneus (a supprimer ?) |
@@ -294,13 +294,13 @@ discard block |
||
| 294 | 294 | function selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') { |
| 295 | 295 | |
| 296 | 296 | if ($id_rubrique) { |
| 297 | - $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 297 | + $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique); |
|
| 298 | 298 | } else { |
| 299 | 299 | $titre = $type == 'auteur' ? ' ' : _T('info_racine_site'); |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | $titre = str_replace('&', '&', (string) entites_html(textebrut(typo($titre)))); |
| 303 | - $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'"; |
|
| 303 | + $init = " disabled='disabled' type='text' value=\"".$titre."\"\nstyle='width:300px;'"; |
|
| 304 | 304 | |
| 305 | 305 | $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do" |
| 306 | 306 | . ($idem ? "&exclus=$idem" : '') |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | . " jQuery(this).toggleClass('toggled'); " |
| 350 | 350 | . "return charger_node_url_si_vide('" |
| 351 | 351 | . $url |
| 352 | - . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'>" |
|
| 352 | + . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='".attribut_html(_T('titre_image_selecteur'))."'>" |
|
| 353 | 353 | . $img_icone |
| 354 | 354 | . "</a><img src='" |
| 355 | 355 | . chemin_image('loader.svg') |
@@ -313,9 +313,9 @@ |
||
| 313 | 313 | && ($e = $flux['args']['contexte']['_etape']) > 1 |
| 314 | 314 | && ($ext = $flux['args']['ext']) |
| 315 | 315 | && ($f = $flux['data']) |
| 316 | - && file_exists($f . "_$e.$ext") |
|
| 316 | + && file_exists($f."_$e.$ext") |
|
| 317 | 317 | ) { |
| 318 | - $flux['data'] = $f . "_$e"; |
|
| 318 | + $flux['data'] = $f."_$e"; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | return $flux; |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | |
| 67 | 67 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 68 | - return; |
|
| 68 | + return; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -76,46 +76,46 @@ discard block |
||
| 76 | 76 | * @return array|false |
| 77 | 77 | */ |
| 78 | 78 | function cvtmulti_recuperer_post_precedents($form) { |
| 79 | - include_spip('inc/filtres'); |
|
| 80 | - if ( |
|
| 81 | - $form |
|
| 82 | - && ($c = _request('cvtm_prev_post')) |
|
| 83 | - && ($c = decoder_contexte_ajax($c, $form)) |
|
| 84 | - ) { |
|
| 85 | - #var_dump($c); |
|
| 79 | + include_spip('inc/filtres'); |
|
| 80 | + if ( |
|
| 81 | + $form |
|
| 82 | + && ($c = _request('cvtm_prev_post')) |
|
| 83 | + && ($c = decoder_contexte_ajax($c, $form)) |
|
| 84 | + ) { |
|
| 85 | + #var_dump($c); |
|
| 86 | 86 | |
| 87 | - # reinjecter dans la bonne variable pour permettre de retrouver |
|
| 88 | - # toutes les saisies dans un seul tableau |
|
| 89 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 90 | - $store = &$_POST; |
|
| 91 | - } else { |
|
| 92 | - $store = &$_GET; |
|
| 93 | - } |
|
| 87 | + # reinjecter dans la bonne variable pour permettre de retrouver |
|
| 88 | + # toutes les saisies dans un seul tableau |
|
| 89 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 90 | + $store = &$_POST; |
|
| 91 | + } else { |
|
| 92 | + $store = &$_GET; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau ! |
|
| 96 | - if (!isset($store[$k])) { |
|
| 97 | - $_REQUEST[$k] = $store[$k] = $v; |
|
| 98 | - } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie |
|
| 99 | - elseif ( |
|
| 100 | - is_array($store[$k]) |
|
| 101 | - && is_array($v) |
|
| 102 | - && ($z = array_keys($v)) |
|
| 103 | - && !is_numeric(reset($z)) |
|
| 104 | - && ($z = array_keys($store[$k])) |
|
| 105 | - && !is_numeric(reset($z)) |
|
| 106 | - ) { |
|
| 107 | - $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]); |
|
| 108 | - } |
|
| 109 | - } |
|
| 95 | + foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau ! |
|
| 96 | + if (!isset($store[$k])) { |
|
| 97 | + $_REQUEST[$k] = $store[$k] = $v; |
|
| 98 | + } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie |
|
| 99 | + elseif ( |
|
| 100 | + is_array($store[$k]) |
|
| 101 | + && is_array($v) |
|
| 102 | + && ($z = array_keys($v)) |
|
| 103 | + && !is_numeric(reset($z)) |
|
| 104 | + && ($z = array_keys($store[$k])) |
|
| 105 | + && !is_numeric(reset($z)) |
|
| 106 | + ) { |
|
| 107 | + $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - // vider pour eviter un second appel a verifier_n |
|
| 112 | - // en cas de double implementation (unipotence) |
|
| 113 | - set_request('cvtm_prev_post'); |
|
| 111 | + // vider pour eviter un second appel a verifier_n |
|
| 112 | + // en cas de double implementation (unipotence) |
|
| 113 | + set_request('cvtm_prev_post'); |
|
| 114 | 114 | |
| 115 | - return [$c['_etape'], $c['_etapes']]; |
|
| 116 | - } |
|
| 115 | + return [$c['_etape'], $c['_etapes']]; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - return false; |
|
| 118 | + return false; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -128,28 +128,28 @@ discard block |
||
| 128 | 128 | * @return array |
| 129 | 129 | */ |
| 130 | 130 | function cvtmulti_sauver_post($form, $je_suis_poste, &$valeurs) { |
| 131 | - if (!isset($valeurs['_cvtm_prev_post'])) { |
|
| 132 | - $post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']]; |
|
| 133 | - foreach (array_keys($valeurs) as $champ) { |
|
| 134 | - if ( |
|
| 135 | - !str_starts_with($champ, '_') |
|
| 136 | - && ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) |
|
| 137 | - && ($v = _request($champ)) !== null |
|
| 138 | - ) { |
|
| 139 | - $post[$champ] = $v; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - include_spip('inc/filtres'); |
|
| 143 | - $c = encoder_contexte_ajax($post, $form); |
|
| 144 | - if (!isset($valeurs['_hidden'])) { |
|
| 145 | - $valeurs['_hidden'] = ''; |
|
| 146 | - } |
|
| 147 | - $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />"; |
|
| 148 | - // marquer comme fait, pour eviter double encodage (unipotence) |
|
| 149 | - $valeurs['_cvtm_prev_post'] = true; |
|
| 150 | - } |
|
| 131 | + if (!isset($valeurs['_cvtm_prev_post'])) { |
|
| 132 | + $post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']]; |
|
| 133 | + foreach (array_keys($valeurs) as $champ) { |
|
| 134 | + if ( |
|
| 135 | + !str_starts_with($champ, '_') |
|
| 136 | + && ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) |
|
| 137 | + && ($v = _request($champ)) !== null |
|
| 138 | + ) { |
|
| 139 | + $post[$champ] = $v; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + include_spip('inc/filtres'); |
|
| 143 | + $c = encoder_contexte_ajax($post, $form); |
|
| 144 | + if (!isset($valeurs['_hidden'])) { |
|
| 145 | + $valeurs['_hidden'] = ''; |
|
| 146 | + } |
|
| 147 | + $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />"; |
|
| 148 | + // marquer comme fait, pour eviter double encodage (unipotence) |
|
| 149 | + $valeurs['_cvtm_prev_post'] = true; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - return $valeurs; |
|
| 152 | + return $valeurs; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -159,19 +159,19 @@ discard block |
||
| 159 | 159 | * @return array |
| 160 | 160 | */ |
| 161 | 161 | function cvtmulti_formulaire_charger_etapes($args, $valeurs) { |
| 162 | - if (!isset($valeurs['_etape'])) { |
|
| 163 | - $form = $args['form']; |
|
| 164 | - $je_suis_poste = $args['je_suis_poste']; |
|
| 165 | - $nb_etapes = $valeurs['_etapes']; |
|
| 166 | - $etape = _request('_etape'); |
|
| 167 | - $etape = min(max($etape, 1), $nb_etapes); |
|
| 168 | - set_request('_etape', $etape); |
|
| 169 | - $valeurs['_etape'] = $etape; |
|
| 162 | + if (!isset($valeurs['_etape'])) { |
|
| 163 | + $form = $args['form']; |
|
| 164 | + $je_suis_poste = $args['je_suis_poste']; |
|
| 165 | + $nb_etapes = $valeurs['_etapes']; |
|
| 166 | + $etape = _request('_etape'); |
|
| 167 | + $etape = min(max($etape, 1), $nb_etapes); |
|
| 168 | + set_request('_etape', $etape); |
|
| 169 | + $valeurs['_etape'] = $etape; |
|
| 170 | 170 | |
| 171 | - // sauver les posts de cette etape pour les avoir a la prochaine etape |
|
| 172 | - $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs); |
|
| 173 | - } |
|
| 174 | - return $valeurs; |
|
| 171 | + // sauver les posts de cette etape pour les avoir a la prochaine etape |
|
| 172 | + $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs); |
|
| 173 | + } |
|
| 174 | + return $valeurs; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -182,87 +182,87 @@ discard block |
||
| 182 | 182 | * @return array |
| 183 | 183 | */ |
| 184 | 184 | function cvtmulti_formulaire_verifier_etapes($args, $erreurs) { |
| 185 | - #var_dump('Pipe verifier'); |
|
| 185 | + #var_dump('Pipe verifier'); |
|
| 186 | 186 | |
| 187 | - if ( |
|
| 188 | - ($form = $args['form']) |
|
| 189 | - && ($e = cvtmulti_recuperer_post_precedents($form)) !== false |
|
| 190 | - ) { |
|
| 191 | - // recuperer l'etape saisie et le nombre d'etapes total |
|
| 192 | - [$etape, $etapes] = $e; |
|
| 193 | - $etape_demandee = (int) _request('aller_a_etape'); // possibilite de poster un entier dans aller_a_etape |
|
| 187 | + if ( |
|
| 188 | + ($form = $args['form']) |
|
| 189 | + && ($e = cvtmulti_recuperer_post_precedents($form)) !== false |
|
| 190 | + ) { |
|
| 191 | + // recuperer l'etape saisie et le nombre d'etapes total |
|
| 192 | + [$etape, $etapes] = $e; |
|
| 193 | + $etape_demandee = (int) _request('aller_a_etape'); // possibilite de poster un entier dans aller_a_etape |
|
| 194 | 194 | |
| 195 | - $args['etape_saisie'] = $etape; |
|
| 196 | - $args['etapes'] = $etapes; |
|
| 197 | - // lancer les verifs pour chaque etape deja saisie de 1 a $etape |
|
| 198 | - $erreurs_etapes = []; |
|
| 199 | - $derniere_etape_ok = 0; |
|
| 200 | - $e = 0; |
|
| 201 | - while ($e < max($etape, $etape_demandee - 1) && $e < $etapes) { |
|
| 202 | - $e++; |
|
| 203 | - $erreurs_etapes[$e] = []; |
|
| 204 | - if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
|
| 205 | - $erreurs_etapes[$e] = $verifier(...$args['args']); |
|
| 206 | - } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) { |
|
| 207 | - $a = $args['args']; |
|
| 208 | - array_unshift($a, $e); |
|
| 209 | - $erreurs_etapes[$e] = $verifier(...$a); |
|
| 210 | - } |
|
| 211 | - // et on appelle un pipeline dedie aux etapes, plus easy |
|
| 212 | - $args['etape'] = $e; |
|
| 213 | - $args['etape_demandee'] = $etape_demandee; |
|
| 214 | - $erreurs_etapes[$e] = pipeline( |
|
| 215 | - 'formulaire_verifier_etape', |
|
| 216 | - [ |
|
| 217 | - 'args' => $args, |
|
| 218 | - 'data' => $erreurs_etapes[$e] |
|
| 219 | - ] |
|
| 220 | - ); |
|
| 195 | + $args['etape_saisie'] = $etape; |
|
| 196 | + $args['etapes'] = $etapes; |
|
| 197 | + // lancer les verifs pour chaque etape deja saisie de 1 a $etape |
|
| 198 | + $erreurs_etapes = []; |
|
| 199 | + $derniere_etape_ok = 0; |
|
| 200 | + $e = 0; |
|
| 201 | + while ($e < max($etape, $etape_demandee - 1) && $e < $etapes) { |
|
| 202 | + $e++; |
|
| 203 | + $erreurs_etapes[$e] = []; |
|
| 204 | + if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
|
| 205 | + $erreurs_etapes[$e] = $verifier(...$args['args']); |
|
| 206 | + } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) { |
|
| 207 | + $a = $args['args']; |
|
| 208 | + array_unshift($a, $e); |
|
| 209 | + $erreurs_etapes[$e] = $verifier(...$a); |
|
| 210 | + } |
|
| 211 | + // et on appelle un pipeline dedie aux etapes, plus easy |
|
| 212 | + $args['etape'] = $e; |
|
| 213 | + $args['etape_demandee'] = $etape_demandee; |
|
| 214 | + $erreurs_etapes[$e] = pipeline( |
|
| 215 | + 'formulaire_verifier_etape', |
|
| 216 | + [ |
|
| 217 | + 'args' => $args, |
|
| 218 | + 'data' => $erreurs_etapes[$e] |
|
| 219 | + ] |
|
| 220 | + ); |
|
| 221 | 221 | |
| 222 | - if ($derniere_etape_ok === $e - 1 && !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) { |
|
| 223 | - $derniere_etape_ok = $e; |
|
| 224 | - } |
|
| 225 | - // possibilite de poster dans _retour_etape_x ou aller_a_etape |
|
| 226 | - if (!is_null(_request("_retour_etape_$e"))) { |
|
| 227 | - $etape_demandee = $e; |
|
| 228 | - } |
|
| 229 | - // Il se peut que les verifications ait décidé de faire sauter des étapes |
|
| 230 | - if ($aller_a_etape = (int) _request('aller_a_etape')) { |
|
| 231 | - $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape |
|
| 232 | - } |
|
| 233 | - } |
|
| 222 | + if ($derniere_etape_ok === $e - 1 && !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) { |
|
| 223 | + $derniere_etape_ok = $e; |
|
| 224 | + } |
|
| 225 | + // possibilite de poster dans _retour_etape_x ou aller_a_etape |
|
| 226 | + if (!is_null(_request("_retour_etape_$e"))) { |
|
| 227 | + $etape_demandee = $e; |
|
| 228 | + } |
|
| 229 | + // Il se peut que les verifications ait décidé de faire sauter des étapes |
|
| 230 | + if ($aller_a_etape = (int) _request('aller_a_etape')) { |
|
| 231 | + $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | |
| 236 | - // si la derniere etape OK etait la derniere |
|
| 237 | - // on renvoie le flux inchange et ca declenche traiter |
|
| 238 | - if ( |
|
| 239 | - $derniere_etape_ok == $etapes |
|
| 240 | - && (!$etape_demandee || $etape_demandee >= $etapes) |
|
| 241 | - ) { |
|
| 242 | - return $erreurs; |
|
| 243 | - } else { |
|
| 244 | - $etape = $derniere_etape_ok + 1; |
|
| 245 | - if ($etape_demandee > 0 && $etape_demandee < $etape) { |
|
| 246 | - $etape = $etape_demandee; |
|
| 247 | - } |
|
| 248 | - $etape = min($etape, $etapes); |
|
| 249 | - #var_dump("prochaine etape $etape"); |
|
| 250 | - // retourner les erreurs de l'etape ciblee |
|
| 251 | - $erreurs = $erreurs_etapes[$etape] ?? []; |
|
| 252 | - // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur ! |
|
| 253 | - if ($erreurs) { |
|
| 254 | - if (!isset($erreurs['message_erreur'])) { |
|
| 255 | - $erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 256 | - } |
|
| 257 | - } else { |
|
| 258 | - $erreurs['message_erreur'] = ''; |
|
| 259 | - } |
|
| 260 | - $erreurs['_etapes'] = "etape suivante $etape"; |
|
| 261 | - set_request('_etape', $etape); |
|
| 262 | - } |
|
| 263 | - } |
|
| 236 | + // si la derniere etape OK etait la derniere |
|
| 237 | + // on renvoie le flux inchange et ca declenche traiter |
|
| 238 | + if ( |
|
| 239 | + $derniere_etape_ok == $etapes |
|
| 240 | + && (!$etape_demandee || $etape_demandee >= $etapes) |
|
| 241 | + ) { |
|
| 242 | + return $erreurs; |
|
| 243 | + } else { |
|
| 244 | + $etape = $derniere_etape_ok + 1; |
|
| 245 | + if ($etape_demandee > 0 && $etape_demandee < $etape) { |
|
| 246 | + $etape = $etape_demandee; |
|
| 247 | + } |
|
| 248 | + $etape = min($etape, $etapes); |
|
| 249 | + #var_dump("prochaine etape $etape"); |
|
| 250 | + // retourner les erreurs de l'etape ciblee |
|
| 251 | + $erreurs = $erreurs_etapes[$etape] ?? []; |
|
| 252 | + // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur ! |
|
| 253 | + if ($erreurs) { |
|
| 254 | + if (!isset($erreurs['message_erreur'])) { |
|
| 255 | + $erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 256 | + } |
|
| 257 | + } else { |
|
| 258 | + $erreurs['message_erreur'] = ''; |
|
| 259 | + } |
|
| 260 | + $erreurs['_etapes'] = "etape suivante $etape"; |
|
| 261 | + set_request('_etape', $etape); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - return $erreurs; |
|
| 265 | + return $erreurs; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -274,17 +274,17 @@ discard block |
||
| 274 | 274 | * @return array |
| 275 | 275 | */ |
| 276 | 276 | function cvtmulti_styliser($flux) { |
| 277 | - if ( |
|
| 278 | - str_starts_with((string) $flux['args']['fond'], 'formulaires/') |
|
| 279 | - && isset($flux['args']['contexte']['_etapes']) |
|
| 280 | - && isset($flux['args']['contexte']['_etape']) |
|
| 281 | - && ($e = $flux['args']['contexte']['_etape']) > 1 |
|
| 282 | - && ($ext = $flux['args']['ext']) |
|
| 283 | - && ($f = $flux['data']) |
|
| 284 | - && file_exists($f . "_$e.$ext") |
|
| 285 | - ) { |
|
| 286 | - $flux['data'] = $f . "_$e"; |
|
| 287 | - } |
|
| 277 | + if ( |
|
| 278 | + str_starts_with((string) $flux['args']['fond'], 'formulaires/') |
|
| 279 | + && isset($flux['args']['contexte']['_etapes']) |
|
| 280 | + && isset($flux['args']['contexte']['_etape']) |
|
| 281 | + && ($e = $flux['args']['contexte']['_etape']) > 1 |
|
| 282 | + && ($ext = $flux['args']['ext']) |
|
| 283 | + && ($f = $flux['data']) |
|
| 284 | + && file_exists($f . "_$e.$ext") |
|
| 285 | + ) { |
|
| 286 | + $flux['data'] = $f . "_$e"; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - return $flux; |
|
| 289 | + return $flux; |
|
| 290 | 290 | } |
@@ -267,8 +267,7 @@ discard block |
||
| 267 | 267 | if ($id === '*') { |
| 268 | 268 | unset($GLOBALS['autoriser_exception'][$faire][$type]); |
| 269 | 269 | unset($autorisation[$faire][$type]); |
| 270 | - } |
|
| 271 | - else { |
|
| 270 | + } else { |
|
| 272 | 271 | unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
| 273 | 272 | unset($autorisation[$faire][$type][$id]); |
| 274 | 273 | } |
@@ -635,8 +634,7 @@ discard block |
||
| 635 | 634 | function autoriser_rubrique_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 636 | 635 | if (!empty($opt['id_parent'])) { |
| 637 | 636 | return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
| 638 | - } |
|
| 639 | - else { |
|
| 637 | + } else { |
|
| 640 | 638 | return autoriser('defaut', null, 0, $qui, $opt); |
| 641 | 639 | } |
| 642 | 640 | } |
@@ -791,8 +789,7 @@ discard block |
||
| 791 | 789 | if (!empty($opt['id_parent'])) { |
| 792 | 790 | // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
| 793 | 791 | return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
| 794 | - } |
|
| 795 | - else { |
|
| 792 | + } else { |
|
| 796 | 793 | return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite'])); |
| 797 | 794 | } |
| 798 | 795 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Autorisations |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('base/abstract_sql'); |
@@ -37,89 +37,89 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | if (!function_exists('autoriser')) { |
| 40 | - /** |
|
| 41 | - * Autoriser une action |
|
| 42 | - * |
|
| 43 | - * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 44 | - * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 45 | - * les autorisations. |
|
| 46 | - * |
|
| 47 | - * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 48 | - * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 49 | - * dans cet ordre : |
|
| 50 | - * |
|
| 51 | - * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 52 | - * - autoriser_{type}, sinon avec _dist |
|
| 53 | - * - autoriser_{faire}, sinon avec _dist |
|
| 54 | - * - autoriser_{defaut}, sinon avec _dist |
|
| 55 | - * |
|
| 56 | - * Seul le premier argument est obligatoire. |
|
| 57 | - * |
|
| 58 | - * @note |
|
| 59 | - * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 60 | - * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 61 | - * cette valeur. |
|
| 62 | - * |
|
| 63 | - * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 64 | - * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 65 | - * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 66 | - * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 67 | - * |
|
| 68 | - * @note |
|
| 69 | - * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 70 | - * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 71 | - * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 72 | - * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 73 | - * quel serait le type, quel serait l'action ? |
|
| 74 | - * |
|
| 75 | - * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 76 | - * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 77 | - * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 78 | - * |
|
| 79 | - * @api |
|
| 80 | - * @see autoriser_dist() |
|
| 81 | - * @see objet_type() |
|
| 82 | - * |
|
| 83 | - * @param string $faire |
|
| 84 | - * une action ('modifier', 'publier'...) |
|
| 85 | - * @param string|null $type |
|
| 86 | - * Type d’objet ou élément sur lequel appliquer l’action. |
|
| 87 | - * - null: indifférent à tout type d’élément ou objet éditorial |
|
| 88 | - * - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée) |
|
| 89 | - * - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()). |
|
| 90 | - * Les soulignés seront retirés (cf. la note). |
|
| 91 | - * @param string|int|null $id |
|
| 92 | - * id de l'objet ou élément sur lequel on veut agir, si pertinent. |
|
| 93 | - * - null: non utile pour l’autorisation |
|
| 94 | - * - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP) |
|
| 95 | - * - string: identifiant textuel |
|
| 96 | - * @param null|int|array $qui |
|
| 97 | - * - si null on prend alors visiteur_session |
|
| 98 | - * - un id_auteur (on regarde dans la base) |
|
| 99 | - * - un tableau auteur complet, y compris [restreint] |
|
| 100 | - * @param array $opt |
|
| 101 | - * options sous forme de tableau associatif |
|
| 102 | - * @return bool |
|
| 103 | - * true si la personne peut effectuer l'action |
|
| 104 | - */ |
|
| 105 | - function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool { |
|
| 106 | - // Charger les fonctions d'autorisation supplementaires |
|
| 107 | - static $pipe; |
|
| 108 | - if (!isset($pipe)) { |
|
| 109 | - $pipe = 1; |
|
| 110 | - pipeline('autoriser'); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return autoriser_dist($faire, $type, $id, $qui, $opt); |
|
| 114 | - } |
|
| 40 | + /** |
|
| 41 | + * Autoriser une action |
|
| 42 | + * |
|
| 43 | + * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 44 | + * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 45 | + * les autorisations. |
|
| 46 | + * |
|
| 47 | + * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 48 | + * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 49 | + * dans cet ordre : |
|
| 50 | + * |
|
| 51 | + * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 52 | + * - autoriser_{type}, sinon avec _dist |
|
| 53 | + * - autoriser_{faire}, sinon avec _dist |
|
| 54 | + * - autoriser_{defaut}, sinon avec _dist |
|
| 55 | + * |
|
| 56 | + * Seul le premier argument est obligatoire. |
|
| 57 | + * |
|
| 58 | + * @note |
|
| 59 | + * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 60 | + * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 61 | + * cette valeur. |
|
| 62 | + * |
|
| 63 | + * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 64 | + * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 65 | + * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 66 | + * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 67 | + * |
|
| 68 | + * @note |
|
| 69 | + * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 70 | + * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 71 | + * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 72 | + * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 73 | + * quel serait le type, quel serait l'action ? |
|
| 74 | + * |
|
| 75 | + * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 76 | + * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 77 | + * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 78 | + * |
|
| 79 | + * @api |
|
| 80 | + * @see autoriser_dist() |
|
| 81 | + * @see objet_type() |
|
| 82 | + * |
|
| 83 | + * @param string $faire |
|
| 84 | + * une action ('modifier', 'publier'...) |
|
| 85 | + * @param string|null $type |
|
| 86 | + * Type d’objet ou élément sur lequel appliquer l’action. |
|
| 87 | + * - null: indifférent à tout type d’élément ou objet éditorial |
|
| 88 | + * - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée) |
|
| 89 | + * - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()). |
|
| 90 | + * Les soulignés seront retirés (cf. la note). |
|
| 91 | + * @param string|int|null $id |
|
| 92 | + * id de l'objet ou élément sur lequel on veut agir, si pertinent. |
|
| 93 | + * - null: non utile pour l’autorisation |
|
| 94 | + * - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP) |
|
| 95 | + * - string: identifiant textuel |
|
| 96 | + * @param null|int|array $qui |
|
| 97 | + * - si null on prend alors visiteur_session |
|
| 98 | + * - un id_auteur (on regarde dans la base) |
|
| 99 | + * - un tableau auteur complet, y compris [restreint] |
|
| 100 | + * @param array $opt |
|
| 101 | + * options sous forme de tableau associatif |
|
| 102 | + * @return bool |
|
| 103 | + * true si la personne peut effectuer l'action |
|
| 104 | + */ |
|
| 105 | + function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool { |
|
| 106 | + // Charger les fonctions d'autorisation supplementaires |
|
| 107 | + static $pipe; |
|
| 108 | + if (!isset($pipe)) { |
|
| 109 | + $pipe = 1; |
|
| 110 | + pipeline('autoriser'); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return autoriser_dist($faire, $type, $id, $qui, $opt); |
|
| 114 | + } |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger |
| 119 | 119 | // mais apres la fonction autoriser() |
| 120 | 120 | if ($f = find_in_path('mes_fonctions.php')) { |
| 121 | - global $dossier_squelettes; |
|
| 122 | - include_once(_ROOT_CWD . $f); |
|
| 121 | + global $dossier_squelettes; |
|
| 122 | + include_once(_ROOT_CWD . $f); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
@@ -150,84 +150,84 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | function autoriser_dist(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool { |
| 152 | 152 | |
| 153 | - if ($type === null) { |
|
| 154 | - $type = ''; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // Qui ? visiteur_session ? |
|
| 158 | - // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 159 | - if ($qui === null || $qui === '') { |
|
| 160 | - $qui = $GLOBALS['visiteur_session'] ?: []; |
|
| 161 | - $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
|
| 162 | - } elseif (is_numeric($qui)) { |
|
| 163 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 164 | - if (!$qui) { |
|
| 165 | - return false; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // Admins restreints, on construit ici (pas generique mais...) |
|
| 170 | - // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 171 | - if (_ADMINS_RESTREINTS && is_array($qui)) { |
|
| 172 | - $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : []; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - spip_log( |
|
| 176 | - "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 177 | - 'autoriser' . _LOG_DEBUG |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - $type = autoriser_type($type); |
|
| 181 | - |
|
| 182 | - // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 183 | - if ( |
|
| 184 | - isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
|
| 185 | - && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
|
| 186 | - ) { |
|
| 187 | - spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 188 | - return true; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Chercher une fonction d'autorisation |
|
| 192 | - // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 193 | - // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 194 | - $fonctions = $type |
|
| 195 | - ? [ |
|
| 196 | - 'autoriser_' . $type . '_' . $faire, |
|
| 197 | - 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 198 | - 'autoriser_' . $type, |
|
| 199 | - 'autoriser_' . $type . '_dist', |
|
| 200 | - 'autoriser_' . $faire, |
|
| 201 | - 'autoriser_' . $faire . '_dist', |
|
| 202 | - 'autoriser_defaut', |
|
| 203 | - 'autoriser_defaut_dist' |
|
| 204 | - ] |
|
| 205 | - : [ |
|
| 206 | - 'autoriser_' . $faire, |
|
| 207 | - 'autoriser_' . $faire . '_dist', |
|
| 208 | - 'autoriser_defaut', |
|
| 209 | - 'autoriser_defaut_dist' |
|
| 210 | - ]; |
|
| 211 | - |
|
| 212 | - $a = false; |
|
| 213 | - foreach ($fonctions as $f) { |
|
| 214 | - if (function_exists($f)) { |
|
| 215 | - $a = $f($faire, $type, $id, $qui, $opt); |
|
| 216 | - break; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - spip_log( |
|
| 221 | - "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 222 | - 'autoriser' . _LOG_DEBUG |
|
| 223 | - ); |
|
| 224 | - |
|
| 225 | - if (!is_bool($a)) { |
|
| 226 | - trigger_error(sprintf('Function %s should returns a boolean instead of %s (casts as boolean). This will trigger fatal error in future versions.', $f, gettype($a)), \E_USER_DEPRECATED); |
|
| 227 | - $a = (bool) $a; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return $a; |
|
| 153 | + if ($type === null) { |
|
| 154 | + $type = ''; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // Qui ? visiteur_session ? |
|
| 158 | + // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 159 | + if ($qui === null || $qui === '') { |
|
| 160 | + $qui = $GLOBALS['visiteur_session'] ?: []; |
|
| 161 | + $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
|
| 162 | + } elseif (is_numeric($qui)) { |
|
| 163 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 164 | + if (!$qui) { |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // Admins restreints, on construit ici (pas generique mais...) |
|
| 170 | + // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 171 | + if (_ADMINS_RESTREINTS && is_array($qui)) { |
|
| 172 | + $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : []; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + spip_log( |
|
| 176 | + "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 177 | + 'autoriser' . _LOG_DEBUG |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + $type = autoriser_type($type); |
|
| 181 | + |
|
| 182 | + // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 183 | + if ( |
|
| 184 | + isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
|
| 185 | + && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
|
| 186 | + ) { |
|
| 187 | + spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 188 | + return true; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Chercher une fonction d'autorisation |
|
| 192 | + // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 193 | + // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 194 | + $fonctions = $type |
|
| 195 | + ? [ |
|
| 196 | + 'autoriser_' . $type . '_' . $faire, |
|
| 197 | + 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 198 | + 'autoriser_' . $type, |
|
| 199 | + 'autoriser_' . $type . '_dist', |
|
| 200 | + 'autoriser_' . $faire, |
|
| 201 | + 'autoriser_' . $faire . '_dist', |
|
| 202 | + 'autoriser_defaut', |
|
| 203 | + 'autoriser_defaut_dist' |
|
| 204 | + ] |
|
| 205 | + : [ |
|
| 206 | + 'autoriser_' . $faire, |
|
| 207 | + 'autoriser_' . $faire . '_dist', |
|
| 208 | + 'autoriser_defaut', |
|
| 209 | + 'autoriser_defaut_dist' |
|
| 210 | + ]; |
|
| 211 | + |
|
| 212 | + $a = false; |
|
| 213 | + foreach ($fonctions as $f) { |
|
| 214 | + if (function_exists($f)) { |
|
| 215 | + $a = $f($faire, $type, $id, $qui, $opt); |
|
| 216 | + break; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + spip_log( |
|
| 221 | + "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 222 | + 'autoriser' . _LOG_DEBUG |
|
| 223 | + ); |
|
| 224 | + |
|
| 225 | + if (!is_bool($a)) { |
|
| 226 | + trigger_error(sprintf('Function %s should returns a boolean instead of %s (casts as boolean). This will trigger fatal error in future versions.', $f, gettype($a)), \E_USER_DEPRECATED); |
|
| 227 | + $a = (bool) $a; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return $a; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // une globale pour aller au plus vite dans la fonction generique ci dessus |
@@ -247,31 +247,31 @@ discard block |
||
| 247 | 247 | * @return bool |
| 248 | 248 | */ |
| 249 | 249 | function autoriser_exception(string $faire, ?string $type = '', $id = null, $autoriser = true): bool { |
| 250 | - // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 251 | - static $autorisation; |
|
| 252 | - // Tolérance avec certains appels |
|
| 253 | - if ($id === null) { |
|
| 254 | - $id = 0; |
|
| 255 | - } |
|
| 256 | - $type = autoriser_type($type); |
|
| 257 | - if ($autoriser === 'verifier') { |
|
| 258 | - return isset($autorisation[$faire][$type][$id]); |
|
| 259 | - } |
|
| 260 | - if ($autoriser === true) { |
|
| 261 | - $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 262 | - } |
|
| 263 | - if ($autoriser === false) { |
|
| 264 | - if ($id === '*') { |
|
| 265 | - unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 266 | - unset($autorisation[$faire][$type]); |
|
| 267 | - } |
|
| 268 | - else { |
|
| 269 | - unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 270 | - unset($autorisation[$faire][$type][$id]); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - return false; |
|
| 250 | + // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 251 | + static $autorisation; |
|
| 252 | + // Tolérance avec certains appels |
|
| 253 | + if ($id === null) { |
|
| 254 | + $id = 0; |
|
| 255 | + } |
|
| 256 | + $type = autoriser_type($type); |
|
| 257 | + if ($autoriser === 'verifier') { |
|
| 258 | + return isset($autorisation[$faire][$type][$id]); |
|
| 259 | + } |
|
| 260 | + if ($autoriser === true) { |
|
| 261 | + $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 262 | + } |
|
| 263 | + if ($autoriser === false) { |
|
| 264 | + if ($id === '*') { |
|
| 265 | + unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 266 | + unset($autorisation[$faire][$type]); |
|
| 267 | + } |
|
| 268 | + else { |
|
| 269 | + unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 270 | + unset($autorisation[$faire][$type][$id]); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + return false; |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -284,13 +284,13 @@ discard block |
||
| 284 | 284 | * - Les _ sont supprimés |
| 285 | 285 | */ |
| 286 | 286 | function autoriser_type(?string $type = ''): string { |
| 287 | - // passer par objet_type pour avoir les alias |
|
| 288 | - // sauf si _ est le premier caractère. |
|
| 289 | - if ($type && $type[0] !== '_') { |
|
| 290 | - $type = objet_type($type, false); |
|
| 291 | - } |
|
| 292 | - // et supprimer les _ |
|
| 293 | - return str_replace('_', '', (string) $type); |
|
| 287 | + // passer par objet_type pour avoir les alias |
|
| 288 | + // sauf si _ est le premier caractère. |
|
| 289 | + if ($type && $type[0] !== '_') { |
|
| 290 | + $type = objet_type($type, false); |
|
| 291 | + } |
|
| 292 | + // et supprimer les _ |
|
| 293 | + return str_replace('_', '', (string) $type); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * @return bool true s'il a le droit, false sinon |
| 310 | 310 | **/ |
| 311 | 311 | function autoriser_defaut_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 312 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 312 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /** |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * @return bool true s'il a le droit, false sinon |
| 330 | 330 | */ |
| 331 | 331 | function autoriser_loger_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 332 | - return $qui['statut'] !== '5poubelle'; |
|
| 332 | + return $qui['statut'] !== '5poubelle'; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | * @return bool true s'il a le droit, false sinon |
| 346 | 346 | **/ |
| 347 | 347 | function autoriser_ecrire_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 348 | - return isset($qui['statut']) && in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 348 | + return isset($qui['statut']) && in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | * @return bool true s'il a le droit, false sinon |
| 365 | 365 | **/ |
| 366 | 366 | function autoriser_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 367 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 367 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -384,14 +384,14 @@ discard block |
||
| 384 | 384 | **/ |
| 385 | 385 | function autoriser_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 386 | 386 | |
| 387 | - // Le visiteur a-t-il un statut prevu par la config ? |
|
| 388 | - if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 389 | - return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 390 | - } |
|
| 387 | + // Le visiteur a-t-il un statut prevu par la config ? |
|
| 388 | + if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 389 | + return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 390 | + } |
|
| 391 | 391 | |
| 392 | - // A-t-on un token de prévisualisation valable ? |
|
| 393 | - include_spip('inc/securiser_action'); |
|
| 394 | - return (bool) decrire_token_previsu(); |
|
| 392 | + // A-t-on un token de prévisualisation valable ? |
|
| 393 | + include_spip('inc/securiser_action'); |
|
| 394 | + return (bool) decrire_token_previsu(); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -420,58 +420,58 @@ discard block |
||
| 420 | 420 | */ |
| 421 | 421 | function test_previsualiser_objet_champ(string $type = '', $id = null, array $qui = [], array $opt = []): bool { |
| 422 | 422 | |
| 423 | - // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 424 | - if (!$type) { |
|
| 425 | - return true; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - include_spip('base/objets'); |
|
| 429 | - $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 430 | - if (isset($infos['statut'])) { |
|
| 431 | - foreach ($infos['statut'] as $c) { |
|
| 432 | - if (isset($c['publie'])) { |
|
| 433 | - if (!isset($c['previsu'])) { |
|
| 434 | - return false; |
|
| 435 | - } // pas de previsu definie => NIET |
|
| 436 | - $champ = $c['champ']; |
|
| 437 | - if (!isset($opt[$champ])) { |
|
| 438 | - return false; |
|
| 439 | - } // pas de champ passe a la demande => NIET |
|
| 440 | - $previsu = explode(',', (string) $c['previsu']); |
|
| 441 | - // regarder si ce statut est autorise pour l'auteur |
|
| 442 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 443 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 444 | - // sinon l’auteur en session |
|
| 445 | - include_spip('inc/securiser_action'); |
|
| 446 | - if ($desc = decrire_token_previsu()) { |
|
| 447 | - $id_auteur = $desc['id_auteur']; |
|
| 448 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 449 | - $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 450 | - } else { |
|
| 451 | - $id_auteur = null; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - if (!$id_auteur) { |
|
| 455 | - return false; |
|
| 456 | - } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 457 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 458 | - } elseif ( |
|
| 459 | - !sql_countsel( |
|
| 460 | - 'spip_auteurs_liens', |
|
| 461 | - 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 462 | - ) |
|
| 463 | - ) { |
|
| 464 | - return false; |
|
| 465 | - } // pas auteur de cet objet => NIET |
|
| 466 | - } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 467 | - // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 468 | - return false; |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - return true; |
|
| 423 | + // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 424 | + if (!$type) { |
|
| 425 | + return true; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + include_spip('base/objets'); |
|
| 429 | + $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 430 | + if (isset($infos['statut'])) { |
|
| 431 | + foreach ($infos['statut'] as $c) { |
|
| 432 | + if (isset($c['publie'])) { |
|
| 433 | + if (!isset($c['previsu'])) { |
|
| 434 | + return false; |
|
| 435 | + } // pas de previsu definie => NIET |
|
| 436 | + $champ = $c['champ']; |
|
| 437 | + if (!isset($opt[$champ])) { |
|
| 438 | + return false; |
|
| 439 | + } // pas de champ passe a la demande => NIET |
|
| 440 | + $previsu = explode(',', (string) $c['previsu']); |
|
| 441 | + // regarder si ce statut est autorise pour l'auteur |
|
| 442 | + if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 443 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 444 | + // sinon l’auteur en session |
|
| 445 | + include_spip('inc/securiser_action'); |
|
| 446 | + if ($desc = decrire_token_previsu()) { |
|
| 447 | + $id_auteur = $desc['id_auteur']; |
|
| 448 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 449 | + $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 450 | + } else { |
|
| 451 | + $id_auteur = null; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + if (!$id_auteur) { |
|
| 455 | + return false; |
|
| 456 | + } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 457 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 458 | + } elseif ( |
|
| 459 | + !sql_countsel( |
|
| 460 | + 'spip_auteurs_liens', |
|
| 461 | + 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 462 | + ) |
|
| 463 | + ) { |
|
| 464 | + return false; |
|
| 465 | + } // pas auteur de cet objet => NIET |
|
| 466 | + } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 467 | + // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 468 | + return false; |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + return true; |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
@@ -487,49 +487,49 @@ discard block |
||
| 487 | 487 | * @return bool true s'il a le droit, false sinon |
| 488 | 488 | **/ |
| 489 | 489 | function autoriser_changerlangue_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 490 | - $multi_objets = explode(',', (string) lire_config('multi_objets')); |
|
| 491 | - $gerer_trad_objets = explode(',', (string) lire_config('gerer_trad_objets')); |
|
| 492 | - $table = table_objet_sql($type); |
|
| 493 | - if ( |
|
| 494 | - in_array($table, $multi_objets) |
|
| 495 | - || in_array($table, $gerer_trad_objets) |
|
| 496 | - ) { // affichage du formulaire si la configuration l'accepte |
|
| 497 | - $multi_secteurs = lire_config('multi_secteurs'); |
|
| 498 | - $champs = objet_info($type, 'field'); |
|
| 499 | - if ( |
|
| 500 | - $multi_secteurs === 'oui' |
|
| 501 | - && array_key_exists('id_rubrique', $champs) |
|
| 502 | - ) { |
|
| 503 | - // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 504 | - $primary = id_table_objet($type); |
|
| 505 | - $id_rubrique = $table != 'spip_rubriques' |
|
| 506 | - ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 507 | - : $id; |
|
| 508 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 509 | - if (!$id_secteur > 0) { |
|
| 510 | - $id_secteur = $id_rubrique; |
|
| 511 | - } |
|
| 512 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 513 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 514 | - if ($langue_secteur != $langue_objet) { |
|
| 515 | - // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 516 | - return true; |
|
| 517 | - } |
|
| 518 | - if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 519 | - return false; |
|
| 520 | - } else { |
|
| 521 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 522 | - if ($id_parent != 0) { |
|
| 523 | - // sous-rubriques : pas de choix de langue |
|
| 524 | - return false; |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } else { |
|
| 529 | - return false; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 490 | + $multi_objets = explode(',', (string) lire_config('multi_objets')); |
|
| 491 | + $gerer_trad_objets = explode(',', (string) lire_config('gerer_trad_objets')); |
|
| 492 | + $table = table_objet_sql($type); |
|
| 493 | + if ( |
|
| 494 | + in_array($table, $multi_objets) |
|
| 495 | + || in_array($table, $gerer_trad_objets) |
|
| 496 | + ) { // affichage du formulaire si la configuration l'accepte |
|
| 497 | + $multi_secteurs = lire_config('multi_secteurs'); |
|
| 498 | + $champs = objet_info($type, 'field'); |
|
| 499 | + if ( |
|
| 500 | + $multi_secteurs === 'oui' |
|
| 501 | + && array_key_exists('id_rubrique', $champs) |
|
| 502 | + ) { |
|
| 503 | + // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 504 | + $primary = id_table_objet($type); |
|
| 505 | + $id_rubrique = $table != 'spip_rubriques' |
|
| 506 | + ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 507 | + : $id; |
|
| 508 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 509 | + if (!$id_secteur > 0) { |
|
| 510 | + $id_secteur = $id_rubrique; |
|
| 511 | + } |
|
| 512 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 513 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 514 | + if ($langue_secteur != $langue_objet) { |
|
| 515 | + // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 516 | + return true; |
|
| 517 | + } |
|
| 518 | + if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 519 | + return false; |
|
| 520 | + } else { |
|
| 521 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 522 | + if ($id_parent != 0) { |
|
| 523 | + // sous-rubriques : pas de choix de langue |
|
| 524 | + return false; |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } else { |
|
| 529 | + return false; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | * @return bool true s'il a le droit, false sinon |
| 546 | 546 | **/ |
| 547 | 547 | function autoriser_changertraduction_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 548 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 548 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | /** |
@@ -561,38 +561,38 @@ discard block |
||
| 561 | 561 | * @return bool true s'il a le droit, false sinon |
| 562 | 562 | **/ |
| 563 | 563 | function autoriser_dater_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 564 | - $table = table_objet($type); |
|
| 565 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 566 | - $desc = $trouver_table($table); |
|
| 567 | - if (!$desc) { |
|
| 568 | - return false; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - if (!isset($opt['statut'])) { |
|
| 572 | - if (isset($desc['field']['statut'])) { |
|
| 573 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 574 | - } else { |
|
| 575 | - $statut = 'publie'; |
|
| 576 | - } // pas de statut => publie |
|
| 577 | - } else { |
|
| 578 | - $statut = $opt['statut']; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - // Liste des statuts publiés pour cet objet |
|
| 582 | - // Sinon en dur le statut "publie" |
|
| 583 | - $statuts_publies = isset($desc['statut'][0]['publie']) |
|
| 584 | - ? explode(',', (string) $desc['statut'][0]['publie']) |
|
| 585 | - : ['publie']; |
|
| 586 | - |
|
| 587 | - if ( |
|
| 588 | - in_array($statut, $statuts_publies) |
|
| 589 | - // Ou cas particulier géré en dur ici pour les articles |
|
| 590 | - || $statut === 'prop' && $type === 'article' && $GLOBALS['meta']['post_dates'] === 'non' |
|
| 591 | - ) { |
|
| 592 | - return autoriser('modifier', $type, $id); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - return false; |
|
| 564 | + $table = table_objet($type); |
|
| 565 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 566 | + $desc = $trouver_table($table); |
|
| 567 | + if (!$desc) { |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + if (!isset($opt['statut'])) { |
|
| 572 | + if (isset($desc['field']['statut'])) { |
|
| 573 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 574 | + } else { |
|
| 575 | + $statut = 'publie'; |
|
| 576 | + } // pas de statut => publie |
|
| 577 | + } else { |
|
| 578 | + $statut = $opt['statut']; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + // Liste des statuts publiés pour cet objet |
|
| 582 | + // Sinon en dur le statut "publie" |
|
| 583 | + $statuts_publies = isset($desc['statut'][0]['publie']) |
|
| 584 | + ? explode(',', (string) $desc['statut'][0]['publie']) |
|
| 585 | + : ['publie']; |
|
| 586 | + |
|
| 587 | + if ( |
|
| 588 | + in_array($statut, $statuts_publies) |
|
| 589 | + // Ou cas particulier géré en dur ici pour les articles |
|
| 590 | + || $statut === 'prop' && $type === 'article' && $GLOBALS['meta']['post_dates'] === 'non' |
|
| 591 | + ) { |
|
| 592 | + return autoriser('modifier', $type, $id); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + return false; |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | /** |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | * @return bool true s'il a le droit, false sinon |
| 612 | 612 | **/ |
| 613 | 613 | function autoriser_instituer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 614 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 614 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -629,9 +629,9 @@ discard block |
||
| 629 | 629 | * @return bool true s'il a le droit, false sinon |
| 630 | 630 | **/ |
| 631 | 631 | function autoriser_rubrique_publierdans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 632 | - return |
|
| 633 | - $qui['statut'] === '0minirezo' |
|
| 634 | - && (!$qui['restreint'] || !$id || in_array($id, $qui['restreint'])); |
|
| 632 | + return |
|
| 633 | + $qui['statut'] === '0minirezo' |
|
| 634 | + && (!$qui['restreint'] || !$id || in_array($id, $qui['restreint'])); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
@@ -649,12 +649,12 @@ discard block |
||
| 649 | 649 | * @return bool true s'il a le droit, false sinon |
| 650 | 650 | **/ |
| 651 | 651 | function autoriser_rubrique_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 652 | - if (!empty($opt['id_parent'])) { |
|
| 653 | - return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 654 | - } |
|
| 655 | - else { |
|
| 656 | - return autoriser('defaut', null, 0, $qui, $opt); |
|
| 657 | - } |
|
| 652 | + if (!empty($opt['id_parent'])) { |
|
| 653 | + return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 654 | + } |
|
| 655 | + else { |
|
| 656 | + return autoriser('defaut', null, 0, $qui, $opt); |
|
| 657 | + } |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | /** |
@@ -672,8 +672,8 @@ discard block |
||
| 672 | 672 | * @return bool true s'il a le droit, false sinon |
| 673 | 673 | **/ |
| 674 | 674 | function autoriser_rubrique_creerrubriquedans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 675 | - return |
|
| 676 | - ($id || $qui['statut'] === '0minirezo' && !$qui['restreint']) && autoriser('voir', 'rubrique', $id) && autoriser('publierdans', 'rubrique', $id); |
|
| 675 | + return |
|
| 676 | + ($id || $qui['statut'] === '0minirezo' && !$qui['restreint']) && autoriser('voir', 'rubrique', $id) && autoriser('publierdans', 'rubrique', $id); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | /** |
@@ -691,10 +691,10 @@ discard block |
||
| 691 | 691 | * @return bool true s'il a le droit, false sinon |
| 692 | 692 | **/ |
| 693 | 693 | function autoriser_rubrique_creerarticledans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 694 | - return |
|
| 695 | - $id |
|
| 696 | - && autoriser('voir', 'rubrique', $id) |
|
| 697 | - && autoriser('creer', 'article'); |
|
| 694 | + return |
|
| 695 | + $id |
|
| 696 | + && autoriser('voir', 'rubrique', $id) |
|
| 697 | + && autoriser('creer', 'article'); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
@@ -713,7 +713,7 @@ discard block |
||
| 713 | 713 | * @return bool true s'il a le droit, false sinon |
| 714 | 714 | **/ |
| 715 | 715 | function autoriser_rubrique_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 716 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 716 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | /** |
@@ -731,29 +731,29 @@ discard block |
||
| 731 | 731 | * @return bool true s'il a le droit, false sinon |
| 732 | 732 | **/ |
| 733 | 733 | function autoriser_rubrique_supprimer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 734 | - if (!$id = (int) $id) { |
|
| 735 | - return false; |
|
| 736 | - } |
|
| 734 | + if (!$id = (int) $id) { |
|
| 735 | + return false; |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | - if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 739 | - return false; |
|
| 740 | - } |
|
| 738 | + if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 739 | + return false; |
|
| 740 | + } |
|
| 741 | 741 | |
| 742 | - if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 743 | - return false; |
|
| 744 | - } |
|
| 742 | + if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 743 | + return false; |
|
| 744 | + } |
|
| 745 | 745 | |
| 746 | - $compte = pipeline( |
|
| 747 | - 'objet_compte_enfants', |
|
| 748 | - ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 749 | - ); |
|
| 750 | - foreach ($compte as $objet => $n) { |
|
| 751 | - if ($n) { |
|
| 752 | - return false; |
|
| 753 | - } |
|
| 754 | - } |
|
| 746 | + $compte = pipeline( |
|
| 747 | + 'objet_compte_enfants', |
|
| 748 | + ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 749 | + ); |
|
| 750 | + foreach ($compte as $objet => $n) { |
|
| 751 | + if ($n) { |
|
| 752 | + return false; |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | 755 | |
| 756 | - return autoriser('modifier', 'rubrique', $id); |
|
| 756 | + return autoriser('modifier', 'rubrique', $id); |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | |
@@ -773,20 +773,20 @@ discard block |
||
| 773 | 773 | * @return bool true s'il a le droit, false sinon |
| 774 | 774 | **/ |
| 775 | 775 | function autoriser_article_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 776 | - if (!$id) { |
|
| 777 | - return false; |
|
| 778 | - } |
|
| 779 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 776 | + if (!$id) { |
|
| 777 | + return false; |
|
| 778 | + } |
|
| 779 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 780 | 780 | |
| 781 | - return $r && ( |
|
| 782 | - autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 783 | - || ( |
|
| 784 | - (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
|
| 785 | - && in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 786 | - && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 787 | - && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 788 | - ) |
|
| 789 | - ); |
|
| 781 | + return $r && ( |
|
| 782 | + autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 783 | + || ( |
|
| 784 | + (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
|
| 785 | + && in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 786 | + && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 787 | + && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 788 | + ) |
|
| 789 | + ); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | /** |
@@ -804,13 +804,13 @@ discard block |
||
| 804 | 804 | * @return bool true s'il a le droit, false sinon |
| 805 | 805 | **/ |
| 806 | 806 | function autoriser_article_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 807 | - if (!empty($opt['id_parent'])) { |
|
| 808 | - // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 809 | - return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 810 | - } |
|
| 811 | - else { |
|
| 812 | - return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 813 | - } |
|
| 807 | + if (!empty($opt['id_parent'])) { |
|
| 808 | + // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 809 | + return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 810 | + } |
|
| 811 | + else { |
|
| 812 | + return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 813 | + } |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | /** |
@@ -832,26 +832,26 @@ discard block |
||
| 832 | 832 | * @return bool true s'il a le droit, false sinon |
| 833 | 833 | */ |
| 834 | 834 | function autoriser_article_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 835 | - if ($qui['statut'] === '0minirezo') { |
|
| 836 | - return true; |
|
| 837 | - } |
|
| 838 | - // cas des articles : depend du statut de l'article et de l'auteur |
|
| 839 | - if (isset($opt['statut'])) { |
|
| 840 | - $statut = $opt['statut']; |
|
| 841 | - } else { |
|
| 842 | - if (!$id) { |
|
| 843 | - return false; |
|
| 844 | - } |
|
| 845 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 846 | - } |
|
| 835 | + if ($qui['statut'] === '0minirezo') { |
|
| 836 | + return true; |
|
| 837 | + } |
|
| 838 | + // cas des articles : depend du statut de l'article et de l'auteur |
|
| 839 | + if (isset($opt['statut'])) { |
|
| 840 | + $statut = $opt['statut']; |
|
| 841 | + } else { |
|
| 842 | + if (!$id) { |
|
| 843 | + return false; |
|
| 844 | + } |
|
| 845 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 846 | + } |
|
| 847 | 847 | |
| 848 | - return |
|
| 849 | - // si on est pas auteur de l'article, |
|
| 850 | - // seuls les propose et publies sont visibles |
|
| 851 | - in_array($statut, ['prop', 'publie']) |
|
| 852 | - // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 848 | + return |
|
| 849 | + // si on est pas auteur de l'article, |
|
| 850 | + // seuls les propose et publies sont visibles |
|
| 851 | + in_array($statut, ['prop', 'publie']) |
|
| 852 | + // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 853 | 853 | |
| 854 | - || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 854 | + || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | |
@@ -870,24 +870,24 @@ discard block |
||
| 870 | 870 | * @return bool true s'il a le droit, false sinon |
| 871 | 871 | **/ |
| 872 | 872 | function autoriser_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 873 | - # securite, mais on aurait pas du arriver ici ! |
|
| 874 | - if ( |
|
| 875 | - function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 876 | - || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 877 | - ) { |
|
| 878 | - return $f($faire, $type, $id, $qui, $opt); |
|
| 879 | - } |
|
| 873 | + # securite, mais on aurait pas du arriver ici ! |
|
| 874 | + if ( |
|
| 875 | + function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 876 | + || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 877 | + ) { |
|
| 878 | + return $f($faire, $type, $id, $qui, $opt); |
|
| 879 | + } |
|
| 880 | 880 | |
| 881 | - if ($qui['statut'] === '0minirezo') { |
|
| 882 | - return true; |
|
| 883 | - } |
|
| 884 | - // admins et redacteurs peuvent voir un auteur |
|
| 885 | - if ($type === 'auteur') { |
|
| 886 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 887 | - } |
|
| 888 | - // sinon par defaut tout est visible |
|
| 889 | - // sauf cas particuliers traites separemment (ie article) |
|
| 890 | - return true; |
|
| 881 | + if ($qui['statut'] === '0minirezo') { |
|
| 882 | + return true; |
|
| 883 | + } |
|
| 884 | + // admins et redacteurs peuvent voir un auteur |
|
| 885 | + if ($type === 'auteur') { |
|
| 886 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 887 | + } |
|
| 888 | + // sinon par defaut tout est visible |
|
| 889 | + // sauf cas particuliers traites separemment (ie article) |
|
| 890 | + return true; |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | |
@@ -909,10 +909,10 @@ discard block |
||
| 909 | 909 | * @return bool true s'il a le droit, false sinon |
| 910 | 910 | **/ |
| 911 | 911 | function autoriser_webmestre_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 912 | - return |
|
| 913 | - $qui['webmestre'] === 'oui' |
|
| 914 | - && $qui['statut'] === '0minirezo' |
|
| 915 | - && !$qui['restreint']; |
|
| 912 | + return |
|
| 913 | + $qui['webmestre'] === 'oui' |
|
| 914 | + && $qui['statut'] === '0minirezo' |
|
| 915 | + && !$qui['restreint']; |
|
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | /** |
@@ -930,7 +930,7 @@ discard block |
||
| 930 | 930 | * @return bool true s'il a le droit, false sinon |
| 931 | 931 | **/ |
| 932 | 932 | function autoriser_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 933 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 933 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
@@ -948,7 +948,7 @@ discard block |
||
| 948 | 948 | * @return bool true s'il a le droit, false sinon |
| 949 | 949 | **/ |
| 950 | 950 | function autoriser_sauvegarder_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 951 | - return $qui['statut'] === '0minirezo'; |
|
| 951 | + return $qui['statut'] === '0minirezo'; |
|
| 952 | 952 | } |
| 953 | 953 | |
| 954 | 954 | /** |
@@ -966,7 +966,7 @@ discard block |
||
| 966 | 966 | * @return bool true s'il a le droit, false sinon |
| 967 | 967 | **/ |
| 968 | 968 | function autoriser_detruire_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 969 | - return autoriser('webmestre', null, 0, $qui, $opt); |
|
| 969 | + return autoriser('webmestre', null, 0, $qui, $opt); |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | /** |
@@ -985,23 +985,23 @@ discard block |
||
| 985 | 985 | * @return bool true s'il a le droit, false sinon |
| 986 | 986 | **/ |
| 987 | 987 | function autoriser_auteur_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 988 | - // les admins peuvent "previsualiser" une page auteur |
|
| 989 | - if ( |
|
| 990 | - $qui['statut'] === '0minirezo' |
|
| 991 | - && !$qui['restreint'] |
|
| 992 | - ) { |
|
| 993 | - return true; |
|
| 994 | - } elseif ($id === 0) { |
|
| 995 | - return false; |
|
| 996 | - } |
|
| 997 | - // "Voir en ligne" si l'auteur a un article publie |
|
| 998 | - $n = sql_fetsel( |
|
| 999 | - 'A.id_article', |
|
| 1000 | - 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 1001 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 1002 | - ); |
|
| 988 | + // les admins peuvent "previsualiser" une page auteur |
|
| 989 | + if ( |
|
| 990 | + $qui['statut'] === '0minirezo' |
|
| 991 | + && !$qui['restreint'] |
|
| 992 | + ) { |
|
| 993 | + return true; |
|
| 994 | + } elseif ($id === 0) { |
|
| 995 | + return false; |
|
| 996 | + } |
|
| 997 | + // "Voir en ligne" si l'auteur a un article publie |
|
| 998 | + $n = sql_fetsel( |
|
| 999 | + 'A.id_article', |
|
| 1000 | + 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 1001 | + "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 1002 | + ); |
|
| 1003 | 1003 | |
| 1004 | - return (bool) $n; |
|
| 1004 | + return (bool) $n; |
|
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | 1007 | |
@@ -1030,7 +1030,7 @@ discard block |
||
| 1030 | 1030 | * @return bool true s'il a le droit, false sinon |
| 1031 | 1031 | **/ |
| 1032 | 1032 | function autoriser_auteur_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1033 | - return ($qui['statut'] === '0minirezo'); |
|
| 1033 | + return ($qui['statut'] === '0minirezo'); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | |
@@ -1051,62 +1051,62 @@ discard block |
||
| 1051 | 1051 | * @return bool true s'il a le droit, false sinon |
| 1052 | 1052 | **/ |
| 1053 | 1053 | function autoriser_auteur_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1054 | - $id = (int) $id; |
|
| 1055 | - |
|
| 1056 | - // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1057 | - // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1058 | - if ($qui['statut'] != '0minirezo') { |
|
| 1059 | - return $id == $qui['id_auteur'] |
|
| 1060 | - && empty($opt['statut']) |
|
| 1061 | - && empty($opt['webmestre']) |
|
| 1062 | - && empty($opt['restreintes']) |
|
| 1063 | - && empty($opt['login']); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1067 | - // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1068 | - if ($qui['restreint']) { |
|
| 1069 | - if (isset($opt['webmestre']) && $opt['webmestre']) { |
|
| 1070 | - return false; |
|
| 1071 | - } elseif ( |
|
| 1072 | - isset($opt['statut']) && $opt['statut'] === '0minirezo' || isset($opt['restreintes']) && $opt['restreintes'] |
|
| 1073 | - ) { |
|
| 1074 | - return false; |
|
| 1075 | - } else { |
|
| 1076 | - if ($id == $qui['id_auteur']) { |
|
| 1077 | - if (isset($opt['statut']) && $opt['statut']) { |
|
| 1078 | - return false; |
|
| 1079 | - } else { |
|
| 1080 | - return true; |
|
| 1081 | - } |
|
| 1082 | - } else { |
|
| 1083 | - if ($id_auteur = (int) $id) { |
|
| 1084 | - $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1085 | - if ($t && $t['statut'] != '0minirezo') { |
|
| 1086 | - return true; |
|
| 1087 | - } else { |
|
| 1088 | - return false; |
|
| 1089 | - } |
|
| 1090 | - } else { |
|
| 1091 | - // id = 0 => creation |
|
| 1092 | - return true; |
|
| 1093 | - } |
|
| 1094 | - } |
|
| 1095 | - } |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - // Un admin complet fait ce qu'il veut, sauf se degrader |
|
| 1099 | - if ($id == $qui['id_auteur'] && (isset($opt['statut']) && $opt['statut'])) { |
|
| 1100 | - return false; |
|
| 1101 | - } elseif (isset($opt['webmestre']) && $opt['webmestre'] && !autoriser('webmestre')) { |
|
| 1102 | - // et toucher au statut webmestre si il ne l'est pas lui même |
|
| 1103 | - return false; |
|
| 1104 | - } elseif ((int) $id && !autoriser('webmestre') && autoriser('webmestre', '', 0, $id)) { |
|
| 1105 | - // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1106 | - return false; |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - return true; |
|
| 1054 | + $id = (int) $id; |
|
| 1055 | + |
|
| 1056 | + // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1057 | + // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1058 | + if ($qui['statut'] != '0minirezo') { |
|
| 1059 | + return $id == $qui['id_auteur'] |
|
| 1060 | + && empty($opt['statut']) |
|
| 1061 | + && empty($opt['webmestre']) |
|
| 1062 | + && empty($opt['restreintes']) |
|
| 1063 | + && empty($opt['login']); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1067 | + // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1068 | + if ($qui['restreint']) { |
|
| 1069 | + if (isset($opt['webmestre']) && $opt['webmestre']) { |
|
| 1070 | + return false; |
|
| 1071 | + } elseif ( |
|
| 1072 | + isset($opt['statut']) && $opt['statut'] === '0minirezo' || isset($opt['restreintes']) && $opt['restreintes'] |
|
| 1073 | + ) { |
|
| 1074 | + return false; |
|
| 1075 | + } else { |
|
| 1076 | + if ($id == $qui['id_auteur']) { |
|
| 1077 | + if (isset($opt['statut']) && $opt['statut']) { |
|
| 1078 | + return false; |
|
| 1079 | + } else { |
|
| 1080 | + return true; |
|
| 1081 | + } |
|
| 1082 | + } else { |
|
| 1083 | + if ($id_auteur = (int) $id) { |
|
| 1084 | + $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1085 | + if ($t && $t['statut'] != '0minirezo') { |
|
| 1086 | + return true; |
|
| 1087 | + } else { |
|
| 1088 | + return false; |
|
| 1089 | + } |
|
| 1090 | + } else { |
|
| 1091 | + // id = 0 => creation |
|
| 1092 | + return true; |
|
| 1093 | + } |
|
| 1094 | + } |
|
| 1095 | + } |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + // Un admin complet fait ce qu'il veut, sauf se degrader |
|
| 1099 | + if ($id == $qui['id_auteur'] && (isset($opt['statut']) && $opt['statut'])) { |
|
| 1100 | + return false; |
|
| 1101 | + } elseif (isset($opt['webmestre']) && $opt['webmestre'] && !autoriser('webmestre')) { |
|
| 1102 | + // et toucher au statut webmestre si il ne l'est pas lui même |
|
| 1103 | + return false; |
|
| 1104 | + } elseif ((int) $id && !autoriser('webmestre') && autoriser('webmestre', '', 0, $id)) { |
|
| 1105 | + // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1106 | + return false; |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + return true; |
|
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | 1112 | |
@@ -1125,7 +1125,7 @@ discard block |
||
| 1125 | 1125 | * @return bool true s'il a le droit, false sinon |
| 1126 | 1126 | **/ |
| 1127 | 1127 | function autoriser_associerauteurs_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1128 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1128 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | 1131 | |
@@ -1144,7 +1144,7 @@ discard block |
||
| 1144 | 1144 | * @return bool true s'il a le droit, false sinon |
| 1145 | 1145 | **/ |
| 1146 | 1146 | function autoriser_chargerftp_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1147 | - return $qui['statut'] === '0minirezo'; |
|
| 1147 | + return $qui['statut'] === '0minirezo'; |
|
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | /** |
@@ -1162,7 +1162,7 @@ discard block |
||
| 1162 | 1162 | * @return bool true s'il a le droit, false sinon |
| 1163 | 1163 | **/ |
| 1164 | 1164 | function autoriser_debug_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1165 | - return $qui['statut'] === '0minirezo'; |
|
| 1165 | + return $qui['statut'] === '0minirezo'; |
|
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | 1168 | /** |
@@ -1179,53 +1179,53 @@ discard block |
||
| 1179 | 1179 | * @return array Liste des rubriques |
| 1180 | 1180 | **/ |
| 1181 | 1181 | function liste_rubriques_auteur($id_auteur, $raz = false) { |
| 1182 | - static $restreint = []; |
|
| 1183 | - |
|
| 1184 | - if (!$id_auteur = (int) $id_auteur) { |
|
| 1185 | - return []; |
|
| 1186 | - } |
|
| 1187 | - if ($raz) { |
|
| 1188 | - unset($restreint[$id_auteur]); |
|
| 1189 | - } elseif (isset($restreint[$id_auteur])) { |
|
| 1190 | - return $restreint[$id_auteur]; |
|
| 1191 | - } |
|
| 1192 | - |
|
| 1193 | - $rubriques = []; |
|
| 1194 | - if ( |
|
| 1195 | - (!isset($GLOBALS['meta']['version_installee']) || $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1196 | - && ($r = sql_allfetsel( |
|
| 1197 | - 'id_objet', |
|
| 1198 | - 'spip_auteurs_liens', |
|
| 1199 | - 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1200 | - )) |
|
| 1201 | - && (is_countable($r) ? count($r) : 0) |
|
| 1202 | - ) { |
|
| 1203 | - $r = array_column($r, 'id_objet'); |
|
| 1204 | - |
|
| 1205 | - // recuperer toute la branche, au format chaine enumeration |
|
| 1206 | - include_spip('inc/rubriques'); |
|
| 1207 | - $r = calcul_branche_in($r); |
|
| 1208 | - $r = explode(',', (string) $r); |
|
| 1209 | - |
|
| 1210 | - // passer les rubriques en index, elimine les doublons |
|
| 1211 | - $r = array_flip($r); |
|
| 1212 | - // recuperer les index seuls |
|
| 1213 | - $r = array_keys($r); |
|
| 1214 | - // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1215 | - // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1216 | - $rubriques = array_combine($r, $r); |
|
| 1217 | - } |
|
| 1218 | - |
|
| 1219 | - // Affecter l'auteur session le cas echeant |
|
| 1220 | - if ( |
|
| 1221 | - isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1222 | - && $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1223 | - ) { |
|
| 1224 | - $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1225 | - } |
|
| 1226 | - |
|
| 1227 | - |
|
| 1228 | - return $restreint[$id_auteur] = $rubriques; |
|
| 1182 | + static $restreint = []; |
|
| 1183 | + |
|
| 1184 | + if (!$id_auteur = (int) $id_auteur) { |
|
| 1185 | + return []; |
|
| 1186 | + } |
|
| 1187 | + if ($raz) { |
|
| 1188 | + unset($restreint[$id_auteur]); |
|
| 1189 | + } elseif (isset($restreint[$id_auteur])) { |
|
| 1190 | + return $restreint[$id_auteur]; |
|
| 1191 | + } |
|
| 1192 | + |
|
| 1193 | + $rubriques = []; |
|
| 1194 | + if ( |
|
| 1195 | + (!isset($GLOBALS['meta']['version_installee']) || $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1196 | + && ($r = sql_allfetsel( |
|
| 1197 | + 'id_objet', |
|
| 1198 | + 'spip_auteurs_liens', |
|
| 1199 | + 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1200 | + )) |
|
| 1201 | + && (is_countable($r) ? count($r) : 0) |
|
| 1202 | + ) { |
|
| 1203 | + $r = array_column($r, 'id_objet'); |
|
| 1204 | + |
|
| 1205 | + // recuperer toute la branche, au format chaine enumeration |
|
| 1206 | + include_spip('inc/rubriques'); |
|
| 1207 | + $r = calcul_branche_in($r); |
|
| 1208 | + $r = explode(',', (string) $r); |
|
| 1209 | + |
|
| 1210 | + // passer les rubriques en index, elimine les doublons |
|
| 1211 | + $r = array_flip($r); |
|
| 1212 | + // recuperer les index seuls |
|
| 1213 | + $r = array_keys($r); |
|
| 1214 | + // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1215 | + // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1216 | + $rubriques = array_combine($r, $r); |
|
| 1217 | + } |
|
| 1218 | + |
|
| 1219 | + // Affecter l'auteur session le cas echeant |
|
| 1220 | + if ( |
|
| 1221 | + isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1222 | + && $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1223 | + ) { |
|
| 1224 | + $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1225 | + } |
|
| 1226 | + |
|
| 1227 | + |
|
| 1228 | + return $restreint[$id_auteur] = $rubriques; |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | /** |
@@ -1243,7 +1243,7 @@ discard block |
||
| 1243 | 1243 | * @return bool true s'il a le droit, false sinon |
| 1244 | 1244 | **/ |
| 1245 | 1245 | function autoriser_rubrique_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1246 | - return autoriser('previsualiser'); |
|
| 1246 | + return autoriser('previsualiser'); |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | /** |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | * @return bool true s'il a le droit, false sinon |
| 1262 | 1262 | **/ |
| 1263 | 1263 | function autoriser_rubrique_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1264 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1264 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | 1267 | /** |
@@ -1279,8 +1279,8 @@ discard block |
||
| 1279 | 1279 | * @return bool true s'il a le droit, false sinon |
| 1280 | 1280 | **/ |
| 1281 | 1281 | function autoriser_auteur_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1282 | - $id = (int) $id; |
|
| 1283 | - return ($id == $qui['id_auteur'] || $qui['statut'] === '0minirezo' && !$qui['restreint']); |
|
| 1282 | + $id = (int) $id; |
|
| 1283 | + return ($id == $qui['id_auteur'] || $qui['statut'] === '0minirezo' && !$qui['restreint']); |
|
| 1284 | 1284 | } |
| 1285 | 1285 | |
| 1286 | 1286 | /** |
@@ -1298,8 +1298,8 @@ discard block |
||
| 1298 | 1298 | * @return bool true s'il a le droit, false sinon |
| 1299 | 1299 | **/ |
| 1300 | 1300 | function autoriser_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1301 | - // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1302 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1301 | + // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1302 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | |
@@ -1319,7 +1319,7 @@ discard block |
||
| 1319 | 1319 | * @return true |
| 1320 | 1320 | **/ |
| 1321 | 1321 | function autoriser_ok_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1322 | - return true; |
|
| 1322 | + return true; |
|
| 1323 | 1323 | } |
| 1324 | 1324 | |
| 1325 | 1325 | /** |
@@ -1338,7 +1338,7 @@ discard block |
||
| 1338 | 1338 | * @return false |
| 1339 | 1339 | **/ |
| 1340 | 1340 | function autoriser_niet_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1341 | - return false; |
|
| 1341 | + return false; |
|
| 1342 | 1342 | } |
| 1343 | 1343 | |
| 1344 | 1344 | /** |
@@ -1356,7 +1356,7 @@ discard block |
||
| 1356 | 1356 | * @return bool true s'il a le droit, false sinon |
| 1357 | 1357 | **/ |
| 1358 | 1358 | function autoriser_base_reparer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1359 | - return autoriser('detruire') && !_request('reinstall'); |
|
| 1359 | + return autoriser('detruire') && !_request('reinstall'); |
|
| 1360 | 1360 | } |
| 1361 | 1361 | |
| 1362 | 1362 | /** |
@@ -1374,7 +1374,7 @@ discard block |
||
| 1374 | 1374 | * @return true |
| 1375 | 1375 | **/ |
| 1376 | 1376 | function autoriser_infosperso_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1377 | - return true; |
|
| 1377 | + return true; |
|
| 1378 | 1378 | } |
| 1379 | 1379 | |
| 1380 | 1380 | /** |
@@ -1392,7 +1392,7 @@ discard block |
||
| 1392 | 1392 | * @return true |
| 1393 | 1393 | **/ |
| 1394 | 1394 | function autoriser_langage_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1395 | - return true; |
|
| 1395 | + return true; |
|
| 1396 | 1396 | } |
| 1397 | 1397 | |
| 1398 | 1398 | /** |
@@ -1410,7 +1410,7 @@ discard block |
||
| 1410 | 1410 | * @return bool true s'il a le droit, false sinon |
| 1411 | 1411 | **/ |
| 1412 | 1412 | function autoriser_configurerlangage_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1413 | - return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1413 | + return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1414 | 1414 | } |
| 1415 | 1415 | |
| 1416 | 1416 | /** |
@@ -1428,7 +1428,7 @@ discard block |
||
| 1428 | 1428 | * @return true |
| 1429 | 1429 | **/ |
| 1430 | 1430 | function autoriser_preferences_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1431 | - return true; |
|
| 1431 | + return true; |
|
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | 1434 | /** |
@@ -1446,7 +1446,7 @@ discard block |
||
| 1446 | 1446 | * @return bool true s'il a le droit, false sinon |
| 1447 | 1447 | **/ |
| 1448 | 1448 | function autoriser_configurerpreferences_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1449 | - return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1449 | + return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1450 | 1450 | } |
| 1451 | 1451 | |
| 1452 | 1452 | /** |
@@ -1464,7 +1464,7 @@ discard block |
||
| 1464 | 1464 | * @return bool true s'il a le droit, false sinon |
| 1465 | 1465 | **/ |
| 1466 | 1466 | function autoriser_menudeveloppement_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1467 | - return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) && $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui'); |
|
| 1467 | + return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) && $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui'); |
|
| 1468 | 1468 | } |
| 1469 | 1469 | |
| 1470 | 1470 | /** |
@@ -1483,7 +1483,7 @@ discard block |
||
| 1483 | 1483 | * @return true |
| 1484 | 1484 | **/ |
| 1485 | 1485 | function autoriser_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1486 | - return true; |
|
| 1486 | + return true; |
|
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 1489 | 1489 | /** |
@@ -1501,7 +1501,7 @@ discard block |
||
| 1501 | 1501 | * @return true |
| 1502 | 1502 | **/ |
| 1503 | 1503 | function autoriser_auteurs_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1504 | - return true; |
|
| 1504 | + return true; |
|
| 1505 | 1505 | } |
| 1506 | 1506 | |
| 1507 | 1507 | /** |
@@ -1519,7 +1519,7 @@ discard block |
||
| 1519 | 1519 | * @return bool true s'il a le droit, false sinon |
| 1520 | 1520 | **/ |
| 1521 | 1521 | function autoriser_auteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1522 | - return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1522 | + return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1523 | 1523 | } |
| 1524 | 1524 | |
| 1525 | 1525 | /** |
@@ -1537,7 +1537,7 @@ discard block |
||
| 1537 | 1537 | * @return true |
| 1538 | 1538 | **/ |
| 1539 | 1539 | function autoriser_articles_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1540 | - return true; |
|
| 1540 | + return true; |
|
| 1541 | 1541 | } |
| 1542 | 1542 | |
| 1543 | 1543 | /** |
@@ -1555,7 +1555,7 @@ discard block |
||
| 1555 | 1555 | * @return bool true s'il a le droit, false sinon |
| 1556 | 1556 | **/ |
| 1557 | 1557 | function autoriser_articles_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1558 | - return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1558 | + return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | /** |
@@ -1573,7 +1573,7 @@ discard block |
||
| 1573 | 1573 | * @return true |
| 1574 | 1574 | **/ |
| 1575 | 1575 | function autoriser_rubriques_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1576 | - return true; |
|
| 1576 | + return true; |
|
| 1577 | 1577 | } |
| 1578 | 1578 | |
| 1579 | 1579 | /** |
@@ -1591,7 +1591,7 @@ discard block |
||
| 1591 | 1591 | * @return bool true s'il a le droit, false sinon |
| 1592 | 1592 | **/ |
| 1593 | 1593 | function autoriser_rubriques_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1594 | - return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1594 | + return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1595 | 1595 | } |
| 1596 | 1596 | |
| 1597 | 1597 | /** |
@@ -1609,7 +1609,7 @@ discard block |
||
| 1609 | 1609 | * @return bool true s'il a le droit, false sinon |
| 1610 | 1610 | **/ |
| 1611 | 1611 | function autoriser_articlecreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1612 | - return verifier_table_non_vide(); |
|
| 1612 | + return verifier_table_non_vide(); |
|
| 1613 | 1613 | } |
| 1614 | 1614 | |
| 1615 | 1615 | |
@@ -1630,7 +1630,7 @@ discard block |
||
| 1630 | 1630 | * @return bool true s'il a le droit, false sinon |
| 1631 | 1631 | **/ |
| 1632 | 1632 | function autoriser_auteurcreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1633 | - return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1633 | + return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1634 | 1634 | } |
| 1635 | 1635 | |
| 1636 | 1636 | /** |
@@ -1648,11 +1648,11 @@ discard block |
||
| 1648 | 1648 | * @return bool true s'il a le droit, false sinon |
| 1649 | 1649 | **/ |
| 1650 | 1650 | function autoriser_visiteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1651 | - include_spip('base/abstract_sql'); |
|
| 1652 | - return |
|
| 1653 | - $qui['statut'] === '0minirezo' |
|
| 1654 | - && !$qui['restreint'] |
|
| 1655 | - && ($GLOBALS['meta']['accepter_visiteurs'] != 'non' || sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0); |
|
| 1651 | + include_spip('base/abstract_sql'); |
|
| 1652 | + return |
|
| 1653 | + $qui['statut'] === '0minirezo' |
|
| 1654 | + && !$qui['restreint'] |
|
| 1655 | + && ($GLOBALS['meta']['accepter_visiteurs'] != 'non' || sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0); |
|
| 1656 | 1656 | } |
| 1657 | 1657 | |
| 1658 | 1658 | /** |
@@ -1670,7 +1670,7 @@ discard block |
||
| 1670 | 1670 | * @return bool true s'il a le droit, false sinon |
| 1671 | 1671 | **/ |
| 1672 | 1672 | function autoriser_suiviedito_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1673 | - return $qui['statut'] === '0minirezo'; |
|
| 1673 | + return $qui['statut'] === '0minirezo'; |
|
| 1674 | 1674 | } |
| 1675 | 1675 | |
| 1676 | 1676 | /** |
@@ -1688,7 +1688,7 @@ discard block |
||
| 1688 | 1688 | * @return bool true s'il a le droit, false sinon |
| 1689 | 1689 | **/ |
| 1690 | 1690 | function autoriser_synchro_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1691 | - return $qui['statut'] === '0minirezo'; |
|
| 1691 | + return $qui['statut'] === '0minirezo'; |
|
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | 1694 | /** |
@@ -1706,7 +1706,7 @@ discard block |
||
| 1706 | 1706 | * @return bool true s'il a le droit, false sinon |
| 1707 | 1707 | **/ |
| 1708 | 1708 | function autoriser_configurerinteractions_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1709 | - return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1709 | + return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1710 | 1710 | } |
| 1711 | 1711 | |
| 1712 | 1712 | /** |
@@ -1724,7 +1724,7 @@ discard block |
||
| 1724 | 1724 | * @return bool true s'il a le droit, false sinon |
| 1725 | 1725 | **/ |
| 1726 | 1726 | function autoriser_configurerlangue_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1727 | - return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1727 | + return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1728 | 1728 | } |
| 1729 | 1729 | |
| 1730 | 1730 | /** |
@@ -1742,7 +1742,7 @@ discard block |
||
| 1742 | 1742 | * @return bool true s'il a le droit, false sinon |
| 1743 | 1743 | **/ |
| 1744 | 1744 | function autoriser_configurermultilinguisme_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1745 | - return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1745 | + return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1746 | 1746 | } |
| 1747 | 1747 | |
| 1748 | 1748 | /** |
@@ -1760,7 +1760,7 @@ discard block |
||
| 1760 | 1760 | * @return bool true s'il a le droit, false sinon |
| 1761 | 1761 | **/ |
| 1762 | 1762 | function autoriser_configurercontenu_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1763 | - return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1763 | + return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1764 | 1764 | } |
| 1765 | 1765 | |
| 1766 | 1766 | /** |
@@ -1778,7 +1778,7 @@ discard block |
||
| 1778 | 1778 | * @return bool true s'il a le droit, false sinon |
| 1779 | 1779 | **/ |
| 1780 | 1780 | function autoriser_configureravancees_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1781 | - return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1781 | + return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1782 | 1782 | } |
| 1783 | 1783 | |
| 1784 | 1784 | /** |
@@ -1796,7 +1796,7 @@ discard block |
||
| 1796 | 1796 | * @return bool true s'il a le droit, false sinon |
| 1797 | 1797 | **/ |
| 1798 | 1798 | function autoriser_adminplugin_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1799 | - return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1799 | + return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1800 | 1800 | } |
| 1801 | 1801 | |
| 1802 | 1802 | /** |
@@ -1814,7 +1814,7 @@ discard block |
||
| 1814 | 1814 | * @return bool true s'il a le droit, false sinon |
| 1815 | 1815 | **/ |
| 1816 | 1816 | function autoriser_admintech_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1817 | - return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1817 | + return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1818 | 1818 | } |
| 1819 | 1819 | |
| 1820 | 1820 | /** |
@@ -1832,7 +1832,7 @@ discard block |
||
| 1832 | 1832 | * @return bool true s'il a le droit, false sinon |
| 1833 | 1833 | **/ |
| 1834 | 1834 | function autoriser_queue_purger_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1835 | - return autoriser('webmestre'); |
|
| 1835 | + return autoriser('webmestre'); |
|
| 1836 | 1836 | } |
| 1837 | 1837 | |
| 1838 | 1838 | |
@@ -1852,11 +1852,11 @@ discard block |
||
| 1852 | 1852 | * @return bool true s'il a le droit, false sinon |
| 1853 | 1853 | **/ |
| 1854 | 1854 | function autoriser_echafauder_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1855 | - if (test_espace_prive()) { |
|
| 1856 | - return (bool) (int) $qui['id_auteur']; |
|
| 1857 | - } else { |
|
| 1858 | - return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1859 | - } |
|
| 1855 | + if (test_espace_prive()) { |
|
| 1856 | + return (bool) (int) $qui['id_auteur']; |
|
| 1857 | + } else { |
|
| 1858 | + return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1859 | + } |
|
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | |
@@ -1871,27 +1871,27 @@ discard block |
||
| 1871 | 1871 | * Identifiants d'auteurs |
| 1872 | 1872 | */ |
| 1873 | 1873 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1874 | - $objet = objet_type($objet); |
|
| 1875 | - $where = [ |
|
| 1876 | - 'objet=' . sql_quote($objet), |
|
| 1877 | - 'id_objet=' . (int) $id_objet |
|
| 1878 | - ]; |
|
| 1879 | - if (!empty($cond)) { |
|
| 1880 | - if (is_array($cond)) { |
|
| 1881 | - $where = array_merge($where, $cond); |
|
| 1882 | - } else { |
|
| 1883 | - $where[] = $cond; |
|
| 1884 | - } |
|
| 1885 | - } |
|
| 1886 | - $auteurs = sql_allfetsel( |
|
| 1887 | - 'id_auteur', |
|
| 1888 | - 'spip_auteurs_liens', |
|
| 1889 | - $where |
|
| 1890 | - ); |
|
| 1891 | - if (is_array($auteurs)) { |
|
| 1892 | - return array_column($auteurs, 'id_auteur'); |
|
| 1893 | - } |
|
| 1894 | - return []; |
|
| 1874 | + $objet = objet_type($objet); |
|
| 1875 | + $where = [ |
|
| 1876 | + 'objet=' . sql_quote($objet), |
|
| 1877 | + 'id_objet=' . (int) $id_objet |
|
| 1878 | + ]; |
|
| 1879 | + if (!empty($cond)) { |
|
| 1880 | + if (is_array($cond)) { |
|
| 1881 | + $where = array_merge($where, $cond); |
|
| 1882 | + } else { |
|
| 1883 | + $where[] = $cond; |
|
| 1884 | + } |
|
| 1885 | + } |
|
| 1886 | + $auteurs = sql_allfetsel( |
|
| 1887 | + 'id_auteur', |
|
| 1888 | + 'spip_auteurs_liens', |
|
| 1889 | + $where |
|
| 1890 | + ); |
|
| 1891 | + if (is_array($auteurs)) { |
|
| 1892 | + return array_column($auteurs, 'id_auteur'); |
|
| 1893 | + } |
|
| 1894 | + return []; |
|
| 1895 | 1895 | } |
| 1896 | 1896 | |
| 1897 | 1897 | /** |
@@ -1904,7 +1904,7 @@ discard block |
||
| 1904 | 1904 | */ |
| 1905 | 1905 | function acces_restreint_rubrique($id_rubrique) { |
| 1906 | 1906 | |
| 1907 | - return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1907 | + return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1908 | 1908 | } |
| 1909 | 1909 | |
| 1910 | 1910 | |
@@ -1917,12 +1917,12 @@ discard block |
||
| 1917 | 1917 | * @return bool true si un parent existe |
| 1918 | 1918 | */ |
| 1919 | 1919 | function verifier_table_non_vide($table = 'spip_rubriques') { |
| 1920 | - static $done = []; |
|
| 1921 | - if (!isset($done[$table])) { |
|
| 1922 | - $done[$table] = sql_countsel($table) > 0; |
|
| 1923 | - } |
|
| 1920 | + static $done = []; |
|
| 1921 | + if (!isset($done[$table])) { |
|
| 1922 | + $done[$table] = sql_countsel($table) > 0; |
|
| 1923 | + } |
|
| 1924 | 1924 | |
| 1925 | - return $done[$table]; |
|
| 1925 | + return $done[$table]; |
|
| 1926 | 1926 | } |
| 1927 | 1927 | |
| 1928 | 1928 | /** |
@@ -1949,12 +1949,12 @@ discard block |
||
| 1949 | 1949 | */ |
| 1950 | 1950 | function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) { |
| 1951 | 1951 | |
| 1952 | - $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1953 | - return match ($s) { |
|
| 1954 | - 'info_redacteurs' => $GLOBALS['meta']['accepter_inscriptions'] === 'oui', |
|
| 1955 | - 'info_visiteurs' => $GLOBALS['meta']['accepter_visiteurs'] === 'oui' || $GLOBALS['meta']['forums_publics'] === 'abo', |
|
| 1956 | - default => false, |
|
| 1957 | - }; |
|
| 1952 | + $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1953 | + return match ($s) { |
|
| 1954 | + 'info_redacteurs' => $GLOBALS['meta']['accepter_inscriptions'] === 'oui', |
|
| 1955 | + 'info_visiteurs' => $GLOBALS['meta']['accepter_visiteurs'] === 'oui' || $GLOBALS['meta']['forums_publics'] === 'abo', |
|
| 1956 | + default => false, |
|
| 1957 | + }; |
|
| 1958 | 1958 | } |
| 1959 | 1959 | |
| 1960 | 1960 | /** |
@@ -1972,7 +1972,7 @@ discard block |
||
| 1972 | 1972 | * @return bool true s'il a le droit, false sinon |
| 1973 | 1973 | **/ |
| 1974 | 1974 | function autoriser_inscription_relancer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1975 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 1975 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 1976 | 1976 | } |
| 1977 | 1977 | |
| 1978 | 1978 | /** |
@@ -1990,5 +1990,5 @@ discard block |
||
| 1990 | 1990 | * @return bool true s'il a le droit, false sinon |
| 1991 | 1991 | **/ |
| 1992 | 1992 | function autoriser_phpinfos_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1993 | - return autoriser('webmestre'); |
|
| 1993 | + return autoriser('webmestre'); |
|
| 1994 | 1994 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | // mais apres la fonction autoriser() |
| 120 | 120 | if ($f = find_in_path('mes_fonctions.php')) { |
| 121 | 121 | global $dossier_squelettes; |
| 122 | - include_once(_ROOT_CWD . $f); |
|
| 122 | + include_once(_ROOT_CWD.$f); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $qui = $GLOBALS['visiteur_session'] ?: []; |
| 161 | 161 | $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
| 162 | 162 | } elseif (is_numeric($qui)) { |
| 163 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 163 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur='.$qui); |
|
| 164 | 164 | if (!$qui) { |
| 165 | 165 | return false; |
| 166 | 166 | } |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | spip_log( |
| 176 | - "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 177 | - 'autoriser' . _LOG_DEBUG |
|
| 176 | + "autoriser $faire $type $id (".($qui['nom'] ?? '').') ?', |
|
| 177 | + 'autoriser'._LOG_DEBUG |
|
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | 180 | $type = autoriser_type($type); |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
| 185 | 185 | && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
| 186 | 186 | ) { |
| 187 | - spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 187 | + spip_log("autoriser ($faire, $type, $id, ".($qui['nom'] ?? '').') : OK Exception', 'autoriser'._LOG_DEBUG); |
|
| 188 | 188 | return true; |
| 189 | 189 | } |
| 190 | 190 | |
@@ -193,18 +193,18 @@ discard block |
||
| 193 | 193 | // autoriser_faire[_dist], autoriser_defaut[_dist] |
| 194 | 194 | $fonctions = $type |
| 195 | 195 | ? [ |
| 196 | - 'autoriser_' . $type . '_' . $faire, |
|
| 197 | - 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 198 | - 'autoriser_' . $type, |
|
| 199 | - 'autoriser_' . $type . '_dist', |
|
| 200 | - 'autoriser_' . $faire, |
|
| 201 | - 'autoriser_' . $faire . '_dist', |
|
| 196 | + 'autoriser_'.$type.'_'.$faire, |
|
| 197 | + 'autoriser_'.$type.'_'.$faire.'_dist', |
|
| 198 | + 'autoriser_'.$type, |
|
| 199 | + 'autoriser_'.$type.'_dist', |
|
| 200 | + 'autoriser_'.$faire, |
|
| 201 | + 'autoriser_'.$faire.'_dist', |
|
| 202 | 202 | 'autoriser_defaut', |
| 203 | 203 | 'autoriser_defaut_dist' |
| 204 | 204 | ] |
| 205 | 205 | : [ |
| 206 | - 'autoriser_' . $faire, |
|
| 207 | - 'autoriser_' . $faire . '_dist', |
|
| 206 | + 'autoriser_'.$faire, |
|
| 207 | + 'autoriser_'.$faire.'_dist', |
|
| 208 | 208 | 'autoriser_defaut', |
| 209 | 209 | 'autoriser_defaut_dist' |
| 210 | 210 | ]; |
@@ -218,8 +218,8 @@ discard block |
||
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | spip_log( |
| 221 | - "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 222 | - 'autoriser' . _LOG_DEBUG |
|
| 221 | + "$f($faire, $type, $id, ".($qui['nom'] ?? '').') : '.($a ? 'OK' : 'niet'), |
|
| 222 | + 'autoriser'._LOG_DEBUG |
|
| 223 | 223 | ); |
| 224 | 224 | |
| 225 | 225 | if (!is_bool($a)) { |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | function autoriser_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 386 | 386 | |
| 387 | 387 | // Le visiteur a-t-il un statut prevu par la config ? |
| 388 | - if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 388 | + if (str_contains((string) $GLOBALS['meta']['preview'], ','.$qui['statut'].',')) { |
|
| 389 | 389 | return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
| 390 | 390 | } |
| 391 | 391 | |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | } // pas de champ passe a la demande => NIET |
| 440 | 440 | $previsu = explode(',', (string) $c['previsu']); |
| 441 | 441 | // regarder si ce statut est autorise pour l'auteur |
| 442 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 442 | + if (in_array($opt[$champ].'/auteur', $previsu)) { |
|
| 443 | 443 | // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
| 444 | 444 | // sinon l’auteur en session |
| 445 | 445 | include_spip('inc/securiser_action'); |
@@ -453,12 +453,12 @@ discard block |
||
| 453 | 453 | |
| 454 | 454 | if (!$id_auteur) { |
| 455 | 455 | return false; |
| 456 | - } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 456 | + } elseif (autoriser('previsualiser'.$opt[$champ], $type, 0, $id_auteur)) { |
|
| 457 | 457 | // dans ce cas (admin en general), pas de filtrage sur ce statut |
| 458 | 458 | } elseif ( |
| 459 | 459 | !sql_countsel( |
| 460 | 460 | 'spip_auteurs_liens', |
| 461 | - 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 461 | + 'id_auteur='.(int) $id_auteur.' AND objet='.sql_quote($type).' AND id_objet='.(int) $id |
|
| 462 | 462 | ) |
| 463 | 463 | ) { |
| 464 | 464 | return false; |
@@ -503,14 +503,14 @@ discard block |
||
| 503 | 503 | // multilinguisme par secteur et objet rattaché à une rubrique |
| 504 | 504 | $primary = id_table_objet($type); |
| 505 | 505 | $id_rubrique = $table != 'spip_rubriques' |
| 506 | - ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 506 | + ? sql_getfetsel('id_rubrique', "$table", "$primary=".(int) $id) |
|
| 507 | 507 | : $id; |
| 508 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 508 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique); |
|
| 509 | 509 | if (!$id_secteur > 0) { |
| 510 | 510 | $id_secteur = $id_rubrique; |
| 511 | 511 | } |
| 512 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 513 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 512 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique='.(int) $id_secteur); |
|
| 513 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=".(int) $id); |
|
| 514 | 514 | if ($langue_secteur != $langue_objet) { |
| 515 | 515 | // configuration incohérente, on laisse l'utilisateur corriger la situation |
| 516 | 516 | return true; |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
| 519 | 519 | return false; |
| 520 | 520 | } else { |
| 521 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 521 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.(int) $id); |
|
| 522 | 522 | if ($id_parent != 0) { |
| 523 | 523 | // sous-rubriques : pas de choix de langue |
| 524 | 524 | return false; |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | |
| 571 | 571 | if (!isset($opt['statut'])) { |
| 572 | 572 | if (isset($desc['field']['statut'])) { |
| 573 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 573 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type).'='.(int) $id); |
|
| 574 | 574 | } else { |
| 575 | 575 | $statut = 'publie'; |
| 576 | 576 | } // pas de statut => publie |
@@ -735,11 +735,11 @@ discard block |
||
| 735 | 735 | return false; |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | - if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 738 | + if (sql_countsel('spip_rubriques', 'id_parent='.(int) $id)) { |
|
| 739 | 739 | return false; |
| 740 | 740 | } |
| 741 | 741 | |
| 742 | - if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 742 | + if (sql_countsel('spip_articles', 'id_rubrique='.(int) $id." AND (statut<>'poubelle')")) { |
|
| 743 | 743 | return false; |
| 744 | 744 | } |
| 745 | 745 | |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | if (!$id) { |
| 777 | 777 | return false; |
| 778 | 778 | } |
| 779 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 779 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article='.sql_quote($id)); |
|
| 780 | 780 | |
| 781 | 781 | return $r && ( |
| 782 | 782 | autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
@@ -784,7 +784,7 @@ discard block |
||
| 784 | 784 | (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
| 785 | 785 | && in_array($qui['statut'], ['0minirezo', '1comite']) |
| 786 | 786 | && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
| 787 | - && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 787 | + && auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur']) |
|
| 788 | 788 | ) |
| 789 | 789 | ); |
| 790 | 790 | } |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | if (!$id) { |
| 843 | 843 | return false; |
| 844 | 844 | } |
| 845 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 845 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article='.(int) $id); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | return |
@@ -851,7 +851,7 @@ discard block |
||
| 851 | 851 | in_array($statut, ['prop', 'publie']) |
| 852 | 852 | // sinon si on est auteur, on a le droit de le voir, evidemment ! |
| 853 | 853 | |
| 854 | - || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 854 | + || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur']); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | |
@@ -872,8 +872,8 @@ discard block |
||
| 872 | 872 | function autoriser_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 873 | 873 | # securite, mais on aurait pas du arriver ici ! |
| 874 | 874 | if ( |
| 875 | - function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 876 | - || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 875 | + function_exists($f = 'autoriser_'.$type.'_voir') |
|
| 876 | + || function_exists($f = 'autoriser_'.$type.'_voir_dist') |
|
| 877 | 877 | ) { |
| 878 | 878 | return $f($faire, $type, $id, $qui, $opt); |
| 879 | 879 | } |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | $n = sql_fetsel( |
| 999 | 999 | 'A.id_article', |
| 1000 | 1000 | 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
| 1001 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 1001 | + "A.statut='publie' AND L.id_auteur=".sql_quote($id) |
|
| 1002 | 1002 | ); |
| 1003 | 1003 | |
| 1004 | 1004 | return (bool) $n; |
@@ -1196,7 +1196,7 @@ discard block |
||
| 1196 | 1196 | && ($r = sql_allfetsel( |
| 1197 | 1197 | 'id_objet', |
| 1198 | 1198 | 'spip_auteurs_liens', |
| 1199 | - 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1199 | + 'id_auteur='.(int) $id_auteur." AND objet='rubrique' AND id_objet!=0" |
|
| 1200 | 1200 | )) |
| 1201 | 1201 | && (is_countable($r) ? count($r) : 0) |
| 1202 | 1202 | ) { |
@@ -1873,8 +1873,8 @@ discard block |
||
| 1873 | 1873 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1874 | 1874 | $objet = objet_type($objet); |
| 1875 | 1875 | $where = [ |
| 1876 | - 'objet=' . sql_quote($objet), |
|
| 1877 | - 'id_objet=' . (int) $id_objet |
|
| 1876 | + 'objet='.sql_quote($objet), |
|
| 1877 | + 'id_objet='.(int) $id_objet |
|
| 1878 | 1878 | ]; |
| 1879 | 1879 | if (!empty($cond)) { |
| 1880 | 1880 | if (is_array($cond)) { |