@@ -19,19 +19,19 @@ |
||
| 19 | 19 | * Retourne la liste des menus favoris par défaut ainsi que leur rang |
| 20 | 20 | */ |
| 21 | 21 | function inc_definir_menus_favoris_dist() { |
| 22 | - return [ |
|
| 22 | + return [ |
|
| 23 | 23 | |
| 24 | - // Menu Édition, |
|
| 25 | - 'auteurs' => 1, |
|
| 26 | - 'rubriques' => 2, |
|
| 27 | - 'articles' => 3, |
|
| 24 | + // Menu Édition, |
|
| 25 | + 'auteurs' => 1, |
|
| 26 | + 'rubriques' => 2, |
|
| 27 | + 'articles' => 3, |
|
| 28 | 28 | |
| 29 | - // Menu Maintenance |
|
| 30 | - 'admin_vider' => 1, |
|
| 29 | + // Menu Maintenance |
|
| 30 | + 'admin_vider' => 1, |
|
| 31 | 31 | |
| 32 | - // Menu Configurations |
|
| 33 | - 'configurer_identite' => 1, |
|
| 34 | - 'admin_plugin' => 2, |
|
| 32 | + // Menu Configurations |
|
| 33 | + 'configurer_identite' => 1, |
|
| 34 | + 'admin_plugin' => 2, |
|
| 35 | 35 | |
| 36 | - ]; |
|
| 36 | + ]; |
|
| 37 | 37 | } |
@@ -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 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/autoriser'); // necessaire si appel de l'espace public |
@@ -44,66 +44,66 @@ discard block |
||
| 44 | 44 | **/ |
| 45 | 45 | function precharger_objet($type, $id_objet, $id_rubrique = 0, $lier_trad = 0, $champ_titre = 'titre') { |
| 46 | 46 | |
| 47 | - $row = []; |
|
| 48 | - $table = table_objet_sql($type); |
|
| 49 | - $_id_objet = id_table_objet($table); |
|
| 50 | - |
|
| 51 | - // si l'objet existe deja, on retourne simplement ses valeurs |
|
| 52 | - if (is_numeric($id_objet)) { |
|
| 53 | - return sql_fetsel('*', $table, "$_id_objet=" . (int) $id_objet); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // ici, on demande une creation. |
|
| 57 | - // on prerempli certains elements : les champs si traduction, |
|
| 58 | - // les id_rubrique et id_secteur si l'objet a ces champs |
|
| 59 | - $desc = lister_tables_objets_sql($table); |
|
| 60 | - # il faudrait calculer $champ_titre ici |
|
| 61 | - $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 62 | - $is_secteur = isset($desc['field']['id_secteur']); |
|
| 63 | - |
|
| 64 | - // si demande de traduction |
|
| 65 | - // on recupere les valeurs de la traduction |
|
| 66 | - if ($lier_trad) { |
|
| 67 | - if ($select = charger_fonction('precharger_traduction_' . $type, 'inc', true)) { |
|
| 68 | - $row = $select($id_objet, $id_rubrique, $lier_trad); |
|
| 69 | - } else { |
|
| 70 | - $row = precharger_traduction_objet($type, $id_objet, $id_rubrique, $lier_trad, $champ_titre); |
|
| 71 | - } |
|
| 72 | - } else { |
|
| 73 | - $row[$champ_titre] = ''; |
|
| 74 | - if ($is_rubrique) { |
|
| 75 | - $row['id_rubrique'] = $id_rubrique; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // calcul de la rubrique |
|
| 80 | - # note : comment faire pour des traductions sur l'objet rubriques ? |
|
| 81 | - // appel du script a la racine, faut choisir |
|
| 82 | - // admin restreint ==> sa premiere rubrique |
|
| 83 | - // autre ==> la derniere rubrique cree |
|
| 84 | - if ($is_rubrique && !$row['id_rubrique']) { |
|
| 85 | - if ($GLOBALS['connect_id_rubrique']) { |
|
| 86 | - $row['id_rubrique'] = $id_rubrique = current($GLOBALS['connect_id_rubrique']); |
|
| 87 | - } else { |
|
| 88 | - $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', 1); |
|
| 89 | - $row['id_rubrique'] = $id_rubrique = $row_rub['id_rubrique']; |
|
| 90 | - } |
|
| 91 | - if (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique'])) { |
|
| 92 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 93 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 94 | - while (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique']) && $row_rub = sql_fetch($res)) { |
|
| 95 | - $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // recuperer le secteur, pour affecter les bons champs extras |
|
| 101 | - if ($id_rubrique && $is_secteur && !$row['id_secteur']) { |
|
| 102 | - $row_rub = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . sql_quote($id_rubrique)); |
|
| 103 | - $row['id_secteur'] = $row_rub; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $row; |
|
| 47 | + $row = []; |
|
| 48 | + $table = table_objet_sql($type); |
|
| 49 | + $_id_objet = id_table_objet($table); |
|
| 50 | + |
|
| 51 | + // si l'objet existe deja, on retourne simplement ses valeurs |
|
| 52 | + if (is_numeric($id_objet)) { |
|
| 53 | + return sql_fetsel('*', $table, "$_id_objet=" . (int) $id_objet); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // ici, on demande une creation. |
|
| 57 | + // on prerempli certains elements : les champs si traduction, |
|
| 58 | + // les id_rubrique et id_secteur si l'objet a ces champs |
|
| 59 | + $desc = lister_tables_objets_sql($table); |
|
| 60 | + # il faudrait calculer $champ_titre ici |
|
| 61 | + $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 62 | + $is_secteur = isset($desc['field']['id_secteur']); |
|
| 63 | + |
|
| 64 | + // si demande de traduction |
|
| 65 | + // on recupere les valeurs de la traduction |
|
| 66 | + if ($lier_trad) { |
|
| 67 | + if ($select = charger_fonction('precharger_traduction_' . $type, 'inc', true)) { |
|
| 68 | + $row = $select($id_objet, $id_rubrique, $lier_trad); |
|
| 69 | + } else { |
|
| 70 | + $row = precharger_traduction_objet($type, $id_objet, $id_rubrique, $lier_trad, $champ_titre); |
|
| 71 | + } |
|
| 72 | + } else { |
|
| 73 | + $row[$champ_titre] = ''; |
|
| 74 | + if ($is_rubrique) { |
|
| 75 | + $row['id_rubrique'] = $id_rubrique; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // calcul de la rubrique |
|
| 80 | + # note : comment faire pour des traductions sur l'objet rubriques ? |
|
| 81 | + // appel du script a la racine, faut choisir |
|
| 82 | + // admin restreint ==> sa premiere rubrique |
|
| 83 | + // autre ==> la derniere rubrique cree |
|
| 84 | + if ($is_rubrique && !$row['id_rubrique']) { |
|
| 85 | + if ($GLOBALS['connect_id_rubrique']) { |
|
| 86 | + $row['id_rubrique'] = $id_rubrique = current($GLOBALS['connect_id_rubrique']); |
|
| 87 | + } else { |
|
| 88 | + $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', 1); |
|
| 89 | + $row['id_rubrique'] = $id_rubrique = $row_rub['id_rubrique']; |
|
| 90 | + } |
|
| 91 | + if (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique'])) { |
|
| 92 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 93 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 94 | + while (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique']) && $row_rub = sql_fetch($res)) { |
|
| 95 | + $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // recuperer le secteur, pour affecter les bons champs extras |
|
| 101 | + if ($id_rubrique && $is_secteur && !$row['id_secteur']) { |
|
| 102 | + $row_rub = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . sql_quote($id_rubrique)); |
|
| 103 | + $row['id_secteur'] = $row_rub; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $row; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
@@ -125,78 +125,78 @@ discard block |
||
| 125 | 125 | * Couples clés / valeurs des champs du formulaire à charger |
| 126 | 126 | **/ |
| 127 | 127 | function precharger_traduction_objet($type, $id_objet, $id_rubrique = 0, $lier_trad = 0, $champ_titre = 'titre') { |
| 128 | - $table = table_objet_sql($type); |
|
| 129 | - $_id_objet = id_table_objet($table); |
|
| 130 | - |
|
| 131 | - // Recuperer les donnees de l'objet original |
|
| 132 | - $row = sql_fetsel('*', $table, "$_id_objet=" . (int) $lier_trad); |
|
| 133 | - if ($row) { |
|
| 134 | - include_spip('inc/filtres'); |
|
| 135 | - $row[$champ_titre] = filtrer_entites(objet_T($type, 'info_nouvelle_traduction')) . ' ' . $row[$champ_titre]; |
|
| 136 | - } else { |
|
| 137 | - $row = []; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // on met l'objet dans une rubrique si l'objet le peut |
|
| 141 | - $desc = lister_tables_objets_sql($table); |
|
| 142 | - $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 143 | - |
|
| 144 | - if ($is_rubrique) { |
|
| 145 | - $langues_dispo = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 146 | - // si le redacteur utilise une autre langue que celle de la source, on suppose que c'est pour traduire dans sa langue |
|
| 147 | - if (in_array($GLOBALS['spip_lang'], $langues_dispo) && $GLOBALS['spip_lang'] !== $row['lang']) { |
|
| 148 | - $row['lang'] = $GLOBALS['spip_lang']; |
|
| 149 | - } |
|
| 150 | - // sinon si il y a seulement 2 langues dispos, on bascule sur l'"autre" |
|
| 151 | - elseif (count($langues_dispo) == 2) { |
|
| 152 | - $autre_langue = array_diff($langues_dispo, [$row['lang']]); |
|
| 153 | - if (count($autre_langue) == 1) { |
|
| 154 | - $row['lang'] = reset($autre_langue); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - else { |
|
| 158 | - $row['lang'] = 'en'; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if ($id_rubrique) { |
|
| 162 | - $row['id_rubrique'] = $id_rubrique; |
|
| 163 | - |
|
| 164 | - return $row; |
|
| 165 | - } |
|
| 166 | - $id_rubrique = $row['id_rubrique']; |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - // Regler la langue, si possible, sur celle du redacteur |
|
| 170 | - // Cela implique souvent de choisir une rubrique ou un secteur |
|
| 171 | - if (in_array($GLOBALS['spip_lang'], $langues_dispo)) { |
|
| 172 | - // Si le menu de langues est autorise sur l'objet, |
|
| 173 | - // on peut changer la langue quelle que soit la rubrique |
|
| 174 | - // donc on reste dans la meme rubrique |
|
| 175 | - if (in_array($table, explode(',', (string) $GLOBALS['meta']['multi_objets']))) { |
|
| 176 | - $row['id_rubrique'] = $row['id_rubrique']; # explicite :-) |
|
| 177 | - |
|
| 178 | - // Sinon, chercher la rubrique la plus adaptee pour |
|
| 179 | - // accueillir l'objet dans la langue du traducteur |
|
| 180 | - } elseif ($is_rubrique && $GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 181 | - if ($GLOBALS['meta']['multi_secteurs'] == 'oui') { |
|
| 182 | - $id_parent = 0; |
|
| 183 | - } else { |
|
| 184 | - // on cherche une rubrique soeur dans la bonne langue |
|
| 185 | - $row_rub = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 186 | - $id_parent = $row_rub['id_parent']; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $row_rub = sql_fetsel( |
|
| 190 | - 'id_rubrique', |
|
| 191 | - 'spip_rubriques', |
|
| 192 | - "lang='" . $GLOBALS['spip_lang'] . "' AND id_parent=" . (int) $id_parent |
|
| 193 | - ); |
|
| 194 | - if ($row_rub) { |
|
| 195 | - $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $row; |
|
| 128 | + $table = table_objet_sql($type); |
|
| 129 | + $_id_objet = id_table_objet($table); |
|
| 130 | + |
|
| 131 | + // Recuperer les donnees de l'objet original |
|
| 132 | + $row = sql_fetsel('*', $table, "$_id_objet=" . (int) $lier_trad); |
|
| 133 | + if ($row) { |
|
| 134 | + include_spip('inc/filtres'); |
|
| 135 | + $row[$champ_titre] = filtrer_entites(objet_T($type, 'info_nouvelle_traduction')) . ' ' . $row[$champ_titre]; |
|
| 136 | + } else { |
|
| 137 | + $row = []; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // on met l'objet dans une rubrique si l'objet le peut |
|
| 141 | + $desc = lister_tables_objets_sql($table); |
|
| 142 | + $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 143 | + |
|
| 144 | + if ($is_rubrique) { |
|
| 145 | + $langues_dispo = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 146 | + // si le redacteur utilise une autre langue que celle de la source, on suppose que c'est pour traduire dans sa langue |
|
| 147 | + if (in_array($GLOBALS['spip_lang'], $langues_dispo) && $GLOBALS['spip_lang'] !== $row['lang']) { |
|
| 148 | + $row['lang'] = $GLOBALS['spip_lang']; |
|
| 149 | + } |
|
| 150 | + // sinon si il y a seulement 2 langues dispos, on bascule sur l'"autre" |
|
| 151 | + elseif (count($langues_dispo) == 2) { |
|
| 152 | + $autre_langue = array_diff($langues_dispo, [$row['lang']]); |
|
| 153 | + if (count($autre_langue) == 1) { |
|
| 154 | + $row['lang'] = reset($autre_langue); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + else { |
|
| 158 | + $row['lang'] = 'en'; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if ($id_rubrique) { |
|
| 162 | + $row['id_rubrique'] = $id_rubrique; |
|
| 163 | + |
|
| 164 | + return $row; |
|
| 165 | + } |
|
| 166 | + $id_rubrique = $row['id_rubrique']; |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + // Regler la langue, si possible, sur celle du redacteur |
|
| 170 | + // Cela implique souvent de choisir une rubrique ou un secteur |
|
| 171 | + if (in_array($GLOBALS['spip_lang'], $langues_dispo)) { |
|
| 172 | + // Si le menu de langues est autorise sur l'objet, |
|
| 173 | + // on peut changer la langue quelle que soit la rubrique |
|
| 174 | + // donc on reste dans la meme rubrique |
|
| 175 | + if (in_array($table, explode(',', (string) $GLOBALS['meta']['multi_objets']))) { |
|
| 176 | + $row['id_rubrique'] = $row['id_rubrique']; # explicite :-) |
|
| 177 | + |
|
| 178 | + // Sinon, chercher la rubrique la plus adaptee pour |
|
| 179 | + // accueillir l'objet dans la langue du traducteur |
|
| 180 | + } elseif ($is_rubrique && $GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 181 | + if ($GLOBALS['meta']['multi_secteurs'] == 'oui') { |
|
| 182 | + $id_parent = 0; |
|
| 183 | + } else { |
|
| 184 | + // on cherche une rubrique soeur dans la bonne langue |
|
| 185 | + $row_rub = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 186 | + $id_parent = $row_rub['id_parent']; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $row_rub = sql_fetsel( |
|
| 190 | + 'id_rubrique', |
|
| 191 | + 'spip_rubriques', |
|
| 192 | + "lang='" . $GLOBALS['spip_lang'] . "' AND id_parent=" . (int) $id_parent |
|
| 193 | + ); |
|
| 194 | + if ($row_rub) { |
|
| 195 | + $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $row; |
|
| 202 | 202 | } |
@@ -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 | } |
@@ -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 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | **/ |
| 8 | 8 | |
| 9 | 9 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 10 | - return; |
|
| 10 | + return; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -28,49 +28,49 @@ discard block |
||
| 28 | 28 | * - afficher : tableau des objets à afficher (mais pas forcément sélectionnables) |
| 29 | 29 | */ |
| 30 | 30 | function selecteur_lister_objets($includelist = [], $excludelist = []) { |
| 31 | - static $liste_selecteurs, $liste_parents; |
|
| 32 | - |
|
| 33 | - if (!$liste_selecteurs) { |
|
| 34 | - $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | - } |
|
| 36 | - $objets_selectionner = []; |
|
| 37 | - foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | - $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | - if (!empty($includelist)) { |
|
| 43 | - $includelist = array_map('table_objet', $includelist); |
|
| 44 | - $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | - } |
|
| 46 | - // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | - $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | - // On enlève toujours la racine |
|
| 49 | - $excludelist[] = 'racine'; |
|
| 50 | - $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | - |
|
| 52 | - // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | - $objets_afficher = $objets_selectionner; |
|
| 54 | - |
|
| 55 | - // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | - // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | - if (!$liste_parents) { |
|
| 58 | - $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | - } |
|
| 60 | - foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | - preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures); |
|
| 62 | - $parent = $captures[1]; |
|
| 63 | - $type = $captures[2]; |
|
| 64 | - // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | - if (in_array($type, $objets_afficher)) { |
|
| 66 | - $objets_afficher[] = $parent; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return [ |
|
| 71 | - 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | - 'afficher' => array_unique($objets_afficher), |
|
| 73 | - ]; |
|
| 31 | + static $liste_selecteurs, $liste_parents; |
|
| 32 | + |
|
| 33 | + if (!$liste_selecteurs) { |
|
| 34 | + $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | + } |
|
| 36 | + $objets_selectionner = []; |
|
| 37 | + foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | + $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | + if (!empty($includelist)) { |
|
| 43 | + $includelist = array_map('table_objet', $includelist); |
|
| 44 | + $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | + } |
|
| 46 | + // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | + $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | + // On enlève toujours la racine |
|
| 49 | + $excludelist[] = 'racine'; |
|
| 50 | + $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | + |
|
| 52 | + // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | + $objets_afficher = $objets_selectionner; |
|
| 54 | + |
|
| 55 | + // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | + // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | + if (!$liste_parents) { |
|
| 58 | + $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | + } |
|
| 60 | + foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | + preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures); |
|
| 62 | + $parent = $captures[1]; |
|
| 63 | + $type = $captures[2]; |
|
| 64 | + // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | + if (in_array($type, $objets_afficher)) { |
|
| 66 | + $objets_afficher[] = $parent; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return [ |
|
| 71 | + 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | + 'afficher' => array_unique($objets_afficher), |
|
| 73 | + ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -97,31 +97,31 @@ discard block |
||
| 97 | 97 | * liste des couples (objets => id_objet) ou liste des identifiants d'un type d'objet. |
| 98 | 98 | **/ |
| 99 | 99 | function picker_selected($selected, $type = '') { |
| 100 | - $select = []; |
|
| 101 | - $type = preg_replace(',\W,', '', $type); |
|
| 102 | - |
|
| 103 | - if ($selected && !is_array($selected)) { |
|
| 104 | - $selected = explode(',', $selected); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if (is_array($selected)) { |
|
| 108 | - foreach ($selected as $value) { |
|
| 109 | - // Si c'est le bon format déjà |
|
| 110 | - if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) { |
|
| 111 | - $objet = $captures[1]; |
|
| 112 | - $id_objet = (int) $captures[2]; |
|
| 113 | - |
|
| 114 | - // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | - if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | - $select[] = $id_objet; |
|
| 117 | - } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | - $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $select; |
|
| 100 | + $select = []; |
|
| 101 | + $type = preg_replace(',\W,', '', $type); |
|
| 102 | + |
|
| 103 | + if ($selected && !is_array($selected)) { |
|
| 104 | + $selected = explode(',', $selected); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if (is_array($selected)) { |
|
| 108 | + foreach ($selected as $value) { |
|
| 109 | + // Si c'est le bon format déjà |
|
| 110 | + if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) { |
|
| 111 | + $objet = $captures[1]; |
|
| 112 | + $id_objet = (int) $captures[2]; |
|
| 113 | + |
|
| 114 | + // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | + if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | + $select[] = $id_objet; |
|
| 117 | + } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | + $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $select; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -138,53 +138,53 @@ discard block |
||
| 138 | 138 | * Booléen indiquant si les articles sont sélectionnables |
| 139 | 139 | */ |
| 140 | 140 | function picker_identifie_id_rapide($ref, $rubriques_ou_objets = false, $articles = false) { |
| 141 | - include_spip('inc/json'); |
|
| 142 | - include_spip('inc/lien'); |
|
| 143 | - |
|
| 144 | - // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | - $objets = []; |
|
| 146 | - if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | - $objets = $rubriques_ou_objets; |
|
| 148 | - } else { |
|
| 149 | - if ($rubriques_ou_objets) { |
|
| 150 | - $objets[] = 'rubriques'; |
|
| 151 | - } |
|
| 152 | - if ($articles) { |
|
| 153 | - $objets[] = 'articles'; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | - if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | - $type = reset($objets); |
|
| 160 | - $type = objet_type($type); |
|
| 161 | - $id = (int) $ref; |
|
| 162 | - $ref = $type . $ref; |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - // Si la référence ne correspond à rien, c'est fini |
|
| 166 | - if (!($match = typer_raccourci($ref))) { |
|
| 167 | - return json_export(false); |
|
| 168 | - } |
|
| 169 | - // Sinon on récupère les infos utiles |
|
| 170 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | - |
|
| 172 | - // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | - if (!in_array(table_objet($type), $objets)) { |
|
| 174 | - return json_export(false); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | - include_spip('inc/filtres'); |
|
| 180 | - if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | - return json_export(false); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // On simplifie le texte |
|
| 185 | - $titre = attribut_html($titre); |
|
| 186 | - |
|
| 187 | - return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 141 | + include_spip('inc/json'); |
|
| 142 | + include_spip('inc/lien'); |
|
| 143 | + |
|
| 144 | + // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | + $objets = []; |
|
| 146 | + if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | + $objets = $rubriques_ou_objets; |
|
| 148 | + } else { |
|
| 149 | + if ($rubriques_ou_objets) { |
|
| 150 | + $objets[] = 'rubriques'; |
|
| 151 | + } |
|
| 152 | + if ($articles) { |
|
| 153 | + $objets[] = 'articles'; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | + if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | + $type = reset($objets); |
|
| 160 | + $type = objet_type($type); |
|
| 161 | + $id = (int) $ref; |
|
| 162 | + $ref = $type . $ref; |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + // Si la référence ne correspond à rien, c'est fini |
|
| 166 | + if (!($match = typer_raccourci($ref))) { |
|
| 167 | + return json_export(false); |
|
| 168 | + } |
|
| 169 | + // Sinon on récupère les infos utiles |
|
| 170 | + [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | + |
|
| 172 | + // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | + if (!in_array(table_objet($type), $objets)) { |
|
| 174 | + return json_export(false); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | + include_spip('inc/filtres'); |
|
| 180 | + if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | + return json_export(false); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // On simplifie le texte |
|
| 185 | + $titre = attribut_html($titre); |
|
| 186 | + |
|
| 187 | + return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -207,34 +207,34 @@ discard block |
||
| 207 | 207 | * Comme le filtre `oui` : espace (` `) si rubrique à afficher, chaîne vide sinon. |
| 208 | 208 | */ |
| 209 | 209 | function test_enfants_rubrique($id_rubrique, $types = []) { |
| 210 | - static $has_child = []; |
|
| 211 | - |
|
| 212 | - if (!isset($has_child[$id_rubrique])) { |
|
| 213 | - $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | - |
|
| 215 | - // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | - $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | - $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | - $has = array_column($has, 'id_parent'); |
|
| 221 | - $fratrie = array_diff($fratrie, $has); |
|
| 222 | - |
|
| 223 | - while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | - $type = array_shift($types); |
|
| 225 | - $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | - $h = array_column($h, 'id_rubrique'); |
|
| 227 | - $has = [...$has, ...$h]; |
|
| 228 | - $fratrie = array_diff($fratrie, $h); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - if ($has !== []) { |
|
| 232 | - $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | - } |
|
| 234 | - if ($fratrie !== []) { |
|
| 235 | - $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 210 | + static $has_child = []; |
|
| 211 | + |
|
| 212 | + if (!isset($has_child[$id_rubrique])) { |
|
| 213 | + $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | + |
|
| 215 | + // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | + $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | + $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | + $has = array_column($has, 'id_parent'); |
|
| 221 | + $fratrie = array_diff($fratrie, $has); |
|
| 222 | + |
|
| 223 | + while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | + $type = array_shift($types); |
|
| 225 | + $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | + $h = array_column($h, 'id_rubrique'); |
|
| 227 | + $has = [...$has, ...$h]; |
|
| 228 | + $fratrie = array_diff($fratrie, $h); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + if ($has !== []) { |
|
| 232 | + $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | + } |
|
| 234 | + if ($fratrie !== []) { |
|
| 235 | + $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 240 | 240 | } |
@@ -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 | } |
@@ -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 | /** |
@@ -37,70 +37,70 @@ discard block |
||
| 37 | 37 | * @return array|string |
| 38 | 38 | */ |
| 39 | 39 | function inc_couleurs_dist($choix = null, $ajouter = false) { |
| 40 | - static $couleurs_spip = [ |
|
| 41 | - // Violet soutenu |
|
| 42 | - 9 => ['couleur_theme' => '#9a6ef2'], |
|
| 43 | - // Violet rosé |
|
| 44 | - 4 => ['couleur_theme' => '#c464cb'], |
|
| 45 | - // Rose interface SPIP |
|
| 46 | - 2 => ['couleur_theme' => '#F02364'], |
|
| 47 | - // Rouge |
|
| 48 | - 8 => ['couleur_theme' => '#ff4524'], |
|
| 49 | - // Orange |
|
| 50 | - 3 => ['couleur_theme' => '#c97500'], |
|
| 51 | - // Vert SPIP |
|
| 52 | - 1 => ['couleur_theme' => '#9dba00'], |
|
| 53 | - // Vert Troglo |
|
| 54 | - 7 => ['couleur_theme' => '#419a2c'], |
|
| 55 | - // Bleu-vert |
|
| 56 | - 12 => ['couleur_theme' => '#269681'], |
|
| 57 | - // Bleu pastel |
|
| 58 | - 5 => ['couleur_theme' => '#3190ae'], |
|
| 59 | - // Bleu Kermesse |
|
| 60 | - 11 => ['couleur_theme' => '#288bdd'], |
|
| 61 | - // Gris bleuté |
|
| 62 | - 6 => ['couleur_theme' => '#7d90a2'], |
|
| 63 | - // Gris |
|
| 64 | - 10 => ['couleur_theme' => '#909090'], |
|
| 65 | - ]; |
|
| 40 | + static $couleurs_spip = [ |
|
| 41 | + // Violet soutenu |
|
| 42 | + 9 => ['couleur_theme' => '#9a6ef2'], |
|
| 43 | + // Violet rosé |
|
| 44 | + 4 => ['couleur_theme' => '#c464cb'], |
|
| 45 | + // Rose interface SPIP |
|
| 46 | + 2 => ['couleur_theme' => '#F02364'], |
|
| 47 | + // Rouge |
|
| 48 | + 8 => ['couleur_theme' => '#ff4524'], |
|
| 49 | + // Orange |
|
| 50 | + 3 => ['couleur_theme' => '#c97500'], |
|
| 51 | + // Vert SPIP |
|
| 52 | + 1 => ['couleur_theme' => '#9dba00'], |
|
| 53 | + // Vert Troglo |
|
| 54 | + 7 => ['couleur_theme' => '#419a2c'], |
|
| 55 | + // Bleu-vert |
|
| 56 | + 12 => ['couleur_theme' => '#269681'], |
|
| 57 | + // Bleu pastel |
|
| 58 | + 5 => ['couleur_theme' => '#3190ae'], |
|
| 59 | + // Bleu Kermesse |
|
| 60 | + 11 => ['couleur_theme' => '#288bdd'], |
|
| 61 | + // Gris bleuté |
|
| 62 | + 6 => ['couleur_theme' => '#7d90a2'], |
|
| 63 | + // Gris |
|
| 64 | + 10 => ['couleur_theme' => '#909090'], |
|
| 65 | + ]; |
|
| 66 | 66 | |
| 67 | - if (is_numeric($choix)) { |
|
| 68 | - $c = $couleurs_spip[$choix]; |
|
| 69 | - // compat < SPIP 3.3 |
|
| 70 | - include_spip('inc/filtres_images_mini'); |
|
| 71 | - $c['couleur_foncee'] = $c['couleur_theme']; |
|
| 72 | - $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 67 | + if (is_numeric($choix)) { |
|
| 68 | + $c = $couleurs_spip[$choix]; |
|
| 69 | + // compat < SPIP 3.3 |
|
| 70 | + include_spip('inc/filtres_images_mini'); |
|
| 71 | + $c['couleur_foncee'] = $c['couleur_theme']; |
|
| 72 | + $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 73 | 73 | |
| 74 | - return |
|
| 75 | - 'couleur_theme=' . substr((string) $c['couleur_theme'], 1) |
|
| 76 | - // compat < SPIP 3.3 |
|
| 77 | - . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 78 | - . '&couleur_foncee=' . substr((string) $c['couleur_foncee'], 1); |
|
| 79 | - } else { |
|
| 80 | - if (is_array($choix)) { |
|
| 81 | - // compat < SPIP 3.3 |
|
| 82 | - $compat_spip_33 = function ($c) { |
|
| 83 | - if (!isset($c['couleur_theme'])) { |
|
| 84 | - $c['couleur_theme'] = $c['couleur_foncee']; |
|
| 85 | - unset($c['couleur_foncee']); |
|
| 86 | - unset($c['couleur_claire']); |
|
| 87 | - unset($c['couleur_lien']); |
|
| 88 | - unset($c['couleur_lien_off']); |
|
| 89 | - } |
|
| 90 | - return $c; |
|
| 91 | - }; |
|
| 92 | - if ($ajouter) { |
|
| 93 | - foreach ($choix as $c) { |
|
| 94 | - $couleurs_spip[] = $compat_spip_33($c); |
|
| 95 | - } |
|
| 74 | + return |
|
| 75 | + 'couleur_theme=' . substr((string) $c['couleur_theme'], 1) |
|
| 76 | + // compat < SPIP 3.3 |
|
| 77 | + . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 78 | + . '&couleur_foncee=' . substr((string) $c['couleur_foncee'], 1); |
|
| 79 | + } else { |
|
| 80 | + if (is_array($choix)) { |
|
| 81 | + // compat < SPIP 3.3 |
|
| 82 | + $compat_spip_33 = function ($c) { |
|
| 83 | + if (!isset($c['couleur_theme'])) { |
|
| 84 | + $c['couleur_theme'] = $c['couleur_foncee']; |
|
| 85 | + unset($c['couleur_foncee']); |
|
| 86 | + unset($c['couleur_claire']); |
|
| 87 | + unset($c['couleur_lien']); |
|
| 88 | + unset($c['couleur_lien_off']); |
|
| 89 | + } |
|
| 90 | + return $c; |
|
| 91 | + }; |
|
| 92 | + if ($ajouter) { |
|
| 93 | + foreach ($choix as $c) { |
|
| 94 | + $couleurs_spip[] = $compat_spip_33($c); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return $couleurs_spip; |
|
| 98 | - } else { |
|
| 99 | - $choix = array_map($compat_spip_33, $choix); |
|
| 100 | - return $couleurs_spip = $choix; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } |
|
| 97 | + return $couleurs_spip; |
|
| 98 | + } else { |
|
| 99 | + $choix = array_map($compat_spip_33, $choix); |
|
| 100 | + return $couleurs_spip = $choix; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return $couleurs_spip; |
|
| 105 | + return $couleurs_spip; |
|
| 106 | 106 | } |