@@ -20,188 +20,188 @@ |
||
| 20 | 20 | // par souci de compatiilite). |
| 21 | 21 | |
| 22 | 22 | if (isset($GLOBALS['_INC_PUBLIC']) && $GLOBALS['_INC_PUBLIC']) { |
| 23 | - echo recuperer_fond($fond, $contexte_inclus, [], _request('connect') ?? ''); |
|
| 23 | + echo recuperer_fond($fond, $contexte_inclus, [], _request('connect') ?? ''); |
|
| 24 | 24 | } else { |
| 25 | - $GLOBALS['_INC_PUBLIC'] = 1; |
|
| 26 | - define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : ''); |
|
| 27 | - |
|
| 28 | - // Faut-il initialiser SPIP ? (oui dans le cas general) |
|
| 29 | - if (!defined('_DIR_RESTREINT_ABS')) { |
|
| 30 | - if ( |
|
| 31 | - defined('_DIR_RESTREINT') |
|
| 32 | - && @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 33 | - ) { |
|
| 34 | - include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 35 | - } else { |
|
| 36 | - die('inc_version absent ?'); |
|
| 37 | - } |
|
| 38 | - } // $fond defini dans le fichier d'appel ? |
|
| 39 | - |
|
| 40 | - else { |
|
| 41 | - if (isset($fond) && !_request('fond')) { |
|
| 42 | - } // fond demande dans l'url par page=xxxx ? |
|
| 43 | - else { |
|
| 44 | - if (isset($_GET[_SPIP_PAGE])) { |
|
| 45 | - $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 46 | - |
|
| 47 | - // Securite |
|
| 48 | - if ( |
|
| 49 | - strstr($fond, '/') |
|
| 50 | - && !(isset($GLOBALS['visiteur_session']) && include_spip('inc/autoriser') && autoriser('webmestre')) |
|
| 51 | - ) { |
|
| 52 | - include_spip('inc/minipres'); |
|
| 53 | - echo minipres(); |
|
| 54 | - exit; |
|
| 55 | - } |
|
| 56 | - // l'argument Page a priorite sur l'argument action |
|
| 57 | - // le cas se presente a cause des RewriteRule d'Apache |
|
| 58 | - // qui permettent d'ajouter un argument dans la QueryString |
|
| 59 | - // mais pas d'en retirer un en conservant les autres. |
|
| 60 | - if (isset($_GET['action']) && $_GET['action'] === $fond) { |
|
| 61 | - unset($_GET['action']); |
|
| 62 | - } |
|
| 63 | - # sinon, fond par defaut |
|
| 64 | - } else { |
|
| 65 | - // sinon fond par defaut (cf. assembler.php) |
|
| 66 | - $fond = pipeline('detecter_fond_par_defaut', ''); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $tableau_des_temps = []; |
|
| 72 | - |
|
| 73 | - // Particularites de certains squelettes |
|
| 74 | - if ($fond == 'login') { |
|
| 75 | - $forcer_lang = true; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if ( |
|
| 79 | - isset($forcer_lang) && $forcer_lang && $forcer_lang !== 'non' |
|
| 80 | - && !_request('action') |
|
| 81 | - && $_SERVER['REQUEST_METHOD'] != 'POST' |
|
| 82 | - ) { |
|
| 83 | - include_spip('inc/lang'); |
|
| 84 | - verifier_lang_url(); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $lang = isset($_GET['lang']) ? lang_select($_GET['lang']) : ''; |
|
| 88 | - |
|
| 89 | - // Charger l'aiguilleur des traitements derogatoires |
|
| 90 | - // (action en base SQL, formulaires CVT, AJax) |
|
| 91 | - if (_request('action') || _request('var_ajax') || _request('formulaire_action')) { |
|
| 92 | - include_spip('public/aiguiller'); |
|
| 93 | - if ( |
|
| 94 | - // cas des appels actions ?action=xxx |
|
| 95 | - traiter_appels_actions() |
|
| 96 | - // cas des hits ajax sur les inclusions ajax |
|
| 97 | - || traiter_appels_inclusions_ajax() |
|
| 98 | - // cas des formulaires charger/verifier/traiter |
|
| 99 | - || traiter_formulaires_dynamiques() |
|
| 100 | - ) { |
|
| 101 | - // lancer les taches sur affichage final, comme le cron |
|
| 102 | - // mais sans rien afficher |
|
| 103 | - $GLOBALS['html'] = false; // ne rien afficher |
|
| 104 | - pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 105 | - exit; // le hit est fini ! |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // Il y a du texte a produire, charger le metteur en page |
|
| 110 | - include_spip('public/assembler'); |
|
| 111 | - $page = assembler($fond, _request('connect') ?? ''); |
|
| 112 | - |
|
| 113 | - if (isset($page['status'])) { |
|
| 114 | - include_spip('inc/headers'); |
|
| 115 | - http_response_code($page['status']); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // Content-Type ? |
|
| 119 | - if (!isset($page['entetes']['Content-Type'])) { |
|
| 120 | - $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
|
| 121 | - $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 122 | - $html = true; |
|
| 123 | - } else { |
|
| 124 | - $html = preg_match(',^\s*text/html,', (string) $page['entetes']['Content-Type']); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // Tester si on est admin et il y a des choses supplementaires a dire |
|
| 128 | - // type tableau pour y mettre des choses au besoin. |
|
| 129 | - $debug = (_request('var_mode') == 'debug' || $tableau_des_temps) ? [1] : []; |
|
| 130 | - |
|
| 131 | - // affiche-t-on les boutons d'administration ? voir f_admin() |
|
| 132 | - $affiche_boutons_admin = ($html && ( |
|
| 133 | - isset($_COOKIE['spip_admin']) && (!isset($flag_preserver) || !$flag_preserver) |
|
| 134 | - || $debug && include_spip('inc/autoriser') && autoriser('debug') |
|
| 135 | - || defined('_VAR_PREVIEW') && _VAR_PREVIEW) |
|
| 136 | - ); |
|
| 137 | - |
|
| 138 | - if ($affiche_boutons_admin) { |
|
| 139 | - include_spip('balise/formulaire_admin'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - // Execution de la page calculee |
|
| 144 | - |
|
| 145 | - // traitements sur les entetes avant envoi |
|
| 146 | - // peut servir pour le plugin de stats |
|
| 147 | - $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - // eval $page et affecte $res |
|
| 151 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 152 | - envoyer_entetes($page['entetes']); |
|
| 153 | - if ($res === false) { |
|
| 154 | - include_spip('inc/autoriser'); |
|
| 155 | - $err = _T('zbug_erreur_execution_page'); |
|
| 156 | - if (autoriser('webmestre')) { |
|
| 157 | - $err .= "\n<hr />\n" |
|
| 158 | - . highlight_string($page['codephp'], true) |
|
| 159 | - . "\n<hr />\n"; |
|
| 160 | - } |
|
| 161 | - $msg = [$err]; |
|
| 162 | - erreur_squelette($msg); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // |
|
| 166 | - // Envoyer le resultat apres post-traitements |
|
| 167 | - // |
|
| 168 | - // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
|
| 169 | - // cf. public/assembler.php) |
|
| 170 | - echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 171 | - |
|
| 172 | - if ($lang) { |
|
| 173 | - lang_select(); |
|
| 174 | - } |
|
| 175 | - // l'affichage de la page a pu lever des erreurs (inclusion manquante) |
|
| 176 | - // il faut tester a nouveau |
|
| 177 | - $debug = (_request('var_mode') == 'debug' || $tableau_des_temps) ? [1] : []; |
|
| 178 | - |
|
| 179 | - // Appel au debusqueur en cas d'erreurs ou de demande de trace |
|
| 180 | - // at last |
|
| 181 | - if ($debug) { |
|
| 182 | - // en cas d'erreur, retester l'affichage |
|
| 183 | - if ($html && ($affiche_boutons_admin || $debug)) { |
|
| 184 | - $var_mode_affiche = _request('var_mode_affiche'); |
|
| 185 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 186 | - $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 187 | - echo erreur_squelette(false); |
|
| 188 | - } |
|
| 189 | - } else { |
|
| 190 | - if ( |
|
| 191 | - isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 192 | - && $GLOBALS['meta']['date_prochain_postdate'] <= time() |
|
| 193 | - ) { |
|
| 194 | - include_spip('inc/rubriques'); |
|
| 195 | - calculer_prochain_postdate(true); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - // Effectuer une tache de fond ? |
|
| 199 | - // si _DIRECT_CRON_FORCE est present, on force l'appel |
|
| 200 | - if (defined('_DIRECT_CRON_FORCE')) { |
|
| 201 | - cron(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // sauver le cache chemin si necessaire |
|
| 205 | - save_path_cache(); |
|
| 206 | - } |
|
| 25 | + $GLOBALS['_INC_PUBLIC'] = 1; |
|
| 26 | + define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : ''); |
|
| 27 | + |
|
| 28 | + // Faut-il initialiser SPIP ? (oui dans le cas general) |
|
| 29 | + if (!defined('_DIR_RESTREINT_ABS')) { |
|
| 30 | + if ( |
|
| 31 | + defined('_DIR_RESTREINT') |
|
| 32 | + && @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 33 | + ) { |
|
| 34 | + include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 35 | + } else { |
|
| 36 | + die('inc_version absent ?'); |
|
| 37 | + } |
|
| 38 | + } // $fond defini dans le fichier d'appel ? |
|
| 39 | + |
|
| 40 | + else { |
|
| 41 | + if (isset($fond) && !_request('fond')) { |
|
| 42 | + } // fond demande dans l'url par page=xxxx ? |
|
| 43 | + else { |
|
| 44 | + if (isset($_GET[_SPIP_PAGE])) { |
|
| 45 | + $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 46 | + |
|
| 47 | + // Securite |
|
| 48 | + if ( |
|
| 49 | + strstr($fond, '/') |
|
| 50 | + && !(isset($GLOBALS['visiteur_session']) && include_spip('inc/autoriser') && autoriser('webmestre')) |
|
| 51 | + ) { |
|
| 52 | + include_spip('inc/minipres'); |
|
| 53 | + echo minipres(); |
|
| 54 | + exit; |
|
| 55 | + } |
|
| 56 | + // l'argument Page a priorite sur l'argument action |
|
| 57 | + // le cas se presente a cause des RewriteRule d'Apache |
|
| 58 | + // qui permettent d'ajouter un argument dans la QueryString |
|
| 59 | + // mais pas d'en retirer un en conservant les autres. |
|
| 60 | + if (isset($_GET['action']) && $_GET['action'] === $fond) { |
|
| 61 | + unset($_GET['action']); |
|
| 62 | + } |
|
| 63 | + # sinon, fond par defaut |
|
| 64 | + } else { |
|
| 65 | + // sinon fond par defaut (cf. assembler.php) |
|
| 66 | + $fond = pipeline('detecter_fond_par_defaut', ''); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $tableau_des_temps = []; |
|
| 72 | + |
|
| 73 | + // Particularites de certains squelettes |
|
| 74 | + if ($fond == 'login') { |
|
| 75 | + $forcer_lang = true; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if ( |
|
| 79 | + isset($forcer_lang) && $forcer_lang && $forcer_lang !== 'non' |
|
| 80 | + && !_request('action') |
|
| 81 | + && $_SERVER['REQUEST_METHOD'] != 'POST' |
|
| 82 | + ) { |
|
| 83 | + include_spip('inc/lang'); |
|
| 84 | + verifier_lang_url(); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $lang = isset($_GET['lang']) ? lang_select($_GET['lang']) : ''; |
|
| 88 | + |
|
| 89 | + // Charger l'aiguilleur des traitements derogatoires |
|
| 90 | + // (action en base SQL, formulaires CVT, AJax) |
|
| 91 | + if (_request('action') || _request('var_ajax') || _request('formulaire_action')) { |
|
| 92 | + include_spip('public/aiguiller'); |
|
| 93 | + if ( |
|
| 94 | + // cas des appels actions ?action=xxx |
|
| 95 | + traiter_appels_actions() |
|
| 96 | + // cas des hits ajax sur les inclusions ajax |
|
| 97 | + || traiter_appels_inclusions_ajax() |
|
| 98 | + // cas des formulaires charger/verifier/traiter |
|
| 99 | + || traiter_formulaires_dynamiques() |
|
| 100 | + ) { |
|
| 101 | + // lancer les taches sur affichage final, comme le cron |
|
| 102 | + // mais sans rien afficher |
|
| 103 | + $GLOBALS['html'] = false; // ne rien afficher |
|
| 104 | + pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 105 | + exit; // le hit est fini ! |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // Il y a du texte a produire, charger le metteur en page |
|
| 110 | + include_spip('public/assembler'); |
|
| 111 | + $page = assembler($fond, _request('connect') ?? ''); |
|
| 112 | + |
|
| 113 | + if (isset($page['status'])) { |
|
| 114 | + include_spip('inc/headers'); |
|
| 115 | + http_response_code($page['status']); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // Content-Type ? |
|
| 119 | + if (!isset($page['entetes']['Content-Type'])) { |
|
| 120 | + $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
|
| 121 | + $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 122 | + $html = true; |
|
| 123 | + } else { |
|
| 124 | + $html = preg_match(',^\s*text/html,', (string) $page['entetes']['Content-Type']); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // Tester si on est admin et il y a des choses supplementaires a dire |
|
| 128 | + // type tableau pour y mettre des choses au besoin. |
|
| 129 | + $debug = (_request('var_mode') == 'debug' || $tableau_des_temps) ? [1] : []; |
|
| 130 | + |
|
| 131 | + // affiche-t-on les boutons d'administration ? voir f_admin() |
|
| 132 | + $affiche_boutons_admin = ($html && ( |
|
| 133 | + isset($_COOKIE['spip_admin']) && (!isset($flag_preserver) || !$flag_preserver) |
|
| 134 | + || $debug && include_spip('inc/autoriser') && autoriser('debug') |
|
| 135 | + || defined('_VAR_PREVIEW') && _VAR_PREVIEW) |
|
| 136 | + ); |
|
| 137 | + |
|
| 138 | + if ($affiche_boutons_admin) { |
|
| 139 | + include_spip('balise/formulaire_admin'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + // Execution de la page calculee |
|
| 144 | + |
|
| 145 | + // traitements sur les entetes avant envoi |
|
| 146 | + // peut servir pour le plugin de stats |
|
| 147 | + $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + // eval $page et affecte $res |
|
| 151 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 152 | + envoyer_entetes($page['entetes']); |
|
| 153 | + if ($res === false) { |
|
| 154 | + include_spip('inc/autoriser'); |
|
| 155 | + $err = _T('zbug_erreur_execution_page'); |
|
| 156 | + if (autoriser('webmestre')) { |
|
| 157 | + $err .= "\n<hr />\n" |
|
| 158 | + . highlight_string($page['codephp'], true) |
|
| 159 | + . "\n<hr />\n"; |
|
| 160 | + } |
|
| 161 | + $msg = [$err]; |
|
| 162 | + erreur_squelette($msg); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // |
|
| 166 | + // Envoyer le resultat apres post-traitements |
|
| 167 | + // |
|
| 168 | + // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
|
| 169 | + // cf. public/assembler.php) |
|
| 170 | + echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 171 | + |
|
| 172 | + if ($lang) { |
|
| 173 | + lang_select(); |
|
| 174 | + } |
|
| 175 | + // l'affichage de la page a pu lever des erreurs (inclusion manquante) |
|
| 176 | + // il faut tester a nouveau |
|
| 177 | + $debug = (_request('var_mode') == 'debug' || $tableau_des_temps) ? [1] : []; |
|
| 178 | + |
|
| 179 | + // Appel au debusqueur en cas d'erreurs ou de demande de trace |
|
| 180 | + // at last |
|
| 181 | + if ($debug) { |
|
| 182 | + // en cas d'erreur, retester l'affichage |
|
| 183 | + if ($html && ($affiche_boutons_admin || $debug)) { |
|
| 184 | + $var_mode_affiche = _request('var_mode_affiche'); |
|
| 185 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 186 | + $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 187 | + echo erreur_squelette(false); |
|
| 188 | + } |
|
| 189 | + } else { |
|
| 190 | + if ( |
|
| 191 | + isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 192 | + && $GLOBALS['meta']['date_prochain_postdate'] <= time() |
|
| 193 | + ) { |
|
| 194 | + include_spip('inc/rubriques'); |
|
| 195 | + calculer_prochain_postdate(true); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + // Effectuer une tache de fond ? |
|
| 199 | + // si _DIRECT_CRON_FORCE est present, on force l'appel |
|
| 200 | + if (defined('_DIRECT_CRON_FORCE')) { |
|
| 201 | + cron(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // sauver le cache chemin si necessaire |
|
| 205 | + save_path_cache(); |
|
| 206 | + } |
|
| 207 | 207 | } |
@@ -29,9 +29,9 @@ discard block |
||
| 29 | 29 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 30 | 30 | if ( |
| 31 | 31 | defined('_DIR_RESTREINT') |
| 32 | - && @file_exists(_ROOT_RESTREINT . 'inc_version.php') |
|
| 32 | + && @file_exists(_ROOT_RESTREINT.'inc_version.php') |
|
| 33 | 33 | ) { |
| 34 | - include_once _ROOT_RESTREINT . 'inc_version.php'; |
|
| 34 | + include_once _ROOT_RESTREINT.'inc_version.php'; |
|
| 35 | 35 | } else { |
| 36 | 36 | die('inc_version absent ?'); |
| 37 | 37 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | } // fond demande dans l'url par page=xxxx ? |
| 43 | 43 | else { |
| 44 | 44 | if (isset($_GET[_SPIP_PAGE])) { |
| 45 | - $fond = (string)$_GET[_SPIP_PAGE]; |
|
| 45 | + $fond = (string) $_GET[_SPIP_PAGE]; |
|
| 46 | 46 | |
| 47 | 47 | // Securite |
| 48 | 48 | if ( |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | // lancer les taches sur affichage final, comme le cron |
| 102 | 102 | // mais sans rien afficher |
| 103 | 103 | $GLOBALS['html'] = false; // ne rien afficher |
| 104 | - pipeline('affichage_final' . _PIPELINE_SUFFIX, ''); |
|
| 104 | + pipeline('affichage_final'._PIPELINE_SUFFIX, ''); |
|
| 105 | 105 | exit; // le hit est fini ! |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | // Content-Type ? |
| 119 | 119 | if (!isset($page['entetes']['Content-Type'])) { |
| 120 | 120 | $charset = $GLOBALS['meta']['charset'] ?? 'utf-8'; |
| 121 | - $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset; |
|
| 121 | + $page['entetes']['Content-Type'] = 'text/html; charset='.$charset; |
|
| 122 | 122 | $html = true; |
| 123 | 123 | } else { |
| 124 | 124 | $html = preg_match(',^\s*text/html,', (string) $page['entetes']['Content-Type']); |
@@ -144,11 +144,11 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | // traitements sur les entetes avant envoi |
| 146 | 146 | // peut servir pour le plugin de stats |
| 147 | - $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']); |
|
| 147 | + $page['entetes'] = pipeline('affichage_entetes_final'._PIPELINE_SUFFIX, $page['entetes']); |
|
| 148 | 148 | |
| 149 | 149 | |
| 150 | 150 | // eval $page et affecte $res |
| 151 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 151 | + include _ROOT_RESTREINT.'public/evaluer_page.php'; |
|
| 152 | 152 | envoyer_entetes($page['entetes']); |
| 153 | 153 | if ($res === false) { |
| 154 | 154 | include_spip('inc/autoriser'); |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | // |
| 168 | 168 | // (c'est ici qu'on fait var_recherche, validation, boutons d'admin, |
| 169 | 169 | // cf. public/assembler.php) |
| 170 | - echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']); |
|
| 170 | + echo pipeline('affichage_final'._PIPELINE_SUFFIX, $page['texte']); |
|
| 171 | 171 | |
| 172 | 172 | if ($lang) { |
| 173 | 173 | lang_select(); |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | if ($html && ($affiche_boutons_admin || $debug)) { |
| 184 | 184 | $var_mode_affiche = _request('var_mode_affiche'); |
| 185 | 185 | $var_mode_objet = _request('var_mode_objet'); |
| 186 | - $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 186 | + $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet.'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : ''); |
|
| 187 | 187 | echo erreur_squelette(false); |
| 188 | 188 | } |
| 189 | 189 | } else { |
@@ -311,7 +311,7 @@ |
||
| 311 | 311 | foreach ($erreurs as $k => $v) { |
| 312 | 312 | if (is_string($v) && strlen(trim($v)) && !str_starts_with((string) $k, '_')) { |
| 313 | 313 | // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form |
| 314 | - $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>'; |
|
| 314 | + $valeurs['erreurs'][$k] = "<span role='alert'>".$erreurs[$k].'</span>'; |
|
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Formulaires |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('inc/filtres'); |
@@ -34,26 +34,26 @@ discard block |
||
| 34 | 34 | * @see spip_htmlspecialchars() |
| 35 | 35 | */ |
| 36 | 36 | function protege_champ(mixed $valeur, $max_prof = 128) { |
| 37 | - if (is_array($valeur)) { |
|
| 38 | - if ($max_prof > 0) { |
|
| 39 | - return array_map( |
|
| 40 | - fn($v) => protege_champ($v, $max_prof - 1), |
|
| 41 | - $valeur |
|
| 42 | - ); |
|
| 43 | - } |
|
| 44 | - // si on dépasse la prof max on tronque |
|
| 45 | - return []; |
|
| 46 | - } elseif ($valeur === null) { |
|
| 47 | - return $valeur; |
|
| 48 | - } elseif (is_bool($valeur)) { |
|
| 49 | - return $valeur ? '1' : ''; |
|
| 50 | - } elseif (is_string($valeur) && $valeur) { |
|
| 51 | - if (strpbrk($valeur, "&\"'<>") !== false) { |
|
| 52 | - return spip_htmlspecialchars($valeur, ENT_QUOTES); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - return $valeur; |
|
| 37 | + if (is_array($valeur)) { |
|
| 38 | + if ($max_prof > 0) { |
|
| 39 | + return array_map( |
|
| 40 | + fn($v) => protege_champ($v, $max_prof - 1), |
|
| 41 | + $valeur |
|
| 42 | + ); |
|
| 43 | + } |
|
| 44 | + // si on dépasse la prof max on tronque |
|
| 45 | + return []; |
|
| 46 | + } elseif ($valeur === null) { |
|
| 47 | + return $valeur; |
|
| 48 | + } elseif (is_bool($valeur)) { |
|
| 49 | + return $valeur ? '1' : ''; |
|
| 50 | + } elseif (is_string($valeur) && $valeur) { |
|
| 51 | + if (strpbrk($valeur, "&\"'<>") !== false) { |
|
| 52 | + return spip_htmlspecialchars($valeur, ENT_QUOTES); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return $valeur; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | * - false : pas de squelette trouvé |
| 68 | 68 | **/ |
| 69 | 69 | function existe_formulaire($form) { |
| 70 | - $form = str_starts_with($form, 'FORMULAIRE_') ? strtolower(substr($form, 11)) : strtolower($form); |
|
| 70 | + $form = str_starts_with($form, 'FORMULAIRE_') ? strtolower(substr($form, 11)) : strtolower($form); |
|
| 71 | 71 | |
| 72 | - if (!$form) { |
|
| 73 | - return ''; |
|
| 74 | - } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 72 | + if (!$form) { |
|
| 73 | + return ''; |
|
| 74 | + } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 75 | 75 | |
| 76 | - return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 76 | + return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -82,30 +82,30 @@ discard block |
||
| 82 | 82 | * @return false|array |
| 83 | 83 | */ |
| 84 | 84 | function test_formulaire_inclus_par_modele() { |
| 85 | - $trace = debug_backtrace(0, 20); |
|
| 86 | - $trace_fonctions = array_column($trace, 'function'); |
|
| 87 | - $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 88 | - |
|
| 89 | - // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 90 | - if ( |
|
| 91 | - function_exists('arguments_balise_dyn_depuis_modele') |
|
| 92 | - && ($form = arguments_balise_dyn_depuis_modele(null, 'read')) |
|
| 93 | - && in_array('balise_formulaire__dyn', $trace_fonctions) |
|
| 94 | - ) { |
|
| 95 | - $k = array_search('balise_formulaire__dyn', $trace_fonctions); |
|
| 96 | - if ($trace[$k]['args'][0] === $form) { |
|
| 97 | - return $trace[$k]['args']; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 102 | - // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 103 | - if (in_array('eval', $trace_fonctions) && in_array('inclure_modele', $trace_fonctions)) { |
|
| 104 | - $k = array_search('inclure_modele', $trace_fonctions); |
|
| 105 | - // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 106 | - return $trace[$k - 1]['args'][1]['args']; |
|
| 107 | - } |
|
| 108 | - return false; |
|
| 85 | + $trace = debug_backtrace(0, 20); |
|
| 86 | + $trace_fonctions = array_column($trace, 'function'); |
|
| 87 | + $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 88 | + |
|
| 89 | + // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 90 | + if ( |
|
| 91 | + function_exists('arguments_balise_dyn_depuis_modele') |
|
| 92 | + && ($form = arguments_balise_dyn_depuis_modele(null, 'read')) |
|
| 93 | + && in_array('balise_formulaire__dyn', $trace_fonctions) |
|
| 94 | + ) { |
|
| 95 | + $k = array_search('balise_formulaire__dyn', $trace_fonctions); |
|
| 96 | + if ($trace[$k]['args'][0] === $form) { |
|
| 97 | + return $trace[$k]['args']; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 102 | + // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 103 | + if (in_array('eval', $trace_fonctions) && in_array('inclure_modele', $trace_fonctions)) { |
|
| 104 | + $k = array_search('inclure_modele', $trace_fonctions); |
|
| 105 | + // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 106 | + return $trace[$k - 1]['args'][1]['args']; |
|
| 107 | + } |
|
| 108 | + return false; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -120,19 +120,19 @@ discard block |
||
| 120 | 120 | **/ |
| 121 | 121 | function balise_FORMULAIRE__dist($p) { |
| 122 | 122 | |
| 123 | - // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 124 | - // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 125 | - if (existe_formulaire($p->nom_champ) === false) { |
|
| 126 | - $p->code = "''"; |
|
| 127 | - $p->interdire_scripts = false; |
|
| 123 | + // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 124 | + // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 125 | + if (existe_formulaire($p->nom_champ) === false) { |
|
| 126 | + $p->code = "''"; |
|
| 127 | + $p->interdire_scripts = false; |
|
| 128 | 128 | |
| 129 | - return $p; |
|
| 130 | - } |
|
| 129 | + return $p; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - // sinon renvoyer un code php dynamique |
|
| 133 | - $p = calculer_balise_dynamique($p, $p->nom_champ, []); |
|
| 132 | + // sinon renvoyer un code php dynamique |
|
| 133 | + $p = calculer_balise_dynamique($p, $p->nom_champ, []); |
|
| 134 | 134 | |
| 135 | - return $p; |
|
| 135 | + return $p; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -152,17 +152,17 @@ discard block |
||
| 152 | 152 | * - string : texte à afficher directement |
| 153 | 153 | */ |
| 154 | 154 | function balise_FORMULAIRE__dyn($form, ...$args) { |
| 155 | - $form = existe_formulaire($form); |
|
| 156 | - if (!$form) { |
|
| 157 | - return ''; |
|
| 158 | - } |
|
| 155 | + $form = existe_formulaire($form); |
|
| 156 | + if (!$form) { |
|
| 157 | + return ''; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 161 | - if (!is_array($contexte)) { |
|
| 162 | - return $contexte; |
|
| 163 | - } |
|
| 160 | + $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 161 | + if (!is_array($contexte)) { |
|
| 162 | + return $contexte; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - return ["formulaires/$form", 3600, $contexte]; |
|
| 165 | + return ["formulaires/$form", 3600, $contexte]; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -177,134 +177,134 @@ discard block |
||
| 177 | 177 | * string: Formulaire non applicable (message d’explication) |
| 178 | 178 | **/ |
| 179 | 179 | function balise_FORMULAIRE__contexte($form, $args) { |
| 180 | - // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 181 | - // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 182 | - // si poste, on recupere les erreurs |
|
| 183 | - |
|
| 184 | - $je_suis_poste = false; |
|
| 185 | - if ( |
|
| 186 | - ($post_form = _request('formulaire_action')) |
|
| 187 | - && $post_form == $form |
|
| 188 | - && ($p = _request('formulaire_action_args')) |
|
| 189 | - && is_array($p = decoder_contexte_ajax($p, $post_form)) |
|
| 190 | - ) { |
|
| 191 | - // enlever le faux attribut de langue masque |
|
| 192 | - array_shift($p); |
|
| 193 | - if (formulaire__identifier($form, $args, $p)) { |
|
| 194 | - $je_suis_poste = true; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - $editable = true; |
|
| 199 | - $erreurs = $post = []; |
|
| 200 | - if ($je_suis_poste) { |
|
| 201 | - $post = traiter_formulaires_dynamiques(true); |
|
| 202 | - $e = "erreurs_$form"; |
|
| 203 | - $erreurs = $post[$e] ?? []; |
|
| 204 | - $editable = "editable_$form"; |
|
| 205 | - $editable = (!isset($post[$e])) |
|
| 206 | - || (is_countable($erreurs) ? count($erreurs) : 0) |
|
| 207 | - || (isset($post[$editable]) && $post[$editable]); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 211 | - |
|
| 212 | - // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 213 | - // C'est plus fort qu'editable qui est gere par le squelette |
|
| 214 | - // Idealement $valeur doit etre alors un message explicatif. |
|
| 215 | - if (!is_array($valeurs)) { |
|
| 216 | - return is_string($valeurs) ? $valeurs : ''; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 220 | - // ou une action vide si elle ne sert pas |
|
| 221 | - $action = $valeurs['action'] ?? self('&', true); |
|
| 222 | - // bug IEx : si action finit par / |
|
| 223 | - // IE croit que le <form ... action=../ > est autoferme |
|
| 224 | - if (str_ends_with((string) $action, '/')) { |
|
| 225 | - // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 226 | - $action .= '#'; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // recuperer la saisie en cours si erreurs |
|
| 230 | - // seulement si c'est ce formulaire qui est poste |
|
| 231 | - // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 232 | - $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 233 | - foreach (array_keys($valeurs) as $champ) { |
|
| 234 | - $champ = (string) $champ; |
|
| 235 | - if ($champ[0] !== '_' && !in_array($champ, ['message_ok', 'message_erreur', 'editable'])) { |
|
| 236 | - if ($dispo && ($v = _request($champ)) !== null) { |
|
| 237 | - $valeurs[$champ] = $v; |
|
| 238 | - } |
|
| 239 | - // nettoyer l'url des champs qui vont etre saisis |
|
| 240 | - if ($action) { |
|
| 241 | - $action = parametre_url($action, $champ, ''); |
|
| 242 | - } |
|
| 243 | - // proteger les ' et les " dans les champs que l'on va injecter |
|
| 244 | - $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - if ($action) { |
|
| 249 | - // nettoyer l'url |
|
| 250 | - $action = parametre_url($action, 'formulaire_action', ''); |
|
| 251 | - $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 252 | - $action = parametre_url($action, 'formulaire_action_sign', ''); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - // empiler la lang en tant que premier argument implicite du CVT |
|
| 256 | - // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 257 | - array_unshift($args, $GLOBALS['spip_lang']); |
|
| 258 | - |
|
| 259 | - $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 260 | - $valeurs['erreurs'] = $erreurs; |
|
| 261 | - $valeurs['action'] = $action; |
|
| 262 | - $valeurs['form'] = $form; |
|
| 263 | - |
|
| 264 | - $valeurs['formulaire_sign'] = ''; |
|
| 265 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 266 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 267 | - $secu = $securiser_action($valeurs['form'], $valeurs['formulaire_args'], '', -1); |
|
| 268 | - $valeurs['formulaire_sign'] = $secu['hash']; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - if (!isset($valeurs['id'])) { |
|
| 272 | - $valeurs['id'] = 'new'; |
|
| 273 | - } |
|
| 274 | - // editable peut venir de charger() ou de traiter() sinon |
|
| 275 | - if (!isset($valeurs['editable'])) { |
|
| 276 | - $valeurs['editable'] = $editable; |
|
| 277 | - } |
|
| 278 | - // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 279 | - $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 280 | - |
|
| 281 | - if ($je_suis_poste) { |
|
| 282 | - $valeurs['message_erreur'] = ''; |
|
| 283 | - if (isset($erreurs['message_erreur'])) { |
|
| 284 | - $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - $valeurs['message_ok'] = ''; |
|
| 288 | - if (isset($post["message_ok_$form"])) { |
|
| 289 | - $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 290 | - } elseif (isset($erreurs['message_ok'])) { |
|
| 291 | - $valeurs['message_ok'] = $erreurs['message_ok']; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - // accessibilite : encapsuler toutes les erreurs dans un role='alert' |
|
| 295 | - // uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux) |
|
| 296 | - // et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ) |
|
| 297 | - if (html5_permis()) { |
|
| 298 | - foreach ($erreurs as $k => $v) { |
|
| 299 | - if (is_string($v) && strlen(trim($v)) && !str_starts_with((string) $k, '_')) { |
|
| 300 | - // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form |
|
| 301 | - $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>'; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - return $valeurs; |
|
| 180 | + // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 181 | + // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 182 | + // si poste, on recupere les erreurs |
|
| 183 | + |
|
| 184 | + $je_suis_poste = false; |
|
| 185 | + if ( |
|
| 186 | + ($post_form = _request('formulaire_action')) |
|
| 187 | + && $post_form == $form |
|
| 188 | + && ($p = _request('formulaire_action_args')) |
|
| 189 | + && is_array($p = decoder_contexte_ajax($p, $post_form)) |
|
| 190 | + ) { |
|
| 191 | + // enlever le faux attribut de langue masque |
|
| 192 | + array_shift($p); |
|
| 193 | + if (formulaire__identifier($form, $args, $p)) { |
|
| 194 | + $je_suis_poste = true; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + $editable = true; |
|
| 199 | + $erreurs = $post = []; |
|
| 200 | + if ($je_suis_poste) { |
|
| 201 | + $post = traiter_formulaires_dynamiques(true); |
|
| 202 | + $e = "erreurs_$form"; |
|
| 203 | + $erreurs = $post[$e] ?? []; |
|
| 204 | + $editable = "editable_$form"; |
|
| 205 | + $editable = (!isset($post[$e])) |
|
| 206 | + || (is_countable($erreurs) ? count($erreurs) : 0) |
|
| 207 | + || (isset($post[$editable]) && $post[$editable]); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 211 | + |
|
| 212 | + // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 213 | + // C'est plus fort qu'editable qui est gere par le squelette |
|
| 214 | + // Idealement $valeur doit etre alors un message explicatif. |
|
| 215 | + if (!is_array($valeurs)) { |
|
| 216 | + return is_string($valeurs) ? $valeurs : ''; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 220 | + // ou une action vide si elle ne sert pas |
|
| 221 | + $action = $valeurs['action'] ?? self('&', true); |
|
| 222 | + // bug IEx : si action finit par / |
|
| 223 | + // IE croit que le <form ... action=../ > est autoferme |
|
| 224 | + if (str_ends_with((string) $action, '/')) { |
|
| 225 | + // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 226 | + $action .= '#'; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // recuperer la saisie en cours si erreurs |
|
| 230 | + // seulement si c'est ce formulaire qui est poste |
|
| 231 | + // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 232 | + $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 233 | + foreach (array_keys($valeurs) as $champ) { |
|
| 234 | + $champ = (string) $champ; |
|
| 235 | + if ($champ[0] !== '_' && !in_array($champ, ['message_ok', 'message_erreur', 'editable'])) { |
|
| 236 | + if ($dispo && ($v = _request($champ)) !== null) { |
|
| 237 | + $valeurs[$champ] = $v; |
|
| 238 | + } |
|
| 239 | + // nettoyer l'url des champs qui vont etre saisis |
|
| 240 | + if ($action) { |
|
| 241 | + $action = parametre_url($action, $champ, ''); |
|
| 242 | + } |
|
| 243 | + // proteger les ' et les " dans les champs que l'on va injecter |
|
| 244 | + $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + if ($action) { |
|
| 249 | + // nettoyer l'url |
|
| 250 | + $action = parametre_url($action, 'formulaire_action', ''); |
|
| 251 | + $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 252 | + $action = parametre_url($action, 'formulaire_action_sign', ''); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + // empiler la lang en tant que premier argument implicite du CVT |
|
| 256 | + // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 257 | + array_unshift($args, $GLOBALS['spip_lang']); |
|
| 258 | + |
|
| 259 | + $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 260 | + $valeurs['erreurs'] = $erreurs; |
|
| 261 | + $valeurs['action'] = $action; |
|
| 262 | + $valeurs['form'] = $form; |
|
| 263 | + |
|
| 264 | + $valeurs['formulaire_sign'] = ''; |
|
| 265 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 266 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 267 | + $secu = $securiser_action($valeurs['form'], $valeurs['formulaire_args'], '', -1); |
|
| 268 | + $valeurs['formulaire_sign'] = $secu['hash']; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + if (!isset($valeurs['id'])) { |
|
| 272 | + $valeurs['id'] = 'new'; |
|
| 273 | + } |
|
| 274 | + // editable peut venir de charger() ou de traiter() sinon |
|
| 275 | + if (!isset($valeurs['editable'])) { |
|
| 276 | + $valeurs['editable'] = $editable; |
|
| 277 | + } |
|
| 278 | + // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 279 | + $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 280 | + |
|
| 281 | + if ($je_suis_poste) { |
|
| 282 | + $valeurs['message_erreur'] = ''; |
|
| 283 | + if (isset($erreurs['message_erreur'])) { |
|
| 284 | + $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + $valeurs['message_ok'] = ''; |
|
| 288 | + if (isset($post["message_ok_$form"])) { |
|
| 289 | + $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 290 | + } elseif (isset($erreurs['message_ok'])) { |
|
| 291 | + $valeurs['message_ok'] = $erreurs['message_ok']; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + // accessibilite : encapsuler toutes les erreurs dans un role='alert' |
|
| 295 | + // uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux) |
|
| 296 | + // et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ) |
|
| 297 | + if (html5_permis()) { |
|
| 298 | + foreach ($erreurs as $k => $v) { |
|
| 299 | + if (is_string($v) && strlen(trim($v)) && !str_starts_with((string) $k, '_')) { |
|
| 300 | + // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form |
|
| 301 | + $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>'; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + return $valeurs; |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
@@ -316,51 +316,51 @@ discard block |
||
| 316 | 316 | * @return array |
| 317 | 317 | */ |
| 318 | 318 | function formulaire__charger($form, $args, $poste) { |
| 319 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form", true)) { |
|
| 320 | - $valeurs = $charger_valeurs(...$args); |
|
| 321 | - } else { |
|
| 322 | - $valeurs = []; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - $valeurs = pipeline( |
|
| 326 | - 'formulaire_charger', |
|
| 327 | - [ |
|
| 328 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 329 | - 'data' => $valeurs |
|
| 330 | - ] |
|
| 331 | - ); |
|
| 332 | - |
|
| 333 | - // prise en charge CVT multi etape |
|
| 334 | - if (is_array($valeurs) && isset($valeurs['_etapes'])) { |
|
| 335 | - include_spip('inc/cvt_multietapes'); |
|
| 336 | - $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 337 | - ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 338 | - $valeurs |
|
| 339 | - ); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 343 | - if (is_array($valeurs)) { |
|
| 344 | - if (!isset($valeurs['_pipelines'])) { |
|
| 345 | - $valeurs['_pipelines'] = []; |
|
| 346 | - } |
|
| 347 | - // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 348 | - // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 349 | - if (isset($valeurs['_pipeline'])) { |
|
| 350 | - $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 351 | - $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : []; |
|
| 352 | - |
|
| 353 | - $pipelines = [$pipe => $args]; |
|
| 354 | - $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 358 | - // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 359 | - // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 360 | - $valeurs['_pipelines']['formulaire_fond'] = ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste]; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - return $valeurs; |
|
| 319 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form", true)) { |
|
| 320 | + $valeurs = $charger_valeurs(...$args); |
|
| 321 | + } else { |
|
| 322 | + $valeurs = []; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + $valeurs = pipeline( |
|
| 326 | + 'formulaire_charger', |
|
| 327 | + [ |
|
| 328 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 329 | + 'data' => $valeurs |
|
| 330 | + ] |
|
| 331 | + ); |
|
| 332 | + |
|
| 333 | + // prise en charge CVT multi etape |
|
| 334 | + if (is_array($valeurs) && isset($valeurs['_etapes'])) { |
|
| 335 | + include_spip('inc/cvt_multietapes'); |
|
| 336 | + $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 337 | + ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 338 | + $valeurs |
|
| 339 | + ); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 343 | + if (is_array($valeurs)) { |
|
| 344 | + if (!isset($valeurs['_pipelines'])) { |
|
| 345 | + $valeurs['_pipelines'] = []; |
|
| 346 | + } |
|
| 347 | + // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 348 | + // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 349 | + if (isset($valeurs['_pipeline'])) { |
|
| 350 | + $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 351 | + $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : []; |
|
| 352 | + |
|
| 353 | + $pipelines = [$pipe => $args]; |
|
| 354 | + $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 358 | + // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 359 | + // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 360 | + $valeurs['_pipelines']['formulaire_fond'] = ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste]; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + return $valeurs; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | /** |
@@ -379,9 +379,9 @@ discard block |
||
| 379 | 379 | * @return bool |
| 380 | 380 | */ |
| 381 | 381 | function formulaire__identifier($form, $args, $p) { |
| 382 | - if ($identifier_args = charger_fonction('identifier', "formulaires/$form", true)) { |
|
| 383 | - return $identifier_args(...$args) === $identifier_args(...$p); |
|
| 384 | - } |
|
| 382 | + if ($identifier_args = charger_fonction('identifier', "formulaires/$form", true)) { |
|
| 383 | + return $identifier_args(...$args) === $identifier_args(...$p); |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | - return $args === $p; |
|
| 386 | + return $args === $p; |
|
| 387 | 387 | } |
@@ -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 | /** |
@@ -39,29 +39,29 @@ discard block |
||
| 39 | 39 | * Pile complétée par le code à générer |
| 40 | 40 | */ |
| 41 | 41 | function balise_INFO__dist($p) { |
| 42 | - $info = $p->nom_champ; |
|
| 43 | - $type_objet = interprete_argument_balise(1, $p); |
|
| 44 | - $id_objet = interprete_argument_balise(2, $p); |
|
| 45 | - if ($info === 'INFO_' || !$type_objet || !$id_objet) { |
|
| 46 | - $msg = _T('zbug_balise_sans_argument', ['balise' => ' INFO_']); |
|
| 47 | - erreur_squelette($msg, $p); |
|
| 48 | - $p->interdire_scripts = true; |
|
| 42 | + $info = $p->nom_champ; |
|
| 43 | + $type_objet = interprete_argument_balise(1, $p); |
|
| 44 | + $id_objet = interprete_argument_balise(2, $p); |
|
| 45 | + if ($info === 'INFO_' || !$type_objet || !$id_objet) { |
|
| 46 | + $msg = _T('zbug_balise_sans_argument', ['balise' => ' INFO_']); |
|
| 47 | + erreur_squelette($msg, $p); |
|
| 48 | + $p->interdire_scripts = true; |
|
| 49 | 49 | |
| 50 | - return $p; |
|
| 51 | - } else { |
|
| 52 | - // Récupérer tous les params à la suite de objet et id_objet |
|
| 53 | - $_params = '['; |
|
| 54 | - $nb_params = is_countable($p->param[0]) ? count($p->param[0]) : 0; // 1ère valeur vide donc 1 en plus |
|
| 55 | - for ($i = 3; $i < $nb_params; $i++) { |
|
| 56 | - $_params .= interprete_argument_balise($i, $p) . ','; |
|
| 57 | - } |
|
| 58 | - $_params .= ']'; |
|
| 50 | + return $p; |
|
| 51 | + } else { |
|
| 52 | + // Récupérer tous les params à la suite de objet et id_objet |
|
| 53 | + $_params = '['; |
|
| 54 | + $nb_params = is_countable($p->param[0]) ? count($p->param[0]) : 0; // 1ère valeur vide donc 1 en plus |
|
| 55 | + for ($i = 3; $i < $nb_params; $i++) { |
|
| 56 | + $_params .= interprete_argument_balise($i, $p) . ','; |
|
| 57 | + } |
|
| 58 | + $_params .= ']'; |
|
| 59 | 59 | |
| 60 | - $info_sql = strtolower(substr((string) $info, 5)); |
|
| 61 | - $code = "generer_objet_info($id_objet, $type_objet, '$info_sql', " . ($p->etoile ? _q($p->etoile) : "''") . ", $_params)"; |
|
| 62 | - $p->code = champ_sql($info, $p, $code); |
|
| 63 | - $p->interdire_scripts = true; |
|
| 60 | + $info_sql = strtolower(substr((string) $info, 5)); |
|
| 61 | + $code = "generer_objet_info($id_objet, $type_objet, '$info_sql', " . ($p->etoile ? _q($p->etoile) : "''") . ", $_params)"; |
|
| 62 | + $p->code = champ_sql($info, $p, $code); |
|
| 63 | + $p->interdire_scripts = true; |
|
| 64 | 64 | |
| 65 | - return $p; |
|
| 66 | - } |
|
| 65 | + return $p; |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -53,12 +53,12 @@ |
||
| 53 | 53 | $_params = '['; |
| 54 | 54 | $nb_params = is_countable($p->param[0]) ? count($p->param[0]) : 0; // 1ère valeur vide donc 1 en plus |
| 55 | 55 | for ($i = 3; $i < $nb_params; $i++) { |
| 56 | - $_params .= interprete_argument_balise($i, $p) . ','; |
|
| 56 | + $_params .= interprete_argument_balise($i, $p).','; |
|
| 57 | 57 | } |
| 58 | 58 | $_params .= ']'; |
| 59 | 59 | |
| 60 | 60 | $info_sql = strtolower(substr((string) $info, 5)); |
| 61 | - $code = "generer_objet_info($id_objet, $type_objet, '$info_sql', " . ($p->etoile ? _q($p->etoile) : "''") . ", $_params)"; |
|
| 61 | + $code = "generer_objet_info($id_objet, $type_objet, '$info_sql', ".($p->etoile ? _q($p->etoile) : "''").", $_params)"; |
|
| 62 | 62 | $p->code = champ_sql($info, $p, $code); |
| 63 | 63 | $p->interdire_scripts = true; |
| 64 | 64 | |
@@ -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 | /** |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * Pile complétée du code compilé |
| 36 | 36 | **/ |
| 37 | 37 | function balise_URL_LOGOUT($p) { |
| 38 | - return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 38 | + return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | * Liste (url) des arguments collectés. |
| 52 | 52 | */ |
| 53 | 53 | function balise_URL_LOGOUT_stat($args, $context_compil) { |
| 54 | - $url = $args[0] ?? ''; |
|
| 54 | + $url = $args[0] ?? ''; |
|
| 55 | 55 | |
| 56 | - return [$url]; |
|
| 56 | + return [$url]; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | **/ |
| 69 | 69 | function balise_URL_LOGOUT_dyn($cible) { |
| 70 | 70 | |
| 71 | - if (empty($GLOBALS['visiteur_session']['login']) && empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 72 | - return ''; |
|
| 73 | - } |
|
| 71 | + if (empty($GLOBALS['visiteur_session']['login']) && empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 72 | + return ''; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - return generer_url_action('logout', 'logout=public&url=' . rawurlencode((string) ($cible ?: self('&')))); |
|
| 75 | + return generer_url_action('logout', 'logout=public&url=' . rawurlencode((string) ($cible ?: self('&')))); |
|
| 76 | 76 | } |
@@ -72,5 +72,5 @@ |
||
| 72 | 72 | return ''; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - return generer_url_action('logout', 'logout=public&url=' . rawurlencode((string) ($cible ?: self('&')))); |
|
| 75 | + return generer_url_action('logout', 'logout=public&url='.rawurlencode((string) ($cible ?: self('&')))); |
|
| 76 | 76 | } |
@@ -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 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * Pile complétée du code compilé |
| 37 | 37 | **/ |
| 38 | 38 | function balise_MENU_LANG($p) { |
| 39 | - return calculer_balise_dynamique($p, 'MENU_LANG', ['lang']); |
|
| 39 | + return calculer_balise_dynamique($p, 'MENU_LANG', ['lang']); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | * string: (vide) si pas de multilinguisme |
| 56 | 56 | */ |
| 57 | 57 | function balise_MENU_LANG_stat($args, $context_compil) { |
| 58 | - if (!str_contains((string) $GLOBALS['meta']['langues_multilingue'], ',')) { |
|
| 59 | - return ''; |
|
| 60 | - } |
|
| 58 | + if (!str_contains((string) $GLOBALS['meta']['langues_multilingue'], ',')) { |
|
| 59 | + return ''; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return $args; |
|
| 62 | + return $args; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * Liste : Chemin du squelette, durée du cache, contexte |
| 76 | 76 | **/ |
| 77 | 77 | function balise_MENU_LANG_dyn($opt) { |
| 78 | - include_spip('balise/menu_lang_ecrire'); |
|
| 78 | + include_spip('balise/menu_lang_ecrire'); |
|
| 79 | 79 | |
| 80 | - return menu_lang_pour_tous('var_lang', $opt); |
|
| 80 | + return menu_lang_pour_tous('var_lang', $opt); |
|
| 81 | 81 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | if ($fichier) { |
| 110 | 110 | $code = "quete_logo_file($doc, $qconnect)"; |
| 111 | 111 | } else { |
| 112 | - $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 112 | + $code = "quete_logo_document($doc, ".($lien ?: "''").", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 113 | 113 | } |
| 114 | 114 | // (x=non-faux ? y : '') pour affecter x en retournant y |
| 115 | 115 | if ($p->descr['documents']) { |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
| 134 | 134 | if ($coord_x || $coord_y) { |
| 135 | - $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 135 | + $code = "filtrer('image_graver',filtrer('image_reduire',".$code.", '$coord_x', '$coord_y'))"; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | $p->code = $code; |
@@ -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 | |
@@ -55,88 +55,88 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function balise_LOGO__dist($p) { |
| 57 | 57 | |
| 58 | - preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 59 | - $type = strtolower($regs[1]); |
|
| 60 | - $suite_logo = $regs[2]; |
|
| 61 | - |
|
| 62 | - // cas de #LOGO_SITE_SPIP |
|
| 63 | - if ($type == 'site_spip') { |
|
| 64 | - $type = 'site'; |
|
| 65 | - $_id_objet = "\"'0'\""; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $id_objet = id_table_objet($type); |
|
| 69 | - if (!isset($_id_objet)) { |
|
| 70 | - $_id_objet = champ_sql($id_objet, $p); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $fichier = ($p->etoile === '**') ? -1 : 0; |
|
| 74 | - $coord = []; |
|
| 75 | - $align = $lien = ''; |
|
| 76 | - $mode_logo = ''; |
|
| 77 | - |
|
| 78 | - if ($p->param && !$p->param[0][0]) { |
|
| 79 | - $params = $p->param[0]; |
|
| 80 | - array_shift($params); |
|
| 81 | - foreach ($params as $a) { |
|
| 82 | - if ($a[0]->type === 'texte') { |
|
| 83 | - $n = $a[0]->texte; |
|
| 84 | - if (is_numeric($n)) { |
|
| 85 | - $coord[] = $n; |
|
| 86 | - } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) { |
|
| 87 | - $align = $n; |
|
| 88 | - } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) { |
|
| 89 | - $mode_logo = $n; |
|
| 90 | - } |
|
| 91 | - } else { |
|
| 92 | - $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $coord_x = $coord ? (int) array_shift($coord) : 0; |
|
| 98 | - $coord_y = $coord ? (int) array_shift($coord) : 0; |
|
| 99 | - |
|
| 100 | - if ($p->etoile === '*') { |
|
| 101 | - include_spip('balise/url_'); |
|
| 102 | - $lien = generer_generer_url_arg($type, $p, $_id_objet); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 106 | - if ($type == 'document') { |
|
| 107 | - $qconnect = _q($connect); |
|
| 108 | - $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 109 | - if ($fichier) { |
|
| 110 | - $code = "quete_logo_file($doc, $qconnect)"; |
|
| 111 | - } else { |
|
| 112 | - $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 113 | - } |
|
| 114 | - // (x=non-faux ? y : '') pour affecter x en retournant y |
|
| 115 | - if ($p->descr['documents']) { |
|
| 116 | - $code = '(($doublons["documents"] .= ",". ' |
|
| 117 | - . $_id_objet |
|
| 118 | - . ") ? $code : '')"; |
|
| 119 | - } |
|
| 120 | - } elseif ($connect) { |
|
| 121 | - $code = "''"; |
|
| 122 | - spip_logger()->info('Les logos distants ne sont pas prevus'); |
|
| 123 | - } else { |
|
| 124 | - // pour generer_code_logo |
|
| 125 | - include_spip('balise/id_logo_'); |
|
| 126 | - $champ_logo = ''; |
|
| 127 | - if ($fichier) { |
|
| 128 | - $champ_logo = 'fichier'; |
|
| 129 | - } |
|
| 130 | - $code = generer_code_logo($id_objet, $_id_objet, $type, $align, $lien, $p, $suite_logo, $champ_logo); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
|
| 134 | - if ($coord_x || $coord_y) { |
|
| 135 | - $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $p->code = $code; |
|
| 139 | - $p->interdire_scripts = false; |
|
| 140 | - |
|
| 141 | - return $p; |
|
| 58 | + preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 59 | + $type = strtolower($regs[1]); |
|
| 60 | + $suite_logo = $regs[2]; |
|
| 61 | + |
|
| 62 | + // cas de #LOGO_SITE_SPIP |
|
| 63 | + if ($type == 'site_spip') { |
|
| 64 | + $type = 'site'; |
|
| 65 | + $_id_objet = "\"'0'\""; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $id_objet = id_table_objet($type); |
|
| 69 | + if (!isset($_id_objet)) { |
|
| 70 | + $_id_objet = champ_sql($id_objet, $p); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $fichier = ($p->etoile === '**') ? -1 : 0; |
|
| 74 | + $coord = []; |
|
| 75 | + $align = $lien = ''; |
|
| 76 | + $mode_logo = ''; |
|
| 77 | + |
|
| 78 | + if ($p->param && !$p->param[0][0]) { |
|
| 79 | + $params = $p->param[0]; |
|
| 80 | + array_shift($params); |
|
| 81 | + foreach ($params as $a) { |
|
| 82 | + if ($a[0]->type === 'texte') { |
|
| 83 | + $n = $a[0]->texte; |
|
| 84 | + if (is_numeric($n)) { |
|
| 85 | + $coord[] = $n; |
|
| 86 | + } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) { |
|
| 87 | + $align = $n; |
|
| 88 | + } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) { |
|
| 89 | + $mode_logo = $n; |
|
| 90 | + } |
|
| 91 | + } else { |
|
| 92 | + $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $coord_x = $coord ? (int) array_shift($coord) : 0; |
|
| 98 | + $coord_y = $coord ? (int) array_shift($coord) : 0; |
|
| 99 | + |
|
| 100 | + if ($p->etoile === '*') { |
|
| 101 | + include_spip('balise/url_'); |
|
| 102 | + $lien = generer_generer_url_arg($type, $p, $_id_objet); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 106 | + if ($type == 'document') { |
|
| 107 | + $qconnect = _q($connect); |
|
| 108 | + $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 109 | + if ($fichier) { |
|
| 110 | + $code = "quete_logo_file($doc, $qconnect)"; |
|
| 111 | + } else { |
|
| 112 | + $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 113 | + } |
|
| 114 | + // (x=non-faux ? y : '') pour affecter x en retournant y |
|
| 115 | + if ($p->descr['documents']) { |
|
| 116 | + $code = '(($doublons["documents"] .= ",". ' |
|
| 117 | + . $_id_objet |
|
| 118 | + . ") ? $code : '')"; |
|
| 119 | + } |
|
| 120 | + } elseif ($connect) { |
|
| 121 | + $code = "''"; |
|
| 122 | + spip_logger()->info('Les logos distants ne sont pas prevus'); |
|
| 123 | + } else { |
|
| 124 | + // pour generer_code_logo |
|
| 125 | + include_spip('balise/id_logo_'); |
|
| 126 | + $champ_logo = ''; |
|
| 127 | + if ($fichier) { |
|
| 128 | + $champ_logo = 'fichier'; |
|
| 129 | + } |
|
| 130 | + $code = generer_code_logo($id_objet, $_id_objet, $type, $align, $lien, $p, $suite_logo, $champ_logo); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
|
| 134 | + if ($coord_x || $coord_y) { |
|
| 135 | + $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $p->code = $code; |
|
| 139 | + $p->interdire_scripts = false; |
|
| 140 | + |
|
| 141 | + return $p; |
|
| 142 | 142 | } |
@@ -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 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * Pile complétée du code compilé |
| 37 | 37 | **/ |
| 38 | 38 | function balise_MENU_LANG_ECRIRE($p) { |
| 39 | - return calculer_balise_dynamique($p, 'MENU_LANG_ECRIRE', ['lang']); |
|
| 39 | + return calculer_balise_dynamique($p, 'MENU_LANG_ECRIRE', ['lang']); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -55,12 +55,12 @@ discard block |
||
| 55 | 55 | * - string: Si pas de multilinguisme |
| 56 | 56 | */ |
| 57 | 57 | function balise_MENU_LANG_ECRIRE_stat($args, $context_compil) { |
| 58 | - include_spip('inc/lang'); |
|
| 59 | - if (!str_contains((string) $GLOBALS['meta']['langues_proposees'], ',')) { |
|
| 60 | - return ''; |
|
| 61 | - } |
|
| 58 | + include_spip('inc/lang'); |
|
| 59 | + if (!str_contains((string) $GLOBALS['meta']['langues_proposees'], ',')) { |
|
| 60 | + return ''; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return $args; |
|
| 63 | + return $args; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * Liste : Chemin du squelette, durée du cache, contexte |
| 77 | 77 | **/ |
| 78 | 78 | function balise_MENU_LANG_ECRIRE_dyn($opt) { |
| 79 | - return menu_lang_pour_tous('var_lang_ecrire', $opt); |
|
| 79 | + return menu_lang_pour_tous('var_lang_ecrire', $opt); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -96,30 +96,30 @@ discard block |
||
| 96 | 96 | * Liste : Chemin du squelette, durée du cache, contexte |
| 97 | 97 | **/ |
| 98 | 98 | function menu_lang_pour_tous($nom, $default) { |
| 99 | - include_spip('inc/lang'); |
|
| 99 | + include_spip('inc/lang'); |
|
| 100 | 100 | |
| 101 | - if ($GLOBALS['spip_lang'] != $default) { |
|
| 102 | - $opt = lang_select($default); # et remplace |
|
| 103 | - if ($GLOBALS['spip_lang'] != $default) { |
|
| 104 | - $default = ''; # annule tout choix par defaut |
|
| 105 | - if ($opt) { |
|
| 106 | - lang_select(); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 101 | + if ($GLOBALS['spip_lang'] != $default) { |
|
| 102 | + $opt = lang_select($default); # et remplace |
|
| 103 | + if ($GLOBALS['spip_lang'] != $default) { |
|
| 104 | + $default = ''; # annule tout choix par defaut |
|
| 105 | + if ($opt) { |
|
| 106 | + lang_select(); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - # lien a partir de / |
|
| 112 | - $cible = parametre_url(self(), 'lang', '', '&'); |
|
| 113 | - $post = generer_url_action('converser', 'redirect=' . rawurlencode((string) $cible), true); |
|
| 111 | + # lien a partir de / |
|
| 112 | + $cible = parametre_url(self(), 'lang', '', '&'); |
|
| 113 | + $post = generer_url_action('converser', 'redirect=' . rawurlencode((string) $cible), true); |
|
| 114 | 114 | |
| 115 | - return [ |
|
| 116 | - 'formulaires/menu_lang', |
|
| 117 | - 3600, |
|
| 118 | - [ |
|
| 119 | - 'nom' => $nom, |
|
| 120 | - 'url' => $post, |
|
| 121 | - 'name' => $nom, |
|
| 122 | - 'default' => $default, |
|
| 123 | - ] |
|
| 124 | - ]; |
|
| 115 | + return [ |
|
| 116 | + 'formulaires/menu_lang', |
|
| 117 | + 3600, |
|
| 118 | + [ |
|
| 119 | + 'nom' => $nom, |
|
| 120 | + 'url' => $post, |
|
| 121 | + 'name' => $nom, |
|
| 122 | + 'default' => $default, |
|
| 123 | + ] |
|
| 124 | + ]; |
|
| 125 | 125 | } |
@@ -99,9 +99,9 @@ discard block |
||
| 99 | 99 | include_spip('inc/lang'); |
| 100 | 100 | |
| 101 | 101 | if ($GLOBALS['spip_lang'] != $default) { |
| 102 | - $opt = lang_select($default); # et remplace |
|
| 102 | + $opt = lang_select($default); # et remplace |
|
| 103 | 103 | if ($GLOBALS['spip_lang'] != $default) { |
| 104 | - $default = ''; # annule tout choix par defaut |
|
| 104 | + $default = ''; # annule tout choix par defaut |
|
| 105 | 105 | if ($opt) { |
| 106 | 106 | lang_select(); |
| 107 | 107 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | # lien a partir de / |
| 112 | 112 | $cible = parametre_url(self(), 'lang', '', '&'); |
| 113 | - $post = generer_url_action('converser', 'redirect=' . rawurlencode((string) $cible), true); |
|
| 113 | + $post = generer_url_action('converser', 'redirect='.rawurlencode((string) $cible), true); |
|
| 114 | 114 | |
| 115 | 115 | return [ |
| 116 | 116 | 'formulaires/menu_lang', |
@@ -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 | /** |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * Pile complétée du code compilé |
| 42 | 42 | **/ |
| 43 | 43 | function balise_FORMULAIRE_ADMIN($p) { |
| 44 | - return calculer_balise_dynamique($p, 'FORMULAIRE_ADMIN', []); |
|
| 44 | + return calculer_balise_dynamique($p, 'FORMULAIRE_ADMIN', []); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * - chaîne vide sinon. |
| 59 | 59 | */ |
| 60 | 60 | function balise_FORMULAIRE_ADMIN_stat($args, $context_compil) { |
| 61 | - return $args; |
|
| 61 | + return $args; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -83,64 +83,64 @@ discard block |
||
| 83 | 83 | **/ |
| 84 | 84 | function balise_FORMULAIRE_ADMIN_dyn($float = '', $debug = '') { |
| 85 | 85 | |
| 86 | - static $dejafait = false; |
|
| 86 | + static $dejafait = false; |
|
| 87 | 87 | |
| 88 | - if (empty($_COOKIE['spip_admin'])) { |
|
| 89 | - return ''; |
|
| 90 | - } |
|
| 88 | + if (empty($_COOKIE['spip_admin'])) { |
|
| 89 | + return ''; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - if (!is_array($debug)) { |
|
| 93 | - if ($dejafait) { |
|
| 94 | - return ''; |
|
| 95 | - } |
|
| 96 | - } else { |
|
| 97 | - if ($dejafait) { |
|
| 98 | - if (empty($debug['sourcefile'])) { |
|
| 99 | - return ''; |
|
| 100 | - } |
|
| 101 | - foreach ($debug['sourcefile'] as $k => $v) { |
|
| 102 | - if (str_contains((string) $v, 'administration.') && isset($debug['resultat'][$k . 'tout'])) { |
|
| 103 | - return $debug['resultat'][$k . 'tout']; |
|
| 104 | - } |
|
| 105 | - } |
|
| 92 | + if (!is_array($debug)) { |
|
| 93 | + if ($dejafait) { |
|
| 94 | + return ''; |
|
| 95 | + } |
|
| 96 | + } else { |
|
| 97 | + if ($dejafait) { |
|
| 98 | + if (empty($debug['sourcefile'])) { |
|
| 99 | + return ''; |
|
| 100 | + } |
|
| 101 | + foreach ($debug['sourcefile'] as $k => $v) { |
|
| 102 | + if (str_contains((string) $v, 'administration.') && isset($debug['resultat'][$k . 'tout'])) { |
|
| 103 | + return $debug['resultat'][$k . 'tout']; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - return ''; |
|
| 108 | - } |
|
| 109 | - } |
|
| 107 | + return ''; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - include_spip('inc/autoriser'); |
|
| 112 | - include_spip('base/abstract_sql'); |
|
| 111 | + include_spip('inc/autoriser'); |
|
| 112 | + include_spip('base/abstract_sql'); |
|
| 113 | 113 | |
| 114 | 114 | |
| 115 | - $dejafait = true; |
|
| 115 | + $dejafait = true; |
|
| 116 | 116 | |
| 117 | - // Preparer le #ENV des boutons |
|
| 117 | + // Preparer le #ENV des boutons |
|
| 118 | 118 | |
| 119 | - $env = admin_objet(); |
|
| 119 | + $env = admin_objet(); |
|
| 120 | 120 | |
| 121 | - // Pas de "modifier ce..." ? -> donner "acces a l'espace prive" |
|
| 122 | - if (!$env) { |
|
| 123 | - $env['ecrire'] = _DIR_RESTREINT_ABS; |
|
| 124 | - } |
|
| 121 | + // Pas de "modifier ce..." ? -> donner "acces a l'espace prive" |
|
| 122 | + if (!$env) { |
|
| 123 | + $env['ecrire'] = _DIR_RESTREINT_ABS; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - $env['divclass'] = $float; |
|
| 127 | - $env['lang'] = admin_lang(); |
|
| 128 | - $env['calcul'] = (_request('var_mode') ? 'recalcul' : 'calcul'); |
|
| 129 | - $env['debug'] = ((defined('_VAR_PREVIEW') && _VAR_PREVIEW) ? '' : admin_debug()); |
|
| 130 | - $env['analyser'] = (!$env['debug'] && !$GLOBALS['xhtml']) ? '' : admin_valider(); |
|
| 131 | - $env['inclure'] = ((defined('_VAR_INCLURE') && _VAR_INCLURE) ? 'inclure' : ''); |
|
| 126 | + $env['divclass'] = $float; |
|
| 127 | + $env['lang'] = admin_lang(); |
|
| 128 | + $env['calcul'] = (_request('var_mode') ? 'recalcul' : 'calcul'); |
|
| 129 | + $env['debug'] = ((defined('_VAR_PREVIEW') && _VAR_PREVIEW) ? '' : admin_debug()); |
|
| 130 | + $env['analyser'] = (!$env['debug'] && !$GLOBALS['xhtml']) ? '' : admin_valider(); |
|
| 131 | + $env['inclure'] = ((defined('_VAR_INCLURE') && _VAR_INCLURE) ? 'inclure' : ''); |
|
| 132 | 132 | |
| 133 | - if (empty($GLOBALS['use_cache'])) { |
|
| 134 | - $env['use_cache'] = ' *'; |
|
| 135 | - } |
|
| 133 | + if (empty($GLOBALS['use_cache'])) { |
|
| 134 | + $env['use_cache'] = ' *'; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - if (isset($debug['validation'])) { |
|
| 138 | - $env['xhtml_error'] = $debug['validation']; |
|
| 139 | - } |
|
| 137 | + if (isset($debug['validation'])) { |
|
| 138 | + $env['xhtml_error'] = $debug['validation']; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - $env['_pipelines']['formulaire_admin'] = []; |
|
| 141 | + $env['_pipelines']['formulaire_admin'] = []; |
|
| 142 | 142 | |
| 143 | - return ['formulaires/administration', 0, $env]; |
|
| 143 | + return ['formulaires/administration', 0, $env]; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | |
@@ -158,46 +158,46 @@ discard block |
||
| 158 | 158 | * Tableau de l'environnement calculé |
| 159 | 159 | **/ |
| 160 | 160 | function admin_objet() { |
| 161 | - include_spip('inc/urls'); |
|
| 162 | - $env = []; |
|
| 163 | - |
|
| 164 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 165 | - $objets = urls_liste_objets(false); |
|
| 166 | - $objets = array_diff($objets, ['rubrique']); |
|
| 167 | - $objets = array_reverse($objets); |
|
| 168 | - array_unshift($objets, 'rubrique'); |
|
| 169 | - foreach ($objets as $obj) { |
|
| 170 | - $type = $obj; |
|
| 171 | - if ( |
|
| 172 | - $type == objet_type($type, false) |
|
| 173 | - && ($_id_type = id_table_objet($type)) |
|
| 174 | - && isset($GLOBALS['contexte'][$_id_type]) |
|
| 175 | - && ($id = $GLOBALS['contexte'][$_id_type]) |
|
| 176 | - && !is_array($id) |
|
| 177 | - && ($id = (int) $id) |
|
| 178 | - && ($desc = $trouver_table(table_objet_sql($type))) |
|
| 179 | - ) { |
|
| 180 | - $id = sql_getfetsel($_id_type, table_objet_sql($type), "$_id_type=" . (int) $id); |
|
| 181 | - if ($id) { |
|
| 182 | - $env[$_id_type] = $id; |
|
| 183 | - $env['objet'] = $type; |
|
| 184 | - $env['id_objet'] = $id; |
|
| 185 | - $env['voir_' . $obj] = str_replace('&', '&', (string) generer_objet_url($id, $obj, '', '', false)); |
|
| 186 | - if ( |
|
| 187 | - isset($desc['field']['id_rubrique']) |
|
| 188 | - && $type != 'rubrique' |
|
| 189 | - ) { |
|
| 190 | - unset($env['id_rubrique']); |
|
| 191 | - unset($env['voir_rubrique']); |
|
| 192 | - if (admin_preview($type, $id, $desc)) { |
|
| 193 | - $env['preview'] = parametre_url(self(), 'var_mode', 'preview', '&'); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $env; |
|
| 161 | + include_spip('inc/urls'); |
|
| 162 | + $env = []; |
|
| 163 | + |
|
| 164 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 165 | + $objets = urls_liste_objets(false); |
|
| 166 | + $objets = array_diff($objets, ['rubrique']); |
|
| 167 | + $objets = array_reverse($objets); |
|
| 168 | + array_unshift($objets, 'rubrique'); |
|
| 169 | + foreach ($objets as $obj) { |
|
| 170 | + $type = $obj; |
|
| 171 | + if ( |
|
| 172 | + $type == objet_type($type, false) |
|
| 173 | + && ($_id_type = id_table_objet($type)) |
|
| 174 | + && isset($GLOBALS['contexte'][$_id_type]) |
|
| 175 | + && ($id = $GLOBALS['contexte'][$_id_type]) |
|
| 176 | + && !is_array($id) |
|
| 177 | + && ($id = (int) $id) |
|
| 178 | + && ($desc = $trouver_table(table_objet_sql($type))) |
|
| 179 | + ) { |
|
| 180 | + $id = sql_getfetsel($_id_type, table_objet_sql($type), "$_id_type=" . (int) $id); |
|
| 181 | + if ($id) { |
|
| 182 | + $env[$_id_type] = $id; |
|
| 183 | + $env['objet'] = $type; |
|
| 184 | + $env['id_objet'] = $id; |
|
| 185 | + $env['voir_' . $obj] = str_replace('&', '&', (string) generer_objet_url($id, $obj, '', '', false)); |
|
| 186 | + if ( |
|
| 187 | + isset($desc['field']['id_rubrique']) |
|
| 188 | + && $type != 'rubrique' |
|
| 189 | + ) { |
|
| 190 | + unset($env['id_rubrique']); |
|
| 191 | + unset($env['voir_rubrique']); |
|
| 192 | + if (admin_preview($type, $id, $desc)) { |
|
| 193 | + $env['preview'] = parametre_url(self(), 'var_mode', 'preview', '&'); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $env; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | |
@@ -215,30 +215,30 @@ discard block |
||
| 215 | 215 | * - Tableau d'un élément sinon. |
| 216 | 216 | **/ |
| 217 | 217 | function admin_preview($type, $id, $desc = null) { |
| 218 | - if (defined('_VAR_PREVIEW') && _VAR_PREVIEW) { |
|
| 219 | - return ''; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if (!$desc) { |
|
| 223 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 224 | - $desc = $trouver_table(table_objet_sql($type)); |
|
| 225 | - } |
|
| 226 | - if (!$desc || !isset($desc['field']['statut'])) { |
|
| 227 | - return ''; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - include_spip('inc/autoriser'); |
|
| 231 | - if (!autoriser('previsualiser')) { |
|
| 232 | - return ''; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $notpub = sql_in('statut', ['prop', 'prive']); |
|
| 236 | - |
|
| 237 | - if ($type == 'article' && $GLOBALS['meta']['post_dates'] != 'oui') { |
|
| 238 | - $notpub .= " OR (statut='publie' AND date>" . sql_quote(date('Y-m-d H:i:s')) . ')'; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - return sql_fetsel('1', table_objet_sql($type), id_table_objet($type) . '=' . $id . " AND ($notpub)"); |
|
| 218 | + if (defined('_VAR_PREVIEW') && _VAR_PREVIEW) { |
|
| 219 | + return ''; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if (!$desc) { |
|
| 223 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 224 | + $desc = $trouver_table(table_objet_sql($type)); |
|
| 225 | + } |
|
| 226 | + if (!$desc || !isset($desc['field']['statut'])) { |
|
| 227 | + return ''; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + include_spip('inc/autoriser'); |
|
| 231 | + if (!autoriser('previsualiser')) { |
|
| 232 | + return ''; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $notpub = sql_in('statut', ['prop', 'prive']); |
|
| 236 | + |
|
| 237 | + if ($type == 'article' && $GLOBALS['meta']['post_dates'] != 'oui') { |
|
| 238 | + $notpub .= " OR (statut='publie' AND date>" . sql_quote(date('Y-m-d H:i:s')) . ')'; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + return sql_fetsel('1', table_objet_sql($type), id_table_objet($type) . '=' . $id . " AND ($notpub)"); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -249,25 +249,25 @@ discard block |
||
| 249 | 249 | * Code de langue |
| 250 | 250 | **/ |
| 251 | 251 | function admin_lang() { |
| 252 | - $alang = ''; |
|
| 253 | - if (!empty($_COOKIE['spip_admin'])) { |
|
| 254 | - $email_or_login = preg_replace(',^@,', '', (string) $_COOKIE['spip_admin']); |
|
| 255 | - $alang = sql_getfetsel('lang', 'spip_auteurs', 'email=' . sql_quote($email_or_login)); |
|
| 256 | - if (!$alang) { |
|
| 257 | - $alang = sql_getfetsel('lang', 'spip_auteurs', 'login=' . sql_quote($email_or_login)); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - if (!$alang) { |
|
| 261 | - return ''; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $l = lang_select($alang); |
|
| 265 | - $alang = $GLOBALS['spip_lang']; |
|
| 266 | - if ($l) { |
|
| 267 | - lang_select(); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - return $alang; |
|
| 252 | + $alang = ''; |
|
| 253 | + if (!empty($_COOKIE['spip_admin'])) { |
|
| 254 | + $email_or_login = preg_replace(',^@,', '', (string) $_COOKIE['spip_admin']); |
|
| 255 | + $alang = sql_getfetsel('lang', 'spip_auteurs', 'email=' . sql_quote($email_or_login)); |
|
| 256 | + if (!$alang) { |
|
| 257 | + $alang = sql_getfetsel('lang', 'spip_auteurs', 'login=' . sql_quote($email_or_login)); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + if (!$alang) { |
|
| 261 | + return ''; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $l = lang_select($alang); |
|
| 265 | + $alang = $GLOBALS['spip_lang']; |
|
| 266 | + if ($l) { |
|
| 267 | + lang_select(); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + return $alang; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -277,11 +277,11 @@ discard block |
||
| 277 | 277 | **/ |
| 278 | 278 | function admin_valider() { |
| 279 | 279 | |
| 280 | - return ((!isset($GLOBALS['xhtml']) || $GLOBALS['xhtml'] !== 'true') ? |
|
| 281 | - (parametre_url(self(), 'var_mode', 'debug', '&') |
|
| 282 | - . '&var_mode_affiche=validation') : |
|
| 283 | - ('http://validator.w3.org/check?uri=' |
|
| 284 | - . rawurlencode('http://' . $_SERVER['HTTP_HOST'] . nettoyer_uri()))); |
|
| 280 | + return ((!isset($GLOBALS['xhtml']) || $GLOBALS['xhtml'] !== 'true') ? |
|
| 281 | + (parametre_url(self(), 'var_mode', 'debug', '&') |
|
| 282 | + . '&var_mode_affiche=validation') : |
|
| 283 | + ('http://validator.w3.org/check?uri=' |
|
| 284 | + . rawurlencode('http://' . $_SERVER['HTTP_HOST'] . nettoyer_uri()))); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -290,10 +290,10 @@ discard block |
||
| 290 | 290 | * @return string |
| 291 | 291 | **/ |
| 292 | 292 | function admin_debug() { |
| 293 | - return ( |
|
| 294 | - (isset($GLOBALS['forcer_debug']) && $GLOBALS['forcer_debug'] |
|
| 295 | - || isset($GLOBALS['bouton_admin_debug']) && $GLOBALS['bouton_admin_debug'] |
|
| 296 | - || defined('_VAR_MODE') && _VAR_MODE == 'debug' && isset($_COOKIE['spip_debug']) && $_COOKIE['spip_debug']) && autoriser('debug') |
|
| 297 | - ) |
|
| 298 | - ? parametre_url(self(), 'var_mode', 'debug', '&') : ''; |
|
| 293 | + return ( |
|
| 294 | + (isset($GLOBALS['forcer_debug']) && $GLOBALS['forcer_debug'] |
|
| 295 | + || isset($GLOBALS['bouton_admin_debug']) && $GLOBALS['bouton_admin_debug'] |
|
| 296 | + || defined('_VAR_MODE') && _VAR_MODE == 'debug' && isset($_COOKIE['spip_debug']) && $_COOKIE['spip_debug']) && autoriser('debug') |
|
| 297 | + ) |
|
| 298 | + ? parametre_url(self(), 'var_mode', 'debug', '&') : ''; |
|
| 299 | 299 | } |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | return ''; |
| 100 | 100 | } |
| 101 | 101 | foreach ($debug['sourcefile'] as $k => $v) { |
| 102 | - if (str_contains((string) $v, 'administration.') && isset($debug['resultat'][$k . 'tout'])) { |
|
| 103 | - return $debug['resultat'][$k . 'tout']; |
|
| 102 | + if (str_contains((string) $v, 'administration.') && isset($debug['resultat'][$k.'tout'])) { |
|
| 103 | + return $debug['resultat'][$k.'tout']; |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
@@ -177,12 +177,12 @@ discard block |
||
| 177 | 177 | && ($id = (int) $id) |
| 178 | 178 | && ($desc = $trouver_table(table_objet_sql($type))) |
| 179 | 179 | ) { |
| 180 | - $id = sql_getfetsel($_id_type, table_objet_sql($type), "$_id_type=" . (int) $id); |
|
| 180 | + $id = sql_getfetsel($_id_type, table_objet_sql($type), "$_id_type=".(int) $id); |
|
| 181 | 181 | if ($id) { |
| 182 | 182 | $env[$_id_type] = $id; |
| 183 | 183 | $env['objet'] = $type; |
| 184 | 184 | $env['id_objet'] = $id; |
| 185 | - $env['voir_' . $obj] = str_replace('&', '&', (string) generer_objet_url($id, $obj, '', '', false)); |
|
| 185 | + $env['voir_'.$obj] = str_replace('&', '&', (string) generer_objet_url($id, $obj, '', '', false)); |
|
| 186 | 186 | if ( |
| 187 | 187 | isset($desc['field']['id_rubrique']) |
| 188 | 188 | && $type != 'rubrique' |
@@ -235,10 +235,10 @@ discard block |
||
| 235 | 235 | $notpub = sql_in('statut', ['prop', 'prive']); |
| 236 | 236 | |
| 237 | 237 | if ($type == 'article' && $GLOBALS['meta']['post_dates'] != 'oui') { |
| 238 | - $notpub .= " OR (statut='publie' AND date>" . sql_quote(date('Y-m-d H:i:s')) . ')'; |
|
| 238 | + $notpub .= " OR (statut='publie' AND date>".sql_quote(date('Y-m-d H:i:s')).')'; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - return sql_fetsel('1', table_objet_sql($type), id_table_objet($type) . '=' . $id . " AND ($notpub)"); |
|
| 241 | + return sql_fetsel('1', table_objet_sql($type), id_table_objet($type).'='.$id." AND ($notpub)"); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -252,9 +252,9 @@ discard block |
||
| 252 | 252 | $alang = ''; |
| 253 | 253 | if (!empty($_COOKIE['spip_admin'])) { |
| 254 | 254 | $email_or_login = preg_replace(',^@,', '', (string) $_COOKIE['spip_admin']); |
| 255 | - $alang = sql_getfetsel('lang', 'spip_auteurs', 'email=' . sql_quote($email_or_login)); |
|
| 255 | + $alang = sql_getfetsel('lang', 'spip_auteurs', 'email='.sql_quote($email_or_login)); |
|
| 256 | 256 | if (!$alang) { |
| 257 | - $alang = sql_getfetsel('lang', 'spip_auteurs', 'login=' . sql_quote($email_or_login)); |
|
| 257 | + $alang = sql_getfetsel('lang', 'spip_auteurs', 'login='.sql_quote($email_or_login)); |
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | if (!$alang) { |
@@ -279,9 +279,8 @@ discard block |
||
| 279 | 279 | |
| 280 | 280 | return ((!isset($GLOBALS['xhtml']) || $GLOBALS['xhtml'] !== 'true') ? |
| 281 | 281 | (parametre_url(self(), 'var_mode', 'debug', '&') |
| 282 | - . '&var_mode_affiche=validation') : |
|
| 283 | - ('http://validator.w3.org/check?uri=' |
|
| 284 | - . rawurlencode('http://' . $_SERVER['HTTP_HOST'] . nettoyer_uri()))); |
|
| 282 | + . '&var_mode_affiche=validation') : ('http://validator.w3.org/check?uri=' |
|
| 283 | + . rawurlencode('http://'.$_SERVER['HTTP_HOST'].nettoyer_uri()))); |
|
| 285 | 284 | } |
| 286 | 285 | |
| 287 | 286 | /** |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
| 68 | 68 | |
| 69 | 69 | // Si l'utilisateur figure deja dans la base, y recuperer les infos |
| 70 | - $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 70 | + $r = sql_fetsel('*', 'spip_auteurs', 'login='.sql_quote($login)." AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | 71 | |
| 72 | 72 | if ($r) { |
| 73 | 73 | return array_merge($r, $credentials_ldap); |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | if ($r) { |
| 91 | 91 | return array_merge( |
| 92 | 92 | $credentials_ldap, |
| 93 | - sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . (int) $r, '', '', '', '', $serveur) |
|
| 93 | + sql_fetsel('*', 'spip_auteurs', 'id_auteur='.(int) $r, '', '', '', '', $serveur) |
|
| 94 | 94 | ); |
| 95 | 95 | } |
| 96 | 96 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $connexion = spip_connect($serveur); |
| 120 | 120 | if (!is_array($connexion['ldap'])) { |
| 121 | 121 | if ($connexion['authentification']['ldap']) { |
| 122 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 122 | + $f = _DIR_CONNECT.$connexion['authentification']['ldap']; |
|
| 123 | 123 | unset($GLOBALS['ldap_link']); |
| 124 | 124 | if (is_readable($f)) { |
| 125 | 125 | include_once($f); |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
| 333 | 333 | return false; |
| 334 | 334 | } |
| 335 | - $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5((string) $new_pass))); |
|
| 335 | + $encoded_pass = '{MD5}'.base64_encode(pack('H*', md5((string) $new_pass))); |
|
| 336 | 336 | |
| 337 | 337 | return ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
| 338 | 338 | } |
@@ -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 | // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok |
@@ -24,12 +24,12 @@ discard block |
||
| 24 | 24 | // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login |
| 25 | 25 | // ne pas ecraser une definition perso dans mes_options |
| 26 | 26 | if (!isset($GLOBALS['ldap_attributes']) || !is_array($GLOBALS['ldap_attributes'])) { |
| 27 | - $GLOBALS['ldap_attributes'] = [ |
|
| 28 | - 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 29 | - 'nom' => 'cn', |
|
| 30 | - 'email' => 'mail', |
|
| 31 | - 'bio' => 'description' |
|
| 32 | - ]; |
|
| 27 | + $GLOBALS['ldap_attributes'] = [ |
|
| 28 | + 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 29 | + 'nom' => 'cn', |
|
| 30 | + 'email' => 'mail', |
|
| 31 | + 'bio' => 'description' |
|
| 32 | + ]; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -55,49 +55,49 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function auth_ldap_dist($login, #[\SensitiveParameter] $pass, $serveur = '', $phpauth = false) { |
| 57 | 57 | |
| 58 | - #spip_logger()->info("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 59 | - |
|
| 60 | - // Utilisateur connu ? |
|
| 61 | - // si http auth, inutile de reauthentifier: cela |
|
| 62 | - // ne marchera pas avec auth http autre que basic. |
|
| 63 | - $checkpass = !isset($_SERVER['REMOTE_USER']); |
|
| 64 | - if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 65 | - return []; |
|
| 66 | - } |
|
| 67 | - $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 68 | - |
|
| 69 | - // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 70 | - $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | - |
|
| 72 | - if ($r) { |
|
| 73 | - return array_merge($r, $credentials_ldap); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // sinon importer les infos depuis LDAP, |
|
| 77 | - |
|
| 78 | - if ( |
|
| 79 | - $GLOBALS['meta']['ldap_statut_import'] && ($desc = auth_ldap_retrouver($dn, [], $serveur)) |
|
| 80 | - ) { |
|
| 81 | - // rajouter le statut indique a l'install |
|
| 82 | - $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 83 | - $desc['login'] = $login; |
|
| 84 | - $desc['source'] = 'ldap'; |
|
| 85 | - $desc['pass'] = ''; |
|
| 86 | - |
|
| 87 | - $r = sql_insertq('spip_auteurs', $desc, [], $serveur); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - if ($r) { |
|
| 91 | - return array_merge( |
|
| 92 | - $credentials_ldap, |
|
| 93 | - sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . (int) $r, '', '', '', '', $serveur) |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // sinon echec |
|
| 98 | - spip_logger()->info("Creation de l'auteur '$login' impossible"); |
|
| 99 | - |
|
| 100 | - return []; |
|
| 58 | + #spip_logger()->info("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 59 | + |
|
| 60 | + // Utilisateur connu ? |
|
| 61 | + // si http auth, inutile de reauthentifier: cela |
|
| 62 | + // ne marchera pas avec auth http autre que basic. |
|
| 63 | + $checkpass = !isset($_SERVER['REMOTE_USER']); |
|
| 64 | + if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 65 | + return []; |
|
| 66 | + } |
|
| 67 | + $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 68 | + |
|
| 69 | + // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 70 | + $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | + |
|
| 72 | + if ($r) { |
|
| 73 | + return array_merge($r, $credentials_ldap); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // sinon importer les infos depuis LDAP, |
|
| 77 | + |
|
| 78 | + if ( |
|
| 79 | + $GLOBALS['meta']['ldap_statut_import'] && ($desc = auth_ldap_retrouver($dn, [], $serveur)) |
|
| 80 | + ) { |
|
| 81 | + // rajouter le statut indique a l'install |
|
| 82 | + $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 83 | + $desc['login'] = $login; |
|
| 84 | + $desc['source'] = 'ldap'; |
|
| 85 | + $desc['pass'] = ''; |
|
| 86 | + |
|
| 87 | + $r = sql_insertq('spip_auteurs', $desc, [], $serveur); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + if ($r) { |
|
| 91 | + return array_merge( |
|
| 92 | + $credentials_ldap, |
|
| 93 | + sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . (int) $r, '', '', '', '', $serveur) |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // sinon echec |
|
| 98 | + spip_logger()->info("Creation de l'auteur '$login' impossible"); |
|
| 99 | + |
|
| 100 | + return []; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -111,36 +111,36 @@ discard block |
||
| 111 | 111 | * @return array |
| 112 | 112 | */ |
| 113 | 113 | function auth_ldap_connect($serveur = '') { |
| 114 | - include_spip('base/connect_sql'); |
|
| 115 | - static $connexions_ldap = []; |
|
| 116 | - if (isset($connexions_ldap[$serveur])) { |
|
| 117 | - return $connexions_ldap[$serveur]; |
|
| 118 | - } |
|
| 119 | - $connexion = spip_connect($serveur); |
|
| 120 | - if (!is_array($connexion['ldap'])) { |
|
| 121 | - if ($connexion['authentification']['ldap']) { |
|
| 122 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 123 | - unset($GLOBALS['ldap_link']); |
|
| 124 | - if (is_readable($f)) { |
|
| 125 | - include_once($f); |
|
| 126 | - }; |
|
| 127 | - if (isset($GLOBALS['ldap_link'])) { |
|
| 128 | - $connexion['ldap'] = [ |
|
| 129 | - 'link' => $GLOBALS['ldap_link'], |
|
| 130 | - 'base' => $GLOBALS['ldap_base'] |
|
| 131 | - ]; |
|
| 132 | - } else { |
|
| 133 | - spip_logger()->info("connection LDAP $serveur mal definie dans $f"); |
|
| 134 | - } |
|
| 135 | - if (isset($GLOBALS['ldap_champs'])) { |
|
| 136 | - $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 137 | - } |
|
| 138 | - } else { |
|
| 139 | - spip_logger()->info("connection LDAP $serveur inconnue"); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 114 | + include_spip('base/connect_sql'); |
|
| 115 | + static $connexions_ldap = []; |
|
| 116 | + if (isset($connexions_ldap[$serveur])) { |
|
| 117 | + return $connexions_ldap[$serveur]; |
|
| 118 | + } |
|
| 119 | + $connexion = spip_connect($serveur); |
|
| 120 | + if (!is_array($connexion['ldap'])) { |
|
| 121 | + if ($connexion['authentification']['ldap']) { |
|
| 122 | + $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 123 | + unset($GLOBALS['ldap_link']); |
|
| 124 | + if (is_readable($f)) { |
|
| 125 | + include_once($f); |
|
| 126 | + }; |
|
| 127 | + if (isset($GLOBALS['ldap_link'])) { |
|
| 128 | + $connexion['ldap'] = [ |
|
| 129 | + 'link' => $GLOBALS['ldap_link'], |
|
| 130 | + 'base' => $GLOBALS['ldap_base'] |
|
| 131 | + ]; |
|
| 132 | + } else { |
|
| 133 | + spip_logger()->info("connection LDAP $serveur mal definie dans $f"); |
|
| 134 | + } |
|
| 135 | + if (isset($GLOBALS['ldap_champs'])) { |
|
| 136 | + $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 137 | + } |
|
| 138 | + } else { |
|
| 139 | + spip_logger()->info("connection LDAP $serveur inconnue"); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -154,52 +154,52 @@ discard block |
||
| 154 | 154 | * Le login trouvé ou chaine vide si non trouvé |
| 155 | 155 | */ |
| 156 | 156 | function auth_ldap_search($login, #[\SensitiveParameter] $pass, $checkpass = true, $serveur = '') { |
| 157 | - // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 158 | - $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 159 | - if (!strlen($login_search) || $checkpass && !strlen($pass)) { |
|
| 160 | - return ''; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // verifier la connexion |
|
| 164 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 165 | - return ''; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $ldap_link = $ldap['link'] ?? null; |
|
| 169 | - $ldap_base = $ldap['base'] ?? null; |
|
| 170 | - $desc = empty($ldap['attributes']) ? $GLOBALS['ldap_attributes'] : $ldap['attributes']; |
|
| 171 | - |
|
| 172 | - $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 173 | - |
|
| 174 | - // Tenter une recherche pour essayer de retrouver le DN |
|
| 175 | - foreach ($logins as $att) { |
|
| 176 | - $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 177 | - $info = @ldap_get_entries($ldap_link, $result); |
|
| 178 | - // Ne pas accepter les resultats si plus d'une entree |
|
| 179 | - // (on veut un attribut unique) |
|
| 180 | - |
|
| 181 | - if (is_array($info) && $info['count'] == 1) { |
|
| 182 | - $dn = $info[0]['dn']; |
|
| 183 | - if (!$checkpass) { |
|
| 184 | - return $dn; |
|
| 185 | - } |
|
| 186 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 187 | - return $dn; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - if ($checkpass && !isset($dn)) { |
|
| 193 | - // Si echec, essayer de deviner le DN |
|
| 194 | - foreach ($logins as $att) { |
|
| 195 | - $dn = "$att=$login_search, $ldap_base"; |
|
| 196 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 197 | - return "$att=$login_search, $ldap_base"; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return ''; |
|
| 157 | + // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 158 | + $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 159 | + if (!strlen($login_search) || $checkpass && !strlen($pass)) { |
|
| 160 | + return ''; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // verifier la connexion |
|
| 164 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 165 | + return ''; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $ldap_link = $ldap['link'] ?? null; |
|
| 169 | + $ldap_base = $ldap['base'] ?? null; |
|
| 170 | + $desc = empty($ldap['attributes']) ? $GLOBALS['ldap_attributes'] : $ldap['attributes']; |
|
| 171 | + |
|
| 172 | + $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 173 | + |
|
| 174 | + // Tenter une recherche pour essayer de retrouver le DN |
|
| 175 | + foreach ($logins as $att) { |
|
| 176 | + $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 177 | + $info = @ldap_get_entries($ldap_link, $result); |
|
| 178 | + // Ne pas accepter les resultats si plus d'une entree |
|
| 179 | + // (on veut un attribut unique) |
|
| 180 | + |
|
| 181 | + if (is_array($info) && $info['count'] == 1) { |
|
| 182 | + $dn = $info[0]['dn']; |
|
| 183 | + if (!$checkpass) { |
|
| 184 | + return $dn; |
|
| 185 | + } |
|
| 186 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 187 | + return $dn; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + if ($checkpass && !isset($dn)) { |
|
| 193 | + // Si echec, essayer de deviner le DN |
|
| 194 | + foreach ($logins as $att) { |
|
| 195 | + $dn = "$att=$login_search, $ldap_base"; |
|
| 196 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 197 | + return "$att=$login_search, $ldap_base"; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return ''; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -211,40 +211,40 @@ discard block |
||
| 211 | 211 | * @return array |
| 212 | 212 | */ |
| 213 | 213 | function auth_ldap_retrouver($dn, $desc = [], $serveur = '') { |
| 214 | - // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 214 | + // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 215 | 215 | |
| 216 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 217 | - spip_logger()->info("ldap $serveur injoignable"); |
|
| 216 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 217 | + spip_logger()->info("ldap $serveur injoignable"); |
|
| 218 | 218 | |
| 219 | - return []; |
|
| 220 | - } |
|
| 219 | + return []; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - $ldap_link = $ldap['link']; |
|
| 223 | - if (!$desc) { |
|
| 224 | - $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes']; |
|
| 225 | - unset($desc['login']); |
|
| 226 | - } |
|
| 227 | - $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 222 | + $ldap_link = $ldap['link']; |
|
| 223 | + if (!$desc) { |
|
| 224 | + $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes']; |
|
| 225 | + unset($desc['login']); |
|
| 226 | + } |
|
| 227 | + $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 228 | 228 | |
| 229 | - if (!$result) { |
|
| 230 | - return []; |
|
| 231 | - } |
|
| 229 | + if (!$result) { |
|
| 230 | + return []; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 234 | - $val = @ldap_get_entries($ldap_link, $result); |
|
| 235 | - if (!is_array($val) || !is_array($val[0])) { |
|
| 236 | - return []; |
|
| 237 | - } |
|
| 238 | - $val = $val[0]; |
|
| 233 | + // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 234 | + $val = @ldap_get_entries($ldap_link, $result); |
|
| 235 | + if (!is_array($val) || !is_array($val[0])) { |
|
| 236 | + return []; |
|
| 237 | + } |
|
| 238 | + $val = $val[0]; |
|
| 239 | 239 | |
| 240 | - // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 241 | - include_spip('inc/charsets'); |
|
| 240 | + // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 241 | + include_spip('inc/charsets'); |
|
| 242 | 242 | |
| 243 | - foreach ($desc as $k => $v) { |
|
| 244 | - $desc[$k] = importer_charset($val[strtolower((string) $v)][0], 'utf-8'); |
|
| 245 | - } |
|
| 243 | + foreach ($desc as $k => $v) { |
|
| 244 | + $desc[$k] = importer_charset($val[strtolower((string) $v)][0], 'utf-8'); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - return $desc; |
|
| 247 | + return $desc; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * @return string |
| 257 | 257 | */ |
| 258 | 258 | function auth_ldap_retrouver_login($login, $serveur = '') { |
| 259 | - return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 259 | + return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | * Message d'erreur si login non valide, chaîne vide sinon |
| 277 | 277 | */ |
| 278 | 278 | function auth_ldap_verifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') { |
| 279 | - include_spip('auth/spip'); |
|
| 279 | + include_spip('auth/spip'); |
|
| 280 | 280 | |
| 281 | - return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 281 | + return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * ``` |
| 300 | 300 | */ |
| 301 | 301 | function auth_ldap_autoriser_modifier_pass($serveur = '') { |
| 302 | - return true; |
|
| 302 | + return true; |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -317,22 +317,22 @@ discard block |
||
| 317 | 317 | * Informe du succès ou de l'echec du changement du mot de passe |
| 318 | 318 | */ |
| 319 | 319 | function auth_ldap_modifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') { |
| 320 | - if (is_null($new_pass) || auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 321 | - return false; |
|
| 322 | - } |
|
| 323 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 324 | - return false; |
|
| 325 | - } |
|
| 326 | - $link = $ldap['link']; |
|
| 327 | - include_spip('inc/session'); |
|
| 328 | - $dn = session_get('ldap_dn'); |
|
| 329 | - if ('' == $dn) { |
|
| 330 | - return false; |
|
| 331 | - } |
|
| 332 | - if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 333 | - return false; |
|
| 334 | - } |
|
| 335 | - $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5((string) $new_pass))); |
|
| 336 | - |
|
| 337 | - return ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 320 | + if (is_null($new_pass) || auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 323 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 324 | + return false; |
|
| 325 | + } |
|
| 326 | + $link = $ldap['link']; |
|
| 327 | + include_spip('inc/session'); |
|
| 328 | + $dn = session_get('ldap_dn'); |
|
| 329 | + if ('' == $dn) { |
|
| 330 | + return false; |
|
| 331 | + } |
|
| 332 | + if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 333 | + return false; |
|
| 334 | + } |
|
| 335 | + $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5((string) $new_pass))); |
|
| 336 | + |
|
| 337 | + return ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 338 | 338 | } |